liu
2026-10-27 17ce55a3b038ed61d332bb54916de4fa55ba19c6
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
package cn.iocoder.yudao.module.mes.controller.admin.pd.reel;
 
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
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.pd.reel.vo.ProductCtcReelImportExcelVO;
import cn.iocoder.yudao.module.mes.controller.admin.pd.reel.vo.ProductCtcReelImportRespVO;
import cn.iocoder.yudao.module.mes.controller.admin.pd.reel.vo.ProductCtcReelPageReqVO;
import cn.iocoder.yudao.module.mes.controller.admin.pd.reel.vo.ProductCtcReelRespVO;
import cn.iocoder.yudao.module.mes.controller.admin.pd.reel.vo.ProductCtcReelSaveReqVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.pd.ctc.ProductCtcDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.pd.reel.ProductCtcReelDO;
import cn.iocoder.yudao.module.mes.service.pd.ctc.ProductCtcService;
import cn.iocoder.yudao.module.mes.service.pd.reel.ProductCtcReelService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
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 org.springframework.web.multipart.MultipartFile;
 
import java.io.IOException;
import java.util.Collections;
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.convertMap;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
 
@Tag(name = "管理后台 - 换位导线盘具计算")
@RestController
@RequestMapping("/mes/pd/ctc-reel")
@Validated
public class ProductCtcReelController {
 
    @Resource
    private ProductCtcReelService reelService;
 
    @Resource
    private ProductCtcService ctcService;
 
    @PostMapping("/create")
    @Operation(summary = "创建盘具计算记录")
    @PreAuthorize("@ss.hasPermission('mes:pd-ctc-reel:create')")
    public CommonResult<Long> createReel(@Valid @RequestBody ProductCtcReelSaveReqVO createReqVO) {
        return success(reelService.createReel(createReqVO));
    }
 
    @PutMapping("/update")
    @Operation(summary = "更新盘具计算记录")
    @PreAuthorize("@ss.hasPermission('mes:pd-ctc-reel:update')")
    public CommonResult<Boolean> updateReel(@Valid @RequestBody ProductCtcReelSaveReqVO updateReqVO) {
        reelService.updateReel(updateReqVO);
        return success(true);
    }
 
    @DeleteMapping("/delete")
    @Operation(summary = "删除盘具计算记录")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('mes:pd-ctc-reel:delete')")
    public CommonResult<Boolean> deleteReel(@RequestParam("id") Long id) {
        reelService.deleteReel(id);
        return success(true);
    }
 
    @GetMapping("/get")
    @Operation(summary = "获得盘具计算记录")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('mes:pd-ctc-reel:query')")
    public CommonResult<ProductCtcReelRespVO> getReel(@RequestParam("id") Long id) {
        ProductCtcReelDO reel = reelService.getReel(id);
        if (reel == null) {
            return success(null);
        }
        return success(buildReelRespVOList(Collections.singletonList(reel)).get(0));
    }
 
    @GetMapping("/page")
    @Operation(summary = "获得盘具计算记录分页")
    @PreAuthorize("@ss.hasPermission('mes:pd-ctc-reel:query')")
    public CommonResult<PageResult<ProductCtcReelRespVO>> getReelPage(@Valid ProductCtcReelPageReqVO pageReqVO) {
        PageResult<ProductCtcReelDO> pageResult = reelService.getReelPage(pageReqVO);
        return success(new PageResult<>(buildReelRespVOList(pageResult.getList()), pageResult.getTotal()));
    }
 
    @GetMapping("/list-by-ctc")
    @Operation(summary = "获得指定换位导线产品的盘具计算记录列表")
    @Parameter(name = "ctcId", description = "换位导线产品ID", required = true)
    @PreAuthorize("@ss.hasPermission('mes:pd-ctc-reel:query')")
    public CommonResult<List<ProductCtcReelRespVO>> getReelListByCtcId(@RequestParam("ctcId") Long ctcId) {
        List<ProductCtcReelDO> list = reelService.getReelListByCtcId(ctcId);
        return success(buildReelRespVOList(list));
    }
 
    @GetMapping("/get-import-template")
    @Operation(summary = "获得盘具计算记录导入模板")
    public void importTemplate(HttpServletResponse response) throws IOException {
        List<ProductCtcReelImportExcelVO> list = Collections.singletonList(
                ProductCtcReelImportExcelVO.builder()
                        .ctcOrderSpec("QQNB-2/120").reelType("木盘")
                        .reelOuterDiameter(new java.math.BigDecimal("1200")).reelInnerDiameter(new java.math.BigDecimal("630"))
                        .reelWidth(new java.math.BigDecimal("850")).maxCapacity(new java.math.BigDecimal("3"))
                        .recommendedLength(new java.math.BigDecimal("2.5")).netWeight(new java.math.BigDecimal("180"))
                        .grossWeight(new java.math.BigDecimal("200")).calcFormula("").remark("").build()
        );
        ExcelUtils.write(response, "盘具计算记录导入模板.xls", "盘具计算记录列表", ProductCtcReelImportExcelVO.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:pd-ctc-reel:import')")
    public CommonResult<ProductCtcReelImportRespVO> importExcel(@RequestParam("file") MultipartFile file,
                                                                @RequestParam(value = "updateSupport", required = false,
                                                                        defaultValue = "false") Boolean updateSupport) throws Exception {
        List<ProductCtcReelImportExcelVO> list = ExcelUtils.read(file, ProductCtcReelImportExcelVO.class);
        return success(reelService.importReelList(list, updateSupport));
    }
 
    // ==================== 拼接 VO ====================
 
    private List<ProductCtcReelRespVO> buildReelRespVOList(List<ProductCtcReelDO> list) {
        if (CollUtil.isEmpty(list)) {
            return Collections.emptyList();
        }
        // 批量获取换位导线产品订货规格
        Map<Long, ProductCtcDO> ctcFullMap = loadCtcMap(convertSet(list, ProductCtcReelDO::getCtcId));
        // 拼接 VO
        return BeanUtils.toBean(list, ProductCtcReelRespVO.class, vo -> {
            MapUtils.findAndThen(ctcFullMap, vo.getCtcId(),
                    ctc -> vo.setCtcOrderSpec(ctc.getOrderSpec()));
        });
    }
 
    private Map<Long, ProductCtcDO> loadCtcMap(java.util.Set<Long> ctcIds) {
        if (CollUtil.isEmpty(ctcIds)) {
            return Collections.emptyMap();
        }
        java.util.List<ProductCtcDO> list = ctcIds.stream()
                .map(ctcService::getCtc)
                .filter(java.util.Objects::nonNull)
                .toList();
        return convertMap(list, ProductCtcDO::getId);
    }
 
}