Search in sources :

Example 1 with ViewLogDto

use of com.topcom.cms.vo.ViewLogDto 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)1 User (com.topcom.cms.domain.User)1 ViewLogDto (com.topcom.cms.vo.ViewLogDto)1 ViewLogRequest (com.topcom.cms.vo.ViewLogRequest)1 CurrentUser (com.topcom.cms.web.bind.annotation.CurrentUser)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ArrayList (java.util.ArrayList)1