mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-12 03:00:53 +08:00
perf: 系统参数新增根据类别查询方法
This commit is contained in:
@@ -166,9 +166,9 @@ public enum PasswordPolicyEnum {
|
||||
private final String msg;
|
||||
|
||||
/**
|
||||
* 策略前缀
|
||||
* 策略类别
|
||||
*/
|
||||
public static final String PREFIX = "PASSWORD_";
|
||||
public static final String CATEGORY = "PASSWORD";
|
||||
|
||||
/**
|
||||
* 校验取值范围
|
||||
|
@@ -16,9 +16,13 @@
|
||||
|
||||
package top.continew.admin.system.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import top.continew.admin.system.model.entity.OptionDO;
|
||||
import top.continew.starter.data.mybatis.plus.base.BaseMapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 参数 Mapper
|
||||
*
|
||||
@@ -26,4 +30,13 @@ import top.continew.starter.data.mybatis.plus.base.BaseMapper;
|
||||
* @since 2023/8/26 19:38
|
||||
*/
|
||||
public interface OptionMapper extends BaseMapper<OptionDO> {
|
||||
|
||||
/**
|
||||
* 根据类别查询
|
||||
*
|
||||
* @param category 类别
|
||||
* @return 列表
|
||||
*/
|
||||
@Select("SELECT code, value, default_value FROM sys_option WHERE category = #{category}")
|
||||
List<OptionDO> selectByCategory(@Param("category") String category);
|
||||
}
|
@@ -22,6 +22,7 @@ import top.continew.admin.system.model.req.OptionResetValueReq;
|
||||
import top.continew.admin.system.model.resp.OptionResp;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
@@ -40,6 +41,14 @@ public interface OptionService {
|
||||
*/
|
||||
List<OptionResp> list(OptionQuery query);
|
||||
|
||||
/**
|
||||
* 根据类别查询
|
||||
*
|
||||
* @param category 类别
|
||||
* @return 参数信息
|
||||
*/
|
||||
Map<String, String> getByCategory(String category);
|
||||
|
||||
/**
|
||||
* 修改参数
|
||||
*
|
||||
|
@@ -19,7 +19,9 @@ 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.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alicp.jetcache.anno.Cached;
|
||||
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -56,14 +58,25 @@ public class OptionServiceImpl implements OptionService {
|
||||
private final OptionMapper baseMapper;
|
||||
|
||||
@Override
|
||||
@Cached(key = "#query.category", name = CacheConstants.OPTION_KEY_PREFIX)
|
||||
public List<OptionResp> list(OptionQuery query) {
|
||||
return BeanUtil.copyToList(baseMapper.selectList(QueryWrapperHelper.build(query)), OptionResp.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cached(key = "#category", name = CacheConstants.OPTION_KEY_PREFIX + "MAP:")
|
||||
public Map<String, String> getByCategory(String category) {
|
||||
return baseMapper.selectByCategory(category)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(OptionDO::getCode, o -> StrUtil.emptyIfNull(ObjectUtil.defaultIfNull(o
|
||||
.getValue(), o.getDefaultValue())), (oldVal, newVal) -> oldVal));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(List<OptionReq> options) {
|
||||
Map<String, String> passwordPolicyOptionMap = options.stream()
|
||||
.filter(option -> StrUtil.startWith(option.getCode(), PasswordPolicyEnum.PREFIX))
|
||||
.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()) {
|
||||
|
@@ -20,6 +20,7 @@ import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.img.ImgUtil;
|
||||
import cn.hutool.core.io.file.FileNameUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alicp.jetcache.anno.CacheInvalidate;
|
||||
@@ -333,16 +334,17 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserRes
|
||||
* @param user 用户信息
|
||||
*/
|
||||
private int checkPassword(String password, UserDO user) {
|
||||
Map<String, String> passwordPolicy = optionService.getByCategory(CATEGORY);
|
||||
// 密码最小长度
|
||||
PASSWORD_MIN_LENGTH.validate(password, optionService.getValueByCode2Int(PASSWORD_MIN_LENGTH.name()), user);
|
||||
PASSWORD_MIN_LENGTH.validate(password, MapUtil.getInt(passwordPolicy, PASSWORD_MIN_LENGTH.name()), user);
|
||||
// 密码是否必须包含特殊字符
|
||||
PASSWORD_CONTAIN_SPECIAL_CHARACTERS.validate(password, optionService
|
||||
.getValueByCode2Int(PASSWORD_CONTAIN_SPECIAL_CHARACTERS.name()), user);
|
||||
PASSWORD_CONTAIN_SPECIAL_CHARACTERS.validate(password, MapUtil
|
||||
.getInt(passwordPolicy, PASSWORD_CONTAIN_SPECIAL_CHARACTERS.name()), user);
|
||||
// 密码是否允许包含正反序账号名
|
||||
PASSWORD_ALLOW_CONTAIN_USERNAME.validate(password, optionService
|
||||
.getValueByCode2Int(PASSWORD_ALLOW_CONTAIN_USERNAME.name()), user);
|
||||
PASSWORD_ALLOW_CONTAIN_USERNAME.validate(password, MapUtil
|
||||
.getInt(passwordPolicy, PASSWORD_ALLOW_CONTAIN_USERNAME.name()), user);
|
||||
// 密码重复使用规则
|
||||
int passwordReusePolicy = optionService.getValueByCode2Int(PASSWORD_REUSE_POLICY.name());
|
||||
int passwordReusePolicy = MapUtil.getInt(passwordPolicy, PASSWORD_REUSE_POLICY.name());
|
||||
PASSWORD_REUSE_POLICY.validate(password, passwordReusePolicy, user);
|
||||
return passwordReusePolicy;
|
||||
}
|
||||
|
@@ -20,7 +20,6 @@ import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.core.util.ClassUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alicp.jetcache.anno.Cached;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||
@@ -31,7 +30,6 @@ import org.dromara.x.file.storage.core.FileInfo;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import top.continew.admin.common.constant.CacheConstants;
|
||||
import top.continew.admin.common.model.resp.LabelValueResp;
|
||||
import top.continew.admin.system.model.query.DeptQuery;
|
||||
import top.continew.admin.system.model.query.MenuQuery;
|
||||
@@ -112,7 +110,6 @@ public class CommonController {
|
||||
@SaIgnore
|
||||
@Operation(summary = "查询参数字典", description = "查询参数字典")
|
||||
@GetMapping("/dict/option")
|
||||
@Cached(key = "#query.category", name = CacheConstants.OPTION_KEY_PREFIX)
|
||||
public R<List<LabelValueResp<String>>> listOptionDict(@Validated OptionQuery query) {
|
||||
return R.ok(optionService.list(query)
|
||||
.stream()
|
||||
|
Reference in New Issue
Block a user