gaoluyang
昨天 8c65f898ed6e5b0c7a94c792c4562f6ec831dccd
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
package cn.iocoder.yudao.module.mes.controller.admin.qc.template;
 
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.mes.controller.admin.qc.template.vo.MesQcTemplateProcessRespVO;
import cn.iocoder.yudao.module.mes.controller.admin.qc.template.vo.MesQcTemplateProcessSaveByTemplateReqVO;
import cn.iocoder.yudao.module.mes.controller.admin.qc.template.vo.MesQcTemplateProcessSaveListReqVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.pro.process.MesProProcessDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.qc.template.MesQcTemplateDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.qc.template.MesQcTemplateProcessDO;
import cn.iocoder.yudao.module.mes.service.pro.process.MesProProcessService;
import cn.iocoder.yudao.module.mes.service.qc.template.MesQcTemplateProcessService;
import cn.iocoder.yudao.module.mes.service.qc.template.MesQcTemplateService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
import java.util.Map;
 
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
 
@Tag(name = "管理后台 - MES 质检方案-工序绑定")
@RestController
@RequestMapping("/mes/qc/template-process")
@Validated
public class MesQcTemplateProcessController {
 
    @Resource
    private MesQcTemplateProcessService templateProcessService;
    @Resource
    private MesQcTemplateService templateService;
    @Resource
    private MesProProcessService processService;
 
    @GetMapping("/list")
    @Operation(summary = "获得工序绑定的质检方案列表")
    @Parameter(name = "processId", description = "工序编号", required = true, example = "1024")
    public CommonResult<List<MesQcTemplateProcessRespVO>> getList(@RequestParam("processId") Long processId) {
        List<MesQcTemplateProcessDO> list = templateProcessService.getListByProcessId(processId);
        Map<Long, MesQcTemplateDO> templateMap = templateService.getTemplateMap(
                convertSet(list, MesQcTemplateProcessDO::getTemplateId));
        MesProProcessDO process = processService.getProcess(processId);
        return success(convertList(list, binding -> {
            MesQcTemplateProcessRespVO vo = BeanUtils.toBean(binding, MesQcTemplateProcessRespVO.class);
            MesQcTemplateDO template = templateMap.get(binding.getTemplateId());
            if (template != null) {
                vo.setTemplateCode(template.getCode()).setTemplateName(template.getName());
            }
            if (process != null) {
                vo.setProcessName(process.getName());
            }
            return vo;
        }));
    }
 
    @PostMapping("/save-list")
    @Operation(summary = "批量保存工序绑定的质检方案")
    @PreAuthorize("@ss.hasPermission('mes:qc-template:update')")
    public CommonResult<Boolean> saveList(@Valid @RequestBody MesQcTemplateProcessSaveListReqVO reqVO) {
        templateProcessService.saveList(reqVO);
        return success(true);
    }
 
    @GetMapping("/list-by-template")
    @Operation(summary = "获得质检方案适用的工序列表")
    @Parameter(name = "templateId", description = "质检方案编号", required = true, example = "1024")
    public CommonResult<List<MesQcTemplateProcessRespVO>> getListByTemplate(
            @RequestParam("templateId") Long templateId) {
        List<MesQcTemplateProcessDO> list = templateProcessService.getListByTemplateId(templateId);
        Map<Long, MesProProcessDO> processMap = processService.getProcessMap(
                convertSet(list, MesQcTemplateProcessDO::getProcessId));
        return success(convertList(list, binding -> {
            MesQcTemplateProcessRespVO vo = BeanUtils.toBean(binding, MesQcTemplateProcessRespVO.class);
            MesProProcessDO process = processMap.get(binding.getProcessId());
            if (process != null) {
                vo.setProcessName(process.getName());
            }
            return vo;
        }));
    }
 
    @PostMapping("/save-by-template")
    @Operation(summary = "批量保存质检方案适用的工序")
    @PreAuthorize("@ss.hasPermission('mes:qc-template:update')")
    public CommonResult<Boolean> saveByTemplate(
            @Valid @RequestBody MesQcTemplateProcessSaveByTemplateReqVO reqVO) {
        templateProcessService.saveByTemplate(reqVO);
        return success(true);
    }
 
}