feat(system): 优化动态表格功能并添加查询搜索支持
- 在SystemQueryMenuArgs中添加模糊查询注解支持 - 重构KitDynamicTableResponse类为泛型实现,支持更灵活的数据类型 - 新增KitDynamicTableUtil工具类提供排序和查询条件构建功能 - 添加多种查询方式的API接口实现
This commit is contained in:
@@ -8,5 +8,13 @@ export function searchMenu(query) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export default { searchMenu }
|
export function searchMenu2(query) {
|
||||||
|
return request({
|
||||||
|
url: 'api/features/CuteDynamicTable/searchMenu2',
|
||||||
|
method: 'post',
|
||||||
|
data: query
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export default { searchMenu, searchMenu2 }
|
||||||
|
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
fetch: async(queryParams) => {
|
fetch: async(queryParams) => {
|
||||||
return FeatureCuteDynamicTableService.searchMenu(queryParams)
|
return FeatureCuteDynamicTableService.searchMenu2(queryParams)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
apiData: [
|
apiData: [
|
||||||
|
|||||||
+3
@@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package cn.odboy.system.dal.model.request;
|
package cn.odboy.system.dal.model.request;
|
||||||
|
|
||||||
|
import cn.odboy.framework.mybatisplus.config.KitMpQTypeEnum;
|
||||||
|
import cn.odboy.framework.mybatisplus.config.KitMpQuery;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -24,6 +26,7 @@ import lombok.Data;
|
|||||||
public class SystemQueryMenuArgs {
|
public class SystemQueryMenuArgs {
|
||||||
|
|
||||||
@ApiModelProperty(value = "模糊查询")
|
@ApiModelProperty(value = "模糊查询")
|
||||||
|
@KitMpQuery(type = KitMpQTypeEnum.INNER_LIKE)
|
||||||
private String blurry;
|
private String blurry;
|
||||||
@ApiModelProperty(value = "创建时间")
|
@ApiModelProperty(value = "创建时间")
|
||||||
private List<Date> createTime;
|
private List<Date> createTime;
|
||||||
|
|||||||
+31
-3
@@ -17,11 +17,13 @@ package cn.odboy.system.features;
|
|||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.odboy.base.KitPageArgs;
|
import cn.odboy.base.KitPageArgs;
|
||||||
|
import cn.odboy.framework.mybatisplus.core.KitMpQUtil;
|
||||||
import cn.odboy.system.features.core.KitDynamicTableResponse;
|
import cn.odboy.system.features.core.KitDynamicTableResponse;
|
||||||
import cn.odboy.system.features.model.SystemMenuDynamicTableModel;
|
import cn.odboy.system.features.model.SystemMenuDynamicTableModel;
|
||||||
import cn.odboy.system.dal.dataobject.SystemMenuTb;
|
import cn.odboy.system.dal.dataobject.SystemMenuTb;
|
||||||
import cn.odboy.system.dal.model.request.SystemQueryMenuArgs;
|
import cn.odboy.system.dal.model.request.SystemQueryMenuArgs;
|
||||||
import cn.odboy.system.dal.mysql.SystemMenuMapper;
|
import cn.odboy.system.dal.mysql.SystemMenuMapper;
|
||||||
|
import cn.odboy.system.features.util.KitDynamicTableUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
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;
|
||||||
@@ -45,10 +47,10 @@ public class CuteDynamicTableDemoApi {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private SystemMenuMapper systemMenuMapper;
|
private SystemMenuMapper systemMenuMapper;
|
||||||
|
|
||||||
@ApiOperation("查询动态数据")
|
@ApiOperation("写法1:查询动态数据")
|
||||||
@PostMapping(value = "/searchMenu")
|
@PostMapping(value = "/searchMenu")
|
||||||
@PreAuthorize("@el.check()")
|
@PreAuthorize("@el.check()")
|
||||||
public ResponseEntity<KitDynamicTableResponse<SystemMenuDynamicTableModel>> searchMenu(@Validated @RequestBody KitPageArgs<SystemQueryMenuArgs> pageArgs) {
|
public ResponseEntity<KitDynamicTableResponse<SystemMenuTb, SystemMenuDynamicTableModel>> searchMenu(@Validated @RequestBody KitPageArgs<SystemQueryMenuArgs> pageArgs) {
|
||||||
// 请求参数
|
// 请求参数
|
||||||
Integer page = pageArgs.getPage();
|
Integer page = pageArgs.getPage();
|
||||||
Integer size = pageArgs.getSize();
|
Integer size = pageArgs.getSize();
|
||||||
@@ -66,6 +68,32 @@ public class CuteDynamicTableDemoApi {
|
|||||||
}
|
}
|
||||||
IPage<SystemMenuTb> pageResult = systemMenuMapper.selectPage(iPage, wrapper);
|
IPage<SystemMenuTb> pageResult = systemMenuMapper.selectPage(iPage, wrapper);
|
||||||
// 响应结果
|
// 响应结果
|
||||||
return ResponseEntity.ok(new KitDynamicTableResponse<>(SystemMenuDynamicTableModel.class, "id", pageResult));
|
return ResponseEntity.ok(new KitDynamicTableResponse<>(SystemMenuDynamicTableModel.class, pageResult, "id"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("写法2:查询动态数据")
|
||||||
|
@PostMapping(value = "/searchMenu2")
|
||||||
|
@PreAuthorize("@el.check()")
|
||||||
|
public ResponseEntity<KitDynamicTableResponse<SystemMenuTb, SystemMenuDynamicTableModel>> searchMenu2(@Validated @RequestBody KitPageArgs<SystemQueryMenuArgs> pageArgs) {
|
||||||
|
// 渲染排序(非必须)
|
||||||
|
QueryWrapper<SystemMenuTb> wrapper = KitDynamicTableUtil.renderOrder(pageArgs);
|
||||||
|
LambdaQueryWrapper<SystemMenuTb> lambda = wrapper.lambda();
|
||||||
|
// 查询条件
|
||||||
|
SystemQueryMenuArgs args = pageArgs.getArgs();
|
||||||
|
if (args != null) {
|
||||||
|
lambda.like(StrUtil.isNotBlank(args.getBlurry()), SystemMenuTb::getTitle, args.getBlurry());
|
||||||
|
}
|
||||||
|
// 响应结果
|
||||||
|
return ResponseEntity.ok(new KitDynamicTableResponse<>(SystemMenuDynamicTableModel.class, pageArgs, "id", systemMenuMapper, lambda));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("写法3:查询动态数据")
|
||||||
|
@PostMapping(value = "/searchMenu3")
|
||||||
|
@PreAuthorize("@el.check()")
|
||||||
|
public ResponseEntity<KitDynamicTableResponse<SystemMenuTb, SystemMenuDynamicTableModel>> searchMenu3(@Validated @RequestBody KitPageArgs<SystemQueryMenuArgs> pageArgs) {
|
||||||
|
// 渲染查询条件
|
||||||
|
LambdaQueryWrapper<SystemMenuTb> wrapper = KitDynamicTableUtil.renderAll(pageArgs);
|
||||||
|
// 响应结果
|
||||||
|
return ResponseEntity.ok(new KitDynamicTableResponse<>(SystemMenuDynamicTableModel.class, pageArgs, "id", systemMenuMapper, wrapper));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+58
-8
@@ -17,9 +17,12 @@ package cn.odboy.system.features.core;
|
|||||||
|
|
||||||
import cn.hutool.core.util.ReflectUtil;
|
import cn.hutool.core.util.ReflectUtil;
|
||||||
import cn.odboy.base.KitObject;
|
import cn.odboy.base.KitObject;
|
||||||
|
import cn.odboy.base.KitPageArgs;
|
||||||
import cn.odboy.system.features.model.SystemMenuDynamicTableModel;
|
import cn.odboy.system.features.model.SystemMenuDynamicTableModel;
|
||||||
import cn.odboy.system.dal.dataobject.SystemMenuTb;
|
import cn.odboy.system.dal.dataobject.SystemMenuTb;
|
||||||
import cn.odboy.util.KitBeanUtil;
|
import cn.odboy.util.KitBeanUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@@ -32,11 +35,13 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* 动态表格
|
* 动态表格
|
||||||
*
|
*
|
||||||
|
* @param <E> 数据表对象
|
||||||
|
* @param <T> 渲染对象
|
||||||
* @author odboy
|
* @author odboy
|
||||||
* @date 2026-02-05
|
* @date 2026-02-05
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
public class KitDynamicTableResponse<T> extends KitObject {
|
public class KitDynamicTableResponse<E, T> extends KitObject {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 主键
|
* 主键
|
||||||
@@ -56,17 +61,57 @@ public class KitDynamicTableResponse<T> extends KitObject {
|
|||||||
*/
|
*/
|
||||||
private List<T> content;
|
private List<T> content;
|
||||||
|
|
||||||
public KitDynamicTableResponse(Class<T> clazz, IPage<SystemMenuTb> pageResult) {
|
/**
|
||||||
|
* @param clazz 渲染类型
|
||||||
|
* @param pageResult 渲染类型分页参数
|
||||||
|
*/
|
||||||
|
public KitDynamicTableResponse(Class<T> clazz, IPage<E> pageResult) {
|
||||||
this.renderColumns(clazz);
|
this.renderColumns(clazz);
|
||||||
this.setPage(clazz, pageResult);
|
this.setContent(clazz, pageResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
public KitDynamicTableResponse(Class<T> clazz, String id, IPage<SystemMenuTb> pageResult) {
|
/**
|
||||||
this.primaryKey = id;
|
* @param clazz 渲染类型
|
||||||
|
* @param pageResult 渲染类型分页参数
|
||||||
|
* @param primaryKey 主键
|
||||||
|
*/
|
||||||
|
public KitDynamicTableResponse(Class<T> clazz, IPage<E> pageResult, String primaryKey) {
|
||||||
|
this.primaryKey = primaryKey;
|
||||||
this.renderColumns(clazz);
|
this.renderColumns(clazz);
|
||||||
this.setPage(clazz, pageResult);
|
this.setContent(clazz, pageResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param clazz 渲染类型
|
||||||
|
* @param pageArgs 分页参数
|
||||||
|
* @param baseMapper 数据表Mapper
|
||||||
|
* @param wrapper 查询条件
|
||||||
|
*/
|
||||||
|
public KitDynamicTableResponse(Class<T> clazz, KitPageArgs<?> pageArgs, BaseMapper<E> baseMapper, LambdaQueryWrapper<E> wrapper) {
|
||||||
|
this.renderColumns(clazz);
|
||||||
|
Page<?> pageResult = baseMapper.selectPage(new Page<>(pageArgs.getPage(), pageArgs.getSize()), wrapper);
|
||||||
|
this.setContent(clazz, pageResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param clazz 渲染类型
|
||||||
|
* @param pageArgs 分页参数
|
||||||
|
* @param primaryKey 主键
|
||||||
|
* @param baseMapper 数据表Mapper
|
||||||
|
* @param wrapper 查询条件
|
||||||
|
*/
|
||||||
|
public KitDynamicTableResponse(Class<T> clazz, KitPageArgs<?> pageArgs, String primaryKey, BaseMapper<E> baseMapper, LambdaQueryWrapper<E> wrapper) {
|
||||||
|
this.primaryKey = primaryKey;
|
||||||
|
this.renderColumns(clazz);
|
||||||
|
Page<?> pageResult = baseMapper.selectPage(new Page<>(pageArgs.getPage(), pageArgs.getSize()), wrapper);
|
||||||
|
this.setContent(clazz, pageResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 渲染表格列
|
||||||
|
*
|
||||||
|
* @param clazz 渲染类型
|
||||||
|
*/
|
||||||
private void renderColumns(Class<T> clazz) {
|
private void renderColumns(Class<T> clazz) {
|
||||||
List<Column> columns = new ArrayList<>();
|
List<Column> columns = new ArrayList<>();
|
||||||
if (clazz == null) {
|
if (clazz == null) {
|
||||||
@@ -94,7 +139,11 @@ public class KitDynamicTableResponse<T> extends KitObject {
|
|||||||
this.columns = columns;
|
this.columns = columns;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPage(Class<T> clazz, IPage<SystemMenuTb> pageResult) {
|
/**
|
||||||
|
* @param clazz 渲染类型
|
||||||
|
* @param pageResult 渲染结果
|
||||||
|
*/
|
||||||
|
public void setContent(Class<T> clazz, IPage<?> pageResult) {
|
||||||
if (pageResult == null) {
|
if (pageResult == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -125,7 +174,8 @@ public class KitDynamicTableResponse<T> extends KitObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
KitDynamicTableResponse<SystemMenuDynamicTableModel> response = new KitDynamicTableResponse<>(SystemMenuDynamicTableModel.class, "id", new Page<>());
|
KitDynamicTableResponse<SystemMenuTb, SystemMenuDynamicTableModel> response = new KitDynamicTableResponse<>(
|
||||||
|
SystemMenuDynamicTableModel.class, new Page<>(), "id");
|
||||||
System.err.println(response);
|
System.err.println(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
@@ -20,6 +20,9 @@ import cn.odboy.system.features.core.KitDynamicTableColumn;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 例子:渲染对象
|
||||||
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
public class SystemMenuDynamicTableModel extends KitObject {
|
public class SystemMenuDynamicTableModel extends KitObject {
|
||||||
|
|||||||
+67
@@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2021-2026 Odboy
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package cn.odboy.system.features.util;
|
||||||
|
|
||||||
|
import cn.odboy.base.KitPageArgs;
|
||||||
|
import cn.odboy.framework.mybatisplus.core.KitMpQUtil;
|
||||||
|
import cn.odboy.system.dal.dataobject.SystemMenuTb;
|
||||||
|
import cn.odboy.system.dal.model.request.SystemQueryMenuArgs;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import lombok.experimental.UtilityClass;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 动态表格辅助工具
|
||||||
|
*
|
||||||
|
* @author odboy
|
||||||
|
*/
|
||||||
|
@UtilityClass
|
||||||
|
public class KitDynamicTableUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 渲染排序规则
|
||||||
|
*
|
||||||
|
* @param pageArgs 分页参数
|
||||||
|
* @param <M> 数据表对象
|
||||||
|
* @param <T> 渲染对象
|
||||||
|
* @return /
|
||||||
|
*/
|
||||||
|
public static <M, T> QueryWrapper<M> renderOrder(KitPageArgs<T> pageArgs) {
|
||||||
|
QueryWrapper<M> wrapper = new QueryWrapper<>();
|
||||||
|
KitPageArgs.OrderBy orderBy = pageArgs.getOrderBy();
|
||||||
|
if (orderBy != null) {
|
||||||
|
wrapper.orderBy(true, orderBy.isAsc(), orderBy.getColumn());
|
||||||
|
}
|
||||||
|
return wrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 渲染所有规则(需要配合 @KitMpQuery 注解使用)
|
||||||
|
*
|
||||||
|
* @param pageArgs 分页参数
|
||||||
|
* @param <M> 数据表对象
|
||||||
|
* @param <T> 渲染对象
|
||||||
|
* @return /
|
||||||
|
*/
|
||||||
|
public static <M, T> LambdaQueryWrapper<M> renderAll(KitPageArgs<T> pageArgs) {
|
||||||
|
QueryWrapper<M> wrapper = KitMpQUtil.build(pageArgs.getArgs());
|
||||||
|
KitPageArgs.OrderBy orderBy = pageArgs.getOrderBy();
|
||||||
|
if (orderBy != null) {
|
||||||
|
wrapper.orderBy(true, orderBy.isAsc(), orderBy.getColumn());
|
||||||
|
}
|
||||||
|
return wrapper.lambda();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user