Search in sources :

Example 1 with MyAdoptionVO

use of com.ch999.haha.admin.vo.MyAdoptionVO in project haha by hahafreeasair666.

the class AdoptionRequestServiceImpl method getMyAdoptionList.

@Override
public PageVO<MyAdoptionVO> getMyAdoptionList(Integer userId, Integer currentPage) {
    Integer size = 10;
    Wrapper<AdoptionRequest> wrapper = new EntityWrapper<>();
    wrapper.eq("userid", userId);
    List<MyAdoptionVO> list = new ArrayList<>();
    List<AdoptionRequest> adoptionRequests = this.selectList(wrapper);
    PageVO<MyAdoptionVO> pageVO = new PageVO<>();
    pageVO.setTotalPage((int) Math.ceil(adoptionRequests.size() / (double) size));
    pageVO.setCurrentPage(currentPage);
    if (CollectionUtils.isNotEmpty(adoptionRequests)) {
        if (adoptionRequests.size() > size * (currentPage - 1)) {
            adoptionRequests = adoptionRequests.subList(size * (currentPage - 1), size * currentPage > adoptionRequests.size() ? adoptionRequests.size() : size * currentPage);
        } else {
            adoptionRequests = new ArrayList<>();
        }
        adoptionRequests.forEach(li -> {
            News news = newsService.selectById(li.getNewsId());
            MyAdoptionVO myAdoptionVO = new MyAdoptionVO();
            myAdoptionVO.setNewsId(li.getNewsId());
            myAdoptionVO.setTitle(news.getTitle());
            // 组装领养成功与否状态
            Adoption adoption = adoptionService.selectOne(new EntityWrapper<Adoption>().eq("adoptionid", li.getNewsId()));
            if (adoption.getIsAdoption()) {
                myAdoptionVO.setIsSuccess(adoption.getUserId().equals(userId) ? 1 : 2);
            } else {
                myAdoptionVO.setIsSuccess(0);
            }
            myAdoptionVO.setPic(getOnePicPath(news));
            list.add(myAdoptionVO);
        });
    }
    pageVO.setList(list);
    return pageVO;
}
Also used : AdoptionRequest(com.ch999.haha.admin.entity.AdoptionRequest) PageVO(com.ch999.haha.admin.vo.PageVO) ArrayList(java.util.ArrayList) MyAdoptionVO(com.ch999.haha.admin.vo.MyAdoptionVO) News(com.ch999.haha.admin.entity.News) EntityWrapper(com.baomidou.mybatisplus.mapper.EntityWrapper) Adoption(com.ch999.haha.admin.entity.Adoption)

Aggregations

EntityWrapper (com.baomidou.mybatisplus.mapper.EntityWrapper)1 Adoption (com.ch999.haha.admin.entity.Adoption)1 AdoptionRequest (com.ch999.haha.admin.entity.AdoptionRequest)1 News (com.ch999.haha.admin.entity.News)1 MyAdoptionVO (com.ch999.haha.admin.vo.MyAdoptionVO)1 PageVO (com.ch999.haha.admin.vo.PageVO)1 ArrayList (java.util.ArrayList)1