From 6d0060b21c374afd9880e57490345a140187a7cd Mon Sep 17 00:00:00 2001 From: Charles7c Date: Tue, 28 May 2024 23:04:03 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E5=8F=82=E6=95=B0=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/system/model/query/OptionQuery.java | 3 +- .../admin/system/model/req/OptionReq.java | 8 ++ .../system/model/req/OptionResetValueReq.java | 10 ++- .../admin/system/model/resp/OptionResp.java | 6 ++ .../service/impl/OptionServiceImpl.java | 13 ++- .../admin/webapi/common/CommonController.java | 2 +- .../changelog/mysql/continew-admin_table.sql | 84 +++++++++---------- .../postgresql/continew-admin_table.sql | 2 +- 8 files changed, 78 insertions(+), 50 deletions(-) diff --git a/continew-admin-system/src/main/java/top/continew/admin/system/model/query/OptionQuery.java b/continew-admin-system/src/main/java/top/continew/admin/system/model/query/OptionQuery.java index e24a52f8..8a3d44a4 100644 --- a/continew-admin-system/src/main/java/top/continew/admin/system/model/query/OptionQuery.java +++ b/continew-admin-system/src/main/java/top/continew/admin/system/model/query/OptionQuery.java @@ -41,7 +41,7 @@ public class OptionQuery implements Serializable { /** * 键列表 */ - @Schema(description = "键列表", example = "site_title,site_copyright") + @Schema(description = "键列表", example = "SITE_TITLE,SITE_COPYRIGHT") @Query(type = QueryType.IN) private List code; @@ -49,6 +49,5 @@ public class OptionQuery implements Serializable { * 类别 */ @Schema(description = "类别", example = "SITE") - @Query private String category; } \ No newline at end of file diff --git a/continew-admin-system/src/main/java/top/continew/admin/system/model/req/OptionReq.java b/continew-admin-system/src/main/java/top/continew/admin/system/model/req/OptionReq.java index 6ec62cf0..a5c05e11 100644 --- a/continew-admin-system/src/main/java/top/continew/admin/system/model/req/OptionReq.java +++ b/continew-admin-system/src/main/java/top/continew/admin/system/model/req/OptionReq.java @@ -18,6 +18,7 @@ package top.continew.admin.system.model.req; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; import lombok.Data; import org.hibernate.validator.constraints.Length; import top.continew.starter.extension.crud.model.req.BaseReq; @@ -37,6 +38,13 @@ public class OptionReq extends BaseReq { @Serial private static final long serialVersionUID = 1L; + /** + * ID + */ + @Schema(description = "ID", example = "1") + @NotNull(message = "ID不能为空") + private Long id; + /** * 键 */ diff --git a/continew-admin-system/src/main/java/top/continew/admin/system/model/req/OptionResetValueReq.java b/continew-admin-system/src/main/java/top/continew/admin/system/model/req/OptionResetValueReq.java index 831cd5a3..9315fcd6 100644 --- a/continew-admin-system/src/main/java/top/continew/admin/system/model/req/OptionResetValueReq.java +++ b/continew-admin-system/src/main/java/top/continew/admin/system/model/req/OptionResetValueReq.java @@ -17,7 +17,6 @@ package top.continew.admin.system.model.req; import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotEmpty; import lombok.Data; import java.io.Serial; @@ -40,7 +39,12 @@ public class OptionResetValueReq implements Serializable { /** * 键列表 */ - @Schema(description = "键列表", example = "site_title,site_copyright") - @NotEmpty(message = "键不能为空") + @Schema(description = "键列表", example = "SITE_TITLE,SITE_COPYRIGHT") private List code; + + /** + * 类别 + */ + @Schema(description = "类别", example = "SITE") + private String category; } diff --git a/continew-admin-system/src/main/java/top/continew/admin/system/model/resp/OptionResp.java b/continew-admin-system/src/main/java/top/continew/admin/system/model/resp/OptionResp.java index 0baee5cd..8ce83b27 100644 --- a/continew-admin-system/src/main/java/top/continew/admin/system/model/resp/OptionResp.java +++ b/continew-admin-system/src/main/java/top/continew/admin/system/model/resp/OptionResp.java @@ -37,6 +37,12 @@ public class OptionResp implements Serializable { @Serial private static final long serialVersionUID = 1L; + /** + * ID + */ + @Schema(description = "ID", example = "1") + private Long id; + /** * 名称 */ diff --git a/continew-admin-system/src/main/java/top/continew/admin/system/service/impl/OptionServiceImpl.java b/continew-admin-system/src/main/java/top/continew/admin/system/service/impl/OptionServiceImpl.java index 679727d0..53daeb59 100644 --- a/continew-admin-system/src/main/java/top/continew/admin/system/service/impl/OptionServiceImpl.java +++ b/continew-admin-system/src/main/java/top/continew/admin/system/service/impl/OptionServiceImpl.java @@ -17,8 +17,10 @@ package top.continew.admin.system.service.impl; import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import top.continew.admin.common.constant.CacheConstants; @@ -78,7 +80,16 @@ public class OptionServiceImpl implements OptionService { @Override public void resetValue(OptionResetValueReq req) { RedisUtils.deleteByPattern(CacheConstants.OPTION_KEY_PREFIX + StringConstants.ASTERISK); - baseMapper.lambdaUpdate().set(OptionDO::getValue, null).in(OptionDO::getCode, req.getCode()).update(); + String category = req.getCategory(); + List codeList = req.getCode(); + ValidationUtils.throwIf(StrUtil.isBlank(category) && CollUtil.isEmpty(codeList), "键列表不能为空"); + LambdaUpdateChainWrapper chainWrapper = baseMapper.lambdaUpdate().set(OptionDO::getValue, null); + if (StrUtil.isNotBlank(category)) { + chainWrapper.eq(OptionDO::getCategory, category); + } else { + chainWrapper.in(OptionDO::getCode, req.getCode()); + } + chainWrapper.update(); } @Override diff --git a/continew-admin-webapi/src/main/java/top/continew/admin/webapi/common/CommonController.java b/continew-admin-webapi/src/main/java/top/continew/admin/webapi/common/CommonController.java index b287edaf..5d97b484 100644 --- a/continew-admin-webapi/src/main/java/top/continew/admin/webapi/common/CommonController.java +++ b/continew-admin-webapi/src/main/java/top/continew/admin/webapi/common/CommonController.java @@ -112,7 +112,7 @@ public class CommonController { @SaIgnore @Operation(summary = "查询参数字典", description = "查询参数字典") @GetMapping("/dict/option") - @Cached(key = "#query.code", name = CacheConstants.OPTION_KEY_PREFIX) + @Cached(key = "#query.category", name = CacheConstants.OPTION_KEY_PREFIX) public R>> listOptionDict(@Validated OptionQuery query) { return R.ok(optionService.list(query) .stream() diff --git a/continew-admin-webapi/src/main/resources/db/changelog/mysql/continew-admin_table.sql b/continew-admin-webapi/src/main/resources/db/changelog/mysql/continew-admin_table.sql index 22ce9287..7e1e3274 100644 --- a/continew-admin-webapi/src/main/resources/db/changelog/mysql/continew-admin_table.sql +++ b/continew-admin-webapi/src/main/resources/db/changelog/mysql/continew-admin_table.sql @@ -3,7 +3,7 @@ -- changeset Charles7c:1 -- comment 初始化表结构 CREATE TABLE IF NOT EXISTS `sys_menu` ( - `id` bigint(20) NOT NULL COMMENT 'ID', + `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID', `title` varchar(30) NOT NULL COMMENT '标题', `parent_id` bigint(20) NOT NULL DEFAULT 0 COMMENT '上级菜单ID', `type` tinyint(1) UNSIGNED NOT NULL DEFAULT 1 COMMENT '类型(1:目录;2:菜单;3:按钮)', @@ -30,7 +30,7 @@ CREATE TABLE IF NOT EXISTS `sys_menu` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='菜单表'; CREATE TABLE IF NOT EXISTS `sys_dept` ( - `id` bigint(20) NOT NULL COMMENT 'ID', + `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID', `name` varchar(30) NOT NULL COMMENT '名称', `parent_id` bigint(20) NOT NULL DEFAULT 0 COMMENT '上级部门ID', `ancestors` varchar(512) NOT NULL DEFAULT '' COMMENT '祖级列表', @@ -50,7 +50,7 @@ CREATE TABLE IF NOT EXISTS `sys_dept` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='部门表'; CREATE TABLE IF NOT EXISTS `sys_role` ( - `id` bigint(20) NOT NULL COMMENT 'ID', + `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID', `name` varchar(30) NOT NULL COMMENT '名称', `code` varchar(30) NOT NULL COMMENT '编码', `data_scope` tinyint(1) NOT NULL DEFAULT 4 COMMENT '数据权限(1:全部数据权限;2:本部门及以下数据权限;3:本部门数据权限;4:仅本人数据权限;5:自定义数据权限)', @@ -69,7 +69,7 @@ CREATE TABLE IF NOT EXISTS `sys_role` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='角色表'; CREATE TABLE IF NOT EXISTS `sys_user` ( - `id` bigint(20) NOT NULL COMMENT 'ID', + `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID', `username` varchar(64) NOT NULL COMMENT '用户名', `nickname` varchar(30) NOT NULL COMMENT '昵称', `password` varchar(255) DEFAULT NULL COMMENT '密码', @@ -96,10 +96,10 @@ CREATE TABLE IF NOT EXISTS `sys_user` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户表'; CREATE TABLE IF NOT EXISTS `sys_user_password_history` ( - `id` bigint(20) NOT NULL COMMENT 'ID', - `user_id` bigint(20) NOT NULL COMMENT '用户ID', - `password` varchar(255) NOT NULL COMMENT '密码', - `create_time` datetime NOT NULL COMMENT '创建时间', + `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID', + `user_id` bigint(20) NOT NULL COMMENT '用户ID', + `password` varchar(255) NOT NULL COMMENT '密码', + `create_time` datetime NOT NULL COMMENT '创建时间', PRIMARY KEY (`id`) USING BTREE, INDEX `idx_user_id`(`user_id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户历史密码表'; @@ -133,36 +133,36 @@ CREATE TABLE IF NOT EXISTS `sys_role_dept` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='角色和部门关联表'; CREATE TABLE IF NOT EXISTS `sys_option` ( - `id` bigint(20) NOT NULL COMMENT 'ID', - `category` varchar(50) DEFAULT NULL COMMENT '类别', - `name` varchar(50) NOT NULL COMMENT '名称', - `code` varchar(100) NOT NULL COMMENT '键', - `value` text DEFAULT NULL COMMENT '值', - `default_value` text DEFAULT NULL COMMENT '默认值', - `description` varchar(200) DEFAULT NULL COMMENT '描述', - `update_user` bigint(20) DEFAULT NULL COMMENT '修改人', - `update_time` datetime DEFAULT NULL COMMENT '修改时间', + `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID', + `category` varchar(50) NOT NULL COMMENT '类别', + `name` varchar(50) NOT NULL COMMENT '名称', + `code` varchar(100) NOT NULL COMMENT '键', + `value` text DEFAULT NULL COMMENT '值', + `default_value` text DEFAULT NULL COMMENT '默认值', + `description` varchar(200) DEFAULT NULL COMMENT '描述', + `update_user` bigint(20) DEFAULT NULL COMMENT '修改人', + `update_time` datetime DEFAULT NULL COMMENT '修改时间', PRIMARY KEY (`id`) USING BTREE, UNIQUE INDEX `uk_category_code`(`category`, `code`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='参数表'; CREATE TABLE IF NOT EXISTS `sys_dict` ( - `id` bigint(20) NOT NULL COMMENT 'ID', - `name` varchar(30) NOT NULL COMMENT '名称', - `code` varchar(30) NOT NULL COMMENT '编码', - `description` varchar(200) DEFAULT NULL COMMENT '描述', - `is_system` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否为系统内置数据', - `create_user` bigint(20) NOT NULL COMMENT '创建人', - `create_time` datetime NOT NULL COMMENT '创建时间', - `update_user` bigint(20) DEFAULT NULL COMMENT '修改人', - `update_time` datetime DEFAULT NULL COMMENT '修改时间', + `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID', + `name` varchar(30) NOT NULL COMMENT '名称', + `code` varchar(30) NOT NULL COMMENT '编码', + `description` varchar(200) DEFAULT NULL COMMENT '描述', + `is_system` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否为系统内置数据', + `create_user` bigint(20) NOT NULL COMMENT '创建人', + `create_time` datetime NOT NULL COMMENT '创建时间', + `update_user` bigint(20) DEFAULT NULL COMMENT '修改人', + `update_time` datetime DEFAULT NULL COMMENT '修改时间', PRIMARY KEY (`id`) USING BTREE, UNIQUE INDEX `uk_name`(`name`) USING BTREE, UNIQUE INDEX `uk_code`(`code`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='字典表'; CREATE TABLE IF NOT EXISTS `sys_dict_item` ( - `id` bigint(20) NOT NULL COMMENT 'ID', + `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID', `label` varchar(30) NOT NULL COMMENT '标签', `value` varchar(30) NOT NULL COMMENT '值', `color` varchar(30) DEFAULT NULL COMMENT '标签颜色', @@ -182,7 +182,7 @@ CREATE TABLE IF NOT EXISTS `sys_dict_item` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='字典项表'; CREATE TABLE IF NOT EXISTS `sys_log` ( - `id` bigint(20) NOT NULL COMMENT 'ID', + `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID', `trace_id` varchar(255) DEFAULT NULL COMMENT '链路ID', `description` varchar(255) NOT NULL COMMENT '日志描述', `module` varchar(50) NOT NULL COMMENT '所属模块', @@ -209,7 +209,7 @@ CREATE TABLE IF NOT EXISTS `sys_log` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='系统日志表'; CREATE TABLE IF NOT EXISTS `sys_message` ( - `id` bigint(20) NOT NULL COMMENT 'ID', + `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID', `title` varchar(50) NOT NULL COMMENT '标题', `content` varchar(255) DEFAULT NULL COMMENT '内容', `type` tinyint(1) UNSIGNED NOT NULL DEFAULT 1 COMMENT '类型(1:系统消息)', @@ -227,24 +227,24 @@ CREATE TABLE IF NOT EXISTS `sys_message_user` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='消息和用户关联表'; CREATE TABLE IF NOT EXISTS `sys_notice` ( - `id` bigint(20) NOT NULL COMMENT 'ID', - `title` varchar(150) NOT NULL COMMENT '标题', - `content` mediumtext NOT NULL COMMENT '内容', - `type` varchar(30) NOT NULL COMMENT '类型', - `effective_time` datetime DEFAULT NULL COMMENT '生效时间', - `terminate_time` datetime DEFAULT NULL COMMENT '终止时间', - `sort` int NOT NULL DEFAULT 999 COMMENT '排序', - `create_user` bigint(20) NOT NULL COMMENT '创建人', - `create_time` datetime NOT NULL COMMENT '创建时间', - `update_user` bigint(20) DEFAULT NULL COMMENT '修改人', - `update_time` datetime DEFAULT NULL COMMENT '修改时间', + `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID', + `title` varchar(150) NOT NULL COMMENT '标题', + `content` mediumtext NOT NULL COMMENT '内容', + `type` varchar(30) NOT NULL COMMENT '类型', + `effective_time` datetime DEFAULT NULL COMMENT '生效时间', + `terminate_time` datetime DEFAULT NULL COMMENT '终止时间', + `sort` int NOT NULL DEFAULT 999 COMMENT '排序', + `create_user` bigint(20) NOT NULL COMMENT '创建人', + `create_time` datetime NOT NULL COMMENT '创建时间', + `update_user` bigint(20) DEFAULT NULL COMMENT '修改人', + `update_time` datetime DEFAULT NULL COMMENT '修改时间', PRIMARY KEY (`id`) USING BTREE, INDEX `idx_create_user`(`create_user`) USING BTREE, INDEX `idx_update_user`(`update_user`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='公告表'; CREATE TABLE IF NOT EXISTS `sys_storage` ( - `id` bigint(20) NOT NULL COMMENT 'ID', + `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID', `name` varchar(100) NOT NULL COMMENT '名称', `code` varchar(30) NOT NULL COMMENT '编码', `type` tinyint(1) UNSIGNED NOT NULL DEFAULT 1 COMMENT '类型(1:兼容S3协议存储;2:本地存储)', @@ -268,7 +268,7 @@ CREATE TABLE IF NOT EXISTS `sys_storage` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='存储表'; CREATE TABLE IF NOT EXISTS `sys_file` ( - `id` bigint(20) NOT NULL COMMENT 'ID', + `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID', `name` varchar(255) NOT NULL COMMENT '名称', `size` bigint(20) NOT NULL COMMENT '大小(字节)', `url` varchar(512) NOT NULL COMMENT 'URL', diff --git a/continew-admin-webapi/src/main/resources/db/changelog/postgresql/continew-admin_table.sql b/continew-admin-webapi/src/main/resources/db/changelog/postgresql/continew-admin_table.sql index db81d87b..09bac1f6 100644 --- a/continew-admin-webapi/src/main/resources/db/changelog/postgresql/continew-admin_table.sql +++ b/continew-admin-webapi/src/main/resources/db/changelog/postgresql/continew-admin_table.sql @@ -218,7 +218,7 @@ COMMENT ON TABLE "sys_role_dept" IS '角色和部门关联表'; CREATE TABLE IF NOT EXISTS "sys_option" ( "id" int8 NOT NULL, - "category" varchar(50) DEFAULT NULL, + "category" varchar(50) NOT NULL, "name" varchar(50) NOT NULL, "code" varchar(100) NOT NULL, "value" text DEFAULT NULL,