懒羊羊
2023-08-30 1ac2bc1590406d9babec036e154d8d08f34a6aa1
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
package cn.stylefeng.guns.workflow.modular.controller;
 
import cn.stylefeng.guns.base.auth.context.LoginContextHolder;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.workflow.modular.controller.base.ActBaseController;
import cn.stylefeng.guns.workflow.core.cache.TempAssignCache;
import cn.stylefeng.guns.workflow.core.consts.ActConst;
import cn.stylefeng.guns.workflow.core.util.ImageAnd64Binary;
import cn.stylefeng.guns.workflow.core.util.PathUtil;
import cn.stylefeng.guns.workflow.core.util.TimeCalcUtil;
import cn.stylefeng.guns.workflow.modular.model.params.ActHandleDto;
import cn.stylefeng.guns.workflow.modular.model.params.TaskParam;
import cn.stylefeng.guns.workflow.modular.service.ProcessService;
import cn.stylefeng.guns.workflow.modular.service.TaskWaitingService;
import cn.stylefeng.roses.core.util.ToolUtil;
import cn.stylefeng.roses.kernel.model.exception.RequestEmptyException;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import cn.stylefeng.roses.kernel.model.response.SuccessResponseData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
 
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
 
 
/**
 * 待办任务控制器
 *
 * @author fengshuonan
 * @Date 2019-08-19 16:17:40
 */
@Controller
@RequestMapping("/taskWaiting")
@Slf4j
public class TaskWaitingController extends ActBaseController {
 
    private String PREFIX = "/modular/act/taskWaiting";
 
    @Autowired
    private TaskWaitingService taskWaitingService;
 
    @Autowired
    private ProcessService processService;
 
    /**
     * 跳转到主页面
     *
     * @author fengshuonan
     * @Date 2019-08-19
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/taskWaiting.html";
    }
 
    /**
     * 委派页面
     *
     * @author fengshuonan
     * @Date 2019-08-19
     */
    @RequestMapping("/delegatePage")
    public String delegatePage(@RequestParam("ID_") String id, Model model) {
        if (ToolUtil.isEmpty(id)) {
            throw new RequestEmptyException("id不能为空");
        }
        model.addAttribute("ID_", id);
        return PREFIX + "/delegate.html";
    }
 
    /**
     * 办理页面
     *
     * @author fengshuonan
     * @Date 2019-08-19
     */
    @RequestMapping("/handlePage")
    public String handlePage(@RequestParam("ID_") String id,
                             @RequestParam("DGRM_RESOURCE_NAME_") String dgrmResourceName,
                             @RequestParam("PROC_INST_ID_") String procInstId,
                             Model model) {
 
        if (ToolUtil.isEmpty(id) || ToolUtil.isEmpty(procInstId)) {
            throw new RequestEmptyException("id不能为空");
        }
 
        model.addAttribute("ID_", id);
        model.addAttribute("DGRM_RESOURCE_NAME_", dgrmResourceName);
        model.addAttribute("PROC_INST_ID_", procInstId);
 
        return PREFIX + "/handle.html";
    }
 
    /**
     * 委派人员页面
     *
     * @author fengshuonan
     * @Date 2019-08-19
     */
    @RequestMapping("/delegateUserPage")
    public String delegateUserPage(@RequestParam("ID_") String id, Model model) {
        if (ToolUtil.isEmpty(id)) {
            throw new RequestEmptyException("id不能为空");
        }
        model.addAttribute("ID_", id);
        return PREFIX + "/user.html";
    }
 
    /**
     * 选择办理人
     *
     * @author fengshuonan
     * @Date 2019-8-22 19:01
     */
    @RequestMapping("/selectDealer")
    public String selectDealer() {
        return PREFIX + "/selectDealer.html";
    }
 
    /**
     * 选择角色
     *
     * @author fengshuonan
     * @Date 2019-8-22 19:01
     */
    @RequestMapping("/selectRole")
    public String selectRole() {
        return PREFIX + "/selectRole.html";
    }
 
