|
|
@@ -1,6 +1,9 @@
|
|
|
package org.dromara.product.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
@@ -10,6 +13,15 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.dromara.customer.api.RemoteSupplierInfoService;
|
|
|
+import org.dromara.customer.api.domain.dto.SupplierAreaDTO;
|
|
|
+import org.dromara.easyes.core.biz.EsPageInfo;
|
|
|
+import org.dromara.easyes.core.conditions.select.LambdaEsQueryWrapper;
|
|
|
+import org.dromara.product.domain.ProductBase;
|
|
|
+import org.dromara.product.domain.vo.ProductBaseVo;
|
|
|
+import org.dromara.product.esmapper.ProductEsMapper;
|
|
|
+import org.dromara.product.mapper.ProductBaseMapper;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.dromara.product.domain.bo.ContractProductBo;
|
|
|
import org.dromara.product.domain.vo.ContractProductVo;
|
|
|
@@ -17,9 +29,8 @@ import org.dromara.product.domain.ContractProduct;
|
|
|
import org.dromara.product.mapper.ContractProductMapper;
|
|
|
import org.dromara.product.service.IContractProductService;
|
|
|
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Collection;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 合同产品关联Service业务层处理
|
|
|
@@ -34,6 +45,13 @@ public class ContractProductServiceImpl extends ServiceImpl<ContractProductMapp
|
|
|
|
|
|
private final ContractProductMapper baseMapper;
|
|
|
|
|
|
+ @DubboReference
|
|
|
+ private final RemoteSupplierInfoService remoteSupplierInfoService;
|
|
|
+
|
|
|
+ private final ProductBaseMapper productBaseMapper;
|
|
|
+
|
|
|
+ private final ProductEsMapper esMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 查询合同产品关联
|
|
|
*
|
|
|
@@ -137,4 +155,200 @@ public class ContractProductServiceImpl extends ServiceImpl<ContractProductMapp
|
|
|
}
|
|
|
return baseMapper.deleteByIds(ids) > 0;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public TableDataInfo<ContractProductVo> queryscmPageList(ContractProductBo bo, PageQuery pageQuery) {
|
|
|
+ LambdaQueryWrapper<ContractProduct> lqw = new LambdaQueryWrapper<>();
|
|
|
+
|
|
|
+ // 用于存最终 supplierId
|
|
|
+ Set<Long> supplierIdSet = null;
|
|
|
+
|
|
|
+ // =========================
|
|
|
+ // 1 供应商名称
|
|
|
+ // =========================
|
|
|
+ if (StringUtils.isNotBlank(bo.getEnterpriseName())) {
|
|
|
+
|
|
|
+ List<Long> supplierIds =
|
|
|
+ remoteSupplierInfoService.getSupplierIds(bo.getEnterpriseName());
|
|
|
+
|
|
|
+ supplierIdSet = new HashSet<>(supplierIds);
|
|
|
+ }
|
|
|
+ // =========================
|
|
|
+ // 2 省
|
|
|
+ // =========================
|
|
|
+ if (StringUtils.isNotBlank(bo.getProvinceName())) {
|
|
|
+
|
|
|
+ List<Long> supplierIds =
|
|
|
+ remoteSupplierInfoService.getSupplierIdsBySupplyArea(
|
|
|
+ bo.getProvinceName(), "1");
|
|
|
+
|
|
|
+ if (supplierIdSet == null) {
|
|
|
+ supplierIdSet = new HashSet<>(supplierIds);
|
|
|
+ } else {
|
|
|
+ supplierIdSet.retainAll(supplierIds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // =========================
|
|
|
+ // 3 市
|
|
|
+ // =========================
|
|
|
+ if (StringUtils.isNotBlank(bo.getCityName())) {
|
|
|
+
|
|
|
+ List<Long> supplierIds =
|
|
|
+ remoteSupplierInfoService.getSupplierIdsBySupplyArea(
|
|
|
+ bo.getCityName(), "2");
|
|
|
+
|
|
|
+ if (supplierIdSet == null) {
|
|
|
+ supplierIdSet = new HashSet<>(supplierIds);
|
|
|
+ } else {
|
|
|
+ supplierIdSet.retainAll(supplierIds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // =========================
|
|
|
+ // 4 产品名称
|
|
|
+ // =========================
|
|
|
+ if (StringUtils.isNotBlank(bo.getProductName())) {
|
|
|
+
|
|
|
+ if (!esMapper.existsIndex("productbasevo")) {
|
|
|
+ LambdaQueryWrapper<ProductBase> lqw1 = new LambdaQueryWrapper<>();
|
|
|
+ lqw1.like(ProductBase::getItemName, bo.getProductName());
|
|
|
+ lqw1.select(ProductBase::getId);
|
|
|
+
|
|
|
+ List<Long> productIds = productBaseMapper.selectList(lqw1)
|
|
|
+ .stream()
|
|
|
+ .map(ProductBase::getId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (CollUtil.isNotEmpty(productIds)) {
|
|
|
+ lqw.in(ContractProduct::getProductId, productIds);
|
|
|
+ } else {
|
|
|
+ return TableDataInfo.build(new Page<>());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ LambdaEsQueryWrapper<ProductBaseVo> esQueryWrapper = new LambdaEsQueryWrapper<ProductBaseVo>()
|
|
|
+ .like(ProductBaseVo::getItemName, bo.getProductName())
|
|
|
+ .select(ProductBaseVo::getId);
|
|
|
+ List<ProductBaseVo> esListInfo = esMapper.selectList(esQueryWrapper);
|
|
|
+ List<Long> collect = esListInfo.stream().map(ProductBaseVo::getId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (CollUtil.isNotEmpty(collect)) {
|
|
|
+ lqw.in(ContractProduct::getProductId, collect);
|
|
|
+ } else {
|
|
|
+ return TableDataInfo.build(new Page<>());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // =========================
|
|
|
+ // 5 产品编号
|
|
|
+ // =========================
|
|
|
+ if (StringUtils.isNotBlank(bo.getProductNo())) {
|
|
|
+ lqw.eq(ContractProduct::getProductNo, bo.getProductNo());
|
|
|
+ }
|
|
|
+
|
|
|
+ // =========================
|
|
|
+ // 6 supplierId 过滤
|
|
|
+ // =========================
|
|
|
+ if (CollUtil.isNotEmpty(supplierIdSet)) {
|
|
|
+ List<Long> contractIds = remoteSupplierInfoService.getContractIdBySupplySupplierID(supplierIdSet);
|
|
|
+ if (CollUtil.isNotEmpty(contractIds)) {
|
|
|
+ lqw.in(ContractProduct::getContractSupplyId, contractIds);
|
|
|
+ } else {
|
|
|
+ return TableDataInfo.build(new Page<>());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Page<ContractProductVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
|
|
+ List<ContractProductVo> records = result.getRecords();
|
|
|
+ if (records.isEmpty()) {
|
|
|
+ return TableDataInfo.build(result);
|
|
|
+ }
|
|
|
+ List<Long> productIds = records.stream()
|
|
|
+ .map(ContractProductVo::getProductId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ LambdaEsQueryWrapper<ProductBaseVo> esQueryWrapper = new LambdaEsQueryWrapper<ProductBaseVo>()
|
|
|
+ .in(ProductBaseVo::getId, productIds);
|
|
|
+ List<ProductBaseVo> productVos;
|
|
|
+ try {
|
|
|
+ if (!esMapper.existsIndex("productbasevo")) {
|
|
|
+ log.warn("ES索引 [productbasevo] 不存在,降级到数据库查询");
|
|
|
+ // 可调用 fallback 方法
|
|
|
+ productVos = productBaseMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<ProductBase>().in(ProductBase::getId, productIds)
|
|
|
+ ).stream().map(pb -> {
|
|
|
+ ProductBaseVo vo = new ProductBaseVo();
|
|
|
+ BeanUtils.copyProperties(pb, vo);
|
|
|
+ return vo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ EsPageInfo<ProductBaseVo> esPageInfo = esMapper.pageQuery(esQueryWrapper, 1, productIds.size());
|
|
|
+ productVos = esPageInfo.getList();
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("ES查询商品信息异常: {}", e.getMessage(), e);
|
|
|
+ productVos = productBaseMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<ProductBase>().in(ProductBase::getId, productIds)
|
|
|
+ ).stream().map(pb -> {
|
|
|
+ ProductBaseVo vo = new ProductBaseVo();
|
|
|
+ BeanUtils.copyProperties(pb, vo);
|
|
|
+ return vo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<Long, ProductBaseVo> productMap = productVos.stream()
|
|
|
+ .collect(Collectors.toMap(ProductBaseVo::getId, p -> p));
|
|
|
+
|
|
|
+ // ----------------------
|
|
|
+ // 4️⃣ 批量填充 VO
|
|
|
+ // ----------------------
|
|
|
+ for (ContractProductVo vo : records) {
|
|
|
+ if (vo.getProductId() != null && productMap.containsKey(vo.getProductId())) {
|
|
|
+ ProductBaseVo pb = productMap.get(vo.getProductId());
|
|
|
+ vo.setProductName(pb.getItemName());
|
|
|
+ vo.setProductImage(pb.getProductImage());
|
|
|
+ vo.setBrandId(pb.getBrandId());
|
|
|
+ vo.setBrandName(pb.getBrandName());
|
|
|
+ vo.setUnitName(pb.getUnitName());
|
|
|
+ vo.setMarketPrice(pb.getMarketPrice());
|
|
|
+ vo.setMemberPrice(pb.getMemberPrice());
|
|
|
+ vo.setMinOrderQuantity(pb.getMinOrderQuantity());
|
|
|
+ vo.setMinSellingPrice(pb.getMinSellingPrice());
|
|
|
+ vo.setTotalInventory(pb.getTotalInventory());
|
|
|
+ vo.setNowInventory(pb.getNowInventory());
|
|
|
+ vo.setVirtualInventory(pb.getVirtualInventory());
|
|
|
+ vo.setBottomCategoryName(pb.getBottomCategoryName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //供应商名称回填
|
|
|
+ List<Long> contractSupplyIds = records.stream()
|
|
|
+ .map(ContractProductVo::getContractSupplyId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+
|
|
|
+ Map<Long, SupplierAreaDTO> suppliers = remoteSupplierInfoService.selectSupplierInfoByContractIds(contractSupplyIds);
|
|
|
+
|
|
|
+ for (ContractProductVo vo : records) {
|
|
|
+ Long contractSupplyId = vo.getContractSupplyId();
|
|
|
+
|
|
|
+ SupplierAreaDTO supplier = suppliers.get(contractSupplyId);
|
|
|
+
|
|
|
+ if (supplier != null) {
|
|
|
+
|
|
|
+ // 企业名称
|
|
|
+ vo.setEnterpriseName(supplier.getEnterpriseName());
|
|
|
+
|
|
|
+ // 供应区域
|
|
|
+ vo.setProvinceName(supplier.getProvinceName());
|
|
|
+ vo.setCityName(supplier.getCityName());
|
|
|
+ vo.setEndTime(supplier.getEndTime());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return TableDataInfo.build(result);
|
|
|
+ }
|
|
|
+
|
|
|
}
|