Ver código fonte

优化代码

java110 4 anos atrás
pai
commit
fd53a098c2

+ 44 - 0
java110-bean/src/main/java/com/java110/dto/workflow/WorkflowModelDto.java

@@ -0,0 +1,44 @@
+package com.java110.dto.workflow;
+
+import java.io.Serializable;
+
+/**
+ * @ClassName WorkflowModelDto
+ * @Description TODO
+ * @Author wuxw
+ * @Date 2021/8/17 0:19
+ * @Version 1.0
+ * add by wuxw 2021/8/17
+ **/
+public class WorkflowModelDto implements Serializable {
+
+    private String name;
+
+    private String key;
+
+    private String modelId;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getKey() {
+        return key;
+    }
+
+    public void setKey(String key) {
+        this.key = key;
+    }
+
+    public String getModelId() {
+        return modelId;
+    }
+
+    public void setModelId(String modelId) {
+        this.modelId = modelId;
+    }
+}

+ 102 - 104
java110-db/src/main/resources/mapper/oa/OaWorkflowServiceDaoImplMapper.xml

@@ -5,129 +5,127 @@
 <mapper namespace="oaWorkflowServiceDaoImpl">
 
 
-
-
-
     <!-- 保存OA工作流信息 add by wuxw 2018-07-03 -->
     <insert id="saveOaWorkflowInfo" parameterType="Map">
         insert into oa_workflow(
-describle,model_id,flow_key,store_id,flow_id,flow_name,flow_type,process_definition_key
-) values (
-#{describle},#{modelId},#{flowKey},#{storeId},#{flowId},#{flowName},#{flowType},#{processDefinitionKey}
-)
+        describle,model_id,flow_key,store_id,flow_id,flow_name,flow_type,process_definition_key
+        ) values (
+        #{describle},#{modelId},#{flowKey},#{storeId},#{flowId},#{flowName},#{flowType},#{processDefinitionKey}
+        )
     </insert>
 
 
-
     <!-- 查询OA工作流信息 add by wuxw 2018-07-03 -->
     <select id="getOaWorkflowInfo" parameterType="Map" resultType="Map">
-        select  t.describle,t.model_id,t.model_id modelId,t.status_cd,t.status_cd statusCd,t.flow_key,t.flow_key flowKey,t.store_id,t.store_id storeId,t.flow_id,t.flow_id flowId,t.flow_name,t.flow_name flowName,t.flow_type,t.flow_type flowType,t.process_definition_key,t.process_definition_key processDefinitionKey 
-from oa_workflow t 
-where 1 =1 
-<if test="describle !=null and describle != ''">
-   and t.describle= #{describle}
-</if> 
-<if test="modelId !=null and modelId != ''">
-   and t.model_id= #{modelId}
-</if> 
-<if test="statusCd !=null and statusCd != ''">
-   and t.status_cd= #{statusCd}
-</if> 
-<if test="flowKey !=null and flowKey != ''">
-   and t.flow_key= #{flowKey}
-</if> 
-<if test="storeId !=null and storeId != ''">
-   and t.store_id= #{storeId}
-</if> 
-<if test="flowId !=null and flowId != ''">
-   and t.flow_id= #{flowId}
-</if> 
-<if test="flowName !=null and flowName != ''">
-   and t.flow_name= #{flowName}
-</if> 
-<if test="flowType !=null and flowType != ''">
-   and t.flow_type= #{flowType}
-</if> 
-<if test="processDefinitionKey !=null and processDefinitionKey != ''">
-   and t.process_definition_key= #{processDefinitionKey}
-</if> 
-order by t.create_time desc
-<if test="page != -1 and page != null ">
-   limit #{page}, #{row}
-</if> 
+        select t.describle,t.model_id,t.model_id modelId,t.status_cd,t.status_cd statusCd,t.flow_key,t.flow_key
+        flowKey,t.store_id,t.store_id storeId,t.flow_id,t.flow_id flowId,t.flow_name,t.flow_name
+        flowName,t.flow_type,t.flow_type flowType,t.process_definition_key,t.process_definition_key processDefinitionKey,
+        t.create_time createTime
+        from oa_workflow t
+        where 1 =1
+        <if test="describle !=null and describle != ''">
+            and t.describle= #{describle}
+        </if>
+        <if test="modelId !=null and modelId != ''">
+            and t.model_id= #{modelId}
+        </if>
+        <if test="statusCd !=null and statusCd != ''">
+            and t.status_cd= #{statusCd}
+        </if>
+        <if test="flowKey !=null and flowKey != ''">
+            and t.flow_key= #{flowKey}
+        </if>
+        <if test="storeId !=null and storeId != ''">
+            and t.store_id= #{storeId}
+        </if>
+        <if test="flowId !=null and flowId != ''">
+            and t.flow_id= #{flowId}
+        </if>
+        <if test="flowName !=null and flowName != ''">
+            and t.flow_name= #{flowName}
+        </if>
+        <if test="flowType !=null and flowType != ''">
+            and t.flow_type= #{flowType}
+        </if>
+        <if test="processDefinitionKey !=null and processDefinitionKey != ''">
+            and t.process_definition_key= #{processDefinitionKey}
+        </if>
+        order by t.create_time desc
+        <if test="page != -1 and page != null ">
+            limit #{page}, #{row}
+        </if>
 
     </select>
 
 
