diff --git a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/emParam/entity/ParamBackupsDetailEntity.java b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/emParam/entity/ParamBackupsDetailEntity.java index ff7b15d..269580c 100644 --- a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/emParam/entity/ParamBackupsDetailEntity.java +++ b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/emParam/entity/ParamBackupsDetailEntity.java @@ -51,4 +51,10 @@ public class ParamBackupsDetailEntity extends TenantEntity implements Serializab @ApiModelProperty("最小值") private String minValue; + @ApiModelProperty("保留小数位") + private Integer keepFigures; + + @ApiModelProperty("描述") + private String descs; + } diff --git a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/emParam/vo/ParamVO.java b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/emParam/vo/ParamVO.java index 76816be..8f76c9c 100644 --- a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/emParam/vo/ParamVO.java +++ b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/emParam/vo/ParamVO.java @@ -61,4 +61,10 @@ public class ParamVO implements Serializable { @ApiModelProperty("最小值") private String minValue; + @ApiModelProperty("保留小数位") + private Integer keepFigures; + + @ApiModelProperty("描述") + private String descs; + } diff --git a/hzims-service/equipment/src/main/resources/db/1.0.1.sql b/hzims-service/equipment/src/main/resources/db/1.0.1.sql index 98b3759..1f41725 100644 --- a/hzims-service/equipment/src/main/resources/db/1.0.1.sql +++ b/hzims-service/equipment/src/main/resources/db/1.0.1.sql @@ -44,4 +44,7 @@ CREATE TABLE `hzims_param_backups_detail` ( `STATUS` tinyint(4) DEFAULT NULL COMMENT '状态 ', `CREATE_DEPT` bigint(20) DEFAULT NULL COMMENT '创建部门', PRIMARY KEY (`ID`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; \ No newline at end of file +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +alter table `HZIMS_PARAM_BACKUPS_DETAIL` add COLUMN `KEEP_FIGURES` INT(11) COMMENT '小数点位数'; +alter table `HZIMS_PARAM_BACKUPS_DETAIL` add COLUMN `DESCS` VARCHAR(255) COMMENT '描述'; 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 new file mode 100644 index 0000000..ea0052e --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskSchedule.java @@ -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 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 planQW = Wrappers.lambdaQuery().isNull(OperMaintenancePlanEntity::getCreateTaskTime) + .gt(OperMaintenancePlanEntity::getDisposeTime, startDate).le(OperMaintenancePlanEntity::getDisposeTime, endDate); + List 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 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 maintenanceTasks = taskService.list(Wrappers.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 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; +// } +// } + } + +}