|
|
@ -42,51 +42,78 @@ public class TaskOverdueHandler { |
|
|
|
private final IFlowClient flowClient; |
|
|
|
private final IFlowClient flowClient; |
|
|
|
private final ITicketInfoClient ticketInfoClient; |
|
|
|
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) |
|
|
|
@XxlJob(TASK_MAINTENANCE_OVERDUE_HANDLER) |
|
|
|
public ReturnT<String> execute(String param) throws Exception { |
|
|
|
public ReturnT<String> execute(String param) throws Exception { |
|
|
|
//获取当前时间段 redis内缓存的任务列表
|
|
|
|
//获取当前时间段 redis内缓存的任务列表
|
|
|
|
Set<OperMaintenanceTaskEntity> taskEntitySet = redisTemplate.opsForZSet().rangeByScore(REMIND_TASK_END_LIST,0, LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8"))); |
|
|
|
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)) { |
|
|
|
if(CollectionUtil.isNotEmpty(taskEntitySet)) { |
|
|
|
ExecutorService executorService = Executors.newSingleThreadExecutor(); |
|
|
|
taskEntitySet.forEach(operMaintenanceTaskEntity -> { |
|
|
|
executorService.execute(()-> { |
|
|
|
OperMaintenanceTaskEntity taskEntity = taskService.getById(operMaintenanceTaskEntity.getId()); |
|
|
|
taskEntitySet.forEach(operMaintenanceTaskEntity -> { |
|
|
|
//如果任务仍在待执行则自动结束
|
|
|
|
OperMaintenanceTaskEntity taskEntity = taskService.getById(operMaintenanceTaskEntity.getId()); |
|
|
|
if(!"结束".equals(taskEntity.getFlowTaskName())) { |
|
|
|
//如果任务仍在待执行则自动结束
|
|
|
|
XxlJobLogger.log("开始执行id为{}的任务", Optional.ofNullable(operMaintenanceTaskEntity.getId()).orElse(0L)); |
|
|
|
if(MaintenanceConstant.TASK_STATUS_5 != taskEntity.getStatus()) { |
|
|
|
//将任务置为未完成状态
|
|
|
|
XxlJobLogger.log("开始执行id为{}的任务", Optional.ofNullable(operMaintenanceTaskEntity.getId()).orElse(0L)); |
|
|
|
LambdaUpdateWrapper<OperMaintenanceTaskEntity> updateWrapper = new LambdaUpdateWrapper(); |
|
|
|
//将任务置为未完成状态
|
|
|
|
updateWrapper.set(OperMaintenanceTaskEntity::getDelayStatus,true); |
|
|
|
LambdaUpdateWrapper<OperMaintenanceTaskEntity> updateWrapper = new LambdaUpdateWrapper(); |
|
|
|
updateWrapper.eq(OperMaintenanceTaskEntity::getId,operMaintenanceTaskEntity.getId()); |
|
|
|
updateWrapper.set(OperMaintenanceTaskEntity::getStatus,MaintenanceConstant.TASK_STATUS_6); |
|
|
|
taskService.update(updateWrapper); |
|
|
|
updateWrapper.eq(OperMaintenanceTaskEntity::getId,operMaintenanceTaskEntity.getId()); |
|
|
|
redisTemplate.opsForZSet().remove(REMIND_TASK_END_LIST,operMaintenanceTaskEntity); |
|
|
|
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 { |
|
|
|
else { |
|
|
|
XxlJobLogger.log("无提醒任务!"); |
|
|
|
XxlJobLogger.log("无提醒任务!"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return new ReturnT<>("SUCCESS"); |
|
|
|
return new ReturnT<>("SUCCESS"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|