From 5e9b83d6160481924f92a62cd63f2ba9d8e1a799 Mon Sep 17 00:00:00 2001 From: fengshuonan Date: Fri, 14 Jul 2023 01:20:11 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=908.0=E3=80=91=E3=80=90system=E3=80=91?= =?UTF-8?q?=E3=80=90org=E3=80=91=E7=BB=84=E7=BB=87=E6=9C=BA=E6=9E=84?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E5=90=AB=E6=9C=89=E4=B8=8B=E7=BA=A7=E6=A0=87?= =?UTF-8?q?=E8=AF=86=E5=A2=9E=E5=8A=A0=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/service/HrOrganizationService.java | 10 ++++ .../impl/HrOrganizationServiceImpl.java | 44 +++++++++++--- .../org/OrgMemoryCacheAutoConfiguration.java | 57 ++++++++++++++++++ .../org/OrgRedisCacheAutoConfiguration.java | 58 +++++++++++++++++++ .../ResourceMemoryCacheAutoConfiguration.java | 2 +- .../ResourceRedisCacheAutoConfiguration.java | 2 +- .../ThemeMemoryCacheAutoConfiguration.java} | 4 +- .../ThemeRedisCacheAutoConfiguration.java} | 4 +- .../main/resources/META-INF/spring.factories | 12 ++-- 9 files changed, 173 insertions(+), 20 deletions(-) create mode 100644 kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/sys/starter/cache/org/OrgMemoryCacheAutoConfiguration.java create mode 100644 kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/sys/starter/cache/org/OrgRedisCacheAutoConfiguration.java rename kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/sys/starter/cache/{ => resource}/ResourceMemoryCacheAutoConfiguration.java (97%) rename kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/sys/starter/cache/{ => resource}/ResourceRedisCacheAutoConfiguration.java (97%) rename kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/sys/starter/cache/{SystemMemoryCacheAutoConfiguration.java => theme/ThemeMemoryCacheAutoConfiguration.java} (95%) rename kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/sys/starter/cache/{SystemRedisCacheAutoConfiguration.java => theme/ThemeRedisCacheAutoConfiguration.java} (95%) diff --git a/kernel-s-system/system-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/org/service/HrOrganizationService.java b/kernel-s-system/system-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/org/service/HrOrganizationService.java index 8f16abd11..6bdc56450 100644 --- a/kernel-s-system/system-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/org/service/HrOrganizationService.java +++ b/kernel-s-system/system-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/org/service/HrOrganizationService.java @@ -151,4 +151,14 @@ public interface HrOrganizationService extends IService { */ Set queryOrgIdParentIdList(Set orgIdList); + /** + * 获取组织机构是否包含下级的标识 + * + * @param orgId 被查询的组织机构id + * @return true-包含下级,false-不含下级 + * @author fengshuonan + * @since 2023/7/14 1:09 + */ + Boolean getOrgHaveSubFlag(Long orgId); + } \ No newline at end of file diff --git a/kernel-s-system/system-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/org/service/impl/HrOrganizationServiceImpl.java b/kernel-s-system/system-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/org/service/impl/HrOrganizationServiceImpl.java index 1b527b527..139c505b7 100644 --- a/kernel-s-system/system-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/org/service/impl/HrOrganizationServiceImpl.java +++ b/kernel-s-system/system-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/org/service/impl/HrOrganizationServiceImpl.java @@ -6,6 +6,7 @@ import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.extra.spring.SpringUtil; 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.factory.PageFactory; import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory; @@ -63,6 +64,9 @@ public class HrOrganizationServiceImpl extends ServiceImpl sysOrgSubFlagCache; + @Override public void add(HrOrganizationRequest hrOrganizationRequest) { HrOrganization hrOrganization = new HrOrganization(); @@ -401,6 +405,34 @@ public class HrOrganizationServiceImpl extends ServiceImpl wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(HrOrganization::getOrgParentId, orgId); + wrapper.select(HrOrganization::getOrgId); + List 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 wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(HrOrganization::getOrgParentId, orgId); - wrapper.select(HrOrganization::getOrgId); - List hrOrganizationList = this.list(wrapper); - - if (hrOrganizationList.size() > 0) { - organization.setHaveSubOrgFlag(true); - } + // 查询是否包含下级,并设置标识 + Boolean orgHaveSubFlag = this.getOrgHaveSubFlag(orgId); + organization.setHaveSubOrgFlag(orgHaveSubFlag); // 如果有children则将展开标识填充,并继续向下递归填充 if (ObjectUtil.isNotEmpty(organization.getChildren())) { diff --git a/kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/sys/starter/cache/org/OrgMemoryCacheAutoConfiguration.java b/kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/sys/starter/cache/org/OrgMemoryCacheAutoConfiguration.java new file mode 100644 index 000000000..59b948de2 --- /dev/null +++ b/kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/sys/starter/cache/org/OrgMemoryCacheAutoConfiguration.java @@ -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 sysOrgSubFlagCache() { + TimedCache themeCache = CacheUtil.newTimedCache(Long.MAX_VALUE); + return new SysOrgSubFlagMemoryCache(themeCache); + } + +} diff --git a/kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/sys/starter/cache/org/OrgRedisCacheAutoConfiguration.java b/kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/sys/starter/cache/org/OrgRedisCacheAutoConfiguration.java new file mode 100644 index 000000000..6b527875c --- /dev/null +++ b/kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/sys/starter/cache/org/OrgRedisCacheAutoConfiguration.java @@ -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 sysOrgSubFlagCache(RedisConnectionFactory redisConnectionFactory) { + RedisTemplate redisTemplate = CreateRedisTemplateUtil.createObject(redisConnectionFactory); + return new SysOrgSubFlagRedisCache(redisTemplate); + } + +} diff --git a/kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/sys/starter/cache/ResourceMemoryCacheAutoConfiguration.java b/kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/sys/starter/cache/resource/ResourceMemoryCacheAutoConfiguration.java similarity index 97% rename from kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/sys/starter/cache/ResourceMemoryCacheAutoConfiguration.java rename to kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/sys/starter/cache/resource/ResourceMemoryCacheAutoConfiguration.java index 180d121e4..cedbc3240 100644 --- a/kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/sys/starter/cache/ResourceMemoryCacheAutoConfiguration.java +++ b/kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/sys/starter/cache/resource/ResourceMemoryCacheAutoConfiguration.java @@ -22,7 +22,7 @@ * 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns * 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.impl.TimedCache; diff --git a/kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/sys/starter/cache/ResourceRedisCacheAutoConfiguration.java b/kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/sys/starter/cache/resource/ResourceRedisCacheAutoConfiguration.java similarity index 97% rename from kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/sys/starter/cache/ResourceRedisCacheAutoConfiguration.java rename to kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/sys/starter/cache/resource/ResourceRedisCacheAutoConfiguration.java index c2d9ebebe..f2160235a 100644 --- a/kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/sys/starter/cache/ResourceRedisCacheAutoConfiguration.java +++ b/kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/sys/starter/cache/resource/ResourceRedisCacheAutoConfiguration.java @@ -22,7 +22,7 @@ * 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns * 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.redis.util.CreateRedisTemplateUtil; diff --git a/kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/sys/starter/cache/SystemMemoryCacheAutoConfiguration.java b/kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/sys/starter/cache/theme/ThemeMemoryCacheAutoConfiguration.java similarity index 95% rename from kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/sys/starter/cache/SystemMemoryCacheAutoConfiguration.java rename to kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/sys/starter/cache/theme/ThemeMemoryCacheAutoConfiguration.java index 4ea9fd890..786bb8b2a 100644 --- a/kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/sys/starter/cache/SystemMemoryCacheAutoConfiguration.java +++ b/kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/sys/starter/cache/theme/ThemeMemoryCacheAutoConfiguration.java @@ -22,7 +22,7 @@ * 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns * 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.impl.TimedCache; @@ -41,7 +41,7 @@ import org.springframework.context.annotation.Configuration; */ @Configuration @ConditionalOnMissingClass("org.springframework.data.redis.connection.RedisConnectionFactory") -public class SystemMemoryCacheAutoConfiguration { +public class ThemeMemoryCacheAutoConfiguration { /** * 主题的缓存 diff --git a/kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/sys/starter/cache/SystemRedisCacheAutoConfiguration.java b/kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/sys/starter/cache/theme/ThemeRedisCacheAutoConfiguration.java similarity index 95% rename from kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/sys/starter/cache/SystemRedisCacheAutoConfiguration.java rename to kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/sys/starter/cache/theme/ThemeRedisCacheAutoConfiguration.java index 61364e37f..778c63d89 100644 --- a/kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/sys/starter/cache/SystemRedisCacheAutoConfiguration.java +++ b/kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/sys/starter/cache/theme/ThemeRedisCacheAutoConfiguration.java @@ -22,7 +22,7 @@ * 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns * 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.redis.util.CreateRedisTemplateUtil; @@ -42,7 +42,7 @@ import org.springframework.data.redis.core.RedisTemplate; */ @Configuration @ConditionalOnClass(name = "org.springframework.data.redis.connection.RedisConnectionFactory") -public class SystemRedisCacheAutoConfiguration { +public class ThemeRedisCacheAutoConfiguration { /** * 主题的缓存 diff --git a/kernel-s-system/system-spring-boot-starter/src/main/resources/META-INF/spring.factories b/kernel-s-system/system-spring-boot-starter/src/main/resources/META-INF/spring.factories index e0ab3f469..c336eee86 100644 --- a/kernel-s-system/system-spring-boot-starter/src/main/resources/META-INF/spring.factories +++ b/kernel-s-system/system-spring-boot-starter/src/main/resources/META-INF/spring.factories @@ -1,6 +1,8 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ - cn.stylefeng.roses.kernel.sys.starter.cache.SystemMemoryCacheAutoConfiguration,\ - cn.stylefeng.roses.kernel.sys.starter.cache.SystemRedisCacheAutoConfiguration,\ - cn.stylefeng.roses.kernel.sys.starter.cache.ResourceMemoryCacheAutoConfiguration,\ - cn.stylefeng.roses.kernel.sys.starter.cache.ResourceRedisCacheAutoConfiguration,\ - cn.stylefeng.roses.kernel.sys.starter.config.RestErrorViewAutoConfiguration \ No newline at end of file + cn.stylefeng.roses.kernel.sys.starter.cache.theme.ThemeMemoryCacheAutoConfiguration,\ + cn.stylefeng.roses.kernel.sys.starter.cache.theme.ThemeRedisCacheAutoConfiguration,\ + cn.stylefeng.roses.kernel.sys.starter.cache.resource.ResourceMemoryCacheAutoConfiguration,\ + cn.stylefeng.roses.kernel.sys.starter.cache.resource.ResourceRedisCacheAutoConfiguration,\ + 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 \ No newline at end of file