mirror of https://gitee.com/stylefeng/roses
【8.3.3】【system】【cache】增加组织机构的缓存
parent
6afa0bf670
commit
243be73ea5
|
@ -0,0 +1,27 @@
|
|||
package cn.stylefeng.roses.kernel.sys.modular.org.cache.orginfo;
|
||||
|
||||
import cn.hutool.cache.impl.TimedCache;
|
||||
import cn.stylefeng.roses.kernel.cache.memory.AbstractMemoryCacheOperator;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.org.HrOrganizationDTO;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.org.constants.OrgConstants;
|
||||
|
||||
/**
|
||||
* 组织机构详情信息的缓存
|
||||
* <p>
|
||||
* key是组织机构id,value是组织机构详情
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2025/1/10 11:47
|
||||
*/
|
||||
public class SysOrgInfoMemoryCache extends AbstractMemoryCacheOperator<HrOrganizationDTO> {
|
||||
|
||||
public SysOrgInfoMemoryCache(TimedCache<String, HrOrganizationDTO> timedCache) {
|
||||
super(timedCache);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommonKeyPrefix() {
|
||||
return OrgConstants.ORG_INFO_CACHE_PREFIX;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package cn.stylefeng.roses.kernel.sys.modular.org.cache.orginfo;
|
||||
|
||||
import cn.stylefeng.roses.kernel.cache.redis.AbstractRedisCacheOperator;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.org.HrOrganizationDTO;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.org.constants.OrgConstants;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
|
||||
/**
|
||||
* 组织机构详情信息的缓存
|
||||
* <p>
|
||||
* key是组织机构id,value是组织机构详情
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/7/14 1:06
|
||||
*/
|
||||
public class SysOrgInfoRedisCache extends AbstractRedisCacheOperator<HrOrganizationDTO> {
|
||||
|
||||
public SysOrgInfoRedisCache(RedisTemplate<String, HrOrganizationDTO> redisTemplate) {
|
||||
super(redisTemplate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommonKeyPrefix() {
|
||||
return OrgConstants.ORG_INFO_CACHE_PREFIX;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package cn.stylefeng.roses.kernel.sys.modular.org.cache.orginfo.clear;
|
||||
|
||||
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
|
||||
import cn.stylefeng.roses.kernel.event.api.annotation.BusinessListener;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.org.HrOrganizationDTO;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.org.constants.OrgConstants;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 监听组织机构的修改,清除相关缓存
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2025/1/10 11:48
|
||||
*/
|
||||
@Service
|
||||
public class OrgInfoClearListener {
|
||||
|
||||
@Resource(name = "sysOrgInfoCache")
|
||||
private CacheOperatorApi<HrOrganizationDTO> sysOrgInfoCache;
|
||||
|
||||
/**
|
||||
* 删除组织机构详情的缓存
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2025/1/10 12:32
|
||||
*/
|
||||
@BusinessListener(businessCode = OrgConstants.UPDATE_ORG_INFO_EVENT)
|
||||
public void updateOrgCallback(Long orgId) {
|
||||
sysOrgInfoCache.remove(orgId.toString());
|
||||
}
|
||||
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
package cn.stylefeng.roses.kernel.sys.modular.org.cache;
|
|
@ -57,4 +57,16 @@ public interface OrgConstants {
|
|||
*/
|
||||
String DELETE_ORG_EVENT = "DELETE_ORG_EVENT";
|
||||
|
||||
//-------------------------------组织机构详情缓存-------------------------------
|
||||
|
||||
/**
|
||||
* 组织机构详情的缓存
|
||||
*/
|
||||
String ORG_INFO_CACHE_PREFIX = "SYS:ORG:INFO:";
|
||||
|
||||
/**
|
||||
* 更新组织机构详情的事件
|
||||
*/
|
||||
String UPDATE_ORG_INFO_EVENT = "UPDATE_ORG_INFO_EVENT";
|
||||
|
||||
}
|
||||
|
|
|
@ -79,6 +79,9 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
|
|||
@Resource(name = "sysOrgSubFlagCache")
|
||||
private CacheOperatorApi<Boolean> sysOrgSubFlagCache;
|
||||
|
||||
@Resource(name = "sysOrgInfoCache")
|
||||
private CacheOperatorApi<HrOrganizationDTO> sysOrgInfoCache;
|
||||
|
||||
@Override
|
||||
public void add(HrOrganizationRequest hrOrganizationRequest) {
|
||||
HrOrganization hrOrganization = new HrOrganization();
|
||||
|
@ -157,6 +160,7 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
|
|||
|
||||
// 发布编辑机构事件
|
||||
BusinessEventPublisher.publishEvent(OrgConstants.EDIT_ORG_EVENT, null);
|
||||
BusinessEventPublisher.publishEvent(OrgConstants.UPDATE_ORG_INFO_EVENT, hrOrganization.getOrgId());
|
||||
|
||||
// 记录日志
|
||||
BusinessLogUtil.addContent("更新后的机构信息为:\n", hrOrganization);
|
||||
|
@ -367,6 +371,15 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
|
|||
|
||||
@Override
|
||||
public HrOrganizationDTO getOrgInfo(Long orgId) {
|
||||
if (orgId == null) {
|
||||
return new HrOrganizationDTO();
|
||||
}
|
||||
|
||||
// 先从缓存中获取
|
||||
HrOrganizationDTO hrOrganizationDTO = sysOrgInfoCache.get(String.valueOf(orgId));
|
||||
if (hrOrganizationDTO != null) {
|
||||
return hrOrganizationDTO;
|
||||
}
|
||||
|
||||
// 查询组织机构对应的信息
|
||||
LambdaQueryWrapper<HrOrganization> hrOrganizationLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
|
@ -376,11 +389,14 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
|
|||
HrOrganization hrOrganization = this.getOne(hrOrganizationLambdaQueryWrapper, false);
|
||||
|
||||
if (ObjectUtil.isEmpty(hrOrganization)) {
|
||||
sysOrgInfoCache.put(String.valueOf(orgId), new HrOrganizationDTO());
|
||||
return new HrOrganizationDTO();
|
||||
}
|
||||
|
||||
HrOrganizationDTO hrOrganizationDTO = new HrOrganizationDTO();
|
||||
hrOrganizationDTO = new HrOrganizationDTO();
|
||||
BeanUtil.copyProperties(hrOrganization, hrOrganizationDTO);
|
||||
sysOrgInfoCache.put(String.valueOf(orgId), hrOrganizationDTO);
|
||||
|
||||
return hrOrganizationDTO;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,8 @@ import cn.hutool.cache.CacheUtil;
|
|||
import cn.hutool.cache.impl.TimedCache;
|
||||
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
|
||||
import cn.stylefeng.roses.kernel.sys.api.constants.SysConstants;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.org.HrOrganizationDTO;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.org.cache.orginfo.SysOrgInfoMemoryCache;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.org.cache.subflag.SysOrgSubFlagMemoryCache;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
@ -56,4 +58,17 @@ public class OrgMemoryCacheAutoConfiguration {
|
|||
return new SysOrgSubFlagMemoryCache(themeCache);
|
||||
}
|
||||
|
||||
/**
|
||||
* 组织机构详情
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2025/1/10 11:48
|
||||
*/
|
||||
@Bean
|
||||
public CacheOperatorApi<HrOrganizationDTO> sysOrgInfoCache() {
|
||||
// 1小时过期
|
||||
TimedCache<String, HrOrganizationDTO> themeCache = CacheUtil.newTimedCache(1000 * SysConstants.DEFAULT_SYS_CACHE_TIMEOUT_SECONDS);
|
||||
return new SysOrgInfoMemoryCache(themeCache);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,6 +26,8 @@ package cn.stylefeng.roses.kernel.sys.starter.cache.org;
|
|||
|
||||
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
|
||||
import cn.stylefeng.roses.kernel.cache.redis.util.CreateRedisTemplateUtil;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.org.HrOrganizationDTO;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.org.cache.orginfo.SysOrgInfoRedisCache;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.org.cache.subflag.SysOrgSubFlagRedisCache;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
@ -55,4 +57,16 @@ public class OrgRedisCacheAutoConfiguration {
|
|||
return new SysOrgSubFlagRedisCache(redisTemplate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 组织机构详情的缓存
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2025/1/10 11:49
|
||||
*/
|
||||
@Bean
|
||||
public CacheOperatorApi<HrOrganizationDTO> sysOrgInfoCache(RedisConnectionFactory redisConnectionFactory) {
|
||||
RedisTemplate<String, HrOrganizationDTO> redisTemplate = CreateRedisTemplateUtil.createObject(redisConnectionFactory);
|
||||
return new SysOrgInfoRedisCache(redisTemplate);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue