Authored by 周少峰

Merge branch 'test6.9.7' of git.yoho.cn:platform/platform-cms into test6.9.7

... ... @@ -35,23 +35,20 @@ public class GrassRefreshCacheServiceImpl implements IGrassRefreshCacheService{
return;
}
logger.info("refreshGrassCache: param is {}", reqVO);
executorService.execute(new Runnable() {
@Override
public void run() {
String elementId = reqVO.getElementId();
int clearCode = reqVO.getClearCode();
int uid = reqVO.getUid();
Integer topicId = reqVO.getTopicId() ;
try{
String url = apiUrl + "?method=clear.grass.cache&elementId=" + elementId + "&clearCode=" + clearCode + "&uid=" + uid+"&userType=" +reqVO.getUserType();
if(topicId != null){
url += "&topicId=" + topicId;
}
logger.info("before refreshGrassCache, url is: {}, reqVo is {}", url, reqVO);
serviceCaller.get("app.clearGrassCache", url, null, String.class, null);
}catch (Exception e){
logger.info("failed refreshGrassCache, reqVo is {}, error is {}", reqVO, e);
executorService.execute(() -> {
String elementId = reqVO.getElementId();
int clearCode = reqVO.getClearCode();
int uid = reqVO.getUid();
Integer topicId = reqVO.getTopicId() ;
try{
String url = apiUrl + "?method=clear.grass.cache&elementId=" + elementId + "&clearCode=" + clearCode + "&uid=" + uid+"&userType=" +reqVO.getUserType();
if(topicId != null){
url += "&topicId=" + topicId;
}
logger.info("before refreshGrassCache, url is: {}, reqVo is {}", url, reqVO);
serviceCaller.get("app.clearGrassCache", url, null, String.class, null);
}catch (Exception e){
logger.info("failed refreshGrassCache, reqVo is {}, error is {}", reqVO, e);
}
});
}
... ...
... ... @@ -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);
}
}
... ...
... ... @@ -41,6 +41,9 @@
<input class="easyui-combobox" id="isHotParam">
</input>
<input class="easyui-combobox" id="hasArticleTop">
</input>
<input class="easyui-textbox" id="topicNameParam" style="width: 140px">
</input>
... ... @@ -110,6 +113,14 @@
data: [{text: "全部", value: "8"}, {text: "热门", value: "1"}, {text: "非热门", value: "0"}]
});
$("#hasArticleTop").combobox({
valueField: "value",
textField: "text",
required: false,
prompt: "置顶状态",
data: [{text: "请选择", value: "-1"},{text: "已置顶", value: "1"}, {text: "未置顶", value: "0"}]
});
$("#topicNameParam").textbox({
required: false,
... ... @@ -141,7 +152,8 @@
topicName: $("#topicNameParam").textbox("getValue"),
groupName: $("#topicGroupParam").textbox("getValue"),
startTime: startTime,
endTime: endTime
endTime: endTime,
hasArticleTop:$("#hasArticleTop").combobox("getValue")
});
}
});
... ... @@ -546,29 +558,29 @@
param.id = data.id;
}
//表单基本检查
if (!$("#setTopForm").form("validate")) {
return false;
}
//校验最多可填五个内容id
var articleStr = $("#setTopForm #topArticleIdsStr").textbox("getValue");
var articleArray = articleStr.split(',');
for(var i = 0; i < articleArray.length; i++){
if(isNaN(articleArray[i])){
$.messager.alert("提示", "非数字字符不允许提交!", "");
if(articleStr == undefined || articleStr == ""){
param.topArticleIds = "";
}else{
var articleArray = articleStr.split(',');
for(var i = 0; i < articleArray.length; i++){
if(isNaN(articleArray[i])){
$.messager.alert("提示", "非数字字符不允许提交!", "");
return false;
}
}
if(articleArray.length > 5){
$.messager.alert("提示", "填写不可超过五个内容ID!", "");
return false;
}
if(articleStr.charAt(articleStr.length - 1) == ','){
param.topArticleIds = articleStr.substring(0,articleStr.length - 1);
}else{
param.topArticleIds = articleStr;
}
}
if(articleArray.length > 5){
$.messager.alert("提示", "填写不可超过五个内容ID!", "");
return false;
}
if(articleStr.charAt(articleStr.length - 1) == ','){
param.topArticleIds = articleStr.substring(0,articleStr.length - 1);
}else{
param.topArticleIds = articleStr;
}
$.messager.progress({
title: "正在执行",
... ...
... ... @@ -5,8 +5,8 @@
<table border="0" style="width:95%;margin-top:5px;line-height:30px;" id="tab">
<tr style="height: 60px">
<td>
<span style="color:red">*</span><label>内容ID</label> <br>
<input id="topArticleIdsStr" name="topArticleIdsStr" class="easyui-textbox" style="width: 350px;" /><br>
<label>内容ID</label> <br>
<input id="topArticleIdsStr" name="topArticleIdsStr" class="easyui-textbox" style="width: 70%;" /><br>
<span style="color:red">注:至多填写5个,设置的内容必须关联该话题</span>
</td>
</tr>
... ... @@ -21,7 +21,7 @@
$(function () {
$("#setTopForm #topArticleIdsStr").textbox({
required: true,
required: false,
missingMessage: "内容ID不能为空",
prompt: "  填写置顶的内容ID,且以半角逗号隔开"
});
... ...