|
@@ -117,7 +117,6 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
inventoryList.add(inventory);
|
|
inventoryList.add(inventory);
|
|
map.put(bomSpecId, inventory);
|
|
map.put(bomSpecId, inventory);
|
|
}
|
|
}
|
|
-
|
|
|
|
List<InOutStorageDetails> detailsList = getDetailsList(warehouseId, bomSpecIdList);
|
|
List<InOutStorageDetails> detailsList = getDetailsList(warehouseId, bomSpecIdList);
|
|
if (CollUtil.isEmpty(detailsList)){
|
|
if (CollUtil.isEmpty(detailsList)){
|
|
for (InOutStorageDetails details : detailsList) {
|
|
for (InOutStorageDetails details : detailsList) {
|
|
@@ -143,9 +142,12 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void out(Long departmentId, Long warehouseId, List<? extends InOutFun> list) {
|
|
public void out(Long departmentId, Long warehouseId, List<? extends InOutFun> list) {
|
|
- Map<Long, BigDecimal> quantityMap = list.stream().collect(Collectors.toMap(InOutFun::getBomSpecId, InOutFun::getQuantity));
|
|
+
|
|
-
|
|
+ Map<Long, BigDecimal> quantityMap = list.stream()
|
|
- Map<Long, BigDecimal> map = list.stream().collect(Collectors.toMap(InOutFun::getBomSpecId, InOutFun::getQuantity));
|
|
+ .collect(Collectors.toMap(InOutFun::getBomSpecId, InOutFun::getQuantity));
|
|
|
|
+
|
|
|
|
+ Map<Long, BigDecimal> map = list.stream()
|
|
|
|
+ .collect(Collectors.toMap(InOutFun::getBomSpecId, InOutFun::getQuantity));
|
|
|
|
|
|
List<Long> bomSpecIdList = new ArrayList<>(map.keySet());
|
|
List<Long> bomSpecIdList = new ArrayList<>(map.keySet());
|
|
|
|
|
|
@@ -153,7 +155,6 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
|
|
|
|
synchronized (this) {
|
|
synchronized (this) {
|
|
List<Inventory> inventoryList = getInventoryList(departmentId, warehouseId, bomSpecIdList);
|
|
List<Inventory> inventoryList = getInventoryList(departmentId, warehouseId, bomSpecIdList);
|
|
-
|
|
|
|
|
|
|
|
for (Inventory inventory : inventoryList) {
|
|
for (Inventory inventory : inventoryList) {
|
|
Long bomSpecId = inventory.getBomSpecId();
|
|
Long bomSpecId = inventory.getBomSpecId();
|
|
@@ -165,17 +166,21 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
throw new ServiceException("出库失败,品名为:" + bomSpec.getName() + "的bom库存不足");
|
|
throw new ServiceException("出库失败,品名为:" + bomSpec.getName() + "的bom库存不足");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
|
|
List<InOutStorageDetails> detailsList = getDetailsList(warehouseId, bomSpecIdList);
|
|
List<InOutStorageDetails> detailsList = getDetailsList(warehouseId, bomSpecIdList);
|
|
|
|
+
|
|
|
|
|
|
- detailsList = detailsList.stream().filter(q -> q.getQuantity().compareTo(BigDecimal.ZERO) > 0).collect(Collectors.toList());
|
|
+
|
|
|
|
+
|
|
|
|
+ detailsList = detailsList.stream()
|
|
|
|
+ .filter(details -> details.getQuantity().compareTo(BigDecimal.ZERO) > 0)
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
|
if (CollUtil.isEmpty(detailsList)) {
|
|
if (CollUtil.isEmpty(detailsList)) {
|
|
- throw new ServiceException("数据不存在");
|
|
+ throw new ServiceException(departmentId + "和" + warehouseId + "的数据为null");
|
|
}
|
|
}
|
|
-
|
|
+ detailsHashMap = detailsList.stream()
|
|
- detailsHashMap = detailsList.stream().collect(Collectors.groupingBy(InOutStorageDetails::getBomSpecId));
|
|
+ .collect(Collectors.groupingBy(InOutStorageDetails::getBomSpecId));
|
|
|
|
|
|
|
|
|
|
List<InOutStorageDetails> updateList = new ArrayList<>();
|
|
List<InOutStorageDetails> updateList = new ArrayList<>();
|
|
@@ -187,26 +192,24 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
int j = 0;
|
|
int j = 0;
|
|
BigDecimal num;
|
|
BigDecimal num;
|
|
BigDecimal quantity;
|
|
BigDecimal quantity;
|
|
-
|
|
|
|
do {
|
|
do {
|
|
|
|
|
|
InOutStorageDetails details = outStorageDetails.get(j);
|
|
InOutStorageDetails details = outStorageDetails.get(j);
|
|
|
|
|
|
|
|
+
|
|
|
|
+ BigDecimal allQuantity = baseMapper.getQuantityByBomSpecId(details.getBomSpecId(), details.getWarehouseId());
|
|
|
|
+ if (allQuantity.compareTo(quantityMap.get(details.getBomSpecId())) < 0) {
|
|
|
|
+ throw new ServiceException(details.getBomSpecId() + "这种规格的库存不够,库存数量为" + details.getQuantity());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
if (j == outStorageDetails.size() - 1) {
|
|
if (j == outStorageDetails.size() - 1) {
|
|
BigDecimal naxtQuantity = outStorageDetails.get(j).getQuantity();
|
|
BigDecimal naxtQuantity = outStorageDetails.get(j).getQuantity();
|
|
|
|
|
|
if (naxtQuantity.compareTo(map.get(details.getBomSpecId())) < 0) {
|
|
if (naxtQuantity.compareTo(map.get(details.getBomSpecId())) < 0) {
|
|
- throw new ServiceException("库存不够!!");
|
|
+ throw new ServiceException(details.getBomSpecId() + "这种规格的库存不够,库存数量为" + details.getQuantity());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
- BigDecimal allQuantity = baseMapper.getQuantityByBomSpecId(details.getBomSpecId(), details.getWarehouseId());
|
|
|
|
- if (allQuantity.compareTo(quantityMap.get(details.getBomSpecId())) < 0) {
|
|
|
|
- throw new ServiceException("库存不够!");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
|
|
quantity = map.get(details.getBomSpecId());
|
|
quantity = map.get(details.getBomSpecId());
|
|
|
|
|
|
@@ -225,6 +228,9 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
j++;
|
|
j++;
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ addOutPriceMap(outPriceMap, map, details);
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
details.setQuantity(num.abs());
|
|
details.setQuantity(num.abs());
|
|
@@ -233,13 +239,9 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
BigDecimal multiply = num.abs().multiply(details.getInUnitPrice());
|
|
BigDecimal multiply = num.abs().multiply(details.getInUnitPrice());
|
|
details.setInSumPrice(multiply);
|
|
details.setInSumPrice(multiply);
|
|
|
|
|
|
-
|
|
|
|
- addOutPriceMap(outPriceMap, map, details);
|
|
|
|
-
|
|
|
|
|
|
|
|
updateList.add(details);
|
|
updateList.add(details);
|
|
j++;
|
|
j++;
|
|
-
|
|
|
|
} while (num.compareTo(BigDecimal.ZERO) < 0 && j < outStorageDetails.size());
|
|
} while (num.compareTo(BigDecimal.ZERO) < 0 && j < outStorageDetails.size());
|
|
}
|
|
}
|
|
inOutStorageDetailsService.updateBatchById(updateList);
|
|
inOutStorageDetailsService.updateBatchById(updateList);
|
|
@@ -272,8 +274,16 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
|
|
|
|
|
|
|
|
private void addOutPriceMap(Map<Long, BigDecimal> outPriceMap, Map<Long, BigDecimal> map, InOutStorageDetails details) {
|
|
private void addOutPriceMap(Map<Long, BigDecimal> outPriceMap, Map<Long, BigDecimal> map, InOutStorageDetails details) {
|
|
|
|
+
|
|
BigDecimal mapQuantity = map.get(details.getBomSpecId());
|
|
BigDecimal mapQuantity = map.get(details.getBomSpecId());
|
|
- BigDecimal multiply = mapQuantity.multiply(details.getInUnitPrice());
|
|
+ BigDecimal multiply;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if (mapQuantity.compareTo(details.getQuantity()) > 0) {
|
|
|
|
+ multiply = details.getQuantity().multiply(details.getInUnitPrice());
|
|
|
|
+ } else {
|
|
|
|
+ multiply = mapQuantity.multiply(details.getInUnitPrice());
|
|
|
|
+ }
|
|
if (outPriceMap.containsKey(details.getBomSpecId())) {
|
|
if (outPriceMap.containsKey(details.getBomSpecId())) {
|
|
BigDecimal naxtPrice = outPriceMap.get(details.getBomSpecId());
|
|
BigDecimal naxtPrice = outPriceMap.get(details.getBomSpecId());
|
|
BigDecimal addPrice = naxtPrice.add(multiply);
|
|
BigDecimal addPrice = naxtPrice.add(multiply);
|
|
@@ -294,9 +304,9 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
private List<InOutStorageDetails> getDetailsList(Long warehouseId, List<Long> bomSpecIdList) {
|
|
private List<InOutStorageDetails> getDetailsList(Long warehouseId, List<Long> bomSpecIdList) {
|
|
return inOutStorageDetailsService.list(q -> q
|
|
return inOutStorageDetailsService.list(q -> q
|
|
.eq(InOutStorageDetails::getWarehouseId, warehouseId)
|
|
.eq(InOutStorageDetails::getWarehouseId, warehouseId)
|
|
- .in(InOutStorageDetails::getBomSpecId, bomSpecIdList)
|
|
+ .eq(InOutStorageDetails::getDelFlag, 0)
|
|
- .isNotNull(InOutStorageDetails::getQuantity)
|
|
+ .in(InOutStorageDetails::getBomSpecId, bomSpecIdList)
|
|
-
|
|
+ .isNotNull(InOutStorageDetails::getQuantity)
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|