| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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 |
| | |
| | | private MesMdmItemService mdmItemService; |
| | | @Resource |
| | | private AdminUserApi adminUserApi; |
| | | @Resource |
| | | private MesProQrLabelAssembler labelAssembler; |
| | | |
| | | @PostMapping("/batch-create") |
| | | @Operation(summary = "批量生成托盘码(一次录入批次生成正式托盘码)") |
| | |
| | | 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") |
| | |
| | | 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 ==================== |
| | |
| | | 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); |
| | | if (list.size() > QrCodeImageUtils.MAX_QR_EXPORT) throw exception(PRO_QR_EXPORT_TOO_MANY); |
| | | QrCodeImageUtils.writeZip(response, "托盘业务二维码", list.stream() |
| | | .map(MesProQrLabelBuilder::buildPalletBusinessCodeLabel).toList()); |
| | | QrCodeImageUtils.writeZip(response, "托盘业务二维码", labelAssembler.buildPalletBusinessLabels(list)); |
| | | } |
| | | |
| | | private List<MesProPalletRespVO> buildPalletRespVOList(List<MesProPalletDO> list) { |
| | |
| | | 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; |
| | | } |
| | | |
| | | } |