From c007f0ca1785db093d48f4846cda82fe8e955765 Mon Sep 17 00:00:00 2001
From: kimi <kimi42345@gmail.com>
Date: 星期三, 27 五月 2020 09:59:29 +0800
Subject: [PATCH] merage

---
 src/main/java/com/highdatas/mdm/controller/ActivitiController.java |  716 ++++++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 505 insertions(+), 211 deletions(-)

diff --git a/src/main/java/com/highdatas/mdm/controller/ActivitiController.java b/src/main/java/com/highdatas/mdm/controller/ActivitiController.java
index 45c2be7..1aed224 100644
--- a/src/main/java/com/highdatas/mdm/controller/ActivitiController.java
+++ b/src/main/java/com/highdatas/mdm/controller/ActivitiController.java
@@ -2,37 +2,35 @@
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
-import com.baomidou.mybatisplus.mapper.EntityWrapper;
-import com.highdatas.mdm.entity.Flows;
-import com.highdatas.mdm.entity.Maintain;
-import com.highdatas.mdm.entity.TUser;
+import com.highdatas.mdm.entity.*;
 import com.highdatas.mdm.mapper.FlowsMapper;
 import com.highdatas.mdm.pojo.*;
-import com.highdatas.mdm.service.ActivitiService;
-import com.highdatas.mdm.service.IFlowsService;
-import com.highdatas.mdm.service.IMaintainService;
-import com.highdatas.mdm.service.ITUserService;
+import com.highdatas.mdm.service.*;
 import com.highdatas.mdm.service.act.*;
 import com.highdatas.mdm.util.Constant;
+import com.highdatas.mdm.util.DbUtils;
+import com.highdatas.mdm.util.TodoClient;
 import lombok.extern.slf4j.Slf4j;
-import org.activiti.engine.history.HistoricActivityInstance;
-import org.activiti.engine.history.HistoricProcessInstance;
 import org.activiti.engine.task.Task;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpSession;
-import java.io.*;
-import java.util.*;
-import java.util.stream.Collectors;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 /**
  * @author kimi
- * @description
+ * @description 宸ヤ綔娴佹帴鍙�
  * @date 2019-12-13 10:57
  */
 
@@ -66,47 +64,91 @@
 
     @Autowired
     IMaintainService maintainService;
-    @Autowired
-    ITUserService userService;
-    @Value("${img.url}")
-    String basePath;
 
