| | |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.salesnotice.vo.line.MesWmSalesNoticeLinePageReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.salesnotice.vo.line.MesWmSalesNoticeLineSaveReqVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.batch.MesWmBatchDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.materialstock.MesWmMaterialStockDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.salesnotice.MesWmSalesNoticeDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.salesnotice.MesWmSalesNoticeLineDO; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.wm.salesnotice.MesWmSalesNoticeLineMapper; |
| | | import cn.iocoder.yudao.module.mes.service.mdm.MesMdmItemService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.batch.MesWmBatchService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.materialstock.MesWmMaterialStockService; |
| | | import jakarta.annotation.Resource; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.List; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | |
| | | private MesWmSalesNoticeService salesNoticeService; |
| | | @Resource |
| | | private MesWmBatchService batchService; |
| | | @Resource |
| | | private MesWmMaterialStockService materialStockService; |
| | | @Resource |
| | | private MesMdmItemService mdmItemService; |
| | | |
| | |
| | | } |
| | | |
| | | private void validateLineSaveData(MesWmSalesNoticeLineSaveReqVO reqVO) { |
| | | // 校验父单据存在且为草稿状态 |
| | | validateNoticeStatusDraft(reqVO.getNoticeId()); |
| | | // 校验物料存在 |
| | | if (reqVO.getItemId() != null) { |
| | | mdmItemService.validateItemExistsAndEnable(reqVO.getItemId()); |
| | | |
| | | MesWmBatchDO batch = resolveBatch(reqVO); |
| | | if (batch == null) { |
| | | throw exception(WM_MATERIAL_STOCK_NOT_EXISTS); |
| | | } |
| | | if (ObjUtil.notEqual(batch.getItemId(), reqVO.getItemId())) { |
| | | throw exception(WM_MATERIAL_STOCK_NOT_EXISTS); |
| | | } |
| | | BigDecimal qualifiedQuantity = materialStockService |
| | | .getQualifiedMaterialStockListByItemAndBatch(reqVO.getItemId(), batch.getId()).stream() |
| | | .map(MesWmMaterialStockDO::getQuantity) |
| | | .filter(quantity -> quantity != null) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | if (qualifiedQuantity.compareTo(reqVO.getQuantity()) < 0) { |
| | | throw exception(WM_MATERIAL_STOCK_INSUFFICIENT); |
| | | } |
| | | reqVO.setBatchId(batch.getId()); |
| | | reqVO.setBatchCode(batch.getCode()); |
| | | } |
| | | |
| | | private MesWmBatchDO resolveBatch(MesWmSalesNoticeLineSaveReqVO reqVO) { |
| | | if (reqVO.getBatchId() != null) { |
| | | return batchService.getBatch(reqVO.getBatchId()); |
| | | } |
| | | if (StrUtil.isNotBlank(reqVO.getBatchCode())) { |
| | | return batchService.getBatchByCode(reqVO.getBatchCode()); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |