lyh
2025-06-27 f472efc9ad1f9bda645dd39b40607c5eabb73b47
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package org.jeecg.modules.flowable.controller;
 
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.Feature;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.flowable.bpmn.model.BpmnModel;
import org.flowable.engine.HistoryService;
import org.flowable.engine.ProcessEngine;
import org.flowable.engine.ProcessEngineConfiguration;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.history.HistoricActivityInstance;
import org.flowable.image.ProcessDiagramGenerator;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.TranslateDictTextUtils;
import org.jeecg.modules.flowable.apithird.business.dto.FlowMyBusinessDto;
import org.jeecg.modules.flowable.apithird.business.service.impl.FlowMyBusinessServiceImpl;
import org.jeecg.modules.flowable.domain.dto.FlowTaskDto;
import org.jeecg.modules.flowable.domain.vo.FlowHistoricalVo;
import org.jeecg.modules.flowable.domain.vo.FlowMy;
import org.jeecg.modules.flowable.domain.vo.WorkTaskDataVo;
import org.jeecg.modules.flowable.service.IFlowTaskService;
import org.jeecg.modules.flowable.service.IHisWorkTaskService;
import org.jeecg.modules.flowable.service.IWorkTaskServiceVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
 
@Api(tags = "工作流通用业务接口")
@RestController
@RequestMapping("assign/flow")
@Slf4j
public class AssignStreamFlowController {
    @Autowired
    FlowMyBusinessServiceImpl flowMyBusinessService;
    @Autowired
    IFlowTaskService flowTaskService;
    @Autowired
    IWorkTaskServiceVo workTaskServicevo;
    @Autowired
    IHisWorkTaskService hisWorkTaskService;
    @Autowired
    private RepositoryService repositoryService;
    @Autowired
    private HistoryService historyService;
    @Autowired
    private ProcessEngine processEngine;
    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    private TranslateDictTextUtils translateDictTextUtils;
 
    @ApiOperation(value = "获取总台账", response = FlowTaskDto.class)
    @GetMapping(value = "/list")
    public Result<IPage<FlowMyBusinessDto>> queryPageList(FlowMyBusinessDto flowMyBusinessDto,
                                                       @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                       @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                                       HttpServletRequest req) {
        Page page = new Page(pageNo, pageSize);
        IPage<FlowMyBusinessDto> pageList = flowMyBusinessService.getPageList(page, flowMyBusinessDto);
        return Result.OK(pageList);
    }
 
    @ApiOperation(value = "通过传入TaskIds判断是否在同一节点")
    @GetMapping(value = "/isSameNode")
    public Result isSameNode(@RequestParam(name = "taskIds") String taskIds) {
        return flowTaskService.isSameNode(taskIds);
    }
 
    @ApiOperation(value = "获取待办列表", response = FlowTaskDto.class)
    @GetMapping(value = "/todoList")
    public Result todoList(@ApiParam(value = "当前页码", required = true) @RequestParam (name="pageNum", defaultValue="1") Integer pageNum,
                           @ApiParam(value = "每页条数", required = true) @RequestParam (name="pageSize", defaultValue="10") Integer pageSize) {
        return flowTaskService.todoList(pageNum, pageSize);
    }
    @ApiOperation(value = "获取本身待办", response = FlowTaskDto.class)
    @GetMapping(value = "/toTaskBySelf")
    public Result<IPage<WorkTaskDataVo>> toTaskBySelf(FlowMy flowMy, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                      @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        Page page = new Page(pageNo, pageSize);
        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        flowMy.setUsername(user.getUsername());
        return Result.OK(workTaskServicevo.toTaskBySelf(flowMy,page));
    }
 
    @ApiOperation(value = "获取已办任务", response = FlowTaskDto.class)
    @GetMapping(value = "/finishedList")
    public Result<?> finishedList(@ApiParam(value = "当前页码", required = true) @RequestParam Integer pageNo,
                               @ApiParam(value = "每页条数", required = true) @RequestParam Integer pageSize,
                                  FlowMyBusinessDto flowMyBusinessDto) {
        return flowTaskService.finishedList(pageNo, pageSize,flowMyBusinessDto);
    }
 
 
    @ApiOperation(value = "获取工作流历史任务", response = FlowTaskDto.class)
    @GetMapping(value = "/queryHisTaskList")
    public Result<?> queryHisTaskList(@RequestParam(name = "procInstId") String procInstId) {
        List<FlowHistoricalVo> flowHistoricalVos = hisWorkTaskService.queryHisTaskByProcInstId(procInstId);
        if(CollectionUtil.isEmpty(flowHistoricalVos)) {
            return Result.OK(Collections.emptyList());
        }
        List<JSONObject> items = new ArrayList<>();
        try {
            for(FlowHistoricalVo vo : flowHistoricalVos) {
                String json = objectMapper.writeValueAsString(vo);
                JSONObject item = JSONObject.parseObject(json, Feature.OrderedField);
                translateDictTextUtils.translateField("assignee", vo.getAssignee(), item, "sys_user,realname,username");
                items.add(item);
            }
            return Result.OK(items);
        }catch (Exception e) {
            return Result.error("数据转译失败!");
        }
    }
 
    @ApiOperation(value = "审批任务-查看流程图")
    @GetMapping("/diagramView")
    public void showImages(@RequestParam(name = "processDefinitionId") String processDefinitionId,
                           @RequestParam(name = "processInstanceId") String processInstanceId,
                           @RequestParam(name = "TaskDefinitionKey") String TaskDefinitionKey,
                           HttpServletResponse response) throws IOException {
        BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
        List<HistoricActivityInstance> historyProcess = historyService.createHistoricActivityInstanceQuery()
                .processInstanceId(processInstanceId)
                .finished()
                .list();
 
        List<String> activityIds = new ArrayList<>();
        List<String> flows = new ArrayList<>();
 
        for (HistoricActivityInstance hi : historyProcess) {
            String activityType = hi.getActivityType();
            if (activityType.equals("sequenceFlow") || activityType.equals("exclusiveGateway")) {
                flows.add(hi.getActivityId());
            } else if (activityType.equals("userTask") || activityType.equals("startEvent")) {
                activityIds.add(hi.getActivityId());
            }
        }
        activityIds.add(TaskDefinitionKey);
        ProcessEngineConfiguration engConf = processEngine.getProcessEngineConfiguration();
        ProcessDiagramGenerator processDiagramGenerator = engConf.getProcessDiagramGenerator();
 
        InputStream in = processDiagramGenerator.generateDiagram(bpmnModel, "png", activityIds, flows,
                engConf.getActivityFontName(), engConf.getLabelFontName(), engConf.getAnnotationFontName(),
                engConf.getClassLoader(), 1.0, true);
 
        OutputStream out = response.getOutputStream();
        byte[] buf = new byte[1024];
        int length = 0;
        while ((length = in.read(buf)) != -1) {
            out.write(buf, 0, length);
        }
        in.close();
        out.close();
    }
}