一:调试会员等级相关接口
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信息
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/84123.html