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;
}
Aggregations