guarantee-lsq 2 年之前
父節點
當前提交
901f456a8e

+ 5 - 0
platform-dao/src/main/java/com/platform/dao/vo/query/fill/FillGatherVO.java

@@ -76,4 +76,9 @@ public class FillGatherVO extends BaseVO implements Serializable {
      * 巡检内容项集合
      */
     private List<FillInfo> fillInfos;
+
+    /**
+     * 关联巡检项数目
+     */
+    private Integer countNum;
 }

+ 112 - 0
platform-rest/src/main/java/com/platform/rest/task/FillGatherTaskTask.java

@@ -0,0 +1,112 @@
+package com.platform.rest.task;
+
+import com.platform.common.cache.ConfigCache;
+import com.platform.common.constant.RedisKeyConstants;
+import com.platform.common.util.*;
+import com.platform.dao.entity.fill.FillGather;
+import com.platform.dao.entity.fill.FillGatherTask;
+import com.platform.dao.entity.upms.SysUser;
+import com.platform.dao.enums.FillGatherTaskStatusEnum;
+import com.platform.dao.enums.SysConfigEnum;
+import com.platform.dao.enums.WorkplaceBacklogDetailTypeEnum;
+import com.platform.dao.enums.WorkplaceBacklogTypeEnum;
+import com.platform.dao.mapper.upms.SysUserMapper;
+import com.platform.dao.util.MessageTemplateUtil;
+import com.platform.service.event.WorkplaceBacklogEvent;
+import com.platform.service.fill.FillGatherTaskService;
+import com.platform.service.util.SendMessageUtils;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @Description 点巡检任务处理
+ * @Author liuyu
+ * @Date 2020-05-09 16:40:01
+ * @Version Copyright (c) 2020,北京乾元坤和科技有限公司 All rights reserved.
+ */
+@Slf4j
+@Component("fillGatherTaskTask")
+@AllArgsConstructor
+public class FillGatherTaskTask {
+    private FillGatherTaskService fillGatherTaskService;
+    private SysUserMapper sysUserMapper;
+
+    /**
+     * 定时生成巡检任务
+     */
+    public void generateFillTask () {
+        String nowDateStr = DateUtils.dateToString(LocalDateTime.now(),DateUtils.PATTERN_YMD);
+        // 获取所有点检任务集合
+        List<FillGatherTask> taskList = fillGatherTaskService.selectAll();
+        // 判断是否需要生成新的巡检任务
+        List<FillGatherTask> handleList = validateList(taskList,nowDateStr);
+        // 生成巡检任务
+        for(FillGatherTask task : handleList){
+            FillGatherTask newTask = BeanConverterUtil.copyObjectProperties(task,FillGatherTask.class);
+            newTask.setCreatedTime(LocalDateTime.now());
+            newTask.setId(IdGeneratorUtils.getObjectId());
+            newTask.setStatus(FillGatherTaskStatusEnum.PROCESSING.getValue());
+            newTask.setWaitNum(task.getTotalNum());
+            newTask.setName(task.getName() + "_" + nowDateStr);
+            newTask.setLateHistoryHours(0);
+            fillGatherTaskService.saveModelNoId(newTask);
+            // 3、通知相关人员(巡检人和主管)
+            sendMessageToChecker(newTask,1);
+            sendMessageToChecker(newTask,2);
+            // 4、启动超时监控预警信息
+            int initMin = newTask.getRequireHour()*60;
+            int hours = newTask.getWarningHour() == null ? initMin + 120 : newTask.getWarningHour()*60 + initMin;
+            RedisUtils.setString(RedisKeyConstants.EXPIRE_BUSINESS_KEY_FILL_PREFIX + RedisKeyConstants.EXPIRE_BUSINESS_SEP + task.getId(), task.getId(), hours, TimeUnit.MINUTES);
+        }
+    }
+
+    private List<FillGatherTask> validateList(List<FillGatherTask> list,String nowDateStr){
+        List<FillGatherTask> retList = new ArrayList<>();
+        for(FillGatherTask task : list){
+            LocalDateTime lastCreatedTime = task.getCreatedTime();
+            String targetCreatedTimeStr = DateUtils.dateToString(lastCreatedTime.plusDays(task.getPeriod()),DateUtils.PATTERN_YMD);
+            if(nowDateStr.equals(targetCreatedTimeStr)){
+                retList.add(task);
+            }
+        }
+        return retList;
+    }
+
+    /**
+     * 给巡检人发送消息
+     * @param task
+     * @param type 1 巡检人  2 巡检主管
+     */
+    private void sendMessageToChecker(FillGatherTask task, Integer type){
+        SysUser user = null; // 用户
+        String info = "";  // 站内信内容
+        String[] values = new String[]{"你有一条巡检任务!","请知悉"}; // 默认是巡检人
+        switch (type){
+            case 1 :
+                user = sysUserMapper.selectByPrimaryKey(task.getChecker());
+                info = MessageTemplateUtil.getFillGatherTaskNoticeForChecker(task.getName());
+                break;
+            case 2 :
+                user = sysUserMapper.selectByPrimaryKey(task.getCheckLeader());
+                info = MessageTemplateUtil.getFillGatherTaskNoticeForLeader(task.getName(),user.getRealName());
+                values = new String[]{"你有一条待监管的巡检任务!","请知悉"};
+                break;
+        }
+        // 1、站内信
+        SpringContextHolder.publishEvent(new WorkplaceBacklogEvent(WorkplaceBacklogTypeEnum.FILL_TASK.getValue(), WorkplaceBacklogDetailTypeEnum.FILL_TASK_NOTICE.getValue(),
+                task.getId(), info, task.getId(), ListUtils.newArrayList(user.getUserId()), ListUtils.newArrayList(user.getEmail())));
+        // 2、微信
+        String wechatTemplateId = ConfigCache.getLabelByValueAllowNull(SysConfigEnum.REPAIR_NOTICE_SUCCESS_WECHAT_TEMPLATE_ID.name());
+        String detailUrl = "pages/repair-detail/repair-detail?detailId=" + task.getId();
+        SendMessageUtils.sendWechatNew(ListUtils.newArrayList(user.getWxOpenId()),detailUrl,values,wechatTemplateId);
+        // 3、短信
+        SendMessageUtils.sendCommonSms(ListUtils.newArrayList(user.getPhone()),info);
+    }
+}

