|
@@ -1,5 +1,7 @@
|
|
package com.sd.business.service.inventory.impl;
|
|
package com.sd.business.service.inventory.impl;
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
@@ -19,6 +21,7 @@ import com.sd.business.entity.inventory.vo.QuantityByWarehouseVo;
|
|
import com.sd.business.mapper.inventory.InventoryMapper;
|
|
import com.sd.business.mapper.inventory.InventoryMapper;
|
|
import com.sd.business.service.bom.BomSpecService;
|
|
import com.sd.business.service.bom.BomSpecService;
|
|
import com.sd.business.service.in.InOutStorageDetailsService;
|
|
import com.sd.business.service.in.InOutStorageDetailsService;
|
|
|
|
+import com.sd.business.service.in.impl.InOutStorageServiceImpl;
|
|
import com.sd.business.service.inventory.InventoryService;
|
|
import com.sd.business.service.inventory.InventoryService;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -96,7 +99,7 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
for (InOutFun inOutFun : list) {
|
|
for (InOutFun inOutFun : list) {
|
|
Long bomSpecId = inOutFun.getBomSpecId();
|
|
Long bomSpecId = inOutFun.getBomSpecId();
|
|
BigDecimal quantity = inOutFun.getQuantity();
|
|
BigDecimal quantity = inOutFun.getQuantity();
|
|
- BigDecimal unitPrice = inOutFun.getUnitPrice();
|
|
+ BigDecimal unitPrice = InOutStorageServiceImpl.UNITPRICE;
|
|
Inventory inventory = map.get(bomSpecId);
|
|
Inventory inventory = map.get(bomSpecId);
|
|
|
|
|
|
if (inventory != null) {
|
|
if (inventory != null) {
|
|
@@ -113,9 +116,13 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
|
|
|
|
|
|
|
|
BalancePriceNum priceAndNum = baseMapper.getPriceAndNum(bomSpecId, warehouseId);
|
|
BalancePriceNum priceAndNum = baseMapper.getPriceAndNum(bomSpecId, warehouseId);
|
|
|
|
+ if (priceAndNum == null){
|
|
|
|
+ throw new ServiceException("没有该数据");
|
|
|
|
+ }
|
|
BigDecimal balanceNum = priceAndNum.getBalanceNum();
|
|
BigDecimal balanceNum = priceAndNum.getBalanceNum();
|
|
BigDecimal balancePrice = priceAndNum.getBalancePrice();
|
|
BigDecimal balancePrice = priceAndNum.getBalancePrice();
|
|
|
|
|
|
|
|
+
|
|
|
|
|
|
balanceNum = balanceNum.add(quantity);
|
|
balanceNum = balanceNum.add(quantity);
|
|
BigDecimal balancep = quantity.multiply(unitPrice);
|
|
BigDecimal balancep = quantity.multiply(unitPrice);
|
|
@@ -151,83 +158,73 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
|
|
|
|
|
|
|
|
List<InOutStorageDetails> detailsList = getDetailsList(warehouseId, bomSpecIdList);
|
|
List<InOutStorageDetails> detailsList = getDetailsList(warehouseId, bomSpecIdList);
|
|
- List<InOutStorageDetails> updateList = new ArrayList<>();
|
|
+ if (CollUtil.isEmpty(detailsList)){
|
|
- List<InOutStorageDetails> outDetailsList = new ArrayList<>();
|
|
+ throw new ServiceException("");
|
|
- Map<Long,BigDecimal> outPriceMap = new HashMap<>();
|
|
|
|
-
|
|
|
|
- for (int i = 0; i < detailsList.size(); i++) {
|
|
|
|
- InOutStorageDetails details = detailsList.get(i);
|
|
|
|
}
|
|
}
|
|
-
|
|
+
|
|
- for (InOutStorageDetails details : detailsList) {
|
|
+ List<InOutStorageDetails> updateList = new ArrayList<>();
|
|
-
|
|
+
|
|
- BigDecimal outNum = map.get(details.getBomSpecId());
|
|
+ Map<Long, BigDecimal> outPriceMap = new HashMap<>();
|
|
- if (details.getQuantity().compareTo(outNum) >= 0){
|
|
+
|
|
-
|
|
+ int j = 0;
|
|
- details.setQuantity(details.getQuantity().subtract(outNum));
|
|
+ BigDecimal quantity;
|
|
-
|
|
+ do {
|
|
-
|
|
+ InOutStorageDetails details = detailsList.get(j);
|
|
- BigDecimal outPrice = details.getInUnitPrice().multiply(outNum);
|
|
+ BigDecimal num = map.get(details.getBomSpecId());
|
|
- outPriceMap.put(details.getBomSpecId(),outPrice);
|
|
+ quantity = details.getQuantity().subtract(num);
|
|
-
|
|
+ if (quantity.compareTo(BigDecimal.ZERO) < 0){
|
|
-
|
|
+ throw new ServiceException("出库失败,库存不足");
|
|
- updateList.add(details);
|
|
|
|
-
|
|
|
|
- InOutStorageDetails outStorageDetails = new InOutStorageDetails();
|
|
|
|
-
|
|
|
|
- BeanUtils.copyProperties(details,outStorageDetails);
|
|
|
|
-
|
|
|
|
- outStorageDetails.setQuantity(outNum);
|
|
|
|
- outStorageDetails.setId(null);
|
|
|
|
- outStorageDetails.setType(0L);
|
|
|
|
-
|
|
|
|
- outDetailsList.add(outStorageDetails);
|
|
|
|
- break;
|
|
|
|
}
|
|
}
|
|
-
|
|
+
|
|
-
|
|
+ BigDecimal detailsNum = details.getQuantity().subtract(num);
|
|
- BigDecimal remainderNum = outNum.subtract(details.getQuantity());
|
|
+ details.setQuantity(detailsNum);
|
|
- if (remainderNum.compareTo(BigDecimal.ZERO) > 0) {
|
|
+
|
|
- details.setQuantity(BigDecimal.ZERO);
|
|
+
|
|
- updateList.add(details);
|
|
+ details.setInSumPrice(detailsNum.multiply(details.getInUnitPrice()));
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ BigDecimal outPrice = details.getInUnitPrice().multiply(num);
|
|
|
|
+ outPriceMap.put(details.getBomSpecId(), outPrice);
|
|
|
|
+
|
|
|
|
+ updateList.add(details);
|
|
|
|
+ j++;
|
|
|
|
+
|
|
|
|
+ }while (quantity.compareTo(BigDecimal.ZERO) > 0);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ inOutStorageDetailsService.updateBatchById(updateList);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ for (Inventory inventory : inventoryList) {
|
|
|
|
+
|
|
|
|
+ BigDecimal balancePrice = inventory.getQuantity().multiply(inventory.getBalanceUnitPrice());
|
|
|
|
+
|
|
|
|
+ BigDecimal newBalancePrice = balancePrice.subtract(outPriceMap.get(inventory.getBomSpecId()));
|
|
|
|
+
|
|
|
|
+ inventory.setQuantity(inventory.getQuantity().subtract(map.get(inventory.getBomSpecId())));
|
|
|
|
+
|
|
|
|
+ BigDecimal balanceUnitPrice = newBalancePrice.divide(inventory.getQuantity(), 2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
+
|
|
|
|
+ inventory.setBalanceUnitPrice(balanceUnitPrice);
|
|
}
|
|
}
|
|
-
|
|
+ updateBatchById(inventoryList);
|
|
-
|
|
|
|
- }
|
|
|
|
- inOutStorageDetailsService.updateBatchById(updateList);
|
|
|
|
- inOutStorageDetailsService.saveBatch(outDetailsList);
|
|
|
|
-
|
|
|
|
- for (Inventory inventory : inventoryList) {
|
|
|
|
-
|
|
|
|
- BigDecimal balancePrice = inventory.getQuantity().multiply(inventory.getBalanceUnitPrice());
|
|
|
|
-
|
|
|
|
- BigDecimal newBalancePrice = balancePrice.subtract(outPriceMap.get(inventory.getBomSpecId()));
|
|
|
|
-
|
|
|
|
- inventory.setQuantity(inventory.getQuantity().subtract(map.get(inventory.getBomSpecId())));
|
|
|
|
-
|
|
|
|
- BigDecimal balanceUnitPrice = newBalancePrice.divide(inventory.getQuantity(), 2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
-
|
|
|
|
- inventory.setBalanceUnitPrice(balanceUnitPrice);
|
|
|
|
}
|
|
}
|
|
- updateBatchById(inventoryList);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
|
|
- private List<Inventory> getInventoryList(Long departmentId, Long warehouseId, List<Long> bomSpecIdList) {
|
|
|
|
- return list(q -> q
|
|
|
|
- .eq(Inventory::getDepartmentId, departmentId)
|
|
|
|
- .eq(Inventory::getWarehouseId, warehouseId)
|
|
|
|
- .in(Inventory::getBomSpecId, bomSpecIdList)
|
|
|
|
- );
|
|
|
|
}
|
|
}
|
|
|
|
+ private List<Inventory> getInventoryList (Long departmentId, Long warehouseId, List < Long > bomSpecIdList){
|
|
|
|
+ return list(q -> q
|
|
|
|
+ .eq(Inventory::getDepartmentId, departmentId)
|
|
|
|
+ .eq(Inventory::getWarehouseId, warehouseId)
|
|
|
|
+ .in(Inventory::getBomSpecId, bomSpecIdList)
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
|
|
- 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)
|
|
+ .in(InOutStorageDetails::getBomSpecId, bomSpecIdList)
|
|
- .isNotNull(InOutStorageDetails::getQuantity)
|
|
+ .isNotNull(InOutStorageDetails::getQuantity)
|
|
- );
|
|
+ );
|
|
- }
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|