Scheduler.java 27 KB

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