|
@@ -4,11 +4,9 @@ import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.ruoyi.common.constant.StatusConstant;
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
import com.sd.business.entity.bom.po.Bom;
|
|
|
import com.sd.business.entity.bom.po.BomSpec;
|
|
|
-import com.sd.business.entity.department.constant.DepartmentConstant;
|
|
|
import com.sd.business.entity.department.po.Department;
|
|
|
import com.sd.business.entity.in.po.InOutStorageBalance;
|
|
|
import com.sd.business.entity.in.po.InOutStorageBom;
|
|
@@ -21,9 +19,7 @@ import com.sd.business.entity.inventory.po.Inventory;
|
|
|
import com.sd.business.entity.inventory.vo.InventoryVo;
|
|
|
import com.sd.business.entity.inventory.vo.QuantityByDepartmentVo;
|
|
|
import com.sd.business.entity.inventory.vo.QuantityByWarehouseVo;
|
|
|
-import com.sd.business.entity.order.po.OrderSku;
|
|
|
import com.sd.business.entity.purchase.po.PurchaseBom;
|
|
|
-import com.sd.business.entity.warehouse.constant.WarehouseConstant;
|
|
|
import com.sd.business.entity.warehouse.po.Warehouse;
|
|
|
import com.sd.business.mapper.inventory.InventoryMapper;
|
|
|
import com.sd.business.service.bom.BomSpecService;
|
|
@@ -42,7 +38,6 @@ import java.util.Collection;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -80,7 +75,6 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
|
.selectAs(BomSpec::getName, InventoryVo::getBomSpecName)
|
|
|
.selectAs(Department::getName, InventoryVo::getDepartmentName)
|
|
|
.multiply(Inventory::getQuantity, Inventory::getBalanceUnitPrice, InventoryVo::getTotalPrice)
|
|
|
- .add(Inventory::getQuantity, Inventory::getLockQuantity, InventoryVo::getTotalQuantity)
|
|
|
|
|
|
.from(Inventory.class)
|
|
|
.leftJoin(BomSpec.class, Inventory::getBomSpecId)
|
|
@@ -157,71 +151,6 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public boolean lockStorage(Map<Long, BigDecimal> map, Long warehouseId) {
|
|
|
- if (ObjectUtil.isEmpty(map)) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- synchronized (this) {
|
|
|
- List<Inventory> list = list(q -> q
|
|
|
- .in(Inventory::getBomSpecId, map.keySet())
|
|
|
- .eq(Inventory::getWarehouseId, warehouseId)
|
|
|
- .eq(Inventory::getDepartmentId, DepartmentConstant.SD_SPORTS)
|
|
|
- );
|
|
|
- if (map.size() != list.size()) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- for (Inventory inventory : list) {
|
|
|
- BigDecimal lockQuantity = map.get(inventory.getBomSpecId());
|
|
|
- if (inventory.getQuantity().compareTo(lockQuantity) >= 0) {
|
|
|
- inventory.setQuantity(inventory.getQuantity().subtract(lockQuantity));
|
|
|
- inventory.setLockQuantity(inventory.getLockQuantity().add(lockQuantity));
|
|
|
- } else {
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
- this.updateBatchById(list);
|
|
|
- }
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean lockStorage(List<OrderSku> orderSkuList) {
|
|
|
- Map<Long, BigDecimal> map = orderSkuList.stream()
|
|
|
- .collect(Collectors.toMap(OrderSku::getBomSpecId, OrderSku::getQuantity, BigDecimal::add));
|
|
|
- return lockStorage(map, WarehouseConstant.SEMI_FINISHED_PRODUCT);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void unlockStorage(Map<Long, BigDecimal> map, Long warehouseId) {
|
|
|
- if (ObjectUtil.isEmpty(map)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- synchronized (this) {
|
|
|
- List<Inventory> list = list(q -> q
|
|
|
- .in(Inventory::getBomSpecId, map.keySet())
|
|
|
- .eq(Inventory::getWarehouseId, warehouseId)
|
|
|
- .eq(Inventory::getDepartmentId, DepartmentConstant.SD_SPORTS)
|
|
|
- );
|
|
|
- for (Inventory inventory : list) {
|
|
|
- BigDecimal lockQuantity = map.get(inventory.getBomSpecId());
|
|
|
- inventory.setQuantity(inventory.getQuantity().add(lockQuantity));
|
|
|
- inventory.setLockQuantity(inventory.getLockQuantity().subtract(lockQuantity));
|
|
|
- }
|
|
|
- updateBatchById(list);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void unlockStorage(List<OrderSku> orderSkuList) {
|
|
|
- if (orderSkuList.isEmpty()) {
|
|
|
- return;
|
|
|
- }
|
|
|
- Map<Long, BigDecimal> map = orderSkuList.stream()
|
|
|
- .collect(Collectors.toMap(OrderSku::getBomSpecId, OrderSku::getQuantity, BigDecimal::add));
|
|
|
- unlockStorage(map, WarehouseConstant.SEMI_FINISHED_PRODUCT);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
public void purchaseInStorage(Long purchaseId, Long departmentId, Long warehouseId, List<InOutStorageBom> inOutStorageBomList) {
|
|
|
List<Long> bomSpecIdList = inOutStorageBomList.stream().map(InOutStorageBom::getBomSpecId).collect(Collectors.toList());
|
|
|
synchronized (this) {
|
|
@@ -260,25 +189,23 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
|
tempInventory.setDepartmentId(departmentId);
|
|
|
tempInventory.setBomSpecId(item);
|
|
|
tempInventory.setQuantity(BigDecimal.ZERO);
|
|
|
- tempInventory.setLockQuantity(BigDecimal.ZERO);
|
|
|
tempInventory.setBalanceUnitPrice(BigDecimal.ZERO);
|
|
|
inventoryList.add(tempInventory);
|
|
|
return tempInventory;
|
|
|
});
|
|
|
|
|
|
- PurchaseBom purchaseBom = purchaseBomMap.get(inOutStorageBom.getBomSpecId());
|
|
|
- // 实际库存数 当前库存数量加锁定库存
|
|
|
- BigDecimal actualInventoryQuantity = inventory.getQuantity().add(inventory.getLockQuantity());
|
|
|
// 结存数量
|
|
|
- BigDecimal sumQuantity = actualInventoryQuantity.add(inOutStorageBom.getQuantity());
|
|
|
+ BigDecimal sumQuantity = inventory.getQuantity().add(inOutStorageBom.getQuantity());
|
|
|
+
|
|
|
// 结存金额
|
|
|
- BigDecimal sumPrice = actualInventoryQuantity.multiply(inventory.getBalanceUnitPrice())
|
|
|
+ PurchaseBom purchaseBom = purchaseBomMap.get(inOutStorageBom.getBomSpecId());
|
|
|
+ BigDecimal sumPrice = inventory.getQuantity().multiply(inventory.getBalanceUnitPrice())
|
|
|
.add(inOutStorageBom.getQuantity().multiply(purchaseBom.getUnitPrice()));
|
|
|
|
|
|
// 获取入库结存单价
|
|
|
BigDecimal balanceUnitPrice = sumPrice.divide(sumQuantity, 3, RoundingMode.HALF_UP);
|
|
|
|
|
|
- inventory.setQuantity(sumQuantity.subtract(inventory.getLockQuantity()));
|
|
|
+ inventory.setQuantity(sumQuantity);
|
|
|
inventory.setBalanceUnitPrice(balanceUnitPrice);
|
|
|
|
|
|
inOutStorageBom.setBalanceInventoryQuantity(sumQuantity);
|
|
@@ -334,7 +261,6 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
|
tempInventory.setDepartmentId(departmentId);
|
|
|
tempInventory.setBomSpecId(item);
|
|
|
tempInventory.setQuantity(BigDecimal.ZERO);
|
|
|
- tempInventory.setLockQuantity(BigDecimal.ZERO);
|
|
|
inventoryList.add(tempInventory);
|
|
|
return tempInventory;
|
|
|
});
|
|
@@ -346,7 +272,7 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
|
inventory.setBalanceUnitPrice(balanceUnitPrice);
|
|
|
|
|
|
// 保存当前入库记录的结存库存
|
|
|
- inOutFun.setBalanceInventoryQuantity(inventory.getQuantity().add(inventory.getLockQuantity()));
|
|
|
+ inOutFun.setBalanceInventoryQuantity(inventory.getQuantity());
|
|
|
}
|
|
|
|
|
|
saveOrUpdateBatch(inventoryList);
|
|
@@ -372,22 +298,17 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
|
Long bomSpecId = inOutFun.getBomSpecId();
|
|
|
Inventory inventory = inventoryMap.get(bomSpecId);
|
|
|
|
|
|
- // 出库冻结库存
|
|
|
- if (Objects.equals(lockStorage, StatusConstant.YES)) {
|
|
|
- inventory.setLockQuantity(inventory.getLockQuantity().subtract(quantity));
|
|
|
- }
|
|
|
- // 出库非冻结库存
|
|
|
- else {
|
|
|
- if (inventory == null || inventory.getQuantity().compareTo(quantity) < 0) {
|
|
|
- BomSpec bomSpec = bomSpecService.getById(bomSpecId);
|
|
|
- if (bomSpec == null) {
|
|
|
- throw new ServiceException("未知bom规格id:" + bomSpecId);
|
|
|
- }
|
|
|
- throw new ServiceException("出库失败,品号为:" + bomSpec.getCode() + " 的bom库存不足,库存为:" +
|
|
|
- (inventory == null ? BigDecimal.ZERO : inventory.getQuantity()) + ",需要出库:" + quantity);
|
|
|
+
|
|
|
+ if (inventory == null || inventory.getQuantity().compareTo(quantity) < 0) {
|
|
|
+ BomSpec bomSpec = bomSpecService.getById(bomSpecId);
|
|
|
+ if (bomSpec == null) {
|
|
|
+ throw new ServiceException("未知bom规格id:" + bomSpecId);
|
|
|
}
|
|
|
- inventory.setQuantity(inventory.getQuantity().subtract(quantity));
|
|
|
+ throw new ServiceException("出库失败,品号为:" + bomSpec.getCode() + " 的bom库存不足,库存为:" +
|
|
|
+ (inventory == null ? BigDecimal.ZERO : inventory.getQuantity()) + ",需要出库:" + quantity);
|
|
|
}
|
|
|
+ inventory.setQuantity(inventory.getQuantity().subtract(quantity));
|
|
|
+
|
|
|
|
|
|
// 计算出库结存单价
|
|
|
BigDecimal balanceUnitPrice = getOutBalanceUnitPrice(inOutStorageBalanceMap, inOutFun);
|
|
@@ -396,7 +317,7 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
|
inventory.setBalanceUnitPrice(balanceUnitPrice);
|
|
|
|
|
|
// 保存当前入库记录的结存库存
|
|
|
- inOutFun.setBalanceInventoryQuantity(inventory.getQuantity().add(inventory.getLockQuantity()));
|
|
|
+ inOutFun.setBalanceInventoryQuantity(inventory.getQuantity());
|
|
|
|
|
|
}
|
|
|
|