懒羊羊
2023-11-14 8286c62256f23bc2367a6729c0f46f84215e380b
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
package cn.stylefeng.guns.workflow.modular.controller;
 
import cn.stylefeng.guns.base.auth.context.LoginContextHolder;
import cn.stylefeng.guns.base.consts.ConstantsContext;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.core.util.FileDownload;
import cn.stylefeng.guns.workflow.modular.controller.base.ActBaseController;
import cn.stylefeng.guns.workflow.core.util.FileZip;
import cn.stylefeng.guns.workflow.core.util.PathUtil;
import cn.stylefeng.guns.workflow.modular.model.params.ProcdefParam;
import cn.stylefeng.guns.workflow.modular.service.ProcessService;
import cn.stylefeng.guns.sys.modular.system.model.UploadResult;
import cn.stylefeng.guns.sys.modular.system.service.FileInfoService;
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.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
 
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
 
 
/**
 * 流程管理控制器
 *
 * @author stylefeng
 * @Date 2019-08-11 21:59:38
 */
@Controller
@RequestMapping("/process")
@Slf4j
public class ProcessController extends ActBaseController {
 
    private String PREFIX = "/modular/act/process";
 
    @Autowired
    private ProcessService processService;
 
    @Autowired
    private FileInfoService fileInfoService;
 
    /**
     * 跳转到主页面
     *
     * @author stylefeng
     * @Date 2019-08-11
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/process.html";
    }
 
    /**
     * 导入流程
     *
     * @author stylefeng
     * @Date 2019-08-11
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/process_add.html";
    }
 
    /**
     * 导入流程
     *
     * @author stylefeng
     * @Date 2019-08-11
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(@RequestPart("file") MultipartFile file) {
        if (null != file && !file.isEmpty()) {
 
            //bpmn文件上传路径
            String fileParentPath = ConstantsContext.getBpmnFileUploadPath();
 
            //执行上传
            UploadResult uploadResult = fileInfoService.uploadFile(file, fileParentPath);
 
            try {
                deploymentProcessDefinitionFromInputStream(uploadResult.getOriginalFilename(), uploadResult.getFileSavePath());
            } catch (Exception e) {
                log.error("上传文件出错", e);
                return ResponseData.error("上传文件出错");
            }
        }
 
        return ResponseData.success();
    }
 
    /**
     * 删除接口
     *
     * @author stylefeng
     * @Date 2019-08-11
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(ProcdefParam procdefParam) {
        try {
            super.deleteDeployment(procdefParam.getDeploymentId());
        } catch (Exception e) {
            log.error("删除失败!", e);
            return ResponseData.error("删除失败!");
        }
        return ResponseData.success();
    }
 
    /**
     * 查询列表
     *
     * @author stylefeng
     * @Date 2019-08-11
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(ProcdefParam procdefParam) {
        return this.processService.findPageBySpec(procdefParam);
    }
 
    /**
     * 打包下载xml和png
     *
     * @author fengshuonan
     * @Date 2019/8/12 21:37
     */
    @RequestMapping(value = "/download")
    public void download(HttpServletResponse response, String deploymentId) throws Exception {
 
        //生成XML和PNG
        createXmlAndPng(deploymentId);
 
        //生成的全部代码压缩成zip文件
        if (FileZip.zip(PathUtil.getProjectpath() + "uploadFiles/activitiFile",
                PathUtil.getProjectpath() + "uploadFiles/activitiFile.zip")) {
 
            //下载代码
            FileDownload.fileDownload(response, PathUtil.getProjectpath() + "uploadFiles/activitiFile.zip", "activitiFile.zip");
        }
    }
 
    /**
     * 激活or挂起流程实例
     *
     * @author fengshuonan
     * @Date 2019/8/12 21:41
     */
    @RequestMapping(value = "/onoffPro")
    @ResponseBody
    public ResponseData onoffProcessDefinition(@RequestParam("id") String id,
                                               @RequestParam("status") Integer status) throws Exception {
 
        //如果是挂起
        if (status == 2) {
 
            //挂起前先把此流程的所有任务状态设置成激活状态
            this.processService.onoffAllTask(id, 1);
 
            //挂起流程实例
            suspendProcessDefinitionById(id);
        } else {
 
            //激活前先把此流程的所有任务状态设置成挂起状态
            this.processService.onoffAllTask(id, 2);
 
            //激活流程实例
            activateProcessDefinitionById(id);
        }
 
        return new SuccessResponseData();
    }
 
    /**
     * 激活or挂起某个任务
     *
     * @author fengshuonan
     * @Date 2019/8/27 10:52
     */
    @RequestMapping(value = "/onoffTask")
    @ResponseBody
    public ResponseData onoffTask(@RequestParam("id") String id,
                                  @RequestParam("status") Integer status) {
 
        if (ToolUtil.isEmpty(id) || ToolUtil.isEmpty(status)) {
            throw new RequestEmptyException("参数不能为空");
        }
        this.processService.onoffTask(id, status);
        return ResponseData.success();
    }
 
 
    /**
     * 委派
     *
     * @author fengshuonan
     * @Date 2019/8/21 21:41
     */
    @RequestMapping(value = "/delegate")
    @ResponseBody
    public ResponseData delegate(@RequestParam("id") String id, @RequestParam("assignee") String assignee) {
 
        if (ToolUtil.isEmpty(id) || ToolUtil.isEmpty(assignee)) {
            throw new RequestEmptyException("id或assignee不能为空");
        }
        Map<String, Object> zmap = new HashMap<>();
        String errInfo = "success";
        Map<String, Object> map = new LinkedHashMap<>();
 
        //审批结果中记录委派
        map.put("审批结果", " 任务由 [" + LoginContextHolder.getContext().getUser().getAccount() + "] 委派  ");
 
        //设置流程变量
        setVariablesByTaskIdAsMap(id, map);
        setAssignee(id, assignee);
 
        //用于给待办人发送新任务消息
        zmap.put("ASSIGNEE_", assignee);
 
        //返回结果
        zmap.put("result", errInfo);
 
        return ResponseData.success(zmap);
    }
 
    /**
     * 作废流程
     *
     * @author fengshuonan
     * @Date 2019/8/21 21:41
     */
    @RequestMapping(value = "/deleteAct")
    @ResponseBody
    public ResponseData delete(@RequestParam("procInstId") String procInstId, @RequestParam("reason") String dReason) {
 
        if (ToolUtil.isEmpty(procInstId)) {
            throw new RequestEmptyException("procInstId不能为空");
        }
        Map<String, Object> map = new HashMap<>();
        String errInfo = "success";
 
        //作废原因
        String reason = null;
        try {
            reason = "【作废】" + LoginContextHolder.getContext().getUser().getName() + ":" + URLDecoder.decode(dReason, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            log.error("作废失败,编码错误!", e);
        }
 
        //作废流程
        deleteProcessInstance(procInstId, reason);
 
        map.put("result", errInfo);
 
        return ResponseData.success(map);
    }
 
}