商品上架-功能实现(1)

1.接口文档

在这里插入图片描述

2.SpuInfoController中添加spuUp方法

 /**
  * 商品上架
  * @param spuId
  * @return
  */
 @PostMapping("/{spuId}/up")
 public R spuUp(@PathVariable("spuId") Long spuId) {
     spuInfoService.up(spuId);
     return R.ok();
 }

3.SpuInfoService中添加up方法

 void up(Long spuId);

4.sku在ES中模型

在gulimall-common项目中新建es包

package com.atguigu.common.to.es;

import lombok.Data;

import java.math.BigDecimal;
import java.util.List;


/**
 * spu在es中模型
 * @author zfh
 * @email hst1406959716@163.com
 * @date 2021-12-14 09:40:46
 */
@Data
public class SkuEsModel {
    private Long skuId;

    private Long spuId;

    private String skuTitle;

    private BigDecimal skuPrice;

    private String skuImg;

    private Long saleCount;

    private Boolean hasStock;

    private Long hotScore;

    private Long brandId;

    private Long catalogId;

    private String brandName;

    private String brandImg;

    private String catalogName;

    private List<Attrs> attrs;

    @Data
    public static class Attrs {
        private Long attrId;

        private String attrName;

        private String attrValue;

    }
}

5.查询当前spuId对应的sku

5.1.SkuInfoService添加getSkusBySpuId方法

List<SkuInfoEntity> getSkusBySpuId(Long spuId);

5.2.SkuInfoServiceImpl中添加getSkusBySpuId方法实现

/**
 * 根据spuId查询对应的sku
 * @param spuId
 * @return
 */
@Override
public List<SkuInfoEntity> getSkusBySpuId(Long spuId) {
    List<SkuInfoEntity> skuInfoEntities = this.list(
            new QueryWrapper<SkuInfoEntity>().eq("spu_id", spuId));
    return skuInfoEntities;
}

6.查询当前sku所有可被检索的规格属性

6.1.AttrService中添加selectSearchAttrIds

List<Long> selectSearchAttrIds(List<Long> attrIds);

6.2.AttrServiceImpl添加selectSearchAttrIds方法实现

 /**
  * 在指定的所有属性中挑出可被检索的属性
  * @param attrIds
  * @return
  */
 @Override
 public List<Long> selectSearchAttrIds(List<Long> attrIds) {
     return baseMapper.selectSearchAttrIds(attrIds);
 }

6.3.AttrDao中添加selectSearchAttrIds

 List<Long> selectSearchAttrIds(@Param("attrIds") List<Long> attrIds);

6.4.AttrDao.xml

<select id="selectSearchAttrIds" resultType="java.lang.Long">
   SELECT attr_id FROM pms_attr WHERE attr_id IN
      <foreach collection="attrIds" item="attrId" separator="," open="(" close=")">
          #{attrId}
      </foreach>
   AND search_type = 1
 </select>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值