Skip to content

Commit

Permalink
fix: 参数配置支持设值为空
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed Sep 23, 2024
1 parent 302f218 commit d7e8fc9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,5 @@ public class OptionReq extends BaseReq {
* 值
*/
@Schema(description = "值", example = "ContiNew Admin")
@NotBlank(message = "值不能为空")
private String value;
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,23 @@ public Map<String, String> getByCategory(String category) {

@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();
Expand All @@ -95,13 +107,13 @@ public void resetValue(OptionResetValueReq req) {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

0 comments on commit d7e8fc9

Please sign in to comment.