gaoluyang
2026-10-16 7081c41bc3beb0ab49a22974ea4b010ae6854afe
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
package cn.iocoder.yudao.module.mes.controller.admin.qc.indicator;
 
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.module.mes.controller.admin.qc.indicator.vo.MesQcIndicatorPageReqVO;
import cn.iocoder.yudao.module.mes.controller.admin.qc.indicator.vo.MesQcIndicatorRespVO;
import cn.iocoder.yudao.module.mes.controller.admin.qc.indicator.vo.MesQcIndicatorSaveReqVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.qc.indicator.MesQcIndicatorDO;
import cn.iocoder.yudao.module.mes.service.qc.indicator.MesQcIndicatorService;
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.servlet.http.HttpServletResponse;
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.io.IOException;
import java.util.List;
 
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import org.springframework.web.multipart.MultipartFile;
import io.swagger.v3.oas.annotations.Parameters;
import java.util.Collections;
import cn.iocoder.yudao.module.mes.controller.admin.qc.indicator.vo.MesQcIndicatorImportExcelVO;
import cn.iocoder.yudao.module.mes.controller.admin.qc.indicator.vo.MesQcIndicatorImportRespVO;
 
@Tag(name = "管理后台 - MES 质检指标")
@RestController
@RequestMapping("/mes/qc/indicator")
@Validated
public class MesQcIndicatorController {
 
    @Resource
    private MesQcIndicatorService indicatorService;
 
    @PostMapping("/create")
    @Operation(summary = "创建质检指标")
    @PreAuthorize("@ss.hasPermission('mes:qc-indicator:create')")
    public CommonResult<Long> createIndicator(@Valid @RequestBody MesQcIndicatorSaveReqVO createReqVO) {
        return success(indicatorService.createIndicator(createReqVO));
    }
 
    @PutMapping("/update")
    @Operation(summary = "更新质检指标")
    @PreAuthorize("@ss.hasPermission('mes:qc-indicator:update')")
    public CommonResult<Boolean> updateIndicator(@Valid @RequestBody MesQcIndicatorSaveReqVO updateReqVO) {
        indicatorService.updateIndicator(updateReqVO);
        return success(true);
    }
 
    @DeleteMapping("/delete")
    @Operation(summary = "删除质检指标")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('mes:qc-indicator:delete')")
    public CommonResult<Boolean> deleteIndicator(@RequestParam("id") Long id) {
        indicatorService.deleteIndicator(id);
        return success(true);
    }
 
    @GetMapping("/get")
    @Operation(summary = "获得质检指标")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('mes:qc-indicator:query')")
    public CommonResult<MesQcIndicatorRespVO> getIndicator(@RequestParam("id") Long id) {
        MesQcIndicatorDO indicator = indicatorService.getIndicator(id);
        return success(BeanUtils.toBean(indicator, MesQcIndicatorRespVO.class));
    }
 
    @GetMapping("/page")
    @Operation(summary = "获得质检指标分页")
    @PreAuthorize("@ss.hasPermission('mes:qc-indicator:query')")
    public CommonResult<PageResult<MesQcIndicatorRespVO>> getIndicatorPage(@Valid MesQcIndicatorPageReqVO pageReqVO) {
        PageResult<MesQcIndicatorDO> pageResult = indicatorService.getIndicatorPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, MesQcIndicatorRespVO.class));
    }
 
    @GetMapping("/export-excel")
    @Operation(summary = "导出质检指标 Excel")
    @PreAuthorize("@ss.hasPermission('mes:qc-indicator:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportIndicatorExcel(@Valid MesQcIndicatorPageReqVO pageReqVO,
                                     HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<MesQcIndicatorDO> list = indicatorService.getIndicatorPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "质检指标.xls", "数据", MesQcIndicatorRespVO.class,
                BeanUtils.toBean(list, MesQcIndicatorRespVO.class));
    }
 
 
    @GetMapping("/get-import-template")
    @Operation(summary = "获得质检指标导入模板")
    public void importTemplate(HttpServletResponse response) throws IOException {
        // 手动创建导出 demo
        List<MesQcIndicatorImportExcelVO> list = Collections.singletonList(
                MesQcIndicatorImportExcelVO.builder()
                        .code("QC-001").name("外观检查").type(1).tool("目视")
                        .resultType(1).resultSpecification("无划伤")
                        .remark("")
                        .build()
        );
        // 输出
        ExcelUtils.write(response, "质检指标导入模板.xls", "质检指标列表", MesQcIndicatorImportExcelVO.class, list);
    }
 
    @PostMapping("/import")
    @Operation(summary = "导入质检指标")
    @Parameters({
            @Parameter(name = "file", description = "Excel 文件", required = true),
            @Parameter(name = "updateSupport", description = "是否支持更新,默认为 false", example = "true")
    })
    @PreAuthorize("@ss.hasPermission('mes:qc-indicator:import')")
    public CommonResult<MesQcIndicatorImportRespVO> importExcel(@RequestParam("file") MultipartFile file,
                                                           @RequestParam(value = "updateSupport", required = false,
                                                                   defaultValue = "false") Boolean updateSupport) throws Exception {
        List<MesQcIndicatorImportExcelVO> list = ExcelUtils.read(file, MesQcIndicatorImportExcelVO.class);
        return success(indicatorService.importIndicatorList(list, updateSupport));
    }
 
}