| | |
| | | import com.ruoyi.common.enums.StockInQualifiedRecordTypeEnum; |
| | | import com.ruoyi.common.enums.StockOutQualifiedRecordTypeEnum; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.production.bean.dto.ProductionOrderPickDto; |
| | | import com.ruoyi.production.bean.vo.ProductionOrderPickVo; |
| | |
| | | BigDecimal totalReturnQty = oldReturnQty.add(currentReturnQty); |
| | | if (currentReturnQty.compareTo(BigDecimal.ZERO) > 0) { |
| | | String returnBatchNo = resolveInventoryBatchNoFromStored(oldPick.getBatchNo()); |
| | | addInventory(oldPick.getId(), oldPick.getProductModelId(), returnBatchNo, currentReturnQty, FEED_RETURN_IN_RECORD_TYPE); |
| | | addInventoryRecordOnly(oldPick.getId(), oldPick.getProductModelId(), returnBatchNo, currentReturnQty, FEED_RETURN_IN_RECORD_TYPE); |
| | | } |
| | | |
| | | BigDecimal actualQty = defaultDecimal(oldPick.getQuantity()) |
| | |
| | | throw ex; |
| | | } catch (Exception ex) { |
| | | throw new ServiceException("回补库存失败:" + ex.getMessage()); |
| | | } |
| | | } |
| | | |
| | | private void addInventoryRecordOnly(Long recordId, |
| | | Long productModelId, |
| | | String batchNo, |
| | | BigDecimal quantity, |
| | | String stockInRecordType) { |
| | | // 仅记录入库申请,不做审核通过。 |
| | | BigDecimal addQuantity = defaultDecimal(quantity); |
| | | if (addQuantity.compareTo(BigDecimal.ZERO) <= 0) { |
| | | return; |
| | | } |
| | | try { |
| | | StockInventoryDto stockInventoryDto = new StockInventoryDto(); |
| | | stockInventoryDto.setProductModelId(productModelId); |
| | | stockInventoryDto.setBatchNo(batchNo); |
| | | stockInventoryDto.setQualitity(addQuantity); |
| | | stockInventoryDto.setRecordType(stockInRecordType); |
| | | stockInventoryDto.setRecordId(recordId == null ? 0L : recordId); |
| | | stockInventoryService.addStockInRecordOnly(stockInventoryDto); |
| | | } catch (ServiceException ex) { |
| | | throw ex; |
| | | } catch (Exception ex) { |
| | | throw new ServiceException("退料入库记录保存失败:" + ex.getMessage()); |
| | | } |
| | | } |
| | | |
| | |
| | | // 数量格式化输出(去除末尾无效0)。 |
| | | return defaultDecimal(value).stripTrailingZeros().toPlainString(); |
| | | } |
| | | |
| | | /** |
| | | * 校验当前用户必须为订单班组长 |
| | | * @param dto 领料DTO |
| | | */ |
| | | private void validateTeamLeader(ProductionOrderPickDto dto) { |
| | | // 获取当前登录用户ID |
| | | Long currentUserId = SecurityUtils.getLoginUser().getUserId(); |
| | | |
| | | // 获取生产订单ID |
| | | Long productionOrderId = resolveProductionOrderId(dto); |
| | | if (productionOrderId == null) { |
| | | throw new ServiceException("生产订单ID不能为空"); |
| | | } |
| | | |
| | | // 查询生产订单 |
| | | ProductionOrder productionOrder = productionOrderMapper.selectById(productionOrderId); |
| | | if (productionOrder == null) { |
| | | throw new ServiceException("生产订单不存在"); |
| | | } |
| | | |
| | | // 获取订单的班组长ID |
| | | Long teamLeaderUserId = productionOrder.getTeamLeaderUserId(); |
| | | if (teamLeaderUserId == null) { |
| | | throw new ServiceException("该订单未设置班组长"); |
| | | } |
| | | |
| | | // 校验当前用户是否为班组长 |
| | | if (!Objects.equals(currentUserId, teamLeaderUserId)) { |
| | | throw new ServiceException("当前用户不是该订单的班组长,无法进行领料操作"); |
| | | } |
| | | } |
| | | } |