懒羊羊
2023-08-30 71e81ed1d12e4d69f53c8ad9e066650ad4186293
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
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.sys.core.exception.enums.BizExceptionEnum;
import cn.stylefeng.guns.workflow.modular.controller.base.ActBaseController;
import cn.stylefeng.guns.workflow.modular.entity.Model;
import cn.stylefeng.guns.workflow.modular.model.ActModel;
import cn.stylefeng.guns.workflow.modular.model.params.ModelParam;
import cn.stylefeng.guns.workflow.modular.service.ModelService;
import cn.stylefeng.roses.core.util.ToolUtil;
import cn.stylefeng.roses.kernel.model.exception.RequestEmptyException;
import cn.stylefeng.roses.kernel.model.exception.ServiceException;
import cn.stylefeng.roses.kernel.model.response.ErrorResponseData;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import cn.stylefeng.roses.kernel.model.response.SuccessResponseData;
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.ResponseBody;
 
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;
 
 
/**
 * 控制器
 *
 * @author stylefeng
 * @Date 2019-08-06 22:03:10
 */
@Controller
@RequestMapping("/model")
public class ModelController extends ActBaseController {
 
    private String PREFIX = "/modular/act/model";
 
    @Autowired
    private ModelService modelService;
 
    /**
     * 跳转到主页面
     *
     * @author stylefeng
     * @Date 2019-08-06
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/model.html";
    }
 
    /**
     * 新增页面
     *
     * @author stylefeng
     * @Date 2019-08-06
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/model_add.html";
    }
 
    /**
     * 编辑页面
     *
     * @author stylefeng
     * @Date 2019-08-06
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/model_edit.html";
    }
 
    /**
     * 代码查看页面
     *
     * @author stylefeng
     * @Date 2019-08-06
     */
    @RequestMapping("/modelView")
    public String modelView() {
        return PREFIX + "/model_view.html";
    }
 
    /**
     * 新增接口
     *
     * @author stylefeng
     * @Date 2019-08-06
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(ActModel actModel) {
        String modelId = null;
        try {
            modelId = createModel(actModel.getProcessId(),
                    actModel.getProcessAuthor(),
                    actModel.getName(),
                    actModel.getModelname(),
                    actModel.getDescription(),
                    actModel.getCategory());
        } catch (UnsupportedEncodingException e) {
            throw new ServiceException(BizExceptionEnum.SERVER_ERROR);
        }
        return new SuccessResponseData(modelId);
    }
 
    /**
     * 编辑接口
     *
     * @author stylefeng
     * @Date 2019-08-06
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(ModelParam modelParam) {
        this.modelService.update(modelParam);
        return ResponseData.success();
    }
 
    /**
     * 删除
     *
     * @author fengshuonan
     * @Date 2019/8/6 21:12
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public ResponseData delete(String modelId) {
        deleteModel(modelId);
        return new SuccessResponseData();
    }
 
    /**
     * 查看详情接口
     *
     * @author stylefeng
     * @Date 2019-08-06
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(ModelParam modelParam) {
        Model detail = this.modelService.getById(modelParam.getId());
        return ResponseData.success(detail);
    }
 
    /**
     * 查询列表
     *
     * @author stylefeng
     * @Date 2019-08-06
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(ModelParam modelParam) {
        return this.modelService.findPageBySpec(modelParam);
    }
 
    /**
     * 获取当前用户
     *
     * @author fengshuonan
     * @Date 2019/8/6 20:58
     */
    @RequestMapping(value = "/getAuthor")
    @ResponseBody
    public Object getAuthor() {
        Map<String, Object> map = new HashMap<>();
        String errInfo = "success";
        map.put("process_author", LoginContextHolder.getContext().getUser().getName());
        map.put("result", errInfo);
        return map;
    }
 
    /**
     * 部署流程定义
     *
     * @author fengshuonan
     * @Date 2019/8/6 21:13
     */
    @RequestMapping(value = "/deployment")
    @ResponseBody
    public ResponseData deployment(String modelId) {
        try {
            //部署流程定义
            deploymentProcessDefinitionFromModelId(modelId);
        } catch (Exception e) {
            return new ErrorResponseData(BizExceptionEnum.SERVER_ERROR.getMessage());
        }
        return new SuccessResponseData();
    }
 
    /**
     * 判断能否正常根据模型ID导出xml文件
     *
     * @author fengshuonan
     * @Date 2019/8/6 21:15
     */
    @RequestMapping(value = "/isCanExportXml")
    @ResponseBody
    public ResponseData isCanexportXml(String modelId, HttpServletResponse response) {
 
        if (ToolUtil.isEmpty(modelId)) {
            throw new RequestEmptyException();
        }
 
        try {
            isCanexportXmlFromModelId(response, modelId);
        } catch (Exception e) {
            throw new ServiceException(BizExceptionEnum.SERVER_ERROR);
        }
 
        return new SuccessResponseData();
    }
 
    /**
     * 获取预览XML页面code
     *
     * @author fengshuonan
     * @Date 2019/8/6 21:16
     */
    @RequestMapping(value = "/getXmlView")
    @ResponseBody
    public ResponseData getXmlView(String modelId) {
        if (ToolUtil.isEmpty(modelId)) {
            throw new RequestEmptyException();
        }
 
        String code = null;
        try {
            code = viewXmlFromModelId(modelId);
        } catch (Exception e) {
            throw new ServiceException(BizExceptionEnum.SERVER_ERROR);
        }
        return new SuccessResponseData(code);
    }
 
    /**
     * 正式根据模型ID导出xml文件
     *
     * @author fengshuonan
     * @Date 2019/8/6 21:18
     */
    @RequestMapping(value = "/exportXml")
    public void exportXml(String modelId, HttpServletResponse response) throws Exception {
        if (ToolUtil.isEmpty(modelId)) {
            throw new RequestEmptyException();
        }
 
        exportXmlFromModelId(response, modelId);
    }
 
    /**
     * 去修改类型页面获取数据
     *
     * @author fengshuonan
     * @Date 2019/8/6 21:18
     */
    @RequestMapping(value = "/goEdit")
    @ResponseBody
    public ResponseData goEdit(String modelId) {
        Model model = modelService.getById(modelId);
        return new SuccessResponseData(model);
    }
 
    /**
     * 修改类型
     *
     * @author fengshuonan
     * @Date 2019/8/6 21:20
     */
    @RequestMapping(value = "/editCategory")
    @ResponseBody
    public ResponseData edit(ActModel actModel) {
 
        String modelId = actModel.getModelId();
 
        Model model = modelService.getById(modelId);
        model.setCategory(actModel.getCategory());
 
        modelService.updateById(model);
        return new SuccessResponseData();
    }
 
    /**
     * 从流程定义映射模型
     *
     * @author fengshuonan
     * @Date 2019/8/6 21:20
     */
    @RequestMapping(value = "/saveModelFromPro")
    @ResponseBody
    public ResponseData saveModelFrom(String processDefinitionId) {
 
        //流程定义ID
        if (ToolUtil.isEmpty(processDefinitionId)) {
            throw new RequestEmptyException();
        }
 
        try {
            super.saveModelFromPro(processDefinitionId);
        } catch (Exception e) {
            throw new ServiceException(BizExceptionEnum.SERVER_ERROR);
        }
 
        return new SuccessResponseData();
    }
 
}