From d7e8fc9bc31409b3652b5ad03a79248726547088 Mon Sep 17 00:00:00 2001 From: Charles7c Date: Tue, 24 Sep 2024 00:23:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8F=82=E6=95=B0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=AE=BE=E5=80=BC=E4=B8=BA=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/system/model/req/OptionReq.java | 1 - .../service/impl/OptionServiceImpl.java | 22 ++++++++++++++----- .../changelog/mysql/continew-admin_data.sql | 5 ++++- 3 files changed, 21 insertions(+), 7 deletions(-) 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 a5c05e11..29769d67 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 @@ -57,6 +57,5 @@ public class OptionReq extends BaseReq { * 值 */ @Schema(description = "值", example = "ContiNew Admin") - @NotBlank(message = "值不能为空") private String value; } \ No newline at end of file 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 771f9624..05f7c033 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 @@ -73,11 +73,23 @@ public class OptionServiceImpl implements OptionService { @Override public void update(List options) { + // 非空校验 + List idList = options.stream().map(OptionReq::getId).toList(); + List optionList = baseMapper.selectBatchIds(idList); + Map optionMap = optionList.stream() + .collect(Collectors.toMap(OptionDO::getCode, Function.identity(), (existing, replacement) -> existing)); + for (OptionReq req : options) { + OptionDO option = optionMap.get(req.getCode()); + ValidationUtils.throwIfNull(option, "参数 [{}] 不存在", req.getCode()); + if (StrUtil.isNotBlank(option.getDefaultValue())) { + ValidationUtils.throwIfBlank(req.getValue(), "参数 [{}] 的值不能为空", option.getName()); + } + } + // 校验密码策略参数取值范围 Map passwordPolicyOptionMap = options.stream() .filter(option -> StrUtil.startWith(option .getCode(), PasswordPolicyEnum.CATEGORY + StringConstants.UNDERLINE)) .collect(Collectors.toMap(OptionReq::getCode, OptionReq::getValue, (oldVal, newVal) -> oldVal)); - // 校验密码策略参数取值范围 for (Map.Entry passwordPolicyOptionEntry : passwordPolicyOptionMap.entrySet()) { String code = passwordPolicyOptionEntry.getKey(); String value = passwordPolicyOptionEntry.getValue(); @@ -95,13 +107,13 @@ public class OptionServiceImpl implements OptionService { String category = req.getCategory(); List codeList = req.getCode(); ValidationUtils.throwIf(StrUtil.isBlank(category) && CollUtil.isEmpty(codeList), "键列表不能为空"); - LambdaUpdateChainWrapper chainWrapper = baseMapper.lambdaUpdate().set(OptionDO::getValue, null); + LambdaUpdateChainWrapper updateWrapper = baseMapper.lambdaUpdate().set(OptionDO::getValue, null); if (StrUtil.isNotBlank(category)) { - chainWrapper.eq(OptionDO::getCategory, category); + updateWrapper.eq(OptionDO::getCategory, category); } else { - chainWrapper.in(OptionDO::getCode, req.getCode()); + updateWrapper.in(OptionDO::getCode, req.getCode()); } - chainWrapper.update(); + updateWrapper.update(); } @Override diff --git a/continew-admin-webapi/src/main/resources/db/changelog/mysql/continew-admin_data.sql b/continew-admin-webapi/src/main/resources/db/changelog/mysql/continew-admin_data.sql index 12c7ad94..a8fe21c2 100644 --- a/continew-admin-webapi/src/main/resources/db/changelog/mysql/continew-admin_data.sql +++ b/continew-admin-webapi/src/main/resources/db/changelog/mysql/continew-admin_data.sql @@ -198,4 +198,7 @@ UPDATE `sys_menu` SET `parent_id` = 4010 WHERE `id` = 4015; INSERT INTO `sys_menu` (`id`, `title`, `parent_id`, `type`, `path`, `name`, `component`, `redirect`, `icon`, `is_external`, `is_cache`, `is_hidden`, `permission`, `sort`, `status`, `create_user`, `create_time`, `update_user`, `update_time`) VALUES -(1017, '导入', 1010, 3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'system:user:import', 7, 1, 1, NOW(), NULL, NULL); \ No newline at end of file +(1017, '导入', 1010, 3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'system:user:import', 7, 1, 1, NOW(), NULL, NULL); + +-- changeset Charles7c:3.4-1 +UPDATE `sys_option` SET `default_value` = NULL WHERE `code` = 'SITE_BEIAN'; \ No newline at end of file