From 821d80e9876575bda25999785081e2e2eb2d9101 Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Mon, 8 Jan 2024 18:58:07 +0800 Subject: [PATCH 1/3] =?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 --- .../entity/OperMaintenanceTaskEntity.java | 3 ++ .../maintenance/vo/MaintenanceTaskQueryVO.java | 62 ++++++++++++++++++++++ .../controller/MaintenanceTaskQueryController.java | 24 +++++++++ .../service/IMaintenanceTaskQueryService.java | 4 ++ .../impl/MaintenanceTaskQueryServiceImpl.java | 14 +++++ .../safeproduct/src/main/resources/db/1.0.2.sql | 1 + 6 files changed, 108 insertions(+) create mode 100644 hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/maintenance/vo/MaintenanceTaskQueryVO.java create mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/controller/MaintenanceTaskQueryController.java create mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/IMaintenanceTaskQueryService.java create mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/MaintenanceTaskQueryServiceImpl.java create mode 100644 hzims-service/safeproduct/src/main/resources/db/1.0.2.sql diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/maintenance/entity/OperMaintenanceTaskEntity.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/maintenance/entity/OperMaintenanceTaskEntity.java index 9cd3385..5e490db 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/maintenance/entity/OperMaintenanceTaskEntity.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/maintenance/entity/OperMaintenanceTaskEntity.java @@ -191,4 +191,7 @@ public class OperMaintenanceTaskEntity extends TenantEntity { */ @ApiModelProperty("当前任务名") private String flowTaskId; + + @ApiModelProperty("是否延期") + private Boolean isDelay; } diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/maintenance/vo/MaintenanceTaskQueryVO.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/maintenance/vo/MaintenanceTaskQueryVO.java new file mode 100644 index 0000000..a565168 --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/maintenance/vo/MaintenanceTaskQueryVO.java @@ -0,0 +1,62 @@ +package com.hnac.hzims.operational.maintenance.vo; + +import com.alibaba.excel.annotation.ExcelProperty; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +@Data +@EqualsAndHashCode +@ApiModel("日常维护任务查询导出对象") +public class MaintenanceTaskQueryVO implements Serializable { + + @ApiModelProperty(value = "序号") + @ExcelProperty("序号") + private Integer index; + + @ApiModelProperty(value = "创建机构名称") + @ExcelProperty("单位") + private String deptName; + + @ApiModelProperty(value = "维护类型 01=定期试验 02=定期保养 03=定期操作 04=其他") + private String typeCode; + + @ExcelProperty("维护类型") + @ApiModelProperty(value = "维护类型名称") + private String typeName; + + @ApiModelProperty(value = "设备编号") + private String emCode; + + @ApiModelProperty(value = "维护设备") + @ExcelProperty("维护设备") + private String emName; + + @ApiModelProperty(value = "维护内容") + @ExcelProperty("维护内容") + private String content; + + @ApiModelProperty(value = "计划执行时间") + @ExcelProperty("计划执行时间") + private String planDisposeTime; + + @ApiModelProperty(value = "实际执行时间") + @ExcelProperty("实际执行时间") + private String disposeTime; + + @ApiModelProperty(value = "执行人") + @ExcelProperty("执行人") + private String disposerName; + + @ApiModelProperty(value = "逾期状态") + @ExcelProperty("逾期状态") + private String delayStatus; + + @ApiModelProperty(value = "状态") + @ExcelProperty("状态") + private String status; + +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/controller/MaintenanceTaskQueryController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/controller/MaintenanceTaskQueryController.java new file mode 100644 index 0000000..6cf12dc --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/controller/MaintenanceTaskQueryController.java @@ -0,0 +1,24 @@ +package com.hnac.hzims.operational.maintenance.controller; + +import io.swagger.annotations.Api; +import lombok.AllArgsConstructor; +import org.springblade.core.boot.ctrl.BladeController; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @ClassName MaintenanceTaskQueryController + * @description: + * @author: hx + * @create: 2024-01-08 14:35 + * @Version 4.0 + **/ +@RestController +@RequestMapping("/maintenance/task/query") +@Api(value = "日常维护任务导出管理",tags = "日常维护任务导出管理") +@AllArgsConstructor +public class MaintenanceTaskQueryController extends BladeController { + + + +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/IMaintenanceTaskQueryService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/IMaintenanceTaskQueryService.java new file mode 100644 index 0000000..31a3078 --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/IMaintenanceTaskQueryService.java @@ -0,0 +1,4 @@ +package com.hnac.hzims.operational.maintenance.service; + +public interface IMaintenanceTaskQueryService { +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/MaintenanceTaskQueryServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/MaintenanceTaskQueryServiceImpl.java new file mode 100644 index 0000000..8e75845 --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/MaintenanceTaskQueryServiceImpl.java @@ -0,0 +1,14 @@ +package com.hnac.hzims.operational.maintenance.service.impl; + +import com.hnac.hzims.operational.maintenance.service.IMaintenanceTaskQueryService; +import com.hnac.hzims.operational.maintenance.service.IOperMaintenanceTaskService; +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@AllArgsConstructor +public class MaintenanceTaskQueryServiceImpl implements IMaintenanceTaskQueryService { + + private final IOperMaintenanceTaskService operMaintenanceTaskService; + +} diff --git a/hzims-service/safeproduct/src/main/resources/db/1.0.2.sql b/hzims-service/safeproduct/src/main/resources/db/1.0.2.sql new file mode 100644 index 0000000..548567a --- /dev/null +++ b/hzims-service/safeproduct/src/main/resources/db/1.0.2.sql @@ -0,0 +1 @@ +alter table `hzims_oper_maintenance_task` add column `is_delay` tinyint(2) default 0 comment '是否延期'; \ No newline at end of file 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 2/3] =?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); } } From 0ea0397d6f689d7e6d1fba8c28a07767287e0e9e Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Tue, 9 Jan 2024 14:10:58 +0800 Subject: [PATCH 3/3] =?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=E6=89=A7=E8=A1=8C=E6=83=85=E5=86=B5=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../maintenance/vo/MaintenanceTaskQueryVO.java | 14 ++- .../controller/MaintenanceTaskQueryController.java | 26 +++- .../service/IMaintenanceTaskQueryService.java | 10 ++ .../impl/MaintenanceTaskQueryServiceImpl.java | 133 ++++++++++++++++++++- .../hnac/hzims/operational/util/ObjectUtils.java | 19 +++ .../operational/src/main/resources/db/1.0.1.sql | 3 +- 6 files changed, 196 insertions(+), 9 deletions(-) diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/maintenance/vo/MaintenanceTaskQueryVO.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/maintenance/vo/MaintenanceTaskQueryVO.java index a565168..ce9c78c 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/maintenance/vo/MaintenanceTaskQueryVO.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/maintenance/vo/MaintenanceTaskQueryVO.java @@ -1,6 +1,7 @@ package com.hnac.hzims.operational.maintenance.vo; import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.write.style.ColumnWidth; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -19,36 +20,37 @@ public class MaintenanceTaskQueryVO implements Serializable { @ApiModelProperty(value = "创建机构名称") @ExcelProperty("单位") + @ColumnWidth(20) private String deptName; - @ApiModelProperty(value = "维护类型 01=定期试验 02=定期保养 03=定期操作 04=其他") - private String typeCode; - @ExcelProperty("维护类型") @ApiModelProperty(value = "维护类型名称") + @ColumnWidth(15) private String typeName; - @ApiModelProperty(value = "设备编号") - private String emCode; - @ApiModelProperty(value = "维护设备") @ExcelProperty("维护设备") + @ColumnWidth(25) private String emName; @ApiModelProperty(value = "维护内容") @ExcelProperty("维护内容") + @ColumnWidth(40) private String content; @ApiModelProperty(value = "计划执行时间") @ExcelProperty("计划执行时间") + @ColumnWidth(20) private String planDisposeTime; @ApiModelProperty(value = "实际执行时间") @ExcelProperty("实际执行时间") + @ColumnWidth(20) private String disposeTime; @ApiModelProperty(value = "执行人") @ExcelProperty("执行人") + @ColumnWidth(20) private String disposerName; @ApiModelProperty(value = "逾期状态") diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/controller/MaintenanceTaskQueryController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/controller/MaintenanceTaskQueryController.java index 6cf12dc..c58ff94 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/controller/MaintenanceTaskQueryController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/controller/MaintenanceTaskQueryController.java @@ -1,11 +1,19 @@ package com.hnac.hzims.operational.maintenance.controller; -import io.swagger.annotations.Api; +import com.hnac.hzims.operational.maintenance.service.IMaintenanceTaskQueryService; +import com.hnac.hzims.operational.maintenance.vo.MaintenanceTaskQueryVO; +import io.swagger.annotations.*; import lombok.AllArgsConstructor; import org.springblade.core.boot.ctrl.BladeController; +import org.springblade.core.tool.api.R; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import javax.servlet.http.HttpServletResponse; +import java.util.List; + /** * @ClassName MaintenanceTaskQueryController * @description: @@ -19,6 +27,22 @@ import org.springframework.web.bind.annotation.RestController; @AllArgsConstructor public class MaintenanceTaskQueryController extends BladeController { + private final IMaintenanceTaskQueryService maintenanceTaskQueryService; + + @GetMapping("/getMaintenanceTaskQuery") + @ApiOperation("查询日常维护任务") + @ApiOperationSupport(order = 1) + public R> getMaintenanceTaskQuery(@RequestParam("month") @ApiParam(value = "查询月份",required = true) String month, + @RequestParam(value = "deptId",required = false) @ApiParam("查询机构") Long deptId) { + return R.data(maintenanceTaskQueryService.getMaintenanceTaskQuery(month, deptId)); + } + @GetMapping("/exportMaintenanceTaskQuery") + @ApiOperation("导出日常维护任务") + @ApiOperationSupport(order = 1) + public void exportMaintenanceTaskQuery(@RequestParam("month") @ApiParam(value = "查询月份",required = true) String month, + @RequestParam(value = "deptId",required = false) @ApiParam("查询机构") Long deptId, HttpServletResponse response) { + maintenanceTaskQueryService.exportMaintenanceTaskQuery(month,deptId,response); + } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/IMaintenanceTaskQueryService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/IMaintenanceTaskQueryService.java index 31a3078..4223c84 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/IMaintenanceTaskQueryService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/IMaintenanceTaskQueryService.java @@ -1,4 +1,14 @@ package com.hnac.hzims.operational.maintenance.service; +import com.hnac.hzims.operational.maintenance.vo.MaintenanceTaskQueryVO; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; + public interface IMaintenanceTaskQueryService { + + List getMaintenanceTaskQuery(String month,Long deptId); + + void exportMaintenanceTaskQuery(String month, Long deptId, HttpServletResponse response); + } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/MaintenanceTaskQueryServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/MaintenanceTaskQueryServiceImpl.java index 8e75845..d04c9e3 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/MaintenanceTaskQueryServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/MaintenanceTaskQueryServiceImpl.java @@ -1,14 +1,145 @@ package com.hnac.hzims.operational.maintenance.service.impl; +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.ExcelWriter; +import com.alibaba.excel.converters.longconverter.LongStringConverter; +import com.alibaba.excel.write.metadata.WriteSheet; +import com.alibaba.excel.write.metadata.style.WriteCellStyle; +import com.alibaba.excel.write.style.HorizontalCellStyleStrategy; +import com.alibaba.excel.write.style.column.SimpleColumnWidthStyleStrategy; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.google.common.collect.Lists; +import com.hnac.hzims.equipment.entity.EmInfoEntity; +import com.hnac.hzims.equipment.feign.IEmInfoClient; +import com.hnac.hzims.operational.maintenance.entity.OperMaintenanceTaskEntity; import com.hnac.hzims.operational.maintenance.service.IMaintenanceTaskQueryService; import com.hnac.hzims.operational.maintenance.service.IOperMaintenanceTaskService; +import com.hnac.hzims.operational.maintenance.vo.MaintenanceTaskQueryVO; +import com.hnac.hzims.operational.util.ObjectUtils; +import com.hnac.hzims.spare.entity.WtSpBasicEntity; import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.poi.ss.usermodel.BorderStyle; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.DateUtil; +import org.springblade.core.tool.utils.Func; +import org.springblade.core.tool.utils.StringUtil; +import org.springblade.system.cache.DictCache; +import org.springblade.system.entity.Dept; +import org.springblade.system.feign.ISysClient; +import org.springblade.system.user.cache.UserCache; +import org.springblade.system.user.entity.User; import org.springframework.stereotype.Service; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; +import java.util.function.Function; +import java.util.function.IntFunction; +import java.util.function.IntUnaryOperator; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + @Service @AllArgsConstructor +@Slf4j public class MaintenanceTaskQueryServiceImpl implements IMaintenanceTaskQueryService { - private final IOperMaintenanceTaskService operMaintenanceTaskService; + private final IOperMaintenanceTaskService maintenanceTaskService; + private final ISysClient sysClient; + private final IEmInfoClient emInfoClient; + + + @Override + public List getMaintenanceTaskQuery(String month,Long deptId) { + LambdaQueryWrapper wq = Wrappers.lambdaQuery() + .like(OperMaintenanceTaskEntity::getDisposeTime, month) + .like(Func.isNotEmpty(deptId),OperMaintenanceTaskEntity::getCreateDept,deptId) + .orderByAsc(OperMaintenanceTaskEntity::getDisposeTime); + List taskList = maintenanceTaskService.list(wq); + if(CollectionUtil.isEmpty(taskList)) { + return Lists.newArrayList(); + } + return this.fillTaskQuery(taskList); + } + + @Override + public void exportMaintenanceTaskQuery(String month, Long deptId, HttpServletResponse response) { + List maintenanceTaskQuery = this.getMaintenanceTaskQuery(month, deptId); + // 设置响应头 + // URLEncoder.encode防止中文乱码 + String fileName; + try { + fileName = URLEncoder.encode("日常维护执行情况报表", "UTF-8"); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); + response.setContentType("application/vnd.ms-excel"); + response.setCharacterEncoding("UTF-8"); + WriteCellStyle contentWriteCellStyle = new WriteCellStyle(); + contentWriteCellStyle.setBorderLeft(BorderStyle.THIN); + contentWriteCellStyle.setBorderTop(BorderStyle.THIN); + contentWriteCellStyle.setBorderRight(BorderStyle.THIN); + contentWriteCellStyle.setBorderBottom(BorderStyle.THIN); + contentWriteCellStyle.setWrapped(true); + try { + EasyExcel.write(response.getOutputStream(), MaintenanceTaskQueryVO.class) + .registerWriteHandler(new HorizontalCellStyleStrategy(new WriteCellStyle(), contentWriteCellStyle)) + .autoCloseStream(Boolean.FALSE).sheet("日常维护执行情况报表") + .doWrite(maintenanceTaskQuery); + } catch (IOException e) { + throw new RuntimeException(e); + } + + } + /** + * 填充查询结果 + * @param taskList 任务列表 + * @return 填充任务结果 + */ + private List fillTaskQuery(List taskList) { + R> deptListR = sysClient.getDeptList(); + List deptList = deptListR.isSuccess() ? deptListR.getData() : Lists.newArrayList(); + List emList = emInfoClient.list(); + IntFunction convert = index -> { + OperMaintenanceTaskEntity task = taskList.get(index); + MaintenanceTaskQueryVO result = new MaintenanceTaskQueryVO(); + result.setIndex(index + 1); + // 获取机构名称 + result.setDeptName(deptList.stream().filter( + dept -> dept.getId().equals(task.getCreateDept()) + ).findFirst().map(Dept::getDeptName).orElse("")); + // 获取维护类型 + result.setTypeName(DictCache.getValue("typeCode",task.getTypeCode())); + // 获取维护设备 + result.setEmName(emList.stream().filter( + em -> em.getNumber().equals(task.getEmCode()) + ).findFirst().map(EmInfoEntity::getName).orElse("")); + // 获取执行时间 + result.setPlanDisposeTime(DateUtil.formatDateTime(task.getDisposeTime())); + result.setDisposeTime(Optional.ofNullable(task.getExecuteTime()).map(DateUtil::formatDateTime).orElse("")); + // 获取执行人 + String disposerName = Optional.ofNullable(task.getDisposer()).map(ObjectUtils::getUserNameByUserIds).orElse(""); + result.setDisposerName(disposerName); + // 获取维护内容 + result.setContent(task.getContent()); + // 获取延期状态 + result.setDelayStatus(task.getIsDelay() ? "逾期" : "未逾期"); + // 获取状态 + result.setStatus("结束".equals(task.getFlowTaskName()) ? "已完成" : "进行中"); + return result; + }; + List result = IntStream.iterate(0,index -> index+1).limit(taskList.size()).mapToObj(convert).collect(Collectors.toList()); + return result; + } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/util/ObjectUtils.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/util/ObjectUtils.java index 66aaeca..9feb555 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/util/ObjectUtils.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/util/ObjectUtils.java @@ -3,7 +3,12 @@ package com.hnac.hzims.operational.util; import lombok.extern.slf4j.Slf4j; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.ObjectUtil; +import org.springblade.core.tool.utils.StringUtil; +import org.springblade.system.user.cache.UserCache; +import org.springblade.system.user.entity.User; + import java.lang.reflect.Field; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; @@ -16,6 +21,20 @@ import java.util.stream.Collectors; public class ObjectUtils { /** + * 根据用户Id获取用户名称 + * @param userIds 用户IDs + * @return 用户名称 + */ + public static String getUserNameByUserIds(String userIds) { + if(StringUtil.isBlank(userIds)) { + return ""; + } + return Arrays.stream(userIds.split(",")).filter(StringUtil::isNotBlank).map(Long::valueOf).filter(Func::isNotEmpty) + .map(UserCache::getUser).filter(Func::isNotEmpty).map(User::getName).collect(Collectors.joining(",")); + } + + + /** * 对象转为map * @param obj * @return diff --git a/hzims-service/operational/src/main/resources/db/1.0.1.sql b/hzims-service/operational/src/main/resources/db/1.0.1.sql index f382c22..3d5860e 100644 --- a/hzims-service/operational/src/main/resources/db/1.0.1.sql +++ b/hzims-service/operational/src/main/resources/db/1.0.1.sql @@ -1 +1,2 @@ -alter table hzims_oper_maintenance_plan add column station_code varchar(60) comment '站点编码' \ No newline at end of file +alter table hzims_oper_maintenance_plan add column station_code varchar(60) comment '站点编码'; +alter table `hzims_oper_maintenance_task` add column `is_delay` tinyint(2) DEFAULT 0 COMMENT '是否逾期'; \ No newline at end of file