Commit 75c1a638248b824160e74467bbe25b532b930357
1 parent
a682efdb
✨ feat(transaction): 添加库存事务创建逻辑,支持生产出库和退料入库操作
Showing
2 changed files
with
44 additions
and
21 deletions
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/productionissue/MesWmProductionIssueServiceImpl.java
| ... | ... | @@ -12,9 +12,13 @@ import cn.iocoder.yudao.module.mes.dal.dataobject.wm.productionissue.MesWmProduc |
| 12 | 12 | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.productionissue.MesWmProductionIssueDO; |
| 13 | 13 | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.productionissue.MesWmProductionIssueLineDO; |
| 14 | 14 | import cn.iocoder.yudao.module.mes.dal.mysql.wm.productionissue.MesWmProductionIssueMapper; |
| 15 | +import cn.iocoder.yudao.module.mes.enums.MesBizTypeConstants; | |
| 15 | 16 | import cn.iocoder.yudao.module.mes.enums.wm.MesWmProductionIssueStatusEnum; |
| 17 | +import cn.iocoder.yudao.module.mes.enums.wm.MesWmTransactionTypeEnum; | |
| 16 | 18 | import cn.iocoder.yudao.module.mes.service.md.workstation.MesMdWorkstationService; |
| 17 | 19 | import cn.iocoder.yudao.module.mes.service.pro.workorder.MesProWorkOrderService; |
| 20 | +import cn.iocoder.yudao.module.mes.service.wm.transaction.MesWmTransactionService; | |
| 21 | +import cn.iocoder.yudao.module.mes.service.wm.transaction.dto.MesWmTransactionSaveReqDTO; | |
| 18 | 22 | import jakarta.annotation.Resource; |
| 19 | 23 | import org.springframework.stereotype.Service; |
| 20 | 24 | import org.springframework.transaction.annotation.Transactional; |
| ... | ... | @@ -24,6 +28,7 @@ import java.math.BigDecimal; |
| 24 | 28 | import java.util.List; |
| 25 | 29 | |
| 26 | 30 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 31 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; | |
| 27 | 32 | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*; |
| 28 | 33 | |
| 29 | 34 | /** |
| ... | ... | @@ -44,6 +49,8 @@ public class MesWmProductionIssueServiceImpl implements MesWmProductionIssueServ |
| 44 | 49 | private MesMdWorkstationService workstationService; |
| 45 | 50 | @Resource |
| 46 | 51 | private MesProWorkOrderService workOrderService; |
| 52 | + @Resource | |
| 53 | + private MesWmTransactionService wmTransactionService; | |
| 47 | 54 | |
| 48 | 55 | @Override |
| 49 | 56 | @Transactional(rollbackFor = Exception.class) |
| ... | ... | @@ -133,26 +140,31 @@ public class MesWmProductionIssueServiceImpl implements MesWmProductionIssueServ |
| 133 | 140 | @Override |
| 134 | 141 | @Transactional(rollbackFor = Exception.class) |
| 135 | 142 | public void finishProductionIssue(Long id) { |
| 136 | - // 校验存在 | |
| 143 | + // 1. 校验存在 | |
| 137 | 144 | MesWmProductionIssueDO issue = validateProductionIssueExists(id); |
| 138 | 145 | if (ObjUtil.notEqual(MesWmProductionIssueStatusEnum.APPROVED.getStatus(), issue.getStatus())) { |
| 139 | 146 | throw exception(WM_PRODUCTION_ISSUE_STATUS_INVALID); |
| 140 | 147 | } |
| 141 | 148 | |
| 142 | - // 遍历所有明细,更新库存台账(扣减库存) | |
| 143 | - // TODO @芋艿:【后续在弄】这里可能有点问题;缺少库存更新;后面在弄; | |
| 144 | - List<MesWmProductionIssueDetailDO> details = issueDetailService.getProductionIssueDetailListByIssueId(id); | |
| 145 | - for (MesWmProductionIssueDetailDO detail : details) { | |
| 146 | - // materialStockService.decreaseStock( | |
| 147 | - // detail.getItemId(), detail.getWarehouseId(), detail.getLocationId(), detail.getAreaId(), | |
| 148 | - // detail.getBatchId(), detail.getQuantity(), issue.getWorkOrderId(), null, null); | |
| 149 | - } | |
| 149 | + // 2. 遍历所有明细,创建库存事务(扣减库存 + 记录流水) | |
| 150 | + createTransactionList(issue); | |
| 150 | 151 | |
| 151 | - // 更新出库单状态 | |
| 152 | + // 3. 更新出库单状态 | |
| 152 | 153 | issueMapper.updateById(new MesWmProductionIssueDO() |
| 153 | 154 | .setId(id).setStatus(MesWmProductionIssueStatusEnum.FINISHED.getStatus())); |
| 154 | 155 | } |
| 155 | 156 | |
| 157 | + private void createTransactionList(MesWmProductionIssueDO issue) { | |
| 158 | + 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()))); | |
| 166 | + } | |
| 167 | + | |
| 156 | 168 | @Override |
| 157 | 169 | @Transactional(rollbackFor = Exception.class) |
| 158 | 170 | public void cancelProductionIssue(Long id) { | ... | ... |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/returnissue/MesWmReturnIssueServiceImpl.java
| ... | ... | @@ -13,11 +13,15 @@ import cn.iocoder.yudao.module.mes.dal.dataobject.wm.returnissue.MesWmReturnIssu |
| 13 | 13 | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.returnissue.MesWmReturnIssueDetailDO; |
| 14 | 14 | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.returnissue.MesWmReturnIssueLineDO; |
| 15 | 15 | import cn.iocoder.yudao.module.mes.dal.mysql.wm.returnissue.MesWmReturnIssueMapper; |
| 16 | +import cn.iocoder.yudao.module.mes.enums.MesBizTypeConstants; | |
| 16 | 17 | import cn.iocoder.yudao.module.mes.enums.wm.MesWmQualityStatusEnum; |
| 17 | 18 | import cn.iocoder.yudao.module.mes.enums.wm.MesWmReturnIssueStatusEnum; |
| 19 | +import cn.iocoder.yudao.module.mes.enums.wm.MesWmTransactionTypeEnum; | |
| 18 | 20 | import cn.iocoder.yudao.module.mes.service.md.item.MesMdItemService; |
| 19 | 21 | import cn.iocoder.yudao.module.mes.service.md.workstation.MesMdWorkstationService; |
| 20 | 22 | import cn.iocoder.yudao.module.mes.service.pro.workorder.MesProWorkOrderService; |
| 23 | +import cn.iocoder.yudao.module.mes.service.wm.transaction.MesWmTransactionService; | |
| 24 | +import cn.iocoder.yudao.module.mes.service.wm.transaction.dto.MesWmTransactionSaveReqDTO; | |
| 21 | 25 | import jakarta.annotation.Resource; |
| 22 | 26 | import org.springframework.stereotype.Service; |
| 23 | 27 | import org.springframework.transaction.annotation.Transactional; |
| ... | ... | @@ -28,6 +32,7 @@ import java.util.List; |
| 28 | 32 | import java.util.Map; |
| 29 | 33 | |
| 30 | 34 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 35 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; | |
| 31 | 36 | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*; |
| 32 | 37 | |
| 33 | 38 | /** |
| ... | ... | @@ -50,6 +55,8 @@ public class MesWmReturnIssueServiceImpl implements MesWmReturnIssueService { |
| 50 | 55 | private MesProWorkOrderService workOrderService; |
| 51 | 56 | @Resource |
| 52 | 57 | private MesMdItemService itemService; |
| 58 | + @Resource | |
| 59 | + private MesWmTransactionService wmTransactionService; | |
| 53 | 60 | |
| 54 | 61 | @Override |
| 55 | 62 | @Transactional(rollbackFor = Exception.class) |
| ... | ... | @@ -172,27 +179,31 @@ public class MesWmReturnIssueServiceImpl implements MesWmReturnIssueService { |
| 172 | 179 | @Override |
| 173 | 180 | @Transactional(rollbackFor = Exception.class) |
| 174 | 181 | public void finishReturnIssue(Long id) { |
| 175 | - // 校验存在 + 待执行退料状态 | |
| 182 | + // 1. 校验存在 + 待执行退料状态 | |
| 176 | 183 | MesWmReturnIssueDO issue = validateReturnIssueExists(id); |
| 177 | 184 | if (ObjUtil.notEqual(MesWmReturnIssueStatusEnum.APPROVED.getStatus(), issue.getStatus())) { |
| 178 | 185 | throw exception(WM_RETURN_ISSUE_NOT_APPROVED); |
| 179 | 186 | } |
| 180 | 187 | |
| 181 | - // 完成退料(待执行退料 → 已完成),更新库存台账 | |
| 182 | - // 遍历所有明细,更新库存台账(增加库存,与领料出库相反) | |
| 183 | - // TODO @芋艿:【后续在弄】这里可能有点问题;缺少库存更新;后面在弄; | |
| 184 | - List<MesWmReturnIssueDetailDO> details = issueDetailService.getReturnIssueDetailListByIssueId(id); | |
| 185 | - for (MesWmReturnIssueDetailDO detail : details) { | |
| 186 | - // materialStockService.increaseStock( | |
| 187 | - // detail.getItemId(), detail.getWarehouseId(), detail.getLocationId(), detail.getAreaId(), | |
| 188 | - // detail.getBatchId(), detail.getQuantity(), issue.getWorkOrderId(), null, null); | |
| 189 | - } | |
| 188 | + // 2. 遍历所有明细,创建库存事务(增加库存 + 记录流水) | |
| 189 | + createTransactionList(issue); | |
| 190 | 190 | |
| 191 | - // 更新退料单状态 | |
| 191 | + // 3. 更新退料单状态 | |
| 192 | 192 | issueMapper.updateById(new MesWmReturnIssueDO() |
| 193 | 193 | .setId(id).setStatus(MesWmReturnIssueStatusEnum.FINISHED.getStatus())); |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | + private void createTransactionList(MesWmReturnIssueDO issue) { | |
| 197 | + List<MesWmReturnIssueDetailDO> details = issueDetailService.getReturnIssueDetailListByIssueId(issue.getId()); | |
| 198 | + wmTransactionService.createTransactionList(convertList(details, detail -> new MesWmTransactionSaveReqDTO() | |
| 199 | + .setType(MesWmTransactionTypeEnum.IN.getType()).setItemId(detail.getItemId()) | |
| 200 | + .setQuantity(detail.getQuantity()) // 入库数量为正数(退料回仓) | |
| 201 | + .setBatchId(detail.getBatchId()).setBatchCode(detail.getBatchCode()) | |
| 202 | + .setWarehouseId(detail.getWarehouseId()).setLocationId(detail.getLocationId()).setAreaId(detail.getAreaId()) | |
| 203 | + .setBizType(MesBizTypeConstants.WM_RETURN_ISSUE).setBizId(issue.getId()) | |
| 204 | + .setBizCode(issue.getCode()).setBizLineId(detail.getLineId()))); | |
| 205 | + } | |
| 206 | + | |
| 196 | 207 | @Override |
| 197 | 208 | @Transactional(rollbackFor = Exception.class) |
| 198 | 209 | public void cancelReturnIssue(Long id) { | ... | ... |