liu
13 小时以前 514f372270b181f82e4deff98f8d0f38ace63183
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pro/pallet/MesProPalletController.java
@@ -21,13 +21,12 @@
import cn.iocoder.yudao.module.mes.dal.dataobject.pro.bagcode.MesProBagCodeDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.pro.batch.MesProBatchDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.pro.pallet.MesProPalletDO;
import cn.iocoder.yudao.module.mes.framework.qrcode.MesProQrLabelBuilder;
import cn.iocoder.yudao.module.mes.framework.qrcode.QrCodeImageUtils;
import cn.iocoder.yudao.module.mes.framework.qrcode.QrLabelInfo;
import cn.iocoder.yudao.module.mes.service.mdm.MesMdmItemService;
import cn.iocoder.yudao.module.mes.service.pro.bagcode.MesProBagCodeService;
import cn.iocoder.yudao.module.mes.service.pro.batch.MesProBatchService;
import cn.iocoder.yudao.module.mes.service.pro.pallet.MesProPalletService;
import cn.iocoder.yudao.module.mes.service.pro.qrexport.MesProQrLabelAssembler;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import io.swagger.v3.oas.annotations.Operation;
@@ -41,7 +40,6 @@
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -53,7 +51,6 @@
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.PRO_PALLET_NOT_EXISTS;
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.PRO_QR_EXPORT_TOO_MANY;
@Tag(name = "管理后台 - MES 托盘码")
@RestController
@@ -71,6 +68,8 @@
    private MesMdmItemService mdmItemService;
    @Resource
    private AdminUserApi adminUserApi;
    @Resource
    private MesProQrLabelAssembler labelAssembler;
    @PostMapping("/batch-create")
    @Operation(summary = "批量生成托盘码(一次录入批次生成正式托盘码)")
@@ -106,10 +105,7 @@
        if (CollUtil.isEmpty(list)) {
            throw exception(PRO_PALLET_NOT_EXISTS);
        }
        if (list.size() > QrCodeImageUtils.MAX_QR_EXPORT) {
            throw exception(PRO_QR_EXPORT_TOO_MANY);
        }
        QrCodeImageUtils.writeZip(response, "托盘码二维码", buildPalletQrLabels(list));
        QrCodeImageUtils.writeZip(response, "托盘码二维码", labelAssembler.buildPalletLabels(list));
    }
    @DeleteMapping("/delete")
@@ -127,7 +123,7 @@
    @PreAuthorize("@ss.hasPermission('mes:pro-pallet:query')")
    public CommonResult<MesProPalletRespVO> getPallet(@RequestParam("id") Long id) {
        MesProPalletDO pallet = palletService.getPallet(id);
        return success(BeanUtils.toBean(pallet, MesProPalletRespVO.class));
        return success(pallet == null ? null : buildPalletRespVOList(List.of(pallet)).get(0));
    }
    @GetMapping("/get-by-code")
@@ -135,7 +131,7 @@
    @Parameter(name = "code", description = "托盘码(二维码内容)", required = true, example = "PC20260818L01001-P01")
    @PreAuthorize("@ss.hasPermission('mes:pro-pallet:query')")
    public CommonResult<MesProPalletTraceRespVO> getPalletByCode(@RequestParam("code") String code) {
        MesProPalletDO pallet = palletService.getPalletByCode(code);
        MesProPalletDO pallet = palletService.getPalletByScanCode(code);
        if (pallet == null) {
            throw exception(PRO_PALLET_NOT_EXISTS);
        }
@@ -147,7 +143,7 @@
    @PreAuthorize("@ss.hasPermission('mes:pro-pallet:query')")
    public CommonResult<PageResult<MesProPalletRespVO>> getPalletPage(@Valid MesProPalletPageReqVO pageReqVO) {
        PageResult<MesProPalletDO> pageResult = palletService.getPalletPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, MesProPalletRespVO.class));
        return success(new PageResult<>(buildPalletRespVOList(pageResult.getList()), pageResult.getTotal()));
    }
    @GetMapping("/simple-list")
@@ -156,7 +152,25 @@
    @PreAuthorize("@ss.hasPermission('mes:pro-pallet:query')")
    public CommonResult<List<MesProPalletRespVO>> getPalletSimpleList(@RequestParam("batchId") Long batchId) {
        List<MesProPalletDO> list = palletService.getPalletListByBatchId(batchId);
        return success(BeanUtils.toBean(list, MesProPalletRespVO.class));
        return success(buildPalletRespVOList(list));
    }
    @GetMapping("/unbound-list")
    @Operation(summary = "获得未绑定批次的临时托盘列表(供批次新增/补录绑定托盘下拉使用)")
    @PreAuthorize("@ss.hasPermission('mes:pro-pallet:query')")
    public CommonResult<List<MesProPalletRespVO>> getUnboundPalletList() {
        List<MesProPalletDO> list = palletService.getUnboundPalletList();
        return success(buildPalletRespVOList(list));
    }
    @GetMapping("/bindable-list")
    @Operation(summary = "获得袋码绑定托盘时可选的目标托盘列表(临时托盘 + 正式托盘,排除已作废)")
    @Parameter(name = "itemId", description = "袋码品种编号(可选,用于过滤非同品种托盘)", example = "1024")
    @PreAuthorize("@ss.hasPermission('mes:pro-pallet:query')")
    public CommonResult<List<MesProPalletRespVO>> getBindablePalletList(
            @RequestParam(value = "itemId", required = false) Long itemId) {
        List<MesProPalletDO> list = palletService.getBindablePalletList(itemId);
        return success(buildPalletRespVOList(list));
    }
    @GetMapping("/export-excel")
