| | |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.miscissue.MesWmMiscIssueLineDO; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.wm.miscissue.MesWmMiscIssueLineMapper; |
| | | import cn.iocoder.yudao.module.mes.service.mdm.MesMdmItemService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.unitconvert.MesWmItemUnitConvertService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.warehouse.MesWmWarehouseAreaService; |
| | | import jakarta.annotation.Resource; |
| | | import org.springframework.context.annotation.Lazy; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | 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; |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.WM_MISC_ISSUE_LINE_NOT_EXISTS; |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.WM_MISC_ISSUE_LINE_QUANTITY_REQUIRED; |
| | | |
| | | /** |
| | | * MES 杂项出库单行 Service 实现类 |
| | |
| | | private MesMdmItemService mdmItemService; |
| | | @Resource |
| | | private MesWmWarehouseAreaService warehouseAreaService; |
| | | @Resource |
| | | private MesWmItemUnitConvertService itemUnitConvertService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | // 1. 校验数据 |
| | | validateMiscIssueLineSaveData(createReqVO.getIssueId(), createReqVO); |
| | | |
| | | // 2. 新增行 |
| | | // 2. 双单位换算:按录入单位换算为物料主单位数量 |
| | | fillPrimaryQuantity(createReqVO); |
| | | |
| | | // 3. 新增行 |
| | | MesWmMiscIssueLineDO line = BeanUtils.toBean(createReqVO, MesWmMiscIssueLineDO.class); |
| | | miscIssueLineMapper.insert(line); |
| | | |
| | | // 3.自动创建明细 |
| | | // 4.自动创建明细 |
| | | createReqVO.setId(line.getId()); |
| | | miscIssueDetailService.createMiscIssueDetail(createReqVO); |
| | | return line.getId(); |
| | |
| | | // 1.2 校验数据 |
| | | validateMiscIssueLineSaveData(line.getIssueId(), updateReqVO); |
| | | |
| | | // 2. 更新行 |
| | | // 2. 双单位换算:按录入单位换算为物料主单位数量 |
| | | fillPrimaryQuantity(updateReqVO); |
| | | |
| | | // 3. 更新行 |
| | | MesWmMiscIssueLineDO updateObj = BeanUtils.toBean(updateReqVO, MesWmMiscIssueLineDO.class); |
| | | miscIssueLineMapper.updateById(updateObj); |
| | | |
| | | // 3. 更新明细(基于行信息) |
| | | // 4. 更新明细(基于行信息) |
| | | miscIssueDetailService.updateMiscIssueDetail(updateReqVO); |
| | | } |
| | | |
| | | /** |
| | | * 双单位换算:选择了录入单位时,按「录入数量 × 换算比率」得到物料主单位口径的出库数量 |
| | | * |
| | | * 换算结果写回请求参数,使行与 1:1 明细的口径保持一致;未按辅单位录入时必须直接填写出库数量 |
| | | */ |
| | | private void fillPrimaryQuantity(MesWmMiscIssueLineSaveReqVO reqVO) { |
| | | if (reqVO.getEnterUnitMeasureId() != null) { |
| | | BigDecimal primaryQuantity = itemUnitConvertService.convertToPrimaryUnit( |
| | | reqVO.getItemId(), reqVO.getItemModelId(), |
| | | reqVO.getEnterUnitMeasureId(), reqVO.getEnterQuantity()); |
| | | if (primaryQuantity != null) { |
| | | reqVO.setQuantity(primaryQuantity); |
| | | } |
| | | } |
| | | if (reqVO.getQuantity() == null) { |
| | | throw exception(WM_MISC_ISSUE_LINE_QUANTITY_REQUIRED); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void deleteMiscIssueLine(Long id) { |