+ 2 - 0
platform-service/src/main/java/com/platform/service/fill/FillGatherTaskService.java

@@ -71,4 +71,6 @@ public interface FillGatherTaskService extends IBaseService<FillGatherTask, Fill
      */
     FillGatherTaskVO getVOById(String id);
 
+    List<FillGatherTask> selectAll();
+
                                                                                                                                                                                                                 }

+ 9 - 1
platform-service/src/main/java/com/platform/service/fill/impl/FillGatherServiceImpl.java

@@ -111,7 +111,15 @@ public class FillGatherServiceImpl extends BaseServiceImpl<FillGatherMapper, Fil
     @Override
     public MyVOPage<FillGatherVO> selectPageList(FillGatherDTO record, int pageNum, int pageSize) {
         PageHelper.startPage(pageNum, pageSize);
-        return new MyVOPage<>(mapper.selectList(record));
+        MyVOPage<FillGatherVO> pageInfos = new MyVOPage<>(mapper.selectList(record));
+        // 巡检项目数
+        if(pageInfos.getRows() != null && pageInfos.getRows().size() > 0){
+            for(FillGatherVO vo : pageInfos.getRows()){
+                int countNum = fillGatherInfoMapper.selectCount(new FillGatherInfo().setGatherId(vo.getId()));
+                vo.setCountNum(countNum);
+            }
+        }
+        return pageInfos;
     }
 
 

+ 5 - 0
platform-service/src/main/java/com/platform/service/fill/impl/FillGatherTaskServiceImpl.java

@@ -243,6 +243,11 @@ public class FillGatherTaskServiceImpl extends BaseServiceImpl<FillGatherTaskMap
         return vo;
     }
 
+    @Override
+    public List<FillGatherTask> selectAll() {
+        return mapper.selectAll();
+    }
+
     /**
      * 给巡检人发送消息
      * @param task