云
22 小时以前 704265308b1227dbada5a36b2027b588c062ded2
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pro/batch/MesProBatchController.java
@@ -181,7 +181,7 @@
    @Parameter(name = "code", description = "批次号(二维码内容)", required = true, example = "PC20260818L01001")
    @PreAuthorize("@ss.hasPermission('mes:pro-batch:query')")
    public CommonResult<MesProBatchTraceRespVO> getBatchByCode(@RequestParam("code") String code) {
        MesProBatchDO batch = batchService.getBatchByCode(code);
        MesProBatchDO batch = batchService.getBatchByScanCode(code);
        if (batch == null) {
            throw exception(PRO_BATCH_NOT_EXISTS);
        }
@@ -209,24 +209,44 @@
    // ==================== 拼接 VO ====================
    @PostMapping("/generate-business-code")
    @Operation(summary = "补生成已有生产批次业务码,已有码值不变")
    @PreAuthorize("@ss.hasPermission('mes:pro-batch:create')")
    public CommonResult<Integer> generateBusinessCodes(@Valid @RequestBody
            cn.iocoder.yudao.module.mes.controller.admin.pro.vo.MesProBusinessCodeGenerateReqVO reqVO) {
        return success(batchService.generateBusinessCodes(reqVO.getIds()));
    }
    @GetMapping("/export-business-qr")
    @Operation(summary = "导出批次及所属托盘业务二维码,内容为纯业务码值")
    @PreAuthorize("@ss.hasPermission('mes:pro-batch:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportBusinessQr(@RequestParam("batchId") Long batchId,
                                  HttpServletResponse response) throws IOException {
        MesProBatchDO batch = batchService.getBatch(batchId);
        if (batch == null) throw exception(PRO_BATCH_NOT_EXISTS);
        if (cn.iocoder.yudao.module.mes.enums.pro.MesProBatchStatusEnum.CANCELED.getStatus().equals(batch.getStatus()))
            throw new cn.iocoder.yudao.framework.common.exception.ServiceException(400, "已作废批次不可导出业务二维码");
        List<MesProPalletDO> pallets = palletService.getPalletListByBatchId(batchId).stream()
                .filter(record -> !cn.iocoder.yudao.module.mes.enums.pro.MesProPalletStatusEnum.CANCELED.getStatus().equals(record.getStatus())).toList();
        if (pallets.size() + 1 > QrCodeImageUtils.MAX_QR_EXPORT) throw exception(PRO_QR_EXPORT_TOO_MANY);
        List<QrLabelInfo> labels = new java.util.ArrayList<>();
        labels.add(MesProQrLabelBuilder.buildBatchBusinessCodeLabel(batch));
        pallets.forEach(pallet -> labels.add(MesProQrLabelBuilder.buildPalletBusinessCodeLabel(pallet)));
        QrCodeImageUtils.writeZip(response, "批次业务二维码-" + batch.getBusinessCode(), labels);
    }
    private List<MesProBatchRespVO> buildBatchRespVOList(List<MesProBatchDO> list) {
        if (CollUtil.isEmpty(list)) {
            return Collections.emptyList();
        }
        // 1. 获得关联数据(责任人、品种物料)
        // 1. 获得关联数据(责任人);品种已下沉到袋码数据包,批次列表不再展示
        Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
                convertSet(list, MesProBatchDO::getOwnerUserId));
        Map<Long, MesMdmItemDO> itemMap = mdmItemService.getItemMap(
                convertSet(list, MesProBatchDO::getItemId));
        // 2. 构建结果
        Map<Long, MesMdmItemDO> itemMap = mdmItemService.getItemMap(convertSet(list, MesProBatchDO::getItemId));
        return BeanUtils.toBean(list, MesProBatchRespVO.class, vo -> {
            MapUtils.findAndThen(userMap, vo.getOwnerUserId(), user ->
                    vo.setOwnerUserName(user.getNickname()));
            MapUtils.findAndThen(itemMap, vo.getItemId(), item -> {
                vo.setItemCode(item.getCode());
                vo.setItemName(item.getName());
                vo.setItemSpecification(item.getSpecification());
            });
            MapUtils.findAndThen(userMap, vo.getOwnerUserId(), user -> vo.setOwnerUserName(user.getNickname()));
            MapUtils.findAndThen(itemMap, vo.getItemId(), item -> { vo.setItemCode(item.getCode()); vo.setItemName(item.getName()); });
        });
    }
@@ -264,6 +284,7 @@
        respVO.setPallets(BeanUtils.toBean(palletService.getPalletListByBatchId(batch.getId()), MesProPalletRespVO.class));
        // 袋码列表(封顶 2000,bagTotal 记录总数)
        List<MesProBagCodeDO> bags = bagCodeService.getBagCodeListByBatchId(batch.getId());
        respVO.setPendingBagQuantity((int) bags.stream().filter(b -> !Integer.valueOf(30).equals(b.getStatus()) && b.getInboundEventId() == null).count());
        respVO.setBagTotal(bags.size());
        if (bags.size() > QrCodeImageUtils.MAX_QR_EXPORT) {
            bags = bags.subList(0, QrCodeImageUtils.MAX_QR_EXPORT);