diff --git a/tyr-server/src/main/java/cn/axzo/tyr/server/job/CacheProductFeatureResourceJob.java b/tyr-server/src/main/java/cn/axzo/tyr/server/job/CacheProductFeatureResourceJob.java index 0bbc2b63..7933977d 100644 --- a/tyr-server/src/main/java/cn/axzo/tyr/server/job/CacheProductFeatureResourceJob.java +++ b/tyr-server/src/main/java/cn/axzo/tyr/server/job/CacheProductFeatureResourceJob.java @@ -9,6 +9,7 @@ import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.handler.IJobHandler; import com.xxl.job.core.handler.annotation.XxlJob; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; @@ -19,7 +20,7 @@ import java.util.stream.Collectors; @Slf4j @Component -public class CacheProductFeatureResourceJob extends IJobHandler { +public class CacheProductFeatureResourceJob extends IJobHandler implements InitializingBean { @Autowired private ProductSaasFeatureResourceCacheService productSaasFeatureResourceCacheService; @@ -50,4 +51,10 @@ public class CacheProductFeatureResourceJob extends IJobHandler { productSaasFeatureResourceCacheService.refreshCache(param); return ReturnT.SUCCESS; } + + @Override + public void afterPropertiesSet() throws Exception { + // 启动时加载做localCache + execute(null); + } } diff --git a/tyr-server/src/main/java/cn/axzo/tyr/server/job/CacheProductPermissionJob.java b/tyr-server/src/main/java/cn/axzo/tyr/server/job/CacheProductPermissionJob.java index e7913351..3c89a156 100644 --- a/tyr-server/src/main/java/cn/axzo/tyr/server/job/CacheProductPermissionJob.java +++ b/tyr-server/src/main/java/cn/axzo/tyr/server/job/CacheProductPermissionJob.java @@ -9,6 +9,7 @@ import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.handler.IJobHandler; import com.xxl.job.core.handler.annotation.XxlJob; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; @@ -19,7 +20,7 @@ import java.util.stream.Collectors; @Slf4j @Component -public class CacheProductPermissionJob extends IJobHandler { +public class CacheProductPermissionJob extends IJobHandler implements InitializingBean { @Autowired private ProductPermissionCacheService productPermissionCacheService; @@ -49,4 +50,10 @@ public class CacheProductPermissionJob extends IJobHandler { productPermissionCacheService.refreshCache(param); return ReturnT.SUCCESS; } + + @Override + public void afterPropertiesSet() throws Exception { + // 启动时加载做localCache + execute(null); + } } diff --git a/tyr-server/src/main/java/cn/axzo/tyr/server/job/CacheRoleFeatureResourceJob.java b/tyr-server/src/main/java/cn/axzo/tyr/server/job/CacheRoleFeatureResourceJob.java index bc60ddd2..911d180d 100644 --- a/tyr-server/src/main/java/cn/axzo/tyr/server/job/CacheRoleFeatureResourceJob.java +++ b/tyr-server/src/main/java/cn/axzo/tyr/server/job/CacheRoleFeatureResourceJob.java @@ -10,6 +10,7 @@ import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.handler.IJobHandler; import com.xxl.job.core.handler.annotation.XxlJob; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; @@ -20,7 +21,7 @@ import java.util.stream.Collectors; @Slf4j @Component -public class CacheRoleFeatureResourceJob extends IJobHandler { +public class CacheRoleFeatureResourceJob extends IJobHandler implements InitializingBean { @Autowired private RoleService roleService; @@ -51,4 +52,10 @@ public class CacheRoleFeatureResourceJob extends IJobHandler { return ReturnT.SUCCESS; } + + @Override + public void afterPropertiesSet() throws Exception { + // 启动时加载做localCache + execute(null); + } } diff --git a/tyr-server/src/main/java/cn/axzo/tyr/server/job/CacheRolePermissionJob.java b/tyr-server/src/main/java/cn/axzo/tyr/server/job/CacheRolePermissionJob.java index edba7b4f..18a1fd78 100644 --- a/tyr-server/src/main/java/cn/axzo/tyr/server/job/CacheRolePermissionJob.java +++ b/tyr-server/src/main/java/cn/axzo/tyr/server/job/CacheRolePermissionJob.java @@ -10,6 +10,7 @@ import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.handler.IJobHandler; import com.xxl.job.core.handler.annotation.XxlJob; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; @@ -20,7 +21,7 @@ import java.util.stream.Collectors; @Slf4j @Component -public class CacheRolePermissionJob extends IJobHandler { +public class CacheRolePermissionJob extends IJobHandler implements InitializingBean { @Autowired private RoleService roleService; @@ -53,4 +54,10 @@ public class CacheRolePermissionJob extends IJobHandler { return ReturnT.SUCCESS; } + @Override + public void afterPropertiesSet() throws Exception { + // 启动时加载做localCache + execute(null); + } + } diff --git a/tyr-server/src/main/java/cn/axzo/tyr/server/job/CacheSaasFeatureJob.java b/tyr-server/src/main/java/cn/axzo/tyr/server/job/CacheSaasFeatureJob.java index 622a1b4c..70e4d129 100644 --- a/tyr-server/src/main/java/cn/axzo/tyr/server/job/CacheSaasFeatureJob.java +++ b/tyr-server/src/main/java/cn/axzo/tyr/server/job/CacheSaasFeatureJob.java @@ -15,6 +15,7 @@ import lombok.Data; import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections.CollectionUtils; +import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -24,7 +25,7 @@ import java.util.stream.Collectors; @Slf4j @Component -public class CacheSaasFeatureJob extends IJobHandler { +public class CacheSaasFeatureJob extends IJobHandler implements InitializingBean { @Autowired private SaasFeatureDao saasFeatureDao; @@ -85,6 +86,12 @@ public class CacheSaasFeatureJob extends IJobHandler { saasFeatureResourceService.refreshCache(param); } + @Override + public void afterPropertiesSet() throws Exception { + // 启动时加载做localCache + execute(null); + } + @Data @Builder @NoArgsConstructor diff --git a/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/RoleServiceImpl.java b/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/RoleServiceImpl.java index fbea81a5..ce2910ad 100644 --- a/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/RoleServiceImpl.java +++ b/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/RoleServiceImpl.java @@ -1737,19 +1737,25 @@ public class RoleServiceImpl extends ServiceImpl Map roles = item.getRoles().stream() .collect(Collectors.toMap(FeatureRoleRelationReq.Role::getRoleId, Function.identity(), (f, s) -> f)); - Map existFeatureGroups = saasPgroupPermissionRelations.stream() - .collect(Collectors.toMap(SaasPgroupPermissionRelation::getGroupId, Function.identity())); + // 现在接口没有收口,也没有找到为什么一个featureId、groupId会有多条记录 + Map> existFeatureGroups = saasPgroupPermissionRelations.stream() + .collect(Collectors.groupingBy(SaasPgroupPermissionRelation::getGroupId)); List update = saasPgroupRoleRelations.stream() .map(e -> { - SaasPgroupPermissionRelation old = existFeatureGroups.get(e.getGroupId()); - if (Objects.isNull(old)) { + List olds = existFeatureGroups.get(e.getGroupId()); + if (CollectionUtils.isEmpty(olds)) { return null; } - e.setId(old.getId()); - return e; + return olds.stream() + .map(old -> { + e.setId(old.getId()); + return e; + }) + .collect(Collectors.toList()); }) .filter(Objects::nonNull) + .flatMap(Collection::stream) .collect(Collectors.toList()); // 记录操作日志 diff --git a/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/SaasPgroupPermissionRelationServiceImpl.java b/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/SaasPgroupPermissionRelationServiceImpl.java index dd979ced..68526898 100644 --- a/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/SaasPgroupPermissionRelationServiceImpl.java +++ b/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/SaasPgroupPermissionRelationServiceImpl.java @@ -74,19 +74,25 @@ public class SaasPgroupPermissionRelationServiceImpl saasPgroupPermissionRelationDao.removeByIds(deleteList.stream().map(SaasPgroupPermissionRelation::getId).sorted().collect(Collectors.toList())); } - Map existFeatureGroups = exists.stream() - .collect(Collectors.toMap(e -> e.getFeatureId() + "_" + e.getGroupId(), Function.identity())); + // 现在接口没有收口,也没有找到为什么一个featureId、groupId会有多条记录 + Map> existFeatureGroups = exists.stream() + .collect(Collectors.groupingBy(e -> e.getFeatureId() + "_" + e.getGroupId())); List updates = relations.stream() .map(e -> { - SaasPgroupPermissionRelation old = existFeatureGroups.get(e.getFeatureId() + "_" + e.getGroupId()); - if (Objects.isNull(old)) { + List olds = existFeatureGroups.get(e.getFeatureId() + "_" + e.getGroupId()); + if (CollectionUtils.isEmpty(olds)) { return null; } - e.setId(old.getId()); - return e; + return olds.stream() + .map(old -> { + e.setId(old.getId()); + return e; + }) + .collect(Collectors.toList()); }) .filter(Objects::nonNull) + .flatMap(Collection::stream) .collect(Collectors.toList()); if (CollectionUtils.isNotEmpty(updates)) { saasPgroupPermissionRelationDao.updateBatchById(updates);