feat(module): 新增巡检任务提醒功能
- 在 IInspectionTaskService 接口中添加 getInspectionTaskList 方法 - 在 InspectionTaskServiceImpl 中实现 getInspectionTaskList 方法,获取巡检任务列表 - 在 TaskRemindJob 中添加巡检任务提醒逻辑,定时推送巡检消息 - 更新 application-dev.yml 和 application-prod.yml,启用定时任务自动启动
正在显示
6 个修改的文件
包含
151 行增加
和
4 行删除
... | @@ -27,7 +27,7 @@ spring: | ... | @@ -27,7 +27,7 @@ spring: |
27 | misfireThreshold: 60000 | 27 | misfireThreshold: 60000 |
28 | job-store-type: jdbc | 28 | job-store-type: jdbc |
29 | #决定当前服务定时是否启用 | 29 | #决定当前服务定时是否启用 |
30 | auto-startup: false | 30 | auto-startup: true |
31 | #json 时间戳统一转换 | 31 | #json 时间戳统一转换 |
32 | jackson: | 32 | jackson: |
33 | date-format: yyyy-MM-dd HH:mm:ss | 33 | date-format: yyyy-MM-dd HH:mm:ss |
... | @@ -86,7 +86,7 @@ spring: | ... | @@ -86,7 +86,7 @@ spring: |
86 | # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙 | 86 | # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙 |
87 | filters: stat,wall,slf4j | 87 | filters: stat,wall,slf4j |
88 | # 通过connectProperties属性来打开mergeSql功能;慢SQL记录 | 88 | # 通过connectProperties属性来打开mergeSql功能;慢SQL记录 |
89 | connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000 | 89 | connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 |
90 | datasource: | 90 | datasource: |
91 | master: | 91 | master: |
92 | url: jdbc:mysql://47.104.179.187:6003/sk-zhongye?characterEncoding=UTF-8&useUnicode=true&useSSL=false | 92 | url: jdbc:mysql://47.104.179.187:6003/sk-zhongye?characterEncoding=UTF-8&useUnicode=true&useSSL=false |
... | @@ -133,7 +133,7 @@ mybatis-plus: | ... | @@ -133,7 +133,7 @@ mybatis-plus: |
133 | configuration: | 133 | configuration: |
134 | call-setters-on-nulls: true | 134 | call-setters-on-nulls: true |
135 | # 这个配置会将执行的sql打印出来,在开发或测试的时候可以用 | 135 | # 这个配置会将执行的sql打印出来,在开发或测试的时候可以用 |
136 | #log-impl: org.apache.ibatis.logging.stdout.StdOutImpl | 136 | log-impl: org.apache.ibatis.logging.stdout.StdOutImpl |
137 | #数矿专用配置 | 137 | #数矿专用配置 |
138 | skua: | 138 | skua: |
139 | web-url: http://103.85.171.27:8096 | 139 | web-url: http://103.85.171.27:8096 | ... | ... |
... | @@ -27,7 +27,7 @@ spring: | ... | @@ -27,7 +27,7 @@ spring: |
27 | misfireThreshold: 60000 | 27 | misfireThreshold: 60000 |
28 | job-store-type: jdbc | 28 | job-store-type: jdbc |
29 | #决定当前服务定时是否启用 | 29 | #决定当前服务定时是否启用 |
30 | auto-startup: false | 30 | auto-startup: true |
31 | #json 时间戳统一转换 | 31 | #json 时间戳统一转换 |
32 | jackson: | 32 | jackson: |
33 | date-format: yyyy-MM-dd HH:mm:ss | 33 | date-format: yyyy-MM-dd HH:mm:ss | ... | ... |
... | @@ -27,6 +27,12 @@ | ... | @@ -27,6 +27,12 @@ |
27 | <groupId>org.springframework</groupId> | 27 | <groupId>org.springframework</groupId> |
28 | <artifactId>spring-test</artifactId> | 28 | <artifactId>spring-test</artifactId> |
29 | </dependency> | 29 | </dependency> |
30 | <dependency> | ||
31 | <groupId>org.jeecgframework.boot</groupId> | ||
32 | <artifactId>sk-module-inspection</artifactId> | ||
33 | <version>1.0.0</version> | ||
34 | <scope>compile</scope> | ||
35 | </dependency> | ||
30 | </dependencies> | 36 | </dependencies> |
31 | 37 | ||
32 | 38 | ... | ... |
1 | package com.skua.modules.equipment.quartz; | 1 | package com.skua.modules.equipment.quartz; |
2 | 2 | ||
3 | import com.alibaba.fastjson.JSONObject; | ||
4 | import com.skua.core.util.ConvertUtils; | ||
3 | import com.skua.core.util.push.MessageEntity; | 5 | import com.skua.core.util.push.MessageEntity; |
4 | import com.skua.modules.equipment.service.IEquipmentMaintainTaskService; | 6 | import com.skua.modules.equipment.service.IEquipmentMaintainTaskService; |
7 | import com.skua.modules.inspection.service.IInspectionTaskService; | ||
8 | import com.skua.modules.system.entity.SysUser; | ||
9 | import com.skua.modules.system.service.ISysUserService; | ||
5 | import com.skua.modules.system.service.WebNoticePushServiceExt; | 10 | import com.skua.modules.system.service.WebNoticePushServiceExt; |
11 | import com.skua.modules.system.service.impl.SysUserServiceImpl; | ||
6 | import lombok.extern.slf4j.Slf4j; | 12 | import lombok.extern.slf4j.Slf4j; |
7 | import org.quartz.Job; | 13 | import org.quartz.Job; |
8 | import org.quartz.JobExecutionContext; | 14 | import org.quartz.JobExecutionContext; |
... | @@ -14,6 +20,7 @@ import java.time.LocalDateTime; | ... | @@ -14,6 +20,7 @@ import java.time.LocalDateTime; |
14 | import java.time.format.DateTimeFormatter; | 20 | import java.time.format.DateTimeFormatter; |
15 | import java.time.temporal.ChronoUnit; | 21 | import java.time.temporal.ChronoUnit; |
16 | import java.util.ArrayList; | 22 | import java.util.ArrayList; |
23 | import java.util.HashMap; | ||
17 | import java.util.List; | 24 | import java.util.List; |
18 | import java.util.Map; | 25 | import java.util.Map; |
19 | 26 | ||
... | @@ -33,6 +40,11 @@ public class TaskRemindJob implements Job { | ... | @@ -33,6 +40,11 @@ public class TaskRemindJob implements Job { |
33 | @Autowired | 40 | @Autowired |
34 | private WebNoticePushServiceExt webNoticePushServiceExt; | 41 | private WebNoticePushServiceExt webNoticePushServiceExt; |
35 | 42 | ||
43 | @Autowired | ||
44 | private IInspectionTaskService inspectionTaskService; | ||
45 | @Autowired | ||
46 | private ISysUserService sysUserService; | ||
47 | |||
36 | @Override | 48 | @Override |
37 | public void execute(JobExecutionContext context) throws JobExecutionException { | 49 | public void execute(JobExecutionContext context) throws JobExecutionException { |
38 | log.info("人员任务提醒定时任务开始"); | 50 | log.info("人员任务提醒定时任务开始"); |
... | @@ -46,10 +58,42 @@ public class TaskRemindJob implements Job { | ... | @@ -46,10 +58,42 @@ public class TaskRemindJob implements Job { |
46 | List<Map<String, Object>> wbList = getWbList(startTime,endTime); | 58 | List<Map<String, Object>> wbList = getWbList(startTime,endTime); |
47 | //推送维保消息 | 59 | //推送维保消息 |
48 | pushWbMessage(wbList); | 60 | pushWbMessage(wbList); |
61 | //巡检记录 | ||
62 | List<JSONObject> inspectionTaskList = inspectionTaskService.getInspectionTaskList(); | ||
63 | //推送巡检消息 | ||
64 | pushInspectionMessage(inspectionTaskList); | ||
49 | 65 | ||
50 | log.info("人员任务提醒定时任务结束"); | 66 | log.info("人员任务提醒定时任务结束"); |
51 | } | 67 | } |
52 | 68 | ||
69 | private boolean pushInspectionMessage(List<JSONObject> inspectionTaskList) { | ||
70 | List<SysUser> userList = sysUserService.list(); | ||
71 | Map<String,String> cidMap = new HashMap<>(); | ||
72 | for (SysUser sysUser : userList) { | ||
73 | if(ConvertUtils.isNotEmpty(sysUser.getCid())){ | ||
74 | cidMap.put(sysUser.getId(), sysUser.getCid()); | ||
75 | } | ||
76 | } | ||
77 | for (JSONObject inspectionTask : inspectionTaskList){ | ||
78 | //获取用户列表后做消息推送 | ||
79 | List<String> userIds = new ArrayList<>(); | ||
80 | userIds.add(inspectionTask.get("taskStartUser").toString()); | ||
81 | if(cidMap.get(inspectionTask.get("taskStartUser").toString()) != null){ | ||
82 | List<String> userCIds = new ArrayList<>(); | ||
83 | userCIds.add(cidMap.get(inspectionTask.get("taskStartUser").toString())); | ||
84 | MessageEntity messageEntity = new MessageEntity(); | ||
85 | messageEntity.setMessageTitle("任务提醒消息"); | ||
86 | messageEntity.setMessageBody("您有一条【" + inspectionTask.get("planName") + "】巡检任务需要完成,请及时处理"); | ||
87 | messageEntity.setReceiveUser(userIds); | ||
88 | messageEntity.setReceiveUserCid(userCIds); | ||
89 | messageEntity.setSendUser("系统"); | ||
90 | messageEntity.setForwardTag("2"); | ||
91 | webNoticePushServiceExt.pushMessage(messageEntity, "inspection", "M"); | ||
92 | } | ||
93 | } | ||
94 | return true; | ||
95 | } | ||
96 | |||
53 | private boolean pushWbMessage(List<Map<String, Object>> wbList) { | 97 | private boolean pushWbMessage(List<Map<String, Object>> wbList) { |
54 | for (Map<String, Object> wbMap : wbList) { | 98 | for (Map<String, Object> wbMap : wbList) { |
55 | //获取用户列表后做消息推送 | 99 | //获取用户列表后做消息推送 | ... | ... |
... | @@ -41,4 +41,6 @@ public interface IInspectionTaskService extends IService<InspectionTask> { | ... | @@ -41,4 +41,6 @@ public interface IInspectionTaskService extends IService<InspectionTask> { |
41 | IPage<InspectionTask> getPage(Page<InspectionTask> page, InspectionTaskVO inspectionTaskVO); | 41 | IPage<InspectionTask> getPage(Page<InspectionTask> page, InspectionTaskVO inspectionTaskVO); |
42 | 42 | ||
43 | List<String> getIsExceptionInspectionTask(QueryWrapper isExceptionQueryWrapper); | 43 | List<String> getIsExceptionInspectionTask(QueryWrapper isExceptionQueryWrapper); |
44 | |||
45 | List<JSONObject> getInspectionTaskList(); | ||
44 | } | 46 | } | ... | ... |
... | @@ -935,4 +935,99 @@ public class InspectionTaskServiceImpl extends ServiceImpl<InspectionTaskMapper, | ... | @@ -935,4 +935,99 @@ public class InspectionTaskServiceImpl extends ServiceImpl<InspectionTaskMapper, |
935 | 935 | ||
936 | } | 936 | } |
937 | 937 | ||
938 | @Override | ||
939 | public List<JSONObject> getInspectionTaskList() { | ||
940 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | ||
941 | //根据班组ID集合,得到班组对应的所有巡检计划 | ||
942 | QueryWrapper<InspectionPlan> inspectionPlanQueryWrapper = new QueryWrapper<>(); | ||
943 | inspectionPlanQueryWrapper.eq("del_flag", "0"); | ||
944 | List<InspectionPlan> inspectionPlanList = inspectionPlanService.list(inspectionPlanQueryWrapper); | ||
945 | List<InspectionTaskVO> inspectionTaskVOList = new ArrayList<>(); | ||
946 | InspectionTaskVO inspectionTaskVO = null; | ||
947 | for (InspectionPlan inspectionPlan : inspectionPlanList) { | ||
948 | inspectionTaskVO = new InspectionTaskVO(); | ||
949 | try { | ||
950 | // 获取当前时间并加上一小时 | ||
951 | Calendar calendar = Calendar.getInstance(); | ||
952 | calendar.setTime(new Date()); | ||
953 | Date afterDate = calendar.getTime(); | ||
954 | calendar.add(Calendar.HOUR_OF_DAY, 1); | ||
955 | Date nowDate = sdf.parse(sdf.format(new Date())); | ||
956 | //判断当天的开始时间 | ||
957 | String startTime = new SimpleDateFormat("yyyy-MM-dd").format(inspectionPlan.getPlanStartDate()) + " " + inspectionPlan.getPlanTaskStartTime() + ":00"; | ||
958 | String endTime = new SimpleDateFormat("yyyy-MM-dd").format(inspectionPlan.getPlanEndDate()) + " " + "23:59:59"; | ||
959 | //判断当前时间是否在巡检计划的有效时间 sdf.parse(startTime) nowDate afterDate | ||
960 | if (isEffectiveDate(sdf.parse(startTime), nowDate, afterDate)) { | ||
961 | //根据持续时长、计划开始时间和计划结束时间,得到巡检时间的时间段分组 | ||
962 | List<String[]> cycleList = new ArrayList<>(); | ||
963 | if (StringUtils.isNotBlank(inspectionPlan.getContinueTime()) && Double.parseDouble(inspectionPlan.getContinueTime()) != 0) { | ||
964 | cycleList = getCycleList(Integer.parseInt(inspectionPlan.getContinueTime()), startTime, endTime); | ||
965 | } | ||
966 | //根据当前时间得到该时间所属的时间段 | ||
967 | SimpleDateFormat taskSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); | ||
968 | String nowTaskTime = taskSimpleDateFormat.format(new Date()); | ||
969 | //当前时间段对应的巡检周期 | ||
970 | String[] nowPlanTaskDateArr = null; | ||
971 | int inspectionCycleIndex = 0; | ||
972 | for (String[] cycleArr : cycleList) { | ||
973 | inspectionCycleIndex++; | ||
974 | if (isEffectiveDate(taskSimpleDateFormat.parse(nowTaskTime), taskSimpleDateFormat.parse(cycleArr[0]), taskSimpleDateFormat.parse(cycleArr[1]))) { | ||
975 | nowPlanTaskDateArr = cycleArr; | ||
976 | break; | ||
977 | } | ||
978 | } | ||
979 | //如果不设置时间间隔 | ||
980 | if (nowPlanTaskDateArr == null){ | ||
981 | nowPlanTaskDateArr = new String[2]; | ||
982 | nowPlanTaskDateArr[0] = startTime; | ||
983 | nowPlanTaskDateArr[1] = endTime; | ||
984 | } | ||
985 | //通过巡检计划ID,得到该计划的上一次任务执行时间 | ||
986 | QueryWrapper<InspectionTask> inspectionTaskQueryWrapper = new QueryWrapper<>(); | ||
987 | inspectionTaskQueryWrapper.eq("inspection_plan_id", inspectionPlan.getId()); | ||
988 | inspectionTaskQueryWrapper.orderByDesc("task_start_time"); | ||
989 | inspectionTaskQueryWrapper.ne("task_state","3"); | ||
990 | inspectionTaskQueryWrapper.last("limit 1"); | ||
991 | InspectionTaskVO lastInspectionTaskVO = getTaskByInspectionPlanId(inspectionTaskQueryWrapper); | ||
992 | //判断该计划的上次任务开始周期和当前日期的是否相同 | ||
993 | if (lastInspectionTaskVO != null && | ||
994 | isEffectiveDate(taskSimpleDateFormat.parse(taskSimpleDateFormat.format(lastInspectionTaskVO.getTaskStartTime())), taskSimpleDateFormat.parse(nowPlanTaskDateArr[0]), taskSimpleDateFormat.parse(nowPlanTaskDateArr[1]))) { | ||
995 | |||
996 | inspectionTaskVOList.add(lastInspectionTaskVO); | ||
997 | continue; | ||
998 | } | ||
999 | if (inspectionPlan.getDelFlag() == 1) { | ||
1000 | continue; | ||
1001 | } | ||
1002 | //如果计划为单次常规任务,并且上次任务状态为完成,则不在需要显示该任务 | ||
1003 | if ("2".equals(inspectionPlan.getTaskType()) && lastInspectionTaskVO != null && "2".equals(lastInspectionTaskVO.getTaskState())) { | ||
1004 | continue; | ||
1005 | } | ||
1006 | inspectionTaskVO.setId(""); | ||
1007 | inspectionTaskVO.setPlanName(inspectionPlan.getPlanName()); | ||
1008 | inspectionTaskVO.setInspectionPlanId(inspectionPlan.getId()); | ||
1009 | inspectionTaskVO.setTaskState("0"); | ||
1010 | if (nowPlanTaskDateArr != null) { | ||
1011 | inspectionTaskVO.setInspectionCycleStartDate(taskSimpleDateFormat.parse(nowPlanTaskDateArr[0])); | ||
1012 | } | ||
1013 | inspectionTaskVO.setTaskDuration(inspectionPlan.getTaskDuration()); | ||
1014 | inspectionTaskVO.setDepartId(inspectionPlan.getDepartId()); | ||
1015 | inspectionTaskVO.setInspectionWorkingGroupId(inspectionPlan.getInspectionWorkingGroupId()); | ||
1016 | inspectionTaskVO.setTaskType(inspectionPlan.getTaskType()); | ||
1017 | inspectionTaskVO.setInspectionCycleIndex(inspectionCycleIndex); | ||
1018 | inspectionTaskVO.setPlanStartDate(inspectionPlan.getPlanStartDate()); | ||
1019 | inspectionTaskVO.setPlanEndDate(inspectionPlan.getPlanEndDate()); | ||
1020 | inspectionTaskVO.setPlanTaskStartTime(inspectionPlan.getPlanTaskStartTime()); | ||
1021 | inspectionTaskVO.setContinueTime(inspectionPlan.getContinueTime()); | ||
1022 | inspectionTaskVOList.add(inspectionTaskVO); | ||
1023 | } | ||
1024 | }catch(Exception e){ | ||
1025 | e.printStackTrace(); | ||
1026 | continue; | ||
1027 | } | ||
1028 | } | ||
1029 | List<JSONObject> jsonObjectList = sysDictService.translateListDictValue(inspectionTaskVOList); | ||
1030 | return jsonObjectList; | ||
1031 | } | ||
1032 | |||
938 | } | 1033 | } | ... | ... |
-
请 注册 或 登录 后发表评论