From eb2d0e02a84419503cded2c53d67475543e4648f Mon Sep 17 00:00:00 2001 From: Odboy Date: Sat, 24 Jan 2026 09:50:13 +0800 Subject: [PATCH] =?UTF-8?q?refactor(util):=20=E7=A7=BB=E9=99=A4=E5=BA=9F?= =?UTF-8?q?=E5=BC=83=E7=B1=BB=E5=B9=B6=E4=BC=98=E5=8C=96=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删除 TaskTemplateInfoVo 类 - 删除 ServerException 类 - 删除 KitDistributedIdUtil 类 - 删除 SystemQuartzJobVo 类 - 在 KitBigDecimalUtil 中新增格式化金额方法 - 在 KitDateUtil 中新增获取周几方法 - 在 KitCollUtil 中修复空集合验证逻辑 - 移除 KitStringUtil 中的日期相关代码 - 在 KitValidUtil 中新增多种验证方法 - 修改 SystemMenuController 中的菜单保存逻辑 - 优化 SystemQuartzJobController 中的定时任务操作方法 - 为 SystemQuartzJobTb 添加扩展字段 uuid --- .../exception/BadRequestException.java | 4 +- .../framework/exception/ServerException.java | 4 +- .../framework/exception/handler/ApiError.java | 3 - .../handler/GlobalExceptionHandler.java | 5 +- .../framework/properties/AppProperties.java | 52 ++++++++ .../properties/model/CaptchaModel.java | 15 +-- .../model/ContentRsaEncodeSettingModel.java | 30 +++++ .../properties/model/JwtAuthSettingModel.java | 45 +++++++ .../properties/model/OSSConfigModel.java | 42 ++++++ .../properties/model/StorageOSSModel.java | 30 +++++ .../model/SwaggerApiDocSettingModel.java | 31 +++++ .../model/ThreadPoolSettingModel.java | 48 +++++++ .../model/UserLoginCaptchaSettingModel.java | 126 ++++++++++++++++++ .../model/UserLoginSettingModel.java | 36 +++++ .../java/cn/odboy/util/KitAnonTagUtil.java | 40 +++--- .../cn/odboy/util/KitBase64SecretUtil.java | 2 +- .../main/java/cn/odboy/util/KitBeanUtil.java | 2 +- .../java/cn/odboy/util/KitBigDecimalUtil.java | 20 ++- .../java/cn/odboy/util/KitBrowserUtil.java | 6 +- .../main/java/cn/odboy/util/KitClassUtil.java | 2 +- .../main/java/cn/odboy/util/KitCloseUtil.java | 2 +- .../main/java/cn/odboy/util/KitCollUtil.java | 6 +- .../main/java/cn/odboy/util/KitDateUtil.java | 21 ++- .../java/cn/odboy/util/KitDesEncryptUtil.java | 4 +- .../main/java/cn/odboy/util/KitFileUtil.java | 19 ++- .../main/java/cn/odboy/util/KitIPUtil.java | 6 +- .../main/java/cn/odboy/util/KitJsonUtil.java | 2 +- .../main/java/cn/odboy/util/KitListUtil.java | 4 +- .../main/java/cn/odboy/util/KitPageUtil.java | 2 +- .../odboy/util/KitReturnValueHandleUtil.java | 4 +- .../java/cn/odboy/util/KitRsaEncryptUtil.java | 6 +- .../java/cn/odboy/util/KitStringUtil.java | 17 --- .../java/cn/odboy/util/KitThreadUtil.java | 17 +++ .../main/java/cn/odboy/util/KitValidUtil.java | 126 +++++++++++++++--- .../cn/odboy/util/xlsx/KitExcelExporter.java | 2 +- .../cn/odboy/util/xlsx/KitXlsxExportUtil.java | 4 +- .../system/application/CuteDeptTreeApi.java | 15 +++ .../system/application/CuteFileUploadApi.java | 15 +++ .../application/CuteProductLineSelectApi.java | 15 +++ .../CuteProductLineSelectProApi.java | 15 +++ .../system/application/CuteUserSelectApi.java | 15 +++ .../application/model/CuteDeptTreeVo.java | 15 +++ .../application/model/CuteUserSelectVo.java | 15 +++ .../application/service/CuteBaseService.java | 15 +++ .../service/CuteDeptTreeService.java | 15 +++ .../service/CuteFileUploadService.java | 15 +++ .../CuteProductLineSelectProService.java | 15 +++ .../service/CuteProductLineSelectService.java | 15 +++ .../service/CuteUserSelectService.java | 15 +++ .../controller/SystemMenuController.java | 4 - .../controller/SystemQuartzJobController.java | 11 +- .../system/dal/dataobject/SystemDeptTb.java | 2 +- .../dal/dataobject/SystemQuartzJobTb.java | 6 + .../dal/model/response/SystemQuartzJobVo.java | 55 -------- .../config/SpringSecurityConfig.java | 21 ++- .../permission/config/TokenConfigurer.java | 42 ------ .../core/handler/UserDetailsHandler.java | 4 +- .../framework/quartz/ActiveJobRegister.java | 7 +- .../framework/quartz/ExecutionJobBean.java | 17 +-- .../system/framework/quartz/QuartzManage.java | 25 ++-- .../system/service/SystemAuthService.java | 17 +-- .../system/service/SystemCaptchaService.java | 14 +- .../system/service/SystemDataService.java | 4 +- .../system/service/SystemDeptService.java | 33 ++--- .../service/SystemDictDetailService.java | 16 +-- .../system/service/SystemDictService.java | 8 +- .../system/service/SystemEmailService.java | 33 ++--- .../system/service/SystemJobService.java | 39 ++---- .../service/SystemLocalStorageService.java | 23 ++-- .../system/service/SystemMenuService.java | 52 +++----- .../system/service/SystemMonitorService.java | 12 +- .../service/SystemOperationLogService.java | 2 +- .../service/SystemQuartzJobService.java | 74 +++++----- .../system/service/SystemRoleDeptService.java | 8 +- .../system/service/SystemRoleMenuService.java | 12 +- .../system/service/SystemRoleService.java | 45 ++----- .../system/service/SystemUserDeptService.java | 2 +- .../system/service/SystemUserJobService.java | 8 +- .../system/service/SystemUserRoleService.java | 18 +-- .../system/service/SystemUserService.java | 102 +++++--------- .../impl/SystemMinioStorageServiceImpl.java | 7 +- .../java/cn/odboy/util/KitBigDecimalUtil.java | 18 +++ .../main/java/cn/odboy/util/KitCollUtil.java | 4 +- .../main/java/cn/odboy/util/KitDateUtil.java | 19 +++ .../java/cn/odboy/util/KitStringUtil.java | 17 --- .../java/cn/odboy/util/KitThreadUtil.java | 17 +++ .../main/java/cn/odboy/util/KitValidUtil.java | 118 ++++++++++++++-- .../system/application/CuteDeptTreeApi.java | 15 +++ .../system/application/CuteFileUploadApi.java | 15 +++ .../application/CuteProductLineSelectApi.java | 15 +++ .../CuteProductLineSelectProApi.java | 15 +++ .../system/application/CuteUserSelectApi.java | 15 +++ .../application/model/CuteDeptTreeVo.java | 15 +++ .../application/model/CuteUserSelectVo.java | 15 +++ .../application/service/CuteBaseService.java | 15 +++ .../service/CuteDeptTreeService.java | 15 +++ .../service/CuteFileUploadService.java | 15 +++ .../CuteProductLineSelectProService.java | 15 +++ .../service/CuteProductLineSelectService.java | 15 +++ .../service/CuteUserSelectService.java | 15 +++ .../controller/SystemMenuController.java | 3 - .../controller/SystemQuartzJobController.java | 11 +- .../dal/dataobject/SystemQuartzJobTb.java | 6 + .../dal/model/response/SystemQuartzJobVo.java | 55 -------- .../framework/quartz/ActiveJobRegister.java | 5 +- .../framework/quartz/ExecutionJobBean.java | 9 +- .../system/framework/quartz/QuartzManage.java | 23 ++-- .../system/service/SystemAuthService.java | 16 +-- .../system/service/SystemCaptchaService.java | 18 +-- .../system/service/SystemDataService.java | 4 +- .../system/service/SystemDeptService.java | 39 ++---- .../service/SystemDictDetailService.java | 16 +-- .../system/service/SystemDictService.java | 8 +- .../system/service/SystemEmailService.java | 35 ++--- .../system/service/SystemJobService.java | 47 +++---- .../service/SystemLocalStorageService.java | 33 ++--- .../system/service/SystemMenuService.java | 62 ++++----- .../system/service/SystemMonitorService.java | 12 +- .../service/SystemOperationLogService.java | 2 +- .../service/SystemQuartzJobService.java | 84 +++++------- .../system/service/SystemRoleDeptService.java | 8 +- .../system/service/SystemRoleMenuService.java | 12 +- .../system/service/SystemRoleService.java | 53 +++----- .../system/service/SystemUserDeptService.java | 2 +- .../system/service/SystemUserJobService.java | 8 +- .../system/service/SystemUserRoleService.java | 18 +-- .../system/service/SystemUserService.java | 110 ++++++--------- .../impl/SystemMinioStorageServiceImpl.java | 13 +- .../java/cn/odboy/util/KitDateUtilTest.java | 31 +++++ 129 files changed, 1757 insertions(+), 1077 deletions(-) create mode 100644 cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/AppProperties.java rename cutejava/cutejava-module-task-v2/src/main/java/cn/odboy/task/dal/model/TaskTemplateInfoVo.java => cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/model/CaptchaModel.java (70%) create mode 100644 cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/model/ContentRsaEncodeSettingModel.java create mode 100644 cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/model/JwtAuthSettingModel.java create mode 100644 cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/model/OSSConfigModel.java create mode 100644 cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/model/StorageOSSModel.java create mode 100644 cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/model/SwaggerApiDocSettingModel.java create mode 100644 cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/model/ThreadPoolSettingModel.java create mode 100644 cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/model/UserLoginCaptchaSettingModel.java create mode 100644 cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/model/UserLoginSettingModel.java create mode 100644 cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitThreadUtil.java delete mode 100644 cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/model/response/SystemQuartzJobVo.java delete mode 100644 cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/permission/config/TokenConfigurer.java create mode 100644 cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitThreadUtil.java delete mode 100644 cutejava/cutejava-module-system/src/main/java/cn/odboy/system/dal/model/response/SystemQuartzJobVo.java create mode 100644 cutejava/cutejava-starter/src/test/java/cn/odboy/util/KitDateUtilTest.java diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/exception/BadRequestException.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/exception/BadRequestException.java index 61ae92e1..186d739e 100644 --- a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/exception/BadRequestException.java +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/exception/BadRequestException.java @@ -13,13 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package cn.odboy.framework.exception; -import static org.springframework.http.HttpStatus.BAD_REQUEST; - import lombok.Getter; import org.springframework.http.HttpStatus; +import static org.springframework.http.HttpStatus.BAD_REQUEST; /** * 统一异常处理 diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/exception/ServerException.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/exception/ServerException.java index f3ad92d6..d7304d59 100644 --- a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/exception/ServerException.java +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/exception/ServerException.java @@ -13,13 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package cn.odboy.framework.exception; -import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; - import lombok.Getter; import org.springframework.http.HttpStatus; +import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; @Getter public class ServerException extends RuntimeException { diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/exception/handler/ApiError.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/exception/handler/ApiError.java index 2ce5221b..e043bbcf 100644 --- a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/exception/handler/ApiError.java +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/exception/handler/ApiError.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package cn.odboy.framework.exception.handler; import lombok.Data; @@ -42,5 +41,3 @@ public final class ApiError { return apiError; } } - - diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/exception/handler/GlobalExceptionHandler.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/exception/handler/GlobalExceptionHandler.java index 7906ae27..85acc5e1 100644 --- a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/exception/handler/GlobalExceptionHandler.java +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/exception/handler/GlobalExceptionHandler.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package cn.odboy.framework.exception.handler; import cn.hutool.core.exceptions.ExceptionUtil; @@ -77,8 +76,8 @@ public class GlobalExceptionHandler { log.error(ExceptionUtil.stacktraceToString(e)); ObjectError objectError = e.getBindingResult().getAllErrors().get(0); String message = objectError.getDefaultMessage(); - if (objectError instanceof FieldError fieldError) { - message = fieldError.getField() + ": " + message; + if (objectError instanceof FieldError) { + message = ((FieldError) objectError).getField() + ": " + message; } return buildResponseEntity(ApiError.error(message)); } diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/AppProperties.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/AppProperties.java new file mode 100644 index 00000000..38b95335 --- /dev/null +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/AppProperties.java @@ -0,0 +1,52 @@ +/* + * 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.framework.properties; + +import cn.odboy.framework.properties.model.CaptchaModel; +import cn.odboy.framework.properties.model.ContentRsaEncodeSettingModel; +import cn.odboy.framework.properties.model.JwtAuthSettingModel; +import cn.odboy.framework.properties.model.StorageOSSModel; +import cn.odboy.framework.properties.model.SwaggerApiDocSettingModel; +import cn.odboy.framework.properties.model.ThreadPoolSettingModel; +import cn.odboy.framework.properties.model.UserLoginSettingModel; +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; +import java.util.List; + +/** + * 应用配置 + * + * @author odboy + * @date 2025-04-13 + */ +@Data +@Component +@ConfigurationProperties(prefix = "app") +public class AppProperties { + + private ContentRsaEncodeSettingModel rsa; + private JwtAuthSettingModel jwt; + private UserLoginSettingModel login; + private SwaggerApiDocSettingModel swagger; + private ThreadPoolSettingModel asyncTaskPool; + private CaptchaModel captcha; + private StorageOSSModel oss; + /** + * 自动识别json对象白名单配置(仅允许解析的包名, 范围越小越安全)
未配置可能导致, 登录失败, 反复登录等问题 + */ + private List serialWhiteList; +} diff --git a/cutejava/cutejava-module-task-v2/src/main/java/cn/odboy/task/dal/model/TaskTemplateInfoVo.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/model/CaptchaModel.java similarity index 70% rename from cutejava/cutejava-module-task-v2/src/main/java/cn/odboy/task/dal/model/TaskTemplateInfoVo.java rename to cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/model/CaptchaModel.java index a89a7a6c..ae015b1d 100644 --- a/cutejava/cutejava-module-task-v2/src/main/java/cn/odboy/task/dal/model/TaskTemplateInfoVo.java +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/model/CaptchaModel.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package cn.odboy.task.dal.model; +package cn.odboy.framework.properties.model; import cn.odboy.base.KitObject; import lombok.Getter; @@ -21,13 +21,10 @@ import lombok.Setter; @Getter @Setter -public class TaskTemplateInfoVo extends KitObject { +public class CaptchaModel extends KitObject { - private String changeType; - private String name; - private String description; - private String envAlias; - private String language; - private String contextName; - private String templateInfo; + /** + * 验证码有效时间, 单位: 秒 + */ + private Long expireTime; } diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/model/ContentRsaEncodeSettingModel.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/model/ContentRsaEncodeSettingModel.java new file mode 100644 index 00000000..a22c3dd9 --- /dev/null +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/model/ContentRsaEncodeSettingModel.java @@ -0,0 +1,30 @@ +/* + * 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.framework.properties.model; + +import cn.odboy.base.KitObject; +import lombok.Getter; +import lombok.Setter; + +/** + * 密码加密传输, 前端公钥加密,后端私钥解密 + */ +@Getter +@Setter +public class ContentRsaEncodeSettingModel extends KitObject { + + private String privateKey; +} diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/model/JwtAuthSettingModel.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/model/JwtAuthSettingModel.java new file mode 100644 index 00000000..4388d431 --- /dev/null +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/model/JwtAuthSettingModel.java @@ -0,0 +1,45 @@ +/* + * 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.framework.properties.model; + +import cn.odboy.base.KitObject; +import lombok.Getter; +import lombok.Setter; + +/** + * Jwt参数配置 + */ +@Getter +@Setter +public class JwtAuthSettingModel extends KitObject { + + /** + * 必须使用最少88位的Base64对该令牌进行编码 + */ + private String base64Secret; + /** + * 令牌过期时间 此处单位/毫秒 + */ + private Long tokenValidityInSeconds; + /** + * token 续期检查 + */ + private Long detect; + /** + * 续期时间 + */ + private Long renew; +} diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/model/OSSConfigModel.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/model/OSSConfigModel.java new file mode 100644 index 00000000..41373388 --- /dev/null +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/model/OSSConfigModel.java @@ -0,0 +1,42 @@ +/* + * 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.framework.properties.model; + +import cn.odboy.base.KitObject; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class OSSConfigModel extends KitObject { + + /** + * 服务地址 + */ + private String endpoint; + /** + * 存储桶名称 + */ + private String bucketName; + /** + * Access Key + */ + private String accessKey; + /** + * Secret Key + */ + private String secretKey; +} diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/model/StorageOSSModel.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/model/StorageOSSModel.java new file mode 100644 index 00000000..0a2e4296 --- /dev/null +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/model/StorageOSSModel.java @@ -0,0 +1,30 @@ +/* + * 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.framework.properties.model; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class StorageOSSModel { + + /** + * 上传大小, 单位: M + */ + private Long maxSize; + private OSSConfigModel minio; +} diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/model/SwaggerApiDocSettingModel.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/model/SwaggerApiDocSettingModel.java new file mode 100644 index 00000000..95006ae9 --- /dev/null +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/model/SwaggerApiDocSettingModel.java @@ -0,0 +1,31 @@ +/* + * 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.framework.properties.model; + +import cn.odboy.base.KitObject; +import lombok.Getter; +import lombok.Setter; + +/** + * @author odboy + * @date 2025-04-13 + */ +@Getter +@Setter +public class SwaggerApiDocSettingModel extends KitObject { + + private Boolean enabled; +} diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/model/ThreadPoolSettingModel.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/model/ThreadPoolSettingModel.java new file mode 100644 index 00000000..067a5833 --- /dev/null +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/model/ThreadPoolSettingModel.java @@ -0,0 +1,48 @@ +/* + * 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.framework.properties.model; + +import cn.odboy.base.KitObject; +import lombok.Getter; +import lombok.Setter; + +/** + * 线程池 配置 + * + * @author odboy + * @date 2025-04-13 + */ +@Getter +@Setter +public class ThreadPoolSettingModel extends KitObject { + + /** + * 核心线程池大小 + */ + private int corePoolSize; + /** + * 最大线程数 + */ + private int maxPoolSize; + /** + * 活跃时间 + */ + private int keepAliveSeconds; + /** + * 队列容量 + */ + private int queueCapacity; +} diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/model/UserLoginCaptchaSettingModel.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/model/UserLoginCaptchaSettingModel.java new file mode 100644 index 00000000..ad5fd417 --- /dev/null +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/model/UserLoginCaptchaSettingModel.java @@ -0,0 +1,126 @@ +/* + * 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.framework.properties.model; + +import cn.hutool.core.util.StrUtil; +import cn.odboy.base.KitObject; +import cn.odboy.constant.CaptchaCodeEnum; +import cn.odboy.framework.exception.BadRequestException; +import com.wf.captcha.ArithmeticCaptcha; +import com.wf.captcha.ChineseCaptcha; +import com.wf.captcha.ChineseGifCaptcha; +import com.wf.captcha.GifCaptcha; +import com.wf.captcha.SpecCaptcha; +import com.wf.captcha.base.Captcha; +import lombok.Getter; +import lombok.Setter; +import java.awt.*; + +/** + * 验证码配置 + * + * @author odboy + */ +@Getter +@Setter +public class UserLoginCaptchaSettingModel extends KitObject { + + private CaptchaCodeEnum codeType; + /** + * 验证码有效期 分钟 + */ + private Long expiration = 5L; + /** + * 验证码内容长度 + */ + private int length = 4; + /** + * 验证码宽度 + */ + private int width = 111; + /** + * 验证码高度 + */ + private int height = 36; + /** + * 验证码字体 + */ + private String fontName; + /** + * 字体大小 + */ + private int fontSize = 25; + + /** + * 依据配置信息生产验证码 + * + * @return / + */ + public Captcha getCaptcha() { + Captcha captcha; + switch (codeType) { + case ARITHMETIC: + // 算术类型 https://gitee.com/whvse/EasyCaptcha + captcha = new FixedArithmeticCaptcha(width, height); + // 几位数运算, 默认是两位 + captcha.setLen(length); + break; + case CHINESE: + captcha = new ChineseCaptcha(width, height); + captcha.setLen(length); + break; + case CHINESE_GIF: + captcha = new ChineseGifCaptcha(width, height); + captcha.setLen(length); + break; + case GIF: + captcha = new GifCaptcha(width, height); + captcha.setLen(length); + break; + case SPEC: + captcha = new SpecCaptcha(width, height); + captcha.setLen(length); + break; + default: + throw new BadRequestException("验证码配置信息错误!正确配置查看 LoginCodeEnum "); + } + if (StrUtil.isNotBlank(fontName)) { + captcha.setFont(new Font(fontName, Font.PLAIN, fontSize)); + } + return captcha; + } + + static class FixedArithmeticCaptcha extends ArithmeticCaptcha { + + public FixedArithmeticCaptcha(int width, int height) { + super(width, height); + } + + @Override + protected char[] alphas() { + // 生成随机数字和运算符 + int n1 = num(1, 10), n2 = num(1, 10); + int opt = num(3); + // 计算结果 + int res = new int[]{n1 + n2, n1 - n2, n1 * n2}[opt]; + // 转换为字符运算符 + char optChar = "+-x".charAt(opt); + this.setArithmeticString(String.format("%s%c%s=?", n1, optChar, n2)); + this.chars = String.valueOf(res); + return chars.toCharArray(); + } + } +} diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/model/UserLoginSettingModel.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/model/UserLoginSettingModel.java new file mode 100644 index 00000000..5250e774 --- /dev/null +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/properties/model/UserLoginSettingModel.java @@ -0,0 +1,36 @@ +/* + * 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.framework.properties.model; + +import cn.odboy.base.KitObject; +import lombok.Getter; +import lombok.Setter; + +/** + * 登录配置 + * + * @author odboy + */ +@Getter +@Setter +public class UserLoginSettingModel extends KitObject { + + /** + * 账号单用户 登录 + */ + private boolean single = false; + private UserLoginCaptchaSettingModel captchaSetting; +} diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitAnonTagUtil.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitAnonTagUtil.java index 0ac244b8..c34db180 100644 --- a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitAnonTagUtil.java +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitAnonTagUtil.java @@ -17,6 +17,14 @@ package cn.odboy.util; import cn.odboy.annotation.AnonymousAccess; import cn.odboy.constant.RequestMethodEnum; +import lombok.experimental.UtilityClass; +import org.springframework.context.ApplicationContext; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.method.HandlerMethod; +import org.springframework.web.servlet.mvc.condition.PathPatternsRequestCondition; +import org.springframework.web.servlet.mvc.condition.PatternsRequestCondition; +import org.springframework.web.servlet.mvc.method.RequestMappingInfo; +import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -24,13 +32,6 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; -import lombok.experimental.UtilityClass; -import org.springframework.context.ApplicationContext; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.method.HandlerMethod; -import org.springframework.web.servlet.mvc.condition.PatternsRequestCondition; -import org.springframework.web.servlet.mvc.method.RequestMappingInfo; -import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; /** * 匿名标记工具 @@ -45,10 +46,9 @@ public class KitAnonTagUtil { * @return / */ public static Map> getAnonymousUrl(final ApplicationContext applicationContext) { - RequestMappingHandlerMapping requestMappingHandlerMapping = - (RequestMappingHandlerMapping) applicationContext.getBean("requestMappingHandlerMapping"); + RequestMappingHandlerMapping requestMappingHandlerMapping = (RequestMappingHandlerMapping) applicationContext.getBean("requestMappingHandlerMapping"); Map handlerMethodMap = requestMappingHandlerMapping.getHandlerMethods(); - Map> anonymousUrls = new HashMap<>(8); + Map> anonymousUrls = new HashMap<>(8); // 获取匿名标记 Set get = new HashSet<>(); Set post = new HashSet<>(); @@ -60,30 +60,28 @@ public class KitAnonTagUtil { HandlerMethod handlerMethod = infoEntry.getValue(); AnonymousAccess anonymousAccess = handlerMethod.getMethodAnnotation(AnonymousAccess.class); if (null != anonymousAccess && infoEntry.getKey() != null) { - List requestMethods = - new ArrayList<>(infoEntry.getKey().getMethodsCondition().getMethods()); - RequestMethodEnum request = RequestMethodEnum.find( - requestMethods.isEmpty() ? RequestMethodEnum.ALL.getType() : requestMethods.get(0).name()); - PatternsRequestCondition patternsCondition = infoEntry.getKey().getPatternsCondition(); + List requestMethods = new ArrayList<>(infoEntry.getKey().getMethodsCondition().getMethods()); + RequestMethodEnum request = RequestMethodEnum.find(requestMethods.isEmpty() ? RequestMethodEnum.ALL.getType() : requestMethods.get(0).name()); + PathPatternsRequestCondition patternsCondition = infoEntry.getKey().getPathPatternsCondition(); if (patternsCondition != null) { switch (Objects.requireNonNull(request)) { case GET: - get.addAll(patternsCondition.getPatterns()); + get.addAll(patternsCondition.getPatternValues()); break; case POST: - post.addAll(patternsCondition.getPatterns()); + post.addAll(patternsCondition.getPatternValues()); break; case PUT: - put.addAll(patternsCondition.getPatterns()); + put.addAll(patternsCondition.getPatternValues()); break; case PATCH: - patch.addAll(patternsCondition.getPatterns()); + patch.addAll(patternsCondition.getPatternValues()); break; case DELETE: - delete.addAll(patternsCondition.getPatterns()); + delete.addAll(patternsCondition.getPatternValues()); break; default: - all.addAll(patternsCondition.getPatterns()); + all.addAll(patternsCondition.getPatternValues()); break; } } diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitBase64SecretUtil.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitBase64SecretUtil.java index ab1ab95f..f68fd677 100644 --- a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitBase64SecretUtil.java +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitBase64SecretUtil.java @@ -17,8 +17,8 @@ package cn.odboy.util; import cn.hutool.core.codec.Base64Encoder; import cn.hutool.core.util.IdUtil; -import java.nio.charset.StandardCharsets; import lombok.experimental.UtilityClass; +import java.nio.charset.StandardCharsets; /** * 加密令牌生成工具 diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitBeanUtil.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitBeanUtil.java index e0c55117..50a57ebd 100644 --- a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitBeanUtil.java +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitBeanUtil.java @@ -17,10 +17,10 @@ package cn.odboy.util; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.copier.CopyOptions; +import lombok.experimental.UtilityClass; import java.util.ArrayList; import java.util.Collection; import java.util.List; -import lombok.experimental.UtilityClass; /** * Bean拷贝相关 diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitBigDecimalUtil.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitBigDecimalUtil.java index 538af470..cb602696 100644 --- a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitBigDecimalUtil.java +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitBigDecimalUtil.java @@ -15,9 +15,10 @@ */ package cn.odboy.util; +import lombok.experimental.UtilityClass; import java.math.BigDecimal; import java.math.RoundingMode; -import lombok.experimental.UtilityClass; +import java.text.NumberFormat; /** * 计算类 @@ -133,6 +134,23 @@ public final class KitBigDecimalUtil { return yuan.multiply(BigDecimal.valueOf(100)).setScale(0, RoundingMode.HALF_UP).longValue(); } + /** + * 格式化为 xxx,xxx,xxx 格式 + * + * @param obj 金额 + * @return / + */ + public static String formatGroupingAmount(Object obj) { + if (obj == null) { + return "0"; + } + BigDecimal bigDecimal = toBigDecimal(obj); + NumberFormat nf = NumberFormat.getInstance(); + // 启用千位分隔符 + nf.setGroupingUsed(true); + return nf.format(bigDecimal.setScale(0, RoundingMode.HALF_UP)); + } + public static void main(String[] args) { BigDecimal num1 = new BigDecimal("10.123"); BigDecimal num2 = new BigDecimal("2.456"); diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitBrowserUtil.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitBrowserUtil.java index ea272959..b620713c 100644 --- a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitBrowserUtil.java +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitBrowserUtil.java @@ -17,11 +17,11 @@ package cn.odboy.util; import cn.hutool.http.useragent.UserAgent; import cn.hutool.http.useragent.UserAgentUtil; -import java.net.InetAddress; -import java.net.UnknownHostException; -import jakarta.servlet.http.HttpServletRequest; import lombok.experimental.UtilityClass; import lombok.extern.slf4j.Slf4j; +import jakarta.servlet.http.HttpServletRequest; +import java.net.InetAddress; +import java.net.UnknownHostException; /** * 浏览器 相关 diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitClassUtil.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitClassUtil.java index 540af5e2..fc039e60 100644 --- a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitClassUtil.java +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitClassUtil.java @@ -15,10 +15,10 @@ */ package cn.odboy.util; +import lombok.experimental.UtilityClass; import java.lang.reflect.Field; import java.util.Arrays; import java.util.List; -import lombok.experimental.UtilityClass; /** * 类 相关 diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitCloseUtil.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitCloseUtil.java index 232cc395..3816799b 100644 --- a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitCloseUtil.java +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitCloseUtil.java @@ -15,8 +15,8 @@ */ package cn.odboy.util; -import java.io.Closeable; import lombok.experimental.UtilityClass; +import java.io.Closeable; /** * 用于关闭各种连接, 缺啥补啥 diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitCollUtil.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitCollUtil.java index 867f7ed1..4a536641 100644 --- a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitCollUtil.java +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitCollUtil.java @@ -15,10 +15,9 @@ */ package cn.odboy.util; -import cn.hutool.core.collection.CollUtil; import cn.odboy.base.KitSelectOptionVo; -import cn.odboy.framework.exception.BadRequestException; import com.alibaba.fastjson2.JSON; +import lombok.experimental.UtilityClass; import java.lang.reflect.Field; import java.math.BigDecimal; import java.math.RoundingMode; @@ -31,7 +30,6 @@ import java.util.Objects; import java.util.function.Function; import java.util.function.Predicate; import java.util.stream.Collectors; -import lombok.experimental.UtilityClass; /** * 集合工具 @@ -194,7 +192,7 @@ public final class KitCollUtil extends cn.hutool.core.collection.CollUtil { * @return / */ public static BigDecimal streamBigDecimalAvg(List data) { - KitValidUtil.notEmpty(data, "data"); + KitValidUtil.isEmpty(data, "data"); return data.stream().filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add) .divide(BigDecimal.valueOf(data.size()), 6, RoundingMode.FLOOR); } diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitDateUtil.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitDateUtil.java index 51f20279..c08c2716 100644 --- a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitDateUtil.java +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitDateUtil.java @@ -17,8 +17,9 @@ package cn.odboy.util; import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; -import java.util.Date; import lombok.experimental.UtilityClass; +import java.util.Calendar; +import java.util.Date; /** * 时间相关工具 @@ -129,4 +130,22 @@ public class KitDateUtil { } return result.toString(); } + + /** + * 获得当天是周几 + */ + public static String getWeekDay() { + String[] weekDays = {"星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"}; + Calendar cal = Calendar.getInstance(); + cal.setTime(new Date()); + int w = cal.get(Calendar.DAY_OF_WEEK) - 1; + if (w < 0) { + w = 0; + } + return weekDays[w]; + } + + public static void main(String[] args) { + System.err.println(getWeekDay()); + } } diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitDesEncryptUtil.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitDesEncryptUtil.java index 68c24482..094d4291 100644 --- a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitDesEncryptUtil.java +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitDesEncryptUtil.java @@ -15,13 +15,13 @@ */ package cn.odboy.util; -import java.nio.charset.StandardCharsets; +import lombok.experimental.UtilityClass; import javax.crypto.Cipher; import javax.crypto.SecretKey; import javax.crypto.SecretKeyFactory; import javax.crypto.spec.DESKeySpec; import javax.crypto.spec.IvParameterSpec; -import lombok.experimental.UtilityClass; +import java.nio.charset.StandardCharsets; /** * DES加密 diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitFileUtil.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitFileUtil.java index 2576a173..9e19208d 100644 --- a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitFileUtil.java +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitFileUtil.java @@ -15,11 +15,6 @@ */ package cn.odboy.util; -import static cn.odboy.constant.SystemConst.SYMBOL_ADD; -import static cn.odboy.constant.SystemConst.SYMBOL_AT; -import static cn.odboy.constant.SystemConst.SYMBOL_EQUAL; -import static cn.odboy.constant.SystemConst.SYMBOL_SUBTRACT; - import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.IoUtil; import cn.hutool.core.util.IdUtil; @@ -29,6 +24,11 @@ import cn.hutool.poi.excel.ExcelUtil; import cn.odboy.constant.FileTypeEnum; import cn.odboy.constant.SystemConst; import cn.odboy.framework.exception.BadRequestException; +import lombok.experimental.UtilityClass; +import lombok.extern.slf4j.Slf4j; +import org.apache.poi.util.IOUtils; +import org.apache.poi.xssf.streaming.SXSSFSheet; +import org.springframework.web.multipart.MultipartFile; import jakarta.servlet.ServletOutputStream; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; @@ -46,11 +46,10 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; -import lombok.experimental.UtilityClass; -import lombok.extern.slf4j.Slf4j; -import org.apache.poi.util.IOUtils; -import org.apache.poi.xssf.streaming.SXSSFSheet; -import org.springframework.web.multipart.MultipartFile; +import static cn.odboy.constant.SystemConst.SYMBOL_ADD; +import static cn.odboy.constant.SystemConst.SYMBOL_AT; +import static cn.odboy.constant.SystemConst.SYMBOL_EQUAL; +import static cn.odboy.constant.SystemConst.SYMBOL_SUBTRACT; /** * File工具类, 扩展 hutool 工具包 diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitIPUtil.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitIPUtil.java index 3134ba54..2e5eec1d 100644 --- a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitIPUtil.java +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitIPUtil.java @@ -16,12 +16,12 @@ package cn.odboy.util; import cn.odboy.framework.context.KitSpringBeanHolder; -import java.net.InetAddress; -import java.net.NetworkInterface; -import java.util.Enumeration; import lombok.experimental.UtilityClass; import net.dreamlu.mica.ip2region.core.Ip2regionSearcher; import net.dreamlu.mica.ip2region.core.IpInfo; +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.util.Enumeration; /** * IP地址 相关 diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitJsonUtil.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitJsonUtil.java index 99f8dce4..26f3afd9 100644 --- a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitJsonUtil.java +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitJsonUtil.java @@ -17,9 +17,9 @@ package cn.odboy.util; import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.TypeReference; +import lombok.experimental.UtilityClass; import java.util.List; import java.util.Map; -import lombok.experimental.UtilityClass; /** * Json工具 diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitListUtil.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitListUtil.java index ae961ba5..7455e2b2 100644 --- a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitListUtil.java +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitListUtil.java @@ -17,11 +17,11 @@ package cn.odboy.util; import cn.hutool.core.date.DateTime; import cn.odboy.base.KitBaseUserTimeTb; +import lombok.experimental.UtilityClass; import java.util.ArrayList; import java.util.List; import java.util.function.Function; import java.util.stream.Collectors; -import lombok.experimental.UtilityClass; /** * List 工具 @@ -40,7 +40,7 @@ public final class KitListUtil { */ public static List distinctByArgs(List items, Function classifier) { return items.stream().collect(Collectors.groupingBy(classifier)).values().stream() - .map(List::getFirst).collect(Collectors.toList()); + .map(monitorItem -> monitorItem.iterator().next()).collect(Collectors.toList()); } /** diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitPageUtil.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitPageUtil.java index 6216e96c..5b5da4da 100644 --- a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitPageUtil.java +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitPageUtil.java @@ -17,9 +17,9 @@ package cn.odboy.util; import cn.odboy.base.KitPageResult; import com.baomidou.mybatisplus.core.metadata.IPage; +import lombok.experimental.UtilityClass; import java.util.Collections; import java.util.List; -import lombok.experimental.UtilityClass; /** * 分页工具 diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitReturnValueHandleUtil.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitReturnValueHandleUtil.java index 67594190..72d70eaa 100644 --- a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitReturnValueHandleUtil.java +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitReturnValueHandleUtil.java @@ -15,13 +15,13 @@ */ package cn.odboy.util; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.reflect.MethodSignature; import java.lang.reflect.Method; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Set; -import org.aspectj.lang.ProceedingJoinPoint; -import org.aspectj.lang.reflect.MethodSignature; /** * 返回值处理 工具 diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitRsaEncryptUtil.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitRsaEncryptUtil.java index cecc94c4..29cbe2b0 100644 --- a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitRsaEncryptUtil.java +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitRsaEncryptUtil.java @@ -15,6 +15,9 @@ */ package cn.odboy.util; +import lombok.experimental.UtilityClass; +import org.apache.commons.codec.binary.Base64; +import javax.crypto.Cipher; import java.io.ByteArrayOutputStream; import java.security.KeyFactory; import java.security.KeyPair; @@ -26,9 +29,6 @@ import java.security.interfaces.RSAPrivateKey; import java.security.interfaces.RSAPublicKey; import java.security.spec.PKCS8EncodedKeySpec; import java.security.spec.X509EncodedKeySpec; -import javax.crypto.Cipher; -import lombok.experimental.UtilityClass; -import org.apache.commons.codec.binary.Base64; /** * Rsa 工具类, 公钥私钥生成, 加解密 diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitStringUtil.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitStringUtil.java index 605d4257..3f5e01dd 100644 --- a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitStringUtil.java +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitStringUtil.java @@ -15,8 +15,6 @@ */ package cn.odboy.util; -import java.util.Calendar; -import java.util.Date; import lombok.experimental.UtilityClass; import lombok.extern.slf4j.Slf4j; @@ -97,19 +95,4 @@ public final class KitStringUtil { } return sb.toString(); } - - /** - * 获得当天是周几 - */ - public static String getWeekDay() { - // String[] weekDays = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; - String[] weekDays = {"星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期天"}; - Calendar cal = Calendar.getInstance(); - cal.setTime(new Date()); - int w = cal.get(Calendar.DAY_OF_WEEK) - 1; - if (w < 0) { - w = 0; - } - return weekDays[w]; - } } diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitThreadUtil.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitThreadUtil.java new file mode 100644 index 00000000..4f9488b3 --- /dev/null +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitThreadUtil.java @@ -0,0 +1,17 @@ +package cn.odboy.util; + +import cn.hutool.core.thread.ThreadUtil; + +public class KitThreadUtil { + + /** + * 可中断的睡眠 + */ + public static void interruptSleep(int i) throws InterruptedException { + Thread.sleep(i); + } + + public static void safeSleep(int i) { + ThreadUtil.safeSleep(i); + } +} diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitValidUtil.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitValidUtil.java index e9ef0ce1..14a1a206 100644 --- a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitValidUtil.java +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitValidUtil.java @@ -18,16 +18,16 @@ package cn.odboy.util; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; import cn.odboy.framework.exception.BadRequestException; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; +import lombok.experimental.UtilityClass; import jakarta.validation.ConstraintViolation; import jakarta.validation.Validation; import jakarta.validation.Validator; import jakarta.validation.ValidatorFactory; import jakarta.validation.constraints.NotNull; import jakarta.validation.groups.Default; -import lombok.experimental.UtilityClass; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; /** * Bean验证工具 @@ -46,6 +46,12 @@ public final class KitValidUtil { } } + /** + * 验证实体是否通过校验
实体内通过 javax.validation.constraints 中的表达式限制参数
+ * + * @param object / + * @param / + */ public static void validate(T object) { Set> violations = VALIDATOR.validate(object, Default.class); if (!violations.isEmpty()) { @@ -54,39 +60,125 @@ public final class KitValidUtil { } } - public static void notNull(Object value) { + /** + * 参数为null,抛异常 + * + * @param value 参数值 + */ + public static void isNull(Object value) { if (value == null) { throw new BadRequestException("参数必填"); } } - public static void isNull(Object value) { - if (value != null) { - throw new BadRequestException("参数非必填"); - } - } - - public static void notNull(Object value, @NotNull String name, @NotNull String code) { + /** + * 参数为空,抛异常 + * + * @param value 参数值 + * @param name 参数名称 + * @param code 参数编码 + */ + public static void isNull(Object value, @NotNull String name, @NotNull String code) { if (value == null) { throw new BadRequestException(String.format("参数 %s(%s) 必填", name, code)); } } - public static void isBlank(CharSequence value, @NotNull String name, @NotNull String code) { - if (StrUtil.isNotBlank(value)) { - throw new BadRequestException(String.format("参数 %s(%s) 非必填", name, code)); + /** + * 参数为空,抛异常 + * + * @param value 参数值 + * @param message 异常信息 + */ + public static void isNull(Object value, @NotNull String message) { + if (value == null) { + throw new BadRequestException(message); } } - public static void notBlank(CharSequence value, @NotNull String name, @NotNull String code) { + /** + * 参数为空,抛异常 + * + * @param value 参数值 + * @param code 参数编码 + */ + public static void isNullF(Object value, @NotNull String code) { + if (value == null) { + throw new BadRequestException(String.format("参数 %s 必填", code)); + } + } + + /** + * 参数为空字符串,抛异常 + * + * @param value 参数值 + * @param name 参数名称 + * @param code 参数编码 + */ + public static void isBlank(CharSequence value, @NotNull String name, @NotNull String code) { if (StrUtil.isBlank(value)) { throw new BadRequestException(String.format("参数 %s(%s) 必填", name, code)); } } - public static void notEmpty(List data, @NotNull String code) { + /** + * 集合为空,抛异常 + * + * @param data 集合值 + * @param code 参数编码 + */ + public static void isEmpty(List data, @NotNull String code) { if (CollUtil.isEmpty(data)) { throw new BadRequestException(String.format("参数 %s 必填", code)); } } + + /** + * 集合为空,抛异常 + * + * @param data 集合值 + * @param name 参数名称 + * @param code 参数编码 + */ + public static void isEmpty(List data, @NotNull String name, @NotNull String code) { + if (CollUtil.isEmpty(data)) { + throw new BadRequestException(String.format("参数 %s(%s) 必填", name, code)); + } + } + + /** + * 表达式为true,抛异常 + * + * @param condition 表达式 + * @param message 异常信息 + */ + public static void isTrue(boolean condition, String message) { + if (condition) { + throw new BadRequestException(message); + } + } + + /** + * 表达式为false,抛异常 + * + * @param condition 表达式 + * @param message 异常信息 + */ + public static void isFalse(boolean condition, String message) { + if (!condition) { + throw new BadRequestException(message); + } + } + + /** + * 参数为空字符串,抛异常 + * + * @param value 参数值 + * @param message 异常信息 + */ + public static void isBlank(String value, String message) { + if (StrUtil.isBlank(value)) { + throw new BadRequestException(message); + } + } } diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/xlsx/KitExcelExporter.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/xlsx/KitExcelExporter.java index 8372a27d..b36f3c3f 100644 --- a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/xlsx/KitExcelExporter.java +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/xlsx/KitExcelExporter.java @@ -3,12 +3,12 @@ package cn.odboy.util.xlsx; import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; import cn.idev.excel.EasyExcel; +import jakarta.servlet.http.HttpServletResponse; import java.io.OutputStream; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.Date; import java.util.List; -import jakarta.servlet.http.HttpServletResponse; /** * EasyExcel 导出增强工具类 (支持普通/分页模式) diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/xlsx/KitXlsxExportUtil.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/xlsx/KitXlsxExportUtil.java index 320b0f2a..520e511d 100644 --- a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/xlsx/KitXlsxExportUtil.java +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/xlsx/KitXlsxExportUtil.java @@ -6,14 +6,14 @@ import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.StrUtil; import cn.idev.excel.FastExcel; import cn.odboy.framework.exception.BadRequestException; +import lombok.experimental.UtilityClass; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Date; import java.util.List; -import jakarta.servlet.http.HttpServletResponse; -import lombok.experimental.UtilityClass; /** * xlsx文件导出工具 diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteDeptTreeApi.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteDeptTreeApi.java index 48b141d1..3263e041 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteDeptTreeApi.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteDeptTreeApi.java @@ -1,3 +1,18 @@ +/* + * 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.application; import cn.odboy.system.application.model.CuteDeptTreeVo; diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteFileUploadApi.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteFileUploadApi.java index e2f184e5..fe44b051 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteFileUploadApi.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteFileUploadApi.java @@ -1,3 +1,18 @@ +/* + * 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.application; import cn.odboy.system.application.service.CuteFileUploadService; diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteProductLineSelectApi.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteProductLineSelectApi.java index 7037874e..7a649e9c 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteProductLineSelectApi.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteProductLineSelectApi.java @@ -1,3 +1,18 @@ +/* + * 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.application; import cn.odboy.system.application.service.CuteProductLineSelectService; diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteProductLineSelectProApi.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteProductLineSelectProApi.java index f671fa7c..76960766 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteProductLineSelectProApi.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteProductLineSelectProApi.java @@ -1,3 +1,18 @@ +/* + * 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.application; import cn.odboy.system.application.service.CuteProductLineSelectProService; diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteUserSelectApi.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteUserSelectApi.java index 21c5978e..18101bf5 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteUserSelectApi.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteUserSelectApi.java @@ -1,3 +1,18 @@ +/* + * 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.application; import cn.odboy.system.application.model.CuteUserSelectVo; diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/model/CuteDeptTreeVo.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/model/CuteDeptTreeVo.java index db474eb8..c3585939 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/model/CuteDeptTreeVo.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/model/CuteDeptTreeVo.java @@ -1,3 +1,18 @@ +/* + * 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.application.model; import cn.odboy.base.KitObject; diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/model/CuteUserSelectVo.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/model/CuteUserSelectVo.java index a03945c8..5efe95be 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/model/CuteUserSelectVo.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/model/CuteUserSelectVo.java @@ -1,3 +1,18 @@ +/* + * 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.application.model; import cn.odboy.base.KitObject; diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteBaseService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteBaseService.java index 565cc64d..d87b93f3 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteBaseService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteBaseService.java @@ -1,3 +1,18 @@ +/* + * 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.application.service; import cn.odboy.system.dal.dataobject.SystemDeptTb; diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteDeptTreeService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteDeptTreeService.java index 96ab9509..40e472b2 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteDeptTreeService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteDeptTreeService.java @@ -1,3 +1,18 @@ +/* + * 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.application.service; import cn.hutool.core.util.ObjectUtil; diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteFileUploadService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteFileUploadService.java index cdf347dc..8cdb5934 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteFileUploadService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteFileUploadService.java @@ -1,3 +1,18 @@ +/* + * 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.application.service; import cn.hutool.core.date.DatePattern; diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteProductLineSelectProService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteProductLineSelectProService.java index 27f1f587..c3933524 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteProductLineSelectProService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteProductLineSelectProService.java @@ -1,3 +1,18 @@ +/* + * 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.application.service; import cn.odboy.system.application.model.CuteProductLineSelectProVo; diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteProductLineSelectService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteProductLineSelectService.java index 94d6ce19..82301e0b 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteProductLineSelectService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteProductLineSelectService.java @@ -1,3 +1,18 @@ +/* + * 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.application.service; import cn.odboy.system.application.model.CuteProductLineSelectVo; diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteUserSelectService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteUserSelectService.java index 34d67f81..9d87d87a 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteUserSelectService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteUserSelectService.java @@ -1,3 +1,18 @@ +/* + * 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.application.service; import cn.hutool.core.collection.CollUtil; diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemMenuController.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemMenuController.java index bbc876cb..de0f96dc 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemMenuController.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemMenuController.java @@ -17,7 +17,6 @@ package cn.odboy.system.controller; import cn.odboy.base.KitPageArgs; import cn.odboy.base.KitPageResult; -import cn.odboy.framework.exception.BadRequestException; import cn.odboy.system.dal.dataobject.SystemMenuTb; import cn.odboy.system.dal.model.request.SystemQueryMenuArgs; import cn.odboy.system.dal.model.response.SystemMenuRouterVo; @@ -102,9 +101,6 @@ public class SystemMenuController { @PostMapping(value = "/saveMenu") @PreAuthorize("@el.check('menu:add')") public ResponseEntity saveMenu(@Validated @RequestBody SystemMenuTb args) { - if (args.getId() != null) { - throw new BadRequestException("无效参数id"); - } systemMenuService.saveMenu(args); return ResponseEntity.ok(null); } diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemQuartzJobController.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemQuartzJobController.java index def140c3..d989cba9 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemQuartzJobController.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemQuartzJobController.java @@ -21,10 +21,8 @@ import cn.odboy.system.dal.dataobject.SystemQuartzJobTb; import cn.odboy.system.dal.dataobject.SystemQuartzLogTb; import cn.odboy.system.dal.model.request.SystemQueryQuartzJobArgs; import cn.odboy.system.dal.model.request.SystemUpdateQuartzJobArgs; -import cn.odboy.system.dal.model.response.SystemQuartzJobVo; import cn.odboy.system.framework.operalog.OperationLog; import cn.odboy.system.service.SystemQuartzJobService; -import cn.odboy.util.KitBeanUtil; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -96,8 +94,7 @@ public class SystemQuartzJobController { @ApiOperation("修改定时任务") @PostMapping(value = "/updateQuartzJobResumeCron") @PreAuthorize("@el.check('quartzJob:edit')") - public ResponseEntity updateQuartzJob( - @Validated(SystemQuartzJobTb.Update.class) @RequestBody SystemUpdateQuartzJobArgs args) { + public ResponseEntity updateQuartzJob(@Validated(SystemQuartzJobTb.Update.class) @RequestBody SystemUpdateQuartzJobArgs args) { systemQuartzJobService.updateQuartzJobResumeCron(args); return ResponseEntity.ok(null); } @@ -108,8 +105,7 @@ public class SystemQuartzJobController { @PreAuthorize("@el.check('quartzJob:edit')") public ResponseEntity switchQuartzJobStatus(@PathVariable Long id) { SystemQuartzJobTb quartzJobTb = systemQuartzJobService.getQuartzJobById(id); - SystemQuartzJobVo quartzJobVo = KitBeanUtil.copyToClass(quartzJobTb, SystemQuartzJobVo.class); - systemQuartzJobService.switchQuartzJobStatus(quartzJobVo); + systemQuartzJobService.switchQuartzJobStatus(quartzJobTb); return ResponseEntity.ok(null); } @@ -119,8 +115,7 @@ public class SystemQuartzJobController { @PreAuthorize("@el.check('quartzJob:edit')") public ResponseEntity startQuartzJob(@PathVariable Long id) { SystemQuartzJobTb quartzJobTb = systemQuartzJobService.getQuartzJobById(id); - SystemQuartzJobVo quartzJobVo = KitBeanUtil.copyToClass(quartzJobTb, SystemQuartzJobVo.class); - systemQuartzJobService.startQuartzJob(quartzJobVo); + systemQuartzJobService.startQuartzJob(quartzJobTb); return ResponseEntity.ok(null); } diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemDeptTb.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemDeptTb.java index 6098ddfc..04f92d14 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemDeptTb.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemDeptTb.java @@ -20,9 +20,9 @@ import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModelProperty; +import jakarta.validation.constraints.NotBlank; import lombok.Getter; import lombok.Setter; -import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; import java.util.Objects; diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemQuartzJobTb.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemQuartzJobTb.java index 51010e21..ee0ab848 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemQuartzJobTb.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemQuartzJobTb.java @@ -63,4 +63,10 @@ public class SystemQuartzJobTb extends KitBaseUserTimeTb { @ApiModelProperty(value = "备注") @TableField(updateStrategy = FieldStrategy.ALWAYS) private String description; + /** + * 扩展字段 + */ + @TableField(exist = false) + @ApiModelProperty(value = "用于子任务唯一标识", hidden = true) + private String uuid; } diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/model/response/SystemQuartzJobVo.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/model/response/SystemQuartzJobVo.java deleted file mode 100644 index 19633561..00000000 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/dal/model/response/SystemQuartzJobVo.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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.dal.model.response; - -import cn.odboy.base.KitBaseUserTimeTb; -import io.swagger.annotations.ApiModelProperty; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -public class SystemQuartzJobVo extends KitBaseUserTimeTb { - - private Long id; - @ApiModelProperty(value = "定时器名称") - private String jobName; - @ApiModelProperty(value = "Bean名称") - private String beanName; - @ApiModelProperty(value = "方法名称") - private String methodName; - @ApiModelProperty(value = "参数") - private String params; - @ApiModelProperty(value = "cron表达式") - private String cronExpression; - @ApiModelProperty(value = "状态:暂停或启动") - private Boolean isPause = false; - @ApiModelProperty(value = "负责人") - private String personInCharge; - @ApiModelProperty(value = "报警邮箱") - private String email; - @ApiModelProperty(value = "子任务") - private String subTask; - @ApiModelProperty(value = "失败后暂停") - private Boolean pauseAfterFailure; - @ApiModelProperty(value = "备注") - private String description; - /** - * 扩展字段 - */ - @ApiModelProperty(value = "用于子任务唯一标识", hidden = true) - private String uuid; -} diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/permission/config/SpringSecurityConfig.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/permission/config/SpringSecurityConfig.java index b80a830b..f3959476 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/permission/config/SpringSecurityConfig.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/permission/config/SpringSecurityConfig.java @@ -85,8 +85,10 @@ public class SpringSecurityConfig { .addFilterBefore(customFilter, UsernamePasswordAuthenticationFilter.class) // 授权异常 .exceptionHandling( - exceptionHandling -> exceptionHandling.authenticationEntryPoint(authenticationErrorHandler) - .accessDeniedHandler(jwtAccessDeniedHandler)) + exceptionHandling -> exceptionHandling + .authenticationEntryPoint(authenticationErrorHandler) + .accessDeniedHandler(jwtAccessDeniedHandler) + ) // 防止iframe 造成跨域 .headers(headers -> headers.frameOptions(HeadersConfigurer.FrameOptionsConfig::disable)) // 不创建会话 @@ -106,20 +108,15 @@ public class SpringSecurityConfig { .requestMatchers(HttpMethod.OPTIONS, "/**").permitAll() // 自定义匿名访问所有url放行:允许匿名和带Token访问,细腻化到每个 Request 类型 // GET - .requestMatchers(HttpMethod.GET, - anonymousUrls.get(RequestMethodEnum.GET.getType()).toArray(new String[0])).permitAll() + .requestMatchers(HttpMethod.GET, anonymousUrls.get(RequestMethodEnum.GET.getType()).toArray(new String[0])).permitAll() // POST - .requestMatchers(HttpMethod.POST, - anonymousUrls.get(RequestMethodEnum.POST.getType()).toArray(new String[0])).permitAll() + .requestMatchers(HttpMethod.POST, anonymousUrls.get(RequestMethodEnum.POST.getType()).toArray(new String[0])).permitAll() // PUT - .requestMatchers(HttpMethod.PUT, - anonymousUrls.get(RequestMethodEnum.PUT.getType()).toArray(new String[0])).permitAll() + .requestMatchers(HttpMethod.PUT, anonymousUrls.get(RequestMethodEnum.PUT.getType()).toArray(new String[0])).permitAll() // PATCH - .requestMatchers(HttpMethod.PATCH, - anonymousUrls.get(RequestMethodEnum.PATCH.getType()).toArray(new String[0])).permitAll() + .requestMatchers(HttpMethod.PATCH, anonymousUrls.get(RequestMethodEnum.PATCH.getType()).toArray(new String[0])).permitAll() // DELETE - .requestMatchers(HttpMethod.DELETE, - anonymousUrls.get(RequestMethodEnum.DELETE.getType()).toArray(new String[0])).permitAll() + .requestMatchers(HttpMethod.DELETE, anonymousUrls.get(RequestMethodEnum.DELETE.getType()).toArray(new String[0])).permitAll() // 所有类型的接口都放行 .requestMatchers(anonymousUrls.get(RequestMethodEnum.ALL.getType()).toArray(new String[0])).permitAll() // 所有请求都需要认证 diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/permission/config/TokenConfigurer.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/permission/config/TokenConfigurer.java deleted file mode 100644 index 9c05ad8f..00000000 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/permission/config/TokenConfigurer.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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.framework.permission.config; - -import cn.odboy.system.dal.redis.SystemUserOnlineInfoDAO; -import cn.odboy.system.framework.permission.core.handler.TokenFilter; -import cn.odboy.system.framework.permission.core.handler.TokenProvider; -import org.springframework.security.config.annotation.SecurityConfigurerAdapter; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.web.DefaultSecurityFilterChain; -import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; - -public class TokenConfigurer extends SecurityConfigurerAdapter { - - private final TokenProvider tokenProvider; - private final SystemUserOnlineInfoDAO systemUserOnlineInfoDAO; - - public TokenConfigurer(TokenProvider tokenProvider, SystemUserOnlineInfoDAO systemUserOnlineInfoDAO) { - this.tokenProvider = tokenProvider; - this.systemUserOnlineInfoDAO = systemUserOnlineInfoDAO; - } - - @Override - public void configure(HttpSecurity http) { - TokenFilter customFilter = new TokenFilter(tokenProvider, systemUserOnlineInfoDAO); - http.addFilterBefore(customFilter, UsernamePasswordAuthenticationFilter.class); - } -} diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/permission/core/handler/UserDetailsHandler.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/permission/core/handler/UserDetailsHandler.java index b7ad2260..2ef1b543 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/permission/core/handler/UserDetailsHandler.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/permission/core/handler/UserDetailsHandler.java @@ -23,11 +23,11 @@ import cn.odboy.system.dal.redis.SystemUserInfoDAO; import cn.odboy.system.service.SystemDataService; import cn.odboy.system.service.SystemRoleService; import cn.odboy.system.service.SystemUserService; -import java.util.List; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.stereotype.Service; +import java.util.List; /** * 通过用户名判断用户信息,并获取拥有的权限与部门 @@ -49,7 +49,7 @@ public class UserDetailsHandler implements UserDetailsService { public SystemUserJwtVo loadUserByUsername(String username) { SystemUserJwtVo userJwtVo = systemUserInfoDAO.getUserLoginInfoByUserName(username); if (userJwtVo == null) { - SystemUserVo user = systemUserService.getUserVoByUsername(username); + SystemUserVo user = systemUserService.getUserVoWithPasswordByUsername(username); if (user == null) { throw new BadRequestException("用户不存在"); } else { diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/ActiveJobRegister.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/ActiveJobRegister.java index 2a0f4641..243e0e13 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/ActiveJobRegister.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/ActiveJobRegister.java @@ -16,15 +16,13 @@ package cn.odboy.system.framework.quartz; import cn.odboy.system.dal.dataobject.SystemQuartzJobTb; -import cn.odboy.system.dal.model.response.SystemQuartzJobVo; import cn.odboy.system.service.SystemQuartzJobService; -import cn.odboy.util.KitBeanUtil; -import java.util.List; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.stereotype.Component; +import java.util.List; @Slf4j @Component @@ -43,8 +41,7 @@ public class ActiveJobRegister implements ApplicationRunner { @Override public void run(ApplicationArguments applicationArguments) { List quartzJobTbs = systemQuartzJobService.listEnableQuartzJob(); - List quartzJobVos = KitBeanUtil.copyToList(quartzJobTbs, SystemQuartzJobVo.class); - quartzJobVos.forEach(quartzManage::addJob); + quartzJobTbs.forEach(quartzManage::addJob); log.info("Timing task injection complete"); } } diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/ExecutionJobBean.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/ExecutionJobBean.java index 2d9f4f3a..5ad84eac 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/ExecutionJobBean.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/ExecutionJobBean.java @@ -27,19 +27,19 @@ import cn.odboy.framework.redis.KitRedisHelper; import cn.odboy.system.dal.dataobject.SystemQuartzJobTb; import cn.odboy.system.dal.dataobject.SystemQuartzLogTb; import cn.odboy.system.dal.model.request.SystemSendEmailArgs; -import cn.odboy.system.dal.model.response.SystemQuartzJobVo; import cn.odboy.system.dal.mysql.SystemQuartzLogMapper; import cn.odboy.system.service.SystemEmailService; import cn.odboy.system.service.SystemQuartzJobService; +import cn.odboy.util.KitBeanUtil; +import lombok.extern.slf4j.Slf4j; +import org.quartz.JobExecutionContext; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; +import org.springframework.scheduling.quartz.QuartzJobBean; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.Future; -import lombok.extern.slf4j.Slf4j; -import org.quartz.JobExecutionContext; -import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; -import org.springframework.scheduling.quartz.QuartzJobBean; @Slf4j public class ExecutionJobBean extends QuartzJobBean { @@ -52,7 +52,7 @@ public class ExecutionJobBean extends QuartzJobBean { @Override public void executeInternal(JobExecutionContext context) { // 获取任务 - SystemQuartzJobVo quartzJob = (SystemQuartzJobVo) context.getMergedJobDataMap().get(SystemQuartzJobTb.JOB_KEY); + SystemQuartzJobTb quartzJob = (SystemQuartzJobTb) context.getMergedJobDataMap().get(SystemQuartzJobTb.JOB_KEY); // 获取spring bean SystemQuartzLogMapper quartzLogMapper = KitSpringBeanHolder.getBean(SystemQuartzLogMapper.class); SystemQuartzJobService systemQuartzJobService = KitSpringBeanHolder.getBean(SystemQuartzJobService.class); @@ -99,7 +99,8 @@ public class ExecutionJobBean extends QuartzJobBean { if (quartzJob.getPauseAfterFailure() != null && quartzJob.getPauseAfterFailure()) { quartzJob.setIsPause(false); // 更新状态 - systemQuartzJobService.switchQuartzJobStatus(quartzJob); + SystemQuartzJobTb quartzJobTb = KitBeanUtil.copyToClass(quartzJob, SystemQuartzJobTb.class); + systemQuartzJobService.switchQuartzJobStatus(quartzJobTb); } if (quartzJob.getEmail() != null) { SystemEmailService emailService = KitSpringBeanHolder.getBean(SystemEmailService.class); @@ -114,7 +115,7 @@ public class ExecutionJobBean extends QuartzJobBean { } } - private SystemSendEmailArgs taskAlarm(SystemQuartzJobVo quartzJob, String msg) { + private SystemSendEmailArgs taskAlarm(SystemQuartzJobTb quartzJob, String msg) { SystemSendEmailArgs sendEmailRequest = new SystemSendEmailArgs(); sendEmailRequest.setSubject("定时任务【" + quartzJob.getJobName() + "】执行失败,请尽快处理!"); Map data = new HashMap<>(16); diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/QuartzManage.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/QuartzManage.java index 415f9946..3f385830 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/QuartzManage.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/QuartzManage.java @@ -17,9 +17,6 @@ package cn.odboy.system.framework.quartz; import cn.odboy.framework.exception.BadRequestException; import cn.odboy.system.dal.dataobject.SystemQuartzJobTb; -import cn.odboy.system.dal.model.response.SystemQuartzJobVo; -import cn.odboy.util.KitBeanUtil; -import java.util.Date; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.quartz.CronScheduleBuilder; @@ -35,6 +32,7 @@ import org.quartz.TriggerBuilder; import org.quartz.TriggerKey; import org.quartz.impl.triggers.CronTriggerImpl; import org.springframework.stereotype.Component; +import java.util.Date; @Slf4j @Component @@ -44,7 +42,7 @@ public class QuartzManage { @Resource private Scheduler scheduler; - public void addJob(SystemQuartzJobVo quartzJob) { + public void addJob(SystemQuartzJobTb quartzJob) { try { String uuid = JOB_NAME + quartzJob.getId(); // 构建job信息 @@ -83,23 +81,22 @@ public class QuartzManage { */ public void updateJobCron(SystemQuartzJobTb quartzJob) { try { - SystemQuartzJobVo quartzJobVo = KitBeanUtil.copyToClass(quartzJob, SystemQuartzJobVo.class); - TriggerKey triggerKey = TriggerKey.triggerKey(JOB_NAME + quartzJobVo.getId()); + TriggerKey triggerKey = TriggerKey.triggerKey(JOB_NAME + quartzJob.getId()); CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey); // 如果不存在则创建一个定时任务 if (trigger == null) { - addJob(quartzJobVo); + addJob(quartzJob); trigger = (CronTrigger) scheduler.getTrigger(triggerKey); } - CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(quartzJobVo.getCronExpression()); + CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(quartzJob.getCronExpression()); trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build(); // 重置启动时间 ((CronTriggerImpl) trigger).setStartTime(new Date()); - trigger.getJobDataMap().put(SystemQuartzJobTb.JOB_KEY, quartzJobVo); + trigger.getJobDataMap().put(SystemQuartzJobTb.JOB_KEY, quartzJob); scheduler.rescheduleJob(triggerKey, trigger); // 暂停任务 - if (quartzJobVo.getIsPause()) { - pauseJob(quartzJobVo); + if (quartzJob.getIsPause()) { + pauseJob(quartzJob); } } catch (Exception e) { log.error("更新定时任务失败", e); @@ -128,7 +125,7 @@ public class QuartzManage { * * @param quartzJob / */ - public void resumeJob(SystemQuartzJobVo quartzJob) { + public void resumeJob(SystemQuartzJobTb quartzJob) { try { TriggerKey triggerKey = TriggerKey.triggerKey(JOB_NAME + quartzJob.getId()); CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey); @@ -149,7 +146,7 @@ public class QuartzManage { * * @param quartzJob / */ - public void runJobNow(SystemQuartzJobVo quartzJob) { + public void runJobNow(SystemQuartzJobTb quartzJob) { try { String uuid = JOB_NAME + quartzJob.getId(); TriggerKey triggerKey = TriggerKey.triggerKey(uuid); @@ -173,7 +170,7 @@ public class QuartzManage { * * @param quartzJob / */ - public void pauseJob(SystemQuartzJobVo quartzJob) { + public void pauseJob(SystemQuartzJobTb quartzJob) { try { JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getId()); scheduler.pauseJob(jobKey); diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemAuthService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemAuthService.java index 801d9dab..380d4be7 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemAuthService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemAuthService.java @@ -16,7 +16,6 @@ package cn.odboy.system.service; import cn.odboy.constant.SystemConst; -import cn.odboy.framework.exception.BadRequestException; import cn.odboy.framework.properties.AppProperties; import cn.odboy.system.dal.model.request.SystemUserLoginArgs; import cn.odboy.system.dal.model.response.SystemAuthVo; @@ -57,25 +56,23 @@ public class SystemAuthService { private SystemCaptchaService systemCaptchaService; /** - * 登录 -> TestPassed + * 登录 * * @param loginArgs / * @param request / */ public SystemAuthVo doLogin(SystemUserLoginArgs loginArgs, HttpServletRequest request) throws Exception { - KitValidUtil.notNull(loginArgs); + KitValidUtil.isNull(loginArgs); // 密码解密 - String password = - KitRsaEncryptUtil.decryptByPrivateKey(properties.getRsa().getPrivateKey(), loginArgs.getPassword()); + String password = KitRsaEncryptUtil.decryptByPrivateKey(properties.getRsa().getPrivateKey(), loginArgs.getPassword()); // 校验验证码 systemCaptchaService.validate(loginArgs.getUuid(), loginArgs.getCode()); // 查询用户信息 SystemUserJwtVo jwtUser = userDetailsService.loadUserByUsername(loginArgs.getUsername()); + // 验证用户密码 - if (!passwordEncoder.matches(password, jwtUser.getPassword())) { - throw new BadRequestException("登录密码错误"); - } + KitValidUtil.isTrue(!passwordEncoder.matches(password, jwtUser.getPassword()), "登录密码错误"); // 登录验证 Authentication authentication = @@ -101,7 +98,7 @@ public class SystemAuthService { } /** - * 查询当前登录人信息 -> TestPassed + * 查询当前登录人信息 */ public SystemUserJwtVo getCurrentUserInfo() { SystemUserJwtVo jwtUser = (SystemUserJwtVo) KitSecurityHelper.getCurrentUser(); @@ -112,7 +109,7 @@ public class SystemAuthService { } /** - * 退出登录 -> TestPassed + * 退出登录 * * @param request / */ diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemCaptchaService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemCaptchaService.java index ba1521ce..d806ed99 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemCaptchaService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemCaptchaService.java @@ -19,11 +19,11 @@ import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.StrUtil; import cn.odboy.constant.CaptchaCodeEnum; import cn.odboy.constant.SystemConst; -import cn.odboy.framework.exception.BadRequestException; import cn.odboy.framework.properties.AppProperties; import cn.odboy.framework.redis.KitRedisHelper; import cn.odboy.system.constant.SystemCacheKey; import cn.odboy.system.dal.model.response.SystemCaptchaVo; +import cn.odboy.util.KitValidUtil; import com.wf.captcha.base.Captcha; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -41,7 +41,7 @@ public class SystemCaptchaService { private AppProperties properties; /** - * 查询登录验证码 -> TestPassed + * 查询登录验证码 */ public SystemCaptchaVo getLoginCaptcha() { // 查询运算的结果 @@ -63,7 +63,7 @@ public class SystemCaptchaService { } /** - * 验证验证码 -> TestPassed + * 验证验证码 * * @param uuid 验证码uuid * @param inputCode 用户输入的验证码 @@ -71,13 +71,9 @@ public class SystemCaptchaService { public void validate(String uuid, String inputCode) { // 查询验证码 String code = redisHelper.get(uuid, String.class); - if (StrUtil.isBlank(code)) { - throw new BadRequestException("验证码不存在或已过期"); - } + KitValidUtil.isBlank(code, "验证码不存在或已过期"); // 清除验证码 redisHelper.del(uuid); - if (StrUtil.isBlank(inputCode) || !code.equalsIgnoreCase(inputCode)) { - throw new BadRequestException("验证码错误"); - } + KitValidUtil.isTrue(StrUtil.isBlank(inputCode) || !code.equalsIgnoreCase(inputCode), "验证码错误"); } } diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDataService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDataService.java index 5e1a39ee..4e0d6d09 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDataService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDataService.java @@ -45,7 +45,7 @@ public class SystemDataService { private SystemRoleDeptService systemRoleDeptService; /** - * 查询数据权限 -> TestPassed + * 查询数据权限 * * @param user / * @return / @@ -75,7 +75,7 @@ public class SystemDataService { } /** - * 查询自定义的数据权限 -> TestPassed + * 查询自定义的数据权限 * * @param deptIds 部门ID(外部数据) * @param roleId 角色ID diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDeptService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDeptService.java index cc5d6b75..41c6dc5b 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDeptService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDeptService.java @@ -34,10 +34,10 @@ import cn.odboy.util.KitClassUtil; import cn.odboy.util.KitValidUtil; import cn.odboy.util.xlsx.KitExcelExporter; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import jakarta.servlet.http.HttpServletResponse; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashSet; @@ -58,13 +58,13 @@ public class SystemDeptService { private SystemRoleDeptService systemRoleDeptService; /** - * 创建 -> TestPassed + * 创建 * * @param args / */ @Transactional(rollbackFor = Exception.class) public void saveDept(SystemCreateDeptArgs args) { - KitValidUtil.notNull(args); + KitValidUtil.isNull(args); SystemDeptTb record = KitBeanUtil.copyToClass(args, SystemDeptTb.class); systemDeptMapper.insert(record); @@ -73,13 +73,13 @@ public class SystemDeptService { } /** - * 编辑 -> TestPassed + * 编辑 * * @param args / */ @Transactional(rollbackFor = Exception.class) public void updateDeptById(SystemDeptTb args) { - KitValidUtil.notNull(args); + KitValidUtil.isNull(args); // 旧的父部门 Long oldPid = this.getDeptById(args.getId()).getPid(); // 新的父部门 @@ -104,7 +104,9 @@ public class SystemDeptService { // 查询部门, 和其所有子部门 Set depts = this.traverseDeptByIdWithPids(ids); // 验证是否被角色或用户关联 - this.verifyBindRelationByIds(depts); + Set deptIds = depts.stream().map(SystemDeptTb::getId).collect(Collectors.toSet()); + KitValidUtil.isTrue(systemUserDeptService.countUserByDeptIds(deptIds) > 0, "所选部门存在用户关联,请解除后再试"); + KitValidUtil.isTrue(systemRoleDeptService.countRoleByDeptIds(deptIds) > 0, "所选部门存在角色关联,请解除后再试"); for (SystemDeptTb dept : depts) { systemDeptMapper.deleteById(dept.getId()); this.updateDeptSubCnt(dept.getPid()); @@ -112,7 +114,7 @@ public class SystemDeptService { } /** - * 更新父节点中子节点数目 -> TestPassed + * 更新父节点中子节点数目 * * @param deptId 部门id */ @@ -252,21 +254,6 @@ public class SystemDeptService { return systemDeptMapper.selectList(wrapper).stream().collect(Collectors.toMap(SystemDeptTb::getId, i -> i, (m, n) -> m)); } - /** - * 验证是否被角色或用户关联 - * - * @param deptSet / - */ - public void verifyBindRelationByIds(Set deptSet) { - Set deptIds = deptSet.stream().map(SystemDeptTb::getId).collect(Collectors.toSet()); - if (systemUserDeptService.countUserByDeptIds(deptIds) > 0) { - throw new BadRequestException("所选部门存在用户关联,请解除后再试!"); - } - if (systemRoleDeptService.countRoleByDeptIds(deptIds) > 0) { - throw new BadRequestException("所选部门存在角色关联,请解除后再试!"); - } - } - /** * 根据部门id遍历所有部门和子部门 * @@ -374,7 +361,7 @@ public class SystemDeptService { } /** - * 根据部门id查询部门信息 -> TestPassed + * 根据部门id查询部门信息 * * @param id 部门id * @return / diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDictDetailService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDictDetailService.java index e1f7de6a..0d9ee16d 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDictDetailService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDictDetailService.java @@ -49,21 +49,21 @@ public class SystemDictDetailService { private SystemDictMapper systemDictMapper; /** - * 创建 -> TestPassed + * 创建 * * @param args / */ @Transactional(rollbackFor = Exception.class) public void saveDictDetail(SystemCreateDictDetailArgs args) { - KitValidUtil.notNull(args); - KitValidUtil.notNull(args.getDict()); + KitValidUtil.isNull(args); + KitValidUtil.isNull(args.getDict()); SystemDictDetailTb dictDetail = KitBeanUtil.copyToClass(args, SystemDictDetailTb.class); dictDetail.setDictId(args.getDict().getId()); systemDictDetailMapper.insert(dictDetail); } /** - * 编辑 -> TestPassed + * 编辑 * * @param args / */ @@ -71,11 +71,11 @@ public class SystemDictDetailService { public void updateDictDetailById(SystemDictDetailTb args) { SystemDictDetailTb dictDetail = systemDictDetailMapper.selectById(args.getId()); args.setId(dictDetail.getId()); - systemDictDetailMapper.insertOrUpdate(args); + systemDictDetailMapper.updateById(args); } /** - * 删除 -> TestPassed + * 删除 * * @param id / */ @@ -99,7 +99,7 @@ public class SystemDictDetailService { } /** - * 分页查询 -> TestPassed + * 分页查询 * * @param args 条件 * @param page 分页参数 @@ -123,7 +123,7 @@ public class SystemDictDetailService { } /** - * 根据字典名称查询字典详情 -> TestPassed + * 根据字典名称查询字典详情 * * @param name 字典名称 * @return / diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDictService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDictService.java index b400df97..c1b81e1b 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDictService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDictService.java @@ -46,7 +46,7 @@ public class SystemDictService { private SystemDictDetailService systemDictDetailService; /** - * 创建 -> TestPassed + * 创建 * * @param args / */ @@ -57,7 +57,7 @@ public class SystemDictService { } /** - * 编辑 -> TestPassed + * 编辑 * * @param args / */ @@ -70,7 +70,7 @@ public class SystemDictService { } /** - * 删除 -> TestPassed + * 删除 * * @param ids / */ @@ -83,7 +83,7 @@ public class SystemDictService { } /** - * 分页查询 -> TestPassed + * 分页查询 * * @param args 条件 * @param page 分页参数 diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemEmailService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemEmailService.java index dc687253..a020c057 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemEmailService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemEmailService.java @@ -30,6 +30,7 @@ import cn.odboy.system.dal.model.request.SystemSendEmailArgs; import cn.odboy.system.dal.mysql.SystemEmailConfigMapper; import cn.odboy.util.KitDesEncryptUtil; import cn.odboy.util.KitResourceTemplateUtil; +import cn.odboy.util.KitValidUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -48,7 +49,7 @@ public class SystemEmailService { private AppProperties properties; /** - * 更新邮件配置 -> TestPassed + * 更新邮件配置 * * @param emailConfig 邮箱配置 */ @@ -64,15 +65,13 @@ public class SystemEmailService { } /** - * 发送邮件 -> TestPassed + * 发送邮件 * * @param sendEmailRequest 邮件发送的内容 */ public void sendEmail(SystemSendEmailArgs sendEmailRequest) { SystemEmailConfigTb systemEmailConfigTb = getLastEmailConfig(); - if (systemEmailConfigTb.getId() == null) { - throw new BadRequestException("请先配置, 再操作"); - } + KitValidUtil.isNull(systemEmailConfigTb.getId(), "请先配置, 再操作"); // 封装 MailAccount account = new MailAccount(); // 设置用户 @@ -112,23 +111,18 @@ public class SystemEmailService { * 发送给邮箱验证码 */ public void sendCaptcha(SystemCaptchaBizEnum biEnum, String email) { - if (biEnum == null) { - throw new BadRequestException("biEnum必填"); - } + KitValidUtil.isNull(biEnum, "biEnum必填"); String content; String redisKey = biEnum.getRedisKey() + email; String oldCode = redisHelper.get(redisKey, String.class); if (oldCode == null) { String code = RandomUtil.randomNumbers(6); // 存入缓存 - if (!redisHelper.set(redisKey, code, properties.getCaptcha().getExpireTime())) { - throw new BadRequestException("服务异常, 请联系网站负责人"); - } + KitValidUtil.isTrue(!redisHelper.set(redisKey, code, properties.getCaptcha().getExpireTime()), "服务异常, 请联系网站负责人"); // 存在就再次发送原来的验证码 content = KitResourceTemplateUtil.render(null, biEnum.getTemplateName(), Dict.create().set("code", code)); } else { - content = - KitResourceTemplateUtil.render(null, biEnum.getTemplateName(), Dict.create().set("code", oldCode)); + content = KitResourceTemplateUtil.render(null, biEnum.getTemplateName(), Dict.create().set("code", oldCode)); } SystemSendEmailArgs sendEmailRequest = new SystemSendEmailArgs(Collections.singletonList(email), SystemConst.CURRENT_APP_TITLE, content); @@ -146,23 +140,18 @@ public class SystemEmailService { } /** - * 校验邮箱验证码 -> TestPassed + * 校验邮箱验证码 */ public void checkEmailCaptcha(SystemCheckEmailCaptchaArgs args) { SystemCaptchaBizEnum biEnum = SystemCaptchaBizEnum.getByBizCode(args.getBizCode()); - if (biEnum == null) { - throw new BadRequestException("不支持的业务"); - } + KitValidUtil.isNull(biEnum, "不支持的业务"); this.checkEmailCaptchaV1(biEnum, args.getEmail(), args.getCode()); } public void checkEmailCaptchaV1(SystemCaptchaBizEnum biEnum, String email, String code) { String redisKey = biEnum.getRedisKey() + email; String value = redisHelper.get(redisKey, String.class); - if (value == null || !value.equals(code)) { - throw new BadRequestException("无效验证码"); - } else { - redisHelper.del(redisKey); - } + KitValidUtil.isTrue(value == null || !value.equals(code), "无效验证码"); + redisHelper.del(redisKey); } } diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemJobService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemJobService.java index 4a1137df..7f4b2c0c 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemJobService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemJobService.java @@ -18,7 +18,6 @@ package cn.odboy.system.service; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; import cn.odboy.base.KitPageResult; -import cn.odboy.framework.exception.BadRequestException; import cn.odboy.system.dal.dataobject.SystemJobTb; import cn.odboy.system.dal.model.export.SystemJobExportRowVo; import cn.odboy.system.dal.model.request.SystemCreateJobArgs; @@ -26,6 +25,7 @@ import cn.odboy.system.dal.model.request.SystemQueryJobArgs; import cn.odboy.system.dal.mysql.SystemJobMapper; import cn.odboy.util.KitBeanUtil; import cn.odboy.util.KitPageUtil; +import cn.odboy.util.KitValidUtil; import cn.odboy.util.xlsx.KitExcelExporter; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -46,48 +46,44 @@ public class SystemJobService { private SystemUserJobService systemUserJobService; /** - * 创建 -> TestPassed + * 创建 * * @param args / */ @Transactional(rollbackFor = Exception.class) public void saveJob(SystemCreateJobArgs args) { - if (this.existJobWithName(args.getName())) { - throw new BadRequestException("职位名称已存在"); - } + KitValidUtil.isTrue(this.existJobWithName(args.getName()), "职位名称已存在"); SystemJobTb systemJobTb = KitBeanUtil.copyToClass(args, SystemJobTb.class); systemJobMapper.insert(systemJobTb); } /** - * 编辑 -> TestPassed + * 编辑 * * @param args / */ @Transactional(rollbackFor = Exception.class) public void updateJobById(SystemJobTb args) { SystemJobTb job = systemJobMapper.selectById(args.getId()); - if (this.existJobWithNameNeSelf(args.getName(), job.getId())) { - throw new BadRequestException("职位名称已存在"); - } + KitValidUtil.isTrue(this.existJobWithNameNeSelf(args.getName(), job.getId()), "职位名称已存在"); args.setId(job.getId()); systemJobMapper.updateById(args); } /** - * 删除 -> TestPassed + * 删除 * * @param ids / */ @Transactional(rollbackFor = Exception.class) public void deleteJobByIds(Set ids) { // 验证是否被用户关联 - this.verifyBindRelationByIds(ids); + KitValidUtil.isTrue(systemUserJobService.countUserByJobIds(ids) > 0, "所选的岗位中存在用户关联, 请解除关联再试"); systemJobMapper.deleteByIds(ids); } /** - * 分页查询 -> TestPassed + * 分页查询 * * @param args 条件 * @param page 分页参数 @@ -100,7 +96,7 @@ public class SystemJobService { } /** - * 查询全部数据 -> TestPassed + * 查询全部数据 */ public List queryJobByArgs(SystemQueryJobArgs args) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); @@ -109,18 +105,7 @@ public class SystemJobService { } /** - * 验证是否被用户关联 -> TestPassed - * - * @param ids / - */ - public void verifyBindRelationByIds(Set ids) { - if (systemUserJobService.countUserByJobIds(ids) > 0) { - throw new BadRequestException("所选的岗位中存在用户关联, 请解除关联再试!"); - } - } - - /** - * 导出岗位数据 -> TestPassed + * 导出岗位数据 */ public void exportJobXlsx(HttpServletResponse response, SystemQueryJobArgs args) { List systemJobTbs = this.queryJobByArgs(args); @@ -136,7 +121,7 @@ public class SystemJobService { } /** - * 根据岗位名称查询岗位是否存在 -> TestPassed + * 根据岗位名称查询岗位是否存在 */ private boolean existJobWithName(String name) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); @@ -145,7 +130,7 @@ public class SystemJobService { } /** - * 根据岗位名称和岗位id查询岗位是否存在 -> TestPassed + * 根据岗位名称和岗位id查询岗位是否存在 */ private boolean existJobWithNameNeSelf(String name, Long currentJobId) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemLocalStorageService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemLocalStorageService.java index c8a0bfaf..20012ed6 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemLocalStorageService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemLocalStorageService.java @@ -32,6 +32,7 @@ import cn.odboy.system.dal.mysql.SystemLocalStorageMapper; import cn.odboy.util.KitBeanUtil; import cn.odboy.util.KitFileUtil; import cn.odboy.util.KitPageUtil; +import cn.odboy.util.KitValidUtil; import cn.odboy.util.xlsx.KitExcelExporter; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -61,7 +62,7 @@ public class SystemLocalStorageService { private SystemLocalStorageService localStorageService; /** - * 上传 -> TestPassed + * 上传 * * @param name 文件名称 * @param multipartFile 文件 @@ -75,9 +76,7 @@ public class SystemLocalStorageService { String type = KitFileUtil.getFileType(suffix); String uploadDateStr = DateUtil.format(new Date(), DatePattern.PURE_DATE_FORMAT); File file = KitFileUtil.upload(multipartFile, fileUploadPathHelper.getPath() + uploadDateStr + File.separator); - if (file == null) { - throw new BadRequestException("上传失败"); - } + KitValidUtil.isNull(file, "上传失败"); try { String formatSize = KitFileUtil.getSize(size); String prefixName = KitFileUtil.getPrefix(multipartFile.getOriginalFilename(), name); @@ -99,7 +98,7 @@ public class SystemLocalStorageService { } /** - * 编辑 -> TestPassed + * 编辑 * * @param args 文件信息 */ @@ -109,7 +108,7 @@ public class SystemLocalStorageService { } /** - * 多选删除 -> TestPassed + * 多选删除 * * @param ids / */ @@ -127,7 +126,7 @@ public class SystemLocalStorageService { } /** - * 分页查询 -> TestPassed + * 分页查询 * * @param args 条件 * @param page 分页参数 @@ -141,7 +140,7 @@ public class SystemLocalStorageService { } /** - * 查询文件上传记录 -> TestPassed + * 查询文件上传记录 */ public List queryLocalStorageByArgs(SystemQueryStorageArgs args) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); @@ -150,20 +149,18 @@ public class SystemLocalStorageService { } /** - * 上传图片 -> TestPassed + * 上传图片 */ @Transactional(rollbackFor = Exception.class) public SystemLocalStorageTb uploadPicture(MultipartFile file) { // 判断文件是否为图片 String suffix = KitFileUtil.getSuffix(file.getOriginalFilename()); - if (!FileTypeEnum.IMAGE.getCode().equals(KitFileUtil.getFileType(suffix))) { - throw new BadRequestException("只能上传图片"); - } + KitValidUtil.isTrue(!FileTypeEnum.IMAGE.getCode().equals(KitFileUtil.getFileType(suffix)), "只能上传图片"); return localStorageService.uploadFile(null, file); } /** - * 导出文件上传记录 -> TestPassed + * 导出文件上传记录 */ public void exportLocalStorageXlsx(HttpServletResponse response, SystemQueryStorageArgs args) { List systemLocalStorageTbs = this.queryLocalStorageByArgs(args); diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemMenuService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemMenuService.java index c6cb2f5b..c28b97e6 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemMenuService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemMenuService.java @@ -64,19 +64,15 @@ public class SystemMenuService { private SystemMenuService proxyService; /** - * 创建 -> TestPassed + * 创建 * * @param args / */ @Transactional(rollbackFor = Exception.class) public void saveMenu(SystemMenuTb args) { - if (this.existMenuWithTitle(args.getTitle())) { - throw new BadRequestException("菜单标题已存在"); - } + KitValidUtil.isTrue(this.existMenuWithTitle(args.getTitle()), "菜单标题已存在"); if (StrUtil.isNotBlank(args.getComponentName())) { - if (this.existMenuWithComponentName(args.getComponentName())) { - throw new BadRequestException("菜单组件名称已存在"); - } + KitValidUtil.isTrue(this.existMenuWithComponentName(args.getComponentName()), "菜单组件名称已存在"); } if (Long.valueOf(0L).equals(args.getPid())) { // 顶级目录 @@ -96,25 +92,20 @@ public class SystemMenuService { } /** - * 编辑 -> TestPassed + * 编辑 * * @param args / */ @Transactional(rollbackFor = Exception.class) public void updateMenuById(SystemMenuTb args) { - if (args.getId().equals(args.getPid())) { - throw new BadRequestException("上级不能为自己"); - } + KitValidUtil.isNullF(args.getId(), "id"); + KitValidUtil.isTrue(args.getId().equals(args.getPid()), "上级不能为自己"); SystemMenuTb menu = systemMenuMapper.selectById(args.getId()); if (args.getIFrame()) { - if (!(args.getPath().toLowerCase().startsWith(SystemTransferProtocolConst.PREFIX_HTTP) || args.getPath() - .toLowerCase().startsWith(SystemTransferProtocolConst.PREFIX_HTTPS))) { - throw new BadRequestException(SystemTransferProtocolConst.PREFIX_HTTPS_BAD_REQUEST); - } - } - if (this.existMenuWithTitleNeSelf(args.getTitle(), menu.getId())) { - throw new BadRequestException("菜单标题已存在"); + KitValidUtil.isTrue(!(args.getPath().toLowerCase().startsWith(SystemTransferProtocolConst.PREFIX_HTTP) || args.getPath() + .toLowerCase().startsWith(SystemTransferProtocolConst.PREFIX_HTTPS)), SystemTransferProtocolConst.PREFIX_HTTPS_BAD_REQUEST); } + KitValidUtil.isTrue(this.existMenuWithTitleNeSelf(args.getTitle(), menu.getId()), "菜单标题已存在"); if (args.getPid().equals(0L)) { args.setPid(null); } @@ -122,9 +113,7 @@ public class SystemMenuService { Long oldPid = menu.getPid(); Long newPid = args.getPid(); if (StrUtil.isNotBlank(args.getComponentName())) { - if (this.existMenuWithComponentNameNeSelf(args.getTitle(), menu.getId())) { - throw new BadRequestException("菜单组件名称已存在"); - } + KitValidUtil.isTrue(this.existMenuWithComponentNameNeSelf(args.getTitle(), menu.getId()), "菜单组件名称已存在"); } menu.setTitle(args.getTitle()); menu.setComponent(args.getComponent()); @@ -148,7 +137,7 @@ public class SystemMenuService { } /** - * 删除 -> TestPassed + * 删除 */ @Transactional(rollbackFor = Exception.class) public void deleteMenuByIds(Set ids) { @@ -261,7 +250,7 @@ public class SystemMenuService { } /** - * 根据ID查询同级与上级数据 -> TestPassed + * 根据ID查询同级与上级数据 * * @param menu / * @param menus / @@ -443,7 +432,7 @@ public class SystemMenuService { } private List queryMenuByArgs(SystemQueryMenuArgs args) { - KitValidUtil.notNull(args); + KitValidUtil.isNull(args); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.isNull(args.getPidIsNull() != null, SystemMenuTb::getPid); wrapper.eq(args.getPid() != null, SystemMenuTb::getPid, args.getPid()); @@ -458,7 +447,7 @@ public class SystemMenuService { } /** - * 查询根目录 -> TestPassed + * 查询根目录 */ private List listRootMenu() { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); @@ -468,7 +457,7 @@ public class SystemMenuService { } /** - * 根据组件名称查询菜单是否存在 -> TestPassed + * 根据组件名称查询菜单是否存在 * * @param componentName 组件名称 * @return / @@ -480,7 +469,7 @@ public class SystemMenuService { } /** - * 根据组件名称查询菜单是否存在 -> TestPassed + * 根据组件名称查询菜单是否存在 * * @param componentName 组件名称 * @return / @@ -493,7 +482,7 @@ public class SystemMenuService { } /** - * 根据菜单标题查询菜单是否存在 -> TestPassed + * 根据菜单标题查询菜单是否存在 * * @param title 菜单标题 * @return / @@ -505,7 +494,7 @@ public class SystemMenuService { } /** - * 根据菜单标题查询菜单是否存在 -> TestPassed + * 根据菜单标题查询菜单是否存在 * * @param title 菜单标题 * @return / @@ -537,7 +526,8 @@ public class SystemMenuService { List children = parentToChildrenMap.get(parentId); if (children != null && !children.isEmpty()) { for (SystemMenuTb child : children) { - if (result.add(child.getId())) { // 如果成功添加(之前不存在),则继续查找其子菜单 + // 如果成功添加(之前不存在),则继续查找其子菜单 + if (result.add(child.getId())) { nextLevelIds.add(child.getId()); } } @@ -563,7 +553,7 @@ public class SystemMenuService { } /** - * 根据菜单id查询目录 -> TestPassed + * 根据菜单id查询目录 * * @param id 菜单id */ diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemMonitorService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemMonitorService.java index 5df34fbd..6c3f7ee1 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemMonitorService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemMonitorService.java @@ -47,7 +47,7 @@ public class SystemMonitorService { private final DecimalFormat df = new DecimalFormat("0.00"); /** - * 查询服务器监控信息 -> TestPassed + * 查询服务器监控信息 * * @return Map */ @@ -75,7 +75,7 @@ public class SystemMonitorService { } /** - * 查询磁盘信息 -> TestPassed + * 查询磁盘信息 * * @return / */ @@ -109,7 +109,7 @@ public class SystemMonitorService { } /** - * 查询交换区信息 -> TestPassed + * 查询交换区信息 * * @param memory / * @return / @@ -131,7 +131,7 @@ public class SystemMonitorService { } /** - * 查询内存信息 -> TestPassed + * 查询内存信息 * * @param memory / * @return / @@ -149,7 +149,7 @@ public class SystemMonitorService { } /** - * 查询Cpu相关信息 -> TestPassed + * 查询Cpu相关信息 * * @param processor / * @return / @@ -196,7 +196,7 @@ public class SystemMonitorService { } /** - * 查询系统相关信息,系统、运行天数、系统IP -> TestPassed + * 查询系统相关信息,系统、运行天数、系统IP * * @param os / * @return / diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemOperationLogService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemOperationLogService.java index a76e9cf9..4243257c 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemOperationLogService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemOperationLogService.java @@ -33,7 +33,7 @@ public class SystemOperationLogService { private SystemOperationLogMapper systemOperationLogMapper; /** - * 查询用户操作日志 -> TestPassed + * 查询用户操作日志 */ public IPage searchUserLog(KitPageArgs pageArgs) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemQuartzJobService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemQuartzJobService.java index 1d81a236..34c6826f 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemQuartzJobService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemQuartzJobService.java @@ -28,12 +28,12 @@ import cn.odboy.system.dal.model.export.SystemQuartzJobExportRowVo; import cn.odboy.system.dal.model.export.SystemQuartzLogExportRowVo; import cn.odboy.system.dal.model.request.SystemQueryQuartzJobArgs; import cn.odboy.system.dal.model.request.SystemUpdateQuartzJobArgs; -import cn.odboy.system.dal.model.response.SystemQuartzJobVo; import cn.odboy.system.dal.mysql.SystemQuartzJobMapper; import cn.odboy.system.dal.mysql.SystemQuartzLogMapper; import cn.odboy.system.framework.quartz.QuartzManage; import cn.odboy.util.KitBeanUtil; import cn.odboy.util.KitPageUtil; +import cn.odboy.util.KitValidUtil; import cn.odboy.util.xlsx.KitExcelExporter; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -60,27 +60,23 @@ public class SystemQuartzJobService { private KitRedisHelper redisHelper; /** - * 创建 -> TestPassed + * 创建 * * @param args / */ @Transactional(rollbackFor = Exception.class) public void createJob(SystemQuartzJobTb args) { - if (args.getId() != null) { - throw new BadRequestException("无效参数id"); - } // 验证Bean是不是合法的, 合法的定时任务 Bean 需要用 @Service 定义 checkBean(args.getBeanName()); if (!CronExpression.isValidExpression(args.getCronExpression())) { throw new BadRequestException("cron表达式格式错误"); } systemQuartzJobMapper.insert(args); - SystemQuartzJobVo quartzJobVo = KitBeanUtil.copyToClass(args, SystemQuartzJobVo.class); - quartzManage.addJob(quartzJobVo); + quartzManage.addJob(args); } /** - * 修改任务并重新调度 -> TestPassed + * 修改任务并重新调度 * * @param args / */ @@ -88,14 +84,10 @@ public class SystemQuartzJobService { public void updateQuartzJobResumeCron(SystemUpdateQuartzJobArgs args) { // 验证Bean是不是合法的, 合法的定时任务 Bean 需要用 @Service 定义 checkBean(args.getBeanName()); - if (!CronExpression.isValidExpression(args.getCronExpression())) { - throw new BadRequestException("cron表达式格式错误"); - } + KitValidUtil.isTrue(!CronExpression.isValidExpression(args.getCronExpression()), "Cron表达式格式错误"); if (StrUtil.isNotBlank(args.getSubTask())) { List tasks = Arrays.asList(args.getSubTask().split("[,,]")); - if (tasks.contains(args.getId().toString())) { - throw new BadRequestException("子任务中不能添加当前任务ID"); - } + KitValidUtil.isTrue(tasks.contains(args.getId().toString()), "子任务中不能添加当前任务ID"); } SystemQuartzJobTb jobTb = KitBeanUtil.copyToClass(args, SystemQuartzJobTb.class); systemQuartzJobMapper.updateById(jobTb); @@ -103,35 +95,34 @@ public class SystemQuartzJobService { } /** - * 更改定时任务状态 -> TestPassed + * 更改定时任务状态 * - * @param quartzJobVo / + * @param quartzJobTb / */ @Transactional(rollbackFor = Exception.class) - public void switchQuartzJobStatus(SystemQuartzJobVo quartzJobVo) { + public void switchQuartzJobStatus(SystemQuartzJobTb quartzJobTb) { // 置换暂停状态 - if (quartzJobVo.getIsPause()) { - quartzManage.resumeJob(quartzJobVo); - quartzJobVo.setIsPause(false); + if (quartzJobTb.getIsPause()) { + quartzManage.resumeJob(quartzJobTb); + quartzJobTb.setIsPause(false); } else { - quartzManage.pauseJob(quartzJobVo); - quartzJobVo.setIsPause(true); + quartzManage.pauseJob(quartzJobTb); + quartzJobTb.setIsPause(true); } - SystemQuartzJobTb record = KitBeanUtil.copyToClass(quartzJobVo, SystemQuartzJobTb.class); - systemQuartzJobMapper.updateById(record); + systemQuartzJobMapper.updateById(quartzJobTb); } /** - * 立即执行定时任务 -> TestPassed + * 立即执行定时任务 * * @param quartzJob / */ - public void startQuartzJob(SystemQuartzJobVo quartzJob) { + public void startQuartzJob(SystemQuartzJobTb quartzJob) { quartzManage.runJobNow(quartzJob); } /** - * 删除任务 -> TestPassed + * 删除任务 * * @param ids / */ @@ -145,7 +136,7 @@ public class SystemQuartzJobService { } /** - * 执行子任务 -> TestPassed + * 执行子任务 * * @param tasks / * @throws InterruptedException / @@ -162,11 +153,10 @@ public class SystemQuartzJobService { // 防止子任务不存在 continue; } - SystemQuartzJobVo quartzJobVo = KitBeanUtil.copyToClass(quartzJobTb, SystemQuartzJobVo.class); // 执行任务 String uuid = IdUtil.simpleUUID(); - quartzJobVo.setUuid(uuid); - startQuartzJob(quartzJobVo); + quartzJobTb.setUuid(uuid); + startQuartzJob(quartzJobTb); // 查询执行状态, 如果执行失败则停止后面的子任务执行 Boolean result = redisHelper.get(uuid, Boolean.class); while (result == null) { @@ -182,7 +172,7 @@ public class SystemQuartzJobService { } /** - * 分页查询 -> TestPassed + * 分页查询 * * @param args 条件 * @param page 分页参数 @@ -195,7 +185,7 @@ public class SystemQuartzJobService { } /** - * 分页查询日志 -> TestPassed + * 分页查询日志 * * @param args 条件 * @param page 分页参数 @@ -208,7 +198,7 @@ public class SystemQuartzJobService { } /** - * 查询全部 -> TestPassed + * 查询全部 * * @param args 条件 * @return / @@ -220,7 +210,7 @@ public class SystemQuartzJobService { } /** - * 查询全部 -> TestPassed + * 查询全部 * * @param args 条件 * @return / @@ -232,7 +222,7 @@ public class SystemQuartzJobService { } /** - * 查询启用的定时任务 -> TestPassed + * 查询启用的定时任务 */ public List listEnableQuartzJob() { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); @@ -241,7 +231,7 @@ public class SystemQuartzJobService { } /** - * 导出定时任务数据 -> TestPassed + * 导出定时任务数据 */ public void exportQuartzJobXlsx(HttpServletResponse response, SystemQueryQuartzJobArgs args) { List systemQuartzJobTbs = this.queryQuartzJobByArgs(args); @@ -262,7 +252,7 @@ public class SystemQuartzJobService { } /** - * 导出定时任务日志数据 -> TestPassed + * 导出定时任务日志数据 */ public void exportQuartzLogXlsx(HttpServletResponse response, SystemQueryQuartzJobArgs args) { List systemQuartzLogTbs = this.queryQuartzLogByArgs(args); @@ -284,7 +274,7 @@ public class SystemQuartzJobService { } /** - * 根据任务id查询定时任务 -> TestPassed + * 根据任务id查询定时任务 */ public SystemQuartzJobTb getQuartzJobById(Long id) { return systemQuartzJobMapper.selectById(id); @@ -332,9 +322,7 @@ public class SystemQuartzJobService { */ private void checkBean(String beanName) { // 避免调用攻击者可以从SpringContextHolder获得控制jdbcTemplate类 - // 并使用getDeclaredMethod调用jdbcTemplate的queryForMap函数,执行任意sql命令。 - if (!KitSpringBeanHolder.getAllServiceBeanName().contains(beanName)) { - throw new BadRequestException("非法的 Bean,请重新输入!"); - } + // 并使用getDeclaredMethod调用jdbcTemplate的queryForMap函数,执行任意sql命令 + KitValidUtil.isTrue(!KitSpringBeanHolder.getAllServiceBeanName().contains(beanName), "非法的 Bean,请重新输入"); } } diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemRoleDeptService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemRoleDeptService.java index c2232ffa..e1c65e9a 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemRoleDeptService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemRoleDeptService.java @@ -34,7 +34,7 @@ public class SystemRoleDeptService { private SystemRoleDeptMapper systemRoleDeptMapper; /** - * 批量删除角色部门关联 -> TestPassed + * 批量删除角色部门关联 * * @param roleIds 角色id集合 */ @@ -48,7 +48,7 @@ public class SystemRoleDeptService { } /** - * 批量绑定角色部门关联 -> TestPassed + * 批量绑定角色部门关联 * * @param depts 部门集合 * @param roleId 角色id @@ -68,7 +68,7 @@ public class SystemRoleDeptService { } /** - * 根据部门ID统计角色数量 -> TestPassed + * 根据部门ID统计角色数量 * * @param deptIds 部门id集合 * @return / @@ -83,7 +83,7 @@ public class SystemRoleDeptService { } /** - * 根据角色id查询部门信息 -> TestPassed + * 根据角色id查询部门信息 * * @param roleId 角色id * @return / diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemRoleMenuService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemRoleMenuService.java index ff921186..e27f88c4 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemRoleMenuService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemRoleMenuService.java @@ -36,7 +36,7 @@ public class SystemRoleMenuService { private SystemRoleMenuMapper systemRoleMenuMapper; /** - * 删除角色菜单关联 -> TestPassed + * 删除角色菜单关联 * * @param roleId 角色id */ @@ -48,7 +48,7 @@ public class SystemRoleMenuService { } /** - * 批量绑定角色菜单关联 -> TestPassed + * 批量绑定角色菜单关联 * * @param menus 菜单集合 * @param roleId 角色id @@ -68,7 +68,7 @@ public class SystemRoleMenuService { } /** - * 批量删除角色菜单关联 -> TestPassed + * 批量删除角色菜单关联 * * @param roleIds 角色id集合 */ @@ -82,7 +82,7 @@ public class SystemRoleMenuService { } /** - * @param roleIds 角色id集合 -> TestPassed + * @param roleIds 角色id集合 * @return / */ public List listMenuByRoleIds(Set roleIds, boolean hasButton) { @@ -109,7 +109,7 @@ public class SystemRoleMenuService { } /** - * 批量删除菜单角色关联 -> TestPassed + * 批量删除菜单角色关联 * * @param menuIds 菜单id集合 */ @@ -124,7 +124,7 @@ public class SystemRoleMenuService { } /** - * 根据角色id集合查询菜单权限 -> TestPassed + * 根据角色id集合查询菜单权限 * * @param roleIds 角色id集合 * @return / diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemRoleService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemRoleService.java index 1b09ae07..4f36282b 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemRoleService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemRoleService.java @@ -19,7 +19,6 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.lang.Dict; import cn.hutool.core.util.StrUtil; import cn.odboy.base.KitPageResult; -import cn.odboy.framework.exception.BadRequestException; import cn.odboy.system.dal.dataobject.SystemMenuTb; import cn.odboy.system.dal.dataobject.SystemRoleTb; import cn.odboy.system.dal.model.export.SystemRoleExportRowVo; @@ -32,6 +31,7 @@ import cn.odboy.system.dal.mysql.SystemRoleMapper; import cn.odboy.system.framework.permission.core.KitSecurityHelper; import cn.odboy.util.KitBeanUtil; import cn.odboy.util.KitPageUtil; +import cn.odboy.util.KitValidUtil; import cn.odboy.util.xlsx.KitExcelExporter; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -60,16 +60,14 @@ public class SystemRoleService { private SystemUserRoleService systemUserRoleService; /** - * 创建 -> TestPassed + * 创建 * * @param args / */ @Transactional(rollbackFor = Exception.class) public void saveRole(SystemCreateRoleArgs args) { this.checkRoleLevels(args.getLevel()); - if (this.existRoleWithName(args.getName())) { - throw new BadRequestException("角色名称已存在"); - } + KitValidUtil.isTrue(this.existRoleWithName(args.getName()), "角色名称已存在"); SystemRoleTb roleTb = KitBeanUtil.copyToClass(args, SystemRoleTb.class); systemRoleMapper.insert(roleTb); // 判断是否有部门数据, 若有, 则需创建关联 @@ -79,7 +77,7 @@ public class SystemRoleService { } /** - * 修改 -> TestPassed + * 修改 * * @param args / */ @@ -87,9 +85,7 @@ public class SystemRoleService { public void updateRoleById(SystemRoleVo args) { this.checkRoleLevels(args.getLevel()); SystemRoleTb role = systemRoleMapper.selectById(args.getId()); - if (this.existRoleWithNameNeSelf(args.getName(), role.getId())) { - throw new BadRequestException("角色名称已存在"); - } + KitValidUtil.isTrue(this.existRoleWithNameNeSelf(args.getName(), role.getId()), "角色名称已存在"); role.setName(args.getName()); role.setDescription(args.getDescription()); role.setDataScope(args.getDataScope()); @@ -105,7 +101,7 @@ public class SystemRoleService { } /** - * 修改绑定的菜单 -> TestPassed + * 修改绑定的菜单 * * @param args / */ @@ -122,7 +118,7 @@ public class SystemRoleService { } /** - * 删除 -> TestPassed + * 删除 * * @param ids / */ @@ -133,7 +129,7 @@ public class SystemRoleService { this.checkRoleLevels(roleLevel); } // 验证是否被用户关联 - this.verifyBindRelationByIds(ids); + KitValidUtil.isTrue(systemUserRoleService.existUserWithRoleIds(ids), "所选角色存在用户关联, 请解除关联再试"); // 删除角色 systemRoleMapper.deleteByIds(ids); // 删除角色部门关联数据、角色菜单关联数据 @@ -142,7 +138,7 @@ public class SystemRoleService { } /** - * 查询全部角色 -> TestPassed + * 查询全部角色 */ public List listAllRole() { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); @@ -151,7 +147,7 @@ public class SystemRoleService { } /** - * 根据条件查询全部角色 -> TestPassed + * 根据条件查询全部角色 * * @param args 条件 * @param rolePage 分页参数 @@ -164,7 +160,7 @@ public class SystemRoleService { } /** - * 分页查询角色 -> TestPassed + * 分页查询角色 * * @param args 条件 * @param page 分页条件 @@ -178,7 +174,7 @@ public class SystemRoleService { } /** - * 查询用户权限信息 -> TestPassed? + * 查询用户权限信息? * * @param user 用户信息 * @return 权限信息 @@ -204,17 +200,6 @@ public class SystemRoleService { return permissions.stream().map(SystemRoleCodeVo::new).collect(Collectors.toList()); } - /** - * 验证是否被用户关联 -> TestPassed - * - * @param ids / - */ - public void verifyBindRelationByIds(Set ids) { - if (systemUserRoleService.existUserWithRoleIds(ids)) { - throw new BadRequestException("所选角色存在用户关联, 请解除关联再试!"); - } - } - /** * 根据角色id查询用户可访问的部门和菜单信息 * @@ -281,7 +266,7 @@ public class SystemRoleService { } /** - * 检查用户的角色级别 -> TestPassed + * 检查用户的角色级别 * * @return / */ @@ -289,9 +274,7 @@ public class SystemRoleService { Set levels = systemUserRoleService.listUserRoleLevelByUserId(KitSecurityHelper.getCurrentUserId()); int min = Collections.min(levels); if (level != null) { - if (level < min) { - throw new BadRequestException("权限不足, 你的角色级别:" + min + ", 低于操作的角色级别:" + level); - } + KitValidUtil.isTrue(level < min, "权限不足, 你的角色级别:" + min + ", 低于操作的角色级别:" + level); } return min; } diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserDeptService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserDeptService.java index d5d7b468..cd009afa 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserDeptService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserDeptService.java @@ -29,7 +29,7 @@ public class SystemUserDeptService { private SystemUserMapper systemUserMapper; /** - * 根据部门id统计用户数量 -> TestPassed + * 根据部门id统计用户数量 */ public long countUserByDeptIds(Set deptIds) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserJobService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserJobService.java index a994d5ee..a42de3a8 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserJobService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserJobService.java @@ -34,7 +34,7 @@ public class SystemUserJobService { private SystemUserJobMapper systemUserJobMapper; /** - * 批量绑定用户岗位 -> TestPassed + * 批量绑定用户岗位 */ @Transactional(rollbackFor = Exception.class) public void batchInsertUserJob(Set jobs, Long userId) { @@ -51,7 +51,7 @@ public class SystemUserJobService { } /** - * 批量解绑用户岗位 -> TestPassed + * 批量解绑用户岗位 */ @Transactional(rollbackFor = Exception.class) public void batchDeleteUserJob(Set userIds) { @@ -63,7 +63,7 @@ public class SystemUserJobService { } /** - * 根据岗位ID统计用户数量 -> TestPassed + * 根据岗位ID统计用户数量 * * @param jobIds / * @return / @@ -78,7 +78,7 @@ public class SystemUserJobService { } /** - * 根据用户id查询岗位 -> TestPassed + * 根据用户id查询岗位 * * @param userId / * @return / diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserRoleService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserRoleService.java index 76d6e861..af81a009 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserRoleService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserRoleService.java @@ -52,7 +52,7 @@ public class SystemUserRoleService { private SystemRoleDeptService systemRoleDeptService; /** - * 批量绑定用户角色 -> TestPassed + * 批量绑定用户角色 */ @Transactional(rollbackFor = Exception.class) public void batchInsertUserRole(Set roles, Long userId) { @@ -69,7 +69,7 @@ public class SystemUserRoleService { } /** - * 批量解绑用户角色 -> TestPassed + * 批量解绑用户角色 */ @Transactional(rollbackFor = Exception.class) public void batchDeleteUserRole(Set userIds) { @@ -101,7 +101,7 @@ public class SystemUserRoleService { } /** - * 根据用户ID查询 -> TestPassed + * 根据用户ID查询 * * @param userId 用户ID * @return / @@ -112,7 +112,7 @@ public class SystemUserRoleService { } /** - * 根据角色查询角色级别 -> TestPassed + * 根据角色查询角色级别 * * @param roles / * @return / @@ -136,7 +136,7 @@ public class SystemUserRoleService { } /** - * 如果当前用户的角色级别低于创建用户的角色级别,则抛出权限不足的错误 -> TestPassed + * 如果当前用户的角色级别低于创建用户的角色级别,则抛出权限不足的错误 * * @param args / */ @@ -150,7 +150,7 @@ public class SystemUserRoleService { } /** - * 根据用户id查询角色 -> TestPassed + * 根据用户id查询角色 * * @param userId / * @return / @@ -160,7 +160,7 @@ public class SystemUserRoleService { } /** - * 根据用户id查询角色级别集合 -> TestPassed + * 根据用户id查询角色级别集合 * * @param userId / * @return / @@ -170,7 +170,7 @@ public class SystemUserRoleService { } /** - * 根据用户id查询角色id集合 -> TestPassed + * 根据用户id查询角色id集合 * * @param userId / * @return / @@ -180,7 +180,7 @@ public class SystemUserRoleService { } /** - * 根据角色id集合判断是否存在关联用户 -> TestPassed + * 根据角色id集合判断是否存在关联用户 * * @param ids 角色id集合 * @return / diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserService.java index 35438ea0..f6e24670 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserService.java @@ -18,7 +18,6 @@ package cn.odboy.system.service; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; import cn.odboy.base.KitPageResult; -import cn.odboy.framework.exception.BadRequestException; import cn.odboy.framework.properties.AppProperties; import cn.odboy.framework.server.core.KitFileLocalUploadHelper; import cn.odboy.system.constant.SystemCaptchaBizEnum; @@ -39,6 +38,7 @@ import cn.odboy.util.KitBeanUtil; import cn.odboy.util.KitFileUtil; import cn.odboy.util.KitPageUtil; import cn.odboy.util.KitRsaEncryptUtil; +import cn.odboy.util.KitValidUtil; import cn.odboy.util.xlsx.KitExcelExporter; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -87,7 +87,7 @@ public class SystemUserService { private PasswordEncoder passwordEncoder; /** - * 新增用户 -> TestPassed + * 新增用户 * * @param args / */ @@ -98,15 +98,9 @@ public class SystemUserService { // 默认密码 123456 record.setPassword(passwordEncoder.encode("123456")); record.setDeptId(args.getDept().getId()); - if (this.existUserWithUsername(record.getUsername())) { - throw new BadRequestException("用户名已存在"); - } - if (this.existUserWithEmail(record.getEmail())) { - throw new BadRequestException("邮箱已存在"); - } - if (this.existUserWithPhone(record.getPhone())) { - throw new BadRequestException("手机号已存在"); - } + KitValidUtil.isTrue(this.existUserWithUsername(record.getUsername()), "用户名已存在"); + KitValidUtil.isTrue(this.existUserWithEmail(record.getEmail()), "邮箱已存在"); + KitValidUtil.isTrue(this.existUserWithPhone(record.getPhone()), "手机号已存在"); // 保存用户 systemUserMapper.insert(record); // 保存用户岗位 @@ -116,7 +110,7 @@ public class SystemUserService { } /** - * 编辑用户 -> TestPassed + * 编辑用户 * * @param args / */ @@ -124,15 +118,9 @@ public class SystemUserService { public void updateUserById(SystemUserVo args) { systemUserRoleService.checkLevel(args); SystemUserTb user = systemUserMapper.selectById(args.getId()); - if (this.existUserWithUsernameNeSelf(args.getUsername(), user.getId())) { - throw new BadRequestException("用户名已存在"); - } - if (this.existUserWithEmailNeSelf(args.getEmail(), user.getId())) { - throw new BadRequestException("邮箱已存在"); - } - if (this.existUserWithPhoneNeSelf(args.getPhone(), user.getId())) { - throw new BadRequestException("手机号已存在"); - } + KitValidUtil.isTrue(this.existUserWithUsernameNeSelf(args.getUsername(), user.getId()), "用户名已存在"); + KitValidUtil.isTrue(this.existUserWithEmailNeSelf(args.getEmail(), user.getId()), "邮箱已存在"); + KitValidUtil.isTrue(this.existUserWithPhoneNeSelf(args.getPhone(), user.getId()), "手机号已存在"); // 如果用户被禁用, 则清除用户登录信息 if (!args.getEnabled()) { systemUserOnlineInfoDAO.kickOutByUsername(args.getUsername()); @@ -156,19 +144,15 @@ public class SystemUserService { } /** - * 用户自助修改资料 -> TestPassed + * 用户自助修改资料 * * @param args / */ @Transactional(rollbackFor = Exception.class) public void updateUserCenterInfoById(SystemUserTb args) { - if (!args.getId().equals(KitSecurityHelper.getCurrentUserId())) { - throw new BadRequestException("不能修改他人资料"); - } + KitValidUtil.isTrue(!args.getId().equals(KitSecurityHelper.getCurrentUserId()), "不能修改他人资料"); SystemUserTb user = systemUserMapper.selectById(args.getId()); - if (this.existUserWithPhoneNeSelf(args.getPhone(), user.getId())) { - throw new BadRequestException("手机号已存在"); - } + KitValidUtil.isTrue(this.existUserWithPhoneNeSelf(args.getPhone(), user.getId()), "手机号已存在"); user.setNickName(args.getNickName()); user.setPhone(args.getPhone()); user.setGender(args.getGender()); @@ -177,7 +161,7 @@ public class SystemUserService { } /** - * 删除用户 -> TestPassed + * 删除用户 * * @param ids / */ @@ -186,12 +170,10 @@ public class SystemUserService { Long currentUserId = KitSecurityHelper.getCurrentUserId(); // 校验权限 for (Long id : ids) { + SystemUserTb systemUserTb = systemUserMapper.selectById(id); Integer currentLevel = Collections.min(systemUserRoleService.listUserRoleLevelByUserId(currentUserId)); Integer optLevel = Collections.min(systemUserRoleService.listUserRoleLevelByUserId(id)); - if (currentLevel > optLevel) { - SystemUserTb systemUserTb = systemUserMapper.selectById(id); - throw new BadRequestException("角色权限不足, 不能删除:" + systemUserTb.getUsername()); - } + KitValidUtil.isTrue(currentLevel > optLevel, "角色权限不足, 不能删除:" + systemUserTb.getUsername()); } // 清理缓存 List usernameList = systemUserMapper.listUsernameByIds(ids); @@ -207,7 +189,7 @@ public class SystemUserService { } /** - * 修改密码 -> TestPassed + * 修改密码 * * @param username 用户名 * @param args 参数 @@ -217,19 +199,15 @@ public class SystemUserService { String oldPass = KitRsaEncryptUtil.decryptByPrivateKey(properties.getRsa().getPrivateKey(), args.getOldPass()); String newPass = KitRsaEncryptUtil.decryptByPrivateKey(properties.getRsa().getPrivateKey(), args.getNewPass()); SystemUserTb user = this.getUserByUsername(username); - if (!passwordEncoder.matches(oldPass, user.getPassword())) { - throw new BadRequestException("修改失败,旧密码错误"); - } - if (passwordEncoder.matches(newPass, user.getPassword())) { - throw new BadRequestException("新密码不能与旧密码相同"); - } + KitValidUtil.isTrue(!passwordEncoder.matches(oldPass, user.getPassword()), "修改失败,旧密码错误"); + KitValidUtil.isTrue(passwordEncoder.matches(newPass, user.getPassword()), "新密码不能与旧密码相同"); String encryptPassword = passwordEncoder.encode(newPass); systemUserMapper.updateUserPasswordByUsername(username, encryptPassword); systemUserInfoDAO.deleteUserLoginInfoByUserName(username); } /** - * 重置密码 -> TestPassed + * 重置密码 * * @param ids 用户id */ @@ -249,7 +227,7 @@ public class SystemUserService { } /** - * 修改头像 -> TestPassed + * 修改头像 * * @param multipartFile 文件 * @return / @@ -258,17 +236,13 @@ public class SystemUserService { public Map updateUserAvatar(MultipartFile multipartFile) { SystemUserTb user = this.getUserByUsername(KitSecurityHelper.getCurrentUsername()); String username = user.getUsername(); - if (StrUtil.isBlank(username)) { - throw new BadRequestException("异常用户数据, 请联系管理员处理!"); - } + KitValidUtil.isBlank(username, "异常用户数据, 请联系管理员处理"); // 文件大小验证 KitFileUtil.checkSize(fileUploadPathHelper.getAvatarMaxSize(), multipartFile.getSize()); // 验证文件上传的格式 String image = "gif jpg png jpeg"; String fileType = KitFileUtil.getSuffix(multipartFile.getOriginalFilename()); - if (fileType != null && !image.contains(fileType)) { - throw new BadRequestException("文件格式错误, 仅支持 " + image + " 格式!"); - } + KitValidUtil.isTrue(fileType != null && !image.contains(fileType), "文件格式错误, 仅支持 " + image + " 格式"); String oldPath = user.getAvatarPath(); File file = KitFileUtil.upload(multipartFile, fileUploadPathHelper.getPath()); user.setAvatarPath(Objects.requireNonNull(file).getPath()); @@ -284,7 +258,7 @@ public class SystemUserService { } /** - * 修改邮箱 -> TestPassed + * 修改邮箱 * * @param username 用户名 * @param args 参数 @@ -294,16 +268,14 @@ public class SystemUserService { public void updateUserEmailByUsername(String username, SystemUserTb args, String code) throws Exception { String password = KitRsaEncryptUtil.decryptByPrivateKey(properties.getRsa().getPrivateKey(), args.getPassword()); SystemUserTb user = this.getUserByUsername(username); - if (!passwordEncoder.matches(password, user.getPassword())) { - throw new BadRequestException("密码错误"); - } + KitValidUtil.isTrue(!passwordEncoder.matches(password, user.getPassword()), "密码错误"); systemEmailService.checkEmailCaptchaV1(SystemCaptchaBizEnum.EMAIL_RESET_EMAIL_CODE, args.getEmail(), code); systemUserMapper.updateUserEmailByUsername(username, args.getEmail()); systemUserInfoDAO.deleteUserLoginInfoByUserName(username); } /** - * 查询全部 -> TestPassed + * 查询全部 * * @param args 条件 * @param page 分页参数 @@ -360,12 +332,12 @@ public class SystemUserService { * @param username 用户名 * @return / */ - public SystemUserVo getUserVoByUsername(String username) { - return this.convertToUserVo(this.getUserByUsername(username), false); + public SystemUserVo getUserVoByUsername(String username, boolean includePassword) { + return this.convertToUserVo(this.getUserByUsername(username), includePassword); } /** - * 聚合查询 -> TestPassed + * 聚合查询 */ public KitPageResult aggregationSearchUserByArgs(Page page, SystemQueryUserArgs args, String currentUsername) { if (!ObjectUtils.isEmpty(args.getDeptId())) { @@ -377,7 +349,7 @@ public class SystemUserService { args.getDeptIds().addAll(systemDeptService.queryChildDeptIdByDeptIds(data, deptPidMap)); } // 数据权限 - List dataScopes = systemDataService.queryDeptIdByArgs(this.getUserVoByUsername(currentUsername)); + List dataScopes = systemDataService.queryDeptIdByArgs(this.getUserVoByUsername(currentUsername, false)); // args.getDeptIds() 不为空并且数据权限不为空则取交集 if (!CollUtil.isEmpty(args.getDeptIds()) && !CollUtil.isEmpty(dataScopes)) { // 取交集 @@ -394,7 +366,7 @@ public class SystemUserService { } /** - * 导出 -> TestPassed + * 导出 */ public void exportUserXlsx(HttpServletResponse response, SystemQueryUserArgs args) { long totalCount = this.countUserByArgs(args); @@ -511,15 +483,9 @@ public class SystemUserService { */ private void injectQueryParams(SystemQueryUserArgs args, LambdaQueryWrapper wrapper) { if (args != null) { - if (args.getId() != null) { - wrapper.eq(SystemUserTb::getId, args.getId()); - } - if (args.getEnabled() != null) { - wrapper.eq(SystemUserTb::getEnabled, args.getEnabled()); - } - if (CollUtil.isNotEmpty(args.getDeptIds())) { - wrapper.in(SystemUserTb::getDeptId, args.getDeptIds()); - } + wrapper.eq(args.getId() != null, SystemUserTb::getId, args.getId()); + wrapper.eq(args.getEnabled() != null, SystemUserTb::getEnabled, args.getEnabled()); + wrapper.in(CollUtil.isNotEmpty(args.getDeptIds()), SystemUserTb::getDeptId, args.getDeptIds()); if (StrUtil.isNotBlank(args.getBlurry())) { wrapper.and(w -> w.like(SystemUserTb::getUsername, args.getBlurry()).or() .like(SystemUserTb::getNickName, args.getBlurry()).or().like(SystemUserTb::getEmail, args.getBlurry())); @@ -532,7 +498,7 @@ public class SystemUserService { } /** - * 转换为SystemUserVo并关联查询部门、角色、岗位信息 -> TestPassed + * 转换为SystemUserVo并关联查询部门、角色、岗位信息 * * @param user 用户基本信息 * @param includePassword 是否包含用户密码 diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/impl/SystemMinioStorageServiceImpl.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/impl/SystemMinioStorageServiceImpl.java index f9488150..ef0296ca 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/impl/SystemMinioStorageServiceImpl.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/impl/SystemMinioStorageServiceImpl.java @@ -80,11 +80,8 @@ public class SystemMinioStorageServiceImpl extends ServiceImpl selectOssStorageByArgs( - SystemQueryStorageArgs args, - Page page - ) { - KitValidUtil.notNull(args); + private IPage selectOssStorageByArgs(SystemQueryStorageArgs args, Page page) { + KitValidUtil.isNull(args); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.and( StrUtil.isNotBlank(args.getBlurry()), diff --git a/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitBigDecimalUtil.java b/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitBigDecimalUtil.java index 538af470..72278f55 100644 --- a/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitBigDecimalUtil.java +++ b/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitBigDecimalUtil.java @@ -17,6 +17,7 @@ package cn.odboy.util; import java.math.BigDecimal; import java.math.RoundingMode; +import java.text.NumberFormat; import lombok.experimental.UtilityClass; /** @@ -133,6 +134,23 @@ public final class KitBigDecimalUtil { return yuan.multiply(BigDecimal.valueOf(100)).setScale(0, RoundingMode.HALF_UP).longValue(); } + /** + * 格式化为 xxx,xxx,xxx 格式 + * + * @param obj 金额 + * @return / + */ + public static String formatGroupingAmount(Object obj) { + if (obj == null) { + return "0"; + } + BigDecimal bigDecimal = toBigDecimal(obj); + NumberFormat nf = NumberFormat.getInstance(); + // 启用千位分隔符 + nf.setGroupingUsed(true); + return nf.format(bigDecimal.setScale(0, RoundingMode.HALF_UP)); + } + public static void main(String[] args) { BigDecimal num1 = new BigDecimal("10.123"); BigDecimal num2 = new BigDecimal("2.456"); diff --git a/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitCollUtil.java b/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitCollUtil.java index 867f7ed1..a4fc92ba 100644 --- a/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitCollUtil.java +++ b/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitCollUtil.java @@ -15,9 +15,7 @@ */ package cn.odboy.util; -import cn.hutool.core.collection.CollUtil; import cn.odboy.base.KitSelectOptionVo; -import cn.odboy.framework.exception.BadRequestException; import com.alibaba.fastjson2.JSON; import java.lang.reflect.Field; import java.math.BigDecimal; @@ -194,7 +192,7 @@ public final class KitCollUtil extends cn.hutool.core.collection.CollUtil { * @return / */ public static BigDecimal streamBigDecimalAvg(List data) { - KitValidUtil.notEmpty(data, "data"); + KitValidUtil.isEmpty(data, "data"); return data.stream().filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add) .divide(BigDecimal.valueOf(data.size()), 6, RoundingMode.FLOOR); } diff --git a/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitDateUtil.java b/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitDateUtil.java index 51f20279..7614342f 100644 --- a/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitDateUtil.java +++ b/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitDateUtil.java @@ -17,6 +17,7 @@ package cn.odboy.util; import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; +import java.util.Calendar; import java.util.Date; import lombok.experimental.UtilityClass; @@ -129,4 +130,22 @@ public class KitDateUtil { } return result.toString(); } + + /** + * 获得当天是周几 + */ + public static String getWeekDay() { + String[] weekDays = {"星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"}; + Calendar cal = Calendar.getInstance(); + cal.setTime(new Date()); + int w = cal.get(Calendar.DAY_OF_WEEK) - 1; + if (w < 0) { + w = 0; + } + return weekDays[w]; + } + + public static void main(String[] args) { + System.err.println(getWeekDay()); + } } diff --git a/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitStringUtil.java b/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitStringUtil.java index 605d4257..3f5e01dd 100644 --- a/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitStringUtil.java +++ b/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitStringUtil.java @@ -15,8 +15,6 @@ */ package cn.odboy.util; -import java.util.Calendar; -import java.util.Date; import lombok.experimental.UtilityClass; import lombok.extern.slf4j.Slf4j; @@ -97,19 +95,4 @@ public final class KitStringUtil { } return sb.toString(); } - - /** - * 获得当天是周几 - */ - public static String getWeekDay() { - // String[] weekDays = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; - String[] weekDays = {"星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期天"}; - Calendar cal = Calendar.getInstance(); - cal.setTime(new Date()); - int w = cal.get(Calendar.DAY_OF_WEEK) - 1; - if (w < 0) { - w = 0; - } - return weekDays[w]; - } } diff --git a/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitThreadUtil.java b/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitThreadUtil.java new file mode 100644 index 00000000..4f9488b3 --- /dev/null +++ b/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitThreadUtil.java @@ -0,0 +1,17 @@ +package cn.odboy.util; + +import cn.hutool.core.thread.ThreadUtil; + +public class KitThreadUtil { + + /** + * 可中断的睡眠 + */ + public static void interruptSleep(int i) throws InterruptedException { + Thread.sleep(i); + } + + public static void safeSleep(int i) { + ThreadUtil.safeSleep(i); + } +} diff --git a/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitValidUtil.java b/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitValidUtil.java index 44b71028..e8d611a9 100644 --- a/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitValidUtil.java +++ b/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitValidUtil.java @@ -46,6 +46,12 @@ public final class KitValidUtil { } } + /** + * 验证实体是否通过校验
实体内通过 javax.validation.constraints 中的表达式限制参数
+ * + * @param object / + * @param / + */ public static void validate(T object) { Set> violations = VALIDATOR.validate(object, Default.class); if (!violations.isEmpty()) { @@ -54,39 +60,125 @@ public final class KitValidUtil { } } - public static void notNull(Object value) { + /** + * 参数为null,抛异常 + * + * @param value 参数值 + */ + public static void isNull(Object value) { if (value == null) { throw new BadRequestException("参数必填"); } } - public static void isNull(Object value) { - if (value != null) { - throw new BadRequestException("参数非必填"); - } - } - - public static void notNull(Object value, @NotNull String name, @NotNull String code) { + /** + * 参数为空,抛异常 + * + * @param value 参数值 + * @param name 参数名称 + * @param code 参数编码 + */ + public static void isNull(Object value, @NotNull String name, @NotNull String code) { if (value == null) { throw new BadRequestException(String.format("参数 %s(%s) 必填", name, code)); } } - public static void isBlank(CharSequence value, @NotNull String name, @NotNull String code) { - if (StrUtil.isNotBlank(value)) { - throw new BadRequestException(String.format("参数 %s(%s) 非必填", name, code)); + /** + * 参数为空,抛异常 + * + * @param value 参数值 + * @param message 异常信息 + */ + public static void isNull(Object value, @NotNull String message) { + if (value == null) { + throw new BadRequestException(message); } } - public static void notBlank(CharSequence value, @NotNull String name, @NotNull String code) { + /** + * 参数为空,抛异常 + * + * @param value 参数值 + * @param code 参数编码 + */ + public static void isNullF(Object value, @NotNull String code) { + if (value == null) { + throw new BadRequestException(String.format("参数 %s 必填", code)); + } + } + + /** + * 参数为空字符串,抛异常 + * + * @param value 参数值 + * @param name 参数名称 + * @param code 参数编码 + */ + public static void isBlank(CharSequence value, @NotNull String name, @NotNull String code) { if (StrUtil.isBlank(value)) { throw new BadRequestException(String.format("参数 %s(%s) 必填", name, code)); } } - public static void notEmpty(List data, @NotNull String code) { + /** + * 集合为空,抛异常 + * + * @param data 集合值 + * @param code 参数编码 + */ + public static void isEmpty(List data, @NotNull String code) { if (CollUtil.isEmpty(data)) { throw new BadRequestException(String.format("参数 %s 必填", code)); } } + + /** + * 集合为空,抛异常 + * + * @param data 集合值 + * @param name 参数名称 + * @param code 参数编码 + */ + public static void isEmpty(List data, @NotNull String name, @NotNull String code) { + if (CollUtil.isEmpty(data)) { + throw new BadRequestException(String.format("参数 %s(%s) 必填", name, code)); + } + } + + /** + * 表达式为true,抛异常 + * + * @param condition 表达式 + * @param message 异常信息 + */ + public static void isTrue(boolean condition, String message) { + if (condition) { + throw new BadRequestException(message); + } + } + + /** + * 表达式为false,抛异常 + * + * @param condition 表达式 + * @param message 异常信息 + */ + public static void isFalse(boolean condition, String message) { + if (!condition) { + throw new BadRequestException(message); + } + } + + /** + * 参数为空字符串,抛异常 + * + * @param value 参数值 + * @param message 异常信息 + */ + public static void isBlank(String value, String message) { + if (StrUtil.isBlank(value)) { + throw new BadRequestException(message); + } + } } diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteDeptTreeApi.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteDeptTreeApi.java index 9924ea5b..96ac9b41 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteDeptTreeApi.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteDeptTreeApi.java @@ -1,3 +1,18 @@ +/* + * 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.application; import cn.odboy.system.application.model.CuteDeptTreeVo; diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteFileUploadApi.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteFileUploadApi.java index f2db7ddb..b6483a6f 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteFileUploadApi.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteFileUploadApi.java @@ -1,3 +1,18 @@ +/* + * 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.application; import cn.odboy.system.application.service.CuteFileUploadService; diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteProductLineSelectApi.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteProductLineSelectApi.java index 7037874e..7a649e9c 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteProductLineSelectApi.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteProductLineSelectApi.java @@ -1,3 +1,18 @@ +/* + * 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.application; import cn.odboy.system.application.service.CuteProductLineSelectService; diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteProductLineSelectProApi.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteProductLineSelectProApi.java index f671fa7c..76960766 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteProductLineSelectProApi.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteProductLineSelectProApi.java @@ -1,3 +1,18 @@ +/* + * 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.application; import cn.odboy.system.application.service.CuteProductLineSelectProService; diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteUserSelectApi.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteUserSelectApi.java index 21c5978e..18101bf5 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteUserSelectApi.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/CuteUserSelectApi.java @@ -1,3 +1,18 @@ +/* + * 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.application; import cn.odboy.system.application.model.CuteUserSelectVo; diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/model/CuteDeptTreeVo.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/model/CuteDeptTreeVo.java index db474eb8..c3585939 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/model/CuteDeptTreeVo.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/model/CuteDeptTreeVo.java @@ -1,3 +1,18 @@ +/* + * 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.application.model; import cn.odboy.base.KitObject; diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/model/CuteUserSelectVo.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/model/CuteUserSelectVo.java index a03945c8..5efe95be 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/model/CuteUserSelectVo.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/model/CuteUserSelectVo.java @@ -1,3 +1,18 @@ +/* + * 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.application.model; import cn.odboy.base.KitObject; diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteBaseService.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteBaseService.java index 565cc64d..d87b93f3 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteBaseService.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteBaseService.java @@ -1,3 +1,18 @@ +/* + * 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.application.service; import cn.odboy.system.dal.dataobject.SystemDeptTb; diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteDeptTreeService.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteDeptTreeService.java index 96ab9509..40e472b2 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteDeptTreeService.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteDeptTreeService.java @@ -1,3 +1,18 @@ +/* + * 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.application.service; import cn.hutool.core.util.ObjectUtil; diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteFileUploadService.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteFileUploadService.java index 9f1c8d09..4582ba98 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteFileUploadService.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteFileUploadService.java @@ -1,3 +1,18 @@ +/* + * 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.application.service; import cn.hutool.core.date.DatePattern; diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteProductLineSelectProService.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteProductLineSelectProService.java index 27f1f587..c3933524 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteProductLineSelectProService.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteProductLineSelectProService.java @@ -1,3 +1,18 @@ +/* + * 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.application.service; import cn.odboy.system.application.model.CuteProductLineSelectProVo; diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteProductLineSelectService.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteProductLineSelectService.java index ebcc28d6..1e21430f 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteProductLineSelectService.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteProductLineSelectService.java @@ -1,3 +1,18 @@ +/* + * 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.application.service; import cn.odboy.system.dal.dataobject.SystemDeptTb; diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteUserSelectService.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteUserSelectService.java index 34d67f81..9d87d87a 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteUserSelectService.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/application/service/CuteUserSelectService.java @@ -1,3 +1,18 @@ +/* + * 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.application.service; import cn.hutool.core.collection.CollUtil; diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemMenuController.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemMenuController.java index 28a400cc..18bfd7ee 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemMenuController.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemMenuController.java @@ -102,9 +102,6 @@ public class SystemMenuController { @PostMapping(value = "/saveMenu") @PreAuthorize("@el.check('menu:add')") public ResponseEntity saveMenu(@Validated @RequestBody SystemMenuTb args) { - if (args.getId() != null) { - throw new BadRequestException("无效参数id"); - } systemMenuService.saveMenu(args); return ResponseEntity.ok(null); } diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemQuartzJobController.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemQuartzJobController.java index 22d3a28d..b0f950e8 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemQuartzJobController.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/controller/SystemQuartzJobController.java @@ -21,10 +21,8 @@ import cn.odboy.system.dal.dataobject.SystemQuartzJobTb; import cn.odboy.system.dal.dataobject.SystemQuartzLogTb; import cn.odboy.system.dal.model.request.SystemQueryQuartzJobArgs; import cn.odboy.system.dal.model.request.SystemUpdateQuartzJobArgs; -import cn.odboy.system.dal.model.response.SystemQuartzJobVo; import cn.odboy.system.framework.operalog.OperationLog; import cn.odboy.system.service.SystemQuartzJobService; -import cn.odboy.util.KitBeanUtil; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -96,8 +94,7 @@ public class SystemQuartzJobController { @ApiOperation("修改定时任务") @PostMapping(value = "/updateQuartzJobResumeCron") @PreAuthorize("@el.check('quartzJob:edit')") - public ResponseEntity updateQuartzJob( - @Validated(SystemQuartzJobTb.Update.class) @RequestBody SystemUpdateQuartzJobArgs args) { + public ResponseEntity updateQuartzJob(@Validated(SystemQuartzJobTb.Update.class) @RequestBody SystemUpdateQuartzJobArgs args) { systemQuartzJobService.updateQuartzJobResumeCron(args); return ResponseEntity.ok(null); } @@ -108,8 +105,7 @@ public class SystemQuartzJobController { @PreAuthorize("@el.check('quartzJob:edit')") public ResponseEntity switchQuartzJobStatus(@PathVariable Long id) { SystemQuartzJobTb quartzJobTb = systemQuartzJobService.getQuartzJobById(id); - SystemQuartzJobVo quartzJobVo = KitBeanUtil.copyToClass(quartzJobTb, SystemQuartzJobVo.class); - systemQuartzJobService.switchQuartzJobStatus(quartzJobVo); + systemQuartzJobService.switchQuartzJobStatus(quartzJobTb); return ResponseEntity.ok(null); } @@ -119,8 +115,7 @@ public class SystemQuartzJobController { @PreAuthorize("@el.check('quartzJob:edit')") public ResponseEntity startQuartzJob(@PathVariable Long id) { SystemQuartzJobTb quartzJobTb = systemQuartzJobService.getQuartzJobById(id); - SystemQuartzJobVo quartzJobVo = KitBeanUtil.copyToClass(quartzJobTb, SystemQuartzJobVo.class); - systemQuartzJobService.startQuartzJob(quartzJobVo); + systemQuartzJobService.startQuartzJob(quartzJobTb); return ResponseEntity.ok(null); } diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemQuartzJobTb.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemQuartzJobTb.java index 48b6597a..110fa666 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemQuartzJobTb.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/dal/dataobject/SystemQuartzJobTb.java @@ -63,4 +63,10 @@ public class SystemQuartzJobTb extends KitBaseUserTimeTb { @ApiModelProperty(value = "备注") @TableField(updateStrategy = FieldStrategy.ALWAYS) private String description; + /** + * 扩展字段 + */ + @TableField(exist = false) + @ApiModelProperty(value = "用于子任务唯一标识", hidden = true) + private String uuid; } diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/dal/model/response/SystemQuartzJobVo.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/dal/model/response/SystemQuartzJobVo.java deleted file mode 100644 index 19633561..00000000 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/dal/model/response/SystemQuartzJobVo.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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.dal.model.response; - -import cn.odboy.base.KitBaseUserTimeTb; -import io.swagger.annotations.ApiModelProperty; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -public class SystemQuartzJobVo extends KitBaseUserTimeTb { - - private Long id; - @ApiModelProperty(value = "定时器名称") - private String jobName; - @ApiModelProperty(value = "Bean名称") - private String beanName; - @ApiModelProperty(value = "方法名称") - private String methodName; - @ApiModelProperty(value = "参数") - private String params; - @ApiModelProperty(value = "cron表达式") - private String cronExpression; - @ApiModelProperty(value = "状态:暂停或启动") - private Boolean isPause = false; - @ApiModelProperty(value = "负责人") - private String personInCharge; - @ApiModelProperty(value = "报警邮箱") - private String email; - @ApiModelProperty(value = "子任务") - private String subTask; - @ApiModelProperty(value = "失败后暂停") - private Boolean pauseAfterFailure; - @ApiModelProperty(value = "备注") - private String description; - /** - * 扩展字段 - */ - @ApiModelProperty(value = "用于子任务唯一标识", hidden = true) - private String uuid; -} diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/ActiveJobRegister.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/ActiveJobRegister.java index 39970ef1..42361798 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/ActiveJobRegister.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/ActiveJobRegister.java @@ -16,9 +16,7 @@ package cn.odboy.system.framework.quartz; import cn.odboy.system.dal.dataobject.SystemQuartzJobTb; -import cn.odboy.system.dal.model.response.SystemQuartzJobVo; import cn.odboy.system.service.SystemQuartzJobService; -import cn.odboy.util.KitBeanUtil; import java.util.List; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -43,8 +41,7 @@ public class ActiveJobRegister implements ApplicationRunner { @Override public void run(ApplicationArguments applicationArguments) { List quartzJobTbs = systemQuartzJobService.listEnableQuartzJob(); - List quartzJobVos = KitBeanUtil.copyToList(quartzJobTbs, SystemQuartzJobVo.class); - quartzJobVos.forEach(quartzManage::addJob); + quartzJobTbs.forEach(quartzManage::addJob); log.info("Timing task injection complete"); } } diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/ExecutionJobBean.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/ExecutionJobBean.java index aa10cbc8..719939b5 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/ExecutionJobBean.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/ExecutionJobBean.java @@ -27,10 +27,10 @@ import cn.odboy.framework.redis.KitRedisHelper; import cn.odboy.system.dal.dataobject.SystemQuartzJobTb; import cn.odboy.system.dal.dataobject.SystemQuartzLogTb; import cn.odboy.system.dal.model.request.SystemSendEmailArgs; -import cn.odboy.system.dal.model.response.SystemQuartzJobVo; import cn.odboy.system.dal.mysql.SystemQuartzLogMapper; import cn.odboy.system.service.SystemEmailService; import cn.odboy.system.service.SystemQuartzJobService; +import cn.odboy.util.KitBeanUtil; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -52,7 +52,7 @@ public class ExecutionJobBean extends QuartzJobBean { @Override public void executeInternal(JobExecutionContext context) { // 获取任务 - SystemQuartzJobVo quartzJob = (SystemQuartzJobVo) context.getMergedJobDataMap().get(SystemQuartzJobTb.JOB_KEY); + SystemQuartzJobTb quartzJob = (SystemQuartzJobTb) context.getMergedJobDataMap().get(SystemQuartzJobTb.JOB_KEY); // 获取spring bean SystemQuartzLogMapper quartzLogMapper = KitSpringBeanHolder.getBean(SystemQuartzLogMapper.class); SystemQuartzJobService systemQuartzJobService = KitSpringBeanHolder.getBean(SystemQuartzJobService.class); @@ -99,7 +99,8 @@ public class ExecutionJobBean extends QuartzJobBean { if (quartzJob.getPauseAfterFailure() != null && quartzJob.getPauseAfterFailure()) { quartzJob.setIsPause(false); // 更新状态 - systemQuartzJobService.switchQuartzJobStatus(quartzJob); + SystemQuartzJobTb quartzJobTb = KitBeanUtil.copyToClass(quartzJob, SystemQuartzJobTb.class); + systemQuartzJobService.switchQuartzJobStatus(quartzJobTb); } if (quartzJob.getEmail() != null) { SystemEmailService emailService = KitSpringBeanHolder.getBean(SystemEmailService.class); @@ -114,7 +115,7 @@ public class ExecutionJobBean extends QuartzJobBean { } } - private SystemSendEmailArgs taskAlarm(SystemQuartzJobVo quartzJob, String msg) { + private SystemSendEmailArgs taskAlarm(SystemQuartzJobTb quartzJob, String msg) { SystemSendEmailArgs sendEmailRequest = new SystemSendEmailArgs(); sendEmailRequest.setSubject("定时任务【" + quartzJob.getJobName() + "】执行失败,请尽快处理!"); Map data = new HashMap<>(16); diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/QuartzManage.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/QuartzManage.java index 40ef044c..33c95874 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/QuartzManage.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/framework/quartz/QuartzManage.java @@ -17,8 +17,6 @@ package cn.odboy.system.framework.quartz; import cn.odboy.framework.exception.BadRequestException; import cn.odboy.system.dal.dataobject.SystemQuartzJobTb; -import cn.odboy.system.dal.model.response.SystemQuartzJobVo; -import cn.odboy.util.KitBeanUtil; import java.util.Date; import javax.annotation.Resource; import lombok.extern.slf4j.Slf4j; @@ -44,7 +42,7 @@ public class QuartzManage { @Resource private Scheduler scheduler; - public void addJob(SystemQuartzJobVo quartzJob) { + public void addJob(SystemQuartzJobTb quartzJob) { try { String uuid = JOB_NAME + quartzJob.getId(); // 构建job信息 @@ -83,23 +81,22 @@ public class QuartzManage { */ public void updateJobCron(SystemQuartzJobTb quartzJob) { try { - SystemQuartzJobVo quartzJobVo = KitBeanUtil.copyToClass(quartzJob, SystemQuartzJobVo.class); - TriggerKey triggerKey = TriggerKey.triggerKey(JOB_NAME + quartzJobVo.getId()); + TriggerKey triggerKey = TriggerKey.triggerKey(JOB_NAME + quartzJob.getId()); CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey); // 如果不存在则创建一个定时任务 if (trigger == null) { - addJob(quartzJobVo); + addJob(quartzJob); trigger = (CronTrigger) scheduler.getTrigger(triggerKey); } - CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(quartzJobVo.getCronExpression()); + CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(quartzJob.getCronExpression()); trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build(); // 重置启动时间 ((CronTriggerImpl) trigger).setStartTime(new Date()); - trigger.getJobDataMap().put(SystemQuartzJobTb.JOB_KEY, quartzJobVo); + trigger.getJobDataMap().put(SystemQuartzJobTb.JOB_KEY, quartzJob); scheduler.rescheduleJob(triggerKey, trigger); // 暂停任务 - if (quartzJobVo.getIsPause()) { - pauseJob(quartzJobVo); + if (quartzJob.getIsPause()) { + pauseJob(quartzJob); } } catch (Exception e) { log.error("更新定时任务失败", e); @@ -128,7 +125,7 @@ public class QuartzManage { * * @param quartzJob / */ - public void resumeJob(SystemQuartzJobVo quartzJob) { + public void resumeJob(SystemQuartzJobTb quartzJob) { try { TriggerKey triggerKey = TriggerKey.triggerKey(JOB_NAME + quartzJob.getId()); CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey); @@ -149,7 +146,7 @@ public class QuartzManage { * * @param quartzJob / */ - public void runJobNow(SystemQuartzJobVo quartzJob) { + public void runJobNow(SystemQuartzJobTb quartzJob) { try { String uuid = JOB_NAME + quartzJob.getId(); TriggerKey triggerKey = TriggerKey.triggerKey(uuid); @@ -173,7 +170,7 @@ public class QuartzManage { * * @param quartzJob / */ - public void pauseJob(SystemQuartzJobVo quartzJob) { + public void pauseJob(SystemQuartzJobTb quartzJob) { try { JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getId()); scheduler.pauseJob(jobKey); diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemAuthService.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemAuthService.java index 0ab9d3c6..37608f8c 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemAuthService.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemAuthService.java @@ -16,7 +16,6 @@ package cn.odboy.system.service; import cn.odboy.constant.SystemConst; -import cn.odboy.framework.exception.BadRequestException; import cn.odboy.framework.properties.AppProperties; import cn.odboy.system.dal.model.request.SystemUserLoginArgs; import cn.odboy.system.dal.model.response.SystemAuthVo; @@ -29,13 +28,13 @@ import cn.odboy.system.framework.permission.core.handler.UserDetailsHandler; import cn.odboy.util.KitBeanUtil; import cn.odboy.util.KitRsaEncryptUtil; import cn.odboy.util.KitValidUtil; +import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; -import javax.servlet.http.HttpServletRequest; /** * 用户认证 @@ -57,13 +56,13 @@ public class SystemAuthService { private SystemCaptchaService systemCaptchaService; /** - * 登录 -> TestPassed + * 登录 * * @param loginArgs / * @param request / */ public SystemAuthVo doLogin(SystemUserLoginArgs loginArgs, HttpServletRequest request) throws Exception { - KitValidUtil.notNull(loginArgs); + KitValidUtil.isNull(loginArgs); // 密码解密 String password = @@ -72,10 +71,9 @@ public class SystemAuthService { systemCaptchaService.validate(loginArgs.getUuid(), loginArgs.getCode()); // 查询用户信息 SystemUserJwtVo jwtUser = userDetailsService.loadUserByUsername(loginArgs.getUsername()); + // 验证用户密码 - if (!passwordEncoder.matches(password, jwtUser.getPassword())) { - throw new BadRequestException("登录密码错误"); - } + KitValidUtil.isTrue(!passwordEncoder.matches(password, jwtUser.getPassword()), "登录密码错误"); // 登录验证 Authentication authentication = @@ -101,7 +99,7 @@ public class SystemAuthService { } /** - * 查询当前登录人信息 -> TestPassed + * 查询当前登录人信息 */ public SystemUserJwtVo getCurrentUserInfo() { SystemUserJwtVo jwtUser = (SystemUserJwtVo) KitSecurityHelper.getCurrentUser(); @@ -112,7 +110,7 @@ public class SystemAuthService { } /** - * 退出登录 -> TestPassed + * 退出登录 * * @param request / */ diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemCaptchaService.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemCaptchaService.java index ffd8443a..8905284c 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemCaptchaService.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemCaptchaService.java @@ -19,15 +19,15 @@ import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.StrUtil; import cn.odboy.constant.CaptchaCodeEnum; import cn.odboy.constant.SystemConst; -import cn.odboy.framework.exception.BadRequestException; import cn.odboy.framework.properties.AppProperties; import cn.odboy.framework.redis.KitRedisHelper; -import cn.odboy.system.dal.model.response.SystemCaptchaVo; import cn.odboy.system.constant.SystemCacheKey; +import cn.odboy.system.dal.model.response.SystemCaptchaVo; +import cn.odboy.util.KitValidUtil; import com.wf.captcha.base.Captcha; +import java.util.concurrent.TimeUnit; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.concurrent.TimeUnit; /** * 验证码 @@ -41,7 +41,7 @@ public class SystemCaptchaService { private AppProperties properties; /** - * 查询登录验证码 -> TestPassed + * 查询登录验证码 */ public SystemCaptchaVo getLoginCaptcha() { // 查询运算的结果 @@ -63,7 +63,7 @@ public class SystemCaptchaService { } /** - * 验证验证码 -> TestPassed + * 验证验证码 * * @param uuid 验证码uuid * @param inputCode 用户输入的验证码 @@ -71,13 +71,9 @@ public class SystemCaptchaService { public void validate(String uuid, String inputCode) { // 查询验证码 String code = redisHelper.get(uuid, String.class); - if (StrUtil.isBlank(code)) { - throw new BadRequestException("验证码不存在或已过期"); - } + KitValidUtil.isBlank(code, "验证码不存在或已过期"); // 清除验证码 redisHelper.del(uuid); - if (StrUtil.isBlank(inputCode) || !code.equalsIgnoreCase(inputCode)) { - throw new BadRequestException("验证码错误"); - } + KitValidUtil.isTrue(StrUtil.isBlank(inputCode) || !code.equalsIgnoreCase(inputCode), "验证码错误"); } } diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDataService.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDataService.java index 8bbda80a..eb538c1f 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDataService.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDataService.java @@ -45,7 +45,7 @@ public class SystemDataService { private SystemRoleDeptService systemRoleDeptService; /** - * 查询数据权限 -> TestPassed + * 查询数据权限 * * @param user / * @return / @@ -75,7 +75,7 @@ public class SystemDataService { } /** - * 查询自定义的数据权限 -> TestPassed + * 查询自定义的数据权限 * * @param deptIds 部门ID(外部数据) * @param roleId 角色ID diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDeptService.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDeptService.java index a2a6cf86..c771c32c 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDeptService.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDeptService.java @@ -34,10 +34,6 @@ import cn.odboy.util.KitClassUtil; import cn.odboy.util.KitValidUtil; import cn.odboy.util.xlsx.KitExcelExporter; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import javax.servlet.http.HttpServletResponse; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashSet; @@ -46,6 +42,10 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; +import javax.servlet.http.HttpServletResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service public class SystemDeptService { @@ -58,13 +58,13 @@ public class SystemDeptService { private SystemRoleDeptService systemRoleDeptService; /** - * 创建 -> TestPassed + * 创建 * * @param args / */ @Transactional(rollbackFor = Exception.class) public void saveDept(SystemCreateDeptArgs args) { - KitValidUtil.notNull(args); + KitValidUtil.isNull(args); SystemDeptTb record = KitBeanUtil.copyToClass(args, SystemDeptTb.class); systemDeptMapper.insert(record); @@ -73,13 +73,13 @@ public class SystemDeptService { } /** - * 编辑 -> TestPassed + * 编辑 * * @param args / */ @Transactional(rollbackFor = Exception.class) public void updateDeptById(SystemDeptTb args) { - KitValidUtil.notNull(args); + KitValidUtil.isNull(args); // 旧的父部门 Long oldPid = this.getDeptById(args.getId()).getPid(); // 新的父部门 @@ -104,7 +104,9 @@ public class SystemDeptService { // 查询部门, 和其所有子部门 Set depts = this.traverseDeptByIdWithPids(ids); // 验证是否被角色或用户关联 - this.verifyBindRelationByIds(depts); + Set deptIds = depts.stream().map(SystemDeptTb::getId).collect(Collectors.toSet()); + KitValidUtil.isTrue(systemUserDeptService.countUserByDeptIds(deptIds) > 0, "所选部门存在用户关联,请解除后再试"); + KitValidUtil.isTrue(systemRoleDeptService.countRoleByDeptIds(deptIds) > 0, "所选部门存在角色关联,请解除后再试"); for (SystemDeptTb dept : depts) { systemDeptMapper.deleteById(dept.getId()); this.updateDeptSubCnt(dept.getPid()); @@ -112,7 +114,7 @@ public class SystemDeptService { } /** - * 更新父节点中子节点数目 -> TestPassed + * 更新父节点中子节点数目 * * @param deptId 部门id */ @@ -252,21 +254,6 @@ public class SystemDeptService { return systemDeptMapper.selectList(wrapper).stream().collect(Collectors.toMap(SystemDeptTb::getId, i -> i, (m, n) -> m)); } - /** - * 验证是否被角色或用户关联 - * - * @param deptSet / - */ - public void verifyBindRelationByIds(Set deptSet) { - Set deptIds = deptSet.stream().map(SystemDeptTb::getId).collect(Collectors.toSet()); - if (systemUserDeptService.countUserByDeptIds(deptIds) > 0) { - throw new BadRequestException("所选部门存在用户关联,请解除后再试!"); - } - if (systemRoleDeptService.countRoleByDeptIds(deptIds) > 0) { - throw new BadRequestException("所选部门存在角色关联,请解除后再试!"); - } - } - /** * 根据部门id遍历所有部门和子部门 * @@ -374,7 +361,7 @@ public class SystemDeptService { } /** - * 根据部门id查询部门信息 -> TestPassed + * 根据部门id查询部门信息 * * @param id 部门id * @return / diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDictDetailService.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDictDetailService.java index feba2bbb..8202445f 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDictDetailService.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDictDetailService.java @@ -49,21 +49,21 @@ public class SystemDictDetailService { private SystemDictMapper systemDictMapper; /** - * 创建 -> TestPassed + * 创建 * * @param args / */ @Transactional(rollbackFor = Exception.class) public void saveDictDetail(SystemCreateDictDetailArgs args) { - KitValidUtil.notNull(args); - KitValidUtil.notNull(args.getDict()); + KitValidUtil.isNull(args); + KitValidUtil.isNull(args.getDict()); SystemDictDetailTb dictDetail = KitBeanUtil.copyToClass(args, SystemDictDetailTb.class); dictDetail.setDictId(args.getDict().getId()); systemDictDetailMapper.insert(dictDetail); } /** - * 编辑 -> TestPassed + * 编辑 * * @param args / */ @@ -71,11 +71,11 @@ public class SystemDictDetailService { public void updateDictDetailById(SystemDictDetailTb args) { SystemDictDetailTb dictDetail = systemDictDetailMapper.selectById(args.getId()); args.setId(dictDetail.getId()); - systemDictDetailMapper.insertOrUpdate(args); + systemDictDetailMapper.updateById(args); } /** - * 删除 -> TestPassed + * 删除 * * @param id / */ @@ -99,7 +99,7 @@ public class SystemDictDetailService { } /** - * 分页查询 -> TestPassed + * 分页查询 * * @param args 条件 * @param page 分页参数 @@ -123,7 +123,7 @@ public class SystemDictDetailService { } /** - * 根据字典名称查询字典详情 -> TestPassed + * 根据字典名称查询字典详情 * * @param name 字典名称 * @return / diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDictService.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDictService.java index eb8f978b..b2bd737c 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDictService.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemDictService.java @@ -46,7 +46,7 @@ public class SystemDictService { private SystemDictDetailService systemDictDetailService; /** - * 创建 -> TestPassed + * 创建 * * @param args / */ @@ -57,7 +57,7 @@ public class SystemDictService { } /** - * 编辑 -> TestPassed + * 编辑 * * @param args / */ @@ -70,7 +70,7 @@ public class SystemDictService { } /** - * 删除 -> TestPassed + * 删除 * * @param ids / */ @@ -83,7 +83,7 @@ public class SystemDictService { } /** - * 分页查询 -> TestPassed + * 分页查询 * * @param args 条件 * @param page 分页参数 diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemEmailService.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemEmailService.java index c2ff9f93..34d022ba 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemEmailService.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemEmailService.java @@ -30,11 +30,12 @@ import cn.odboy.system.dal.model.request.SystemSendEmailArgs; import cn.odboy.system.dal.mysql.SystemEmailConfigMapper; import cn.odboy.util.KitDesEncryptUtil; import cn.odboy.util.KitResourceTemplateUtil; +import cn.odboy.util.KitValidUtil; +import java.util.Collections; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.Collections; @Slf4j @Service @@ -48,7 +49,7 @@ public class SystemEmailService { private AppProperties properties; /** - * 更新邮件配置 -> TestPassed + * 更新邮件配置 * * @param emailConfig 邮箱配置 */ @@ -64,15 +65,13 @@ public class SystemEmailService { } /** - * 发送邮件 -> TestPassed + * 发送邮件 * * @param sendEmailRequest 邮件发送的内容 */ public void sendEmail(SystemSendEmailArgs sendEmailRequest) { SystemEmailConfigTb systemEmailConfigTb = getLastEmailConfig(); - if (systemEmailConfigTb.getId() == null) { - throw new BadRequestException("请先配置, 再操作"); - } + KitValidUtil.isNull(systemEmailConfigTb.getId(), "请先配置, 再操作"); // 封装 MailAccount account = new MailAccount(); // 设置用户 @@ -112,23 +111,18 @@ public class SystemEmailService { * 发送给邮箱验证码 */ public void sendCaptcha(SystemCaptchaBizEnum biEnum, String email) { - if (biEnum == null) { - throw new BadRequestException("biEnum必填"); - } + KitValidUtil.isNull(biEnum, "biEnum必填"); String content; String redisKey = biEnum.getRedisKey() + email; String oldCode = redisHelper.get(redisKey, String.class); if (oldCode == null) { String code = RandomUtil.randomNumbers(6); // 存入缓存 - if (!redisHelper.set(redisKey, code, properties.getCaptcha().getExpireTime())) { - throw new BadRequestException("服务异常, 请联系网站负责人"); - } + KitValidUtil.isTrue(!redisHelper.set(redisKey, code, properties.getCaptcha().getExpireTime()), "服务异常, 请联系网站负责人"); // 存在就再次发送原来的验证码 content = KitResourceTemplateUtil.render(null, biEnum.getTemplateName(), Dict.create().set("code", code)); } else { - content = - KitResourceTemplateUtil.render(null, biEnum.getTemplateName(), Dict.create().set("code", oldCode)); + content = KitResourceTemplateUtil.render(null, biEnum.getTemplateName(), Dict.create().set("code", oldCode)); } SystemSendEmailArgs sendEmailRequest = new SystemSendEmailArgs(Collections.singletonList(email), SystemConst.CURRENT_APP_TITLE, content); @@ -146,23 +140,18 @@ public class SystemEmailService { } /** - * 校验邮箱验证码 -> TestPassed + * 校验邮箱验证码 */ public void checkEmailCaptcha(SystemCheckEmailCaptchaArgs args) { SystemCaptchaBizEnum biEnum = SystemCaptchaBizEnum.getByBizCode(args.getBizCode()); - if (biEnum == null) { - throw new BadRequestException("不支持的业务"); - } + KitValidUtil.isNull(biEnum, "不支持的业务"); this.checkEmailCaptchaV1(biEnum, args.getEmail(), args.getCode()); } public void checkEmailCaptchaV1(SystemCaptchaBizEnum biEnum, String email, String code) { String redisKey = biEnum.getRedisKey() + email; String value = redisHelper.get(redisKey, String.class); - if (value == null || !value.equals(code)) { - throw new BadRequestException("无效验证码"); - } else { - redisHelper.del(redisKey); - } + KitValidUtil.isTrue(value == null || !value.equals(code), "无效验证码"); + redisHelper.del(redisKey); } } diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemJobService.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemJobService.java index eb6fec8b..c98a588f 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemJobService.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemJobService.java @@ -18,7 +18,6 @@ package cn.odboy.system.service; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; import cn.odboy.base.KitPageResult; -import cn.odboy.framework.exception.BadRequestException; import cn.odboy.system.dal.dataobject.SystemJobTb; import cn.odboy.system.dal.model.export.SystemJobExportRowVo; import cn.odboy.system.dal.model.request.SystemCreateJobArgs; @@ -26,16 +25,17 @@ import cn.odboy.system.dal.model.request.SystemQueryJobArgs; import cn.odboy.system.dal.mysql.SystemJobMapper; import cn.odboy.util.KitBeanUtil; import cn.odboy.util.KitPageUtil; +import cn.odboy.util.KitValidUtil; import cn.odboy.util.xlsx.KitExcelExporter; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import javax.servlet.http.HttpServletResponse; import java.util.ArrayList; import java.util.List; import java.util.Set; +import javax.servlet.http.HttpServletResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service public class SystemJobService { @@ -46,48 +46,44 @@ public class SystemJobService { private SystemUserJobService systemUserJobService; /** - * 创建 -> TestPassed + * 创建 * * @param args / */ @Transactional(rollbackFor = Exception.class) public void saveJob(SystemCreateJobArgs args) { - if (this.existJobWithName(args.getName())) { - throw new BadRequestException("职位名称已存在"); - } + KitValidUtil.isTrue(this.existJobWithName(args.getName()), "职位名称已存在"); SystemJobTb systemJobTb = KitBeanUtil.copyToClass(args, SystemJobTb.class); systemJobMapper.insert(systemJobTb); } /** - * 编辑 -> TestPassed + * 编辑 * * @param args / */ @Transactional(rollbackFor = Exception.class) public void updateJobById(SystemJobTb args) { SystemJobTb job = systemJobMapper.selectById(args.getId()); - if (this.existJobWithNameNeSelf(args.getName(), job.getId())) { - throw new BadRequestException("职位名称已存在"); - } + KitValidUtil.isTrue(this.existJobWithNameNeSelf(args.getName(), job.getId()), "职位名称已存在"); args.setId(job.getId()); systemJobMapper.updateById(args); } /** - * 删除 -> TestPassed + * 删除 * * @param ids / */ @Transactional(rollbackFor = Exception.class) public void deleteJobByIds(Set ids) { // 验证是否被用户关联 - this.verifyBindRelationByIds(ids); + KitValidUtil.isTrue(systemUserJobService.countUserByJobIds(ids) > 0, "所选的岗位中存在用户关联, 请解除关联再试"); systemJobMapper.deleteByIds(ids); } /** - * 分页查询 -> TestPassed + * 分页查询 * * @param args 条件 * @param page 分页参数 @@ -100,7 +96,7 @@ public class SystemJobService { } /** - * 查询全部数据 -> TestPassed + * 查询全部数据 */ public List queryJobByArgs(SystemQueryJobArgs args) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); @@ -109,18 +105,7 @@ public class SystemJobService { } /** - * 验证是否被用户关联 -> TestPassed - * - * @param ids / - */ - public void verifyBindRelationByIds(Set ids) { - if (systemUserJobService.countUserByJobIds(ids) > 0) { - throw new BadRequestException("所选的岗位中存在用户关联, 请解除关联再试!"); - } - } - - /** - * 导出岗位数据 -> TestPassed + * 导出岗位数据 */ public void exportJobXlsx(HttpServletResponse response, SystemQueryJobArgs args) { List systemJobTbs = this.queryJobByArgs(args); @@ -136,7 +121,7 @@ public class SystemJobService { } /** - * 根据岗位名称查询岗位是否存在 -> TestPassed + * 根据岗位名称查询岗位是否存在 */ private boolean existJobWithName(String name) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); @@ -145,7 +130,7 @@ public class SystemJobService { } /** - * 根据岗位名称和岗位id查询岗位是否存在 -> TestPassed + * 根据岗位名称和岗位id查询岗位是否存在 */ private boolean existJobWithNameNeSelf(String name, Long currentJobId) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemLocalStorageService.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemLocalStorageService.java index c29c8f9e..d9f37927 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemLocalStorageService.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemLocalStorageService.java @@ -22,7 +22,6 @@ import cn.hutool.core.io.IORuntimeException; import cn.hutool.core.util.StrUtil; import cn.odboy.base.KitPageResult; import cn.odboy.constant.FileTypeEnum; -import cn.odboy.framework.context.KitRequestHolder; import cn.odboy.framework.exception.BadRequestException; import cn.odboy.framework.properties.AppProperties; import cn.odboy.framework.server.core.KitFileLocalUploadHelper; @@ -33,20 +32,20 @@ import cn.odboy.system.dal.mysql.SystemLocalStorageMapper; import cn.odboy.util.KitBeanUtil; import cn.odboy.util.KitFileUtil; import cn.odboy.util.KitPageUtil; +import cn.odboy.util.KitValidUtil; import cn.odboy.util.xlsx.KitExcelExporter; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import java.io.File; +import java.util.Date; +import java.util.List; +import javax.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.File; -import java.util.Date; -import java.util.List; @Slf4j @Service @@ -63,7 +62,7 @@ public class SystemLocalStorageService { private SystemLocalStorageService localStorageService; /** - * 上传 -> TestPassed + * 上传 * * @param name 文件名称 * @param multipartFile 文件 @@ -77,9 +76,7 @@ public class SystemLocalStorageService { String type = KitFileUtil.getFileType(suffix); String uploadDateStr = DateUtil.format(new Date(), DatePattern.PURE_DATE_FORMAT); File file = KitFileUtil.upload(multipartFile, fileUploadPathHelper.getPath() + uploadDateStr + File.separator); - if (file == null) { - throw new BadRequestException("上传失败"); - } + KitValidUtil.isNull(file, "上传失败"); try { String formatSize = KitFileUtil.getSize(size); String prefixName = KitFileUtil.getPrefix(multipartFile.getOriginalFilename(), name); @@ -101,7 +98,7 @@ public class SystemLocalStorageService { } /** - * 编辑 -> TestPassed + * 编辑 * * @param args 文件信息 */ @@ -111,7 +108,7 @@ public class SystemLocalStorageService { } /** - * 多选删除 -> TestPassed + * 多选删除 * * @param ids / */ @@ -129,7 +126,7 @@ public class SystemLocalStorageService { } /** - * 分页查询 -> TestPassed + * 分页查询 * * @param args 条件 * @param page 分页参数 @@ -143,7 +140,7 @@ public class SystemLocalStorageService { } /** - * 查询文件上传记录 -> TestPassed + * 查询文件上传记录 */ public List queryLocalStorageByArgs(SystemQueryStorageArgs args) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); @@ -152,20 +149,18 @@ public class SystemLocalStorageService { } /** - * 上传图片 -> TestPassed + * 上传图片 */ @Transactional(rollbackFor = Exception.class) public SystemLocalStorageTb uploadPicture(MultipartFile file) { // 判断文件是否为图片 String suffix = KitFileUtil.getSuffix(file.getOriginalFilename()); - if (!FileTypeEnum.IMAGE.getCode().equals(KitFileUtil.getFileType(suffix))) { - throw new BadRequestException("只能上传图片"); - } + KitValidUtil.isTrue(!FileTypeEnum.IMAGE.getCode().equals(KitFileUtil.getFileType(suffix)), "只能上传图片"); return localStorageService.uploadFile(null, file); } /** - * 导出文件上传记录 -> TestPassed + * 导出文件上传记录 */ public void exportLocalStorageXlsx(HttpServletResponse response, SystemQueryStorageArgs args) { List systemLocalStorageTbs = this.queryLocalStorageByArgs(args); diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemMenuService.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemMenuService.java index 39082d81..fd1cf1b3 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemMenuService.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemMenuService.java @@ -35,11 +35,6 @@ import cn.odboy.util.KitValidUtil; import cn.odboy.util.xlsx.KitExcelExporter; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Lazy; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import javax.servlet.http.HttpServletResponse; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashSet; @@ -49,6 +44,11 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; +import javax.servlet.http.HttpServletResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service public class SystemMenuService { @@ -64,19 +64,15 @@ public class SystemMenuService { private SystemMenuService proxyService; /** - * 创建 -> TestPassed + * 创建 * * @param args / */ @Transactional(rollbackFor = Exception.class) public void saveMenu(SystemMenuTb args) { - if (this.existMenuWithTitle(args.getTitle())) { - throw new BadRequestException("菜单标题已存在"); - } + KitValidUtil.isTrue(this.existMenuWithTitle(args.getTitle()), "菜单标题已存在"); if (StrUtil.isNotBlank(args.getComponentName())) { - if (this.existMenuWithComponentName(args.getComponentName())) { - throw new BadRequestException("菜单组件名称已存在"); - } + KitValidUtil.isTrue(this.existMenuWithComponentName(args.getComponentName()), "菜单组件名称已存在"); } if (Long.valueOf(0L).equals(args.getPid())) { // 顶级目录 @@ -96,25 +92,20 @@ public class SystemMenuService { } /** - * 编辑 -> TestPassed + * 编辑 * * @param args / */ @Transactional(rollbackFor = Exception.class) public void updateMenuById(SystemMenuTb args) { - if (args.getId().equals(args.getPid())) { - throw new BadRequestException("上级不能为自己"); - } + KitValidUtil.isNullF(args.getId(), "id"); + KitValidUtil.isTrue(args.getId().equals(args.getPid()), "上级不能为自己"); SystemMenuTb menu = systemMenuMapper.selectById(args.getId()); if (args.getIFrame()) { - if (!(args.getPath().toLowerCase().startsWith(SystemTransferProtocolConst.PREFIX_HTTP) || args.getPath() - .toLowerCase().startsWith(SystemTransferProtocolConst.PREFIX_HTTPS))) { - throw new BadRequestException(SystemTransferProtocolConst.PREFIX_HTTPS_BAD_REQUEST); - } - } - if (this.existMenuWithTitleNeSelf(args.getTitle(), menu.getId())) { - throw new BadRequestException("菜单标题已存在"); + KitValidUtil.isTrue(!(args.getPath().toLowerCase().startsWith(SystemTransferProtocolConst.PREFIX_HTTP) || args.getPath() + .toLowerCase().startsWith(SystemTransferProtocolConst.PREFIX_HTTPS)), SystemTransferProtocolConst.PREFIX_HTTPS_BAD_REQUEST); } + KitValidUtil.isTrue(this.existMenuWithTitleNeSelf(args.getTitle(), menu.getId()), "菜单标题已存在"); if (args.getPid().equals(0L)) { args.setPid(null); } @@ -122,9 +113,7 @@ public class SystemMenuService { Long oldPid = menu.getPid(); Long newPid = args.getPid(); if (StrUtil.isNotBlank(args.getComponentName())) { - if (this.existMenuWithComponentNameNeSelf(args.getTitle(), menu.getId())) { - throw new BadRequestException("菜单组件名称已存在"); - } + KitValidUtil.isTrue(this.existMenuWithComponentNameNeSelf(args.getTitle(), menu.getId()), "菜单组件名称已存在"); } menu.setTitle(args.getTitle()); menu.setComponent(args.getComponent()); @@ -148,7 +137,7 @@ public class SystemMenuService { } /** - * 删除 -> TestPassed + * 删除 */ @Transactional(rollbackFor = Exception.class) public void deleteMenuByIds(Set ids) { @@ -261,7 +250,7 @@ public class SystemMenuService { } /** - * 根据ID查询同级与上级数据 -> TestPassed + * 根据ID查询同级与上级数据 * * @param menu / * @param menus / @@ -443,7 +432,7 @@ public class SystemMenuService { } private List queryMenuByArgs(SystemQueryMenuArgs args) { - KitValidUtil.notNull(args); + KitValidUtil.isNull(args); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.isNull(args.getPidIsNull() != null, SystemMenuTb::getPid); wrapper.eq(args.getPid() != null, SystemMenuTb::getPid, args.getPid()); @@ -458,7 +447,7 @@ public class SystemMenuService { } /** - * 查询根目录 -> TestPassed + * 查询根目录 */ private List listRootMenu() { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); @@ -468,7 +457,7 @@ public class SystemMenuService { } /** - * 根据组件名称查询菜单是否存在 -> TestPassed + * 根据组件名称查询菜单是否存在 * * @param componentName 组件名称 * @return / @@ -480,7 +469,7 @@ public class SystemMenuService { } /** - * 根据组件名称查询菜单是否存在 -> TestPassed + * 根据组件名称查询菜单是否存在 * * @param componentName 组件名称 * @return / @@ -493,7 +482,7 @@ public class SystemMenuService { } /** - * 根据菜单标题查询菜单是否存在 -> TestPassed + * 根据菜单标题查询菜单是否存在 * * @param title 菜单标题 * @return / @@ -505,7 +494,7 @@ public class SystemMenuService { } /** - * 根据菜单标题查询菜单是否存在 -> TestPassed + * 根据菜单标题查询菜单是否存在 * * @param title 菜单标题 * @return / @@ -537,7 +526,8 @@ public class SystemMenuService { List children = parentToChildrenMap.get(parentId); if (children != null && !children.isEmpty()) { for (SystemMenuTb child : children) { - if (result.add(child.getId())) { // 如果成功添加(之前不存在),则继续查找其子菜单 + // 如果成功添加(之前不存在),则继续查找其子菜单 + if (result.add(child.getId())) { nextLevelIds.add(child.getId()); } } @@ -563,7 +553,7 @@ public class SystemMenuService { } /** - * 根据菜单id查询目录 -> TestPassed + * 根据菜单id查询目录 * * @param id 菜单id */ diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemMonitorService.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemMonitorService.java index 39a02c2d..b7b12353 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemMonitorService.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemMonitorService.java @@ -47,7 +47,7 @@ public class SystemMonitorService { private final DecimalFormat df = new DecimalFormat("0.00"); /** - * 查询服务器监控信息 -> TestPassed + * 查询服务器监控信息 * * @return Map */ @@ -75,7 +75,7 @@ public class SystemMonitorService { } /** - * 查询磁盘信息 -> TestPassed + * 查询磁盘信息 * * @return / */ @@ -109,7 +109,7 @@ public class SystemMonitorService { } /** - * 查询交换区信息 -> TestPassed + * 查询交换区信息 * * @param memory / * @return / @@ -131,7 +131,7 @@ public class SystemMonitorService { } /** - * 查询内存信息 -> TestPassed + * 查询内存信息 * * @param memory / * @return / @@ -149,7 +149,7 @@ public class SystemMonitorService { } /** - * 查询Cpu相关信息 -> TestPassed + * 查询Cpu相关信息 * * @param processor / * @return / @@ -196,7 +196,7 @@ public class SystemMonitorService { } /** - * 查询系统相关信息,系统、运行天数、系统IP -> TestPassed + * 查询系统相关信息,系统、运行天数、系统IP * * @param os / * @return / diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemOperationLogService.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemOperationLogService.java index a76e9cf9..4243257c 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemOperationLogService.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemOperationLogService.java @@ -33,7 +33,7 @@ public class SystemOperationLogService { private SystemOperationLogMapper systemOperationLogMapper; /** - * 查询用户操作日志 -> TestPassed + * 查询用户操作日志 */ public IPage searchUserLog(KitPageArgs pageArgs) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemQuartzJobService.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemQuartzJobService.java index f17bbc10..6d1e903e 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemQuartzJobService.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemQuartzJobService.java @@ -28,24 +28,24 @@ import cn.odboy.system.dal.model.export.SystemQuartzJobExportRowVo; import cn.odboy.system.dal.model.export.SystemQuartzLogExportRowVo; import cn.odboy.system.dal.model.request.SystemQueryQuartzJobArgs; import cn.odboy.system.dal.model.request.SystemUpdateQuartzJobArgs; -import cn.odboy.system.dal.model.response.SystemQuartzJobVo; import cn.odboy.system.dal.mysql.SystemQuartzJobMapper; import cn.odboy.system.dal.mysql.SystemQuartzLogMapper; import cn.odboy.system.framework.quartz.QuartzManage; import cn.odboy.util.KitBeanUtil; import cn.odboy.util.KitPageUtil; +import cn.odboy.util.KitValidUtil; import cn.odboy.util.xlsx.KitExcelExporter; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import org.quartz.CronExpression; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import javax.servlet.http.HttpServletResponse; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Set; +import javax.servlet.http.HttpServletResponse; +import org.quartz.CronExpression; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service public class SystemQuartzJobService { @@ -60,27 +60,23 @@ public class SystemQuartzJobService { private KitRedisHelper redisHelper; /** - * 创建 -> TestPassed + * 创建 * * @param args / */ @Transactional(rollbackFor = Exception.class) public void createJob(SystemQuartzJobTb args) { - if (args.getId() != null) { - throw new BadRequestException("无效参数id"); - } // 验证Bean是不是合法的, 合法的定时任务 Bean 需要用 @Service 定义 checkBean(args.getBeanName()); if (!CronExpression.isValidExpression(args.getCronExpression())) { throw new BadRequestException("cron表达式格式错误"); } systemQuartzJobMapper.insert(args); - SystemQuartzJobVo quartzJobVo = KitBeanUtil.copyToClass(args, SystemQuartzJobVo.class); - quartzManage.addJob(quartzJobVo); + quartzManage.addJob(args); } /** - * 修改任务并重新调度 -> TestPassed + * 修改任务并重新调度 * * @param args / */ @@ -88,14 +84,10 @@ public class SystemQuartzJobService { public void updateQuartzJobResumeCron(SystemUpdateQuartzJobArgs args) { // 验证Bean是不是合法的, 合法的定时任务 Bean 需要用 @Service 定义 checkBean(args.getBeanName()); - if (!CronExpression.isValidExpression(args.getCronExpression())) { - throw new BadRequestException("cron表达式格式错误"); - } + KitValidUtil.isTrue(!CronExpression.isValidExpression(args.getCronExpression()), "Cron表达式格式错误"); if (StrUtil.isNotBlank(args.getSubTask())) { List tasks = Arrays.asList(args.getSubTask().split("[,,]")); - if (tasks.contains(args.getId().toString())) { - throw new BadRequestException("子任务中不能添加当前任务ID"); - } + KitValidUtil.isTrue(tasks.contains(args.getId().toString()), "子任务中不能添加当前任务ID"); } SystemQuartzJobTb jobTb = KitBeanUtil.copyToClass(args, SystemQuartzJobTb.class); systemQuartzJobMapper.updateById(jobTb); @@ -103,35 +95,34 @@ public class SystemQuartzJobService { } /** - * 更改定时任务状态 -> TestPassed + * 更改定时任务状态 * - * @param quartzJobVo / + * @param quartzJobTb / */ @Transactional(rollbackFor = Exception.class) - public void switchQuartzJobStatus(SystemQuartzJobVo quartzJobVo) { + public void switchQuartzJobStatus(SystemQuartzJobTb quartzJobTb) { // 置换暂停状态 - if (quartzJobVo.getIsPause()) { - quartzManage.resumeJob(quartzJobVo); - quartzJobVo.setIsPause(false); + if (quartzJobTb.getIsPause()) { + quartzManage.resumeJob(quartzJobTb); + quartzJobTb.setIsPause(false); } else { - quartzManage.pauseJob(quartzJobVo); - quartzJobVo.setIsPause(true); + quartzManage.pauseJob(quartzJobTb); + quartzJobTb.setIsPause(true); } - SystemQuartzJobTb record = KitBeanUtil.copyToClass(quartzJobVo, SystemQuartzJobTb.class); - systemQuartzJobMapper.updateById(record); + systemQuartzJobMapper.updateById(quartzJobTb); } /** - * 立即执行定时任务 -> TestPassed + * 立即执行定时任务 * * @param quartzJob / */ - public void startQuartzJob(SystemQuartzJobVo quartzJob) { + public void startQuartzJob(SystemQuartzJobTb quartzJob) { quartzManage.runJobNow(quartzJob); } /** - * 删除任务 -> TestPassed + * 删除任务 * * @param ids / */ @@ -145,7 +136,7 @@ public class SystemQuartzJobService { } /** - * 执行子任务 -> TestPassed + * 执行子任务 * * @param tasks / * @throws InterruptedException / @@ -162,11 +153,10 @@ public class SystemQuartzJobService { // 防止子任务不存在 continue; } - SystemQuartzJobVo quartzJobVo = KitBeanUtil.copyToClass(quartzJobTb, SystemQuartzJobVo.class); // 执行任务 String uuid = IdUtil.simpleUUID(); - quartzJobVo.setUuid(uuid); - startQuartzJob(quartzJobVo); + quartzJobTb.setUuid(uuid); + startQuartzJob(quartzJobTb); // 查询执行状态, 如果执行失败则停止后面的子任务执行 Boolean result = redisHelper.get(uuid, Boolean.class); while (result == null) { @@ -182,7 +172,7 @@ public class SystemQuartzJobService { } /** - * 分页查询 -> TestPassed + * 分页查询 * * @param args 条件 * @param page 分页参数 @@ -195,7 +185,7 @@ public class SystemQuartzJobService { } /** - * 分页查询日志 -> TestPassed + * 分页查询日志 * * @param args 条件 * @param page 分页参数 @@ -208,7 +198,7 @@ public class SystemQuartzJobService { } /** - * 查询全部 -> TestPassed + * 查询全部 * * @param args 条件 * @return / @@ -220,7 +210,7 @@ public class SystemQuartzJobService { } /** - * 查询全部 -> TestPassed + * 查询全部 * * @param args 条件 * @return / @@ -232,7 +222,7 @@ public class SystemQuartzJobService { } /** - * 查询启用的定时任务 -> TestPassed + * 查询启用的定时任务 */ public List listEnableQuartzJob() { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); @@ -241,7 +231,7 @@ public class SystemQuartzJobService { } /** - * 导出定时任务数据 -> TestPassed + * 导出定时任务数据 */ public void exportQuartzJobXlsx(HttpServletResponse response, SystemQueryQuartzJobArgs args) { List systemQuartzJobTbs = this.queryQuartzJobByArgs(args); @@ -262,7 +252,7 @@ public class SystemQuartzJobService { } /** - * 导出定时任务日志数据 -> TestPassed + * 导出定时任务日志数据 */ public void exportQuartzLogXlsx(HttpServletResponse response, SystemQueryQuartzJobArgs args) { List systemQuartzLogTbs = this.queryQuartzLogByArgs(args); @@ -284,7 +274,7 @@ public class SystemQuartzJobService { } /** - * 根据任务id查询定时任务 -> TestPassed + * 根据任务id查询定时任务 */ public SystemQuartzJobTb getQuartzJobById(Long id) { return systemQuartzJobMapper.selectById(id); @@ -332,9 +322,7 @@ public class SystemQuartzJobService { */ private void checkBean(String beanName) { // 避免调用攻击者可以从SpringContextHolder获得控制jdbcTemplate类 - // 并使用getDeclaredMethod调用jdbcTemplate的queryForMap函数,执行任意sql命令。 - if (!KitSpringBeanHolder.getAllServiceBeanName().contains(beanName)) { - throw new BadRequestException("非法的 Bean,请重新输入!"); - } + // 并使用getDeclaredMethod调用jdbcTemplate的queryForMap函数,执行任意sql命令 + KitValidUtil.isTrue(!KitSpringBeanHolder.getAllServiceBeanName().contains(beanName), "非法的 Bean,请重新输入"); } } diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemRoleDeptService.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemRoleDeptService.java index c2232ffa..e1c65e9a 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemRoleDeptService.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemRoleDeptService.java @@ -34,7 +34,7 @@ public class SystemRoleDeptService { private SystemRoleDeptMapper systemRoleDeptMapper; /** - * 批量删除角色部门关联 -> TestPassed + * 批量删除角色部门关联 * * @param roleIds 角色id集合 */ @@ -48,7 +48,7 @@ public class SystemRoleDeptService { } /** - * 批量绑定角色部门关联 -> TestPassed + * 批量绑定角色部门关联 * * @param depts 部门集合 * @param roleId 角色id @@ -68,7 +68,7 @@ public class SystemRoleDeptService { } /** - * 根据部门ID统计角色数量 -> TestPassed + * 根据部门ID统计角色数量 * * @param deptIds 部门id集合 * @return / @@ -83,7 +83,7 @@ public class SystemRoleDeptService { } /** - * 根据角色id查询部门信息 -> TestPassed + * 根据角色id查询部门信息 * * @param roleId 角色id * @return / diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemRoleMenuService.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemRoleMenuService.java index ff921186..e27f88c4 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemRoleMenuService.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemRoleMenuService.java @@ -36,7 +36,7 @@ public class SystemRoleMenuService { private SystemRoleMenuMapper systemRoleMenuMapper; /** - * 删除角色菜单关联 -> TestPassed + * 删除角色菜单关联 * * @param roleId 角色id */ @@ -48,7 +48,7 @@ public class SystemRoleMenuService { } /** - * 批量绑定角色菜单关联 -> TestPassed + * 批量绑定角色菜单关联 * * @param menus 菜单集合 * @param roleId 角色id @@ -68,7 +68,7 @@ public class SystemRoleMenuService { } /** - * 批量删除角色菜单关联 -> TestPassed + * 批量删除角色菜单关联 * * @param roleIds 角色id集合 */ @@ -82,7 +82,7 @@ public class SystemRoleMenuService { } /** - * @param roleIds 角色id集合 -> TestPassed + * @param roleIds 角色id集合 * @return / */ public List listMenuByRoleIds(Set roleIds, boolean hasButton) { @@ -109,7 +109,7 @@ public class SystemRoleMenuService { } /** - * 批量删除菜单角色关联 -> TestPassed + * 批量删除菜单角色关联 * * @param menuIds 菜单id集合 */ @@ -124,7 +124,7 @@ public class SystemRoleMenuService { } /** - * 根据角色id集合查询菜单权限 -> TestPassed + * 根据角色id集合查询菜单权限 * * @param roleIds 角色id集合 * @return / diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemRoleService.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemRoleService.java index 6d50f9ba..bfcf7f45 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemRoleService.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemRoleService.java @@ -19,7 +19,6 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.lang.Dict; import cn.hutool.core.util.StrUtil; import cn.odboy.base.KitPageResult; -import cn.odboy.framework.exception.BadRequestException; import cn.odboy.system.dal.dataobject.SystemMenuTb; import cn.odboy.system.dal.dataobject.SystemRoleTb; import cn.odboy.system.dal.model.export.SystemRoleExportRowVo; @@ -32,20 +31,21 @@ import cn.odboy.system.dal.mysql.SystemRoleMapper; import cn.odboy.system.framework.permission.core.KitSecurityHelper; import cn.odboy.util.KitBeanUtil; import cn.odboy.util.KitPageUtil; +import cn.odboy.util.KitValidUtil; import cn.odboy.util.xlsx.KitExcelExporter; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import javax.servlet.http.HttpServletResponse; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.stream.Collectors; +import javax.servlet.http.HttpServletResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service public class SystemRoleService { @@ -60,16 +60,14 @@ public class SystemRoleService { private SystemUserRoleService systemUserRoleService; /** - * 创建 -> TestPassed + * 创建 * * @param args / */ @Transactional(rollbackFor = Exception.class) public void saveRole(SystemCreateRoleArgs args) { this.checkRoleLevels(args.getLevel()); - if (this.existRoleWithName(args.getName())) { - throw new BadRequestException("角色名称已存在"); - } + KitValidUtil.isTrue(this.existRoleWithName(args.getName()), "角色名称已存在"); SystemRoleTb roleTb = KitBeanUtil.copyToClass(args, SystemRoleTb.class); systemRoleMapper.insert(roleTb); // 判断是否有部门数据, 若有, 则需创建关联 @@ -79,7 +77,7 @@ public class SystemRoleService { } /** - * 修改 -> TestPassed + * 修改 * * @param args / */ @@ -87,9 +85,7 @@ public class SystemRoleService { public void updateRoleById(SystemRoleVo args) { this.checkRoleLevels(args.getLevel()); SystemRoleTb role = systemRoleMapper.selectById(args.getId()); - if (this.existRoleWithNameNeSelf(args.getName(), role.getId())) { - throw new BadRequestException("角色名称已存在"); - } + KitValidUtil.isTrue(this.existRoleWithNameNeSelf(args.getName(), role.getId()), "角色名称已存在"); role.setName(args.getName()); role.setDescription(args.getDescription()); role.setDataScope(args.getDataScope()); @@ -105,7 +101,7 @@ public class SystemRoleService { } /** - * 修改绑定的菜单 -> TestPassed + * 修改绑定的菜单 * * @param args / */ @@ -122,7 +118,7 @@ public class SystemRoleService { } /** - * 删除 -> TestPassed + * 删除 * * @param ids / */ @@ -133,7 +129,7 @@ public class SystemRoleService { this.checkRoleLevels(roleLevel); } // 验证是否被用户关联 - this.verifyBindRelationByIds(ids); + KitValidUtil.isTrue(systemUserRoleService.existUserWithRoleIds(ids), "所选角色存在用户关联, 请解除关联再试"); // 删除角色 systemRoleMapper.deleteByIds(ids); // 删除角色部门关联数据、角色菜单关联数据 @@ -142,7 +138,7 @@ public class SystemRoleService { } /** - * 查询全部角色 -> TestPassed + * 查询全部角色 */ public List listAllRole() { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); @@ -151,7 +147,7 @@ public class SystemRoleService { } /** - * 根据条件查询全部角色 -> TestPassed + * 根据条件查询全部角色 * * @param args 条件 * @param rolePage 分页参数 @@ -164,7 +160,7 @@ public class SystemRoleService { } /** - * 分页查询角色 -> TestPassed + * 分页查询角色 * * @param args 条件 * @param page 分页条件 @@ -178,7 +174,7 @@ public class SystemRoleService { } /** - * 查询用户权限信息 -> TestPassed? + * 查询用户权限信息? * * @param user 用户信息 * @return 权限信息 @@ -204,17 +200,6 @@ public class SystemRoleService { return permissions.stream().map(SystemRoleCodeVo::new).collect(Collectors.toList()); } - /** - * 验证是否被用户关联 -> TestPassed - * - * @param ids / - */ - public void verifyBindRelationByIds(Set ids) { - if (systemUserRoleService.existUserWithRoleIds(ids)) { - throw new BadRequestException("所选角色存在用户关联, 请解除关联再试!"); - } - } - /** * 根据角色id查询用户可访问的部门和菜单信息 * @@ -281,7 +266,7 @@ public class SystemRoleService { } /** - * 检查用户的角色级别 -> TestPassed + * 检查用户的角色级别 * * @return / */ @@ -289,9 +274,7 @@ public class SystemRoleService { Set levels = systemUserRoleService.listUserRoleLevelByUserId(KitSecurityHelper.getCurrentUserId()); int min = Collections.min(levels); if (level != null) { - if (level < min) { - throw new BadRequestException("权限不足, 你的角色级别:" + min + ", 低于操作的角色级别:" + level); - } + KitValidUtil.isTrue(level < min, "权限不足, 你的角色级别:" + min + ", 低于操作的角色级别:" + level); } return min; } diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserDeptService.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserDeptService.java index d5d7b468..cd009afa 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserDeptService.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserDeptService.java @@ -29,7 +29,7 @@ public class SystemUserDeptService { private SystemUserMapper systemUserMapper; /** - * 根据部门id统计用户数量 -> TestPassed + * 根据部门id统计用户数量 */ public long countUserByDeptIds(Set deptIds) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserJobService.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserJobService.java index a994d5ee..a42de3a8 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserJobService.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserJobService.java @@ -34,7 +34,7 @@ public class SystemUserJobService { private SystemUserJobMapper systemUserJobMapper; /** - * 批量绑定用户岗位 -> TestPassed + * 批量绑定用户岗位 */ @Transactional(rollbackFor = Exception.class) public void batchInsertUserJob(Set jobs, Long userId) { @@ -51,7 +51,7 @@ public class SystemUserJobService { } /** - * 批量解绑用户岗位 -> TestPassed + * 批量解绑用户岗位 */ @Transactional(rollbackFor = Exception.class) public void batchDeleteUserJob(Set userIds) { @@ -63,7 +63,7 @@ public class SystemUserJobService { } /** - * 根据岗位ID统计用户数量 -> TestPassed + * 根据岗位ID统计用户数量 * * @param jobIds / * @return / @@ -78,7 +78,7 @@ public class SystemUserJobService { } /** - * 根据用户id查询岗位 -> TestPassed + * 根据用户id查询岗位 * * @param userId / * @return / diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserRoleService.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserRoleService.java index 76d6e861..af81a009 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserRoleService.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserRoleService.java @@ -52,7 +52,7 @@ public class SystemUserRoleService { private SystemRoleDeptService systemRoleDeptService; /** - * 批量绑定用户角色 -> TestPassed + * 批量绑定用户角色 */ @Transactional(rollbackFor = Exception.class) public void batchInsertUserRole(Set roles, Long userId) { @@ -69,7 +69,7 @@ public class SystemUserRoleService { } /** - * 批量解绑用户角色 -> TestPassed + * 批量解绑用户角色 */ @Transactional(rollbackFor = Exception.class) public void batchDeleteUserRole(Set userIds) { @@ -101,7 +101,7 @@ public class SystemUserRoleService { } /** - * 根据用户ID查询 -> TestPassed + * 根据用户ID查询 * * @param userId 用户ID * @return / @@ -112,7 +112,7 @@ public class SystemUserRoleService { } /** - * 根据角色查询角色级别 -> TestPassed + * 根据角色查询角色级别 * * @param roles / * @return / @@ -136,7 +136,7 @@ public class SystemUserRoleService { } /** - * 如果当前用户的角色级别低于创建用户的角色级别,则抛出权限不足的错误 -> TestPassed + * 如果当前用户的角色级别低于创建用户的角色级别,则抛出权限不足的错误 * * @param args / */ @@ -150,7 +150,7 @@ public class SystemUserRoleService { } /** - * 根据用户id查询角色 -> TestPassed + * 根据用户id查询角色 * * @param userId / * @return / @@ -160,7 +160,7 @@ public class SystemUserRoleService { } /** - * 根据用户id查询角色级别集合 -> TestPassed + * 根据用户id查询角色级别集合 * * @param userId / * @return / @@ -170,7 +170,7 @@ public class SystemUserRoleService { } /** - * 根据用户id查询角色id集合 -> TestPassed + * 根据用户id查询角色id集合 * * @param userId / * @return / @@ -180,7 +180,7 @@ public class SystemUserRoleService { } /** - * 根据角色id集合判断是否存在关联用户 -> TestPassed + * 根据角色id集合判断是否存在关联用户 * * @param ids 角色id集合 * @return / diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserService.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserService.java index 7ac4ab7c..901041bd 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserService.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemUserService.java @@ -18,7 +18,6 @@ package cn.odboy.system.service; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; import cn.odboy.base.KitPageResult; -import cn.odboy.framework.exception.BadRequestException; import cn.odboy.framework.properties.AppProperties; import cn.odboy.framework.server.core.KitFileLocalUploadHelper; import cn.odboy.system.constant.SystemCaptchaBizEnum; @@ -39,17 +38,11 @@ import cn.odboy.util.KitBeanUtil; import cn.odboy.util.KitFileUtil; import cn.odboy.util.KitPageUtil; import cn.odboy.util.KitRsaEncryptUtil; +import cn.odboy.util.KitValidUtil; import cn.odboy.util.xlsx.KitExcelExporter; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.crypto.password.PasswordEncoder; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.ObjectUtils; -import org.springframework.web.multipart.MultipartFile; -import javax.servlet.http.HttpServletResponse; import java.io.File; import java.util.ArrayList; import java.util.Collections; @@ -59,6 +52,13 @@ import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; +import javax.servlet.http.HttpServletResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.ObjectUtils; +import org.springframework.web.multipart.MultipartFile; @Service public class SystemUserService { @@ -87,7 +87,7 @@ public class SystemUserService { private PasswordEncoder passwordEncoder; /** - * 新增用户 -> TestPassed + * 新增用户 * * @param args / */ @@ -98,15 +98,9 @@ public class SystemUserService { // 默认密码 123456 record.setPassword(passwordEncoder.encode("123456")); record.setDeptId(args.getDept().getId()); - if (this.existUserWithUsername(record.getUsername())) { - throw new BadRequestException("用户名已存在"); - } - if (this.existUserWithEmail(record.getEmail())) { - throw new BadRequestException("邮箱已存在"); - } - if (this.existUserWithPhone(record.getPhone())) { - throw new BadRequestException("手机号已存在"); - } + KitValidUtil.isTrue(this.existUserWithUsername(record.getUsername()), "用户名已存在"); + KitValidUtil.isTrue(this.existUserWithEmail(record.getEmail()), "邮箱已存在"); + KitValidUtil.isTrue(this.existUserWithPhone(record.getPhone()), "手机号已存在"); // 保存用户 systemUserMapper.insert(record); // 保存用户岗位 @@ -116,7 +110,7 @@ public class SystemUserService { } /** - * 编辑用户 -> TestPassed + * 编辑用户 * * @param args / */ @@ -124,15 +118,9 @@ public class SystemUserService { public void updateUserById(SystemUserVo args) { systemUserRoleService.checkLevel(args); SystemUserTb user = systemUserMapper.selectById(args.getId()); - if (this.existUserWithUsernameNeSelf(args.getUsername(), user.getId())) { - throw new BadRequestException("用户名已存在"); - } - if (this.existUserWithEmailNeSelf(args.getEmail(), user.getId())) { - throw new BadRequestException("邮箱已存在"); - } - if (this.existUserWithPhoneNeSelf(args.getPhone(), user.getId())) { - throw new BadRequestException("手机号已存在"); - } + KitValidUtil.isTrue(this.existUserWithUsernameNeSelf(args.getUsername(), user.getId()), "用户名已存在"); + KitValidUtil.isTrue(this.existUserWithEmailNeSelf(args.getEmail(), user.getId()), "邮箱已存在"); + KitValidUtil.isTrue(this.existUserWithPhoneNeSelf(args.getPhone(), user.getId()), "手机号已存在"); // 如果用户被禁用, 则清除用户登录信息 if (!args.getEnabled()) { systemUserOnlineInfoDAO.kickOutByUsername(args.getUsername()); @@ -156,19 +144,15 @@ public class SystemUserService { } /** - * 用户自助修改资料 -> TestPassed + * 用户自助修改资料 * * @param args / */ @Transactional(rollbackFor = Exception.class) public void updateUserCenterInfoById(SystemUserTb args) { - if (!args.getId().equals(KitSecurityHelper.getCurrentUserId())) { - throw new BadRequestException("不能修改他人资料"); - } + KitValidUtil.isTrue(!args.getId().equals(KitSecurityHelper.getCurrentUserId()), "不能修改他人资料"); SystemUserTb user = systemUserMapper.selectById(args.getId()); - if (this.existUserWithPhoneNeSelf(args.getPhone(), user.getId())) { - throw new BadRequestException("手机号已存在"); - } + KitValidUtil.isTrue(this.existUserWithPhoneNeSelf(args.getPhone(), user.getId()), "手机号已存在"); user.setNickName(args.getNickName()); user.setPhone(args.getPhone()); user.setGender(args.getGender()); @@ -177,7 +161,7 @@ public class SystemUserService { } /** - * 删除用户 -> TestPassed + * 删除用户 * * @param ids / */ @@ -186,12 +170,10 @@ public class SystemUserService { Long currentUserId = KitSecurityHelper.getCurrentUserId(); // 校验权限 for (Long id : ids) { + SystemUserTb systemUserTb = systemUserMapper.selectById(id); Integer currentLevel = Collections.min(systemUserRoleService.listUserRoleLevelByUserId(currentUserId)); Integer optLevel = Collections.min(systemUserRoleService.listUserRoleLevelByUserId(id)); - if (currentLevel > optLevel) { - SystemUserTb systemUserTb = systemUserMapper.selectById(id); - throw new BadRequestException("角色权限不足, 不能删除:" + systemUserTb.getUsername()); - } + KitValidUtil.isTrue(currentLevel > optLevel, "角色权限不足, 不能删除:" + systemUserTb.getUsername()); } // 清理缓存 List usernameList = systemUserMapper.listUsernameByIds(ids); @@ -207,7 +189,7 @@ public class SystemUserService { } /** - * 修改密码 -> TestPassed + * 修改密码 * * @param username 用户名 * @param args 参数 @@ -217,19 +199,15 @@ public class SystemUserService { String oldPass = KitRsaEncryptUtil.decryptByPrivateKey(properties.getRsa().getPrivateKey(), args.getOldPass()); String newPass = KitRsaEncryptUtil.decryptByPrivateKey(properties.getRsa().getPrivateKey(), args.getNewPass()); SystemUserTb user = this.getUserByUsername(username); - if (!passwordEncoder.matches(oldPass, user.getPassword())) { - throw new BadRequestException("修改失败,旧密码错误"); - } - if (passwordEncoder.matches(newPass, user.getPassword())) { - throw new BadRequestException("新密码不能与旧密码相同"); - } + KitValidUtil.isTrue(!passwordEncoder.matches(oldPass, user.getPassword()), "修改失败,旧密码错误"); + KitValidUtil.isTrue(passwordEncoder.matches(newPass, user.getPassword()), "新密码不能与旧密码相同"); String encryptPassword = passwordEncoder.encode(newPass); systemUserMapper.updateUserPasswordByUsername(username, encryptPassword); systemUserInfoDAO.deleteUserLoginInfoByUserName(username); } /** - * 重置密码 -> TestPassed + * 重置密码 * * @param ids 用户id */ @@ -249,7 +227,7 @@ public class SystemUserService { } /** - * 修改头像 -> TestPassed + * 修改头像 * * @param multipartFile 文件 * @return / @@ -258,17 +236,13 @@ public class SystemUserService { public Map updateUserAvatar(MultipartFile multipartFile) { SystemUserTb user = this.getUserByUsername(KitSecurityHelper.getCurrentUsername()); String username = user.getUsername(); - if (StrUtil.isBlank(username)) { - throw new BadRequestException("异常用户数据, 请联系管理员处理!"); - } + KitValidUtil.isBlank(username, "异常用户数据, 请联系管理员处理"); // 文件大小验证 KitFileUtil.checkSize(fileUploadPathHelper.getAvatarMaxSize(), multipartFile.getSize()); // 验证文件上传的格式 String image = "gif jpg png jpeg"; String fileType = KitFileUtil.getSuffix(multipartFile.getOriginalFilename()); - if (fileType != null && !image.contains(fileType)) { - throw new BadRequestException("文件格式错误, 仅支持 " + image + " 格式!"); - } + KitValidUtil.isTrue(fileType != null && !image.contains(fileType), "文件格式错误, 仅支持 " + image + " 格式"); String oldPath = user.getAvatarPath(); File file = KitFileUtil.upload(multipartFile, fileUploadPathHelper.getPath()); user.setAvatarPath(Objects.requireNonNull(file).getPath()); @@ -284,7 +258,7 @@ public class SystemUserService { } /** - * 修改邮箱 -> TestPassed + * 修改邮箱 * * @param username 用户名 * @param args 参数 @@ -294,16 +268,14 @@ public class SystemUserService { public void updateUserEmailByUsername(String username, SystemUserTb args, String code) throws Exception { String password = KitRsaEncryptUtil.decryptByPrivateKey(properties.getRsa().getPrivateKey(), args.getPassword()); SystemUserTb user = this.getUserByUsername(username); - if (!passwordEncoder.matches(password, user.getPassword())) { - throw new BadRequestException("密码错误"); - } + KitValidUtil.isTrue(!passwordEncoder.matches(password, user.getPassword()), "密码错误"); systemEmailService.checkEmailCaptchaV1(SystemCaptchaBizEnum.EMAIL_RESET_EMAIL_CODE, args.getEmail(), code); systemUserMapper.updateUserEmailByUsername(username, args.getEmail()); systemUserInfoDAO.deleteUserLoginInfoByUserName(username); } /** - * 查询全部 -> TestPassed + * 查询全部 * * @param args 条件 * @param page 分页参数 @@ -365,7 +337,7 @@ public class SystemUserService { } /** - * 聚合查询 -> TestPassed + * 聚合查询 */ public KitPageResult aggregationSearchUserByArgs(Page page, SystemQueryUserArgs args, String currentUsername) { if (!ObjectUtils.isEmpty(args.getDeptId())) { @@ -394,7 +366,7 @@ public class SystemUserService { } /** - * 导出 -> TestPassed + * 导出 */ public void exportUserXlsx(HttpServletResponse response, SystemQueryUserArgs args) { long totalCount = this.countUserByArgs(args); @@ -511,15 +483,9 @@ public class SystemUserService { */ private void injectQueryParams(SystemQueryUserArgs args, LambdaQueryWrapper wrapper) { if (args != null) { - if (args.getId() != null) { - wrapper.eq(SystemUserTb::getId, args.getId()); - } - if (args.getEnabled() != null) { - wrapper.eq(SystemUserTb::getEnabled, args.getEnabled()); - } - if (CollUtil.isNotEmpty(args.getDeptIds())) { - wrapper.in(SystemUserTb::getDeptId, args.getDeptIds()); - } + wrapper.eq(args.getId() != null, SystemUserTb::getId, args.getId()); + wrapper.eq(args.getEnabled() != null, SystemUserTb::getEnabled, args.getEnabled()); + wrapper.in(CollUtil.isNotEmpty(args.getDeptIds()), SystemUserTb::getDeptId, args.getDeptIds()); if (StrUtil.isNotBlank(args.getBlurry())) { wrapper.and(w -> w.like(SystemUserTb::getUsername, args.getBlurry()).or() .like(SystemUserTb::getNickName, args.getBlurry()).or().like(SystemUserTb::getEmail, args.getBlurry())); @@ -532,7 +498,7 @@ public class SystemUserService { } /** - * 转换为SystemUserVo并关联查询部门、角色、岗位信息 -> TestPassed + * 转换为SystemUserVo并关联查询部门、角色、岗位信息 * * @param user 用户基本信息 * @param includePassword 是否包含用户密码 diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/impl/SystemMinioStorageServiceImpl.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/impl/SystemMinioStorageServiceImpl.java index c1f8512a..037ae061 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/impl/SystemMinioStorageServiceImpl.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/impl/SystemMinioStorageServiceImpl.java @@ -39,13 +39,13 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import java.io.File; +import java.util.List; +import javax.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; -import javax.servlet.http.HttpServletResponse; -import java.io.File; -import java.util.List; /** *

@@ -80,11 +80,8 @@ public class SystemMinioStorageServiceImpl extends ServiceImpl selectOssStorageByArgs( - SystemQueryStorageArgs args, - Page page - ) { - KitValidUtil.notNull(args); + private IPage selectOssStorageByArgs(SystemQueryStorageArgs args, Page page) { + KitValidUtil.isNull(args); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.and( StrUtil.isNotBlank(args.getBlurry()), diff --git a/cutejava/cutejava-starter/src/test/java/cn/odboy/util/KitDateUtilTest.java b/cutejava/cutejava-starter/src/test/java/cn/odboy/util/KitDateUtilTest.java new file mode 100644 index 00000000..83defe42 --- /dev/null +++ b/cutejava/cutejava-starter/src/test/java/cn/odboy/util/KitDateUtilTest.java @@ -0,0 +1,31 @@ +/* + * 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.util; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.text.SimpleDateFormat; +import java.util.Date; +import org.junit.jupiter.api.Test; + +public class KitDateUtilTest { + + @Test + public void testGetWeekDay() { + SimpleDateFormat simpleDateformat = new SimpleDateFormat("E"); + assertEquals(simpleDateformat.format(new Date()), KitDateUtil.getWeekDay()); + } +}