mirror of https://gitee.com/stylefeng/roses
【8.0】【org】更新org的缓存更新操作
parent
0dc628ad36
commit
5983c18767
|
@ -42,4 +42,14 @@ public interface OrgConstants {
|
||||||
*/
|
*/
|
||||||
String ADD_ORG_EVENT = "ADD_ORG_EVENT";
|
String ADD_ORG_EVENT = "ADD_ORG_EVENT";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改组织机构的事件监听
|
||||||
|
*/
|
||||||
|
String EDIT_ORG_EVENT = "EDIT_ORG_EVENT";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除组织机构的事件监听
|
||||||
|
*/
|
||||||
|
String DELETE_ORG_EVENT = "DELETE_ORG_EVENT";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import cn.stylefeng.roses.kernel.sys.modular.org.entity.HrOrganization;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加组织机构的事件监听器
|
* 添加组织机构的事件监听器
|
||||||
|
@ -22,21 +23,53 @@ public class OrgOperateListener {
|
||||||
private CacheOperatorApi<Boolean> sysOrgSubFlagCache;
|
private CacheOperatorApi<Boolean> sysOrgSubFlagCache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 监听新增组织机构,删除相关的缓存
|
* 监听添加组织机构
|
||||||
|
* <p>
|
||||||
|
* 清空组织机构下级标识
|
||||||
*
|
*
|
||||||
* @author fengshuonan
|
* @author fengshuonan
|
||||||
* @since 2023/7/14 16:22
|
* @since 2023/7/14 18:38
|
||||||
*/
|
*/
|
||||||
@BusinessListener(businessCode = OrgConstants.ADD_ORG_EVENT)
|
@BusinessListener(businessCode = OrgConstants.ADD_ORG_EVENT)
|
||||||
public void addOrgCallback(HrOrganization businessObject) {
|
public void addOrgCallback(HrOrganization businessObject) {
|
||||||
|
|
||||||
if (ObjectUtil.isNotEmpty(businessObject.getOrgId())) {
|
if (ObjectUtil.isNotEmpty(businessObject.getOrgId())) {
|
||||||
sysOrgSubFlagCache.remove(String.valueOf(businessObject.getOrgId()));
|
sysOrgSubFlagCache.remove(String.valueOf(businessObject.getOrgId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ObjectUtil.isNotEmpty(businessObject.getOrgParentId())) {
|
if (ObjectUtil.isNotEmpty(businessObject.getOrgParentId())) {
|
||||||
sysOrgSubFlagCache.remove(String.valueOf(businessObject.getOrgParentId()));
|
sysOrgSubFlagCache.remove(String.valueOf(businessObject.getOrgParentId()));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 监听编辑组织机构
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @since 2023/7/14 18:40
|
||||||
|
*/
|
||||||
|
@BusinessListener(businessCode = OrgConstants.EDIT_ORG_EVENT)
|
||||||
|
public void editOrgCallback(HrOrganization businessObject) {
|
||||||
|
if (ObjectUtil.isNotEmpty(businessObject.getOrgId())) {
|
||||||
|
sysOrgSubFlagCache.remove(String.valueOf(businessObject.getOrgId()));
|
||||||
|
}
|
||||||
|
if (ObjectUtil.isNotEmpty(businessObject.getOrgParentId())) {
|
||||||
|
sysOrgSubFlagCache.remove(String.valueOf(businessObject.getOrgParentId()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 监听删除组织机构的事件
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @since 2023/7/14 18:40
|
||||||
|
*/
|
||||||
|
@BusinessListener(businessCode = OrgConstants.DELETE_ORG_EVENT)
|
||||||
|
public void deleteOrgCallback() {
|
||||||
|
|
||||||
|
// 获取所有主键
|
||||||
|
Collection<String> allKeys = sysOrgSubFlagCache.getAllKeys();
|
||||||
|
|
||||||
|
// 删除所有子集标识
|
||||||
|
sysOrgSubFlagCache.remove(allKeys);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,6 +93,9 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
|
||||||
|
|
||||||
// 执行删除操作
|
// 执行删除操作
|
||||||
this.baseDelete(totalOrgIdSet);
|
this.baseDelete(totalOrgIdSet);
|
||||||
|
|
||||||
|
// 发布删除机构的事件
|
||||||
|
BusinessEventPublisher.publishEvent(OrgConstants.DELETE_ORG_EVENT, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -110,6 +113,9 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
|
||||||
|
|
||||||
// 执行删除操作
|
// 执行删除操作
|
||||||
this.baseDelete(orgIdList);
|
this.baseDelete(orgIdList);
|
||||||
|
|
||||||
|
// 发布删除机构的事件
|
||||||
|
BusinessEventPublisher.publishEvent(OrgConstants.DELETE_ORG_EVENT, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -121,6 +127,10 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
|
||||||
OrganizationFactory.fillParentIds(hrOrganization);
|
OrganizationFactory.fillParentIds(hrOrganization);
|
||||||
|
|
||||||
this.updateById(hrOrganization);
|
this.updateById(hrOrganization);
|
||||||
|
|
||||||
|
// 发布编辑机构事件
|
||||||
|
BusinessEventPublisher.publishEvent(OrgConstants.EDIT_ORG_EVENT, hrOrganization);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -422,10 +432,12 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
|
||||||
|
|
||||||
// 查询结果加到缓存中
|
// 查询结果加到缓存中
|
||||||
if (hrOrganizationList.size() > 0) {
|
if (hrOrganizationList.size() > 0) {
|
||||||
sysOrgSubFlagCache.put(orgId.toString(), true);
|
// 过期时间3600秒
|
||||||
|
sysOrgSubFlagCache.put(orgId.toString(), true, 3600L);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
sysOrgSubFlagCache.put(orgId.toString(), false);
|
// 过期时间3600秒
|
||||||
|
sysOrgSubFlagCache.put(orgId.toString(), false, 3600L);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,8 @@ public class OrgMemoryCacheAutoConfiguration {
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public CacheOperatorApi<Boolean> sysOrgSubFlagCache() {
|
public CacheOperatorApi<Boolean> sysOrgSubFlagCache() {
|
||||||
TimedCache<String, Boolean> themeCache = CacheUtil.newTimedCache(Long.MAX_VALUE);
|
// 1小时过期
|
||||||
|
TimedCache<String, Boolean> themeCache = CacheUtil.newTimedCache(1000 * 3600);
|
||||||
return new SysOrgSubFlagMemoryCache(themeCache);
|
return new SysOrgSubFlagMemoryCache(themeCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue