|
|
@@ -1,13 +1,18 @@
|
|
|
package org.dromara.product.dubbo;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.math3.stat.descriptive.summary.Product;
|
|
|
import org.apache.dubbo.config.annotation.DubboService;
|
|
|
+import org.apache.seata.common.metadata.namingserver.Unit;
|
|
|
import org.dromara.common.core.domain.zhongche.domain.Prices;
|
|
|
import org.dromara.product.api.RemoteProductService;
|
|
|
import org.dromara.product.api.domain.ProductCategoryRemoteVo;
|
|
|
@@ -16,17 +21,16 @@ import org.dromara.product.api.domain.ProductVo;
|
|
|
import org.dromara.product.api.domain.SiteProductRemoteBo;
|
|
|
import org.dromara.product.api.domain.SiteProductRemoteResult;
|
|
|
import org.dromara.product.api.domain.SiteProductRemoteVo;
|
|
|
+import org.dromara.product.api.domain.zhongche.dto.ProductAggregateDto;
|
|
|
import org.dromara.product.api.domain.zhongche.dto.StocksResult;
|
|
|
import org.dromara.product.api.domain.zhongche.dto.StocksResultDto;
|
|
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
-import org.dromara.product.domain.ProductWarehouseInventory;
|
|
|
+import org.dromara.product.domain.*;
|
|
|
import org.dromara.product.domain.bo.SiteProductBo;
|
|
|
import org.dromara.product.domain.vo.*;
|
|
|
-import org.dromara.product.domain.ProductPriceInventory;
|
|
|
import org.dromara.product.domain.bo.ProductCategoryBo;
|
|
|
import org.dromara.product.api.domain.RemoteProductBrand;
|
|
|
-import org.dromara.product.domain.ProductBrand;
|
|
|
import org.dromara.product.domain.bo.ProductBaseBo;
|
|
|
import org.dromara.product.domain.bo.ProductChangeLogBo;
|
|
|
import org.dromara.product.service.*;
|
|
|
@@ -35,6 +39,7 @@ import org.springframework.stereotype.Service;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.util.*;
|
|
|
+import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -60,6 +65,12 @@ public class RemoteProductServiceImpl implements RemoteProductService {
|
|
|
|
|
|
private final IProductWarehouseInventoryService productWarehouseInventoryService;
|
|
|
|
|
|
+ private final IProductUnitService productUnitService;
|
|
|
+
|
|
|
+ private final IProductExtendService productExtendService;
|
|
|
+
|
|
|
+ private final IProductClassificationService productClassificationService;
|
|
|
+
|
|
|
/**
|
|
|
* 获取商品详情
|
|
|
*
|
|
|
@@ -316,5 +327,136 @@ public class RemoteProductServiceImpl implements RemoteProductService {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<ProductAggregateDto> getProductInfo(List<Long> productIds) {
|
|
|
+ if (CollUtil.isEmpty(productIds)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ // 1. 查商品基础表
|
|
|
+ List<ProductBase> productList = productBaseService.list(new LambdaQueryWrapper<ProductBase>().in(ProductBase::getId, productIds));
|
|
|
+ if (CollUtil.isEmpty(productList)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ // 2. 查商品价格库存表
|
|
|
+ List<ProductPriceInventory> priceInventoryList = productPriceInventoryService.list(new LambdaQueryWrapper<ProductPriceInventory>().in(ProductPriceInventory::getProductId, productIds));
|
|
|
+ Map<Long, ProductPriceInventory> priceInventoryMap =
|
|
|
+ priceInventoryList.stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ ProductPriceInventory::getProductId,
|
|
|
+ Function.identity(),
|
|
|
+ (a, b) -> a
|
|
|
+ ));
|
|
|
+ // 3.查询品牌中文或英文名称
|
|
|
+ // 3. 品牌信息(重点)
|
|
|
+ Set<Long> brandIds = productList.stream()
|
|
|
+ .map(ProductBase::getBrandId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ Map<Long, ProductBrand> brandMap = Collections.emptyMap();
|
|
|
+ if (CollUtil.isNotEmpty(brandIds)) {
|
|
|
+ brandMap = productBrandService.list(
|
|
|
+ new LambdaQueryWrapper<ProductBrand>()
|
|
|
+ .in(ProductBrand::getId, brandIds)
|
|
|
+ ).stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ ProductBrand::getId,
|
|
|
+ Function.identity()
|
|
|
+ ));
|
|
|
+ }
|
|
|
+ // 4. 组装聚合 DTO
|
|
|
+ Map<Long, ProductBrand> finalBrandMap = brandMap;
|
|
|
+
|
|
|
+ //5.查询单位名称
|
|
|
+ List<Long> unitIds = productList.stream()
|
|
|
+ .map(ProductBase::getUnitId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .distinct()
|
|
|
+ .toList();
|
|
|
+
|
|
|
+ List<ProductUnit> unitList = productUnitService.list(new LambdaQueryWrapper<ProductUnit>().in(ProductUnit::getId, unitIds));
|
|
|
+ Map<Long, String> unitNameMap = unitList.stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ ProductUnit::getId,
|
|
|
+ ProductUnit::getUnitName,
|
|
|
+ (a, b) -> a
|
|
|
+ ));
|
|
|
+
|
|
|
+ //6.查询商品描述
|
|
|
+ List<ProductExtend> extendList = productExtendService.list(
|
|
|
+ new LambdaQueryWrapper<ProductExtend>()
|
|
|
+ .in(ProductExtend::getProductId, productIds)
|
|
|
+ );
|
|
|
+
|
|
|
+ Map<Long, String> productDescMap = extendList.stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ ProductExtend::getProductId,
|
|
|
+ ProductExtend::getProductDescription,
|
|
|
+ (a, b) -> a
|
|
|
+ ));
|
|
|
+
|
|
|
+ //7.查询商品规格
|
|
|
+ List<ProductClassification> productClassificationList = productClassificationService.list(
|
|
|
+ new LambdaQueryWrapper<ProductClassification>()
|
|
|
+ .in(ProductClassification::getProductId, productIds)
|
|
|
+ );
|
|
|
+
|
|
|
+ Map<Long, String> productClassificationMap = productClassificationList.stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ ProductClassification::getProductId,
|
|
|
+ ProductClassification::getAttributesList,
|
|
|
+ (a, b) -> a
|
|
|
+ ));
|
|
|
+
|
|
|
+
|
|
|
+ // 5. 组装
|
|
|
+ return productList.stream().map(p -> {
|
|
|
+ //TODO 税收编码 写一个伪数据 商品规格没有 就写一个伪数据
|
|
|
+ ProductAggregateDto vo = new ProductAggregateDto();
|
|
|
+ vo.setProductId(p.getId());
|
|
|
+ vo.setName(p.getItemName());
|
|
|
+ vo.setDsPrice(priceInventoryMap.get(p.getId()).getMarketPrice());
|
|
|
+ vo.setPrice(priceInventoryMap.get(p.getId()).getMemberPrice());
|
|
|
+ vo.setStock(priceInventoryMap.get(p.getId()).getTotalInventory().intValue());
|
|
|
+ vo.setUnit(unitNameMap.get(p.getUnitId()));
|
|
|
+ vo.setTax(priceInventoryMap.get(p.getId()).getTaxRate());
|
|
|
+
|
|
|
+ //作json处理
|
|
|
+ String productImage = p.getProductImage();
|
|
|
+ if (StrUtil.isNotBlank(productImage)) {
|
|
|
+ List<String> imgList = Arrays.stream(productImage.split(","))
|
|
|
+ .filter(StrUtil::isNotBlank)
|
|
|
+ .toList();
|
|
|
+
|
|
|
+ vo.setBarImgUrls(JSONUtil.toJsonStr(imgList));
|
|
|
+ }
|
|
|
+ //作json处理
|
|
|
+ vo.setProperties(
|
|
|
+ Optional.ofNullable(productClassificationMap.get(p.getId()))
|
|
|
+ .orElse("{\"1\":\"1kg\",\"2\":\"1cm\",\"3\":\"100\"}")
|
|
|
+ );
|
|
|
+
|
|
|
+ vo.setIsSelfOperated(p.getIsSelf());
|
|
|
+
|
|
|
+ // 商品描述
|
|
|
+ vo.setDescription(productDescMap.get(p.getId()));
|
|
|
+ vo.setTaxCode("123456");
|
|
|
+
|
|
|
+ // ===== 品牌名称规则处理 =====
|
|
|
+ ProductBrand brand = finalBrandMap.get(p.getBrandId());
|
|
|
+ if (brand != null) {
|
|
|
+ if (StrUtil.isNotBlank(brand.getBrandName())) {
|
|
|
+ vo.setBrandName(brand.getBrandName());
|
|
|
+ } else if (StrUtil.isNotBlank(brand.getBrandEnglishName())){
|
|
|
+ vo.setBrandNameEn(brand.getBrandEnglishName());
|
|
|
+ }else {
|
|
|
+ vo.setBrandName(p.getItemName());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return vo;
|
|
|
+ }).toList();
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|