...
|
...
|
@@ -2,22 +2,16 @@ package com.yohobuy.platform.grass.service.impl; |
|
|
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.yohobuy.platform.common.util.BeanTool;
|
|
|
import com.yohobuy.platform.common.util.CollectionUtil;
|
|
|
import com.yohobuy.platform.common.util.DateUtil;
|
|
|
import com.yohobuy.platform.common.util.StringUtil;
|
|
|
import com.yohobuy.platform.dal.grass.*;
|
|
|
import com.yohobuy.platform.dal.grass.model.GrassArticle;
|
|
|
import com.yohobuy.platform.dal.grass.IGrassArticleTopicDao;
|
|
|
import com.yohobuy.platform.dal.grass.IGrassTopicDAO;
|
|
|
import com.yohobuy.platform.dal.grass.IGrassTopicGroupDAO;
|
|
|
import com.yohobuy.platform.dal.grass.model.GrassArticleTopic;
|
|
|
import com.yohobuy.platform.dal.grass.model.GrassLabel;
|
|
|
import com.yohobuy.platform.dal.grass.model.GrassTopic;
|
|
|
import com.yohobuy.platform.grass.service.ITopicService;
|
|
|
import com.yohobuy.platform.grass.service.IlabelService;
|
|
|
import com.yohobuy.platform.model.common.ApiResponse;
|
|
|
import com.yohobuy.platform.model.common.PageResponseVO;
|
|
|
import com.yohobuy.platform.model.grass.request.GrassLabelReq;
|
|
|
import com.yohobuy.platform.model.grass.request.GrassTopicReq;
|
|
|
import com.yohobuy.platform.model.grass.response.GrassLabelBo;
|
|
|
import com.yohobuy.platform.model.grass.response.TopicRespBo;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
...
|
...
|
@@ -26,9 +20,11 @@ import org.slf4j.LoggerFactory; |
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.NumberUtils;
|
|
|
|
|
|
import java.util.*;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
...
|
...
|
@@ -174,6 +170,9 @@ public class TopicServiceImpl implements ITopicService { |
|
|
//查询文章表 统计话题下的文章数(不考虑文章状态)
|
|
|
List<GrassArticleTopic> topicList = articleTopicDao.countBytopicIds(topicIds);
|
|
|
Map<Integer,Integer> topicMap = topicList.stream().collect(Collectors.toMap(GrassArticleTopic::getTopicId, obj -> obj.getNum()));
|
|
|
//查询话题文章关联表,获取话题被置顶的文章ids
|
|
|
List<GrassArticleTopic> topArticles = articleTopicDao.selectTopsByTopicIds(topicIds);
|
|
|
Map<Integer, List<GrassArticleTopic>> articleTopMap = topArticles.stream().collect(Collectors.groupingBy(GrassArticleTopic::getTopicId));
|
|
|
|
|
|
for(GrassTopic grassTopic : sourceList){
|
|
|
TopicRespBo bo = new TopicRespBo();
|
...
|
...
|
@@ -181,8 +180,48 @@ public class TopicServiceImpl implements ITopicService { |
|
|
bo.setUpdateTimeStr(grassTopic.getUpdateTime() == null ? "" : DateUtil.int2DateStr(grassTopic.getUpdateTime(),"yyyy-MM-dd HH:mm:ss"));
|
|
|
//相关的文章
|
|
|
bo.setArticleAmount(topicMap.get(bo.getId()) == null ? 0 : topicMap.get(bo.getId()));
|
|
|
//若该话题下有置顶的文章 则获取置顶文章','间隔
|
|
|
if(articleTopMap != null && articleTopMap.get(grassTopic.getId()) != null){
|
|
|
List<Integer> topArticleIds = articleTopMap.get(grassTopic.getId()).stream().map(GrassArticleTopic::getArticleId).collect(Collectors.toList());
|
|
|
bo.setTopArticles(StringUtils.join(topArticleIds,","));
|
|
|
}
|
|
|
result.add(bo);
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 设置某话题下文章置顶
|
|
|
* @param req
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
public ApiResponse addArticlesTop(GrassTopicReq req){
|
|
|
if(req.getId() == null){
|
|
|
logger.warn("addArticlesTop with topicId null");
|
|
|
return new ApiResponse(201,"话题id不可为空!");
|
|
|
}
|
|
|
//校验设定的内容id是否是该话题下的
|
|
|
List<String> articleStrList = Arrays.asList(req.getTopArticleIds().split(","));
|
|
|
List<Integer> articleList = articleStrList.stream().map(Integer::valueOf).collect(Collectors.toList());
|
|
|
List<GrassArticleTopic> articleTopics = articleTopicDao.selectByArticleIdList(articleList);
|
|
|
if(CollectionUtils.isEmpty(articleTopics)){
|
|
|
logger.warn("the articleIds all is not valid,req:{}",req);
|
|
|
return new ApiResponse(202,"所填内容id均不是该话题下的文章!");
|
|
|
}
|
|
|
List<Integer> validArticles = articleTopics.stream().map(GrassArticleTopic::getArticleId).collect(Collectors.toList());
|
|
|
articleList.removeAll(validArticles);
|
|
|
if(CollectionUtils.isNotEmpty(articleList)){
|
|
|
logger.warn("these articleIds is not valid,topicId:{},invalid:{}",req.getId(),articleList);
|
|
|
return new ApiResponse(202,"所填内容id" + articleList + "不是该话题下的文章!");
|
|
|
}
|
|
|
//将该话题下的所有文章取消置顶
|
|
|
int updateTime = DateUtil.getCurrentTimeSeconds();
|
|
|
articleTopicDao.updateTopByTopicId(req.getId(),updateTime);
|
|
|
|
|
|
//将指定文章写入 话题-文章关联表
|
|
|
int result = articleTopicDao.updateTopByArticles(articleList,1,updateTime);
|
|
|
logger.info("end addArticlesTop,req:{},result:{}",req,result);
|
|
|
return new ApiResponse(result);
|
|
|
}
|
|
|
} |
...
|
...
|
|