|
@@ -0,0 +1,778 @@
|
|
|
+package com.xt.js.gkaq.frame.wf.impl;
|
|
|
+
|
|
|
+import java.awt.print.Pageable;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import org.activiti.engine.ActivitiException;
|
|
|
+import org.activiti.engine.HistoryService;
|
|
|
+import org.activiti.engine.IdentityService;
|
|
|
+import org.activiti.engine.ManagementService;
|
|
|
+import org.activiti.engine.ProcessEngine;
|
|
|
+import org.activiti.engine.RepositoryService;
|
|
|
+import org.activiti.engine.RuntimeService;
|
|
|
+import org.activiti.engine.TaskService;
|
|
|
+import org.activiti.engine.history.HistoricProcessInstance;
|
|
|
+import org.activiti.engine.history.HistoricTaskInstance;
|
|
|
+import org.activiti.engine.history.HistoricVariableInstance;
|
|
|
+import org.activiti.engine.impl.Page;
|
|
|
+import org.activiti.engine.impl.persistence.entity.UserEntity;
|
|
|
+import org.activiti.engine.repository.ProcessDefinition;
|
|
|
+import org.activiti.engine.runtime.ProcessInstance;
|
|
|
+import org.activiti.engine.task.IdentityLink;
|
|
|
+import org.activiti.engine.task.NativeTaskQuery;
|
|
|
+import org.activiti.engine.task.Task;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
+import org.springframework.jdbc.support.rowset.SqlRowSet;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.Assert;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+
|
|
|
+import com.xt.js.gkaq.common.BaseUUIDModel;
|
|
|
+import com.xt.js.gkaq.common.Constants;
|
|
|
+import com.xt.js.gkaq.common.IdGenerator;
|
|
|
+import com.xt.js.gkaq.common.SinglePageRequest;
|
|
|
+import com.xt.js.gkaq.common.UUIDGenerator;
|
|
|
+import com.xt.js.gkaq.frame.model.TaskModel;
|
|
|
+import com.xt.js.gkaq.frame.model.UserModel;
|
|
|
+import com.xt.js.gkaq.frame.service.TaskModelService;
|
|
|
+import com.xt.js.gkaq.frame.service.UserService;
|
|
|
+import com.xt.js.gkaq.frame.service.WFPropService;
|
|
|
+import com.xt.js.gkaq.frame.system.Utils;
|
|
|
+import com.xt.js.gkaq.frame.wf.TaskVarListener;
|
|
|
+import com.xt.js.gkaq.frame.wf.WorkFlowParam;
|
|
|
+import com.xt.js.gkaq.frame.wf.WorkItem;
|
|
|
+import com.xt.js.gkaq.frame.wf.WorkflowMangerService;
|
|
|
+import com.yuanxd.tools.io.http.JsonResult;
|
|
|
+import com.yuanxd.tools.utils.BizException;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 工作流服务基类<br>
|
|
|
+ * 注入的服务:
|
|
|
+ * <li>用户服务SnpecUserService、
|
|
|
+ * <li>流程记录服务GzljlService、
|
|
|
+ * <li>
|
|
|
+ * 菜单服务SnpecMenuService
|
|
|
+ * <li>工作流服务<br>
|
|
|
+ * 实现的功能:
|
|
|
+ * <li>签收处理
|
|
|
+ * <li>提交处理
|
|
|
+ * <li>流程发起
|
|
|
+ * <li>读取流程定义图
|
|
|
+ * <li>待办任务一览查询
|
|
|
+ * <li>流程转发
|
|
|
+ * <li>流程强制结束
|
|
|
+ *
|
|
|
+ * @author 袁晓冬
|
|
|
+ *
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class WorkflowMangerServiceImpl implements WorkflowMangerService {
|
|
|
+ /** 流程定义缓存 */
|
|
|
+ protected static Map<String, ProcessDefinition> PROCESS_DEFINITION_CACHE = new HashMap<String, ProcessDefinition>();
|
|
|
+ @Autowired
|
|
|
+ protected IdentityService identityService;
|
|
|
+ @Autowired
|
|
|
+ protected RuntimeService runtimeService;
|
|
|
+ @Autowired
|
|
|
+ protected ManagementService managementService;
|
|
|
+ @Autowired
|
|
|
+ protected TaskService taskService;
|
|
|
+ @Autowired
|
|
|
+ protected ProcessEngine processEngine;
|
|
|
+ @Autowired
|
|
|
+ protected HistoryService historyService;
|
|
|
+ @Autowired
|
|
|
+ protected RepositoryService repositoryService;
|
|
|
+ @Autowired
|
|
|
+ protected TaskModelService taskModelService;
|
|
|
+ @Autowired
|
|
|
+ protected UserService userService;
|
|
|
+ @Autowired
|
|
|
+ protected WFPropService wfPropService;
|
|
|
+ /** ID主键生成器 */
|
|
|
+ protected IdGenerator idGenerator = new UUIDGenerator();
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private JdbcTemplate jdbcTemplate;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void autoComplete(WorkFlowParam param, String processInstanceId, Map<String, Object> variables) {
|
|
|
+ List<Task> taskList = getProcessActiveTasks(processInstanceId);
|
|
|
+ if (null == taskList) { return; }
|
|
|
+ for (Task t : taskList) {
|
|
|
+ Object autoComplete = taskService.getVariableLocal(t.getId(), TaskVarListener.KEY_AUTO_COMPLETE);
|
|
|
+ if ("true".equals(String.valueOf(autoComplete))) {
|
|
|
+ autoComplete(t, param, variables);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 自动完成任务
|
|
|
+ *
|
|
|
+ * @param param
|
|
|
+ * @param task
|
|
|
+ */
|
|
|
+ public void autoComplete(Task task, WorkFlowParam param, Map<String, Object> variables) {
|
|
|
+ if (variables == null) variables = new HashMap<String, Object>();
|
|
|
+ if (null == param) {
|
|
|
+ param = new WorkFlowParam();
|
|
|
+ }
|
|
|
+ // 设置审核结果为通过
|
|
|
+ if (!variables.containsKey(WorkFlowParam.AUDIT_PASS)) variables.put(WorkFlowParam.AUDIT_PASS, true);
|
|
|
+ // 任务执行时间
|
|
|
+ variables.put(TaskVarListener.KEY_CLAIM_DATE, new Date());
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat(DATA_TIME_FMART);
|
|
|
+ // 设置审核时间为当前时间
|
|
|
+ if (param.get(WorkFlowParam.AUDIT_DATE) == null) {
|
|
|
+ param.put(WorkFlowParam.AUDIT_DATE, sdf.format(new Date()));
|
|
|
+ }
|
|
|
+ // 设置审核意见为空
|
|
|
+ if (StringUtils.isEmpty(param.get(WorkFlowParam.AUDIT_TEXT))) {
|
|
|
+ param.put(WorkFlowParam.AUDIT_TEXT, "");
|
|
|
+ }
|
|
|
+ // 设置审核结果为通过
|
|
|
+ if (StringUtils.isEmpty(param.get(WorkFlowParam.AUDIT_RESULT))) {
|
|
|
+ param.put(WorkFlowParam.AUDIT_RESULT, "1");
|
|
|
+ }
|
|
|
+ // 设置完成人
|
|
|
+ if (StringUtils.isEmpty(param.get(WorkFlowParam.AUDIT_USER))) {
|
|
|
+ if (Utils.getCurrentUser() != null) param.put(WorkFlowParam.AUDIT_USER, Utils.getCurrentUser().getId());
|
|
|
+ }
|
|
|
+ // 完成当前任务
|
|
|
+ complete(param, variables, task);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 提交下一步处理<br>
|
|
|
+ *
|
|
|
+ */
|
|
|
+ public List<Task> complete(WorkFlowParam param, Map<String, Object> variables, Task task) {
|
|
|
+ // initialize variables
|
|
|
+ if (null == variables) {
|
|
|
+ variables = new HashMap<String, Object>();
|
|
|
+ }
|
|
|
+ if (Utils.getCurrentUser() != null) {
|
|
|
+ UserModel user = Utils.getCurrentUser();
|
|
|
+ variables.put(KEY_SENDER_ID, user.getId().toString());
|
|
|
+ variables.put(KEY_SENDER_NAME, user.getRealName());
|
|
|
+ }
|
|
|
+ // set audit result
|
|
|
+ Object auditRes = variables.get(WorkFlowParam.AUDIT_PASS);
|
|
|
+ if (null != auditRes) {
|
|
|
+ variables.remove(WorkFlowParam.AUDIT_PASS);
|
|
|
+ variables.put(WorkFlowParam.AUDIT_PASS + "_" + task.getTaskDefinitionKey(), auditRes);
|
|
|
+ }
|
|
|
+ // 设置上级审核变量
|
|
|
+ String sjshParam = param.getString(WorkFlowParam.AUDIT_SJSH_Field);
|
|
|
+ if (sjshParam == null) {
|
|
|
+ sjshParam = WorkFlowParam.AUDIT_SJSH;
|
|
|
+ }
|
|
|
+ boolean sjsh = !wfPropService.checkProp(param.getString(WorkFlowParam.PROCESS_DEFINITIONKEY),
|
|
|
+ task.getTaskDefinitionKey(), sjshParam, "false");
|
|
|
+ variables.put(WorkFlowParam.AUDIT_SJSH, sjsh);
|
|
|
+ // 完成任务
|
|
|
+ taskService.complete(task.getId(), variables);
|
|
|
+ // 更新工作流记录审核信息
|
|
|
+ TaskModel taskInfo = updateTaskAudit(task.getId(), param);
|
|
|
+ taskInfo.setState(String.valueOf(BaseUUIDModel.STATE_COMPLETED));
|
|
|
+ taskModelService.update(taskInfo);
|
|
|
+ /** 保存下级任务的工作流记录 */
|
|
|
+ List<Task> taskList = getProcessActiveTasks(task.getProcessInstanceId());
|
|
|
+ if (null == taskList) { return null; }
|
|
|
+ // 更新权力阳光办件过程信息
|
|
|
+ for (Task t : taskList) {
|
|
|
+ // 判断task是否已存在,会签时平级的task都会检索出来,此类task不需要更新工作流记录
|
|
|
+ //省级用户根据所在地和
|
|
|
+ TaskModel theTaskInfo = taskModelService.findByTaskId(t.getId());
|
|
|
+ if (null != theTaskInfo) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(t.getAssignee())) {
|
|
|
+ // 设置任务接收时间
|
|
|
+ Date jssj = new Date();
|
|
|
+ taskService.setVariableLocal(t.getId(), TaskVarListener.KEY_CLAIM_DATE, jssj);
|
|
|
+ }
|
|
|
+ // 任务描述延续存储
|
|
|
+ if (StringUtils.isEmpty(param.get(WorkFlowParam.DESCRIPTION))) {
|
|
|
+ t.setDescription(task.getDescription());
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ t.setDescription(param.get(WorkFlowParam.DESCRIPTION).toString());
|
|
|
+ }
|
|
|
+ taskService.saveTask(t);
|
|
|
+ TaskModel subTask = getTaskInfoFromTask(t);
|
|
|
+ subTask.setStartTime(taskInfo.getStartTime());
|
|
|
+ subTask.setStartUser(taskInfo.getStartUser());
|
|
|
+ taskModelService.save(subTask);
|
|
|
+ }
|
|
|
+ return taskList;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Long generateEntityId(String seqName) {
|
|
|
+ if (seqName != null) {
|
|
|
+ String sql = "SELECT " + seqName + ".nextval FROM dual";
|
|
|
+ try {
|
|
|
+ SqlRowSet rs = jdbcTemplate.queryForRowSet(sql);
|
|
|
+ if (rs.next()) {
|
|
|
+ String seq = rs.getString(1);
|
|
|
+ if (null != seq && seq.length() > 0) { return Long.parseLong(seq); }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return 0l;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成唯一编号,供权力阳光使用
|
|
|
+ *
|
|
|
+ * 部门编码(10位)+0000000001(流水号10位)
|
|
|
+ *
|
|
|
+ * @param seqName
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String generateQlygNo(String dept_code, Long entityId) {
|
|
|
+ StringBuffer no = new StringBuffer();
|
|
|
+ // if (null != seqName) {
|
|
|
+ no.append(dept_code);
|
|
|
+ String seq = entityId.toString();
|
|
|
+ if (null != seq && seq.length() > 0) {
|
|
|
+ if (seq.length() < 10) {
|
|
|
+ for (int i = seq.length(); i < 10; i++) {
|
|
|
+ no.append("0");
|
|
|
+ }
|
|
|
+ no.append(seq);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ no.append(seq.substring(seq.length() - 10, seq.length()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return no.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String create(WorkFlowParam param, Map<String, Object> variables, String processDefinitionKey) {
|
|
|
+ // 流程定义key存在判断
|
|
|
+ Assert.hasLength(processDefinitionKey);
|
|
|
+ // 设置流程启动人
|
|
|
+ identityService.setAuthenticatedUserId(param.get(WorkFlowParam.AUDIT_USER).toString());
|
|
|
+ ProcessInstance processInstance = null;
|
|
|
+ String businessKey = param.get(WorkFlowParam.BUSINESS_KEY).toString();
|
|
|
+ if (!StringUtils.hasLength(businessKey)) {
|
|
|
+ businessKey = System.currentTimeMillis() + "";
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ businessKey = processDefinitionKey + BUSKEYSEP + businessKey;
|
|
|
+ }
|
|
|
+ // 判断业务key是否已存在
|
|
|
+ List<ProcessInstance> processList_0 = runtimeService.createProcessInstanceQuery()
|
|
|
+ .processInstanceBusinessKey(businessKey, processDefinitionKey).list();
|
|
|
+ if (null != processList_0 && processList_0
|
|
|
+ .size() > 0) { throw new BizException("record had already started process!" + processList_0); }
|
|
|
+ if (Utils.getCurrentUser() != null) {
|
|
|
+ UserModel user = Utils.getCurrentUser();
|
|
|
+ variables.put(WorkflowMangerServiceImpl.KEY_SENDER_ID, user.getId().toString());
|
|
|
+ variables.put(WorkflowMangerServiceImpl.KEY_SENDER_NAME, user.getRealName());
|
|
|
+ }
|
|
|
+ // 启动流程
|
|
|
+ processInstance = runtimeService.startProcessInstanceByKey(processDefinitionKey, businessKey, variables);
|
|
|
+ // 查询当前任务
|
|
|
+ List<Task> taskList = getProcessActiveTasks(processInstance.getId());
|
|
|
+ if (null != taskList) {
|
|
|
+ for (Task t : taskList) {
|
|
|
+ // 设置任务名称(任务描述)
|
|
|
+ t.setDescription(param.getString(WorkFlowParam.DESCRIPTION));
|
|
|
+ taskService.saveTask(t);
|
|
|
+ // 保存工作流记录
|
|
|
+ taskModelService.add(getTaskInfoFromTask(t));
|
|
|
+ // 更新权力阳光办件过程信息 TODO
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return processInstance.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<Task> getProcessActiveTasks(String processInstanceId) {
|
|
|
+ return taskService.createTaskQuery().processInstanceId(processInstanceId).active().orderByTaskCreateTime().asc()
|
|
|
+ .list();
|
|
|
+ }
|
|
|
+
|
|
|
+ public Map<String, Object> getProcessInstanceVariables(String busId, String processDefinitionKey) {
|
|
|
+ Map<String, Object> variables = new HashMap<String, Object>();
|
|
|
+ String businessKey = processDefinitionKey + BUSKEYSEP + busId;
|
|
|
+ HistoricProcessInstance pi = historyService.createHistoricProcessInstanceQuery()
|
|
|
+ .processDefinitionKey(processDefinitionKey).processInstanceBusinessKey(businessKey).singleResult();
|
|
|
+ if (pi != null) {
|
|
|
+ List<HistoricVariableInstance> hisVariables = historyService.createHistoricVariableInstanceQuery()
|
|
|
+ .processInstanceId(pi.getId()).list();
|
|
|
+ if (hisVariables != null && hisVariables.size() > 0) {
|
|
|
+ for (HistoricVariableInstance ins : hisVariables) {
|
|
|
+ variables.put(ins.getVariableName(), ins.getValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return variables;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object getProcessInstanceVariables(String busId, String processDefinitionKey, String variableName) {
|
|
|
+ String businessKey = processDefinitionKey + BUSKEYSEP + busId;
|
|
|
+ HistoricProcessInstance pi = historyService.createHistoricProcessInstanceQuery()
|
|
|
+ .processDefinitionKey(processDefinitionKey).processInstanceBusinessKey(businessKey).singleResult();
|
|
|
+ if (pi != null) {
|
|
|
+ HistoricVariableInstance ins = historyService.createHistoricVariableInstanceQuery()
|
|
|
+ .processInstanceId(pi.getId()).variableName(variableName).singleResult();
|
|
|
+ if (ins != null) return ins.getValue();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取真实业务KEY<br>
|
|
|
+ * 流程中的业务key有流程前缀
|
|
|
+ *
|
|
|
+ * @param processInstance
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String getRealBusinessKey(ProcessInstance processInstance) {
|
|
|
+ String prefix = repositoryService.createProcessDefinitionQuery()
|
|
|
+ .processDefinitionId(processInstance.getProcessDefinitionId()).singleResult().getKey() + BUSKEYSEP;
|
|
|
+ String businessKey = processInstance.getBusinessKey();
|
|
|
+ if (StringUtils.isEmpty(businessKey) || !businessKey.startsWith(prefix)) { return null; }
|
|
|
+ return businessKey.substring(prefix.length());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取真实业务KEY<br>
|
|
|
+ * 流程中的业务key有流程前缀
|
|
|
+ *
|
|
|
+ * @param processInstance
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String getRealBusinessKey(HistoricProcessInstance processInstance) {
|
|
|
+ String prefix = repositoryService.createProcessDefinitionQuery()
|
|
|
+ .processDefinitionId(processInstance.getProcessDefinitionId()).singleResult().getKey() + BUSKEYSEP;
|
|
|
+ String businessKey = processInstance.getBusinessKey();
|
|
|
+ if (StringUtils.isEmpty(businessKey) || !businessKey.startsWith(prefix)) { return null; }
|
|
|
+ return businessKey.substring(prefix.length());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据工作流任务保存工作流记录
|
|
|
+ *
|
|
|
+ * @param task
|
|
|
+ */
|
|
|
+ private TaskModel getTaskInfoFromTask(Task task) {
|
|
|
+ // 判断task是否已有工作流记录
|
|
|
+ if (null == task) return null;
|
|
|
+ TaskModel taskInfo = taskModelService.findById(task.getId());
|
|
|
+ if (null == taskInfo) {
|
|
|
+ // 工作流记录
|
|
|
+ taskInfo = new TaskModel();
|
|
|
+ }
|
|
|
+ taskInfo.setTaskKey(task.getTaskDefinitionKey());
|
|
|
+ // 设置任务ID
|
|
|
+ taskInfo.setTaskId(task.getId());
|
|
|
+ // 设置business Id
|
|
|
+ ProcessInstance processInstance = runtimeService.createProcessInstanceQuery()
|
|
|
+ .processInstanceId(task.getProcessInstanceId()).singleResult();
|
|
|
+ taskInfo.setBusKey(repositoryService.createProcessDefinitionQuery()
|
|
|
+ .processDefinitionId(processInstance.getProcessDefinitionId()).singleResult().getKey());
|
|
|
+ taskInfo.setBusId(getRealBusinessKey(processInstance));
|
|
|
+ // 步骤
|
|
|
+ taskInfo.setStep(String.valueOf(getNextStep(task.getId())));
|
|
|
+ // 工作流状态
|
|
|
+ taskInfo.setState(String.valueOf(BaseUUIDModel.STATE_COMPLETED));
|
|
|
+ // 当前任务名称
|
|
|
+ taskInfo.setCurrName(task.getName());
|
|
|
+ // 创建时间
|
|
|
+ taskInfo.setStartTime(task.getCreateTime());
|
|
|
+ // 创建人
|
|
|
+ UserModel createUser = userService.findById(historyService.createHistoricProcessInstanceQuery()
|
|
|
+ .processInstanceId(processInstance.getId()).singleResult().getStartUserId());
|
|
|
+ taskInfo.setStartUser(historyService.createHistoricProcessInstanceQuery()
|
|
|
+ .processInstanceId(processInstance.getId()).singleResult().getStartUserId());
|
|
|
+ // 设置执行人
|
|
|
+ String runner = task.getAssignee();
|
|
|
+ if (!StringUtils.isEmpty(runner)) {
|
|
|
+ taskInfo.setRunner(runner);
|
|
|
+ taskInfo.setRunTime((Date) taskService.getVariableLocal(task.getId(), TaskVarListener.KEY_CLAIM_DATE));
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ // 执行者为空时设置任务执行角色
|
|
|
+ List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(task.getId());
|
|
|
+ if (null != identityLinks && identityLinks.size() > 0) {
|
|
|
+ IdentityLink identityLink = identityLinks.get(0);
|
|
|
+ taskInfo.setRoleCode(identityLink.getGroupId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return taskInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新工作流记录的审核信息
|
|
|
+ *
|
|
|
+ * @param taskId
|
|
|
+ * @param param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private TaskModel updateTaskAudit(String taskId, WorkFlowParam param) {
|
|
|
+ TaskModel taskInfo = taskModelService.findById(taskId);
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat(DATA_TIME_FMART);
|
|
|
+ // 审核模式设置审核时间、意见、结果
|
|
|
+ if (!"false".equals(param.get(WorkFlowParam.IS_AUDIT))) {
|
|
|
+ try {
|
|
|
+ // 设置审核时间
|
|
|
+ taskInfo.setAuditTime(sdf.parse(param.getString(WorkFlowParam.AUDIT_DATE)));
|
|
|
+ }
|
|
|
+ catch (ParseException e) {
|
|
|
+ taskInfo.setAuditTime((Date) param.get(WorkFlowParam.AUDIT_DATE));
|
|
|
+ }
|
|
|
+ // 设置审批意见
|
|
|
+ taskInfo.setAuditMsg(param.getString(WorkFlowParam.AUDIT_TEXT));
|
|
|
+ // 设置审批结果
|
|
|
+ taskInfo.setAuditResult(param.getString(WorkFlowParam.AUDIT_RESULT));
|
|
|
+ String auditUser = param.getString(WorkFlowParam.AUDIT_USER);
|
|
|
+ if (StringUtils.isEmpty(auditUser) && Utils.getCurrentUser() != null) {
|
|
|
+ auditUser = Utils.getCurrentUser().getId().toString();
|
|
|
+ }
|
|
|
+ // 设置审批结果
|
|
|
+ taskInfo.setAuditUser(auditUser);
|
|
|
+ if (StringUtils.hasLength(auditUser)) {
|
|
|
+ UserModel user = userService.findById(auditUser);
|
|
|
+ taskInfo.setAuditUsername(user.getRealName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ // 非审核时当前提交时间做为任务执行时间
|
|
|
+ String auditUser = param.getString(WorkFlowParam.AUDIT_USER);
|
|
|
+ if (StringUtils.isEmpty(auditUser) && Utils.getCurrentUser() != null) {
|
|
|
+ auditUser = Utils.getCurrentUser().getId().toString();
|
|
|
+ }
|
|
|
+ // 设置审批结果
|
|
|
+ taskInfo.setAuditUser(auditUser);
|
|
|
+ if (StringUtils.hasLength(auditUser)) {
|
|
|
+ UserModel user = userService.findById(auditUser);
|
|
|
+ taskInfo.setAuditUsername(user.getRealName());
|
|
|
+ }
|
|
|
+ taskInfo.setAuditTime(new Date());
|
|
|
+ }
|
|
|
+ taskModelService.update(taskInfo);
|
|
|
+ return taskInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取任务的下一步步骤数
|
|
|
+ *
|
|
|
+ * @param taskId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private int getNextStep(String taskId) {
|
|
|
+ int currBz = 1;
|
|
|
+ Object obj = taskService.getVariable(taskId, KEY_TASK_STEP);
|
|
|
+ if (null != obj) {
|
|
|
+ if (obj instanceof Integer) {
|
|
|
+ currBz = (Integer) obj;
|
|
|
+ currBz++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ taskService.setVariable(taskId, KEY_TASK_STEP, currBz);
|
|
|
+ return currBz;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Task getTaskByTaskId(String taskId) {
|
|
|
+ return taskService.createTaskQuery().taskId(taskId).singleResult();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据用户及业务key查询当前任务
|
|
|
+ *
|
|
|
+ * @param user
|
|
|
+ * @param businessKey
|
|
|
+ * @param processDefinitionKey
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Task getTaskByUserAndBusKey(String user, String businessKey, String processDefinitionKey) {
|
|
|
+ Task task = taskService.createTaskQuery().processDefinitionKey(processDefinitionKey).taskAssignee(user).active()
|
|
|
+ .orderByTaskPriority().processInstanceBusinessKey(processDefinitionKey + BUSKEYSEP + businessKey).desc()
|
|
|
+ .orderByTaskCreateTime().desc().singleResult();
|
|
|
+ return task;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据用户及业务key查询当前候选任务
|
|
|
+ *
|
|
|
+ * @param user
|
|
|
+ * @param businessKey
|
|
|
+ * @param processDefinitionKey
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Task getCandidateTaskByUserAndBusKey(String user, String businessKey, String processDefinitionKey) {
|
|
|
+ Task task = taskService.createTaskQuery().processDefinitionKey(processDefinitionKey).taskCandidateUser(user)
|
|
|
+ .active().orderByTaskPriority()
|
|
|
+ .processInstanceBusinessKey(processDefinitionKey + BUSKEYSEP + businessKey).desc()
|
|
|
+ .orderByTaskCreateTime().desc().singleResult();
|
|
|
+ return task;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 签收处理<br>
|
|
|
+ * {@inheritDoc}
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void claim(String taskId, String userId) {
|
|
|
+ if (!StringUtils.hasLength(userId)) { throw new ActivitiException("user.is.null"); }
|
|
|
+ Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
|
|
|
+ if (StringUtils.hasLength(task.getAssignee())) { throw new ActivitiException("task.already.claimed"); }
|
|
|
+ Date jssj = new Date();
|
|
|
+ taskService.setVariableLocal(taskId, TaskVarListener.KEY_CLAIM_DATE, jssj);
|
|
|
+ taskService.claim(taskId, userId);
|
|
|
+ // 工作流记录设置
|
|
|
+ TaskModel taskInfo = taskModelService.findByTaskId(taskId);
|
|
|
+ if (null == taskInfo) return;
|
|
|
+ taskInfo.setRunner(userId);
|
|
|
+ taskInfo.setRunTime(jssj);
|
|
|
+ taskModelService.save(taskInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ public int todoListCount(String userid, String busKey, Date begin, Date end) {
|
|
|
+ // 时间格式化
|
|
|
+ StringBuilder sqlBuffer = new StringBuilder();
|
|
|
+ ManagementService ms = processEngine.getManagementService();
|
|
|
+ sqlBuffer.append(ms.getTableName(Task.class));
|
|
|
+ sqlBuffer.append(" T WHERE T .SUSPENSION_STATE_ = 1 ");
|
|
|
+ String workFlowCode = "";
|
|
|
+ if (!StringUtils.isEmpty(busKey)) {
|
|
|
+ if (!StringUtils.isEmpty(busKey)) {
|
|
|
+ if (StringUtils.isEmpty(workFlowCode) || workFlowCode.indexOf("'" + busKey + "'") >= 0)
|
|
|
+ workFlowCode = "'" + busKey + "'";
|
|
|
+ else workFlowCode = "NULL";
|
|
|
+ }
|
|
|
+ sqlBuffer.append(" AND EXISTS(SELECT 1 FROM ");
|
|
|
+ sqlBuffer.append(ms.getTableName(ProcessDefinition.class));
|
|
|
+ sqlBuffer.append(" P WHERE P.ID_=T.PROC_DEF_ID_ AND P.KEY_ IN (");
|
|
|
+ sqlBuffer.append(workFlowCode);
|
|
|
+ sqlBuffer.append(")) ");
|
|
|
+ }
|
|
|
+ if (begin != null) sqlBuffer.append(" AND T.CREATE_TIME_ >= #{begin} ");
|
|
|
+ if (end != null) sqlBuffer.append(" AND T.CREATE_TIME_ < #{end} ");
|
|
|
+ sqlBuffer.append(" AND (T.ASSIGNEE_ = #{userId} ");
|
|
|
+ sqlBuffer.append("OR (T.ASSIGNEE_ IS NULL AND EXISTS (SELECT 1 FROM ACT_RU_IDENTITYLINK ");
|
|
|
+ sqlBuffer.append(" I WHERE I.TYPE_ = 'candidate' AND I.TASK_ID_ = T .ID_ ");
|
|
|
+ sqlBuffer.append("AND (I.USER_ID_ = #{userId} OR I.GROUP_ID_ IN ");
|
|
|
+ sqlBuffer.append("(SELECT r.ROLE_TYPE FROM T_YJPT_ROLE_USER ru,T_YJPT_ROLE r ");
|
|
|
+ sqlBuffer.append("WHERE r.ID=ru.ROLEID AND ru.USERID =#{userId} ))");
|
|
|
+ sqlBuffer.append(
|
|
|
+ " AND (NOT EXISTS (SELECT 1 FROM ACT_RU_VARIABLE V WHERE V.PROC_INST_ID_=T.PROC_INST_ID_ AND NAME_=#{var} ) ");
|
|
|
+ sqlBuffer.append(
|
|
|
+ " OR EXISTS (SELECT 1 FROM ACT_RU_VARIABLE V WHERE V.PROC_INST_ID_=T.PROC_INST_ID_ AND NAME_=#{var} )) ");
|
|
|
+ sqlBuffer.append(")))");
|
|
|
+ TaskService taskService = processEngine.getTaskService();
|
|
|
+ NativeTaskQuery query = taskService.createNativeTaskQuery()
|
|
|
+ .sql("SELECT COUNT(DISTINCT T.id_) FROM " + sqlBuffer.toString() + "ORDER BY T .CREATE_TIME_ DESC")
|
|
|
+ .parameter("userId", Utils.getCurrentUser().getId()).parameter("var", KEY_SZD_ID);
|
|
|
+ if (begin != null) query.parameter("begin", Utils.getDateFirstTime(begin));
|
|
|
+ if (end != null) query.parameter("end", Utils.getDateLastTime(end));
|
|
|
+ long count = query.count();
|
|
|
+ return (int) count;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 待办任务一览查询 {@inheritDoc}
|
|
|
+ */
|
|
|
+ // @Override
|
|
|
+ public JsonResult todoList(SinglePageRequest pageRequest, String userid, String busKey, Date begin, Date end) {
|
|
|
+ // 结果集
|
|
|
+ List<WorkItem> result = new ArrayList<WorkItem>();
|
|
|
+ // 时间格式化
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat(DATA_TIME_FMART);
|
|
|
+ StringBuilder sqlBuffer = new StringBuilder();
|
|
|
+ ManagementService ms = processEngine.getManagementService();
|
|
|
+ sqlBuffer.append(ms.getTableName(Task.class));
|
|
|
+ sqlBuffer.append(" T WHERE T .SUSPENSION_STATE_ = 1 ");
|
|
|
+ String workFlowCode = "";
|
|
|
+ if (!StringUtils.isEmpty(busKey)) {
|
|
|
+ if (!StringUtils.isEmpty(busKey)) {
|
|
|
+ if (StringUtils.isEmpty(workFlowCode) || workFlowCode.indexOf("'" + busKey + "'") >= 0)
|
|
|
+ workFlowCode = "'" + busKey + "'";
|
|
|
+ else workFlowCode = "NULL";
|
|
|
+ }
|
|
|
+ sqlBuffer.append(" AND EXISTS(SELECT 1 FROM ");
|
|
|
+ sqlBuffer.append(ms.getTableName(ProcessDefinition.class));
|
|
|
+ sqlBuffer.append(" P WHERE P.ID_=T.PROC_DEF_ID_ AND P.KEY_ IN (");
|
|
|
+ sqlBuffer.append(workFlowCode);
|
|
|
+ sqlBuffer.append(")) ");
|
|
|
+ }
|
|
|
+ if (begin != null) sqlBuffer.append(" AND T.CREATE_TIME_ >= #{begin} ");
|
|
|
+ if (end != null) sqlBuffer.append(" AND T.CREATE_TIME_ <= #{end} ");
|
|
|
+ sqlBuffer.append(" AND (T.ASSIGNEE_ = #{userId} ");
|
|
|
+ sqlBuffer.append("OR (T.ASSIGNEE_ IS NULL AND EXISTS (SELECT 1 FROM ACT_RU_IDENTITYLINK ");
|
|
|
+ sqlBuffer.append(" I WHERE I.TYPE_ = 'candidate' AND I.TASK_ID_ = T .ID_ ");
|
|
|
+ sqlBuffer.append("AND (I.USER_ID_ = #{userId} OR I.GROUP_ID_ IN ");
|
|
|
+ sqlBuffer.append("(SELECT r.ROLE_TYPE FROM T_YJPT_ROLE_USER ru,T_YJPT_ROLE r ");
|
|
|
+ sqlBuffer.append("WHERE r.ID=ru.ROLEID AND ru.USERID =#{userId} ))");
|
|
|
+ sqlBuffer.append(
|
|
|
+ " AND (NOT EXISTS (SELECT 1 FROM ACT_RU_VARIABLE V WHERE V.PROC_INST_ID_=T.PROC_INST_ID_ AND NAME_=#{var} ) ");
|
|
|
+ sqlBuffer.append(
|
|
|
+ " OR EXISTS (SELECT 1 FROM ACT_RU_VARIABLE V WHERE V.PROC_INST_ID_=T.PROC_INST_ID_ AND NAME_=#{var} )) ");
|
|
|
+ sqlBuffer.append(")))");
|
|
|
+ TaskService taskService = processEngine.getTaskService();
|
|
|
+ int start = pageRequest.getPage() * pageRequest.getSize();
|
|
|
+ NativeTaskQuery query = taskService.createNativeTaskQuery()
|
|
|
+ .sql("SELECT DISTINCT T.* FROM " + sqlBuffer.toString() + "ORDER BY T .CREATE_TIME_ DESC")
|
|
|
+ .parameter("userId", Utils.getCurrentUser().getId()).parameter("var", KEY_SZD_ID);
|
|
|
+ if (begin != null) query.parameter("begin", Utils.getDateFirstTime(begin));
|
|
|
+ if (end != null) query.parameter("end", Utils.getDateLastTime(end));
|
|
|
+ List<Task> todoList = query.listPage(start, pageRequest.getSize());
|
|
|
+ query = taskService.createNativeTaskQuery().sql("SELECT count(DISTINCT T.id_) FROM " + sqlBuffer.toString())
|
|
|
+ .parameter("userId", Utils.getCurrentUser().getId()).parameter("var", KEY_SZD_ID);
|
|
|
+ if (begin != null) query.parameter("begin", Utils.getDateFirstTime(begin));
|
|
|
+ if (end != null) query.parameter("end", Utils.getDateLastTime(end));
|
|
|
+ long count = query.count();
|
|
|
+ for (Task task : todoList) {
|
|
|
+ String processDefinitionId = task.getProcessDefinitionId();
|
|
|
+ ProcessDefinition processDefinition = getProcessDefinition(processDefinitionId);
|
|
|
+ ProcessInstance processInstance = runtimeService.createProcessInstanceQuery()
|
|
|
+ .processInstanceId(task.getProcessInstanceId()).active().singleResult();
|
|
|
+ WorkItem singleTask = packageTaskInfo(sdf, task, processDefinition, processInstance);
|
|
|
+ singleTask.setStatus(STATUS_TODO);
|
|
|
+ result.add(singleTask);
|
|
|
+ }
|
|
|
+ JsonResult bc = new JsonResult();
|
|
|
+ bc.setAttr("todo", result);
|
|
|
+ bc.setAttr("totalCount", count);
|
|
|
+ return bc;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 待办中显示数据处理
|
|
|
+ *
|
|
|
+ * @param sdf
|
|
|
+ * SimpleDateFormat
|
|
|
+ * @param task
|
|
|
+ * Task
|
|
|
+ * @param processDefinition
|
|
|
+ * ProcessDefinition
|
|
|
+ * @return TaskForm
|
|
|
+ */
|
|
|
+ private WorkItem packageTaskInfo(SimpleDateFormat sdf, Task task, ProcessDefinition processDefinition,
|
|
|
+ ProcessInstance processInstance) {
|
|
|
+ WorkItem form = new WorkItem();
|
|
|
+ // 任务ID
|
|
|
+ form.setId(task.getId());
|
|
|
+ // 任务编码
|
|
|
+ form.setDefinitionKey(task.getTaskDefinitionKey());
|
|
|
+ form.setDefinitionName(task.getName());
|
|
|
+ // 任务创建时间
|
|
|
+ form.setCreateTime(sdf.format(task.getCreateTime()));
|
|
|
+ // 流程定义名称
|
|
|
+ form.setProcessKey(processDefinition.getKey());
|
|
|
+ form.setProcessName(processDefinition.getName());
|
|
|
+ form.setPid(task.getProcessInstanceId());
|
|
|
+ form.setBusinessKey(getRealBusinessKey(processInstance));
|
|
|
+ // 接收时间
|
|
|
+ Date jssj = (Date) taskService.getVariableLocal(task.getId(), TaskVarListener.KEY_CLAIM_DATE);
|
|
|
+ if (null != jssj) form.setJssj(sdf.format(jssj));
|
|
|
+ // 设置任务描述
|
|
|
+ form.setDescription(task.getDescription());
|
|
|
+ String applyUserId = String.valueOf(taskService.getVariable(task.getId(), "applyUserId"));
|
|
|
+ form.setApplyUserName(applyUserId);
|
|
|
+ String senderID = taskService.getVariable(task.getId(), KEY_SENDER_ID) != null
|
|
|
+ ? String.valueOf(taskService.getVariable(task.getId(), KEY_SENDER_ID)) : "";
|
|
|
+ String senderName = taskService.getVariable(task.getId(), KEY_SENDER_NAME) != null
|
|
|
+ ? String.valueOf(taskService.getVariable(task.getId(), KEY_SENDER_NAME)) : "";
|
|
|
+ String sendDept = taskService.getVariable(task.getId(), KEY_SEND_DEPT) != null
|
|
|
+ ? String.valueOf(taskService.getVariable(task.getId(), KEY_SEND_DEPT)) : "";
|
|
|
+ form.setSenderID(senderID);
|
|
|
+ form.setSenderName(senderName);
|
|
|
+ form.setSendDept(sendDept);
|
|
|
+ return form;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 已办中显示数据处理
|
|
|
+ *
|
|
|
+ * @param sdf
|
|
|
+ * SimpleDateFormat
|
|
|
+ * @param task
|
|
|
+ * Task
|
|
|
+ * @param processDefinition
|
|
|
+ * ProcessDefinition
|
|
|
+ * @return TaskForm
|
|
|
+ */
|
|
|
+ private WorkItem packageTaskInfo(SimpleDateFormat sdf, HistoricTaskInstance task,
|
|
|
+ ProcessDefinition processDefinition, HistoricProcessInstance processInstance, TaskModel taskinfo) {
|
|
|
+ WorkItem form = new WorkItem();
|
|
|
+ // 任务ID
|
|
|
+ form.setId(task.getId());
|
|
|
+ // 任务编码
|
|
|
+ form.setDefinitionKey(task.getTaskDefinitionKey());
|
|
|
+ form.setDefinitionName(task.getName());
|
|
|
+ // 任务创建时间
|
|
|
+ form.setCreateTime(sdf.format(task.getStartTime()));
|
|
|
+ // 流程定义名称
|
|
|
+ form.setProcessKey(processDefinition.getKey());
|
|
|
+ form.setProcessName(processDefinition.getName());
|
|
|
+ form.setPid(task.getProcessInstanceId());
|
|
|
+ form.setBusinessKey(getRealBusinessKey(processInstance));
|
|
|
+ // 接收时间
|
|
|
+ Date jssj = task.getClaimTime();
|
|
|
+ if (null != jssj) form.setJssj(sdf.format(jssj));
|
|
|
+ // 设置任务描述
|
|
|
+ form.setDescription(task.getDescription());
|
|
|
+ String applyUserId = taskinfo.getStartUser();
|
|
|
+ form.setApplyUserName(applyUserId);
|
|
|
+ UserModel senderUser = userService.findById(taskinfo.getStartUser());
|
|
|
+ String senderID = senderUser.getId().toString();
|
|
|
+ String senderName = senderUser.getRealName();
|
|
|
+ String sendDept = "";
|
|
|
+ form.setSenderID(senderID == null ? "" : senderID);
|
|
|
+ form.setSenderName(senderName == null ? "" : senderName);
|
|
|
+ form.setSendDept(sendDept == null ? "" : sendDept);
|
|
|
+ return form;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据流程定义KEY查询流程定义
|
|
|
+ *
|
|
|
+ * @param processDefinitionId
|
|
|
+ * 流程定义KEY
|
|
|
+ * @return ProcessDefinition
|
|
|
+ */
|
|
|
+ private ProcessDefinition getProcessDefinition(String processDefinitionId) {
|
|
|
+ ProcessDefinition processDefinition = PROCESS_DEFINITION_CACHE.get(processDefinitionId);
|
|
|
+ if (processDefinition == null) {
|
|
|
+ // 缓存中不存在时执行查询
|
|
|
+ processDefinition = repositoryService.createProcessDefinitionQuery()
|
|
|
+ .processDefinitionId(processDefinitionId).singleResult();
|
|
|
+ PROCESS_DEFINITION_CACHE.put(processDefinitionId, processDefinition);
|
|
|
+ }
|
|
|
+ return processDefinition;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public JsonResult todoList(com.xt.js.gkaq.frame.wf.SinglePageRequest pageRequest, String userid, String busKey,
|
|
|
+ Date begin, Date end) {
|
|
|
+ throw new IllegalArgumentException("method not supported!");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<TaskModel> doneList(String busKey, Long userid) {
|
|
|
+ throw new IllegalArgumentException("method not supported!");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<TaskModel> doneList(Long runnerId) {
|
|
|
+ throw new IllegalArgumentException("method not supported!");
|
|
|
+ }
|
|
|
+}
|