private String preView(String operate) { log.debug("*** preView 方法开始"); log.debug( new StringBuilder("*** Received parameter:[") .append("task:") .append(task) .append("]") .toString()); workflowInstance = workflowInstanceManager.getWorkflowInstance(task.getProcessInstanceId()); workflowId = task.getProcessInstanceId(); StringBuilder builder = new StringBuilder(); builder .append("<input type=\"hidden\" name=\"dataId\" value=\"") .append(workflowInstance.getDataId()) .append("\"/>"); FormView form = formViewManager.getFormView(workflowInstance.getFormId()); formHtml = workflowInstanceManager.setValueForHtml(workflowInstance.getDataId(), form, form.getHtml()); formHtml = builder.toString() + formHtml; if (SAVE.equals(operate)) { formHtml = workflowInstanceManager.getFormHtml( workflowInstance, formHtml, workflowInstance.getDataId(), true, false); fieldPermission = ApiFactory.getFormService().getFieldPermission(task.getId()); } else { formHtml = workflowInstanceManager.getFormHtml( workflowInstance, formHtml, workflowInstance.getDataId(), false, false); fieldPermission = workflowRightsManager.getFieldPermission(false); } ApiFactory.getBussinessLogService().log("工作流管理", "查看已完成任务", ContextUtils.getSystemId("wf")); log.debug("*** preView 方法结束"); return "view"; }
/** 处理任务 */ @Override public String input() throws Exception { log.debug("*** input 处理任务方法开始"); log.debug( new StringBuilder("*** Received parameter:[") .append("task:") .append(task) .append("]") .toString()); taskService.updateTaskIsRead(task); workflowId = task.getProcessInstanceId(); workflowInstance = workflowInstanceManager.getWorkflowInstance(workflowId); opinions = workflowInstanceManager.getOpinions(taskId, task.getCompanyId()); if (workflowRightsManager.mustOpinionRight(BeanUtil.turnToModelTask(task)) && (opinions == null || opinions.size() <= 0)) { must = true; } StringBuilder builder = new StringBuilder(); builder .append("<input type=\"hidden\" name=\"dataId\" value=\"") .append(workflowInstance.getDataId()) .append("\"/>"); formHtml = workflowInstanceManager.getHtml( workflowInstance.getProcessDefinitionId(), workflowInstance.getFormId(), workflowInstance.getDataId(), task.getName()); formHtml = builder.toString() + formHtml; if (TaskState.COMPLETED.getIndex().equals(task.getActive()) || TaskState.CANCELLED.getIndex().equals(task.getActive())) { // 列表控件控制 formHtml = workflowInstanceManager.getFormHtml( workflowInstance, formHtml, workflowInstance.getDataId(), false, false); fieldPermission = workflowRightsManager.getFieldPermission(false); } else if (TaskState.WAIT_CHOICE_TACHE.getIndex().equals(task.getActive())) { canChoiceTaches = taskService.isNeedChoiceTache(task, workflowInstance).getCanChoiceTaches(); return choiceTache(); } else { // 列表控件控制 formHtml = workflowInstanceManager.getFormHtml( workflowInstance, formHtml, workflowInstance.getDataId(), true, false); fieldPermission = ApiFactory.getFormService().getFieldPermission(task.getId()); } ApiFactory.getBussinessLogService().log("工作流管理", "任务办理页面", ContextUtils.getSystemId("wf")); log.debug("*** input 处理任务方法结束"); return INPUT; }
/* * 根据条件选定办理人 * @param conditions * @param creator * @param _wf_transactor * @return */ public static Set<String> processCondition( Map<TaskTransactorCondition, String> conditions, OpenExecution execution, Map<String, String> param) { Long companyId = ContextUtils.getCompanyId(); if (companyId == null) { Object compIdStr = execution.getVariable(CommonStrings.COMPANY_ID); if (compIdStr != null) { companyId = Long.parseLong(compIdStr.toString()); } } String userCondition = conditions.get(TaskTransactorCondition.USER_CONDITION); if (userCondition == null) { throw new RuntimeException("办理人设置中,解析条件时,设置的条件不能为null"); } // 根据条件获取办理人 Set<String> candidates = new HashSet<String>(); if ("${documentCreator}".equals(userCondition)) { // 文档创建人 candidates.add(param.get(DOCUMENT_CREATOR)); } else if ("${previousTransactorAssignment}".equals(userCondition)) { // 上一环节办理人指定 candidates.add(CommonStrings.TRANSACTOR_ASSIGNMENT); } else if (userCondition.startsWith("${field[")) { // 文档字段中指定//${field[name_zn[name_en]]} int start = userCondition.lastIndexOf("["); int end = userCondition.indexOf("]"); String fieldName = userCondition.substring(start + 1, end); // 根据流程实例ID获取流程表单中指定字段的值 WorkflowInstanceManager manager = (WorkflowInstanceManager) ContextUtils.getBean("workflowInstanceManager"); String fieldValues = manager.getFieldValueInForm(param.get(PROCESS_INSTANCEID), fieldName); if (fieldValues == null) { throw new RuntimeException("办理人设置中,文档字段中指定时,该字段的值不能为null"); } for (String fieldValue : fieldValues.split(",")) { fieldValue = fieldValue.trim(); if (StringUtils.isNotEmpty(fieldValue)) { if ("ALLCOMPANYID".equals(fieldValue)) { // 所有人员(不包含无部门人员) List<String> loginNames = ApiFactory.getAcsService().getLoginNamesByCompany(companyId); candidates.addAll(loginNames); } else if ("ALLWORKGROUP".equals(fieldValue)) { // 所有工作组中的人员 List<String> loginNames = ApiFactory.getAcsService().getLoginNamesByWorkgroup(companyId); candidates.addAll(loginNames); } else { candidates.add(fieldValue); } } } } else { if (execution == null) { throw new RuntimeException("办理人设置中,解析条件时,execution不能为null"); } FormViewManager formManager = (FormViewManager) ContextUtils.getBean("formViewManager"); WorkflowInstanceManager workflowInstanceManager = (WorkflowInstanceManager) ContextUtils.getBean("workflowInstanceManager"); WorkflowInstance wi = workflowInstanceManager.getWorkflowInstance(param.get(PROCESS_INSTANCEID), companyId); if (wi == null) { throw new RuntimeException("办理人设置中,解析条件时,流程实例不能为null"); } FormView form = formManager.getFormView(wi.getFormId()); UserParseCalculator upc = new UserParseCalculator(); upc.setDataId(wi.getDataId()); upc.setFormView(form); upc.setDocumentCreator(param.get(DOCUMENT_CREATOR)); upc.setPreviousTransactor(param.get(PREVIOUS_TRANSACTOR)); upc.setCurrentTransactor(param.get(CURRENT_TRANSACTOR)); upc.setProcessAdmin(param.get(PROCESS_ADMIN)); candidates.addAll( processAdditionalCondition( conditions, upc.getUsers(userCondition, wi.getSystemId(), wi.getCompanyId()), param.get(DOCUMENT_CREATOR), execution)); } return candidates; }
/* * 根据附加条件过滤办理人 * @param conditions * @param candidates * @param creator * @param _wf_transactor * @return */ private static Set<String> processAdditionalCondition( Map<TaskTransactorCondition, String> conditions, Set<String> candidates, String creator, OpenExecution execution) { Set<String> results = new HashSet<String>(); String selectOne = conditions.get(TaskTransactorCondition.SELECT_ONE_FROM_MULTIPLE); String onlyInCreatorDept = conditions.get(TaskTransactorCondition.ONLY_IN_CREATOR_DEPARTMENT); String withCreatorDept = conditions.get(TaskTransactorCondition.WITH_CREATOR_DEPARTMENT); if ("true".equals(onlyInCreatorDept) || "true".equals(withCreatorDept)) { List<String[]> usersInSameDept = AcsApi.getUsersInSameDept(ContextUtils.getCompanyId(), creator); // 只能为创建人部门(交集) if ("true".equals(onlyInCreatorDept)) { for (String[] user1 : usersInSameDept) { if (candidates.contains(user1[1])) { results.add(user1[1]); } } } else { results.addAll(candidates); } // 创建人部门参与(并集) if ("true".equals(withCreatorDept)) { for (String[] user1 : usersInSameDept) { results.add(user1[1]); } } } else { results.addAll(candidates); } Set<String> latest = new HashSet<String>(); // 需要唯一指定办理人 if ("true".equals(selectOne)) { // <select-type>autoType</select-type> // <select-bean>workflowInstanceManager</select-bean> // 只有一个候选人 if (conditions .get(TaskTransactorCondition.SELECT_TYPE) .equals(TaskTransactorCondition.SELECT_TYPE_CUSTOM)) { // if(results.size() == 1){ // latest.add(results.iterator().next()); // }else if(results.size() > 1){ latest.add(CommonStrings.TRANSACTOR_SINGLE); // 将候选人加入到execution变量中 execution.createVariable(CommonStrings.TRANSACTOR_SINGLE_CANDIDATES, results); // } } else { WorkflowInstanceManager workflowInstanceManager = (WorkflowInstanceManager) ContextUtils.getBean("workflowInstanceManager"); WorkflowInstance instance = workflowInstanceManager.getWorkflowInstance( execution.getProcessInstance().getProcessInstance().getId()); if (instance == null) { throw new RuntimeException("办理人设置中,解析附加条件时,流程实例不能为null"); } String selectorBeanName = conditions.get(TaskTransactorCondition.SELECT_BEAN); ActivityExecution activityExecution = (ActivityExecution) execution; String activityName = activityExecution.getActivityName(); if (StringUtils.isEmpty(selectorBeanName)) throw new WorkflowException("环节:" + activityName + "没有指定自动选择办理人的bean名"); SingleTransactorSelector selector = (SingleTransactorSelector) ContextUtils.getBean(selectorBeanName); boolean moreTransactor = DefinitionXmlParse.hasMoreTransactor(instance.getProcessDefinitionId(), activityName); Set<String> result = selector.filter(instance.getDataId(), results, moreTransactor); Iterator<String> it = result.iterator(); while (it.hasNext()) { latest.add(it.next()); } } } else { for (String user : results) { latest.add(user); } } return latest; }