From 407c7c5f52dad063d61827191cddc7d19d2d7ff3 Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Wed, 21 Jun 2023 08:34:34 +0800 Subject: [PATCH] =?UTF-8?q?#=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E6=8A=BD?= =?UTF-8?q?=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../access/entity/OperAccessPlanEntity.java | 6 + .../access/feign/AccessPlanV4ClientFallback.java | 17 ++ .../access/feign/AccessTaskV4ClientFallback.java | 17 ++ .../access/feign/IAccessPlanV4Client.java | 25 +++ .../access/feign/IAccessTaskV4Client.java | 25 +++ .../scheduled/scheduled/ShowScheduledTask.java | 1 + .../service/ticket/impl/WorkTicketServiceImpl.java | 46 ++--- .../access/controller/AccessPlanV4Controller.java | 38 ++++ .../access/controller/AccessV4Controller.java | 19 ++ .../operational/access/dto/AccessPlanV4DTO.java | 24 +++ .../operational/access/dto/AccessTaskV4DTO.java | 39 ++++ .../access/feign/AccessPlanV4Client.java | 34 ++++ .../access/feign/AccessTaskV4Client.java | 35 ++++ .../access/service/AccessPlanV4Service.java | 14 ++ .../access/service/AccessTaskV4Service.java | 14 ++ .../service/impl/AccessPlanV4ServiceImpl.java | 212 +++++++++++++++++++++ .../service/impl/AccessTaskV4ServiceImpl.java | 160 ++++++++++++++++ 17 files changed, 699 insertions(+), 27 deletions(-) create mode 100644 hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/access/feign/AccessPlanV4ClientFallback.java create mode 100644 hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/access/feign/AccessTaskV4ClientFallback.java create mode 100644 hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/access/feign/IAccessPlanV4Client.java create mode 100644 hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/access/feign/IAccessTaskV4Client.java create mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/controller/AccessPlanV4Controller.java create mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/controller/AccessV4Controller.java create mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/dto/AccessPlanV4DTO.java create mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/dto/AccessTaskV4DTO.java create mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/feign/AccessPlanV4Client.java create mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/feign/AccessTaskV4Client.java create mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/AccessPlanV4Service.java create mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/AccessTaskV4Service.java create mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/impl/AccessPlanV4ServiceImpl.java create mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/impl/AccessTaskV4ServiceImpl.java diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/access/entity/OperAccessPlanEntity.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/access/entity/OperAccessPlanEntity.java index 9ca45d1..4a148ea 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/access/entity/OperAccessPlanEntity.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/access/entity/OperAccessPlanEntity.java @@ -135,4 +135,10 @@ public class OperAccessPlanEntity extends TenantEntity { @ApiModelProperty("票据模板ID") private Long ticketTemplateId; + + @ApiModelProperty("当前步骤任务名称") + private String taskName; + + @ApiModelProperty("当前环节处理人") + private String nextStepOperator; } diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/access/feign/AccessPlanV4ClientFallback.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/access/feign/AccessPlanV4ClientFallback.java new file mode 100644 index 0000000..be198df --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/access/feign/AccessPlanV4ClientFallback.java @@ -0,0 +1,17 @@ +package com.hnac.hzims.operational.access.feign; + +import com.hnac.hzims.common.to.process.ProcessWorkFlowResponse; +import org.springblade.core.tool.api.R; +import org.springframework.stereotype.Component; + +/** + * @author ysj + */ +@Component +public class AccessPlanV4ClientFallback implements IAccessPlanV4Client { + + @Override + public R listener(ProcessWorkFlowResponse processWorkFlowResponse) { + return R.fail("执行失败!"); + } +} diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/access/feign/AccessTaskV4ClientFallback.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/access/feign/AccessTaskV4ClientFallback.java new file mode 100644 index 0000000..1229028 --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/access/feign/AccessTaskV4ClientFallback.java @@ -0,0 +1,17 @@ +package com.hnac.hzims.operational.access.feign; + +import com.hnac.hzims.common.to.process.ProcessWorkFlowResponse; +import org.springblade.core.tool.api.R; +import org.springframework.stereotype.Component; + +/** + * @author ysj + */ +@Component +public class AccessTaskV4ClientFallback implements IAccessTaskV4Client { + + @Override + public R listener(ProcessWorkFlowResponse processWorkFlowResponse) { + return R.fail("执行失败!"); + } +} diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/access/feign/IAccessPlanV4Client.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/access/feign/IAccessPlanV4Client.java new file mode 100644 index 0000000..d8d27a6 --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/access/feign/IAccessPlanV4Client.java @@ -0,0 +1,25 @@ +package com.hnac.hzims.operational.access.feign; + +import com.hnac.hzims.common.to.process.ProcessWorkFlowResponse; +import com.hnac.hzims.operational.OperationalConstants; +import org.springblade.core.tool.api.R; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + +/** + * @author ysj + */ +@FeignClient( + value = OperationalConstants.APP_NAME, + fallback = AccessTaskClientFallback.class +) +public interface IAccessPlanV4Client { + + String API_PREFIX = "/feign/accessPlanV4"; + + String PLAN_PROCESS_LISTENER = API_PREFIX + "listener"; + + @PostMapping(PLAN_PROCESS_LISTENER) + R listener(@RequestBody ProcessWorkFlowResponse processWorkFlowResponse); +} diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/access/feign/IAccessTaskV4Client.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/access/feign/IAccessTaskV4Client.java new file mode 100644 index 0000000..28f8fbb --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/access/feign/IAccessTaskV4Client.java @@ -0,0 +1,25 @@ +package com.hnac.hzims.operational.access.feign; + +import com.hnac.hzims.common.to.process.ProcessWorkFlowResponse; +import com.hnac.hzims.operational.OperationalConstants; +import org.springblade.core.tool.api.R; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + +/** + * @author ysj + */ +@FeignClient( + value = OperationalConstants.APP_NAME, + fallback = AccessTaskClientFallback.class +) +public interface IAccessTaskV4Client { + + String API_PREFIX = "/feign/accessTaskV4"; + + String PLAN_PROCESS_LISTENER = API_PREFIX + "listener"; + + @PostMapping(PLAN_PROCESS_LISTENER) + R listener(@RequestBody ProcessWorkFlowResponse processWorkFlowResponse); +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/ShowScheduledTask.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/ShowScheduledTask.java index a65d1da..e8d43b6 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/ShowScheduledTask.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/ShowScheduledTask.java @@ -42,6 +42,7 @@ public class ShowScheduledTask { * 首页-区域班组数据 */ @XxlJob(REGIONAL_DUTY_INFO) + //@Scheduled(cron = "0/40 * * * * ? ") public ReturnT loadRegionalDuty(String param) { if (Func.isBlank(param)) { param = DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"); diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/ticket/impl/WorkTicketServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/ticket/impl/WorkTicketServiceImpl.java index e8bb066..7cad00b 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/ticket/impl/WorkTicketServiceImpl.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/ticket/impl/WorkTicketServiceImpl.java @@ -12,6 +12,7 @@ import com.hnac.hzims.ticket.workTicket.entity.WorkTicketDelayEntity; import com.hnac.hzims.ticket.workTicket.entity.WorkTicketInfoEntity; import com.hnac.hzims.ticket.workTicket.entity.WorkTicketPrincipalChangeEntity; import com.hnac.hzims.ticket.workTicket.vo.WorkTicketStatisticVO; +import lombok.AllArgsConstructor; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.mp.base.BaseServiceImpl; @@ -29,12 +30,12 @@ import java.util.stream.Collectors; */ @Service @Slf4j -@RequiredArgsConstructor +@AllArgsConstructor @DS("ticket") public class WorkTicketServiceImpl extends BaseServiceImpl implements WorkTicketService { - private WorkPrincipalService workPrincipalService; - private WorkDelayService workDelayService; + private final WorkPrincipalService workPrincipalService; + private final WorkDelayService workDelayService; @Override public WorkTicketStatisticVO work(String start, String end, List areas) { @@ -55,31 +56,22 @@ public class WorkTicketServiceImpl extends BaseServiceImpl completeList = infoList.stream().filter(w -> TicketConstants.FirstWorkTicketFlowStatusEnum.FINISH.getStatus().equals(w.getStatus())) .collect(Collectors.toList()); work.setComplete(CollectionUtil.isNotEmpty(completeList) ? completeList.size() : 0); - //工作票移交 - FutureTask transferTask = new FutureTask(() -> { - List moveList = workPrincipalService.list(new LambdaQueryWrapper() {{ - in(WorkTicketPrincipalChangeEntity::getTicketId, infoIdList); - }}); - return CollectionUtil.isNotEmpty(moveList) ? moveList.size() : 0; - }); - - new Thread(transferTask, "工作票移交Thread").start(); - //工作票延期 - FutureTask delayTask = new FutureTask(() -> { - log.info("开始工作票延期"); - List delayEntityList = workDelayService.list(Wrappers.lambdaQuery() - .in(WorkTicketDelayEntity::getTicketId, infoIdList) - ); - return CollectionUtil.isNotEmpty(delayEntityList) ? delayEntityList.size() : 0; - }); - new Thread(delayTask, "工作票延期Thread").start(); - try { - work.setDelay((Integer) delayTask.get()); - work.setTransfer((Integer) transferTask.get()); - } catch (InterruptedException | ExecutionException e) { - e.printStackTrace(); - Thread.currentThread().interrupt(); + int transferTask = 0; + int delayTask = 0; + List moveList = workPrincipalService.list(new LambdaQueryWrapper() {{ + in(WorkTicketPrincipalChangeEntity::getTicketId, infoIdList); + }}); + if(CollectionUtil.isNotEmpty(moveList)){ + transferTask = moveList.size(); + } + List delayEntityList = workDelayService.list(Wrappers.lambdaQuery() + .in(WorkTicketDelayEntity::getTicketId, infoIdList) + ); + if(CollectionUtil.isNotEmpty(delayEntityList)){ + delayTask = delayEntityList.size(); } + work.setDelay(delayTask); + work.setTransfer(transferTask); } return work; } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/controller/AccessPlanV4Controller.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/controller/AccessPlanV4Controller.java new file mode 100644 index 0000000..aa0b2af --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/controller/AccessPlanV4Controller.java @@ -0,0 +1,38 @@ +package com.hnac.hzims.operational.access.controller; + +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.hnac.hzims.operational.access.dto.AccessPlanV4DTO; +import com.hnac.hzims.operational.access.service.AccessPlanV4Service; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.AllArgsConstructor; +import org.springblade.core.boot.ctrl.BladeController; +import org.springblade.core.tool.api.R; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + + +/** + * @author ysj + */ +@RestController +@AllArgsConstructor +@RequestMapping("/overhaul_plan") +@Api(tags = "v4检修计划流程") +public class AccessPlanV4Controller extends BladeController { + + + private final AccessPlanV4Service service; + + /** + * v4检修计划流程开启 + * @return + */ + @PostMapping("/overhaul_start_v4") + @ApiOperationSupport(order = 1) + @ApiOperation(value = "v4检修计划流程开启") + public R startV4(AccessPlanV4DTO entity) { + return R.status(service.startProcessV4(entity)); + } +} \ No newline at end of file diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/controller/AccessV4Controller.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/controller/AccessV4Controller.java new file mode 100644 index 0000000..6dbfc08 --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/controller/AccessV4Controller.java @@ -0,0 +1,19 @@ +package com.hnac.hzims.operational.access.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; + + +/** + * @author ysj + */ +@RestController +@AllArgsConstructor +@RequestMapping("/overhaul_task") +@Api(tags = "v4检修计划流程") +public class AccessV4Controller extends BladeController { + +} \ No newline at end of file diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/dto/AccessPlanV4DTO.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/dto/AccessPlanV4DTO.java new file mode 100644 index 0000000..70cc9bc --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/dto/AccessPlanV4DTO.java @@ -0,0 +1,24 @@ +package com.hnac.hzims.operational.access.dto; + +import com.hnac.hzims.operational.access.entity.OperAccessPlanEntity; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.List; + +/** + * @author ysj + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class AccessPlanV4DTO extends OperAccessPlanEntity { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty("检修材料列表") + private List accessMaterials; + + @ApiModelProperty("检修内容列表") + private List accessContents; +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/dto/AccessTaskV4DTO.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/dto/AccessTaskV4DTO.java new file mode 100644 index 0000000..36c8b8b --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/dto/AccessTaskV4DTO.java @@ -0,0 +1,39 @@ +package com.hnac.hzims.operational.access.dto; + +import com.hnac.hzims.operational.access.entity.OperAccessTaskEntity; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.List; + +/** + * @author ysj + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class AccessTaskV4DTO extends OperAccessTaskEntity { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "创建机构集合") + private List deptIds; + + @ApiModelProperty(value = "工作流Key") + private String procDefId; + + @ApiModelProperty("为1时排除票据ID为空的数据") + private Long excludeNullTicket; + + @ApiModelProperty("检修任务详情") + private List accessTaskDetails; + + @ApiModelProperty("检修材料列表") + private List accessMaterials; + + @ApiModelProperty("开始时间") + private String startTime; + + @ApiModelProperty("结束时间") + private String endTime; +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/feign/AccessPlanV4Client.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/feign/AccessPlanV4Client.java new file mode 100644 index 0000000..f5d4a88 --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/feign/AccessPlanV4Client.java @@ -0,0 +1,34 @@ +package com.hnac.hzims.operational.access.feign; + +import com.hnac.hzims.common.to.process.ProcessWorkFlowResponse; +import com.hnac.hzims.operational.access.service.AccessPlanV4Service; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.tool.api.R; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author ysj + */ +@RestController +@RequestMapping("/feign/accessPlanV4") +@Slf4j +@RequiredArgsConstructor +public class AccessPlanV4Client implements IAccessPlanV4Client { + + private final AccessPlanV4Service service; + + /** + * 检修计划流程监听 + * @param processWorkFlowResponse + * @return + */ + @Override + @PostMapping("/listener") + public R listener(@RequestBody ProcessWorkFlowResponse processWorkFlowResponse) { + return R.status(service.listener(processWorkFlowResponse)); + } +} \ No newline at end of file diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/feign/AccessTaskV4Client.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/feign/AccessTaskV4Client.java new file mode 100644 index 0000000..031257a --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/feign/AccessTaskV4Client.java @@ -0,0 +1,35 @@ +package com.hnac.hzims.operational.access.feign; + +import com.hnac.hzims.common.to.process.ProcessWorkFlowResponse; +import com.hnac.hzims.operational.access.service.AccessPlanV4Service; +import com.hnac.hzims.operational.access.service.AccessTaskV4Service; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.tool.api.R; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author ysj + */ +@RestController +@RequestMapping("/feign/accessTaskV4") +@Slf4j +@RequiredArgsConstructor +public class AccessTaskV4Client implements IAccessPlanV4Client { + + private final AccessTaskV4Service service; + + /** + * 检修任务流程监听 + * @param processWorkFlowResponse + * @return + */ + @Override + @PostMapping("/listener") + public R listener(@RequestBody ProcessWorkFlowResponse processWorkFlowResponse) { + return R.status(service.listener(processWorkFlowResponse)); + } +} \ No newline at end of file diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/AccessPlanV4Service.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/AccessPlanV4Service.java new file mode 100644 index 0000000..9ec840d --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/AccessPlanV4Service.java @@ -0,0 +1,14 @@ +package com.hnac.hzims.operational.access.service; + +import com.hnac.hzims.common.to.process.ProcessWorkFlowResponse; +import com.hnac.hzims.operational.access.dto.AccessPlanV4DTO; + +/** + * @author ysj + */ +public interface AccessPlanV4Service{ + + boolean startProcessV4(AccessPlanV4DTO entity); + + boolean listener(ProcessWorkFlowResponse processWorkFlowResponse); +} \ No newline at end of file diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/AccessTaskV4Service.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/AccessTaskV4Service.java new file mode 100644 index 0000000..edffde2 --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/AccessTaskV4Service.java @@ -0,0 +1,14 @@ +package com.hnac.hzims.operational.access.service; + +import com.hnac.hzims.common.to.process.ProcessWorkFlowResponse; +import com.hnac.hzims.operational.access.dto.AccessTaskV4DTO; + +/** + * @author ysj + */ +public interface AccessTaskV4Service { + + boolean startProcessV4(AccessTaskV4DTO entity); + + boolean listener(ProcessWorkFlowResponse processWorkFlowResponse); +} \ No newline at end of file diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/impl/AccessPlanV4ServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/impl/AccessPlanV4ServiceImpl.java new file mode 100644 index 0000000..fa8d63c --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/impl/AccessPlanV4ServiceImpl.java @@ -0,0 +1,212 @@ +package com.hnac.hzims.operational.access.service.impl; + +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.hnac.hzims.common.to.process.ProcessWorkFlowResponse; +import com.hnac.hzims.operational.access.dto.*; +import com.hnac.hzims.operational.access.entity.OperAccessContentEntity; +import com.hnac.hzims.operational.access.entity.OperAccessMaterialEntity; +import com.hnac.hzims.operational.access.service.*; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.RandomUtils; +import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.BeanUtil; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.DateUtil; +import org.springblade.core.tool.utils.ObjectUtil; +import org.springblade.flow.core.entity.BladeFlow; +import org.springblade.flow.core.feign.IFlowClient; +import org.springblade.flow.core.utils.FlowUtil; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; + +import java.text.DecimalFormat; +import java.util.*; +import java.util.stream.Collectors; + +/** + * @author ysj + */ +@Service +@Slf4j +@RequiredArgsConstructor +public class AccessPlanV4ServiceImpl implements AccessPlanV4Service{ + + private final IOperAccessPlanService planService; + + private final IOperAccessMaterialService materialService; + + private final IOperAccessContentService contentService; + + private final AccessTaskV4Service accessTaskV4Service; + + private final IFlowClient flowClient; + + /** + * 开启检修计划流程 + * @param entity + * @return + */ + @Override + @Transactional(rollbackFor = Exception.class) + public boolean startProcessV4(AccessPlanV4DTO entity) { + // 步骤1.保存检修计划 + this.saveAccess(entity); + + // 步骤2.保存检修材料 + this.saveAccessMaterial(entity); + + // 步骤3.保存检修明细 + this.saveAccessContent(entity); + + // 步骤2.开启检修计划流程 + this.startProcess(entity); + return true; + } + + /** + * 保存检修计划 + * @param entity + */ + private void saveAccess(AccessPlanV4DTO entity) { + // 检修计划保存 + entity.setCode("PLAN_" + DateUtil.format(DateUtil.now(), DateUtil.PATTERN_DATETIME_MINI) + new DecimalFormat("###").format(RandomUtils.nextInt(0, 999))); + planService.save(entity); + } + + + /** + * 保存检修材料 + * @param entity + */ + private void saveAccessMaterial(AccessPlanV4DTO entity) { + if(CollectionUtils.isEmpty(entity.getAccessMaterials())){ + return; + } + // 查询计划是否绑定检修材料 + List existsDetails = materialService.list(new LambdaQueryWrapper() {{ + eq(OperAccessMaterialEntity::getPlanId, entity.getId()); + eq(OperAccessMaterialEntity::getIsDeleted, 0L); + }}); + Set detailIds = entity.getAccessMaterials().stream().map(OperAccessMaterialDTO::getId).filter(Objects::nonNull).collect(Collectors.toSet()); + List ids = existsDetails.stream().map(OperAccessMaterialEntity::getId).filter(id -> !detailIds.contains(id)).collect(Collectors.toList()); + if (!CollectionUtils.isEmpty(ids)) { + materialService.deleteLogic(ids); + } + // 材料添加/修改 + for (OperAccessMaterialDTO material : entity.getAccessMaterials()) { + material.setPlanId(entity.getId()); + if (ObjectUtil.isEmpty(material.getId())) { + materialService.doSave(material); + continue; + } + materialService.updateById(material); + } + } + + /** + * 保存检修明细 + * @param entity + */ + private void saveAccessContent(AccessPlanV4DTO entity) { + if(CollectionUtils.isEmpty(entity.getAccessContents())){ + return; + } + // 查询计划是否绑定任务明细 + List existsDetails = contentService.list(new LambdaQueryWrapper() {{ + eq(OperAccessContentEntity::getPlanId, entity.getId()); + eq(OperAccessContentEntity::getIsDeleted, 0L); + }}); + Set detailIds = entity.getAccessContents().stream().map(OperAccessContentDTO::getId).filter(Objects::nonNull).collect(Collectors.toSet()); + List ids = existsDetails.stream().map(OperAccessContentEntity::getId).filter(id -> !detailIds.contains(id)).collect(Collectors.toList()); + if (!CollectionUtils.isEmpty(ids)) { + contentService.deleteLogic(ids); + } + // 明细添加/修改 + for (OperAccessContentDTO content : entity.getAccessContents()) { + content.setPlanId(entity.getId()); + if (ObjectUtil.isEmpty(content.getId())) { + contentService.doSave(content); + continue; + } + contentService.doUpdateById(content); + } + } + + + /** + * 开启检修计划流程 + * @param entity + */ + private void startProcess(AccessPlanV4DTO entity) { + Map variables = JSONObject.parseObject(JSONObject.toJSONString(entity), Map.class); + R result = flowClient.startProcessInstanceContainNameByKey("overhaul_plan", FlowUtil.getBusinessKey("access_plan_v4",String.valueOf(entity.getId())), entity.getName(), variables); + // 更新任务流程Id + if (result.isSuccess()) { + BladeFlow flow = result.getData(); + entity.setProcessInstanceId(flow.getProcessInstanceId()); + planService.updateById(entity); + } else { + throw new ServiceException("开启检修计划流程失败,code=" + result.getCode()); + } + } + + /** + * 检修计划流程监听 + * @param processWorkFlowResponse + * @return + */ + @Override + public boolean listener(ProcessWorkFlowResponse processWorkFlowResponse) { + Map variables = (Map) processWorkFlowResponse.getVariables(); + AccessPlanV4DTO entity = JSONObject.parseObject(variables.toString(), AccessPlanV4DTO.class); + entity.setTaskName(processWorkFlowResponse.getTaskName()); + entity.setNextStepOperator(processWorkFlowResponse.getNextStepOperator()); + if((Boolean) variables.get("pass")){ + entity.setTaskName("流程结束"); + entity.setNextStepOperator("流程结束,不需要人员处理"); + // 开启检修任务 + this.startTaskProcess(entity); + } + this.saveAccess(entity); + this.saveAccessMaterial(entity); + this.saveAccessContent(entity); + return true; + } + + /** + * 开启检修任务 + * @param entity + */ + private void startTaskProcess(AccessPlanV4DTO entity) { + for(OperAccessContentDTO item : entity.getAccessContents()){ + //任务参数 + AccessTaskV4DTO task = BeanUtil.copy(item, AccessTaskV4DTO.class); + task.setCreateTime(new Date()); + task.setCreateUser(entity.getCreateUser()); + task.setProcDefId(entity.getProcDefId()); + task.setHandler(item.getManager()); + task.setPlanId(entity.getId()); + task.setContentId(item.getId()); + task.setEmCode(item.getEmCode()); + // 任务详情 + if(CollectionUtil.isNotEmpty(item.getAccessContentDetails())){ + task.setAccessTaskDetails(item.getAccessContentDetails().stream().map(content -> { + OperAccessTaskDetailDTO detail = new OperAccessTaskDetailDTO(); + detail.setContentDetailId(content.getId()); + detail.setContent(content.getContent()); + detail.setName(content.getName()); + return detail; + }).collect(Collectors.toList())); + } + // 材料 + if(CollectionUtil.isNotEmpty(entity.getAccessMaterials())){ + task.setAccessMaterials(entity.getAccessMaterials().stream().map(o-> BeanUtil.copy(o,OperAccessMaterialDTO.class)).collect(Collectors.toList())); + } + accessTaskV4Service.startProcessV4(task); + } + } +} \ No newline at end of file diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/impl/AccessTaskV4ServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/impl/AccessTaskV4ServiceImpl.java new file mode 100644 index 0000000..6eed515 --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/impl/AccessTaskV4ServiceImpl.java @@ -0,0 +1,160 @@ +package com.hnac.hzims.operational.access.service.impl; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.hnac.hzims.common.to.process.ProcessWorkFlowResponse; +import com.hnac.hzims.operational.access.dto.AccessTaskV4DTO; +import com.hnac.hzims.operational.access.dto.OperAccessTaskDetailDTO; +import com.hnac.hzims.operational.access.entity.OperAccessMaterialEntity; +import com.hnac.hzims.operational.access.entity.OperAccessTaskDetailEntity; +import com.hnac.hzims.operational.access.service.AccessTaskV4Service; +import com.hnac.hzims.operational.access.service.IOperAccessMaterialService; +import com.hnac.hzims.operational.access.service.IOperAccessTaskDetailService; +import com.hnac.hzims.operational.access.service.IOperAccessTaskService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.RandomUtils; +import org.springblade.core.log.exception.ServiceException; +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.ObjectUtil; +import org.springblade.flow.core.entity.BladeFlow; +import org.springblade.flow.core.feign.IFlowClient; +import org.springblade.flow.core.utils.FlowUtil; +import org.springblade.flow.core.utils.TaskUtil; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; + +import java.text.DecimalFormat; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * @author ysj + */ +@Service +@Slf4j +@RequiredArgsConstructor +public class AccessTaskV4ServiceImpl implements AccessTaskV4Service { + + private final IOperAccessTaskService taskService; + + private final IOperAccessMaterialService materialService; + + private final IOperAccessTaskDetailService detailService; + + private final IFlowClient flowClient; + + /** + * 开启检修任务流程 + * @param entity + * @return + */ + @Override + @Transactional(rollbackFor = Exception.class) + public boolean startProcessV4(AccessTaskV4DTO entity) { + // 步骤1.保存检修任务 + this.save(entity); + + // 步骤2.保存检修材料 + this.saveMaterial(entity); + + // 步骤3.保存检修详情 + this.saveDetails(entity); + + // 步骤4.开启检修任务流程 + this.startProcess(entity); + return true; + } + + /** + * 开启检修流程 + * @param entity + */ + private void startProcess(AccessTaskV4DTO entity) { + Map variables = JSONObject.parseObject(JSONObject.toJSONString(entity), Map.class); + variables.put("handler",TaskUtil.getTaskUser(entity.getHandler().toString())); + R result = flowClient.startProcessInstanceContainNameByKey("overhaul_task", FlowUtil.getBusinessKey("access_task_v4", String.valueOf(entity.getId())), entity.getName(),variables); + // 更新任务流程Id + if (result.isSuccess()) { + BladeFlow flow = result.getData(); + entity.setProcessInstanceId(flow.getProcessInstanceId()); + taskService.updateById(entity); + } else { + throw new ServiceException("开启检修任务流程失败,code=" + result.getCode()); + } + } + + /** + * 检修任务保存 + * @param entity + */ + private void save(AccessTaskV4DTO entity) { + entity.setCode("TASK" + DateUtil.format(DateUtil.now(), DateUtil.PATTERN_DATETIME_MINI) + new DecimalFormat("###").format(RandomUtils.nextInt(0, 999))); + List materialEntityList = JSONObject.parseArray(JSON.toJSONString(entity.getAccessMaterials()), OperAccessMaterialEntity.class); + taskService.save(entity); + } + + /** + * 保存检修材料 + * @param entity + */ + private void saveMaterial(AccessTaskV4DTO entity) { + if (CollectionUtil.isNotEmpty(entity.getAccessMaterials())) { + return; + } + materialService.saveOrUpdateBatch(entity.getAccessMaterials().stream().peek(material -> { + material.setPlanId(null); + material.setId(null); + material.setTaskId(entity.getId()); + }).collect(Collectors.toList())); + } + + /** + * 保存检修对象 + * @param entity + * + */ + private void saveDetails(AccessTaskV4DTO entity) { + if(CollectionUtil.isEmpty(entity.getAccessTaskDetails())){ + return; + } + // 查询检修任务关联的检修对象 + List existsDetails = detailService.list(new LambdaQueryWrapper() {{ + eq(OperAccessTaskDetailEntity::getTaskId, entity.getId()); + eq(OperAccessTaskDetailEntity::getIsDeleted, 0L); + }}); + Set detailIds = entity.getAccessTaskDetails().stream().map(OperAccessTaskDetailDTO::getId).filter(Objects::nonNull).collect(Collectors.toSet()); + List ids = existsDetails.stream().map(OperAccessTaskDetailEntity::getId).filter(id -> !detailIds.contains(id)).collect(Collectors.toList()); + if (!CollectionUtils.isEmpty(ids)) { + detailService.deleteLogic(ids); + } + // 检修任务对象 + Set existsIds = existsDetails.stream().map(OperAccessTaskDetailEntity::getId).collect(Collectors.toSet()); + for (OperAccessTaskDetailDTO details : entity.getAccessTaskDetails()) { + details.setTaskId(entity.getId()); + if (ObjectUtil.isNotEmpty(entity.getId())) { + detailService.updateById(details); + continue; + } + detailService.doSave(details); + } + } + + /** + * 检修任务流程监听 + * @param processWorkFlowResponse + * @return + */ + @Override + public boolean listener(ProcessWorkFlowResponse processWorkFlowResponse) { + + return false; + } +} \ No newline at end of file