|
@@ -22,10 +22,12 @@ import com.sd.business.entity.inventory.po.InventoryBackup;
|
|
|
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.purchase.po.PurchaseBom;
|
|
|
import com.sd.business.mapper.inventory.InventoryMapper;
|
|
|
import com.sd.business.service.bom.BomSpecService;
|
|
|
import com.sd.business.service.in.InOutStorageDetailsService;
|
|
|
import com.sd.business.service.inventory.InventoryService;
|
|
|
+import com.sd.business.service.purchase.PurchaseBomService;
|
|
|
import com.sd.framework.util.excel.util.ExcelUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -61,6 +63,9 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
|
@Autowired
|
|
|
private InOutStorageDetailsService inOutStorageDetailsService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private PurchaseBomService purchaseBomService;
|
|
|
+
|
|
|
@Override
|
|
|
public Page<InventoryVo> getPage(InventorySelectDto dto, String tableName) {
|
|
|
IWrapper<Inventory> wrapper = getDtoWrapper(dto);
|
|
@@ -328,6 +333,65 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
|
"库存数据", list, InventoryVo.class);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void purchaseInStorage(Long purchaseId, Long departmentId, Long warehouseId, List<? extends InOutFun> list) {
|
|
|
+ List<Long> bomSpecIdList = list.stream().map(InOutFun::getBomSpecId).collect(Collectors.toList());
|
|
|
+ synchronized (this) {
|
|
|
+ // 通过事业部id和出库id获取bom规格库存
|
|
|
+ List<Inventory> inventoryList = getInventoryList(departmentId, warehouseId, bomSpecIdList);
|
|
|
+
|
|
|
+ // 通过bom规格分组
|
|
|
+ Map<Long, Inventory> map = inventoryList.stream().collect(Collectors.toMap(Inventory::getBomSpecId, Function.identity()));
|
|
|
+
|
|
|
+ Map<Long, PurchaseBom> purchaseBomMap = purchaseBomService.mapKEntity(PurchaseBom::getBomSpecId, q -> q.eq(PurchaseBom::getPurchaseId, purchaseId).in(PurchaseBom::getBomSpecId, bomSpecIdList));
|
|
|
+
|
|
|
+ // 保存结存单价批次
|
|
|
+ List<InOutStorageDetails> inOutStorageDetailsList = list.stream().map(item -> {
|
|
|
+ // 获取入库单价
|
|
|
+ PurchaseBom purchaseBom = purchaseBomMap.get(item.getBomSpecId());
|
|
|
+ BigDecimal inUnitPrice = purchaseBom == null ? BigDecimal.ZERO : purchaseBom.getUnitPrice();
|
|
|
+
|
|
|
+ InOutStorageDetails inOutStorageDetails = new InOutStorageDetails();
|
|
|
+ inOutStorageDetails.setDepartmentId(departmentId);
|
|
|
+ inOutStorageDetails.setWarehouseId(warehouseId);
|
|
|
+ inOutStorageDetails.setBomSpecId(item.getBomSpecId());
|
|
|
+ inOutStorageDetails.setInUnitPrice(inUnitPrice);
|
|
|
+ inOutStorageDetails.setQuantity(item.getQuantity());
|
|
|
+ return inOutStorageDetails;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ inOutStorageDetailsService.saveBatch(inOutStorageDetailsList);
|
|
|
+
|
|
|
+ for (InOutFun inOutFun : list) {
|
|
|
+
|
|
|
+ // 库存
|
|
|
+ Inventory inventory = map.computeIfAbsent(inOutFun.getBomSpecId(), item -> {
|
|
|
+ Inventory tempInventory = new Inventory();
|
|
|
+ tempInventory.setWarehouseId(warehouseId);
|
|
|
+ tempInventory.setDepartmentId(departmentId);
|
|
|
+ tempInventory.setBomSpecId(item);
|
|
|
+ tempInventory.setQuantity(BigDecimal.ZERO);
|
|
|
+ tempInventory.setBalanceUnitPrice(BigDecimal.ZERO);
|
|
|
+ inventoryList.add(tempInventory);
|
|
|
+ return tempInventory;
|
|
|
+ });
|
|
|
+ PurchaseBom purchaseBom = purchaseBomMap.get(inOutFun.getBomSpecId());
|
|
|
+ // 结存数量
|
|
|
+ BigDecimal sumQuantity = inventory.getQuantity().add(inOutFun.getQuantity());
|
|
|
+ // 结存金额
|
|
|
+ BigDecimal sumPrice = inventory.getQuantity().multiply(inventory.getBalanceUnitPrice())
|
|
|
+ .add(inOutFun.getQuantity().multiply(purchaseBom.getUnitPrice()));
|
|
|
+
|
|
|
+ // 获取入库结存单价
|
|
|
+ BigDecimal balanceUnitPrice = sumPrice.divide(sumQuantity, 2, RoundingMode.HALF_UP);;
|
|
|
+
|
|
|
+ inventory.setQuantity(sumQuantity);
|
|
|
+ inventory.setBalanceUnitPrice(balanceUnitPrice);
|
|
|
+ }
|
|
|
+
|
|
|
+ saveOrUpdateBatch(inventoryList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 通过事业部id和出库id获取bom规格库存
|
|
|
*/
|