java110 пре 6 година
родитељ
комит
78096f41d3

+ 5 - 0
java110-utils/src/main/java/com/java110/utils/constant/ServiceCodeWorkflowConstant.java

@@ -27,5 +27,10 @@ public class ServiceCodeWorkflowConstant {
      */
     public static final String LIST_WORKFLOWS = "workflow.listWorkflows";
 
+    /**
+     * 查询 工作流成图
+     */
+    public static final String LIST_WORKFLOW_IMAGE = "workflow.listWorkflowImage";
+
 
 }

+ 91 - 0
service-api/src/main/java/com/java110/api/listener/workflow/ListWorkflowImageListener.java

@@ -0,0 +1,91 @@
+package com.java110.api.listener.workflow;
+
+import com.alibaba.fastjson.JSONObject;
+import com.java110.api.listener.AbstractServiceApiPlusListener;
+import com.java110.core.annotation.Java110Listener;
+import com.java110.core.context.DataFlowContext;
+import com.java110.core.event.service.api.ServiceDataFlowEvent;
+import com.java110.core.smo.common.IWorkflowInnerServiceSMO;
+import com.java110.dto.workflow.WorkflowDto;
+import com.java110.po.workflow.WorkflowPo;
+import com.java110.utils.constant.BusinessTypeConstant;
+import com.java110.utils.constant.ServiceCodeWorkflowConstant;
+import com.java110.utils.util.Assert;
+import com.java110.utils.util.BeanConvertUtil;
+import com.java110.utils.util.StringUtil;
+import com.java110.vo.ResultVo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+
+import java.util.List;
+
+/**
+ * 查询小区侦听类
+ */
+@Java110Listener("listWorkflowImageListener")
+public class ListWorkflowImageListener extends AbstractServiceApiPlusListener {
+
+    @Autowired
+    private IWorkflowInnerServiceSMO workflowInnerServiceSMOImpl;
+
+    @Override
+    public String getServiceCode() {
+        return ServiceCodeWorkflowConstant.LIST_WORKFLOW_IMAGE;
+    }
+
+    @Override
+    public HttpMethod getHttpMethod() {
+        return HttpMethod.GET;
+    }
+
+
+    public IWorkflowInnerServiceSMO getWorkflowInnerServiceSMOImpl() {
+        return workflowInnerServiceSMOImpl;
+    }
+
+    public void setWorkflowInnerServiceSMOImpl(IWorkflowInnerServiceSMO workflowInnerServiceSMOImpl) {
+        this.workflowInnerServiceSMOImpl = workflowInnerServiceSMOImpl;
+    }
+
+    @Override
+    protected void validate(ServiceDataFlowEvent event, JSONObject reqJson) {
+        Assert.hasKeyAndValue(reqJson, "communityId", "请求报文中请包含小区ID");
+        Assert.hasKeyAndValue(reqJson, "flowId", "请求报文中请包含商户ID");
+    }
+
+    @Override
+    protected void doSoService(ServiceDataFlowEvent event, DataFlowContext context, JSONObject reqJson) {
+
+        WorkflowDto workflowDto = BeanConvertUtil.covertBean(reqJson, WorkflowDto.class);
+
+
+        List<WorkflowDto> workflowDtos = workflowInnerServiceSMOImpl.queryWorkflows(workflowDto);
+
+        Assert.listOnlyOne(workflowDtos,"未查到工作流");
+
+        workflowDto = workflowDtos.get(0);
+        ResultVo resultVo = null;
+        if(StringUtil.isEmpty(workflowDto.getProcessDefinitionKey())){
+            resultVo = new ResultVo(ResultVo.CODE_ERROR, "流程还没有部署");
+            ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
+            context.setResponseEntity(responseEntity);
+            return;
+        }
+
+        String image = workflowInnerServiceSMOImpl.getWorkflowImage(workflowDto);
+
+        if(StringUtil.isEmpty(workflowDto.getProcessDefinitionKey())){
+            resultVo = new ResultVo(ResultVo.CODE_ERROR, "查询流程错误");
+            ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
+            context.setResponseEntity(responseEntity);
+            return;
+        }
+        resultVo = new ResultVo(ResultVo.CODE_OK, ResultVo.MSG_OK, image);
+        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
+        context.setResponseEntity(responseEntity);
+
+
+    }
+}

+ 23 - 39
service-common/src/main/java/com/java110/common/smo/impl/WorkflowInnerServiceSMOImpl.java

@@ -24,10 +24,10 @@ import org.activiti.bpmn.model.StartEvent;
 import org.activiti.bpmn.model.UserTask;
 import org.activiti.engine.ProcessEngine;
 import org.activiti.engine.ProcessEngines;
