| | |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.productsales.MesWmProductSalesDetailDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.productsales.MesWmProductSalesLineDO; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.wm.productsales.MesWmProductSalesDetailMapper; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.wm.productsales.MesWmProductSalesMapper; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.productsales.MesWmProductSalesDO; |
| | | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| | | import cn.iocoder.yudao.framework.common.exception.ServiceException; |
| | | import cn.iocoder.yudao.module.mes.service.mdm.MesMdmItemService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.materialstock.MesWmMaterialStockService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.warehouse.MesWmWarehouseAreaService; |
| | | import jakarta.annotation.Resource; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | | import java.util.List; |
| | |
| | | private MesWmWarehouseAreaService warehouseAreaService; |
| | | @Resource |
| | | private MesWmSalesReelGuard salesReelGuard; |
| | | @Resource |
| | | private MesWmOqcConcessionGuard oqcConcessionGuard; |
| | | @Resource |
| | | private MesWmProductSalesMapper salesMapper; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Long createProductSalesDetail(MesWmProductSalesDetailSaveReqVO createReqVO) { |
| | | validateEditable(createReqVO.getSalesId(), createReqVO.getLineId()); |
| | | // 校验数据 |
| | | validateProductSalesDetailSaveData(createReqVO); |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updateProductSalesDetail(MesWmProductSalesDetailSaveReqVO updateReqVO) { |
| | | // 校验存在 |
| | | validateProductSalesDetailExists(updateReqVO.getId()); |
| | | MesWmProductSalesDetailDO existing = validateProductSalesDetailExists(updateReqVO.getId()); |
| | | if (!ObjUtil.equal(existing.getSalesId(), updateReqVO.getSalesId()) || !ObjUtil.equal(existing.getLineId(), updateReqVO.getLineId())) { |
| | | throw new ServiceException(400, "不允许更改出库明细所属单据或行"); |
| | | } |
| | | validateEditable(existing.getSalesId(), existing.getLineId()); |
| | | // 校验数据 |
| | | validateProductSalesDetailSaveData(updateReqVO); |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void deleteProductSalesDetail(Long id) { |
| | | // 校验存在 |
| | | validateProductSalesDetailExists(id); |
| | | MesWmProductSalesDetailDO detail = validateProductSalesDetailExists(id); |
| | | validateEditable(detail.getSalesId(), detail.getLineId()); |
| | | // 删除 |
| | | productSalesDetailMapper.deleteById(id); |
| | | } |
| | | |
| | | private void validateEditable(Long salesId, Long lineId) { |
| | | MesWmProductSalesDO sales = salesMapper.selectOne(new LambdaQueryWrapperX<MesWmProductSalesDO>() |
| | | .eq(MesWmProductSalesDO::getId, salesId).last("FOR UPDATE")); |
| | | MesWmProductSalesLineDO line = productSalesLineService.getProductSalesLine(lineId); |
| | | if (sales == null || line == null || !ObjUtil.equal(line.getSalesId(), salesId)) { |
| | | throw new ServiceException(400, "出库单或出库行不存在"); |
| | | } |
| | | oqcConcessionGuard.validateEditable(line, sales.getStatus()); |
| | | } |
| | | |
| | | @Override |
| | |
| | | reqVO.getMaterialStockId(), reqVO.getItemId(), reqVO.getBatchId(), reqVO.getBatchCode(), |
| | | reqVO.getWarehouseId(), reqVO.getLocationId(), reqVO.getAreaId(), reqVO.getQuantity()); |
| | | salesReelGuard.validate(line, reqVO.getBatchId()); |
| | | oqcConcessionGuard.validate(line, reqVO.getMaterialStockId(), reqVO.getBatchCode(), reqVO.getQuantity()); |
| | | } |
| | | |
| | | } |