fix:用户权限功能增加缓存

This commit is contained in:
lulz1 2024-05-17 16:29:50 +08:00
parent 8e1dba066e
commit 546766349b
24 changed files with 406 additions and 49 deletions

View File

@ -1,13 +1,15 @@
package com.chint.application.dtos.system;
import com.chint.domain.value_object.BaseQuery;
import lombok.Data;
import java.util.List;
@Data
public class RoleOrgParam {
public class RoleOrgParam extends BaseQuery {
private Long roleId;
private String roleName;
private String roleCode;
private String roleDesc;
private Long userId;
private List<Long> orgIdList;

View File

@ -341,7 +341,7 @@ public class OrderDetailQuery {
changedTicketNo = changedTicketNo.replace("-", "");
orderDetailDto.setChangedTicketNo(changedTicketNo);
}
return routeRepository.queryById(orderDetail.getRouteId());
return orderDetailDto;
}
return null;
}

View File

@ -10,7 +10,11 @@ import com.chint.domain.aggregates.user.UserDepartmentInfo;
import com.chint.domain.repository.RoleRepository;
import com.chint.domain.repository.RoleUserRepository;
import com.chint.domain.repository.UserRepository;
import com.chint.domain.service.SystemDomainService;
import com.chint.domain.value_object.system.RoleOrganizationVO;
import com.chint.domain.value_object.system.RoleVO;
import com.chint.infrastructure.util.BaseContext;
import com.chint.infrastructure.util.PageResult;
import com.chint.infrastructure.util.Result;
import com.chint.interfaces.rest.data_center.user.BatchUserWorker;
import com.chint.interfaces.rest.data_center.user.UserHttpRequest;
@ -19,6 +23,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Optional;
import static com.chint.infrastructure.constant.CommonMessageConstant.SUCCESS;
@ -41,6 +46,9 @@ public class UserController {
@Autowired
private RoleRepository roleRepository;
@Autowired
private SystemDomainService systemDomainService;
@ApiOperation("根据Id查询用户信息")
@PostMapping("/query")
public Result<UserRes> getUserByEmployeeNo() {
@ -48,6 +56,34 @@ public class UserController {
return Result.Success(SUCCESS, BeanUtil.copyProperties(currentUser, UserRes.class));
}
@ApiOperation("分页查看角色数据")
@PostMapping("/query/role")
public Result<PageResult<RoleVO>> queryRole(@RequestBody RoleOrgParam roleOrgParam) {
PageResult<Role> rolePageResult = roleRepository.pageQuery(roleOrgParam);
List<Role> roleList = rolePageResult.getRecords();
List<RoleVO> roleVOS = roleList
.stream()
.map(Role::mapToVO)
.toList();
return Result.Success(SUCCESS, PageResult.totalPageNum(rolePageResult.getTotal(), roleVOS));
}
@ApiOperation("查看角色数据详情")
@PostMapping("/query/role/detail")
public Result<RoleVO> queryRoleDetail(@RequestBody RoleOrgParam roleOrgParam) {
RoleVO res = roleRepository.findById(roleOrgParam.getRoleId())
.flatMap(role -> {
RoleVO roleVO = role.mapToVO();
List<RoleOrganizationVO> roleOrganizationVOList = systemDomainService.roleOrgWrapper(
role.getRoleOrganizationList()
);
roleVO.setRoleOrganizationVOList(roleOrganizationVOList);
return Optional.of(roleVO);
})
.orElse(null);
return Result.Success(SUCCESS, res);
}
@ApiOperation("根据用户ID添加角色权限")
@PostMapping("/add/role")
public Result<String> addRoleUser(@RequestBody RoleOrgParam roleOrgParam) {

View File

@ -2,6 +2,7 @@ package com.chint.domain.aggregates.system;
import cn.hutool.core.bean.BeanUtil;
import com.chint.domain.value_object.system.RoleOrganizationVO;
import com.chint.domain.value_object.system.SystemOrganizationVO;
import com.chint.interfaces.rest.data_center.org.OrgSfResponse;
import lombok.Data;
@ -87,4 +88,8 @@ public class SystemOrganization implements Serializable {
public SystemOrganizationVO mapToVO() {
return BeanUtil.copyProperties(this, SystemOrganizationVO.class);
}
public RoleOrganizationVO mapToRoleOrganizationVO() {
return BeanUtil.copyProperties(this, RoleOrganizationVO.class);
}
}

View File

@ -1,22 +1,30 @@
package com.chint.domain.aggregates.user;
import cn.hutool.core.bean.BeanUtil;
import com.chint.application.dtos.system.RoleOrgParam;
import com.chint.domain.value_object.system.RoleVO;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.MappedCollection;
import org.springframework.data.relational.core.mapping.Table;
import java.io.Serial;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
@Data
@Table("role")
public class Role {
public class Role implements Serializable {
@Serial
private static final long serialVersionUID = 982691641565825656L;
@Id
private Long id;
private String roleName;
private String roleCode;
private String roleDesc;
private Integer sort;
@MappedCollection(idColumn = "role_id", keyColumn = "role_key")
private List<RoleOrganization> roleOrganizationList;
@ -33,19 +41,57 @@ public class Role {
return this;
}
public Role removeRoleOrganization(Long orgId) {
if (roleOrganizationList == null) {
roleOrganizationList = new ArrayList<>();
}
for (RoleOrganization organization : roleOrganizationList) {
if (organization.getOrgId().equals(orgId)) {
roleOrganizationList.remove(organization);
return this;
}
}
return this;
}
public Role updateWithParam(RoleOrgParam roleOrgParam) {
if (roleOrganizationList == null) {
roleOrganizationList = new ArrayList<>();
}
if (roleOrgParam.getSort() != null) {
this.setSort(roleOrgParam.getSort());
}
if (roleOrgParam.getRoleDesc() != null) {
this.setRoleDesc(roleOrgParam.getRoleDesc());
}
if (roleOrgParam.getRoleCode() != null) {
this.setRoleCode(roleOrgParam.getRoleCode());
}
roleOrgParam.getOrgIdList().stream()
.map(it -> RoleOrganization.of(roleOrgParam.getRoleId(), it))
.toList()
.forEach(this::addRoleOrganization);
List<Long> orgIds = roleOrganizationList
.stream()
.map(RoleOrganization::getOrgId)
.toList();
orgIds.stream()
.filter(it -> !roleOrgParam.getOrgIdList().contains(it))
.toList()
.forEach(this::removeRoleOrganization);
return this;
}
public RoleVO mapToVO() {
return BeanUtil.copyProperties(this, RoleVO.class);
}
public static Role buildWithParam(RoleOrgParam roleOrgParam) {
Role role = new Role();
role.setRoleName(roleOrgParam.getRoleName());
role.setRoleCode(roleOrgParam.getRoleCode());
role.setRoleDesc(roleOrgParam.getRoleDesc());
if(roleOrgParam.getRoleIdList() != null){
if (roleOrgParam.getOrgIdList() != null) {
roleOrgParam.getOrgIdList().stream()
.map(it -> RoleOrganization.of(roleOrgParam.getRoleId(), it))
.toList()
@ -53,4 +99,6 @@ public class Role {
}
return role;
}
}

View File

@ -5,9 +5,14 @@ import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.Table;
import java.io.Serial;
import java.io.Serializable;
@Data
@Table("role_organization")
public class RoleOrganization {
public class RoleOrganization implements Serializable {
@Serial
private static final long serialVersionUID = 986481563255172358L;
@Id
private Long id;
private Long roleId;

View File

@ -4,10 +4,15 @@ import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.Table;
import java.io.Serial;
import java.io.Serializable;
@Data
@Table("role_user")
public class RoleUser {
public class RoleUser implements Serializable {
@Serial
private static final long serialVersionUID = 1937591655113659058L;
@Id
private Long id;
private Long userId;

View File

@ -35,6 +35,7 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Stream;
import static com.chint.infrastructure.constant.AuthMessageConstant.SF_DATA_NOT_EXIST;
import static com.chint.infrastructure.constant.AuthMessageConstant.USER_FSSC_SYSTEM_LIST;
@ -82,6 +83,8 @@ public class User implements Serializable {
private List<String> roleOrgCodeList;
@Transient
private List<SystemOrganizationVO> roleOrgList;
@Transient
private List<Role> roleList;
public User loadInfoFromDept() {
if (this.userDepartmentInfoList == null || this.userDepartmentInfoList.isEmpty()) {
@ -123,10 +126,21 @@ public class User implements Serializable {
departmentInfo -> departmentInfo.getCompanyName().equals(finalCompanyCode) :
departmentInfo -> departmentInfo.getCompanyCode().equals(finalCompanyCode);
UserDepartmentInfo userDepartmentInfo = userDepartmentInfoList.stream()
.filter(matchCompanyCode)
List<UserDepartmentInfo> userDepartmentInfos = userDepartmentInfoList.stream()
.filter(matchCompanyCode).toList();
UserDepartmentInfo userDepartmentInfo;
if(userDepartmentInfos.isEmpty()) {
userDepartmentInfo = getFallbackDeptInfo();
} else if(userDepartmentInfos.size() == 1) {
userDepartmentInfo = userDepartmentInfos.get(0);
} else {
userDepartmentInfo = userDepartmentInfos
.stream()
.filter(UserDepartmentInfo::ifPrimary)
.findFirst()
.orElseGet(this::getFallbackDeptInfo);
}
loadInfoFromDeptInfo(userDepartmentInfo);
} else {
UserDepartmentInfo fallbackDeptInfo = getFallbackDeptInfo();

View File

@ -1,13 +1,25 @@
package com.chint.domain.repository;
import com.chint.application.dtos.system.RoleOrgParam;
import com.chint.domain.aggregates.user.Role;
import com.chint.domain.aggregates.user.User;
import com.chint.domain.value_object.system.SystemOrganizationVO;
import com.chint.infrastructure.util.PageResult;
import javax.swing.text.html.Option;
import java.util.List;
import java.util.Optional;
public interface RoleRepository {
Optional<Role> findById(Long id);
PageResult<Role> pageQuery(RoleOrgParam roleOrgParam);
Role save(Role role);
List<String> roleOrgCodeList(Long userId);
List<SystemOrganizationVO> roleOrgList(Long userId);
void loadUserRole(User user);
}

View File

@ -7,5 +7,7 @@ import java.util.List;
public interface RoleUserRepository {
List<RoleUser> findByUserId(Long userId);
List<RoleUser> findByRoleId(Long roleId);
RoleUser save(RoleUser roleUser);
}

View File

@ -23,4 +23,7 @@ public interface SystemOrganizationRepository {
List<SystemOrganization> findByParentId(Long parentId);
SystemOrganization queryChild(SystemOrganization systemOrganization);
List<SystemOrganization> expandOrganizations(List<SystemOrganization> systemOrganizations);
}

View File

@ -7,12 +7,15 @@ import com.chint.domain.aggregates.system.AccountCompany;
import com.chint.domain.aggregates.system.SystemCode;
import com.chint.domain.aggregates.system.SystemOrganization;
import com.chint.domain.aggregates.system.SystemOrganizationExtension;
import com.chint.domain.aggregates.user.Role;
import com.chint.domain.aggregates.user.RoleOrganization;
import com.chint.domain.aggregates.user.RoleUser;
import com.chint.domain.aggregates.user.User;
import com.chint.domain.exceptions.NotFoundException;
import com.chint.domain.repository.*;
import com.chint.domain.value_object.system.RoleOrganizationVO;
import com.chint.infrastructure.echo_framework.annotation.ListenTo;
import com.chint.infrastructure.repository.cache.CacheRoleRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -43,6 +46,7 @@ public class SystemDomainService {
@Autowired
private RoleRepository roleRepository;
public boolean checkSystemCode(String sysCode) {
boolean b = systemCodeRepository.findBySysCode(sysCode) != null;
if (!b) {
@ -72,7 +76,8 @@ public class SystemDomainService {
public void addOrganizationClerk(OrganizationTicketClerk organizationTicketClerk) {
systemOrganizationRepository
.findByOrgCodeContaining(organizationTicketClerk.getOrgCode())
.ifPresent(it -> loadClerk(queryChild(it), organizationTicketClerk.getClerkName()));
.ifPresent(it -> loadClerk(systemOrganizationRepository.queryChild(it),
organizationTicketClerk.getClerkName()));
}
public void addOrgExtensionField(String orgCode, String fieldName, String fieldValue, String extension) {
@ -162,41 +167,40 @@ public class SystemDomainService {
public void loadUserRole(UserRoleCommand command) {
User user = command.getUser();
List<RoleUser> byUserId = roleUserRepository.findByUserId(user.getUserId());
List<Long> orgListId = byUserId.stream().flatMap(it ->
roleRepository
List<Role> roleList = byUserId.stream().flatMap(it -> roleRepository
.findById(it.getRoleId())
.stream()
.flatMap(role -> role.getRoleOrganizationList().stream())
.map(RoleOrganization::getOrgId)
).distinct().toList();
// 获取所有的 SystemOrganization
List<SystemOrganization> rootOrganizations = systemOrganizationRepository.findByIdIn(orgListId);
// 展开所有的 SystemOrganization
List<SystemOrganization> allOrganizations = new ArrayList<>();
rootOrganizations.forEach(rootOrg -> expandOrganizations(rootOrg, allOrganizations));
// 设置用户的角色组织列表
user.setRoleOrgCodeList(
allOrganizations.stream()
.map(SystemOrganization::getOrgShortCode)
.distinct()
.toList()
);
user.setRoleOrgList(
allOrganizations.stream()
.map(SystemOrganization::mapToVO)
.distinct()
.toList()
);
.stream())
.toList();
user.setRoleList(roleList);
roleRepository.loadUserRole(user);
}
private void expandOrganizations(SystemOrganization org, List<SystemOrganization> allOrganizations) {
private void expandOrganizations( SystemOrganization org, List<SystemOrganization> allOrganizations) {
if (org == null) {
return;
}
queryChild(org); // 查询子组织
allOrganizations.add(org); // 添加当前组织到列表
for (SystemOrganization child : org.getChildOrganizationList()) {
List<SystemOrganization> childOrganizationList = org.getChildOrganizationList();
if (childOrganizationList != null && !childOrganizationList.isEmpty()) {
for (SystemOrganization child : childOrganizationList) {
expandOrganizations(child, allOrganizations); // 递归展开子组织
}
}
}
public List<RoleOrganizationVO> roleOrgWrapper(List<RoleOrganization> roleOrganizationList) {
List<Long> orgIds = roleOrganizationList.stream().map(RoleOrganization::getOrgId).toList();
List<SystemOrganization> byIdIn = systemOrganizationRepository
.findByIdIn(orgIds);
List<SystemOrganization> allOrganizations = new ArrayList<>();
for (SystemOrganization systemOrganization : byIdIn) {
expandOrganizations(systemOrganization, allOrganizations);
}
return allOrganizations
.stream()
.distinct()
.map(SystemOrganization::mapToRoleOrganizationVO)
.toList();
}
}

View File

@ -0,0 +1,12 @@
package com.chint.domain.value_object.system;
import lombok.Data;
@Data
public class RoleOrganizationVO {
private Long id;
private String orgCode;
private String orgName;
private String orgEnName;
}

View File

@ -0,0 +1,17 @@
package com.chint.domain.value_object.system;
import com.chint.domain.aggregates.user.RoleOrganization;
import lombok.Data;
import org.springframework.data.relational.core.mapping.MappedCollection;
import java.util.List;
@Data
public class RoleVO {
private Long id;
private String roleName;
private String roleCode;
private String roleDesc;
private Integer sort;
private List<RoleOrganizationVO> roleOrganizationVOList;
}

View File

@ -2,8 +2,13 @@ package com.chint.domain.value_object.system;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
@Data
public class SystemOrganizationVO {
public class SystemOrganizationVO implements Serializable {
@Serial
private static final long serialVersionUID = 7552825188541271771L;
private Long id;
private String orgCode;
private String orgShortCode;

View File

@ -9,4 +9,6 @@ public class SystemConstant {
public static final Integer H3BPM_LOGIN_TYPE = 3;
public static final String ROLE_JT_ADMIN = "JT_ADMIN";
}

View File

@ -1,12 +1,25 @@
package com.chint.infrastructure.repository;
import com.chint.application.dtos.system.RoleOrgParam;
import com.chint.domain.aggregates.system.SystemOrganization;
import com.chint.domain.aggregates.user.Role;
import com.chint.domain.aggregates.user.RoleOrganization;
import com.chint.domain.aggregates.user.RoleUser;
import com.chint.domain.aggregates.user.User;
import com.chint.domain.repository.RoleRepository;
import com.chint.domain.repository.RoleUserRepository;
import com.chint.domain.repository.SystemOrganizationRepository;
import com.chint.domain.value_object.system.SystemOrganizationVO;
import com.chint.infrastructure.repository.cache.CacheRoleRepository;
import com.chint.infrastructure.repository.jdbc.JdbcRoleRepository;
import com.chint.infrastructure.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
@Repository
@ -17,6 +30,12 @@ public class RoleRepositoryImpl implements RoleRepository {
@Autowired
private CacheRoleRepository cacheRoleRepository;
@Autowired
private RoleUserRepository roleUserRepository;
@Autowired
private SystemOrganizationRepository systemOrganizationRepository;
@Override
public Optional<Role> findById(Long id) {
if (id == null) {
@ -26,17 +45,92 @@ public class RoleRepositoryImpl implements RoleRepository {
if (fromCache.isPresent()) {
return fromCache;
} else {
return cacheRoleRepository.getFromCache(id, jdbcRoleRepository.findById(id));
Optional<Role> byId = jdbcRoleRepository.findById(id);
cacheRoleRepository.evict(id);
cacheRoleRepository.getFromCache(id, byId);
return byId;
}
}
@Override
public PageResult<Role> pageQuery(RoleOrgParam roleOrgParam) {
PageRequest pageRequest = PageRequest.of(roleOrgParam.getPageNum() - 1,
roleOrgParam.getPageSize(), Sort.by("sort"));
Page<Role> all = jdbcRoleRepository.findAll(pageRequest);
return PageResult.totalPageNum(all.getTotalElements(), all.getContent());
}
@Override
public Role save(Role role) {
Long id = role.getId();
if(id != null){
if (id != null) {
cacheRoleRepository.evict(id);
}
//当role角色调整的时候需要清除相关用户的缓存
roleUserRepository.findByRoleId(role.getId())
.stream()
.map(RoleUser::getUserId)
.forEach(userId -> {
cacheRoleRepository.evictRoleOrgCodeList(userId);
cacheRoleRepository.evictRoleOrgList(userId);
});
return jdbcRoleRepository.save(role);
}
@Override
public List<String> roleOrgCodeList(Long userId) {
return List.of();
}
@Override
public List<SystemOrganizationVO> roleOrgList(Long userId) {
return List.of();
}
@Override
public void loadUserRole(User user) {
Long userId = user.getUserId();
List<String> orgCodeList = cacheRoleRepository
.roleOrgCodeList(userId, null);
List<SystemOrganizationVO> systemOrganizationVOList = cacheRoleRepository
.roleOrgList(userId, null);
if (systemOrganizationVOList == null || systemOrganizationVOList.isEmpty() ||
orgCodeList == null || orgCodeList.isEmpty()) {
List<Role> roleList = user.getRoleList();
List<Long> orgListId = roleList
.stream()
.flatMap(role -> role.getRoleOrganizationList().stream())
.map(RoleOrganization::getOrgId)
.distinct()
.toList();
// 获取所有的 SystemOrganization
List<SystemOrganization> rootOrganizations = systemOrganizationRepository.findByIdIn(orgListId);
// 展开所有的 SystemOrganization
rootOrganizations = systemOrganizationRepository.expandOrganizations(rootOrganizations);
orgCodeList = rootOrganizations.stream()
.map(SystemOrganization::getOrgShortCode)
.distinct()
.toList();
systemOrganizationVOList = rootOrganizations.stream()
.map(SystemOrganization::mapToVO)
.distinct()
.toList();
cacheRoleRepository.evictRoleOrgCodeList(userId);
cacheRoleRepository.roleOrgCodeList(userId, orgCodeList);
cacheRoleRepository.evictRoleOrgList(userId);
cacheRoleRepository.roleOrgList(userId, systemOrganizationVOList);
}
// 设置用户的角色组织列表
user.setRoleOrgCodeList(orgCodeList);
user.setRoleOrgList(systemOrganizationVOList);
}
}

View File

@ -22,6 +22,11 @@ public class RoleUserRepositoryImpl implements RoleUserRepository {
return jdbcRoleUserRepository.findByUserId(userId);
}
@Override
public List<RoleUser> findByRoleId(Long roleId) {
return jdbcRoleUserRepository.findByRoleId(roleId);
}
@CacheEvict(value = "RoleUser", key = "#roleUser.userId")
@Override
public RoleUser save(RoleUser roleUser) {

View File

@ -9,6 +9,7 @@ import org.springframework.stereotype.Repository;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
@Repository
@ -51,7 +52,10 @@ public class SystemOrganizationRepositoryImpl implements SystemOrganizationRepos
@Override
public List<SystemOrganization> findByIdIn(List<Long> ids) {
List<SystemOrganization> fromCacheByIdIn = cacheSystemOrganizationRepository.getFromCacheByIdIn(ids);
List<Long> fromCacheOrg = fromCacheByIdIn.stream().map(SystemOrganization::getId).toList();
List<Long> fromCacheOrg = fromCacheByIdIn.stream()
.filter(Objects::nonNull)
.map(SystemOrganization::getId)
.toList();
List<Long> list = ids.stream().filter(it -> !fromCacheOrg.contains(it)).toList();
if (!list.isEmpty()) {
List<SystemOrganization> fromDBByIdIn = jdbcSystemOrganizationRepository.findByIdIn(list);
@ -99,4 +103,42 @@ public class SystemOrganizationRepositoryImpl implements SystemOrganizationRepos
}
return list;
}
@Override
public SystemOrganization queryChild(SystemOrganization systemOrganization) {
List<SystemOrganization> byParentId = findByParentId(systemOrganization.getId());
if (byParentId.isEmpty()) {
return systemOrganization;
} else {
systemOrganization.setChildOrganizationList(byParentId);
for (SystemOrganization organization : byParentId) {
queryChild(organization);
}
return systemOrganization;
}
}
@Override
public List<SystemOrganization> expandOrganizations(List<SystemOrganization> systemOrganizations) {
List<SystemOrganization> allOrganizations = new ArrayList<>();
for (SystemOrganization org : systemOrganizations) {
expandOrganizationRecursively(org, allOrganizations);
}
return allOrganizations;
}
private void expandOrganizationRecursively(SystemOrganization org,
List<SystemOrganization> allOrganizations) {
if (org == null) {
return;
}
queryChild(org); // 查询子组织
allOrganizations.add(org); // 添加当前组织到列表
List<SystemOrganization> childOrganizationList = org.getChildOrganizationList();
if (childOrganizationList != null && !childOrganizationList.isEmpty()) {
for (SystemOrganization child : childOrganizationList) {
expandOrganizationRecursively(child, allOrganizations); // 递归展开子组织
}
}
}
}

View File

@ -1,10 +1,12 @@
package com.chint.infrastructure.repository.cache;
import com.chint.domain.aggregates.user.Role;
import com.chint.domain.value_object.system.SystemOrganizationVO;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
@Repository
@ -19,4 +21,22 @@ public class CacheRoleRepository {
@CacheEvict(value = "Role", key = "#id")
public void evict(Long id) {
}
@Cacheable(value = "Role::OrgCode", key = "#userId")
public List<String> roleOrgCodeList(Long userId, List<String> roleOrgCodeList) {
return roleOrgCodeList;
}
@CacheEvict(value = "Role::OrgCode", key = "#userId")
public void evictRoleOrgCodeList(Long userId) {
}
@Cacheable(value = "Role::Org", key = "#userId")
public List<SystemOrganizationVO> roleOrgList(Long userId, List<SystemOrganizationVO> roleOrgList) {
return roleOrgList;
}
@CacheEvict(value = "Role::Org", key = "#userId")
public void evictRoleOrgList(Long userId) {
}
}

View File

@ -9,6 +9,7 @@ import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Objects;
@Repository
public class CacheSystemOrganizationRepository {
@ -18,7 +19,8 @@ public class CacheSystemOrganizationRepository {
public List<SystemOrganization> getFromCacheByIdIn(List<Long> ids) {
List<String> routeOrderKeys = ids.stream().map(id -> "SystemOrganization::" + id).toList();
return redisTemplate.opsForValue().multiGet(routeOrderKeys);
List<SystemOrganization> systemOrganizationList = redisTemplate.opsForValue().multiGet(routeOrderKeys);
return Objects.requireNonNullElseGet(systemOrganizationList, List::of);
}
@Cacheable(value = "SystemOrganization", key = "#systemOrganization.id")

View File

@ -1,10 +1,12 @@
package com.chint.infrastructure.repository.jdbc;
import com.chint.domain.aggregates.standards.Ranks;
import com.chint.domain.aggregates.user.Role;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface JdbcRoleRepository extends CrudRepository<Role, Long> {
Page<Role> findAll(Pageable pageable);
}

View File

@ -10,4 +10,8 @@ import java.util.List;
public interface JdbcRoleUserRepository extends CrudRepository<RoleUser, Long> {
List<RoleUser> findByUserId(Long userId);
List<RoleUser> findByRoleId(Long roleId);
}

View File

@ -99,6 +99,9 @@ class RouteApplicationTests {
@Autowired
private CTripAirportRequest cTripAirportRequest;
@Autowired
private UserRepository userRepository;
@Value("${FSSC.jt-baseUrl}")
private String jtFSSCUrl;
@ -1308,5 +1311,18 @@ class RouteApplicationTests {
System.out.println(rankName);
}
@Test
void roleTest(){
System.out.println(System.currentTimeMillis());
User byId = userRepository.findByUserEmployeeNo("230615020").loadRoleOrg();
System.out.println(System.currentTimeMillis());
byId.loadRoleOrg();
System.out.println(System.currentTimeMillis());
byId.loadRoleOrg();
System.out.println(System.currentTimeMillis());
byId.loadRoleOrg();
System.out.println(System.currentTimeMillis());
byId.loadRoleOrg();
System.out.println(System.currentTimeMillis());
}
}