Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ spring:
uri: https://www.mozilla.org/en-US/firefox/new/
predicates:
- Query=url,fox,fire
# https://youtu.be/QngyGaQXxz4?t=981
- id: admin_route
uri: lb://renren-fast
predicates:
- Path=/api/** # for any FE request, use "api" prefix
filters: # overwrite request path : https://cloud.spring.io/spring-cloud-gateway/reference/html/#global-filters
- RewritePath=/api/(?<segment>/?.*), /renren-fast/$\{segment}

application:
name: gulimall-gateway

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package com.yen.gulimall.product.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.yen.gulimall.product.entity.CategoryEntity;
import com.yen.gulimall.product.service.CategoryService;
import com.yen.gulimall.common.utils.PageUtils;
import com.yen.gulimall.common.utils.R;

// https://youtu.be/5aWkhC7plsc?t=190


/**
Expand All @@ -33,13 +33,18 @@ public class CategoryController {

/**
* 列表
*
* query all categories and their sub categories,
* then return as tree structure:
* - https://youtu.be/5aWkhC7plsc?t=190
*/
@RequestMapping("/list")
@RequestMapping("/list/tree")
//@RequiresPermissions("product:category:list")
public R list(@RequestParam Map<String, Object> params){
PageUtils page = categoryService.queryPage(params);
public R list(){

return R.ok().put("page", page);
//List<CategoryEntity> list = categoryService.list();
List<CategoryEntity> entities = categoryService.listWithTree();
return R.ok().put("data", entities);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,60 +1,63 @@
package com.yen.gulimall.product.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;
import lombok.Data;
import java.util.List;

/**
*
*
* @author yen
* @email [email protected]
* @date 2023-02-01 08:23:29
*/
@Data
@TableName("pms_category")
public class CategoryEntity implements Serializable {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;

/**
* 分类id
*/
@TableId
private Long catId;
/**
* 分类名称
*/
private String name;
/**
* 父分类id
*/
private Long parentCid;
/**
* 层级
*/
private Integer catLevel;
/**
* 是否显示[0-不显示,1显示]
*/
private Integer showStatus;
/**
* 排序
*/
private Integer sort;
/**
* 图标地址
*/
private String icon;
/**
* 计量单位
*/
private String productUnit;
/**
* 商品数量
*/
private Integer productCount;

/**
* 分类id
*/
@TableId
private Long catId;
/**
* 分类名称
*/
private String name;
/**
* 父分类id
*/
private Long parentCid;
/**
* 层级
*/
private Integer catLevel;
/**
* 是否显示[0-不显示,1显示]
*/
private Integer showStatus;
/**
* 排序
*/
private Integer sort;
/**
* 图标地址
*/
private String icon;
/**
* 计量单位
*/
private String productUnit;
/**
* 商品数量
*/
private Integer productCount;
@TableField(exist = false)
// https://youtu.be/5aWkhC7plsc?t=646
private List<CategoryEntity> children;

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.yen.gulimall.common.utils.PageUtils;
import com.yen.gulimall.product.entity.CategoryEntity;

import java.util.List;
import java.util.Map;

/**
Expand All @@ -16,5 +17,7 @@
public interface CategoryService extends IService<CategoryEntity> {

PageUtils queryPage(Map<String, Object> params);

List<CategoryEntity> listWithTree();
}

Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
package com.yen.gulimall.product.service.impl;

import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yen.gulimall.common.utils.PageUtils;
import com.yen.gulimall.common.utils.Query;

import com.yen.gulimall.product.dao.CategoryDao;
import com.yen.gulimall.product.entity.CategoryEntity;
import com.yen.gulimall.product.service.CategoryService;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

// https://youtu.be/5aWkhC7plsc?t=283

@Service("categoryService")
public class CategoryServiceImpl extends ServiceImpl<CategoryDao, CategoryEntity> implements CategoryService {

// since CategoryDao extends from BaseMapper, so we can use BaseMapper below instead for querying data
// (public interface CategoryDao extends BaseMapper<CategoryEntity>)
//@Autowired
//CategoryDao categoryDao;

@Override
public PageUtils queryPage(Map<String, Object> params) {
IPage<CategoryEntity> page = this.page(
Expand All @@ -26,4 +33,52 @@ public PageUtils queryPage(Map<String, Object> params) {
return new PageUtils(page);
}

/**
* method :
* - query all categories and their sub categories, then return as tree structure
*/
@Override
public List<CategoryEntity> listWithTree() {

// step 1) get all categories
List<CategoryEntity> entities = baseMapper.selectList(null); //NOTE : no query condition (selectList(null)) -> query all data
System.out.println(">>> entities = " + entities);

// step 2) wrap as parent-child tree structure
// step 2-1) get all layer 1 categories
List<CategoryEntity> levelOneEntities = entities.stream()
// ParentCid == 0 : layer 1 categories
.filter(categoryEntity -> {
return categoryEntity.getParentCid() == 0;
}).map(menu -> {
// call private method below
menu.setChildren(getChildren(menu, entities));
return menu;
}).sorted((menu1, menu2) -> {
return menu1.getSort() - menu2.getSort();
}).collect(Collectors.toList());

return levelOneEntities;
}

// local helper method
// recursive get all Children from current CategoryEntity : https://youtu.be/5aWkhC7plsc?t=1010
private List<CategoryEntity> getChildren(CategoryEntity root, List<CategoryEntity> all) {

List<CategoryEntity> children = all.stream().filter(categoryEntity -> {
return categoryEntity.getParentCid() == root.getCatId();
}).map(categoryEntity -> {
// NOTE!!! we call getChildren again below (recursive)
categoryEntity.setChildren(getChildren(categoryEntity, all));
return categoryEntity;
})
.sorted((menu1, menu2) -> {
// handle if menu is null (avoid null pointer error)
return (menu1.getSort() == null ? 0 : menu1.getSort()) - (menu2.getSort() == null ? 0 : menu2.getSort());
})
.collect(Collectors.toList());

return children;
}

}
10 changes: 5 additions & 5 deletions springEcommerceGuli/backend/EcommerceGuli/renren-fast/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@

<dependencies>

<!-- <dependency>-->
<!-- <groupId>com.atguigu.gulimall</groupId>-->
<!-- <artifactId>gulimall-common</artifactId>-->
<!-- <version>0.0.1-SNAPSHOT</version>-->
<!-- </dependency>-->
<dependency>
<groupId>com.yen</groupId>
<artifactId>gulimall-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>com.google.code.gson</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;


@EnableDiscoveryClient
@SpringBootApplication
public class RenrenApplication {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ server:
context-path: /renren-fast

spring:
# https://youtu.be/QngyGaQXxz4?t=857
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
application:
name: renren-fast

# 环境 dev|test|prod
profiles:
active: dev # default env is dev
Expand Down
5 changes: 3 additions & 2 deletions springEcommerceGuli/backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ java -jar <built_jar>

| API | Type | Purpose | Example cmd | Comment|
| ----- | -------- | ---- | ----- | ---- |
| Admin backend | GET | http://localhost:8080/renren-fast/ | |

| Admin backend | GET | http://localhost:8080/renren-fast/ | | run this backend first, then run Admin frontend
| login test | GET | http://localhost:8080/renren-fast/captcha.jpg | |

| API | Type | Purpose | Example cmd | Comment|
| ----- | -------- | ---- | ----- | ---- |
Expand All @@ -99,6 +99,7 @@ java -jar <built_jar>
| API | Type | Purpose | Example cmd | Comment|
| ----- | -------- | ---- | ----- | ---- |
| Product list | GET | http://localhost:10000/product/attrattrgrouprelation/list | |
| Product tree list | GET | http://localhost:10000/product/category/list/tree | |


| API | Type | Purpose | Example cmd | Comment|
Expand Down
2 changes: 2 additions & 0 deletions springEcommerceGuli/frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@ brew install [email protected]
## Run

## Ref
- FE src code ref:
- https://github.com/yennanliu/SpringPlayground/tree/main/courses/%E8%B0%B7%E7%B2%92%E5%95%86%E5%9F%8E_%E5%85%A8%E6%A3%A7%E9%96%8B%E7%99%BC_src_code/docs/%E4%BB%A3%E7%A0%81/%E5%89%8D%E7%AB%AF/modules
- Install node with different version on macbook M1
- https://juejin.cn/post/7002566911456182303
Loading