-    @RequestMapping(value = "/list", method = RequestMethod.GET)
-    public Result<List<Map<String, Object>>> list(HttpServletRequest request) throws FileNotFoundException {
+    @Autowired
+    IMasterModifiedService masterModifiedService;
+
+    @Autowired
+    IMaintainFieldService maintainFieldService;
+    @Autowired
+    ISysFieldService fieldService;
+    @Autowired
+    TodoClient client;
+    @Autowired
+    IMenuMappingService menuMappingService;
+
+    /**
+     *
+     * @description:  model list 鎺ュ彛
+     * @param  pageNo 椤垫暟
+     * @param  request 璇锋眰request
+     * @return: Result 杩斿洖model list
+     *
+     */
+    @RequestMapping(value = "/list/{pageNo}", method = RequestMethod.GET)
+    public Result<List<Map<String, Object>>> list(@PathVariable Integer pageNo, HttpServletRequest request) {
+        /*
+         * filterSegment锛�  filter 鍙傛暟
+         * pageSize锛�  姣忛〉鏁伴噺
+         *
+         * */
+
         String filterSegment = request.getParameter("filterSegment");
+        String pageSize = request.getParameter("pageSize");
         if (StringUtils.isEmpty(filterSegment)) {
             filterSegment = Constant.WHERE_DEFAULT;
         }
+        /* By 鏈�澶х増鏈殑model 鍒楄〃*/
         List<Map<String, Object>> list = flowsMapper.selectVersion(filterSegment);
+         /*娣诲姞鐢熸垚鍚庡浘鐗囩殑url*/
         for (Map<String, Object> one : list) {
             String newModelId = (String) one.get(Constant.ID);
-            String url = "act/img/" +  newModelId;
-            one.put("imgurl",url);
+            String url = "act/img/" + newModelId;
+            one.put("imgurl", url);
         }
-        return Result.success(list);
+        Integer size;
+        /* pageSize 榛樿鍙傛暟*/
+        if (StringUtils.isEmpty(pageSize)) {
+            size = 15;
+        } else {
+            size = Integer.valueOf(pageSize);
+        }
+         /*total list 杞垎椤靛悗鐨� page list*/
+        return fieldService.getPagedDataByList(list, pageNo, size);
     }
+
+    /**
+     *
+     * @description:  閫氳繃modelId鑾峰彇娴佺▼鍥剧墖鎺ュ彛
+     * @param  modelId model鐨刬d
+     * @param  response 璇锋眰杩斿洖鐨剅esponse
+     * @return: void 鐩存帴濉炲埌response閲�
+     *
+     */
     @RequestMapping(value = "/img/{modelId}", method = RequestMethod.GET)
-    public void image(@PathVariable String modelId, HttpServletResponse response)  {
-        String filePath = basePath   + modelId +"/"+ modelId + ".png";
-        File file = new File(filePath);
-        FileInputStream fileInputStream = null;
+    public void image(@PathVariable String modelId, HttpServletResponse response) {
+        /*閫氳繃modelId 鑾峰彇 model鍥剧墖鐨勬祦*/
+        InputStream is = repositoryService.getModelImg(modelId);
+        if (is == null) {
+            return;
+        }
+        /*璁剧疆杩斿洖鐨勫ご淇℃伅*/
         response.setHeader("Content-Type", "image/png");
-        try{
-            fileInputStream = new FileInputStream(file);
+        try {
+            /*鍐欏埌response閲�*/
             OutputStream outputStream = response.getOutputStream();
             byte[] b = new byte[1024];
             int len;
-            while ((len = fileInputStream.read(b, 0, 1024)) != -1) {
+            while ((len = is.read(b, 0, 1024)) != -1) {
                 outputStream.write(b, 0, len);
             }
-        }
-        catch (Exception e) {
+        } catch (Exception e) {
             e.printStackTrace();
-        }
-        finally {
-            if (fileInputStream != null) {
+        } finally {
+            if (is != null) {
                 try {
-                    fileInputStream.close();
+                    /*鍏抽棴娴�*/
+                    is.close();
                 } catch (IOException e) {
                     e.printStackTrace();
                 }
@@ -115,8 +157,17 @@
         }
 
     }
+
+    /**
+     *
+     * @description:  閫氳繃modelId鍒犻櫎model 鎺ュ彛
+     * @param  modelId model鐨刬d
+     * @return: Result 鍒犻櫎淇℃伅鐨勮繑鍥炲��
+     *
+     */
     @RequestMapping(value = "/deleteModel/{modelId}", method = RequestMethod.GET)
-    public Result deleteModel(@PathVariable String modelId)  {
+    public Result deleteModel(@PathVariable String modelId) {
+        /*閫氳繃id鍒犻櫎model*/
         boolean b = repositoryService.deleteModel(modelId);
         if (b) {
             return Result.success(null);
@@ -124,155 +175,283 @@
             return Result.error(CodeMsg.DELETE_ERROR);
         }
     }
-    @RequestMapping(value = "/processlist", method = RequestMethod.GET)
-    public Result<Result<JSONArray>> processlist(HttpServletRequest request)  {
-        Result<JSONArray> processList   = repositoryService.getProcessList();
-        return Result.success(processList);
+
+//    @RequestMapping(value = "/processlist", method = RequestMethod.GET)
+//    public Result<Result<JSONArray>> processlist(HttpServletRequest request) {
+//        Result<JSONArray> processList = repositoryService.getProcessList();
+//        return Result.success(processList);
+//    }
+
+    /**
+     *
+     * @description:  鍚姩娴佺▼鍚庡钩鍙板洖璋冩帴鍙�
+
+     * @return: Result 鍚姩娴佺▼鍚庤繑鍥�
+     *
+     */
+    @RequestMapping(value = "/started", method = RequestMethod.POST)
+    public Result<Object> startRun(@RequestBody JSONArray result) {
+        for (int i = 0; i < result.size(); i++) {
+            String flowId = result.getString(i);
+            log.info(flowId);
+        }
+        return Result.success(null);
     }
 
-    @RequestMapping(value = "/modellist", method = RequestMethod.GET)
-    public Result<Result<JSONArray>> modellist(HttpServletRequest request)  {
-        Result<JSONArray> processList   = repositoryService.getProcessList();
-        return Result.success(processList);
+    /**
+     *
+     * @description:  椤甸潰璋冪敤鍚姩娴佺▼鎺ュ彛
+     * @param: key  model鐨刱ey
+     * @param businessId  涓氬姟绯荤粺鐨刬d
+     * @return: Result 鍚姩娴佺▼鍚庤繑鍥�
+     *
+     */
+    @RequestMapping(value = "/startRun/{key}", method = RequestMethod.GET)
+    public Result<Object> startRun(@PathVariable String key, @RequestParam String businessId, HttpServletRequest request) {
+         /*header閲岄潰鑾峰彇user淇℃伅*/
+        TUser user = DbUtils.getUser(request);
+         /*businessType 涓氬姟绯荤粺鐨勭被鍨�*/
+        String businessType = request.getParameter("businessType");
+        ActivitiBusinessType type;
+        if (StringUtils.isEmpty(businessType)) {
+            type = ActivitiBusinessType.maintain;
+        } else {
+            type = ActivitiBusinessType.valueOf(businessType);
+        }
+        String content;
+        if (type.equals(ActivitiBusinessType.maintain)) {
+            Maintain maintain = maintainService.selectById(businessId);
+             /*閫氳繃琛ㄥ悕鑾峰彇涓婚淇℃伅*/
+            SysMenu menuByTableName = menuMappingService.getMenuByTableName(maintain.getTableName());
+            /* content 閫氱煡淇℃伅鐨勫叿浣撳唴瀹�*/
+            content = menuByTableName.getName() + "涓婚鏂板鐗堟湰闇�瑕佸鎵�";
+        } else {
+            MaintainField maintainField = maintainFieldService.selectById(businessId);
+             /*閫氳繃琛ㄥ悕鑾峰彇涓婚淇℃伅*/
+            SysMenu menuByTableName = menuMappingService.getMenuByTableName(maintainField.getTableName());
+             /*content 閫氱煡淇℃伅鐨勫叿浣撳唴瀹�*/
+            content = menuByTableName.getName() + "涓婚淇敼瀛楁闇�瑕佸鎵�";
+        }
+
+        /*璋冭捣骞冲彴鍚姩娴佺▼鎺ュ彛*/
+        boolean open = client.open(key, businessId, content, user.getUserId(), type);
+        if (open) {
+            return Result.success(CodeMsg.SUCCESS);
+        } else {
+            return Result.error(CodeMsg.Client_fail);
+        }
     }
 
-
-    @RequestMapping(value = "/start/{key}", method = RequestMethod.GET)
-    public Result<Object> start(@PathVariable String key,@RequestParam String businessId, HttpServletRequest request)  {
+    /**
+     *
+     * @description:  骞冲彴璋冪敤鍚姩娴佺▼鎺ュ彛
+     * @param: key  model鐨刱ey
+     * @param reqObj  璇锋眰鍏蜂綋淇℃伅
+     *                businessId锛� 涓氬姟绯荤粺id
+     *                desc锛� 鎻忚堪淇℃伅
+     *                businessType锛� 涓氬姟绯荤粺绫诲瀷
+     *                variableMap锛氬叾浠栭澶栫殑淇℃伅锛屼繚瀛樿繘娴佺▼閲�
+     * @return: Result 鍚姩娴佺▼鍚庤繑鍥炰笅涓�鑺傜偣鐨勭敤鎴蜂俊鎭�
+     *
+     */
+    @RequestMapping(value = "/start/{key}", method = RequestMethod.POST)
+    public Result<Object> start(@PathVariable String key, @RequestBody JSONObject reqObj, HttpServletRequest request) {
+        log.info("process start..");
         if (StringUtils.isEmpty(key)) {
-                return Result.error(new CodeMsg(1000, "key is not found"));
-            }
-            String desp = request.getParameter("desp");
-            String businessType = request.getParameter("businessType");
-            ActivitiBusinessType type;
-            if (StringUtils.isEmpty(businessType)) {
-                type = ActivitiBusinessType.maintain;
-            } else {
-                type = ActivitiBusinessType.valueOf(businessType);
-            }
-            HttpSession session = request.getSession();
-            Flows flows = activitiService.start(key, session, businessId, type);
-            if (flows == null) {
-                return Result.error(CodeMsg.INSERT_ERROR);
-            }  else {
+            return Result.error(new CodeMsg(1000, "key is not found"));
+        }
 
-            if (type.equals(ActivitiBusinessType.maintain)) {
+        String businessId = reqObj.getString("businessId");
+        if (StringUtils.isEmpty(businessId)) {
+            return Result.error(new CodeMsg(1000, "businessId is not found"));
+        }
+        String businessType = reqObj.getString("businessType");
+        JSONObject variableObj = reqObj.getJSONObject("variableMap");
+        Map<String, Object> variableMap = new HashMap<>();
+        if (variableObj != null) {
+            variableMap = DbUtils.JsonObjectToHashMap(variableObj);
+        }
+        ActivitiBusinessType type;
+        if (StringUtils.isEmpty(businessType)) {
+            type = ActivitiBusinessType.maintain;
+        } else {
+            type = ActivitiBusinessType.valueOf(businessType);
+        }
+
+        if (type.equals(ActivitiBusinessType.maintain)) {
+            Maintain maintain = maintainService.selectById(businessId);
+            /*鍒ゆ柇鏈富棰樻槸鍚﹀凡缁忔湁娴佺▼姝e湪鍚姩锛岃嫢宸茬粡鍚姩鍒欎笉鍐嶅厑璁�*/
+            boolean canStart = maintainService.getCanAct(maintain.getTableName());
+            if (!canStart) {
+                return Result.error(CodeMsg.ACT_RUN_ERROR);
+            }
+        }
+
+        Object descObj = variableMap.get("desc");
+        String desc;
+        if (descObj == null) {
+            desc = "鍒涘缓鏂扮増鏈�";
+        } else {
+            desc = descObj.toString();
+        }
+        HttpSession session = request.getSession();
+        Date startDate = new Date();
+        /*鍚姩娴佺▼*/
+        Flows flows = activitiService.start(key, session, businessId, type, variableMap);
+        Date endDate = new Date();
+        log.info("process start:" + (endDate.getTime() - startDate.getTime()) + "ms");
+        if (flows == null) {
+            return Result.error(CodeMsg.INSERT_ERROR);
+        } else {
+            /*鍚姩娴佺▼鍚庣殑鎿嶄綔*/
+            if (type.equals(ActivitiBusinessType.field)) {
+                /*鏇存柊娴佺▼淇℃伅鍒� MaintainField琛�*/
+                MaintainField maintainField = maintainFieldService.selectById(businessId);
+                maintainField.setFlowId(flows.getId());
+                maintainField.setDesp(desc);
+                maintainField.updateById();
+            } else if (type.equals(ActivitiBusinessType.maintain)) {
+                /*鏇存柊娴佺▼淇℃伅鍒� maintain琛�*/
                 Maintain maintain = maintainService.selectById(businessId);
                 maintain.setFlowId(flows.getId());
-                maintain.setDesp(desp);
+                maintain.setDesp(desc);
                 maintain.updateById();
-                return Result.success(flows.getId());
-            }else if (type.equals(ActivitiBusinessType.exists)) {
-                HashMap<String, String> body=new HashMap();
-                NextTaskUserInfo nestTaskAssignee = taskService.getNestTaskAssignee(flows.getWorkflowId());
-
-                body.put("activitiId", flows.getId());
-                if (nestTaskAssignee == null) {
-                    body.put("roleId", null);
-                    body.put("userId", null);
-                } else {
-                    body.put("roleId", nestTaskAssignee.getRoleId());
-                    body.put("userId", nestTaskAssignee.getUserId());
-                }
-                return Result.success(body);
             }
-        }
-        return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED);
-    }
+            startDate = new Date();
+            log.info("process save status:" + (startDate.getTime() - endDate.getTime()) + "ms");
+            HashMap<String, Object> body = new HashMap();
+             /*鑾峰彇涓嬩竴鑺傜偣鐨勭敤鎴蜂俊鎭�*/
 
-    @RequestMapping(value = "/status/{flowid}", method = RequestMethod.GET)
-    public ArrayList<HistoricActivityInstance> status(@PathVariable String flowid, HttpServletRequest request)  {
-        if (StringUtils.isEmpty(flowid)) {
-            return null;
-        }
-        historyService.setSession(request.getSession());
-        Flows flows = flowsService.selectById(flowid);
-        if (flows == null) {
-            return null;
-        }
-        String workflowid = flows.getWorkflowId();
-        ArrayList<HistoricActivityInstance> historyAction = historyService.getHistoryAction(workflowid);
-        return historyAction;
-    }
-
-    @RequestMapping(value = "{tableName}/history/{pageNo}", method = RequestMethod.GET)
-    public Result history(@PathVariable String tableName, @PathVariable Integer pageNo, HttpServletRequest request)  {
-        historyService.setSession(request.getSession());
-        String pageSizeStr = request.getParameter("pageSize");
-
-        List<HistoricProcessInstance> processInstanceList = historyService.getHistoryTask();
-        List<HistoricProcessInstance> subList = new ArrayList<>();
-        for (HistoricProcessInstance historicProcessInstance : processInstanceList) {
-            Flows flows = flowsService.selectOne(new EntityWrapper<Flows>().eq("workflow_id", historicProcessInstance.getId()));
-            if (flows == null) {
-                continue;
+            NextTaskUserInfo nestTaskAssignee = taskService.getNestTaskAssignee(flows.getWorkflowId());
+            endDate = new Date();
+            log.info("process find user info:" + (endDate.getTime() - startDate.getTime()) + "ms");
+            body.put("activitiId", flows.getId());
+            if (nestTaskAssignee == null) {
+                body.put("roleIdList", null);
+                body.put("userIdList", null);
+            } else {
+                body.put("roleIdList", nestTaskAssignee.getRoleIdList());
+                body.put("userIdList", nestTaskAssignee.getUserIdList());
             }
-            ActivitiBusinessType businessType = flows.getBusinessType();
-            if (ActivitiBusinessType.maintain.equals(businessType)) {
-                String businessId = flows.getBusinessId();
-                Maintain maintain = maintainService.selectById(businessId);
-                if (maintain == null) {
-                    continue;
-                }
-                String maintainTableName = maintain.getTableName();
-                if (maintainTableName.equalsIgnoreCase(tableName)) {
-                    subList.add(historicProcessInstance);
-                }
-            }
+            return Result.success(body);
         }
-
-        Page page = new Page(subList.size());
-        page.setPageNo(pageNo);
-        if (!StringUtils.isEmpty(pageSizeStr)) {
-            page.setPageSize(Integer.valueOf(pageSizeStr));
-        }
-        subList = subList.stream().skip(page.getBeginRecordNo_1()).limit(page.getPageSize()).collect(Collectors.toList());
-        ArrayList<Map<String, Object>> result = new ArrayList<>();
-        for (HistoricProcessInstance historicProcessInstance : subList) {
-            HashMap<String, Object> one = new HashMap<>();
-            String workflowId = historicProcessInstance.getId();
-            String startUserId = historicProcessInstance.getStartUserId();
-            TUser user = userService.selectById(startUserId);
-            Flows flows = flowsService.selectOne(new EntityWrapper<Flows>().eq("workflow_id", workflowId));
-            Maintain maintain = maintainService.selectById(flows.getBusinessId());
-            one.put("userName", user.getUserName());
-            one.put("id", flows.getId());
-            one.put("status", flows.getStatus());
-            one.put("createTime", flows.getCreateTime());
-            result.add(one);
-        }
-        JSONObject object = new JSONObject();
-        object.fluentPut("total", page.getRecordCount());
-        object.fluentPut("size", page.getPageSize());
-        object.fluentPut("pages", page.getPageCount());
-        object.fluentPut("current", page.getPageNo());
-        object.fluentPut("record", result);
-
-        return Result.success(object);
     }
 
+//    @RequestMapping(value = "/status/{flowid}", method = RequestMethod.GET)
+//    public ArrayList<HistoricActivityInstance> status(@PathVariable String flowid, HttpServletRequest request) {
+//        if (StringUtils.isEmpty(flowid)) {
+//            return null;
+//        }
+//        historyService.setSession(request.getSession());
+//        Flows flows = flowsService.selectById(flowid);
+//        if (flows == null) {
+//            return null;
+//        }
+//        String workflowid = flows.getWorkflowId();
+//        ArrayList<HistoricActivityInstance> historyAction = historyService.getHistoryAction(workflowid);
+//        return historyAction;
+//    }
 
-    @RequestMapping(value = "/diagram/{flowid}", method = RequestMethod.GET)
-    public void getDiagram(@PathVariable String flowid, HttpServletResponse response)  {
-        if (StringUtils.isEmpty(flowid)) {
-            return;
-        }
-        Flows flows = flowsService.selectById(flowid);
-        if (flows == null) {
-            return;
-        }
-        String workflowid = flows.getWorkflowId();
-        runtimeService.getDiagram(workflowid, response);
-    }
-    @RequestMapping(value = "/run", method = RequestMethod.GET)
-    public List<Map<String, String>> runTask(HttpServletRequest request){
-        historyService.setSession(request.getSession());
-        List<Map<String, String>> myRunTask = historyService.getMyRunTask();
-        return myRunTask;
-    }
+//    @RequestMapping(value = "{tableName}/history/{pageNo}", method = RequestMethod.GET)
+//    public Result history(@PathVariable String tableName, @PathVariable Integer pageNo, HttpServletRequest request) {
+//        historyService.setSession(request.getSession());
+//        String pageSizeStr = request.getParameter("pageSize");
+//
+//        List<HistoricProcessInstance> processInstanceList = historyService.getHistoryTask();
+//        List<HistoricProcessInstance> subList = new ArrayList<>();
+//        for (HistoricProcessInstance historicProcessInstance : processInstanceList) {
+//            Flows flows = flowsService.selectOne(new EntityWrapper<Flows>().eq("workflow_id", historicProcessInstance.getId()));
+//            if (flows == null) {
+//                continue;
+//            }
+//            ActivitiBusinessType businessType = flows.getBusinessType();
+//            if (ActivitiBusinessType.maintain.equals(businessType)) {
+//                String businessId = flows.getBusinessId();
+//                Maintain maintain = maintainService.selectById(businessId);
+//                if (maintain == null) {
+//                    continue;
+//                }
+//                String maintainTableName = maintain.getTableName();
+//                if (maintainTableName.equalsIgnoreCase(tableName)) {
+//                    subList.add(historicProcessInstance);
+//                }
+//            }
+//        }
+//
+//        Page page = new Page(subList.size());
+//        page.setPageNo(pageNo);
+//        if (!StringUtils.isEmpty(pageSizeStr)) {
+//            page.setPageSize(Integer.valueOf(pageSizeStr));
+//        }
+//
+//        subList = subList.stream().skip(page.getBeginRecordNo_1()).limit(page.getPageSize()).collect(Collectors.toList());
+//        ArrayList<Map<String, Object>> result = new ArrayList<>();
+//        for (HistoricProcessInstance historicProcessInstance : subList) {
+//            HashMap<String, Object> one = new HashMap<>();
+//            String workflowId = historicProcessInstance.getId();
+//            String startUserId = historicProcessInstance.getStartUserId();
+//            TUser user = DbUtils.getUserById(startUserId);
+//            Flows flows = flowsService.selectOne(new EntityWrapper<Flows>().eq("workflow_id", workflowId));
+//            Maintain maintain = maintainService.selectById(flows.getBusinessId());
+//            one.put("userName", user.getUserName());
+//            one.put("id", flows.getId());
+//            one.put("status", flows.getStatus());
+//            one.put("createTime", flows.getCreateTime());
+//            result.add(one);
+//        }
+//
+//        Collections.sort(result, new Comparator<Map<String, Object>>() {
+//            @Override
+//            public int compare(Map<String, Object> o1, Map<String, Object> o2) {
+//                Date o1Date = (Date) o1.get("createTime");
+//                Date o2Date = (Date) o2.get("createTime");
+//                return o2Date.compareTo(o1Date);
+//            }
+//        });
+//
+//        JSONObject object = new JSONObject();
+//        object.fluentPut("total", page.getRecordCount());
+//        object.fluentPut("size", page.getPageSize());
+//        object.fluentPut("pages", page.getPageCount());
+//        object.fluentPut("current", page.getPageNo());
+//        object.fluentPut("record", result);
+//
+//        return Result.success(object);
+//    }
 
+
+//    @RequestMapping(value = "/diagram/{flowid}", method = RequestMethod.GET)
+//    public void getDiagram(@PathVariable String flowid, HttpServletResponse response) {
+//        if (StringUtils.isEmpty(flowid)) {
+//            return;
+//        }
+//        Flows flows = flowsService.selectById(flowid);
+//        if (flows == null) {
+//            return;
+//        }
+//        String workflowid = flows.getWorkflowId();
+//        runtimeService.getDiagram(workflowid, response);
+//    }
+
+//    @RequestMapping(value = "/run", method = RequestMethod.GET)
+//    public List<Map<String, String>> runTask(HttpServletRequest request) {
+//        historyService.setSession(request.getSession());
+//        List<Map<String, String>> myRunTask = historyService.getMyRunTask();
+//        return myRunTask;
+//    }
+
+    /**
+     *
+     * @description:  鑾峰彇鐢ㄦ埛鐨勫緟瀹℃壒淇℃伅
+     * @param :pageNo  椤垫暟
+     * @param :pageSize  姣忛〉鏁伴噺
+
+     * @return: Result 寰呭鎵规祦绋嬪垪琛�
+     *
+     */
     @RequestMapping(value = "/todo", method = RequestMethod.GET)
-    public Result todoTask(HttpServletRequest request){
+    public Result todoTask(HttpServletRequest request) {
+
         String pageNo = request.getParameter("pageNo");
         String pageSize = request.getParameter("pageSize");
         if (StringUtils.isEmpty(pageNo)) {
@@ -284,84 +463,199 @@
         return activitiService.todoTask(request.getSession(), request.getParameter(Constant.tableName), Integer.valueOf(pageNo), Integer.valueOf(pageSize));
     }
 
-    @RequestMapping(value = "/deal/{flowid}", method = RequestMethod.GET)
-    public Result doTask(@PathVariable String flowid, @RequestParam boolean pass, HttpServletRequest request)  {
+    /**
+     *
+     * @description:  骞冲彴璋冪敤澶勭悊娴佺▼鎺ュ彛
+     * @param: flowid  娴佺▼id
+     * @param: reqObj  璇锋眰鍏蜂綋淇℃伅
+     *                pass锛� 鏄惁鍚屾剰
+     *                reason锛� 瀹″垽鐞嗙敱
+     *                浠ュ強鍏朵粬棰濆鐨勪俊鎭紝淇濆瓨杩涙祦绋嬮噷
+     * @return: Result 鍚姩娴佺▼鍚庤繑鍥炰笅涓�鑺傜偣鐨勭敤鎴蜂俊鎭�
+     *
+     */
+    @RequestMapping(value = "/deal/{flowid}", method = RequestMethod.POST)
+    @Transactional(rollbackFor = {RuntimeException.class, Error.class})
+    public Result doTask(@PathVariable String flowid, @RequestBody JSONObject reqObj, HttpServletRequest request) {
+        /*鏍¢獙 flowid*/
         if (StringUtils.isEmpty(flowid)) {
             return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED);
         }
+        /*閫氳繃id鑾峰彇flow 淇℃伅*/
         Flows flows = flowsService.selectById(flowid);
+        /*鏍¢獙flows淇℃伅*/
         if (flows == null) {
             return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED);
         }
-        HttpSession session = request.getSession();
+        Boolean pass;
+        /*杞崲pass*/
+        try {
+            pass = (boolean) reqObj.get("pass");
+            if (pass == null) {
+                return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED);
+            }
 
+        } catch (Exception e) {
+            e.printStackTrace();
+            return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED);
+        }
+         /*jsonobject 杞负map*/
+        HashMap<String, Object> vailableMap = DbUtils.JsonObjectToHashMap(reqObj);
+
+        HttpSession session = request.getSession();
         taskService.setSession(session);
         ActivitiStatus status = flows.getStatus();
-
         String workflowId = flows.getWorkflowId();
-//        Task task = taskService.geTask(workflowId);
+//        Task task = TimeTaskService.geTask(workflowId);
 //        String id = task.getId();
         String taskId = null;
+        /*鍒ゆ柇浠诲姟鏄惁宸茬粡琚帴鏀�*/
         if (taskService.checkClaim(workflowId)) {
             taskId = taskService.claimTask(workflowId);
         }
 
         String reason;
-        reason = request.getParameter("reason");
-        if (StringUtils.isEmpty(reason)) {
+        /*杞崲reason淇℃伅*/
+        Object reasonObj = vailableMap.get("reason");
+        if (reasonObj == null) {
             reason = "纭澶勭悊";
+        }else  {
+            reason = reasonObj.toString();
         }
+        /*濡傛灉娌¤幏鍙栧埌task 鍐嶄粠tasksetvice閲岃幏鍙栦竴娆�*/
         if (taskId == null) {
             Task task = taskService.geTask(workflowId);
+            if (task == null) {
+                return Result.error(CodeMsg.ERROR_ACTIVITI_NEXTTASK);
+            }
             taskId = task.getId();
         }
-        boolean completed = taskService.completeTask(taskId, pass, reason);
+        /*澶勭悊浠诲姟*/
+        boolean completed = taskService.completeTask(taskId, pass, reason, vailableMap);
 
         if (completed) {
-                NextTaskUserInfo nextTaskDefinition = null;
-                boolean taskFinished = historyService.isTaskFinished(workflowId);
-                if (taskFinished) {
-                    if (ActivitiStatus.refuse.equals(status)) {
-                        flows.setStatus(ActivitiStatus.close);
-                    } else {
-                        flows.setStatus(ActivitiStatus.open);
-                    }
-
-                    if (!pass) {
-                        flows.setStatus(ActivitiStatus.close);
-                    }
-
-                    if (flows.getBusinessType().equals(ActivitiBusinessType.maintain)){
-                        String maintainId = flows.getBusinessId();
-                        maintainService.dealFlow(maintainId, flows.getStatus());
-                    }
-
+            /*澶勭悊鎴愬姛   缁х画鍚庨潰鐨勬搷浣�*/
+            NextTaskUserInfo nextTaskDefinition = null;
+            /*鍒ゆ柇娴佺▼鏄惁缁撴潫*/
+            boolean taskFinished = historyService.isTaskFinished(workflowId);
+            if (taskFinished) {
+                /*澶勭悊娴佺▼鐘舵��*/
+                if (ActivitiStatus.refuse.equals(status)) {
+                    flows.setStatus(ActivitiStatus.close);
                 } else {
-                    if (pass && flows.getStatus().equals(ActivitiStatus.refuse)) {
-                        flows.setStatus(ActivitiStatus.working);
-                    } else if(!pass && flows.getStatus().equals(ActivitiStatus.working)){
-                        flows.setStatus(ActivitiStatus.refuse);
-                    }
-                    nextTaskDefinition = taskService.getNestTaskAssignee(workflowId);
+                    flows.setStatus(ActivitiStatus.open);
+                }
 
+                if (!pass) {
+                    flows.setStatus(ActivitiStatus.close);
                 }
-            HashMap<String, String> body=new HashMap();
-            if (flows.getBusinessType().equals(ActivitiBusinessType.exists)){
-                body.put("status", flows.getStatus().name());
-                if (nextTaskDefinition == null) {
-                    body.put("roleId", null);
-                    body.put("userId", null);
-                } else {
-                    body.put("roleId", nextTaskDefinition.getRoleId());
-                    body.put("userId", nextTaskDefinition.getUserId());
+                /*娴佺▼瀹屾垚鍚庣殑涓�浜涙搷浣�*/
+                flowsService.aduitFinish(flows);
+
+            } else {
+                /*娴佺▼鏈畬鎴愶紝 淇敼娴佺▼鐘舵��*/
+                if (pass && flows.getStatus().equals(ActivitiStatus.refuse)) {
+                    flows.setStatus(ActivitiStatus.working);
+                } else if (!pass && flows.getStatus().equals(ActivitiStatus.working)) {
+                    flows.setStatus(ActivitiStatus.refuse);
                 }
+                /*杩斿洖 娴佺▼涓嬩竴鑺傜偣鐨勪俊鎭�*/
+                nextTaskDefinition = taskService.getNestTaskAssignee(workflowId);
+
+            }
+            HashMap<String, Object> body = new HashMap();
+        /*缁勮 杩斿洖淇℃伅*/
+            body.put("status", flows.getStatus().name());
+            if (nextTaskDefinition == null) {
+                body.put("roleIdList", null);
+                body.put("userIdList", null);
+            } else {
+                body.put("roleIdList", nextTaskDefinition.getRoleIdList());
+                body.put("userIdList", nextTaskDefinition.getUserIdList());
             }
 
             flows.setUpdateTime(new Date());
             flowsService.updateById(flows);
             return Result.success(body);
-        }else {
+        } else {
             return Result.success(CodeMsg.INSERT_ERROR);
         }
     }
+    /**
+     *
+     * @description:  骞冲彴璋冪敤娣诲姞宸ヤ綔娴佺敤鎴蜂俊鎭帴鍙�
+     * @param: userId  鐢ㄦ埛id
+     * @return: Result 娣诲姞鐢ㄦ埛杩斿洖淇℃伅
+     *
+     */
+    @RequestMapping(value = "/addActUser")
+    public Result addActUser(@RequestParam String userId) {
+        return identityService.addUser(userId);
+    }
+
+    /**
+     *
+     * @description:  骞冲彴璋冪敤娣诲姞宸ヤ綔娴佽鑹蹭俊鎭帴鍙�
+     * @param: roleId  瑙掕壊id
+     * @return: Result 娣诲姞瑙掕壊杩斿洖淇℃伅
+     *
+     */
+    @RequestMapping(value = "/addActRole")
+    public Result addActRole(@RequestParam String roleId) {
+        return identityService.addRole(roleId);
+    }
+
+    /**
+     *
+     * @description:  骞冲彴璋冪敤娣诲姞宸ヤ綔娴佽鑹诧紝鐢ㄦ埛鍏宠仈淇℃伅鎺ュ彛
+     * @param: roleId  瑙掕壊id
+     * @param: userId  鐢ㄦ埛id
+     * @return: Result 娣诲姞瑙掕壊锛岀敤鎴峰叧鑱旇繑鍥炰俊鎭�
+     *
+     */
+
+    @RequestMapping(value = "/addActUserRole")
+    public Result addActUserRole(@RequestParam String roleId, @RequestParam String userId) {
+        return identityService.addUserRole(roleId, userId);
+    }
+
+    /**
+     *
+     * @description:  骞冲彴璋冪敤鍒犻櫎宸ヤ綔娴佽鑹诧紝鐢ㄦ埛鍏宠仈淇℃伅鎺ュ彛
+     * @param: roleId  瑙掕壊id
+     * @param: userId  鐢ㄦ埛id
+     * @return: Result 鍒犻櫎瑙掕壊锛岀敤鎴峰叧鑱旇繑鍥炰俊鎭�
+     *
+     */
+    @RequestMapping(value = "/deleteActUserRole")
+    public Result deleteActUserRole(@RequestParam String roleId, @RequestParam String userId) {
+        return identityService.deleteUserRole(roleId, userId);
+    }
+
+    /**
+     *
+     * @description:  骞冲彴璋冪敤鍒犻櫎宸ヤ綔娴佽鑹蹭俊鎭帴鍙�
+     * @param: roleId  瑙掕壊id
+     * @return: Result 鍒犻櫎瑙掕壊杩斿洖淇℃伅
+     *
+     */
+    @RequestMapping(value = "/deleteActRole")
+    public Result deleteActRole(@RequestParam String roleId) {
+        return identityService.deleteRole(roleId);
+    }
+
+    /**
+     *
+     * @description:  骞冲彴璋冪敤鍒犻櫎宸ヤ綔娴佺敤鎴蜂俊鎭帴鍙�
+     * @param: userId  鐢ㄦ埛id
+     * @return: Result 鍒犻櫎鐢ㄦ埛杩斿洖淇℃伅
+     *
+     */
+    @RequestMapping(value = "/deleteActUser")
+    public Result deleteActUser(@RequestParam String userId) {
+        return identityService.deleteUser(userId);
+    }
+
+
+
 }

--
Gitblit v1.8.0