mirror of https://gitee.com/stylefeng/roses
【8.3.3】【org】【cache】更新组织机构缓存的超时时间和删除缓存
parent
e558e3963b
commit
2a6c414bdd
|
@ -1,33 +0,0 @@
|
|||
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());
|
||||
}
|
||||
|
||||
}
|
|
@ -3,12 +3,14 @@ package cn.stylefeng.roses.kernel.sys.modular.org.cache.subflag.clear;
|
|||
import cn.hutool.core.util.ObjectUtil;
|
||||
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 cn.stylefeng.roses.kernel.sys.modular.org.entity.HrOrganization;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 监听组织机构相关的事件,从而进行清空子级标识,保障缓存同步
|
||||
|
@ -22,6 +24,9 @@ public class OrgSubFlagClearListener {
|
|||
@Resource(name = "sysOrgSubFlagCache")
|
||||
private CacheOperatorApi<Boolean> sysOrgSubFlagCache;
|
||||
|
||||
@Resource(name = "sysOrgInfoCache")
|
||||
private CacheOperatorApi<HrOrganizationDTO> sysOrgInfoCache;
|
||||
|
||||
/**
|
||||
* 监听添加组织机构
|
||||
* <p>
|
||||
|
@ -47,12 +52,15 @@ public class OrgSubFlagClearListener {
|
|||
* @since 2023/7/14 18:40
|
||||
*/
|
||||
@BusinessListener(businessCode = OrgConstants.EDIT_ORG_EVENT)
|
||||
public void editOrgCallback() {
|
||||
public void editOrgCallback(Long orgId) {
|
||||
// 获取所有主键
|
||||
Collection<String> allKeys = sysOrgSubFlagCache.getAllKeys();
|
||||
|
||||
// 删除所有子集标识
|
||||
sysOrgSubFlagCache.remove(allKeys);
|
||||
|
||||
// 删除组织机构详情的缓存
|
||||
sysOrgInfoCache.remove(orgId.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -62,7 +70,7 @@ public class OrgSubFlagClearListener {
|
|||
* @since 2023/7/14 18:40
|
||||
*/
|
||||
@BusinessListener(businessCode = OrgConstants.DELETE_ORG_EVENT)
|
||||
public void deleteOrgCallback() {
|
||||
public void deleteOrgCallback(Set<Long> orgIdList) {
|
||||
|
||||
// 获取所有主键
|
||||
Collection<String> allKeys = sysOrgSubFlagCache.getAllKeys();
|
||||
|
@ -70,6 +78,10 @@ public class OrgSubFlagClearListener {
|
|||
// 删除所有子集标识
|
||||
sysOrgSubFlagCache.remove(allKeys);
|
||||
|
||||
// 删除组织机构详情的缓存
|
||||
// 机构id列表转化为String列表
|
||||
Collection<String> orgIdListStr = orgIdList.stream().map(String::valueOf).toList();
|
||||
sysOrgInfoCache.remove(orgIdListStr);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -64,9 +64,4 @@ public interface OrgConstants {
|
|||
*/
|
||||
String ORG_INFO_CACHE_PREFIX = "SYS:ORG:INFO:";
|
||||
|
||||
/**
|
||||
* 更新组织机构详情的事件
|
||||
*/
|
||||
String UPDATE_ORG_INFO_EVENT = "UPDATE_ORG_INFO_EVENT";
|
||||
|
||||
}
|
||||
|
|
|
@ -114,7 +114,7 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
|
|||
this.baseDelete(totalOrgIdSet);
|
||||
|
||||
// 发布删除机构的事件
|
||||
BusinessEventPublisher.publishEvent(OrgConstants.DELETE_ORG_EVENT, null);
|
||||
BusinessEventPublisher.publishEvent(OrgConstants.DELETE_ORG_EVENT, totalOrgIdSet);
|
||||
|
||||
// 记录日志
|
||||
BusinessLogUtil.setLogTitle("删除机构,机构ID:" + hrOrganizationRequest.getOrgId());
|
||||
|
@ -138,7 +138,7 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
|
|||
this.baseDelete(orgIdList);
|
||||
|
||||
// 发布删除机构的事件
|
||||
BusinessEventPublisher.publishEvent(OrgConstants.DELETE_ORG_EVENT, null);
|
||||
BusinessEventPublisher.publishEvent(OrgConstants.DELETE_ORG_EVENT, orgIdList);
|
||||
|
||||
// 记录日志
|
||||
BusinessLogUtil.setLogTitle("批量删除机构");
|
||||
|
@ -160,8 +160,7 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
|
|||
this.updateById(hrOrganization);
|
||||
|
||||
// 发布编辑机构事件
|
||||
BusinessEventPublisher.publishEvent(OrgConstants.EDIT_ORG_EVENT, null);
|
||||
BusinessEventPublisher.publishEvent(OrgConstants.UPDATE_ORG_INFO_EVENT, hrOrganization.getOrgId());
|
||||
BusinessEventPublisher.publishEvent(OrgConstants.EDIT_ORG_EVENT, hrOrganization.getOrgId());
|
||||
|
||||
// 记录日志
|
||||
BusinessLogUtil.addContent("更新后的机构信息为:\n", hrOrganization);
|
||||
|
@ -392,13 +391,13 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
|
|||
HrOrganization hrOrganization = this.getOne(hrOrganizationLambdaQueryWrapper, false);
|
||||
|
||||
if (ObjectUtil.isEmpty(hrOrganization)) {
|
||||
sysOrgInfoCache.put(String.valueOf(orgId), new HrOrganizationDTO());
|
||||
sysOrgInfoCache.put(String.valueOf(orgId), new HrOrganizationDTO(), SysConstants.DEFAULT_SYS_CACHE_TIMEOUT_SECONDS);
|
||||
return new HrOrganizationDTO();
|
||||
}
|
||||
|
||||
hrOrganizationDTO = new HrOrganizationDTO();
|
||||
BeanUtil.copyProperties(hrOrganization, hrOrganizationDTO);
|
||||
sysOrgInfoCache.put(String.valueOf(orgId), hrOrganizationDTO);
|
||||
sysOrgInfoCache.put(String.valueOf(orgId), hrOrganizationDTO, SysConstants.DEFAULT_SYS_CACHE_TIMEOUT_SECONDS);
|
||||
|
||||
return hrOrganizationDTO;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue