| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int batchApprove(List<Long> ids, Integer approvalStatus) { |
| | | if (CollectionUtils.isEmpty(ids)) { |
| | | public int batchApprove(Integer approvalStatus, List<StockInRecordDto.StockInRecordApproveItemDto> items) { |
| | | if (CollectionUtils.isEmpty(items)) { |
| | | throw new BaseException("请选择至少一条数据"); |
| | | } |
| | | if (approvalStatus == null || (!ReviewStatusEnum.APPROVED.getCode().equals(approvalStatus) && !ReviewStatusEnum.REJECTED.getCode().equals(approvalStatus))) { |
| | | throw new BaseException("审批状态值无效"); |
| | | } |
| | | for (Long id : ids) { |
| | | for (StockInRecordDto.StockInRecordApproveItemDto item : items) { |
| | | Long id = item.getId(); |
| | | if (id == null) { |
| | | throw new BaseException("入库记录ID不能为空"); |
| | | } |
| | | StockInRecord stockInRecord = stockInRecordMapper.selectById(id); |
| | | if (stockInRecord == null) { |
| | | throw new BaseException("入库记录不存在,无法审批!!!"); |
| | |
| | | if (stockInRecord.getApprovalStatus() != null && !ReviewStatusEnum.PENDING_REVIEW.getCode().equals(stockInRecord.getApprovalStatus())) { |
| | | throw new BaseException("只有待审批状态的记录才能审批,入库批次:" + stockInRecord.getInboundBatches()); |
| | | } |
| | | |
| | | // 获取审批时修改的入库数量,如果没有修改则使用原数量 |
| | | final BigDecimal finalStockInNum; |
| | | if (item.getStockInNum() != null && item.getStockInNum().compareTo(BigDecimal.ZERO) > 0) { |
| | | finalStockInNum = item.getStockInNum(); |
| | | // 更新入库记录的入库数量 |
| | | stockInRecord.setStockInNum(finalStockInNum); |
| | | } else { |
| | | finalStockInNum = stockInRecord.getStockInNum(); |
| | | } |
| | | |
| | | stockInRecord.setApprovalStatus(approvalStatus); |
| | | stockInRecordMapper.updateById(stockInRecord); |
| | | |
| | |
| | | // 合格入库 -> 先查库存,存在则更新,不存在则新增 |
| | | StockInventory stockInventory = getStockInventory(stockInRecord.getProductModelId(), stockInRecord.getBatchNo()); |
| | | StockInventoryDto stockInventoryDto = getStockInventoryDto(stockInRecord); |
| | | stockInventoryDto.setQualitity(finalStockInNum); |
| | | if (stockInventory == null) { |
| | | stockInventoryMapper.insert(new StockInventory() {{ |
| | | setProductModelId(stockInRecord.getProductModelId()); |
| | | setQualitity(stockInRecord.getStockInNum()); |
| | | setQualitity(finalStockInNum); |
| | | setBatchNo(stockInRecord.getBatchNo()); |
| | | setRemark(stockInRecord.getRemark()); |
| | | setWarnNum(stockInRecord.getWarnNum()); |
| | |
| | | StockUninventoryDto stockUninventoryDto = new StockUninventoryDto(); |
| | | stockUninventoryDto.setProductModelId(stockInRecord.getProductModelId()); |
| | | stockUninventoryDto.setBatchNo(stockInRecord.getBatchNo()); |
| | | stockUninventoryDto.setQualitity(stockInRecord.getStockInNum()); |
| | | stockUninventoryDto.setQualitity(finalStockInNum); |
| | | stockUninventoryDto.setRemark(stockInRecord.getRemark()); |
| | | stockUninventoryDto.setManufacturerId(stockInRecord.getManufacturerId()); |
| | | stockUninventoryDto.setSource(stockInRecord.getSource()); |
| | | if (stockUninventory == null) { |
| | | stockUninventoryMapper.insert(new StockUninventory() {{ |
| | | setProductModelId(stockInRecord.getProductModelId()); |
| | | setQualitity(stockInRecord.getStockInNum()); |
| | | setQualitity(finalStockInNum); |
| | | setBatchNo(stockInRecord.getBatchNo()); |
| | | setRemark(stockInRecord.getRemark()); |
| | | setManufacturerId(stockInRecord.getManufacturerId()); |
| | |
| | | } |
| | | } |
| | | } |
| | | return ids.size(); |
| | | return items.size(); |
| | | } |
| | | |
| | | private static @NonNull StockInventoryDto getStockInventoryDto(StockInRecord stockInRecord) { |