src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java
@@ -261,24 +261,36 @@ @Override public Boolean frozenStock(StockInventoryDto stockInventoryDto) { StockInventory stockInventory = stockInventoryMapper.selectById(stockInventoryDto.getId()); if (stockInventory.getQualitity().compareTo(stockInventoryDto.getLockedQuantity()) < 0) { throw new RuntimeException("冻结数量不能超过库存数量"); if (ObjectUtils.isEmpty(stockInventory)) { throw new ServiceException("库存记录不存在"); } if (ObjectUtils.isEmpty(stockInventory.getLockedQuantity())) { stockInventory.setLockedQuantity(stockInventoryDto.getLockedQuantity()); } else { stockInventory.setLockedQuantity(stockInventory.getLockedQuantity().add(stockInventoryDto.getLockedQuantity())); if (ObjectUtils.isEmpty(stockInventoryDto.getLockedQuantity()) || stockInventoryDto.getLockedQuantity().compareTo(BigDecimal.ZERO) <= 0) { throw new ServiceException("冻结数量必须大于0"); } BigDecimal totalQty = ObjectUtils.isEmpty(stockInventory.getQualitity()) ? BigDecimal.ZERO : stockInventory.getQualitity(); BigDecimal currentLockedQty = ObjectUtils.isEmpty(stockInventory.getLockedQuantity()) ? BigDecimal.ZERO : stockInventory.getLockedQuantity(); BigDecimal availableQty = totalQty.subtract(currentLockedQty); if (stockInventoryDto.getLockedQuantity().compareTo(availableQty) > 0) { throw new ServiceException("冻结数量不能超过可冻结库存数量"); } stockInventory.setLockedQuantity(currentLockedQty.add(stockInventoryDto.getLockedQuantity())); return this.updateById(stockInventory); } @Override public Boolean thawStock(StockInventoryDto stockInventoryDto) { StockInventory stockInventory = stockInventoryMapper.selectById(stockInventoryDto.getId()); if (stockInventory.getLockedQuantity().compareTo(stockInventoryDto.getLockedQuantity()) < 0) { throw new RuntimeException("解冻数量不能超过冻结数量"); if (ObjectUtils.isEmpty(stockInventory)) { throw new ServiceException("库存记录不存在"); } stockInventory.setLockedQuantity(stockInventory.getLockedQuantity().subtract(stockInventoryDto.getLockedQuantity())); if (ObjectUtils.isEmpty(stockInventoryDto.getLockedQuantity()) || stockInventoryDto.getLockedQuantity().compareTo(BigDecimal.ZERO) <= 0) { throw new ServiceException("解冻数量必须大于0"); } BigDecimal currentLockedQty = ObjectUtils.isEmpty(stockInventory.getLockedQuantity()) ? BigDecimal.ZERO : stockInventory.getLockedQuantity(); if (currentLockedQty.compareTo(stockInventoryDto.getLockedQuantity()) < 0) { throw new ServiceException("解冻数量不能超过冻结数量"); } stockInventory.setLockedQuantity(currentLockedQty.subtract(stockInventoryDto.getLockedQuantity())); return this.updateById(stockInventory); } src/main/java/com/ruoyi/stock/service/impl/StockUninventoryServiceImpl.java
@@ -21,6 +21,7 @@ import org.springframework.transaction.annotation.Transactional; import javax.servlet.http.HttpServletResponse; import java.math.BigDecimal; import java.util.List; /** @@ -116,24 +117,36 @@ @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); } }