|
@@ -39,6 +39,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.cache.annotation.CacheConfig;
|
|
import org.springframework.cache.annotation.CacheConfig;
|
|
import org.springframework.cache.annotation.CacheEvict;
|
|
import org.springframework.cache.annotation.CacheEvict;
|
|
import org.springframework.cache.annotation.Cacheable;
|
|
import org.springframework.cache.annotation.Cacheable;
|
|
|
|
+import org.springframework.cache.annotation.Caching;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
@@ -53,7 +54,9 @@ import static org.hswebframework.web.commons.entity.DataStatus.STATUS_ENABLED;
|
|
import static org.hswebframework.web.entity.authorization.AuthorizationSettingDetailEntity.*;
|
|
import static org.hswebframework.web.entity.authorization.AuthorizationSettingDetailEntity.*;
|
|
import static org.hswebframework.web.entity.authorization.AuthorizationSettingEntity.settingFor;
|
|
import static org.hswebframework.web.entity.authorization.AuthorizationSettingEntity.settingFor;
|
|
import static org.hswebframework.web.entity.authorization.AuthorizationSettingEntity.type;
|
|
import static org.hswebframework.web.entity.authorization.AuthorizationSettingEntity.type;
|
|
|
|
+import static org.hswebframework.web.service.authorization.simple.CacheConstants.MENU_CACHE_NAME;
|
|
import static org.hswebframework.web.service.authorization.simple.CacheConstants.USER_AUTH_CACHE_NAME;
|
|
import static org.hswebframework.web.service.authorization.simple.CacheConstants.USER_AUTH_CACHE_NAME;
|
|
|
|
+import static org.hswebframework.web.service.authorization.simple.CacheConstants.USER_MENU_CACHE_NAME;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 默认的服务实现
|
|
* 默认的服务实现
|
|
@@ -61,7 +64,6 @@ import static org.hswebframework.web.service.authorization.simple.CacheConstants
|
|
* @author hsweb-generator-online
|
|
* @author hsweb-generator-online
|
|
*/
|
|
*/
|
|
@Service("authorizationSettingService")
|
|
@Service("authorizationSettingService")
|
|
-@CacheConfig(cacheNames = USER_AUTH_CACHE_NAME)
|
|
|
|
public class SimpleAuthorizationSettingService extends GenericEntityService<AuthorizationSettingEntity, String>
|
|
public class SimpleAuthorizationSettingService extends GenericEntityService<AuthorizationSettingEntity, String>
|
|
implements AuthorizationSettingService, AuthenticationInitializeService, UserMenuManagerService {
|
|
implements AuthorizationSettingService, AuthenticationInitializeService, UserMenuManagerService {
|
|
|
|
|
|
@@ -81,7 +83,6 @@ public class SimpleAuthorizationSettingService extends GenericEntityService<Auth
|
|
|
|
|
|
private DataAccessFactory dataAccessFactory;
|
|
private DataAccessFactory dataAccessFactory;
|
|
|
|
|
|
-
|
|
|
|
@Override
|
|
@Override
|
|
protected IDGenerator<String> getIDGenerator() {
|
|
protected IDGenerator<String> getIDGenerator() {
|
|
return IDGenerator.MD5;
|
|
return IDGenerator.MD5;
|
|
@@ -102,7 +103,7 @@ public class SimpleAuthorizationSettingService extends GenericEntityService<Auth
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- @CacheEvict(allEntries = true)
|
|
|
|
|
|
+ @CacheEvict(cacheNames = {CacheConstants.USER_AUTH_CACHE_NAME,CacheConstants.USER_MENU_CACHE_NAME}, allEntries = true)
|
|
public String saveOrUpdate(AuthorizationSettingEntity entity) {
|
|
public String saveOrUpdate(AuthorizationSettingEntity entity) {
|
|
AuthorizationSettingEntity old = select(entity.getType(), entity.getSettingFor());
|
|
AuthorizationSettingEntity old = select(entity.getType(), entity.getSettingFor());
|
|
if (old != null) {
|
|
if (old != null) {
|
|
@@ -113,7 +114,7 @@ public class SimpleAuthorizationSettingService extends GenericEntityService<Auth
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- @CacheEvict(allEntries = true)
|
|
|
|
|
|
+ @CacheEvict(cacheNames = {CacheConstants.USER_AUTH_CACHE_NAME,CacheConstants.USER_MENU_CACHE_NAME}, allEntries = true)
|
|
public String insert(AuthorizationSettingEntity entity) {
|
|
public String insert(AuthorizationSettingEntity entity) {
|
|
tryValidateProperty(select(entity.getType(), entity.getSettingFor()) == null, AuthorizationSettingEntity.settingFor, "存在相同的配置!");
|
|
tryValidateProperty(select(entity.getType(), entity.getSettingFor()) == null, AuthorizationSettingEntity.settingFor, "存在相同的配置!");
|
|
entity.setStatus(STATUS_ENABLED);
|
|
entity.setStatus(STATUS_ENABLED);
|
|
@@ -138,7 +139,7 @@ public class SimpleAuthorizationSettingService extends GenericEntityService<Auth
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- @CacheEvict(allEntries = true)
|
|
|
|
|
|
+ @CacheEvict(cacheNames = {CacheConstants.USER_AUTH_CACHE_NAME,CacheConstants.USER_MENU_CACHE_NAME}, allEntries = true)
|
|
public int updateByPk(String id, AuthorizationSettingEntity entity) {
|
|
public int updateByPk(String id, AuthorizationSettingEntity entity) {
|
|
int size = super.updateByPk(id, entity);
|
|
int size = super.updateByPk(id, entity);
|
|
if (entity.getMenus() != null) {
|
|
if (entity.getMenus() != null) {
|
|
@@ -166,7 +167,7 @@ public class SimpleAuthorizationSettingService extends GenericEntityService<Auth
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- @CacheEvict(allEntries = true)
|
|
|
|
|
|
+ @CacheEvict(cacheNames = {CacheConstants.USER_AUTH_CACHE_NAME,CacheConstants.USER_MENU_CACHE_NAME}, allEntries = true)
|
|
public int deleteByPk(String id) {
|
|
public int deleteByPk(String id) {
|
|
Objects.requireNonNull(id, "id can not be null");
|
|
Objects.requireNonNull(id, "id can not be null");
|
|
authorizationSettingMenuService.deleteBySettingId(id);
|
|
authorizationSettingMenuService.deleteBySettingId(id);
|
|
@@ -184,7 +185,7 @@ public class SimpleAuthorizationSettingService extends GenericEntityService<Auth
|
|
Stream<Map.Entry<String, List<SettingInfo>>> settingInfoStream = settingInfo.entrySet().stream();
|
|
Stream<Map.Entry<String, List<SettingInfo>>> settingInfoStream = settingInfo.entrySet().stream();
|
|
//大于1 使用并行处理
|
|
//大于1 使用并行处理
|
|
if (settingInfo.size() > 1) {
|
|
if (settingInfo.size() > 1) {
|
|
- settingInfoStream.parallel();
|
|
|
|
|
|
+ settingInfoStream = settingInfoStream.parallel();
|
|
}
|
|
}
|
|
return settingInfoStream
|
|
return settingInfoStream
|
|
.map(entry ->
|
|
.map(entry ->
|
|
@@ -199,14 +200,14 @@ public class SimpleAuthorizationSettingService extends GenericEntityService<Auth
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- @Cacheable(key = "'user-menu-list:'+#userId")
|
|
|
|
|
|
+ @Cacheable(cacheNames = USER_MENU_CACHE_NAME, key = "'user-menu-list:'+#userId")
|
|
public List<UserMenuEntity> getUserMenuAsList(String userId) {
|
|
public List<UserMenuEntity> getUserMenuAsList(String userId) {
|
|
if (null == userId) {
|
|
if (null == userId) {
|
|
- return null;
|
|
|
|
|
|
+ return Collections.emptyList();
|
|
}
|
|
}
|
|
UserEntity userEntity = userService.selectByPk(userId);
|
|
UserEntity userEntity = userService.selectByPk(userId);
|
|
if (userEntity == null) {
|
|
if (userEntity == null) {
|
|
- return null;
|
|
|
|
|
|
+ return Collections.emptyList();
|
|
}
|
|
}
|
|
List<AuthorizationSettingEntity> entities = getUserSetting(userId);
|
|
List<AuthorizationSettingEntity> entities = getUserSetting(userId);
|
|
if (entities.isEmpty()) {
|
|
if (entities.isEmpty()) {
|
|
@@ -262,7 +263,7 @@ public class SimpleAuthorizationSettingService extends GenericEntityService<Auth
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- @Cacheable(key = "'menu-tree:'+#userId")
|
|
|
|
|
|
+ @Cacheable(cacheNames = USER_MENU_CACHE_NAME, key = "'menu-tree:'+#userId")
|
|
public List<UserMenuEntity> getUserMenuAsTree(String userId) {
|
|
public List<UserMenuEntity> getUserMenuAsTree(String userId) {
|
|
return TreeSupportEntity.list2tree(getUserMenuAsList(userId), UserMenuEntity::setChildren,
|
|
return TreeSupportEntity.list2tree(getUserMenuAsList(userId), UserMenuEntity::setChildren,
|
|
(Predicate<UserMenuEntity>) menuEntity ->
|
|
(Predicate<UserMenuEntity>) menuEntity ->
|