|
@@ -5,6 +5,8 @@ package com.jeeplus.flowable.service;
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.extra.spring.SpringUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.TypeReference;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.google.common.collect.Maps;
|
|
@@ -14,6 +16,7 @@ import com.jeeplus.flowable.common.cmd.BackUserTaskCmd;
|
|
|
import com.jeeplus.flowable.constant.FlowableConstant;
|
|
|
import com.jeeplus.flowable.mapper.FlowMapper;
|
|
|
import com.jeeplus.flowable.model.ActRuTaskInfo;
|
|
|
+import com.jeeplus.flowable.model.CwWorkClientBaseDtoTest;
|
|
|
import com.jeeplus.flowable.model.Flow;
|
|
|
import com.jeeplus.flowable.model.TaskComment;
|
|
|
import com.jeeplus.flowable.service.converter.json.FlowModelService;
|
|
@@ -24,6 +27,7 @@ import com.jeeplus.sys.feign.ITenantApi;
|
|
|
import com.jeeplus.sys.feign.IUserApi;
|
|
|
import com.jeeplus.sys.service.dto.UserDTO;
|
|
|
import com.jeeplus.sys.utils.UserUtils;
|
|
|
+import liquibase.pro.packaged.S;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.flowable.bpmn.constants.BpmnXMLConstants;
|
|
@@ -53,9 +57,13 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.sql.ResultSet;
|
|
|
import java.sql.SQLException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import java.lang.reflect.Field;
|
|
|
+import java.lang.reflect.Method;
|
|
|
+
|
|
|
/**
|
|
|
* 流程定义相关Service
|
|
|
*
|
|
@@ -94,15 +102,243 @@ public class FlowTaskService {
|
|
|
@Autowired
|
|
|
private ITenantApi tenantApi;
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取流转历史任务列表
|
|
|
+ *
|
|
|
+ * @param procInsId 流程实例
|
|
|
+ */
|
|
|
+ public Map historicTaskList2(String procInsId) throws Exception {
|
|
|
+ List<Flow> actList = Lists.newArrayList ();
|
|
|
+ List<HistoricActivityInstance> list = Lists.newArrayList ();
|
|
|
+ List<HistoricActivityInstance> historicActivityInstances2 = historyService.createHistoricActivityInstanceQuery ().processInstanceId (procInsId)
|
|
|
+ .orderByHistoricActivityInstanceStartTime ().asc ().orderByHistoricActivityInstanceEndTime ().asc ().list ();
|
|
|
+ for (HistoricActivityInstance historicActivityInstance : historicActivityInstances2) {
|
|
|
+ if (historicActivityInstance.getEndTime () != null) {
|
|
|
+ list.add (historicActivityInstance);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (HistoricActivityInstance historicActivityInstance : historicActivityInstances2) {
|
|
|
+ if (historicActivityInstance.getEndTime () == null) {
|
|
|
+ list.add (historicActivityInstance);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i = 0; i < list.size (); i++) {
|
|
|
+ HistoricActivityInstance histIns = list.get (i);
|
|
|
+ // 只显示开始节点和结束节点,并且执行人不为空的任务
|
|
|
+ if (StrUtil.isNotBlank (histIns.getAssignee ())
|
|
|
+ && historyService.createHistoricTaskInstanceQuery ().taskId (histIns.getTaskId ()).count () != 0
|
|
|
+ || BpmnXMLConstants.ELEMENT_TASK_USER.equals (histIns.getActivityType ()) && histIns.getEndTime () == null
|
|
|
+ || BpmnXMLConstants.ELEMENT_EVENT_START.equals (histIns.getActivityType ())
|
|
|
+ || BpmnXMLConstants.ELEMENT_EVENT_END.equals (histIns.getActivityType ())) {
|
|
|
+ // 获取流程发起人名称
|
|
|
+ Flow e = queryTaskState (histIns);
|
|
|
+
|
|
|
+ actList.add (e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
|
|
|
+ Map data = new HashMap();
|
|
|
+ for (Flow flow : actList) {
|
|
|
+ HistoricActivityInstance histIns = flow.getHistIns();
|
|
|
+ if(StringUtils.isNotBlank(histIns.getActivityName())){
|
|
|
+
|
|
|
+ switch (histIns.getActivityName()){
|
|
|
+ case "开始":
|
|
|
+ if(StringUtils.isNotBlank(flow.getAssigneeName())){
|
|
|
+ data.put("firstAuditName",flow.getAssigneeName());
|
|
|
+ data.put("giveName",flow.getAssigneeName());
|
|
|
+ }else{
|
|
|
+ data.put("firstAuditName","");
|
|
|
+ }
|
|
|
+ if(null != histIns.getEndTime()){
|
|
|
+ data.put("firstAuditDate",sdf.format(histIns.getEndTime()));
|
|
|
+ }else{
|
|
|
+ data.put("firstAuditDate"," 年 月 日");
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case "二级复核":
|
|
|
+ if(null != flow.getComment() && "success".equals(flow.getComment().getLevel())){
|
|
|
+ if(StringUtils.isNotBlank(flow.getAssigneeName())){
|
|
|
+ data.put("secondAuditName",flow.getAssigneeName());
|
|
|
+ }else{
|
|
|
+ data.put("secondAuditName","");
|
|
|
+ }
|
|
|
+ if(null != histIns.getEndTime()){
|
|
|
+ data.put("secondAuditDate",sdf.format(histIns.getEndTime()));
|
|
|
+ }else{
|
|
|
+ data.put("secondAuditDate"," 年 月 日");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case "三级复核":
|
|
|
+ if(null != flow.getComment() && "success".equals(flow.getComment().getLevel())){
|
|
|
+ if(StringUtils.isNotBlank(flow.getAssigneeName())){
|
|
|
+ UserDTO userDTO = UserUtils.getByName("潘中");
|
|
|
+ if(null != userDTO && StringUtils.isNotBlank(userDTO.getName())){
|
|
|
+ data.put("thirdlyAuditName",userDTO.getName());
|
|
|
+ }else{
|
|
|
+ data.put("thirdlyAuditName","");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ data.put("thirdlyAuditName","");
|
|
|
+ }
|
|
|
+ if(null != histIns.getEndTime()){
|
|
|
+ data.put("thirdlyAuditDate",sdf.format(histIns.getEndTime()));
|
|
|
+ }else{
|
|
|
+ data.put("thirdlyAuditDate"," 年 月 日");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取流转历史任务列表
|
|
|
+ *
|
|
|
+ * @param procInsId 流程实例
|
|
|
+ */
|
|
|
+ public Map historicTaskList3(String procInsId) throws Exception {
|
|
|
+ List<Flow> actList = Lists.newArrayList ();
|
|
|
+ List<HistoricActivityInstance> list = Lists.newArrayList ();
|
|
|
+ List<HistoricActivityInstance> historicActivityInstances2 = historyService.createHistoricActivityInstanceQuery ().processInstanceId (procInsId)
|
|
|
+ .orderByHistoricActivityInstanceStartTime ().asc ().orderByHistoricActivityInstanceEndTime ().asc ().list ();
|
|
|
+ for (HistoricActivityInstance historicActivityInstance : historicActivityInstances2) {
|
|
|
+ if (historicActivityInstance.getEndTime () != null) {
|
|
|
+ list.add (historicActivityInstance);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (HistoricActivityInstance historicActivityInstance : historicActivityInstances2) {
|
|
|
+ if (historicActivityInstance.getEndTime () == null) {
|
|
|
+ list.add (historicActivityInstance);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i = 0; i < list.size (); i++) {
|
|
|
+ HistoricActivityInstance histIns = list.get (i);
|
|
|
+ // 只显示开始节点和结束节点,并且执行人不为空的任务
|
|
|
+ if (StrUtil.isNotBlank (histIns.getAssignee ())
|
|
|
+ && historyService.createHistoricTaskInstanceQuery ().taskId (histIns.getTaskId ()).count () != 0
|
|
|
+ || BpmnXMLConstants.ELEMENT_TASK_USER.equals (histIns.getActivityType ()) && histIns.getEndTime () == null
|
|
|
+ || BpmnXMLConstants.ELEMENT_EVENT_START.equals (histIns.getActivityType ())
|
|
|
+ || BpmnXMLConstants.ELEMENT_EVENT_END.equals (histIns.getActivityType ())) {
|
|
|
+ // 获取流程发起人名称
|
|
|
+ Flow e = queryTaskState (histIns);
|
|
|
+
|
|
|
+ actList.add (e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Map data = new HashMap();
|
|
|
+
|
|
|
+ for (Flow flow : actList) {
|
|
|
+ HistoricActivityInstance histIns = flow.getHistIns();
|
|
|
+ if(StringUtils.isNotBlank(histIns.getActivityName())){
|
|
|
+
|
|
|
+ switch (histIns.getActivityName()){
|
|
|
+ case "归档员审核":
|
|
|
+ if(null != flow.getComment() && "success".equals(flow.getComment().getLevel())){
|
|
|
+ if(StringUtils.isNotBlank(flow.getAssigneeName())){
|
|
|
+ data.put("archiveName",flow.getAssigneeName());
|
|
|
+ }else{
|
|
|
+ data.put("archiveName","");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String taskDispose(String data) {
|
|
|
+ List<CwWorkClientBaseDtoTest> list = JSON.parseObject(data, new TypeReference<List<CwWorkClientBaseDtoTest>>() {});
|
|
|
|
|
|
- public List <Task> getRecords() {
|
|
|
String userId = UserUtils.getCurrentUserDTO ().getId ();
|
|
|
// =============== 已经签收或者等待签收的任务 ===============
|
|
|
TaskQuery todoTaskQuery = taskService.createTaskQuery ().taskCandidateOrAssigned (userId).active ()
|
|
|
.includeProcessVariables ().orderByTaskCreateTime ().desc ();
|
|
|
|
|
|
List <Task> todoList = todoTaskQuery.list ( );
|
|
|
- return todoList;
|
|
|
+
|
|
|
+ Method procInsIdMethod = null;
|
|
|
+ Method processDefinitionIdMethod = null;
|
|
|
+ Method statusMethod = null;
|
|
|
+ for (CwWorkClientBaseDtoTest info : list ) {
|
|
|
+ Class<? extends Object> tClass = info.getClass();
|
|
|
+ //得到所有属性
|
|
|
+ Field[] fields = tClass.getDeclaredFields();
|
|
|
+ Class<? extends Object> superClass = tClass.getSuperclass();
|
|
|
+ //得到所有属性
|
|
|
+ Field[] superField = superClass.getDeclaredFields();
|
|
|
+ Field[] field = concat(fields,superField);
|
|
|
+
|
|
|
+ for (Task taskInfo : todoList) {
|
|
|
+ Integer taskIdInteger = null;
|
|
|
+ try {
|
|
|
+ for (Integer i=0; i<field.length; i++ ){
|
|
|
+ //获取属性的名字
|
|
|
+ String name = field[i].getName();
|
|
|
+ //将属性名字的首字母大写
|
|
|
+ name = name.replaceFirst(name.substring(0, 1), name.substring(0, 1).toUpperCase());
|
|
|
+
|
|
|
+ if("ProcInsId".equals(name)){
|
|
|
+ field[i].setAccessible(true);
|
|
|
+ //整合出 getId() 属性这个方法
|
|
|
+ procInsIdMethod = tClass.getMethod("get"+name);
|
|
|
+
|
|
|
+ }else if("ProcessDefinitionId".equals(name)){
|
|
|
+ field[i].setAccessible(true);
|
|
|
+ //整合出 getId() 属性这个方法
|
|
|
+ processDefinitionIdMethod = tClass.getMethod("get"+name);
|
|
|
+
|
|
|
+ }else if("Status".equals(name)){
|
|
|
+ field[i].setAccessible(true);
|
|
|
+ //整合出 getId() 属性这个方法
|
|
|
+ statusMethod = tClass.getMethod("get"+name);
|
|
|
+
|
|
|
+ }else if("TaskId".equals(name)){
|
|
|
+ field[i].setAccessible(true);
|
|
|
+ //整合出 getId() 属性这个方法
|
|
|
+ taskIdInteger = i;
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //调用这个整合出来的get方法,强转成自己需要的类型
|
|
|
+ String procInsId = (String)procInsIdMethod.invoke(info);
|
|
|
+ String processDefinitionId = (String)processDefinitionIdMethod.invoke(info);
|
|
|
+ String status = (String)statusMethod.invoke(info);
|
|
|
+
|
|
|
+ if(procInsId.equals(taskInfo.getProcessInstanceId()) && processDefinitionId.equals(taskInfo.getProcessDefinitionId()) && "4".equals(status)){
|
|
|
+ field[taskIdInteger].set(info,taskInfo.getId());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return JSON.toJSONString(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据整合方法
|
|
|
+ * @param a
|
|
|
+ * @param b
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ static Field[] concat(Field[] a, Field[] b) {
|
|
|
+
|
|
|
+ Field[] c= new Field[a.length+b.length];
|
|
|
+ System.arraycopy(a, 0, c, 0, a.length);
|
|
|
+ System.arraycopy(b, 0, c, a.length, b.length);
|
|
|
+ return c;
|
|
|
}
|
|
|
|
|
|
public String getTaskIdByprocInstId(String procInsId){
|