@@ -167,7 +181,7 @@
                                  HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<MesProPalletDO> list = palletService.getPalletPage(pageReqVO).getList();
        List<MesProPalletRespVO> voList = BeanUtils.toBean(list, MesProPalletRespVO.class);
        List<MesProPalletRespVO> voList = buildPalletRespVOList(list);
        ExcelUtils.write(response, "托盘码.xls", "数据", MesProPalletRespVO.class, voList);
    }
@@ -182,16 +196,45 @@
        if (CollUtil.isEmpty(list)) {
            throw exception(PRO_PALLET_NOT_EXISTS);
        }
        if (list.size() > QrCodeImageUtils.MAX_QR_EXPORT) {
            throw exception(PRO_QR_EXPORT_TOO_MANY);
        }
        QrCodeImageUtils.writeZip(response, "托盘码二维码-" + batchId, buildPalletQrLabels(list));
        QrCodeImageUtils.writeZip(response, "托盘码二维码-" + batchId, labelAssembler.buildPalletLabels(list));
    }
    // ==================== 拼接 VO ====================
    @PostMapping("/generate-business-code")
    @Operation(summary = "补生成已有托盘业务码,已有码值不变")
    @PreAuthorize("@ss.hasPermission('mes:pro-pallet:create')")
    public CommonResult<Integer> generateBusinessCodes(@Valid @RequestBody
            cn.iocoder.yudao.module.mes.controller.admin.pro.vo.MesProBusinessCodeGenerateReqVO reqVO) {
        return success(palletService.generateBusinessCodes(reqVO.getIds()));
    }
    @PostMapping("/export-business-qr-by-ids")
    @Operation(summary = "按编号导出托盘业务码二维码,内容为纯业务码值")
    @PreAuthorize("@ss.hasPermission('mes:pro-pallet:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportBusinessQrByIds(@Valid @RequestBody MesProPalletExportQrReqVO reqVO,
                                      HttpServletResponse response) throws IOException {
        List<MesProPalletDO> list = palletService.getPalletListByIds(reqVO.getIds()).stream()
                .filter(record -> !cn.iocoder.yudao.module.mes.enums.pro.MesProPalletStatusEnum.CANCELED.getStatus().equals(record.getStatus())).toList();
        if (CollUtil.isEmpty(list)) throw exception(PRO_PALLET_NOT_EXISTS);
        QrCodeImageUtils.writeZip(response, "托盘业务二维码", labelAssembler.buildPalletBusinessLabels(list));
    }
    private List<MesProPalletRespVO> buildPalletRespVOList(List<MesProPalletDO> list) {
        Map<Long, MesMdmItemDO> items = mdmItemService.getItemMap(convertSet(list, MesProPalletDO::getItemId));
        return BeanUtils.toBean(list, MesProPalletRespVO.class, vo ->
                MapUtils.findAndThen(items, vo.getItemId(), item -> { vo.setItemCode(item.getCode()); vo.setItemName(item.getName()); }));
    }
    private MesProPalletTraceRespVO buildPalletTraceRespVO(MesProPalletDO pallet) {
        MesProPalletTraceRespVO respVO = BeanUtils.toBean(pallet, MesProPalletTraceRespVO.class);
        respVO.setPendingBagQuantity((int) bagCodeService.getBagCodeListByPalletId(pallet.getId()).stream()
                .filter(b -> !Integer.valueOf(30).equals(b.getStatus()) && b.getInboundEventId() == null).count());
        if (pallet.getItemId() != null) {
            MesMdmItemDO item = mdmItemService.getItem(pallet.getItemId());
            if (item != null) respVO.setItemCode(item.getCode()).setItemName(item.getName()).setItemSpecification(item.getSpecification());
        }
        // 批次信息(临时托盘未绑定批次时为空批次)
        MesProBatchDO batch = pallet.getBatchId() == null ? null : batchService.getBatch(pallet.getBatchId());
        if (batch != null) {
@@ -233,23 +276,6 @@
        return BeanUtils.toBean(list, MesProBagCodeRespVO.class, vo ->
                MapUtils.findAndThen(batchMap, vo.getBatchId(), batch ->
                        vo.setLineCode(batch.getLineCode()).setLineName(batch.getLineName())));
    }
    private List<QrLabelInfo> buildPalletQrLabels(List<MesProPalletDO> list) {
        // 获得关联数据(批次、品种、责任人)
        Map<Long, MesProBatchDO> batchMap = convertMap(
                batchService.getBatchList(convertSet(list, MesProPalletDO::getBatchId)), MesProBatchDO::getId);
        Map<Long, MesMdmItemDO> itemMap = mdmItemService.getItemMap(
                convertSet(batchMap.values(), MesProBatchDO::getItemId));
        Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
                convertSet(batchMap.values(), MesProBatchDO::getOwnerUserId));
        // 构建标签
        List<QrLabelInfo> labels = new ArrayList<>(list.size());
        for (MesProPalletDO pallet : list) {
            labels.add(MesProQrLabelBuilder.buildPalletLabel(
                    pallet, batchMap.get(pallet.getBatchId()), itemMap, userMap));
        }
        return labels;
    }
}