-
-
     <!-- 修改OA工作流信息 add by wuxw 2018-07-03 -->
     <update id="updateOaWorkflowInfo" parameterType="Map">
-        update  oa_workflow t set t.status_cd = #{statusCd}
-<if test="newBId != null and newBId != ''">
-,t.b_id = #{newBId}
-</if> 
-<if test="describle !=null and describle != ''">
-, t.describle= #{describle}
-</if> 
-<if test="modelId !=null and modelId != ''">
-, t.model_id= #{modelId}
-</if> 
-<if test="flowKey !=null and flowKey != ''">
-, t.flow_key= #{flowKey}
-</if> 
-<if test="storeId !=null and storeId != ''">
-, t.store_id= #{storeId}
-</if> 
-<if test="flowName !=null and flowName != ''">
-, t.flow_name= #{flowName}
-</if> 
-<if test="flowType !=null and flowType != ''">
-, t.flow_type= #{flowType}
-</if> 
-<if test="processDefinitionKey !=null and processDefinitionKey != ''">
-, t.process_definition_key= #{processDefinitionKey}
-</if> 
- where 1=1 <if test="flowId !=null and flowId != ''">
-and t.flow_id= #{flowId}
-</if> 
+        update oa_workflow t set t.status_cd = #{statusCd}
+        <if test="newBId != null and newBId != ''">
+            ,t.b_id = #{newBId}
+        </if>
+        <if test="describle !=null and describle != ''">
+            , t.describle= #{describle}
+        </if>
+        <if test="modelId !=null and modelId != ''">
+            , t.model_id= #{modelId}
+        </if>
+        <if test="flowKey !=null and flowKey != ''">
+            , t.flow_key= #{flowKey}
+        </if>
+        <if test="storeId !=null and storeId != ''">
+            , t.store_id= #{storeId}
+        </if>
+        <if test="flowName !=null and flowName != ''">
+            , t.flow_name= #{flowName}
+        </if>
+        <if test="flowType !=null and flowType != ''">
+            , t.flow_type= #{flowType}
+        </if>
+        <if test="processDefinitionKey !=null and processDefinitionKey != ''">
+            , t.process_definition_key= #{processDefinitionKey}
+        </if>
+        where 1=1
+        <if test="flowId !=null and flowId != ''">
+            and t.flow_id= #{flowId}
+        </if>
 
     </update>
 
     <!-- 查询OA工作流数量 add by wuxw 2018-07-03 -->
