Search in sources :

Example 81 with Pageable

use of org.springframework.data.domain.Pageable in project ArachneCentralAPI by OHDSI.

the class BaseStudyController method getStudyInsights.

@ApiOperation("Get recent Insights of Study")
@RequestMapping(value = "/api/v1/study-management/studies/{studyId}/insights", method = GET)
public List<SubmissionInsightDTO> getStudyInsights(@PathVariable("studyId") Long studyId, @RequestParam(value = "size", required = false) Integer size, @RequestParam(value = "commentsPerInsight", required = false) Integer commentsPerInsight, @RequestParam(value = "order", required = false) Sort.Direction order) {
    if (size == null) {
        size = Integer.MAX_VALUE;
    }
    if (commentsPerInsight == null) {
        commentsPerInsight = Integer.MAX_VALUE;
    }
    if (order == null) {
        order = Sort.Direction.DESC;
    }
    List<SubmissionInsightDTO> submissionInsightDTOS = new ArrayList<>();
    Pageable pageRequest = PageRequest.of(0, size, Sort.by(order, "created"));
    final Page<SubmissionInsight> page = submissionInsightService.getInsightsByStudyId(studyId, pageRequest);
    final List<SubmissionInsight> insights = page.getContent();
    for (int i = 0; i < insights.size(); i++) {
        final SubmissionInsight insight = insights.get(i);
        final Set<CommentTopic> recentTopics = submissionInsightService.getInsightComments(insight, commentsPerInsight, Sort.by(Sort.Direction.DESC, "id"));
        final SubmissionInsightDTO insightDTO = conversionService.convert(insight, SubmissionInsightDTO.class);
        final List<Commentable> recentCommentables = getRecentCommentables(conversionService, recentTopics, insightDTO);
        insightDTO.setRecentCommentEntities(recentCommentables);
        submissionInsightDTOS.add(insightDTO);
    }
    if (LOG.isDebugEnabled()) {
        submissionInsightDTOS.stream().forEach(submissionInsightDTO -> {
            LOG.debug("+" + submissionInsightDTO.getName());
            submissionInsightDTO.getRecentCommentEntities().stream().forEach(commentable -> {
                LOG.debug("|+" + commentable.getName());
                commentable.getTopic().getComments().stream().forEach(commentDTO -> {
                    LOG.debug(" |-" + commentDTO.getAuthor().getFirstname() + ":" + commentDTO.getDate() + ":" + commentDTO.getComment());
                });
            });
        });
    }
    return submissionInsightDTOS;
}
Also used : SubmissionInsightDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionInsightDTO) Pageable(org.springframework.data.domain.Pageable) ArrayList(java.util.ArrayList) Commentable(com.odysseusinc.arachne.portal.api.v1.dto.Commentable) CommentTopic(com.odysseusinc.arachne.portal.model.CommentTopic) SubmissionInsight(com.odysseusinc.arachne.portal.model.SubmissionInsight) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 82 with Pageable

use of org.springframework.data.domain.Pageable in project ArachneCentralAPI by OHDSI.

the class CommentServiceImpl method list.

@Override
public Set<CommentTopic> list(Set<CommentTopic> topics, Integer size, Sort sort) {
    Pageable pageable = PageRequest.of(0, size, sort);
    final Page<Comment> page = commentRepository.getAllByTopicIn(topics, pageable);
    final List<Comment> comments = page.getContent();
    comments.forEach(comment -> connectToTopic(topics, comment));
    return comments.stream().map(Comment::getTopic).collect(Collectors.toCollection(LinkedHashSet::new));
}
Also used : Comment(com.odysseusinc.arachne.portal.model.Comment) Pageable(org.springframework.data.domain.Pageable)

Example 83 with Pageable

use of org.springframework.data.domain.Pageable in project topcom-cloud by 545314690.

the class TjsEnforcementController method findByCompanyId.

@ApiOperation("根据企业id查找")
@RequestMapping(value = { "findByCompany" }, method = { RequestMethod.GET }, produces = { "application/json" })
@ResponseBody
public Page<TjsEnforcement> findByCompanyId(@RequestParam Long companyId, @RequestParam Integer page, @RequestParam Integer limit, @RequestParam String startDate, @RequestParam String endDate) {
    Pageable pageable = new PageRequest(page - 1, limit);
    DateParam dateParam = new DateParam(startDate, endDate);
    return tjsEnforcementManager.findByCompanyIdAndZFJCJZSJBetween(companyId, dateParam.startDate(), dateParam.endDate(), pageable);
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) DateParam(com.topcom.cms.common.page.DateParam) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 84 with Pageable

