diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/constants/TreatMethodConstant.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/constants/TreatMethodConstant.java index faa3a8c..0760506 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/constants/TreatMethodConstant.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/constants/TreatMethodConstant.java @@ -10,6 +10,7 @@ public interface TreatMethodConstant { * 流程主键 */ String DEFECT_CHECK_PRIMARY_KEY = "defect_check"; + String DEFECT_CHECK_PRIMARY_KEY_TY = "defectDealty"; /** * 1-应急抢修处理 、2 - 检修任务处理 、 3- 检修计划处理 diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/entity/OperAppearanceEntity.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/entity/OperAppearanceEntity.java new file mode 100644 index 0000000..38bb8e1 --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/entity/OperAppearanceEntity.java @@ -0,0 +1,169 @@ +package com.hnac.hzims.operational.defect.entity; + +import com.baomidou.mybatisplus.annotation.SqlCondition; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.NullSerializer; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springblade.core.mp.support.QueryField; +import org.springblade.core.tenant.mp.TenantEntity; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; + + +/** + * 实体类 + * + * @author Chill + */ +@Data +@TableName("hzims_oper_appearance") +@EqualsAndHashCode(callSuper = true) +@ApiModel(value = "现象表", description = "现象表") +public class OperAppearanceEntity extends TenantEntity { + + private static final long serialVersionUID = 8353403086998937117L; + + /** + * 缺陷编码 + */ + @QueryField(condition = SqlCondition.LIKE) + @ApiModelProperty(value = "缺陷编码") + private String defectCode; + /** + * 问题来源:ZB:值班管理,RCWH:日常维护,XJ:巡检管理,JX:检修管理,ZNZD:智能诊断 + */ + @QueryField(condition = SqlCondition.EQUAL) + @ApiModelProperty(value = "问题来源: 数据字典:defectSource") + private String sourceCode; + + /** + * 问题发现人 + */ + @QueryField(condition = SqlCondition.EQUAL) + @JsonSerialize(nullsUsing = NullSerializer.class) + @ApiModelProperty(value = "问题发现人") + private Long finder; + /** + * 问题类型: + * + */ + @QueryField(condition = SqlCondition.EQUAL) + @ApiModelProperty(value = "问题类型:字典key : defectType") + private String typeCode; + /** + * 发现时间 + */ + @DateTimeFormat( + pattern = "yyyy-MM-dd HH:mm:ss" + ) + @JsonFormat( + pattern = "yyyy-MM-dd HH:mm:ss" + ) + @ApiModelProperty(value = "发现时间") + private Date findTime; + + /** + * 名称 + */ + @QueryField(condition = SqlCondition.LIKE) + @ApiModelProperty(value = "名称,如果是设备则是设备名称。") + private String name; + /** + * 设备编号 + */ + @QueryField(condition = SqlCondition.LIKE) + @ApiModelProperty(value = "设备编号") + private String emCode; + /** + * 故障编码 + */ + @QueryField(condition = SqlCondition.LIKE) + @ApiModelProperty(value = "故障缺陷编码") + private String faultCode; + /** + * 故障名称 + */ + @QueryField(condition = SqlCondition.LIKE) + @ApiModelProperty(value = "故障缺陷名称") + private String faultName; + /** + * 现象描述 + */ + @ApiModelProperty(value = "现象描述") + private String descripiton; + /** + * 故障文件附件,多个文件url通过,隔开 + */ + @ApiModelProperty(value = "现象文件附件,多个文件url通过,隔开") + private String fileUrls; + /** + * 初步分析结果 + */ + @ApiModelProperty(value = "初步分析结果") + private String initResult; + + + /** + * 甄别人 + */ + @JsonSerialize(nullsUsing = NullSerializer.class) + @ApiModelProperty(value = "甄别人") + private Long discriminator; + /** + * 甄别时间 + */ + @DateTimeFormat( + pattern = "yyyy-MM-dd HH:mm:ss" + ) + @JsonFormat( + pattern = "yyyy-MM-dd HH:mm:ss" + ) + @ApiModelProperty(value = "甄别时间") + private Date discriminateTime; + + + + /** + * 甄别状态:已甄别 1 和未甄别 0 ,默认0 + */ + @QueryField(condition = SqlCondition.EQUAL) + @ApiModelProperty(value = "甄别状态:已甄别 1 和未甄别 0 ,默认0") + private String discriminateStatus; + + /** + * 是否为缺陷 + */ + @QueryField(condition = SqlCondition.EQUAL) + @JsonSerialize(nullsUsing = NullSerializer.class) + @ApiModelProperty(value = "是否为缺陷,0 否,1是") + private Integer isDefect; + /** + * 甄别描述 + */ + @ApiModelProperty(value = "甄别描述") + private String discriminateDesc; + /** + * 备注(冗余) + */ + @ApiModelProperty(value = "备注(冗余)") + private String remark; + + /** + * 是否使用智能诊断 + */ + @JsonSerialize(nullsUsing = NullSerializer.class) + @ApiModelProperty(value = "是否使用智能诊断") + private Integer isDiagnosis; + /** + * 智能诊断任务ID + */ + @JsonSerialize(nullsUsing = NullSerializer.class) + @ApiModelProperty(value = "智能诊断任务ID") + private Long diagnosisId; +} diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/entity/OperDefectEntity.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/entity/OperDefectEntity.java index c4b174c..ac995bc 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/entity/OperDefectEntity.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/entity/OperDefectEntity.java @@ -4,17 +4,18 @@ import com.baomidou.mybatisplus.annotation.SqlCondition; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonFormat; -import org.springblade.core.mp.support.QueryField; -import org.springblade.core.tenant.mp.TenantEntity; -import lombok.Data; -import lombok.EqualsAndHashCode; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.NullSerializer; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springblade.core.mp.support.QueryField; +import org.springblade.core.tenant.mp.TenantEntity; import org.springframework.format.annotation.DateTimeFormat; import java.time.YearMonth; import java.util.Date; -import java.util.List; /** @@ -89,16 +90,17 @@ public class OperDefectEntity extends TenantEntity { private String disposeDesc; @TableField(exist = false) - @ApiModelProperty(value = "开始时间") + @ApiModelProperty(value = "缺陷创建时间-开始时间") private String startTime; @TableField(exist = false) - @ApiModelProperty(value = "结束时间") + @ApiModelProperty(value = "缺陷创建时间-结束时间") private String endTime; - @TableField(exist = false) - @ApiModelProperty(value = "机构编号集合") - private List deptIds; +// 20230612弃用该字段,无地方引用 +// @TableField(exist = false) +// @ApiModelProperty(value = "机构编号集合") +// private List deptIds; /** @@ -113,4 +115,55 @@ public class OperDefectEntity extends TenantEntity { @ApiModelProperty(value = "年月") @TableField(exist = false) private YearMonth yearMonth; + /** + * 计划处理人 + */ + @JsonSerialize(nullsUsing = NullSerializer.class) + @ApiModelProperty(value = "计划处理人") + private String planHandler; + /** + * 处理结论 + */ + @JsonSerialize(nullsUsing = NullSerializer.class) + @ApiModelProperty(value = "处理结论") + private String handlerConclusion; + + /** + * 缺陷等级 + */ + @JsonSerialize(nullsUsing = NullSerializer.class) + @ApiModelProperty(value = "缺陷等级") + private String defectGrading; + /** + * 定论词条 + */ + @JsonSerialize(nullsUsing = NullSerializer.class) + @ApiModelProperty(value = "定论词条") + private String conclusionLabel; + + /** + * 备注(冗余) + */ + @JsonSerialize(nullsUsing = NullSerializer.class) + @ApiModelProperty(value = "备注(冗余)") + private String remark; + /** + * 是否使用智能诊断 + */ + @JsonSerialize(nullsUsing = NullSerializer.class) + @ApiModelProperty(value = "是否使用智能诊断") + private Integer isDiagnosis; + /** + * 智能诊断任务ID + */ + @JsonSerialize(nullsUsing = NullSerializer.class) + @ApiModelProperty(value = "智能诊断任务ID") + private Long diagnosisId; + /** + * 已有缺陷编码 + */ + @JsonSerialize(nullsUsing = NullSerializer.class) + @ApiModelProperty(value = "已有缺陷编码") + private String existDefectId; + } diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/entity/OperDefectStatisticsEntity.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/entity/OperDefectStatisticsEntity.java index d241884..68779a2 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/entity/OperDefectStatisticsEntity.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/entity/OperDefectStatisticsEntity.java @@ -5,16 +5,15 @@ import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.NullSerializer; -import org.springblade.core.mp.support.QueryField; -import org.springblade.core.tenant.mp.TenantEntity; -import lombok.Data; -import lombok.EqualsAndHashCode; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springblade.core.mp.support.QueryField; +import org.springblade.core.tenant.mp.TenantEntity; import org.springframework.format.annotation.DateTimeFormat; import java.util.Date; -import java.time.LocalDateTime; /** @@ -227,4 +226,60 @@ public class OperDefectStatisticsEntity extends TenantEntity { @ApiModelProperty(value = "定论时间") private Date conclusionTime; + /** + * 计划处理人 + */ + @JsonSerialize(nullsUsing = NullSerializer.class) + @ApiModelProperty(value = "计划处理人") + private String planHandler; + + /** + * 处理结论 + */ + @JsonSerialize(nullsUsing = NullSerializer.class) + @ApiModelProperty(value = "处理结论") + private String handlerConclusion; + /** + * 是否入库 + */ + @JsonSerialize(nullsUsing = NullSerializer.class) + @ApiModelProperty(value = "是否入库") + private Boolean isWarehousing; + /** + * 当前处理环节 + */ + @JsonSerialize(nullsUsing = NullSerializer.class) + @ApiModelProperty(value = "当前处理环节") + private String currentOperator; + /** + * 当前环节处理人 + */ + @JsonSerialize(nullsUsing = NullSerializer.class) + @ApiModelProperty(value = "当前环节处理人") + private String currentLinkHandler; + /** + * 备注(冗余) + */ + @JsonSerialize(nullsUsing = NullSerializer.class) + @ApiModelProperty(value = "备注(冗余)") + private String remark; + /** + * 是否使用智能诊断 + */ + @JsonSerialize(nullsUsing = NullSerializer.class) + @ApiModelProperty(value = "是否使用智能诊断") + private Integer isDiagnosis; + /** + * 智能诊断任务ID + */ + @JsonSerialize(nullsUsing = NullSerializer.class) + @ApiModelProperty(value = "智能诊断任务ID") + private Long diagnosisId; + /** + * 已有缺陷编码 + */ + @JsonSerialize(nullsUsing = NullSerializer.class) + @ApiModelProperty(value = "已有缺陷编码") + private String existDefectId; + } diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/entity/OperPhenomenonEntity.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/entity/OperPhenomenonEntity.java index bbcd030..e4ced33 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/entity/OperPhenomenonEntity.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/entity/OperPhenomenonEntity.java @@ -1,23 +1,19 @@ package com.hnac.hzims.operational.defect.entity; import com.baomidou.mybatisplus.annotation.SqlCondition; -import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.NullSerializer; -import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; -import org.springblade.core.mp.support.QueryField; -import org.springblade.core.tenant.mp.TenantEntity; -import lombok.Data; -import lombok.EqualsAndHashCode; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springblade.core.mp.support.QueryField; +import org.springblade.core.tenant.mp.TenantEntity; import org.springframework.format.annotation.DateTimeFormat; -import java.time.YearMonth; import java.util.Date; -import java.time.LocalDateTime; /** @@ -28,7 +24,7 @@ import java.time.LocalDateTime; @Data @TableName("hzims_oper_phenomenon") @EqualsAndHashCode(callSuper = true) -@ApiModel(value = "问题现象表", description = "问题现象表") +@ApiModel(value = "问题现象全表", description = "问题现象全表") public class OperPhenomenonEntity extends TenantEntity { private static final long serialVersionUID = 8353403086998937117L; @@ -54,7 +50,7 @@ public class OperPhenomenonEntity extends TenantEntity { /** * 甄别流程实例 */ - @ApiModelProperty(value = "甄别流程实例") + @ApiModelProperty(value = "流程实例") private String checkProcessInstanceId; /** * 问题发现人 @@ -64,7 +60,7 @@ public class OperPhenomenonEntity extends TenantEntity { @ApiModelProperty(value = "问题发现人") private Long finder; /** - * 问题类型: + * 问题类型:0-设备和1-非设备。 * */ @QueryField(condition = SqlCondition.EQUAL) @@ -287,4 +283,100 @@ public class OperPhenomenonEntity extends TenantEntity { @JsonSerialize(nullsUsing = NullSerializer.class) @ApiModelProperty(value = "核算工时") private Integer checkHours; + /** + * 计划处理人 + */ + @JsonSerialize(nullsUsing = NullSerializer.class) + @ApiModelProperty(value = "计划处理人") + private String planHandler; + /** + * 实际开始时间 + */ + @DateTimeFormat( + pattern = "yyyy-MM-dd HH:mm:ss" + ) + @JsonFormat( + pattern = "yyyy-MM-dd HH:mm:ss" + ) + @ApiModelProperty(value = "实际开始时间") + private Date actStartTime; + + /** + * 实际结束时间 + */ + @DateTimeFormat( + pattern = "yyyy-MM-dd HH:mm:ss" + ) + @JsonFormat( + pattern = "yyyy-MM-dd HH:mm:ss" + ) + @ApiModelProperty(value = "实际结束时间") + private Date actEndTime; + /** + * 处理结论 + */ + @JsonSerialize(nullsUsing = NullSerializer.class) + @ApiModelProperty(value = "处理结论") + private String handlerConclusion; + /** + * 是否入库 + */ + @JsonSerialize(nullsUsing = NullSerializer.class) + @ApiModelProperty(value = "是否入库") + private Boolean isWarehousing; + /** + * 缺陷等级 + */ + @JsonSerialize(nullsUsing = NullSerializer.class) + @ApiModelProperty(value = "缺陷等级") + private String defectGrading; + /** + * 定论词条 + */ + @JsonSerialize(nullsUsing = NullSerializer.class) + @ApiModelProperty(value = "定论词条") + private String conclusionLabel; + /** + * 当前处理环节 + */ + @JsonSerialize(nullsUsing = NullSerializer.class) + @ApiModelProperty(value = "当前处理环节") + private String currentOperator; + /** + * 当前环节处理人 + */ + @JsonSerialize(nullsUsing = NullSerializer.class) + @ApiModelProperty(value = "当前环节处理人") + private String currentLinkHandler; + /** + * 备注(冗余) + */ + @JsonSerialize(nullsUsing = NullSerializer.class) + @ApiModelProperty(value = "备注(冗余)") + private String remark; + /** + * 是否使用智能诊断 + */ + @JsonSerialize(nullsUsing = NullSerializer.class) + @ApiModelProperty(value = "是否使用智能诊断") + private Integer isDiagnosis; + /** + * 智能诊断任务ID + */ + @JsonSerialize(nullsUsing = NullSerializer.class) + @ApiModelProperty(value = "智能诊断任务ID") + private Long diagnosisId; + /** + * 已有缺陷编码 + */ + @JsonSerialize(nullsUsing = NullSerializer.class) + @ApiModelProperty(value = "已有缺陷编码") + private String existDefectId; + /** + * 现象名称 + */ + @QueryField(condition = SqlCondition.LIKE) + @ApiModelProperty(value = "现象名称") + private String defectName; + } diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/feign/Fallback/IOperDefectClientFallback.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/feign/Fallback/IOperDefectClientFallback.java index 5419761..421f3a9 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/feign/Fallback/IOperDefectClientFallback.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/feign/Fallback/IOperDefectClientFallback.java @@ -1,5 +1,6 @@ package com.hnac.hzims.operational.defect.feign.Fallback; +import com.hnac.hzims.middle.process.to.ProcessWorkFlowResponse; import com.hnac.hzims.operational.defect.entity.OperDefectEntity; import com.hnac.hzims.operational.defect.entity.OperPhenomenonEntity; import com.hnac.hzims.operational.defect.feign.IOperDefectClient; @@ -34,4 +35,9 @@ public class IOperDefectClientFallback implements IOperDefectClient { log.error("远程调用失败,接口:" + CREATE_DEFECT); return null; } + @Override + public R saveDefect(ProcessWorkFlowResponse processWorkFlowResponse) { + log.error("远程调用失败,接口:" + SAVE_DEFECT); + return null; + } } diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/feign/IOperDefectClient.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/feign/IOperDefectClient.java index f8fc74c..b3ff803 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/feign/IOperDefectClient.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/feign/IOperDefectClient.java @@ -1,6 +1,6 @@ package com.hnac.hzims.operational.defect.feign; - +import com.hnac.hzims.middle.process.to.ProcessWorkFlowResponse; import com.hnac.hzims.operational.OperationalConstants; import com.hnac.hzims.operational.defect.entity.OperDefectEntity; import com.hnac.hzims.operational.defect.entity.OperPhenomenonEntity; @@ -26,6 +26,8 @@ public interface IOperDefectClient { String UPDATE_DEFECT_HANDLER_STATE = API_PREFIX + "/updateDefectHandlerState"; String CREATE_DEFECT = API_PREFIX + "/createDefect"; + String SAVE_DEFECT = API_PREFIX + "/saveDefect"; + /** * 修改缺陷信息 * @param entity @@ -39,4 +41,10 @@ public interface IOperDefectClient { @PostMapping(CREATE_DEFECT) R createDefect(@RequestBody OperPhenomenonEntity phenomenon); + + @PostMapping(SAVE_DEFECT) + R saveDefect(@RequestBody ProcessWorkFlowResponse processWorkFlowResponse); + + + } diff --git a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/MessageConstants.java b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/MessageConstants.java index 6741a3f..4d55a16 100644 --- a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/MessageConstants.java +++ b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/MessageConstants.java @@ -1,7 +1,6 @@ package com.hnac.hzims.message; import lombok.AllArgsConstructor; -import lombok.Data; import lombok.Getter; import lombok.NoArgsConstructor; @@ -55,6 +54,7 @@ public class MessageConstants { ACCESS("access","检修消息"), TICKETMESSAGE("ticket-message","工作票消息"), OPERATIONTICKETMESSAGE("operation-ticket-message","操作票消息"), + OPERATIONDEFECTMESSAGE("operation-defect-message","消缺消息"), ; @Getter private String key; diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/controller/DefectCheckController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/controller/DefectCheckController.java index 660d34e..4f93ac5 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/controller/DefectCheckController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/controller/DefectCheckController.java @@ -5,17 +5,16 @@ import com.hnac.hzims.operational.defect.entity.OperPhenomenonEntity; import com.hnac.hzims.operational.defect.service.IDefectCheckService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; import lombok.AllArgsConstructor; import org.springblade.core.boot.ctrl.BladeController; import org.springblade.core.log.annotation.ApiLog; import org.springblade.core.tool.api.R; import org.springblade.flow.core.vo.ComleteTask; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; - -import javax.validation.Valid; -import javax.validation.constraints.NotNull; +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 diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/feign/OperDefectClient.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/feign/OperDefectClient.java index 2841984..33366bf 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/feign/OperDefectClient.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/feign/OperDefectClient.java @@ -1,12 +1,13 @@ package com.hnac.hzims.operational.defect.feign; + +import com.hnac.hzims.middle.process.to.ProcessWorkFlowResponse; import com.hnac.hzims.operational.defect.entity.OperDefectEntity; import com.hnac.hzims.operational.defect.entity.OperPhenomenonEntity; import com.hnac.hzims.operational.defect.service.IDefectCheckService; import com.hnac.hzims.operational.defect.service.IOperDefectService; import lombok.AllArgsConstructor; import org.springblade.core.tool.api.R; -import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; @@ -32,8 +33,15 @@ public class OperDefectClient implements IOperDefectClient { return R.data(service.updateDefectHanderState(entity)); } + @PostMapping(CREATE_DEFECT) @Override public R createDefect(@RequestBody OperPhenomenonEntity entity) { return R.data(defectCheckService.startCheck(entity)); } + + @PostMapping(SAVE_DEFECT) + @Override + public R saveDefect(@RequestBody ProcessWorkFlowResponse processWorkFlowResponse) { + return defectCheckService.listenAndUpdateDefect(processWorkFlowResponse); + } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/mapper/OperAppearanceMapper.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/mapper/OperAppearanceMapper.java new file mode 100644 index 0000000..5e6b381 --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/mapper/OperAppearanceMapper.java @@ -0,0 +1,14 @@ +package com.hnac.hzims.operational.defect.mapper; + +import com.hnac.hzims.operational.defect.entity.OperAppearanceEntity; +import org.springblade.core.datascope.mapper.UserDataScopeBaseMapper; + +/** + * Mapper 接口 + * + * @author Chill + */ +public interface OperAppearanceMapper extends UserDataScopeBaseMapper { + + +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/mapper/OperAppearanceMapper.xml b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/mapper/OperAppearanceMapper.xml new file mode 100644 index 0000000..4fbcacd --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/mapper/OperAppearanceMapper.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/IDefectCheckService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/IDefectCheckService.java index 54479d2..8869659 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/IDefectCheckService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/IDefectCheckService.java @@ -1,7 +1,9 @@ package com.hnac.hzims.operational.defect.service; +import com.hnac.hzims.middle.process.to.ProcessWorkFlowResponse; import com.hnac.hzims.operational.defect.entity.OperPhenomenonEntity; import org.springblade.core.mp.base.BaseService; +import org.springblade.core.tool.api.R; import org.springblade.flow.core.vo.ComleteTask; @@ -42,6 +44,7 @@ public interface IDefectCheckService extends BaseService { * @param task */ void conclusion(ComleteTask task); + R listenAndUpdateDefect(ProcessWorkFlowResponse processWorkFlowResponse); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/IOperAppearanceService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/IOperAppearanceService.java new file mode 100644 index 0000000..0b28cbb --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/IOperAppearanceService.java @@ -0,0 +1,13 @@ +package com.hnac.hzims.operational.defect.service; + +import com.hnac.hzims.operational.defect.entity.OperAppearanceEntity; +import org.springblade.core.mp.base.BaseService; + +/** + * 服务类 + * + * @author Chill + */ +public interface IOperAppearanceService extends BaseService { + +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/impl/DefectCheckServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/impl/DefectCheckServiceImpl.java index 0311a6d..54d09c8 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/impl/DefectCheckServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/impl/DefectCheckServiceImpl.java @@ -4,25 +4,34 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.hnac.hzims.common.logs.utils.StringUtils; import com.hnac.hzims.fdp.feign.IFdpTaskClient; +import com.hnac.hzims.message.MessageConstants; +import com.hnac.hzims.message.dto.MessagePushRecordDto; +import com.hnac.hzims.message.fegin.IMessageClient; +import com.hnac.hzims.middle.process.to.ProcessWorkFlowResponse; import com.hnac.hzims.operational.access.dto.OperAccessPlanDTO; import com.hnac.hzims.operational.access.dto.OperAccessTaskDTO; import com.hnac.hzims.operational.access.service.IOperAccessPlanService; import com.hnac.hzims.operational.access.service.IOperAccessTaskService; -import com.hnac.hzims.operational.defect.config.DefectConfiguration; import com.hnac.hzims.operational.defect.constants.RepairConstant; import com.hnac.hzims.operational.defect.constants.TreatMethodConstant; +import com.hnac.hzims.operational.defect.entity.OperAppearanceEntity; import com.hnac.hzims.operational.defect.entity.OperDefectEntity; import com.hnac.hzims.operational.defect.entity.OperDefectStatisticsEntity; import com.hnac.hzims.operational.defect.entity.OperPhenomenonEntity; import com.hnac.hzims.operational.defect.mapper.OperPhenomenonMapper; import com.hnac.hzims.operational.defect.service.IDefectCheckService; +import com.hnac.hzims.operational.defect.service.IOperAppearanceService; import com.hnac.hzims.operational.defect.service.IOperDefectService; import com.hnac.hzims.operational.defect.service.IOperDefectStatisticsService; import com.hnac.hzims.ticket.repair.entity.RepairEntity; import com.hnac.hzims.ticket.repair.fegin.IRepairClient; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.math.NumberUtils; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.mp.base.BaseServiceImpl; import org.springblade.core.secure.utils.AuthUtil; @@ -34,6 +43,7 @@ import org.springblade.flow.core.feign.IFlowClient; import org.springblade.flow.core.utils.FlowUtil; import org.springblade.flow.core.vo.ComleteTask; import org.springblade.system.cache.DictCache; +import org.springblade.system.feign.ISysClient; import org.springblade.system.user.cache.UserCache; import org.springblade.system.user.entity.User; import org.springblade.system.user.feign.IUserClient; @@ -41,6 +51,11 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.Assert; +import java.beans.BeanInfo; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.*; @@ -53,549 +68,774 @@ import java.util.stream.Collectors; * @author ysj */ @Service +@Slf4j @RequiredArgsConstructor public class DefectCheckServiceImpl extends BaseServiceImpl implements IDefectCheckService { - private final IOperAccessTaskService operAccessTaskService; - - private final IOperAccessPlanService operAccessPlanService; - - private final IOperDefectStatisticsService statisticsService; - private final IOperDefectService defectService; - - private final IOperAccessPlanService accessPlanService; - - private final OperPhenomenonMapper phenomenonMapper; - - private final IFlowClient processClient; - - private final IUserClient userClient; - - private final IFdpTaskClient fdpTaskClient; - - - private final IRepairClient repairClient; - - /** - * 保存现象、开启缺陷处理流程 - * @param entity - * @return - */ - @Override - @Transactional(rollbackFor = Exception.class) - public OperPhenomenonEntity startCheck(OperPhenomenonEntity entity) { - // 步骤1.保存现象 - if(!this.savePhenomenon(entity)){ - throw new ServiceException("保存现象失败!"); - } - // 步骤2.开启缺陷流程 - this.startDefectCheck(entity); - return entity; - } - - /** - * 保存现象 - * @param entity - * @return - */ - private boolean savePhenomenon(OperPhenomenonEntity entity) { - DateTimeFormatter format = DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME_MINI); - // 缺陷编码 : 缺陷来源 + 时间格式化 + 三位长度随机值 - if(Func.isEmpty(entity.getDefectCode())){ - entity.setDefectCode(entity.getSourceCode() + format.format(LocalDateTime.now()) + Func.random(3)); - } - // 现象发起人 : 当前用户Id - if(Func.isEmpty(entity.getFinder())){ - entity.setFinder(AuthUtil.getUserId()); - } - // 现象发起时间 - entity.setFindTime(new Date()); - // 现象更新时间 - entity.setUpdateTime(new Date()); - // 现在最后甄别时间 - Date discriminateDeadline = DateUtil.plusHours(entity.getUpdateTime(), DefectConfiguration.discriminateDeadline); - entity.setDiscriminateDeadline(discriminateDeadline); - return this.save(entity); - } - - /** - * 启动缺陷处理流程 - * @param entity - */ - private void startDefectCheck(OperPhenomenonEntity entity) { - // 获取机构下执行定论缺陷角色用户 - List list = this.getAliasUser(entity.getTenantId(),entity.getCreateDept(),TreatMethodConstant.PHENOMENON_SCREEN_ALIAS); - if(CollectionUtil.isEmpty(list)){ - throw new ServiceException("请先添加甄别缺陷角色用户,再发起现象!"); - } - List userList = list.stream().map(o -> "taskUser_" + o.getId().toString()).collect(Collectors.toList()); - // 现象发起人名字 - String userName = Optional.ofNullable(UserCache.getUser(entity.getFinder()).getName()).orElse(""); - // 现象发起来源 - String sourceName = DictCache.getValue(TreatMethodConstant.SOURCE_CODE_PREFIX,entity.getSourceCode()); - // 流程名称 - String processName = "[" + userName + "] 发起 " + "【" + sourceName + "】缺陷处理流程" +"——>" + entity.getDefectCode(); - // 设置下一步执行流程用户 - Kv variables = Kv.create() - .set(TreatMethodConstant.PHENOMENON_SCREEN_USER,String.join(",", userList)); - // 开启新的缺陷流程 - R result = processClient.startProcessInstanceContainNameByKey(TreatMethodConstant.DEFECT_CHECK_PRIMARY_KEY, FlowUtil.getBusinessKey("hzims_oper_phenomenon","" + entity.getId()), processName, variables); - // 流程开启失败 - if (!result.isSuccess()) { - throw new ServiceException("缺陷流程开启失败,错误描述 : " + result.getCode()); - } - // 关联流程唯一键 - entity.setCheckProcessInstanceId(result.getData().getProcessInstanceId()); - this.baseMapper.updateById(entity); - } - - - /** - * 获取当前机构指定角色的用户 - * @param tenantId - * @param deptId - * @param alias - * @return - */ - public List getAliasUser(String tenantId,Long deptId,String alias){ - if(Func.isEmpty(tenantId)){ - tenantId = AuthUtil.getTenantId(); - } - R> result = userClient.relationUserListByRoleAlias(tenantId, deptId, alias); - if(!result.isSuccess()){ - throw new ServiceException("查询角色用户信息失败!"); - } - return result.getData(); - } - - /** - * 修改缺陷状态 -> 问题定论 - * @param handleStatus - * @param defectCode - */ - private void updateDefectHandleState(String handleStatus, String defectCode) { - this.defectService.update(Wrappers.lambdaUpdate() - .set(OperDefectEntity::getHandleStatus,handleStatus) - .eq(OperDefectEntity::getDefectCode,defectCode) - ); - } - - - /** - * 甄别缺陷 - * @param task - * @return - */ - @Override - @Transactional(rollbackFor = Exception.class) - public void screeDefect(ComleteTask task) { - // 步骤1.现象前置判断(现象状态检查) - OperPhenomenonEntity entity = this.preposePhenomenon(task.getProcessInstanceId()); - - // 步骤2.更新甄别状态、数据 - this.screePhenomenonUpdate(task); - - // 步骤3.现象添加至缺陷库 - this.defectSave(entity); - - // 步骤4.流程执行至甄别处理方式 - processClient.completeTask(task); - } - - /** - * 现象前置判断 - * @param processInstanceId - * @return - */ - private OperPhenomenonEntity preposePhenomenon(String processInstanceId) { - LambdaQueryWrapper wrapper = new LambdaQueryWrapper() {{ - eq(OperPhenomenonEntity::getCheckProcessInstanceId, processInstanceId); - }}; - // 查询现象状态 - OperPhenomenonEntity entity = this.getOne(wrapper); - if(ObjectUtil.isEmpty(entity)){ - throw new ServiceException("现象不存在"); - } - // 现象已被自动甄别 - if(TreatMethodConstant.AUTO_SCREENED.equals(entity.getAutoDiscriminateStatus())){ - throw new ServiceException("该现象已经自动甄别"); - } - // 现象已被手动动甄别 - if(TreatMethodConstant.SCREENED.equals(entity.getDiscriminateStatus())){ - throw new ServiceException("该现象已甄别"); - } - return entity; - } - - /** - * 缺陷保存 - * @param phenomenon - */ - private void defectSave(OperPhenomenonEntity phenomenon) { - OperDefectEntity defect = new OperDefectEntity(); - defect.setHandleStatus(RepairConstant.DEFAULT_DEFECT_STATE); - defect.setProcessInstanceId(phenomenon.getCheckProcessInstanceId()); - defect.setDefectCode(phenomenon.getDefectCode()); - defect.setCreateUser(phenomenon.getCreateUser()); - defect.setCreateDept(phenomenon.getCreateDept()); - defect.setTenantId(phenomenon.getTenantId()); - this.defectService.save(defect); - } - - /** - * 更新甄别状态、数据 - * @param task - */ - private void screePhenomenonUpdate(ComleteTask task) { - // 查询流程状态 - String processStatus = TreatMethodConstant.RUNNING; - R result = processClient.queryProcessInstanceStatus(task.getProcessInstanceId()); - if(result.isSuccess() && StringUtil.isNotBlank(result.getData()) && TreatMethodConstant.PROCESS_STATE_OVER.equals(result.getData())){ - processStatus = TreatMethodConstant.PROCESS_STATE_OVER; - } - // 获取参数集 - Map variables = task.getVariables(); - boolean invalid = (boolean) variables.get("invalid"); - LambdaUpdateWrapper lambdaUpdate = Wrappers.lambdaUpdate(); - if(invalid){ - lambdaUpdate - .set(OperPhenomenonEntity::getStatus,processStatus) - .set(OperPhenomenonEntity::getIsDefect, TreatMethodConstant.IS_DEFECT) - .set(OperPhenomenonEntity::getAutoDiscriminateStatus, TreatMethodConstant.ORDINARY_SCREENED) - .set(OperPhenomenonEntity::getDiscriminator, AuthUtil.getUserId()) - .set(OperPhenomenonEntity::getDiscriminateTime, new Date()) - .set(OperPhenomenonEntity::getDiscriminateStatus,variables.get("discriminateStatus").toString()) - .set(OperPhenomenonEntity::getDiscriminateDesc, Optional.ofNullable(variables.get("discriminateDesc")).map(Object::toString).orElse(null)) - .set(OperPhenomenonEntity::getSafeInfos, variables.get("safeInfos").toString()) - .set(OperPhenomenonEntity::getWorkStandards, Optional.ofNullable(variables.get("workStandards")).map(Object::toString).orElse(null)) - .set(OperPhenomenonEntity::getHandleProgramme, variables.get("handleProgramme").toString().substring(9)) - .set(OperPhenomenonEntity::getPlanHours, variables.get("planHours").toString()) - .set(OperPhenomenonEntity::getPlanStartTime, variables.get("planStartTime").toString()) - .set(OperPhenomenonEntity::getPlanEndTime, variables.get("planEndTime").toString()) - .set(OperPhenomenonEntity::getDefectLevel, variables.get("defectLevel").toString()) - .eq(OperPhenomenonEntity::getCheckProcessInstanceId,task.getProcessInstanceId()); - }else{ - lambdaUpdate - .set(OperPhenomenonEntity::getStatus,processStatus) - .set(OperPhenomenonEntity::getIsDefect, TreatMethodConstant.NO_DEFECT) - .set(OperPhenomenonEntity::getDiscriminateStatus,variables.get("discriminateStatus").toString()) - .set(OperPhenomenonEntity::getDiscriminator, AuthUtil.getUserId()) - .set(OperPhenomenonEntity::getDiscriminateTime, new Date()) - .set(OperPhenomenonEntity::getDiscriminateDesc, variables.get("discriminateDesc").toString()) - .eq(OperPhenomenonEntity::getCheckProcessInstanceId,task.getProcessInstanceId()); - } - this.update(lambdaUpdate); - } - - /** - * 决策处理方式 - * @param task - * @return - */ - @Override - @Transactional(rollbackFor = Exception.class) - public void treatmentMethod(ComleteTask task) { - // 步骤1.获取参数集 - Map variables = task.getVariables(); - - // 步骤2.根据处理方式进行处理 - String state = RepairConstant.REPAIR_DEFECT_STATE,processKey = RepairConstant.REPAIR_PROCESS_PRIMARY_KEY - ,type = variables.get("type").toString(); - switch (type){ - // 应急抢修处理 - case TreatMethodConstant.TYPE_RUSH_TO_REPAIR: - this.startRepair(task,variables); - break; - // 检修计划处理 - case TreatMethodConstant.TYPE_PLAN: - state = RepairConstant.ACCESS_PLAN_STATE; - this.startMaintenancePlan(task,variables); - break; - // 检修任务处理 - case TreatMethodConstant.TYPE_TASK: - state = RepairConstant.ACCESS_TASK_STATE; - this.startMaintenanceTask(task); - break; - default: - throw new IllegalStateException("Unexpected type: " + type); - } - // 步骤3.关联处理任务 - this.relationHandlerTask(variables,type,task.getProcessInstanceId(),state); - - // 步骤4.缺陷库保存处理任务信息 - this.saveDefectInfo(variables,task.getProcessInstanceId(),processKey,state); - - // 步骤5.流程执行 -> 处理缺陷 - processClient.completeTask(task); - } - - /** - * 启动应急抢修流程 - * @param variables - */ - private void startRepair(ComleteTask task,Map variables) { - String json = JSON.toJSONString(variables.get("repair")); - RepairEntity entity = JSONObject.parseObject(json, RepairEntity.class); - R result = repairClient.startRepair(entity); - if(!result.isSuccess()){ - throw new ServiceException("开启检修任务流程失败!"); - } - variables.put("handlerTaskId",result.getData().getId()); - variables.put("handlerType",TreatMethodConstant.REPAIR); - variables.put("handlerProcessInstanceId",result.getData().getProcessInstanceId()); - variables.put("handlerUserId",result.getData().getCharge()); - variables.put(TreatMethodConstant.DEFECT_HANDLER_USER,"taskUser_" + result.getData().getCharge()); - task.setVariables(variables); - } - - /** - * 开启检修计划 - * @param variables - */ - private void startMaintenancePlan(ComleteTask task,Map variables) { - String json = JSON.toJSONString(variables.get("accessPlan")); - OperAccessPlanDTO accessPlan = JSONObject.parseObject(json,OperAccessPlanDTO.class); - // 查询现象 - OperPhenomenonEntity phenomenon = this.getOne(new LambdaQueryWrapper() {{ - eq(OperPhenomenonEntity::getCheckProcessInstanceId, task.getProcessInstanceId()); - }}); - - // 查询缺陷 - OperDefectEntity defect = this.defectService.getOne(Wrappers.lambdaUpdate().eq(OperDefectEntity::getDefectCode, phenomenon.getDefectCode())); - accessPlan.setDefectId(defect.getId()); - accessPlan.setPhenomenonId(phenomenon.getId()); - accessPlan.setActStartTime(DateUtil.now()); - // 计划草稿 - R result = operAccessPlanService.doSave(accessPlan); - if(!result.isSuccess()){ - throw new ServiceException("开启检修计划失败"); - } - // 计划流程开启 - accessPlanService.handlePlan(accessPlan,null); - variables.put("handlerTaskId",accessPlan.getId()); - variables.put("handlerProcessInstanceId",accessPlan.getProcessInstanceId()); - variables.put("handlerUserId",AuthUtil.getUserId()); - variables.put("handlerType",TreatMethodConstant.MAINTENANCE_PLAN); - variables.put("actStartTime",accessPlan.getActStartTime()); - variables.put(TreatMethodConstant.DEFECT_HANDLER_USER,"taskUser_" + AuthUtil.getUserId()); - task.setVariables(variables); - } - - /** - * 开启检修任务 - * @param comleteTask - */ - @Transactional(rollbackFor = Exception.class) - public void startMaintenanceTask(ComleteTask comleteTask) { - Assert.isTrue(CollectionUtil.isNotEmpty(comleteTask.getVariables()) && ObjectUtil.isNotEmpty(comleteTask.getVariables().get("accessTask")),()->{ - throw new ServiceException("检修任务信息不能为空!"); - }); - Map variables = comleteTask.getVariables(); - OperAccessTaskDTO accessTask = JSONObject.parseObject(JSON.toJSONString(variables.get("accessTask")),OperAccessTaskDTO.class); - Assert.isTrue(Func.isNotEmpty(accessTask.getPhenomenonId()),()->{ - throw new ServiceException("检修任务信息必须传入现象Id"); - }); - R result = operAccessTaskService.doSave(accessTask); - if(result.isSuccess()){ - variables.put("handler", "taskUser_"+accessTask.getHandler()); - } - comleteTask.setVariables(this.excludeProperties(variables,"accessTask")); - processClient.completeTask(comleteTask); - variables.put("handlerTaskId",accessTask.getId()); - variables.put("handlerProcessInstanceId",accessTask.getProcessInstanceId()); - variables.put("handlerUserId",accessTask.getHandler()); - variables.put("handlerType",TreatMethodConstant.MAINTENANCE_TASK); - variables.put("actStartTime",accessTask.getCreateTime()); - } - - - /** - * 保存缺陷信息 - * @param variables - */ - private void saveDefectInfo(Map variables,String processInstanceId,String processKey,String state) { - // 新启线程保存缺陷 - ExecutorService exe = Executors.newSingleThreadExecutor(); - exe.execute(()->{ - // 查询现象 - OperPhenomenonEntity entity = this.queryPhenomenon(processInstanceId); - - // 保存流程信息至缺陷表 - this.defectService.update(Wrappers.lambdaUpdate() - .set(OperDefectEntity::getProcDefId,processKey + "->" + variables.get("handlerTaskId")) - .set(OperDefectEntity::getActStartTime,variables.get("actStartTime")) - .set(OperDefectEntity::getHandleStatus,state) - .set(OperDefectEntity::getHandleType,variables.get("handlerType")) - .eq(OperDefectEntity::getDefectCode,entity.getDefectCode()) - ); - }); - exe.shutdown(); - } - - /** - * 关联处理任务 - * @param variables - * @param type - * @param processInstanceId - */ - private void relationHandlerTask( Map variables,String type,String processInstanceId,String state) { - this.update(Wrappers.lambdaUpdate() - .set(OperPhenomenonEntity::getHandleTaskId,variables.get("handlerTaskId")) - .set(OperPhenomenonEntity::getHandler,variables.get("handlerUserId")) - .set(OperPhenomenonEntity::getHandleType,type) - .set(OperPhenomenonEntity::getHandleStatus,state) - .eq(OperPhenomenonEntity::getCheckProcessInstanceId,processInstanceId) - ); - } - - /** - * 补开工作票 - * @param task - */ - @Override - public void makeUpTicket(ComleteTask task) { - // 步骤1.查询现象 - OperPhenomenonEntity entity = this.queryPhenomenon(task.getProcessInstanceId()); - - // 步骤2.获取定论角色-用户 - List list = this.getAliasUser(entity.getTenantId(),entity.getCreateDept(),TreatMethodConstant.PHENOMENON_CONCLUSION_ALIAS); - if(CollectionUtil.isEmpty(list)){ - throw new ServiceException("请先添加缺陷定论角色用户,再进行补工作票"); - } - List userList = list.stream().map(o -> "taskUser_" + o.getId().toString()).collect(Collectors.toList()); - - // 步骤3.现象状态 -> 问题定论 - this.updatePhenomenonState(entity); - - // 步骤4.缺陷状态 -> 问题定论 - this.updateDefectHandleState(RepairConstant.CONCLUSION_PROBLEM,entity.getDefectCode()); - - // 步骤5.设置参数 - Map variables = task.getVariables(); - variables.put(TreatMethodConstant.PHENOMENON_CONCLUSION_ALIAS,String.join(",", userList)); - task.setVariables(variables); - - // 步骤6.执行流程->问题定论 - processClient.completeTask(task); - } - - /** - * 现象状态 -> 问题定论 - * @param entity - */ - private void updatePhenomenonState(OperPhenomenonEntity entity) { - entity.setHandleStatus(RepairConstant.CONCLUSION_PROBLEM); - this.phenomenonMapper.updateById(entity); - } - - /** - * 查询现象 - * @param processInstanceId - * @return - */ - private OperPhenomenonEntity queryPhenomenon(String processInstanceId) { - LambdaQueryWrapper wrapper = new LambdaQueryWrapper() {{ - eq(OperPhenomenonEntity::getCheckProcessInstanceId, processInstanceId); - }}; - return this.getOne(wrapper); - } - - /** - * 定论 - * @param task - */ - @Override - public void conclusion(ComleteTask task) { - // 步骤1.查询现象 - OperPhenomenonEntity entity = this.queryPhenomenon(task.getProcessInstanceId()); - - // 步骤2.更新现象定论信息 - this.defectConclusionInfo(task,entity.getId()); - - // 步骤3.现象加入台账 - this.saveDefect(entity); - - // 步骤4.故障状态更新 - this.updateFaultState(entity.getFaultCode()); - - // 步骤5.更新缺陷状态 -> 已处理 - this.updateDefectHandleState(RepairConstant.COMPLETE_DEFECT_STATE,entity.getDefectCode()); - - // 步骤6.缺陷流程->结束 - processClient.completeTask(task); - } - - /** - * 更新现象定论信息 - * @param task - */ - private void defectConclusionInfo(ComleteTask task,Long phenomenonId) { - // 获取参数集 - Map variables = task.getVariables(); - - // 修改现象定论信息 - OperPhenomenonEntity entity = new OperPhenomenonEntity(); - entity.setStatus(Integer.valueOf(TreatMethodConstant.OVER)); - entity.setHandleStatus(RepairConstant.COMPLETE_DEFECT_STATE); - entity.setConclusionTime(new Date()); - entity.setConclusionPeople(AuthUtil.getUserId()); - entity.setConclusionStatus(TreatMethodConstant.CONCLUSION_COMPLETED); - entity.setConclusion((String) variables.get("conclusion")); - entity.setCheckHours(Integer.valueOf(variables.get("checkHours").toString())); - entity.setId(phenomenonId); - this.phenomenonMapper.updateById(entity); - } - - /** - * 现象加入台账 - * @param entity - */ - private void saveDefect(OperPhenomenonEntity entity) { - entity = phenomenonMapper.selectById(entity.getId()); - // 复制现象数据 - OperDefectStatisticsEntity statistics = BeanUtil.copy(entity, OperDefectStatisticsEntity.class); - // 查询缺陷 - OperDefectEntity defect = this.defectService.getOne(Wrappers.lambdaUpdate().eq(OperDefectEntity::getDefectCode, entity.getDefectCode())); - if(ObjectUtil.isEmpty(statistics)){ - return; - } - // 实际执行时长 - statistics.setCheckHours(entity.getCheckHours()); - statistics.setConclusion(entity.getConclusion()); - statistics.setConclusionPeople(entity.getConclusionPeople()); - statistics.setConclusionTime(entity.getConclusionTime()); - statistics.setActEndTime(defect.getActEndTime()); - statistics.setActStartTime(defect.getActStartTime()); - statistics.setDisposeDesc(defect.getDisposeDesc()); - // 台账存储 - this.statisticsService.save(statistics); - } - - /** - * 故障状态更新 - * @param faultCode - */ - private void updateFaultState(String faultCode) { - if(StringUtil.isBlank(faultCode)){ - return; - } - fdpTaskClient.updateFinishStatusByDefectCode(faultCode); - } - - /** - * 排除业务中所需属性 避免传入工作流中 - * @param variable 工作流传参map - * @param properties 不计入工作流传参的属性 - * @return - */ - private Map excludeProperties(Map variable,String... properties) { - Map result = new HashMap<>(); - variable.forEach((k,v)->{ - if(!Arrays.asList(properties).contains(k)) { - result.put(k,v); - } - }); - return result; - } + private final IOperAccessTaskService operAccessTaskService; + + private final IOperAccessPlanService operAccessPlanService; + + private final IOperAppearanceService operAppearanceService; + + private final IOperDefectStatisticsService statisticsService; + private final IOperDefectService defectService; + + private final IOperAccessPlanService accessPlanService; + + private final OperPhenomenonMapper phenomenonMapper; + + private final IFlowClient processClient; + + private final IUserClient userClient; + + private final ISysClient sysClient; + + private final IMessageClient messageClient; + + private final IFdpTaskClient fdpTaskClient; + + + private final IRepairClient repairClient; + + /** + * 保存现象、开启缺陷处理流程 + * + * @param entity + * @return + */ + @Override + @Transactional(rollbackFor = Exception.class) + public OperPhenomenonEntity startCheck(OperPhenomenonEntity entity) { + // 步骤1.保存现象 + if (!this.savePhenomenon(entity)) { + throw new ServiceException("保存现象失败!"); + } + // 步骤2.开启缺陷流程 + this.startDefectCheckV2(entity); + return entity; + } + + /** + * 保存现象 + * + * @param entity + * @return + */ + private boolean savePhenomenon(OperPhenomenonEntity entity) { + DateTimeFormatter format = DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME_MINI); + // 缺陷编码 : 缺陷来源 + 时间格式化 + 三位长度随机值 + if (Func.isEmpty(entity.getDefectCode())) { + entity.setDefectCode(entity.getSourceCode() + format.format(LocalDateTime.now()) + Func.random(3)); + } + // 现象发起人 : 当前用户Id + if (Func.isEmpty(entity.getFinder())) { + entity.setFinder(AuthUtil.getUserId()); + } + // 现象发起时间 + entity.setFindTime(new Date()); + // 现象更新时间 + entity.setUpdateTime(new Date()); + // 现在最后甄别时间 +// Date discriminateDeadline = DateUtil.plusHours(entity.getUpdateTime(), DefectConfiguration.discriminateDeadline); +// entity.setDiscriminateDeadline(discriminateDeadline); +// 最后甄别时间字段弃用 + return this.save(entity); + + } + + /** + * 启动缺陷处理流程 + * + * @param entity + */ + private void startDefectCheckV2(OperPhenomenonEntity entity) { + // 获取机构下执行定论缺陷角色用户 + List list = this.getAliasUser(entity.getTenantId(), entity.getCreateDept(), TreatMethodConstant.PHENOMENON_SCREEN_ALIAS); + if (CollectionUtil.isEmpty(list)) { + throw new ServiceException("请先添加甄别缺陷角色用户,再发起现象!"); + } + // 现象发起人名字 + String userName = Optional.ofNullable(UserCache.getUser(entity.getFinder()).getName()).orElse(""); + // 现象发起来源 + String sourceName = DictCache.getValue(TreatMethodConstant.SOURCE_CODE_PREFIX, entity.getSourceCode()); + // 流程名称 + String processName = "[" + userName + "] 发起 " + "【" + sourceName + "】缺陷处理流程" + "——>" + entity.getDefectCode(); + // 开启新的缺陷流程 + String businessKey = FlowUtil.getBusinessKey("hzims_oper_phenomenon", "" + entity.getId()); + Map variable = entityToMap(entity); + R result = processClient.startProcessInstanceContainNameByKey(TreatMethodConstant.DEFECT_CHECK_PRIMARY_KEY_TY, businessKey, processName, variable); + // 流程开启失败 + if (!result.isSuccess()) { + throw new ServiceException("缺陷流程开启失败,错误描述 : " + result.getCode()); + } + // 关联流程唯一键 + entity.setCheckProcessInstanceId(result.getData().getProcessInstanceId()); + this.baseMapper.updateById(entity); + //新增缺陷流程记录 + OperDefectStatisticsEntity operDefectStatisticsEntity = new OperDefectStatisticsEntity(); + BeanUtil.copy(entity, operDefectStatisticsEntity); + statisticsService.save(operDefectStatisticsEntity); + //新增现象记录 + OperAppearanceEntity operAppearanceEntity = new OperAppearanceEntity(); + BeanUtil.copy(entity, operAppearanceEntity); + operAppearanceService.save(operAppearanceEntity); + this.save(entity); + } + + /** + * 实体类转换成map + * + * @param obj + * @return + */ + public static Map entityToMap(Object obj) { + Map map = new HashMap(); + Class clazz = obj.getClass(); + for (Field field : clazz.getDeclaredFields()) { + field.setAccessible(true); + String fieldName = field.getName(); + Object object = null; + try { + object = field.get(obj); + } catch (IllegalArgumentException | IllegalAccessException e) { + log.info(e.getMessage()); + } + map.put(fieldName, object); + } + return map; + } + + /** + * Map转实体类:要转换的Map的key跟实体类属性名相同的数据会转过去,不相同的字段会为null + * + * @param clazz + * @param map + * @return + */ + public static T mapToEntity(Class clazz, Map map) { + T obj = null; + try { + BeanInfo beanInfo = Introspector.getBeanInfo(clazz); + obj = clazz.newInstance(); // 创建 JavaBean 对象 + PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); + // 给 JavaBean 对象的属性赋值 + for (int i = 0; i < propertyDescriptors.length; i++) { + PropertyDescriptor descriptor = propertyDescriptors[i]; + String propertyName = descriptor.getName(); + if (map.containsKey(propertyName)) { + Object value = map.get(propertyName); + Object[] args = new Object[1]; + args[0] = value; + try { + descriptor.getWriteMethod().invoke(obj, args); + } catch (InvocationTargetException e) { + log.info(e.getMessage()); + } + } + } + } catch (Exception e) { + log.info(e.getMessage()); + } + return (T) obj; + } + + + /** + * @param processWorkFlowResponse + * + */ + @Override + public R listenAndUpdateDefect(ProcessWorkFlowResponse processWorkFlowResponse) { + String variables = processWorkFlowResponse.getVariables().toString(); + OperPhenomenonEntity operPhenomenonEntity; + try { + //现象缺陷全表更新 + operPhenomenonEntity = JSONObject.parseObject(variables, OperPhenomenonEntity.class); + } catch (Exception e) { + log.info("消息转换失败"); + return R.fail("消息转换失败"); + } + if (processWorkFlowResponse.getTaskId() != null || processWorkFlowResponse.getUserId() != null) { + operPhenomenonEntity.setCurrentOperator(processWorkFlowResponse.getNextStepOperator()); + operPhenomenonEntity.setCurrentLinkHandler(processWorkFlowResponse.getProcessDefinitionKey()); + } + //缺陷记录 + OperDefectStatisticsEntity statisticsEntity = statisticsService.getOne(new LambdaUpdateWrapper() {{ + eq(OperDefectStatisticsEntity::getDefectCode, operPhenomenonEntity.getDefectCode()); + }}); + //现象记录 + OperAppearanceEntity appearanceEntity = operAppearanceService.getOne(new LambdaUpdateWrapper() {{ + eq(OperAppearanceEntity::getDefectCode, operPhenomenonEntity.getDefectCode()); + }}); + if (ObjectUtil.isNotEmpty(operPhenomenonEntity.getIsWarehousing()) && operPhenomenonEntity.getIsWarehousing()) { + OperDefectEntity operDefectEntity=new OperDefectEntity(); + BeanUtil.copy(operPhenomenonEntity,operDefectEntity); + operDefectEntity.setProcessInstanceId(operPhenomenonEntity.getHandleTaskId().toString()); + defectService.save(operDefectEntity); + log.info("缺陷ID:"+operPhenomenonEntity.getDefectCode()+"入库成功"); + operPhenomenonEntity.setCurrentOperator("定论"); + operPhenomenonEntity.setCurrentLinkHandler(null); + } + //更新数据库 + Long statisticsEntityId = statisticsEntity.getId(); + Long appearanceEntityId = appearanceEntity.getId(); + BeanUtil.copy(operPhenomenonEntity, statisticsEntity); + BeanUtil.copy(operPhenomenonEntity, appearanceEntity); + statisticsEntity.setId(statisticsEntityId); + appearanceEntity.setId(appearanceEntityId); + this.baseMapper.update(operPhenomenonEntity, new LambdaUpdateWrapper() {{ + eq(OperPhenomenonEntity::getDefectCode, operPhenomenonEntity.getDefectCode()); + }}); + statisticsService.updateById(statisticsEntity); + operAppearanceService.updateById(appearanceEntity); + //推送消息中心相关消息 + sendMessage(processWorkFlowResponse, operPhenomenonEntity); + return R.success("消息保存成功"); + } + + private void sendMessage(ProcessWorkFlowResponse processWorkFlowResponse, OperPhenomenonEntity operPhenomenonEntity) { + //推送消息 + if (processWorkFlowResponse.getTaskId() != null) { + MessagePushRecordDto message = new MessagePushRecordDto(); + message.setBusinessClassify("business"); + message.setBusinessKey(MessageConstants.BusinessClassifyEnum.OPERATIONDEFECTMESSAGE.getKey()); + message.setSubject(MessageConstants.BusinessClassifyEnum.OPERATIONDEFECTMESSAGE.getDescription()); + message.setTaskId(operPhenomenonEntity.getId()); + message.setTenantId("200000"); + message.setTypes(Arrays.asList(MessageConstants.APP_PUSH, MessageConstants.WS_PUSH)); + message.setPushType(MessageConstants.IMMEDIATELY); + //您有一张工作票待审批,工作内容:*****,审批环节:*****; + String countent = + "您的消缺流程待审批!现象名称:".concat(operPhenomenonEntity.getDefectName()) + .concat(",审批环节:") + .concat(processWorkFlowResponse.getTaskName()); + message.setContent(countent); + message.setDeptId(operPhenomenonEntity.getCreateDept()); + R deptName = sysClient.getDeptName(operPhenomenonEntity.getCreateDept()); + if (deptName.isSuccess()) { + message.setDeptName(deptName.getData()); + } + String userIds = processWorkFlowResponse.getUserId(); + if (StringUtils.isBlank(userIds)) { + log.error("推送的消息不能为空哦,{}", userIds); + return; + } + String[] split = userIds.split(","); + for (String userId : split) { + message.setPusher(userId); + User user = UserCache.getUser(NumberUtils.toLong(userId)); + if (ObjectUtils.isNotEmpty(user)) { + message.setPusherName(user.getName()); + } + message.setAccount(userId); + + message.setCreateUser(NumberUtils.toLong(userId)); + messageClient.sendMessage(message); + } + } + } + + /** + * 启动缺陷处理流程 + * 此端口弃用20230614 + * + * @param entity + */ + @Deprecated + private void startDefectCheck(OperPhenomenonEntity entity) { + // 获取机构下执行定论缺陷角色用户 + List list = this.getAliasUser(entity.getTenantId(), entity.getCreateDept(), TreatMethodConstant.PHENOMENON_SCREEN_ALIAS); + if (CollectionUtil.isEmpty(list)) { + throw new ServiceException("请先添加甄别缺陷角色用户,再发起现象!"); + } + List userList = list.stream().map(o -> "taskUser_" + o.getId().toString()).collect(Collectors.toList()); + // 现象发起人名字 + String userName = Optional.ofNullable(UserCache.getUser(entity.getFinder()).getName()).orElse(""); + // 现象发起来源 + String sourceName = DictCache.getValue(TreatMethodConstant.SOURCE_CODE_PREFIX, entity.getSourceCode()); + // 流程名称 + String processName = "[" + userName + "] 发起 " + "【" + sourceName + "】缺陷处理流程" + "——>" + entity.getDefectCode(); + // 设置下一步执行流程用户 + Kv variables = Kv.create() + .set(TreatMethodConstant.PHENOMENON_SCREEN_USER, String.join(",", userList)); + // 开启新的缺陷流程 + R result = processClient.startProcessInstanceContainNameByKey(TreatMethodConstant.DEFECT_CHECK_PRIMARY_KEY, FlowUtil.getBusinessKey("hzims_oper_phenomenon", "" + entity.getId()), processName, variables); + // 流程开启失败 + if (!result.isSuccess()) { + throw new ServiceException("缺陷流程开启失败,错误描述 : " + result.getCode()); + } + // 关联流程唯一键 + entity.setCheckProcessInstanceId(result.getData().getProcessInstanceId()); + this.baseMapper.updateById(entity); + } + + /** + * 获取当前机构指定角色的用户 + * + * @param tenantId + * @param deptId + * @param alias + * @return + */ + public List getAliasUser(String tenantId, Long deptId, String alias) { + if (Func.isEmpty(tenantId)) { + tenantId = AuthUtil.getTenantId(); + } + R> result = userClient.relationUserListByRoleAlias(tenantId, deptId, alias); + if (!result.isSuccess()) { + throw new ServiceException("查询角色用户信息失败!"); + } + return result.getData(); + } + + /** + * 修改缺陷状态 -> 问题定论 + * + * @param handleStatus + * @param defectCode + */ + private void updateDefectHandleState(String handleStatus, String defectCode) { + this.defectService.update(Wrappers.lambdaUpdate() + .set(OperDefectEntity::getHandleStatus, handleStatus) + .eq(OperDefectEntity::getDefectCode, defectCode) + ); + } + + + /** + * 甄别缺陷 + * + * @param task + * @return + */ + @Override + @Transactional(rollbackFor = Exception.class) + public void screeDefect(ComleteTask task) { + // 步骤1.现象前置判断(现象状态检查) + OperPhenomenonEntity entity = this.preposePhenomenon(task.getProcessInstanceId()); + + // 步骤2.更新甄别状态、数据 + this.screePhenomenonUpdate(task); + + // 步骤3.现象添加至缺陷库 + this.defectSave(entity); + + // 步骤4.流程执行至甄别处理方式 + processClient.completeTask(task); + } + + /** + * 现象前置判断 + * + * @param processInstanceId + * @return + */ + private OperPhenomenonEntity preposePhenomenon(String processInstanceId) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper() {{ + eq(OperPhenomenonEntity::getCheckProcessInstanceId, processInstanceId); + }}; + // 查询现象状态 + OperPhenomenonEntity entity = this.getOne(wrapper); + if (ObjectUtil.isEmpty(entity)) { + throw new ServiceException("现象不存在"); + } + // 现象已被自动甄别 + if (TreatMethodConstant.AUTO_SCREENED.equals(entity.getAutoDiscriminateStatus())) { + throw new ServiceException("该现象已经自动甄别"); + } + // 现象已被手动动甄别 + if (TreatMethodConstant.SCREENED.equals(entity.getDiscriminateStatus())) { + throw new ServiceException("该现象已甄别"); + } + return entity; + } + + /** + * 缺陷保存 + * + * @param phenomenon + */ + private void defectSave(OperPhenomenonEntity phenomenon) { + OperDefectEntity defect = new OperDefectEntity(); + defect.setHandleStatus(RepairConstant.DEFAULT_DEFECT_STATE); + defect.setProcessInstanceId(phenomenon.getCheckProcessInstanceId()); + defect.setDefectCode(phenomenon.getDefectCode()); + defect.setCreateUser(phenomenon.getCreateUser()); + defect.setCreateDept(phenomenon.getCreateDept()); + defect.setTenantId(phenomenon.getTenantId()); + this.defectService.save(defect); + } + + /** + * 更新甄别状态、数据 + * + * @param task + */ + private void screePhenomenonUpdate(ComleteTask task) { + // 查询流程状态 + String processStatus = TreatMethodConstant.RUNNING; + R result = processClient.queryProcessInstanceStatus(task.getProcessInstanceId()); + if (result.isSuccess() && StringUtil.isNotBlank(result.getData()) && TreatMethodConstant.PROCESS_STATE_OVER.equals(result.getData())) { + processStatus = TreatMethodConstant.PROCESS_STATE_OVER; + } + // 获取参数集 + Map variables = task.getVariables(); + boolean invalid = (boolean) variables.get("invalid"); + LambdaUpdateWrapper lambdaUpdate = Wrappers.lambdaUpdate(); + if (invalid) { + lambdaUpdate + .set(OperPhenomenonEntity::getStatus, processStatus) + .set(OperPhenomenonEntity::getIsDefect, TreatMethodConstant.IS_DEFECT) + .set(OperPhenomenonEntity::getAutoDiscriminateStatus, TreatMethodConstant.ORDINARY_SCREENED) + .set(OperPhenomenonEntity::getDiscriminator, AuthUtil.getUserId()) + .set(OperPhenomenonEntity::getDiscriminateTime, new Date()) + .set(OperPhenomenonEntity::getDiscriminateStatus, variables.get("discriminateStatus").toString()) + .set(OperPhenomenonEntity::getDiscriminateDesc, Optional.ofNullable(variables.get("discriminateDesc")).map(Object::toString).orElse(null)) + .set(OperPhenomenonEntity::getSafeInfos, variables.get("safeInfos").toString()) + .set(OperPhenomenonEntity::getWorkStandards, Optional.ofNullable(variables.get("workStandards")).map(Object::toString).orElse(null)) + .set(OperPhenomenonEntity::getHandleProgramme, variables.get("handleProgramme").toString().substring(9)) + .set(OperPhenomenonEntity::getPlanHours, variables.get("planHours").toString()) + .set(OperPhenomenonEntity::getPlanStartTime, variables.get("planStartTime").toString()) + .set(OperPhenomenonEntity::getPlanEndTime, variables.get("planEndTime").toString()) + .set(OperPhenomenonEntity::getDefectLevel, variables.get("defectLevel").toString()) + .eq(OperPhenomenonEntity::getCheckProcessInstanceId, task.getProcessInstanceId()); + } else { + lambdaUpdate + .set(OperPhenomenonEntity::getStatus, processStatus) + .set(OperPhenomenonEntity::getIsDefect, TreatMethodConstant.NO_DEFECT) + .set(OperPhenomenonEntity::getDiscriminateStatus, variables.get("discriminateStatus").toString()) + .set(OperPhenomenonEntity::getDiscriminator, AuthUtil.getUserId()) + .set(OperPhenomenonEntity::getDiscriminateTime, new Date()) + .set(OperPhenomenonEntity::getDiscriminateDesc, variables.get("discriminateDesc").toString()) + .eq(OperPhenomenonEntity::getCheckProcessInstanceId, task.getProcessInstanceId()); + } + this.update(lambdaUpdate); + } + + /** + * 决策处理方式 + * + * @param task + * @return + */ + @Override + @Transactional(rollbackFor = Exception.class) + public void treatmentMethod(ComleteTask task) { + // 步骤1.获取参数集 + Map variables = task.getVariables(); + + // 步骤2.根据处理方式进行处理 + String state = RepairConstant.REPAIR_DEFECT_STATE, processKey = RepairConstant.REPAIR_PROCESS_PRIMARY_KEY, type = variables.get("type").toString(); + switch (type) { + // 应急抢修处理 + case TreatMethodConstant.TYPE_RUSH_TO_REPAIR: + this.startRepair(task, variables); + break; + // 检修计划处理 + case TreatMethodConstant.TYPE_PLAN: + state = RepairConstant.ACCESS_PLAN_STATE; + this.startMaintenancePlan(task, variables); + break; + // 检修任务处理 + case TreatMethodConstant.TYPE_TASK: + state = RepairConstant.ACCESS_TASK_STATE; + this.startMaintenanceTask(task); + break; + default: + throw new IllegalStateException("Unexpected type: " + type); + } + // 步骤3.关联处理任务 + this.relationHandlerTask(variables, type, task.getProcessInstanceId(), state); + + // 步骤4.缺陷库保存处理任务信息 + this.saveDefectInfo(variables, task.getProcessInstanceId(), processKey, state); + + // 步骤5.流程执行 -> 处理缺陷 + processClient.completeTask(task); + } + + /** + * 启动应急抢修流程 + * + * @param variables + */ + private void startRepair(ComleteTask task, Map variables) { + String json = JSON.toJSONString(variables.get("repair")); + RepairEntity entity = JSONObject.parseObject(json, RepairEntity.class); + R result = repairClient.startRepair(entity); + if (!result.isSuccess()) { + throw new ServiceException("开启检修任务流程失败!"); + } + variables.put("handlerTaskId", result.getData().getId()); + variables.put("handlerType", TreatMethodConstant.REPAIR); + variables.put("handlerProcessInstanceId", result.getData().getProcessInstanceId()); + variables.put("handlerUserId", result.getData().getCharge()); + variables.put(TreatMethodConstant.DEFECT_HANDLER_USER, "taskUser_" + result.getData().getCharge()); + task.setVariables(variables); + } + + /** + * 开启检修计划 + * + * @param variables + */ + private void startMaintenancePlan(ComleteTask task, Map variables) { + String json = JSON.toJSONString(variables.get("accessPlan")); + OperAccessPlanDTO accessPlan = JSONObject.parseObject(json, OperAccessPlanDTO.class); + // 查询现象 + OperPhenomenonEntity phenomenon = this.getOne(new LambdaQueryWrapper() {{ + eq(OperPhenomenonEntity::getCheckProcessInstanceId, task.getProcessInstanceId()); + }}); + + // 查询缺陷 + OperDefectEntity defect = this.defectService.getOne(Wrappers.lambdaUpdate().eq(OperDefectEntity::getDefectCode, phenomenon.getDefectCode())); + accessPlan.setDefectId(defect.getId()); + accessPlan.setPhenomenonId(phenomenon.getId()); + accessPlan.setActStartTime(DateUtil.now()); + // 计划草稿 + R result = operAccessPlanService.doSave(accessPlan); + if (!result.isSuccess()) { + throw new ServiceException("开启检修计划失败"); + } + // 计划流程开启 + accessPlanService.handlePlan(accessPlan, null); + variables.put("handlerTaskId", accessPlan.getId()); + variables.put("handlerProcessInstanceId", accessPlan.getProcessInstanceId()); + variables.put("handlerUserId", AuthUtil.getUserId()); + variables.put("handlerType", TreatMethodConstant.MAINTENANCE_PLAN); + variables.put("actStartTime", accessPlan.getActStartTime()); + variables.put(TreatMethodConstant.DEFECT_HANDLER_USER, "taskUser_" + AuthUtil.getUserId()); + task.setVariables(variables); + } + + /** + * 开启检修任务 + * + * @param comleteTask + */ + @Transactional(rollbackFor = Exception.class) + public void startMaintenanceTask(ComleteTask comleteTask) { + Assert.isTrue(CollectionUtil.isNotEmpty(comleteTask.getVariables()) && ObjectUtil.isNotEmpty(comleteTask.getVariables().get("accessTask")), () -> { + throw new ServiceException("检修任务信息不能为空!"); + }); + Map variables = comleteTask.getVariables(); + OperAccessTaskDTO accessTask = JSONObject.parseObject(JSON.toJSONString(variables.get("accessTask")), OperAccessTaskDTO.class); + Assert.isTrue(Func.isNotEmpty(accessTask.getPhenomenonId()), () -> { + throw new ServiceException("检修任务信息必须传入现象Id"); + }); + R result = operAccessTaskService.doSave(accessTask); + if (result.isSuccess()) { + variables.put("handler", "taskUser_" + accessTask.getHandler()); + } + comleteTask.setVariables(this.excludeProperties(variables, "accessTask")); + processClient.completeTask(comleteTask); + variables.put("handlerTaskId", accessTask.getId()); + variables.put("handlerProcessInstanceId", accessTask.getProcessInstanceId()); + variables.put("handlerUserId", accessTask.getHandler()); + variables.put("handlerType", TreatMethodConstant.MAINTENANCE_TASK); + variables.put("actStartTime", accessTask.getCreateTime()); + } + + + /** + * 保存缺陷信息 + * + * @param variables + */ + private void saveDefectInfo(Map variables, String processInstanceId, String processKey, String state) { + // 新启线程保存缺陷 + ExecutorService exe = Executors.newSingleThreadExecutor(); + exe.execute(() -> { + // 查询现象 + OperPhenomenonEntity entity = this.queryPhenomenon(processInstanceId); + + // 保存流程信息至缺陷表 + this.defectService.update(Wrappers.lambdaUpdate() + .set(OperDefectEntity::getProcDefId, processKey + "->" + variables.get("handlerTaskId")) + .set(OperDefectEntity::getActStartTime, variables.get("actStartTime")) + .set(OperDefectEntity::getHandleStatus, state) + .set(OperDefectEntity::getHandleType, variables.get("handlerType")) + .eq(OperDefectEntity::getDefectCode, entity.getDefectCode()) + ); + }); + exe.shutdown(); + } + + /** + * 关联处理任务 + * + * @param variables + * @param type + * @param processInstanceId + */ + private void relationHandlerTask(Map variables, String type, String processInstanceId, String state) { + this.update(Wrappers.lambdaUpdate() + .set(OperPhenomenonEntity::getHandleTaskId, variables.get("handlerTaskId")) + .set(OperPhenomenonEntity::getHandler, variables.get("handlerUserId")) + .set(OperPhenomenonEntity::getHandleType, type) + .set(OperPhenomenonEntity::getHandleStatus, state) + .eq(OperPhenomenonEntity::getCheckProcessInstanceId, processInstanceId) + ); + } + + /** + * 补开工作票 + * + * @param task + */ + @Override + public void makeUpTicket(ComleteTask task) { + // 步骤1.查询现象 + OperPhenomenonEntity entity = this.queryPhenomenon(task.getProcessInstanceId()); + + // 步骤2.获取定论角色-用户 + List list = this.getAliasUser(entity.getTenantId(), entity.getCreateDept(), TreatMethodConstant.PHENOMENON_CONCLUSION_ALIAS); + if (CollectionUtil.isEmpty(list)) { + throw new ServiceException("请先添加缺陷定论角色用户,再进行补工作票"); + } + List userList = list.stream().map(o -> "taskUser_" + o.getId().toString()).collect(Collectors.toList()); + + // 步骤3.现象状态 -> 问题定论 + this.updatePhenomenonState(entity); + + // 步骤4.缺陷状态 -> 问题定论 + this.updateDefectHandleState(RepairConstant.CONCLUSION_PROBLEM, entity.getDefectCode()); + + // 步骤5.设置参数 + Map variables = task.getVariables(); + variables.put(TreatMethodConstant.PHENOMENON_CONCLUSION_ALIAS, String.join(",", userList)); + task.setVariables(variables); + + // 步骤6.执行流程->问题定论 + processClient.completeTask(task); + } + + /** + * 现象状态 -> 问题定论 + * + * @param entity + */ + private void updatePhenomenonState(OperPhenomenonEntity entity) { + entity.setHandleStatus(RepairConstant.CONCLUSION_PROBLEM); + this.phenomenonMapper.updateById(entity); + } + + /** + * 查询现象 + * + * @param processInstanceId + * @return + */ + private OperPhenomenonEntity queryPhenomenon(String processInstanceId) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper() {{ + eq(OperPhenomenonEntity::getCheckProcessInstanceId, processInstanceId); + }}; + return this.getOne(wrapper); + } + + /** + * 定论 + * + * @param task + */ + @Override + public void conclusion(ComleteTask task) { + // 步骤1.查询现象 + OperPhenomenonEntity entity = this.queryPhenomenon(task.getProcessInstanceId()); + + // 步骤2.更新现象定论信息 + this.defectConclusionInfo(task, entity.getId()); + + // 步骤3.现象加入台账 + this.saveDefect(entity); + + // 步骤4.故障状态更新 + this.updateFaultState(entity.getFaultCode()); + + // 步骤5.更新缺陷状态 -> 已处理 + this.updateDefectHandleState(RepairConstant.COMPLETE_DEFECT_STATE, entity.getDefectCode()); + + // 步骤6.缺陷流程->结束 + processClient.completeTask(task); + } + + + /** + * 更新现象定论信息 + * + * @param task + */ + private void defectConclusionInfo(ComleteTask task, Long phenomenonId) { + // 获取参数集 + Map variables = task.getVariables(); + + // 修改现象定论信息 + OperPhenomenonEntity entity = new OperPhenomenonEntity(); + entity.setStatus(Integer.valueOf(TreatMethodConstant.OVER)); + entity.setHandleStatus(RepairConstant.COMPLETE_DEFECT_STATE); + entity.setConclusionTime(new Date()); + entity.setConclusionPeople(AuthUtil.getUserId()); + entity.setConclusionStatus(TreatMethodConstant.CONCLUSION_COMPLETED); + entity.setConclusion((String) variables.get("conclusion")); + entity.setCheckHours(Integer.valueOf(variables.get("checkHours").toString())); + entity.setId(phenomenonId); + this.phenomenonMapper.updateById(entity); + } + + /** + * 现象加入台账 + * + * @param entity + */ + private void saveDefect(OperPhenomenonEntity entity) { + entity = phenomenonMapper.selectById(entity.getId()); + // 复制现象数据 + OperDefectStatisticsEntity statistics = BeanUtil.copy(entity, OperDefectStatisticsEntity.class); + // 查询缺陷 + OperDefectEntity defect = this.defectService.getOne(Wrappers.lambdaUpdate().eq(OperDefectEntity::getDefectCode, entity.getDefectCode())); + if (ObjectUtil.isEmpty(statistics)) { + return; + } + // 实际执行时长 + statistics.setCheckHours(entity.getCheckHours()); + statistics.setConclusion(entity.getConclusion()); + statistics.setConclusionPeople(entity.getConclusionPeople()); + statistics.setConclusionTime(entity.getConclusionTime()); + statistics.setActEndTime(defect.getActEndTime()); + statistics.setActStartTime(defect.getActStartTime()); + statistics.setDisposeDesc(defect.getDisposeDesc()); + // 台账存储 + this.statisticsService.save(statistics); + } + + /** + * 故障状态更新 + * + * @param faultCode + */ + private void updateFaultState(String faultCode) { + if (StringUtil.isBlank(faultCode)) { + return; + } + fdpTaskClient.updateFinishStatusByDefectCode(faultCode); + } + + /** + * 排除业务中所需属性 避免传入工作流中 + * + * @param variable 工作流传参map + * @param properties 不计入工作流传参的属性 + * @return + */ + private Map excludeProperties(Map variable, String... properties) { + Map result = new HashMap<>(); + variable.forEach((k, v) -> { + if (!Arrays.asList(properties).contains(k)) { + result.put(k, v); + } + }); + return result; + } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/impl/OperAppearanceServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/impl/OperAppearanceServiceImpl.java new file mode 100644 index 0000000..6134d4a --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/impl/OperAppearanceServiceImpl.java @@ -0,0 +1,16 @@ +package com.hnac.hzims.operational.defect.service.impl; + +import com.hnac.hzims.operational.defect.entity.OperAppearanceEntity; +import com.hnac.hzims.operational.defect.mapper.OperAppearanceMapper; +import com.hnac.hzims.operational.defect.service.IOperAppearanceService; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springframework.stereotype.Service; + +/** + * 服务实现类 + * + * @author Chill + */ +@Service +public class OperAppearanceServiceImpl extends BaseServiceImpl implements IOperAppearanceService { +}