|
@@ -2,6 +2,7 @@ package com.fjhx.wms.service.stock.impl;
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
@@ -205,48 +206,57 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
|
|
|
wrapper.eq(Stock::getWarehouseId, dto.getId());
|
|
|
wrapper.like(Stock::getQuantity, dto.getKeyword());
|
|
|
wrapper.eq("pi.definition", dto.getDefinition());
|
|
|
- wrapper.isNotNull("ps.id");
|
|
|
- wrapper.groupBy("pi.product_spu_id");
|
|
|
wrapper.orderByDesc("s", Stock::getId);
|
|
|
-
|
|
|
-
|
|
|
Page<StockVo> page = this.baseMapper.pageByProductSpu(dto.getPage(), wrapper);
|
|
|
- List<StockVo> stockVos = page.getRecords();
|
|
|
-
|
|
|
- //赋值产品名称
|
|
|
- productInfoService.attributeAssign(stockVos, StockVo::getProductId, (item, productInfo) -> {
|
|
|
- item.setType(productInfo.getType());
|
|
|
- item.setProductName(productInfo.getName());
|
|
|
- item.setProductCode(productInfo.getCode());
|
|
|
- item.setProductUnit(productInfo.getUnit());
|
|
|
- item.setProductType(productInfo.getType());
|
|
|
- item.setProductSpec(productInfo.getSpec());
|
|
|
- item.setProductClassifyId(productInfo.getProductClassifyId());
|
|
|
- item.setProductDefinition(productInfo.getDefinition());
|
|
|
-
|
|
|
- //赋值维多利亚扩展产品信息
|
|
|
- String victoriatouristJson = item.getVictoriatouristJson();
|
|
|
- JSONObject json = ObjectUtil.isNotEmpty(victoriatouristJson) ? JSONObject.parseObject(victoriatouristJson) : new JSONObject();
|
|
|
- json.put("code", productInfo.getCode());
|
|
|
- json.put("spec", productInfo.getSpec());
|
|
|
- json.put("unit", productInfo.getUnit());
|
|
|
- json.put("productSpuName", item.getProductSpuName());
|
|
|
-
|
|
|
-
|
|
|
- BigDecimal frozenQuantity = json.getBigDecimal("frozenQuantity");
|
|
|
- frozenQuantity = ObjectUtil.isEmpty(frozenQuantity) ? BigDecimal.ZERO : frozenQuantity;
|
|
|
- json.put("frozenQuantity", frozenQuantity);
|
|
|
- BigDecimal defectiveQuantity = json.getBigDecimal("defectiveQuantity");
|
|
|
- defectiveQuantity = ObjectUtil.isEmpty(defectiveQuantity) ? BigDecimal.ZERO : defectiveQuantity;
|
|
|
- json.put("defectiveQuantity", defectiveQuantity);
|
|
|
- item.setVictoriatouristJson(json.toJSONString());
|
|
|
- });
|
|
|
-
|
|
|
- //赋值仓库名称
|
|
|
- warehouseService.attributeAssign(stockVos, StockVo::getWarehouseId, (item, warehouse) -> {
|
|
|
- item.setWarehouseName(warehouse.getName());
|
|
|
- });
|
|
|
-
|
|
|
+ //赋值关联产品数
|
|
|
+ List<StockVo> records = page.getRecords();
|
|
|
+ List<Long> spuids = records.stream().map(StockVo::getProductSpuId).collect(Collectors.toList());
|
|
|
+ List<ProductInfo> productInfoList = productInfoService.list(q -> q.in(ProductInfo::getProductSpuId, spuids));
|
|
|
+ Map<Long, List<ProductInfo>> productInfoMap = productInfoList.stream().collect(Collectors.groupingBy(ProductInfo::getProductSpuId));
|
|
|
+ for (StockVo record : records) {
|
|
|
+ List<ProductInfo> productInfoList1 = productInfoMap.get(record.getProductSpuId());
|
|
|
+ record.setLinkProductQuantity(BigDecimal.valueOf(productInfoList1.size()));
|
|
|
+ }
|
|
|
+ //赋值可组合数量
|
|
|
+ List<Long> linkProductIds = new ArrayList<>();
|
|
|
+ for (StockVo record : records) {
|
|
|
+ String victoriatouristJson = record.getVictoriatouristJson();
|
|
|
+ JSONObject json = JSONObject.parseObject(victoriatouristJson);
|
|
|
+ JSONArray productCombinationList = json.getJSONArray("productCombinationList");
|
|
|
+ for (int i = 0; i < productCombinationList.size(); i++) {
|
|
|
+ JSONObject item = productCombinationList.getJSONObject(i);
|
|
|
+ Long linkProductId = item.getLong("linkProductId");
|
|
|
+ linkProductIds.add(linkProductId);
|
|
|
+// BigDecimal linkQuantity = item.getBigDecimal("linkQuantity");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //查询关联产品库存
|
|
|
+ List<Stock> list = list(q -> q.in(Stock::getProductId, linkProductIds));
|
|
|
+ Map<Long, BigDecimal> stockMap = list.stream().collect(Collectors.toMap(Stock::getProductId, Stock::getQuantity));
|
|
|
+ for (StockVo record : records) {
|
|
|
+ String victoriatouristJson = record.getVictoriatouristJson();
|
|
|
+ JSONObject json = JSONObject.parseObject(victoriatouristJson);
|
|
|
+ JSONArray productCombinationList = json.getJSONArray("productCombinationList");
|
|
|
+
|
|
|
+ Long min = -1l;
|
|
|
+ for (int i = 0; i < productCombinationList.size(); i++) {
|
|
|
+ JSONObject item = productCombinationList.getJSONObject(i);
|
|
|
+ Long linkProductId = item.getLong("linkProductId");
|
|
|
+ BigDecimal linkQuantity = item.getBigDecimal("linkQuantity");
|
|
|
+
|
|
|
+ BigDecimal stockQuantity = stockMap.getOrDefault(linkProductId,BigDecimal.ZERO);
|
|
|
+
|
|
|
+ BigDecimal divide = stockQuantity.divide(linkQuantity, 0, BigDecimal.ROUND_DOWN);
|
|
|
+
|
|
|
+ //计算最小值
|
|
|
+ if (min == -1) {
|
|
|
+ min = divide.longValue();
|
|
|
+ } else if (divide.intValue() < min) {
|
|
|
+ min = divide.longValue();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ record.setCombinationQuantity(min);
|
|
|
+ }
|
|
|
return page;
|
|
|
}
|
|
|
|