✨ 三级菜单接口
This commit is contained in:
parent
f812c50f04
commit
9dfa357071
|
@ -27,5 +27,7 @@ target/
|
||||||
/.nb-gradle/
|
/.nb-gradle/
|
||||||
build/
|
build/
|
||||||
|
|
||||||
|
node_modules
|
||||||
|
|
||||||
### VS Code ###
|
### VS Code ###
|
||||||
.vscode/
|
.vscode/
|
||||||
|
|
|
@ -18,3 +18,9 @@ spring:
|
||||||
uri: https://qq.com
|
uri: https://qq.com
|
||||||
predicates:
|
predicates:
|
||||||
- Query=url,qq
|
- Query=url,qq
|
||||||
|
- id: admin_route
|
||||||
|
uri: lb://renren-fast
|
||||||
|
predicates:
|
||||||
|
- Path=/api/**
|
||||||
|
filters:
|
||||||
|
- RewritePath=/api/(?<segment>.*),/renren-fast/$\{segment}
|
|
@ -1,20 +1,15 @@
|
||||||
package com.xunqi.gulimall.product.controller;
|
package com.xunqi.gulimall.product.controller;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
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.xunqi.gulimall.product.entity.PmsCategoryEntity;
|
|
||||||
import com.xunqi.gulimall.product.service.PmsCategoryService;
|
|
||||||
import com.xunqi.common.utils.PageUtils;
|
import com.xunqi.common.utils.PageUtils;
|
||||||
import com.xunqi.common.utils.R;
|
import com.xunqi.common.utils.R;
|
||||||
|
import com.xunqi.gulimall.product.entity.PmsCategoryEntity;
|
||||||
|
import com.xunqi.gulimall.product.service.PmsCategoryService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,9 +21,21 @@ import com.xunqi.common.utils.R;
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("product/pmscategory")
|
@RequestMapping("product/pmscategory")
|
||||||
|
@RequiredArgsConstructor
|
||||||
public class PmsCategoryController {
|
public class PmsCategoryController {
|
||||||
@Autowired
|
|
||||||
private PmsCategoryService pmsCategoryService;
|
private final PmsCategoryService pmsCategoryService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有分类以及子分类,以树形结构展示
|
||||||
|
*
|
||||||
|
* @return List<PmsCategoryEntity>
|
||||||
|
*/
|
||||||
|
@RequestMapping("list/tree")
|
||||||
|
public R list() {
|
||||||
|
List<PmsCategoryEntity> entities = pmsCategoryService.listWithTree();
|
||||||
|
return R.ok().put("data", entities);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 列表
|
* 列表
|
||||||
|
@ -41,7 +48,6 @@ public class PmsCategoryController {
|
||||||
return R.ok().put("page", page);
|
return R.ok().put("page", page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 信息
|
* 信息
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
package com.xunqi.gulimall.product.entity;
|
package com.xunqi.gulimall.product.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.util.List;
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品三级分类
|
* 商品三级分类
|
||||||
|
@ -57,4 +58,6 @@ public class PmsCategoryEntity implements Serializable {
|
||||||
*/
|
*/
|
||||||
private Integer productCount;
|
private Integer productCount;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private List<PmsCategoryEntity> children;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
package com.xunqi.gulimall.product.feign;
|
|
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.xunqi.common.utils.PageUtils;
|
import com.xunqi.common.utils.PageUtils;
|
||||||
import com.xunqi.gulimall.product.entity.PmsCategoryEntity;
|
import com.xunqi.gulimall.product.entity.PmsCategoryEntity;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,5 +17,12 @@ import java.util.Map;
|
||||||
public interface PmsCategoryService extends IService<PmsCategoryEntity> {
|
public interface PmsCategoryService extends IService<PmsCategoryEntity> {
|
||||||
|
|
||||||
PageUtils queryPage(Map<String, Object> params);
|
PageUtils queryPage(Map<String, Object> params);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有分类以及子分类,以树形结构展示
|
||||||
|
*
|
||||||
|
* @return 分类列表
|
||||||
|
*/
|
||||||
|
List<PmsCategoryEntity> listWithTree();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,20 @@
|
||||||
package com.xunqi.gulimall.product.service.impl;
|
package com.xunqi.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.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.xunqi.common.utils.PageUtils;
|
import com.xunqi.common.utils.PageUtils;
|
||||||
import com.xunqi.common.utils.Query;
|
import com.xunqi.common.utils.Query;
|
||||||
|
|
||||||
import com.xunqi.gulimall.product.dao.PmsCategoryDao;
|
import com.xunqi.gulimall.product.dao.PmsCategoryDao;
|
||||||
import com.xunqi.gulimall.product.entity.PmsCategoryEntity;
|
import com.xunqi.gulimall.product.entity.PmsCategoryEntity;
|
||||||
import com.xunqi.gulimall.product.service.PmsCategoryService;
|
import com.xunqi.gulimall.product.service.PmsCategoryService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
@Service("pmsCategoryService")
|
@Service("pmsCategoryService")
|
||||||
|
@ -18,12 +22,40 @@ public class PmsCategoryServiceImpl extends ServiceImpl<PmsCategoryDao, PmsCateg
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageUtils queryPage(Map<String, Object> params) {
|
public PageUtils queryPage(Map<String, Object> params) {
|
||||||
IPage<PmsCategoryEntity> page = this.page(
|
IPage<PmsCategoryEntity> page = page(
|
||||||
new Query<PmsCategoryEntity>().getPage(params),
|
new Query<PmsCategoryEntity>().getPage(params),
|
||||||
new QueryWrapper<PmsCategoryEntity>()
|
new QueryWrapper<>()
|
||||||
);
|
);
|
||||||
|
|
||||||
return new PageUtils(page);
|
return new PageUtils(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有分类以及子分类,以树形结构展示
|
||||||
|
*
|
||||||
|
* @return 分类列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<PmsCategoryEntity> listWithTree() {
|
||||||
|
// 查询所有的分类
|
||||||
|
List<PmsCategoryEntity> list = list();
|
||||||
|
return list.stream()
|
||||||
|
.filter(entity -> entity.getParentCid().equals(0L))
|
||||||
|
.peek(entity -> entity.setChildren(getChildren(entity, list)))
|
||||||
|
.sorted(Comparator.comparingInt(PmsCategoryEntity::getSort))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<PmsCategoryEntity> getChildren(PmsCategoryEntity entity, List<PmsCategoryEntity> list) {
|
||||||
|
List<PmsCategoryEntity> voList = new ArrayList<>();
|
||||||
|
|
||||||
|
for (PmsCategoryEntity category : list) {
|
||||||
|
if (entity.getParentCid().equals(category.getParentCid())) {
|
||||||
|
voList.add(category);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return voList;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -3,14 +3,14 @@ server:
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
datasource:
|
datasource:
|
||||||
username: root
|
username: gulimall
|
||||||
password: "123456"
|
password: 0212Gulimall
|
||||||
url: jdbc:mysql://192.168.95.40:3306/gulimall_pms?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true
|
url: jdbc:mysql://rm-bp12z6hlv46vi6g8mro.mysql.rds.aliyuncs.com:3306/gulimall_pms?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
# cloud:
|
cloud:
|
||||||
# nacos:
|
nacos:
|
||||||
# discovery:
|
discovery:
|
||||||
# server-addr: 127.0.0.1:8848
|
server-addr: 192.168.95.40:8848
|
||||||
jackson:
|
jackson:
|
||||||
date-format: yyyy-MM-dd HH:mm:ss
|
date-format: yyyy-MM-dd HH:mm:ss
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,9 @@ spring:
|
||||||
type: com.alibaba.druid.pool.DruidDataSource
|
type: com.alibaba.druid.pool.DruidDataSource
|
||||||
druid:
|
druid:
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
url: jdbc:mysql://192.168.56.10:3306/gulimall_admin?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
|
url: jdbc:mysql://rm-bp12z6hlv46vi6g8mro.mysql.rds.aliyuncs.com:3306/gulimall_admin?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
|
||||||
username: root
|
username: gulimall
|
||||||
password: root
|
password: 0212Gulimall
|
||||||
initial-size: 10
|
initial-size: 10
|
||||||
max-active: 100
|
max-active: 100
|
||||||
min-idle: 10
|
min-idle: 10
|
||||||
|
|
|
@ -3,9 +3,9 @@ spring:
|
||||||
type: com.alibaba.druid.pool.DruidDataSource
|
type: com.alibaba.druid.pool.DruidDataSource
|
||||||
druid:
|
druid:
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
url: jdbc:mysql://localhost:3306/renren_fast?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
|
url: jdbc:mysql://rm-bp12z6hlv46vi6g8mro.mysql.rds.aliyuncs.com:3306/renren_fast?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
|
||||||
username: renren
|
username: gulimall
|
||||||
password: 123456
|
password: 0212Gulimall
|
||||||
initial-size: 10
|
initial-size: 10
|
||||||
max-active: 100
|
max-active: 100
|
||||||
min-idle: 10
|
min-idle: 10
|
||||||
|
|
|
@ -3,9 +3,9 @@ spring:
|
||||||
type: com.alibaba.druid.pool.DruidDataSource
|
type: com.alibaba.druid.pool.DruidDataSource
|
||||||
druid:
|
druid:
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
url: jdbc:mysql://localhost:3306/renren_fast?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
|
url: jdbc:mysql://rm-bp12z6hlv46vi6g8mro.mysql.rds.aliyuncs.com:3306/renren_fast?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
|
||||||
username: renren
|
username: gulimall
|
||||||
password: 123456
|
password: 0212Gulimall
|
||||||
initial-size: 10
|
initial-size: 10
|
||||||
max-active: 100
|
max-active: 100
|
||||||
min-idle: 10
|
min-idle: 10
|
||||||
|
|
|
@ -10,6 +10,8 @@ server:
|
||||||
context-path: /renren-fast
|
context-path: /renren-fast
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
|
application:
|
||||||
|
name: renren-fast
|
||||||
# 环境 dev|test|prod
|
# 环境 dev|test|prod
|
||||||
profiles:
|
profiles:
|
||||||
active: dev
|
active: dev
|
||||||
|
@ -37,12 +39,10 @@ spring:
|
||||||
min-idle: 5 # 连接池中的最小空闲连接
|
min-idle: 5 # 连接池中的最小空闲连接
|
||||||
mvc:
|
mvc:
|
||||||
throw-exception-if-no-handler-found: true
|
throw-exception-if-no-handler-found: true
|
||||||
application:
|
|
||||||
name: renren-fast
|
|
||||||
cloud:
|
cloud:
|
||||||
nacos:
|
nacos:
|
||||||
discovery:
|
discovery:
|
||||||
server-addr: 127.0.0.1:8848
|
server-addr: 192.168.95.40:8848
|
||||||
# resources:
|
# resources:
|
||||||
# add-mappings: false
|
# add-mappings: false
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue