李林
2023-10-07 658d4927d468c47208fd012d9128b09249c07eff
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
/*
 *    Copyright (c) 2018-2025, ztt All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: ztt
 */
 
package com.chinaztt.mes.technology.controller;
 
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.read.builder.ExcelReaderBuilder;
import com.alibaba.excel.read.metadata.ReadSheet;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chinaztt.mes.basic.util.DictUtils;
import com.chinaztt.mes.common.wrapper.QueryWrapperUtil;
import com.chinaztt.mes.technology.dto.RoutingDTO;
import com.chinaztt.mes.technology.dto.RoutingOperationDTO;
import com.chinaztt.mes.technology.entity.RoutingOperationTemplate;
import com.chinaztt.mes.technology.excel.RoutingData;
import com.chinaztt.mes.technology.excel.RoutingExcelData;
import com.chinaztt.mes.technology.excel.RoutingFormUploadListener;
import com.chinaztt.mes.technology.excel.RoutingUploadListener;
import com.chinaztt.mes.technology.service.RoutingService;
import com.chinaztt.ztt.common.core.util.R;
import com.chinaztt.ztt.common.log.annotation.SysLog;
import com.chinaztt.ztt.common.security.annotation.Inner;
import com.chinaztt.ztt.common.security.service.ZttUser;
import com.chinaztt.ztt.common.security.util.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
 
 
/**
 * 工艺
 *
 * @author zhangxy
 * @date 2020-08-19 09:36:29
 */
@RestController
@AllArgsConstructor
@RequestMapping("/routing")
@Api(value = "routing", tags = "工艺管理")
public class RoutingController {
 
    private final RoutingService routingService;
    private final DictUtils dictUtils;
 
    /**
     * 工序详情
     *
     * @param operationId
     * @param routingOperationId
     * @return
     */
    @ApiOperation(value = "工序详情", notes = "工序详情")
    @GetMapping("/operationDetail")
    @PreAuthorize("@pms.hasPermission('technology_routing_view')")
    public R operationDetail(Long operationId, Long routingOperationId) {
        return R.ok(routingService.operationDetail(operationId, routingOperationId));
    }
 
 
    /**
     * 分页查询
     *
     * @param page    分页对象
     * @param routing 工艺
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    @PreAuthorize("@pms.hasPermission('technology_routing_view')")
    public R getRoutingPage(Page page, RoutingDTO routing) {
        return R.ok(routingService.getPage(page, QueryWrapperUtil.gen(routing)));
    }
 
 
    /**
     * 修改工作中心
     *
     * @param
     * @return R
     */
    @ApiOperation(value = "修改工作中心", notes = "修改工作中心")
    @SysLog("修改工作中心")
    @PostMapping("/routingOperationChange")
    public R routingOperationChange(@RequestBody RoutingOperationDTO routingOperation) {
        return R.ok(routingService.routingOperationChange(routingOperation));
    }
 
    /**
     * 通过id查询工艺
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('technology_routing_view')")
    public R getById(@PathVariable("id") Long id) {
        return R.ok(routingService.getRoutingById(id));
    }
 
 
    /**
     * 批量对接IFS
     *
     * @param ids
     * @return R
     */
    @ApiOperation(value = "批量对接IFS", notes = "批量对接IFS")
    @PostMapping("/routingIfsSync")
    public R routingIfsSync(@RequestBody List<Long> ids) {
        return R.ok(routingService.routingIfsSync(ids));
    }
 
    /**
     * 工艺路线替代提前计算
     *
     * @param ids
     * @return R
     */
    @ApiOperation(value = "工艺路线替代提前计算", notes = "工艺路线替代提前计算")
    @PostMapping("/routingIfsCal")
    public R routingIfsCal(@RequestBody List<Long> ids) {
        return R.ok(routingService.routingIfsCal(ids));
    }
 
 
    /**
     * 新增工艺
     *
     * @param routing 工艺
     * @return R
     */
    @ApiOperation(value = "新增工艺", notes = "新增工艺")
    @SysLog("新增工艺")
    @PostMapping
    @PreAuthorize("@pms.hasPermission('technology_routing_add')")
    public R save(@RequestBody RoutingDTO routing) {
        return R.ok(routingService.fullSave(routing));
    }
 
