懒羊羊
2023-11-14 8286c62256f23bc2367a6729c0f46f84215e380b
提交 | 用户 | 时间
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.consts.ConstantsContext;
5 import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
6 import cn.stylefeng.guns.sys.core.util.FileDownload;
7 import cn.stylefeng.guns.workflow.modular.controller.base.ActBaseController;
8 import cn.stylefeng.guns.workflow.core.util.FileZip;
9 import cn.stylefeng.guns.workflow.core.util.PathUtil;
10 import cn.stylefeng.guns.workflow.modular.model.params.ProcdefParam;
11 import cn.stylefeng.guns.workflow.modular.service.ProcessService;
12 import cn.stylefeng.guns.sys.modular.system.model.UploadResult;
13 import cn.stylefeng.guns.sys.modular.system.service.FileInfoService;
14 import cn.stylefeng.roses.core.util.ToolUtil;
15 import cn.stylefeng.roses.kernel.model.exception.RequestEmptyException;
16 import cn.stylefeng.roses.kernel.model.response.ResponseData;
17 import cn.stylefeng.roses.kernel.model.response.SuccessResponseData;
18 import lombok.extern.slf4j.Slf4j;
19 import org.springframework.beans.factory.annotation.Autowired;
20 import org.springframework.stereotype.Controller;
21 import org.springframework.web.bind.annotation.RequestMapping;
22 import org.springframework.web.bind.annotation.RequestParam;
23 import org.springframework.web.bind.annotation.RequestPart;
24 import org.springframework.web.bind.annotation.ResponseBody;
25 import org.springframework.web.multipart.MultipartFile;
26
27 import javax.servlet.http.HttpServletResponse;
28 import java.io.UnsupportedEncodingException;
29 import java.net.URLDecoder;
30 import java.util.HashMap;
31 import java.util.LinkedHashMap;
32 import java.util.Map;
33
34
35 /**
36  * 流程管理控制器
37  *
38  * @author stylefeng
39  * @Date 2019-08-11 21:59:38
40  */
41 @Controller
42 @RequestMapping("/process")
43 @Slf4j
44 public class ProcessController extends ActBaseController {
45
46     private String PREFIX = "/modular/act/process";
47
48     @Autowired
49     private ProcessService processService;
50
51     @Autowired
52     private FileInfoService fileInfoService;
53
54     /**
55      * 跳转到主页面
56      *
57      * @author stylefeng
58      * @Date 2019-08-11
59      */
60     @RequestMapping("")
61     public String index() {
62         return PREFIX + "/process.html";
63     }
64
65     /**
66      * 导入流程
67      *
68      * @author stylefeng
69      * @Date 2019-08-11
70      */
71     @RequestMapping("/add")
72     public String add() {
73         return PREFIX + "/process_add.html";
74     }
75
76     /**
77      * 导入流程
78      *
79      * @author stylefeng
80      * @Date 2019-08-11
81      */
82     @RequestMapping("/addItem")
83     @ResponseBody
84     public ResponseData addItem(@RequestPart("file") MultipartFile file) {
85         if (null != file && !file.isEmpty()) {
86
87             //bpmn文件上传路径
88             String fileParentPath = ConstantsContext.getBpmnFileUploadPath();
89
90             //执行上传
91             UploadResult uploadResult = fileInfoService.uploadFile(file, fileParentPath);
92
93             try {
94                 deploymentProcessDefinitionFromInputStream(uploadResult.getOriginalFilename(), uploadResult.getFileSavePath());
95             } catch (Exception e) {
96                 log.error("上传文件出错", e);
97                 return ResponseData.error("上传文件出错");
98             }
99         }
100
101         return ResponseData.success();
102     }
103
104     /**
105      * 删除接口
106      *
107      * @author stylefeng
108      * @Date 2019-08-11
109      */
110     @RequestMapping("/delete")
111     @ResponseBody
112     public ResponseData delete(ProcdefParam procdefParam) {
113         try {
114             super.deleteDeployment(procdefParam.getDeploymentId());
115         } catch (Exception e) {
116             log.error("删除失败!", e);
117             return ResponseData.error("删除失败!");
118         }
119         return ResponseData.success();
120     }
121
122     /**
123      * 查询列表
124      *
125      * @author stylefeng
126      * @Date 2019-08-11
127      */
128     @ResponseBody
129     @RequestMapping("/list")
130     public LayuiPageInfo list(ProcdefParam procdefParam) {
131         return this.processService.findPageBySpec(procdefParam);
132     }
133
134     /**
135      * 打包下载xml和png
136      *
137      * @author fengshuonan
138      * @Date 2019/8/12 21:37
139      */
140     @RequestMapping(value = "/download")
141     public void download(HttpServletResponse response, String deploymentId) throws Exception {
142
143         //生成XML和PNG
144         createXmlAndPng(deploymentId);
145
146         //生成的全部代码压缩成zip文件
147         if (FileZip.zip(PathUtil.getProjectpath() + "uploadFiles/activitiFile",
148                 PathUtil.getProjectpath() + "uploadFiles/activitiFile.zip")) {
149
150             //下载代码
151             FileDownload.fileDownload(response, PathUtil.getProjectpath() + "uploadFiles/activitiFile.zip", "activitiFile.zip");
152         }
153     }
154
155     /**
156      * 激活or挂起流程实例
157      *
158      * @author fengshuonan
159      * @Date 2019/8/12 21:41
160      */
161     @RequestMapping(value = "/onoffPro")
162     @ResponseBody
163     public ResponseData onoffProcessDefinition(@RequestParam("id") String id,
164                                                @RequestParam("status") Integer status) throws Exception {
165
166         //如果是挂起
167         if (status == 2) {
168
169             //挂起前先把此流程的所有任务状态设置成激活状态
170             this.processService.onoffAllTask(id, 1);
171
172             //挂起流程实例
173             suspendProcessDefinitionById(id);
174         } else {
175
176             //激活前先把此流程的所有任务状态设置成挂起状态
177             this.processService.onoffAllTask(id, 2);
178
179             //激活流程实例
180             activateProcessDefinitionById(id);
181         }
182
183         return new SuccessResponseData();
184     }
185
186     /**
187      * 激活or挂起某个任务
188      *
189      * @author fengshuonan
190      * @Date 2019/8/27 10:52
191      */
192     @RequestMapping(value = "/onoffTask")
193     @ResponseBody
194     public ResponseData onoffTask(@RequestParam("id") String id,
195                                   @RequestParam("status") Integer status) {
196
197         if (ToolUtil.isEmpty(id) || ToolUtil.isEmpty(status)) {
198             throw new RequestEmptyException("参数不能为空");
199         }
200         this.processService.onoffTask(id, status);
201         return ResponseData.success();
202     }
203
204
205     /**
206      * 委派
207      *
208      * @author fengshuonan
209      * @Date 2019/8/21 21:41
210      */
211     @RequestMapping(value = "/delegate")
212     @ResponseBody
213     public ResponseData delegate(@RequestParam("id") String id, @RequestParam("assignee") String assignee) {
214
215         if (ToolUtil.isEmpty(id) || ToolUtil.isEmpty(assignee)) {
216             throw new RequestEmptyException("id或assignee不能为空");
217         }
218         Map<String, Object> zmap = new HashMap<>();
219         String errInfo = "success";
220         Map<String, Object> map = new LinkedHashMap<>();
221
222         //审批结果中记录委派
223         map.put("审批结果", " 任务由 [" + LoginContextHolder.getContext().getUser().getAccount() + "] 委派  ");
224
225         //设置流程变量
226         setVariablesByTaskIdAsMap(id, map);
227         setAssignee(id, assignee);
228
229         //用于给待办人发送新任务消息
230         zmap.put("ASSIGNEE_", assignee);
231
232         //返回结果
233         zmap.put("result", errInfo);
234
235         return ResponseData.success(zmap);
236     }
237
238     /**
239      * 作废流程
240      *
241      * @author fengshuonan
242      * @Date 2019/8/21 21:41
243      */
244     @RequestMapping(value = "/deleteAct")
245     @ResponseBody
246     public ResponseData delete(@RequestParam("procInstId") String procInstId, @RequestParam("reason") String dReason) {
247
248         if (ToolUtil.isEmpty(procInstId)) {
249             throw new RequestEmptyException("procInstId不能为空");
250         }
251         Map<String, Object> map = new HashMap<>();
252         String errInfo = "success";
253
254         //作废原因
255         String reason = null;
256         try {
257             reason = "【作废】" + LoginContextHolder.getContext().getUser().getName() + ":" + URLDecoder.decode(dReason, "UTF-8");
258         } catch (UnsupportedEncodingException e) {
259             log.error("作废失败,编码错误!", e);
260         }
261
262         //作废流程
263         deleteProcessInstance(procInstId, reason);
264
265         map.put("result", errInfo);
266
267         return ResponseData.success(map);
268     }
269
270 }
271
272