From 485aad735affed28bbc0f221974e55d2b9cd7f46 Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Wed, 10 Jan 2024 09:20:58 +0800 Subject: [PATCH] =?UTF-8?q?#=20=E6=97=A5=E5=B8=B8=E7=BB=B4=E6=8A=A4?= =?UTF-8?q?=E9=80=BE=E6=9C=9F=E9=80=BB=E8=BE=91=E5=88=A4=E6=96=AD=20#=20?= =?UTF-8?q?=E6=97=A5=E5=B8=B8=E7=BB=B4=E6=8A=A4=E4=BB=BB=E5=8A=A1=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E6=83=85=E5=86=B5=E7=BB=9F=E8=AE=A1=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hzims/operational/OperationApplication.java | 9 -- .../scheduled/MaintenanceTaskSchedule.java | 10 ++- .../maintenance/scheduled/TaskOverdueHandler.java | 97 ++++++++++++++-------- .../impl/MaintenanceTaskQueryServiceImpl.java | 3 +- 4 files changed, 72 insertions(+), 47 deletions(-) diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/OperationApplication.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/OperationApplication.java index f17bc99..6a4175c 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/OperationApplication.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/OperationApplication.java @@ -39,15 +39,6 @@ import javax.annotation.Resource; public class OperationApplication extends SpringBootServletInitializer { - static { - System.setProperty("spring.cloud.nacos.discovery.erver-addr", "http://hadoop:8848"); - System.setProperty("spring.cloud.nacos.config.server-addr", "http://hadoop:8848"); - System.setProperty("spring.cloud.nacos.username", "nacos"); - System.setProperty("spring.cloud.nacos.password", "nacos"); - } - - - public static void main(String[] args) { BladeApplication.run(OperationalConstants.APP_NAME, OperationApplication.class, args); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskSchedule.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskSchedule.java index 7a9587b..ac69b88 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskSchedule.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskSchedule.java @@ -27,17 +27,20 @@ import org.springblade.flow.core.entity.BladeFlow; import org.springblade.flow.core.feign.IFlowClient; import org.springblade.system.user.feign.IUserClient; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; +import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; import static com.hnac.hzims.operational.maintenance.constants.ScheduledConstant.TASK_VALUE_MAINTENANCE_TASK_CREATE; +import static com.hnac.hzims.operational.maintenance.scheduled.MaintenanceTaskCreateTask.REMIND_TASK_END_LIST; import static org.springblade.core.tool.utils.DateUtil.PATTERN_DATE; /** @@ -53,6 +56,7 @@ public class MaintenanceTaskSchedule { private final IOperMaintenanceTaskService taskService; private final IFlowClient flowClient; private final IImsDutyMainService dutyMainService; + private final RedisTemplate redisTemplate; //@XxlJob(TASK_VALUE_MAINTENANCE_TASK_CREATE) public ReturnT execute(String param) throws Exception { @@ -137,8 +141,10 @@ public class MaintenanceTaskSchedule { } } // 保存日常维护任务 - taskService.save(task); - this.startProcessInstance(task); + if(taskService.save(task)) { + redisTemplate.opsForZSet().add(REMIND_TASK_END_LIST,task,task.getPlanEndTime().toEpochSecond(ZoneOffset.of("+8"))); + this.startProcessInstance(task); + } } /** diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/TaskOverdueHandler.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/TaskOverdueHandler.java index 51a3022..d581bd3 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/TaskOverdueHandler.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/TaskOverdueHandler.java @@ -42,51 +42,78 @@ public class TaskOverdueHandler { private final IFlowClient flowClient; private final ITicketInfoClient ticketInfoClient; +// @XxlJob(TASK_MAINTENANCE_OVERDUE_HANDLER) +// public ReturnT execute(String param) throws Exception { +// //获取当前时间段 redis内缓存的任务列表 +// Set taskEntitySet = redisTemplate.opsForZSet().rangeByScore(REMIND_TASK_END_LIST,0, LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8"))); +// //XxlJobLogger.log("从redis内取出{}条数据",taskEntitySet.size()); +// if(CollectionUtil.isNotEmpty(taskEntitySet)) { +// ExecutorService executorService = Executors.newSingleThreadExecutor(); +// executorService.execute(()-> { +// taskEntitySet.forEach(operMaintenanceTaskEntity -> { +// OperMaintenanceTaskEntity taskEntity = taskService.getById(operMaintenanceTaskEntity.getId()); +// //如果任务仍在待执行则自动结束 +// if(MaintenanceConstant.TASK_STATUS_5 != taskEntity.getStatus()) { +// XxlJobLogger.log("开始执行id为{}的任务", Optional.ofNullable(operMaintenanceTaskEntity.getId()).orElse(0L)); +// //将任务置为未完成状态 +// LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper(); +// updateWrapper.set(OperMaintenanceTaskEntity::getStatus,MaintenanceConstant.TASK_STATUS_6); +// updateWrapper.set(OperMaintenanceTaskEntity::getDelayStatus,true); +// updateWrapper.eq(OperMaintenanceTaskEntity::getId,operMaintenanceTaskEntity.getId()); +// taskService.update(updateWrapper); +// //若该任务已领用 则终止工作流 +// if(Func.isNotEmpty(taskEntity.getProcessInstanceId())){ +// R delFlowResult = flowClient.delProcessInstanceById(taskEntity.getProcessInstanceId(),"该日常维护任务已逾期,删除工作流"); +// if(!delFlowResult.isSuccess()){ +// XxlJobLogger.log(delFlowResult.getMsg()); +// throw new ServiceException(delFlowResult.getMsg()); +// } +// } +// //若该任务开了工作票,则更新工作票状态;终止工作流 +// if(Func.isNotEmpty(taskEntity.getTicketId())){ +// XxlJobLogger.log("开始处理逾期工作票"); +// R ticketSaveResult = ticketInfoClient.updateUndoneStatus(taskEntity.getTicketId()); +// if(!ticketSaveResult.isSuccess()){ +// XxlJobLogger.log("处理逾期工作票失败"); +// throw new ServiceException(ticketSaveResult.getMsg()); +// } +// } +// redisTemplate.opsForZSet().remove(REMIND_TASK_END_LIST,operMaintenanceTaskEntity); +// } +// }); +// }); +// executorService.shutdown(); +// } +// else { +// XxlJobLogger.log("无提醒任务!"); +// } +// +// return new ReturnT<>("SUCCESS"); +// } + @XxlJob(TASK_MAINTENANCE_OVERDUE_HANDLER) public ReturnT execute(String param) throws Exception { //获取当前时间段 redis内缓存的任务列表 Set taskEntitySet = redisTemplate.opsForZSet().rangeByScore(REMIND_TASK_END_LIST,0, LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8"))); - //XxlJobLogger.log("从redis内取出{}条数据",taskEntitySet.size()); + XxlJobLogger.log("从redis内取出{}条数据",taskEntitySet.size()); if(CollectionUtil.isNotEmpty(taskEntitySet)) { - ExecutorService executorService = Executors.newSingleThreadExecutor(); - executorService.execute(()-> { - taskEntitySet.forEach(operMaintenanceTaskEntity -> { - OperMaintenanceTaskEntity taskEntity = taskService.getById(operMaintenanceTaskEntity.getId()); - //如果任务仍在待执行则自动结束 - if(MaintenanceConstant.TASK_STATUS_5 != taskEntity.getStatus()) { - XxlJobLogger.log("开始执行id为{}的任务", Optional.ofNullable(operMaintenanceTaskEntity.getId()).orElse(0L)); - //将任务置为未完成状态 - LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper(); - updateWrapper.set(OperMaintenanceTaskEntity::getStatus,MaintenanceConstant.TASK_STATUS_6); - updateWrapper.eq(OperMaintenanceTaskEntity::getId,operMaintenanceTaskEntity.getId()); - taskService.update(updateWrapper); - //若该任务已领用 则终止工作流 - if(Func.isNotEmpty(taskEntity.getProcessInstanceId())){ - R delFlowResult = flowClient.delProcessInstanceById(taskEntity.getProcessInstanceId(),"该日常维护任务已逾期,删除工作流"); - if(!delFlowResult.isSuccess()){ - XxlJobLogger.log(delFlowResult.getMsg()); - throw new ServiceException(delFlowResult.getMsg()); - } - } - //若该任务开了工作票,则更新工作票状态;终止工作流 - if(Func.isNotEmpty(taskEntity.getTicketId())){ - XxlJobLogger.log("开始处理逾期工作票"); - R ticketSaveResult = ticketInfoClient.updateUndoneStatus(taskEntity.getTicketId()); - if(!ticketSaveResult.isSuccess()){ - XxlJobLogger.log("处理逾期工作票失败"); - throw new ServiceException(ticketSaveResult.getMsg()); - } - } - redisTemplate.opsForZSet().remove(REMIND_TASK_END_LIST,operMaintenanceTaskEntity); - } - }); + taskEntitySet.forEach(operMaintenanceTaskEntity -> { + OperMaintenanceTaskEntity taskEntity = taskService.getById(operMaintenanceTaskEntity.getId()); + //如果任务仍在待执行则自动结束 + if(!"结束".equals(taskEntity.getFlowTaskName())) { + XxlJobLogger.log("开始执行id为{}的任务", Optional.ofNullable(operMaintenanceTaskEntity.getId()).orElse(0L)); + //将任务置为未完成状态 + LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper(); + updateWrapper.set(OperMaintenanceTaskEntity::getDelayStatus,true); + updateWrapper.eq(OperMaintenanceTaskEntity::getId,operMaintenanceTaskEntity.getId()); + taskService.update(updateWrapper); + redisTemplate.opsForZSet().remove(REMIND_TASK_END_LIST,operMaintenanceTaskEntity); + } }); - executorService.shutdown(); } else { XxlJobLogger.log("无提醒任务!"); } - return new ReturnT<>("SUCCESS"); } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/MaintenanceTaskQueryServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/MaintenanceTaskQueryServiceImpl.java index d04c9e3..ec533e2 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/MaintenanceTaskQueryServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/MaintenanceTaskQueryServiceImpl.java @@ -12,6 +12,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.google.common.collect.Lists; import com.hnac.hzims.equipment.entity.EmInfoEntity; import com.hnac.hzims.equipment.feign.IEmInfoClient; +import com.hnac.hzims.operational.maintenance.constants.DictConstant; import com.hnac.hzims.operational.maintenance.entity.OperMaintenanceTaskEntity; import com.hnac.hzims.operational.maintenance.service.IMaintenanceTaskQueryService; import com.hnac.hzims.operational.maintenance.service.IOperMaintenanceTaskService; @@ -120,7 +121,7 @@ public class MaintenanceTaskQueryServiceImpl implements IMaintenanceTaskQuerySer dept -> dept.getId().equals(task.getCreateDept()) ).findFirst().map(Dept::getDeptName).orElse("")); // 获取维护类型 - result.setTypeName(DictCache.getValue("typeCode",task.getTypeCode())); + result.setTypeName(DictCache.getValue(DictConstant.MAINTENANCE_TYPE_CODE,task.getTypeCode())); // 获取维护设备 result.setEmName(emList.stream().filter( em -> em.getNumber().equals(task.getEmCode())