Showing
7 changed files
with
222 additions
and
21 deletions
@@ -67,4 +67,10 @@ public class GrassTopicController { | @@ -67,4 +67,10 @@ public class GrassTopicController { | ||
67 | List<TopicRespBo> result = topicService.getAllTopic(); | 67 | List<TopicRespBo> result = topicService.getAllTopic(); |
68 | return new ApiResponse.ApiResponseBuilder().data(result).build(); | 68 | return new ApiResponse.ApiResponseBuilder().data(result).build(); |
69 | }*/ | 69 | }*/ |
70 | + | ||
71 | + @RequestMapping("/addArticlesTop") | ||
72 | + @ResponseBody | ||
73 | + public ApiResponse addArticlesTop(@RequestBody GrassTopicReq req){ | ||
74 | + return topicService.addArticlesTop(req); | ||
75 | + } | ||
70 | } | 76 | } |
1 | package com.yohobuy.platform.grass.service; | 1 | package com.yohobuy.platform.grass.service; |
2 | 2 | ||
3 | -import com.yohobuy.platform.dal.grass.model.GrassTopic; | ||
4 | import com.yohobuy.platform.model.common.ApiResponse; | 3 | import com.yohobuy.platform.model.common.ApiResponse; |
5 | import com.yohobuy.platform.model.common.PageResponseVO; | 4 | import com.yohobuy.platform.model.common.PageResponseVO; |
6 | -import com.yohobuy.platform.model.grass.request.GrassLabelReq; | ||
7 | import com.yohobuy.platform.model.grass.request.GrassTopicReq; | 5 | import com.yohobuy.platform.model.grass.request.GrassTopicReq; |
8 | -import com.yohobuy.platform.model.grass.response.GrassLabelBo; | ||
9 | import com.yohobuy.platform.model.grass.response.TopicRespBo; | 6 | import com.yohobuy.platform.model.grass.response.TopicRespBo; |
10 | 7 | ||
11 | import java.util.List; | 8 | import java.util.List; |
@@ -23,4 +20,11 @@ public interface ITopicService { | @@ -23,4 +20,11 @@ public interface ITopicService { | ||
23 | void changeTopicStatus(GrassTopicReq req); | 20 | void changeTopicStatus(GrassTopicReq req); |
24 | 21 | ||
25 | ApiResponse changeTopicHotStatus(GrassTopicReq req); | 22 | ApiResponse changeTopicHotStatus(GrassTopicReq req); |
23 | + | ||
24 | + /** | ||
25 | + * 设置某话题下文章置顶 | ||
26 | + * @param req | ||
27 | + * @return | ||
28 | + */ | ||
29 | + ApiResponse addArticlesTop(GrassTopicReq req); | ||
26 | } | 30 | } |
@@ -2,22 +2,16 @@ package com.yohobuy.platform.grass.service.impl; | @@ -2,22 +2,16 @@ package com.yohobuy.platform.grass.service.impl; | ||
2 | 2 | ||
3 | 3 | ||
4 | import com.google.common.collect.Lists; | 4 | import com.google.common.collect.Lists; |
5 | -import com.yohobuy.platform.common.util.BeanTool; | ||
6 | -import com.yohobuy.platform.common.util.CollectionUtil; | ||
7 | import com.yohobuy.platform.common.util.DateUtil; | 5 | import com.yohobuy.platform.common.util.DateUtil; |
8 | -import com.yohobuy.platform.common.util.StringUtil; | ||
9 | -import com.yohobuy.platform.dal.grass.*; | ||
10 | -import com.yohobuy.platform.dal.grass.model.GrassArticle; | 6 | +import com.yohobuy.platform.dal.grass.IGrassArticleTopicDao; |
7 | +import com.yohobuy.platform.dal.grass.IGrassTopicDAO; | ||
8 | +import com.yohobuy.platform.dal.grass.IGrassTopicGroupDAO; | ||
11 | import com.yohobuy.platform.dal.grass.model.GrassArticleTopic; | 9 | import com.yohobuy.platform.dal.grass.model.GrassArticleTopic; |
12 | -import com.yohobuy.platform.dal.grass.model.GrassLabel; | ||
13 | import com.yohobuy.platform.dal.grass.model.GrassTopic; | 10 | import com.yohobuy.platform.dal.grass.model.GrassTopic; |
14 | import com.yohobuy.platform.grass.service.ITopicService; | 11 | import com.yohobuy.platform.grass.service.ITopicService; |
15 | -import com.yohobuy.platform.grass.service.IlabelService; | ||
16 | import com.yohobuy.platform.model.common.ApiResponse; | 12 | import com.yohobuy.platform.model.common.ApiResponse; |
17 | import com.yohobuy.platform.model.common.PageResponseVO; | 13 | import com.yohobuy.platform.model.common.PageResponseVO; |
18 | -import com.yohobuy.platform.model.grass.request.GrassLabelReq; | ||
19 | import com.yohobuy.platform.model.grass.request.GrassTopicReq; | 14 | import com.yohobuy.platform.model.grass.request.GrassTopicReq; |
20 | -import com.yohobuy.platform.model.grass.response.GrassLabelBo; | ||
21 | import com.yohobuy.platform.model.grass.response.TopicRespBo; | 15 | import com.yohobuy.platform.model.grass.response.TopicRespBo; |
22 | import org.apache.commons.collections.CollectionUtils; | 16 | import org.apache.commons.collections.CollectionUtils; |
23 | import org.apache.commons.lang.StringUtils; | 17 | import org.apache.commons.lang.StringUtils; |
@@ -26,9 +20,11 @@ import org.slf4j.LoggerFactory; | @@ -26,9 +20,11 @@ import org.slf4j.LoggerFactory; | ||
26 | import org.springframework.beans.BeanUtils; | 20 | import org.springframework.beans.BeanUtils; |
27 | import org.springframework.beans.factory.annotation.Autowired; | 21 | import org.springframework.beans.factory.annotation.Autowired; |
28 | import org.springframework.stereotype.Service; | 22 | import org.springframework.stereotype.Service; |
29 | -import org.springframework.util.NumberUtils; | ||
30 | 23 | ||
31 | -import java.util.*; | 24 | +import java.util.ArrayList; |
25 | +import java.util.Arrays; | ||
26 | +import java.util.List; | ||
27 | +import java.util.Map; | ||
32 | import java.util.stream.Collectors; | 28 | import java.util.stream.Collectors; |
33 | 29 | ||
34 | 30 | ||
@@ -174,6 +170,9 @@ public class TopicServiceImpl implements ITopicService { | @@ -174,6 +170,9 @@ public class TopicServiceImpl implements ITopicService { | ||
174 | //查询文章表 统计话题下的文章数(不考虑文章状态) | 170 | //查询文章表 统计话题下的文章数(不考虑文章状态) |
175 | List<GrassArticleTopic> topicList = articleTopicDao.countBytopicIds(topicIds); | 171 | List<GrassArticleTopic> topicList = articleTopicDao.countBytopicIds(topicIds); |
176 | Map<Integer,Integer> topicMap = topicList.stream().collect(Collectors.toMap(GrassArticleTopic::getTopicId, obj -> obj.getNum())); | 172 | Map<Integer,Integer> topicMap = topicList.stream().collect(Collectors.toMap(GrassArticleTopic::getTopicId, obj -> obj.getNum())); |
173 | + //查询话题文章关联表,获取话题被置顶的文章ids | ||
174 | + List<GrassArticleTopic> topArticles = articleTopicDao.selectTopsByTopicIds(topicIds); | ||
175 | + Map<Integer, List<GrassArticleTopic>> articleTopMap = topArticles.stream().collect(Collectors.groupingBy(GrassArticleTopic::getTopicId)); | ||
177 | 176 | ||
178 | for(GrassTopic grassTopic : sourceList){ | 177 | for(GrassTopic grassTopic : sourceList){ |
179 | TopicRespBo bo = new TopicRespBo(); | 178 | TopicRespBo bo = new TopicRespBo(); |
@@ -181,8 +180,49 @@ public class TopicServiceImpl implements ITopicService { | @@ -181,8 +180,49 @@ public class TopicServiceImpl implements ITopicService { | ||
181 | bo.setUpdateTimeStr(grassTopic.getUpdateTime() == null ? "" : DateUtil.int2DateStr(grassTopic.getUpdateTime(),"yyyy-MM-dd HH:mm:ss")); | 180 | bo.setUpdateTimeStr(grassTopic.getUpdateTime() == null ? "" : DateUtil.int2DateStr(grassTopic.getUpdateTime(),"yyyy-MM-dd HH:mm:ss")); |
182 | //相关的文章 | 181 | //相关的文章 |
183 | bo.setArticleAmount(topicMap.get(bo.getId()) == null ? 0 : topicMap.get(bo.getId())); | 182 | bo.setArticleAmount(topicMap.get(bo.getId()) == null ? 0 : topicMap.get(bo.getId())); |
183 | + //若该话题下有置顶的文章 则获取置顶文章','间隔 | ||
184 | + if(articleTopMap != null && articleTopMap.get(grassTopic.getId()) != null){ | ||
185 | + List<Integer> topArticleIds = articleTopMap.get(grassTopic.getId()).stream().map(GrassArticleTopic::getArticleId).collect(Collectors.toList()); | ||
186 | + bo.setTopArticles(StringUtils.join(topArticleIds,",")); | ||
187 | + bo.setTopStatus(1); | ||
188 | + } | ||
184 | result.add(bo); | 189 | result.add(bo); |
185 | } | 190 | } |
186 | return result; | 191 | return result; |
187 | } | 192 | } |
193 | + | ||
194 | + /** | ||
195 | + * 设置某话题下文章置顶 | ||
196 | + * @param req | ||
197 | + * @return | ||
198 | + */ | ||
199 | + @Override | ||
200 | + public ApiResponse addArticlesTop(GrassTopicReq req){ | ||
201 | + if(req.getId() == null){ | ||
202 | + logger.warn("addArticlesTop with topicId null"); | ||
203 | + return new ApiResponse(201,"话题id不可为空!"); | ||
204 | + } | ||
205 | + //校验设定的内容id是否是该话题下的 | ||
206 | + List<String> articleStrList = Arrays.asList(req.getTopArticleIds().split(",")); | ||
207 | + List<Integer> articleList = articleStrList.stream().map(Integer::valueOf).collect(Collectors.toList()); | ||
208 | + List<GrassArticleTopic> articleTopics = articleTopicDao.selectByArticleIdList(articleList); | ||
209 | + if(CollectionUtils.isEmpty(articleTopics)){ | ||
210 | + logger.warn("the articleIds all is not valid,req:{}",req); | ||
211 | + return new ApiResponse(202,"所填内容id均不是该话题下的文章!"); | ||
212 | + } | ||
213 | + List<Integer> validArticles = articleTopics.stream().map(GrassArticleTopic::getArticleId).collect(Collectors.toList()); | ||
214 | + articleList.removeAll(validArticles); | ||
215 | + if(CollectionUtils.isNotEmpty(articleList)){ | ||
216 | + logger.warn("these articleIds is not valid,topicId:{},invalid:{}",req.getId(),articleList); | ||
217 | + return new ApiResponse(202,"所填内容id" + articleList + "不是该话题下的文章!"); | ||
218 | + } | ||
219 | + //将该话题下的所有文章取消置顶 | ||
220 | + int updateTime = DateUtil.getCurrentTimeSeconds(); | ||
221 | + articleTopicDao.updateTopByTopicId(req.getId(),updateTime); | ||
222 | + | ||
223 | + //将指定文章写入 话题-文章关联表 | ||
224 | + int result = articleTopicDao.updateTopByArticles(validArticles,1,updateTime); | ||
225 | + logger.info("end addArticlesTop,req:{},result:{}",req,result); | ||
226 | + return new ApiResponse(result); | ||
227 | + } | ||
188 | } | 228 | } |
@@ -47,7 +47,7 @@ | @@ -47,7 +47,7 @@ | ||
47 | <dependency> | 47 | <dependency> |
48 | <groupId>com.yohobuy.platform</groupId> | 48 | <groupId>com.yohobuy.platform</groupId> |
49 | <artifactId>platform-dal</artifactId> | 49 | <artifactId>platform-dal</artifactId> |
50 | - <version>1.0.3-6.9.6-SNAPSHOT</version> | 50 | + <version>1.0.3-6.9.7-SNAPSHOT</version> |
51 | </dependency> | 51 | </dependency> |
52 | </dependencies> | 52 | </dependencies> |
53 | 53 |
@@ -24,7 +24,7 @@ | @@ -24,7 +24,7 @@ | ||
24 | <dependency> | 24 | <dependency> |
25 | <groupId>com.yoho.service.platform.model</groupId> | 25 | <groupId>com.yoho.service.platform.model</groupId> |
26 | <artifactId>platform-service-model</artifactId> | 26 | <artifactId>platform-service-model</artifactId> |
27 | - <version>1.2.3-6.9.6-SNAPSHOT</version> | 27 | + <version>1.2.3-6.9.7-SNAPSHOT</version> |
28 | </dependency> | 28 | </dependency> |
29 | <dependency> | 29 | <dependency> |
30 | <groupId>com.yoho.dsf.yhplatform</groupId> | 30 | <groupId>com.yoho.dsf.yhplatform</groupId> |
@@ -59,7 +59,7 @@ | @@ -59,7 +59,7 @@ | ||
59 | <dependency> | 59 | <dependency> |
60 | <groupId>com.yohobuy.platform</groupId> | 60 | <groupId>com.yohobuy.platform</groupId> |
61 | <artifactId>platform-common</artifactId> | 61 | <artifactId>platform-common</artifactId> |
62 | - <version>1.0.3-6.9.6-SNAPSHOT</version> | 62 | + <version>1.0.3-6.9.7-SNAPSHOT</version> |
63 | </dependency> | 63 | </dependency> |
64 | 64 | ||
65 | 65 |
@@ -224,7 +224,20 @@ | @@ -224,7 +224,20 @@ | ||
224 | width: 25, | 224 | width: 25, |
225 | align: "left" | 225 | align: "left" |
226 | }, { | 226 | }, { |
227 | - title: "状态", | 227 | + title: "置顶状态", |
228 | + field: "topStatus", | ||
229 | + width: 25, | ||
230 | + align: "left", | ||
231 | + formatter: function (value, rowData, rowIndex) { | ||
232 | + if (value == 1) { | ||
233 | + return "已设置"; | ||
234 | + } else { | ||
235 | + return "未设置"; | ||
236 | + } | ||
237 | + } | ||
238 | + | ||
239 | + }, { | ||
240 | + title: "话题状态", | ||
228 | field: "status", | 241 | field: "status", |
229 | width: 25, | 242 | width: 25, |
230 | align: "left", | 243 | align: "left", |
@@ -254,13 +267,13 @@ | @@ -254,13 +267,13 @@ | ||
254 | str = "";//进行中的话题不可编辑 | 267 | str = "";//进行中的话题不可编辑 |
255 | changeStatus = "<a role='changeStatus' style='margin-left:10px;background-color: #ffa951' changedStatus='0' dataId='" + rowData.id + "' index='" + rowIndex + "'>下架</a>"; | 268 | changeStatus = "<a role='changeStatus' style='margin-left:10px;background-color: #ffa951' changedStatus='0' dataId='" + rowData.id + "' index='" + rowIndex + "'>下架</a>"; |
256 | } | 269 | } |
257 | - debugger | ||
258 | if(rowData.isHot == 1){ | 270 | if(rowData.isHot == 1){ |
259 | changeHot = "<a role='changeHot' style='margin-left:10px;background-color: #ea40ff' changedStatus='0' dataId='" + rowData.id + "' index='" + rowIndex + "'>取消热门</a>"; | 271 | changeHot = "<a role='changeHot' style='margin-left:10px;background-color: #ea40ff' changedStatus='0' dataId='" + rowData.id + "' index='" + rowIndex + "'>取消热门</a>"; |
260 | } | 272 | } |
273 | + var topStr = "<a role='setTop' dataId='" + rowData.id + "' style='margin-left:10px;background-color: #31b0d5' index='" + rowIndex + "'>设置置顶</a>"; | ||
261 | 274 | ||
262 | //编辑 上下架 复制链接 设置热门 | 275 | //编辑 上下架 复制链接 设置热门 |
263 | - return str + changeStatus + changeHot + link ; | 276 | + return str + changeStatus + changeHot + link + topStr; |
264 | } | 277 | } |
265 | } | 278 | } |
266 | 279 | ||
@@ -330,6 +343,17 @@ | @@ -330,6 +343,17 @@ | ||
330 | } | 343 | } |
331 | }); | 344 | }); |
332 | 345 | ||
346 | + // 设置置顶 | ||
347 | + $(this).datagrid("getPanel").find("a[role='setTop']").linkbutton({ | ||
348 | + iconCls: "icon-edit", | ||
349 | + onClick: function () { | ||
350 | + | ||
351 | + index = $(this).attr("index"); | ||
352 | + var row = $("#labelListTable").datagrid('getData').rows[index]; | ||
353 | + setTopicTopDialog(row); | ||
354 | + } | ||
355 | + }); | ||
356 | + | ||
333 | } | 357 | } |
334 | }); | 358 | }); |
335 | 359 | ||
@@ -494,7 +518,90 @@ | @@ -494,7 +518,90 @@ | ||
494 | } | 518 | } |
495 | }], | 519 | }], |
496 | modal: true, | 520 | modal: true, |
497 | - href: contextPath + "/html/grass/topicManage/topicEdit.html", | 521 | + href: contextPath + "/html/grass/topicManage/topicEdit.html" |
522 | + }); | ||
523 | + } | ||
524 | + | ||
525 | + // 设置置顶 | ||
526 | + function setTopicTopDialog(data) { | ||
527 | + | ||
528 | + var labelList = $("<div id='labelList'>").appendTo($(document.body)); | ||
529 | + var title = "设置置顶"; | ||
530 | + window.self.paramObject.mkData = data; | ||
531 | + $(labelList).myDialog({ | ||
532 | + title: title, | ||
533 | + width: "30%", | ||
534 | + height: "30%", | ||
535 | + resizable: false, | ||
536 | + buttons: [{ | ||
537 | + id: "saveBtn", | ||
538 | + text: "保存", | ||
539 | + iconCls: "icon-save", | ||
540 | + handler: function () { | ||
541 | + | ||
542 | + $("#setTopForm").form("submit", { | ||
543 | + url: serverContextPath + "/grassTopicManage/addArticlesTop", | ||
544 | + onSubmit: function (param) { | ||
545 | + if (data != null) { | ||
546 | + param.id = data.id; | ||
547 | + } | ||
548 | + | ||
549 | + //表单基本检查 | ||
550 | + if (!$("#setTopForm").form("validate")) { | ||
551 | + return false; | ||
552 | + } | ||
553 | + | ||
554 | + //校验最多可填五个内容id | ||
555 | + var articleStr = $("#setTopForm #topArticleIdsStr").textbox("getValue"); | ||
556 | + var articleArray = articleStr.split(','); | ||
557 | + for(var i = 0; i < articleArray.length; i++){ | ||
558 | + if(isNaN(articleArray[i])){ | ||
559 | + $.messager.alert("提示", "非数字字符不允许提交!", ""); | ||
560 | + return false; | ||
561 | + } | ||
562 | + } | ||
563 | + if(articleArray.length > 5){ | ||
564 | + $.messager.alert("提示", "填写不可超过五个内容ID!", ""); | ||
565 | + return false; | ||
566 | + } | ||
567 | + if(articleStr.charAt(articleStr.length - 1) == ','){ | ||
568 | + param.topArticleIds = articleStr.substring(0,articleStr.length - 1); | ||
569 | + }else{ | ||
570 | + param.topArticleIds = articleStr; | ||
571 | + } | ||
572 | + | ||
573 | + $.messager.progress({ | ||
574 | + title: "正在执行", | ||
575 | + msg: "正在执行,请稍后..." | ||
576 | + }); | ||
577 | + return true; | ||
578 | + }, | ||
579 | + success: function (data) { | ||
580 | + $.messager.progress("close"); | ||
581 | + data = JSON.parse(data); | ||
582 | + if (data.code == 200) { | ||
583 | + $(labelList).dialog("close"); | ||
584 | + $("#labelListTable").datagrid("reload"); | ||
585 | + $.messager.show({ | ||
586 | + title: "提示", | ||
587 | + msg: title + "成功!", | ||
588 | + height: 120 | ||
589 | + }); | ||
590 | + } else { | ||
591 | + $.messager.alert("错误", data.message, "error"); | ||
592 | + } | ||
593 | + } | ||
594 | + }); | ||
595 | + } | ||
596 | + }, { | ||
597 | + text: "关闭", | ||
598 | + iconCls: "icon-cancel", | ||
599 | + handler: function () { | ||
600 | + $(labelList).dialog("close"); | ||
601 | + } | ||
602 | + }], | ||
603 | + modal: true, | ||
604 | + href: contextPath + "/html/grass/topicManage/topicSetTop.html" | ||
498 | }); | 605 | }); |
499 | } | 606 | } |
500 | 607 |
1 | +<!DOCTYPE html> | ||
2 | +<div id="tt" class="easyui-layout" fit="true" style="overflow-y: scroll"> | ||
3 | + <form name="setTopForm" id="setTopForm" method="post"> | ||
4 | + <div style="margin-top: 20px;margin-left: 30px"> | ||
5 | + <table border="0" style="width:95%;margin-top:5px;line-height:30px;" id="tab"> | ||
6 | + <tr style="height: 60px"> | ||
7 | + <td> | ||
8 | + <span style="color:red">*</span><label>内容ID</label> <br> | ||
9 | + <input id="topArticleIdsStr" name="topArticleIdsStr" class="easyui-textbox" style="width: 500px;" /><br> | ||
10 | + <span style="color:red">注:至多填写5个,设置的内容必须关联该话题</span> | ||
11 | + </td> | ||
12 | + </tr> | ||
13 | + </table> | ||
14 | + </div> | ||
15 | + </form> | ||
16 | + | ||
17 | +</div> | ||
18 | + | ||
19 | + | ||
20 | +<script> | ||
21 | + | ||
22 | + $(function () { | ||
23 | + $("#setTopForm #topArticleIdsStr").textbox({ | ||
24 | + required: true, | ||
25 | + missingMessage: "内容ID不能为空", | ||
26 | + prompt: " 填写置顶的内容ID,且以半角逗号隔开" | ||
27 | + }); | ||
28 | + | ||
29 | + var data = paramObject.mkData; | ||
30 | + if (data) {//编辑窗口 | ||
31 | + $("#topArticleIdsStr").textbox("setValue", data.topArticles); | ||
32 | + }else{ | ||
33 | + $("#topArticleIdsStr").textbox("setValue", ""); | ||
34 | + } | ||
35 | + | ||
36 | + | ||
37 | + | ||
38 | + }); | ||
39 | + | ||
40 | + | ||
41 | +</script> | ||
42 | + | ||
43 | +</html> | ||
44 | + |
-
Please register or login to post a comment