| | |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.pro.batch.MesProBatchWorkerMapper; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.pro.pallet.MesProPalletMapper; |
| | | import cn.iocoder.yudao.module.mes.enums.md.autocode.MesMdAutoCodeRuleCodeEnum; |
| | | import cn.iocoder.yudao.module.mes.enums.pro.MesProBagTypeEnum; |
| | | import cn.iocoder.yudao.module.mes.enums.pro.MesProBatchStatusEnum; |
| | | import cn.iocoder.yudao.module.mes.service.md.autocode.MesMdAutoCodeRecordService; |
| | | import cn.iocoder.yudao.module.mes.service.mdm.MesMdmItemService; |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Long createBatch(MesProBatchSaveReqVO createReqVO) { |
| | | validateBagType(createReqVO.getBagType()); |
| | | // 1. 校验关联数据(品种、产线、生产人员) |
| | | MesMdmItemDO item = mdmItemService.validateItemExists(createReqVO.getItemId()); |
| | | MesProLineDO line = lineService.validateLineExistsAndEnable(createReqVO.getLineId()); |
| | |
| | | .setCode(code) |
| | | .setLineCode(line.getCode()) |
| | | .setLineName(line.getName()) |
| | | .setBagType(createReqVO.getBagType()) |
| | | .setBagQuantity(0) |
| | | .setPalletQuantity(0) |
| | | .setStatus(MesProBatchStatusEnum.DRAFT.getStatus()); |
| | |
| | | // 1. 校验存在 + 状态(草稿/生产中才允许修改) |
| | | MesProBatchDO oldBatch = validateBatchExists(updateReqVO.getId()); |
| | | validateBatchEditable(oldBatch); |
| | | // 2. 已生成袋码或托盘码后不允许修改袋型(避免同一批次阈值变化导致归集错乱) |
| | | if (updateReqVO.getBagType() != null && !Objects.equals(oldBatch.getBagType(), updateReqVO.getBagType()) |
| | | && (bagQuantityOrPalletCreated(oldBatch))) { |
| | | throw exception(PRO_BATCH_BAG_TYPE_NOT_ALLOW_CHANGE); |
| | | } |
| | | validateBagType(updateReqVO.getBagType()); |
| | | // 2. 校验关联数据(生产人员) |
| | | validateRelations(updateReqVO); |
| | | |
| | |
| | | } |
| | | if (!valid) { |
| | | throw exception(PRO_BATCH_STATUS_INVALID); |
| | | } |
| | | if (MesProBatchStatusEnum.PRODUCING.getStatus().equals(status)) { |
| | | validateBagType(batch.getBagType()); |
| | | } |
| | | // 3. 更新状态 |
| | | batchMapper.updateById(new MesProBatchDO().setId(id).setStatus(status)); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 校验包装袋型有效 |
| | | */ |
| | | private void validateBagType(Integer bagType) { |
| | | if (bagType != null && MesProBagTypeEnum.valueOfType(bagType) == null) { |
| | | throw exception(PRO_BATCH_BAG_TYPE_INVALID); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 判断批次是否已生成袋码或托盘码(用于禁止修改袋型) |
| | | */ |
| | | private boolean bagQuantityOrPalletCreated(MesProBatchDO batch) { |
| | | return (batch.getBagQuantity() != null && batch.getBagQuantity() > 0) |
| | | || (batch.getPalletQuantity() != null && batch.getPalletQuantity() > 0); |
| | | } |
| | | |
| | | /** |
| | | * 插入批次生产人员配置 |
| | | */ |
| | | private void insertBatchWorkers(Long batchId, List<MesProBatchSaveReqVO.Worker> workers) { |