refactor: 代码优化
This commit is contained in:
@@ -1,8 +1,5 @@
|
|||||||
package com.youlai.system.config;
|
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.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||||
@@ -13,22 +10,21 @@ import org.springframework.data.redis.serializer.RedisSerializer;
|
|||||||
* Redis 配置
|
* Redis 配置
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@AutoConfigureBefore({RedisAutoConfiguration.class, RedissonAutoConfiguration.class})
|
|
||||||
public class RedisConfig {
|
public class RedisConfig {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RedisTemplate 序列化配置
|
* RedisTemplate 自定义序列化配置
|
||||||
* <p>
|
* <p>
|
||||||
* 默认 JdkSerializationRedisSerializer,修改为 JSON 序列化
|
* 默认 JdkSerializationRedisSerializer,修改为 JSON 序列化
|
||||||
*
|
*
|
||||||
* @param lettuceConnectionFactory
|
* @param redisConnectionFactory
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory lettuceConnectionFactory) {
|
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
|
||||||
|
|
||||||
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
|
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
|
||||||
redisTemplate.setConnectionFactory(lettuceConnectionFactory);
|
redisTemplate.setConnectionFactory(redisConnectionFactory);
|
||||||
|
|
||||||
redisTemplate.setKeySerializer(RedisSerializer.string());
|
redisTemplate.setKeySerializer(RedisSerializer.string());
|
||||||
redisTemplate.setValueSerializer(RedisSerializer.json());
|
redisTemplate.setValueSerializer(RedisSerializer.json());
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ public class SysUserController {
|
|||||||
|
|
||||||
@Operation(summary = "新增用户", security = {@SecurityRequirement(name = "Authorization")})
|
@Operation(summary = "新增用户", security = {@SecurityRequirement(name = "Authorization")})
|
||||||
@PostMapping
|
@PostMapping
|
||||||
@PreAuthorize("@pms.hasPermission('sys:user:add')")
|
@PreAuthorize("@ss.hasPerm('sys:user:add')")
|
||||||
@Resubmit
|
@Resubmit
|
||||||
public Result saveUser(
|
public Result saveUser(
|
||||||
@RequestBody @Valid UserForm userForm
|
@RequestBody @Valid UserForm userForm
|
||||||
@@ -84,7 +84,7 @@ public class SysUserController {
|
|||||||
|
|
||||||
@Operation(summary = "修改用户", security = {@SecurityRequirement(name = "Authorization")})
|
@Operation(summary = "修改用户", security = {@SecurityRequirement(name = "Authorization")})
|
||||||
@PutMapping(value = "/{userId}")
|
@PutMapping(value = "/{userId}")
|
||||||
@PreAuthorize("@pms.hasPermission('sys:user:edit')")
|
@PreAuthorize("@ss.hasPerm('sys:user:edit')")
|
||||||
public Result updateUser(
|
public Result updateUser(
|
||||||
@Parameter(description = "用户ID") @PathVariable Long userId,
|
@Parameter(description = "用户ID") @PathVariable Long userId,
|
||||||
@RequestBody @Validated UserForm userForm) {
|
@RequestBody @Validated UserForm userForm) {
|
||||||
@@ -94,7 +94,7 @@ public class SysUserController {
|
|||||||
|
|
||||||
@Operation(summary = "删除用户", security = {@SecurityRequirement(name = "Authorization")})
|
@Operation(summary = "删除用户", security = {@SecurityRequirement(name = "Authorization")})
|
||||||
@DeleteMapping("/{ids}")
|
@DeleteMapping("/{ids}")
|
||||||
@PreAuthorize("@pms.hasPermission('sys:user:delete')")
|
@PreAuthorize("@ss.hasPerm('sys:user:delete')")
|
||||||
public Result deleteUsers(
|
public Result deleteUsers(
|
||||||
@Parameter(description = "用户ID,多个以英文逗号(,)分割") @PathVariable String ids
|
@Parameter(description = "用户ID,多个以英文逗号(,)分割") @PathVariable String ids
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -11,12 +11,12 @@ import org.springframework.util.PatternMatchUtils;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 权限校验
|
* SpringSecurity权限校验
|
||||||
*
|
*
|
||||||
* @author haoxr
|
* @author haoxr
|
||||||
* @date 2022/2/22
|
* @date 2022/2/22
|
||||||
*/
|
*/
|
||||||
@Service("pms")
|
@Service("ss")
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class PermissionService {
|
public class PermissionService {
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ public class PermissionService {
|
|||||||
* @param perm 权限标识(eg: sys:user:add)
|
* @param perm 权限标识(eg: sys:user:add)
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public boolean hasPermission(String perm) {
|
public boolean hasPerm(String perm) {
|
||||||
|
|
||||||
if (StrUtil.isBlank(perm)) {
|
if (StrUtil.isBlank(perm)) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public class UserForm {
|
|||||||
@NotBlank(message = "昵称不能为空")
|
@NotBlank(message = "昵称不能为空")
|
||||||
private String nickname;
|
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;
|
private String mobile;
|
||||||
|
|
||||||
@Schema(description="性别")
|
@Schema(description="性别")
|
||||||
|
|||||||
@@ -11,17 +11,20 @@ spring:
|
|||||||
data:
|
data:
|
||||||
redis:
|
redis:
|
||||||
database: 6
|
database: 6
|
||||||
host: www.youlai.tech
|
host: 47.117.115.107
|
||||||
port: 6379
|
port: 6379
|
||||||
password: 123456
|
password: 123456
|
||||||
timeout: 10s
|
timeout: 10s
|
||||||
lettuce:
|
lettuce:
|
||||||
pool:
|
pool:
|
||||||
min-idle: 0
|
# 连接池最大连接数 默认8 ,负数表示没有限制
|
||||||
max-idle: 8
|
|
||||||
max-active: 8
|
max-active: 8
|
||||||
max-wait: -1ms
|
# 连接池最大阻塞等待时间(使用负值表示没有限制) 默认-1
|
||||||
|
max-wait: -1
|
||||||
|
# 连接池中的最大空闲连接 默认8
|
||||||
|
max-idle: 8
|
||||||
|
# 连接池中的最小空闲连接 默认0
|
||||||
|
min-idle: 0
|
||||||
mybatis-plus:
|
mybatis-plus:
|
||||||
global-config:
|
global-config:
|
||||||
db-config:
|
db-config:
|
||||||
|
|||||||
@@ -11,16 +11,20 @@ spring:
|
|||||||
data:
|
data:
|
||||||
redis:
|
redis:
|
||||||
database: 6
|
database: 6
|
||||||
host: www.youlai.tech
|
host: 47.117.115.107
|
||||||
port: 6379
|
port: 6379
|
||||||
password: 123456
|
password: 123456
|
||||||
timeout: 10s
|
timeout: 10s
|
||||||
lettuce:
|
lettuce:
|
||||||
pool:
|
pool:
|
||||||
min-idle: 0
|
# 连接池最大连接数 默认8 ,负数表示没有限制
|
||||||
max-idle: 8
|
|
||||||
max-active: 8
|
max-active: 8
|
||||||
max-wait: -1ms
|
# 连接池最大阻塞等待时间(使用负值表示没有限制) 默认-1
|
||||||
|
max-wait: -1
|
||||||
|
# 连接池中的最大空闲连接 默认8
|
||||||
|
max-idle: 8
|
||||||
|
# 连接池中的最小空闲连接 默认0
|
||||||
|
min-idle: 0
|
||||||
|
|
||||||
mybatis-plus:
|
mybatis-plus:
|
||||||
global-config:
|
global-config:
|
||||||
|
|||||||
Reference in New Issue
Block a user