use of org.springframework.data.domain.Pageable in project haha by hahafreeasair666.

the class NewsCommentServiceImpl method getNewsCommentList.

@Override
public PageVO<NewsCommentBO> getNewsCommentList(Integer newsId, Pageable pageable, Integer userId) {
    Page<NewsCommentBO> allByNewsIdAndIsDel = newsCommentRepository.findAllByNewsIdAndIsDel(newsId, false, pageable);
    List<NewsCommentBO> commentList = allByNewsIdAndIsDel.getContent();
    commentList.forEach(li -> {
        // 评论中评论的回复只显示未删除的点赞最多的三条
        if (li.getReplies().size() > 3) {
            li.setReplies(li.getReplies().stream().filter(de -> !de.getIsDel()).sorted(Comparator.comparing(NewsCommentBO.Reply::getZan).reversed()).collect(Collectors.toList()).subList(0, 3));
            li.setIsNeedOpen(true);
        } else {
            li.setIsNeedOpen(false);
        }
        // 评论字段赋值
        UserInfo userInfo = userInfoService.selectById(li.getUserId());
        li.setUserName(userInfo.getUsername());
        li.setAvatar(userInfo.getPicPath());
        if (li.getZan() > 0 && userId != null) {
            CommentZanBO zanInfo = commentZanRepository.findOne(li.getId());
            if (zanInfo != null && zanInfo.getZanUserList().parallelStream().anyMatch(zan -> zan.equals(userId))) {
                li.setIsPraised(true);
            } else {
                li.setIsPraised(false);
            }
        } else {
            li.setIsPraised(false);
        }
        // 设置能否删除该评论字段
        if (li.getUserId().equals(userId)) {
            li.setIsCanDel(true);
        } else {
            li.setIsCanDel(false);
        }
        // 回复字段赋值
        li.getReplies().forEach(re -> handleReplies(re, userId));
    });
    return new PageVO(allByNewsIdAndIsDel, pageable.getPageNumber(), commentList);
}
Also used : java.util(java.util) CommentZanRepository(com.ch999.haha.admin.repository.redis.CommentZanRepository) PageVO(com.ch999.haha.admin.vo.PageVO) Resource(javax.annotation.Resource) NewsCommentService(com.ch999.haha.admin.service.NewsCommentService) StopWatch(org.springframework.util.StopWatch) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) NewsCommentBO(com.ch999.haha.admin.document.mongo.NewsCommentBO) UserInfoService(com.ch999.haha.admin.service.UserInfoService) CommentReplyVO(com.ch999.haha.admin.vo.CommentReplyVO) CollectionUtils(org.apache.commons.collections.CollectionUtils) PageableVo(com.ch999.haha.common.PageableVo) Service(org.springframework.stereotype.Service) UserInfo(com.ch999.haha.admin.entity.UserInfo) CommentZanBO(com.ch999.haha.admin.document.redis.CommentZanBO) NewsCommentRepository(com.ch999.haha.admin.repository.mongo.NewsCommentRepository) Pageable(org.springframework.data.domain.Pageable) PageVO(com.ch999.haha.admin.vo.PageVO) UserInfo(com.ch999.haha.admin.entity.UserInfo) NewsCommentBO(com.ch999.haha.admin.document.mongo.NewsCommentBO) CommentZanBO(com.ch999.haha.admin.document.redis.CommentZanBO)

Example 85 with Pageable

use of org.springframework.data.domain.Pageable 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)

Aggregations

Pageable (org.springframework.data.domain.Pageable)172 PageRequest (org.springframework.data.domain.PageRequest)91 Sort (org.springframework.data.domain.Sort)79 Test (org.junit.Test)39 PageImpl (org.springframework.data.domain.PageImpl)24 Collectors (java.util.stream.Collectors)17 Page (org.springframework.data.domain.Page)16 ArrayList (java.util.ArrayList)14 Autowired (org.springframework.beans.factory.annotation.Autowired)14 GetMapping (org.springframework.web.bind.annotation.GetMapping)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 List (java.util.List)11 UUID (java.util.UUID)10 ApiOperation (io.swagger.annotations.ApiOperation)9 Calendar (java.util.Calendar)9 Test (org.junit.jupiter.api.Test)9 java.util (java.util)8 Lists (com.google.common.collect.Lists)7 Map (java.util.Map)6 Transactional (org.springframework.transaction.annotation.Transactional)6