【雷丰阳-谷粒商城 】【分布式基础篇-全栈开发篇】【06】【商品服务】接口文档地址_三级分类_SPU_SKU


持续学习&持续更新中...

学习态度:守破离


【雷丰阳-谷粒商城 】【分布式基础篇-全栈开发篇】【06】【商品服务】接口文档地址_三级分类_SPU_SKU

接口文档地址

可以按照接口的规范来开发其他剩余的功能。

https://easydoc.net/s/78237135/ZUqEdvA4/hKJTcbfd

三级分类

效果图

建表

sql 复制代码
create table if not exists gulimall_pms.pms_category
(
    cat_id        bigint auto_increment comment '分类id'
        primary key,
    name          char(50)  null comment '分类名称',
    parent_cid    bigint    null comment '父分类id',
    cat_level     int       null comment '层级',
    show_status   tinyint   null comment '是否显示[0-不显示,1显示]',
    sort          int       null comment '排序',
    icon          char(255) null comment '图标地址',
    product_unit  char(50)  null comment '计量单位',
    product_count int       null comment '商品数量'
)
    comment '商品三级分类';

后台组建数据的树形结构

java 复制代码
@Service("categoryService")
public class CategoryServiceImpl extends ServiceImpl<CategoryDao, CategoryEntity> implements CategoryService {

    // ......

    @Override
    public List<CategoryEntity> listTree() {
        // 查出所有分类
        List<CategoryEntity> entities = baseMapper.selectList(null);

        /// 组装父子结构:

        // 查出一级分类
        List<CategoryEntity> level1 = entities.stream()
                .filter(entity -> entity.getParentCid() == 0)
                .map(entity -> {
                    entity.setChildren(getChildren(entity, entities));
                    return entity;
                })
                // 0 是排序的默认值
                .sorted((menu1, menu2) -> (menu1.getSort() == null ? 0 : menu1.getSort()) - (menu2.getSort() == null ? 0 : menu2.getSort()))
                .collect(Collectors.toList());
        return level1;
    }

    // 递归查找所有子分类
    private List<CategoryEntity> getChildren(CategoryEntity root, List<CategoryEntity> all) {
        List<CategoryEntity> collect = all.stream()
                .filter(entity -> entity.getParentCid() == root.getCatId())
                .map(entity -> {
                    entity.setChildren(getChildren(entity, all));
                    return entity;
                })
                .sorted((menu1, menu2) -> (menu1.getSort() == null ? 0 : menu1.getSort()) - (menu2.getSort() == null ? 0 : menu2.getSort()))
                .collect(Collectors.toList());
        return collect;
    }

}

在人人(后台管理系统)中实现管理商品的三级分类


路径规则

以角色管理为例:



所以刚才我们给分类维护设置的/product/category,浏览器应该访问http://localhost:8001/#/product-category,对应代码中的src\views\modules\product\category.vue

使用ElementUI构建三级分类

前后端联调

给网关配置路由规则:

yaml 复制代码
spring:
  cloud:
    gateway:
      routes:
#        - id: product_route
#          uri: lb://gulimall-product
#          predicates:
#            - Path=/api/product/**
#          filters:
#            - RewritePath=/api/(?<segment>.*),/$\{segment}
#          #需要把精确的路由放到上面【/api/product/**比/api/**更精确】
        - id: admin_route
          uri: lb://renren-fast
          predicates:
            - Path=/api/**
# 规则:前端项目都带上/api/前缀
#renrenfast代表的是renren-fast的url+port,也就是:localhost:8080
# 默认是这样子转发的 http://localhost:88/api/captcha.jpg  ==》 http://renrenfast/api/captcha.jpg
# 希望这样子转发 http://renrenfast/renren-fast/captcha.jpg
          filters:
            - RewritePath=/api/?(?<segment>.*),/renren-fast/$\{segment}

使用逻辑删除

【MybatisPlus】https://baomidou.com/guides/logic-delete/

局部配置:

全局配置:

注:上图注释的文字应该是:这个方法不推荐直接使用,推荐使用逻辑删除

调整日志级别

复制代码
logging:
  level: 
    com.atguigu.gulimall: debug

SPU与SKU

基本属性【规格参数】与销售属性

  • 基本属性:SPU

商品介绍/规格与包装,这些都是SPU的属性,代表了一类商品

  • 销售属性:SKU

能决定售价与库存的叫做:销售属性

  • 总结

【属性分组-规格参数-销售属性-三级分类】关联关系

SPU-SKU属性表

  • 网络/像素,是商品的基本属性【组成了一个SPU,比如华为V20】
  • 内存/容量,决定商品的价格和库存,是销售属性【组成了一个SKU,比如华为V20(6G+128G版)】

注意

  • nacos中不同命名空间的服务不能直接调用,可以使用其他方法【所以把所有服务都注册到public命名空间下】
  • 每个服务可以设置给自己的配置设置命名空间,做到配置隔离

参考

雷丰阳: Java项目《谷粒商城》Java架构师 | 微服务 | 大型电商项目).


本文完,感谢您的关注支持!


相关推荐
考虑考虑26 分钟前
JDK9中的dropWhile
java·后端·java ee
想躺平的咸鱼干35 分钟前
Volatile解决指令重排和单例模式
java·开发语言·单例模式·线程·并发编程
hqxstudying1 小时前
java依赖注入方法
java·spring·log4j·ioc·依赖
·云扬·1 小时前
【Java源码阅读系列37】深度解读Java BufferedReader 源码
java·开发语言
KellenKellenHao1 小时前
MySQL数据库主从复制
数据库·mysql
Bug退退退1232 小时前
RabbitMQ 高级特性之重试机制
java·分布式·spring·rabbitmq
小皮侠2 小时前
nginx的使用
java·运维·服务器·前端·git·nginx·github
一只fish2 小时前
MySQL 8.0 OCP 1Z0-908 题目解析(16)
数据库·mysql
Zz_waiting.2 小时前
Javaweb - 10.4 ServletConfig 和 ServletContext
java·开发语言·前端·servlet·servletconfig·servletcontext·域对象
全栈凯哥2 小时前
02.SpringBoot常用Utils工具类详解
java·spring boot·后端