@Override
public boolean doCommonFlowApproveAsync(FlowApprovalDtoSync flowApprovalDtoSync, LoginAuthDto loginAuthDto) {
// (1) menuDto置空,防止数据过大导致setpRecord失败
loginAuthDto.setMenuDtos(null);
FlowApprovalDto flowApprovalDto = flowApprovalDtoSync.getFlowApprovalDto();
log.info("=====================================多场景完成工作项=============================");
log.info("入参flowApprovalDtoSync:{}", JSON.toJSONString(flowApprovalDtoSync));
final WorkFlowHistory infoDto = this.mdsgFlowService.getWorkFlowInfo(flowApprovalDto.getWorkflowId());
log.info("=========infoDto:================={}", infoDto);
final DesignReply designReply = this.designReplyMapper.selectById(flowApprovalDto.getBusinessId());
log.info("=========designReply:================={}", designReply);
// (2) 重置流程节点单据名称
if (ReplyConstant.DESIGN_REPLY_TYPE.equals(infoDto.getBusinessType()) || ReplyConstant.CHANGE_REPLY_TYPE.equals(infoDto.getBusinessType())) {
final String subject = OddNumbersGenerate.createSubject(DESIGN_CHANGE_REPLY_NAME, designReply.getProjectName(), designReply.getProjectCode());
infoDto.setSubject(subject);
flowApprovalDto.setSubject(subject);
}
flowApprovalDto.setUserId(loginAuthDto.getLoginName());
flowApprovalDto.setSubject(infoDto.getSubject());
flowApprovalDto.setBusinessType(BusinessTypeEnum.SBPF_TYPE.getType());
String isReceived = "false";
if (ReplyConstant.DESIGN_CHANGE_REPLY_RECEIVED.equals(infoDto.getBusinessType())) {
isReceived = "true";
}
// (3) 更新待办为已办
if (Objects.nonNull(infoDto)) {
final String doneBusinessUrl = URL_PREFIX_CHANGE_REPLY + "look" + CommonConstant.ADD_ + "current="
+ infoDto.getActivityDefId() + CommonConstant.ADD_ + "auditId=" + infoDto.getBusinessId()
+ CommonConstant.ADD_ + "workflowId=" + infoDto.getId() + CommonConstant.ADD_ + "proInsID="
+ infoDto.getProcessInstId() + CommonConstant.ADD_ + "workItemId=" + infoDto.getWorkItemId() + CommonConstant.ADD_ + "isReceived=" + isReceived;
infoDto.setBusinessUrl(doneBusinessUrl);
flowApprovalDto.setDoneBusinessUrl(doneBusinessUrl);
final String doneMoaBusinessUrl = CommonConstant.CHANGE_REPLY_MOA_PREFIX_URL + infoDto.getBusinessId();
infoDto.setBusinessMoaUrl(doneMoaBusinessUrl);
flowApprovalDto.setDoneMoaBusinessUrl(doneMoaBusinessUrl);
}
// (4) MOA url
flowApprovalDto.setBusinessMoaUrl(CommonConstant.CHANGE_REPLY_MOA_PREFIX_URL + infoDto.getBusinessId() + "?current={activityDefIdValue}"
+ "&workItemID={workitemIdValue}" + "&workflowId={workflowIdValue}");
// (5) 判断是否为驳回
if (CommonConstant.S_TWO.equals(flowApprovalDto.getOptionType())) {
//是驳回
String type = "recp";
if ("startDesignReply".equals(flowApprovalDto.getNextActivityDefId())) {
type = "edit";
}
final String businessUrl = URL_PREFIX_CHANGE_REPLY + type + CommonConstant.ADD_ + "current={activityDefIdValue}"
+ CommonConstant.ADD_ + "auditId=" + infoDto.getBusinessId()
+ CommonConstant.ADD_ + "workflowId={workflowIdValue}" + CommonConstant.ADD_
+ "proInsID={processInstIdValue}" + CommonConstant.ADD_ + "workItemId={workitemIdValue}" + CommonConstant.ADD_ + "isReceived=" + isReceived;
flowApprovalDto.setBusinessUrl(businessUrl);
} else {//不是驳回
final String businessUrl1 = URL_PREFIX_CHANGE_REPLY + "recp" + CommonConstant.ADD_
+ "current={activityDefIdValue}" + CommonConstant.ADD_ + "auditId="
+ infoDto.getBusinessId() + CommonConstant.ADD_ + "workflowId={workflowIdValue}"
+ CommonConstant.ADD_ + "proInsID={processInstIdValue}"
+ CommonConstant.ADD_ + "workItemId={workitemIdValue}" + CommonConstant.ADD_ + "isReceived=" + isReceived;
flowApprovalDto.setBusinessUrl(businessUrl1);
}
// (6) 设计变更批复审批
AsyncStep<FlowSubmitResponseDto> asyncStep = AsyncStep.of("设计变更批复审批", () -> {
//设计批复审批放到第一步,防止补偿时重复执行报错。
FlowSubmitResponseDto flowSubmitResponseDto = this.mdsgFlowService.multiSceneCompleteWorkItemExtra(flowApprovalDto, loginAuthDto);
return flowSubmitResponseDto;
});
// (7) 流程编排
String finalIsReceived = isReceived;
AsyncStep<Boolean> vAsyncStep = asyncStep.andThen("更新本地待办", flowSubmitResponseDto -> {
this.mdsgFlowService.updateWorkFlow(infoDto, flowApprovalDto.getOptionText(), flowApprovalDto.getOptionType());
return flowSubmitResponseDto;
}).andThen("创建下一步待办", flowSubmitResponseDto -> {
if (!(flowSubmitResponseDto.getProcessInstIsEnd() && !CommonConstant.CODE_02.equals(designReply.getReplyStatus()))) {
final List<WFWorkItemDto> workItemList = flowSubmitResponseDto.getWorkItemList();
if (CollectionUtils.isNotEmpty(workItemList)) {
final WorkFlowHistory pendingInfo = new WorkFlowHistory();
BeanUtils.copyProperties(infoDto, pendingInfo);
for (int i = 0; i < workItemList.size(); i++) {
final WFWorkItemDto workItem = workItemList.get(i);
log.info("workItem:{}", JsonUtil.toJson(workItem));
final WorkFlowHistory workFlowHistory = this.historyMapper
.selectOne(Wrappers.<WorkFlowHistory>lambdaQuery().eq(WorkFlowHistory::getWorkItemId,
String.valueOf(workItem.getWorkItemID())).eq(WorkFlowHistory::getBusinessId, flowApprovalDto.getBusinessId()));
if (Objects.isNull(workFlowHistory)) {
pendingInfo.setId(workItem.getWorkflowId());
//创建下一待办人的信息
final String activityDefId = workItem.getActivityDefID();
//MOA url
final String moaUrl = CommonConstant.CHANGE_REPLY_MOA_PREFIX_URL + pendingInfo.getBusinessId() + "?current="
+ activityDefId + "&workItemID=" + workItem.getWorkItemID() + "&workflowId=" + workItem.getWorkflowId();
pendingInfo.setBusinessMoaUrl(moaUrl);
final List<WFParticipant> participants = new ArrayList<>();
if (CommonConstant.SIX.equals(flowApprovalDto.getSceneId())) {
log.info("subflowParticipants:{}", JsonUtil.toJson(flowApprovalDto.getSubflowParticipants()));
participants.addAll(flowApprovalDto.getSubflowParticipants());
} else {
final List<WFParticipant> wfParticipants = flowApprovalDto.getParticipants();
log.info("wfParticipants:{}", JsonUtil.toJson(wfParticipants));
if (Objects.nonNull(wfParticipants) && !wfParticipants.isEmpty()) {
participants.addAll(wfParticipants);
} else {
log.info("如果是会签子流程结束不传人则在数据库中查找起草人");
final WFParticipant participant = new WFParticipant();
final String UID = flowSubmitResponseDto.getWorkItemList().get(i).getParticipant();
final ResponseDto<User> userResponseDto = this.componentsFeignApi.queryPmsUserAndCooperationUser(UID);
if (Objects.nonNull(userResponseDto.getBody())) {
participant.setName(userResponseDto.getBody().getUserName());
}
participant.setId(UID);
participants.add(participant);
}
}
log.info("参与者:{}", JsonUtil.toJson(participants));
WFParticipant participant;
participant = participants.get(0);
final Optional<WFParticipant> optional = participants.stream().filter(p -> p.getId().equals(workItem.getParticipant())).findFirst();
if (optional.isPresent()) {
participant = optional.get();
}
//判断是否为驳回
if (CommonConstant.S_TWO.equals(flowApprovalDto.getOptionType())) {
//是驳回
String type = "recp";
if ("startDesignReply".equals(workItem.getActivityDefID())) {
type = "edit";
}
final String businessUrl = URL_PREFIX_CHANGE_REPLY + type + CommonConstant.ADD_ + "current="
+ activityDefId + CommonConstant.ADD_ + "auditId=" + pendingInfo.getBusinessId()
+ CommonConstant.ADD_ + "workflowId=" + workItem.getWorkflowId() + CommonConstant.ADD_
+ "proInsID=" + workItem.getProcessInstID() + CommonConstant.ADD_ + "workItemId="
+ workItem.getWorkItemID() + CommonConstant.ADD_ + "isReceived=" + finalIsReceived;
pendingInfo.setBusinessUrl(businessUrl);
pendingInfo.setFromNodeName(pendingInfo.getCurrentNodeName());
this.mdsgFlowService.createWorkFlow(pendingInfo, workItem, loginAuthDto, participant);
} else {//不是驳回
final String businessUrl1 = URL_PREFIX_CHANGE_REPLY + "recp" + CommonConstant.ADD_
+ "current=" + activityDefId + CommonConstant.ADD_ + "auditId="
+ pendingInfo.getBusinessId() + CommonConstant.ADD_ + "workflowId=" + workItem.getWorkflowId()
+ CommonConstant.ADD_ + "proInsID=" + workItem.getProcessInstID()
+ CommonConstant.ADD_ + "workItemId=" + workItem.getWorkItemID() + CommonConstant.ADD_ + "isReceived=" + finalIsReceived;
pendingInfo.setBusinessUrl(businessUrl1);
this.mdsgFlowService.createWorkFlow(pendingInfo, workItem, loginAuthDto, participant);
}
this.mdsgFlowService.billProjectRelation(pendingInfo.getId(), infoDto.getBusinessId(), BusinessTypeEnum.SBPF_TYPE.getType(), BusinessTypeEnum.SBPF_TYPE.getName(), designReply.getProjectCode(), designReply.getProjectName());
}
}
}
if (CollectionUtils.isNotEmpty(flowSubmitResponseDto.getNotificationList())) {
final List<NotificationResponseDto> notificationList = flowSubmitResponseDto.getNotificationList();
for (int i = 0; i < notificationList.size(); i++) {
final WorkFlowHistory workFlowHistory =
this.historyMapper.selectOne(Wrappers.<WorkFlowHistory>lambdaQuery().eq(WorkFlowHistory::getWorkItemId, notificationList.get(i).getNotificationID()).eq(WorkFlowHistory::getBusinessId, flowApprovalDto.getBusinessId()));
if (Objects.isNull(workFlowHistory)) {
//创建下一待办人的信息
infoDto.setId(notificationList.get(i).getWorkflowId());
final String activityDefId = "multipleApproval";
//MOA url
final String moaUrl = CommonConstant.CHANGE_REPLY_MOA_PREFIX_URL + infoDto.getBusinessId() + "?current="
+ activityDefId + "&workItemID=" + notificationList.get(i).getNotificationID() + "&workflowId=" + notificationList.get(i).getWorkflowId();
infoDto.setBusinessMoaUrl(moaUrl);
final List<WFParticipant> participants = new ArrayList<>();
if (CollectionUtils.isNotEmpty(flowApprovalDto.getNoticeParticipants())) {
log.info("NoticeParticipants:{}", JsonUtil.toJson(flowApprovalDto.getNoticeParticipants()));
participants.addAll(flowApprovalDto.getNoticeParticipants());
}
log.info("参与者:{}", JsonUtil.toJson(participants));
final String businessUrl = URL_PREFIX_CHANGE_REPLY + "recp" + CommonConstant.ADD_
+ "current=" + activityDefId + CommonConstant.ADD_ + "auditId="
+ infoDto.getBusinessId() + CommonConstant.ADD_ + "workflowId=" + notificationList.get(i).getWorkflowId()
+ CommonConstant.ADD_ + "proInsID=" + infoDto.getProcessInstId()
+ CommonConstant.ADD_ + "workItemId=" + notificationList.get(i).getNotificationID() + CommonConstant.ADD_ + "isReceived=" + finalIsReceived;
infoDto.setBusinessUrl(businessUrl);
infoDto.setFromNodeName(infoDto.getCurrentNodeName());
this.mdsgFlowService.createNoticeWorkflow(infoDto, notificationList.get(i).getNotificationID(), activityDefId, loginAuthDto, participants.get(i));
this.mdsgFlowService.billProjectRelation(infoDto.getId(), infoDto.getBusinessId(), BusinessTypeEnum.SBPF_TYPE.getType(), BusinessTypeEnum.SBPF_TYPE.getName(), designReply.getProjectCode(), designReply.getProjectName());
}
}
}
}
return flowSubmitResponseDto;
}).andThen("更新单据状态", flowSubmitResponseDto -> {
Map<String, Object> stepParams = new HashMap<>();
stepParams.put("flowSubmitResponseDto", flowSubmitResponseDto);
//设计批复发文结束节点标识
stepParams.put("processInstIsEnd", false);
//结束节点、且批复状态未更新
if (flowSubmitResponseDto.getProcessInstIsEnd() && !CommonConstant.CODE_02.equals(designReply.getReplyStatus())) {
//不是收文流程在做一下操作,因为之前把变更批复的类型写错了,写成了设计批复的,所以这边同时加了设计批复和变更批复
if (ReplyConstant.DESIGN_REPLY_TYPE.equals(infoDto.getBusinessType()) || ReplyConstant.CHANGE_REPLY_TYPE.equals(infoDto.getBusinessType())) {
this.updateReply(Long.valueOf(flowApprovalDto.getBusinessId()), loginAuthDto, null, "3");
stepParams.put("processInstIsEnd", true);
}
}
return stepParams;
}).andThen("推送能力指标", stepParams -> {
if ((Boolean) stepParams.get("processInstIsEnd")) {
//V1.9_432_设计变更批复_审批 - (文档:6.10.7)推送能力指标
this.designReplyFlowService.pushDesignScale(designReply);
}
return stepParams;
}).andThen("给领导发送待阅", stepParams -> {
if ((Boolean) stepParams.get("processInstIsEnd")) {
if (ReplyConstant.DESIGN_REPLY_TYPE.equals(infoDto.getBusinessType()) || ReplyConstant.CHANGE_REPLY_TYPE.equals(infoDto.getBusinessType())) {
//给领导发送待阅
infoDto.setPortalBusinessType(BusinessTypeEnum.SBPF_TYPE.getType());
this.designReplyFlowService.sendReplyNoticeId(infoDto, loginAuthDto, CommonConstant.CODE_03);
}
}
return stepParams;
}).andThen("最后一次批复释放投资", stepParams -> {
if ((Boolean) stepParams.get("processInstIsEnd")) {
//当选择为是最后一次批复时,在单据完成后调用投资计划接口,将项目已批复金额推送给投资计划用于释放投资
// replyLink: 设计批复【05】、设计批复变更【06】
if (CommonConstant.CODE_00.equals(designReply.getIsLastReply())) {
this.amqServer.planChinAmt(Long.valueOf(flowApprovalDto.getBusinessId()), "06");
}
}
return stepParams;
}).andThen("重新生成正文", stepParams -> {
if ((Boolean) stepParams.get("processInstIsEnd")) {
log.info("===========设计变更批复审批完成-->开始重新生成正文====================");
//获取批复正文详情
ReplyTextDto replyTextInfo = getReplyTextInfo(flowApprovalDtoSync.getReplyId(), REPLY_SYMBOL_CODE, loginAuthDto);
log.info("获取批复正文详情replyTextInfo:{}", replyTextInfo);
if (Objects.nonNull(replyTextInfo) && org.apache.commons.lang3.StringUtils.isNotEmpty(replyTextInfo.getFileText())){
//重新生成正文
AddReplyFileDto addReplyFileDto = new AddReplyFileDto();
addReplyFileDto.setReplyId(flowApprovalDto.getBusinessId());
addReplyFileDto.setAttachmentName(replyTextInfo.getFileCode() + "-" + replyTextInfo.getFileTitle());
addReplyFileDto.setTitle(replyTextInfo.getFileTitle());
String replyContent = ReplyUtil.buildChangeReplyContent(designReply, replyTextInfo);
addReplyFileDto.setContent(replyContent);
this.designReplyService.generateReplyFile(addReplyFileDto, loginAuthDto);
}else {
//调用公文组件接口更新公文组件审批状态, 获取设计批复文号
final PiuCommonDocumentOrderDto piuCommonDocumentOrderDto = new PiuCommonDocumentOrderDto();
piuCommonDocumentOrderDto.setParentId(Long.parseLong(flowApprovalDto.getBusinessId()));
piuCommonDocumentOrderDto.setDocumentStatus(2);
// 更新附件审批状态并推送至归档微服务
this.designReplyService.updateApprovalStatus(piuCommonDocumentOrderDto, designReply, loginAuthDto, BusinessTypeEnum.SBPF_TYPE.getType());
//调用归档接口,更新附件可用状态
this.updateFileStatusByBusinessIds(flowApprovalDto.getBusinessId());
//更新批复表文号
this.designReplyService.update(
Wrappers.<DesignReply>lambdaUpdate().set(DesignReply::getDesignReplyNo, designReply.getDesignReplyNo())
.eq(DesignReply::getId, designReply.getId()).eq(BaseEntity::getDeleteFlag, 0));
}
}
return stepParams;
}).andThen("推送批复消息队列", stepParams -> {
if ((Boolean) stepParams.get("processInstIsEnd")) {
PushReplyQueueDto pushReplyQueueDto = new PushReplyQueueDto();
pushReplyQueueDto.setReplyId(Long.parseLong(flowApprovalDto.getBusinessId()));
pushReplyQueueDto.setChangeType(0);
this.designReplyFlowService.pushReplyQueue(pushReplyQueueDto);
}
return stepParams;
}).andThen("启动收文流程", stepParams -> {
if ((Boolean) stepParams.get("processInstIsEnd")) {
flowApprovalDto.setReplyType("4");
this.designReplyFlowService.startReceivedProcess(loginAuthDto, flowApprovalDto);
}
return stepParams;
}).andThen("更新项目全业务流程状态", stepParams -> {
// 最后一次批复 更新项目全业务流程状态
if ((Boolean) stepParams.get("processInstIsEnd")) {
// 最后一次批复 更新项目全业务流程状态
SaveReplyInfoDto saveReplyInfoDto = new SaveReplyInfoDto();
saveReplyInfoDto.setId(Long.parseLong(flowApprovalDtoSync.getReplyId()));
saveReplyInfoDto.setProjectCode(flowApprovalDtoSync.getProjectCode());
this.designReplyService.updateProjectBusStatus(saveReplyInfoDto, loginAuthDto);
return true;
}
return true;
});
try {
asyncSupport.with(flowApprovalDtoSync.getReplyId() + "_" + flowApprovalDto.getWorkflowId(), BusinessTypeEnum.SBPF_TYPE.getType(), this, "doCommonFlowApproveAsync", flowApprovalDtoSync, loginAuthDto)
.execute(
() -> {
//前置验证
ResponseDto response = null;
if (flowApprovalDtoSync.getReplyId().isEmpty()) {
response = ResponseUtil.wrapSuccess(false);
}
//这里如果返回非null,不会执行后面的函数。
return Optional.ofNullable(response);
},
vAsyncStep,
future -> {
future.addCallback(result -> {
log.info("异步任务完成");
}, error -> {
log.error("异步任务出错", error);
});
return ResponseUtil.wrapSuccess(true);
}
);
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
/**
* 审批完成、流程结束后调用归档接口,更新附件可用状态
*
* @param businessId
*/
@Override
public void updateFileStatusByBusinessIds(final String businessId) {
CompletableFuture.runAsync(() -> {
try {
//更新附件可用状态
final IdsDto idsDto = new IdsDto();
final List<String> ids = new ArrayList<>();
ids.add(businessId);
idsDto.setIds(ids);
this.profileFeignApi.updateByBusinessIds(idsDto);
} catch (final Exception e) {
log.error("调用归档接口失败,单据id:{},线程名:{},异常:{}", businessId, Thread.currentThread().getName(), e);
}
});
}
变更批复提交优化
于 2024-01-16 11:15:50 首次发布