-     <select id="queryOaWorkflowsCount" parameterType="Map" resultType="Map">
-        select  count(1) count 
-from oa_workflow t 
-where 1 =1 
-<if test="describle !=null and describle != ''">
-   and t.describle= #{describle}
-</if> 
-<if test="modelId !=null and modelId != ''">
-   and t.model_id= #{modelId}
-</if> 
-<if test="statusCd !=null and statusCd != ''">
-   and t.status_cd= #{statusCd}
-</if> 
-<if test="flowKey !=null and flowKey != ''">
-   and t.flow_key= #{flowKey}
-</if> 
-<if test="storeId !=null and storeId != ''">
-   and t.store_id= #{storeId}
-</if> 
-<if test="flowId !=null and flowId != ''">
-   and t.flow_id= #{flowId}
-</if> 
-<if test="flowName !=null and flowName != ''">
-   and t.flow_name= #{flowName}
-</if> 
-<if test="flowType !=null and flowType != ''">
-   and t.flow_type= #{flowType}
-</if> 
-<if test="processDefinitionKey !=null and processDefinitionKey != ''">
-   and t.process_definition_key= #{processDefinitionKey}
-</if> 
+    <select id="queryOaWorkflowsCount" parameterType="Map" resultType="Map">
+        select count(1) count
+        from oa_workflow t
+        where 1 =1
+        <if test="describle !=null and describle != ''">
+            and t.describle= #{describle}
+        </if>
+        <if test="modelId !=null and modelId != ''">
+            and t.model_id= #{modelId}
+        </if>
+        <if test="statusCd !=null and statusCd != ''">
+            and t.status_cd= #{statusCd}
+        </if>
+        <if test="flowKey !=null and flowKey != ''">
+            and t.flow_key= #{flowKey}
+        </if>
+        <if test="storeId !=null and storeId != ''">
+            and t.store_id= #{storeId}
+        </if>
+        <if test="flowId !=null and flowId != ''">
+            and t.flow_id= #{flowId}
+        </if>
+        <if test="flowName !=null and flowName != ''">
+            and t.flow_name= #{flowName}
+        </if>
+        <if test="flowType !=null and flowType != ''">
+            and t.flow_type= #{flowType}
+        </if>
+        <if test="processDefinitionKey !=null and processDefinitionKey != ''">
+            and t.process_definition_key= #{processDefinitionKey}
+        </if>
 
 
-     </select>
+    </select>
 
 </mapper>

+ 11 - 0
java110-interface/src/main/java/com/java110/intf/common/IWorkflowInnerServiceSMO.java

@@ -3,6 +3,7 @@ package com.java110.intf.common;
 import com.java110.config.feign.FeignConfiguration;
 import com.java110.dto.workflow.WorkflowAuditInfoDto;
 import com.java110.dto.workflow.WorkflowDto;
+import com.java110.dto.workflow.WorkflowModelDto;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -61,4 +62,14 @@ public interface IWorkflowInnerServiceSMO {
      */
     @RequestMapping(value = "/queryWorkflowAuditHistory", method = RequestMethod.POST)
     List<WorkflowAuditInfoDto> queryWorkflowAuditHistory(@RequestBody WorkflowAuditInfoDto workflowAuditInfoDto);
+
+    /**
+     * 创建模型
+     * @param workflowModelDto
+     * @return
+     */
+    @RequestMapping(value = "/createModel", method = RequestMethod.POST)
+    WorkflowModelDto createModel(@RequestBody WorkflowModelDto workflowModelDto);
+
+
 }

+ 2 - 48
service-common/src/main/java/com/java110/common/api/WorkflowApi.java

@@ -34,55 +34,9 @@ public class WorkflowApi {
         return queryWorkFlowFirstStaffBMOImpl.query(workflowDto);
     }
 
-    private static final Logger logger = LoggerFactory.getLogger(ModelController.class);
 
-    @Autowired
-    private RepositoryService repositoryService;
-    @Autowired
-    private ObjectMapper objectMapper;
 
-    /**
-     * 创建模型
-     * @param response
-     * @param name 模型名称
-     * @param key 模型key
-     */
-    @RequestMapping("/create")
-    @ResponseBody
-    public String create(HttpServletResponse response, String name, String key) throws IOException {
-        logger.info("创建模型入参name:{},key:{}",name,key);
-        Model model = repositoryService.newModel();
-        ObjectNode modelNode = objectMapper.createObjectNode();
-        modelNode.put(ModelDataJsonConstants.MODEL_NAME, name);
-        modelNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, "");
-        modelNode.put(ModelDataJsonConstants.MODEL_REVISION, 1);
-        model.setName(name);
-        model.setKey(key);
-        model.setMetaInfo(modelNode.toString());
-        repositoryService.saveModel(model);
-        createObjectNode(model.getId());
-        logger.info("创建模型结束,返回模型ID:{}",model.getId());
-        return model.getId();
-    }
 
