From 57784d9eb705eb591638f9d810c1cd8479af6104 Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Wed, 17 Apr 2024 15:28:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E6=97=A5=E5=B8=B8=E7=BB=B4=E6=8A=A4?= =?UTF-8?q?=E9=80=BE=E6=9C=9F=E5=88=A4=E5=AE=9A=E5=AE=9A=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1bug=E8=A7=A3=E5=86=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scheduled/MaintenanceTaskRemindHandler.java | 2 +- .../service/impl/MaintenanceServiceImpl.java | 47 +++++++--------------- 2 files changed, 15 insertions(+), 34 deletions(-) diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskRemindHandler.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskRemindHandler.java index 60c442d..534545f 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskRemindHandler.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskRemindHandler.java @@ -56,7 +56,7 @@ public class MaintenanceTaskRemindHandler { XxlJobLogger.log("开始执行id为{}的任务", Optional.ofNullable(operMaintenanceTaskEntity.getId()).orElse(0L)); //日常维护任务到期消息提醒,提醒对象:执行人、项目经理角色 取出 this.sendMessage(taskEntity); - redisTemplate.opsForZSet().remove(RedisKeyConstants.MAINTENANCE_TASK_DELAY_LIST,operMaintenanceTaskEntity); + redisTemplate.opsForZSet().remove(RedisKeyConstants.REMIND_TASK_END_LIST,operMaintenanceTaskEntity); } }); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/MaintenanceServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/MaintenanceServiceImpl.java index 2fb3d98..bc4c8a3 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/MaintenanceServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/MaintenanceServiceImpl.java @@ -1,5 +1,6 @@ package com.hnac.hzims.operational.maintenance.service.impl; +import cn.hutool.core.stream.CollectorUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; @@ -18,6 +19,7 @@ import com.hnac.hzims.operational.duty.entity.ImsDutyMainEntity; import com.hnac.hzims.operational.duty.service.IImsDutyMainService; import com.hnac.hzims.operational.maintenance.entity.OperMaintenancePlanEntity; import com.hnac.hzims.operational.maintenance.entity.OperMaintenanceTaskEntity; +import com.hnac.hzims.operational.maintenance.scheduled.MaintenanceTaskSchedule; import com.hnac.hzims.operational.maintenance.service.IOperMaintenancePlanService; import com.hnac.hzims.operational.maintenance.service.IOperMaintenanceTaskService; import com.hnac.hzims.operational.maintenance.service.MaintenanceService; @@ -40,11 +42,9 @@ import org.springframework.beans.BeanUtils; import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.Assert; -import java.time.Instant; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.ZoneId; +import java.time.*; import java.time.format.DateTimeFormatter; import java.util.*; import java.util.concurrent.ThreadPoolExecutor; @@ -72,12 +72,9 @@ public class MaintenanceServiceImpl implements MaintenanceService { private final List templateService; private final IFlowClient flowClient; private final ISysClient sysClient; - + private final MaintenanceTaskSchedule taskSchedule; private final ThreadPoolExecutor executor; - - private final DataSourceTransactionManager dataSourceTransactionManager; - /** * 日常维护生成任务 * @@ -87,33 +84,16 @@ public class MaintenanceServiceImpl implements MaintenanceService { // @Transactional(rollbackFor = Exception.class) public void createTask(List ids) { try { - //获取日常维护计划 - LambdaQueryWrapper planEntityLambdaQueryWrapper = new LambdaQueryWrapper<>(); - planEntityLambdaQueryWrapper.in(BaseEntity::getId, ids); - List planEntities = maintenancePlanService.list(planEntityLambdaQueryWrapper); - //筛选当月没生成任务的计划 - List finalPlanEntities = planEntities.stream(). - filter(planEntity -> ObjectUtil.isEmpty(planEntity.getCreateTaskTime()) || - !DateUtil.judgeSameDay(DateUtil.DateToLocalDateTime(planEntity.getCreateTaskTime()), LocalDate.now())) + LambdaQueryWrapper wrapper = Wrappers.lambdaQuery() + .in(OperMaintenancePlanEntity::getId, ids); + List planList = maintenancePlanService.list(wrapper); + LocalDateTime minDate = LocalDateTime.of(LocalDate.now(), LocalTime.MIN); + List generatePlanList = planList.stream().filter(plan -> Func.isEmpty(plan.getCreateTaskTime()) || minDate.isAfter(DateUtil.DateToLocalDateTime(plan.getCreateTaskTime()))) .collect(Collectors.toList()); - if (CollectionUtil.isEmpty(finalPlanEntities)) { + Assert.isTrue(CollectionUtil.isNotEmpty(generatePlanList), () -> { throw new ServiceException("所选计划当天已生成任务"); - } - for (OperMaintenancePlanEntity finalPlanEntity : finalPlanEntities) { - // 通过计划生成任务 - Boolean taskByPlan = this.createTaskByPlan(finalPlanEntity); - if (taskByPlan) { - //更新任务派发时间 - LambdaUpdateWrapper planEntityLambdaUpdateWrapper = new LambdaUpdateWrapper<>(); - planEntityLambdaUpdateWrapper.set(OperMaintenancePlanEntity::getCreateTaskTime, new Date()); - planEntityLambdaUpdateWrapper.eq(OperMaintenancePlanEntity::getId, finalPlanEntity.getId()); - boolean update = maintenancePlanService.update(planEntityLambdaUpdateWrapper); - if (!update) { - log.error("maintenance:generateTask 更新任务派发失败"); - throw new ServiceException("更新任务派发失败"); - } - } - } + }); + generatePlanList.forEach(plan -> taskSchedule.generateTaskByPlan(plan)); } catch (Exception e) { e.printStackTrace(); } @@ -316,6 +296,7 @@ public class MaintenanceServiceImpl implements MaintenanceService { * @param finalPlanEntity */ @Override + @Deprecated // @Transactional(rollbackFor = Exception.class) public Long fillTask(OperMaintenanceTaskEntity taskEntity, OperMaintenancePlanEntity finalPlanEntity, Boolean flag) { // DefaultTransactionDefinition = new DefaultTransactionDefinition();