|
@@ -1,424 +1,37 @@
|
|
|
package com.qmth.paper.library.common.service.impl;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import com.qmth.boot.core.solar.model.AppInfo;
|
|
|
-import com.qmth.boot.core.solar.model.OrgInfo;
|
|
|
-import com.qmth.boot.core.solar.service.SolarService;
|
|
|
-import com.qmth.paper.library.common.bean.auth.AuthBean;
|
|
|
-import com.qmth.paper.library.common.bean.dto.AuthOrgInfoDto;
|
|
|
-import com.qmth.paper.library.common.bean.result.MenuResult;
|
|
|
import com.qmth.paper.library.common.contant.SystemConstant;
|
|
|
-import com.qmth.paper.library.common.entity.*;
|
|
|
-import com.qmth.paper.library.common.enums.PrivilegePropertyEnum;
|
|
|
-import com.qmth.paper.library.common.service.*;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
+import com.qmth.paper.library.common.entity.TBSession;
|
|
|
+import com.qmth.paper.library.common.service.CommonCacheService;
|
|
|
+import com.qmth.paper.library.common.service.TBSessionService;
|
|
|
import org.springframework.cache.annotation.CacheEvict;
|
|
|
import org.springframework.cache.annotation.CachePut;
|
|
|
import org.springframework.cache.annotation.Cacheable;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
-import java.util.Set;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
-
|
|
|
- * @Description: 缓存操作serviceImpl 实现类
|
|
|
- * @Param:
|
|
|
- * @return:
|
|
|
- * @Author: wangliang
|
|
|
- * @Date: 2021/3/25
|
|
|
- */
|
|
|
@Service
|
|
|
public class CommonCacheServiceImpl implements CommonCacheService {
|
|
|
- private final static Logger log = LoggerFactory.getLogger(CommonCacheServiceImpl.class);
|
|
|
|
|
|
@Resource
|
|
|
- SysUserService sysUserService;
|
|
|
+ TBSessionService tbSessionService;
|
|
|
|
|
|
- @Resource
|
|
|
- BasicSchoolService basicSchoolService;
|
|
|
-
|
|
|
- @Resource
|
|
|
- LibraryCommonService commonService;
|
|
|
-
|
|
|
- @Resource
|
|
|
- SysOrgService sysOrgService;
|
|
|
-
|
|
|
- @Resource
|
|
|
- SysRoleService sysRoleService;
|
|
|
-
|
|
|
- @Resource
|
|
|
- SolarService solarService;
|
|
|
-
|
|
|
- @Resource
|
|
|
- SysConfigService sysConfigService;
|
|
|
-
|
|
|
-
|
|
|
- * 添加角色缓存
|
|
|
- *
|
|
|
- * @param roleId
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- @Cacheable(value = SystemConstant.ROLE_CACHE, key = "#p0", unless = "#result == null")
|
|
|
- public SysRole roleCache(Long roleId) {
|
|
|
- return sysRoleService.getById(roleId);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * 修改角色缓存
|
|
|
- *
|
|
|
- * @param roleId
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- @CachePut(value = SystemConstant.ROLE_CACHE, key = "#p0", condition = "#result != null")
|
|
|
- public SysRole updateRoleCache(Long roleId) {
|
|
|
- return sysRoleService.getById(roleId);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * 删除角色缓存
|
|
|
- *
|
|
|
- * @param roleId
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- @CacheEvict(value = SystemConstant.ROLE_CACHE, key = "#p0")
|
|
|
- public void removeRoleCache(Long roleId) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * 添加用户菜单缓存
|
|
|
- *
|
|
|
- * @param userId
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- @Cacheable(value = SystemConstant.USER_MENU_CACHE, key = "#p0", unless = "#result == null")
|
|
|
- public MenuResult userMenuCache(Long userId) {
|
|
|
- return commonService.getUserMenu(userId);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * 修改用户菜单缓存
|
|
|
- *
|
|
|
- * @param userId
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- @CachePut(value = SystemConstant.USER_MENU_CACHE, key = "#p0", condition = "#result != null")
|
|
|
- public MenuResult updateUserMenuCache(Long userId) {
|
|
|
- return commonService.getUserMenu(userId);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * 删除用户菜单缓存
|
|
|
- *
|
|
|
- * @param userId
|
|
|
- */
|
|
|
- @Override
|
|
|
- @CacheEvict(value = SystemConstant.USER_MENU_CACHE, key = "#p0")
|
|
|
- public void removeUserMenuCache(Long userId) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * 添加用户缓存
|
|
|
- *
|
|
|
- * @param userId
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- @Cacheable(value = SystemConstant.USER_ACCOUNT_CACHE, key = "#p0", unless = "#result == null")
|
|
|
- public SysUser userCache(Long userId) {
|
|
|
- return sysUserService.getById(userId);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * 修改用户缓存
|
|
|
- *
|
|
|
- * @param userId
|
|
|
- * @return
|
|
|
- */
|
|
|
@Override
|
|
|
- @CachePut(value = SystemConstant.USER_ACCOUNT_CACHE, key = "#p0", condition = "#result != null")
|
|
|
- public SysUser updateUserCache(Long userId) {
|
|
|
- return sysUserService.getById(userId);
|
|
|
+ @CachePut(value = SystemConstant.CACHE_NAME, key = "'tbSession' + #sessionId")
|
|
|
+ public TBSession saveTbSession(String sessionId, TBSession tbSession) {
|
|
|
+ return tbSession;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- * 删除用户缓存
|
|
|
- *
|
|
|
- * @param userId
|
|
|
- */
|
|
|
@Override
|
|
|
- @CacheEvict(value = SystemConstant.USER_ACCOUNT_CACHE, key = "#p0")
|
|
|
- public void removeUserCache(Long userId) {
|
|
|
-
|
|
|
+ @Cacheable(value = SystemConstant.CACHE_NAME, key = "'tbSession' + #sessionId")
|
|
|
+ public TBSession getTbSession(String sessionId) {
|
|
|
+ return tbSessionService.getById(sessionId);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- * 添加用户鉴权缓存
|
|
|
- *
|
|
|
- * @param userId
|
|
|
- * @return
|
|
|
- */
|
|
|
@Override
|
|
|
- @Cacheable(value = SystemConstant.USER_OAUTH_CACHE, key = "#p0", unless = "#result == null")
|
|
|
- public AuthBean userAuthCache(Long userId) {
|
|
|
- return commonService.getUserAuth(userId);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * 修改用户鉴权缓存
|
|
|
- *
|
|
|
- * @param userId
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- @CachePut(value = SystemConstant.USER_OAUTH_CACHE, key = "#p0", condition = "#result != null")
|
|
|
- public AuthBean updateUserAuthCache(Long userId) {
|
|
|
- return commonService.getUserAuth(userId);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * 删除用户鉴权缓存
|
|
|
- *
|
|
|
- * @param userId
|
|
|
- */
|
|
|
- @Override
|
|
|
- @CacheEvict(value = SystemConstant.USER_OAUTH_CACHE, key = "#p0")
|
|
|
- public void removeUserAuthCache(Long userId) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * 添加学校缓存
|
|
|
- *
|
|
|
- * @param schoolId
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- @Cacheable(value = SystemConstant.SCHOOL_CACHE, key = "#p0", unless = "#result == null")
|
|
|
- public BasicSchool schoolCache(Long schoolId) {
|
|
|
- return basicSchoolService.getById(schoolId);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * 添加学校缓存
|
|
|
- *
|
|
|
- * @param code
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- @Cacheable(value = SystemConstant.SCHOOL_CODE_CACHE, key = "#p0", unless = "#result == null")
|
|
|
- public BasicSchool schoolCache(String code) {
|
|
|
- QueryWrapper<BasicSchool> basicSchoolQueryWrapper = new QueryWrapper<>();
|
|
|
- basicSchoolQueryWrapper.lambda().eq(BasicSchool::getCode, code);
|
|
|
- return basicSchoolService.getOne(basicSchoolQueryWrapper);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * 删除学校缓存
|
|
|
- */
|
|
|
- @Override
|
|
|
- @CacheEvict(value = SystemConstant.SCHOOL_CACHE, allEntries = true)
|
|
|
- public void removeSchoolIdCache() {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * 删除学校缓存
|
|
|
- */
|
|
|
- @Override
|
|
|
- @CacheEvict(value = SystemConstant.SCHOOL_CODE_CACHE, allEntries = true)
|
|
|
- public void removeSchoolCodeCache() {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * 添加机构缓存
|
|
|
- *
|
|
|
- * @param orgId
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- @Cacheable(value = SystemConstant.ORG_CACHE, key = "#p0", unless = "#result == null")
|
|
|
- public SysOrg orgCache(Long orgId) {
|
|
|
- return sysOrgService.getById(orgId);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- * 删除机构缓存
|
|
|
- */
|
|
|
- @Override
|
|
|
- @CacheEvict(value = SystemConstant.ORG_CACHE, allEntries = true)
|
|
|
- public void removeOrgCache() {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * 获取鉴权url
|
|
|
- *
|
|
|
- * @param privilegePropertyEnum
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- @Cacheable(value = SystemConstant.PRIVILEGE_URL_CACHE, key = "#p0", unless = "#result == null")
|
|
|
- public Set<String> privilegeUrlCache(PrivilegePropertyEnum privilegePropertyEnum) {
|
|
|
- return commonService.getPrivilegeUrl(privilegePropertyEnum);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- @Cacheable(value = SystemConstant.PRIVILEGE_URL_CACHE, key = "#p0 + '-' + #p1", unless = "#result == null")
|
|
|
- public Set<String> privilegeUrlCache(PrivilegePropertyEnum privilegePropertyEnum, Long schoolId) {
|
|
|
- return commonService.getPrivilegeUrl(privilegePropertyEnum, schoolId);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * 获取角色权限缓存
|
|
|
- *
|
|
|
- * @param roleId
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- @Cacheable(value = SystemConstant.ROLE_PRIVILEGE_CACHE, key = "#p0", unless = "#result == null")
|
|
|
- public List<SysRolePrivilege> rolePrivilegeCache(Long roleId) {
|
|
|
- return commonService.getRolePrivilege(roleId);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * 修改角色权限缓存
|
|
|
- *
|
|
|
- * @param roleId
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- @CachePut(value = SystemConstant.ROLE_PRIVILEGE_CACHE, key = "#p0", condition = "#result != null")
|
|
|
- public List<SysRolePrivilege> updateRolePrivilegeCache(Long roleId) {
|
|
|
- return commonService.getRolePrivilege(roleId);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * 删除角色权限缓存
|
|
|
- *
|
|
|
- * @param roleId
|
|
|
- */
|
|
|
- @Override
|
|
|
- @CacheEvict(value = SystemConstant.ROLE_PRIVILEGE_CACHE, key = "#p0")
|
|
|
- public void removeRolePrivilegeCache(Long roleId) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * 添加用户角色权限缓存
|
|
|
- *
|
|
|
- * @param userId
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- @Cacheable(value = SystemConstant.USER_ROLE_PRIVILEGE_CACHE, key = "#p0", unless = "#result == null")
|
|
|
- public List<SysUserRole> userRolePrivilegeCache(Long userId) {
|
|
|
- return commonService.getUserRolePrivilege(userId);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * 删除用户角色权限缓存
|
|
|
- *
|
|
|
- * @param userId
|
|
|
- */
|
|
|
- @Override
|
|
|
- @CacheEvict(value = SystemConstant.USER_ROLE_PRIVILEGE_CACHE, key = "#p0")
|
|
|
- public void removeUserRolePrivilegeCache(Long userId) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- @Cacheable(value = SystemConstant.AUTH_INFO_CACHE, key = "#p0", unless = "#result == null")
|
|
|
- public AuthOrgInfoDto authInfoCache(String code) {
|
|
|
- AppInfo appInfo = solarService.getAppInfo();
|
|
|
- AuthOrgInfoDto authOrgInfoDto = null;
|
|
|
- if (Objects.nonNull(appInfo)) {
|
|
|
- List<OrgInfo> orgInfoList = solarService.getOrgList().stream().filter(s -> Objects.equals(s.getCode(), code)).collect(Collectors.toList());
|
|
|
- if (Objects.nonNull(orgInfoList) && orgInfoList.size() > 0) {
|
|
|
- authOrgInfoDto = new AuthOrgInfoDto(orgInfoList.get(0), appInfo.getControl());
|
|
|
- }
|
|
|
- }
|
|
|
- return authOrgInfoDto;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- @CachePut(value = SystemConstant.AUTH_INFO_CACHE, key = "#p0", condition = "#result != null")
|
|
|
- public AuthOrgInfoDto updateAuthInfoCache(String code) {
|
|
|
- AppInfo appInfo = solarService.getAppInfo();
|
|
|
- AuthOrgInfoDto authOrgInfoDto = null;
|
|
|
- if (Objects.nonNull(appInfo)) {
|
|
|
- List<OrgInfo> orgInfoList = solarService.getOrgList().stream().filter(s -> Objects.equals(s.getCode(), code)).collect(Collectors.toList());
|
|
|
- if (Objects.nonNull(orgInfoList) && orgInfoList.size() > 0) {
|
|
|
- authOrgInfoDto = new AuthOrgInfoDto(orgInfoList.get(0), appInfo.getControl());
|
|
|
- }
|
|
|
- }
|
|
|
- return authOrgInfoDto;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- @CacheEvict(value = SystemConstant.AUTH_INFO_CACHE, key = "#p0")
|
|
|
- public void removeAuthInfoCache(String code) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * 添加系统参数缓存
|
|
|
- *
|
|
|
- * @param key
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- @Cacheable(value = SystemConstant.SYS_CONFIG_CACHE, key = "#p0", unless = "#result == null")
|
|
|
- public SysConfig addSysConfigCache(String key) {
|
|
|
- return sysConfigService.getOne(new QueryWrapper<SysConfig>().lambda().eq(SysConfig::getConfigKey, key));
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * 添加系统参数缓存
|
|
|
- *
|
|
|
- * @param schoolId
|
|
|
- * @param key
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- @Cacheable(value = SystemConstant.SYS_CONFIG_CACHE, key = "#p0 + '-' + #p1", unless = "#result == null")
|
|
|
- public SysConfig addSysConfigCache(Long schoolId, String key) {
|
|
|
- return sysConfigService.getOne(new QueryWrapper<SysConfig>().lambda().eq(SysConfig::getSchoolId, schoolId).eq(SysConfig::getConfigKey, key));
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * 删除系统参数缓存
|
|
|
- *
|
|
|
- * @param schoolId
|
|
|
- * @param key
|
|
|
- */
|
|
|
- @Override
|
|
|
- @CacheEvict(value = SystemConstant.SYS_CONFIG_CACHE, key = "#p0 + '-' + #p1")
|
|
|
- public void removeSysConfigCache(Long schoolId, String key) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- @CachePut(value = SystemConstant.ORG_COLLEGE_LEVEL_CACHE, key = "#p0", condition = "#result != null")
|
|
|
- public List<SysOrg> updateOrgCollegeLevelCache(Long schoolId) {
|
|
|
- return sysOrgService.findCollegeLevelOrgList(schoolId);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- @CacheEvict(value = SystemConstant.ORG_COLLEGE_LEVEL_CACHE, key = "#p0")
|
|
|
- public void removeOrgCollegeLevelCache(Long schoolId) {
|
|
|
-
|
|
|
+ @CacheEvict(value = SystemConstant.CACHE_NAME, key = "'tbSession' + #sessionId")
|
|
|
+ public String removeTbSession(String sessionId) {
|
|
|
+ return null;
|
|
|
}
|
|
|
}
|