-    /**
-     * 创建模型时完善ModelEditorSource
-     * @param modelId
-     */
-    @SuppressWarnings("deprecation")
-    private void createObjectNode(String modelId){
-        logger.info("创建模型完善ModelEditorSource入参模型ID:{}",modelId);
-        ObjectNode editorNode = objectMapper.createObjectNode();
-        editorNode.put("id", "canvas");
-        editorNode.put("resourceId", "canvas");
-        ObjectNode stencilSetNode = objectMapper.createObjectNode();
-        stencilSetNode.put("namespace","http://b3mn.org/stencilset/bpmn2.0#");
-        editorNode.put("stencilset", stencilSetNode);
-        try {
-            repositoryService.addModelEditorSource(modelId,editorNode.toString().getBytes("utf-8"));
-        } catch (Exception e) {
-            logger.info("创建模型时完善ModelEditorSource服务异常:{}",e);
-        }
-        logger.info("创建模型完善ModelEditorSource结束");
-    }
+
+
 }

+ 65 - 4
service-common/src/main/java/com/java110/common/smo/impl/WorkflowInnerServiceSMOImpl.java

@@ -1,30 +1,47 @@
 package com.java110.common.smo.impl;
 
 
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.java110.common.dao.IWorkflowServiceDao;
 import com.java110.core.base.smo.BaseServiceSMO;
-import com.java110.intf.common.IWorkflowInnerServiceSMO;
-import com.java110.intf.user.IUserInnerServiceSMO;
 import com.java110.dto.PageDto;
 import com.java110.dto.user.UserDto;
 import com.java110.dto.workflow.WorkflowAuditInfoDto;
 import com.java110.dto.workflow.WorkflowDto;
+import com.java110.dto.workflow.WorkflowModelDto;
 import com.java110.dto.workflow.WorkflowStepDto;
 import com.java110.dto.workflow.WorkflowStepStaffDto;
+import com.java110.intf.common.IWorkflowInnerServiceSMO;
+import com.java110.intf.user.IUserInnerServiceSMO;
 import com.java110.utils.util.Base64Convert;
 import com.java110.utils.util.BeanConvertUtil;
 import com.java110.utils.util.DateUtil;
 import com.java110.utils.util.StringUtil;
 import org.activiti.bpmn.BpmnAutoLayout;
+import org.activiti.bpmn.model.BpmnModel;
+import org.activiti.bpmn.model.EndEvent;
+import org.activiti.bpmn.model.ExclusiveGateway;
+import org.activiti.bpmn.model.FlowNode;
+import org.activiti.bpmn.model.ParallelGateway;
 import org.activiti.bpmn.model.Process;
-import org.activiti.bpmn.model.*;
-import org.activiti.engine.*;
+import org.activiti.bpmn.model.SequenceFlow;
+import org.activiti.bpmn.model.StartEvent;
+import org.activiti.bpmn.model.UserTask;
+import org.activiti.editor.constants.ModelDataJsonConstants;
+import org.activiti.engine.HistoryService;
+import org.activiti.engine.ProcessEngine;
+import org.activiti.engine.ProcessEngines;
+import org.activiti.engine.RepositoryService;
+import org.activiti.engine.RuntimeService;
+import org.activiti.engine.TaskService;
 import org.activiti.engine.history.HistoricActivityInstance;
 import org.activiti.engine.history.HistoricActivityInstanceQuery;
 import org.activiti.engine.history.HistoricProcessInstance;
 import org.activiti.engine.impl.RepositoryServiceImpl;
 import org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity;
 import org.activiti.engine.repository.Deployment;
+import org.activiti.engine.repository.Model;
 import org.activiti.engine.task.Comment;
 import org.activiti.image.ProcessDiagramGenerator;
 import org.slf4j.Logger;
@@ -71,6 +88,9 @@ public class WorkflowInnerServiceSMOImpl extends BaseServiceSMO implements IWork
     @Autowired
     private TaskService taskService;
 
+    @Autowired
+    private ObjectMapper objectMapper;
+
     @Override
     public List<WorkflowDto> queryWorkflows(@RequestBody WorkflowDto workflowDto) {
 
@@ -570,6 +590,47 @@ public class WorkflowInnerServiceSMOImpl extends BaseServiceSMO implements IWork
         return workflowAuditInfoDtos;
     }
 
