haungxing
1 year ago
4 changed files with 150 additions and 1 deletions
@ -0,0 +1,134 @@ |
|||||||
|
package com.hnac.hzims.operational.maintenance.scheduled; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
||||||
|
import com.hnac.hzims.equipment.feign.IEmInfoClient; |
||||||
|
import com.hnac.hzims.operational.duty.entity.ImsDutyMainEntity; |
||||||
|
import com.hnac.hzims.operational.maintenance.entity.OperMaintenanceLibraryEntity; |
||||||
|
import com.hnac.hzims.operational.maintenance.entity.OperMaintenancePlanEntity; |
||||||
|
import com.hnac.hzims.operational.maintenance.entity.OperMaintenanceTaskEntity; |
||||||
|
import com.hnac.hzims.operational.maintenance.mapper.OperMaintenanceLibraryMapper; |
||||||
|
import com.hnac.hzims.operational.maintenance.service.IOperMaintenancePlanService; |
||||||
|
import com.hnac.hzims.operational.maintenance.service.IOperMaintenanceTaskService; |
||||||
|
import com.hnac.hzinfo.inspect.plan.entity.PlanEntity; |
||||||
|
import com.xxl.job.core.biz.model.ReturnT; |
||||||
|
import com.xxl.job.core.handler.annotation.XxlJob; |
||||||
|
import com.xxl.job.core.log.XxlJobLogger; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.apache.commons.lang.StringUtils; |
||||||
|
import org.springblade.core.log.logger.BladeLogger; |
||||||
|
import org.springblade.core.tool.utils.*; |
||||||
|
import org.springblade.flow.core.feign.IFlowClient; |
||||||
|
import org.springblade.system.user.feign.IUserClient; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
import java.time.Instant; |
||||||
|
import java.time.LocalDateTime; |
||||||
|
import java.time.ZoneId; |
||||||
|
import java.time.format.DateTimeFormatter; |
||||||
|
import java.util.*; |
||||||
|
import java.util.stream.Collectors; |
||||||
|
|
||||||
|
import static com.hnac.hzims.operational.maintenance.constants.ScheduledConstant.TASK_VALUE_MAINTENANCE_TASK_CREATE; |
||||||
|
import static org.springblade.core.tool.utils.DateUtil.PATTERN_DATE; |
||||||
|
|
||||||
|
/** |
||||||
|
* 日常维护任务生成 |
||||||
|
*/ |
||||||
|
@Component |
||||||
|
@Slf4j |
||||||
|
@AllArgsConstructor |
||||||
|
public class MaintenanceTaskSchedule { |
||||||
|
|
||||||
|
private final BladeLogger logger; |
||||||
|
private final IOperMaintenancePlanService planService; |
||||||
|
private final IOperMaintenanceTaskService taskService; |
||||||
|
private final IFlowClient flowClient; |
||||||
|
|
||||||
|
@XxlJob(TASK_VALUE_MAINTENANCE_TASK_CREATE) |
||||||
|
public ReturnT<String> execute(String param) throws Exception { |
||||||
|
Date startDate = StringUtil.isNotBlank(param) ? DateUtil.parse(param, DateUtil.PATTERN_DATE) : DateUtil.parse(DateUtil.formatDate(DateUtil.now()), DateUtil.PATTERN_DATE); |
||||||
|
Date endDate = DateUtil.parse(DateUtil.formatDate(DateUtil.plusDays(startDate, 1)), DateUtil.PATTERN_DATE); |
||||||
|
LambdaQueryWrapper<OperMaintenancePlanEntity> planQW = Wrappers.<OperMaintenancePlanEntity>lambdaQuery().isNull(OperMaintenancePlanEntity::getCreateTaskTime) |
||||||
|
.gt(OperMaintenancePlanEntity::getDisposeTime, startDate).le(OperMaintenancePlanEntity::getDisposeTime, endDate); |
||||||
|
List<OperMaintenancePlanEntity> planList = planService.list(planQW); |
||||||
|
XxlJobLogger.log("日常维护任务生成开始!计划ID为:"+planList.stream().map(OperMaintenancePlanEntity::getId).map(String::valueOf).collect(Collectors.joining(","))); |
||||||
|
//分页插入日常维护计划
|
||||||
|
planList.forEach(this::generateTaskByPlan); |
||||||
|
XxlJobLogger.log("日常维护任务生成完成!"); |
||||||
|
return new ReturnT<>("SUCCESS"); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 根据日常维护计划生成日常维护任务 |
||||||
|
* @param plan 日常维护计划 |
||||||
|
*/ |
||||||
|
private void generateTaskByPlan(OperMaintenancePlanEntity plan) { |
||||||
|
try { |
||||||
|
OperMaintenanceTaskEntity taskEntity = BeanUtil.copy(plan,OperMaintenanceTaskEntity.class); |
||||||
|
taskEntity.setPlanId(plan.getId()); |
||||||
|
taskEntity.setDisposer(Optional.ofNullable(plan.getDisposer()).map(String::valueOf).orElse(null)); |
||||||
|
LocalDateTime disposeTime = taskEntity.getDisposeTime().toInstant() |
||||||
|
.atZone(ZoneId.systemDefault()).toLocalDateTime(); |
||||||
|
taskEntity.setPlanEndTime(disposeTime.plusHours(taskEntity.getHours())); |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if(StringUtil.isNotBlank(plan.getEmCode())){ |
||||||
|
List<String> emCodeList = Arrays.asList(plan.getEmCode().split(",")); |
||||||
|
for(String emCode : emCodeList){ |
||||||
|
taskEntity.setEmCode(emCode); |
||||||
|
this.createTask(taskEntity); |
||||||
|
} |
||||||
|
} |
||||||
|
else { |
||||||
|
this.createTask(taskEntity); |
||||||
|
} |
||||||
|
} |
||||||
|
catch(Exception e) { |
||||||
|
logger.error("MaintenanceTaskSchedule:generateTaskByPlan",e.getLocalizedMessage()); |
||||||
|
XxlJobLogger.log(plan.getId()+"计划创建任务失败"); |
||||||
|
// 查询到日常维护计划所创建的任务
|
||||||
|
List<OperMaintenanceTaskEntity> maintenanceTasks = taskService.list(Wrappers.<OperMaintenanceTaskEntity>lambdaQuery().eq(OperMaintenanceTaskEntity::getPlanId, plan.getId())); |
||||||
|
for (OperMaintenanceTaskEntity maintenanceTask : maintenanceTasks) { |
||||||
|
if(Func.isNotEmpty(maintenanceTask.getProcessInstanceId())) { |
||||||
|
flowClient.delProcessInstanceById(maintenanceTask.getProcessInstanceId(),"错误流程"); |
||||||
|
taskService.removeById(maintenanceTask.getId()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 创建日常维护任务以及生成工作流 |
||||||
|
* @param task 日常维护任务 |
||||||
|
*/ |
||||||
|
private void createTask(OperMaintenanceTaskEntity task) { |
||||||
|
task.setId(null); |
||||||
|
task.setCreateTime(new Date()); |
||||||
|
task.setUpdateTime(new Date()); |
||||||
|
task.setTaskCode(UUID.randomUUID().toString()); |
||||||
|
// if (ObjectUtil.isNotEmpty(task.getMaintenanceModel()) && finalPlanEntity.getMaintenanceModel() == 2) {
|
||||||
|
// //查询值班信息
|
||||||
|
// LambdaQueryWrapper<ImsDutyMainEntity> entityLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
// entityLambdaQueryWrapper.eq(ImsDutyMainEntity::getDutyDate, DateTimeFormatter.ofPattern(PATTERN_DATE).format(disposeTime));
|
||||||
|
// entityLambdaQueryWrapper.eq(ImsDutyMainEntity::getClassId, finalPlanEntity.getImsDutyClassId());
|
||||||
|
// ImsDutyMainEntity entity = mainService.getOne(entityLambdaQueryWrapper);
|
||||||
|
// if (ObjectUtil.isNotEmpty(entity) && StringUtils.isNotEmpty(entity.getDutyPersonIds())) {
|
||||||
|
// String userId = entity.getDutyPersonIds();
|
||||||
|
// taskEntity.setDisposer(userId.replaceAll("\\^", ","));
|
||||||
|
// } else {
|
||||||
|
// log.info("计划ID为:{}未查询到排班记录", finalPlanEntity.getId());
|
||||||
|
// LambdaUpdateWrapper<OperMaintenancePlanEntity> planQueryWrapper = Wrappers.<OperMaintenancePlanEntity>lambdaUpdate()
|
||||||
|
// .set(OperMaintenancePlanEntity::getCreateTaskTime, new Date())
|
||||||
|
// .eq(OperMaintenancePlanEntity::getId, finalPlanEntity.getId());
|
||||||
|
// maintenancePlanService.update(planQueryWrapper);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue