wangliang 1 年間 前
コミット
1d0aef74c6

+ 38 - 13
sop-business/src/main/java/com/qmth/sop/business/activiti/listener/ProcessEventListener.java

@@ -25,7 +25,6 @@ import org.springframework.util.CollectionUtils;
 import java.io.Serializable;
 import java.nio.charset.StandardCharsets;
 import java.util.*;
-import java.util.concurrent.atomic.AtomicInteger;
 
 /**
  * @Description: 全局监听
@@ -61,33 +60,35 @@ public class ProcessEventListener implements ActivitiEventListener, Serializable
                 if (activitiEntityEvent.getEntity() instanceof ResourceEntity) {
                     ResourceEntity resourceEntity = (ResourceEntity) activitiEntityEvent.getEntity();
                     log.info("ENTITY_CREATED,id:{},name:{},deploymentId:{},persistentState:{}", resourceEntity.getId(), resourceEntity.getName(), resourceEntity.getDeploymentId(), resourceEntity.getPersistentState());
+                    String xml = new String(resourceEntity.getBytes(), StandardCharsets.UTF_8);
                     if (resourceEntity.getName().endsWith(SystemConstant.BPMN_PREFIX)) {
-                        String xml = new String(resourceEntity.getBytes(), StandardCharsets.UTF_8);
 //                        log.info("ENTITY_CREATED,xml:{}", xml);
                         try {
                             Document doc = DocumentHelper.parseText(xml);
                             Element rootElement = doc.getRootElement();
                             // 通过element对象的elementIterator方法获取迭代器
-                            AtomicInteger atomicInteger = new AtomicInteger(1);
                             Iterator iterator = rootElement.elementIterator();
                             Map<String, FlowTaskResult> setupMap = new LinkedHashMap<>();//流程审批步骤map
+                            TFCustomTypeEnum customTypeEnum = null;
                             while (iterator.hasNext()) {
                                 Element element = (Element) iterator.next();
                                 List<Attribute> attributes = element.attributes();
-//                                for (Attribute attr : attributes) {
+                                for (Attribute attr : attributes) {
 //                                    log.info("属性:{},---值:{}", attr.getName(), attr.getValue());
-//                                }
+                                    if (Objects.equals(attr.getName(), SystemConstant.ID_FLOW) && Objects.equals(attr.getValue(), TFCustomTypeEnum.OFFICE_SOP_FLOW.name())) {
+                                        customTypeEnum = TFCustomTypeEnum.valueOf(attr.getValue());
+                                        break;
+                                    }
+                                }
                                 Iterator itt = element.elementIterator();
                                 while (itt.hasNext()) {
                                     FlowTaskResult flowTaskResult = new FlowTaskResult();
                                     Element node = (Element) itt.next();
                                     attributes = node.attributes();
 //                                    log.info("节点:{},---值:{}", node.getName(), node.getStringValue());
-                                    if (Objects.equals(node.getName(), SystemConstant.START_EVENT) || Objects.equals(node.getName(), SystemConstant.USER_TASK) || Objects.equals(node.getName(), SystemConstant.END_EVENT)) {
+                                    if (Objects.equals(node.getName(), SystemConstant.USER_TASK) || Objects.equals(node.getName(), SystemConstant.END_EVENT)) {
                                         if (Objects.equals(node.getName(), SystemConstant.END_EVENT)) {
-                                            flowTaskResult.setSetup(0);
-                                        } else {
-                                            flowTaskResult.setSetup(atomicInteger.getAndIncrement());
+                                            flowTaskResult.setSetup(SystemConstant.END_TEMP_ID);
                                         }
                                         for (Attribute attr : attributes) {
 //                                            log.info("节点属性:{},---节点值:{}", attr.getName(), attr.getValue());
@@ -98,6 +99,7 @@ public class ProcessEventListener implements ActivitiEventListener, Serializable
                                                 flowTaskResult.setTaskName(attr.getValue());
                                             } else if (Objects.equals(attr.getName(), SystemConstant.FORM_KEY) && SystemConstant.FLOW_MAP.containsKey(resourceEntity.getDeploymentId() + SystemConstant.FLOW_FORM_ID_SPACE + attr.getValue())) {
                                                 flowTaskResult.setFormKey(attr.getValue());
+                                                flowTaskResult.setSetup(Integer.valueOf(attr.getValue().substring(attr.getValue().indexOf(".") - 1, attr.getValue().indexOf("."))));
                                                 List<String> list = SystemConstant.FLOW_MAP.get(resourceEntity.getDeploymentId() + SystemConstant.FLOW_FORM_ID_SPACE + attr.getValue());
                                                 String data = list.get(list.size() - 1);
                                                 List<FlowFormWidgetResult> listData = JSONArray.parseArray(data, FlowFormWidgetResult.class);
@@ -117,14 +119,38 @@ public class ProcessEventListener implements ActivitiEventListener, Serializable
                                     }
                                 }
                             }
+                            List<Map.Entry<String, FlowTaskResult>> entryList = new ArrayList<Map.Entry<String, FlowTaskResult>>(setupMap.entrySet());
+                            //比较器
+                            Collections.sort(entryList, new Comparator<Map.Entry<String, FlowTaskResult>>() {
+                                @Override
+                                public int compare(Map.Entry<String, FlowTaskResult> o1, Map.Entry<String, FlowTaskResult> o2) {
+                                    if (o2.getValue().getSetup() < o1.getValue().getSetup()) {
+                                        return 1;
+                                    } else if (o2.getValue().getSetup() > o1.getValue().getSetup()) {
+                                        return -1;
+                                    } else {
+                                        return 0;
+                                    }
+                                }
+                            });
+                            entryList.get(entryList.size() - 1).getValue().setSetup(0);
+                            setupMap.clear();
+                            Iterator<Map.Entry<String, FlowTaskResult>> iter = entryList.iterator();
+                            Map.Entry<String, FlowTaskResult> tmpEntry = null;
+                            while (iter.hasNext()) {
+                                tmpEntry = iter.next();
+                                setupMap.put(tmpEntry.getKey(), tmpEntry.getValue());
+                            }
                             FlowResult flowResult = new FlowResult(resourceEntity.getDeploymentId(), resourceEntity.getName(), setupMap);
                             log.info("flowResult:{}", JacksonUtil.parseJson(flowResult));
                             TFCustomFlowService tfCustomFlowService = SpringContextHolder.getBean(TFCustomFlowService.class);
-                            TFCustomFlow maxTfCustomFlow = tfCustomFlowService.findMaxVersion(null, flowResult.getFlowName(), TFCustomTypeEnum.OFFICE_SOP_FLOW);
-                            TFCustomFlow tfCustomFlow = new TFCustomFlow(null, flowResult.getFlowName(), TFCustomTypeEnum.OFFICE_SOP_FLOW, flowResult.getDeploymentId(), TFCustomModelTypeEnum.USER_FIXED);
+                            TFCustomFlow maxTfCustomFlow = tfCustomFlowService.findMaxVersion(null, flowResult.getFlowName(), customTypeEnum);
+                            TFCustomFlow tfCustomFlow = new TFCustomFlow(null, flowResult.getFlowName(), customTypeEnum, flowResult.getDeploymentId(), TFCustomModelTypeEnum.USER_FIXED);
                             flowResult.setId(tfCustomFlow.getId());
                             if (Objects.nonNull(maxTfCustomFlow)) {
                                 tfCustomFlow.setVersion(maxTfCustomFlow.getVersion() + 1);
+                            } else {
+                                tfCustomFlow.setVersion(1);
                             }
                             flowResult.setVersion(tfCustomFlow.getVersion());
                             tfCustomFlow.setFlowProcessVar(JacksonUtil.parseJson(flowResult));
@@ -133,9 +159,8 @@ public class ProcessEventListener implements ActivitiEventListener, Serializable
                             log.error(SystemConstant.LOG_ERROR, e);
                         }
                     } else {
-                        String data = new String(resourceEntity.getBytes(), StandardCharsets.UTF_8);
 //                        log.info("ENTITY_CREATED,data:{}", data);
-                        SystemConstant.FLOW_MAP.add(resourceEntity.getDeploymentId() + SystemConstant.FLOW_FORM_ID_SPACE + resourceEntity.getName(), data);
+                        SystemConstant.FLOW_MAP.add(resourceEntity.getDeploymentId() + SystemConstant.FLOW_FORM_ID_SPACE + resourceEntity.getName(), xml);
                     }
                 }
                 break;

+ 13 - 1
sop-business/src/main/java/com/qmth/sop/business/bean/result/FlowTaskResult.java

@@ -3,6 +3,7 @@ package com.qmth.sop.business.bean.result;
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
 import io.swagger.annotations.ApiModelProperty;
+import org.jetbrains.annotations.NotNull;
 
 import java.io.Serializable;
 import java.util.List;
@@ -14,7 +15,7 @@ import java.util.List;
  * @Author: wangliang
  * @Date: 2021/8/6
  */
