Search in sources :

Example 6 with CurrentUser

use of com.topcom.cms.web.bind.annotation.CurrentUser in project topcom-cloud by 545314690.

the class SearchWordController method findByWord.

@RequestMapping(method = RequestMethod.GET, value = "/findByWord", produces = "application/json")
@ResponseBody
public List<SearchWord> findByWord(@CurrentUser User user, @ApiParam("limit") @RequestParam(required = true) Integer limit, @ApiParam("word") @RequestParam(required = true) String word) {
    Sort sort = new Sort(new Sort.Order(Sort.Direction.DESC, "wordCount"));
    Pageable page = new PageRequest(0, limit, sort);
    User user1 = this.userManager.findById(user.getId());
    Set<Group> groups = user1.getGroups();
    String groupId = SearchWord.groupIdBySet(groups);
    List<String> groupIdList = new ArrayList<>();
    groupIdList.add(groupId);
    if (groupId.indexOf(",") != -1) {
        String[] split = groupId.split(",");
        for (String s : split) {
            groupIdList.add(s);
        }
    }
    Page<SearchWord> searchWords = this.searchWordManager.findByWordAndGroupIdIn(page, word, groupIdList);
    return filterNull(searchWords);
}
Also used : Group(com.topcom.cms.domain.Group) CurrentUser(com.topcom.cms.web.bind.annotation.CurrentUser) User(com.topcom.cms.domain.User) SearchWord(com.topcom.cms.domain.SearchWord) PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 7 with CurrentUser

use of com.topcom.cms.web.bind.annotation.CurrentUser 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;
}
Also used : CurrentUser(com.topcom.cms.web.bind.annotation.CurrentUser) User(com.topcom.cms.domain.User) PublicResource(com.topcom.cms.perm.annotation.PublicResource) Resource(com.topcom.cms.domain.Resource) ApiOperation(io.swagger.annotations.ApiOperation)

Example 8 with CurrentUser

use of com.topcom.cms.web.bind.annotation.CurrentUser 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

CurrentUser (com.topcom.cms.web.bind.annotation.CurrentUser)8 User (com.topcom.cms.domain.User)7 ApiOperation (io.swagger.annotations.ApiOperation)4 Group (com.topcom.cms.domain.Group)3 Resource (com.topcom.cms.domain.Resource)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 SearchWord (com.topcom.cms.domain.SearchWord)2 PublicResource (com.topcom.cms.perm.annotation.PublicResource)2 PageRequest (org.springframework.data.domain.PageRequest)2 Pageable (org.springframework.data.domain.Pageable)2 Sort (org.springframework.data.domain.Sort)2 Application (com.topcom.cms.domain.Application)1 BusinessException (com.topcom.cms.exception.BusinessException)1 UnLoginException (com.topcom.cms.perm.exception.UnLoginException)1 ViewLogDto (com.topcom.cms.vo.ViewLogDto)1 ViewLogRequest (com.topcom.cms.vo.ViewLogRequest)1 ArrayList (java.util.ArrayList)1