From 504333e56f249d16e71e8ac2a435cf2212040c23 Mon Sep 17 00:00:00 2001 From: cuikaidong <ckd2942379034@163.com> Date: 星期二, 27 五月 2025 17:32:50 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- lxzn-module-flowable/src/main/java/org/jeecg/modules/flowable/service/impl/FlowDefinitionServiceImpl.java | 240 +++++++++++++++++++++++++++++++++++++++--------------------- 1 files changed, 156 insertions(+), 84 deletions(-) diff --git a/lxzn-module-flowable/src/main/java/org/jeecg/modules/flowable/service/impl/FlowDefinitionServiceImpl.java b/lxzn-module-flowable/src/main/java/org/jeecg/modules/flowable/service/impl/FlowDefinitionServiceImpl.java index bbb90bc..379cfdd 100644 --- a/lxzn-module-flowable/src/main/java/org/jeecg/modules/flowable/service/impl/FlowDefinitionServiceImpl.java +++ b/lxzn-module-flowable/src/main/java/org/jeecg/modules/flowable/service/impl/FlowDefinitionServiceImpl.java @@ -1,6 +1,8 @@ package org.jeecg.modules.flowable.service.impl; +import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; @@ -44,7 +46,6 @@ /** * 娴佺▼瀹氫箟 - * */ @Service public class FlowDefinitionServiceImpl extends FlowServiceFactory implements IFlowDefinitionService { @@ -69,8 +70,8 @@ /** * 娴佺▼瀹氫箟鍒楄〃 * - * @param pageNum 褰撳墠椤电爜 - * @param pageSize 姣忛〉鏉℃暟 + * @param pageNum 褰撳墠椤电爜 + * @param pageSize 姣忛〉鏉℃暟 * @param flowProcDefDto * @return 娴佺▼瀹氫箟鍒嗛〉鍒楄〃鏁版嵁 */ @@ -83,19 +84,19 @@ //.processDefinitionId("cs:5:15e953ed-4d09-11ec-85b8-e884a5deddfc") .orderByProcessDefinitionKey().asc().orderByProcessDefinitionVersion().desc(); /*=====鍙傛暟=====*/ - if (StrUtil.isNotBlank(flowProcDefDto.getName())){ - processDefinitionQuery.processDefinitionNameLike("%"+flowProcDefDto.getName()+"%"); + if (StrUtil.isNotBlank(flowProcDefDto.getName())) { + processDefinitionQuery.processDefinitionNameLike("%" + flowProcDefDto.getName() + "%"); } - if (StrUtil.isNotBlank(flowProcDefDto.getCategory())){ + if (StrUtil.isNotBlank(flowProcDefDto.getCategory())) { processDefinitionQuery.processDefinitionCategory(flowProcDefDto.getCategory()); } - if (flowProcDefDto.getSuspensionState() == 1){ + if (flowProcDefDto.getSuspensionState() == 1) { processDefinitionQuery.active(); } - if (StrUtil.isNotBlank(flowProcDefDto.getKey())){ + if (StrUtil.isNotBlank(flowProcDefDto.getKey())) { processDefinitionQuery.processDefinitionKey(flowProcDefDto.getKey()); } - if (flowProcDefDto.getIsLastVersion() == 1){ + if (flowProcDefDto.getIsLastVersion() == 1) { processDefinitionQuery.latestVersion(); } /*============*/ @@ -149,7 +150,7 @@ @Override public Result readXmlByDataId(String dataId) throws IOException { LambdaQueryWrapper<FlowMyBusiness> flowMyBusinessLambdaQueryWrapper = new LambdaQueryWrapper<>(); - flowMyBusinessLambdaQueryWrapper.eq(FlowMyBusiness::getDataId,dataId) + flowMyBusinessLambdaQueryWrapper.eq(FlowMyBusiness::getDataId, dataId) ; //濡傛灉淇濆瓨鏁版嵁鍓嶆湭璋冪敤蹇呰皟鐨凢lowCommonService.initActBusiness鏂规硶锛屽氨浼氭湁闂 FlowMyBusiness business = flowMyBusinessService.getOne(flowMyBusinessLambdaQueryWrapper); @@ -201,6 +202,7 @@ InputStream in = processDiagramGenerator.generateDiagram(bpmnModel, "png", activityIds, flows, engConf.getActivityFontName(), engConf.getLabelFontName(), engConf.getAnnotationFontName(), engConf.getClassLoader(), 1.0, true); return in; } + /** * 璇诲彇xml * @@ -232,7 +234,7 @@ * 鏍规嵁娴佺▼瀹氫箟ID鍚姩娴佺▼瀹炰緥 * * @param procDefKey 娴佺▼瀹氫箟Id - * @param variables 娴佺▼鍙橀噺 + * @param variables 娴佺▼鍙橀噺 * @return */ @Override @@ -241,9 +243,10 @@ ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery() .processDefinitionKey(procDefKey) .latestVersion().singleResult(); - Result result = startProcessInstanceById(processDefinition.getId(),variables); + Result result = startProcessInstanceById(processDefinition.getId(), variables); return result; } + /** * 鏍规嵁娴佺▼瀹氫箟ID鍚姩娴佺▼瀹炰緥 * @@ -254,28 +257,28 @@ @Override @Transactional public Result<?> startProcessInstanceById(String procDefId, Map<String, Object> variables) { - ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery() - .processDefinitionId(procDefId) - .singleResult(); - if (Objects.nonNull(processDefinition) && processDefinition.isSuspended()) { - return Result.error("娴佺▼宸茶鎸傝捣,璇峰厛婵�娲绘祦绋�"); - } + ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery() + .processDefinitionId(procDefId) + .singleResult(); + if (Objects.nonNull(processDefinition) && processDefinition.isSuspended()) { + return Result.error("娴佺▼宸茶鎸傝捣,璇峰厛婵�娲绘祦绋�"); + } // variables.put("skip", true); // variables.put(ProcessConstants.FLOWABLE_SKIP_EXPRESSION_ENABLED, true); - // 璁剧疆娴佺▼鍙戣捣浜篒d鍒版祦绋嬩腑 - SysUser sysUser = iFlowThirdService.getLoginUser(); - identityService.setAuthenticatedUserId(sysUser.getUsername()); - variables.put(ProcessConstants.PROCESS_INITIATOR, sysUser.getUsername()); - ProcessInstance processInstance = runtimeService.startProcessInstanceById(procDefId, variables); - // 缁欑涓�姝ョ敵璇蜂汉鑺傜偣璁剧疆浠诲姟鎵ц浜哄拰鎰忚 - Task task = taskService.createTaskQuery().processInstanceId(processInstance.getProcessInstanceId()).active().singleResult(); - if (Objects.nonNull(task)) { - taskService.addComment(task.getId(), processInstance.getProcessInstanceId(), FlowComment.NORMAL.getType(), variables.get("organization").toString()); - taskService.setAssignee(task.getId(), sysUser.getUsername()); - task.setDescription(variables.get("organization").toString()); - //taskService.complete(task.getId(), variables); - } - //璁剧疆鎵�鏈夌敵璇蜂汉 + // 璁剧疆娴佺▼鍙戣捣浜篒d鍒版祦绋嬩腑 + SysUser sysUser = iFlowThirdService.getLoginUser(); + identityService.setAuthenticatedUserId(sysUser.getUsername()); + variables.put(ProcessConstants.PROCESS_INITIATOR, sysUser.getUsername()); + ProcessInstance processInstance = runtimeService.startProcessInstanceById(procDefId, variables); + // 缁欑涓�姝ョ敵璇蜂汉鑺傜偣璁剧疆浠诲姟鎵ц浜哄拰鎰忚 + Task task = taskService.createTaskQuery().processInstanceId(processInstance.getProcessInstanceId()).active().singleResult(); + if (Objects.nonNull(task)) { + taskService.addComment(task.getId(), processInstance.getProcessInstanceId(), FlowComment.NORMAL.getType(), variables.get("organization").toString()); + taskService.setAssignee(task.getId(), sysUser.getUsername()); + task.setDescription(variables.get("organization").toString()); + //taskService.complete(task.getId(), variables); + } + //璁剧疆鎵�鏈夌敵璇蜂汉 /*======================todo 鍚姩涔嬪悗 鍥炶皟浠ュ強鍏抽敭鏁版嵁淇濆瓨======================*/ //涓氬姟鏁版嵁id @@ -283,77 +286,146 @@ //濡傛灉淇濆瓨鏁版嵁鍓嶆湭璋冪敤蹇呰皟鐨凢lowCommonService.initActBusiness鏂规硶锛屽氨浼氭湁闂 FlowMyBusiness business = flowMyBusinessService.getByDataId(dataId); //璁剧疆鏁版嵁 - FlowNextDto nextFlowNode = flowTaskService.getNextFlowNode(task.getId(), variables); + List<FlowNextDto> nextFlowNodeList = flowTaskService.getNextFlowNode(task.getId(), variables); taskService.complete(task.getId(), variables); //涓嬩竴涓疄渚嬭妭鐐� 澶氬疄渚嬩細鏄竴涓猯ist,闅忔剰鍙栦竴涓嵆鍙� 鏁扮粍涓畾涔塊ey鏄竴鑷寸殑 //Task task2 = taskService.createTaskQuery().processInstanceId(processInstance.getProcessInstanceId()).active().singleResult(); List<Task> task2List = taskService.createTaskQuery().processInstanceId(processInstance.getProcessInstanceId()).active().list(); - Task task2 = null; - if(task2List.size()>0) task2 = task2List.get(0); String doneUsers = business.getDoneUsers(); // 澶勭悊杩囨祦绋嬬殑浜� JSONArray doneUserList = new JSONArray(); - if (StrUtil.isNotBlank(doneUsers)){ + if (StrUtil.isNotBlank(doneUsers)) { doneUserList = JSON.parseArray(doneUsers); } - if (!doneUserList.contains(sysUser.getUsername())){ + if (!doneUserList.contains(sysUser.getUsername())) { doneUserList.add(sysUser.getUsername()); } - if (nextFlowNode!=null){ - //**鏈変笅涓�涓妭鐐� - UserTask nextTask = nextFlowNode.getUserTask(); - //鑳藉澶勭悊涓嬩釜鑺傜偣鐨勫�欓�変汉 - List<SysUser> nextFlowNodeUserList = nextFlowNode.getUserList(); - - List<String> collect_username = nextFlowNodeUserList.stream().map(SysUser::getUsername).collect(Collectors.toList()); - //spring瀹瑰櫒绫诲悕 - String serviceImplName = business.getServiceImplName(); - FlowCallBackServiceI flowCallBackService = (FlowCallBackServiceI) SpringContextUtils.getBean(serviceImplName); - List<String> beforeParamsCandidateUsernames = flowCallBackService.flowCandidateUsernamesOfTask(task2.getTaskDefinitionKey(), variables); - business.setProcessDefinitionId(procDefId) - .setProcessInstanceId(processInstance.getProcessInstanceId()) -//// .setActStatus(ActStatus.start) - .setProposer(sysUser.getUsername()) - .setTaskId(task2.getId()) - .setTaskName(nextTask.getName()) - .setTaskNameId(nextTask.getId()) - .setPriority(nextTask.getPriority()) - .setDoneUsers(doneUserList.toJSONString()); - if (CollUtil.isNotEmpty(beforeParamsCandidateUsernames)){ - // 鍒犻櫎鍚庨噸鍐� - for (Task task2One : task2List) { - for (String oldUser : collect_username) { - taskService.deleteCandidateUser(task2One.getId(),oldUser); - } - } - // 涓氬姟灞傛湁鎸囧畾鍊欓�変汉锛岃鐩� - for (Task task2One : task2List) { - for (String newUser : beforeParamsCandidateUsernames) { - taskService.addCandidateUser(task2One.getId(),newUser); - } - } - business.setTodoUsers(JSON.toJSONString(beforeParamsCandidateUsernames)); - }else { - // 涓氬姟灞傛病鏈夋寚瀹氬�欓�変汉锛岀洿鎺ヨ鐩� - business.setTodoUsers(JSON.toJSONString(collect_username)); - } - } else { - // **娌℃湁涓嬩竴涓妭鐐癸紝娴佺▼宸茬粡缁撴潫浜� + if (CollectionUtil.isEmpty(nextFlowNodeList)) { + // **娌℃湁涓嬩竴涓妭鐐癸紝娴佺▼宸茬粡缁撴潫浜� business.setProcessDefinitionId(procDefId) .setProcessInstanceId(processInstance.getProcessInstanceId()) // .setActStatus(ActStatus.pass) .setProposer(sysUser.getUsername()) .setDoneUsers(doneUserList.toJSONString()) ; + flowMyBusinessService.updateById(business); + } else if (nextFlowNodeList.size() == 1) { + //涓嬩釜鑺傜偣鍙湁涓�涓� + FlowNextDto nextFlowNode = nextFlowNodeList.get(0); + UserTask nextTask = nextFlowNode.getUserTask(); + Task task2 = null; + Optional<Task> first = task2List.stream().filter(t -> t.getTaskDefinitionKey().equals(nextTask.getId())).findFirst(); + if (first.isPresent()) { + task2 = first.get(); + } + if (task2 != null) { + //鑳藉澶勭悊涓嬩釜鑺傜偣鐨勫�欓�変汉 + List<SysUser> nextFlowNodeUserList = nextFlowNode.getUserList(); + + List<String> collect_username = nextFlowNodeUserList.stream().map(SysUser::getUsername).collect(Collectors.toList()); + //spring瀹瑰櫒绫诲悕 + String serviceImplName = business.getServiceImplName(); + FlowCallBackServiceI flowCallBackService = (FlowCallBackServiceI) SpringContextUtils.getBean(serviceImplName); + List<String> beforeParamsCandidateUsernames = flowCallBackService.flowCandidateUsernamesOfTask(task2.getTaskDefinitionId(), variables); + business.setProcessDefinitionId(procDefId) + .setProcessInstanceId(processInstance.getProcessInstanceId()) +//// .setActStatus(ActStatus.start) + .setProposer(sysUser.getUsername()) + .setTaskId(task2.getId()) + .setTaskName(nextTask.getName()) + .setTaskNameId(nextTask.getId()) + .setPriority(nextTask.getPriority()) + .setDoneUsers(doneUserList.toJSONString()); + if (CollUtil.isNotEmpty(beforeParamsCandidateUsernames)) { + // 鍒犻櫎鍚庨噸鍐� + for (String oldUser : collect_username) { + taskService.deleteCandidateUser(task2.getId(), oldUser); + } + // 涓氬姟灞傛湁鎸囧畾鍊欓�変汉锛岃鐩� + for (String newUser : beforeParamsCandidateUsernames) { + taskService.addCandidateUser(task2.getId(), newUser); + } + business.setTodoUsers(JSON.toJSONString(beforeParamsCandidateUsernames)); + } else { + // 涓氬姟灞傛病鏈夋寚瀹氬�欓�変汉锛岀洿鎺ヨ鐩� + business.setTodoUsers(JSON.toJSONString(collect_username)); + } + flowMyBusinessService.updateById(business); + } + } else { + for (FlowNextDto nextFlowNode : nextFlowNodeList) { + //**鏈変笅涓�涓妭鐐� + UserTask nextTask = nextFlowNode.getUserTask(); + Task task2 = null; + Optional<Task> first = task2List.stream().filter(t -> t.getTaskDefinitionKey().equals(nextTask.getId())).findFirst(); + if (first.isPresent()) { + task2 = first.get(); + } + if (task2 != null) { + //鏂扮殑涓氬姟娴佺▼鑺傜偣 + FlowMyBusiness newBusiness = BeanUtil.copyProperties(business, FlowMyBusiness.class, "id"); + //鑳藉澶勭悊涓嬩釜鑺傜偣鐨勫�欓�変汉 + List<SysUser> nextFlowNodeUserList = nextFlowNode.getUserList(); + + List<String> collect_username = nextFlowNodeUserList.stream().map(SysUser::getUsername).collect(Collectors.toList()); + //spring瀹瑰櫒绫诲悕 + String serviceImplName = newBusiness.getServiceImplName(); + FlowCallBackServiceI flowCallBackService = (FlowCallBackServiceI) SpringContextUtils.getBean(serviceImplName); + List<String> beforeParamsCandidateUsernames = flowCallBackService.flowCandidateUsernamesOfTask(task2.getTaskDefinitionId(), variables); + newBusiness.setProcessDefinitionId(procDefId) + .setProcessInstanceId(processInstance.getProcessInstanceId()) +//// .setActStatus(ActStatus.start) + .setProposer(sysUser.getUsername()) + .setTaskId(task2.getId()) + .setTaskName(nextTask.getName()) + .setTaskNameId(nextTask.getId()) + .setPriority(nextTask.getPriority()) + .setDoneUsers(doneUserList.toJSONString()); + if (CollUtil.isNotEmpty(beforeParamsCandidateUsernames)) { + // 鍒犻櫎鍚庨噸鍐� + for (Task task2One : task2List) { + for (String oldUser : beforeParamsCandidateUsernames) { + taskService.deleteCandidateUser(task2One.getId(), oldUser); + } + } + // 涓氬姟灞傛湁鎸囧畾鍊欓�変汉锛岃鐩� + for (Task task2One : task2List) { + for (String newUser : beforeParamsCandidateUsernames) { + taskService.addCandidateUser(task2One.getId(), newUser); + } + } + newBusiness.setTodoUsers(JSON.toJSONString(beforeParamsCandidateUsernames)); + } else { + // 涓氬姟灞傛病鏈夋寚瀹氬�欓�変汉锛岀洿鎺ヨ鐩� + newBusiness.setTodoUsers(JSON.toJSONString(collect_username)); + // 鍒犻櫎鍚庨噸鍐� + for (Task task2One : task2List) { + for (String oldUser : collect_username) { + taskService.deleteCandidateUser(task2One.getId(), oldUser); + } + } + // 涓氬姟灞傛湁鎸囧畾鍊欓�変汉锛岃鐩� + for (Task task2One : task2List) { + for (String newUser : collect_username) { + taskService.addCandidateUser(task2One.getId(), newUser); + } + } + } + flowMyBusinessService.save(newBusiness); + } + } + //鍒犻櫎鍘熸湁鐨勪笟鍔℃暟鎹� + flowMyBusinessService.removeById(business.getId()); } - flowMyBusinessService.updateById(business); //spring瀹瑰櫒绫诲悕 String serviceImplName = business.getServiceImplName(); FlowCallBackServiceI flowCallBackService = (FlowCallBackServiceI) SpringContextUtils.getBean(serviceImplName); // 娴佺▼澶勭悊瀹屽悗锛岃繘琛屽洖璋冧笟鍔″眰 business.setValues(variables); - if (flowCallBackService!=null)flowCallBackService.afterFlowHandle(business); + if (flowCallBackService != null) { + flowCallBackService.afterFlowHandle(business); + } return Result.OK("娴佺▼鍚姩鎴愬姛"); } @@ -363,13 +435,13 @@ flowMyBusinessLambdaQueryWrapper.eq(FlowMyBusiness::getDataId, dataId) ; FlowMyBusiness business = flowMyBusinessService.getOne(flowMyBusinessLambdaQueryWrapper); - if (business==null){ - return Result.error("鏈壘鍒癲ataId锛�"+dataId); + if (business == null) { + return Result.error("鏈壘鍒癲ataId锛�" + dataId); } - if (StrUtil.isNotBlank(business.getProcessDefinitionId())){ - return this.startProcessInstanceById(business.getProcessDefinitionId(),variables); + if (StrUtil.isNotBlank(business.getProcessDefinitionId())) { + return this.startProcessInstanceById(business.getProcessDefinitionId(), variables); } - return this.startProcessInstanceByKey(business.getProcessDefinitionKey(),variables); + return this.startProcessInstanceByKey(business.getProcessDefinitionKey(), variables); } -- Gitblit v1.9.3