懒羊羊
2023-08-30 1ac2bc1590406d9babec036e154d8d08f34a6aa1
提交 | 用户 | 时间
1ac2bc 1 package cn.stylefeng.guns.workflow.modular.service.impl;
2
3 import cn.stylefeng.guns.base.auth.context.LoginContextHolder;
4 import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
5 import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
6 import cn.stylefeng.guns.workflow.core.util.TimeCalcUtil;
7 import cn.stylefeng.guns.workflow.modular.entity.RuTask;
8 import cn.stylefeng.guns.workflow.modular.mapper.TaskHistoryMapper;
9 import cn.stylefeng.guns.workflow.modular.mapper.TaskRunningMapper;
10 import cn.stylefeng.guns.workflow.modular.service.TaskHistoryService;
11 import cn.stylefeng.guns.workflow.modular.service.TaskWaitingService;
12 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
13 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
14 import org.activiti.bpmn.model.BpmnModel;
15 import org.activiti.bpmn.model.FlowNode;
16 import org.activiti.engine.HistoryService;
17 import org.activiti.engine.RepositoryService;
18 import org.activiti.engine.history.HistoricActivityInstance;
19 import org.activiti.engine.history.HistoricProcessInstance;
20 import org.springframework.beans.factory.annotation.Autowired;
21 import org.springframework.stereotype.Service;
22
23 import java.util.LinkedList;
24 import java.util.List;
25 import java.util.Map;
26
27 /**
28  * 历史任务
29  *
30  * @author fengshuonan
31  * @Date 2019-08-28 17:54
32  */
33 @Service
34 public class TaskHistoryServiceImpl extends ServiceImpl<TaskRunningMapper, RuTask> implements TaskHistoryService {
35
36     @Autowired
37     private TaskHistoryMapper ruprocdefMapper;
38
39     @Autowired
40     private HistoryService historyService;
41
42     @Autowired
43     private RepositoryService repositoryService;
44
45     @Autowired
46     private TaskWaitingService taskService;
47
48     @Override
49     public LayuiPageInfo historyTaskListPage(Map<String, Object> map) {
50
51         map.put("username", LoginContextHolder.getContext().getUser().getAccount());
52
53         String userRoleString = taskService.getUserRoleString();
54
55         map.put("rnumbers", userRoleString);
56
57         Page pageContext = LayuiPageFactory.defaultPage();
58         List<Map<String, Object>> list = this.baseMapper.hitasklist(pageContext, map);
59
60         for (int i = 0; i < list.size(); i++) {
61             Long ztime = Long.parseLong(list.get(i).get("duration_").toString());
62             list.get(i).put("ztime", TimeCalcUtil.calc(ztime));
63
64             //流程申请人
65             list.get(i).put("initator", getInitiator(String.valueOf(list.get(i).get("proc_inst_id_"))));
66         }
67
68         pageContext.setRecords(list);
69         return LayuiPageFactory.createPageInfo(pageContext);
70     }
71
72     @Override
73     public List<Map<String, Object>> historyTaskList(String procInstId) {
74         return ruprocdefMapper.historyTaskList(procInstId);
75     }
76
77     /**
78      * 获取发起人
79      *
80      * @author fengshuonan
81      * @Date 2019-8-23 17:37
82      */
83     private String getInitiator(String procInstId) {
84
85         //获取历史流程实例
86         HistoricProcessInstance hip = historyService.createHistoricProcessInstanceQuery().processInstanceId(procInstId).singleResult();
87         List<HistoricActivityInstance> hais = historyService.createHistoricActivityInstanceQuery().processInstanceId(procInstId)
88
89                 //获取流程中已经执行的节点,按照执行先后顺序排序
90                 .orderByHistoricActivityInstanceId().asc().list();
91
92         // 获取bpmnModel
93         BpmnModel bpmnModel = repositoryService.getBpmnModel(hip.getProcessDefinitionId());
94
95         //全部活动实例
96         List<FlowNode> historicFlowNodeList = new LinkedList<FlowNode>();
97         for (HistoricActivityInstance hai : hais) {
98             historicFlowNodeList.add((FlowNode) bpmnModel.getMainProcess().getFlowElement(hai.getActivityId(), true));
99             if (hai.getAssignee() != null) {
100
101                 //不为空的第一个节点办理人就是发起人
102                 return hai.getAssignee();
103             }
104         }
105
106         return null;
107     }
108 }