Search in sources :

Example 1 with SearchWord

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

the class SearchWordController method findByType.

/**
 * 热词查询 查询排名前 limit 的word
 * @return
 */
@RequestMapping(method = RequestMethod.GET, value = "/findByType", produces = "application/json")
@ResponseBody
public List<SearchWord> findByType(@CurrentUser User user, @ApiParam("limit") @RequestParam(required = true) Integer limit, @ApiParam("type") @RequestParam(required = true) Integer type) {
    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.findByTypeAndGroupIdIn(page, type, 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 2 with SearchWord

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

the class SearchWordManagerImpl method addClickCount.

@Override
public SearchWord addClickCount(Set<Group> groups, String word, Integer type) {
    String groupId = SearchWord.groupIdBySet(groups);
    SearchWord result = new SearchWord();
    List<SearchWord> searchWords = searchWordDao.findByWordAndTypeAndGroupId(word, type, groupId);
    if (searchWords != null && searchWords.size() > 0) {
        if (searchWords.size() > 1) {
            for (int i = 1; i < searchWords.size(); i++) {
                this.delete(searchWords.get(i).getId());
            }
        }
        result = searchWords.get(0);
        long wordCount = result.getWordCount();
        result.setWordCount(++wordCount);
        result.setDateModified(new Date());
    } else {
        result.setType(type);
        result.setWord(word);
        result.setGroupId(groupId);
        result.setWordCount(1);
    }
    return this.save(result);
}
Also used : SearchWord(com.topcom.cms.domain.SearchWord) Date(java.util.Date)

Example 3 with SearchWord

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

the class SearchWordController method filterNull.

private List<SearchWord> filterNull(Page<SearchWord> searchWords) {
    List<SearchWord> result = new ArrayList<>();
    Set<String> s_set = new HashSet<>();
    for (int i = 0; i < searchWords.getContent().size(); i++) {
        SearchWord searchWord = searchWords.getContent().get(i);
        if (!StringUtils.isEmpty(searchWord.getWord())) {
            if (!result.contains(searchWord)) {
                result.add(searchWord);
            }
        }
    }
    return result;
}
Also used : SearchWord(com.topcom.cms.domain.SearchWord)

Example 4 with SearchWord

use of com.topcom.cms.domain.SearchWord 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)

Aggregations

SearchWord (com.topcom.cms.domain.SearchWord)4 Group (com.topcom.cms.domain.Group)2 User (com.topcom.cms.domain.User)2 CurrentUser (com.topcom.cms.web.bind.annotation.CurrentUser)2 PageRequest (org.springframework.data.domain.PageRequest)2 Pageable (org.springframework.data.domain.Pageable)2 Sort (org.springframework.data.domain.Sort)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 Date (java.util.Date)1