use of com.topcom.cms.domain.Application in project topcom-cloud by 545314690.
the class UserController method appResource.
/**
* 返回登录用户指定app的resource
*/
@ApiOperation("获取指定app的resource")
@RequestMapping(value = { "appResource" }, method = { RequestMethod.GET })
@ResponseBody
public Set<Resource> appResource(@CurrentUser User user, @RequestParam(required = false) Long appId, @RequestParam(required = false) String appName) throws Exception {
if (appId == null && StringUtils.isBlank(appName)) {
throw new BusinessException("appId 和 appName 不能同时为空!");
}
if (appId == null) {
Application app = applicationManager.findByName(appName);
appId = app.getId();
}
// 缓存user懒加载,没有resource,需要在数据库查询
User user1 = this.manager.findById(user.getId());
Set<Resource> resourceSet = user1.getResource();
if (resourceSet == null || resourceSet.size() == 0) {
return null;
}
Set<Resource> filteredResourceSet = new LinkedHashSet<>();
for (Resource resource : resourceSet) {
if (appId.equals(resource.getAppId())) {
filteredResourceSet.add(resource);
}
}
for (Resource resource : filteredResourceSet) {
resource.sortByChildId();
}
return filteredResourceSet;
}
Aggregations