zss
2023-11-07 3c34085a21511610477f555cebf3f6fa42272402
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
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
/*
 *    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.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chinaztt.mes.common.wrapper.QueryWrapperUtil;
import com.chinaztt.mes.quality.dto.TestStandardDTO;
import com.chinaztt.mes.technology.dto.BatchAddDocSamplingRuleParamDTO;
import com.chinaztt.mes.technology.dto.BatchAddDocTestStandardParamDTO;
import com.chinaztt.mes.technology.dto.JoinDocumentTestStandardDTO;
import com.chinaztt.mes.technology.entity.Document;
import com.chinaztt.mes.technology.entity.DocumentStandardParam;
import com.chinaztt.mes.technology.entity.JoinDocumentBomRouting;
import com.chinaztt.mes.technology.excel.DocumentTestStandardData;
import com.chinaztt.mes.technology.excel.DocumentTestStandardUploadListener;
import com.chinaztt.mes.technology.service.DocumentService;
import com.chinaztt.mes.technology.state.document.constant.DocumentStates;
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.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
 
 
/**
 * 工艺文件
 *
 * @author zhangxy
 * @date 2021-05-07 09:45:58
 */
@RestController
@AllArgsConstructor
@RequestMapping("/document")
@Api(value = "document", tags = "工艺文件管理")
public class DocumentController {
 
    private final DocumentService documentService;
 
    /**
     * 分页查询
     *
     * @param page     分页对象
     * @param document 工艺文件
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    public R getDocumentPage(Page page, Document document) {
        return R.ok(documentService.page(page, QueryWrapperUtil.gen(document).orderByDesc("id")));
    }
 
    /**
     * 通过id查询工艺文件
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}")
    public R getById(@PathVariable("id") Long id) {
        return R.ok(documentService.getDtoById(id));
    }
 
    /**
     * 通过id查询工艺文件绑定的检测规则
     *
     * @param testStandardDTO id
     * @return R
     */
    @ApiOperation(value = "通过id查询工艺文件绑定的检测规则", notes = "通过id查询工艺文件绑定的检测规则")
    @GetMapping("/getTestStand")
    public R getTestStand(Page page, TestStandardDTO testStandardDTO) {
        Long id = testStandardDTO.getDocumentId();
        testStandardDTO.setDocumentId(null);
        return R.ok(documentService.getTestStand(page, QueryWrapperUtil.gen(testStandardDTO), id));
    }
 
    /**
     * 新增工艺文件
     *
     * @param document 工艺文件
     * @return R
     */
    @ApiOperation(value = "新增工艺文件", notes = "新增工艺文件")
    @SysLog("新增工艺文件")
    @PostMapping
    public R save(@RequestBody Document document) {
        return documentService.fullSave(document);
    }
 
    /**
     * 修改工艺文件
     *
     * @param document 工艺文件
     * @return R
     */
    @ApiOperation(value = "修改工艺文件", notes = "修改工艺文件")
    @SysLog("修改工艺文件")
    @PutMapping
    public R updateById(@RequestBody Document document) {
        return R.ok(documentService.fullUpdate(document));
    }
 
    /**
     * 通过id删除工艺文件
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除工艺文件", notes = "通过id删除工艺文件")
    @SysLog("通过id删除工艺文件")
    @DeleteMapping("/{id}")
    public R removeById(@PathVariable Long id) {
        return R.ok(documentService.removeById(id));
    }
 
    /**
     * 通过id删除工艺文件
     *
     * @param ids id
     * @return R
     */
    @ApiOperation(value = "批量删除工艺文件", notes = "批量删除工艺文件")
    @SysLog("批量删除工艺文件")
    @PostMapping("/batchDel")
    public R batchDel(@RequestBody List<Long> ids) {
        return R.ok(documentService.batchDel(ids));
    }
 
    /**
     * 计算材料用量
     *
     * @param documentId
     * @return
     */
    @PostMapping("/calcMaterialCost/{documentId}")
    public R calcMaterialCost(@PathVariable Long documentId) {
        return documentService.calcMaterialCost(documentId);
    }
 
