Scheduler.java 25 KB

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