fix: 参数配置支持设值为空

This commit is contained in:
2024-09-24 00:23:44 +08:00
parent 302f21867a
commit d7e8fc9bc3
3 changed files with 21 additions and 7 deletions

View File

@@ -57,6 +57,5 @@ public class OptionReq extends BaseReq {
* 值
*/
@Schema(description = "", example = "ContiNew Admin")
@NotBlank(message = "值不能为空")
private String value;
}

View File

@@ -73,11 +73,23 @@ public class OptionServiceImpl implements OptionService {
@Override
public void update(List<OptionReq> options) {
// 非空校验
List<Long> idList = options.stream().map(OptionReq::getId).toList();
List<OptionDO> optionList = baseMapper.selectBatchIds(idList);
Map<String, OptionDO> 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<String, String> 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<String, String> 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<String> codeList = req.getCode();
ValidationUtils.throwIf(StrUtil.isBlank(category) && CollUtil.isEmpty(codeList), "键列表不能为空");
LambdaUpdateChainWrapper<OptionDO> chainWrapper = baseMapper.lambdaUpdate().set(OptionDO::getValue, null);
LambdaUpdateChainWrapper<OptionDO> 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

View File

@@ -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);
(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';