【8.0】【system】【org】组织机构是否含有下级标识增加缓存

pull/57/head
fengshuonan 2023-07-14 01:20:11 +08:00
parent ce4d93256a
commit 5e9b83d616
9 changed files with 173 additions and 20 deletions

View File

@ -151,4 +151,14 @@ public interface HrOrganizationService extends IService<HrOrganization> {
*/ */
Set<Long> queryOrgIdParentIdList(Set<Long> orgIdList); Set<Long> queryOrgIdParentIdList(Set<Long> orgIdList);
/**
*
*
* @param orgId id
* @return true-false-
* @author fengshuonan
* @since 2023/7/14 1:09
*/
Boolean getOrgHaveSubFlag(Long orgId);
} }

View File

@ -6,6 +6,7 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil; import cn.hutool.extra.spring.SpringUtil;
import cn.stylefeng.roses.kernel.auth.api.context.LoginContext; import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
import cn.stylefeng.roses.kernel.db.api.context.DbOperatorContext; import cn.stylefeng.roses.kernel.db.api.context.DbOperatorContext;
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory; import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory; import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
@ -63,6 +64,9 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
@Resource @Resource
private SysUserOrgService sysUserOrgService; private SysUserOrgService sysUserOrgService;
@Resource(name = "sysOrgSubFlagCache")
private CacheOperatorApi<Boolean> sysOrgSubFlagCache;
@Override @Override
public void add(HrOrganizationRequest hrOrganizationRequest) { public void add(HrOrganizationRequest hrOrganizationRequest) {
HrOrganization hrOrganization = new HrOrganization(); HrOrganization hrOrganization = new HrOrganization();
@ -401,6 +405,34 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
return parentIdListTotal; return parentIdListTotal;
} }
@Override
public Boolean getOrgHaveSubFlag(Long orgId) {
if (ObjectUtil.isEmpty(orgId)) {
return false;
}
Boolean cacheResult = sysOrgSubFlagCache.get(orgId.toString());
if (cacheResult != null) {
return cacheResult;
}
// 查询库中是否有上级包含了本orgId
LambdaQueryWrapper<HrOrganization> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(HrOrganization::getOrgParentId, orgId);
wrapper.select(HrOrganization::getOrgId);
List<HrOrganization> hrOrganizationList = this.list(wrapper);
// 查询结果加到缓存中
if (hrOrganizationList.size() > 0) {
sysOrgSubFlagCache.put(orgId.toString(), true);
return true;
} else {
sysOrgSubFlagCache.put(orgId.toString(), false);
return false;
}
}
/** /**
* *
* *
@ -528,15 +560,9 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
Long orgId = organization.getOrgId(); Long orgId = organization.getOrgId();
// 查询库中是否有上级包含了本orgId // 查询是否包含下级,并设置标识
LambdaQueryWrapper<HrOrganization> wrapper = new LambdaQueryWrapper<>(); Boolean orgHaveSubFlag = this.getOrgHaveSubFlag(orgId);
wrapper.eq(HrOrganization::getOrgParentId, orgId); organization.setHaveSubOrgFlag(orgHaveSubFlag);
wrapper.select(HrOrganization::getOrgId);
List<HrOrganization> hrOrganizationList = this.list(wrapper);
if (hrOrganizationList.size() > 0) {
organization.setHaveSubOrgFlag(true);
}
// 如果有children则将展开标识填充并继续向下递归填充 // 如果有children则将展开标识填充并继续向下递归填充
if (ObjectUtil.isNotEmpty(organization.getChildren())) { if (ObjectUtil.isNotEmpty(organization.getChildren())) {

View File

@ -0,0 +1,57 @@
/*
* Copyright [2020-2030] [https://www.stylefeng.cn]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* GunsAPACHE LICENSE 2.0使
*
* 1.LICENSE
* 2.Guns
* 3.
* 4. https://gitee.com/stylefeng/guns
* 5. https://gitee.com/stylefeng/guns
* 6.
*/
package cn.stylefeng.roses.kernel.sys.starter.cache.org;
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.modular.org.cache.SysOrgSubFlagMemoryCache;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
*
*
* @author fengshuonan
* @since 2023/7/14 1:16
*/
@Configuration
@ConditionalOnMissingClass("org.springframework.data.redis.connection.RedisConnectionFactory")
public class OrgMemoryCacheAutoConfiguration {
/**
*
*
* @author fengshuonan
* @since 2023/7/14 1:17
*/
@Bean
public CacheOperatorApi<Boolean> sysOrgSubFlagCache() {
TimedCache<String, Boolean> themeCache = CacheUtil.newTimedCache(Long.MAX_VALUE);
return new SysOrgSubFlagMemoryCache(themeCache);
}
}

View File

