提交 | 用户 | 时间
|
8286c6
|
1 |
package cn.stylefeng.guns.workflow.modular.controller; |
懒 |
2 |
|
|
3 |
import cn.stylefeng.guns.base.auth.context.LoginContextHolder; |
|
4 |
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo; |
|
5 |
import cn.stylefeng.guns.workflow.modular.controller.base.ActBaseController; |
|
6 |
import cn.stylefeng.guns.workflow.core.cache.TempAssignCache; |
|
7 |
import cn.stylefeng.guns.workflow.core.consts.ActConst; |
|
8 |
import cn.stylefeng.guns.workflow.core.util.ImageAnd64Binary; |
|
9 |
import cn.stylefeng.guns.workflow.core.util.PathUtil; |
|
10 |
import cn.stylefeng.guns.workflow.core.util.TimeCalcUtil; |
|
11 |
import cn.stylefeng.guns.workflow.modular.model.params.ActHandleDto; |
|
12 |
import cn.stylefeng.guns.workflow.modular.model.params.TaskParam; |
|
13 |
import cn.stylefeng.guns.workflow.modular.service.ProcessService; |
|
14 |
import cn.stylefeng.guns.workflow.modular.service.TaskWaitingService; |
|
15 |
import cn.stylefeng.roses.core.util.ToolUtil; |
|
16 |
import cn.stylefeng.roses.kernel.model.exception.RequestEmptyException; |
|
17 |
import cn.stylefeng.roses.kernel.model.response.ResponseData; |
|
18 |
import cn.stylefeng.roses.kernel.model.response.SuccessResponseData; |
|
19 |
import lombok.extern.slf4j.Slf4j; |
|
20 |
import org.springframework.beans.factory.annotation.Autowired; |
|
21 |
import org.springframework.stereotype.Controller; |
|
22 |
import org.springframework.ui.Model; |
|
23 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
24 |
import org.springframework.web.bind.annotation.RequestParam; |
|
25 |
import org.springframework.web.bind.annotation.ResponseBody; |
|
26 |
|
|
27 |
import java.net.URLDecoder; |
|
28 |
import java.util.HashMap; |
|
29 |
import java.util.LinkedHashMap; |
|
30 |
import java.util.List; |
|
31 |
import java.util.Map; |
|
32 |
|
|
33 |
|
|
34 |
/** |
|
35 |
* 待办任务控制器 |
|
36 |
* |
|
37 |
* @author fengshuonan |
|
38 |
* @Date 2019-08-19 16:17:40 |
|
39 |
*/ |
|
40 |
@Controller |
|
41 |
@RequestMapping("/taskWaiting") |
|
42 |
@Slf4j |
|
43 |
public class TaskWaitingController extends ActBaseController { |
|
44 |
|
|
45 |
private String PREFIX = "/modular/act/taskWaiting"; |
|
46 |
|
|
47 |
@Autowired |
|
48 |
private TaskWaitingService taskWaitingService; |
|
49 |
|
|
50 |
@Autowired |
|
51 |
private ProcessService processService; |
|
52 |
|
|
53 |
/** |
|
54 |
* 跳转到主页面 |
|
55 |
* |
|
56 |
* @author fengshuonan |
|
57 |
* @Date 2019-08-19 |
|
58 |
*/ |
|
59 |
@RequestMapping("") |
|
60 |
public String index() { |
|
61 |
return PREFIX + "/taskWaiting.html"; |
|
62 |
} |
|
63 |
|
|
64 |
/** |
|
65 |
* 委派页面 |
|
66 |
* |
|
67 |
* @author fengshuonan |
|
68 |
* @Date 2019-08-19 |
|
69 |
*/ |
|
70 |
@RequestMapping("/delegatePage") |
|
71 |
public String delegatePage(@RequestParam("ID_") String id, Model model) { |
|
72 |
if (ToolUtil.isEmpty(id)) { |
|
73 |
throw new RequestEmptyException("id不能为空"); |
|
74 |
} |
|
75 |
model.addAttribute("ID_", id); |
|
76 |
return PREFIX + "/delegate.html"; |
|
77 |
} |
|
78 |
|
|
79 |
/** |
|
80 |
* 办理页面 |
|
81 |
* |
|
82 |
* @author fengshuonan |
|
83 |
* @Date 2019-08-19 |
|
84 |
*/ |
|
85 |
@RequestMapping("/handlePage") |
|
86 |
public String handlePage(@RequestParam("ID_") String id, |
|
87 |
@RequestParam("DGRM_RESOURCE_NAME_") String dgrmResourceName, |
|
88 |
@RequestParam("PROC_INST_ID_") String procInstId, |
|
89 |
Model model) { |
|
90 |
|
|
91 |
if (ToolUtil.isEmpty(id) || ToolUtil.isEmpty(procInstId)) { |
|
92 |
throw new RequestEmptyException("id不能为空"); |
|
93 |
} |
|
94 |
|
|
95 |
model.addAttribute("ID_", id); |
|
96 |
model.addAttribute("DGRM_RESOURCE_NAME_", dgrmResourceName); |
|
97 |
model.addAttribute("PROC_INST_ID_", procInstId); |
|
98 |
|
|
99 |
return PREFIX + "/handle.html"; |
|
100 |
} |
|
101 |
|
|
102 |
/** |
|
103 |
* 委派人员页面 |
|
104 |
* |
|
105 |
* @author fengshuonan |
|
106 |
* @Date 2019-08-19 |
|
107 |
*/ |
|
108 |
@RequestMapping("/delegateUserPage") |
|
109 |
public String delegateUserPage(@RequestParam("ID_") String id, Model model) { |
|
110 |
if (ToolUtil.isEmpty(id)) { |
|
111 |
throw new RequestEmptyException("id不能为空"); |
|
112 |
} |
|
113 |
model.addAttribute("ID_", id); |
|
114 |
return PREFIX + "/user.html"; |
|
115 |
} |
|
116 |
|
|
117 |
/** |
|
118 |
* 选择办理人 |
|
119 |
* |
|
120 |
* @author fengshuonan |
|
121 |
* @Date 2019-8-22 19:01 |
|
122 |
*/ |
|
123 |
@RequestMapping("/selectDealer") |
|
124 |
public String selectDealer() { |
|
125 |
return PREFIX + "/selectDealer.html"; |
|
126 |
} |
|
127 |
|
|
128 |
/** |
|
129 |
* 选择角色 |
|
130 |
* |
|
131 |
* @author fengshuonan |
|
132 |
* @Date 2019-8-22 19:01 |
|
133 |
*/ |
|
134 |
@RequestMapping("/selectRole") |
|
135 |
public String selectRole() { |
|
136 |
return PREFIX + "/selectRole.html"; |
|
137 |
} |
|
138 |
|
|
139 |
/** |
|
140 |
* 待办任务查询列表 |
|
141 |
* |
|
142 |
* @author fengshuonan |
|
143 |
* @Date 2019-08-20 |
|
144 |
*/ |
|
145 |
@ResponseBody |
|
146 |
@RequestMapping("/list") |
|
147 |
public LayuiPageInfo list(TaskParam taskParam) { |
|
148 |
|
|
149 |
LayuiPageInfo pageBySpec = this.taskWaitingService.findPageBySpec(taskParam); |
|
150 |
|
|
151 |
//添加流程申请人 |
|
152 |
if (ToolUtil.isNotEmpty(pageBySpec.getData())) { |
|
153 |
List<Map<String, Object>> maps = pageBySpec.getData(); |
|
154 |
for (int i = 0; i < maps.size(); i++) { |
|
155 |
maps.get(i).put("initator", getInitiator((String) maps.get(i).get("proc_inst_id_"))); |
|
156 |
} |
|
157 |
} |
|
158 |
|
|
159 |
return pageBySpec; |
|
160 |
} |
|
161 |
|
|
162 |
|
|
163 |
/** |
|
164 |
* 办理任务 |
|
165 |
* |
|
166 |
* @author fengshuonan |
|
167 |
* @Date 2019-08-21 |
|
168 |
*/ |
|
169 |
@RequestMapping(value = "/handle") |
|
170 |
@ResponseBody |
|
171 |
public ResponseData handle(ActHandleDto actHandleDto) { |
|
172 |
|
|
173 |
//任务ID |
|
174 |
String taskId = actHandleDto.getID_(); |
|
175 |
|
|
176 |
//审批结果 |
|
177 |
String sfrom = ""; |
|
178 |
Object ofrom = getVariablesByTaskIdAsMap(taskId, "审批结果"); |
|
179 |
if (null != ofrom) { |
|
180 |
sfrom = ofrom.toString(); |
|
181 |
} |
|
182 |
|
|
183 |
Map<String, Object> map = new LinkedHashMap<>(); |
|
184 |
|
|
185 |
//审批结果+审批人的姓名+审批意见 |
|
186 |
String opinion = sfrom + LoginContextHolder.getContext().getUser().getName() + "," + actHandleDto.getOPINION(); |
|
187 |
|
|
188 |
String msg = actHandleDto.getMsg(); |
|
189 |
|
|
190 |
//批准 |
|
191 |
if ("yes".equals(msg)) { |
|
192 |
|
|
193 |
//审批结果 |
|
194 |
map.put("审批结果", "【批准】" + opinion); |
|
195 |
|
|
196 |
//设置流程变量 |
|
197 |
setVariablesByTaskIdAsMap(taskId, map); |
|
198 |
setVariablesByTaskId(taskId, "RESULT", "批准"); |
|
199 |
completeMyPersonalTask(taskId); |
|
200 |
} else { |
|
201 |
|
|
202 |
//驳回 |
|
203 |
map.put("审批结果", "【驳回】" + opinion); |
|
204 |
|
|
205 |
//设置流程变量 |
|
206 |
setVariablesByTaskIdAsMap(taskId, map); |
|
207 |
setVariablesByTaskId(taskId, "RESULT", "驳回"); |
|
208 |
completeMyPersonalTask(taskId); |
|
209 |
} |
|
210 |
|
|
211 |
try { |
|
212 |
//移除流程变量(从正在运行中) |
|
213 |
removeVariablesByPROC_INST_ID_(actHandleDto.getPROC_INST_ID_(), "RESULT"); |
|
214 |
} catch (Exception e) { |
|
215 |
log.error("移除流程变量错误,此流程变量在历史中", e); |
|
216 |
} |
|
217 |
|
|
218 |
try { |
|
219 |
//下一待办对象 |
|
220 |
String assignee = actHandleDto.getASSIGNEE_(); |
|
221 |
if (ToolUtil.isNotEmpty(assignee)) { |
|
222 |
|
|
223 |
//指定下一任务待办对象 |
|
224 |
setAssignee(TempAssignCache.get(), assignee); |
|
225 |
} |
|
226 |
} catch (Exception e) { |
|
227 |
//手动指定下一待办人,才会触发此异常 |
|
228 |
//任务结束不需要指定下一步办理人了,发送站内信通知任务发起人 |
|
229 |
log.error("指定下一代办人错误", e); |
|
230 |
} |
|
231 |
|
|
232 |
return new SuccessResponseData(); |
|
233 |
} |
|
234 |
|
|
235 |
/** |
|
236 |
* 去办理任务页面获取数据 |
|
237 |
* |
|
238 |
* @author fengshuonan |
|
239 |
* @Date 2019-08-28 13:46 |
|
240 |
*/ |
|
241 |
@RequestMapping(value = "/getHandleData") |
|
242 |
@ResponseBody |
|
243 |
public ResponseData getHandleData(@RequestParam("fileName") String fileName, |
|
244 |
@RequestParam("id") String id, |
|
245 |
@RequestParam("procInstId") String procInstId) throws Exception { |
|
246 |
|
|
247 |
if (ToolUtil.isEmpty(id) || ToolUtil.isEmpty(procInstId)) { |
|
248 |
throw new RequestEmptyException("id或procInstId不能为空"); |
|
249 |
} |
|
250 |
Map<String, Object> map = new HashMap<>(); |
|
251 |
String errInfo = "success"; |
|
252 |
|
|
253 |
//列出流程变量列表 |
|
254 |
Map<String, Object> varList = processService.varList(procInstId); |
|
255 |
|
|
256 |
//历史任务节点列表 |
|
257 |
List<Map<String, Object>> hitaskList = processService.hitoryTaskList(procInstId); |
|
258 |
|
|
259 |
//根据耗时的毫秒数计算天时分秒 |
|
260 |
for (int i = 0; i < hitaskList.size(); i++) { |
|
261 |
if (null != hitaskList.get(i).get("duration_")) { |
|
262 |
Long ztime = Long.parseLong(hitaskList.get(i).get("duration_").toString()); |
|
263 |
hitaskList.get(i).put("ztime", TimeCalcUtil.calc(ztime)); |
|
264 |
} |
|
265 |
} |
|
266 |
|
|
267 |
String filename = URLDecoder.decode(fileName, "UTF-8"); |
|
268 |
|
|
269 |
//生成当前任务节点的流程图片 |
|
270 |
createXmlAndPngAtNowTask(procInstId, filename); |
|
271 |
String imgSrcPath = PathUtil.getProjectpath() + ActConst.FILEACTIVITI + filename; |
|
272 |
|
|
273 |
//解决图片src中文乱码,把图片转成base64格式显示 |
|
274 |
map.put("imgSrc", "data:image/jpeg;base64," + ImageAnd64Binary.getImageStr(imgSrcPath)); |
|
275 |
|
|
276 |
//流程变量列表 |
|
277 |
map.put("varList", varList); |
|
278 |
|
|
279 |
//审批记录表格 |
|
280 |
map.put("hitaskList", hitaskList); |
|
281 |
|
|
282 |
//返回结果 |
|
283 |
map.put("result", errInfo); |
|
284 |
|
|
285 |
return ResponseData.success(map); |
|
286 |
} |
|
287 |
|
|
288 |
} |
|
289 |
|
|
290 |
|