...
|
...
|
@@ -8,9 +8,11 @@ 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.GrassTopic;
|
|
|
import com.yohobuy.platform.grass.service.IGrassRefreshCacheService;
|
|
|
import com.yohobuy.platform.grass.service.ITopicService;
|
|
|
import com.yohobuy.platform.model.common.ApiResponse;
|
|
|
import com.yohobuy.platform.model.common.PageResponseVO;
|
|
|
import com.yohobuy.platform.model.grass.request.GrassCacheReq;
|
|
|
import com.yohobuy.platform.model.grass.request.GrassTopicReq;
|
|
|
import com.yohobuy.platform.model.grass.response.TopicRespBo;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
...
|
...
|
@@ -44,6 +46,9 @@ public class TopicServiceImpl implements ITopicService { |
|
|
@Autowired
|
|
|
private IGrassArticleTopicDao articleTopicDao;
|
|
|
|
|
|
@Autowired
|
|
|
private IGrassRefreshCacheService grassRefreshCacheService;
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public PageResponseVO<TopicRespBo> getGrassTopicList(GrassTopicReq req) {
|
...
|
...
|
@@ -56,10 +61,11 @@ public class TopicServiceImpl implements ITopicService { |
|
|
String groupName = req.getGroupName();
|
|
|
Integer startTime = req.getStartTime();
|
|
|
Integer endTime = req.getEndTime();
|
|
|
int total = grassTopicDAO.countByCondition(status,isOfficial,topicName,groupName,isHot,startTime,endTime);
|
|
|
req.setHasArticleTop((req.getHasArticleTop() != null && req.getHasArticleTop() == -1) ? null : req.getHasArticleTop());
|
|
|
int total = grassTopicDAO.countByCondition(status,isOfficial,topicName,groupName,isHot,startTime,endTime,req.getHasArticleTop());
|
|
|
List<TopicRespBo> pageData = new ArrayList<>();
|
|
|
if(total > 0){
|
|
|
List<GrassTopic> list = grassTopicDAO.selectByPageCondition(status,isOfficial,topicName,groupName,isHot,startTime,endTime,req.getStart(),req.getSize());
|
|
|
List<GrassTopic> list = grassTopicDAO.selectByPageCondition(status,isOfficial,topicName,groupName,isHot,startTime,endTime,req.getStart(),req.getSize(),req.getHasArticleTop());
|
|
|
pageData = convertTopicRespBo(list);
|
|
|
}
|
|
|
PageResponseVO responseVO = new PageResponseVO();
|
...
|
...
|
@@ -203,6 +209,16 @@ public class TopicServiceImpl implements ITopicService { |
|
|
logger.warn("addArticlesTop with topicId null");
|
|
|
return new ApiResponse(201,"话题id不可为空!");
|
|
|
}
|
|
|
int updateTime = DateUtil.getCurrentTimeSeconds();
|
|
|
if(StringUtils.isEmpty(req.getTopArticleIds())){
|
|
|
//该种情况取消该话题下的置顶
|
|
|
articleTopicDao.updateTopByTopicId(req.getId(),updateTime);
|
|
|
setTopicHasTop(req, 0);
|
|
|
logger.info("end addArticlesTop with cancel all top,topicId:{}",req.getId());
|
|
|
//清空前台话题关联文章列表缓存
|
|
|
clearTopicRelatedArticlesCache(req.getId());
|
|
|
return new ApiResponse();
|
|
|
}
|
|
|
//校验设定的内容id是否是该话题下的
|
|
|
List<String> articleStrList = Arrays.asList(req.getTopArticleIds().split(","));
|
|
|
List<Integer> articleList = articleStrList.stream().map(Integer::valueOf).collect(Collectors.toList());
|
...
|
...
|
@@ -218,12 +234,37 @@ public class TopicServiceImpl implements ITopicService { |
|
|
return new ApiResponse(202,"所填内容id" + articleList + "不是该话题下的文章!");
|
|
|
}
|
|
|
//将该话题下的所有文章取消置顶
|
|
|
int updateTime = DateUtil.getCurrentTimeSeconds();
|
|
|
articleTopicDao.updateTopByTopicId(req.getId(),updateTime);
|
|
|
|
|
|
//将指定文章写入 话题-文章关联表
|
|
|
int result = articleTopicDao.updateTopByArticles(validArticles,1,updateTime);
|
|
|
//设置该话题有置顶文章标识
|
|
|
setTopicHasTop(req, 1);
|
|
|
logger.info("end addArticlesTop,req:{},result:{}",req,result);
|
|
|
|
|
|
//清空前台话题关联文章列表缓存
|
|
|
clearTopicRelatedArticlesCache(req.getId());
|
|
|
return new ApiResponse(result);
|
|
|
}
|
|
|
|
|
|
private void setTopicHasTop(GrassTopicReq req, int hasArticleTop) {
|
|
|
GrassTopic topic = new GrassTopic();
|
|
|
topic.setId(req.getId());
|
|
|
topic.setHasArticleTop(hasArticleTop);
|
|
|
grassTopicDAO.updateByPrimaryKeySelective(topic);
|
|
|
}
|
|
|
|
|
|
private void clearTopicRelatedArticlesCache(Integer topicId) {
|
|
|
logger.info("clearTopicRelatedArticlesCache, type=1001");
|
|
|
//清空最热文章列表
|
|
|
GrassCacheReq cacheReq = new GrassCacheReq();
|
|
|
cacheReq.setClearCode(1007);
|
|
|
cacheReq.setTopicId(topicId);
|
|
|
cacheReq.setElementId(String.valueOf(1));
|
|
|
grassRefreshCacheService.refreshGrassCache(cacheReq);
|
|
|
|
|
|
//清空最新文章列表
|
|
|
cacheReq.setElementId(String.valueOf(2));
|
|
|
grassRefreshCacheService.refreshGrassCache(cacheReq);
|
|
|
}
|
|
|
} |
...
|
...
|
|