Преглед изворни кода

我的承办定时消息提醒

dzx пре 7 месеци
родитељ
комит
640887c34d

+ 84 - 2
src/main/java/com/xjrsoft/module/job/OfficialDocumentReceivedHandleTask.java

@@ -1,8 +1,20 @@
 package com.xjrsoft.module.job;
 
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
 import com.xjrsoft.common.enums.DeleteMark;
 import com.xjrsoft.common.enums.EnabledMark;
+import com.xjrsoft.common.utils.VoToColumnUtil;
+import com.xjrsoft.module.oa.entity.OfficialDocumentReceived;
+import com.xjrsoft.module.oa.entity.OfficialDocumentReceivedHandle;
 import com.xjrsoft.module.oa.service.IOfficialDocumentReceivedHandleService;
+import com.xjrsoft.module.oa.service.IOfficialDocumentReceivedService;
+import com.xjrsoft.module.organization.dto.WeChatSendMessageDto;
+import com.xjrsoft.module.organization.entity.User;
+import com.xjrsoft.module.organization.service.IUserService;
+import com.xjrsoft.module.organization.service.IWeChatService;
+import com.xjrsoft.module.organization.vo.WeChatPageVO;
 import com.xjrsoft.module.student.dto.EnrollmentStatisticsCalendarInfoDto;
 import com.xjrsoft.module.student.dto.EnrollmentStatisticsGraduationInfoDto;
 import com.xjrsoft.module.student.dto.EnrollmentStatisticsInfoDto;
@@ -12,8 +24,10 @@ import com.xjrsoft.module.student.service.IPbCseFeeobjupdateService;
 import com.xjrsoft.module.student.vo.EnrollmentStatisticsCalendarInfoVo;
 import com.xjrsoft.module.student.vo.EnrollmentStatisticsGraduationInfoVo;
 import com.xjrsoft.module.student.vo.EnrollmentStatisticsInfoVo;
+import com.xjrsoft.module.workflow.entity.WorkflowFormRelation;
 import com.yomahub.liteflow.util.JsonUtil;
 import lombok.extern.slf4j.Slf4j;
+import org.camunda.bpm.engine.history.HistoricProcessInstance;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.scheduling.annotation.Scheduled;
@@ -21,9 +35,13 @@ import org.springframework.stereotype.Component;
 
 import java.time.DayOfWeek;
 import java.time.LocalDate;
+import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.time.temporal.TemporalAdjusters;
 import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * 将招生计划数据固化
@@ -37,15 +55,79 @@ public class OfficialDocumentReceivedHandleTask {
 
 
     @Autowired
-    private IOfficialDocumentReceivedHandleService officialDocumentReceivedHandleService;
+    private IOfficialDocumentReceivedHandleService handleService;
+
+    @Autowired
+    private IUserService userService;
+
+    @Autowired
+    private IOfficialDocumentReceivedService receivedService;
+
+    @Autowired
+    private IWeChatService weChatService;
 
     @Async
-    @Scheduled(cron = "00 0/30 * * * ?")
+    @Scheduled(cron = "00 0/60 * * * ?")
     public void execute() {
         doExecute();
     }
 
     void doExecute() {
+        LocalDateTime now = LocalDateTime.now().withMinute(0).withSecond(0);
+        List<User> list = userService.list(
+                new MPJLambdaWrapper<User>()
+                        .select(User::getId)
+                        .select(User.class, x -> VoToColumnUtil.fieldsToColumns(User.class).contains(x.getProperty()))
+                        .innerJoin(OfficialDocumentReceivedHandle.class, OfficialDocumentReceivedHandle::getCreateUserId, User::getId)
+                        .eq(OfficialDocumentReceivedHandle::getAlertTime, now)
+                        .isNotNull(User::getOpenId)
+        );
+
+        List<OfficialDocumentReceived> documentReceivedList = receivedService.list(
+                new MPJLambdaWrapper<OfficialDocumentReceived>()
+                        .select(OfficialDocumentReceived::getId)
+                        .select(OfficialDocumentReceived.class, x -> VoToColumnUtil.fieldsToColumns(OfficialDocumentReceived.class).contains(x.getProperty()))
+                        .innerJoin(WorkflowFormRelation.class, WorkflowFormRelation::getFormKeyValue, OfficialDocumentReceived::getId)
+                        .eq(WorkflowFormRelation::getCurrentState, HistoricProcessInstance.STATE_COMPLETED)
+        );
+
+        Map<Long, OfficialDocumentReceived> documentReceivedMap = documentReceivedList.stream().collect(Collectors.toMap(OfficialDocumentReceived::getId, x -> x));
+
+        List<OfficialDocumentReceivedHandle> handleList = handleService.list(
+                new QueryWrapper<OfficialDocumentReceivedHandle>().lambda()
+                        .eq(OfficialDocumentReceivedHandle::getAlertTime, now)
+        );
+        Map<Long, List<OfficialDocumentReceivedHandle>> handleGroupMap = handleList.stream().collect(Collectors.groupingBy(OfficialDocumentReceivedHandle::getCreateUserId));
+
+        for (User user : list) {
+            List<OfficialDocumentReceivedHandle> handles = handleGroupMap.get(user.getId());
+            for (OfficialDocumentReceivedHandle handle : handles) {
+                if(handle.getIsHandle() == 1){
+                    continue;
+                }
+                OfficialDocumentReceived received = documentReceivedMap.get(handle.getOfficialDocumentReceivedId());
+
+                WeChatSendMessageDto weChatSendMessageDto = new WeChatSendMessageDto();
+                weChatSendMessageDto.setUserId(user.getOpenId());
+                weChatSendMessageDto.setTemplateId("qmpXORPM1Cocqn503Qa4On6BJhR92UZ00eod2-6IcGo");
+                //weChatSendMessageDto.setUrl(StrUtil.format("{}/pages/message/notice/detail?id={}", commonPropertiesConfig.getDomainApp(), id));
+                weChatSendMessageDto.setMsgId(handle.getId().toString());
+                JSONObject data = new JSONObject();
+
+                JSONObject thing23 = new JSONObject();
+                thing23.put("value", "您有一个行政收文待处理");
+                data.put("thing23", thing23);
+
+                JSONObject data2 = new JSONObject();
+                data2.put("value", user.getName());
+                data.put("thing29", data2);
 
+                JSONObject data3 = new JSONObject();
+                data3.put("value", now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
+                data.put("time17", data3);
+                weChatSendMessageDto.setContent(data);
+                weChatService.sendTemplateMessage(weChatSendMessageDto);
+            }
+        }
     }
 }