    /**
     * 修改工艺
     *
     * @param routing 工艺
     * @return R
     */
    @ApiOperation(value = "修改工艺", notes = "修改工艺")
    @SysLog("修改工艺")
    @PutMapping
    @PreAuthorize("@pms.hasPermission('technology_routing_edit')")
    public R updateById(@RequestBody RoutingDTO routing) {
        return R.ok(routingService.fullUpdate(routing));
    }
 
    /**
     * 通过id删除工艺
     *
     * @param ids ids
     * @return R
     */
    @ApiOperation(value = "通过id删除工艺", notes = "通过id删除工艺")
    @SysLog("通过id删除工艺")
    @DeleteMapping
    @PreAuthorize("@pms.hasPermission('technology_routing_del')")
    public R removeById(@RequestBody List<Long> ids) {
        return R.ok(routingService.removeByIds(ids));
    }
 
 
    /**
     * 批准、作废
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "更改状态", notes = "更改状态")
    @SysLog("更改状态")
    @PostMapping("/state/{id}/{event}")
    @PreAuthorize("@pms.hasPermission('technology_routing_edit')")
    public R changeState(@PathVariable Long id, @PathVariable String event) {
        return routingService.changeState(id, event);
    }
 
 
    /**
     * 批准、作废
     *
     * @param
     * @return
     */
    @ApiOperation(value = "更改状态", notes = "更改状态")
    @SysLog("更改状态")
    @PostMapping("/state/{event}")
    public R changeState(@RequestBody List<Long> ids, @PathVariable String event) {
        return R.ok(routingService.changeState(ids, event));
    }
 
 
    /**
     * 根据工艺id和工序id获取复制的工序模板
     *
     * @param routingDTO
     * @return
     */
    @ApiOperation(value = "根据工艺id和工序id获取复制的工序模板", notes = "根据工艺id和工序id获取复制的工序模板")
    @GetMapping("/routingTemplate")
    public R getOperationTemplate(RoutingDTO routingDTO) {
        return R.ok(routingService.getOperationTemplate(routingDTO));
    }
 
    /**
     * 获取工艺工序参数集
     *
     * @param page
     * @param routingOperationTemplate
     * @return
     */
    @ApiOperation(value = "获取工艺工序参数集", notes = "获取工艺工序参数集")
    @GetMapping("/routingOperationTemplate/page")
    public R getRoutingOperationTemplatePage(Page page, RoutingOperationTemplate routingOperationTemplate) {
        return R.ok(routingService.getRoutingOperationTemplatePage(page, QueryWrapperUtil.gen(routingOperationTemplate)));
    }
 
    /**
     * 根据工艺工序id和工序模板id获取工序参数
     *
     * @param routingDTO
     * @return
     */
    @ApiOperation(value = "根据工艺工序id和工序模板id获取工序参数", notes = "根据工艺工序id和工序模板id获取工序参数")
    @GetMapping("/routingTemplateParam")
    public R getOperationTemplateParam(RoutingDTO routingDTO) {
        return R.ok(routingService.getOperationTemplateParam(routingDTO));
    }
 
    /**
     * 复制工艺路线
     *
     * @param routing 工艺
     * @return R
     */
    @ApiOperation(value = "复制工艺路线", notes = "复制工艺路线")
    @SysLog("复制工艺路线")
    @PostMapping("/copy")
    public R copyRoutingSave(@RequestBody List<RoutingDTO> routing) {
        return routingService.copyRoutingSave(routing);
    }
 
    /**
     * 根据工艺工序id关联添加工序模板
     *
     * @param routingDTO
     * @return
     */
    @ApiOperation(value = "根据工艺工序id关联添加工序模板", notes = "根据工艺工序id关联添加工序模板")
    @PostMapping("/addRoutingTemplate")
    public R addOperationTemplate(@RequestBody RoutingDTO routingDTO) {
        return R.ok(routingService.addOperationTemplate(routingDTO));
    }
 
    /**
     * 根据复制工序模板的id删除工序模板
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "根据复制工序模板的id删除工序模板", notes = "根据复制工序模板的id删除工序模板")
    @DeleteMapping("/deleteRoutingTemplate/{id}")
    public R deleteOperationTemplate(@PathVariable Long id) {
        return R.ok(routingService.deleteOperationTemplate(id));
    }
 
    /**
     * 根据工艺工序id和工序模板id关联添加工序参数
     *
     * @param routingDTO
     * @return
     */
    @ApiOperation(value = "根据工艺工序id和工序模板id关联添加工序参数", notes = "根据工艺工序id和工序模板id关联添加工序参数")
    @PostMapping("/addRoutingTemplateParam")
    public R addOperationTemplateParam(@RequestBody RoutingDTO routingDTO) {
        return R.ok(routingService.addOperationTemplateParam(routingDTO));
    }
 
