|
|
@@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
@@ -23,7 +24,9 @@ import org.dromara.common.satoken.utils.LoginHelper;
|
|
|
import org.dromara.easyes.core.biz.EsPageInfo;
|
|
|
import org.dromara.easyes.core.conditions.select.LambdaEsQueryWrapper;
|
|
|
import org.dromara.external.api.domain.ExternalProductDto;
|
|
|
+import org.dromara.external.api.service.RemoteErpPushService;
|
|
|
import org.dromara.external.api.service.RemoteExternalProductService;
|
|
|
+import org.dromara.product.api.erp.domain.push.ComProdInfo;
|
|
|
import org.dromara.product.domain.*;
|
|
|
import org.dromara.product.domain.bo.*;
|
|
|
import org.dromara.product.domain.vo.*;
|
|
|
@@ -73,6 +76,8 @@ public class ProductBaseServiceImpl extends ServiceImpl<ProductBaseMapper, Produ
|
|
|
private final ProductCustomizationMapper customizationMapper;
|
|
|
//产品分类Mapper
|
|
|
private final ProductCategoryMapper categoryMapper;
|
|
|
+ //产品分类Mapper
|
|
|
+ private final ProductCategoryBindingMapper categoryBindingMapper;
|
|
|
//获取分类绑定的商品
|
|
|
private final ProductCategoryBindingMapper productCategoryBindingMapper;
|
|
|
//品牌信息
|
|
|
@@ -85,6 +90,8 @@ public class ProductBaseServiceImpl extends ServiceImpl<ProductBaseMapper, Produ
|
|
|
private final ProductDecorationFloorLinkMapper decorationFloorLinkMapper;
|
|
|
//工业装修楼层
|
|
|
private final ProductIndustrialFloorLinkMapper industrialFloorLinkMapper;
|
|
|
+ //协议
|
|
|
+ private final ProtocolInfoMapper protocolInfoMapper;
|
|
|
//协议商品
|
|
|
private final ProtocolProductsMapper protocolProductsMapper;
|
|
|
//产品diy属性
|
|
|
@@ -109,6 +116,8 @@ public class ProductBaseServiceImpl extends ServiceImpl<ProductBaseMapper, Produ
|
|
|
|
|
|
@DubboReference
|
|
|
private RemoteExternalProductService externalProductService;
|
|
|
+ @DubboReference
|
|
|
+ private RemoteErpPushService erpPushService;
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -479,21 +488,97 @@ public class ProductBaseServiceImpl extends ServiceImpl<ProductBaseMapper, Produ
|
|
|
LambdaEsQueryWrapper<ProductBaseVo> wrapper = new LambdaEsQueryWrapper<ProductBaseVo>()
|
|
|
.eq(ProductBaseVo::getProductStatus, 1)
|
|
|
;
|
|
|
+ if(LoginHelper.isLogin()){
|
|
|
+ if(Objects.equals(LoginHelper.getLoginUser().getUserSonType(),"3")){
|
|
|
+ //查询是否是大客户
|
|
|
+ ClientSite one = clientSiteMapper.selectOne(Wrappers.lambdaQuery(ClientSite.class)
|
|
|
+ .eq(ClientSite::getClientId, LoginHelper.getLoginUser().getCustomerId())
|
|
|
+ .eq(ClientSite::getStatus, "0")
|
|
|
+ .last("limit 1")
|
|
|
+ );
|
|
|
+ if (ObjectUtil.isNotEmpty(one)){
|
|
|
+ //如果是大客户只查询客户协议池中的商品
|
|
|
+ //获取协议池
|
|
|
+ List<ProtocolProductsVo> protocolProductsVos = protocolProductsMapper.selectVoList(Wrappers.lambdaQuery(ProtocolProducts.class)
|
|
|
+ .eq(ProtocolProducts::getCustomerId, LoginHelper.getLoginUser().getCustomerId())
|
|
|
+ );
|
|
|
+ if (ObjectUtil.isEmpty(protocolProductsVos)){
|
|
|
+ wrapper.eq(ProductBaseVo::getId, 0L);
|
|
|
+ }else{
|
|
|
+ wrapper.in(ProductBaseVo::getId, protocolProductsVos.stream().map(ProtocolProductsVo::getProductId).distinct().toList());
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ //如果是企业购用户只查询企业购的商品
|
|
|
+ //获取客户商品池
|
|
|
+ List<ClientSiteProductVo> clientSiteProductVos = clientSiteProductMapper.selectVoList(Wrappers.lambdaQuery(ClientSiteProduct.class)
|
|
|
+ .eq(ClientSiteProduct::getClientId, LoginHelper.getLoginUser().getCustomerId())
|
|
|
+ );
|
|
|
+ if (ObjectUtil.isEmpty(clientSiteProductVos)){
|
|
|
+ wrapper.eq(ProductBaseVo::getId, 0L);
|
|
|
+ }else {
|
|
|
+ wrapper.in(ProductBaseVo::getId, clientSiteProductVos.stream().map(ClientSiteProductVo::getProductId).distinct().toList());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
if(ObjectUtil.isNotEmpty(bo.getProductNo())){
|
|
|
wrapper.eq(ProductBaseVo::getProductNo, bo.getProductNo());
|
|
|
}
|
|
|
if (ObjectUtil.isNotEmpty(bo.getBrandId())) {
|
|
|
wrapper.eq(ProductBaseVo::getBrandId, bo.getBrandId());
|
|
|
}
|
|
|
-// if (ObjectUtil.isNotEmpty(bo.getTopCategoryId())) {
|
|
|
-// wrapper.eq(ProductBaseVo::getTopCategoryId, bo.getTopCategoryId());
|
|
|
-// }
|
|
|
-// if (ObjectUtil.isNotEmpty(bo.getMediumCategoryId())) {
|
|
|
-// wrapper.eq(ProductBaseVo::getMediumCategoryId, bo.getMediumCategoryId());
|
|
|
-// }
|
|
|
-// if (ObjectUtil.isNotEmpty(bo.getBottomCategoryId())) {
|
|
|
-// wrapper.eq(ProductBaseVo::getBottomCategoryId, bo.getBottomCategoryId());
|
|
|
-// }
|
|
|
+ if (ObjectUtil.isNotEmpty(bo.getTopCategoryId())) {
|
|
|
+ //获取分类所属的平台
|
|
|
+ ProductCategory productCategory = categoryMapper.selectById(bo.getTopCategoryId());
|
|
|
+ Long platform = productCategory.getPlatform();
|
|
|
+ if (platform == 0) {
|
|
|
+ wrapper.eq(ProductBaseVo::getTopCategoryId, bo.getTopCategoryId());
|
|
|
+ }else{
|
|
|
+ List<ProductCategoryBindingVo> productCategoryBindingVos = productCategoryBindingMapper.selectVoList(Wrappers.lambdaQuery(ProductCategoryBinding.class)
|
|
|
+ .eq(ProductCategoryBinding::getTopCategoryId, bo.getTopCategoryId())
|
|
|
+ );
|
|
|
+ if (CollUtil.isEmpty(productCategoryBindingVos)) {
|
|
|
+ wrapper.eq(ProductBaseVo::getId,0);
|
|
|
+ }else{
|
|
|
+ wrapper.in(ProductBaseVo::getId, productCategoryBindingVos.stream().map(ProductCategoryBindingVo::getProductId).distinct().toList());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotEmpty(bo.getMediumCategoryId())) {
|
|
|
+
|
|
|
+ //获取分类所属的平台
|
|
|
+ ProductCategory productCategory = categoryMapper.selectById(bo.getMediumCategoryId());
|
|
|
+ Long platform = productCategory.getPlatform();
|
|
|
+ if (platform == 0) {
|
|
|
+ wrapper.eq(ProductBaseVo::getMediumCategoryId, bo.getMediumCategoryId());
|
|
|
+ }else{
|
|
|
+ List<ProductCategoryBindingVo> productCategoryBindingVos = productCategoryBindingMapper.selectVoList(Wrappers.lambdaQuery(ProductCategoryBinding.class)
|
|
|
+ .eq(ProductCategoryBinding::getMediumCategoryId, bo.getMediumCategoryId())
|
|
|
+ );
|
|
|
+ if (CollUtil.isEmpty(productCategoryBindingVos)) {
|
|
|
+ wrapper.eq(ProductBaseVo::getId,0);
|
|
|
+ }else{
|
|
|
+ wrapper.in(ProductBaseVo::getId, productCategoryBindingVos.stream().map(ProductCategoryBindingVo::getProductId).distinct().toList());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotEmpty(bo.getBottomCategoryId())) {
|
|
|
+ //获取分类所属的平台
|
|
|
+ ProductCategory productCategory = categoryMapper.selectById(bo.getBottomCategoryId());
|
|
|
+ Long platform = productCategory.getPlatform();
|
|
|
+ if (platform == 0) {
|
|
|
+ wrapper.eq(ProductBaseVo::getBottomCategoryId, bo.getBottomCategoryId());
|
|
|
+ }else{
|
|
|
+ List<ProductCategoryBindingVo> productCategoryBindingVos = productCategoryBindingMapper.selectVoList(Wrappers.lambdaQuery(ProductCategoryBinding.class)
|
|
|
+ .eq(ProductCategoryBinding::getBottomCategoryId, bo.getBottomCategoryId())
|
|
|
+ );
|
|
|
+ if (CollUtil.isEmpty(productCategoryBindingVos)) {
|
|
|
+ wrapper.eq(ProductBaseVo::getId,0);
|
|
|
+ }else{
|
|
|
+ wrapper.in(ProductBaseVo::getId, productCategoryBindingVos.stream().map(ProductCategoryBindingVo::getProductId).distinct().toList());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
if (ObjectUtil.isNotEmpty(bo.getIsCustomize())) {
|
|
|
wrapper.eq(ProductBaseVo::getIsCustomize, bo.getIsCustomize());
|
|
|
}
|
|
|
@@ -553,9 +638,66 @@ public class ProductBaseServiceImpl extends ServiceImpl<ProductBaseMapper, Produ
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 处理商品属性查询
|
|
|
+ if (ObjectUtil.isNotEmpty(bo.getAttributesList())) {
|
|
|
+ parseAndApplyAttributesFilter(wrapper, bo.getAttributesList());
|
|
|
+ }
|
|
|
+
|
|
|
return wrapper;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 解析并应用商品属性过滤器
|
|
|
+ * 前端传值格式: 属性名:属性值|属性名:属性值
|
|
|
+ * 例如: 测试:123|商品123:123
|
|
|
+ * 数据库存储格式: {"测试":"456","商品123":["123","456"]}
|
|
|
+ *
|
|
|
+ * @param wrapper ES查询包装器
|
|
|
+ * @param attributesListStr 前端传来的属性字符串
|
|
|
+ */
|
|
|
+ private void parseAndApplyAttributesFilter(LambdaEsQueryWrapper<ProductBaseVo> wrapper, String attributesListStr) {
|
|
|
+ try {
|
|
|
+ // 解析前端传来的属性字符串,格式:属性名:属性值|属性名:属性值
|
|
|
+ String[] attributePairs = attributesListStr.split("\\|");
|
|
|
+
|
|
|
+ if (attributePairs.length == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建ES查询条件,需要匹配所有属性(AND关系)
|
|
|
+ for (String pair : attributePairs) {
|
|
|
+ if (!pair.contains(":")) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ String[] keyValue = pair.split(":", 2);
|
|
|
+ if (keyValue.length != 2) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ String attributeName = keyValue[0].trim();
|
|
|
+ String attributeValue = keyValue[1].trim();
|
|
|
+
|
|
|
+ if (ObjectUtil.isEmpty(attributeName) || ObjectUtil.isEmpty(attributeValue)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 由于attributes_list是JSON字符串,需要使用ES的script查询或wildcard查询
|
|
|
+ // 这里使用wildcard模糊匹配JSON中的键值对
|
|
|
+ // 匹配两种情况:
|
|
|
+ // 1. 字符串值:"属性名":"属性值"
|
|
|
+ // 2. 数组值:"属性名":["属性值",...]
|
|
|
+ wrapper.and(w -> w
|
|
|
+ .like(ProductBaseVo::getAttributesList, "\"" + attributeName + "\":\"" + attributeValue + "\"")
|
|
|
+ .or()
|
|
|
+ .like(ProductBaseVo::getAttributesList, "\"" + attributeName + "\":[\"" + attributeValue + "\"")
|
|
|
+ );
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("解析商品属性失败: {}", e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* PC端商品列表降级查询
|
|
|
*/
|
|
|
@@ -647,7 +789,6 @@ public class ProductBaseServiceImpl extends ServiceImpl<ProductBaseMapper, Produ
|
|
|
saveProductDetail(bo, productId);
|
|
|
// 7. 同步到ES索引
|
|
|
syncToES(productId);
|
|
|
-
|
|
|
log.info("成功新增产品,ID: {}, 名称: {}", productId, bo.getItemName());
|
|
|
return true;
|
|
|
|
|
|
@@ -709,7 +850,6 @@ public class ProductBaseServiceImpl extends ServiceImpl<ProductBaseMapper, Produ
|
|
|
|
|
|
// 7. 同步到ES索引
|
|
|
syncToES(productId);
|
|
|
-
|
|
|
log.info("成功更新产品,ID: {}, 名称: {}", productId, bo.getItemName());
|
|
|
return true;
|
|
|
|
|
|
@@ -1281,8 +1421,6 @@ public class ProductBaseServiceImpl extends ServiceImpl<ProductBaseMapper, Produ
|
|
|
if (vo != null) {
|
|
|
// 先尝试更新,如果不存在则插入
|
|
|
try {
|
|
|
- vo.setAttributesList(null);
|
|
|
- vo.setDiyAttributesList(null);
|
|
|
vo.setPcDetail(null);
|
|
|
vo.setMobileDetail(null);
|
|
|
esMapper.updateById(vo);
|
|
|
@@ -1299,6 +1437,62 @@ public class ProductBaseServiceImpl extends ServiceImpl<ProductBaseMapper, Produ
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 同步产品到Erp
|
|
|
+ * */
|
|
|
+ public void syncProductToErp(Long productId,boolean isUpdate) {
|
|
|
+ try {
|
|
|
+ // 查询完整的产品信息(包含关联表数据)
|
|
|
+ ProductBaseVo vo = queryById(productId);
|
|
|
+ if (vo != null) {
|
|
|
+ // 映射字段到 ERP 推送对象
|
|
|
+ ComProdInfo erpProduct = new ComProdInfo();
|
|
|
+ erpProduct.setProdId(vo.getProductNo());
|
|
|
+ erpProduct.setProdNm(vo.getItemName());
|
|
|
+ erpProduct.setUid(vo.getUnitId());
|
|
|
+ erpProduct.setProdCatgId(vo.getBottomCategoryId() != null ? vo.getBottomCategoryId().toString() : null);
|
|
|
+ erpProduct.setTypeId(vo.getProductCategory() != null ? vo.getProductCategory().toString() : null);
|
|
|
+ erpProduct.setProdSpec(vo.getSpecification());
|
|
|
+ erpProduct.setBarCd(vo.getBarCoding());
|
|
|
+ erpProduct.setUseMultUi(false); // 默认不使用多单位
|
|
|
+
|
|
|
+ // 产品状态映射:1=已上架,0=下架 -> ERP 状态可能需要转换,这里暂存字符串
|
|
|
+ erpProduct.setProdSts(vo.getProductStatus() != null ? vo.getProductStatus().toString() : "0");
|
|
|
+
|
|
|
+ erpProduct.setInvNm(vo.getInvoiceName());
|
|
|
+ erpProduct.setInvSpec(vo.getInvoiceSpecs());
|
|
|
+
|
|
|
+ // 价格相关
|
|
|
+ erpProduct.setPurIsPrWtTax(true); // 假设进价含税,可根据业务调整
|
|
|
+ erpProduct.setPurStdPr(vo.getPurchasingPrice());
|
|
|
+ erpProduct.setHighPurPr(vo.getMaxPurchasePrice());
|
|
|
+ erpProduct.setSupId(vo.getSupplierNo());
|
|
|
+ erpProduct.setPurTaxId(vo.getTaxCode());
|
|
|
+
|
|
|
+ erpProduct.setSlsIsPrWtTax(true); // 假设售价含税
|
|
|
+ erpProduct.setSlsStdPr(vo.getMemberPrice());
|
|
|
+ erpProduct.setMinPr(vo.getMinSellingPrice());
|
|
|
+ erpProduct.setSltTaxId(vo.getTaxCode());
|
|
|
+
|
|
|
+ erpProduct.setRemark(vo.getRemark());
|
|
|
+ erpProduct.setTradMrkId(vo.getBrandId() != null ? vo.getBrandId().toString() : null);
|
|
|
+ erpProduct.setMinSalQty(vo.getMinOrderQuantity() != null ? BigDecimal.valueOf(vo.getMinOrderQuantity()) : null);
|
|
|
+ erpProduct.setPurPerId(vo.getPurchaseManagerNo());
|
|
|
+ erpProduct.setCuBhsx("1"); // 备货属性,根据实际业务设置
|
|
|
+
|
|
|
+ // 调用远程服务推送
|
|
|
+ String productJson = JSONUtil.toJsonStr(erpProduct);
|
|
|
+ erpPushService.pushProductData(productJson, isUpdate);
|
|
|
+
|
|
|
+ log.debug("成功{}ERP产品索引,产品ID: {}", isUpdate ? "更新" : "插入", productId);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ // Erp同步失败不影响主业务,只记录日志
|
|
|
+ log.error("同步产品到Erp失败,产品ID: {}, 错误: {}", productId, e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 从ES索引中批量删除产品
|
|
|
*
|
|
|
@@ -1514,196 +1708,10 @@ public class ProductBaseServiceImpl extends ServiceImpl<ProductBaseMapper, Produ
|
|
|
*/
|
|
|
@Override
|
|
|
public TableDataInfo<PcProductVo> getPcProductPage(PcProductBo bo, PageQuery pageQuery) {
|
|
|
- //获取当前登录用户的商品池
|
|
|
-// List<Long> productIds = new ArrayList<>();
|
|
|
-// Map<Long, BigDecimal> agreementPriceMap = new HashMap<>();
|
|
|
-//
|
|
|
-// //是否是大客户
|
|
|
-// if(ObjectUtil.isNotEmpty(LoginHelper.getLoginUser().getCustomerId())) {
|
|
|
-// ClientSiteVo clientSiteVo = clientSiteMapper.selectVoOne(Wrappers.lambdaQuery(ClientSite.class)
|
|
|
-// .eq(ClientSite::getClientId, LoginHelper.getLoginUser().getCustomerId())
|
|
|
-// .orderByDesc(ClientSite::getCreateTime)
|
|
|
-// .last("limit 1")
|
|
|
-// );
|
|
|
-// if (ObjectUtil.isNotEmpty(clientSiteVo)) {
|
|
|
-// Long isDiy = clientSiteVo.getIsDiy();
|
|
|
-// if (ObjectUtil.isNotEmpty(isDiy) && isDiy == 1) {
|
|
|
-// //获取协议商品池商品
|
|
|
-// List<ProtocolProducts> protocolProducts = protocolProductsMapper.selectList(Wrappers.lambdaQuery(ProtocolProducts.class)
|
|
|
-// .eq(ProtocolProducts::getCustomerId, LoginHelper.getLoginUser().getCustomerId())
|
|
|
-// .eq(ProtocolProducts::getAuditStatus, 2)
|
|
|
-// );
|
|
|
-// if (CollUtil.isNotEmpty(protocolProducts)) {
|
|
|
-// agreementPriceMap = protocolProducts.stream().collect(Collectors.toMap(ProtocolProducts::getProductId, ProtocolProducts::getAgreementPrice));
|
|
|
-// productIds = protocolProducts.stream().map(ProtocolProducts::getProductId).toList();
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }else {
|
|
|
-// //获取企业的商品池商品
|
|
|
-// if(Objects.equals(LoginHelper.getLoginUser().getUserSonType(),"3")) {
|
|
|
-// List<ClientSiteProduct> clientSiteProducts = clientSiteProductMapper.selectList();
|
|
|
-// if (CollUtil.isNotEmpty(clientSiteProducts)) {
|
|
|
-// productIds = clientSiteProducts.stream().map(ClientSiteProduct::getProductId).toList();
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// //是否是企业购
|
|
|
-// QueryWrapper<ProductBase> lqw = Wrappers.query(ProductBase.class);
|
|
|
-// if(Objects.equals(LoginHelper.getLoginUser().getUserSonType(),"3")){
|
|
|
-// if (ObjectUtil.isNotEmpty(productIds) ){
|
|
|
-// lqw.in("b.id", productIds);
|
|
|
-// }else {
|
|
|
-// lqw.isNull("b.id");
|
|
|
-// }
|
|
|
-// if (ObjectUtil.isNotEmpty(bo.getTopCategoryId())){
|
|
|
-// //获取分类绑定的商品
|
|
|
-// List<ProductCategoryBinding> productCategoryBindings = productCategoryBindingMapper.selectList(Wrappers.lambdaQuery(ProductCategoryBinding.class)
|
|
|
-// .eq(ProductCategoryBinding::getTopCategoryId, bo.getTopCategoryId())
|
|
|
-// );
|
|
|
-// if (CollUtil.isNotEmpty(productCategoryBindings)) {
|
|
|
-// lqw.in("b.id", productCategoryBindings.stream().map(ProductCategoryBinding::getProductId).toList());
|
|
|
-// }else {
|
|
|
-// lqw.isNull("b.id");
|
|
|
-// }
|
|
|
-// }
|
|
|
-// if (ObjectUtil.isNotEmpty(bo.getMediumCategoryId())){
|
|
|
-// //获取分类绑定的商品
|
|
|
-// List<ProductCategoryBinding> productCategoryBindings = productCategoryBindingMapper.selectList(Wrappers.lambdaQuery(ProductCategoryBinding.class)
|
|
|
-// .eq(ProductCategoryBinding::getMediumCategoryId, bo.getMediumCategoryId())
|
|
|
-// );
|
|
|
-// if (CollUtil.isNotEmpty(productCategoryBindings)) {
|
|
|
-// lqw.in("b.id", productCategoryBindings.stream().map(ProductCategoryBinding::getProductId).toList());
|
|
|
-// }else {
|
|
|
-// lqw.isNull("b.id");
|
|
|
-// }
|
|
|
-// }
|
|
|
-// if (ObjectUtil.isNotEmpty(bo.getBottomCategoryId())){
|
|
|
-// //获取分类绑定的商品
|
|
|
-// List<ProductCategoryBinding> productCategoryBindings = productCategoryBindingMapper.selectList(Wrappers.lambdaQuery(ProductCategoryBinding.class)
|
|
|
-// .eq(ProductCategoryBinding::getBottomCategoryId, bo.getBottomCategoryId())
|
|
|
-// );
|
|
|
-// if (CollUtil.isNotEmpty(productCategoryBindings)) {
|
|
|
-// lqw.in("b.id", productCategoryBindings.stream().map(ProductCategoryBinding::getProductId).toList());
|
|
|
-// }else {
|
|
|
-// lqw.isNull("b.id");
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// if(ObjectUtil.isNotEmpty( bo.getIds())){
|
|
|
-// lqw.in("b.id", bo.getIds().split(","));
|
|
|
-// }
|
|
|
-//
|
|
|
-// if (ObjectUtil.isNotEmpty(bo.getBrandIds())){
|
|
|
-// lqw.in("b.brand_id", bo.getBrandIds().split(","));
|
|
|
-// }
|
|
|
-// if (ObjectUtil.isNotEmpty(bo.getCategoryIds())){
|
|
|
-// lqw.in("b.bottom_category_id", bo.getCategoryIds().split(","));
|
|
|
-// }
|
|
|
-// lqw.ge(ObjectUtil.isNotEmpty(pageQuery.getFirstSeenId()) && pageQuery.getWay() == 0,"b.id", pageQuery.getFirstSeenId());
|
|
|
-// lqw.gt(ObjectUtil.isNotEmpty(pageQuery.getLastSeenId()) && pageQuery.getWay() == 1,"b.id", pageQuery.getLastSeenId());
|
|
|
-// lqw.eq(ObjectUtil.isNotEmpty(bo.getIsSelf()), "b.is_self", bo.getIsSelf());
|
|
|
-//// lqw.eq("b.product_status", 1);
|
|
|
-// lqw.and(ObjectUtil.isNotEmpty(bo.getSearchKeyword())
|
|
|
-// , (queryWrapper) -> queryWrapper.and(qw ->
|
|
|
-// qw.like("b.item_name", bo.getSearchKeyword())
|
|
|
-// .or().like("tc.category_name", bo.getSearchKeyword())
|
|
|
-// .or().like("mc.category_name", bo.getSearchKeyword())
|
|
|
-// .or().like("bc.category_name", bo.getSearchKeyword())
|
|
|
-// .or().like("br.brand_name", bo.getSearchKeyword())
|
|
|
-// )
|
|
|
-// );
|
|
|
-// lqw.like(StringUtils.isNotBlank(bo.getProductNo()), "b.product_no", bo.getProductNo());
|
|
|
-// lqw.eq(ObjectUtil.isNotEmpty(bo.getBrandId()), "b.brand_id", bo.getBrandId());
|
|
|
-// lqw.eq(ObjectUtil.isNotEmpty(bo.getTopCategoryId()), "b.top_category_id", bo.getTopCategoryId());
|
|
|
-// lqw.eq(ObjectUtil.isNotEmpty(bo.getMediumCategoryId()), "b.medium_category_id", bo.getMediumCategoryId());
|
|
|
-// lqw.eq(ObjectUtil.isNotEmpty(bo.getBottomCategoryId()), "b.bottom_category_id", bo.getBottomCategoryId());
|
|
|
-// lqw.eq(ObjectUtil.isNotEmpty(bo.getIsCustomize()), "e.is_customize", bo.getIsCustomize());
|
|
|
-// if(bo.getPriceRange() != null){
|
|
|
-// //价格区间 1:1-100 2:100-500 3:500-1000 4:1000以上
|
|
|
-// switch (bo.getPriceRange()) {
|
|
|
-// case "1":
|
|
|
-// lqw.between("p.market_price", 1, 100);
|
|
|
-// case "2":
|
|
|
-// lqw.between("p.market_price", 100, 500);
|
|
|
-// case "3":
|
|
|
-// lqw.between("p.market_price", 500, 1000);
|
|
|
-// case "4":
|
|
|
-// lqw.ge("p.market_price", 1000);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// if(bo.getSortField() != null && bo.getSortOrder() != null){
|
|
|
-// String[] sortFields = bo.getSortField().split(",");
|
|
|
-// String[] sortOrders = bo.getSortOrder().split(",");
|
|
|
-// for (int i = 0; i < sortFields.length; i++) {
|
|
|
-// switch (sortFields[i]) {
|
|
|
-// case "1":
|
|
|
-// lqw.orderBy( true, sortOrders[i].equals("Asc"),"b.id");
|
|
|
-// case "2":
|
|
|
-// lqw.orderBy( true, sortOrders[i].equals("Asc"),"p.total_inventory");
|
|
|
-// case "3":
|
|
|
-// lqw.orderBy( true, sortOrders[i].equals("Asc"),"p.market_price");
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
// 使用ES分页查询
|
|
|
try {
|
|
|
LambdaEsQueryWrapper<ProductBaseVo> esQueryWrapper = buildEsQueryWrapperForPc(bo);
|
|
|
- if(LoginHelper.isLogin()){
|
|
|
- if(Objects.equals(LoginHelper.getLoginUser().getUserSonType(),"3")){
|
|
|
-// if (ObjectUtil.isNotEmpty(productIds) ){
|
|
|
-// esQueryWrapper.in(ProductBaseVo::getId, productIds);
|
|
|
-// }else {
|
|
|
-// esQueryWrapper.eq(ProductBaseVo::getId, 0L);
|
|
|
-// }
|
|
|
- if (ObjectUtil.isNotEmpty(bo.getTopCategoryId())){
|
|
|
- //获取分类绑定的商品
|
|
|
- List<ProductCategoryBinding> productCategoryBindings = productCategoryBindingMapper.selectList(Wrappers.lambdaQuery(ProductCategoryBinding.class)
|
|
|
- .eq(ProductCategoryBinding::getTopCategoryId, bo.getTopCategoryId())
|
|
|
- );
|
|
|
- if (CollUtil.isNotEmpty(productCategoryBindings)) {
|
|
|
- esQueryWrapper.in(ProductBaseVo::getId, productCategoryBindings.stream().map(ProductCategoryBinding::getProductId).toList());
|
|
|
- }else {
|
|
|
- esQueryWrapper.eq(ProductBaseVo::getId, 0L);
|
|
|
- }
|
|
|
- }
|
|
|
- if (ObjectUtil.isNotEmpty(bo.getMediumCategoryId())){
|
|
|
- //获取分类绑定的商品
|
|
|
- List<ProductCategoryBinding> productCategoryBindings = productCategoryBindingMapper.selectList(Wrappers.lambdaQuery(ProductCategoryBinding.class)
|
|
|
- .eq(ProductCategoryBinding::getMediumCategoryId, bo.getMediumCategoryId())
|
|
|
- );
|
|
|
- if (CollUtil.isNotEmpty(productCategoryBindings)) {
|
|
|
- esQueryWrapper.in(ProductBaseVo::getId, productCategoryBindings.stream().map(ProductCategoryBinding::getProductId).toList());
|
|
|
- }else {
|
|
|
- esQueryWrapper.eq(ProductBaseVo::getId, 0L);
|
|
|
- }
|
|
|
- }
|
|
|
- if (ObjectUtil.isNotEmpty(bo.getBottomCategoryId())){
|
|
|
- //获取分类绑定的商品
|
|
|
- List<ProductCategoryBinding> productCategoryBindings = productCategoryBindingMapper.selectList(Wrappers.lambdaQuery(ProductCategoryBinding.class)
|
|
|
- .eq(ProductCategoryBinding::getBottomCategoryId, bo.getBottomCategoryId())
|
|
|
- );
|
|
|
- if (CollUtil.isNotEmpty(productCategoryBindings)) {
|
|
|
- esQueryWrapper.in(ProductBaseVo::getId, productCategoryBindings.stream().map(ProductCategoryBinding::getProductId).toList());
|
|
|
- }else {
|
|
|
- esQueryWrapper.eq(ProductBaseVo::getId, 0L);
|
|
|
- }
|
|
|
- }
|
|
|
- }else {
|
|
|
- if (ObjectUtil.isNotEmpty(bo.getTopCategoryId())) {
|
|
|
- esQueryWrapper.eq(ProductBaseVo::getTopCategoryId, bo.getTopCategoryId());
|
|
|
- }
|
|
|
- if (ObjectUtil.isNotEmpty(bo.getMediumCategoryId())) {
|
|
|
- esQueryWrapper.eq(ProductBaseVo::getMediumCategoryId, bo.getMediumCategoryId());
|
|
|
- }
|
|
|
- if (ObjectUtil.isNotEmpty(bo.getBottomCategoryId())) {
|
|
|
- esQueryWrapper.eq(ProductBaseVo::getBottomCategoryId, bo.getBottomCategoryId());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
// 检查ES索引是否存在
|
|
|
if (!esMapper.existsIndex("productbasevo")) {
|
|
|
log.warn("ES索引 [productbasevo] 不存在,降级到数据库查询");
|
|
|
@@ -1715,6 +1723,36 @@ public class ProductBaseServiceImpl extends ServiceImpl<ProductBaseMapper, Produ
|
|
|
|
|
|
if (CollUtil.isNotEmpty(esPageInfo.getList())) {
|
|
|
List<PcProductVo> pcProductVos = BeanUtil.copyToList(esPageInfo.getList(), PcProductVo.class);
|
|
|
+ //如果是大客户则需要将价格改为协议价
|
|
|
+ if(LoginHelper.isLogin()){
|
|
|
+ if(Objects.equals(LoginHelper.getLoginUser().getUserSonType(),"3")){
|
|
|
+ //查询是否是大客户
|
|
|
+ ClientSite one = clientSiteMapper.selectOne(Wrappers.lambdaQuery(ClientSite.class)
|
|
|
+ .eq(ClientSite::getClientId, LoginHelper.getLoginUser().getCustomerId())
|
|
|
+ .eq(ClientSite::getStatus, "0")
|
|
|
+ .last("limit 1")
|
|
|
+ );
|
|
|
+ if (ObjectUtil.isNotEmpty(one)){
|
|
|
+ //如果是大客户只查询客户协议池中的商品
|
|
|
+ //获取协议
|
|
|
+ ProtocolInfo protocolInfo = protocolInfoMapper.selectOne(Wrappers.lambdaQuery(ProtocolInfo.class)
|
|
|
+ .eq(ProtocolInfo::getCustomerId, LoginHelper.getLoginUser().getCustomerId())
|
|
|
+ .orderByDesc(ProtocolInfo::getCreateTime)
|
|
|
+ .last("limit 1")
|
|
|
+ );
|
|
|
+ //获取协议池
|
|
|
+ List<ProtocolProducts> protocolProductsVos = protocolProductsMapper.selectList(Wrappers.lambdaQuery(ProtocolProducts.class)
|
|
|
+ .eq(ProtocolProducts::getProtocolId, protocolInfo.getId())
|
|
|
+ );
|
|
|
+ if (CollUtil.isNotEmpty(protocolProductsVos)) {
|
|
|
+ Map<Long, BigDecimal> map = protocolProductsVos.stream().collect(Collectors.toMap(ProtocolProducts::getProductId, ProtocolProducts::getAgreementPrice));
|
|
|
+ pcProductVos.forEach(pcProductVo -> {
|
|
|
+ pcProductVo.setMemberPrice(map.get(pcProductVo.getId()));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
TableDataInfo<PcProductVo> tableDataInfo = TableDataInfo.build(pcProductVos);
|
|
|
tableDataInfo.setTotal(esPageInfo.getTotal());
|
|
|
return tableDataInfo;
|
|
|
@@ -1728,6 +1766,7 @@ public class ProductBaseServiceImpl extends ServiceImpl<ProductBaseMapper, Produ
|
|
|
return TableDataInfo.build();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
public static void main(String[] args) {
|
|
|
Date oldPlanStartAt = DateUtil.parse("2026-03-18 00:00:00");
|
|
|
Date oldPlanEndAt = DateUtil.parse("2026-04-18 00:00:00");
|