Browse Source

# 日常维护任务生成改造

zhongwei
haungxing 11 months ago
parent
commit
1ae7fa5f9d
  1. 86
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskSchedule.java

86
hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskSchedule.java

@ -5,12 +5,14 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hnac.hzims.equipment.feign.IEmInfoClient; import com.hnac.hzims.equipment.feign.IEmInfoClient;
import com.hnac.hzims.operational.duty.entity.ImsDutyMainEntity; import com.hnac.hzims.operational.duty.entity.ImsDutyMainEntity;
import com.hnac.hzims.operational.duty.service.IImsDutyMainService;
import com.hnac.hzims.operational.maintenance.entity.OperMaintenanceLibraryEntity; import com.hnac.hzims.operational.maintenance.entity.OperMaintenanceLibraryEntity;
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.mapper.OperMaintenanceLibraryMapper; import com.hnac.hzims.operational.maintenance.mapper.OperMaintenanceLibraryMapper;
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.vo.OperMaintenanceTaskEntityVo;
import com.hnac.hzinfo.inspect.plan.entity.PlanEntity; import com.hnac.hzinfo.inspect.plan.entity.PlanEntity;
import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob; import com.xxl.job.core.handler.annotation.XxlJob;
@ -19,7 +21,9 @@ import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springblade.core.log.logger.BladeLogger; import org.springblade.core.log.logger.BladeLogger;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.*; import org.springblade.core.tool.utils.*;
import org.springblade.flow.core.entity.BladeFlow;
import org.springblade.flow.core.feign.IFlowClient; import org.springblade.flow.core.feign.IFlowClient;
import org.springblade.system.user.feign.IUserClient; import org.springblade.system.user.feign.IUserClient;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -31,6 +35,7 @@ import java.time.ZoneId;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; 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.constants.ScheduledConstant.TASK_VALUE_MAINTENANCE_TASK_CREATE;
import static org.springblade.core.tool.utils.DateUtil.PATTERN_DATE; import static org.springblade.core.tool.utils.DateUtil.PATTERN_DATE;
@ -47,6 +52,7 @@ public class MaintenanceTaskSchedule {
private final IOperMaintenancePlanService planService; private final IOperMaintenancePlanService planService;
private final IOperMaintenanceTaskService taskService; private final IOperMaintenanceTaskService taskService;
private final IFlowClient flowClient; private final IFlowClient flowClient;
private final IImsDutyMainService dutyMainService;
//@XxlJob(TASK_VALUE_MAINTENANCE_TASK_CREATE) //@XxlJob(TASK_VALUE_MAINTENANCE_TASK_CREATE)
public ReturnT<String> execute(String param) throws Exception { public ReturnT<String> execute(String param) throws Exception {
@ -74,18 +80,15 @@ public class MaintenanceTaskSchedule {
LocalDateTime disposeTime = taskEntity.getDisposeTime().toInstant() LocalDateTime disposeTime = taskEntity.getDisposeTime().toInstant()
.atZone(ZoneId.systemDefault()).toLocalDateTime(); .atZone(ZoneId.systemDefault()).toLocalDateTime();
taskEntity.setPlanEndTime(disposeTime.plusHours(taskEntity.getHours())); taskEntity.setPlanEndTime(disposeTime.plusHours(taskEntity.getHours()));
if(StringUtil.isNotBlank(plan.getEmCode())){ if(StringUtil.isNotBlank(plan.getEmCode())){
List<String> emCodeList = Arrays.asList(plan.getEmCode().split(",")); List<String> emCodeList = Arrays.asList(plan.getEmCode().split(","));
for(String emCode : emCodeList){ for(String emCode : emCodeList){
taskEntity.setEmCode(emCode); taskEntity.setEmCode(emCode);
this.createTask(taskEntity); this.createTask(taskEntity,plan);
} }
} }
else { else {
this.createTask(taskEntity); this.createTask(taskEntity,plan);
} }
} }
catch(Exception e) { catch(Exception e) {
@ -105,30 +108,61 @@ public class MaintenanceTaskSchedule {
/** /**
* 创建日常维护任务以及生成工作流 * 创建日常维护任务以及生成工作流
* @param task 日常维护任务 * @param task 日常维护任务
* @param plan 日常维护计划
*/ */
private void createTask(OperMaintenanceTaskEntity task) { private void createTask(OperMaintenanceTaskEntity task,OperMaintenancePlanEntity plan) {
task.setId(null); task.setId(null);
task.setCreateTime(new Date()); task.setCreateTime(null);
task.setUpdateTime(new Date()); task.setUpdateTime(null);
task.setTaskCode(UUID.randomUUID().toString()); task.setTaskCode(UUID.randomUUID().toString());
// if (ObjectUtil.isNotEmpty(task.getMaintenanceModel()) && finalPlanEntity.getMaintenanceModel() == 2) { //补充计划结束时间
// //查询值班信息 Instant instant = task.getDisposeTime().toInstant();
// LambdaQueryWrapper<ImsDutyMainEntity> entityLambdaQueryWrapper = new LambdaQueryWrapper<>(); ZoneId zoneId = ZoneId.systemDefault();
// entityLambdaQueryWrapper.eq(ImsDutyMainEntity::getDutyDate, DateTimeFormatter.ofPattern(PATTERN_DATE).format(disposeTime)); LocalDateTime disposeTime = instant.atZone(zoneId).toLocalDateTime();
// entityLambdaQueryWrapper.eq(ImsDutyMainEntity::getClassId, finalPlanEntity.getImsDutyClassId()); task.setPlanEndTime(disposeTime.plusHours(task.getHours()));
// ImsDutyMainEntity entity = mainService.getOne(entityLambdaQueryWrapper); // 当模式为班次时
// if (ObjectUtil.isNotEmpty(entity) && StringUtils.isNotEmpty(entity.getDutyPersonIds())) { Integer maintenanceModel = plan.getMaintenanceModel();
// String userId = entity.getDutyPersonIds(); if(Func.isNotEmpty(maintenanceModel) && maintenanceModel == 2 ) {
// taskEntity.setDisposer(userId.replaceAll("\\^", ",")); LambdaQueryWrapper<ImsDutyMainEntity> dutyQuery = Wrappers.<ImsDutyMainEntity>lambdaQuery()
// } else { .eq(ImsDutyMainEntity::getDutyDate, DateUtil.formatDate(task.getDisposeTime()))
// log.info("计划ID为:{}未查询到排班记录", finalPlanEntity.getId()); .eq(ImsDutyMainEntity::getClassId, plan.getImsDutyClassId());
// LambdaUpdateWrapper<OperMaintenancePlanEntity> planQueryWrapper = Wrappers.<OperMaintenancePlanEntity>lambdaUpdate() ImsDutyMainEntity entity = dutyMainService.getOne(dutyQuery);
// .set(OperMaintenancePlanEntity::getCreateTaskTime, new Date()) if (ObjectUtil.isNotEmpty(entity) && StringUtils.isNotEmpty(entity.getDutyPersonIds())) {
// .eq(OperMaintenancePlanEntity::getId, finalPlanEntity.getId()); String userId = entity.getDutyPersonIds();
// maintenancePlanService.update(planQueryWrapper); task.setDisposer(userId.replaceAll("\\^", ","));
// return; }
// } else {
// } XxlJobLogger.log("ID为:"+plan.getId()+"的日常维护计划未获取到值班人员,未生成任务。");
return;
}
}
// 保存日常维护任务
taskService.save(task);
this.startProcessInstance(task);
}
/**
* 开启日常维护任务工作流
* @param task 日常维护任务
* @return 工作流实例ID
*/
private String startProcessInstance(OperMaintenanceTaskEntity task) {
if(Func.isEmpty(task.getDisposer())) {
return null;
}
OperMaintenanceTaskEntityVo vo = BeanUtil.copy(task,OperMaintenanceTaskEntityVo.class);
Map<String,Object> params = new HashMap<String, Object>() {{
put("taskId", task.getId());
String userId = task.getDisposer();
List<String> userIds = Stream.of(userId.split(",")).collect(Collectors.toList());
Stream.iterate(0, i -> i + 1).limit(5).forEach(index -> {
String key = index == 0 ? "initUserIds" : "initUserIds".concat(String.valueOf(index));
put(key,index + 1 > userIds.size() ? "" : "taskUser_".concat(userIds.get(index)));
});
put("operMaintenanceTaskEntityVo",vo);
}};
R<BladeFlow> flowResult = flowClient.startProcessInstanceContainNameByKey("", String.valueOf(task.getId()), task.getTitle(), params);
return Optional.ofNullable(flowResult).filter(r -> r.isSuccess()).map(R::getData).map(BladeFlow::getProcessInstanceId).orElse(null);
} }
} }

Loading…
Cancel
Save