    /**
     * 保存工艺文件与BOM关系
     *
     * @param join
     * @return
     */
    @PostMapping("/saveBom")
    public R saveBom(@RequestBody JoinDocumentBomRouting join) {
        return documentService.saveBom(join);
    }
 
    /**
     * 保存流程图json
     *
     * @param document
     * @return
     */
    @PostMapping("/saveLctJson")
    public R saveLctJson(@RequestBody Document document) {
        return R.ok(documentService.updateById(documentService.doUpdateRealUser(document)));
    }
 
    /**
     * 获取流程图json
     *
     * @param id
     * @return
     */
    @GetMapping("/getLctJson/{id}")
    public R getLctJson(@PathVariable("id") Long id) {
        return R.ok(documentService.getById(id).getLctJson());
    }
 
    /**
     * 保存工艺文件与检测标准关系
     *
     * @param joins
     * @return
     */
    @PostMapping("/saveTestStandard")
    public R saveTestStandard(@RequestBody List<JoinDocumentTestStandardDTO> joins) {
        return documentService.saveTestStandard(joins);
    }
 
    /**
     * 删除工艺文件与检测标准关系
     *
     * @param join
     * @return
     */
    @PostMapping("/deleteTestStandard")
    public R deleteTestStandard(@RequestBody JoinDocumentTestStandardDTO join) {
        return documentService.deleteTestStandard(join);
    }
 
    /**
     * 删除工艺文件与BOM关系
     *
     * @param join
     * @return
     */
    @PostMapping("/deleteBom")
    public R deleteBom(@RequestBody JoinDocumentBomRouting join) {
        return documentService.deleteBom(join);
    }
 
    /**
     * 工艺路线判断是否有子节点
     *
     * @param id
     * @return
     */
    @GetMapping("/routingChildCheck/{id}")
    public R routingChildCheck(@PathVariable Long id) {
        return documentService.routingChildCheck(id);
    }
 
    /**
     * 原材料用量导出
     *
     * @param documentId
     * @param response
     */
    @ApiOperation(value = "导出原材料用量", notes = "导出原材料用量")
    @GetMapping("/exportMaterialCost/{documentId}")
    public void exportDutyRecord(@PathVariable Long documentId, HttpServletResponse response) {
        documentService.exportMaterialCost(documentId, response);
    }
 
    /**
     * 上传结构图文件
     *
     * @param file
     * @return
     */
    @PostMapping("/uploadJgt")
    public R uploadJgt(@RequestParam("file") MultipartFile file, @RequestParam("documentId") Long documentId) {
        return documentService.uploadJgt(file, documentId);
    }
 
    /**
     * 删除结构图
     *
     * @param jgtId
     * @return
     */
    @PostMapping("/removeJgt/{jgtId}")
    public R removeJgt(@PathVariable Long jgtId) {
        return documentService.removeJgt(jgtId);
    }
 
    /**
     * 删除流程图
     *
     * @param documentId
     * @return
     */
    @PostMapping("/removeLct/{documentId}")
    public R removeLct(@PathVariable Long documentId) {
        return documentService.removeLct(documentId);
    }
 
    /**
     * 上传流程图文件
     *
     * @param file
     * @return
     */
    @PostMapping("/uploadLct")
    public R uploadLct(@RequestParam("file") MultipartFile file, @RequestParam("documentId") Long documentId, @RequestParam("lctRemark") String lctRemark) {
        return documentService.uploadLct(file, documentId, lctRemark);
    }
 
    /**
     * 查看附件图片
     *
     * @param fileName
     * @param response
     */
    @Inner(value = false)
    @GetMapping("/file")
    public void file(@RequestParam("fileName") String fileName, HttpServletResponse response) {
        documentService.getFile(fileName, response);
    }
 
    /**
     * 复制工艺路线
     *
     * @param documentList 工艺
     * @return R
     */
    @ApiOperation(value = "复制工艺路线", notes = "复制工艺路线")
    @SysLog("复制工艺路线")
    @PostMapping("/copy")
    public R copyDocument(@RequestBody List<Document> documentList) {
        return documentService.copyDocument(documentList);
    }
 
