|
@@ -0,0 +1,206 @@
|
|
|
+package com.zfire.mall.manager.schedule;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.zfire.mall.manager.bean.trade.TradeLoginCountBean;
|
|
|
+import com.zfire.mall.manager.commonmapper.LoginOrderMapper;
|
|
|
+import com.zfire.mall.manager.enums.OrderTypeEnum;
|
|
|
+import com.zfire.mall.manager.plus.entity.*;
|
|
|
+import com.zfire.mall.manager.plus.service.*;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.*;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
+public class TradeOrder2Schedule {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ TradeLoginOrderService tradeLoginOrderService;
|
|
|
+ @Resource
|
|
|
+ NoticeRecordService noticeRecordService;
|
|
|
+ @Resource
|
|
|
+ AdminUserService adminUserService;
|
|
|
+ @Resource
|
|
|
+ AdminUserWebsitRelaService adminUserWebsitRelaService;
|
|
|
+
|
|
|
+ @Scheduled(cron = "0 0 1 1/1 * ? ")
|
|
|
+// @Scheduled(initialDelay = 5000, fixedDelay = 100 * 1000)
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void sendOrderUpdateSysNoticeTask() {
|
|
|
+ int pageNum = 1;
|
|
|
+ int pageSize = 500;
|
|
|
+ int handleCount = 0;
|
|
|
+
|
|
|
+ log.info("家装提醒更新开始-------------------------------------");
|
|
|
+ List<AdminUser> adminUserList = adminUserService.lambdaQuery()
|
|
|
+ .eq(AdminUser::getStatus, 1)
|
|
|
+ .isNotNull(AdminUser::getCustomerId)
|
|
|
+ .list();
|
|
|
+
|
|
|
+ Map<String, List<AdminUser>> userMap = adminUserList.stream().collect(Collectors.groupingBy(AdminUser::getCustomerId));
|
|
|
+
|
|
|
+ for (int i = 0; i < 100; i++) {
|
|
|
+ IPage<TradeLoginOrder> page = tradeLoginOrderService.lambdaQuery()
|
|
|
+ .select(TradeLoginOrder::getId, TradeLoginOrder::getProjectNo, TradeLoginOrder::getCustomerId,
|
|
|
+ TradeLoginOrder::getCustomerNumber, TradeLoginOrder::getCustomerName,
|
|
|
+ TradeLoginOrder::getSubmitTime, TradeLoginOrder::getConfirmTime, TradeLoginOrder::getUpdateTime)
|
|
|
+ .eq(TradeLoginOrder::getIsSpan, false)
|
|
|
+ .eq(TradeLoginOrder::getOrderType, "HOME")
|
|
|
+ .eq(TradeLoginOrder::getOrderStatus, "OK")
|
|
|
+ .eq(TradeLoginOrder::getLoginStatus, "OK")
|
|
|
+ .eq(TradeLoginOrder::getStatus, "ING")
|
|
|
+ .orderByAsc(TradeLoginOrder::getCustomerId)
|
|
|
+ .page(new Page<>(pageNum, pageSize));
|
|
|
+ if (CollectionUtil.isEmpty(page.getRecords())) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<TradeLoginOrder> orderList = page.getRecords();
|
|
|
+ List<NoticeRecord> noticeRecordList = new ArrayList<>();
|
|
|
+
|
|
|
+ for (TradeLoginOrder order : orderList) {
|
|
|
+ // 格式为日期
|
|
|
+ String formatDate = DateUtil.formatDate(order.getUpdateTime());
|
|
|
+ DateTime tipsDay = DateUtil.offsetDay(DateUtil.parseDate(formatDate), 5);
|
|
|
+ Date curDay = DateUtil.date();
|
|
|
+ if (curDay.getTime() >= tipsDay.getTime()) {
|
|
|
+ List<AdminUser> adminUsers = userMap.get(order.getCustomerId());
|
|
|
+ if (CollectionUtil.isEmpty(adminUsers)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ for (AdminUser adminUser : adminUsers) {
|
|
|
+ AdminUserWebsitRela rela = adminUserWebsitRelaService.lambdaQuery()
|
|
|
+ .eq(AdminUserWebsitRela::getAdminUserId, adminUser.getAdminUserId())
|
|
|
+ .last("limit 1")
|
|
|
+ .one();
|
|
|
+ NoticeRecord noticeRecord = new NoticeRecord();
|
|
|
+ noticeRecord.setId(IdWorker.getIdStr());
|
|
|
+ noticeRecord.setNoticeId(order.getId());
|
|
|
+ noticeRecord.setTitle(order.getProjectNo() + "更新提醒");
|
|
|
+ noticeRecord.setContent("家装" + order.getProjectNo() + "编号, 请更新跟进状态");
|
|
|
+ noticeRecord.setType("提醒更新");
|
|
|
+ noticeRecord.setSource("商用工程家装登录单");
|
|
|
+ noticeRecord.setIssueNickName("系统");
|
|
|
+ noticeRecord.setIssueTime(DateUtil.date());
|
|
|
+ noticeRecord.setAdminWebsitId(Objects.nonNull(rela) ? rela.getAdminWebsitId() : null);
|
|
|
+ noticeRecord.setAdminCompanyId(adminUser.getAdminCompanyId());
|
|
|
+ noticeRecord.setAdminCompanyName(adminUser.getAdminCompanyName());
|
|
|
+ noticeRecord.setAdminUserId(adminUser.getAdminUserId());
|
|
|
+ noticeRecord.setAdminNickName(adminUser.getNickName());
|
|
|
+ noticeRecordList.add(noticeRecord);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (CollectionUtil.isNotEmpty(noticeRecordList)) {
|
|
|
+ noticeRecordService.lambdaUpdate()
|
|
|
+ .in(NoticeRecord::getNoticeId, noticeRecordList.stream().map(NoticeRecord::getId).collect(Collectors.toList()))
|
|
|
+ .eq(NoticeRecord::getIssueNickName, "系统")
|
|
|
+ .remove();
|
|
|
+ noticeRecordService.saveBatch(noticeRecordList);
|
|
|
+ }
|
|
|
+ pageNum++;
|
|
|
+ handleCount = handleCount + noticeRecordList.size();
|
|
|
+ }
|
|
|
+ log.info("已向" + handleCount + "个经销商发送提醒");
|
|
|
+ log.info("家装提醒更新结束-------------------------------------");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Scheduled(cron = "0 0 2 1/1 * ? ")
|
|
|
+// @Scheduled(initialDelay = 5000, fixedDelay = 100 * 1000)
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void sendOrderUpdateSysNoticeTask2() {
|
|
|
+ int pageNum = 1;
|
|
|
+ int pageSize = 500;
|
|
|
+ int handleCount = 0;
|
|
|
+
|
|
|
+ log.info("工装提醒更新开始-------------------------------------");
|
|
|
+ List<AdminUser> adminUserList = adminUserService.lambdaQuery()
|
|
|
+ .eq(AdminUser::getStatus, 1)
|
|
|
+ .isNotNull(AdminUser::getCustomerId)
|
|
|
+ .list();
|
|
|
+
|
|
|
+ Map<String, List<AdminUser>> userMap = adminUserList.stream().collect(Collectors.groupingBy(AdminUser::getCustomerId));
|
|
|
+
|
|
|
+ for (int i = 0; i < 100; i++) {
|
|
|
+ IPage<TradeLoginOrder> page = tradeLoginOrderService.lambdaQuery()
|
|
|
+ .select(TradeLoginOrder::getId, TradeLoginOrder::getProjectNo, TradeLoginOrder::getCustomerId,
|
|
|
+ TradeLoginOrder::getCustomerNumber, TradeLoginOrder::getCustomerName,
|
|
|
+ TradeLoginOrder::getSubmitTime, TradeLoginOrder::getConfirmTime, TradeLoginOrder::getUpdateTime)
|
|
|
+ .eq(TradeLoginOrder::getIsSpan, false)
|
|
|
+ .eq(TradeLoginOrder::getOrderType, "WORK")
|
|
|
+ .eq(TradeLoginOrder::getOrderStatus, "OK")
|
|
|
+ .eq(TradeLoginOrder::getLoginStatus, "OK")
|
|
|
+ .eq(TradeLoginOrder::getStatus, "ING")
|
|
|
+ .orderByAsc(TradeLoginOrder::getCustomerId)
|
|
|
+ .page(new Page<>(pageNum, pageSize));
|
|
|
+ if (CollectionUtil.isEmpty(page.getRecords())) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<TradeLoginOrder> orderList = page.getRecords();
|
|
|
+ List<NoticeRecord> noticeRecordList = new ArrayList<>();
|
|
|
+
|
|
|
+ for (TradeLoginOrder order : orderList) {
|
|
|
+ // 格式为日期
|
|
|
+ String formatDate = DateUtil.formatDate(order.getUpdateTime());
|
|
|
+ DateTime tipsDay = DateUtil.offsetDay(DateUtil.parseDate(formatDate), 90);
|
|
|
+ Date curDay = DateUtil.date();
|
|
|
+ if (curDay.getTime() >= tipsDay.getTime()) {
|
|
|
+ List<AdminUser> adminUsers = userMap.get(order.getCustomerId());
|
|
|
+ if (CollectionUtil.isEmpty(adminUsers)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ for (AdminUser adminUser : adminUsers) {
|
|
|
+ AdminUserWebsitRela rela = adminUserWebsitRelaService.lambdaQuery()
|
|
|
+ .eq(AdminUserWebsitRela::getAdminUserId, adminUser.getAdminUserId())
|
|
|
+ .last("limit 1")
|
|
|
+ .one();
|
|
|
+ NoticeRecord noticeRecord = new NoticeRecord();
|
|
|
+ noticeRecord.setId(IdWorker.getIdStr());
|
|
|
+ noticeRecord.setNoticeId(order.getId());
|
|
|
+ noticeRecord.setTitle(order.getProjectNo() + "更新提醒");
|
|
|
+ noticeRecord.setContent("工装" + order.getProjectNo() + "编号, 请更新跟进状态");
|
|
|
+ noticeRecord.setType("提醒更新");
|
|
|
+ noticeRecord.setSource("商用工程工装登录单");
|
|
|
+ noticeRecord.setIssueNickName("系统");
|
|
|
+ noticeRecord.setIssueTime(DateUtil.date());
|
|
|
+ noticeRecord.setAdminWebsitId(Objects.nonNull(rela) ? rela.getAdminWebsitId() : null);
|
|
|
+ noticeRecord.setAdminCompanyId(adminUser.getAdminCompanyId());
|
|
|
+ noticeRecord.setAdminCompanyName(adminUser.getAdminCompanyName());
|
|
|
+ noticeRecord.setAdminUserId(adminUser.getAdminUserId());
|
|
|
+ noticeRecord.setAdminNickName(adminUser.getNickName());
|
|
|
+ noticeRecordList.add(noticeRecord);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (CollectionUtil.isNotEmpty(noticeRecordList)) {
|
|
|
+ noticeRecordService.lambdaUpdate()
|
|
|
+ .in(NoticeRecord::getNoticeId, noticeRecordList.stream().map(NoticeRecord::getId).collect(Collectors.toList()))
|
|
|
+ .eq(NoticeRecord::getIssueNickName, "系统")
|
|
|
+ .remove();
|
|
|
+ noticeRecordService.saveBatch(noticeRecordList);
|
|
|
+ }
|
|
|
+ pageNum++;
|
|
|
+ handleCount = handleCount + noticeRecordList.size();
|
|
|
+ }
|
|
|
+ log.info("已向" + handleCount + "个经销商发送提醒");
|
|
|
+ log.info("工装提醒更新结束-------------------------------------");
|
|
|
+ }
|
|
|
+}
|