feat: 修改模块名称
This commit is contained in:
59
qing-yu-club-auth/qing-yu-club-auth-domain/pom.xml
Normal file
59
qing-yu-club-auth/qing-yu-club-auth-domain/pom.xml
Normal file
@@ -0,0 +1,59 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.landaiqing</groupId>
|
||||
<artifactId>qing-yu-club-auth</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>qing-yu-club-auth-domain</artifactId>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>qing-yu-club-auth-domain</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.landaiqing</groupId>
|
||||
<artifactId>qing-yu-club-auth-infra</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.landaiqing</groupId>
|
||||
<artifactId>qing-yu-club-auth-common</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-core</artifactId>
|
||||
<version>2.12.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.12.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.8.6</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@@ -0,0 +1,13 @@
|
||||
package com.landaiqing.auth.domain.constants;
|
||||
|
||||
/**
|
||||
* auth服务常量
|
||||
*
|
||||
* @author: landaiqing
|
||||
* @date: 2024/2/19
|
||||
*/
|
||||
public class AuthConstant {
|
||||
|
||||
public static final String NORMAL_USER = "normal_user";
|
||||
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
package com.landaiqing.auth.domain.convert;
|
||||
|
||||
import com.landaiqing.auth.domain.entity.AuthPermissionBO;
|
||||
import com.landaiqing.auth.infra.basic.entity.AuthPermission;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
* 权限bo转换器
|
||||
*
|
||||
* @author: landaiqing
|
||||
* @date: 2024/2/19
|
||||
*/
|
||||
@Mapper
|
||||
public interface AuthPermissionBOConverter {
|
||||
|
||||
AuthPermissionBOConverter INSTANCE = Mappers.getMapper(AuthPermissionBOConverter.class);
|
||||
|
||||
AuthPermission convertBOToEntity(AuthPermissionBO authPermissionBO);
|
||||
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
package com.landaiqing.auth.domain.convert;
|
||||
|
||||
import com.landaiqing.auth.domain.entity.AuthRoleBO;
|
||||
import com.landaiqing.auth.infra.basic.entity.AuthRole;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
* 角色bo转换器
|
||||
*
|
||||
* @author: landaiqing
|
||||
* @date: 2024/2/19
|
||||
*/
|
||||
@Mapper
|
||||
public interface AuthRoleBOConverter {
|
||||
|
||||
AuthRoleBOConverter INSTANCE = Mappers.getMapper(AuthRoleBOConverter.class);
|
||||
|
||||
AuthRole convertBOToEntity(AuthRoleBO authRoleBO);
|
||||
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
package com.landaiqing.auth.domain.convert;
|
||||
|
||||
import com.landaiqing.auth.domain.entity.AuthUserBO;
|
||||
import com.landaiqing.auth.infra.basic.entity.AuthUser;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
* 用户bo转换器
|
||||
*
|
||||
* @author: landaiqing
|
||||
* @date: 2024/2/19
|
||||
*/
|
||||
@Mapper
|
||||
public interface AuthUserBOConverter {
|
||||
|
||||
AuthUserBOConverter INSTANCE = Mappers.getMapper(AuthUserBOConverter.class);
|
||||
|
||||
AuthUser convertBOToEntity(AuthUserBO authUserBO);
|
||||
|
||||
AuthUserBO convertEntityToBO(AuthUser authUser);
|
||||
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
package com.landaiqing.auth.domain.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 权限dto
|
||||
*
|
||||
* @author: landaiqing
|
||||
* @date: 2024/2/19
|
||||
*/
|
||||
@Data
|
||||
public class AuthPermissionBO implements Serializable {
|
||||
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
private Long parentId;
|
||||
|
||||
private Integer type;
|
||||
|
||||
private String menuUrl;
|
||||
|
||||
private Integer status;
|
||||
|
||||
private Integer show;
|
||||
|
||||
private String icon;
|
||||
|
||||
private String permissionKey;
|
||||
}
|
||||
|
@@ -0,0 +1,22 @@
|
||||
package com.landaiqing.auth.domain.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 角色bo
|
||||
*
|
||||
* @author: landaiqing
|
||||
*/
|
||||
@Data
|
||||
public class AuthRoleBO implements Serializable {
|
||||
|
||||
private Long id;
|
||||
|
||||
private String roleName;
|
||||
|
||||
private String roleKey;
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,25 @@
|
||||
package com.landaiqing.auth.domain.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* (AuthRolePermission)实体类
|
||||
*
|
||||
* @author landaiqing
|
||||
*/
|
||||
@Data
|
||||
public class AuthRolePermissionBO implements Serializable {
|
||||
private static final long serialVersionUID = 459343371709166261L;
|
||||
|
||||
private Long id;
|
||||
|
||||
private Long roleId;
|
||||
|
||||
private Long permissionId;
|
||||
|
||||
private List<Long> permissionIdList;
|
||||
}
|
||||
|
@@ -0,0 +1,38 @@
|
||||
package com.landaiqing.auth.domain.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 用戶信息dto
|
||||
*
|
||||
* @author: landaiqing
|
||||
*/
|
||||
@Data
|
||||
public class AuthUserBO implements Serializable {
|
||||
|
||||
private Long id;
|
||||
|
||||
private String userName;
|
||||
|
||||
private String nickName;
|
||||
|
||||
private String email;
|
||||
|
||||
private String phone;
|
||||
|
||||
private String password;
|
||||
|
||||
private Integer sex;
|
||||
|
||||
private String avatar;
|
||||
|
||||
private Integer status;
|
||||
|
||||
private String introduce;
|
||||
|
||||
private String extJson;
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,46 @@
|
||||
package com.landaiqing.auth.domain.redis;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
/**
|
||||
* Redis的config处理
|
||||
*
|
||||
* @author: landaiqing
|
||||
*/
|
||||
@Configuration
|
||||
public class RedisConfig {
|
||||
|
||||
@Bean
|
||||
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
|
||||
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
|
||||
RedisSerializer<String> redisSerializer = new StringRedisSerializer();
|
||||
redisTemplate.setConnectionFactory(redisConnectionFactory);
|
||||
redisTemplate.setKeySerializer(redisSerializer);
|
||||
redisTemplate.setHashKeySerializer(redisSerializer);
|
||||
redisTemplate.setValueSerializer(jackson2JsonRedisSerializer());
|
||||
redisTemplate.setHashValueSerializer(jackson2JsonRedisSerializer());
|
||||
return redisTemplate;
|
||||
}
|
||||
|
||||
private Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer() {
|
||||
Jackson2JsonRedisSerializer<Object> jsonRedisSerializer = new Jackson2JsonRedisSerializer<>(Object.class);
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
|
||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
|
||||
jsonRedisSerializer.setObjectMapper(objectMapper);
|
||||
return jsonRedisSerializer;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,107 @@
|
||||
package com.landaiqing.auth.domain.redis;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* RedisUtil工具类
|
||||
*
|
||||
* @author: landaiqing
|
||||
* @date: 2024/2/19
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class RedisUtil {
|
||||
|
||||
@Resource
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
private static final String CACHE_KEY_SEPARATOR = ".";
|
||||
|
||||
/**
|
||||
* 构建缓存key
|
||||
*/
|
||||
public String buildKey(String... strObjs) {
|
||||
return Stream.of(strObjs).collect(Collectors.joining(CACHE_KEY_SEPARATOR));
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否存在key
|
||||
*/
|
||||
public boolean exist(String key) {
|
||||
return redisTemplate.hasKey(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除key
|
||||
*/
|
||||
public boolean del(String key) {
|
||||
return redisTemplate.delete(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* set(不带过期)
|
||||
*/
|
||||
public void set(String key, String value) {
|
||||
redisTemplate.opsForValue().set(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* set(带过期)
|
||||
*/
|
||||
public boolean setNx(String key, String value, Long time, TimeUnit timeUnit) {
|
||||
return redisTemplate.opsForValue().setIfAbsent(key, value, time, timeUnit);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取string类型缓存
|
||||
*/
|
||||
public String get(String key) {
|
||||
return (String) redisTemplate.opsForValue().get(key);
|
||||
}
|
||||
|
||||
public Boolean zAdd(String key, String value, Long score) {
|
||||
return redisTemplate.opsForZSet().add(key, value, Double.valueOf(String.valueOf(score)));
|
||||
}
|
||||
|
||||
public Long countZset(String key) {
|
||||
return redisTemplate.opsForZSet().size(key);
|
||||
}
|
||||
|
||||
public Set<String> rangeZset(String key, long start, long end) {
|
||||
return redisTemplate.opsForZSet().range(key, start, end);
|
||||
}
|
||||
|
||||
public Long removeZset(String key, Object value) {
|
||||
return redisTemplate.opsForZSet().remove(key, value);
|
||||
}
|
||||
|
||||
public void removeZsetList(String key, Set<String> value) {
|
||||
value.stream().forEach((val) -> redisTemplate.opsForZSet().remove(key, val));
|
||||
}
|
||||
|
||||
public Double score(String key, Object value) {
|
||||
return redisTemplate.opsForZSet().score(key, value);
|
||||
}
|
||||
|
||||
public Set<String> rangeByScore(String key, long start, long end) {
|
||||
return redisTemplate.opsForZSet().rangeByScore(key, Double.valueOf(String.valueOf(start)), Double.valueOf(String.valueOf(end)));
|
||||
}
|
||||
|
||||
public Object addScore(String key, Object obj, double score) {
|
||||
return redisTemplate.opsForZSet().incrementScore(key, obj, score);
|
||||
}
|
||||
|
||||
public Object rank(String key, Object obj) {
|
||||
return redisTemplate.opsForZSet().rank(key, obj);
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
package com.landaiqing.auth.domain.service;
|
||||
|
||||
import com.landaiqing.auth.domain.entity.AuthPermissionBO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 权限领域service
|
||||
*
|
||||
* @author: landaiqing
|
||||
* @date: 2024/2/19
|
||||
*/
|
||||
public interface AuthPermissionDomainService {
|
||||
|
||||
Boolean add(AuthPermissionBO authPermissionBO);
|
||||
|
||||
Boolean update(AuthPermissionBO authPermissionBO);
|
||||
|
||||
Boolean delete(AuthPermissionBO authPermissionBO);
|
||||
|
||||
List<String> getPermission(String userName);
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
package com.landaiqing.auth.domain.service;
|
||||
|
||||
|
||||
import com.landaiqing.auth.domain.entity.AuthRoleBO;
|
||||
|
||||
/**
|
||||
* 角色领域service
|
||||
*
|
||||
* @author: landaiqing
|
||||
* @date: 2024/2/19
|
||||
*/
|
||||
public interface AuthRoleDomainService {
|
||||
|
||||
/**
|
||||
* 注册
|
||||
*/
|
||||
Boolean add(AuthRoleBO authRoleBO);
|
||||
|
||||
Boolean update(AuthRoleBO authRoleBO);
|
||||
|
||||
Boolean delete(AuthRoleBO authRoleBO);
|
||||
}
|
||||
|
@@ -0,0 +1,14 @@
|
||||
package com.landaiqing.auth.domain.service;
|
||||
|
||||
import com.landaiqing.auth.domain.entity.AuthRolePermissionBO;
|
||||
|
||||
/**
|
||||
* 角色领域service
|
||||
*
|
||||
* @author: landaiqing
|
||||
*/
|
||||
public interface AuthRolePermissionDomainService {
|
||||
|
||||
Boolean add(AuthRolePermissionBO authRolePermissionBO);
|
||||
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
package com.landaiqing.auth.domain.service;
|
||||
|
||||
|
||||
import com.landaiqing.auth.domain.entity.AuthUserBO;
|
||||
|
||||
/**
|
||||
* 用户领域service
|
||||
*
|
||||
* @author: landaiqing
|
||||
* @date: 2024/2/19
|
||||
*/
|
||||
public interface AuthUserDomainService {
|
||||
|
||||
/**
|
||||
* 注册
|
||||
*/
|
||||
Boolean register(AuthUserBO authUserBO);
|
||||
|
||||
/**
|
||||
* 更新用户信息
|
||||
*/
|
||||
Object update(AuthUserBO authUserBO);
|
||||
|
||||
Object delete(AuthUserBO authUserBO);
|
||||
}
|
||||
|
@@ -0,0 +1,71 @@
|
||||
package com.landaiqing.auth.domain.service.impl;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.landaiqing.auth.common.enums.IsDeletedFlagEnum;
|
||||
import com.landaiqing.auth.domain.convert.AuthPermissionBOConverter;
|
||||
import com.landaiqing.auth.domain.entity.AuthPermissionBO;
|
||||
import com.landaiqing.auth.domain.redis.RedisUtil;
|
||||
import com.landaiqing.auth.domain.service.AuthPermissionDomainService;
|
||||
import com.landaiqing.auth.infra.basic.entity.AuthPermission;
|
||||
import com.landaiqing.auth.infra.basic.service.AuthPermissionService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class AuthPermissionDomainServiceImpl implements AuthPermissionDomainService {
|
||||
|
||||
@Resource
|
||||
private AuthPermissionService authPermissionService;
|
||||
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
private String authPermissionPrefix = "auth.permission";
|
||||
|
||||
@Override
|
||||
public Boolean add(AuthPermissionBO authPermissionBO) {
|
||||
AuthPermission authPermission = AuthPermissionBOConverter.INSTANCE.convertBOToEntity(authPermissionBO);
|
||||
authPermission.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
|
||||
Integer count = authPermissionService.insert(authPermission);
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean update(AuthPermissionBO authPermissionBO) {
|
||||
AuthPermission authPermission = AuthPermissionBOConverter.INSTANCE.convertBOToEntity(authPermissionBO);
|
||||
Integer count = authPermissionService.update(authPermission);
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean delete(AuthPermissionBO authPermissionBO) {
|
||||
AuthPermission authPermission = new AuthPermission();
|
||||
authPermission.setId(authPermissionBO.getId());
|
||||
authPermission.setIsDeleted(IsDeletedFlagEnum.DELETED.getCode());
|
||||
Integer count = authPermissionService.update(authPermission);
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getPermission(String userName) {
|
||||
String permissionKey = redisUtil.buildKey(authPermissionPrefix, userName);
|
||||
String permissionValue = redisUtil.get(permissionKey);
|
||||
if (StringUtils.isBlank(permissionValue)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<AuthPermission> permissionList = new Gson().fromJson(permissionValue,
|
||||
new TypeToken<List<AuthPermission>>() {
|
||||
}.getType());
|
||||
List<String> authList = permissionList.stream().map(AuthPermission::getPermissionKey).collect(Collectors.toList());
|
||||
return authList;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
package com.landaiqing.auth.domain.service.impl;
|
||||
|
||||
import com.landaiqing.auth.common.enums.IsDeletedFlagEnum;
|
||||
import com.landaiqing.auth.domain.convert.AuthRoleBOConverter;
|
||||
import com.landaiqing.auth.domain.entity.AuthRoleBO;
|
||||
import com.landaiqing.auth.domain.service.AuthRoleDomainService;
|
||||
import com.landaiqing.auth.infra.basic.entity.AuthRole;
|
||||
import com.landaiqing.auth.infra.basic.service.AuthRoleService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class AuthRoleDomainServiceImpl implements AuthRoleDomainService {
|
||||
|
||||
@Resource
|
||||
private AuthRoleService authRoleService;
|
||||
|
||||
@Override
|
||||
public Boolean add(AuthRoleBO authRoleBO) {
|
||||
AuthRole authRole = AuthRoleBOConverter.INSTANCE.convertBOToEntity(authRoleBO);
|
||||
authRole.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
|
||||
Integer count = authRoleService.insert(authRole);
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean update(AuthRoleBO authRoleBO) {
|
||||
AuthRole authRole = AuthRoleBOConverter.INSTANCE.convertBOToEntity(authRoleBO);
|
||||
int count = authRoleService.update(authRole);
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean delete(AuthRoleBO authRoleBO) {
|
||||
AuthRole authRole = new AuthRole();
|
||||
authRole.setId(authRoleBO.getId());
|
||||
authRole.setIsDeleted(IsDeletedFlagEnum.DELETED.getCode());
|
||||
int count = authRoleService.update(authRole);
|
||||
return count > 0;
|
||||
}
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
package com.landaiqing.auth.domain.service.impl;
|
||||
|
||||
import com.landaiqing.auth.common.enums.IsDeletedFlagEnum;
|
||||
import com.landaiqing.auth.domain.entity.AuthRolePermissionBO;
|
||||
import com.landaiqing.auth.domain.service.AuthRolePermissionDomainService;
|
||||
import com.landaiqing.auth.infra.basic.entity.AuthRolePermission;
|
||||
import com.landaiqing.auth.infra.basic.service.AuthRolePermissionService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class AuthRolePermissionDomainServiceImpl implements AuthRolePermissionDomainService {
|
||||
|
||||
@Resource
|
||||
private AuthRolePermissionService authRolePermissionService;
|
||||
|
||||
@Override
|
||||
public Boolean add(AuthRolePermissionBO authRolePermissionBO) {
|
||||
List<AuthRolePermission> rolePermissionList = new LinkedList<>();
|
||||
Long roleId = authRolePermissionBO.getRoleId();
|
||||
authRolePermissionBO.getPermissionIdList().forEach(permissionId -> {
|
||||
AuthRolePermission authRolePermission = new AuthRolePermission();
|
||||
authRolePermission.setRoleId(roleId);
|
||||
authRolePermission.setPermissionId(permissionId);
|
||||
authRolePermission.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
|
||||
rolePermissionList.add(authRolePermission);
|
||||
});
|
||||
int count = authRolePermissionService.batchInsert(rolePermissionList);
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,106 @@
|
||||
package com.landaiqing.auth.domain.service.impl;
|
||||
|
||||
import cn.dev33.satoken.secure.SaSecureUtil;
|
||||
import com.google.gson.Gson;
|
||||
import com.landaiqing.auth.common.enums.AuthUserStatusEnum;
|
||||
import com.landaiqing.auth.common.enums.IsDeletedFlagEnum;
|
||||
import com.landaiqing.auth.domain.constants.AuthConstant;
|
||||
import com.landaiqing.auth.domain.convert.AuthUserBOConverter;
|
||||
import com.landaiqing.auth.domain.entity.AuthUserBO;
|
||||
import com.landaiqing.auth.domain.redis.RedisUtil;
|
||||
import com.landaiqing.auth.domain.service.AuthUserDomainService;
|
||||
import com.landaiqing.auth.infra.basic.entity.*;
|
||||
import com.landaiqing.auth.infra.basic.service.*;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class AuthUserDomainServiceImpl implements AuthUserDomainService {
|
||||
|
||||
@Resource
|
||||
private AuthUserService authUserService;
|
||||
|
||||
@Resource
|
||||
private AuthUserRoleService authUserRoleService;
|
||||
|
||||
@Resource
|
||||
private AuthRoleService authRoleService;
|
||||
|
||||
@Resource
|
||||
private AuthPermissionService authPermissionService;
|
||||
|
||||
@Resource
|
||||
private AuthRolePermissionService authRolePermissionService;
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
private String authPermissionPrefix = "auth.permission";
|
||||
|
||||
private String authRolePrefix = "auth.role";
|
||||
|
||||
private String salt="landaiqing";
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean register(AuthUserBO authUserBO) {
|
||||
AuthUser authUser = AuthUserBOConverter.INSTANCE.convertBOToEntity(authUserBO);
|
||||
authUser.setPassword(SaSecureUtil.md5BySalt(authUser.getPassword(),salt));
|
||||
authUser.setStatus(AuthUserStatusEnum.OPEN.getCode());
|
||||
authUser.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
|
||||
Integer count = authUserService.insert(authUser);
|
||||
|
||||
// 用户和角色关联
|
||||
AuthRole authRole=new AuthRole();
|
||||
authRole.setRoleKey(AuthConstant.NORMAL_USER);
|
||||
AuthRole roleResult = authRoleService.queryByCondition(authRole);
|
||||
Long roleId = roleResult.getId();
|
||||
Long userId = authUser.getId();
|
||||
AuthUserRole authUserRole=new AuthUserRole();
|
||||
authUserRole.setUserId(userId);
|
||||
authUserRole.setRoleId(roleId);
|
||||
authUserRole.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
|
||||
authUserRoleService.insert(authUserRole);
|
||||
|
||||
String roleKey = redisUtil.buildKey(authRolePrefix, authUser.getUserName());
|
||||
List<AuthRole> roleList = new LinkedList<>();
|
||||
roleList.add(authRole);
|
||||
redisUtil.set(roleKey, new Gson().toJson(roleList));
|
||||
|
||||
AuthRolePermission authRolePermission = new AuthRolePermission();
|
||||
authRolePermission.setRoleId(roleId);
|
||||
List<AuthRolePermission> rolePermissionList = authRolePermissionService.
|
||||
queryByCondition(authRolePermission);
|
||||
|
||||
List<Long> permissionIdList = rolePermissionList.stream()
|
||||
.map(AuthRolePermission::getPermissionId).collect(Collectors.toList());
|
||||
//根据roleId查权限
|
||||
List<AuthPermission> permissionList = authPermissionService.queryByRoleList(permissionIdList);
|
||||
String permissionKey = redisUtil.buildKey(authPermissionPrefix, authUser.getUserName());
|
||||
redisUtil.set(permissionKey, new Gson().toJson(permissionList));
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object update(AuthUserBO authUserBO) {
|
||||
AuthUser authUser = AuthUserBOConverter.INSTANCE.convertBOToEntity(authUserBO);
|
||||
Integer count = authUserService.update(authUser);
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object delete(AuthUserBO authUserBO) {
|
||||
AuthUser authUser = new AuthUser();
|
||||
authUser.setId(authUserBO.getId());
|
||||
authUser.setIsDeleted(IsDeletedFlagEnum.DELETED.getCode());
|
||||
Integer count = authUserService.update(authUser);
|
||||
return count > 0;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user