三级菜单接口

This commit is contained in:
bunny 2025-07-04 00:31:16 +08:00
parent f812c50f04
commit 9dfa357071
12 changed files with 246 additions and 188 deletions

2
.gitignore vendored
View File

@ -27,5 +27,7 @@ target/
/.nb-gradle/ /.nb-gradle/
build/ build/
node_modules
### VS Code ### ### VS Code ###
.vscode/ .vscode/

View File

@ -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}

View File

@ -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,28 +21,39 @@ 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);
}
/** /**
* 列表 * 列表
*/ */
@RequestMapping("/list") @RequestMapping("/list")
//@RequiresPermissions("product:pmscategory:list") //@RequiresPermissions("product:pmscategory:list")
public R list(@RequestParam Map<String, Object> params){ public R list(@RequestParam Map<String, Object> params) {
PageUtils page = pmsCategoryService.queryPage(params); PageUtils page = pmsCategoryService.queryPage(params);
return R.ok().put("page", page); return R.ok().put("page", page);
} }
/** /**
* 信息 * 信息
*/ */
@RequestMapping("/info/{catId}") @RequestMapping("/info/{catId}")
//@RequiresPermissions("product:pmscategory:info") //@RequiresPermissions("product:pmscategory:info")
public R info(@PathVariable("catId") Long catId){ public R info(@PathVariable("catId") Long catId) {
PmsCategoryEntity pmsCategory = pmsCategoryService.getById(catId); PmsCategoryEntity pmsCategory = pmsCategoryService.getById(catId);
return R.ok().put("pmsCategory", pmsCategory); return R.ok().put("pmsCategory", pmsCategory);
@ -58,7 +64,7 @@ public class PmsCategoryController {
*/ */
@RequestMapping("/save") @RequestMapping("/save")
//@RequiresPermissions("product:pmscategory:save") //@RequiresPermissions("product:pmscategory:save")
public R save(@RequestBody PmsCategoryEntity pmsCategory){ public R save(@RequestBody PmsCategoryEntity pmsCategory) {
pmsCategoryService.save(pmsCategory); pmsCategoryService.save(pmsCategory);
return R.ok(); return R.ok();
@ -69,7 +75,7 @@ public class PmsCategoryController {
*/ */
@RequestMapping("/update") @RequestMapping("/update")
//@RequiresPermissions("product:pmscategory:update") //@RequiresPermissions("product:pmscategory:update")
public R update(@RequestBody PmsCategoryEntity pmsCategory){ public R update(@RequestBody PmsCategoryEntity pmsCategory) {
pmsCategoryService.updateById(pmsCategory); pmsCategoryService.updateById(pmsCategory);
return R.ok(); return R.ok();
@ -80,7 +86,7 @@ public class PmsCategoryController {
*/ */
@RequestMapping("/delete") @RequestMapping("/delete")
//@RequiresPermissions("product:pmscategory:delete") //@RequiresPermissions("product:pmscategory:delete")
public R delete(@RequestBody Long[] catIds){ public R delete(@RequestBody Long[] catIds) {
pmsCategoryService.removeByIds(Arrays.asList(catIds)); pmsCategoryService.removeByIds(Arrays.asList(catIds));
return R.ok(); return R.ok();

View File

@ -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;
} }

View File

@ -0,0 +1 @@
package com.xunqi.gulimall.product.feign;

View File

@ -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();
} }

View File

@ -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;
}
} }

View File

@ -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

View File

@ -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
@ -14,16 +14,16 @@ spring:
max-pool-prepared-statement-per-connection-size: 20 max-pool-prepared-statement-per-connection-size: 20
time-between-eviction-runs-millis: 60000 time-between-eviction-runs-millis: 60000
min-evictable-idle-time-millis: 300000 min-evictable-idle-time-millis: 300000
#Oracle需要打开注释 # Oracle需要打开注释
#validation-query: SELECT 1 FROM DUAL # validation-query: SELECT 1 FROM DUAL
test-while-idle: true test-while-idle: true
test-on-borrow: false test-on-borrow: false
test-on-return: false test-on-return: false
stat-view-servlet: stat-view-servlet:
enabled: true enabled: true
url-pattern: /druid/* url-pattern: /druid/*
#login-username: admin # login-username: admin
#login-password: admin # login-password: admin
filter: filter:
stat: stat:
log-slow-sql: true log-slow-sql: true
@ -35,7 +35,7 @@ spring:
##多数据源的配置 ##多数据源的配置
#dynamic: # dynamic:
# datasource: # datasource:
# slave1: # slave1:
# driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver # driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver

View File

@ -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
@ -14,16 +14,16 @@ spring:
max-pool-prepared-statement-per-connection-size: 20 max-pool-prepared-statement-per-connection-size: 20
time-between-eviction-runs-millis: 60000 time-between-eviction-runs-millis: 60000
min-evictable-idle-time-millis: 300000 min-evictable-idle-time-millis: 300000
#Oracle需要打开注释 # Oracle需要打开注释
#validation-query: SELECT 1 FROM DUAL # validation-query: SELECT 1 FROM DUAL
test-while-idle: true test-while-idle: true
test-on-borrow: false test-on-borrow: false
test-on-return: false test-on-return: false
stat-view-servlet: stat-view-servlet:
enabled: true enabled: true
url-pattern: /druid/* url-pattern: /druid/*
#login-username: admin # login-username: admin
#login-password: admin # login-password: admin
filter: filter:
stat: stat:
log-slow-sql: true log-slow-sql: true
@ -35,7 +35,7 @@ spring:
##多数据源的配置 ##多数据源的配置
#dynamic: # dynamic:
# datasource: # datasource:
# slave1: # slave1:
# driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver # driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver

View File

@ -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
@ -14,16 +14,16 @@ spring:
max-pool-prepared-statement-per-connection-size: 20 max-pool-prepared-statement-per-connection-size: 20
time-between-eviction-runs-millis: 60000 time-between-eviction-runs-millis: 60000
min-evictable-idle-time-millis: 300000 min-evictable-idle-time-millis: 300000
#Oracle需要打开注释 # Oracle需要打开注释
#validation-query: SELECT 1 FROM DUAL # validation-query: SELECT 1 FROM DUAL
test-while-idle: true test-while-idle: true
test-on-borrow: false test-on-borrow: false
test-on-return: false test-on-return: false
stat-view-servlet: stat-view-servlet:
enabled: true enabled: true
url-pattern: /druid/* url-pattern: /druid/*
#login-username: admin # login-username: admin
#login-password: admin # login-password: admin
filter: filter:
stat: stat:
log-slow-sql: true log-slow-sql: true
@ -35,7 +35,7 @@ spring:
##多数据源的配置 ##多数据源的配置
#dynamic: # dynamic:
# datasource: # datasource:
# slave1: # slave1:
# driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver # driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver

View File

@ -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,30 +39,28 @@ 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
#mybatis # mybatis
mybatis-plus: mybatis-plus:
mapper-locations: classpath*:/mapper/**/*.xml mapper-locations: classpath*:/mapper/**/*.xml
#实体扫描多个package用逗号或者分号分隔 # 实体扫描多个package用逗号或者分号分隔
typeAliasesPackage: io.renren.modules.*.entity typeAliasesPackage: io.renren.modules.*.entity
global-config: global-config:
#数据库相关配置 # 数据库相关配置
db-config: db-config:
#主键类型 AUTO:"数据库ID自增", INPUT:"用户输入ID", ID_WORKER:"全局唯一ID (数字类型唯一ID)", UUID:"全局唯一ID UUID"; # 主键类型 AUTO:"数据库ID自增", INPUT:"用户输入ID", ID_WORKER:"全局唯一ID (数字类型唯一ID)", UUID:"全局唯一ID UUID";
id-type: AUTO id-type: AUTO
logic-delete-value: -1 logic-delete-value: -1
logic-not-delete-value: 0 logic-not-delete-value: 0
banner: false banner: false
#原生配置 # 原生配置
configuration: configuration:
map-underscore-to-camel-case: true map-underscore-to-camel-case: true
cache-enabled: false cache-enabled: false