Compare commits

..

18 Commits

Author SHA1 Message Date
99c9071eae release: v2.7.5 2024-12-06 21:24:19 +08:00
73b066a88d chore: 优化部分代码格式 2024-12-06 21:01:25 +08:00
2a5ace0033 refactor(extension/crud): BaseController => AbstractBaseController,并移除 CrudApiStrategy 2024-12-06 21:00:23 +08:00
93ab4e50cc refactor(data): 使用 Hutool 工具方法替换反射 API,以解决扫描问题 2024-12-06 10:50:56 +08:00
6a6c559d2f refactor(extension/crud): 优化校验器分组命名 2024-12-06 10:05:20 +08:00
16da470008 refactor(extension/crud): CrudApiHandler preHandle 方法增加 args 方法参数入餐 2024-11-21 23:11:16 +08:00
f2a30e8b74 refactor(extension/crud): 优化部分代码 2024-11-21 20:13:19 +08:00
15f87068c6 refactor(extension/crud): 增强 BaseController 内 API 校验,支持指定 Controller 单独处理 2024-11-20 22:32:03 +08:00
3a0c3e02b0 refactor(extension/crud): 调整 BaseController、BaseService 到 crud-core 模块 2024-11-20 21:40:21 +08:00
3edf79cf3b refactor(extension/crud): 重构 BaseController 内权限校验
1.移除 SaToken 依赖
2.移除 checkPermission 方法
3.新增 CrudApi 注解
2024-11-19 23:08:39 +08:00
6b3bc832de fix(data/mp): 修复 Query 范围查询数组类型数据解析错误 2024-11-19 20:20:31 +08:00
1d53eaa3c3 release: v2.7.4 2024-11-18 22:56:58 +08:00
4e2096e37d fix: 修复遗漏的 validate 导入替换 2024-11-18 22:56:48 +08:00
8dcde6b84d chore(extension/crud): 优化部分注释 2024-11-18 22:46:02 +08:00
fd9d2bb370 chore(core): 移除多余的校验工具类 2024-11-17 19:24:20 +08:00
464b87c9c7 refactor(core): 增加 + 号字符串/字符常量 2024-11-17 19:21:13 +08:00
27ce092b79 fix(extension/crud): 修复新增响应结构 BaseIdResp 无法被继承问题 2024-11-17 19:16:39 +08:00
b11013ee80 fix(json/jackson): 修复 BaseEnum 反序列化数据类型仅支持数值的问题 2024-11-16 21:29:09 +08:00
42 changed files with 411 additions and 1095 deletions

View File

