|
|
|
|
@ -32,6 +32,7 @@ import java.util.Collections;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@ -184,16 +185,11 @@ public class ErpStockServiceImpl implements ErpStockService {
|
|
|
|
|
|
|
|
|
|
private void fillStockCards(ErpStockStatisticsRespVO respVO, List<ErpStockDO> stockList,
|
|
|
|
|
Map<Long, ErpProductRespVO> productMap) {
|
|
|
|
|
ErpStockStatisticsRespVO.ProductStockCard productStockCard = new ErpStockStatisticsRespVO.ProductStockCard();
|
|
|
|
|
|
|
|
|
|
List<ErpStockDO> productStockList = filterStockByCategory(stockList, productMap, ProductTypeEnum.ITEM.getTypeId());
|
|
|
|
|
List<ErpStockDO> materialStockList = filterStockByCategory(stockList, productMap, ProductTypeEnum.PRODUCT.getTypeId());
|
|
|
|
|
List<ErpStockDO> sparePartStockList = filterStockByCategory(stockList, productMap, ProductTypeEnum.BEIJIAN.getTypeId());
|
|
|
|
|
|
|
|
|
|
productStockCard.setSkuCount(countDistinctProduct(productStockList));
|
|
|
|
|
productStockCard.setStockDisplay(formatProductStockDisplay(productStockList));
|
|
|
|
|
productStockCard.setTodayFinishedInDisplay(formatProductStockDisplay(Collections.emptyList()));
|
|
|
|
|
respVO.setProductStock(productStockCard);
|
|
|
|
|
respVO.setProductStock(buildProductStockCard(productStockList, productMap));
|
|
|
|
|
|
|
|
|
|
respVO.setMaterialStock(buildUnitGroupedStockCard(materialStockList));
|
|
|
|
|
respVO.setSparePartStock(buildUnitGroupedStockCard(sparePartStockList));
|
|
|
|
|
@ -213,7 +209,7 @@ public class ErpStockServiceImpl implements ErpStockService {
|
|
|
|
|
|
|
|
|
|
todayInCard.setOrderCount((long) stockInIds.size());
|
|
|
|
|
todayInCard.setItemCount((long) itemList.size());
|
|
|
|
|
todayInCard.setProductStock(buildInItemUnitGroupedStockCard(filterInItemByCategory(itemList, productMap, ProductTypeEnum.ITEM.getTypeId()), productMap));
|
|
|
|
|
todayInCard.setProductStock(buildInItemProductStockCard(filterInItemByCategory(itemList, productMap, ProductTypeEnum.ITEM.getTypeId()), productMap));
|
|
|
|
|
todayInCard.setMaterialStock(buildInItemUnitGroupedStockCard(filterInItemByCategory(itemList, productMap, ProductTypeEnum.PRODUCT.getTypeId()), productMap));
|
|
|
|
|
todayInCard.setSparePartStock(buildInItemUnitGroupedStockCard(filterInItemByCategory(itemList, productMap, ProductTypeEnum.BEIJIAN.getTypeId()), productMap));
|
|
|
|
|
respVO.setTodayIn(todayInCard);
|
|
|
|
|
@ -234,7 +230,7 @@ public class ErpStockServiceImpl implements ErpStockService {
|
|
|
|
|
|
|
|
|
|
todayOutCard.setOrderCount((long) stockOutIds.size());
|
|
|
|
|
todayOutCard.setItemCount((long) itemList.size());
|
|
|
|
|
todayOutCard.setProductStock(buildOutItemUnitGroupedStockCard(filterOutItemByCategory(itemList, productMap, ProductTypeEnum.ITEM.getTypeId()), productMap));
|
|
|
|
|
todayOutCard.setProductStock(buildOutItemProductStockCard(filterOutItemByCategory(itemList, productMap, ProductTypeEnum.ITEM.getTypeId()), productMap));
|
|
|
|
|
todayOutCard.setMaterialStock(buildOutItemUnitGroupedStockCard(filterOutItemByCategory(itemList, productMap, ProductTypeEnum.PRODUCT.getTypeId()), productMap));
|
|
|
|
|
todayOutCard.setSparePartStock(buildOutItemUnitGroupedStockCard(filterOutItemByCategory(itemList, productMap, ProductTypeEnum.BEIJIAN.getTypeId()), productMap));
|
|
|
|
|
respVO.setTodayOut(todayOutCard);
|
|
|
|
|
@ -296,6 +292,46 @@ public class ErpStockServiceImpl implements ErpStockService {
|
|
|
|
|
return buildUnitStock(firstStock.getUnitId(), firstStock.getUnitName(), count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ErpStockStatisticsRespVO.ProductStockCard buildProductStockCard(List<ErpStockDO> stockList,
|
|
|
|
|
Map<Long, ErpProductRespVO> productMap) {
|
|
|
|
|
ErpStockStatisticsRespVO.ProductStockCard card = new ErpStockStatisticsRespVO.ProductStockCard();
|
|
|
|
|
BigDecimal totalCount = sumStockCount(stockList);
|
|
|
|
|
String unitName = resolveStockUnitName(stockList, productMap);
|
|
|
|
|
card.setSkuCount(countDistinctProduct(stockList));
|
|
|
|
|
card.setTotalCount(totalCount);
|
|
|
|
|
card.setUnitName(unitName);
|
|
|
|
|
card.setStockDisplay(formatNumber(totalCount) + nullToEmpty(unitName));
|
|
|
|
|
card.setPackagingStocks(buildStockPackagingStocks(stockList, productMap));
|
|
|
|
|
card.setTodayFinishedInDisplay(formatNumber(BigDecimal.ZERO) + nullToEmpty(unitName));
|
|
|
|
|
return card;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ErpStockStatisticsRespVO.ProductStockCard buildInItemProductStockCard(List<ErpStockInItemDO> itemList,
|
|
|
|
|
Map<Long, ErpProductRespVO> productMap) {
|
|
|
|
|
ErpStockStatisticsRespVO.ProductStockCard card = new ErpStockStatisticsRespVO.ProductStockCard();
|
|
|
|
|
BigDecimal totalCount = sumInItemCount(itemList);
|
|
|
|
|
String unitName = resolveInItemUnitName(itemList, productMap);
|
|
|
|
|
card.setSkuCount(itemList.stream().map(ErpStockInItemDO::getProductId).distinct().count());
|
|
|
|
|
card.setTotalCount(totalCount);
|
|
|
|
|
card.setUnitName(unitName);
|
|
|
|
|
card.setStockDisplay(formatNumber(totalCount) + nullToEmpty(unitName));
|
|
|
|
|
card.setPackagingStocks(buildInItemPackagingStocks(itemList, productMap));
|
|
|
|
|
return card;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ErpStockStatisticsRespVO.ProductStockCard buildOutItemProductStockCard(List<ErpStockOutItemDO> itemList,
|
|
|
|
|
Map<Long, ErpProductRespVO> productMap) {
|
|
|
|
|
ErpStockStatisticsRespVO.ProductStockCard card = new ErpStockStatisticsRespVO.ProductStockCard();
|
|
|
|
|
BigDecimal totalCount = sumOutItemCount(itemList);
|
|
|
|
|
String unitName = resolveOutItemUnitName(itemList, productMap);
|
|
|
|
|
card.setSkuCount(itemList.stream().map(ErpStockOutItemDO::getProductId).distinct().count());
|
|
|
|
|
card.setTotalCount(totalCount);
|
|
|
|
|
card.setUnitName(unitName);
|
|
|
|
|
card.setStockDisplay(formatNumber(totalCount) + nullToEmpty(unitName));
|
|
|
|
|
card.setPackagingStocks(buildOutItemPackagingStocks(itemList, productMap));
|
|
|
|
|
return card;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String buildUnitKey(Long unitId, String unitName) {
|
|
|
|
|
return String.valueOf(unitId) + "_" + String.valueOf(unitName);
|
|
|
|
|
}
|
|
|
|
|
@ -305,7 +341,7 @@ public class ErpStockServiceImpl implements ErpStockService {
|
|
|
|
|
ErpStockStatisticsRespVO.UnitGroupedStockCard card = new ErpStockStatisticsRespVO.UnitGroupedStockCard();
|
|
|
|
|
card.setSkuCount(itemList.stream().map(ErpStockInItemDO::getProductId).distinct().count());
|
|
|
|
|
List<ErpStockStatisticsRespVO.UnitStock> unitStocks = itemList.stream()
|
|
|
|
|
.collect(Collectors.groupingBy(item -> buildProductUnitKey(item.getProductId(), productMap)))
|
|
|
|
|
.collect(Collectors.groupingBy(item -> buildInItemUnitKey(item, productMap)))
|
|
|
|
|
.values().stream()
|
|
|
|
|
.map(items -> buildInItemUnitStock(items, productMap))
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
@ -321,7 +357,7 @@ public class ErpStockServiceImpl implements ErpStockService {
|
|
|
|
|
ErpStockStatisticsRespVO.UnitGroupedStockCard card = new ErpStockStatisticsRespVO.UnitGroupedStockCard();
|
|
|
|
|
card.setSkuCount(itemList.stream().map(ErpStockOutItemDO::getProductId).distinct().count());
|
|
|
|
|
List<ErpStockStatisticsRespVO.UnitStock> unitStocks = itemList.stream()
|
|
|
|
|
.collect(Collectors.groupingBy(item -> buildProductUnitKey(item.getProductId(), productMap)))
|
|
|
|
|
.collect(Collectors.groupingBy(item -> buildOutItemUnitKey(item, productMap)))
|
|
|
|
|
.values().stream()
|
|
|
|
|
.map(items -> buildOutItemUnitStock(items, productMap))
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
@ -335,21 +371,17 @@ public class ErpStockServiceImpl implements ErpStockService {
|
|
|
|
|
private ErpStockStatisticsRespVO.UnitStock buildInItemUnitStock(List<ErpStockInItemDO> itemList,
|
|
|
|
|
Map<Long, ErpProductRespVO> productMap) {
|
|
|
|
|
ErpStockInItemDO firstItem = itemList.get(0);
|
|
|
|
|
ErpProductRespVO product = productMap.get(firstItem.getProductId());
|
|
|
|
|
BigDecimal count = itemList.stream().map(item -> defaultZero(item.getCount()))
|
|
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
return buildUnitStock(product != null ? product.getUnitId() : null,
|
|
|
|
|
product != null ? product.getUnitName() : null, count);
|
|
|
|
|
return buildUnitStock(resolveInItemUnitId(firstItem, productMap), resolveInItemUnitName(firstItem, productMap), count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ErpStockStatisticsRespVO.UnitStock buildOutItemUnitStock(List<ErpStockOutItemDO> itemList,
|
|
|
|
|
Map<Long, ErpProductRespVO> productMap) {
|
|
|
|
|
ErpStockOutItemDO firstItem = itemList.get(0);
|
|
|
|
|
ErpProductRespVO product = productMap.get(firstItem.getProductId());
|
|
|
|
|
BigDecimal count = itemList.stream().map(item -> defaultZero(item.getCount()))
|
|
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
return buildUnitStock(product != null ? product.getUnitId() : null,
|
|
|
|
|
product != null ? product.getUnitName() : null, count);
|
|
|
|
|
return buildUnitStock(resolveOutItemUnitId(firstItem, productMap), resolveOutItemUnitName(firstItem, productMap), count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ErpStockStatisticsRespVO.UnitStock buildUnitStock(Long unitId, String unitName, BigDecimal count) {
|
|
|
|
|
@ -361,9 +393,188 @@ public class ErpStockServiceImpl implements ErpStockService {
|
|
|
|
|
return unitStock;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String buildProductUnitKey(Long productId, Map<Long, ErpProductRespVO> productMap) {
|
|
|
|
|
private String buildInItemUnitKey(ErpStockInItemDO item, Map<Long, ErpProductRespVO> productMap) {
|
|
|
|
|
return buildUnitKey(resolveInItemUnitId(item, productMap), resolveInItemUnitName(item, productMap));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String buildOutItemUnitKey(ErpStockOutItemDO item, Map<Long, ErpProductRespVO> productMap) {
|
|
|
|
|
return buildUnitKey(resolveOutItemUnitId(item, productMap), resolveOutItemUnitName(item, productMap));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Long resolveInItemUnitId(ErpStockInItemDO item, Map<Long, ErpProductRespVO> productMap) {
|
|
|
|
|
if (item.getProductUnitId() != null) {
|
|
|
|
|
return item.getProductUnitId();
|
|
|
|
|
}
|
|
|
|
|
ErpProductRespVO product = productMap.get(item.getProductId());
|
|
|
|
|
return product != null ? product.getUnitId() : null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String resolveInItemUnitName(ErpStockInItemDO item, Map<Long, ErpProductRespVO> productMap) {
|
|
|
|
|
if (item.getProductUnitName() != null) {
|
|
|
|
|
return item.getProductUnitName();
|
|
|
|
|
}
|
|
|
|
|
return resolveCurrentProductUnitName(item.getProductId(), item.getProductUnitId(), productMap);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Long resolveOutItemUnitId(ErpStockOutItemDO item, Map<Long, ErpProductRespVO> productMap) {
|
|
|
|
|
if (item.getProductUnitId() != null) {
|
|
|
|
|
return item.getProductUnitId();
|
|
|
|
|
}
|
|
|
|
|
ErpProductRespVO product = productMap.get(item.getProductId());
|
|
|
|
|
return product != null ? product.getUnitId() : null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String resolveOutItemUnitName(ErpStockOutItemDO item, Map<Long, ErpProductRespVO> productMap) {
|
|
|
|
|
if (item.getProductUnitName() != null) {
|
|
|
|
|
return item.getProductUnitName();
|
|
|
|
|
}
|
|
|
|
|
return resolveCurrentProductUnitName(item.getProductId(), item.getProductUnitId(), productMap);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String resolveCurrentProductUnitName(Long productId, Long unitId, Map<Long, ErpProductRespVO> productMap) {
|
|
|
|
|
ErpProductRespVO product = productMap.get(productId);
|
|
|
|
|
return product != null ? buildUnitKey(product.getUnitId(), product.getUnitName()) : buildUnitKey(null, null);
|
|
|
|
|
if (product == null || (unitId != null && !Objects.equals(unitId, product.getUnitId()))) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return product.getUnitName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<ErpStockStatisticsRespVO.ProductPackagingStock> buildStockPackagingStocks(List<ErpStockDO> stockList,
|
|
|
|
|
Map<Long, ErpProductRespVO> productMap) {
|
|
|
|
|
return stockList.stream()
|
|
|
|
|
.collect(Collectors.groupingBy(this::buildStockPackagingKey))
|
|
|
|
|
.values().stream()
|
|
|
|
|
.map(items -> buildStockPackagingStock(items, productMap))
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ErpStockStatisticsRespVO.ProductPackagingStock buildStockPackagingStock(List<ErpStockDO> stockList,
|
|
|
|
|
Map<Long, ErpProductRespVO> productMap) {
|
|
|
|
|
ErpStockDO firstStock = stockList.get(0);
|
|
|
|
|
BigDecimal totalCount = sumStockCount(stockList);
|
|
|
|
|
String unitName = firstStock.getUnitName();
|
|
|
|
|
ErpStockStatisticsRespVO.ProductPackagingStock detail = buildProductPackagingStock(
|
|
|
|
|
firstStock.getProductId(), resolveProductName(firstStock.getProductId(), productMap),
|
|
|
|
|
firstStock.getDefaultPackagingSchemeId(), firstStock.getDefaultPackagingSchemeName(),
|
|
|
|
|
totalCount, unitName, firstStock.getPackageQuantity(), firstStock.getPalletPackageQuantity(),
|
|
|
|
|
firstStock.getPalletTotalQuantity());
|
|
|
|
|
return detail;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<ErpStockStatisticsRespVO.ProductPackagingStock> buildInItemPackagingStocks(List<ErpStockInItemDO> itemList,
|
|
|
|
|
Map<Long, ErpProductRespVO> productMap) {
|
|
|
|
|
return itemList.stream()
|
|
|
|
|
.collect(Collectors.groupingBy(this::buildInItemPackagingKey))
|
|
|
|
|
.values().stream()
|
|
|
|
|
.map(items -> buildInItemPackagingStock(items, productMap))
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ErpStockStatisticsRespVO.ProductPackagingStock buildInItemPackagingStock(List<ErpStockInItemDO> itemList,
|
|
|
|
|
Map<Long, ErpProductRespVO> productMap) {
|
|
|
|
|
ErpStockInItemDO firstItem = itemList.get(0);
|
|
|
|
|
BigDecimal totalCount = sumInItemCount(itemList);
|
|
|
|
|
return buildProductPackagingStock(firstItem.getProductId(), resolveProductName(firstItem.getProductId(), productMap),
|
|
|
|
|
firstItem.getPackagingSchemeId(), firstItem.getPackagingSchemeName(), totalCount,
|
|
|
|
|
resolveInItemUnitName(firstItem, productMap), firstItem.getPackageQuantity(),
|
|
|
|
|
firstItem.getPalletPackageQuantity(), firstItem.getPalletTotalQuantity());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<ErpStockStatisticsRespVO.ProductPackagingStock> buildOutItemPackagingStocks(List<ErpStockOutItemDO> itemList,
|
|
|
|
|
Map<Long, ErpProductRespVO> productMap) {
|
|
|
|
|
return itemList.stream()
|
|
|
|
|
.collect(Collectors.groupingBy(this::buildOutItemPackagingKey))
|
|
|
|
|
.values().stream()
|
|
|
|
|
.map(items -> buildOutItemPackagingStock(items, productMap))
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ErpStockStatisticsRespVO.ProductPackagingStock buildOutItemPackagingStock(List<ErpStockOutItemDO> itemList,
|
|
|
|
|
Map<Long, ErpProductRespVO> productMap) {
|
|
|
|
|
ErpStockOutItemDO firstItem = itemList.get(0);
|
|
|
|
|
BigDecimal totalCount = sumOutItemCount(itemList);
|
|
|
|
|
return buildProductPackagingStock(firstItem.getProductId(), resolveProductName(firstItem.getProductId(), productMap),
|
|
|
|
|
firstItem.getPackagingSchemeId(), firstItem.getPackagingSchemeName(), totalCount,
|
|
|
|
|
resolveOutItemUnitName(firstItem, productMap), firstItem.getPackageQuantity(),
|
|
|
|
|
firstItem.getPalletPackageQuantity(), firstItem.getPalletTotalQuantity());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ErpStockStatisticsRespVO.ProductPackagingStock buildProductPackagingStock(Long productId, String productName,
|
|
|
|
|
Long packagingSchemeId, String packagingSchemeName,
|
|
|
|
|
BigDecimal totalCount, String unitName,
|
|
|
|
|
BigDecimal packageQuantity,
|
|
|
|
|
BigDecimal palletPackageQuantity,
|
|
|
|
|
BigDecimal palletTotalQuantity) {
|
|
|
|
|
ErpStockStatisticsRespVO.ProductPackagingStock detail = new ErpStockStatisticsRespVO.ProductPackagingStock();
|
|
|
|
|
detail.setProductId(productId);
|
|
|
|
|
detail.setProductName(productName);
|
|
|
|
|
detail.setPackagingSchemeId(packagingSchemeId);
|
|
|
|
|
detail.setPackagingSchemeName(packagingSchemeName);
|
|
|
|
|
detail.setTotalCount(totalCount);
|
|
|
|
|
detail.setUnitName(unitName);
|
|
|
|
|
detail.setStockDisplay(formatNumber(totalCount) + nullToEmpty(unitName));
|
|
|
|
|
detail.setPackagingDisplay(formatProductQuantity(calculateProductQuantity(totalCount, palletTotalQuantity, packageQuantity)));
|
|
|
|
|
detail.setPackageQuantity(packageQuantity);
|
|
|
|
|
detail.setPalletPackageQuantity(palletPackageQuantity);
|
|
|
|
|
detail.setPalletTotalQuantity(palletTotalQuantity);
|
|
|
|
|
return detail;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String buildStockPackagingKey(ErpStockDO stock) {
|
|
|
|
|
return buildProductPackagingKey(stock.getProductId(), stock.getDefaultPackagingSchemeId(), stock.getPackageQuantity(),
|
|
|
|
|
stock.getPalletPackageQuantity(), stock.getPalletTotalQuantity(), stock.getUnitId(), stock.getUnitName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String buildInItemPackagingKey(ErpStockInItemDO item) {
|
|
|
|
|
return buildProductPackagingKey(item.getProductId(), item.getPackagingSchemeId(), item.getPackageQuantity(),
|
|
|
|
|
item.getPalletPackageQuantity(), item.getPalletTotalQuantity(), item.getProductUnitId(), item.getProductUnitName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String buildOutItemPackagingKey(ErpStockOutItemDO item) {
|
|
|
|
|
return buildProductPackagingKey(item.getProductId(), item.getPackagingSchemeId(), item.getPackageQuantity(),
|
|
|
|
|
item.getPalletPackageQuantity(), item.getPalletTotalQuantity(), item.getProductUnitId(), item.getProductUnitName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String buildProductPackagingKey(Long productId, Long packagingSchemeId, BigDecimal packageQuantity,
|
|
|
|
|
BigDecimal palletPackageQuantity, BigDecimal palletTotalQuantity,
|
|
|
|
|
Long unitId, String unitName) {
|
|
|
|
|
return String.valueOf(productId) + "_" + String.valueOf(packagingSchemeId) + "_"
|
|
|
|
|
+ String.valueOf(packageQuantity) + "_" + String.valueOf(palletPackageQuantity) + "_"
|
|
|
|
|
+ String.valueOf(palletTotalQuantity) + "_" + buildUnitKey(unitId, unitName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private BigDecimal sumStockCount(List<ErpStockDO> stockList) {
|
|
|
|
|
return stockList.stream().map(stock -> defaultZero(stock.getCount()))
|
|
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private BigDecimal sumInItemCount(List<ErpStockInItemDO> itemList) {
|
|
|
|
|
return itemList.stream().map(item -> defaultZero(item.getCount()))
|
|
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private BigDecimal sumOutItemCount(List<ErpStockOutItemDO> itemList) {
|
|
|
|
|
return itemList.stream().map(item -> defaultZero(item.getCount()))
|
|
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String resolveStockUnitName(List<ErpStockDO> stockList, Map<Long, ErpProductRespVO> productMap) {
|
|
|
|
|
return stockList.stream().map(ErpStockDO::getUnitName).filter(Objects::nonNull).findFirst()
|
|
|
|
|
.orElseGet(() -> stockList.stream().map(stock -> resolveCurrentProductUnitName(stock.getProductId(), stock.getUnitId(), productMap))
|
|
|
|
|
.filter(Objects::nonNull).findFirst().orElse(null));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String resolveInItemUnitName(List<ErpStockInItemDO> itemList, Map<Long, ErpProductRespVO> productMap) {
|
|
|
|
|
return itemList.stream().map(item -> resolveInItemUnitName(item, productMap)).filter(Objects::nonNull).findFirst().orElse(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String resolveOutItemUnitName(List<ErpStockOutItemDO> itemList, Map<Long, ErpProductRespVO> productMap) {
|
|
|
|
|
return itemList.stream().map(item -> resolveOutItemUnitName(item, productMap)).filter(Objects::nonNull).findFirst().orElse(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String resolveProductName(Long productId, Map<Long, ErpProductRespVO> productMap) {
|
|
|
|
|
ErpProductRespVO product = productMap.get(productId);
|
|
|
|
|
return product != null ? product.getName() : null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Integer resolveCategoryType(ErpStockDO stock, Map<Long, ErpProductRespVO> productMap) {
|
|
|
|
|
@ -419,6 +630,10 @@ public class ErpStockServiceImpl implements ErpStockService {
|
|
|
|
|
return display.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String formatProductQuantity(ProductQuantity quantity) {
|
|
|
|
|
return formatProductQuantity(quantity.getPalletCount(), quantity.getPackageCount(), quantity.getPieceCount());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void appendDisplay(StringBuilder display, BigDecimal quantity, String unitName, boolean keepZero) {
|
|
|
|
|
if (quantity == null || quantity.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
|
|
if (!keepZero) {
|
|
|
|
|
|