添加商品关联推荐
This commit is contained in:
@@ -32,7 +32,7 @@ public interface ProductMapper extends BaseMapper<Product> {
|
||||
|
||||
List<ShopProductVo> selectHotsProductList(@Param("shopId") Long shopId);
|
||||
|
||||
List<ShopProductVo> selectGroupProductList(@Param("shopId") Long shopId);
|
||||
List<ShopProductVo> selectGroupProductList(@Param("shopId") Long shopId, @Param("idList") List<Long> idList);
|
||||
|
||||
ShopProductInfoVo selectOneProductInfo(@Param("id") Long id, @Param("shopId") Long shopId);
|
||||
|
||||
|
||||
@@ -6,14 +6,12 @@ import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONWriter;
|
||||
import com.czg.constant.CacheConstant;
|
||||
import com.czg.constants.SystemConstants;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.product.dto.ProdConsRelationDTO;
|
||||
import com.czg.product.dto.ProdSkuDTO;
|
||||
import com.czg.product.dto.ProductDTO;
|
||||
import com.czg.product.dto.ShopProdCategoryDTO;
|
||||
import com.czg.product.dto.*;
|
||||
import com.czg.product.entity.*;
|
||||
import com.czg.product.enums.*;
|
||||
import com.czg.product.param.*;
|
||||
@@ -310,6 +308,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
dto.setSkuList(skuList);
|
||||
List<ProdConsRelationDTO> consList = prodConsRelationMapper.selectListByProdId(dto.getId());
|
||||
dto.setConsList(consList);
|
||||
dto.setRelatedRecommendJson(getRelateProductList(dto.getRelatedRecommend()));
|
||||
return dto;
|
||||
}
|
||||
|
||||
@@ -336,6 +335,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
}
|
||||
entity.setIsDel(SystemConstants.OneZero.ZERO);
|
||||
entity.setShopId(shopId);
|
||||
entity.setRelatedRecommend(dto.getRelatedRecommendStr());
|
||||
super.save(entity);
|
||||
dto.setId(entity.getId());
|
||||
// 清除商品分类列表缓存
|
||||
@@ -404,6 +404,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
if (!ProductTypeEnum.SKU.value().equals(entity.getType())) {
|
||||
UpdateChain.of(Product.class).set(Product::getSpecId, null).eq(Product::getId, dto.getId()).update();
|
||||
}
|
||||
entity.setRelatedRecommend(dto.getRelatedRecommendStr());
|
||||
super.updateById(entity);
|
||||
// 清除商品分类列表缓存
|
||||
clearProductCache(old.getCategoryId());
|
||||
@@ -788,4 +789,16 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
String key = StrUtil.format(CacheConstant.SHOP_PRODUCT_STOCK, shopId, productId);
|
||||
redisService.set(key, stockNumber);
|
||||
}
|
||||
|
||||
private List<RelatedProductDTO> getRelateProductList(String relatedProduct) {
|
||||
if (StrUtil.isNotBlank(relatedProduct) && !"[]".equals(relatedProduct)) {
|
||||
List<Long> idList = JSONArray.parseArray(relatedProduct, Long.class);
|
||||
|
||||
QueryWrapper wrapper = QueryWrapper.create().select(Product::getId, Product::getName, Product::getCoverImg).eq(Product::getIsDel, SystemConstants.OneZero.ZERO)
|
||||
.in(Product::getId, idList);
|
||||
return super.listAs(wrapper, RelatedProductDTO.class);
|
||||
}
|
||||
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.czg.constant.CacheConstant;
|
||||
import com.czg.constants.SystemConstants;
|
||||
import com.czg.exception.CzgException;
|
||||
@@ -27,6 +28,7 @@ import com.czg.service.product.mapper.ProdGroupMapper;
|
||||
import com.czg.service.product.mapper.ProdGroupRelationMapper;
|
||||
import com.czg.service.product.mapper.ProdSkuMapper;
|
||||
import com.czg.service.product.mapper.ProductMapper;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -78,7 +80,7 @@ public class UProductServiceImpl extends ServiceImpl<ProductMapper, Product> imp
|
||||
query().select(ProdGroup::getId, ProdGroup::getName, ProdGroup::getSortMode, ProdGroup::getUseTime, ProdGroup::getSaleStartTime, ProdGroup::getSaleEndTime)
|
||||
.eq(ProdGroup::getShopId, shopId).eq(ProdGroup::getStatus,SystemConstants.OneZero.ONE)
|
||||
.orderBy(ProdGroup::getSort, true), ShopGroupProductVo.class);
|
||||
List<ShopProductVo> productAllList = productMapper.selectGroupProductList(shopId);
|
||||
List<ShopProductVo> productAllList = productMapper.selectGroupProductList(shopId, null);
|
||||
productAllList.forEach(item -> {
|
||||
List<ProdSkuDTO> skuList = prodSkuMapper.selectListByQueryAs(query()
|
||||
.eq(ProdSku::getProductId, item.getId())
|
||||
@@ -233,6 +235,31 @@ public class UProductServiceImpl extends ServiceImpl<ProductMapper, Product> imp
|
||||
return SystemConstants.OneZero.ZERO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ShopProductVo> queryProductRelatedList(Long productId) {
|
||||
Product product = getOne(QueryWrapper.create().eq(Product::getId, productId)
|
||||
.eq(Product::getShopId, StpKit.USER.getShopId())
|
||||
.eq(Product::getIsDel, SystemConstants.OneZero.ZERO));
|
||||
|
||||
if (product == null) {
|
||||
throw new CzgException("商品信息不存在");
|
||||
}
|
||||
|
||||
if (StrUtil.isBlank(product.getRelatedRecommend()) || "[]".equals(product.getRelatedRecommend())) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
List<ShopProductVo> productAllList = productMapper.selectGroupProductList(product.getShopId(), JSONArray.parseArray(product.getRelatedRecommend(), Long.class));
|
||||
productAllList.forEach(item -> {
|
||||
List<ProdSkuDTO> skuList = prodSkuMapper.selectListByQueryAs(query()
|
||||
.eq(ProdSku::getProductId, item.getId())
|
||||
.eq(ProdSku::getIsGrounding, SystemConstants.OneZero.ONE)
|
||||
.eq(ProdSku::getIsDel, SystemConstants.OneZero.ZERO), ProdSkuDTO.class);
|
||||
item.setSkuList(skuList);
|
||||
});
|
||||
return productAllList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算是否在可售时间内
|
||||
*
|
||||
|
||||
@@ -147,6 +147,12 @@
|
||||
and t2.sale_price is not null
|
||||
and t1.shop_id = #{shopId}
|
||||
</where>
|
||||
<if test="idList != null">
|
||||
and t1.id in
|
||||
<foreach item="item" collection="idList" separator="," open="(" close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
order by t1.sort desc,t1.id desc
|
||||
</select>
|
||||
<select id="selectOneProductInfo" resultType="com.czg.product.vo.ShopProductInfoVo">
|
||||
|
||||
Reference in New Issue
Block a user