Browse Source

# 日常维护逾期逻辑判断

# 日常维护任务执行情况统计问题修改
zhongwei
haungxing 11 months ago
parent
commit
485aad735a
  1. 9
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/OperationApplication.java
  2. 10
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskSchedule.java
  3. 97
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/TaskOverdueHandler.java
  4. 3
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/MaintenanceTaskQueryServiceImpl.java

9
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);
}

10
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<String> 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);
}
}
/**

97
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<String> execute(String param) throws Exception {
// //获取当前时间段 redis内缓存的任务列表
// Set<OperMaintenanceTaskEntity> 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<OperMaintenanceTaskEntity> 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<Boolean> 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<String> execute(String param) throws Exception {
//获取当前时间段 redis内缓存的任务列表
Set<OperMaintenanceTaskEntity> 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<OperMaintenanceTaskEntity> 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<Boolean> 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<OperMaintenanceTaskEntity> 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");
}
}

3
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())

Loading…
Cancel
Save