Commit e7ee268a76aeb583ee1646f7a503b72b343d831a
1 parent
b660fe45
✨ feat(mes): 添加库存事务关联错误码
新增错误码 WM_TRANSACTION_RELATED_NOT_EXISTS,用于处理关联库存事务不存在的情况。
Showing
2 changed files
with
38 additions
and
8 deletions
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java
| ... | ... | @@ -363,6 +363,7 @@ public interface ErrorCodeConstants { |
| 363 | 363 | ErrorCode WM_TRANSACTION_BATCH_REQUIRED = new ErrorCode(1_040_703_007, "当前物料启用了批次管理,批次号不能为空"); |
| 364 | 364 | ErrorCode WM_MATERIAL_STOCK_AREA_ITEM_MIXING_NOT_ALLOWED = new ErrorCode(1_040_703_008, "库位({})不允许物料混放,请选择其他库位"); |
| 365 | 365 | ErrorCode WM_MATERIAL_STOCK_AREA_BATCH_MIXING_NOT_ALLOWED = new ErrorCode(1_040_703_009, "库位({})不允许批次混放,请选择其他库位"); |
| 366 | + ErrorCode WM_TRANSACTION_RELATED_NOT_EXISTS = new ErrorCode(1_040_703_010, "关联的库存事务不存在"); | |
| 366 | 367 | |
| 367 | 368 | // ========== MES 仓库管理-到货通知单(1-040-704-000) ========== |
| 368 | 369 | ErrorCode WM_ARRIVAL_NOTICE_NOT_EXISTS = new ErrorCode(1_040_704_000, "到货通知单不存在"); | ... | ... |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/productionissue/MesWmProductionIssueServiceImpl.java
| ... | ... | @@ -19,6 +19,12 @@ import cn.iocoder.yudao.module.mes.service.md.workstation.MesMdWorkstationServic |
| 19 | 19 | import cn.iocoder.yudao.module.mes.service.pro.workorder.MesProWorkOrderService; |
| 20 | 20 | import cn.iocoder.yudao.module.mes.service.wm.transaction.MesWmTransactionService; |
| 21 | 21 | import cn.iocoder.yudao.module.mes.service.wm.transaction.dto.MesWmTransactionSaveReqDTO; |
| 22 | +import cn.iocoder.yudao.module.mes.service.wm.warehouse.MesWmWarehouseAreaService; | |
| 23 | +import cn.iocoder.yudao.module.mes.service.wm.warehouse.MesWmWarehouseLocationService; | |
| 24 | +import cn.iocoder.yudao.module.mes.service.wm.warehouse.MesWmWarehouseService; | |
| 25 | +import cn.iocoder.yudao.module.mes.dal.dataobject.wm.warehouse.MesWmWarehouseAreaDO; | |
| 26 | +import cn.iocoder.yudao.module.mes.dal.dataobject.wm.warehouse.MesWmWarehouseDO; | |
| 27 | +import cn.iocoder.yudao.module.mes.dal.dataobject.wm.warehouse.MesWmWarehouseLocationDO; | |
| 22 | 28 | import jakarta.annotation.Resource; |
| 23 | 29 | import org.springframework.stereotype.Service; |
| 24 | 30 | import org.springframework.transaction.annotation.Transactional; |
| ... | ... | @@ -28,7 +34,6 @@ import java.math.BigDecimal; |
| 28 | 34 | import java.util.List; |
| 29 | 35 | |
| 30 | 36 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 31 | -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; | |
| 32 | 37 | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*; |
| 33 | 38 | |
| 34 | 39 | /** |
| ... | ... | @@ -51,6 +56,12 @@ public class MesWmProductionIssueServiceImpl implements MesWmProductionIssueServ |
| 51 | 56 | private MesProWorkOrderService workOrderService; |
| 52 | 57 | @Resource |
| 53 | 58 | private MesWmTransactionService wmTransactionService; |
| 59 | + @Resource | |
| 60 | + private MesWmWarehouseService warehouseService; | |
| 61 | + @Resource | |
| 62 | + private MesWmWarehouseLocationService locationService; | |
| 63 | + @Resource | |
| 64 | + private MesWmWarehouseAreaService areaService; | |
| 54 | 65 | |
| 55 | 66 | @Override |
| 56 | 67 | @Transactional(rollbackFor = Exception.class) |
| ... | ... | @@ -155,14 +166,32 @@ public class MesWmProductionIssueServiceImpl implements MesWmProductionIssueServ |
| 155 | 166 | } |
| 156 | 167 | |
| 157 | 168 | private void createTransactionList(MesWmProductionIssueDO issue) { |
| 169 | + // 1. 查询虚拟线边库 | |
| 170 | + MesWmWarehouseDO virtualWarehouse = warehouseService.getWarehouseByCode(MesWmWarehouseDO.WIP_VIRTUAL_WAREHOUSE); | |
| 171 | + MesWmWarehouseLocationDO virtualLocation = locationService.getWarehouseLocationByCode(MesWmWarehouseLocationDO.WIP_VIRTUAL_LOCATION); | |
| 172 | + MesWmWarehouseAreaDO virtualArea = areaService.getWarehouseAreaByCode(MesWmWarehouseAreaDO.WIP_VIRTUAL_AREA); | |
| 173 | + | |
| 174 | + // 2. 遍历明细,每条明细产生 OUT(实际仓库扣减)+ IN(虚拟线边库增加) | |
| 158 | 175 | List<MesWmProductionIssueDetailDO> details = issueDetailService.getProductionIssueDetailListByIssueId(issue.getId()); |
| 159 | - wmTransactionService.createTransactionList(convertList(details, detail -> new MesWmTransactionSaveReqDTO() | |
| 160 | - .setType(MesWmTransactionTypeEnum.OUT.getType()).setItemId(detail.getItemId()) | |
| 161 | - .setQuantity(detail.getQuantity().negate()) // 出库数量为负数 | |
| 162 | - .setBatchId(detail.getBatchId()).setBatchCode(detail.getBatchCode()) | |
| 163 | - .setWarehouseId(detail.getWarehouseId()).setLocationId(detail.getLocationId()).setAreaId(detail.getAreaId()) | |
| 164 | - .setBizType(MesBizTypeConstants.WM_ISSUE).setBizId(issue.getId()) | |
| 165 | - .setBizCode(issue.getCode()).setBizLineId(detail.getLineId()))); | |
| 176 | + for (MesWmProductionIssueDetailDO detail : details) { | |
| 177 | + // 2.1 先从实际仓库出库(库存减少) | |
| 178 | + Long outTransactionId = wmTransactionService.createTransaction(new MesWmTransactionSaveReqDTO() | |
| 179 | + .setType(MesWmTransactionTypeEnum.OUT.getType()).setItemId(detail.getItemId()) | |
| 180 | + .setQuantity(detail.getQuantity().negate()) // 库存减少 | |
| 181 | + .setBatchId(detail.getBatchId()).setBatchCode(detail.getBatchCode()) | |
| 182 | + .setWarehouseId(detail.getWarehouseId()).setLocationId(detail.getLocationId()).setAreaId(detail.getAreaId()) | |
| 183 | + .setBizType(MesBizTypeConstants.WM_ISSUE).setBizId(issue.getId()) | |
| 184 | + .setBizCode(issue.getCode()).setBizLineId(detail.getLineId())); | |
| 185 | + // 2.2 再入虚拟线边库(库存增加) | |
| 186 | + wmTransactionService.createTransaction(new MesWmTransactionSaveReqDTO() | |
| 187 | + .setType(MesWmTransactionTypeEnum.IN.getType()).setItemId(detail.getItemId()) | |
| 188 | + .setQuantity(detail.getQuantity()) // 库存增加 | |
| 189 | + .setBatchId(detail.getBatchId()).setBatchCode(detail.getBatchCode()) | |
| 190 | + .setWarehouseId(virtualWarehouse.getId()).setLocationId(virtualLocation.getId()).setAreaId(virtualArea.getId()) | |
| 191 | + .setBizType(MesBizTypeConstants.WM_ISSUE).setBizId(issue.getId()) | |
| 192 | + .setBizCode(issue.getCode()).setBizLineId(detail.getLineId()) | |
| 193 | + .setRelatedTransactionId(outTransactionId)); // 关联出库事务 | |
| 194 | + } | |
| 166 | 195 | } |
| 167 | 196 | |
| 168 | 197 | @Override | ... | ... |