Browse Source

fix:日常维护逾期判定定时任务bug解决

zhongwei
haungxing 9 months ago
parent
commit
57784d9eb7
  1. 2
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskRemindHandler.java
  2. 47
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/MaintenanceServiceImpl.java

2
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)); XxlJobLogger.log("开始执行id为{}的任务", Optional.ofNullable(operMaintenanceTaskEntity.getId()).orElse(0L));
//日常维护任务到期消息提醒,提醒对象:执行人、项目经理角色 取出 //日常维护任务到期消息提醒,提醒对象:执行人、项目经理角色 取出
this.sendMessage(taskEntity); this.sendMessage(taskEntity);
redisTemplate.opsForZSet().remove(RedisKeyConstants.MAINTENANCE_TASK_DELAY_LIST,operMaintenanceTaskEntity); redisTemplate.opsForZSet().remove(RedisKeyConstants.REMIND_TASK_END_LIST,operMaintenanceTaskEntity);
} }
}); });
} }

47
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; package com.hnac.hzims.operational.maintenance.service.impl;
import cn.hutool.core.stream.CollectorUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference; 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.duty.service.IImsDutyMainService;
import com.hnac.hzims.operational.maintenance.entity.OperMaintenancePlanEntity; import com.hnac.hzims.operational.maintenance.entity.OperMaintenancePlanEntity;
import com.hnac.hzims.operational.maintenance.entity.OperMaintenanceTaskEntity; 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.IOperMaintenancePlanService;
import com.hnac.hzims.operational.maintenance.service.IOperMaintenanceTaskService; import com.hnac.hzims.operational.maintenance.service.IOperMaintenanceTaskService;
import com.hnac.hzims.operational.maintenance.service.MaintenanceService; 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.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import java.time.Instant; import java.time.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
@ -72,12 +72,9 @@ public class MaintenanceServiceImpl implements MaintenanceService {
private final List<TemplateService> templateService; private final List<TemplateService> templateService;
private final IFlowClient flowClient; private final IFlowClient flowClient;
private final ISysClient sysClient; private final ISysClient sysClient;
private final MaintenanceTaskSchedule taskSchedule;
private final ThreadPoolExecutor executor; private final ThreadPoolExecutor executor;
private final DataSourceTransactionManager dataSourceTransactionManager;
/** /**
* 日常维护生成任务 * 日常维护生成任务
* *
@ -87,33 +84,16 @@ public class MaintenanceServiceImpl implements MaintenanceService {
// @Transactional(rollbackFor = Exception.class) // @Transactional(rollbackFor = Exception.class)
public void createTask(List<String> ids) { public void createTask(List<String> ids) {
try { try {
//获取日常维护计划 LambdaQueryWrapper<OperMaintenancePlanEntity> wrapper = Wrappers.<OperMaintenancePlanEntity>lambdaQuery()
LambdaQueryWrapper<OperMaintenancePlanEntity> planEntityLambdaQueryWrapper = new LambdaQueryWrapper<>(); .in(OperMaintenancePlanEntity::getId, ids);
planEntityLambdaQueryWrapper.in(BaseEntity::getId, ids); List<OperMaintenancePlanEntity> planList = maintenancePlanService.list(wrapper);
List<OperMaintenancePlanEntity> planEntities = maintenancePlanService.list(planEntityLambdaQueryWrapper); LocalDateTime minDate = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
//筛选当月没生成任务的计划 List<OperMaintenancePlanEntity> generatePlanList = planList.stream().filter(plan -> Func.isEmpty(plan.getCreateTaskTime()) || minDate.isAfter(DateUtil.DateToLocalDateTime(plan.getCreateTaskTime())))
List<OperMaintenancePlanEntity> finalPlanEntities = planEntities.stream().
filter(planEntity -> ObjectUtil.isEmpty(planEntity.getCreateTaskTime()) ||
!DateUtil.judgeSameDay(DateUtil.DateToLocalDateTime(planEntity.getCreateTaskTime()), LocalDate.now()))
.collect(Collectors.toList()); .collect(Collectors.toList());
if (CollectionUtil.isEmpty(finalPlanEntities)) { Assert.isTrue(CollectionUtil.isNotEmpty(generatePlanList), () -> {
throw new ServiceException("所选计划当天已生成任务"); throw new ServiceException("所选计划当天已生成任务");
} });
for (OperMaintenancePlanEntity finalPlanEntity : finalPlanEntities) { generatePlanList.forEach(plan -> taskSchedule.generateTaskByPlan(plan));
// 通过计划生成任务
Boolean taskByPlan = this.createTaskByPlan(finalPlanEntity);
if (taskByPlan) {
//更新任务派发时间
LambdaUpdateWrapper<OperMaintenancePlanEntity> 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("更新任务派发失败");
}
}
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -316,6 +296,7 @@ public class MaintenanceServiceImpl implements MaintenanceService {
* @param finalPlanEntity * @param finalPlanEntity
*/ */
@Override @Override
@Deprecated
// @Transactional(rollbackFor = Exception.class) // @Transactional(rollbackFor = Exception.class)
public Long fillTask(OperMaintenanceTaskEntity taskEntity, OperMaintenancePlanEntity finalPlanEntity, Boolean flag) { public Long fillTask(OperMaintenanceTaskEntity taskEntity, OperMaintenancePlanEntity finalPlanEntity, Boolean flag) {
// DefaultTransactionDefinition = new DefaultTransactionDefinition(); // DefaultTransactionDefinition = new DefaultTransactionDefinition();

Loading…
Cancel
Save