zhuguifei
2025-04-28 442928123f63ee497d766f9a7a14f0a6ee067e25
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
package org.jeecg.modules.activiti.controller;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.activiti.engine.repository.Model;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.modules.activiti.service.ReProcdefService;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.exception.JeecgBootException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.util.Map;
 
/**
 * 流程管理
 *
 * @author len
 * @date 2019/06/13
 */
@RestController
@RequestMapping("act/reprocdef")
public class ReProcdefController {
    @Autowired
    private ReProcdefService reProcdefService;
 
    /**
     * 分页查询
     *
     * @param req
     *            查询参数
     * @return RestResponse
     */
    @GetMapping("/list")
    public Result list(@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                       @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                       HttpServletRequest req) {
        IPage page = reProcdefService.queryPage( pageNo,pageSize,req);
        return Result.OK(page);
    }
 
    /**
     * 获取激活的流程
     *
     * @return RestResponse
     */
    @GetMapping("/list/active")
    public Result listActive(HttpServletRequest request) {
        return Result.OK(reProcdefService.listActive(request));
    }
 
    /**
     * 读取资源,通过部署ID
     *
     * @param id
     *            流程定义ID
     * @param proInsId
     *            流程实例ID
     * @param resType
     *            资源类型(xml|image)
     * @param response
     *            响应
     * @throws Exception
     *             读写流异常
     */
    @RequestMapping("/read")
    public void resourceRead(String id, String proInsId, String resType, HttpServletResponse response)
        throws Exception {
        InputStream resourceAsStream = reProcdefService.resourceRead(id, proInsId, resType);
        byte[] b = new byte[1024];
        int len = -1;
        int lenEnd = 1024;
        while ((len = resourceAsStream.read(b, 0, lenEnd)) != -1) {
            response.getOutputStream().write(b, 0, len);
        }
    }
 
    /**
     * 部署流程文件
     *
     * @param file
     *            file
     * @return RestResponse
     */
    @RequestMapping("/deploy")
    public Result deploy(MultipartFile file,HttpServletRequest request) {
        String exportDir = this.getClass().getResource("/").getPath();
        String fileName = file.getOriginalFilename();
        String msg = "";
        if (StringUtils.isBlank(fileName)) {
            throw new JeecgBootException("请选择要部署的流程文件");
        } else {
            try {
                msg = reProcdefService.deploy(exportDir, file, request);
            } catch (Exception e) {
                return Result.error(e.getMessage());
            }
        }
        return Result.OK(msg);
    }
 
    /**
     * 转为模型
     *
     * @param id
     *            id
     * @return RestResponse
     */
    @GetMapping("/convertToModel")
    public Result convertToModel(String id,HttpServletRequest request) {
        Model model = null;
        try {
             model = reProcdefService.convertToModel(id,request);
 
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
        return Result.OK(model);
    }
 
    /**
     * 启动流程实例,通过processDefinitionId
     *
     * @param processDefinitionId
     *            processDefinitionId
     * @return RestResponse
     */
    @RequestMapping("/startProcessInstanceById")
    public Result startProcessInstanceById(String processDefinitionId) {
        try {
            reProcdefService.startProcessInstanceById(processDefinitionId);
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
        return Result.OK();
    }
 
    /**
     * 激活 / 挂起
     *
     * @param state
     * @param id
     * @return
     */
    @GetMapping("/update")
    public Result update(String id,int state) {
        String msg = reProcdefService.updateState(state, id);
        return Result.OK(msg);
    }
 
    /**
     * 批量删除部署的流程,级联删除流程实例
     *
     * @param ids
     *            流程部署标识
     * @return RestResponse
     */
    @RequestMapping("/deleteBatchByIds")
    public Result deleteBatchByIds(@RequestParam("ids[]") String[] ids) {
        reProcdefService.deleteBatch(ids);
        return Result.OK();
    }
 
    /**
     * 删除部署的流程,级联删除流程实例
     *
     * @param deploymentId
     *            流程部署标识
     * @return RestResponse
     */
    @DeleteMapping("/deleteByDeploymentId")
    public Result deleteByDeploymentId(String deploymentId) {
        reProcdefService.deleteByDeploymentId(deploymentId);
        return Result.OK();
    }
 
}