✨ 三级菜单接口
This commit is contained in:
parent
f812c50f04
commit
9dfa357071
|
@ -27,5 +27,7 @@ target/
|
|||
/.nb-gradle/
|
||||
build/
|
||||
|
||||
node_modules
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
|
|
@ -18,3 +18,9 @@ spring:
|
|||
uri: https://qq.com
|
||||
predicates:
|
||||
- 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;
|
||||
|
||||
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.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
|
||||
@RequestMapping("product/pmscategory")
|
||||
@RequiredArgsConstructor
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 信息
|
||||
*/
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package com.xunqi.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;
|
||||
|
||||
/**
|
||||
* 商品三级分类
|
||||
|
@ -57,4 +58,6 @@ public class PmsCategoryEntity implements Serializable {
|
|||
*/
|
||||
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.gulimall.product.entity.PmsCategoryEntity;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
@ -16,5 +17,12 @@ import java.util.Map;
|
|||
public interface PmsCategoryService extends IService<PmsCategoryEntity> {
|
||||
|
||||
PageUtils queryPage(Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 查询所有分类以及子分类,以树形结构展示
|
||||
*
|
||||
* @return 分类列表
|
||||
*/
|
||||
List<PmsCategoryEntity> listWithTree();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,16 +1,20 @@
|
|||
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.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xunqi.common.utils.PageUtils;
|
||||
import com.xunqi.common.utils.Query;
|
||||
|
||||
import com.xunqi.gulimall.product.dao.PmsCategoryDao;
|
||||
import com.xunqi.gulimall.product.entity.PmsCategoryEntity;
|
||||
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")
|
||||
|
@ -18,12 +22,40 @@ public class PmsCategoryServiceImpl extends ServiceImpl<PmsCategoryDao, PmsCateg
|
|||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String, Object> params) {
|
||||
IPage<PmsCategoryEntity> page = this.page(
|
||||
IPage<PmsCategoryEntity> page = page(
|
||||
new Query<PmsCategoryEntity>().getPage(params),
|
||||
new QueryWrapper<PmsCategoryEntity>()
|
||||
new QueryWrapper<>()
|
||||
);
|
||||
|
||||
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:
|
||||
datasource:
|
||||
username: root
|
||||
password: "123456"
|
||||
url: jdbc:mysql://192.168.95.40:3306/gulimall_pms?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true
|
||||
username: gulimall
|
||||
password: 0212Gulimall
|
||||
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
|
||||
# cloud:
|
||||
# nacos:
|
||||
# discovery:
|
||||
# server-addr: 127.0.0.1:8848
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: 192.168.95.40:8848
|
||||
jackson:
|
||||
date-format: yyyy-MM-dd HH:mm:ss
|
||||
|
||||
|
|
|
@ -3,9 +3,9 @@ spring:
|
|||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
druid:
|
||||
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
|
||||
username: root
|
||||
password: root
|
||||
url: jdbc:mysql://rm-bp12z6hlv46vi6g8mro.mysql.rds.aliyuncs.com:3306/gulimall_admin?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
|
||||
username: gulimall
|
||||
password: 0212Gulimall
|
||||
initial-size: 10
|
||||
max-active: 100
|
||||
min-idle: 10
|
||||
|
|
|
@ -3,9 +3,9 @@ spring:
|
|||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
druid:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306/renren_fast?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
|
||||
username: renren
|
||||
password: 123456
|
||||
url: jdbc:mysql://rm-bp12z6hlv46vi6g8mro.mysql.rds.aliyuncs.com:3306/renren_fast?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
|
||||
username: gulimall
|
||||
password: 0212Gulimall
|
||||
initial-size: 10
|
||||
max-active: 100
|
||||
min-idle: 10
|
||||
|
|
|
@ -3,9 +3,9 @@ spring:
|
|||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
druid:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306/renren_fast?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
|
||||
username: renren
|
||||
password: 123456
|
||||
url: jdbc:mysql://rm-bp12z6hlv46vi6g8mro.mysql.rds.aliyuncs.com:3306/renren_fast?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
|
||||
username: gulimall
|
||||
password: 0212Gulimall
|
||||
initial-size: 10
|
||||
max-active: 100
|
||||
min-idle: 10
|
||||
|
|
|
@ -10,6 +10,8 @@ server:
|
|||
context-path: /renren-fast
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: renren-fast
|
||||
# 环境 dev|test|prod
|
||||
profiles:
|
||||
active: dev
|
||||
|
@ -37,12 +39,10 @@ spring:
|
|||
min-idle: 5 # 连接池中的最小空闲连接
|
||||
mvc:
|
||||
throw-exception-if-no-handler-found: true
|
||||
application:
|
||||
name: renren-fast
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: 127.0.0.1:8848
|
||||
server-addr: 192.168.95.40:8848
|
||||
# resources:
|
||||
# add-mappings: false
|
||||
|
||||
|
|
Loading…
Reference in New Issue