    /**
     * 待办任务查询列表
     *
     * @author fengshuonan
     * @Date 2019-08-20
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(TaskParam taskParam) {
 
        LayuiPageInfo pageBySpec = this.taskWaitingService.findPageBySpec(taskParam);
 
        //添加流程申请人
        if (ToolUtil.isNotEmpty(pageBySpec.getData())) {
            List<Map<String, Object>> maps = pageBySpec.getData();
            for (int i = 0; i < maps.size(); i++) {
                maps.get(i).put("initator", getInitiator((String) maps.get(i).get("proc_inst_id_")));
            }
        }
 
        return pageBySpec;
    }
 
 
    /**
     * 办理任务
     *
     * @author fengshuonan
     * @Date 2019-08-21
     */
    @RequestMapping(value = "/handle")
    @ResponseBody
    public ResponseData handle(ActHandleDto actHandleDto) {
 
        //任务ID
        String taskId = actHandleDto.getID_();
 
        //审批结果
        String sfrom = "";
        Object ofrom = getVariablesByTaskIdAsMap(taskId, "审批结果");
        if (null != ofrom) {
            sfrom = ofrom.toString();
        }
 
        Map<String, Object> map = new LinkedHashMap<>();
 
        //审批结果+审批人的姓名+审批意见
        String opinion = sfrom + LoginContextHolder.getContext().getUser().getName() + "," + actHandleDto.getOPINION();
 
        String msg = actHandleDto.getMsg();
 
        //批准
        if ("yes".equals(msg)) {
 
            //审批结果
            map.put("审批结果", "【批准】" + opinion);
 
            //设置流程变量
            setVariablesByTaskIdAsMap(taskId, map);
            setVariablesByTaskId(taskId, "RESULT", "批准");
            completeMyPersonalTask(taskId);
        } else {
 
            //驳回
            map.put("审批结果", "【驳回】" + opinion);
 
            //设置流程变量
            setVariablesByTaskIdAsMap(taskId, map);
            setVariablesByTaskId(taskId, "RESULT", "驳回");
            completeMyPersonalTask(taskId);
        }
 
        try {
            //移除流程变量(从正在运行中)
            removeVariablesByPROC_INST_ID_(actHandleDto.getPROC_INST_ID_(), "RESULT");
        } catch (Exception e) {
            log.error("移除流程变量错误,此流程变量在历史中", e);
        }
 
        try {
            //下一待办对象
            String assignee = actHandleDto.getASSIGNEE_();
            if (ToolUtil.isNotEmpty(assignee)) {
 
                //指定下一任务待办对象
                setAssignee(TempAssignCache.get(), assignee);
            }
        } catch (Exception e) {
            //手动指定下一待办人,才会触发此异常
            //任务结束不需要指定下一步办理人了,发送站内信通知任务发起人
            log.error("指定下一代办人错误", e);
        }
 
        return new SuccessResponseData();
    }
 
    /**
     * 去办理任务页面获取数据
     *
     * @author fengshuonan
     * @Date 2019-08-28 13:46
     */
    @RequestMapping(value = "/getHandleData")
    @ResponseBody
    public ResponseData getHandleData(@RequestParam("fileName") String fileName,
                                      @RequestParam("id") String id,
                                      @RequestParam("procInstId") String procInstId) throws Exception {
 
        if (ToolUtil.isEmpty(id) || ToolUtil.isEmpty(procInstId)) {
            throw new RequestEmptyException("id或procInstId不能为空");
        }
        Map<String, Object> map = new HashMap<>();
        String errInfo = "success";
 
        //列出流程变量列表
        Map<String, Object> varList = processService.varList(procInstId);
 
        //历史任务节点列表
        List<Map<String, Object>> hitaskList = processService.hitoryTaskList(procInstId);
 
        //根据耗时的毫秒数计算天时分秒
        for (int i = 0; i < hitaskList.size(); i++) {
            if (null != hitaskList.get(i).get("duration_")) {
                Long ztime = Long.parseLong(hitaskList.get(i).get("duration_").toString());
                hitaskList.get(i).put("ztime", TimeCalcUtil.calc(ztime));
            }
        }
 
        String filename = URLDecoder.decode(fileName, "UTF-8");
 
        //生成当前任务节点的流程图片
        createXmlAndPngAtNowTask(procInstId, filename);
        String imgSrcPath = PathUtil.getProjectpath() + ActConst.FILEACTIVITI + filename;
 
        //解决图片src中文乱码,把图片转成base64格式显示
        map.put("imgSrc", "data:image/jpeg;base64," + ImageAnd64Binary.getImageStr(imgSrcPath));
 
        //流程变量列表
        map.put("varList", varList);
 
        //审批记录表格
        map.put("hitaskList", hitaskList);
 
        //返回结果
        map.put("result", errInfo);
 
        return ResponseData.success(map);
    }
 
}