kimi
2020-05-27 c007f0ca1785db093d48f4846cda82fe8e955765
src/main/java/com/highdatas/mdm/controller/ActivitiController.java
@@ -2,35 +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.MaintainField;
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.*;
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
 */
@@ -64,52 +64,91 @@
    @Autowired
    IMaintainService maintainService;
    @Autowired
    ITUserService userService;
    @Autowired
    IMasterModifiedService masterModifiedService;
    @Autowired
    IMaintainFieldService maintainFieldService;
    @Value("${img.url}")
    String basePath;
    @Autowired
    ISysFieldService fieldService;
    @Autowired
    TodoClient client;
    @Autowired
    IMenuMappingService menuMappingService;
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public Result<List<Map<String, Object>>> list(HttpServletRequest request) throws FileNotFoundException {
    /**
     *
     * @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的id
     * @param  response 请求返回的response
     * @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();
                }
@@ -118,8 +157,17 @@
        }
    }
    /**
     *
     * @description:  通过modelId删除model 接口
     * @param  modelId model的id
     * @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);
@@ -127,25 +175,42 @@
            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 = "/modellist", method = RequestMethod.GET)
    public Result<Result<JSONArray>> modellist(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:  启动流程后平台回调接口
    @RequestMapping(value = "/start/{key}", method = RequestMethod.GET)
    public Result<Object> start(@PathVariable String key,@RequestParam String businessId, HttpServletRequest request)  {
        if (StringUtils.isEmpty(key)) {
            return Result.error(new CodeMsg(1000, "key is not found"));
     * @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);
        }
        String desp = request.getParameter("desp");
        return Result.success(null);
    }
    /**
     *
     * @description:  页面调用启动流程接口
     * @param: key  model的key
     * @param businessId  业务系统的id
     * @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)) {
@@ -153,146 +218,240 @@
        } 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);
        }
    }
    /**
     *
     * @description:  平台调用启动流程接口
     * @param: key  model的key
     * @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 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);
            /*判断本主题是否已经有流程正在启动,若已经启动则不再允许*/
            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();
        Flows flows = activitiService.start(key, session, businessId, type);
        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 {
        } else {
            /*启动流程后的操作*/
            if (type.equals(ActivitiBusinessType.field)) {
                /*更新流程信息到 MaintainField表*/
                MaintainField maintainField = maintainFieldService.selectById(businessId);
                maintainField.setFlowId(flows.getId());
                maintainField.setDesp(desp);
                maintainField.setDesp(desc);
                maintainField.updateById();
                return Result.success(flows.getId());
            }
            else if (type.equals(ActivitiBusinessType.maintain)) {
            } 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);
        }
        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 = "/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)) {
@@ -304,112 +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 = 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);
                    }
                    flowsService.aduitFinish(flows);
            /*处理成功   继续后面的操作*/
            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){
    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){
    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);
    }
    @RequestMapping(value = "/deleteActUserRole")
    public Result deleteActUserRole(@RequestParam String roleId, @RequestParam String userId){
        return identityService.deleteUserRole(roleId,userId);
    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){
    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){
    public Result deleteActUser(@RequestParam String userId) {
        return identityService.deleteUser(userId);
    }
}