Pārlūkot izejas kodu

Merge branch 'master' of http://git.keao.tech/SupplyChain/flowable

tudc 4 gadi atpakaļ
vecāks
revīzija
a87cdc4bbe

+ 266 - 1
flowable/src/main/java/com/huyi/flowable/controller/ApiController.java

@@ -1,21 +1,50 @@
 package com.huyi.flowable.controller;
 
+import com.huyi.flowable.BaseException;
 import com.huyi.flowable.BaseResult;
 import com.huyi.flowable.annotation.Log;
+import com.huyi.flowable.api.FlowModel;
+import com.huyi.flowable.entity.CusMeHistory;
+import com.huyi.flowable.entity.CusMeconfig;
+import com.huyi.flowable.mapper.MeHistoryMapper;
+import com.huyi.flowable.mapper.MenuMapper;
+import com.huyi.flowable.server.mapper.ConfigMapper;
+import com.huyi.flowable.util.FileUtil;
+import com.huyi.flowable.util.HttpClient;
+import com.huyi.flowable.util.JsonUtil;
+import com.huyi.flowable.util.XmlUtil;
+import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
 import org.apache.commons.lang3.StringUtils;
 import org.flowable.engine.IdentityService;
+import org.flowable.engine.RepositoryService;
+import org.flowable.engine.repository.Deployment;
+import org.flowable.engine.repository.ProcessDefinition;
 import org.flowable.idm.api.Group;
 import org.flowable.idm.api.User;
 import org.flowable.idm.engine.impl.persistence.entity.GroupEntityImpl;
 import org.flowable.idm.engine.impl.persistence.entity.UserEntityImpl;
+import org.jdom.JDOMException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseBody;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
 
