use of com.topcom.cms.domain.Resource in project topcom-cloud by 545314690.
the class ResourceManagerImpl method searchResource.
@Override
public Page<Resource> searchResource(Set<Resource> resourceSet, String word, Integer limit, Integer page, String filterType) {
Page result = null;
if (limit == null || limit == 0) {
limit = 20;
}
if (page == null || page == 0) {
page = 1;
}
List<Resource> content = new ArrayList<>();
if (StringUtils.isEmpty(word)) {
content.addAll(resourceSet);
} else {
content = searchText(word, resourceSet, filterType);
}
int index_s = (page - 1) * limit;
int index_e = page * limit;
if (index_s > content.size()) {
content.clear();
} else {
result = new PageImpl(content.subList(index_s, index_e > content.size() ? content.size() : index_e), new PageRequest(page - 1, limit), content.size());
}
return result;
}
use of com.topcom.cms.domain.Resource in project topcom-cloud by 545314690.
the class UserController method mergeChild.
private List<Resource> mergeChild(List<Resource> resourceList) {
Map<Long, Resource> resultMap = new HashMap<>();
for (int i = 0; i < resourceList.size(); i++) {
if (i == 23) {
System.out.println("23");
}
Resource resource_i = resourceList.get(i);
Long resourceId_i = resource_i.getId();
for (int j = i + 1; j < resourceList.size(); j++) {
Resource resource_j = resourceList.get(j);
Long resourceId_j = resource_j.getId();
if (resourceId_i.equals(resourceId_j)) {
// List<Resource> childrenList = resource_i.getChildren();
// childrenList.addAll(resource_j.getChildren());
resource_i = mergeChild(resource_i, resource_j);
}
}
if (!resultMap.keySet().contains(resourceId_i)) {
resultMap.put(resourceId_i, resource_i);
}
}
resourceList.clear();
for (Long l : resultMap.keySet()) {
resourceList.add(resultMap.get(l));
}
return resourceList;
}
use of com.topcom.cms.domain.Resource in project topcom-cloud by 545314690.
the class UserController method resource.
/**
* 返回登录用户的resource
*/
@ApiOperation("获取resource")
@RequestMapping(value = { "resource" }, method = { RequestMethod.GET })
@ResponseBody
public Set<Resource> resource(@CurrentUser User user) {
// 缓存user懒加载,没有resource,需要在数据库查询
User user1 = this.manager.findById(user.getId());
// user.getPermissionNames();
Set<Resource> resourceSet = user1.getResource();
if (resourceSet == null || resourceSet.size() == 0) {
return null;
}
for (Resource resource : resourceSet) {
resource.sortByChildId();
}
return resourceSet;
}
use of com.topcom.cms.domain.Resource in project topcom-cloud by 545314690.
the class UserController method getResourceParentId.
private Long getResourceParentId(Resource resource) {
Long parentId = resource.getParentId();
if (parentId != null) {
Resource parent = resource.getParent();
List<Resource> resourceList = new ArrayList<>();
resourceList.add(resource);
parent.setChildren(resourceList);
return getResourceParentId(parent);
} else {
return parentId;
}
}
use of com.topcom.cms.domain.Resource in project topcom-cloud by 545314690.
the class UserController method megerBtoA.
private Resource megerBtoA(Resource resource_a, Resource resource_b) {
Long aId = resource_a.getId();
Long bId = resource_b.getId();
Long parentId_b = resource_b.getParentId();
if (aId == bId) {
return resource_b;
}
if (parentId_b == null) {
return resource_a;
}
List<Resource> childrenList = resource_a.getChildren();
if (parentId_b == aId) {
childrenList = addToList(childrenList, resource_b);
} else {
for (int i = 0; i < childrenList.size(); i++) {
Resource resouce_i = megerBtoA(childrenList.get(i), resource_b);
childrenList = addToList(childrenList, resouce_i);
}
}
resource_a.setChildren(childrenList);
return resource_a;
}
Aggregations