    /**
     * 通过id查询工艺文件(oa页面展示)
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询工艺文件(oa页面展示)", notes = "通过id查询工艺文件(oa页面展示)")
    @GetMapping("/oa/{id}")
    @Inner(value = false)
    public R getDocumentById(@PathVariable("id") Long id) {
        return R.ok(documentService.getDocumentById(id));
    }
 
    /**
     * 批准
     *
     * @param ids
     * @return
     */
    @SysLog("修改工艺文件状态为批准")
    @PostMapping("/accept")
    public R accept(@RequestBody List<Long> ids) {
        return R.ok(documentService.updateStateByIds(ids, DocumentStates.ACCEPTED));
    }
 
    /**
     * 拒绝
     *
     * @param ids
     * @return
     */
    @SysLog("修改工艺文件状态为拒绝")
    @PostMapping("/reject")
    public R reject(@RequestBody List<Long> ids) {
        return R.ok(documentService.updateStateByIds(ids, DocumentStates.REJECT));
    }
 
    /**
     * 取消
     *
     * @param ids
     * @return
     */
    @PostMapping("/cancel")
    @SysLog("修改工艺文件状态为草稿")
    public R cancel(@RequestBody List<Long> ids) {
        return R.ok(documentService.updateStateByIds(ids, DocumentStates.DRAFT));
    }
 
    /**
     * 数据同步到ifs
     *
     * @param id
     * @return
     */
    @GetMapping("/ifsSync/{id}")
    public R ifsSync(@PathVariable Long id) {
        try {
            return documentService.ifsSync(id);
        } catch (Exception e) {
            return R.failed(e.getMessage());
        }
    }
 
    /**
     * 工艺文件-工艺路线-工序-检测标准主从表新增
     *
     * @param docBomId           工艺文件与BOM关系表id
     * @param routingOperationId 工艺工序id
     * @param testStandardId     检测标准id
     * @return
     */
    @ApiOperation(value = "工艺文件-工艺路线-工序-检测标准主从表新增", notes = "传参:工艺文件与BOM关系表id&工序id&检测标准id")
    @SysLog("工艺文件-工艺路线-工序-检测标准主从表新增")
    @PostMapping("/addDocTestStandard")
    public R addDocTestStandard(@RequestParam("docBomId") Long docBomId, @RequestParam("routingOperationId") Long routingOperationId, @RequestParam("testStandardId") Long testStandardId) {
        return R.ok(documentService.addDocTestStandard(docBomId, routingOperationId, testStandardId));
    }
 
    /**
     * 工艺文件-工艺路线-工序-检测标准主从表批量新增
     *
     * @param paramList
     * @return
     */
    @ApiOperation(value = "工艺文件-工艺路线-工序-检测标准主从表批量新增", notes = "传参:工艺文件与BOM关系表id&工序id&检测标准id")
    @SysLog("工艺文件-工艺路线-工序-检测标准主从表批量新增")
    @PostMapping("/batchAddDocTestStandard")
    public R batchAddDocTestStandard(@RequestBody List<BatchAddDocTestStandardParamDTO> paramList) {
        for (BatchAddDocTestStandardParamDTO param : paramList) {
            documentService.addDocTestStandard(param.getDocBomId(), param.getRoutingOperationId(), param.getTestStandardId());
        }
        Document document = documentService.changeTestStandard(paramList.get(0).getDocBomId());
        return R.ok(document);
    }
 
    /**
     * 工艺文件-工艺路线-工序-根据检测标准记录id删除检测标准
     *
     * @param id 检测标准id
     * @return
     */
    @ApiOperation(value = "工艺文件-工艺路线-工序-检测标准主表删除", notes = "传参:记录id")
    @SysLog("工艺文件-工艺路线-工序-检测标准删除")
    @DeleteMapping("/delDocTestStandardById/{id}")
    public R delDocTestStandardById(@PathVariable("id") Long id) {
        return R.ok(documentService.delDocTestStandardById(id));
    }
 
    /**
     * 根据工艺文件-工艺路线-工序id查询检测标准
     *
     * @param docBomId           工艺文件与BOM关系表id
     * @param routingOperationId 工艺工序id
     * @return
     */
    @ApiOperation(value = "根据工艺文件-工艺路线-查询检测标准", notes = "传参:工艺文件与BOM关系表id&工序id")
    @GetMapping("/qryDocTestStandard")
    public R qryDocTestStandard(@RequestParam("docBomId") Long docBomId, @RequestParam("routingOperationId") Long routingOperationId) {
        return documentService.qryDocTestStandard(docBomId, routingOperationId);
    }
 