@@ -1,3 +1,28 @@
## [v2.7.5](https://github.com/continew-org/continew-starter/compare/v2.7.4...v2.7.5) (2024-12-06)
### 💎 功能优化
- 【extension/crud】重构 BaseController 内权限校验BaseController => AbstractBaseController ([3edf79c](https://github.com/continew-org/continew-starter/commit/3edf79cf3bdba91010776c95902414fa7481c39e)) ([15f8706](https://github.com/continew-org/continew-starter/commit/15f87068c65e4afd83ee7020bde2707870012fb9)) ([16da470](https://github.com/continew-org/continew-starter/commit/16da470008d44ebf37cbe9e292ac8db8fc04ceb5)) ([2a5ace0](https://github.com/continew-org/continew-starter/commit/2a5ace003329422589af834431ac2bd8fa30ac28))
- 【extension/crud】调整 BaseController、BaseService 到 crud-core 模块 ([3a0c3e0](https://github.com/continew-org/continew-starter/commit/3a0c3e02b03837789bfc433a335b062ec5dab511))
- 【extension/crud】优化部分代码ValidateGroup => CrudValidationGroup ([f2a30e8](https://github.com/continew-org/continew-starter/commit/f2a30e8b74b828644970be0b05920a32d6eb514a)) ([6a6c559](https://github.com/continew-org/continew-starter/commit/6a6c559d2f53f25888259a7e5d020281408aaa9f))
- 【data】使用 Hutool 工具方法替换反射 API以解决扫描问题 ([93ab4e5](https://github.com/continew-org/continew-starter/commit/93ab4e50cc1957ab772b31c9c433f9fc3d29da33))
### 🐛 问题修复
- 【data/mp】修复 Query 范围查询数组类型数据解析错误 ([6b3bc83](https://github.com/continew-org/continew-starter/commit/6b3bc832de25acdb2be418ad7626e9b6e234adde))
## [v2.7.4](https://github.com/continew-org/continew-starter/compare/v2.7.3...v2.7.4) (2024-11-18)
### 💎 功能优化
- 【core】增加 + 号字符串/字符常量 ([464b87c](https://github.com/continew-org/continew-starter/commit/464b87c9c7789bc142538bc146ecfe4358c12a50))
- 【core】移除多余的校验工具类 ([fd9d2bb](https://github.com/continew-org/continew-starter/commit/fd9d2bb370caef4e9f9e3874e113c381ab4e5eb9))
### 🐛 问题修复
- 【extension/crud】修复新增响应结构 BaseIdResp 无法被继承问题 ([27ce092](https://github.com/continew-org/continew-starter/commit/27ce092b796a66f1c59d8715cf5648edab9efa65))
- 【json/jackson】修复 BaseEnum 反序列化数据类型仅支持数值的问题 ([b11013e](https://github.com/continew-org/continew-starter/commit/b11013ee80cb00022890d950ff7f666909de2082))
## [v2.7.3](https://github.com/continew-org/continew-starter/compare/v2.7.2...v2.7.3) (2024-11-15)
### ✨ 新特性

View File

@@ -76,6 +76,16 @@ public class CharConstants {
*/
public static final char DASHED = '-';
/**
* 加号 {@code '+'}
*/
public static final char PLUS = '+';
/**
* 等号 {@code '='}
*/
public static final char EQUALS = '=';
/**
* 星号 {@code '*'}
*/
@@ -146,11 +156,6 @@ public class CharConstants {
*/
public static final char SINGLE_QUOTE = '\'';
/**
* 等号 {@code '='}
*/
public static final char EQUALS = '=';
/**
* 回车符 {@code '\r'}
*/

View File

@@ -94,6 +94,16 @@ public class StringConstants {
*/
public static final String DASHED = "-";
/**
* 加号 {@code "+"}
*/
public static final String PLUS = "+";
/**
* 等号 {@code "="}
*/
public static final String EQUALS = "=";
/**
* 星号 {@code "*"}
*/
@@ -164,11 +174,6 @@ public class StringConstants {
*/
public static final String SINGLE_QUOTE = "'";
/**
* 等号 {@code "="}
*/
public static final String EQUALS = "=";
/**
* 回车符 {@code "\r"}
*/

View File

@@ -1,204 +0,0 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* 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 top.continew.starter.core.util.validate;
import cn.hutool.core.text.CharSequenceUtil;
import top.continew.starter.core.constant.StringConstants;
import top.continew.starter.core.exception.BusinessException;
import java.util.function.BooleanSupplier;
/**
* 业务参数校验工具类(抛出 500 ServiceException
*
* @author Charles7c
* @see BusinessException
* @since 1.0.0
*/
public class CheckUtils extends Validator {
private static final Class<BusinessException> EXCEPTION_TYPE = BusinessException.class;
private CheckUtils() {
}
/**
* 如果不存在,抛出异常
*
* @param obj 被检测的对象
* @param entityName 实体名
* @param fieldName 字段名
* @param fieldValue 字段值
*/
public static void throwIfNotExists(Object obj, String entityName, String fieldName, Object fieldValue) {
String message = "%s 为 [%s] 的 %s 记录已不存在".formatted(fieldName, fieldValue, CharSequenceUtil
.replace(entityName, "DO", StringConstants.EMPTY));
throwIfNull(obj, message, EXCEPTION_TYPE);
}
/**
* 如果为空,抛出异常
*
* @param obj 被检测的对象
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null返回 "null"
* @param params 参数值
*/
public static void throwIfNull(Object obj, String template, Object... params) {
throwIfNull(obj, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
}
/**
* 如果不为空,抛出异常
*
* @param obj 被检测的对象
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null返回 "null"
* @param params 参数值
*/
public static void throwIfNotNull(Object obj, String template, Object... params) {
throwIfNotNull(obj, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
}
/**
* 如果存在,抛出异常
*
* @param obj 被检测的对象
* @param entityName 实体名
* @param fieldName 字段名
* @param fieldValue 字段值
*/
public static void throwIfExists(Object obj, String entityName, String fieldName, Object fieldValue) {
String message = "%s 为 [%s] 的 %s 记录已存在".formatted(fieldName, fieldValue, entityName);
throwIfNotNull(obj, message, EXCEPTION_TYPE);
}
/**
* 如果为空,抛出异常
*
* @param obj 被检测的对象
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null返回 "null"
* @param params 参数值
*/
public static void throwIfEmpty(Object obj, String template, Object... params) {
throwIfEmpty(obj, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
}
/**
* 如果不为空,抛出异常
*
* @param obj 被检测的对象
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null返回 "null"
* @param params 参数值
*/
public static void throwIfNotEmpty(Object obj, String template, Object... params) {
throwIfNotEmpty(obj, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
}
/**
* 如果为空,抛出异常
*
* @param str 被检测的字符串
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null返回 "null"
* @param params 参数值
*/
public static void throwIfBlank(CharSequence str, String template, Object... params) {
throwIfBlank(str, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
}
/**
* 如果不为空,抛出异常
*
* @param str 被检测的字符串
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null返回 "null"
* @param params 参数值
*/
public static void throwIfNotBlank(CharSequence str, String template, Object... params) {
throwIfNotBlank(str, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
}
/**
* 如果相同,抛出异常
*
* @param obj1 要比较的对象1
* @param obj2 要比较的对象2
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null返回 "null"
* @param params 参数值
*/
public static void throwIfEqual(Object obj1, Object obj2, String template, Object... params) {
throwIfEqual(obj1, obj2, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
}
/**
* 如果不相同,抛出异常
*
* @param obj1 要比较的对象1
* @param obj2 要比较的对象2
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null返回 "null"
* @param params 参数值
*/
public static void throwIfNotEqual(Object obj1, Object obj2, String template, Object... params) {
throwIfNotEqual(obj1, obj2, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
}
/**
* 如果相同,抛出异常(不区分大小写)
*
* @param str1 要比较的字符串1
* @param str2 要比较的字符串2
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null返回 "null"
* @param params 参数值
*/
public static void throwIfEqualIgnoreCase(CharSequence str1, CharSequence str2, String template, Object... params) {
throwIfEqualIgnoreCase(str1, str2, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
}
/**
* 如果不相同,抛出异常(不区分大小写)
*
* @param str1 要比较的字符串1
* @param str2 要比较的字符串2
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null返回 "null"
* @param params 参数值
*/
public static void throwIfNotEqualIgnoreCase(CharSequence str1,
CharSequence str2,
String template,
Object... params) {
throwIfNotEqualIgnoreCase(str1, str2, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
}
/**
* 如果条件成立,抛出异常
*
* @param condition 条件
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null返回 "null"
* @param params 参数值
*/
public static void throwIf(boolean condition, String template, Object... params) {
throwIf(condition, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
}
/**
* 如果条件成立,抛出异常
*
* @param conditionSupplier 条件
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null返回 "null"
* @param params 参数值
*/
public static void throwIf(BooleanSupplier conditionSupplier, String template, Object... params) {
throwIf(conditionSupplier, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
}
}

View File

@@ -1,176 +0,0 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* 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 top.continew.starter.core.util.validate;
import cn.hutool.core.text.CharSequenceUtil;
import top.continew.starter.core.exception.BadRequestException;
import java.util.function.BooleanSupplier;
/**
* 基本参数校验工具类(抛出 400 BadRequestException
*
* @author Charles7c
* @see BadRequestException
* @since 1.0.0
*/
public class ValidationUtils extends Validator {
private static final Class<BadRequestException> EXCEPTION_TYPE = BadRequestException.class;
private ValidationUtils() {
}
/**
* 如果为空,抛出异常
*
* @param obj 被检测的对象
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null返回 "null"
* @param params 参数值
*/
public static void throwIfNull(Object obj, String template, Object... params) {
throwIfNull(obj, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
}
/**
* 如果不为空,抛出异常
*
* @param obj 被检测的对象
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null返回 "null"
* @param params 参数值
*/
public static void throwIfNotNull(Object obj, String template, Object... params) {
throwIfNotNull(obj, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
}
/**
* 如果为空,抛出异常
*
* @param obj 被检测的对象
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null返回 "null"
* @param params 参数值
*/
public static void throwIfEmpty(Object obj, String template, Object... params) {
throwIfEmpty(obj, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
}
/**
* 如果不为空,抛出异常
*
* @param obj 被检测的对象
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null返回 "null"
* @param params 参数值
*/
public static void throwIfNotEmpty(Object obj, String template, Object... params) {
throwIfNotEmpty(obj, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
}
/**
* 如果为空,抛出异常
*
* @param str 被检测的字符串
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null返回 "null"
* @param params 参数值
*/
public static void throwIfBlank(CharSequence str, String template, Object... params) {
throwIfBlank(str, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
}
/**
* 如果不为空,抛出异常
*
* @param str 被检测的字符串
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null返回 "null"
* @param params 参数值
*/
public static void throwIfNotBlank(CharSequence str, String template, Object... params) {
throwIfNotBlank(str, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
}
/**
* 如果相同,抛出异常
*
* @param obj1 要比较的对象1
* @param obj2 要比较的对象2
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null返回 "null"
* @param params 参数值
*/
public static void throwIfEqual(Object obj1, Object obj2, String template, Object... params) {
throwIfEqual(obj1, obj2, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
}
/**
* 如果不相同,抛出异常
*
* @param obj1 要比较的对象1
* @param obj2 要比较的对象2
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null返回 "null"
* @param params 参数值
*/
public static void throwIfNotEqual(Object obj1, Object obj2, String template, Object... params) {
throwIfNotEqual(obj1, obj2, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
}
/**
* 如果相同,抛出异常(不区分大小写)
*
* @param str1 要比较的字符串1
* @param str2 要比较的字符串2
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null返回 "null"
* @param params 参数值
*/
public static void throwIfEqualIgnoreCase(CharSequence str1, CharSequence str2, String template, Object... params) {
throwIfEqualIgnoreCase(str1, str2, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
}
/**
* 如果不相同,抛出异常(不区分大小写)
*
* @param str1 要比较的字符串1
* @param str2 要比较的字符串2
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null返回 "null"
* @param params 参数值
*/
public static void throwIfNotEqualIgnoreCase(CharSequence str1,
CharSequence str2,
String template,
Object... params) {
throwIfNotEqualIgnoreCase(str1, str2, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
}
/**
* 如果条件成立,抛出异常
*
* @param condition 条件
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null返回 "null"
* @param params 参数值
*/
public static void throwIf(boolean condition, String template, Object... params) {
throwIf(condition, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
}
/**
* 如果条件成立,抛出异常
*
* @param conditionSupplier 条件
* @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null返回 "null"
* @param params 参数值
*/
public static void throwIf(BooleanSupplier conditionSupplier, String template, Object... params) {
throwIf(conditionSupplier, CharSequenceUtil.format(template, params), EXCEPTION_TYPE);
}
}

View File

@@ -1,218 +0,0 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* 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 top.continew.starter.core.util.validate;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.extra.spring.SpringUtil;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.ConstraintViolationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Set;
import java.util.function.BooleanSupplier;
/**
* 校验器
*
* @author Charles7c
* @since 1.0.0
*/
public class Validator {
private static final Logger log = LoggerFactory.getLogger(Validator.class);
private static final jakarta.validation.Validator VALIDATOR = SpringUtil
.getBean(jakarta.validation.Validator.class);
protected Validator() {
}
/**
* 如果为空,抛出异常
*
* @param obj 被检测的对象
* @param message 错误信息
* @param exceptionType 异常类型
*/
protected static void throwIfNull(Object obj, String message, Class<? extends RuntimeException> exceptionType) {
throwIf(null == obj, message, exceptionType);
}
/**
* 如果不为空,抛出异常
*
* @param obj 被检测的对象
* @param message 错误信息
* @param exceptionType 异常类型
*/
protected static void throwIfNotNull(Object obj, String message, Class<? extends RuntimeException> exceptionType) {
throwIf(null != obj, message, exceptionType);
}
/**
* 如果为空,抛出异常
*
* @param obj 被检测的对象
* @param message 错误信息
* @param exceptionType 异常类型
*/
protected static void throwIfEmpty(Object obj, String message, Class<? extends RuntimeException> exceptionType) {
throwIf(ObjectUtil.isEmpty(obj), message, exceptionType);
}
/**
* 如果不为空,抛出异常
*
* @param obj 被检测的对象
* @param message 错误信息
* @param exceptionType 异常类型
*/
protected static void throwIfNotEmpty(Object obj, String message, Class<? extends RuntimeException> exceptionType) {
throwIf(ObjectUtil.isNotEmpty(obj), message, exceptionType);
}
/**
* 如果为空,抛出异常
*
* @param str 被检测的字符串
* @param message 错误信息
* @param exceptionType 异常类型
*/
protected static void throwIfBlank(CharSequence str,
String message,
Class<? extends RuntimeException> exceptionType) {
throwIf(CharSequenceUtil.isBlank(str), message, exceptionType);
}
/**
* 如果不为空,抛出异常
*
* @param str 被检测的字符串
* @param message 错误信息
* @param exceptionType 异常类型
*/
protected static void throwIfNotBlank(CharSequence str,
String message,
Class<? extends RuntimeException> exceptionType) {
throwIf(CharSequenceUtil.isNotBlank(str), message, exceptionType);
}
/**
* 如果相同,抛出异常
*
* @param obj1 要比较的对象1
* @param obj2 要比较的对象2
* @param message 错误信息
* @param exceptionType 异常类型
*/
protected static void throwIfEqual(Object obj1,
Object obj2,
String message,
Class<? extends RuntimeException> exceptionType) {
throwIf(ObjectUtil.equal(obj1, obj2), message, exceptionType);
}
/**
* 如果不相同,抛出异常
*
* @param obj1 要比较的对象1
* @param obj2 要比较的对象2
* @param message 错误信息
* @param exceptionType 异常类型
*/
protected static void throwIfNotEqual(Object obj1,
Object obj2,
String message,
Class<? extends RuntimeException> exceptionType) {
throwIf(ObjectUtil.notEqual(obj1, obj2), message, exceptionType);
}
/**
* 如果相同,抛出异常(不区分大小写)
*
* @param str1 要比较的字符串1
* @param str2 要比较的字符串2
* @param message 错误信息
* @param exceptionType 异常类型
*/
protected static void throwIfEqualIgnoreCase(CharSequence str1,
CharSequence str2,
String message,
Class<? extends RuntimeException> exceptionType) {
throwIf(CharSequenceUtil.equalsIgnoreCase(str1, str2), message, exceptionType);
}
/**
* 如果不相同,抛出异常(不区分大小写)
*
* @param str1 要比较的字符串1
* @param str2 要比较的字符串2
* @param message 错误信息
* @param exceptionType 异常类型
*/
protected static void throwIfNotEqualIgnoreCase(CharSequence str1,
CharSequence str2,
String message,
Class<? extends RuntimeException> exceptionType) {
throwIf(!CharSequenceUtil.equalsIgnoreCase(str1, str2), message, exceptionType);
}
/**
* 如果条件成立,抛出异常
*
* @param condition 条件
* @param message 错误信息
* @param exceptionType 异常类型
*/
protected static void throwIf(boolean condition, String message, Class<? extends RuntimeException> exceptionType) {
if (condition) {
log.error(message);
throw ReflectUtil.newInstance(exceptionType, message);
}
}
/**
* 如果条件成立,抛出异常
*
* @param conditionSupplier 条件
* @param message 错误信息
* @param exceptionType 异常类型
*/
protected static void throwIf(BooleanSupplier conditionSupplier,
String message,
Class<? extends RuntimeException> exceptionType) {
if (null != conditionSupplier && conditionSupplier.getAsBoolean()) {
log.error(message);
throw ReflectUtil.newInstance(exceptionType, message);
}
}
/**
* JSR 303 校验
*
* @param obj 被校验对象
* @param groups 分组
* @since 2.3.0
*/
public static void validate(Object obj, Class<?>... groups) {
Set<ConstraintViolation<Object>> violations = VALIDATOR.validate(obj, groups);
if (!violations.isEmpty()) {
throw new ConstraintViolationException(violations);
}
}
}

View File

@@ -33,7 +33,7 @@ import static java.lang.annotation.ElementType.*;
* {@code @EnumValue(value = XxxEnum.class, message = "参数值非法")} <br />
* {@code @EnumValue(enumValues = {"F", "M"} ,message = "性别只允许为F或M")}
* </p>
*
*
* @author Jasmine
* @author Charles7c
* @since 2.7.3

View File

@@ -16,6 +16,7 @@
package top.continew.starter.core.validation.constraints;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.text.CharSequenceUtil;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
@@ -54,20 +55,20 @@ public class EnumValueValidator implements ConstraintValidator<EnumValue, Object
}
// 优先校验 enumValues
if (enumValues.length > 0) {
return Arrays.asList(enumValues).contains(value.toString());
return Arrays.asList(enumValues).contains(Convert.toStr(value));
}
Enum[] enumConstants = enumClass.getEnumConstants();
if (enumConstants.length == 0) {
return false;
}
if (CharSequenceUtil.isBlank(enumMethod)) {
return findEnumValue(enumConstants, Enum::toString, value.toString());
return findEnumValue(enumConstants, Enum::toString, Convert.toStr(value));
}
try {
// 枚举类指定了方法名,则调用指定方法获取枚举值
Method method = enumClass.getMethod(enumMethod);
for (Enum enumConstant : enumConstants) {
if (method.invoke(enumConstant).equals(value)) {
if (Convert.toStr(method.invoke(enumConstant)).equals(Convert.toStr(value))) {
return true;
}
}

View File

@@ -68,8 +68,8 @@ public class DataPermissionDialect extends CommonsDialectImpl {
* 构建自定义数据权限表达式
*
* <p>
* 处理完后的 SQL 示例:<br /> select t1.* from table as t1 where t1.dept_id in (select dept_id from sys_role_dept
* where role_id = xxx);
* 处理完后的 SQL 示例:<br /> select t1.* from table as t1 where t1.dept_id in (select dept_id from sys_role_dept where
* role_id = xxx);
* </p>
*
* @param dataPermission 数据权限
@@ -124,8 +124,8 @@ public class DataPermissionDialect extends CommonsDialectImpl {
* 构建本部门及以下数据权限表达式
*
* <p>
* 处理完后的 SQL 示例:<br /> select t1.* from table as t1 where t1.dept_id in (select id from sys_dept where id =
* xxx or find_in_set(xxx, ancestors));
* 处理完后的 SQL 示例:<br /> select t1.* from table as t1 where t1.dept_id in (select id from sys_dept where id = xxx or
* find_in_set(xxx, ancestors));
* </p>
*
* @param dataPermission 数据权限

View File

@@ -16,10 +16,12 @@
package top.continew.starter.data.mf.util;
import cn.hutool.core.annotation.AnnotationUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ReflectUtil;
import com.mybatisflex.core.query.QueryWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -133,23 +135,21 @@ public class QueryWrapperHelper {
* @return QueryWrapper Consumer
*/
private static <Q, R> List<Consumer<QueryWrapper>> buildWrapperConsumer(Q query, Field field) {
boolean accessible = field.canAccess(query);
try {
field.setAccessible(true);
// 如果字段值为空,直接返回
Object fieldValue = field.get(query);
Object fieldValue = ReflectUtil.getFieldValue(query, field);
if (ObjectUtil.isEmpty(fieldValue)) {
return Collections.emptyList();
}
// 设置了 @QueryIgnore 注解,直接忽略
QueryIgnore queryIgnoreAnnotation = field.getAnnotation(QueryIgnore.class);
QueryIgnore queryIgnoreAnnotation = AnnotationUtil.getAnnotation(field, QueryIgnore.class);
if (null != queryIgnoreAnnotation) {
return Collections.emptyList();
}
// 建议:数据库表列建议采用下划线连接法命名,程序变量建议采用驼峰法命名
String fieldName = field.getName();
String fieldName = ReflectUtil.getFieldName(field);
// 没有 @Query 注解,默认等值查询
Query queryAnnotation = field.getAnnotation(Query.class);
Query queryAnnotation = AnnotationUtil.getAnnotation(field, Query.class);
if (null == queryAnnotation) {
return Collections.singletonList(q -> q.eq(CharSequenceUtil.toUnderlineCase(fieldName), fieldValue));
}
@@ -173,8 +173,6 @@ public class QueryWrapperHelper {
} catch (Exception e) {
log.error("Build query wrapper occurred an error: {}. Query: {}, Field: {}.", e
.getMessage(), query, field, e);
} finally {
field.setAccessible(accessible);
}
return Collections.emptyList();
}

View File

@@ -19,7 +19,10 @@ package top.continew.starter.data.mp.autoconfigure;
import cn.hutool.extra.spring.SpringUtil;
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusPropertiesCustomizer;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.*;
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import jakarta.annotation.PostConstruct;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;

View File

@@ -16,10 +16,12 @@
package top.continew.starter.data.mp.util;
import cn.hutool.core.annotation.AnnotationUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ReflectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -127,23 +129,21 @@ public class QueryWrapperHelper {
* @return QueryWrapper Consumer
*/
private static <Q, R> List<Consumer<QueryWrapper<R>>> buildWrapperConsumer(Q query, Field field) {
boolean accessible = field.canAccess(query);
try {
field.setAccessible(true);
// 如果字段值为空,直接返回
Object fieldValue = field.get(query);
Object fieldValue = ReflectUtil.getFieldValue(query, field);
if (ObjectUtil.isEmpty(fieldValue)) {
return Collections.emptyList();
}
// 设置了 @QueryIgnore 注解,直接忽略
QueryIgnore queryIgnoreAnnotation = field.getAnnotation(QueryIgnore.class);
QueryIgnore queryIgnoreAnnotation = AnnotationUtil.getAnnotation(field, QueryIgnore.class);
if (null != queryIgnoreAnnotation) {
return Collections.emptyList();
}
// 建议:数据库表列建议采用下划线连接法命名,程序变量建议采用驼峰法命名
String fieldName = field.getName();
String fieldName = ReflectUtil.getFieldName(field);
// 没有 @Query 注解,默认等值查询
Query queryAnnotation = field.getAnnotation(Query.class);
Query queryAnnotation = AnnotationUtil.getAnnotation(field, Query.class);
if (null == queryAnnotation) {
return Collections.singletonList(q -> q.eq(CharSequenceUtil.toUnderlineCase(fieldName), fieldValue));
}
@@ -167,8 +167,6 @@ public class QueryWrapperHelper {
} catch (Exception e) {
log.error("Build query wrapper occurred an error: {}. Query: {}, Field: {}.", e
.getMessage(), query, field, e);
} finally {
field.setAccessible(accessible);
}
return Collections.emptyList();
}
@@ -193,8 +191,9 @@ public class QueryWrapperHelper {
case LT -> consumers.add(q -> q.lt(columnName, fieldValue));
case LE -> consumers.add(q -> q.le(columnName, fieldValue));
case BETWEEN -> {
// 数组转集合
List<Object> between = new ArrayList<>(ArrayUtil.isArray(fieldValue)
? CollUtil.toList(fieldValue)
? List.of((Object[])fieldValue)
: (List<Object>)fieldValue);
ValidationUtils.throwIf(between.size() != 2, "[{}] 必须是一个范围", columnName);
consumers.add(q -> q.between(columnName, between.get(0), between.get(1)));
@@ -205,13 +204,13 @@ public class QueryWrapperHelper {
case IN -> {
ValidationUtils.throwIfEmpty(fieldValue, "[{}] 不能为空", columnName);
consumers.add(q -> q.in(columnName, ArrayUtil.isArray(fieldValue)
? CollUtil.toList(fieldValue)
? List.of((Object[])fieldValue)
: (Collection<Object>)fieldValue));
}
case NOT_IN -> {
ValidationUtils.throwIfEmpty(fieldValue, "[{}] 不能为空", columnName);
consumers.add(q -> q.notIn(columnName, ArrayUtil.isArray(fieldValue)
? CollUtil.toList(fieldValue)
? List.of((Object[])fieldValue)
: (Collection<Object>)fieldValue));
}
case IS_NULL -> consumers.add(q -> q.isNull(columnName));

View File

@@ -43,7 +43,7 @@
<properties>
<!-- 项目版本号 -->
<revision>2.7.3</revision>
<revision>2.7.5</revision>
<snail-job.version>1.1.2</snail-job.version>
<sa-token.version>1.39.0</sa-token.version>
<just-auth.version>1.16.6</just-auth.version>

View File

@@ -30,18 +30,6 @@
<artifactId>continew-starter-web</artifactId>
</dependency>
<!-- 认证模块 - SaToken -->
<dependency>
<groupId>top.continew</groupId>
<artifactId>continew-starter-auth-satoken</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- 数据访问模块 - 核心模块 -->
<dependency>
<groupId>top.continew</groupId>

View File

@@ -0,0 +1,38 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* 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 top.continew.starter.extension.crud.annotation;
import top.continew.starter.extension.crud.enums.Api;
import java.lang.annotation.*;
/**
* CRUD增删改查API
*
* @author Charles7c
* @since 2.7.5
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface CrudApi {
/**
* API 类型
*/
Api value() default Api.LIST;
}

View File

@@ -17,6 +17,7 @@
package top.continew.starter.extension.crud.annotation;
import org.springframework.context.annotation.Import;
import top.continew.starter.extension.crud.autoconfigure.CrudRequestMappingAutoConfiguration;
import top.continew.starter.extension.crud.autoconfigure.CrudRestControllerAutoConfiguration;
import java.lang.annotation.*;
@@ -30,5 +31,5 @@ import java.lang.annotation.*;
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Import({CrudRestControllerAutoConfiguration.class})
@Import({CrudRequestMappingAutoConfiguration.class, CrudRestControllerAutoConfiguration.class})
public @interface EnableCrudRestController {}

View File

@@ -0,0 +1,62 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* 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 top.continew.starter.extension.crud.aop;
import org.aopalliance.aop.Advice;
import org.springframework.aop.Pointcut;
import org.springframework.aop.support.AbstractPointcutAdvisor;
import org.springframework.aop.support.ComposablePointcut;
import org.springframework.aop.support.annotation.AnnotationMatchingPointcut;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import java.lang.annotation.Annotation;
/**
* CRUD API 注解通知
*
* @author Charles7c
* @since 2.7.5
*/
public class CrudApiAnnotationAdvisor extends AbstractPointcutAdvisor implements BeanFactoryAware {
private final Advice advice;
private final Pointcut pointcut;
public CrudApiAnnotationAdvisor(CrudApiAnnotationInterceptor advice, Class<? extends Annotation> annotation) {
this.advice = advice;
this.pointcut = new ComposablePointcut(AnnotationMatchingPointcut.forMethodAnnotation(annotation));
}
@Override
public Pointcut getPointcut() {
return this.pointcut;
}
@Override
public Advice getAdvice() {
return this.advice;
}
@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
if (this.advice instanceof BeanFactoryAware beanFactoryAware) {
beanFactoryAware.setBeanFactory(beanFactory);
}
}
}

View File

@@ -0,0 +1,53 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* 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 top.continew.starter.extension.crud.aop;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.support.AopUtils;
import org.springframework.core.BridgeMethodResolver;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.util.ClassUtils;
import top.continew.starter.extension.crud.annotation.CrudApi;
import top.continew.starter.extension.crud.controller.AbstractBaseController;
import java.lang.reflect.Method;
import java.util.Objects;
/**
* CRUD API 注解拦截器
*
* @author Charles7c
* @since 2.7.5
*/
public class CrudApiAnnotationInterceptor implements MethodInterceptor {
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
// 获取目标类
Class<?> targetClass = AopUtils.getTargetClass(Objects.requireNonNull(invocation.getThis()));
// 获取目标方法
Method specificMethod = ClassUtils.getMostSpecificMethod(invocation.getMethod(), targetClass);
Method targetMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
// 获取 @CrudApi 注解
CrudApi crudApi = AnnotatedElementUtils.findMergedAnnotation(targetMethod, CrudApi.class);
// 执行处理
AbstractBaseController controller = (AbstractBaseController)invocation.getThis();
controller.preHandle(crudApi, invocation.getArguments(), targetMethod, targetClass);
return invocation.proceed();
}
}

View File

@@ -0,0 +1,56 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* 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 top.continew.starter.extension.crud.autoconfigure;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.format.support.FormattingConversionService;
import org.springframework.web.accept.ContentNegotiationManager;
import org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import org.springframework.web.servlet.resource.ResourceUrlProvider;
/**
* CRUD Request Mapping 自动配置
*
* @author Charles7c
* @since 1.0.0
*/
@Configuration
@EnableConfigurationProperties(CrudProperties.class)
public class CrudRequestMappingAutoConfiguration extends DelegatingWebMvcConfiguration {
/**
* CRUD 请求映射器处理器映射器(覆盖默认 RequestMappingHandlerMapping
*/
@Override
public RequestMappingHandlerMapping createRequestMappingHandlerMapping() {
return new CrudRequestMappingHandlerMapping();
}
@Bean
@Primary
@Override
public RequestMappingHandlerMapping requestMappingHandlerMapping(@Qualifier("mvcContentNegotiationManager") ContentNegotiationManager contentNegotiationManager,
@Qualifier("mvcConversionService") FormattingConversionService conversionService,
@Qualifier("mvcResourceUrlProvider") ResourceUrlProvider resourceUrlProvider) {
return super.requestMappingHandlerMapping(contentNegotiationManager, conversionService, resourceUrlProvider);
}
}

View File

@@ -53,7 +53,7 @@ public class CrudRequestMappingHandlerMapping extends RequestMappingHandlerMappi
// 过滤 API如果非本类中定义且 API 列表中不包含,则忽略
Api[] apiArr = crudRequestMapping.api();
Api api = ExceptionUtils.exToNull(() -> Api.valueOf(method.getName().toUpperCase()));
if (method.getDeclaringClass() != handlerType && !ArrayUtil.containsAny(apiArr, Api.ALL, api)) {
if (method.getDeclaringClass() != handlerType && !ArrayUtil.contains(apiArr, api)) {
return null;
}
// 拼接路径(合并了 @RequestMapping 的部分能力)

View File

@@ -19,44 +19,42 @@ package top.continew.starter.extension.crud.autoconfigure;
import jakarta.annotation.PostConstruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.format.support.FormattingConversionService;
import org.springframework.web.accept.ContentNegotiationManager;
import org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import org.springframework.web.servlet.resource.ResourceUrlProvider;
import top.continew.starter.extension.crud.annotation.CrudApi;
import top.continew.starter.extension.crud.aop.CrudApiAnnotationAdvisor;
import top.continew.starter.extension.crud.aop.CrudApiAnnotationInterceptor;
/**
* CRUD REST Controller 自动配置
*
* @author Charles7c
* @since 1.0.0
* @since 2.7.5
*/
@Configuration
@AutoConfiguration
@EnableConfigurationProperties(CrudProperties.class)
public class CrudRestControllerAutoConfiguration extends DelegatingWebMvcConfiguration {
public class CrudRestControllerAutoConfiguration {
private static final Logger log = LoggerFactory.getLogger(CrudRestControllerAutoConfiguration.class);
/**
* CRUD 请求映射器处理器映射器(覆盖默认 RequestMappingHandlerMapping
* CRUD API 注解通知
*/
@Override
public RequestMappingHandlerMapping createRequestMappingHandlerMapping() {
return new CrudRequestMappingHandlerMapping();
@Bean
@ConditionalOnMissingBean
public CrudApiAnnotationAdvisor crudApiAnnotationAdvisor(CrudApiAnnotationInterceptor crudApiAnnotationInterceptor) {
return new CrudApiAnnotationAdvisor(crudApiAnnotationInterceptor, CrudApi.class);
}
/**
* CRUD API 注解拦截器
*/
@Bean
@Primary
@Override
public RequestMappingHandlerMapping requestMappingHandlerMapping(@Qualifier("mvcContentNegotiationManager") ContentNegotiationManager contentNegotiationManager,
@Qualifier("mvcConversionService") FormattingConversionService conversionService,
@Qualifier("mvcResourceUrlProvider") ResourceUrlProvider resourceUrlProvider) {
return super.requestMappingHandlerMapping(contentNegotiationManager, conversionService, resourceUrlProvider);
@ConditionalOnMissingBean
public CrudApiAnnotationInterceptor crudApiAnnotationInterceptor() {
return new CrudApiAnnotationInterceptor();
}
@PostConstruct

View File

@@ -17,7 +17,7 @@
package top.continew.starter.extension.crud.autoconfigure;
import cn.hutool.core.lang.tree.TreeNodeConfig;
import top.continew.starter.core.util.validate.CheckUtils;
import top.continew.starter.core.validation.CheckUtils;
import top.continew.starter.extension.crud.annotation.TreeField;
/**
@@ -35,25 +35,21 @@ public class CrudTreeProperties {
/**
* 父 ID 字段名
*
*/
private String parentIdKey = "parentId";
/**
* 名称字段名
*
*/
private String nameKey = "name";
/**
* 排序字段名
*
*/
private String weightKey = "weight";
/**
* 子列表字段名
*
*/
private String childrenKey = "children";

View File

@@ -16,9 +16,7 @@
package top.continew.starter.extension.crud.controller;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.text.CharSequenceUtil;
import com.feiniaojin.gracefulresponse.api.ExcludeFromGracefulResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
@@ -27,31 +25,31 @@ import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.continew.starter.core.constant.StringConstants;
import top.continew.starter.extension.crud.annotation.CrudRequestMapping;
import top.continew.starter.extension.crud.annotation.CrudApi;
import top.continew.starter.extension.crud.enums.Api;
import top.continew.starter.extension.crud.handler.CrudApiHandler;
import top.continew.starter.extension.crud.model.query.PageQuery;
import top.continew.starter.extension.crud.model.query.SortQuery;
import top.continew.starter.extension.crud.model.req.BaseReq;
import top.continew.starter.extension.crud.model.resp.BaseIdResp;
import top.continew.starter.extension.crud.model.resp.PageResp;
import top.continew.starter.extension.crud.model.resp.BasePageResp;
import top.continew.starter.extension.crud.service.BaseService;
import top.continew.starter.extension.crud.util.ValidateGroup;
import top.continew.starter.extension.crud.validation.CrudValidationGroup;
import java.util.List;
/**
* 控制器基类
* 控制器抽象基类
*
* @param <S> 业务接口
* @param <L> 列表类型
* @param <D> 详情类型
* @param <Q> 查询条件
* @param <C> 创建或修改类型
* @param <C> 创建或修改参数类型
* @author Charles7c
* @since 1.0.0
*/
public abstract class BaseController<S extends BaseService<L, D, Q, C>, L, D, Q, C extends BaseReq> {
public abstract class AbstractBaseController<S extends BaseService<L, D, Q, C>, L, D, Q, C extends BaseReq> implements CrudApiHandler {
@Autowired
protected S baseService;
@@ -63,11 +61,11 @@ public abstract class BaseController<S extends BaseService<L, D, Q, C>, L, D, Q,
* @param pageQuery 分页查询条件
* @return 分页信息
*/
@CrudApi(Api.PAGE)
@Operation(summary = "分页查询列表", description = "分页查询列表")
@ResponseBody
@GetMapping
public PageResp<L> page(Q query, @Validated PageQuery pageQuery) {
this.checkPermission(Api.LIST);
public BasePageResp<L> page(Q query, @Validated PageQuery pageQuery) {
return baseService.page(query, pageQuery);
}
@@ -78,11 +76,11 @@ public abstract class BaseController<S extends BaseService<L, D, Q, C>, L, D, Q,
* @param sortQuery 排序查询条件
* @return 列表信息
*/
@CrudApi(Api.LIST)
@Operation(summary = "查询列表", description = "查询列表")
@ResponseBody
@GetMapping("/list")
public List<L> list(Q query, SortQuery sortQuery) {
this.checkPermission(Api.LIST);
return baseService.list(query, sortQuery);
}
@@ -93,11 +91,11 @@ public abstract class BaseController<S extends BaseService<L, D, Q, C>, L, D, Q,
* @param sortQuery 排序查询条件
* @return 树列表信息
*/
@CrudApi(Api.TREE)
@Operation(summary = "查询树列表", description = "查询树列表")
@ResponseBody
@GetMapping("/tree")
public List<Tree<Long>> tree(Q query, SortQuery sortQuery) {
this.checkPermission(Api.LIST);
return baseService.tree(query, sortQuery, false);
}
@@ -107,41 +105,41 @@ public abstract class BaseController<S extends BaseService<L, D, Q, C>, L, D, Q,
* @param id ID
* @return 详情信息
*/
@CrudApi(Api.DETAIL)
@Operation(summary = "查询详情", description = "查询详情")
@Parameter(name = "id", description = "ID", example = "1", in = ParameterIn.PATH)
@ResponseBody
@GetMapping("/{id}")
public D detail(@PathVariable("id") Long id) {
this.checkPermission(Api.DETAIL);
return baseService.get(id);
}
/**
* 新增
*
* @param req 创建信息
* @return 自增 ID
* @param req 创建参数
* @return ID
*/
@CrudApi(Api.ADD)
@Operation(summary = "新增数据", description = "新增数据")
@ResponseBody
@PostMapping
public BaseIdResp<Long> add(@Validated(ValidateGroup.Crud.Add.class) @RequestBody C req) {
this.checkPermission(Api.ADD);
return BaseIdResp.<Long>builder().id(baseService.add(req)).build();
public BaseIdResp<Long> add(@Validated(CrudValidationGroup.Add.class) @RequestBody C req) {
return new BaseIdResp<>(baseService.add(req));
}
/**
* 修改
*
* @param req 修改信息
* @param req 修改参数
* @param id ID
*/
@CrudApi(Api.UPDATE)
@Operation(summary = "修改数据", description = "修改数据")
@Parameter(name = "id", description = "ID", example = "1", in = ParameterIn.PATH)
@ResponseBody
@PutMapping("/{id}")
public void update(@Validated(ValidateGroup.Crud.Update.class) @RequestBody C req, @PathVariable("id") Long id) {
this.checkPermission(Api.UPDATE);
public void update(@Validated(CrudValidationGroup.Update.class) @RequestBody C req, @PathVariable("id") Long id) {
baseService.update(req, id);
}
@@ -150,12 +148,12 @@ public abstract class BaseController<S extends BaseService<L, D, Q, C>, L, D, Q,
*
* @param ids ID 列表
*/
@CrudApi(Api.DELETE)
@Operation(summary = "删除数据", description = "删除数据")
@Parameter(name = "ids", description = "ID 列表", example = "1,2", in = ParameterIn.PATH)
@ResponseBody
@DeleteMapping("/{ids}")
public void delete(@PathVariable("ids") List<Long> ids) {
this.checkPermission(Api.DELETE);
baseService.delete(ids);
}
@@ -166,24 +164,11 @@ public abstract class BaseController<S extends BaseService<L, D, Q, C>, L, D, Q,
* @param sortQuery 排序查询条件
* @param response 响应对象
*/
@CrudApi(Api.EXPORT)
@ExcludeFromGracefulResponse
@Operation(summary = "导出数据", description = "导出数据")
@GetMapping("/export")
public void export(Q query, SortQuery sortQuery, HttpServletResponse response) {
this.checkPermission(Api.EXPORT);
baseService.export(query, sortQuery, response);
}
/**
* 根据 API 类型进行权限验证
*
* @param api API 类型
*/
protected void checkPermission(Api api) {
CrudRequestMapping crudRequestMapping = this.getClass().getDeclaredAnnotation(CrudRequestMapping.class);
String path = crudRequestMapping.value();
String permissionPrefix = String.join(StringConstants.COLON, CharSequenceUtil
.splitTrim(path, StringConstants.SLASH));
StpUtil.checkPermission("%s:%s".formatted(permissionPrefix, api.name().toLowerCase()));
}
}

View File

@@ -24,11 +24,6 @@ package top.continew.starter.extension.crud.enums;
*/
public enum Api {
/**
* 所有 API
*/
ALL,
/**
* 分页
*/

View File

@@ -0,0 +1,41 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* 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 top.continew.starter.extension.crud.handler;
import top.continew.starter.extension.crud.annotation.CrudApi;
import java.lang.reflect.Method;
/**
* CRUD API 处理器
*
* @author Charles7c
* @since 2.7.5
*/
public interface CrudApiHandler {
/**
* 前置处理
*
* @param crudApi CRUD API 注解
* @param args 方法参数
* @param targetMethod 目标方法
* @param targetClass 目标类
* @throws Exception 处理异常
*/
void preHandle(CrudApi crudApi, Object[] args, Method targetMethod, Class<?> targetClass) throws Exception;
}

View File

@@ -21,7 +21,7 @@ import cn.hutool.core.util.ArrayUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import org.springframework.data.domain.Sort;
import top.continew.starter.core.constant.StringConstants;
import top.continew.starter.core.util.validate.ValidationUtils;
import top.continew.starter.core.validation.ValidationUtils;
import top.continew.starter.data.core.util.SqlInjectionUtils;
import java.io.Serial;

View File

@@ -20,7 +20,7 @@ import java.io.Serial;
import java.io.Serializable;
/**
* 请求基类
* 请求参数基类
*
* @author Charles7c
* @since 1.0.0

View File

@@ -42,27 +42,10 @@ public class BaseIdResp<T extends Serializable> implements Serializable {
this.id = id;
}
BaseIdResp(final T id) {
public BaseIdResp() {
}
public BaseIdResp(final T id) {
this.id = id;
}
public static <T extends Serializable> BaseIdRespBuilder<T> builder() {
return new BaseIdRespBuilder();
}
public static class BaseIdRespBuilder<T extends Serializable> {
private T id;
BaseIdRespBuilder() {
}
public BaseIdRespBuilder<T> id(final T id) {
this.id = id;
return this;
}
public BaseIdResp<T> build() {
return new BaseIdResp(this.id);
}
}
}

View File

@@ -29,7 +29,7 @@ import java.io.Serializable;
import java.time.LocalDateTime;
/**
* 响应基类
* 响应参数基类
*
* @author Charles7c
* @since 1.0.0

View File

@@ -20,8 +20,8 @@ import cn.hutool.core.lang.tree.Tree;
import jakarta.servlet.http.HttpServletResponse;
import top.continew.starter.extension.crud.model.query.PageQuery;
import top.continew.starter.extension.crud.model.query.SortQuery;
import top.continew.starter.extension.crud.model.resp.BasePageResp;
import top.continew.starter.extension.crud.model.resp.LabelValueResp;
import top.continew.starter.extension.crud.model.resp.PageResp;
import java.util.List;
@@ -31,7 +31,7 @@ import java.util.List;
* @param <L> 列表类型
* @param <D> 详情类型
* @param <Q> 查询条件
* @param <C> 创建或修改类型
* @param <C> 创建或修改参数类型
* @author Charles7c
* @since 1.0.0
*/
@@ -44,7 +44,7 @@ public interface BaseService<L, D, Q, C> {
* @param pageQuery 分页查询条件
* @return 分页列表信息
*/
PageResp<L> page(Q query, PageQuery pageQuery);
BasePageResp<L> page(Q query, PageQuery pageQuery);
/**
* 查询列表
@@ -90,7 +90,7 @@ public interface BaseService<L, D, Q, C> {
/**
* 新增
*
* @param req 创建信息
* @param req 创建参数
* @return 自增 ID
*/
Long add(C req);
@@ -98,7 +98,7 @@ public interface BaseService<L, D, Q, C> {
/**
* 修改
*
* @param req 修改信息
* @param req 修改参数
* @param id ID
*/
void update(C req, Long id);

View File

@@ -14,30 +14,25 @@
* limitations under the License.
*/
package top.continew.starter.extension.crud.util;
package top.continew.starter.extension.crud.validation;
import jakarta.validation.groups.Default;
/**
* 分组校验
* CRUD 分组校验
*
* @author Charles7c
* @since 1.0.0
*/
public interface ValidateGroup extends Default {
public interface CrudValidationGroup extends Default {
/**
* 分组校验-删改查
* CRUD 分组校验-
*/
interface Crud extends ValidateGroup {
/**
* 分组校验-创建
*/
interface Add extends Crud {}
interface Add extends CrudValidationGroup {}
/**
* 分组校验-修改
*/
interface Update extends Crud {}
}
/**
* CRUD 分组校验-修改
*/
interface Update extends CrudValidationGroup {}
}

View File

@@ -1,189 +0,0 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* 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 top.continew.starter.extension.crud.controller;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.text.CharSequenceUtil;
import com.feiniaojin.gracefulresponse.api.ExcludeFromGracefulResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.continew.starter.core.constant.StringConstants;
import top.continew.starter.extension.crud.annotation.CrudRequestMapping;
import top.continew.starter.extension.crud.enums.Api;
import top.continew.starter.extension.crud.model.query.PageQuery;
import top.continew.starter.extension.crud.model.query.SortQuery;
import top.continew.starter.extension.crud.model.req.BaseReq;
import top.continew.starter.extension.crud.model.resp.BaseIdResp;
import top.continew.starter.extension.crud.model.resp.PageResp;
import top.continew.starter.extension.crud.service.BaseService;
import top.continew.starter.extension.crud.util.ValidateGroup;
import java.util.List;
/**
* 控制器基类
*
* @param <S> 业务接口
* @param <L> 列表类型
* @param <D> 详情类型
* @param <Q> 查询条件
* @param <C> 创建或修改类型
* @author Charles7c
* @since 1.0.0
*/
public abstract class BaseController<S extends BaseService<L, D, Q, C>, L, D, Q, C extends BaseReq> {
@Autowired
protected S baseService;
/**
* 分页查询列表
*
* @param query 查询条件
* @param pageQuery 分页查询条件
* @return 分页信息
*/
@Operation(summary = "分页查询列表", description = "分页查询列表")
@ResponseBody
@GetMapping
public PageResp<L> page(Q query, @Validated PageQuery pageQuery) {
this.checkPermission(Api.LIST);
return baseService.page(query, pageQuery);
}
/**
* 查询列表
*
* @param query 查询条件
* @param sortQuery 排序查询条件
* @return 列表信息
*/
@Operation(summary = "查询列表", description = "查询列表")
@ResponseBody
@GetMapping("/list")
public List<L> list(Q query, SortQuery sortQuery) {
this.checkPermission(Api.LIST);
return baseService.list(query, sortQuery);
}
/**
* 查询树列表
*
* @param query 查询条件
* @param sortQuery 排序查询条件
* @return 树列表信息
*/
@Operation(summary = "查询树列表", description = "查询树列表")
@ResponseBody
@GetMapping("/tree")
public List<Tree<Long>> tree(Q query, SortQuery sortQuery) {
this.checkPermission(Api.LIST);
return baseService.tree(query, sortQuery, false);
}
/**
* 查询详情
*
* @param id ID
* @return 详情信息
*/
@Operation(summary = "查询详情", description = "查询详情")
@Parameter(name = "id", description = "ID", example = "1", in = ParameterIn.PATH)
@ResponseBody
@GetMapping("/{id}")
public D detail(@PathVariable("id") Long id) {
this.checkPermission(Api.DETAIL);
return baseService.get(id);
}
/**
* 新增
*
* @param req 创建信息
* @return 自增 ID
*/
@Operation(summary = "新增数据", description = "新增数据")
@ResponseBody
@PostMapping
public BaseIdResp<Long> add(@Validated(ValidateGroup.Crud.Add.class) @RequestBody C req) {
this.checkPermission(Api.ADD);
return BaseIdResp.<Long>builder().id(baseService.add(req)).build();
}
/**
* 修改
*
* @param req 修改信息
* @param id ID
*/
@Operation(summary = "修改数据", description = "修改数据")
@Parameter(name = "id", description = "ID", example = "1", in = ParameterIn.PATH)
@ResponseBody
@PutMapping("/{id}")
public void update(@Validated(ValidateGroup.Crud.Update.class) @RequestBody C req, @PathVariable("id") Long id) {
this.checkPermission(Api.UPDATE);
baseService.update(req, id);
}
/**
* 删除
*
* @param ids ID 列表
*/
@Operation(summary = "删除数据", description = "删除数据")
@Parameter(name = "ids", description = "ID 列表", example = "1,2", in = ParameterIn.PATH)
@ResponseBody
@DeleteMapping("/{ids}")
public void delete(@PathVariable("ids") List<Long> ids) {
this.checkPermission(Api.DELETE);
baseService.delete(ids);
}
/**
* 导出
*
* @param query 查询条件
* @param sortQuery 排序查询条件
* @param response 响应对象
*/
@ExcludeFromGracefulResponse
@Operation(summary = "导出数据", description = "导出数据")
@GetMapping("/export")
public void export(Q query, SortQuery sortQuery, HttpServletResponse response) {
this.checkPermission(Api.EXPORT);
baseService.export(query, sortQuery, response);
}
/**
* 根据 API 类型进行权限验证
*
* @param api API 类型
*/
protected void checkPermission(Api api) {
CrudRequestMapping crudRequestMapping = this.getClass().getDeclaredAnnotation(CrudRequestMapping.class);
String path = crudRequestMapping.value();
String permissionPrefix = String.join(StringConstants.COLON, CharSequenceUtil
.splitTrim(path, StringConstants.SLASH));
StpUtil.checkPermission("%s:%s".formatted(permissionPrefix, api.name().toLowerCase()));
}
}

View File

@@ -1,120 +0,0 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* 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 top.continew.starter.extension.crud.service;
import cn.hutool.core.lang.tree.Tree;
import jakarta.servlet.http.HttpServletResponse;
import top.continew.starter.extension.crud.model.query.PageQuery;
import top.continew.starter.extension.crud.model.query.SortQuery;
import top.continew.starter.extension.crud.model.resp.LabelValueResp;
import top.continew.starter.extension.crud.model.resp.PageResp;
import java.util.List;
/**
* 业务接口基类
*
* @param <L> 列表类型
* @param <D> 详情类型
* @param <Q> 查询条件
* @param <C> 创建或修改类型
* @author Charles7c
* @since 1.0.0
*/
public interface BaseService<L, D, Q, C> {
/**
* 分页查询列表
*
* @param query 查询条件
* @param pageQuery 分页查询条件
* @return 分页列表信息
*/
PageResp<L> page(Q query, PageQuery pageQuery);
/**
* 查询列表
*
* @param query 查询条件
* @param sortQuery 排序查询条件
* @return 列表信息
*/
List<L> list(Q query, SortQuery sortQuery);
/**
* 查询树列表
* <p>
* 虽然提供了查询条件,但不建议使用,容易因缺失根节点导致树节点丢失。
* 建议在前端进行查询过滤,如需使用建议重写方法。
* </p>
*
* @param query 查询条件
* @param sortQuery 排序查询条件
* @param isSimple 是否为简单树结构(不包含基本树结构之外的扩展字段,简单树(下拉列表)使用全局配置结构,复杂树(表格)使用 @DictField 局部配置)
* @return 树列表信息
*/
List<Tree<Long>> tree(Q query, SortQuery sortQuery, boolean isSimple);
/**
* 查看详情
*
* @param id ID
* @return 详情信息
*/
D get(Long id);
/**
* 查询字典列表
*
* @param query 查询条件
* @param sortQuery 排序查询条件
* @return 字典列表信息
*/
List<LabelValueResp> listDict(Q query, SortQuery sortQuery);
/**
* 新增
*
* @param req 创建信息
* @return 自增 ID
*/
Long add(C req);
/**
* 修改
*
* @param req 修改信息
* @param id ID
*/
void update(C req, Long id);
/**
* 删除
*
* @param ids ID 列表
*/
void delete(List<Long> ids);
/**
* 导出
*
* @param query 查询条件
* @param sortQuery 排序查询条件
* @param response 响应对象
*/
void export(Q query, SortQuery sortQuery, HttpServletResponse response);
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.continew.starter.extension.crud.service.impl;
package top.continew.starter.extension.crud.service;
import cn.crane4j.core.support.OperateTemplate;
import cn.hutool.core.bean.BeanUtil;
@@ -29,12 +29,11 @@ import cn.hutool.extra.spring.SpringUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.data.domain.Sort;
import org.springframework.transaction.annotation.Transactional;
import top.continew.starter.core.constant.StringConstants;
import top.continew.starter.core.util.ReflectUtils;
import top.continew.starter.core.util.validate.ValidationUtils;
import top.continew.starter.core.validation.ValidationUtils;
import top.continew.starter.data.mf.base.BaseMapper;
import top.continew.starter.data.mf.service.impl.ServiceImpl;
import top.continew.starter.data.mf.util.QueryWrapperHelper;
@@ -45,7 +44,6 @@ import top.continew.starter.extension.crud.model.entity.BaseIdDO;
import top.continew.starter.extension.crud.model.query.PageQuery;
import top.continew.starter.extension.crud.model.query.SortQuery;
import top.continew.starter.extension.crud.model.resp.PageResp;
import top.continew.starter.extension.crud.service.BaseService;
import top.continew.starter.file.excel.util.ExcelUtils;
import java.lang.reflect.Field;
@@ -61,7 +59,7 @@ import java.util.Optional;
* @param <L> 列表类型
* @param <D> 详情类型
* @param <Q> 查询条件
* @param <C> 创建或修改类型
* @param <C> 创建或修改参数类型
* @author Charles7c
* @since 1.0.0
*/

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.continew.starter.extension.crud.service.impl;
package top.continew.starter.extension.crud.service;
import cn.crane4j.core.support.OperateTemplate;
import cn.hutool.core.bean.BeanUtil;
@@ -37,8 +37,8 @@ import org.springframework.transaction.annotation.Transactional;
import top.continew.starter.core.constant.StringConstants;
import top.continew.starter.core.util.ClassUtils;
import top.continew.starter.core.util.ReflectUtils;
import top.continew.starter.core.util.validate.CheckUtils;
import top.continew.starter.core.util.validate.ValidationUtils;
import top.continew.starter.core.validation.CheckUtils;
import top.continew.starter.core.validation.ValidationUtils;
import top.continew.starter.data.mp.base.BaseMapper;
import top.continew.starter.data.mp.service.impl.ServiceImpl;
import top.continew.starter.data.mp.util.QueryWrapperHelper;
@@ -51,7 +51,6 @@ import top.continew.starter.extension.crud.model.query.PageQuery;
import top.continew.starter.extension.crud.model.query.SortQuery;
import top.continew.starter.extension.crud.model.resp.LabelValueResp;
import top.continew.starter.extension.crud.model.resp.PageResp;
import top.continew.starter.extension.crud.service.BaseService;
import top.continew.starter.file.excel.util.ExcelUtils;
import java.lang.reflect.Field;
@@ -65,7 +64,7 @@ import java.util.*;
* @param <L> 列表类型
* @param <D> 详情类型
* @param <Q> 查询条件
* @param <C> 创建或修改类型
* @param <C> 创建或修改参数类型
* @author Charles7c
* @since 1.0.0
*/

View File

@@ -117,8 +117,8 @@ public class DefaultDataPermissionHandler implements DataPermissionHandler {
* 构建本部门及以下数据权限表达式
*
* <p>
* 处理完后的 SQL 示例:<br /> select t1.* from table as t1 where t1.dept_id in (select id from sys_dept where id =
* xxx or find_in_set(xxx, ancestors));
* 处理完后的 SQL 示例:<br /> select t1.* from table as t1 where t1.dept_id in (select id from sys_dept where id = xxx or
* find_in_set(xxx, ancestors));
* </p>
*
* @param dataPermission 数据权限
@@ -194,8 +194,8 @@ public class DefaultDataPermissionHandler implements DataPermissionHandler {
* 构建自定义数据权限表达式
*
* <p>
* 处理完后的 SQL 示例:<br /> select t1.* from table as t1 where t1.dept_id in (select dept_id from sys_role_dept
* where role_id = xxx);
* 处理完后的 SQL 示例:<br /> select t1.* from table as t1 where t1.dept_id in (select dept_id from sys_role_dept where
* role_id = xxx);
* </p>
*
* @param dataPermission 数据权限

View File

@@ -17,7 +17,7 @@
package top.continew.starter.file.excel.converter;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.text.CharSequenceUtil;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
@@ -57,7 +57,7 @@ public class ExcelListConverter implements Converter<List> {
ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
String stringValue = cellData.getStringValue();
return StrUtil.split(stringValue, StringConstants.COMMA);
return CharSequenceUtil.split(stringValue, StringConstants.COMMA);
}
@Override

View File

@@ -16,6 +16,7 @@
package top.continew.starter.json.jackson.serializer;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ClassUtil;
import cn.hutool.core.util.ReflectUtil;
import com.fasterxml.jackson.core.JsonParser;
@@ -26,6 +27,7 @@ import top.continew.starter.core.enums.BaseEnum;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Objects;
/**
* 枚举接口 BaseEnum 反序列化器
@@ -66,7 +68,7 @@ public class BaseEnumDeserializer extends JsonDeserializer<BaseEnum> {
for (Object enumConstant : enumConstants) {
if (ClassUtil.isAssignable(BaseEnum.class, fieldTypeClass)) {
BaseEnum baseEnum = (BaseEnum)enumConstant;
if (baseEnum.getValue().equals(Integer.valueOf(value))) {
if (Objects.equals(Convert.toStr(baseEnum.getValue()), Convert.toStr(value))) {
return baseEnum;
}
}

View File

@@ -17,7 +17,7 @@
package top.continew.starter.messaging.mail.core;
import cn.hutool.core.map.MapUtil;
import top.continew.starter.core.util.validate.ValidationUtils;
import top.continew.starter.core.validation.ValidationUtils;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

View File

@@ -17,7 +17,7 @@
package top.continew.starter.messaging.mail.core;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import top.continew.starter.core.util.validate.ValidationUtils;
import top.continew.starter.core.validation.ValidationUtils;
/**
* 邮件配置

View File

@@ -33,7 +33,7 @@ import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.crypto.password.Pbkdf2PasswordEncoder;
import org.springframework.security.crypto.scrypt.SCryptPasswordEncoder;
import top.continew.starter.core.constant.PropertiesConstants;
import top.continew.starter.core.util.validate.CheckUtils;
import top.continew.starter.core.validation.CheckUtils;
import java.util.HashMap;
import java.util.List;

View File

@@ -18,7 +18,6 @@ package top.continew.starter.web.autoconfigure.mvc;
import org.springframework.core.convert.converter.Converter;
import top.continew.starter.core.enums.BaseEnum;
import top.continew.starter.core.util.validate.ValidationUtils;
import java.util.HashMap;
import java.util.Map;
@@ -42,8 +41,6 @@ public class BaseEnumConverter<T extends BaseEnum> implements Converter<String,
@Override
public T convert(String source) {
T t = enumMap.get(source);
ValidationUtils.throwIfNull(t, "枚举值非法:{}", source);
return t;
return enumMap.get(source);
}
}