Scheduler.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. package com.cyksj.task;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.date.BetweenFormater;
  4. import cn.hutool.core.date.DateField;
  5. import cn.hutool.core.date.DateTime;
  6. import cn.hutool.core.date.DateUtil;
  7. import cn.hutool.core.util.StrUtil;
  8. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  9. import com.cyksj.common.EnvCommonService;
  10. import com.cyksj.common.constant.Constant;
  11. import com.cyksj.common.util.SmsUtil;
  12. import com.cyksj.common.util.StringUtil;
  13. import com.cyksj.dto.RedisKey;
  14. import com.cyksj.mapper.*;
  15. import com.cyksj.mapper.manage.cms.CmsUserMapper;
  16. import com.cyksj.mapper.manage.distribute.DistributeWaitingSendPointsMapper;
  17. import com.cyksj.mapper.manage.sys.WorkOrderMapper;
  18. import com.cyksj.model.entity.*;
  19. import com.cyksj.model.manage.views.AccountView;
  20. import com.cyksj.model.manage.views.GroupsRelationView;
  21. import com.cyksj.model.views.CloseGroupsTripsView;
  22. import com.cyksj.model.views.CmsUserVO;
  23. import com.cyksj.model.views.UserDistributeViews;
  24. import com.cyksj.redis.RedisService;
  25. import com.cyksj.service.mange.CmsAccountService;
  26. import com.cyksj.service.order.OrderDonService;
  27. import com.cyksj.service.register.RegisterOrderDonService;
  28. import com.cyksj.service.register.SpotifyService;
  29. import com.cyksj.service.relation.GroupRelationClearService;
  30. import com.cyksj.service.sms.SmsService;
  31. import com.cyksj.service.user.UserBenefitsService;
  32. import com.ejlchina.searcher.BeanSearcher;
  33. import com.ejlchina.searcher.param.Operator;
  34. import com.ejlchina.searcher.util.MapUtils;
  35. import com.google.common.collect.Lists;
  36. import lombok.RequiredArgsConstructor;
  37. import lombok.extern.slf4j.Slf4j;
  38. import org.springframework.dao.DuplicateKeyException;
  39. import org.springframework.scheduling.annotation.Scheduled;
  40. import org.springframework.stereotype.Component;
  41. import org.springframework.transaction.annotation.Transactional;
  42. import java.math.BigDecimal;
  43. import java.math.RoundingMode;
  44. import java.util.*;
  45. import java.util.concurrent.ConcurrentHashMap;
  46. import java.util.stream.Collectors;
  47. @Component
  48. @Slf4j
  49. @RequiredArgsConstructor
  50. public class Scheduler {
  51. private final GoodsDonMapper donMapper;
  52. private final GroupsMapper groupsMapper;
  53. private final OrderDonService orderDonService;
  54. private final GroupsRelationMapper groupsRelationMapper;
  55. private final UserMapper userMapper;
  56. private final BeanSearcher beanSearcher;
  57. private final SpotifyService spotifyService;
  58. private final RegisterOrderDonMapper registerOrderDonMapper;
  59. private final RedisService redisService;
  60. private final SysConfigMapper sysConfigMapper;
  61. private final DistributeWaitingSendPointsMapper distributeWaitingSendPointsMapper;
  62. private final RegisterOrderDonService registerOrderDonService;
  63. private final AppleAutoRegisterDataMapper appleAutoRegisterDataMapper;
  64. private final RealGoodsInterestUserMapper realGoodsInterestUserMapper;
  65. private final GroupRelationClearService groupRelationClearService;
  66. private final CmsAccountService cmsAccountService;
  67. private final EnvCommonService envCommonService;
  68. private final WorkOrderMapper workOrderMapper;
  69. private final SmsService smsService;
  70. private final CmsUserMapper cmsUserMapper;
  71. private final AccountDoubleVerifyRecordMapper doubleVerifyRecordMapper;
  72. private final UserBenefitsService userBenefitsService;
  73. /**
  74. * 每5分钟清理过期账号
  75. */
  76. @Scheduled(cron = "0 0/5 * * * ?")
  77. @Transactional(rollbackFor = Throwable.class)
  78. public void clearExpiry() {
  79. DateTime now = new DateTime();
  80. List<GroupsRelation> expiryList = groupsRelationMapper.selectList(Wrappers.lambdaQuery(GroupsRelation.class).le(GroupsRelation::getExpiryTime, now));
  81. log.info("定时清理过期账号start ===> 数量:{}", expiryList.size());
  82. //过期账号清楚有效期
  83. expiryList.forEach(relation -> groupRelationClearService.clearTicket(relation, UserTicketClearedRecord.Source.self));
  84. }
  85. @Scheduled(cron = "0 0 9 * * ?")
  86. public void expiryWxMsg() throws Exception {
  87. if (envCommonService.isPrdEnv()) {
  88. DateTime now = new DateTime();
  89. DateTime zero = DateUtil.offset(now, DateField.HOUR, -9);
  90. DateTime time = DateUtil.offset(zero, DateField.DAY_OF_MONTH, 1);
  91. List<GroupsRelationView> groupsRelations = beanSearcher.searchAll(GroupsRelationView.class, MapUtils.builder().field(GroupsRelationView::getExpiryTime, time).op(Operator.LessEqual).build());
  92. //String url = String.format("%sauth/weChat?url=%syinhe/web/ticket", envCommonService.getHost(), envCommonService.getDomain());
  93. for (GroupsRelationView relation : groupsRelations) {
  94. // User user = userMapper.selectById(relation.getUserId());
  95. // if (user != null && StrUtil.isNotBlank(user.getOpenId())) {
  96. // String openId = user.getOpenId();
  97. // WxAppTemplateView wxAppTemplateView = templateCommonService.getWxAppByUserId(openId, TemplateEnum.EXPIRY_TEMPLATE.getDesc());
  98. // if (wxAppTemplateView != null) {
  99. // WxMpTemplateMessage templateMessage = new WxMpTemplateMessage()
  100. // .setToUser(openId)
  101. // .setTemplateId(wxAppTemplateView.getTemplateId())
  102. // .setUrl(url);
  103. //
  104. // /**
  105. // * 您的账号即将到期
  106. // * 账号名称:Netflix账号
  107. // * 平台:Netflix
  108. // * 失效日期:3天后
  109. // * 异常原因:账号即将到期
  110. // * 请尽快续费,以免影响使用
  111. // */
  112. // GroupsTrips groupsTrips = groupsMapper.selectById(relation.getGroupsId());
  113. // GoodsDonSku donSku = skuMapper.selectById(groupsTrips.getSkuId());
  114. // GoodsDon goodsDon = donMapper.selectById(donSku.getGoodsId());
  115. // WxMpTemplateMessage.TemplateData data = templateMessage.getData();
  116. // data.setFirst(new WxMpTemplateData("您的账号即将到期"));
  117. // data.setKeyword1(new WxMpTemplateData(goodsDon.getTitle()));
  118. // data.setKeyword2(new WxMpTemplateData(DateUtil.format(relation.getExpiryTime(), "yyyy-MM-dd HH:mm:ss")));
  119. // data.setRemark(new WxMpTemplateData("请尽快续费,以免影响使用"));
  120. // log.info("发送账号即将到期消息至用户:{}", user.getId());
  121. // weChatService.sendTemplateMessage(weChatService.getAccessToken(wxAppTemplateView.getAppId()), Jsons.toJson(templateMessage));
  122. // }
  123. // List<Account> accounts = accountMapper.selectList(Wrappers.lambdaQuery(Account.class).le(Account::getExpiryTime, time));
  124. // List<CustomerService> customerServices = customerServiceMapper.selectList(null);
  125. // if(!accounts.isEmpty()){
  126. // for (CustomerService customerService : customerServices) {
  127. // openId = customerService.getOpenId();
  128. // WxMpTemplateMessage manageMessage = new WxMpTemplateMessage()
  129. // .setToUser(openId)
  130. // .setTemplateId(wxAppTemplateView.getTemplateId())
  131. // .setUrl(" ");
  132. // WxMpTemplateMessage.TemplateData data2 = manageMessage.getData();
  133. // data2.setFirst(new WxMpTemplateData("您有" + accounts.size() + "个主账号即将到期"));
  134. // data2.setKeyword1(new WxMpTemplateData("车队主账号"));
  135. // data2.setKeyword2(new WxMpTemplateData("车队主账号"));
  136. // data2.setKeyword3(new WxMpTemplateData("5天后"));
  137. // data2.setKeyword4(new WxMpTemplateData("账号即将到期"));
  138. // data2.setRemark(new WxMpTemplateData("请尽快登录后台-在账号管理中查看"));
  139. // log.info("发送账号即将到期消息至客服:{}", customerService.getNickName());
  140. // weChatService.sendTemplateMessage(weChatService.getAccessToken(),Jsons.toJson(manageMessage));
  141. // }
  142. // }
  143. // }
  144. //短信通知过期账号 用户
  145. try {
  146. String day = DateUtil.formatBetween(zero, relation.getExpiryTime(), BetweenFormater.Level.DAY);
  147. if ("0".equals(day)) day = "今";
  148. smsService.sendSmsToRelationUser(relation.getUserId(), String.format(Constant.ACCOUNT_EXPIRY_MSG_TEMPLATE, relation.getTitle(), day));
  149. } catch (Exception e) {
  150. log.error("过期账号用户:{}发送短信错误:{}", relation.getUserId(), StringUtil.getErrorText(e));
  151. }
  152. }
  153. }
  154. }
  155. /**
  156. * 定时关闭订单
  157. */
  158. @Scheduled(cron = "0 0/5 * * * ?")
  159. public void closeOrder() {
  160. //获取为支付订单
  161. DateTime now = new DateTime();
  162. Date newDate = DateUtil.offset(now, DateField.MINUTE, -5);
  163. List<OrderDon> list = orderDonService.list(Wrappers.lambdaQuery(OrderDon.class).eq(OrderDon::getStatus, OrderDon.Status.noPayment).le(OrderDon::getCreatedTime,newDate));
  164. log.info("定时任务 关闭 订单数:{}",list.size());
  165. list.forEach((orderDon)->{
  166. orderDonService.closeOrder(orderDon.getId());
  167. });
  168. }
  169. /**
  170. * spotify 注册
  171. */
  172. @Scheduled(cron = "0 0/15 * * * ?")
  173. public void spotify() {
  174. List<RegisterOrderDon> spotify = registerOrderDonMapper.selectList(Wrappers.lambdaQuery(RegisterOrderDon.class)
  175. .select(RegisterOrderDon::getId)
  176. .eq(RegisterOrderDon::getPlatform, "spotify")
  177. .eq(RegisterOrderDon::getStatus, RegisterOrderDon.Status.hasPayment));
  178. for (RegisterOrderDon orderDon : spotify) {
  179. spotifyService.register(orderDon.getId());
  180. }
  181. }
  182. /**
  183. * 每日免单重置
  184. */
  185. @Scheduled(cron = "0 0 0 * * ?")
  186. public void freeReset() {
  187. log.info("每日重置 spotify 免单账户数 [start]");
  188. SysConfig register_free_num = sysConfigMapper.selectOne(Wrappers.lambdaQuery(SysConfig.class).eq(SysConfig::getSysKey, "register_free_num"));
  189. redisService.set(RedisKey.SPOTIFY_FREE_NUM, Long.parseLong(register_free_num.getSysValue()));
  190. log.info("每日重置 spotify 免单账户数 [end] 数量:{}",register_free_num.getSysValue());
  191. }
  192. /**
  193. * 分销订单积分奖励分发
  194. */
  195. @Scheduled(cron = "0 0 0/2 * * ?")
  196. @Transactional(rollbackFor = Throwable.class)
  197. public void distributeOrdersSendPoints() {
  198. List<DistributeWaitingSendPoints> waitingSendPoints = Optional.ofNullable(distributeWaitingSendPointsMapper.selectList(Wrappers.lambdaQuery(DistributeWaitingSendPoints.class)
  199. .eq(DistributeWaitingSendPoints::getSendStatus, DistributeWaitingSendPoints.Status.waiting)
  200. .lt(DistributeWaitingSendPoints::getSendTime, DateTime.now())
  201. .select(DistributeWaitingSendPoints::getId,
  202. DistributeWaitingSendPoints::getOrderId,
  203. DistributeWaitingSendPoints::getPoints,
  204. DistributeWaitingSendPoints::getUserId,
  205. DistributeWaitingSendPoints::getSharedId,
  206. DistributeWaitingSendPoints::getSendTime))).orElse(new ArrayList<>());
  207. log.info("查询分销订单积分分发记录开始,条数:{}=======》", waitingSendPoints.size());
  208. waitingSendPoints.forEach(wait -> {
  209. //积分待发人
  210. Long sharedId = wait.getSharedId();
  211. User user = userMapper.selectById(sharedId);
  212. if (user == null) {
  213. wait.setSendStatus(DistributeWaitingSendPoints.Status.not_exist);
  214. log.info("分销订单,发送积分用户不存在");
  215. distributeWaitingSendPointsMapper.updateById(wait);
  216. } else {
  217. wait.setSendStatus(DistributeWaitingSendPoints.Status.success);
  218. log.info("更新用户积分开始=====>");
  219. userBenefitsService.addDistributePoints(sharedId, wait.getPoints());
  220. distributeWaitingSendPointsMapper.updateById(wait);
  221. log.info("分销积分表订单id:{}发放积分success", wait.getOrderId());
  222. }
  223. });
  224. }
  225. /**
  226. * 定时更新未支付AppleID自动注册订单
  227. */
  228. @Scheduled(cron = "0 0/5 * * * ?")
  229. public void updateAppleAutoStatus() {
  230. //获取为支付订单
  231. DateTime now = new DateTime();
  232. Date newDate = DateUtil.offset(now, DateField.MINUTE, -5);
  233. List<Long> orderDons = appleAutoRegisterDataMapper.getAllNoPayOrders(newDate);
  234. log.info("定时更新未支付AppleID自动注册订单 订单数:{}",orderDons.size());
  235. orderDons.forEach((orderId)->{
  236. registerOrderDonService.updateAppleAutoStatus(orderId);
  237. });
  238. }
  239. /**
  240. * 实物订单意愿数据
  241. */
  242. @Scheduled(cron = "0 0/5 * * * ?")
  243. public void realGoodsInterestUser() {
  244. Optional.ofNullable(orderDonService.selectNoPaymentRealGoods()).ifPresent(list -> {
  245. if (list.size() > 0) {
  246. Map<String, List<RealGoodsInterestUser>> collect = list.stream().collect(Collectors.groupingBy(RealGoodsInterestUser::getGroupBy));
  247. log.info("实物订单意愿数据同步开始");
  248. collect.forEach((k, data) -> {
  249. RealGoodsInterestUser realGoodsInterestUser = null;
  250. if (data.size() == 0) {
  251. realGoodsInterestUser = data.get(0);
  252. } else {
  253. List<RealGoodsInterestUser> high = data.stream().sorted(Comparator.comparing(RealGoodsInterestUser::getMoney).thenComparing(RealGoodsInterestUser::getOrderCreatedTime).reversed()).collect(Collectors.toList());
  254. realGoodsInterestUser = high.get(0);
  255. }
  256. try {
  257. realGoodsInterestUserMapper.insert(realGoodsInterestUser);
  258. } catch (DuplicateKeyException e) {
  259. log.info("重复插入用户相同实物商品记录");
  260. }
  261. });
  262. log.info("实物订单意愿数据同步结束");
  263. }
  264. }
  265. );
  266. Integer update = orderDonService.updateHasPaymentInterestRealGoods();
  267. orderDonService.updateHasPaymentInterestRealGoodsPayTime();
  268. if (update > 0) {
  269. log.info("更新用户记录:{}已购买实物意愿商品状态成功", update);
  270. }
  271. }
  272. /**
  273. * 统计昨日过期账号 分配给客服
  274. */
  275. @Scheduled(cron = "0 30 8 * * ?")
  276. public void assignNeedUpdateExpiredAccount() {
  277. DateTime beginOfDay = DateUtil.beginOfDay(DateTime.now());
  278. String yesTimeSql = String.format("and ur.created_time < '%s'", beginOfDay);
  279. String extra_sql = String.format("(if((select count(distinct relation_id) from user_ticket_cleared_record ur where ur.account_id = a.id and deleted is true and source = 'self' %s)>=5,true,false)) = 1", yesTimeSql);
  280. List<AccountView> accountViews = beanSearcher.searchAll(AccountView.class, MapUtils.builder()
  281. .put("extra_sql", extra_sql)
  282. .field(AccountView::getCustomerServiceId, 0)
  283. .build());
  284. if (accountViews.size() > 0) {
  285. int accountSize = accountViews.size();
  286. log.info("开始给客服分配过期账号,过期账号数量:{}", accountSize);
  287. List<CmsUserVO> customers = beanSearcher.searchAll(CmsUserVO.class, MapUtils.builder().field(CmsUserVO::getRoleNames, "客服").op(Operator.Contain).build());
  288. if (customers.isEmpty()) {
  289. log.info("暂无客服");
  290. return;
  291. }
  292. //分配过期账号
  293. cmsAccountService.assignCustomerAccount(customers, accountViews);
  294. }
  295. }
  296. /**
  297. * 2天前的工单未关闭 直接关闭
  298. */
  299. @Scheduled(cron = "0 10 0 * * ?")
  300. public void closeWorkOrderBeforeTowDays() {
  301. DateTime twoBefore = DateUtil.offsetDay(DateTime.now(), -2);
  302. List<WorkOrder> workOrders = beanSearcher.searchAll(WorkOrder.class, MapUtils.builder()
  303. .field(WorkOrder::getStatus, WorkOrder.Status.waiting.name())
  304. .field(WorkOrder::getCreatedTime, twoBefore).op(Operator.LessEqual)
  305. .onlySelect(WorkOrder::getId)
  306. .build());
  307. if (CollUtil.isNotEmpty(workOrders)) {
  308. List<Long> collect = workOrders.stream().map(WorkOrder::getId).collect(Collectors.toList());
  309. List<List<Long>> lists = Lists.partition(collect, 1000);
  310. log.info("关闭2天前未关闭的工单");
  311. lists.forEach(ids -> {
  312. workOrderMapper.update(null, Wrappers.lambdaUpdate(WorkOrder.class)
  313. .set(WorkOrder::getStatus, WorkOrder.Status.close)
  314. .in(WorkOrder::getId, ids));
  315. });
  316. }
  317. }
  318. /**
  319. * 推广者渠道昨天订单金额是否小于过去7天平均订单金额的一半
  320. * 若小于 则发送短信到对应商务
  321. */
  322. @Scheduled(cron = "0 30 8 * * ?")
  323. public void distributeOrderDetailAndSendMsgToBusiness() {
  324. Integer daysRule = 7;
  325. DateTime thisZero = DateUtil.beginOfDay(DateTime.now());
  326. DateTime yesZero = DateUtil.offsetDay(thisZero, -1);
  327. DateTime thePast7dZero = DateUtil.offsetDay(yesZero, -daysRule);
  328. DateTime twoYesZero = DateUtil.offsetDay(thisZero, -2);
  329. DateTime theTwoPast7dZero = DateUtil.offsetDay(twoYesZero, -daysRule);
  330. //总销量小于1000的 不算、建立天数低于7天的不算、 连续2天销量低于7天平均值的50%的 提醒
  331. List<UserDistributeViews> userDistributeViews = beanSearcher.searchAll(UserDistributeViews.class, MapUtils.builder()
  332. .field(UserDistributeViews::getCreatedTime, thePast7dZero).op(Operator.LessEqual)
  333. .field(UserDistribute::getBusinessId, 0).op(Operator.GreaterThan)
  334. .put("time", String.format("and od.created_time < '%s'", thisZero))
  335. .field(UserDistributeViews::getDistributeOrdersMoney, BigDecimal.valueOf(100000)).op(Operator.GreaterEqual)
  336. .build());
  337. String thePast7dTimeSql = String.format("and od.created_time >= '%s' and od.created_time < '%s'", thePast7dZero, yesZero);
  338. String yesTimeSql = String.format("and od.created_time >= '%s' and od.created_time < '%s'", yesZero, thisZero);
  339. String theTwoPast7dTimeSql = String.format("and od.created_time >= '%s' and od.created_time < '%s'", theTwoPast7dZero, twoYesZero);
  340. String twoYesTimeSql = String.format("and od.created_time >= '%s' and od.created_time < '%s'", twoYesZero, yesZero);
  341. Map<Long, String> phoneMap = new ConcurrentHashMap<>();
  342. userDistributeViews.forEach(data -> {
  343. //昨天过去7天总订单金额
  344. Number yesPastFtMoneySum = beanSearcher.searchSum(UserDistributeViews.class, MapUtils.builder()
  345. .field(UserDistributeViews::getUserId, data.getUserId())
  346. .put("time", thePast7dTimeSql).build(), "distributeOrdersMoney");
  347. //前天过去7天总订单金额
  348. Number towYesPastMoneySum = beanSearcher.searchSum(UserDistributeViews.class, MapUtils.builder()
  349. .field(UserDistributeViews::getUserId, data.getUserId())
  350. .put("time", theTwoPast7dTimeSql).build(), "distributeOrdersMoney");
  351. int theYes7dPastMoney = yesPastFtMoneySum.intValue();
  352. int theTwoYes7dPastMoney = towYesPastMoneySum.intValue();
  353. UserDistributeViews yesDistribute = beanSearcher.searchFirst(UserDistributeViews.class, MapUtils.builder()
  354. .field(UserDistributeViews::getUserId, data.getUserId())
  355. .put("time", yesTimeSql).build());
  356. UserDistributeViews twoYesDistribute = beanSearcher.searchFirst(UserDistributeViews.class, MapUtils.builder()
  357. .field(UserDistributeViews::getUserId, data.getUserId())
  358. .put("time", twoYesTimeSql).build());
  359. BigDecimal yesDistributeOrdersMoney = yesDistribute.getDistributeOrdersMoney();
  360. BigDecimal twoYesDistributeOrdersMoney = twoYesDistribute.getDistributeOrdersMoney();
  361. BigDecimal thePast7dAverage = BigDecimal.valueOf(theYes7dPastMoney).divide(BigDecimal.valueOf(daysRule).multiply(BigDecimal.valueOf(2)), 2, RoundingMode.HALF_DOWN);
  362. BigDecimal theTwoPast7dAverage = BigDecimal.valueOf(theTwoYes7dPastMoney).divide(BigDecimal.valueOf(daysRule).multiply(BigDecimal.valueOf(2)), 2, RoundingMode.HALF_DOWN);
  363. if (yesDistributeOrdersMoney.compareTo(thePast7dAverage) < 0 && twoYesDistributeOrdersMoney.compareTo(theTwoPast7dAverage) < 0) {
  364. User user = userMapper.selectById(data.getUserId());
  365. String msg = String.format(Constant.BUSINESS_CHANNEL_MSG, (user == null ? "用户" : user.getNickname()), data.getUserId());
  366. String phone = phoneMap.get(data.getUserId());
  367. if (StrUtil.isBlank(phone)) {
  368. CmsUser cmsUser = cmsUserMapper.selectById(data.getBusinessId());
  369. if (cmsUser != null) {
  370. phone = cmsUser.getPhone();
  371. phoneMap.putIfAbsent(data.getBusinessId(), phone);
  372. }
  373. }
  374. if (StrUtil.isNotBlank(phone)) {
  375. log.info("商务businessId:{}所下渠道用户id:{}分销数据已低于7天平均值的50%%", data.getBusinessId(), data.getUserId());
  376. //发短信
  377. SmsUtil.sendLuoKey2Msg(phone, msg);
  378. }
  379. return;
  380. }
  381. });
  382. }
  383. @Scheduled(cron = "0 0 0/3 * * ?")
  384. public void accountDoubleVerify() {
  385. //chatGPT PLUS
  386. Long goodsId = 18l;
  387. List<AccountDoubleVerifyRecord> doubleVerifyRecords = groupsMapper.selectGPTDoubleVerifyTrips(goodsId);
  388. doubleVerifyRecords.forEach(data -> {
  389. AccountDoubleVerifyRecord exist = doubleVerifyRecordMapper.selectOne(Wrappers.lambdaQuery(AccountDoubleVerifyRecord.class)
  390. .eq(AccountDoubleVerifyRecord::getAccountId, data.getAccountId())
  391. .eq(AccountDoubleVerifyRecord::getDeleted, true).last("limit 1"));
  392. if (exist == null) {
  393. if (redisService.setNx(String.format("%s-%s", data.getAccountId(), data.getId()), data.getId(), 60l)) {
  394. log.info("插入待开启双重验证号账号:{}", data.getAccount());
  395. data.setRemark("车队满员后三天后自动移入");
  396. doubleVerifyRecordMapper.insert(data);
  397. }
  398. }
  399. });
  400. }
  401. /**
  402. * 每日凌晨下架今日过期车队账号
  403. */
  404. @Scheduled(cron = "0 0 0 * * ?")
  405. public void closeGroupsTrips() {
  406. DateTime now = DateTime.now();
  407. DateTime nextDay = DateUtil.offsetDay(DateUtil.beginOfDay(now), 3);
  408. List<CloseGroupsTripsView> closeGroupsTripsViews = Optional.ofNullable(beanSearcher.searchAll(CloseGroupsTripsView.class, MapUtils.builder()
  409. .field(CloseGroupsTripsView::getExpiryTime, nextDay).op(Operator.LessThan)
  410. .field(CloseGroupsTripsView::getGoodsId, List.of(18, 26)).op(Operator.InList)
  411. .field(CloseGroupsTripsView::getGroupsId).op(Operator.NotNull)
  412. .field(CloseGroupsTripsView::getGroupsStatus, GroupsTrips.Status.down.name()).op(Operator.NotEqual)
  413. .build())).orElse(new ArrayList<>());
  414. log.info("下架过期账号数量:{}", closeGroupsTripsViews.size());
  415. closeGroupsTripsViews.forEach(account -> {
  416. int update = groupsMapper.update(null, Wrappers.lambdaUpdate(GroupsTrips.class)
  417. .set(GroupsTrips::getStatus, GroupsTrips.Status.down)
  418. .ne(GroupsTrips::getStatus, GroupsTrips.Status.down)
  419. .eq(GroupsTrips::getId, account.getGroupsId()));
  420. if (update == 1) {
  421. log.info("将过期账号:{}车队:{}下架", account.getId(), account.getGroupsId());
  422. }
  423. });
  424. }
  425. }