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 cb82cba..3511d30 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 @@ -249,234 +249,239 @@ public class TicketProcessServiceImpl implements TicketProcessService { @Override @Transactional(rollbackFor = Exception.class) public void findPending(ProcessWorkFlowResponse response) { - log.info("获取待处理的数据 {}", response); - log.info("获取businessKey: {}", response.getBusinessKey()); - log.info("获取taskId: {}", response.getTaskId()); - log.info("获取下一个审批人是: {}", response.getNextStepOperator()); - log.info("获取下一个用户Id是: {}", response.getUserId()); - log.info("获取当前任务名称是: {}", response.getTaskName()); - log.info("获取根据handleType区分是用户还是候选组角色: {}", response.getHandleType()); - //json转换表单 - String formData = JSON.toJSONString(response.getVariables()); - log.info("获取表单的数据:{}", formData); - FristWorkTicketVo fristWorkFlowResponse = null; + try { - fristWorkFlowResponse = JSONObject.parseObject(formData, FristWorkTicketVo.class); - } catch (Exception e) { - log.error("获取表单出现异常了~~~~"); - throw new IllegalArgumentException(e.getMessage()); - } - //获取表单数据 - WorkTicketVo workTicketVo = fristWorkFlowResponse.getWorkTicketVo(); - WorkTicketInfoEntity workTicket = workTicketVo.getWorkTicket(); - //2.流程处理 - String businessKey = response.getBusinessKey(); - WorkTicketInfoEntity workTicketInfo = ticketInfoService.getById(businessKey); - if (ObjectUtils.isEmpty(workTicketInfo)) { - log.error("获取工作票的数据为不存在"); - return; - } - //更新工作票 - workTicket.setId(workTicketInfo.getId()); - //保存流程描述 - workTicket.setCreateDept(workTicketInfo.getCreateDept()); - workTicket.setCreateUser(workTicketInfo.getCreateUser()); - workTicket.setTenantId(workTicketInfo.getTenantId()); - saveWorkTicket(workTicket, response); - //工作流ID - workTicket.setProcessInstanceId(response.getProcessInstanceId()); - workTicketInfoService.updateById(workTicket); - //更新安全措施 - List safetyMeasuresList = workTicketVo.getSafetyMeasuresList(); - if (CollectionUtils.isNotEmpty(safetyMeasuresList)) { - log.info("获取安全措施的数据:{}", safetyMeasuresList); - for (WorkTicketSafetyMeasureEntity item : safetyMeasuresList) { - if (ObjectUtils.isNotEmpty(item.getId())) { - workTicketSafetyMeasureService.updateById(item); - } else { - item.setTicketId(workTicketInfo.getId()); - workTicketSafetyMeasureService.save(item); + log.info("获取待处理的数据 {}", response); + log.info("获取businessKey: {}", response.getBusinessKey()); + log.info("获取taskId: {}", response.getTaskId()); + log.info("获取下一个审批人是: {}", response.getNextStepOperator()); + log.info("获取下一个用户Id是: {}", response.getUserId()); + log.info("获取当前任务名称是: {}", response.getTaskName()); + log.info("获取根据handleType区分是用户还是候选组角色: {}", response.getHandleType()); + //json转换表单 + String formData = JSON.toJSONString(response.getVariables()); + log.info("获取表单的数据:{}", formData); + FristWorkTicketVo fristWorkFlowResponse = null; + try { + fristWorkFlowResponse = JSONObject.parseObject(formData, FristWorkTicketVo.class); + } catch (Exception e) { + log.error("获取表单出现异常了~~~~"); + throw new IllegalArgumentException(e.getMessage()); + } + //获取表单数据 + WorkTicketVo workTicketVo = fristWorkFlowResponse.getWorkTicketVo(); + WorkTicketInfoEntity workTicket = workTicketVo.getWorkTicket(); + //2.流程处理 + String businessKey = response.getBusinessKey(); + WorkTicketInfoEntity workTicketInfo = ticketInfoService.getById(businessKey); + if (ObjectUtils.isEmpty(workTicketInfo)) { + log.error("获取工作票的数据为不存在"); + return; + } + //更新工作票 + workTicket.setId(workTicketInfo.getId()); + //保存流程描述 + workTicket.setCreateDept(workTicketInfo.getCreateDept()); + workTicket.setCreateUser(workTicketInfo.getCreateUser()); + workTicket.setTenantId(workTicketInfo.getTenantId()); + saveWorkTicket(workTicket, response); + //工作流ID + workTicket.setProcessInstanceId(response.getProcessInstanceId()); + workTicketInfoService.updateById(workTicket); + //更新安全措施 + List safetyMeasuresList = workTicketVo.getSafetyMeasuresList(); + if (CollectionUtils.isNotEmpty(safetyMeasuresList)) { + log.info("获取安全措施的数据:{}", safetyMeasuresList); + for (WorkTicketSafetyMeasureEntity item : safetyMeasuresList) { + if (ObjectUtils.isNotEmpty(item.getId())) { + workTicketSafetyMeasureService.updateById(item); + } else { + item.setTicketId(workTicketInfo.getId()); + workTicketSafetyMeasureService.save(item); + } } } - } - // 第二种 工作票工作任务组 - List workTicketContentDtoList = workTicketVo.getWorkTicketContentDtoList(); - if (CollectionUtils.isNotEmpty(workTicketContentDtoList)) { - log.info("获取工作票工作任务组:{}", workTicketContentDtoList); - workTicketContentDtoList.forEach(item -> { - if (ObjectUtils.isEmpty(item.getId())) { - contentService.save(item); + // 第二种 工作票工作任务组 + List workTicketContentDtoList = workTicketVo.getWorkTicketContentDtoList(); + if (CollectionUtils.isNotEmpty(workTicketContentDtoList)) { + log.info("获取工作票工作任务组:{}", workTicketContentDtoList); + workTicketContentDtoList.forEach(item -> { + if (ObjectUtils.isEmpty(item.getId())) { + contentService.save(item); + } else { + contentService.updateById(item); + } + }); + } + + // 工作票延期 + WorkTicketDelayEntity workTicketDelay = workTicketVo.getWorkTicketDelay(); + if (ObjectUtils.isNotEmpty(workTicketDelay) && "延期".equals(workTicket.getInput())) { + + WorkTicketDelayEntity workTicketDelayEntity = workTicketDelayService.selectByTicketId(workTicketInfo.getId()); + log.info("获取工作票延期:{}", workTicketDelay); + workTicketDelay.setCreateDept(workTicketInfo.getCreateDept()); + workTicketDelay.setTicketId(workTicketInfo.getId()); + workTicketDelay.setTenantId(workTicketInfo.getTenantId()); + if (ObjectUtils.isEmpty(workTicketDelayEntity)) { + log.info("正在保存工作票延期"); + workTicketDelayService.save(workTicketDelay); } else { - contentService.updateById(item); + log.info("正在更新工作票延期"); + workTicketDelayService.updateByTicketId(workTicketDelay); } - }); - } - - // 工作票延期 - WorkTicketDelayEntity workTicketDelay = workTicketVo.getWorkTicketDelay(); - if (ObjectUtils.isNotEmpty(workTicketDelay) && "延期".equals(workTicket.getInput())) { - - WorkTicketDelayEntity workTicketDelayEntity = workTicketDelayService.selectByTicketId(workTicketInfo.getId()); - log.info("获取工作票延期:{}", workTicketDelay); - workTicketDelay.setCreateDept(workTicketInfo.getCreateDept()); - workTicketDelay.setTicketId(workTicketInfo.getId()); - workTicketDelay.setTenantId(workTicketInfo.getTenantId()); - if (ObjectUtils.isEmpty(workTicketDelayEntity)) { - log.info("正在保存工作票延期"); - workTicketDelayService.save(workTicketDelay); - } else { - log.info("正在更新工作票延期"); - workTicketDelayService.updateByTicketId(workTicketDelay); } - } - //工作结束 - WorkTicketFinish workTicketFinish = workTicketVo.getWorkTicketFinish(); - log.info("工作结束==============>" + (workTicket.getFlowStatus().intValue())); - if (ObjectUtils.isNotEmpty(workTicketFinish)) { - WorkTicketFinish ticketFinish = workTicketFinishService.selectByTicketId(workTicketInfo.getId()); - log.info("获取工作结束:{}", workTicketFinish); - if (ObjectUtils.isEmpty(workTicketFinish.getId()) || ObjectUtils.isEmpty(ticketFinish)) { - log.info("获取工作结束保存成功"); - workTicketFinish.setTicketId(workTicketInfo.getId()); - workTicketFinishService.save(workTicketFinish); - } else { - log.info("获取工作结束更新成功"); - workTicketDelay.setInitialTime(LocalDateTime.now()); - workTicketFinishService.updateByTicketId(workTicketFinish); + //工作结束 + WorkTicketFinish workTicketFinish = workTicketVo.getWorkTicketFinish(); + log.info("工作结束==============>" + (workTicket.getFlowStatus().intValue())); + if (ObjectUtils.isNotEmpty(workTicketFinish)) { + WorkTicketFinish ticketFinish = workTicketFinishService.selectByTicketId(workTicketInfo.getId()); + log.info("获取工作结束:{}", workTicketFinish); + if (ObjectUtils.isEmpty(workTicketFinish.getId()) || ObjectUtils.isEmpty(ticketFinish)) { + log.info("获取工作结束保存成功"); + workTicketFinish.setTicketId(workTicketInfo.getId()); + workTicketFinishService.save(workTicketFinish); + } else { + log.info("获取工作结束更新成功"); + workTicketDelay.setInitialTime(LocalDateTime.now()); + workTicketFinishService.updateByTicketId(workTicketFinish); + } } - } - // 工作开始时间和结束时间 - // List workTicketOperateTimeEntities = workTicketVo.getWorkTicketOperateTimeEntities(); - // if (CollectionUtils.isNotEmpty(workTicketOperateTimeEntities)) { - // log.info("工作开始时间和结束时间:{}", workTicketFinish); - // workTicketOperateTimeService.saveBatch(workTicketOperateTimeEntities); - // } - //工作票负责人变更 - WorkTicketPrincipalChangeEntity workTicketPrincipalChange = workTicketVo.getWorkTicketPrincipalChange(); - if (ObjectUtils.isNotEmpty(workTicketPrincipalChange) && "转移".equals(workTicket.getInput())) { - log.info("工作票负责人变更: {}", workTicketPrincipalChange); - //原来的负责人 - User user = UserCache.getUser(workTicketPrincipalChange.getInitialPrincipal()); - //新的负责人 - User newUser = UserCache.getUser(workTicketPrincipalChange.getChangePrincipal()); - workTicketPrincipalChange.setCreateDept(workTicketInfo.getCreateDept()); - workTicketPrincipalChange.setTicketId(workTicketInfo.getId()); - workTicketPrincipalChange.setTenantId(workTicketInfo.getTenantId()); - if (workTicketPrincipalChange.getFlowCode() == null) { - workTicketPrincipalChange.setFlowCode(IdWorker.getIdStr()); - } + // 工作开始时间和结束时间 + // List workTicketOperateTimeEntities = workTicketVo.getWorkTicketOperateTimeEntities(); + // if (CollectionUtils.isNotEmpty(workTicketOperateTimeEntities)) { + // log.info("工作开始时间和结束时间:{}", workTicketFinish); + // workTicketOperateTimeService.saveBatch(workTicketOperateTimeEntities); + // } + //工作票负责人变更 + WorkTicketPrincipalChangeEntity workTicketPrincipalChange = workTicketVo.getWorkTicketPrincipalChange(); + if (ObjectUtils.isNotEmpty(workTicketPrincipalChange) && "转移".equals(workTicket.getInput())) { + log.info("工作票负责人变更: {}", workTicketPrincipalChange); + //原来的负责人 + User user = UserCache.getUser(workTicketPrincipalChange.getInitialPrincipal()); + //新的负责人 + User newUser = UserCache.getUser(workTicketPrincipalChange.getChangePrincipal()); + workTicketPrincipalChange.setCreateDept(workTicketInfo.getCreateDept()); + workTicketPrincipalChange.setTicketId(workTicketInfo.getId()); + workTicketPrincipalChange.setTenantId(workTicketInfo.getTenantId()); + if (workTicketPrincipalChange.getFlowCode() == null) { + workTicketPrincipalChange.setFlowCode(IdWorker.getIdStr()); + } - WorkTicketPrincipalChangeEntity workTicketPrincipalChangeEntity = workTicketPrincipalChangeService.selectByTicketId(workTicket.getId()); + WorkTicketPrincipalChangeEntity workTicketPrincipalChangeEntity = workTicketPrincipalChangeService.selectByTicketId(workTicket.getId()); - if (ObjectUtils.isEmpty(workTicketPrincipalChangeEntity)) { - log.info("工作票负责人保存变更"); - workTicketPrincipalChangeService.save(workTicketPrincipalChange); - } else { - log.info("工作票负责人更新变更"); - workTicketPrincipalChangeService.updateByTicketId(workTicketPrincipalChange); + if (ObjectUtils.isEmpty(workTicketPrincipalChangeEntity)) { + log.info("工作票负责人保存变更"); + workTicketPrincipalChangeService.save(workTicketPrincipalChange); + } else { + log.info("工作票负责人更新变更"); + workTicketPrincipalChangeService.updateByTicketId(workTicketPrincipalChange); + } + log.info("工作负责人变更 原来的负责人 {},变更为 {}", user.getName(), newUser.getName()); + workTicket.setPrincipal(workTicketPrincipalChange.getChangePrincipal()); + workTicket.setPrincipalName(newUser.getName()); + //更新工作票 + workTicketInfoService.updateById(workTicket); } - log.info("工作负责人变更 原来的负责人 {},变更为 {}", user.getName(), newUser.getName()); - workTicket.setPrincipal(workTicketPrincipalChange.getChangePrincipal()); - workTicket.setPrincipalName(newUser.getName()); - //更新工作票 - workTicketInfoService.updateById(workTicket); - } - //工作票危险点分析及控制措施票 - if (workTicket.getIsHazard()) { - List ticketInfoDangers = workTicketVo.getTicketInfoDangers(); - if (CollectionUtils.isNotEmpty(ticketInfoDangers)) { - List collect = ticketInfoDangers.stream().map(item -> { - item.setTicketId(workTicketInfo.getId()); - return item; - }).collect(Collectors.toList()); + //工作票危险点分析及控制措施票 + if (workTicket.getIsHazard()) { + List ticketInfoDangers = workTicketVo.getTicketInfoDangers(); + if (CollectionUtils.isNotEmpty(ticketInfoDangers)) { + List collect = ticketInfoDangers.stream().map(item -> { + item.setTicketId(workTicketInfo.getId()); + return item; + }).collect(Collectors.toList()); - System.out.println("工作票危险点分析及控制措施票 : " + collect); + System.out.println("工作票危险点分析及控制措施票 : " + collect); - ticketInfoDangerService.saveBatch(collect); + ticketInfoDangerService.saveBatch(collect); + } } - } - if (response.getTaskId() != null || response.getUserId() != null) { - //推送消息 - // try { - // MessagePushRecordDto message = new MessagePushRecordDto(); - // message.setBusinessClassify("business"); - // message.setBusinessKey(MessageConstants.BusinessClassifyEnum.TICKETMESSAGE.getKey()); - // message.setSubject(MessageConstants.BusinessClassifyEnum.TICKETMESSAGE.getDescription()); - // message.setTaskId(workTicketInfo.getId()); - // message.setTenantId("200000"); - // message.setTypes(Arrays.asList(MessageConstants.APP_PUSH, MessageConstants.WS_PUSH)); - // message.setPushType(MessageConstants.IMMEDIATELY); - // //您有一张工作票待审批,工作内容:*****,审批环节:*****; - // String countent = - // "您有一张工作票待审批,工作内容: ".concat(workTicketInfo.getWorkContent()) - // .concat(",审批环节: ") - // .concat(response.getTaskName()); - // message.setContent(countent); - // message.setDeptId(workTicketInfo.getCreateDept()); - // message.setCreateDept(workTicketInfo.getCreateDept()); - // R deptName = sysClient.getDeptName(workTicketInfo.getCreateDept()); - // if (deptName.isSuccess()) { - // message.setDeptName(deptName.getData()); - // } - // String userIds = response.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); - // log.info("推送消息成功,用户名称{},消息{}", user.getName(), message); - // } - // } catch (Exception e) { - // e.printStackTrace(); - // } - - - BusinessMessageDTO businessMessageDTO = new BusinessMessageDTO(); - businessMessageDTO.setBusinessClassify("business"); - businessMessageDTO.setBusinessKey(MessageConstants.BusinessClassifyEnum.TICKETMESSAGE.getKey()); - businessMessageDTO.setSubject(MessageConstants.BusinessClassifyEnum.TICKETMESSAGE.getDescription()); - businessMessageDTO.setTaskId(workTicketInfo.getId()); - businessMessageDTO.setTenantId("200000"); - //您有一张工作票待审批,工作内容:*****,审批环节:*****; - String countent = - "您有一张工作票待审批,工作内容: ".concat(workTicketInfo.getWorkContent()) - .concat(",审批环节: ") - .concat(response.getTaskName()); - businessMessageDTO.setContent(countent); - businessMessageDTO.setDeptId(workTicketInfo.getCreateDept()); - R deptName = sysClient.getDeptName(workTicketInfo.getCreateDept()); - if (deptName.isSuccess()) { - businessMessageDTO.setDeptName(deptName.getData()); - } - String userIds = response.getUserId(); - businessMessageDTO.setUserIds(userIds); - businessMessageDTO.setCreateUser(workTicketInfo.getCreateUser()); - System.out.println("======================================================"); - System.out.println("businessMessageDTO = " + businessMessageDTO); - System.out.println("======================================================"); - R booleanR = messageClient.sendAppAndWsMsgByUsers(businessMessageDTO); - if (!booleanR.isSuccess()) { - throw new ServiceException("消息推送失败"); + if (response.getTaskId() != null || response.getUserId() != null) { + //推送消息 + // try { + // MessagePushRecordDto message = new MessagePushRecordDto(); + // message.setBusinessClassify("business"); + // message.setBusinessKey(MessageConstants.BusinessClassifyEnum.TICKETMESSAGE.getKey()); + // message.setSubject(MessageConstants.BusinessClassifyEnum.TICKETMESSAGE.getDescription()); + // message.setTaskId(workTicketInfo.getId()); + // message.setTenantId("200000"); + // message.setTypes(Arrays.asList(MessageConstants.APP_PUSH, MessageConstants.WS_PUSH)); + // message.setPushType(MessageConstants.IMMEDIATELY); + // //您有一张工作票待审批,工作内容:*****,审批环节:*****; + // String countent = + // "您有一张工作票待审批,工作内容: ".concat(workTicketInfo.getWorkContent()) + // .concat(",审批环节: ") + // .concat(response.getTaskName()); + // message.setContent(countent); + // message.setDeptId(workTicketInfo.getCreateDept()); + // message.setCreateDept(workTicketInfo.getCreateDept()); + // R deptName = sysClient.getDeptName(workTicketInfo.getCreateDept()); + // if (deptName.isSuccess()) { + // message.setDeptName(deptName.getData()); + // } + // String userIds = response.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); + // log.info("推送消息成功,用户名称{},消息{}", user.getName(), message); + // } + // } catch (Exception e) { + // e.printStackTrace(); + // } + + + BusinessMessageDTO businessMessageDTO = new BusinessMessageDTO(); + businessMessageDTO.setBusinessClassify("business"); + businessMessageDTO.setBusinessKey(MessageConstants.BusinessClassifyEnum.TICKETMESSAGE.getKey()); + businessMessageDTO.setSubject(MessageConstants.BusinessClassifyEnum.TICKETMESSAGE.getDescription()); + businessMessageDTO.setTaskId(workTicketInfo.getId()); + businessMessageDTO.setTenantId("200000"); + //您有一张工作票待审批,工作内容:*****,审批环节:*****; + String countent = + "您有一张工作票待审批,工作内容: ".concat(workTicketInfo.getWorkContent()) + .concat(",审批环节: ") + .concat(response.getTaskName()); + businessMessageDTO.setContent(countent); + businessMessageDTO.setDeptId(workTicketInfo.getCreateDept()); + R deptName = sysClient.getDeptName(workTicketInfo.getCreateDept()); + if (deptName.isSuccess()) { + businessMessageDTO.setDeptName(deptName.getData()); + } + String userIds = response.getUserId(); + businessMessageDTO.setUserIds(userIds); + businessMessageDTO.setCreateUser(workTicketInfo.getCreateUser()); + System.out.println("======================================================"); + System.out.println("businessMessageDTO = " + businessMessageDTO); + System.out.println("======================================================"); + R booleanR = messageClient.sendAppAndWsMsgByUsers(businessMessageDTO); + if (!booleanR.isSuccess()) { + throw new ServiceException("消息推送失败"); + } + log.info("推送成功~"); } - log.info("推送成功~"); + } catch (Exception e) { + e.getMessage(); } }