mirror of https://gitee.com/stylefeng/roses
【8.0】【system】【org】组织机构是否含有下级标识增加缓存
parent
ce4d93256a
commit
5e9b83d616
|
@ -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);
|
||||||
|
|
||||||
}
|
}
|
|
@ -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())) {
|
||||||
|
|
|
@ -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.
|
||||||
|
*
|
||||||
|
* Guns采用APACHE 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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.
|
||||||
|
*
|
||||||
|
* Guns采用APACHE 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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;
|
|
@ -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;
|
|
@ -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 {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 主题的缓存
|
* 主题的缓存
|
|
@ -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 {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 主题的缓存
|
* 主题的缓存
|
|
@ -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
|
Loading…
Reference in New Issue