@ -0,0 +1,58 @@
/*
* Copyright [2020-2030] [https://www.stylefeng.cn]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* GunsAPACHE LICENSE 2.0使
*
* 1.LICENSE
* 2.Guns
* 3.
* 4. https://gitee.com/stylefeng/guns
* 5. https://gitee.com/stylefeng/guns
* 6.
*/
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.modular.org.cache.SysOrgSubFlagRedisCache;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
/**
* Redis
*
* @author fengshuonan
* @since 2023/7/14 1:16
*/
@Configuration
@ConditionalOnClass(name = "org.springframework.data.redis.connection.RedisConnectionFactory")
public class OrgRedisCacheAutoConfiguration {
/**
*
*
* @author fengshuonan
* @since 2023/7/14 1:17
*/
@Bean
public CacheOperatorApi<Boolean> sysOrgSubFlagCache(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<String, Boolean> redisTemplate = CreateRedisTemplateUtil.createObject(redisConnectionFactory);
return new SysOrgSubFlagRedisCache(redisTemplate);
}
}

View File

@ -22,7 +22,7 @@
* 5. https://gitee.com/stylefeng/guns * 5. https://gitee.com/stylefeng/guns
* 6. * 6.
*/ */
package cn.stylefeng.roses.kernel.sys.starter.cache; package cn.stylefeng.roses.kernel.sys.starter.cache.resource;
import cn.hutool.cache.CacheUtil; import cn.hutool.cache.CacheUtil;
import cn.hutool.cache.impl.TimedCache; import cn.hutool.cache.impl.TimedCache;

View File

@ -22,7 +22,7 @@
* 5. https://gitee.com/stylefeng/guns * 5. https://gitee.com/stylefeng/guns
* 6. * 6.
*/ */
package cn.stylefeng.roses.kernel.sys.starter.cache; package cn.stylefeng.roses.kernel.sys.starter.cache.resource;
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi; import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
import cn.stylefeng.roses.kernel.cache.redis.util.CreateRedisTemplateUtil; import cn.stylefeng.roses.kernel.cache.redis.util.CreateRedisTemplateUtil;

View File

@ -22,7 +22,7 @@
* 5. https://gitee.com/stylefeng/guns * 5. https://gitee.com/stylefeng/guns
* 6. * 6.
*/ */
package cn.stylefeng.roses.kernel.sys.starter.cache; package cn.stylefeng.roses.kernel.sys.starter.cache.theme;
import cn.hutool.cache.CacheUtil; import cn.hutool.cache.CacheUtil;
import cn.hutool.cache.impl.TimedCache; import cn.hutool.cache.impl.TimedCache;
@ -41,7 +41,7 @@ import org.springframework.context.annotation.Configuration;
*/ */
@Configuration @Configuration
@ConditionalOnMissingClass("org.springframework.data.redis.connection.RedisConnectionFactory") @ConditionalOnMissingClass("org.springframework.data.redis.connection.RedisConnectionFactory")
public class SystemMemoryCacheAutoConfiguration { public class ThemeMemoryCacheAutoConfiguration {
/** /**
* *

View File

@ -22,7 +22,7 @@
* 5. https://gitee.com/stylefeng/guns * 5. https://gitee.com/stylefeng/guns
* 6. * 6.
*/ */
package cn.stylefeng.roses.kernel.sys.starter.cache; package cn.stylefeng.roses.kernel.sys.starter.cache.theme;
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi; import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
import cn.stylefeng.roses.kernel.cache.redis.util.CreateRedisTemplateUtil; import cn.stylefeng.roses.kernel.cache.redis.util.CreateRedisTemplateUtil;
@ -42,7 +42,7 @@ import org.springframework.data.redis.core.RedisTemplate;
*/ */
@Configuration @Configuration
@ConditionalOnClass(name = "org.springframework.data.redis.connection.RedisConnectionFactory") @ConditionalOnClass(name = "org.springframework.data.redis.connection.RedisConnectionFactory")
public class SystemRedisCacheAutoConfiguration { public class ThemeRedisCacheAutoConfiguration {
/** /**
* *

View File

@ -1,6 +1,8 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
cn.stylefeng.roses.kernel.sys.starter.cache.SystemMemoryCacheAutoConfiguration,\ cn.stylefeng.roses.kernel.sys.starter.cache.theme.ThemeMemoryCacheAutoConfiguration,\
cn.stylefeng.roses.kernel.sys.starter.cache.SystemRedisCacheAutoConfiguration,\ cn.stylefeng.roses.kernel.sys.starter.cache.theme.ThemeRedisCacheAutoConfiguration,\
cn.stylefeng.roses.kernel.sys.starter.cache.ResourceMemoryCacheAutoConfiguration,\ cn.stylefeng.roses.kernel.sys.starter.cache.resource.ResourceMemoryCacheAutoConfiguration,\
cn.stylefeng.roses.kernel.sys.starter.cache.ResourceRedisCacheAutoConfiguration,\ cn.stylefeng.roses.kernel.sys.starter.cache.resource.ResourceRedisCacheAutoConfiguration,\
cn.stylefeng.roses.kernel.sys.starter.config.RestErrorViewAutoConfiguration cn.stylefeng.roses.kernel.sys.starter.config.RestErrorViewAutoConfiguration,\
cn.stylefeng.roses.kernel.sys.starter.cache.org.OrgMemoryCacheAutoConfiguration,\
cn.stylefeng.roses.kernel.sys.starter.cache.org.OrgRedisCacheAutoConfiguration