From 5867f253bfaa0dcb1b09c7d4c2e1ef444a106469 Mon Sep 17 00:00:00 2001 From: Troy Date: Wed, 6 Nov 2024 22:03:21 +0800 Subject: [PATCH 01/17] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20Bean=20Searcher=20?= =?UTF-8?q?=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- maku-framework/pom.xml | 4 ++++ pom.xml | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/maku-framework/pom.xml b/maku-framework/pom.xml index bce670f..d3ce851 100644 --- a/maku-framework/pom.xml +++ b/maku-framework/pom.xml @@ -61,6 +61,10 @@ org.postgresql postgresql + + cn.zhxu + bean-searcher-boot-starter + com.baomidou mybatis-plus-spring-boot3-starter diff --git a/pom.xml b/pom.xml index 117074b..7dce496 100644 --- a/pom.xml +++ b/pom.xml @@ -32,6 +32,7 @@ UTF-8 17 3.5.7 + 4.3.5 4.3.1 3.21.3 2.2.7 @@ -79,6 +80,11 @@ + + cn.zhxu + bean-searcher-boot-starter + ${bean-searcher.version} + com.baomidou mybatis-plus-spring-boot3-starter -- Gitee From bf1a6aecbd835dc087407d6d01121544c6c92bb3 Mon Sep 17 00:00:00 2001 From: Troy Date: Wed, 6 Nov 2024 22:04:54 +0800 Subject: [PATCH 02/17] =?UTF-8?q?=E4=BC=98=E5=8C=96=20Result=20=E7=B1=BB?= =?UTF-8?q?=EF=BC=9A=E6=96=B0=E5=A2=9E=20ok(SearchResult=20res)=20?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/maku/framework/common/utils/Result.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/maku-framework/src/main/java/net/maku/framework/common/utils/Result.java b/maku-framework/src/main/java/net/maku/framework/common/utils/Result.java index f0a4cff..ef9770c 100644 --- a/maku-framework/src/main/java/net/maku/framework/common/utils/Result.java +++ b/maku-framework/src/main/java/net/maku/framework/common/utils/Result.java @@ -1,5 +1,6 @@ package net.maku.framework.common.utils; +import cn.zhxu.bs.SearchResult; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import net.maku.framework.common.exception.ErrorCode; @@ -23,7 +24,9 @@ public class Result { private T data; public static Result ok() { - return ok(null); + Result result = new Result<>(); + result.setData(null); + return result; } public static Result ok(T data) { @@ -32,6 +35,15 @@ public class Result { return result; } + public static Result> ok(SearchResult res) { + Result> result = new Result<>(); + result.setData(new PageResult<>( + res.getDataList(), + res.getTotalCount().intValue() + )); + return result; + } + public static Result error() { return error(ErrorCode.INTERNAL_SERVER_ERROR); } -- Gitee From b5ef2173d02a7d2295c9422b85ad6658c407220a Mon Sep 17 00:00:00 2001 From: Troy Date: Wed, 6 Nov 2024 22:05:12 +0800 Subject: [PATCH 03/17] =?UTF-8?q?=E5=90=AF=E7=94=A8=20Bean=20Searcher=20?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- maku-server/src/main/resources/logback.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/maku-server/src/main/resources/logback.xml b/maku-server/src/main/resources/logback.xml index 533483c..cbea6c3 100644 --- a/maku-server/src/main/resources/logback.xml +++ b/maku-server/src/main/resources/logback.xml @@ -109,5 +109,6 @@ + \ No newline at end of file -- Gitee From 199a84bf2db37a2751f0e86b50f39bcd412ad448 Mon Sep 17 00:00:00 2001 From: Troy Date: Wed, 6 Nov 2024 22:06:42 +0800 Subject: [PATCH 04/17] =?UTF-8?q?=E9=85=8D=E7=BD=AE=20Bean=20Searcher=20?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=8A=A0=E8=BD=BD=E5=BD=93=E5=89=8D=E7=9A=84?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../beansearcher/AutoLoadParamFilter.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 maku-framework/src/main/java/net/maku/framework/beansearcher/AutoLoadParamFilter.java diff --git a/maku-framework/src/main/java/net/maku/framework/beansearcher/AutoLoadParamFilter.java b/maku-framework/src/main/java/net/maku/framework/beansearcher/AutoLoadParamFilter.java new file mode 100644 index 0000000..bfb5b9d --- /dev/null +++ b/maku-framework/src/main/java/net/maku/framework/beansearcher/AutoLoadParamFilter.java @@ -0,0 +1,45 @@ +package net.maku.framework.beansearcher; + +import cn.zhxu.bs.BeanMeta; +import cn.zhxu.bs.ParamFilter; +import cn.zhxu.bs.util.MapBuilder; +import cn.zhxu.bs.util.MapUtils; +import jakarta.servlet.http.HttpServletRequest; +import org.springframework.core.Ordered; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; +import org.springframework.web.context.request.RequestAttributes; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import java.util.Map; + +/** + * 自动加载当前的请求参数 + * @author Troy.Zhou @ 2024-11-06 + */ +@Component +@Order(Ordered.HIGHEST_PRECEDENCE) +public class AutoLoadParamFilter implements ParamFilter { + + // 定义一个常量,作为一个开关,当启用时,则取消自动加载功能 + public static final String IGNORE_REQUEST_PARAMS = "IGNORE_REQUEST_PARAMS"; + + @Override + public Map doFilter(BeanMeta beanMeta, Map paraMap) { + MapBuilder builder; + RequestAttributes attributes = RequestContextHolder.getRequestAttributes(); + if (attributes instanceof ServletRequestAttributes && + !paraMap.containsKey(IGNORE_REQUEST_PARAMS)) { + // 在一个 Web 请求上下文中,并且没有开启 IGNORE_REQUEST_PARAMS,则取出前端传来的所有参数 + HttpServletRequest request = ((ServletRequestAttributes) attributes).getRequest(); + builder = MapUtils.flatBuilder(request.getParameterMap()); + } else { + builder = MapUtils.builder(); + } + // 自定义查询参数,优先级最高,可以覆盖上面的参数 + builder.putAll(paraMap); + return builder.build(); + } + +} -- Gitee From 23d52a76c059dd5863d1db055e856be2f136f843 Mon Sep 17 00:00:00 2001 From: Troy Date: Wed, 6 Nov 2024 22:09:04 +0800 Subject: [PATCH 05/17] =?UTF-8?q?=E9=85=8D=E7=BD=AE=20Bean=20Searcher=20?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=20key[0]=3Dv1=20&=20key[1]=3Dv2=20=E5=BD=A2?= =?UTF-8?q?=E5=BC=8F=E7=9A=84=E5=89=8D=E7=AB=AF=E6=95=B0=E7=BB=84=E5=8F=82?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../beansearcher/IndexArrayParamFilter.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 maku-framework/src/main/java/net/maku/framework/beansearcher/IndexArrayParamFilter.java diff --git a/maku-framework/src/main/java/net/maku/framework/beansearcher/IndexArrayParamFilter.java b/maku-framework/src/main/java/net/maku/framework/beansearcher/IndexArrayParamFilter.java new file mode 100644 index 0000000..6b87675 --- /dev/null +++ b/maku-framework/src/main/java/net/maku/framework/beansearcher/IndexArrayParamFilter.java @@ -0,0 +1,50 @@ +package net.maku.framework.beansearcher; + +import cn.zhxu.bs.BeanMeta; +import cn.zhxu.bs.IllegalParamException; +import cn.zhxu.bs.ParamFilter; +import cn.zhxu.bs.boot.prop.BeanSearcherParams; +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * 下标数组参数过滤器, 用于兼容如下形式的前端数组参数: + * ? key[0]=v1 & key[1]=v2 + * @author Troy.Zhou + */ +@Component +@AllArgsConstructor +public class IndexArrayParamFilter implements ParamFilter { + + static final Pattern KEY_PATTERN = Pattern.compile("([a-zA-Z0-9_]+)\\[([0-9]*)]"); + + private final BeanSearcherParams config; + + @Override + public Map doFilter(BeanMeta beanMeta, Map paraMap) throws IllegalParamException { + Map newMap = null; + for (Map.Entry entry : paraMap.entrySet()) { + String key = entry.getKey(); + Matcher matcher = KEY_PATTERN.matcher(key); + if (!matcher.matches()) { + continue; + } + if (newMap == null) { + newMap = new HashMap<>(); + } + String field = matcher.group(1); + String index = matcher.group(2); + newMap.put(field + config.getSeparator() + index, entry.getValue()); + } + if (newMap != null) { + paraMap.putAll(newMap); + } + return paraMap; + } + +} -- Gitee From 74167d31e32c6e6e3b8b9c1882661eaa2b7e1695 Mon Sep 17 00:00:00 2001 From: Troy Date: Wed, 6 Nov 2024 22:10:36 +0800 Subject: [PATCH 06/17] =?UTF-8?q?=E9=85=8D=E7=BD=AE=20Bean=20Searcher=20?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=9D=83=E9=99=90=E6=8B=A6=E6=88=AA=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/beansearcher/DataScope.java | 31 +++++++ .../beansearcher/DataScopeSqlInterceptor.java | 85 +++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 maku-framework/src/main/java/net/maku/framework/beansearcher/DataScope.java create mode 100644 maku-framework/src/main/java/net/maku/framework/beansearcher/DataScopeSqlInterceptor.java diff --git a/maku-framework/src/main/java/net/maku/framework/beansearcher/DataScope.java b/maku-framework/src/main/java/net/maku/framework/beansearcher/DataScope.java new file mode 100644 index 0000000..51fd3f9 --- /dev/null +++ b/maku-framework/src/main/java/net/maku/framework/beansearcher/DataScope.java @@ -0,0 +1,31 @@ +package net.maku.framework.beansearcher; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 数据权限注解 + * @author Troy.Zhou @ 2024-11-06 + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE}) +public @interface DataScope { + + /** + * 用于指定数据权限作用在哪张表上(因为可能是联表查询) + */ + String on() default ""; + + /** + * 组织/机构 ID + */ + String orgId() default "org_id"; + + /** + * 数据拥有者 ID + */ + String ownerId() default "creator"; + +} diff --git a/maku-framework/src/main/java/net/maku/framework/beansearcher/DataScopeSqlInterceptor.java b/maku-framework/src/main/java/net/maku/framework/beansearcher/DataScopeSqlInterceptor.java new file mode 100644 index 0000000..eb28d35 --- /dev/null +++ b/maku-framework/src/main/java/net/maku/framework/beansearcher/DataScopeSqlInterceptor.java @@ -0,0 +1,85 @@ +package net.maku.framework.beansearcher; + +import cn.hutool.core.util.StrUtil; +import cn.zhxu.bs.SearchSql; +import cn.zhxu.bs.SqlInterceptor; +import cn.zhxu.bs.param.FetchType; +import com.baomidou.mybatisplus.core.toolkit.StringUtils; +import net.maku.framework.common.constant.Constant; +import net.maku.framework.security.user.SecurityUser; +import net.maku.framework.security.user.UserDetail; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Map; + +/** + * 数据权限拦截器 + * @author Troy.Zhou @ 2024-11-06 + */ +@Component +public class DataScopeSqlInterceptor implements SqlInterceptor { + + @Override + public SearchSql intercept(SearchSql searchSql, Map paraMap, FetchType fetchType) { + DataScope scope = searchSql.getBeanMeta().getBeanClass().getAnnotation(DataScope.class); + if (scope == null) { + return searchSql; // 如果没有启用数据权限,则直接返回 + } + searchSql.setListSqlString(process(scope, searchSql.getListSqlString())); + searchSql.setClusterSqlString(process(scope, searchSql.getClusterSqlString())); + return searchSql; + } + + static final String PLACEHOLDER = ""; // 占位符 + + private String process(DataScope scope, String sql) { + int index = sql.indexOf(PLACEHOLDER); + if (index < 0) { + return sql; // 没有占位符,直接返回 + } + String preSql = sql.substring(0, index); + String nexSql = sql.substring(index + PLACEHOLDER.length()); + UserDetail user = SecurityUser.getUser(); + if (user == null) { + throw new IllegalStateException("用户未登录,代码不应该执行到此,请检查接口的权限保护策略是否有漏洞!"); + } + String scopeSql = buildScopeSql(scope, user); + if (scopeSql == null) { + return preSql + nexSql; + } + String trim = preSql.trim().toLowerCase(); + if (trim.endsWith("where") || trim.endsWith("and")) { + return preSql + " " + scopeSql + " " + nexSql; + } + return preSql + " and " + scopeSql + " " + nexSql; + } + + private String buildScopeSql(DataScope scope, UserDetail user) { + if (user.getSuperAdmin().equals(Constant.SUPER_ADMIN)) { + return null; + } + List orgIds = user.getDataScopeList(); + if (orgIds == null) { + return null; + } + StringBuilder scopeSql = new StringBuilder("("); + if (!orgIds.isEmpty()) { + scopeSql.append(concat(scope.on(), scope.orgId())) + .append(" in (").append(StrUtil.join(",", orgIds)).append(")") + .append(" or "); + } + scopeSql.append(concat(scope.on(), scope.ownerId())) + .append(" = ").append(user.getId()) + .append(")"); + return scopeSql.toString(); + } + + private String concat(String on, String field) { + if (StringUtils.isBlank(on)) { + return field; + } + return on + "." + field; + } + +} -- Gitee From 2b8a8439934d57e476a03e6d42c4fa37d4318910 Mon Sep 17 00:00:00 2001 From: Troy Date: Wed, 6 Nov 2024 22:57:06 +0800 Subject: [PATCH 07/17] =?UTF-8?q?=E9=85=8D=E7=BD=AE=20Bean=20Searcher=20?= =?UTF-8?q?=E5=89=8D=E7=AB=AF=E7=9A=84=E6=8E=92=E5=BA=8F=E5=8F=82=E6=95=B0?= =?UTF-8?q?=20order=20=E4=B8=8E=20asc=20=E7=BB=9F=E4=B8=80=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../beansearcher/OrderParamFilter.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 maku-framework/src/main/java/net/maku/framework/beansearcher/OrderParamFilter.java diff --git a/maku-framework/src/main/java/net/maku/framework/beansearcher/OrderParamFilter.java b/maku-framework/src/main/java/net/maku/framework/beansearcher/OrderParamFilter.java new file mode 100644 index 0000000..35f2881 --- /dev/null +++ b/maku-framework/src/main/java/net/maku/framework/beansearcher/OrderParamFilter.java @@ -0,0 +1,39 @@ +package net.maku.framework.beansearcher; + +import cn.zhxu.bs.BeanMeta; +import cn.zhxu.bs.IllegalParamException; +import cn.zhxu.bs.ParamFilter; +import cn.zhxu.bs.boot.prop.BeanSearcherParams; +import cn.zhxu.bs.util.MapUtils; +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * 排序字段参数转换处理 + * 前端的排序参数是 order 与 asc + * Bean Searcher 的排序参数是 sort 与 order + * @author Troy.Zhou + */ +@Component +@AllArgsConstructor +public class OrderParamFilter implements ParamFilter { + + @Override + public Map doFilter(BeanMeta beanMeta, Map paraMap) throws IllegalParamException { + var order = paraMap.get("order"); + var asc = paraMap.get("asc"); + if (order instanceof String orderField && asc instanceof String ascStr) { + var isAsc = Boolean.parseBoolean(ascStr); + return MapUtils.builder(paraMap) + .orderBy(orderField).asc(isAsc).desc(!isAsc) + .build(); + } + return paraMap; + } + +} -- Gitee From 6f14c4faed794c4d194a7d8eaccbd841b6d38b48 Mon Sep 17 00:00:00 2001 From: Troy Date: Wed, 6 Nov 2024 23:51:23 +0800 Subject: [PATCH 08/17] =?UTF-8?q?=E9=85=8D=E7=BD=AE=20Bean=20Searcher=20?= =?UTF-8?q?=E5=88=86=E9=A1=B5=E5=8F=82=E6=95=B0=20=E4=B8=8E=20VO=20?= =?UTF-8?q?=E5=90=8E=E7=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- maku-server/src/main/resources/application.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/maku-server/src/main/resources/application.yml b/maku-server/src/main/resources/application.yml index 49aa9d0..32a6f36 100644 --- a/maku-server/src/main/resources/application.yml +++ b/maku-server/src/main/resources/application.yml @@ -76,6 +76,15 @@ mybatis-plus: blobType: BLOB boolValue: TRUE +bean-searcher: + params: + pagination: + start: 1 + size: limit + sql: + default-mapping: + redundant-suffixes: VO + #easy trans 数据翻译组件 easy-trans: #启用redis缓存 如果不用redis请设置为false -- Gitee From d7ef4dfc38896d47b1180fe22a76d61e13b2727f Mon Sep 17 00:00:00 2001 From: troyzhxu <1573555987@qq.com> Date: Thu, 7 Nov 2024 11:49:28 +0800 Subject: [PATCH 09/17] =?UTF-8?q?=E4=BD=BF=E7=94=A8=20Bean=20Searcher=20?= =?UTF-8?q?=E9=87=8D=E6=9E=84=20GET/sys/user/page=20=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=EF=BC=8C=E8=8A=82=E7=9C=81=2022=20=E8=A1=8C=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/controller/SysUserController.java | 11 ++++-- .../java/net/maku/system/dao/SysUserDao.java | 3 +- .../maku/system/service/SysUserService.java | 3 +- .../service/impl/SysUserServiceImpl.java | 29 +++++++------- .../java/net/maku/system/vo/SysUserVO.java | 14 ++++++- .../src/main/resources/mapper/SysUserDao.xml | 39 ++++++++++--------- 6 files changed, 59 insertions(+), 40 deletions(-) diff --git a/maku-boot-system/src/main/java/net/maku/system/controller/SysUserController.java b/maku-boot-system/src/main/java/net/maku/system/controller/SysUserController.java index 8f00e7b..483fb01 100644 --- a/maku-boot-system/src/main/java/net/maku/system/controller/SysUserController.java +++ b/maku-boot-system/src/main/java/net/maku/system/controller/SysUserController.java @@ -1,6 +1,7 @@ package net.maku.system.controller; import cn.hutool.core.util.StrUtil; +import cn.zhxu.bs.BeanSearcher; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; @@ -47,14 +48,16 @@ public class SysUserController { private final SysUserPostService sysUserPostService; private final SysPostService sysPostService; private final PasswordEncoder passwordEncoder; + private final BeanSearcher beanSearcher; @GetMapping("page") @Operation(summary = "分页") @PreAuthorize("hasAuthority('sys:user:page')") - public Result> page(@ParameterObject @Valid SysUserQuery query) { - PageResult page = sysUserService.page(query); - - return Result.ok(page); + public Result> page(@ParameterObject SysUserQuery ignore) { + // return Result.ok(sysUserService.page(ignore)); + // 使用 Bean Searcher 方案,共节省 1+8(Service)+1+19(Dao)-7(VO)= 22 行代码 + // 其实 SysUserQuery 也可以不要,为了生成接口文档,先保留 + return Result.ok(beanSearcher.search(SysUserVO.class)); } @GetMapping("{id}") diff --git a/maku-boot-system/src/main/java/net/maku/system/dao/SysUserDao.java b/maku-boot-system/src/main/java/net/maku/system/dao/SysUserDao.java index 8560874..c031f6c 100644 --- a/maku-boot-system/src/main/java/net/maku/system/dao/SysUserDao.java +++ b/maku-boot-system/src/main/java/net/maku/system/dao/SysUserDao.java @@ -18,7 +18,8 @@ import java.util.Map; @Mapper public interface SysUserDao extends BaseDao { - List getList(Map params); + // 用户管理分页接口使用 Bean Searcher 该方法已不在需要,节省 1 行代码 +// List getList(Map params); SysUserEntity getById(@Param("id") Long id); diff --git a/maku-boot-system/src/main/java/net/maku/system/service/SysUserService.java b/maku-boot-system/src/main/java/net/maku/system/service/SysUserService.java index 29ccb37..e219792 100644 --- a/maku-boot-system/src/main/java/net/maku/system/service/SysUserService.java +++ b/maku-boot-system/src/main/java/net/maku/system/service/SysUserService.java @@ -20,7 +20,8 @@ import java.util.List; */ public interface SysUserService extends BaseService { - PageResult page(SysUserQuery query); +// 用户管理分页接口使用 Bean Searcher 该方法已不在需要,节省 1 行代码 +// PageResult page(SysUserQuery query); void save(SysUserVO vo); diff --git a/maku-boot-system/src/main/java/net/maku/system/service/impl/SysUserServiceImpl.java b/maku-boot-system/src/main/java/net/maku/system/service/impl/SysUserServiceImpl.java index 2b7ea11..f231913 100644 --- a/maku-boot-system/src/main/java/net/maku/system/service/impl/SysUserServiceImpl.java +++ b/maku-boot-system/src/main/java/net/maku/system/service/impl/SysUserServiceImpl.java @@ -51,20 +51,21 @@ public class SysUserServiceImpl extends BaseServiceImpl page(SysUserQuery query) { - // 查询参数 - Map params = getParams(query); - - // 分页查询 - IPage page = getPage(query); - params.put(Constant.PAGE, page); - - // 数据列表 - List list = baseMapper.getList(params); - - return new PageResult<>(SysUserConvert.INSTANCE.convertList(list), page.getTotal()); - } + // 用户管理分页接口使用 Bean Searcher 该方法已不在需要,节省有效代码 8 行 +// @Override +// public PageResult page(SysUserQuery query) { +// // 查询参数 +// Map params = getParams(query); +// +// // 分页查询 +// IPage page = getPage(query); +// params.put(Constant.PAGE, page); +// +// // 数据列表 +// List list = baseMapper.getList(params); +// +// return new PageResult<>(SysUserConvert.INSTANCE.convertList(list), page.getTotal()); +// } private Map getParams(SysUserQuery query) { Map params = new HashMap<>(); diff --git a/maku-boot-system/src/main/java/net/maku/system/vo/SysUserVO.java b/maku-boot-system/src/main/java/net/maku/system/vo/SysUserVO.java index e1163a0..cce2058 100644 --- a/maku-boot-system/src/main/java/net/maku/system/vo/SysUserVO.java +++ b/maku-boot-system/src/main/java/net/maku/system/vo/SysUserVO.java @@ -1,5 +1,9 @@ package net.maku.system.vo; +import cn.zhxu.bs.bean.DbField; +import cn.zhxu.bs.bean.DbIgnore; +import cn.zhxu.bs.bean.SearchBean; +import cn.zhxu.bs.operator.InList; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonProperty; import com.fhs.core.trans.anno.Trans; @@ -10,6 +14,7 @@ import jakarta.validation.constraints.Email; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; import lombok.Data; +import net.maku.framework.beansearcher.DataScope; import net.maku.framework.common.utils.DateUtils; import net.maku.system.entity.SysOrgEntity; import org.hibernate.validator.constraints.Range; @@ -20,12 +25,14 @@ import java.util.List; /** * 用户 - * * @author 阿沐 babamu@126.com * MAKU + * 使用 Bean Searcher 改造, 实体类添加相关注解,共增加有效代码 7 行 */ @Data +@DataScope @Schema(description = "用户") +@SearchBean(where = "super_admin = 0 and deleted = 0 ") public class SysUserVO implements Serializable, TransPojo { private static final long serialVersionUID = 1L; @@ -62,24 +69,29 @@ public class SysUserVO implements Serializable, TransPojo { @Schema(description = "机构ID", required = true) @NotNull(message = "机构ID不能为空") @Trans(type = TransType.SIMPLE, target = SysOrgEntity.class, fields = "name", ref = "orgName") + @DbField(onlyOn = InList.class) private Long orgId; @Schema(description = "状态 0:停用 1:正常", required = true) @Range(min = 0, max = 1, message = "用户状态不正确") private Integer status; + @DbIgnore @Schema(description = "角色ID列表") private List roleIdList; + @DbIgnore @Schema(description = "岗位ID列表") private List postIdList; + @DbIgnore @Schema(description = "岗位名称列表") private List postNameList; @Schema(description = "超级管理员 0:否 1:是") private Integer superAdmin; + @DbIgnore @Schema(description = "机构名称") private String orgName; diff --git a/maku-boot-system/src/main/resources/mapper/SysUserDao.xml b/maku-boot-system/src/main/resources/mapper/SysUserDao.xml index 207a9aa..8b91641 100644 --- a/maku-boot-system/src/main/resources/mapper/SysUserDao.xml +++ b/maku-boot-system/src/main/resources/mapper/SysUserDao.xml @@ -3,25 +3,26 @@ - + + + + + + + + + + + + + + + + + + + +