|
@@ -3,12 +3,12 @@ package com.sd.business.service.inventory.impl;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.google.common.collect.HashBasedTable;
|
|
|
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.in.dto.InOutStorageDto;
|
|
|
import com.sd.business.entity.in.po.InOutStorageBom;
|
|
|
-import com.sd.business.entity.inventory.bo.InOutFun;
|
|
|
import com.sd.business.entity.inventory.dto.InventorySelectDto;
|
|
|
import com.sd.business.entity.inventory.dto.QuantityByWarehouseDto;
|
|
|
import com.sd.business.entity.inventory.dto.QuantityDto;
|
|
@@ -27,9 +27,10 @@ import org.springframework.stereotype.Service;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
-import java.util.function.Function;
|
|
|
+import java.util.Objects;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@@ -112,29 +113,68 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
|
public void in(InOutStorageDto dto) {
|
|
|
List<InOutStorageBom> list = dto.getInOutStorageBomList();
|
|
|
Long warehouseId = dto.getWarehouseId();
|
|
|
+ Integer classifyType = dto.getClassifyType();
|
|
|
|
|
|
- List<Long> bomSpecIdList = list.stream().map(InOutFun::getBomSpecId).collect(Collectors.toList());
|
|
|
+ List<Long> bomSpecIdList = list.stream().map(InOutStorageBom::getBomSpecId).collect(Collectors.toList());
|
|
|
|
|
|
synchronized (this) {
|
|
|
// 通过事业部id和出库id获取bom规格库存
|
|
|
List<Inventory> inventoryList = getInventoryList(warehouseId, bomSpecIdList);
|
|
|
|
|
|
- // 通过bom规格分组
|
|
|
- Map<Long, Inventory> map = inventoryList.stream().collect(Collectors.toMap(Inventory::getBomSpecId, Function.identity()));
|
|
|
-
|
|
|
- for (InOutFun inOutFun : list) {
|
|
|
- // 库存
|
|
|
- Inventory inventory = map.computeIfAbsent(inOutFun.getBomSpecId(), item -> {
|
|
|
- Inventory tempInventory = new Inventory();
|
|
|
- tempInventory.setWarehouseId(warehouseId);
|
|
|
- tempInventory.setBomSpecId(item);
|
|
|
- tempInventory.setQuantity(BigDecimal.ZERO);
|
|
|
- return tempInventory;
|
|
|
- });
|
|
|
- inventory.setQuantity(inventory.getQuantity().add(inOutFun.getQuantity()));
|
|
|
+ // 原料分组
|
|
|
+ HashBasedTable<Long, String, Inventory> meterMap = HashBasedTable.create();
|
|
|
+
|
|
|
+ // 包材分组
|
|
|
+ Map<Long, Inventory> map = new HashMap<>();
|
|
|
+
|
|
|
+ // 原料
|
|
|
+ if (Objects.equals(classifyType, 1)) {
|
|
|
+ inventoryList.forEach(item -> meterMap.put(item.getBomSpecId(), item.getMeter().toPlainString(), item));
|
|
|
+ }
|
|
|
+ // 包材
|
|
|
+ else {
|
|
|
+ inventoryList.forEach(item -> map.put(item.getBomSpecId(), item));
|
|
|
+ }
|
|
|
+
|
|
|
+ for (InOutStorageBom inOutStorageBom : list) {
|
|
|
+ Long bomSpecId = inOutStorageBom.getBomSpecId();
|
|
|
+ BigDecimal meter = inOutStorageBom.getMeter();
|
|
|
+
|
|
|
+ Inventory inventory;
|
|
|
+
|
|
|
+ // 原料
|
|
|
+ if (Objects.equals(classifyType, 1)) {
|
|
|
+ inventory = meterMap.get(bomSpecId, meter.toPlainString());
|
|
|
+ }
|
|
|
+ // 包材
|
|
|
+ else {
|
|
|
+ inventory = map.get(bomSpecId);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (inventory == null) {
|
|
|
+ inventory = new Inventory();
|
|
|
+ inventory.setClassifyType(classifyType);
|
|
|
+ inventory.setWarehouseId(warehouseId);
|
|
|
+ inventory.setBomSpecId(bomSpecId);
|
|
|
+ inventory.setQuantity(BigDecimal.ZERO);
|
|
|
+
|
|
|
+ // 原料
|
|
|
+ if (Objects.equals(classifyType, 1)) {
|
|
|
+ inventory.setMeter(meter);
|
|
|
+ meterMap.put(bomSpecId, meter.toPlainString(), inventory);
|
|
|
+ }
|
|
|
+ // 包材
|
|
|
+ else {
|
|
|
+ map.put(bomSpecId, inventory);
|
|
|
+ }
|
|
|
+
|
|
|
+ inventoryList.add(inventory);
|
|
|
+ }
|
|
|
+
|
|
|
+ inventory.setQuantity(inventory.getQuantity().add(inOutStorageBom.getQuantity()));
|
|
|
}
|
|
|
|
|
|
- saveOrUpdateBatch(map.values());
|
|
|
+ saveOrUpdateBatch(inventoryList);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -142,20 +182,46 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
|
public void out(InOutStorageDto dto) {
|
|
|
List<InOutStorageBom> list = dto.getInOutStorageBomList();
|
|
|
Long warehouseId = dto.getWarehouseId();
|
|
|
+ Integer classifyType = dto.getClassifyType();
|
|
|
|
|
|
- List<Long> bomSpecIdList = list.stream().map(InOutFun::getBomSpecId).collect(Collectors.toList());
|
|
|
+ List<Long> bomSpecIdList = list.stream().map(InOutStorageBom::getBomSpecId).collect(Collectors.toList());
|
|
|
|
|
|
synchronized (this) {
|
|
|
|
|
|
// 通过事业部id和出库id获取bom规格库存
|
|
|
List<Inventory> inventoryList = getInventoryList(warehouseId, bomSpecIdList);
|
|
|
- Map<Long, Inventory> map = inventoryList.stream().collect(Collectors.toMap(Inventory::getBomSpecId, Function.identity()));
|
|
|
|
|
|
- for (InOutFun inOutFun : list) {
|
|
|
+ // 原料分组
|
|
|
+ HashBasedTable<Long, String, Inventory> meterMap = HashBasedTable.create();
|
|
|
+
|
|
|
+ // 包材分组
|
|
|
+ Map<Long, Inventory> map = new HashMap<>();
|
|
|
+
|
|
|
+ // 原料
|
|
|
+ if (Objects.equals(classifyType, 1)) {
|
|
|
+ inventoryList.forEach(item -> meterMap.put(item.getBomSpecId(), item.getMeter().toPlainString(), item));
|
|
|
+ }
|
|
|
+ // 包材
|
|
|
+ else {
|
|
|
+ inventoryList.forEach(item -> map.put(item.getBomSpecId(), item));
|
|
|
+ }
|
|
|
+
|
|
|
+ for (InOutStorageBom inOutStorageBom : list) {
|
|
|
+
|
|
|
+ BigDecimal quantity = inOutStorageBom.getQuantity();
|
|
|
+ Long bomSpecId = inOutStorageBom.getBomSpecId();
|
|
|
+ BigDecimal meter = inOutStorageBom.getMeter();
|
|
|
|
|
|
- BigDecimal quantity = inOutFun.getQuantity();
|
|
|
- Long bomSpecId = inOutFun.getBomSpecId();
|
|
|
- Inventory inventory = map.get(bomSpecId);
|
|
|
+ Inventory inventory;
|
|
|
+
|
|
|
+ // 原料
|
|
|
+ if (Objects.equals(classifyType, 1)) {
|
|
|
+ inventory = meterMap.get(bomSpecId, meter.toPlainString());
|
|
|
+ }
|
|
|
+ // 包材
|
|
|
+ else {
|
|
|
+ inventory = map.get(bomSpecId);
|
|
|
+ }
|
|
|
|
|
|
if (inventory == null || inventory.getQuantity().compareTo(quantity) < 0) {
|
|
|
BomSpec bomSpec = bomSpecService.getById(bomSpecId);
|
|
@@ -177,10 +243,7 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
|
* 通过仓库id获取bom规格库存
|
|
|
*/
|
|
|
private List<Inventory> getInventoryList(Long warehouseId, List<Long> bomSpecIdList) {
|
|
|
- return list(q -> q
|
|
|
- .eq(Inventory::getWarehouseId, warehouseId)
|
|
|
- .in(Inventory::getBomSpecId, bomSpecIdList)
|
|
|
- );
|
|
|
+ return list(q -> q.eq(Inventory::getWarehouseId, warehouseId).in(Inventory::getBomSpecId, bomSpecIdList));
|
|
|
}
|
|
|
|
|
|
}
|