+    @Override
+    public WorkflowModelDto createModel(@RequestBody  WorkflowModelDto workflowModelDto) {
+        logger.info("创建模型入参name:{},key:{}", workflowModelDto.getName(), workflowModelDto.getKey());
+        Model model = repositoryService.newModel();
+        ObjectNode modelNode = objectMapper.createObjectNode();
+        modelNode.put(ModelDataJsonConstants.MODEL_NAME, workflowModelDto.getName());
+        modelNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, "");
+        modelNode.put(ModelDataJsonConstants.MODEL_REVISION, 1);
+        model.setName(workflowModelDto.getName());
+        model.setKey(workflowModelDto.getKey());
+        model.setMetaInfo(modelNode.toString());
+        repositoryService.saveModel(model);
+        createObjectNode(model.getId());
+        logger.info("创建模型结束,返回模型ID:{}", model.getId());
+        workflowModelDto.setModelId(model.getId());
+        return workflowModelDto;
+    }
+
+
+    /**
+     * 创建模型时完善ModelEditorSource
+     *
+     * @param modelId
+     */
+    @SuppressWarnings("deprecation")
+    private void createObjectNode(String modelId) {
+        logger.info("创建模型完善ModelEditorSource入参模型ID:{}", modelId);
+        ObjectNode editorNode = objectMapper.createObjectNode();
+        editorNode.put("id", "canvas");
+        editorNode.put("resourceId", "canvas");
+        ObjectNode stencilSetNode = objectMapper.createObjectNode();
+        stencilSetNode.put("namespace", "http://b3mn.org/stencilset/bpmn2.0#");
+        editorNode.put("stencilset", stencilSetNode);
+        try {
+            repositoryService.addModelEditorSource(modelId, editorNode.toString().getBytes("utf-8"));
+        } catch (Exception e) {
+            logger.info("创建模型时完善ModelEditorSource服务异常:{}", e);
+        }
+        logger.info("创建模型完善ModelEditorSource结束");
+    }
+
     /**
      * @param processInstanceId
      * @return

+ 14 - 1
service-oa/src/main/java/com/java110/oa/bmo/oaWorkflow/impl/SaveOaWorkflowBMOImpl.java

@@ -2,6 +2,8 @@ package com.java110.oa.bmo.oaWorkflow.impl;
 
 import com.java110.core.annotation.Java110Transactional;
 import com.java110.core.factory.GenerateCodeFactory;
+import com.java110.dto.workflow.WorkflowModelDto;
+import com.java110.intf.common.IWorkflowInnerServiceSMO;
 import com.java110.intf.oa.IOaWorkflowInnerServiceSMO;
 import com.java110.oa.bmo.oaWorkflow.ISaveOaWorkflowBMO;
 import com.java110.po.oaWorkflow.OaWorkflowPo;
@@ -16,6 +18,9 @@ public class SaveOaWorkflowBMOImpl implements ISaveOaWorkflowBMO {
     @Autowired
     private IOaWorkflowInnerServiceSMO oaWorkflowInnerServiceSMOImpl;
 
+    @Autowired
+    private IWorkflowInnerServiceSMO workflowInnerServiceSMOImpl;
+
     /**
      * 添加小区信息
      *
@@ -24,8 +29,16 @@ public class SaveOaWorkflowBMOImpl implements ISaveOaWorkflowBMO {
      */
     @Java110Transactional
     public ResponseEntity<String> save(OaWorkflowPo oaWorkflowPo) {
-
         oaWorkflowPo.setFlowId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_flowId));
+
+        //创建model
+        WorkflowModelDto workflowModelDto = new WorkflowModelDto();
+        workflowModelDto.setName(oaWorkflowPo.getFlowName());
+        workflowModelDto.setKey(oaWorkflowPo.getFlowId());
+        workflowModelDto = workflowInnerServiceSMOImpl.createModel(workflowModelDto);
+
+        oaWorkflowPo.setModelId(workflowModelDto.getModelId());
+        oaWorkflowPo.setFlowKey(workflowModelDto.getKey());
         int flag = oaWorkflowInnerServiceSMOImpl.saveOaWorkflow(oaWorkflowPo);
 
         if (flag > 0) {