-import org.activiti.engine.history.HistoricProcessInstance;
+import org.activiti.engine.RuntimeService;
 import org.activiti.engine.repository.Deployment;
-import org.activiti.engine.runtime.ProcessInstance;
-import org.activiti.engine.task.Task;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RestController;
@@ -35,7 +35,6 @@ import org.springframework.web.bind.annotation.RestController;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 
 /**
@@ -48,6 +47,7 @@ import java.util.List;
  **/
 @RestController
 public class WorkflowInnerServiceSMOImpl extends BaseServiceSMO implements IWorkflowInnerServiceSMO {
+    private static final Logger logger = LoggerFactory.getLogger(BaseServiceSMO.class);
 
     @Autowired
     private IWorkflowServiceDao workflowServiceDaoImpl;
@@ -55,6 +55,9 @@ public class WorkflowInnerServiceSMOImpl extends BaseServiceSMO implements IWork
     @Autowired
     private IUserInnerServiceSMO userInnerServiceSMOImpl;
 
+    @Autowired
+    private RuntimeService runtimeService;
+
     @Override
     public List<WorkflowDto> queryWorkflows(@RequestBody WorkflowDto workflowDto) {
 
@@ -111,46 +114,28 @@ public class WorkflowInnerServiceSMOImpl extends BaseServiceSMO implements IWork
         return userIds.toArray(new String[userIds.size()]);
     }
 
-    public String getWorkflowImage(@RequestBody WorkflowDto workflowDto){
+    public String getWorkflowImage(@RequestBody WorkflowDto workflowDto) {
 
         ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
+        List<String> list = processEngine.getRepositoryService()//
+                .getDeploymentResourceNames(workflowDto.getProcessDefinitionKey());
         String image = "";
-        /*ProcessInstance processInstance = runtimeService.createProcessInstanceQuery()
-                .processInstanceId(processInstanceId).singleResult();
-        String processDefinitionId = "";
-        if (processInstance == null) {
-            //查询已经结束的流程实例
-            HistoricProcessInstance processInstanceHistory =
-                    historyService.createHistoricProcessInstanceQuery()
-                            .processInstanceId(processInstanceId).singleResult();
-            if (processInstanceHistory == null)
-                return null;
-            else
-                processDefinitionId = processInstanceHistory.getProcessDefinitionId();
-        } else {
-            processDefinitionId = processInstance.getProcessDefinitionId();
+        String resourceName = "";
+        if (list != null && list.size() > 0) {
+            for (String name : list) {
+                if (name.indexOf(".png") >= 0) {
+                    resourceName = name;
+                }
+            }
         }
 
-        //使用宋体
-        String fontName = "宋体";
-        //获取BPMN模型对象
-        BpmnModel model = repositoryService.getBpmnModel(processDefinitionId);
-        //获取流程实例当前的节点,需要高亮显示
-        List<String> currentActs = Collections.EMPTY_LIST;
-        if (processInstance != null)
-            currentActs = runtimeService.getActiveActivityIds(processInstance.getId());
-
-        InputStream is = processEngine.getProcessEngineConfiguration()
-                .getProcessDiagramGenerator()
-                .generateDiagram(model, "png", currentActs, new ArrayList<String>(),
-                        fontName, fontName, fontName, null, 1.0);
-
+        InputStream in = processEngine.getRepositoryService()
+                .getResourceAsStream(workflowDto.getProcessDefinitionKey(), resourceName);
         try {
-            image = Base64Convert.ioToBase64(is);
+            image = Base64Convert.ioToBase64(in);
         } catch (IOException e) {
-            e.printStackTrace();
-        }*/
-
+            logger.error("读取图片失败", e);
+        }
         return image;
     }
 
@@ -172,7 +157,6 @@ public class WorkflowInnerServiceSMOImpl extends BaseServiceSMO implements IWork
         process.setId(WorkflowDto.DEFAULT_PROCESS + workflowDto.getFlowId());
         process.setName(workflowDto.getFlowName());
         process.setDocumentation(workflowDto.getDescrible());
-        workflowDto.setProcessDefinitionKey(process.getId());
         //添加流程
         //开始节点
         process.addFlowElement(createStartEvent());
@@ -266,7 +250,7 @@ public class WorkflowInnerServiceSMOImpl extends BaseServiceSMO implements IWork
 
         // 3. 部署流程
         Deployment deployment = processEngine.getRepositoryService().createDeployment().addBpmnModel(process.getId() + ".bpmn", model).name(process.getId() + "_deployment").deploy();
-
+        workflowDto.setProcessDefinitionKey(deployment.getId());
         //        // 4. 启动一个流程实例
 //        ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceByKey(process.getId());
 //