From 1ae7fa5f9d4fe9b020a7e981f25e7c3dad30b77d Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Mon, 8 Jan 2024 18:58:15 +0800 Subject: [PATCH] =?UTF-8?q?#=20=E6=97=A5=E5=B8=B8=E7=BB=B4=E6=8A=A4?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=94=9F=E6=88=90=E6=94=B9=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scheduled/MaintenanceTaskSchedule.java | 86 +++++++++++++++------- 1 file changed, 60 insertions(+), 26 deletions(-) diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskSchedule.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskSchedule.java index 692cdd9..7a9587b 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskSchedule.java +++ b/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 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 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 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 planQueryWrapper = Wrappers.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 dutyQuery = Wrappers.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 params = new HashMap() {{ + put("taskId", task.getId()); + String userId = task.getDisposer(); + List 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 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); } }