天天看點

activiti擷取下一步審批人員及表單資訊

作者:阿亮堅持

備注:本文隻摘抄片段,整項目源代碼待全部整理完畢再提供代碼下載下傳。

(1),擷取下一步審批人員及表單資訊

@RequestMapping(value = "/getNextUsersLj", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> getNextUsersLj(@RequestParam(value = "processInstanceId", required = true)String processInstanceId
            , @RequestParam Map<String, Object> params) {
        String user = params.get("user") != null ? params.get("user").toString(): "";
        Map<String, Object> resultMap = new HashMap<String, Object>();
        String deptKey = params.get("deptKey")!= null ? params.get("deptKey").toString(): "";
        try {
            ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
            if(processInstance == null) {
                resultMap.put("success", false);
                resultMap.put("message", "未找到該流程執行個體!");
            }
            params.remove("deptKey");
            params.remove("user");
          // 在上一篇有workFlowService的方法
            resultMap = workFlowService.getNextTaskInfosLj(processInstanceId, params);
            List<ActivityBehavior> taskList = (List<ActivityBehavior>)resultMap.get("taskList");

            TaskDefinition task = null;
            resultMap.put("multiInstance", false);
            Map<String, String> actionNameMap = new HashMap<String, String>();
            List<String> conditionList = (List<String>)resultMap.get("conditionList");
            Map<String, List> usersMap = new HashMap<String, List>();
            Map<String, Map<String, String>> agreeActionMap = new LinkedHashMap<String, Map<String, String>>();
            Map<String, Map<String, String>> disAgreeActionMap = new LinkedHashMap<String, Map<String, String>>();

            ActivityBehavior activityBehavior = null;
            for(int i = 0; i < taskList.size() ; i++) {
                activityBehavior = taskList.get(i) != null ? taskList.get(i) : null;
                Map<String, String> propertyMap = new HashMap<String, String>();
                if(activityBehavior != null) {
                    if(activityBehavior instanceof ParallelMultiInstanceBehavior) {
                        resultMap.put("multiInstance", true);
                        continue;
                    }
                    task = null;
                    if(activityBehavior instanceof UserTaskActivityBehavior){
                        task = ((UserTaskActivityBehavior)activityBehavior).getTaskDefinition();
                    }
                    if(task == null)
                        continue;
                    if(task.getTaskFormHandler() instanceof DefaultFormHandler) {
                        DefaultFormHandler defaultFormHandler = (DefaultFormHandler)task.getTaskFormHandler();
                        List<FormPropertyHandler> formPropertyHandlers = defaultFormHandler.getFormPropertyHandlers();
                        for (FormPropertyHandler formPropertyHandler : formPropertyHandlers) {
                            if(formPropertyHandler.getVariableExpression() != null) {
                                propertyMap.put(formPropertyHandler.getId(), "");
                                continue;
                            }
                            propertyMap.put(formPropertyHandler.getId(), formPropertyHandler.getVariableExpression().getExpressionText() );
                        }
                    } // 表單屬性 end
                    actionNameMap.put(task.getKey(), task.getNameExpression().getExpressionText());
                    if(conditionList.get(i) == null || conditionList.get(i).replaceAll("\\s*", "").indexOf("agree==1") > -1 ) {
                        // 審批人員
                        List userList = new ArrayList();
                        List<HistoricTaskInstance> hisTaskList = historyService.createHistoricTaskInstanceQuery().processInstanceId(processInstanceId)
                                .taskDefinitionKey(task.getKey()).orderByHistoricTaskInstanceEndTime().desc().list();
                        if(!hisTaskList.isEmpty()) {
                            String _user = " and username = '" + hisTaskList.get(0).getAssignee() + "'";
                            userList.addAll(commonService.getUsers(_user));
                        } else {
                            Set<Expression> groups = task.getCandidateGroupIdExpressions();
                            Set<Expression> users = task.getCandidateUserIdExpressions();
                            for (Expression exp : groups) {
                                String expTxt = exp.getExpressionText();
                                if(StringUtils.isNotEmpty(expTxt)) {
                                    String[] expGroups = expTxt.split(",");
                                    for(int idx = 0, length = expGroups.length ; idx < length; idx++) {
                                        // 添加審批人員 目前暫時注解
                                        userList.addAll(commonService.getNextTaskHandlersLj(expGroups[idx], deptKey));
                                    }
                                }
                            } // 組循環結束
                            if(!users.isEmpty()) {
                                String[] userArr = new String[users.size()];
                                // 此審批人員是在流程設計器界面上設定的,是以暫不看
                                int j = 0;
                            }
                        } // 無曆史
                        usersMap.put(task.getKey(), (List)commonService.removeDupicateElement(userList) );
                        agreeActionMap.put(task.getKey(), propertyMap);
                    } else {
                        // 無condition
                        disAgreeActionMap.put(task.getKey(), propertyMap);
                    }
                } // 循環任務空判斷
                else {
                    usersMap.put("taskEnd", (List) commonService.removeDupicateElement(commonService.getUsers(" and username = '" + user + "'")));
                    actionNameMap.put("taskEnd", "結 束");
                    agreeActionMap.put("taskEnd", propertyMap);
                }
            }
            resultMap.put("usersMap", usersMap);              //對應的使用者清單
            resultMap.put("actionNameMap", actionNameMap);    //名稱映射
            resultMap.put("agreeActionMap", agreeActionMap);  //同意的表單屬性
            resultMap.put("disAgreeActionMap", disAgreeActionMap);//不同意的表單屬性
            resultMap.put("success", true);

        } catch (Exception ex1) {
            ex1.printStackTrace();
        }
        return resultMap;
    }           

(2),調用

<form action="<%=childPath %>/process/getNextUsersLj" method="post">
                <input type="hidden" name="form_name" value="YYG_QING_JIA_PROCESS_KEY" />

				(3)業務主鍵1:<input name="bussiness_key" type="text" value="1" /> <br />
                流程執行個體id:<input type="text" name="processInstanceId" value="" />

                <input type="submit" value="擷取下個任務及人員" />
            </form>           

繼續閱讀