refactor: 代码优化
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
package com.youlai.system.config;
|
||||
|
||||
import org.redisson.spring.starter.RedissonAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
@@ -13,22 +10,21 @@ import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
* Redis 配置
|
||||
*/
|
||||
@Configuration
|
||||
@AutoConfigureBefore({RedisAutoConfiguration.class, RedissonAutoConfiguration.class})
|
||||
public class RedisConfig {
|
||||
|
||||
/**
|
||||
* RedisTemplate 序列化配置
|
||||
* RedisTemplate 自定义序列化配置
|
||||
* <p>
|
||||
* 默认 JdkSerializationRedisSerializer,修改为 JSON 序列化
|
||||
*
|
||||
* @param lettuceConnectionFactory
|
||||
* @param redisConnectionFactory
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory lettuceConnectionFactory) {
|
||||
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
|
||||
|
||||
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
|
||||
redisTemplate.setConnectionFactory(lettuceConnectionFactory);
|
||||
redisTemplate.setConnectionFactory(redisConnectionFactory);
|
||||
|
||||
redisTemplate.setKeySerializer(RedisSerializer.string());
|
||||
redisTemplate.setValueSerializer(RedisSerializer.json());
|
||||
|
||||
@@ -64,7 +64,7 @@ public class SysUserController {
|
||||
|
||||
@Operation(summary = "新增用户", security = {@SecurityRequirement(name = "Authorization")})
|
||||
@PostMapping
|
||||
@PreAuthorize("@pms.hasPermission('sys:user:add')")
|
||||
@PreAuthorize("@ss.hasPerm('sys:user:add')")
|
||||
@Resubmit
|
||||
public Result saveUser(
|
||||
@RequestBody @Valid UserForm userForm
|
||||
@@ -84,7 +84,7 @@ public class SysUserController {
|
||||
|
||||
@Operation(summary = "修改用户", security = {@SecurityRequirement(name = "Authorization")})
|
||||
@PutMapping(value = "/{userId}")
|
||||
@PreAuthorize("@pms.hasPermission('sys:user:edit')")
|
||||
@PreAuthorize("@ss.hasPerm('sys:user:edit')")
|
||||
public Result updateUser(
|
||||
@Parameter(description = "用户ID") @PathVariable Long userId,
|
||||
@RequestBody @Validated UserForm userForm) {
|
||||
@@ -94,7 +94,7 @@ public class SysUserController {
|
||||
|
||||
@Operation(summary = "删除用户", security = {@SecurityRequirement(name = "Authorization")})
|
||||
@DeleteMapping("/{ids}")
|
||||
@PreAuthorize("@pms.hasPermission('sys:user:delete')")
|
||||
@PreAuthorize("@ss.hasPerm('sys:user:delete')")
|
||||
public Result deleteUsers(
|
||||
@Parameter(description = "用户ID,多个以英文逗号(,)分割") @PathVariable String ids
|
||||
) {
|
||||
|
||||
@@ -11,12 +11,12 @@ import org.springframework.util.PatternMatchUtils;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 权限校验
|
||||
* SpringSecurity权限校验
|
||||
*
|
||||
* @author haoxr
|
||||
* @date 2022/2/22
|
||||
*/
|
||||
@Service("pms")
|
||||
@Service("ss")
|
||||
@RequiredArgsConstructor
|
||||
public class PermissionService {
|
||||
|
||||
@@ -28,7 +28,7 @@ public class PermissionService {
|
||||
* @param perm 权限标识(eg: sys:user:add)
|
||||
* @return
|
||||
*/
|
||||
public boolean hasPermission(String perm) {
|
||||
public boolean hasPerm(String perm) {
|
||||
|
||||
if (StrUtil.isBlank(perm)) {
|
||||
return false;
|
||||
|
||||
@@ -29,7 +29,7 @@ public class UserForm {
|
||||
@NotBlank(message = "昵称不能为空")
|
||||
private String nickname;
|
||||
|
||||
@Pattern(regexp = "^1(3\\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\\d|9[0-35-9])\\d{8}$", message = "{phone.valid}")
|
||||
@Pattern(regexp = "^1(3\\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\\d|9[0-35-9])\\d{8}$", message = "手机号码格式不正确")
|
||||
private String mobile;
|
||||
|
||||
@Schema(description="性别")
|
||||
|
||||
Reference in New Issue
Block a user