【大型电商项目开发】商品服务之新增商品会员调试&获取分类关联的品牌-26

一:调试会员等级相关接口

1.获取所有会员等级接口

POST   /member/memberlevel/list

2.在网关配置好路由关系

spring:
  cloud:
    gateway:
      routes:
        - id: product_route
          uri: lb://gulimail-product
          predicates:
            - Path=/api/product/**
          filters:
            - RewritePath=/api/(?<segment>.*),/$\{segment}

        - id: third_party_route
          uri: lb://gulimail-third-party
          predicates:
            - Path=/api/thirdparty/**
          filters:
            - RewritePath=/api/thirdparty/(?<segment>.*),/$\{segment}

        - id: member_route
          uri: lb://gulimail-member
          predicates:
            - Path=/api/member/**
          filters:
            - RewritePath=/api/(?<segment>.*),/$\{segment}

3.将前端代码复制过来,重启项目

在这里插入图片描述

二:发布商品

1.获取当前分类关联的所有品牌

在这里插入图片描述
1)在product模块新建BrandVo实体类

package com.sysg.gulimail.product.vo;
import lombok.Data;
/**
 * @author 77916
 */
@Data
public class BrandVo {
    /**
     * 品牌Id
     */
    private Long brandId;
    /**
     * 品牌名称
     */
    private String brandName;
}

2)在CategoryBrandRelationController新建relationBrandsList方法

  /**
     * 通过catId获取商品分类列表
     * @return
     */
    @GetMapping("/brands/list")
    public R relationBrandsList(@RequestParam(value = "catId",required = true) Long catId){
        List<BrandEntity> vos= categoryBrandRelationService.getBrandsByCatId(catId);
        List<BrandVo> list = vos.stream().map((item) -> {
            BrandVo brandVo = new BrandVo();
            brandVo.setBrandName(item.getName());
            brandVo.setBrandId(item.getBrandId());
            return brandVo;
        }).collect(Collectors.toList());
        return R.ok().put("data",list);
    }
  • 1.controller:处理请求,接收和校验数据
  • 2.service:接收controller传递的参数进行业务处理
  • 3.controller:接收service处理完的数据封装成指定的对象

3)在CategoryBrandRelationServiceImpl编写getBrandsByCatId方法

@Override
    public List<BrandEntity> getBrandsByCatId(Long catId) {
        QueryWrapper<CategoryBrandRelationEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("catelog_id", catId);
        List<CategoryBrandRelationEntity> entities = categoryBrandRelationDao.selectList(wrapper);
        List<BrandEntity> brandEntities = entities.stream().map((item) -> {
            Long brandId = item.getBrandId();
            BrandEntity brandEntity = brandService.getById(brandId);
            return brandEntity;
        }).collect(Collectors.toList());
        return brandEntities;
    }

在这里插入图片描述
注:关于pubsub、publish报错,无法发送查询品牌信息的请求:
1、npm install --save pubsub-js
2、在src下的main.js中引用:

  • import PubSub from ‘pubsub-js’
  • Vue.prototype.PubSub = PubSub
import Vue from 'vue'
import App from '@/App'
import router from '@/router'                 // api: https://github.com/vuejs/vue-router
import store from '@/store'                   // api: https://github.com/vuejs/vuex
import VueCookie from 'vue-cookie'            // api: https://github.com/alfhen/vue-cookie
import '@/element-ui'                         // api: https://github.com/ElemeFE/element
import '@/icons'                              // api: http://www.iconfont.cn/
import '@/element-ui-theme'
import '@/assets/scss/index.scss'
import httpRequest from '@/utils/httpRequest' // api: https://github.com/axios/axios
import { isAuth } from '@/utils'
import cloneDeep from 'lodash/cloneDeep'
import PubSub from 'pubsub-js'

Vue.use(VueCookie)
Vue.config.productionTip = false
Vue.prototype.PubSub = PubSub

// 非生产环境, 适配mockjs模拟数据                 // api: https://github.com/nuysoft/Mock
if (process.env.NODE_ENV !== 'production') {
  require('@/mock')
}

// 挂载全局
Vue.prototype.$http = httpRequest // ajax请求方法
Vue.prototype.isAuth = isAuth     // 权限方法

// 保存整站vuex本地储存初始状态
window.SITE_CONFIG['storeState'] = cloneDeep(store.state)

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  template: '<App/>',
  components: { App }
})

2. 获取分类下所有分组&关联属性

1)在vo下新建AttrGroupWithAttrsVo实体类

package com.sysg.gulimail.product.vo;
import com.baomidou.mybatisplus.annotation.TableId;
import com.sysg.gulimail.product.entity.AttrEntity;
import lombok.Data;
import java.util.List;
@Data
public class AttrGroupWithAttrsVo {
    /**
     * 分组id
     */
    private Long attrGroupId;
    /**
     * 组名
     */
    private String attrGroupName;
    /**
     * 排序
     */
    private Integer sort;
    /**
     * 描述
     */
    private String descript;
    /**
     * 组图标
     */
    private String icon;
    /**
     * 所属分类id
     */
    private Long catelogId;
    /**
     * AttrEntity实体
     */
    private List<AttrEntity> attrs;
}

2)在AttrGroupController新建getAttrGroupWithAttrs方法

/**
     * 获取分类下所有分组&关联属性
     * @return
     */
    @GetMapping("{catelogId}/withattr")
    public R getAttrGroupWithAttrs(@PathVariable("catelogId") Long catelogId){
        //1.查出当前分类下所有的属性分组
        //2.查出每个属性分组的所有属性
        List<AttrGroupWithAttrsVo> entity = attrGroupService.getAttrGroupWithAttrsByCatelogId(catelogId);
        return R.ok().put("data",entity);
    }

3)在AttrGroupServiceImpl编写getAttrGroupWithAttrsByCatelogId方法

    /**
     * 获取分类下所有分组&关联属性
     * @param catelogId
     * @return
     */
    @Override
    public List<AttrGroupWithAttrsVo> getAttrGroupWithAttrsByCatelogId(Long catelogId) {
        //1.查询分组信息
        QueryWrapper<AttrGroupEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("catelog_Id",catelogId);
        List<AttrGroupEntity> list = this.list(wrapper);
        List<AttrGroupWithAttrsVo> collect = list.stream().map(item -> {
            AttrGroupWithAttrsVo attrsVo = new AttrGroupWithAttrsVo();
            BeanUtils.copyProperties(item, attrsVo);
            //2.查询分组关联的属性
            List<AttrEntity> attrs = attrService.getRelationAttr(attrsVo.getAttrGroupId());
            attrsVo.setAttrs(attrs);
            return attrsVo;
        }).collect(Collectors.toList());
        return collect;
    }

3.测试商品发布功能

  • 基本信息
    在这里插入图片描述
  • 销售属性
    在这里插入图片描述
  • sku信息
    在这里插入图片描述
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

随意石光

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值