Search in sources :

Example 6 with Adoption

use of com.ch999.haha.admin.entity.Adoption in project haha by hahafreeasair666.

the class NewsServiceImpl method getNewsById.

@Override
public NewsDetailVO getNewsById(Integer id, Integer userId) {
    NewsDetailVO newsDetailVO = newsMapper.selectNewsDetail(id);
    if (newsDetailVO != null) {
        // 是否已赞
        if (userId != null && newsDetailVO.getZan() > 0) {
            CommentZanBO one = commentZanRepository.findOne(id.toString());
            if (one != null && one.getZanUserList().stream().anyMatch(userId::equals)) {
                newsDetailVO.setIsPraised(true);
            } else {
                newsDetailVO.setIsPraised(false);
            }
        } else {
            newsDetailVO.setIsPraised(false);
        }
        // 是否能收藏
        Wrapper<NewsCollections> wrapper = new EntityWrapper<>();
        wrapper.eq("userid", userId).eq("newid", id);
        if (newsCollectionsService.selectCount(wrapper) > 0) {
            newsDetailVO.setIsCanCollection(false);
        } else {
            newsDetailVO.setIsCanCollection(true);
        }
        if (StringUtils.isNotBlank(newsDetailVO.getPic())) {
            String[] split = newsDetailVO.getPic().split(",");
            List<String> imgMap = new ArrayList<>();
            List<Imgs> imgs = imgsService.selectBatchIds(Arrays.asList(split));
            imgs.forEach(li -> imgMap.add(li.getImgUrl()));
            newsDetailVO.setPicMap(imgMap);
        }
        // 是否能收养
        Wrapper<Adoption> wrapper1 = new EntityWrapper<>();
        wrapper1.eq("adoptionid", newsDetailVO.getId()).eq("isadoption", 0);
        if (CollectionUtils.isNotEmpty(adoptionService.selectList(wrapper1))) {
            newsDetailVO.setIsCanAdoption(true);
        } else {
            newsDetailVO.setIsCanAdoption(false);
        }
        // 组装父公告id
        if (newsDetailVO.getParentId() != null) {
            News news = this.selectById(newsDetailVO.getParentId());
            Map<String, Object> map = new HashMap<>();
            map.put("id", news.getId());
            map.put("title", news.getTitle());
            newsDetailVO.setParentNews(map);
        }
        // 组装反馈公告id
        List<News> news = this.selectList(new EntityWrapper<News>().eq("parentid", id).orderBy("createtime", false));
        if (CollectionUtils.isNotEmpty(news)) {
            Map<String, Object> map = new HashMap<>();
            map.put("id", news.get(0).getId());
            map.put("title", news.get(0).getTitle());
            newsDetailVO.setFeedBackNews(map);
        }
    }
    return newsDetailVO;
}
Also used : NewsDetailVO(com.ch999.haha.admin.vo.NewsDetailVO) EntityWrapper(com.baomidou.mybatisplus.mapper.EntityWrapper) JSONObject(com.alibaba.fastjson.JSONObject) CommentZanBO(com.ch999.haha.admin.document.redis.CommentZanBO)

Aggregations

EntityWrapper (com.baomidou.mybatisplus.mapper.EntityWrapper)6 Adoption (com.ch999.haha.admin.entity.Adoption)4 News (com.ch999.haha.admin.entity.News)4 AdoptionRequest (com.ch999.haha.admin.entity.AdoptionRequest)3 Date (java.util.Date)3 JSONObject (com.alibaba.fastjson.JSONObject)1 CommentZanBO (com.ch999.haha.admin.document.redis.CommentZanBO)1 AdoptionFeedBack (com.ch999.haha.admin.entity.AdoptionFeedBack)1 MyAdoptionVO (com.ch999.haha.admin.vo.MyAdoptionVO)1 NewsDetailVO (com.ch999.haha.admin.vo.NewsDetailVO)1 PageVO (com.ch999.haha.admin.vo.PageVO)1 AdoptionSuccessNewsVO (com.ch999.haha.admin.vo.mappervo.AdoptionSuccessNewsVO)1 ArrayList (java.util.ArrayList)1 Scheduled (org.springframework.scheduling.annotation.Scheduled)1