-import java.util.List;
+import javax.servlet.http.HttpServletRequest;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import java.io.*;
+import java.util.*;
 
 /**
  * @Description     集成接口,用户,组织结构等
@@ -27,6 +56,25 @@ public class ApiController {
     @Autowired
     IdentityService identityService;
 
+    @Autowired
+    HttpClient httpClient;
+
+    @Autowired
+    private MenuMapper menuMapper;
+
+    @Autowired
+    private RepositoryService repositoryService;
+
+    @Autowired
+    private MeHistoryMapper meHistoryMapper;
+
+    @Autowired
+    private FlowModel flowModel;
+
+    @Autowired
+    ConfigMapper configMapper;
+
+
     /**
      * 新增用户
      * @param id        用户id
@@ -189,4 +237,221 @@ public class ApiController {
         identityService.deleteGroup(groupId);
         return baseResult;
     }
+
+    /**
+     * 初始化企业流程图
+     * @param companyId
+     * @param personId
+     * @return
+     */
+    @Log
+    @Transactional(rollbackFor=Exception.class)
+    @RequestMapping(value = "initializeFlow")
+    @ResponseBody
+    public BaseResult initializeFlow (@RequestParam("companyId") String companyId, @RequestParam("personId") String personId, HttpServletRequest request) throws JDOMException, BaseException, IOException {
+        BaseResult baseResult = new BaseResult();
+
+        // 请求获取参数
+        String menuListStr = httpClient.doPost(HttpClient.GET_MENU, null, request);
+        menuListStr = menuListStr.replace(":null", ":\"\"");
+        Map dataMap = (Map) JSONObject.fromObject(menuListStr);
+        JSONObject  obc = JSONObject.fromObject(dataMap.get("data"));
+        JSONArray menuListJsonArray = (JSONArray)obc.get("records");
+        //获取审批菜单列表
+        List menuList = JsonUtil.JsonArrayToArrayList(menuListJsonArray);
+        //先查询流程表的数据是否存在
+        if(menuList.size() > 0) {
+            List<Map<String, String>> newList = menuList;
+            for (int i = 0; i < newList.size(); i++) {
+                //获取编号
+                String  papId = newList.get(i).get("papId");
+                //获取审批名称
+                String  papBusinessName = newList.get(i).get("papBusinessName");
+                //新增审批配置
+                CusMeconfig config = new CusMeconfig();
+                //编号getMenuList
+                config.setMenuId(papId);
+                //公司
+                config.setCompanyId(companyId);
+                //是否审批
+                config.setModel("1");
+                //获取表名
+                String  papTableName = newList.get(i).get("papTableName");
+                config.setTableName(papTableName);
+                //获取类型
+                String  papType = newList.get(i).get("papType");
+                config.setType(papType);
+                //获取链接
+                String  papUrl = newList.get(i).get("papUrl");
+                //获取回调地址
+                String papTokenUrl = newList.get(i).get("papTokenUrl");
+                config.setCallBackUrl(papTokenUrl);
+                //视图
+                if("0".equals(papType)){
+                    config.setFormJson(papUrl);
+                }//自定义链接
+                else if("1".equals(papType)){
+                    config.setCustomUrl(papUrl);
+                }
+                menuMapper.insertMenuModel(config);
+                //获取操作文件夹路径
+                String xml_template_url = configMapper.querySysConfig("xml_template_url").get("value");
+                //源文件地址
+                String filePath = xml_template_url.concat("template.bpmn20.xml");
+                System.out.println("源文件地址:" + filePath);
+                //目标文件地址
+                String newFilePath = xml_template_url.concat(papBusinessName + ".bpmn20.xml");
+                System.out.println("目标文件地址:" + newFilePath);
+                // 1、创建 File 对象,映射 XML 文件
+                File file = new File(filePath);
+                System.out.println("源文件是否存在:" + file.exists());
+                //流程id
+                String flowKey = "process_".concat(UUID.randomUUID().toString().replaceAll("-", ""));
+                System.out.println("流程的key:" + flowKey);
+                ProcessDefinition processDefinition;
+                processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey(flowKey).singleResult();
+                // 与其他流程的key重复
+                if (processDefinition != null) {
+                    System.out.println("流程的key重复");
+                    return new BaseResult("500", "流程的key重复", null);
+                }
+                //修改文件配置
+                updateXML(file,flowKey,personId);
+                InputStream stream = new FileInputStream(file);
+                String fileContent = FileUtil.inStreamToString(stream);
+                // 数据校验
+                XmlUtil.checkUserTask(fileContent);
+                //复制文件
+                copyFile(filePath, newFilePath);
+                File copayfile = new File(newFilePath);
+                Deployment deployment = flowModel.deployFlowXml(copayfile.getAbsolutePath());
+                boolean delete = copayfile.delete();
+                if (!delete) {
+                    System.out.println("文件删除失败!");
+                    return new BaseResult("500", "文件删除失败!", null);
+                }
+                processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
+
+                // 修改菜单配置和新增历史数据
+                updateMenuProcdefIdAndInsertHistory(papId, companyId, processDefinition.getId());
+            }
+        }
+        return baseResult;
+    }
+
+
+    private void updateMenuProcdefIdAndInsertHistory(String menuId, String companyId, String prodefId) {
+        Map<String, Object> param = new HashMap<>();
+        param.put("menuId", menuId);
+        param.put("companyId", companyId);
+        List<Map<String, Object>> menuList = menuMapper.selectMenu(param);
+        if (menuList.size() == 0) {
+            return;
+        }
+        Map<String, Object> menuMap = menuList.get(0);
+
+        // 修改cus_me_config的PROCDEF_ID
+        CusMeconfig meconfig = new CusMeconfig();
+        meconfig.setMenuId(menuId);
+        meconfig.setCompanyId(companyId);
+        meconfig.setProcdefId(prodefId);
+        menuMapper.updateMenuModel(meconfig);
+
+        CusMeHistory m = new CusMeHistory();
+        m.setCompanyId(companyId);
+        m.setMenuId(menuId);
+        m.setProcdefId(prodefId);
+        m.setCreateTime(new Date());
+        m.setTableName(String.valueOf(menuMap.get("tableName")));
+        m.setType(String.valueOf(menuMap.get("type")));
+        m.setFormJson(String.valueOf(menuMap.get("formJson")));
+        m.setCustomUrl(String.valueOf(menuMap.get("customUrl")));
+        meHistoryMapper.insertMeHistory(m);
+    }
+
+    /**
+     * 复制文件
+     * @param srcPathStr        源文件地址
+     * @param desPathStr        目标文件地址
+     * @return
+     */
+    private static void copyFile(String srcPathStr, String desPathStr)
+    {
+        try
+        {
+            //创建输入流对象
+            FileInputStream fis = new FileInputStream(srcPathStr);
+            //创建输出流对象
+            FileOutputStream fos = new FileOutputStream(desPathStr);
+            //创建搬运工具
+            byte datas[] = new byte[1024*8];
+            //创建长度
+            int len = 0;
+            //循环读取数据
+            while((len = fis.read(datas))!=-1)
+            {
+                fos.write(datas,0,len);
+            }
+            //释放资源
+            fos.close();
+            //释放资源
+            fis.close();
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 修改XML文件内容
+     * @param file        源文件
+     * @return
+     */
+    public static void updateXML(File file, String id, String personId) {
+        try {
+            // 2、创建 DocumentBuilderFactory 对象,用来创建 DocumentBuilder 对象
+            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+            // 3、创建 DocumentBuilder 对象,用来将 XML 文件 转化为 Document 对象
+            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
+            // 4、创建 Document 对象,解析 XML 文件
+            Document document = documentBuilder.parse(file);
+
+            // 修改第一个
+            // 5、获取 process 结点
+            Node processElement = document.getElementsByTagName("process").item(0);
+            NamedNodeMap processNodeMap = processElement.getAttributes();
+            Node processId = processNodeMap.getNamedItem("id");
+            processId.setTextContent(id);
+
+            // 修改第二个
+            // 5、获取 bpmndi 结点
+            Node bpmndiElement = document.getElementsByTagName("bpmndi:BPMNPlane").item(0);
+            NamedNodeMap bpmndiNodeMap = bpmndiElement.getAttributes();
+            Node bpmndiId = bpmndiNodeMap.getNamedItem("bpmnElement");
+            bpmndiId.setTextContent(id);
+
+            // 修改第三个
+            // 5、获取 userTask 结点
+            Node userTaskElement = document.getElementsByTagName("userTask").item(0);
+            NamedNodeMap userTaskNodeMap = userTaskElement.getAttributes();
+            Node userTaskAssignee = userTaskNodeMap.getNamedItem("flowable:assignee");
+            userTaskAssignee.setTextContent(personId);
+
+            // 9、创建 TransformerFactory 对象
+            TransformerFactory transformerFactory = TransformerFactory.newInstance();
+            // 10、创建 Transformer 对象
+            Transformer transformer = transformerFactory.newTransformer();
+            // 11、创建 DOMSource 对象
+            DOMSource domSource = new DOMSource(document);
+            // 12、创建 StreamResult 对象
+            StreamResult reStreamResult = new StreamResult(file);
+            transformer.transform(domSource, reStreamResult);
+            // 输出测试结果
+            StreamResult consoleResult = new StreamResult(System.out);
+            transformer.transform(domSource, consoleResult);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
 }

+ 102 - 3
flowable/src/main/java/com/huyi/flowable/controller/CloudSupplyChainController.java

@@ -3,16 +3,26 @@ package com.huyi.flowable.controller;
 import com.huyi.flowable.BaseResult;
 import com.huyi.flowable.annotation.Log;
 import com.huyi.flowable.mapper.CloudSupplyChainMapper;
+import com.huyi.flowable.util.ListUtil;
+import org.flowable.bpmn.constants.BpmnXMLConstants;
+import org.flowable.engine.HistoryService;
 import org.flowable.engine.IdentityService;
+import org.flowable.engine.RuntimeService;
+import org.flowable.engine.TaskService;
+import org.flowable.engine.history.HistoricActivityInstance;
+import org.flowable.engine.history.HistoricProcessInstance;
+import org.flowable.engine.runtime.ProcessInstance;
+import org.flowable.engine.task.Comment;
+import org.flowable.idm.api.User;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseBody;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.*;
 
 /**
  * 查询是否配置流程审批
@@ -24,6 +34,12 @@ public class CloudSupplyChainController {
     IdentityService identityService;
     @Autowired
     private CloudSupplyChainMapper cloudSupplyChainMapper;
+    @Autowired
+    protected HistoryService historyService;
+    @Autowired
+    protected RuntimeService runtimeService;
+    @Autowired
+    protected TaskService taskService;
 
     /**
      * 查询是否配置审批流程
@@ -45,6 +61,89 @@ public class CloudSupplyChainController {
         baseResult.setData(list);
         return baseResult;
     }
+    /**
+     * 查询当前审批进程
+     * @param businessKey
+     * @return
+     */
+    @Log
+    @RequestMapping(value = "selectCurrentProcess")
+    @ResponseBody
+    public BaseResult selectCurrentProcess(@RequestParam("businessKey") String businessKey) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
+        // TODO,需在流程展示的类型均需在此配置
+        Set<String> typeSet = new HashSet<String>();
+        typeSet.add(BpmnXMLConstants.ELEMENT_TASK_USER);
+        typeSet.add(BpmnXMLConstants.ELEMENT_EVENT_START);
+        typeSet.add(BpmnXMLConstants.ELEMENT_EVENT_END);
+        List<HistoricProcessInstance> processInstanceList = historyService.createHistoricProcessInstanceQuery().processInstanceBusinessKey(businessKey).orderByProcessInstanceStartTime().desc().list();
+        if (processInstanceList.size() != 0) {
+            List<HistoricActivityInstance> hisTaskList = historyService.createHistoricActivityInstanceQuery()
+                    .processInstanceId(processInstanceList.get(0).getId())
+                    .activityTypes(typeSet)
+                    .orderByHistoricActivityInstanceStartTime()
+                    .asc().list();
+            List<String> assigneeList = ListUtil.getIdFromList(hisTaskList, "assignee");
+
+            Collections.sort(hisTaskList, new Comparator<HistoricActivityInstance>() {
+                @Override
+                public int compare(HistoricActivityInstance o1, HistoricActivityInstance o2) {
+                    if (o1.getStartTime().getTime() > o2.getStartTime().getTime()) {
+                        return 1;
+                    } else if ((o1.getStartTime().getTime() < o2.getStartTime().getTime())) {
+                        return -1;
+                    } else {
+                        if (o1.getEndTime() != null && o2.getEndTime() != null) {
+                            if (o1.getEndTime().getTime() > o2.getEndTime().getTime()) {
+                                return 1;
+                            } else if ((o1.getEndTime().getTime() < o2.getEndTime().getTime())) {
+                                return -1;
+                            } else {
+                                return 0;
+                            }
+                        } else {
+                            if (o1.getEndTime() == null) {
+                                return 1;
+                            } else {
+                                return -1;
+                            }
+                        }
+                    }
+                }
+            });
+
+            List<User> userList = identityService.createUserQuery().userIds(assigneeList).list();
+
+            String[] str1 = {"assignee"};
+            String[] str2 = {"id"};
+            String[] str3 = {"displayName"};
+            String[] str4 = {"displayName"};
+
+            List<Map<String, Object>> resList = ListUtil.mergeList(hisTaskList, userList, str1, str2, str3, str4);
+
+            // 查询意见
+            List<Comment> commentEntityList = taskService.getProcessInstanceComments(processInstanceList.get(0).getId());
+
+            for (Map<String, Object> data : resList) {
+                for (Comment comment : commentEntityList) {
+                    System.out.println(comment.getTaskId() + "   " + data.get("id"));
+                    if (comment.getTaskId().equals(data.get("taskId"))) {
+                        if (data.get("commontList") != null) {
+                            ((List<Comment>)data.get("commontList")).add(comment);
+                        } else {
+                            List<Comment> commentList = new ArrayList<>();
+                            commentList.add(comment);
+                            data.put("commentList", commentList);
+                        }
+                    }
+                }
+            }
+
+            return new BaseResult(resList);
+        } else {
+            return new BaseResult("500", "未查询到流程", null);
+        }
+
+    }
 
 
 

+ 1 - 1
flowable/src/main/java/com/huyi/flowable/message/MessageService.java

@@ -61,7 +61,7 @@ public class MessageService {
         if ("1000000006".equals(menuId)) {
             param.put("workType", "08");
             //TODO 加标题
-            param.put("title","【融资审批】您有一笔" + paras.get("zfrAmountCN") + "(" + paras.get("zfrAmount") + ")的融资申请待内部审批");
+            param.put("title","【融资审批】您有一笔" + paras.get("zfrAmountCN") + "【¥" + paras.get("zfrAmount") + "】的融资申请待内部审批");
         // 融信审批
         } else {
 //            Map<String, Object> financeInf = messageMapper.queryFinanceInf(businessKey);

+ 8 - 8
flowable/src/main/resources/application-test.yml

@@ -2,17 +2,17 @@ spring:
   datasource:
     hikari:
       primary :
-        jdbc-url: jdbc:mysql://123.138.111.28:3506/supplychainFlowable?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
-        username: flowableUser
-        password: Aa1111111
+        jdbc-url: jdbc:mysql://124.71.226.2:3506/zcylflowable_test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
+        username: root
+        password: Keao@2021
       second:
-        jdbc-url: jdbc:mysql://123.138.111.28:3506/supplychain?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
-        username: supplychain
-        password: Aa1111111
+        jdbc-url: jdbc:mysql://124.71.226.2:3506/supplychain_test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
+        username: supplychain_test
+        password: Test@2021
   redis:
     port : 6379
-    host: 115.159.103.82
-    password  : 1234
+    host: 124.71.226.2
+    password  : 123456
 
 pagehelper:
   helperDialect: mysql

+ 1 - 1
flowable/src/main/resources/application.yml

@@ -13,7 +13,7 @@ mybatis:
     log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
 spring:
   profiles:
-    active: test
+    active: prod
 
 flowable:
   check-process-definitions: false