Authored by min.ling

话题内容置顶

... ... @@ -67,4 +67,10 @@ public class GrassTopicController {
List<TopicRespBo> result = topicService.getAllTopic();
return new ApiResponse.ApiResponseBuilder().data(result).build();
}*/
@RequestMapping("/addArticlesTop")
@ResponseBody
public ApiResponse addArticlesTop(@RequestBody GrassTopicReq req){
return topicService.addArticlesTop(req);
}
}
... ...
package com.yohobuy.platform.grass.service;
import com.yohobuy.platform.dal.grass.model.GrassTopic;
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 java.util.List;
... ... @@ -23,4 +20,11 @@ public interface ITopicService {
void changeTopicStatus(GrassTopicReq req);
ApiResponse changeTopicHotStatus(GrassTopicReq req);
/**
* 设置某话题下文章置顶
* @param req
* @return
*/
ApiResponse addArticlesTop(GrassTopicReq req);
}
... ...
... ... @@ -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);
}
}
... ...
... ... @@ -224,7 +224,20 @@
width: 25,
align: "left"
}, {
title: "状态",
title: "置顶状态",
field: "topStatus",
width: 25,
align: "left",
formatter: function (value, rowData, rowIndex) {
if (value == 1) {
return "已设置";
} else {
return "未设置";
}
}
}, {
title: "话题状态",
field: "status",
width: 25,
align: "left",
... ... @@ -254,10 +267,10 @@
str = "";//进行中的话题不可编辑
changeStatus = "<a role='changeStatus' style='margin-left:10px;background-color: #ffa951' changedStatus='0' dataId='" + rowData.id + "' index='" + rowIndex + "'>下架</a>";
}
debugger
if(rowData.isHot == 1){
changeHot = "<a role='changeHot' style='margin-left:10px;background-color: #ea40ff' changedStatus='0' dataId='" + rowData.id + "' index='" + rowIndex + "'>取消热门</a>";
}
str = str + "<a role='setTop' dataId='" + rowData.id + "' style='margin-left:10px;background-color: #31b0d5' index='" + rowIndex + "'>设置置顶</a>";
//编辑 上下架 复制链接 设置热门
return str + changeStatus + changeHot + link ;
... ... @@ -330,6 +343,17 @@
}
});
// 设置置顶
$(this).datagrid("getPanel").find("a[role='setTop']").linkbutton({
iconCls: "icon-edit",
onClick: function () {
index = $(this).attr("index");
var row = $("#labelListTable").datagrid('getData').rows[index];
setTopicTopDialog(row);
}
});
}
});
... ... @@ -494,7 +518,71 @@
}
}],
modal: true,
href: contextPath + "/html/grass/topicManage/topicEdit.html",
href: contextPath + "/html/grass/topicManage/topicEdit.html"
});
}
// 设置置顶
function setTopicTopDialog(data) {
var labelList = $("<div id='labelList'>").appendTo($(document.body));
var title = "设置置顶";
window.self.paramObject.mkData = data;
$(labelList).myDialog({
title: title,
width: "50%",
height: "50%",
resizable: false,
buttons: [{
id: "saveBtn",
text: "保存",
iconCls: "icon-save",
handler: function () {
$("#setTopForm").form("submit", {
url: serverContextPath + "/grassTopicManage/addArticlesTop",
onSubmit: function (param) {
if (data != null) {
param.id = data.id;
}
//1)表单基本检查
if (!$("#setTopForm").form("validate")) {
return false;
}
$.messager.progress({
title: "正在执行",
msg: "正在执行,请稍后..."
});
return true;
},
success: function (data) {
$.messager.progress("close");
data = JSON.parse(data);
if (data.code == 200) {
$(labelList).dialog("close");
$("#labelListTable").datagrid("reload");
$.messager.show({
title: "提示",
msg: title + "成功!",
height: 120
});
} else {
$.messager.alert("失败", "操作失败", "error");
}
}
});
}
}, {
text: "关闭",
iconCls: "icon-cancel",
handler: function () {
$(labelList).dialog("close");
}
}],
modal: true,
href: contextPath + "/html/grass/topicManage/topicSetTop.html"
});
}
... ...
<!DOCTYPE html>
<div id="tt" class="easyui-layout" fit="true" style="overflow-y: scroll">
<form name="setTopForm" id="setTopForm" method="post">
<div style="margin-top: 20px;margin-left: 30px">
<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="topArticleIds" name="topArticleIds" class="easyui-textbox" style="width: 500px;"/>
<td><span style="color:red">注:至多填写5个,设置的内容必须关联该话题</span></td>
</td>
</tr>
</table>
</div>
</form>
</div>
<script>
$(function () {
$("#setTopForm #topArticleIds").textbox({
required: true,
missingMessage: "内容ID不能为空",
prompt: "  填写置顶的内容ID,且以半角逗号隔开"
});
var data = paramObject.mkData;
if (data) {//编辑窗口
$("#topArticleIds").textbox("setValue", data.topArticles);
}else{
$("#topArticleIds").textbox("setValue", "");
}
});
</script>
</html>
... ...