-public class FlowTaskResult implements Serializable {
+public class FlowTaskResult implements Serializable, Comparable<FlowTaskResult> {
 
     @ApiModelProperty(value = "流程id")
     @JsonSerialize(using = ToStringSerializer.class)
@@ -82,4 +83,15 @@ public class FlowTaskResult implements Serializable {
     public void setFormKey(String formKey) {
         this.formKey = formKey;
     }
+
+    @Override
+    public int compareTo(@NotNull FlowTaskResult o) {
+        if (o.getSetup() < this.getSetup()) {
+            return 1;
+        } else if (o.getSetup() > this.getSetup()) {
+            return -1;
+        } else {
+            return 0;
+        }
+    }
 }

+ 1 - 0
sop-common/src/main/java/com/qmth/sop/common/contant/SystemConstant.java

@@ -118,6 +118,7 @@ public class SystemConstant {
     public static final String FORM_KEY = "formKey";
     public static final String ID_FLOW = "id";
     public static final String FLOW_FORM_ID_SPACE = "|";
+    public static final Integer END_TEMP_ID = 100000000;
 
     /**
      * 获取数据库uuid

+ 11 - 2
sop-server/src/main/java/com/qmth/sop/server/api/ActivitiFromHtmlController.java

@@ -85,7 +85,7 @@ public class ActivitiFromHtmlController {
     @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = Object.class)})
     public Map<String, Object> flowStart(@ApiParam(value = "部署流程id", required = true) @RequestParam String deploymentId) {
         Map<String, Object> map = new HashMap<>();
-        String processDefinitionId = activitiConsumerService.findProcessDefinitionIdByDeploymentId(deploymentId);
+        String processDefinitionId = null;
 //        ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionId).singleResult();
 //        boolean hasStartFormKey = processDefinition.hasStartFormKey();
 //        //获得流程模型
@@ -110,13 +110,20 @@ public class ActivitiFromHtmlController {
 //            }
 //        }
         TFCustomFlow tfCustomFlow = tfCustomFlowService.getOne(new QueryWrapper<TFCustomFlow>().lambda().eq(TFCustomFlow::getActFlowId, deploymentId));
+        Optional.ofNullable(tfCustomFlow.getFlowProcessVar()).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("流程没有部署数据!"));
 //        Object o = formService.getRenderedStartForm(processDefinitionId);
 //        if (Objects.nonNull(o)) {
 //            log.info("start formProperties:{}", JacksonUtil.parseJson(o));
 //            List<FlowFormWidgetResult> list = JSONArray.parseArray(o.toString(), FlowFormWidgetResult.class);
 //            map.put("FormProperty", new FormPropertyBean(null, null, list));
 //        }
-        Optional.ofNullable(tfCustomFlow.getFlowProcessVar()).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("流程没有部署数据!"));
+        if (Objects.isNull(tfCustomFlow.getFlowKey())) {
+            processDefinitionId = activitiConsumerService.findProcessDefinitionIdByDeploymentId(deploymentId);
+            tfCustomFlow.setFlowKey(processDefinitionId);
+            tfCustomFlowService.updateById(tfCustomFlow);
+        } else {
+            processDefinitionId = tfCustomFlow.getFlowKey();
+        }
         FlowResult flowResult = JSONObject.parseObject(tfCustomFlow.getFlowProcessVar(), FlowResult.class);
         Map<String, FlowTaskResult> setupMap = flowResult.getSetupMap();
         for (Map.Entry<String, FlowTaskResult> entry : setupMap.entrySet()) {
@@ -127,6 +134,8 @@ public class ActivitiFromHtmlController {
                 break;
             }
         }
+        map.put("processDefinitionId", processDefinitionId);
+        map.put("deploymentId", deploymentId);
         return map;
     }
 

ファイルの差分が大きいため隠しています
+ 0 - 0
sop-server/src/main/resources/inside_approve.form


ファイルの差分が大きいため隠しています
+ 0 - 0
sop-server/src/main/resources/project.form


ファイルの差分が大きいため隠しています
+ 0 - 0
sop-server/src/main/resources/start.form


+ 27 - 18
sop-server/src/main/resources/testform1.bpmn

@@ -1,39 +1,48 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" xmlns:tns="http://www.activiti.org/test" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test" id="m1626068475250" name="">
-  <process id="myFormProcess_1" isExecutable="true" isClosed="false" processType="None">
-    <startEvent id="f_usertask_jwc_start" name="开始" activiti:formKey="start.form"></startEvent>
-    <userTask id="f_usertask_jwc_project" name="教务处sop_项目关键信息" activiti:assignee="${approveId}" activiti:formKey="project.form"></userTask>
-    <userTask id="f_usertask_jwc_inside_approve" name="教务处sop_内审" activiti:assignee="${approveId}" activiti:formKey="inside_approve.form"></userTask>
+  <process id="OFFICE_SOP_FLOW" isExecutable="true" isClosed="false" processType="None">
+    <startEvent id="start" name="开始"></startEvent>
+    <userTask id="f_usertask_jwc_start" name="新增sop" activiti:assignee="${approveId}" activiti:formKey="start_1.form"></userTask>
+    <userTask id="f_usertask_jwc_inside_approve" name="教务处sop_内审" activiti:assignee="${approveId}" activiti:formKey="inside_approve_3.form"></userTask>
     <endEvent id="f_usertask_jwc_end" name="结束"></endEvent>
-    <sequenceFlow id="_7" sourceRef="f_usertask_jwc_project" targetRef="f_usertask_jwc_inside_approve"></sequenceFlow>
     <sequenceFlow id="_8" sourceRef="f_usertask_jwc_inside_approve" targetRef="f_usertask_jwc_end"></sequenceFlow>
-    <sequenceFlow id="flow1" sourceRef="f_usertask_jwc_start" targetRef="f_usertask_jwc_project"></sequenceFlow>
+    <sequenceFlow id="flow1" sourceRef="start" targetRef="start"></sequenceFlow>
+    <userTask id="f_usertask_jwc_project" name="教务处sop_项目关键信息" activiti:assignee="${approveId}" activiti:formKey="project_2.form"></userTask>
+    <sequenceFlow id="flow2" sourceRef="f_usertask_jwc_start" targetRef="f_usertask_jwc_project"></sequenceFlow>
+    <sequenceFlow id="flow3" sourceRef="f_usertask_jwc_project" targetRef="f_usertask_jwc_inside_approve"></sequenceFlow>
   </process>
-  <bpmndi:BPMNDiagram id="BPMNDiagram_myFormProcess_1">
-    <bpmndi:BPMNPlane bpmnElement="myFormProcess_1" id="BPMNPlane_myFormProcess_1">
-      <bpmndi:BPMNShape bpmnElement="f_usertask_jwc_start" id="BPMNShape_f_usertask_jwc_start">
+  <bpmndi:BPMNDiagram id="BPMNDiagram_OFFICE_SOP_FLOW">
+    <bpmndi:BPMNPlane bpmnElement="OFFICE_SOP_FLOW" id="BPMNPlane_OFFICE_SOP_FLOW">
+      <bpmndi:BPMNShape bpmnElement="start" id="BPMNShape_start">
         <omgdc:Bounds height="35.0" width="35.0" x="240.0" y="15.0"></omgdc:Bounds>
       </bpmndi:BPMNShape>
-      <bpmndi:BPMNShape bpmnElement="f_usertask_jwc_project" id="BPMNShape_f_usertask_jwc_project">
+      <bpmndi:BPMNShape bpmnElement="f_usertask_jwc_start" id="BPMNShape_f_usertask_jwc_start">
         <omgdc:Bounds height="55.0" width="85.0" x="215.0" y="135.0"></omgdc:Bounds>
       </bpmndi:BPMNShape>
       <bpmndi:BPMNShape bpmnElement="f_usertask_jwc_inside_approve" id="BPMNShape_f_usertask_jwc_inside_approve">
-        <omgdc:Bounds height="55.0" width="85.0" x="215.0" y="276.0"></omgdc:Bounds>
+        <omgdc:Bounds height="55.0" width="85.0" x="215.0" y="360.0"></omgdc:Bounds>
       </bpmndi:BPMNShape>
       <bpmndi:BPMNShape bpmnElement="f_usertask_jwc_end" id="BPMNShape_f_usertask_jwc_end">
         <omgdc:Bounds height="35.0" width="35.0" x="240.0" y="480.0"></omgdc:Bounds>
       </bpmndi:BPMNShape>
-      <bpmndi:BPMNEdge bpmnElement="_7" id="BPMNEdge__7">
-        <omgdi:waypoint x="257.0" y="190.0"></omgdi:waypoint>
-        <omgdi:waypoint x="257.0" y="276.0"></omgdi:waypoint>
-      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNShape bpmnElement="f_usertask_jwc_project" id="BPMNShape_f_usertask_jwc_project">
+        <omgdc:Bounds height="55.0" width="85.0" x="215.0" y="240.0"></omgdc:Bounds>
+      </bpmndi:BPMNShape>
       <bpmndi:BPMNEdge bpmnElement="_8" id="BPMNEdge__8">
-        <omgdi:waypoint x="257.0" y="331.0"></omgdi:waypoint>
+        <omgdi:waypoint x="257.0" y="415.0"></omgdi:waypoint>
         <omgdi:waypoint x="257.0" y="480.0"></omgdi:waypoint>
       </bpmndi:BPMNEdge>
       <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
-        <omgdi:waypoint x="257.0" y="50.0"></omgdi:waypoint>
-        <omgdi:waypoint x="257.0" y="135.0"></omgdi:waypoint>
+        <omgdi:waypoint x="275.0" y="32.0"></omgdi:waypoint>
+        <omgdi:waypoint x="275.0" y="32.0"></omgdi:waypoint>
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
+        <omgdi:waypoint x="257.0" y="190.0"></omgdi:waypoint>
+        <omgdi:waypoint x="257.0" y="240.0"></omgdi:waypoint>
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
+        <omgdi:waypoint x="257.0" y="295.0"></omgdi:waypoint>
+        <omgdi:waypoint x="257.0" y="360.0"></omgdi:waypoint>
       </bpmndi:BPMNEdge>
     </bpmndi:BPMNPlane>
   </bpmndi:BPMNDiagram>

BIN
sop-server/src/main/resources/testform1.zip


この差分においてかなりの量のファイルが変更されているため、一部のファイルを表示していません