    /**
     * 根据复制工序参数的id删除工序参数
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "根据复制工序参数的id删除工序参数", notes = "根据复制工序参数的id删除工序参数")
    @DeleteMapping("/deleteRoutingTemplateParam/{id}")
    public R deleteOperationTemplateParam(@PathVariable Long id) {
        return R.ok(routingService.deleteOperationTemplateParam(id));
    }
 
    /**
     * 工序参数的参数值的修改
     *
     * @param routing 工艺
     * @return R
     */
    @ApiOperation(value = "工序参数的参数值的修改", notes = "工序参数的参数值的修改")
    @SysLog("工序参数的参数值的修改")
    @PutMapping("routingTemplateParam")
    public R updateRoutingTemplateParamById(@RequestBody RoutingDTO routing) {
        return routingService.updateRoutingTemplateParamById(routing);
    }
 
 
    /**
     * excel上传
     *
     * @return
     */
    @PostMapping("/uploadExcel")
    public R uploadExcel(@RequestParam("file") MultipartFile file) {
        ZttUser currentUser = SecurityUtils.getUser();
        System.out.println(currentUser);
        //初始化监听器
        RoutingFormUploadListener routingFormUploadListener = new RoutingFormUploadListener(routingService);
        HashMap<String, Object> result = new HashMap<>();
        try {
            ExcelReaderBuilder excelReaderBuilder = EasyExcel.read(file.getInputStream());
            ExcelReader excelReader = excelReaderBuilder.build();
            List<ReadSheet> sheets = excelReader.excelExecutor().sheetList();
            List<ReadSheet> readSheetList = new ArrayList<>();
            for (ReadSheet sheet : sheets) {
                ReadSheet readSheet = EasyExcel.readSheet(sheet.getSheetName()).registerReadListener(new RoutingFormUploadListener(routingService)).build();
                readSheetList.add(readSheet);
            }
            excelReader.read(readSheetList);
            // 这里千万别忘记关闭,读的时候会创建临时文件,到时磁盘会崩的
            excelReader.finish();
        } catch (IOException e) {
            e.printStackTrace();
            return R.failed(e.getMessage());
        }
        return R.ok();
    }
 
    /**
     * 竖着导入
     *
     * @param file
     * @return
     */
    @PostMapping("/upload")
    public R simpleRead(@RequestParam("file") MultipartFile file) {
        ExcelReader excelReader = null;
        try {
            excelReader = EasyExcel.read(file.getInputStream(), RoutingExcelData.class, new RoutingUploadListener(routingService, dictUtils)).build();
            ReadSheet readSheet = EasyExcel.readSheet(0).build();
            excelReader.read(readSheet);
        } catch (IOException e) {
            e.printStackTrace();
            return R.failed(e.getMessage());
        } finally {
            if (excelReader != null) {
                // 这里千万别忘记关闭,读的时候会创建临时文件,到时磁盘会崩的
                excelReader.finish();
            }
        }
        return R.ok();
    }
 
    /**
     * 查询模板与参数
     *
     * @param routingOperationId
     * @return
     */
    @GetMapping("/templateAndParam/{routingOperationId}")
    public R getOperationTemplateAndParam(@PathVariable Long routingOperationId) {
        return routingService.getOperationTemplateAndParam(routingOperationId);
    }
 
 
    /**
     * 导入模板下载
     *
     * @return
     */
    @ApiOperation(value = "导入模板下载", notes = "导入模板下载")
    @GetMapping("/exportModel")
    public void exportModel(HttpServletResponse response) throws IOException {
        routingService.exportModel(response);
    }
 
    /**
     * 根据工艺文件id和工序id查询工艺路线
     *
     * @param documentId
     * @param operationId
     * @return
     */
    @GetMapping("/getRoutingByDocumentIdAndOperationId")
    public R getRoutingByDocumentIdAndOperationId(Long documentId, Long operationId) {
        return R.ok(routingService.getRoutingByDocumentIdAndOperationId(documentId, operationId));
    }
}