| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.math.BigDecimal; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | stockInRecordService.add(stockInRecordDto); |
| | | //再进行新增库存数量库存 |
| | | //先查询库存表中的产品是否存在,不存在新增,存在更新 |
| | | StockUninventory oldStockUnInventory = stockUninventoryMapper.selectOne(new QueryWrapper<StockUninventory>().lambda().eq(StockUninventory::getProductModelId, stockUninventoryDto.getProductModelId())); |
| | | List<StockUninventory> stockUninventories = stockUninventoryMapper.selectList(new QueryWrapper<StockUninventory>().lambda() |
| | | .eq(StockUninventory::getProductModelId, stockUninventoryDto.getProductModelId()) |
| | | .orderByDesc(StockUninventory::getId)); |
| | | StockUninventory oldStockUnInventory = (stockUninventories == null || stockUninventories.isEmpty()) ? null : stockUninventories.get(0); |
| | | if (ObjectUtils.isEmpty(oldStockUnInventory)) { |
| | | StockUninventory newStockUnInventory = new StockUninventory(); |
| | | newStockUnInventory.setProductModelId(stockUninventoryDto.getProductModelId()); |
| | | newStockUnInventory.setQualitity(stockUninventoryDto.getQualitity()); |
| | | newStockUnInventory.setLockedQuantity(stockUninventoryDto.getLockedQuantity()); |
| | | newStockUnInventory.setVersion(1); |
| | | newStockUnInventory.setRemark(stockUninventoryDto.getRemark()); |
| | | stockUninventoryMapper.insert(newStockUnInventory); |
| | |
| | | stockOutRecordDto.setSalesLedgerId(stockUninventoryDto.getSalesLedgerId()); |
| | | stockOutRecordDto.setSalesLedgerProductId(stockUninventoryDto.getSalesLedgerProductId()); |
| | | stockOutRecordService.add(stockOutRecordDto); |
| | | StockUninventory oldStockInventory = stockUninventoryMapper.selectOne(new QueryWrapper<StockUninventory>().lambda().eq(StockUninventory::getProductModelId, stockUninventoryDto.getProductModelId())); |
| | | List<StockUninventory> stockUninventories = stockUninventoryMapper.selectList(new QueryWrapper<StockUninventory>().lambda() |
| | | .eq(StockUninventory::getProductModelId, stockUninventoryDto.getProductModelId()) |
| | | .orderByDesc(StockUninventory::getId)); |
| | | StockUninventory oldStockInventory = (stockUninventories == null || stockUninventories.isEmpty()) ? null : stockUninventories.get(0); |
| | | if (ObjectUtils.isEmpty(oldStockInventory)) { |
| | | throw new RuntimeException("产品库存不存在"); |
| | | }else { |
| | |
| | | @Override |
| | | public Boolean frozenStock(StockInventoryDto stockInventoryDto) { |
| | | StockUninventory stockUninventory = stockUninventoryMapper.selectById(stockInventoryDto.getId()); |
| | | if (stockUninventory.getQualitity().compareTo(stockInventoryDto.getLockedQuantity())<0) { |
| | | throw new RuntimeException("冻结数量不能超过库存数量"); |
| | | if (ObjectUtils.isEmpty(stockUninventory)) { |
| | | throw new RuntimeException("库存记录不存在"); |
| | | } |
| | | if (ObjectUtils.isEmpty(stockUninventory.getLockedQuantity())) { |
| | | stockUninventory.setLockedQuantity(stockInventoryDto.getLockedQuantity()); |
| | | }else { |
| | | stockUninventory.setLockedQuantity(stockUninventory.getLockedQuantity().add(stockInventoryDto.getLockedQuantity())); |
| | | if (ObjectUtils.isEmpty(stockInventoryDto.getLockedQuantity()) || stockInventoryDto.getLockedQuantity().compareTo(BigDecimal.ZERO) <= 0) { |
| | | throw new RuntimeException("冻结数量必须大于0"); |
| | | } |
| | | BigDecimal totalQty = ObjectUtils.isEmpty(stockUninventory.getQualitity()) ? BigDecimal.ZERO : stockUninventory.getQualitity(); |
| | | BigDecimal currentLockedQty = ObjectUtils.isEmpty(stockUninventory.getLockedQuantity()) ? BigDecimal.ZERO : stockUninventory.getLockedQuantity(); |
| | | BigDecimal availableQty = totalQty.subtract(currentLockedQty); |
| | | if (stockInventoryDto.getLockedQuantity().compareTo(availableQty) > 0) { |
| | | throw new RuntimeException("冻结数量不能超过可冻结库存数量"); |
| | | } |
| | | stockUninventory.setLockedQuantity(currentLockedQty.add(stockInventoryDto.getLockedQuantity())); |
| | | return this.updateById(stockUninventory); |
| | | } |
| | | |
| | | @Override |
| | | public Boolean thawStock(StockInventoryDto stockInventoryDto) { |
| | | StockUninventory stockUninventory = stockUninventoryMapper.selectById(stockInventoryDto.getId()); |
| | | if (stockUninventory.getLockedQuantity().compareTo(stockInventoryDto.getLockedQuantity())<0) { |
| | | if (ObjectUtils.isEmpty(stockUninventory)) { |
| | | throw new RuntimeException("库存记录不存在"); |
| | | } |
| | | if (ObjectUtils.isEmpty(stockInventoryDto.getLockedQuantity()) || stockInventoryDto.getLockedQuantity().compareTo(BigDecimal.ZERO) <= 0) { |
| | | throw new RuntimeException("解冻数量必须大于0"); |
| | | } |
| | | BigDecimal currentLockedQty = ObjectUtils.isEmpty(stockUninventory.getLockedQuantity()) ? BigDecimal.ZERO : stockUninventory.getLockedQuantity(); |
| | | if (currentLockedQty.compareTo(stockInventoryDto.getLockedQuantity()) < 0) { |
| | | throw new RuntimeException("解冻数量不能超过冻结数量"); |
| | | } |
| | | stockUninventory.setLockedQuantity(stockUninventory.getLockedQuantity().subtract(stockInventoryDto.getLockedQuantity())); |
| | | stockUninventory.setLockedQuantity(currentLockedQty.subtract(stockInventoryDto.getLockedQuantity())); |
| | | return this.updateById(stockUninventory); |
| | | } |
| | | } |