    /**
     * 根据工艺文件-工艺路线-工序-检测标准-根据检测参数id删除记录
     *
     * @param id 检测参数id
     * @return
     */
    @ApiOperation(value = "根据工艺文件-工艺路线-工序-检测标准-检测参数记录删除", notes = "传参:记录id")
    @SysLog("根据工艺文件-工艺路线-工序-检测标准-根据检测参数id删除记录")
    @DeleteMapping("/delDocTestStandardDetailById/{id}")
    public R delDocTestStandardDetailById(@PathVariable("id") Long id) {
        return documentService.delDocTestStandardDetailById(id);
    }
 
    /**
     * 根据工艺文件-工艺路线-工序-检测标准-检测参数明细更新
     *
     * @param documentStandardParamList
     * @return
     */
    @ApiOperation(value = "根据工艺文件-工艺路线-工序-检测标准-检测参数明细更新", notes = "")
    @SysLog("根据工艺文件-工艺路线-工序-检测标准-检测参数明细更新")
    @PostMapping("/updDocTestStandardDetails")
    public R updDocTestStandardDetails(@RequestBody List<DocumentStandardParam> documentStandardParamList) {
        return documentService.updDocTestStandardDetails(documentStandardParamList);
    }
 
    /**
     * 根据工艺文件-工艺路线-工序-检测标准id查询检测参数明细
     *
     * @param standardId 检测标准id
     * @return
     */
    @ApiOperation(value = "根据工艺文件-工艺路线-工序-查询检测参数明细", notes = "传参:检测标准id")
    @GetMapping("/qryDocTestStandardDetailsByStandardId")
    public R qryDocTestStandardDetailsByStandardId(@RequestParam("standardId") Long standardId) {
        return documentService.qryDocTestStandardDetailsByStandardId(standardId);
    }
 
    /**
     * 根据工艺文件-工艺路线-工序-抽检规则-批量新增抽检规则
     * @param paramList
     */
    @ApiOperation(value = "根据工艺文件-工艺路线-工序-抽检规则-批量新增抽检规则")
    @SysLog("根据工艺文件-工艺路线-工序-抽检规则-批量新增抽检规则")
    @PostMapping("/batchAddDocSamplingRule")
    public R batchAddDocSamplingRule(@RequestBody List<BatchAddDocSamplingRuleParamDTO> paramList) {
        for (BatchAddDocSamplingRuleParamDTO param : paramList) {
            documentService.addDocSamplingRule(param.getDocBomId(), param.getRoutingOperationId(), param.getSamplingRuleId(), null, null);
        }
        return R.ok();
    }
 
    /**
     * 根据工艺文件-工艺路线-工序-抽检规则-查询抽检规则
     * @param docBomId
     * @param routingOperationId
     */
    @ApiOperation(value = "根据工艺文件-工艺路线-工序-抽检规则-查询抽检规则")
    @GetMapping("/qryDocSamplingRule")
    public R qryDocSamplingRule(@RequestParam("docBomId") Long docBomId, @RequestParam("routingOperationId") Long routingOperationId) {
        return R.ok(documentService.qryDocSamplingRule(docBomId, routingOperationId));
    }
    /**
     * 导入模板下载
     *
     * @return
     */
    @ApiOperation(value = "导入模板下载", notes = "导入模板下载")
    @GetMapping("/export")
    public void export(HttpServletResponse response) throws IOException {
        documentService.export(response);
    }
 
    /**
     * 导入工单批次
     *
     * @return
     */
    @ApiOperation(value = "工艺文件检测标准导入", notes = "工艺文件检测标准导入")
    @PostMapping("/upload")
    public R upload(@RequestParam("file") MultipartFile file) {
        try {
            EasyExcel.read(file.getInputStream(), DocumentTestStandardData.class, new DocumentTestStandardUploadListener(documentService)).sheet().doRead();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return R.ok();
    }
 
}