Search in sources :

Example 11 with Resource

use of com.topcom.cms.domain.Resource in project topcom-cloud by 545314690.

the class ViewLogController method topByUser.

@ApiOperation("访问量前limit名的资源")
@RequestMapping(value = { "/topByUser" }, method = RequestMethod.GET, produces = "application/json")
@ResponseBody
public List<ViewLogDto> topByUser(@CurrentUser User user, @RequestParam(required = false) Integer limit) {
    if (limit == null || limit == 0) {
        limit = 20;
    }
    // 缓存user懒加载,没有resource,需要在数据库查询
    User user1 = this.userManager.findById(user.getId());
    // user.getPermissionNames();
    Set<Resource> resourceSet = user1.getResource();
    if (resourceSet == null) {
        return null;
    } else {
        ViewLogRequest request = new ViewLogRequest();
        request.setLimit(limit);
        List<Long> resourceIds = new ArrayList<>();
        for (Resource r : resourceSet) {
            resourceIds.add(r.getId());
        }
        request.setResourceIds(resourceIds);
        List<ViewLogDto> viewLogDtoList = this.viewLogManager.searchHotPage(request);
        if (viewLogDtoList.size() < limit) {
            return viewLogDtoList;
        } else {
            return viewLogDtoList.subList(0, request.getLimit());
        }
    }
}
Also used : CurrentUser(com.topcom.cms.web.bind.annotation.CurrentUser) User(com.topcom.cms.domain.User) ViewLogDto(com.topcom.cms.vo.ViewLogDto) Resource(com.topcom.cms.domain.Resource) ArrayList(java.util.ArrayList) ViewLogRequest(com.topcom.cms.vo.ViewLogRequest) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

Resource (com.topcom.cms.domain.Resource)11 PublicResource (com.topcom.cms.perm.annotation.PublicResource)8 User (com.topcom.cms.domain.User)3 CurrentUser (com.topcom.cms.web.bind.annotation.CurrentUser)3 ApiOperation (io.swagger.annotations.ApiOperation)3 Application (com.topcom.cms.domain.Application)1 BusinessException (com.topcom.cms.exception.BusinessException)1 ViewLogDto (com.topcom.cms.vo.ViewLogDto)1 ViewLogRequest (com.topcom.cms.vo.ViewLogRequest)1 ArrayList (java.util.ArrayList)1 HashedMap (org.apache.commons.collections.map.HashedMap)1 Page (org.springframework.data.domain.Page)1 PageImpl (org.springframework.data.domain.PageImpl)1 PageRequest (org.springframework.data.domain.PageRequest)1