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
package cn.iocoder.yudao.module.mes.controller.admin.qc.ledger;
 
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
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.dict.core.DictFrameworkUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.module.mes.controller.admin.qc.ledger.vo.MesQcInspectionLedgerExportVO;
import cn.iocoder.yudao.module.mes.controller.admin.qc.ledger.vo.MesQcInspectionLedgerPageReqVO;
import cn.iocoder.yudao.module.mes.controller.admin.qc.ledger.vo.MesQcInspectionLedgerRespVO;
import cn.iocoder.yudao.module.mes.controller.admin.qc.vo.MesQcQualityExportVO;
import cn.iocoder.yudao.module.mes.enums.DictTypeConstants;
import cn.iocoder.yudao.module.mes.enums.qc.MesQcTypeEnum;
import cn.iocoder.yudao.module.mes.service.qc.ledger.MesQcInspectionLedgerService;
import io.swagger.v3.oas.annotations.Operation;
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.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
 
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
 
@Tag(name = "管理后台 - MES 检测结果台账")
@RestController
@RequestMapping("/mes/qc/inspection-ledger")
@Validated
public class MesQcInspectionLedgerController {
 
    @Resource
    private MesQcInspectionLedgerService ledgerService;
 
    @GetMapping("/page")
    @Operation(summary = "获得检测结果台账分页(四类检验单统一查询)")
    @PreAuthorize("@ss.hasPermission('mes:qc-inspection-ledger:query')")
    public CommonResult<PageResult<MesQcInspectionLedgerRespVO>> getInspectionLedgerPage(
            @Valid MesQcInspectionLedgerPageReqVO pageReqVO) {
        return success(ledgerService.getInspectionLedgerPage(pageReqVO));
    }
 
    @GetMapping("/export-excel")
    @Operation(summary = "导出检测结果台账 Excel")
    @PreAuthorize("@ss.hasPermission('mes:qc-inspection-ledger:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportInspectionLedgerExcel(@Valid MesQcInspectionLedgerPageReqVO pageReqVO,
                                            HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<MesQcInspectionLedgerRespVO> list = ledgerService.getInspectionLedgerPage(pageReqVO).getList();
        ExcelUtils.write(response, "检测结果台账.xls", "检测结果台账",
                MesQcInspectionLedgerExportVO.class, buildExportList(list));
    }
 
    private List<MesQcInspectionLedgerExportVO> buildExportList(List<MesQcInspectionLedgerRespVO> list) {
        if (CollUtil.isEmpty(list)) {
            return new ArrayList<>();
        }
        List<MesQcInspectionLedgerExportVO> exportList = new ArrayList<>(list.size());
        for (MesQcInspectionLedgerRespVO vo : list) {
            MesQcInspectionLedgerExportVO export = new MesQcInspectionLedgerExportVO();
            export.setQcTypeName(qcTypeName(vo.getQcType()));
            export.setCode(vo.getCode());
            export.setName(vo.getName());
            export.setItemCode(vo.getItemCode());
            export.setItemName(vo.getItemName());
            export.setItemSpecification(vo.getItemSpecification());
            export.setBatchNo(vo.getBatchNo());
            export.setIndicatorName(vo.getIndicatorName());
            export.setIndicatorValue(vo.getIndicatorValue());
            export.setJudgementBasis(vo.getJudgementBasis());
            export.setCheckResultText(parseDictLabel(DictTypeConstants.MES_QC_CHECK_RESULT, vo.getCheckResult()));
            export.setCheckQuantity(MesQcQualityExportVO.formatDecimal(vo.getCheckQuantity()));
            export.setQualifiedQuantity(MesQcQualityExportVO.formatDecimal(vo.getQualifiedQuantity()));
            export.setUnqualifiedQuantity(MesQcQualityExportVO.formatDecimal(vo.getUnqualifiedQuantity()));
            export.setInspectorName(vo.getInspectorName());
            export.setInspectDate(MesQcQualityExportVO.formatDateTime(vo.getInspectDate()));
            export.setStatusText(parseDictLabel(DictTypeConstants.MES_ORDER_STATUS, vo.getStatus()));
            export.setRemark(vo.getRemark());
            exportList.add(export);
        }
        return exportList;
    }
 
    private static String qcTypeName(Integer qcType) {
        for (MesQcTypeEnum e : MesQcTypeEnum.values()) {
            if (Objects.equals(e.getType(), qcType)) {
                return e.getName();
            }
        }
        return "";
    }
 
    private static String parseDictLabel(String dictType, Integer value) {
        if (value == null) {
            return "";
        }
        String label = DictFrameworkUtils.parseDictDataLabel(dictType, String.valueOf(value));
        return StrUtil.nullToEmpty(label);
    }
 
}