【8.3.3】【org】【cache】更新组织机构缓存的超时时间和删除缓存

dev-8.3.3
stylefeng 2025-01-14 15:55:37 +08:00
parent e558e3963b
commit 2a6c414bdd
4 changed files with 19 additions and 46 deletions

View File

@ -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());
}
}

View File

@ -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);
}
}

View File

@ -64,9 +64,4 @@ public interface OrgConstants {
*/
String ORG_INFO_CACHE_PREFIX = "SYS:ORG:INFO:";
/**
*
*/
String UPDATE_ORG_INFO_EVENT = "UPDATE_ORG_INFO_EVENT";
}

View File

@ -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;
}