| | |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.returnsales.MesWmReturnSalesLineDO; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.wm.returnsales.MesWmReturnSalesDetailMapper; |
| | | import cn.iocoder.yudao.module.mes.enums.wm.MesWmReturnSalesStatusEnum; |
| | | import cn.iocoder.yudao.module.mes.enums.wm.MesWmQualityStatusEnum; |
| | | import cn.iocoder.yudao.module.mes.service.wm.batch.MesWmBatchService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.materialstock.MesWmMaterialStockService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.warehouse.MesWmWarehouseAreaService; |
| | |
| | | /** |
| | | * MES 销售退货明细 Service 实现类 |
| | | * |
| | | * @author 芋道源码 |
| | | * @author 超级管理员 |
| | | */ |
| | | @Service |
| | | @Validated |
| | |
| | | @Override |
| | | public void updateReturnSalesDetail(MesWmReturnSalesDetailSaveReqVO updateReqVO) { |
| | | // 校验存在 |
| | | validateReturnSalesDetailExists(updateReqVO.getId()); |
| | | MesWmReturnSalesDetailDO oldDetail = validateReturnSalesDetailExists(updateReqVO.getId()); |
| | | if (ObjUtil.notEqual(oldDetail.getLineId(), updateReqVO.getLineId()) |
| | | || ObjUtil.notEqual(oldDetail.getReturnId(), updateReqVO.getReturnId())) { |
| | | throw exception(WM_RETURN_SALES_DETAIL_SOURCE_MISMATCH); |
| | | } |
| | | // 校验保存数据 |
| | | validateReturnSalesDetailSaveData(updateReqVO); |
| | | |
| | |
| | | private void validateReturnSalesDetailSaveData(MesWmReturnSalesDetailSaveReqVO reqVO) { |
| | | // 校验父数据存在 |
| | | MesWmReturnSalesLineDO line = returnSalesLineService.validateReturnSalesLineExists(reqVO.getLineId()); |
| | | if (ObjUtil.notEqual(line.getReturnId(), reqVO.getReturnId()) |
| | | || ObjUtil.notEqual(line.getItemId(), reqVO.getItemId())) { |
| | | throw exception(WM_RETURN_SALES_DETAIL_SOURCE_MISMATCH); |
| | | } |
| | | // 校验退货单为待上架状态 |
| | | validateReturnSalesStatusApproved(line.getReturnId()); |
| | | if (ObjUtil.notEqual(line.getQualityStatus(), MesWmQualityStatusEnum.PASS.getStatus())) { |
| | | throw exception(WM_RETURN_SALES_LINE_NOT_QUALIFIED); |
| | | } |
| | | // 上架使用退货行的批次;若行没有指定批次,允许显式选择属于该物料的批次。 |
| | | fillBatchId(reqVO, line); |
| | | // 校验仓库、库区、库位的关联关系 |
| | | warehouseAreaService.validateWarehouseAreaExists( |
| | | reqVO.getWarehouseId(), reqVO.getLocationId(), reqVO.getAreaId()); |
| | |
| | | // 校验明细总数量不超过行数量(排除自身) |
| | | validateDetailQuantityNotExceed(reqVO.getLineId(), reqVO.getQuantity(), reqVO.getId(), line); |
| | | |
| | | // 根据 batchCode 解析 batchId(必须在混放规则校验之前,因为它依赖 batchId) |
| | | fillBatchId(reqVO); |
| | | } |
| | | |
| | | /** |
| | |
| | | /** |
| | | * 根据 batchCode 解析并回填 batchId |
| | | */ |
| | | private void fillBatchId(MesWmReturnSalesDetailSaveReqVO reqVO) { |
| | | if (StrUtil.isBlank(reqVO.getBatchCode())) { |
| | | return; |
| | | private void fillBatchId(MesWmReturnSalesDetailSaveReqVO reqVO, MesWmReturnSalesLineDO line) { |
| | | MesWmBatchDO batch = null; |
| | | if (StrUtil.isNotBlank(reqVO.getBatchCode())) { |
| | | batch = batchService.getBatchByCode(reqVO.getBatchCode()); |
| | | if (batch == null) throw exception(WM_BATCH_NOT_EXISTS); |
| | | if (reqVO.getBatchId() != null && ObjUtil.notEqual(batch.getId(), reqVO.getBatchId())) { |
| | | throw exception(WM_RETURN_SALES_DETAIL_BATCH_MISMATCH); |
| | | } |
| | | } else if (reqVO.getBatchId() != null || line.getBatchId() != null) { |
| | | batch = batchService.validateBatchExists( |
| | | reqVO.getBatchId() != null ? reqVO.getBatchId() : line.getBatchId(), reqVO.getItemId()); |
| | | } |
| | | MesWmBatchDO batch = batchService.getBatchByCode(reqVO.getBatchCode()); |
| | | if (batch != null) { |
| | | if (ObjUtil.notEqual(batch.getItemId(), reqVO.getItemId()) |
| | | || (line.getBatchId() != null && ObjUtil.notEqual(line.getBatchId(), batch.getId()))) { |
| | | throw exception(WM_RETURN_SALES_DETAIL_BATCH_MISMATCH); |
| | | } |
| | | reqVO.setBatchId(batch.getId()); |
| | | reqVO.setBatchCode(batch.getCode()); |
| | | } |
| | | } |
| | | |