|
|
@@ -26,10 +26,7 @@ import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -152,11 +149,20 @@ public class RoleSceneInfoService extends SuperService {
|
|
|
return ResultContent.buildSuccess(models);
|
|
|
}
|
|
|
|
|
|
- public ResultContent<List<RoleSceneComTreeModel>> tree(List<String> roleIds) {
|
|
|
+ public ResultContent<List<RoleSceneComTreeModel>> tree(List<String> roleIds, DataState state) {
|
|
|
List<RoleSceneComTreeModel> models = new ArrayList<>();
|
|
|
|
|
|
List<RoleSceneInfo> list = roleSceneInfoDao.findByRoleIdInOrderBySortAsc(roleIds);
|
|
|
if (ObjectUtils.isNotEmpty(list)) {
|
|
|
+ if (state != null) {
|
|
|
+ list = list.stream().filter(it -> {
|
|
|
+ return it.getProjectSceneInfo().getState() == state && it.getSceneInfo().getState() == state;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isEmpty(list)) {
|
|
|
+ return ResultContent.buildSuccess(models);
|
|
|
+ }
|
|
|
+
|
|
|
// 以项目应用ID
|
|
|
Map<String, List<RoleSceneInfo>> map = list.stream().collect(
|
|
|
Collectors.toMap(RoleSceneInfo::getProjectSceneInfoId, e -> {
|
|
|
@@ -177,6 +183,8 @@ public class RoleSceneInfoService extends SuperService {
|
|
|
BeanUtils.copyProperties(sceneInfoModel, model);
|
|
|
|
|
|
model.setProjectSceneInfoId(projectSceneInfoId);
|
|
|
+ model.setPSort(projectSceneInfo.getSort());
|
|
|
+ model.setPState(projectSceneInfo.getState());
|
|
|
|
|
|
// 组件信息
|
|
|
List<RoleSceneInfo> roleSceneInfos = map.get(projectSceneInfoId);
|
|
|
@@ -192,68 +200,28 @@ public class RoleSceneInfoService extends SuperService {
|
|
|
model.setChildren(children);
|
|
|
models.add(model);
|
|
|
}
|
|
|
- }
|
|
|
- return ResultContent.buildSuccess(models);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 查询角色可用的应用
|
|
|
- *
|
|
|
- * @param roleId
|
|
|
- * @return
|
|
|
- */
|
|
|
- public List<SceneInfoAboutComModel> getAllEnableScenes(String roleId) {
|
|
|
- List<SceneInfoAboutComModel> models = new ArrayList<>();
|
|
|
|
|
|
- if (StringUtils.isNotEmpty(roleId)) {
|
|
|
- // 角色关联的应用数据
|
|
|
- List<RoleSceneInfo> list = roleSceneInfoDao.findByRoleIdOrderBySortAsc(roleId);
|
|
|
- if (ObjectUtils.isNotEmpty(list)) {
|
|
|
- list.stream().forEach(it -> {
|
|
|
- SceneInfo sceneInfo = it.getSceneInfo();
|
|
|
- ProjectSceneInfo projectSceneInfo = it.getProjectSceneInfo();
|
|
|
- if (ObjectUtils.isNotEmpty(projectSceneInfo) && ObjectUtils.isNotEmpty(sceneInfo)) {
|
|
|
- if (projectSceneInfo.getState() == DataState.Enable && sceneInfo.getState() == DataState.Enable) {
|
|
|
- models.add(sceneInfoService.toAboutComModel(sceneInfo));
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
+ // 排序
|
|
|
+ Collections.sort(models, new Comparator<RoleSceneComTreeModel>() {
|
|
|
+ @Override
|
|
|
+ public int compare(RoleSceneComTreeModel o1, RoleSceneComTreeModel o2) {
|
|
|
+ return (int) (o1.getPSort() - o2.getPSort());
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
- return models;
|
|
|
+ return ResultContent.buildSuccess(models);
|
|
|
}
|
|
|
|
|
|
- public List<SceneInfoAboutComModel> getUserAllEnableScenes() {
|
|
|
+ public List<RoleSceneComTreeModel> getUserAllEnableScenes() {
|
|
|
// 得到当前用户所有的角色
|
|
|
ResultContent<List<RoleSimpleModel>> content = roleServiceImpl.xcxGetCurrentRoles();
|
|
|
if (content.isSuccess()) {
|
|
|
List<RoleSimpleModel> roles = content.getContent();
|
|
|
if (ObjectUtils.isNotEmpty(roles)) {
|
|
|
- List<SceneInfoAboutComModel> models = new ArrayList<>();
|
|
|
-
|
|
|
- List<String> roleIds = roles.stream().map(it -> it.getId()).collect(Collectors.toUnmodifiableList());
|
|
|
- List<RoleSceneInfo> list = roleSceneInfoDao.findByRoleIdInOrderBySortAsc(roleIds);
|
|
|
- if (ObjectUtils.isNotEmpty(list)) {
|
|
|
- list.stream().forEach(it -> {
|
|
|
- SceneInfo sceneInfo = it.getSceneInfo();
|
|
|
- ProjectSceneInfo projectSceneInfo = it.getProjectSceneInfo();
|
|
|
- if (ObjectUtils.isNotEmpty(projectSceneInfo) && ObjectUtils.isNotEmpty(sceneInfo)) {
|
|
|
- if (projectSceneInfo.getState() == DataState.Enable && sceneInfo.getState() == DataState.Enable) {
|
|
|
- models.add(sceneInfoService.toAboutComModel(sceneInfo));
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- List<SceneInfoAboutComModel> reModels = new ArrayList<>();
|
|
|
- HashMap<String, String> map = new HashMap<>();
|
|
|
- for (SceneInfoAboutComModel model : models) {
|
|
|
- if (!map.containsKey(model.getId())) {
|
|
|
- map.put(model.getId(), model.getName());
|
|
|
- reModels.add(model);
|
|
|
- }
|
|
|
+ ResultContent<List<RoleSceneComTreeModel>> treeContent = tree(roles.stream().map(RoleSimpleModel::getId).collect(Collectors.toList()), DataState.Enable);
|
|
|
+ if (treeContent.isSuccess()) {
|
|
|
+ return treeContent.getContent();
|
|
|
}
|
|
|
- // 去重
|
|
|
- return reModels;
|
|
|
}
|
|
|
}
|
|
|
return Lists.newArrayList();
|