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.hnac.hzims.equipment.feign.IEmInfoClient;
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.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.hzims.operational.maintenance.vo.OperMaintenanceTaskEntityVo;
import com.hnac.hzinfo.inspect.plan.entity.PlanEntity;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
@ -19,7 +21,9 @@ 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.api.R;
import org.springblade.core.tool.utils.*;
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;
@ -31,6 +35,7 @@ import java.time.ZoneId;
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 org.springblade.core.tool.utils.DateUtil.PATTERN_DATE;
@ -47,6 +52,7 @@ public class MaintenanceTaskSchedule {
private final IOperMaintenancePlanService planService;
private final IOperMaintenanceTaskService taskService;
private final IFlowClient flowClient;
private final IImsDutyMainService dutyMainService;
//@XxlJob(TASK_VALUE_MAINTENANCE_TASK_CREATE)
public ReturnT<String> execute(String param) throws Exception {
@ -74,18 +80,15 @@ public class MaintenanceTaskSchedule {
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);
this.createTask(taskEntity,plan);
}
}
else {
this.createTask(taskEntity);
this.createTask(taskEntity,plan);
}
}
catch(Exception e) {
@ -105,30 +108,61 @@ public class MaintenanceTaskSchedule {
/**
* 创建日常维护任务以及生成工作流
* @param task 日常维护任务
* @param plan 日常维护计划
*/
private void createTask(OperMaintenanceTaskEntity task) {
private void createTask(OperMaintenanceTaskEntity task,OperMaintenancePlanEntity plan) {
task.setId(null);
task.setCreateTime(new Date());
task.setUpdateTime(new Date());
task.setCreateTime(null);
task.setUpdateTime(null);
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;
// }
// }
//补充计划结束时间
Instant instant = task.getDisposeTime().toInstant();
ZoneId zoneId = ZoneId.systemDefault();
LocalDateTime disposeTime = instant.atZone(zoneId).toLocalDateTime();
task.setPlanEndTime(disposeTime.plusHours(task.getHours()));
// 当模式为班次时
Integer maintenanceModel = plan.getMaintenanceModel();
if(Func.isNotEmpty(maintenanceModel) && maintenanceModel == 2 ) {
LambdaQueryWrapper<ImsDutyMainEntity> dutyQuery = Wrappers.<ImsDutyMainEntity>lambdaQuery()
.eq(ImsDutyMainEntity::getDutyDate, DateUtil.formatDate(task.getDisposeTime()))
.eq(ImsDutyMainEntity::getClassId, plan.getImsDutyClassId());
ImsDutyMainEntity entity = dutyMainService.getOne(dutyQuery);
if (ObjectUtil.isNotEmpty(entity) && StringUtils.isNotEmpty(entity.getDutyPersonIds())) {
String userId = entity.getDutyPersonIds();
task.setDisposer(userId.replaceAll("\\^", ","));
}
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