李林
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
/*
 *    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.common.wrapper.QueryWrapperUtil;
import com.chinaztt.mes.technology.dto.OperationDTO;
import com.chinaztt.mes.technology.entity.Operation;
import com.chinaztt.mes.technology.entity.OperationJoinStep;
import com.chinaztt.mes.technology.entity.OperationJoinTemplate;
import com.chinaztt.mes.technology.excel.OperationData;
import com.chinaztt.mes.technology.excel.OperationUploadListener;
import com.chinaztt.mes.technology.excel.TestStandardBindingUploadListener;
import com.chinaztt.mes.technology.service.OperationService;
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 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.List;
 
 
/**
 * 工序
 *
 * @author zhangxy
 * @date 2020-08-18 10:22:27
 */
@RestController
@AllArgsConstructor
@RequestMapping("/operation")
@Api(value = "operation", tags = "工序管理")
public class OperationController {
 
    private final OperationService operationService;
 
    /**
     * 分页查询
     *
     * @param page      分页对象
     * @param operation 工序
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    @PreAuthorize("@pms.hasPermission('technology_operation_view')")
    public R getTechnologyOperationPage(Page page, Operation operation) {
        return R.ok(operationService.getOperationPage(page, QueryWrapperUtil.gen(operation)));
    }
 
    /**
     * 根据工序id和工序模板id删除关联表
     *
     * @param operationJoinTemplate 工序模板
     * @return
     */
    @ApiOperation(value = "根据工序id和工序模板id删除关联表", notes = "根据工序id和工序模板id删除关联表")
    @PostMapping("/operationTemplate")
    public R deleteOperationTemplate(@RequestBody OperationJoinTemplate operationJoinTemplate) {
        return R.ok(operationService.deleteOperationTemplate(operationJoinTemplate));
    }
 
    /**
     * 通过id查询工序
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('technology_operation_view')")
    public R getById(@PathVariable("id") Long id) {
        return R.ok(operationService.getFullById(id));
    }
 
    /**
     * 新增工序
     *
     * @param operation 工序
     * @return R
     */
    @ApiOperation(value = "新增工序", notes = "新增工序")
    @SysLog("新增工序")
    @PostMapping
    @PreAuthorize("@pms.hasPermission('technology_operation_add')")
    public R save(@RequestBody OperationDTO operation) {
        return operationService.fullSave(operation);
    }
 
 
    /**
     * 修改工序
     *
     * @param operation 工序
     * @return R
     */
    @ApiOperation(value = "修改工序", notes = "修改工序")
    @SysLog("修改工序")
    @PutMapping
    @PreAuthorize("@pms.hasPermission('technology_operation_edit')")
    public R updateById(@RequestBody OperationDTO operation) {
        return operationService.fullUpdate(operation);
    }
 
    /**
     * 新增工序与模板的关联
     *
     * @param operation 工序
     * @return R
     */
    @ApiOperation(value = "新增工序与模板的关联", notes = "新增工序与模板的关联")
    @SysLog("新增工序与模板的关联")
    @PostMapping("saveOperationTemplate")
    public R saveOperationTemplate(@RequestBody OperationDTO operation) {
        return operationService.saveOperationTemplate(operation);
    }
 
    /**
     * 新增工序与工步的关联
     *
     * @param operationJoinStepList 工序
     * @return R
     */
    @ApiOperation(value = "新增工序与工步的关联", notes = "新增工序与工步的关联")
    @SysLog("新增工序与工步的关联")
    @PostMapping("saveOperationStep/{id}")
    public R saveOperationStep(@RequestBody List<OperationJoinStep> operationJoinStepList, @PathVariable("id") Long id) {
        return R.ok(operationService.saveOperationStep(operationJoinStepList, id));
    }
 
    /**
     * excel上传
     *
     * @return
     */
    @PostMapping("/excel/upload")
    public R upload(@RequestParam("file") MultipartFile file) {
        try {
            EasyExcel.read(file.getInputStream(), OperationData.class, new OperationUploadListener(operationService)).sheet().doRead();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return R.ok();
    }
 
    /**
     * 上传文件
     *
     * @param file
     * @return
     */
    @PostMapping("/upload")
    public R upload(@RequestParam("operationId") Long operationId, @RequestParam("file") MultipartFile file) {
        return operationService.uploadFile(file, operationId);
    }
 
 
    /**
     * 通过id删除工序
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除工序", notes = "通过id删除工序")
    @SysLog("通过id删除工序")
    @DeleteMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('technology_operation_del')")
    public R removeById(@PathVariable Long id) {
        return operationService.fullDelete(id);
    }
 
    /**
     * @param fileName
     * @return
     */
    @ApiOperation(value = "通过文件名删除附件", notes = "通过文件名删除附件")
    @SysLog("通过文件名删除附件")
    @DeleteMapping("/removeFile")
    @PreAuthorize("@pms.hasPermission('technology_operation_edit')")
    public R removeFileById(String fileName) {
        return operationService.deleteFile(fileName);
    }
 
 
    /**
     * 获取文件
     *
     * @param bucket   桶名称
     * @param fileName 文件空间/名称
     * @param response
     * @return
     */
    @Inner(false)
    @GetMapping("/{bucket}/{fileName}")
    public void file(@PathVariable String bucket, @PathVariable String fileName, HttpServletResponse response) {
        operationService.getFile(bucket, fileName, response);
    }
 
 
    /**
     * 获取ifs人工类别接口
     *
     * @param laborClassNo 人工类别接口
     * @return R
     */
    @ApiOperation(value = "获取ifs人工类别接口", notes = "获取ifs人工类别接口")
    @SysLog("获取ifs人工类别接口")
    @GetMapping("/getIfsLaborClass")
    public R getIfsLaborClass(String laborClassNo) {
        return operationService.getIfsLaborClass(laborClassNo);
    }
 
    /**
     *
     * @param file
     * @return
     */
    @PostMapping("/importTestStandardBindingExcel")
    public R importTestStandardBindingExcel(@RequestParam("file") MultipartFile file) {
        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 TestStandardBindingUploadListener(operationService)).build();
                readSheetList.add(readSheet);
            }
            excelReader.read(readSheetList);
            // 这里千万别忘记关闭,读的时候会创建临时文件,到时磁盘会崩的
            excelReader.finish();
        } catch (IOException e) {
            e.printStackTrace();
            return R.failed(e.getMessage());
        }
        return R.ok();
    }
 
 
}