|
@@ -114,20 +114,22 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
|
map.put(bomSpecId, inventory);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- BalancePriceNum priceAndNum = baseMapper.getPriceAndNum(bomSpecId, warehouseId);
|
|
|
- if (priceAndNum == null){
|
|
|
- throw new ServiceException("没有该数据");
|
|
|
+ List<InOutStorageDetails> detailsList = getDetailsList(warehouseId, bomSpecIdList);
|
|
|
+ if (CollUtil.isEmpty(detailsList)){
|
|
|
+ for (InOutStorageDetails details : detailsList) {
|
|
|
+ details.setInSumPrice(BigDecimal.ZERO);
|
|
|
+ details.setQuantity(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
}
|
|
|
- BigDecimal balanceNum = priceAndNum.getBalanceNum();
|
|
|
- BigDecimal balancePrice = priceAndNum.getBalancePrice();
|
|
|
-
|
|
|
+ BigDecimal sumPrice = detailsList.stream().map(InOutStorageDetails::getInSumPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ BigDecimal sumQuantity = detailsList.stream().map(InOutStorageDetails::getQuantity).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
|
|
|
|
- balanceNum = balanceNum.add(quantity);
|
|
|
+ sumQuantity = sumQuantity.add(quantity);
|
|
|
+
|
|
|
BigDecimal balancep = quantity.multiply(unitPrice);
|
|
|
- balancePrice = balancePrice.add(balancep);
|
|
|
- BigDecimal balanceUnitPrice = balancePrice.divide(balanceNum, 2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ sumPrice = sumPrice.add(balancep);
|
|
|
+ BigDecimal balanceUnitPrice = sumPrice.divide(sumQuantity, 2, BigDecimal.ROUND_HALF_UP);
|
|
|
inventory.setBalanceUnitPrice(balanceUnitPrice);
|
|
|
}
|
|
|
|
|
@@ -159,7 +161,7 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
|
|
|
|
List<InOutStorageDetails> detailsList = getDetailsList(warehouseId, bomSpecIdList);
|
|
|
if (CollUtil.isEmpty(detailsList)){
|
|
|
- throw new ServiceException("");
|
|
|
+ throw new ServiceException("数据不存在");
|
|
|
}
|
|
|
|
|
|
List<InOutStorageDetails> updateList = new ArrayList<>();
|
|
@@ -167,20 +169,30 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
|
Map<Long, BigDecimal> outPriceMap = new HashMap<>();
|
|
|
|
|
|
int j = 0;
|
|
|
+ BigDecimal num;
|
|
|
BigDecimal quantity;
|
|
|
do {
|
|
|
+
|
|
|
InOutStorageDetails details = detailsList.get(j);
|
|
|
- BigDecimal num = map.get(details.getBomSpecId());
|
|
|
- quantity = details.getQuantity().subtract(num);
|
|
|
- if (quantity.compareTo(BigDecimal.ZERO) < 0){
|
|
|
- throw new ServiceException("出库失败,库存不足");
|
|
|
+
|
|
|
+
|
|
|
+ quantity = map.get(details.getBomSpecId());
|
|
|
+
|
|
|
+
|
|
|
+ num = details.getQuantity().subtract(quantity);
|
|
|
+
|
|
|
+
|
|
|
+ if (num.compareTo(BigDecimal.ZERO) < 0){
|
|
|
+ details.setQuantity(BigDecimal.ZERO);
|
|
|
+ j++;
|
|
|
+ continue;
|
|
|
}
|
|
|
|
|
|
- BigDecimal detailsNum = details.getQuantity().subtract(num);
|
|
|
- details.setQuantity(detailsNum);
|
|
|
+
|
|
|
+ details.setQuantity(num.abs());
|
|
|
|
|
|
|
|
|
- details.setInSumPrice(detailsNum.multiply(details.getInUnitPrice()));
|
|
|
+ details.setInSumPrice(num.abs().multiply(details.getInUnitPrice()));
|
|
|
|
|
|
|
|
|
BigDecimal outPrice = details.getInUnitPrice().multiply(num);
|
|
@@ -189,17 +201,21 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
|
updateList.add(details);
|
|
|
j++;
|
|
|
|
|
|
- }while (quantity.compareTo(BigDecimal.ZERO) > 0);
|
|
|
-
|
|
|
+ }while (num.compareTo(BigDecimal.ZERO) < 0 && j < detailsList.size() );
|
|
|
|
|
|
inOutStorageDetailsService.updateBatchById(updateList);
|
|
|
-
|
|
|
+
|
|
|
|
|
|
for (Inventory inventory : inventoryList) {
|
|
|
|
|
|
BigDecimal balancePrice = inventory.getQuantity().multiply(inventory.getBalanceUnitPrice());
|
|
|
|
|
|
- BigDecimal newBalancePrice = balancePrice.subtract(outPriceMap.get(inventory.getBomSpecId()));
|
|
|
+ BigDecimal newBalancePrice;
|
|
|
+ if (outPriceMap.get(inventory.getBomSpecId()) == null){
|
|
|
+ newBalancePrice = balancePrice.subtract(BigDecimal.ZERO);
|
|
|
+ }else {
|
|
|
+ newBalancePrice = balancePrice.subtract(outPriceMap.get(inventory.getBomSpecId()));
|
|
|
+ }
|
|
|
|
|
|
inventory.setQuantity(inventory.getQuantity().subtract(map.get(inventory.getBomSpecId())));
|
|
|
|
|
@@ -224,6 +240,7 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
|
.eq(InOutStorageDetails::getWarehouseId, warehouseId)
|
|
|
.in(InOutStorageDetails::getBomSpecId, bomSpecIdList)
|
|
|
.isNotNull(InOutStorageDetails::getQuantity)
|
|
|
+
|
|
|
);
|
|
|
}
|
|
|
|