From 8be8ed37d3fac3a690ca5eb597a26dfda1fc6ff5 Mon Sep 17 00:00:00 2001 From: ty <1577900710@qq.com> Date: Mon, 8 Jul 2024 20:55:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E:=E5=B7=A5=E4=BD=9C=E6=B5=81?= =?UTF-8?q?=E8=A1=A5=E5=81=BF=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hzims/common/flow/StartProcessService.java | 38 +++++ .../alarm/config/entity/AlarmHandleFlowEntity.java | 2 + .../safeproduct/entity/InnerDangerEntity.java | 3 + .../hzims/ticket/repair/entity/WorkTaskEntity.java | 3 + .../entity/StandardTicketInfoEntity.java | 3 + .../workTicket/entity/WorkTicketInfoEntity.java | 4 + .../show/service/impl/AlarmHandleServiceImpl.java | 66 ++++++--- .../service/impl/InnerDangerFlowServiceImpl.java | 82 ++++++----- .../risk/service/impl/HazardTaskServiceImpl.java | 40 +++++- .../controller/TicketInfoEvaluateController.java | 1 + .../repair/service/impl/WorkTaskServiceImpl.java | 72 +++++----- .../service/impl/OperationTicketServiceImpl.java | 113 ++++++++------- .../service/impl/TicketProcessServiceImpl.java | 155 +++++++++++---------- .../vo/operation/StandardTicketInfoVo.java | 3 + 14 files changed, 361 insertions(+), 224 deletions(-) create mode 100644 hzims-biz-common/src/main/java/com/hnac/hzims/common/flow/StartProcessService.java diff --git a/hzims-biz-common/src/main/java/com/hnac/hzims/common/flow/StartProcessService.java b/hzims-biz-common/src/main/java/com/hnac/hzims/common/flow/StartProcessService.java new file mode 100644 index 0000000..3b014bb --- /dev/null +++ b/hzims-biz-common/src/main/java/com/hnac/hzims/common/flow/StartProcessService.java @@ -0,0 +1,38 @@ +package com.hnac.hzims.common.flow; + + +import org.springblade.core.tenant.mp.TenantEntity; +import org.springblade.core.tool.api.R; +import org.springframework.transaction.annotation.Transactional; + +/** + * @Author dfy + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/3/27 16:39 + */ +public interface StartProcessService { + + /** + * 业务保存相关方法 + * @param entity + * @return + */ + String saveEntity(String entity); + + + /** + * 启动工作流流程 + * @param entity + * @param dictValue + * @return + */ + void startProcess(String entity, String dictValue); + +// /** +// * 补偿工作流流程 +// * @param response +// */ +// Boolean compensation(ProcessWorkFlowRes ponse response); + +} diff --git a/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/config/entity/AlarmHandleFlowEntity.java b/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/config/entity/AlarmHandleFlowEntity.java index 75ebc7b..14d4d38 100644 --- a/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/config/entity/AlarmHandleFlowEntity.java +++ b/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/config/entity/AlarmHandleFlowEntity.java @@ -101,4 +101,6 @@ public class AlarmHandleFlowEntity extends BaseEntity { private String approvalUserName; @ApiModelProperty("创建机构名称") private String createDeptName; + @ApiModelProperty("工作流是否运行正常") + private Boolean isNormal; } diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/InnerDangerEntity.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/InnerDangerEntity.java index edee04b..dfeb664 100644 --- a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/InnerDangerEntity.java +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/InnerDangerEntity.java @@ -296,4 +296,7 @@ public class InnerDangerEntity extends TenantEntity implements Serializable { private Date conclusionTime; + @ApiModelProperty("工作流是否运行正常") + private Boolean isNormal; + } diff --git a/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/repair/entity/WorkTaskEntity.java b/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/repair/entity/WorkTaskEntity.java index 83ffbcd..f01ff29 100644 --- a/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/repair/entity/WorkTaskEntity.java +++ b/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/repair/entity/WorkTaskEntity.java @@ -103,4 +103,7 @@ public class WorkTaskEntity extends TenantEntity { @ApiModelProperty(value = "创建机构名称") private String deptName; + + @ApiModelProperty("工作流是否运行正常") + private Boolean isNormal; } diff --git a/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/standardTicket/entity/StandardTicketInfoEntity.java b/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/standardTicket/entity/StandardTicketInfoEntity.java index ade487d..59a74ca 100644 --- a/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/standardTicket/entity/StandardTicketInfoEntity.java +++ b/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/standardTicket/entity/StandardTicketInfoEntity.java @@ -159,6 +159,9 @@ public class StandardTicketInfoEntity extends TenantEntity implements Serializab @ApiModelProperty("许可人名称") private String guardianName; + @ApiModelProperty("是否运行正常") + private Boolean isNormal; + @TableField(exist = false) @ApiModelProperty("监护人确认结果:approved-确认,rejected-作废") private String verifyResult; diff --git a/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/workTicket/entity/WorkTicketInfoEntity.java b/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/workTicket/entity/WorkTicketInfoEntity.java index 265e156..6d45228 100644 --- a/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/workTicket/entity/WorkTicketInfoEntity.java +++ b/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/workTicket/entity/WorkTicketInfoEntity.java @@ -509,4 +509,8 @@ public class WorkTicketInfoEntity extends TenantEntity implements Serializable { @ApiModelProperty("修改人名称") private String updateUserName; + + @ApiModelProperty("工作流是否运行正常") + private Boolean isNormal; + } diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmHandleServiceImpl.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmHandleServiceImpl.java index 9c1b8aa..d12f5d7 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmHandleServiceImpl.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmHandleServiceImpl.java @@ -12,8 +12,10 @@ import com.hnac.hzims.alarm.show.service.AlarmHandleDetailService; import com.hnac.hzims.alarm.show.service.AlarmHandleService; import com.hnac.hzims.alarm.show.vo.HandleQueryVo; import com.hnac.hzims.alarm.show.wrapper.HandleWrapper; +import com.hnac.hzims.common.flow.StartProcessService; import com.hnac.hzims.common.logs.utils.StringUtils; import com.hnac.hzims.fdp.feign.IFdpDiagnoseClient; +import com.hnac.hzims.safeproduct.vo.InnerDangerVo; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.log.exception.ServiceException; @@ -42,7 +44,7 @@ import java.util.stream.Collectors; @Slf4j @Service @RequiredArgsConstructor -public class AlarmHandleServiceImpl extends ServiceImpl implements AlarmHandleService { +public class AlarmHandleServiceImpl extends ServiceImpl implements AlarmHandleService , StartProcessService { private final AlarmHandleDetailService detailService; @@ -67,33 +69,44 @@ public class AlarmHandleServiceImpl extends ServiceImpl map=new HashMap<>(); @@ -114,8 +127,13 @@ public class AlarmHandleServiceImpl extends ServiceImpl result = processClient.startProcessInstanceContainNameByKey(AlarmHandleConstant.dealAlarm, businessKey, processName, variable); // 流程开启失败 if (!result.isSuccess()) { + param.setIsNormal(false); + alarmHandleFlowMapper.updateById(param); log.error("缺陷流程开启失败,错误描述 : " + result.getMsg()); throw new ServiceException("缺陷流程开启失败,错误描述 : " + result.getMsg()); + }else { + param.setProcessInstanceId(result.getData().getProcessInstanceId()); + alarmHandleFlowMapper.updateById(param); } - param.setProcessInstanceId(result.getData().getProcessInstanceId()); - alarmHandleFlowMapper.updateById(param); } - return true; } - /** * 分页 * @param query @@ -190,4 +209,5 @@ public class AlarmHandleServiceImpl extends ServiceImpl implements IInnerDangerFlowService { +@Slf4j +public class InnerDangerFlowServiceImpl extends ServiceImpl implements IInnerDangerFlowService , StartProcessService { @Autowired private ISysClient sysClient; @@ -71,65 +75,74 @@ public class InnerDangerFlowServiceImpl extends ServiceImpl() {{ eq(InnerDangerEntity::getCode, innerDangerEntity.getCode()); last("limit 1"); }}); - InnerDangerEntity res = this.startHiddenDangerFlow(saveEntity, hiddenDangerVo); - return R.data(res); + BeanUtil.copy(saveEntity,hiddenDangerVo); + this.startProcess(JSONObject.toJSONString(hiddenDangerVo), HIDDEN_DANGER_CHECK); + return R.success("隐患流程发起成功"); } - - private boolean saveHiddenDanger(InnerDangerEntity entity) { - if (Func.isEmpty(entity.getCode())) { - entity.setCode(UUID.randomUUID().toString()); + @Override + public String saveEntity(String entity) { + InnerDangerEntity innerDangerEntity= JSONObject.parseObject(entity, InnerDangerEntity.class); + if (Func.isEmpty(innerDangerEntity.getCode())) { + innerDangerEntity.setCode(UUID.randomUUID().toString()); } // 隐患发起人 : 当前用户Id - if (Func.isEmpty(entity.getRegistrant())) { - entity.setRegistrant(AuthUtil.getUserId()); - entity.setRegistrantName(AuthUtil.getUserName()); + if (Func.isEmpty(innerDangerEntity.getRegistrant())) { + innerDangerEntity.setRegistrant(AuthUtil.getUserId()); + innerDangerEntity.setRegistrantName(AuthUtil.getUserName()); } // 隐患发起时间 - entity.setRegistrantTime(new Date()); + innerDangerEntity.setRegistrantTime(new Date()); // 隐患发起时间 - entity.setUpdateTime(new Date()); - entity.setCreateUser(AuthUtil.getUserId()); - entity.setCreateDept(Long.valueOf(AuthUtil.getDeptId())); - if (Func.isEmpty(entity.getHiddenDangerDept())) { - return false; + innerDangerEntity.setUpdateTime(new Date()); + innerDangerEntity.setCreateUser(AuthUtil.getUserId()); + innerDangerEntity.setCreateDept(Long.valueOf(AuthUtil.getDeptId())); + if (Func.isEmpty(innerDangerEntity.getHiddenDangerDept())) { + throw new ServiceException("隐患保存失败,请检查好填写信息后重试!"); } - if (Func.isEmpty(entity.getHiddenDangerDeptName())) { - R deptNameR = sysClient.getDeptName(entity.getHiddenDangerDept()); + if (Func.isEmpty(innerDangerEntity.getHiddenDangerDeptName())) { + R deptNameR = sysClient.getDeptName(innerDangerEntity.getHiddenDangerDept()); if (deptNameR.isSuccess() && StringUtils.isNotEmpty(deptNameR.getData())) { - entity.setHiddenDangerDeptName(deptNameR.getData()); + innerDangerEntity.setHiddenDangerDeptName(deptNameR.getData()); } } - return this.save(entity); + boolean save = this.save(innerDangerEntity); + if (!save) { + throw new ServiceException("隐患保存失败,请稍后重试!"); + } + return JSON.toJSONString(innerDangerEntity); } - private InnerDangerEntity startHiddenDangerFlow(InnerDangerEntity entity,InnerDangerVo hiddenDangerVo) { - BeanUtil.copy(entity,hiddenDangerVo); + @Override + public void startProcess(String entity, String dictValue) { + InnerDangerVo innerDangerVo = JSONObject.parseObject(entity, InnerDangerVo.class); + InnerDangerEntity innerDangerEntity = new InnerDangerEntity(); + BeanUtil.copy(innerDangerVo, innerDangerEntity); // 隐患处理名字 String userName = Optional.ofNullable(AuthUtil.getUserName()).orElse(""); // 流程名称 - String processName = "[" + userName + "] 发起 " + "【风险点:" + entity.getRiskPointName() + "】隐患处理流程" + "——>" + entity.getHiddenDangerName(); + String processName = "[" + userName + "] 发起 " + "【风险点:" + innerDangerVo.getRiskPointName() + "】隐患处理流程" + "——>" + innerDangerVo.getHiddenDangerName(); // 开启新的隐患处理流程 - Map variable = JSONObject.parseObject(JSONObject.toJSONStringWithDateFormat(hiddenDangerVo, DateUtil.PATTERN_DATETIME), Map.class); - R result = processClient.startProcessInstanceContainNameByKey(HIDDEN_DANGER_CHECK, entity.getId().toString(), processName, variable); + Map variable = JSONObject.parseObject(JSONObject.toJSONStringWithDateFormat(innerDangerVo, DateUtil.PATTERN_DATETIME), Map.class); + R result = processClient.startProcessInstanceContainNameByKey(HIDDEN_DANGER_CHECK, innerDangerVo.getId().toString(), processName, variable); // 流程开启失败 if (!result.isSuccess()) { + innerDangerEntity.setIsNormal(false); + this.baseMapper.updateById(innerDangerEntity); + log.error("隐患处理流程开启失败,错误描述 : {}", result); throw new ServiceException("隐患处理流程开启失败,错误描述 : " + result.getMsg()); + } else { + // 关联流程唯一键 + innerDangerEntity.setProcessInstanceId(result.getData().getProcessInstanceId()); + innerDangerEntity.setTaskId(result.getData().getTaskId()); + this.baseMapper.updateById(innerDangerEntity); } - // 关联流程唯一键 - entity.setProcessInstanceId(result.getData().getProcessInstanceId()); - entity.setTaskId(result.getData().getTaskId()); - this.baseMapper.updateById(entity); - return entity; } - /** * @param processWorkFlowResponse */ @@ -392,4 +405,5 @@ public class InnerDangerFlowServiceImpl extends ServiceImpl implements HazardTaskService { +public class HazardTaskServiceImpl extends ServiceImpl implements HazardTaskService , StartProcessService { private final HazardWorkService workService; @@ -64,6 +67,16 @@ public class HazardTaskServiceImpl extends ServiceImpllambdaQuery() .eq(HazardTask::getWorkId,process.getWorkId()) @@ -92,10 +105,8 @@ public class HazardTaskServiceImpl extends ServiceImpl{ HazardEstimateVo estimate = new HazardEstimateVo(); @@ -115,12 +126,26 @@ public class HazardTaskServiceImpl extends ServiceImpl variables = JSONObject.parseObject(JSONObject.toJSONStringWithDateFormat(process, DateUtil.PATTERN_DATETIME), Map.class); + variables.put(HazardRiskConstants.TROUBLE, TaskUtil.getTaskUser(String.valueOf(process.getHead()))); + R result = flowClient.startProcessInstanceContainNameByKey(dictValue, FlowUtil.getBusinessKey(HazardRiskConstants.HAZARD_RISK_KEY,String.valueOf(process.getId())), process.getTaskName(), variables); + log.error("start_process_planV4 :{}",result); + // 更新任务流程Id + if (result.isSuccess()) { + BladeFlow flow = result.getData(); + process.setProcessInstanceId(flow.getProcessInstanceId()); + this.updateById(process); + } else { + throw new ServiceException("开启检修计划流程失败,code=" + result.getCode()); + } + } /** * 流程发起 @@ -374,4 +399,5 @@ public class HazardTaskServiceImpl extends ServiceImpl implements IWorkTaskService { +public class WorkTaskServiceImpl extends ServiceImpl implements IWorkTaskService , StartProcessService { private final IWorkTicketInfoService workTicketInfoService; @@ -80,42 +81,15 @@ public class WorkTaskServiceImpl extends ServiceImpl variables = JSONObject.parseObject(JSONObject.toJSONStringWithDateFormat(workTask, DateUtil.PATTERN_DATETIME), Map.class); - variables.put("head", TaskUtil.getTaskUser(String.valueOf(workTask.getHead()))); - // 班组成员 - String[] member = workTask.getMember().split(","); - for(int i = 1;i <= 5 ; i++){ - if(i > member.length){ - variables.put("duty" + i, ""); - }else{ - variables.put("duty" + i, TaskUtil.getTaskUser(member[i-1])); - } - } - R result = flowClient.startProcessInstanceContainNameByKey("work_task", FlowUtil.getBusinessKey("work_task_v4",String.valueOf(workTask.getId())), workTask.getCode(), variables); - log.error("work_task_start_process_result :{}",result); - // 更新任务流程Id - if (result.isSuccess()) { - BladeFlow flow = result.getData(); - workTask.setProcessInstanceId(flow.getProcessInstanceId()); - this.updateById(workTask); - } else { - throw new ServiceException("开启工作任务计划流程失败,code=" + result.getCode()); - } - } - - /** - * 保存工作任务单 - * @param workTask - */ - private void saveWorkTask(WorkTaskVO workTask) { + @Override + public String saveEntity(String entity) { + WorkTaskVO workTask= JSONObject.parseObject(entity, WorkTaskVO.class); // 查询当月最序号记录 WorkTaskEntity max = this.getOne(Wrappers.lambdaQuery() .like(WorkTaskEntity::getCreateTime,DateUtil.format(new Date(),"yyyy-MM")) @@ -143,8 +117,38 @@ public class WorkTaskServiceImpl extends ServiceImpl variables = JSONObject.parseObject(JSONObject.toJSONStringWithDateFormat(workTask, DateUtil.PATTERN_DATETIME), Map.class); + variables.put("head", TaskUtil.getTaskUser(String.valueOf(workTask.getHead()))); + // 班组成员 + String[] member = workTask.getMember().split(","); + for(int i = 1;i <= 5 ; i++){ + if(i > member.length){ + variables.put("duty" + i, ""); + }else{ + variables.put("duty" + i, TaskUtil.getTaskUser(member[i-1])); + } + } + R result = flowClient.startProcessInstanceContainNameByKey(dictValue, FlowUtil.getBusinessKey("work_task_v4",String.valueOf(workTask.getId())), workTask.getCode(), variables); + log.error("work_task_start_process_result :{}",result); + // 更新任务流程Id + if (result.isSuccess()) { + BladeFlow flow = result.getData(); + workTask.setProcessInstanceId(flow.getProcessInstanceId()); + this.updateById(workTask); + } else { + workTask.setIsNormal(false); + this.updateById(workTask); + throw new ServiceException("开启工作任务计划流程失败,code=" + result.getCode()); + } } + /** * 工作任务监听 - 业务处理 * @param processWorkFlowResponse diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/service/impl/OperationTicketServiceImpl.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/service/impl/OperationTicketServiceImpl.java index 4442a1e..af2826e 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/service/impl/OperationTicketServiceImpl.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/service/impl/OperationTicketServiceImpl.java @@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; +import com.hnac.hzims.common.flow.StartProcessService; import com.hnac.hzims.common.logs.utils.StringUtils; import com.hnac.hzims.middle.process.feign.ProcessDictFeignService; import com.hnac.hzims.middle.process.to.ProcessWorkFlowResponse; @@ -32,6 +33,7 @@ import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.secure.BladeUser; import org.springblade.core.secure.utils.AuthUtil; +import org.springblade.core.tenant.mp.TenantEntity; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.BeanUtil; import org.springblade.core.tool.utils.CollectionUtil; @@ -72,7 +74,7 @@ import static com.hnac.hzims.middle.process.constant.TicketProcessConstant.OPERA @Slf4j @Service @RequiredArgsConstructor -public class OperationTicketServiceImpl implements OperationTicketService { +public class OperationTicketServiceImpl implements OperationTicketService , StartProcessService { private final IStandardTicketInfoService standardTicketInfoService; @@ -101,6 +103,20 @@ public class OperationTicketServiceImpl implements OperationTicketService { @Override public void startUp(StandardTicketInfoVo standardTicketInfoVo) { log.info("执行 com.hnac.hzims.ticket.standardTicket.service.impl【startUp】 。。。方法"); + //保存操作票 + String standardTicketInfoVoBySave = this.saveEntity(JSONObject.toJSONString(standardTicketInfoVo)); + //查询流程对应value + String dictValue = processDictFeignService.selectDictValueByKey(OPERATION_TICKET_KEY); + log.info("查询第操作票值: {}", dictValue); + if (StringUtils.isBlank(dictValue)) { + throw new ServiceException("服务器异常,请联系管理员"); + } + //启动流程 + this.startProcess(standardTicketInfoVoBySave, dictValue); + } + @Override + public String saveEntity(String entity) { + StandardTicketInfoVo standardTicketInfoVo= JSONObject.parseObject(entity, StandardTicketInfoVo.class); if (standardTicketInfoVo.getSignage() == null) { throw new ServiceException("票据抬头未配置,请您到站点管理配置"); } @@ -126,7 +142,6 @@ public class OperationTicketServiceImpl implements OperationTicketService { throw new ServiceException("票据抬头未配置,请您到站点管理配置"); } //signage = signage.length() == 2 ? station.getSignage() : station.getSignage().substring(0, 2); - standardTicketInfoVo.setSignage(signage); standardTicketInfoVo.setSignageCode(station.getCode()); //2. 获取编码 @@ -137,18 +152,43 @@ public class OperationTicketServiceImpl implements OperationTicketService { } standardTicketInfoVo.setCode(code); //3. 保存操作对象 - this.saveStandardTicketInfo(standardTicketInfoVo); + StandardTicketInfoEntity standardTicketInfo = getStandardTicketInfoEntity(standardTicketInfoVo); + boolean save = standardTicketInfoService.save(standardTicketInfo); + if (!save) { + throw new ServiceException("Save failed"); + } + BeanUtils.copyProperties(standardTicketInfo, standardTicketInfoVo); //5. 保存安全措施 List standardTicketInfoVos = this.saveStandardTicketMeasure(this.saveStandardTicketMeasureWichTicket(standardTicketInfoVo)); standardTicketInfoVo.setStandardTicketMeasureVos(standardTicketInfoVos); - //6. 查询第操作票值 - String dictValue = processDictFeignService.selectDictValueByKey(OPERATION_TICKET_KEY); - log.info("查询第操作票值: {}", dictValue); - if (StringUtils.isBlank(dictValue)) { - throw new ServiceException("服务器异常,请联系管理员"); + log.info("保存操作对象 :{}", standardTicketInfoVo); + return JSON.toJSONString(standardTicketInfoVo); + } + + + + @Override + public void startProcess(String entity, String dictValue) { + StandardTicketInfoVo standardTicketInfoVo= JSONObject.parseObject(entity, StandardTicketInfoVo.class); + StandardTicketInfoEntity standardTicketInfoEntity = getStandardTicketInfoEntity(standardTicketInfoVo); + Instant start = Instant.now(); + Map params = new HashMap<>(4); + params.put("standardTicketInfoVo", standardTicketInfoVo); + params.put("taskId", standardTicketInfoVo.getId()); + params.put("guardianUserIds", "taskUser_".concat(standardTicketInfoVo.getGuardian().toString())); + //已开启流程 + R processInstanceContainNameByKey = flowClient.startProcessInstanceContainNameByKey(dictValue, String.valueOf(standardTicketInfoVo.getId()), standardTicketInfoVo.getTitle(), params); + if (!processInstanceContainNameByKey.isSuccess()) { + standardTicketInfoEntity.setIsNormal(false); + standardTicketInfoService.save(standardTicketInfoEntity); + log.error("开启流程失败 {}", processInstanceContainNameByKey.getMsg()); + throw new ServiceException("不好意思,您暂无权限..."); } - // 7.启动流程 - this.startProcess(standardTicketInfoVo, dictValue); + Duration between = Duration.between(start, Instant.now()); + log.info("================================================================"); + log.info("耗时: " + (between.getSeconds()) + "秒"); + log.info("耗时: " + (between.toMillis()) + "毫秒"); + log.info("================================================================"); } /** @@ -292,30 +332,6 @@ public class OperationTicketServiceImpl implements OperationTicketService { } } - /** - * 启动流程 - * - * @param standardTicketInfoVo - * @param dictValue - */ - private void startProcess(StandardTicketInfoVo standardTicketInfoVo, String dictValue) { - Instant start = Instant.now(); - Map params = new HashMap<>(4); - params.put("standardTicketInfoVo", standardTicketInfoVo); - params.put("taskId", standardTicketInfoVo.getId()); - params.put("guardianUserIds", "taskUser_".concat(standardTicketInfoVo.getGuardian().toString())); - //已开启流程 - R processInstanceContainNameByKey = flowClient.startProcessInstanceContainNameByKey(dictValue, String.valueOf(standardTicketInfoVo.getId()), standardTicketInfoVo.getTitle(), params); - if (!processInstanceContainNameByKey.isSuccess()) { - log.error("processInstanceContainNameByKey {}", processInstanceContainNameByKey.getMsg()); - throw new ServiceException("不好意思,您暂无权限..."); - } - Duration between = Duration.between(start, Instant.now()); - log.info("================================================================"); - log.info("耗时: " + (between.getSeconds()) + "秒"); - log.info("耗时: " + (between.toMillis()) + "毫秒"); - log.info("================================================================"); - } /** @@ -353,7 +369,6 @@ public class OperationTicketServiceImpl implements OperationTicketService { if (!save) { throw new ServiceException("Save failed"); } - return measureEntityList.stream().map(item -> { StandardTicketMeasureVo standardTicketMeasureVo = new StandardTicketMeasureVo(); BeanUtils.copyProperties(item, standardTicketMeasureVo); @@ -361,21 +376,16 @@ public class OperationTicketServiceImpl implements OperationTicketService { }).collect(Collectors.toList()); } - /** - * 保存工作对象 - * - * @param standardTicketInfoVo - * @return - */ - private void saveStandardTicketInfo(StandardTicketInfoVo standardTicketInfoVo) { + + private static StandardTicketInfoEntity getStandardTicketInfoEntity(StandardTicketInfoVo standardTicketInfoVo) { StandardTicketInfoEntity standardTicketInfo = new StandardTicketInfoEntity(); BeanUtils.copyProperties(standardTicketInfoVo, standardTicketInfo); - //保存前保存对应用户得姓名 - BladeUser user = AuthUtil.getUser(); - if (ObjectUtil.isNotEmpty(user.getUserName())){ - standardTicketInfo.setCreateUserName(user.getUserName()); - standardTicketInfo.setUpdateUserName(user.getUserName()); - } + //保存前保存对应用户得姓名 + BladeUser user = AuthUtil.getUser(); + if (ObjectUtil.isNotEmpty(user.getUserName())){ + standardTicketInfo.setCreateUserName(user.getUserName()); + standardTicketInfo.setUpdateUserName(user.getUserName()); + } /*发令人、受令人、负责人、监护人*/ if(ObjectUtil.isNotEmpty(standardTicketInfoVo.getIssueOrderPerson())) { @@ -397,12 +407,7 @@ public class OperationTicketServiceImpl implements OperationTicketService { standardTicketInfo.setGuardianName(guardian.getRealName()); } } - - boolean save = standardTicketInfoService.save(standardTicketInfo); - if (!save) { - throw new ServiceException("Save failed"); - } - BeanUtils.copyProperties(standardTicketInfo, standardTicketInfoVo); + return standardTicketInfo; } diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/TicketProcessServiceImpl.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/TicketProcessServiceImpl.java index 35f3e1e..425df0e 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/TicketProcessServiceImpl.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/TicketProcessServiceImpl.java @@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; +import com.hnac.hzims.common.flow.StartProcessService; import com.hnac.hzims.common.logs.utils.StringUtils; import com.hnac.hzims.middle.process.feign.ProcessDictFeignService; import com.hnac.hzims.middle.process.to.ProcessWorkFlowResponse; @@ -27,6 +28,7 @@ import com.hnac.hzims.ticket.twoTicket.service.TicketInfoDangerService; import com.hnac.hzims.ticket.twoTicket.service.TicketProcessService; import com.hnac.hzims.ticket.twoTicket.utils.WordHelper; import com.hnac.hzims.ticket.twoTicket.utils.WordMapUtils; +import com.hnac.hzims.ticket.twoTicket.vo.operation.StandardTicketInfoVo; import com.hnac.hzims.ticket.twoTicket.vo.process.FristWorkTicketVo; import com.hnac.hzims.ticket.twoTicket.vo.process.WorkTicketVo; import com.hnac.hzims.ticket.utils.MergeDocUtils; @@ -87,7 +89,7 @@ import static com.hnac.hzims.middle.process.constant.TicketProcessConstant.MACHI @Slf4j @RequiredArgsConstructor @Service -public class TicketProcessServiceImpl implements TicketProcessService { +public class TicketProcessServiceImpl implements TicketProcessService, StartProcessService { private final IFlowClient flowClient; @@ -159,12 +161,31 @@ public class TicketProcessServiceImpl implements TicketProcessService { * * @param workTicketVo */ - @SneakyThrows +// @SneakyThrows @Override @Transactional public Long startUp(WorkTicketVo workTicketVo) { log.info("ticket:start:request",JSON.toJSONString(workTicketVo)); log.info("执行 com.hnac.hzims.ticket.twoTicket.service.impl【startUp】 。。。方法"); + //保存操作票 + String saveEntity = saveEntity(JSONObject.toJSONString(workTicketVo)); + workTicketVo= JSONObject.parseObject(saveEntity, WorkTicketVo.class); + //查询第工作票值 + String dictValue = getDictValue(workTicketVo); + log.info("查询第工作票值: {}", dictValue); + if (StringUtils.isBlank(dictValue)) { + throw new ServiceException("服务器异常,请联系管理员"); + } + //开启动作流 + this.startProcess(saveEntity,dictValue); +// //处理任务--老版本业务要求,2024/07/05弃用 +// this.returnTicket(workTicketVo); + return workTicketVo.getWorkTicket().getId(); + } + + @Override + public String saveEntity(String entity) { + WorkTicketVo workTicketVo= JSONObject.parseObject(entity, WorkTicketVo.class); if (workTicketVo.getWorkTicket().getSignage() == null) { throw new ServiceException("票据抬头未配置,请您到站点管理配置"); } @@ -200,27 +221,63 @@ public class TicketProcessServiceImpl implements TicketProcessService { throw new ServiceException("服务器异常,请联系管理员"); } workTicketVo.getWorkTicket().setCode(code); - //3 .保存工作对象 + //保存工作对象 log.info("ticket:start:vo",JSON.toJSONString(workTicketVo.getWorkTicket())); - this.saveWorkTicketInfo(workTicketVo.getWorkTicket()); - //4. 保存安全措施 + WorkTicketInfoEntity workTicket = getWorkTicketInfo(workTicketVo.getWorkTicket()); + boolean isSave = firstWorkTicketService.save(workTicket); + log.info("ticket:start:save",JSON.toJSONString(workTicket)); + if (!isSave) { + throw new IllegalArgumentException("保存工作对象错误"); + } + //保存安全措施 this.saveSafetyMeasures(workTicketVo.getSafetyMeasuresList(), workTicketVo.getWorkTicket()); - //5. 保存工作任务 + //保存工作任务 this.saveWorkTicketContentDto(workTicketVo.getWorkTicketContentDtoList(), workTicketVo.getWorkTicket()); - //6. 查询第工作票值 - String dictValue = getDictValue(workTicketVo); - log.info("查询第工作票值: {}", dictValue); - if (StringUtils.isBlank(dictValue)) { - throw new ServiceException("服务器异常,请联系管理员"); + return JSONObject.toJSONString(workTicketVo); + } + + @Override + public void startProcess(String entity, String dictValue) { + WorkTicketVo workTicketVo= JSONObject.parseObject(entity, WorkTicketVo.class); + WorkTicketInfoEntity workTicket = getWorkTicketInfo(workTicketVo.getWorkTicket()); + workTicketVo.setWorkTicket(workTicket); + Instant start = Instant.now(); + //若为线下工作票 则无需开启工作流 + Integer status = WorkTicketConstants.FirstWorkTicketStatusEnum.SIGN.getStatus(); + if (status.intValue() != workTicketVo.getWorkTicket().getFlowStatus().intValue()) { + return; + } + Map params = new HashMap<>(4); + params.put("workTicketVo", workTicketVo); + //获取当前登录人 + Long userId = AuthUtil.getUserId(); + //负责人 + Long principal = workTicketVo.getWorkTicket().getPrincipal(); + if ("8".equals(workTicketVo.getWorkTicket().getType()) && principal.longValue() != userId.longValue()) { + params.put("principal", "taskUser_" + workTicketVo.getWorkTicket().getPrincipal()); } - //7. 开启动作流 - this.dealProcess(dictValue, workTicketVo); - //8. 处理任务 - this.returnTicket(workTicketVo); + //已开启流程 + R processInstanceContainNameByKey = flowClient.startProcessInstanceContainNameByKey(dictValue, String.valueOf(workTicketVo.getWorkTicket().getId()), workTicketVo.getWorkTicket().getWorkContent(), params); + log.info("processInstanceContainNameByKey.isSuccess() : {}", processInstanceContainNameByKey.isSuccess()); + if (!processInstanceContainNameByKey.isSuccess()) { + //保存流程开始失败情况 + workTicket.setIsNormal(false); + boolean isSave = firstWorkTicketService.save(workTicket); + log.info("ticket:start:save",JSON.toJSONString(workTicket)); + if (!isSave) { + throw new IllegalArgumentException("保存工作对象错误"); + } + log.error("processInstanceContainNameByKey {}", processInstanceContainNameByKey.getMsg()); + throw new ServiceException("流程开启失败,请检查流程和用户权限后重试!"); + } + log.info("获取启动流程数据 : {}", processInstanceContainNameByKey); + Duration between = Duration.between(start, Instant.now()); - return workTicketVo.getWorkTicket().getId(); + log.info("================================================================"); + log.info("耗时: " + (between.getSeconds()) + "秒"); + log.info("耗时: " + (between.toMillis()) + "毫秒"); + log.info("================================================================"); } - /** * 验证是走那种工作票流程,默认走第一种工作票 * @@ -707,54 +764,6 @@ public class TicketProcessServiceImpl implements TicketProcessService { } } - - /** - * 开启流程 - * - * @param newFirstWorkTicketFlowKey - * @param workTicketVo - */ - public void dealProcess(String newFirstWorkTicketFlowKey, WorkTicketVo workTicketVo) { - Instant start = Instant.now(); - //若为线下工作票 则无需开启工作流 - Integer status = WorkTicketConstants.FirstWorkTicketStatusEnum.SIGN.getStatus(); - if (status.intValue() != workTicketVo.getWorkTicket().getFlowStatus().intValue()) { - return; - } - //log.info("租户Id:{}", AuthUtil.getTenantId()); - //log.info("用户部门Id: {}", AuthUtil.getUser().getDeptId()); - //log.info("用户Id: {}", AuthUtil.getUserId()); - //获取签发人角色下的人员 - // R> listR = userClient.relationUserListByRoleAlias(AuthUtil.getTenantId(), Long.parseLong(AuthUtil.getUser().getDeptId()), TicketConstants.SIGNER_ROLE); - // if (!listR.isSuccess() || CollectionUtil.isEmpty(listR.getData())) { - // throw new ServiceException("工作票签发人角色下未查询到相关人员"); - // } - Map params = new HashMap<>(4); - params.put("workTicketVo", workTicketVo); - //获取当前登录人 - Long userId = AuthUtil.getUserId(); - //负责人 - Long principal = workTicketVo.getWorkTicket().getPrincipal(); - if ("8".equals(workTicketVo.getWorkTicket().getType()) && principal.longValue() != userId.longValue()) { - params.put("principal", "taskUser_" + workTicketVo.getWorkTicket().getPrincipal()); - } - //已开启流程 - R processInstanceContainNameByKey = flowClient.startProcessInstanceContainNameByKey(newFirstWorkTicketFlowKey, String.valueOf(workTicketVo.getWorkTicket().getId()), workTicketVo.getWorkTicket().getWorkContent(), params); - log.info("processInstanceContainNameByKey.isSuccess() : {}", processInstanceContainNameByKey.isSuccess()); - if (!processInstanceContainNameByKey.isSuccess() && processInstanceContainNameByKey.getCode() == 500) { - log.error("processInstanceContainNameByKey {}", processInstanceContainNameByKey.getMsg()); - throw new ServiceException("不好意思,您暂无权限..."); - } - log.info("获取启动流程数据 : {}", processInstanceContainNameByKey); - Duration between = Duration.between(start, Instant.now()); - - log.info("================================================================"); - log.info("耗时: " + (between.getSeconds()) + "秒"); - log.info("耗时: " + (between.toMillis()) + "毫秒"); - log.info("================================================================"); - } - - /** * 保存工作任务 * @@ -810,7 +819,7 @@ public class TicketProcessServiceImpl implements TicketProcessService { * @param workTicket * @return */ - public WorkTicketInfoEntity saveWorkTicketInfo(WorkTicketInfoEntity workTicket) { + public WorkTicketInfoEntity getWorkTicketInfo(WorkTicketInfoEntity workTicket) { workTicket.setStatus(Func.isEmpty(workTicket.getPrincipal()) || Func.isEmpty(workTicket.getClassGroupMembers()) ? WorkTicketConstants.FirstWorkTicketStatusEnum.OFFLINE_OPERATE.getStatus() : WorkTicketConstants.FirstWorkTicketStatusEnum.SIGN.getStatus()); //班组成员名称 String byclassGroupMembers = getByClassGroupMembers(workTicket); @@ -826,11 +835,6 @@ public class TicketProcessServiceImpl implements TicketProcessService { workTicket.setIsHazard(false); workTicket.setIsRailway(false); workTicket.setIsLimited(false); - boolean isSave = firstWorkTicketService.save(workTicket); - log.info("ticket:start:save",JSON.toJSONString(workTicket)); - if (!isSave) { - throw new IllegalArgumentException("保存工作对象错误"); - } return workTicket; } @@ -1392,7 +1396,7 @@ public class TicketProcessServiceImpl implements TicketProcessService { * @param workTicketVo 工作票 * @return 工作流实例ID */ - private String startOfflineTicketProcess(WorkTicketVo workTicketVo) { + public String startOfflineTicketProcess(WorkTicketVo workTicketVo) { WorkTicketInfoEntity workTicket = workTicketVo.getWorkTicket(); Map params = new HashMap<>(); workTicketVo.setWorkTicket(workTicket); @@ -1400,6 +1404,13 @@ public class TicketProcessServiceImpl implements TicketProcessService { R flowR = flowClient.startProcessInstanceContainNameByKey("offlineWorkTicket",String.valueOf(workTicket.getId()),workTicket.getWorkContent(), params); Assert.isTrue(flowR.isSuccess(),() -> { + //保存流程开始失败情况 + workTicket.setIsNormal(false); + boolean isSave = firstWorkTicketService.save(workTicket); + log.info("ticket:start:save",JSON.toJSONString(workTicket)); + if (!isSave) { + throw new IllegalArgumentException("保存工作对象错误"); + } throw new ServiceException("开启工作流失败,请联系管理员"); }); return flowR.getData().getProcessInstanceId(); diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/vo/operation/StandardTicketInfoVo.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/vo/operation/StandardTicketInfoVo.java index e777e6e..083aeb3 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/vo/operation/StandardTicketInfoVo.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/vo/operation/StandardTicketInfoVo.java @@ -150,6 +150,9 @@ public class StandardTicketInfoVo extends TenantEntity { @ApiModelProperty("许可人名称") private String guardianName; + @ApiModelProperty("是否运行正常") + private Boolean isNormal; + @ApiModelProperty("安全措施") private List standardTicketMeasureVos; }