Authored by chaogeng

Merge branch 'dev_grass_20190108' of http://git.yoho.cn/platform/platform-cms in…

…to dev_grass_20190108
package com.yohobuy.platform.grass.restapi;
import com.yoho.core.dal.datasource.annotation.Database;
import com.yohobuy.platform.common.exception.PlatformException;
import com.yohobuy.platform.grass.service.IGrassArticleService;
import com.yohobuy.platform.model.common.ApiResponse;
... ...
package com.yohobuy.platform.grass.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.yoho.core.dal.datasource.annotation.Database;
import com.yohobuy.platform.common.exception.PlatformException;
import com.yohobuy.platform.common.util.DateUtil;
import com.yohobuy.platform.dal.grass.IGrassArticleBlockDao;
... ... @@ -66,8 +69,11 @@ public class GrassArticleServiceImpl implements IGrassArticleService{
int contentOrder =0;
for (String url : urls) {
GrassArticleBlock content = new GrassArticleBlock();
JSONObject data = new JSONObject();
data.put("template_name", "image");
data.put("data", url);
content.setArticleId(article.getId());
content.setContentData(url);
content.setContentData(data.toJSONString());
content.setCreateTime(DateUtil.getCurrentTimeSeconds());
content.setTemplateKey("image");
content.setOrderBy(contentOrder);
... ... @@ -75,8 +81,11 @@ public class GrassArticleServiceImpl implements IGrassArticleService{
contentList.add(content);
}
GrassArticleBlock content = new GrassArticleBlock();
JSONObject data = new JSONObject();
data.put("template_name", "text");
data.put("data", req.getContent());
content.setArticleId(article.getId());
content.setContentData(req.getContent());
content.setContentData(data.toJSONString());
content.setCreateTime(DateUtil.getCurrentTimeSeconds());
content.setTemplateKey("text");
content.setOrderBy(contentOrder);
... ... @@ -146,6 +155,7 @@ public class GrassArticleServiceImpl implements IGrassArticleService{
}
@Override
@Database(ForceMaster = true)
public void updateArticle(GrassArticleReq req) throws PlatformException {
Integer type= req.getOperateType();
logger.info("enter updateArticle, req is {}",req);
... ... @@ -174,49 +184,61 @@ public class GrassArticleServiceImpl implements IGrassArticleService{
if(articleId == null){
throw new PlatformException("articleId is null", 402);
}
//修改文章内容
//修改文章主体内容
if(req.getTopicId() !=null){
GrassArticle grassArticle = new GrassArticle();
grassArticle.setId(articleId);
grassArticle.setTopicId(req.getTopicId());
grassArticle.setUpdateTime(DateUtil.getCurrentTimeSeconds());
grassArticleDao.updateByPrimaryKeySelective(grassArticle);
//文章图片
List<GrassArticleBlock> imageList = grassArticleBlockDao.selectByArticleId(articleId);
List<String> dbImageList = imageList.stream().filter(Objects::nonNull).filter(content ->"image".equals(content.getTemplateKey()) ).map(GrassArticleBlock::getContentData).collect(Collectors.toList());
}
//文章内容
grassArticleBlockDao.deleteByArticleId(articleId);
//图片内容
List<String> reqlist = req.getArticleImages() == null ? Lists.newArrayList() : Lists.newArrayList(req.getArticleImages().split(","));
List<String> newimgList = reqlist.stream().filter(s -> !dbImageList.contains(s)).collect(Collectors.toList());
List<GrassArticleBlock> deleteList = imageList.stream().filter(content -> content!=null&&!reqlist.contains(content.getContentData())).collect(Collectors.toList());
//新增
List<GrassArticleBlock> addList = Lists.newArrayList();
int contentOrder = imageList.size();
for (String src : newimgList) {
int contentOrder = 0;
for (String src : reqlist) {
GrassArticleBlock content = new GrassArticleBlock();
JSONObject data = new JSONObject();
data.put("template_name", "image");
data.put("data", src);
content.setArticleId(articleId);
content.setContentData(src);
content.setContentData(data.toJSONString());
content.setCreateTime(DateUtil.getCurrentTimeSeconds());
content.setTemplateKey("image");
content.setOrderBy(contentOrder);
contentOrder++;
addList.add(content);
}
//文字内容
if(StringUtils.isNotEmpty(req.getContent())){
GrassArticleBlock content = new GrassArticleBlock();
JSONObject data = new JSONObject();
data.put("template_name", "text");
data.put("data", req.getContent());
content.setArticleId(articleId);
content.setContentData(data.toJSONString());
content.setCreateTime(DateUtil.getCurrentTimeSeconds());
content.setTemplateKey("text");
content.setOrderBy(contentOrder);
addList.add(content);
}
if(CollectionUtils.isNotEmpty(addList)){
grassArticleBlockDao.insertArticleContents(addList);
}
//删除
List<Integer> delList = deleteList.stream().filter(Objects::nonNull).map(GrassArticleBlock::getArticleId).collect(Collectors.toList());
if(CollectionUtils.isNotEmpty(delList)){
grassArticleBlockDao.deleteArticleContentByIds(delList, DateUtil.getCurrentTimeSeconds());
}
//商品
List<GrassArticleProduct> sknList = grassArticleProductDao.selectByArticleId(articleId);
List<Integer> dbSknList = sknList.stream().filter(Objects::nonNull).map(GrassArticleProduct::getProductSkn).collect(Collectors.toList());
grassArticleProductDao.deleteByArticleId(articleId);
List<String> reqSknlist = req.getArticleSkns() == null ? Lists.newArrayList() : Lists.newArrayList(req.getArticleSkns().split(","));
List<String> newSknList = reqSknlist.stream().filter(s -> !dbSknList.contains(Integer.valueOf(s))).collect(Collectors.toList());
List<GrassArticleProduct> delSknList = sknList.stream().filter(skn -> skn !=null && !reqlist.contains(String.valueOf(skn.getProductSkn()))).collect(Collectors.toList());
//新增
List<GrassArticleProduct> addSknList = Lists.newArrayList();
int orderBy = sknList.size();
for (String skn : newSknList) {
int orderBy = 0;
for (String skn : reqSknlist) {
GrassArticleProduct grassArticleSkn = new GrassArticleProduct();
grassArticleSkn.setArticleId(articleId);
grassArticleSkn.setProductSkn(Integer.valueOf(skn));
... ... @@ -224,14 +246,11 @@ public class GrassArticleServiceImpl implements IGrassArticleService{
grassArticleSkn.setOrderBy(orderBy);
orderBy++;
addSknList.add(grassArticleSkn);
}if(CollectionUtils.isNotEmpty(addList)){
grassArticleProductDao.insertArticleSkns(addSknList);
}
//删除
List<Integer> delSknIds = delSknList.stream().filter(Objects::nonNull).map(GrassArticleProduct::getArticleId).collect(Collectors.toList());
if(CollectionUtils.isNotEmpty(delSknIds)){
grassArticleProductDao.deleteArticleSkns(delSknIds, DateUtil.getCurrentTimeSeconds());
if(CollectionUtils.isNotEmpty(addSknList)){
grassArticleProductDao.insertArticleSkns(addSknList);
}
}
}
... ... @@ -243,11 +262,13 @@ public class GrassArticleServiceImpl implements IGrassArticleService{
List<Integer> topicIds = articleList.stream().map(GrassArticle::getTopicId).collect(Collectors.toList());
List<GrassArticleBlock> grassArticleContentList = grassArticleBlockDao.selectByArticleIds(ids);
List<GrassArticleProduct> grassArticlePoductList = grassArticleProductDao.selectByArticleIds(ids);
GrassArticleBlock grassArticleContent = grassArticleContentList.stream().filter(content -> "text".equals(content.getTemplateKey())).findFirst().orElse(null);
List<GrassArticleBlock> textContent = grassArticleContentList.stream().filter(content -> "text".equals(content.getTemplateKey())).collect(Collectors.toList());
if(CollectionUtils.isNotEmpty(topicIds)){
List<String> topics = Lists.newArrayList();
}
Map<Integer, List<String>> imgMap = Maps.newHashMap();
Map<Integer,String> textMap = Maps.newHashMap();
Map<Integer, List<Integer>> sknMap = Maps.newHashMap();
grassArticleContentList.forEach(content ->{
if ("image".equals(content.getTemplateKey())) {
... ... @@ -255,11 +276,21 @@ public class GrassArticleServiceImpl implements IGrassArticleService{
if(images == null){
images = Lists.newArrayList();
}
images.add(content.getContentData());
JSONObject data = JSON.parseObject(content.getContentData());
images.add(data.getString("data"));
imgMap.put(content.getArticleId(), images);
}
});
textContent.forEach(content ->{
if ("text".equals(content.getTemplateKey())) {
String text = textMap.get(content.getArticleId());
JSONObject data = JSON.parseObject(content.getContentData());
text = data.getString("data");
textMap.put(content.getArticleId(), text);
}
});
grassArticlePoductList.forEach(product -> {
List<Integer> skns = sknMap.get(product.getArticleId());
if(skns == null){
... ... @@ -272,7 +303,7 @@ public class GrassArticleServiceImpl implements IGrassArticleService{
articleList.forEach(article -> {
ArticleDetailRspBo rspBo = new ArticleDetailRspBo();
rspBo.setArticleId(article.getId());
rspBo.setArticleContent(grassArticleContent ==null ? "": grassArticleContent.getContentData());
rspBo.setArticleContent(textMap.get(article.getId()));
rspBo.setAuthorUid(article.getAuthorUid());
rspBo.setTopicId(article.getTopicId());
rspBo.setNickName("");
... ...
... ... @@ -28,7 +28,13 @@
iconCls : "icon-search",
onClick : function() {
checkedItemsObj ={};
$("#labelGroupListTable").datagrid("load", {});
$("#labelGroupListTable").datagrid("load", {
productSkns: $("#skn").textbox("getValue"),
status: 1,
sales: "Y",
stocknumber: "1",
attribute_not: "2"
});
}
});
$("#skn").textbox({
... ... @@ -44,14 +50,14 @@
onUncheckAll: removeAllItem,
onUncheck: removeSingleItem,
queryParams: {
query: $("#skn").textbox("getValue"),
productSkns: $("#skn").textbox("getValue"),
status: 1,
sales: "Y",
stocknumber: "1",
attribute_not: "2"
},
url: "/yohosearch/search",
// url: contextPath+"/product/queryProductInfoBySkns",
url: "/yohosearch/search.json",
// url: +serverContextPath+"/product/queryProductInfoBySkns",
// url: serverContextPath+"/labelGroupManage/getLabelGroupList",
method: 'POST',
loadFilter: function (data) {
... ...
... ... @@ -245,14 +245,18 @@
align: "center",
formatter: function (value, rowData, rowIndex) {
debugger
var str = "<a role='edit' dataId='"+ rowData.articleId +"' style='margin-left:10px' index='"+ rowIndex +"'>编辑内容</a>";
str += "<a role='switch'"
var str='';
str += "<a role='switchR'"
var classStr = rowData.isRecommend == 1 ? "class='btn-danger'" : "class='btn-success'";
str += classStr +" dataId='" + rowData.articleId + "' index='"+ rowIndex +"' status='" + rowData.isRecommend + "' style='margin-left:10px'>";
var optStr = rowData.isRecommend == 1 ? "取消推荐</a>" : "推荐</a>";
str += optStr;
str += "<a role='switchT'"
var classStr = rowData.isTop == 1 ? "class='btn-danger'" : "class='btn-success'";
str += classStr +" dataId='" + rowData.articleId + "' index='"+ rowIndex +"' status='" + rowData.isTop + "' style='margin-left:10px'>";
var optStr = rowData.isTop == 1 ? "取消置顶</a>" : "置顶</a>";
str += optStr;
return str;
}
}
... ... @@ -272,19 +276,31 @@
}
// 编辑
$(this).datagrid("getPanel").find("a[role='edit']").linkbutton({
$(this).datagrid("getPanel").find("a[role='switchR']").linkbutton({
iconCls : "icon-edit",
onClick : function() {
debugger
onClick: function () {
var status = $(this).attr("status");
var dataId = $(this).attr("dataId");
index = $(this).attr("index");
var row = $("#activityListTable").datagrid('getData').rows[index];
getEditDialog(row)
var message = "";
if(status == 1){
message = "取消推荐";
}
if(status == 0){
message = "推荐";
}
$.messager.confirm("确认", "确认"+message+"该文章吗?", function (flag) {
if(flag){
switchRecommend(dataId, status);
}
});
// 停用
$(this).datagrid("getPanel").find("a[role='switch']").linkbutton({
}
});
$(this).datagrid("getPanel").find("a[role='switchT']").linkbutton({
iconCls : "icon-edit",
onClick: function () {
var status = $(this).attr("status");
... ... @@ -292,14 +308,14 @@
index = $(this).attr("index");
var message = "";
if(status == 1){
message = "取消推荐";
message = "取消置顶";
}
if(status == 0){
message = "推荐";
message = "置顶";
}
$.messager.confirm("确认", "确认"+message+"该文章吗?", function (flag) {
if(flag){
switchStatus(dataId, status);
switchTop(dataId, status);
}
});
... ... @@ -314,7 +330,7 @@
});
function switchStatus(id, status) {
function switchRecommend(id, status) {
debugger
var switchStatus = status == 1 ? 0 : 1;
$.post(contextPath + "/grassArticle/updateArticle?articleId=" + id + "&isRecommend=" + switchStatus+ "&operateType=0", function (data) {
... ... @@ -326,75 +342,20 @@
}, "json");
}
// 编辑活动
function getEditDialog(data){
function switchTop(id, status) {
debugger
var activityList = $("<div id='activityList'>").appendTo($(document.body));
var title = data == null ? "新增奖品":"编辑内容";
var textVar = data == null ? "保存":"保存";
var msgVar = data == null ? "确认新增奖品吗?":"确认保存本次修改吗?";
window.self.paramObject.mkData = data;
$(activityList).myDialog({
title: title,
width: "70%",
height: "80%",
resizable:false,
buttons:[{
id : "saveBtn",
text:textVar,
iconCls : "icon-save",
handler:function(){
debugger;
$("#publishArticleForm").form("submit", {
url: contextPath + "/grassArticle/updateArticle",
onSubmit: function (param) {
if (!$("#activityAddForm").form("validate")) {
return false;
}
$.messager.progress({
title: "正在执行",
msg: "正在执行,请稍后..."
});
return true;
},
success: function (data) {
debugger;
$.messager.progress("close");
data = JSON.parse(data);
if (data.code == 200) {
$(activityList).dialog("close");
var switchStatus = status == 1 ? 0 : 1;
$.post(contextPath + "/grassArticle/updateArticle?articleId=" + id + "&isTop=" + switchStatus+ "&operateType=0", function (data) {
if(data.code != 200){
alert(data.message);
}else{
$("#activityListTable").datagrid("reload");
$.messager.show({
title: "提示",
msg: title + "成功!",
height: 120
});
needTips();
} else {
$.messager.alert("失败", data.message, "error");
}
}, "json");
}
});
}
}, {
text: "关闭",
iconCls: "icon-cancel",
handler: function () {
$.messager.confirm("确认", "确认关闭吗?", function (flag) {
if(flag){
$(activityList).dialog("close");
}
});
}
}],
modal: true,
href: contextPath + "/html/grass/articleManage/editArticle.html",
});
}
});
... ...
... ... @@ -2,6 +2,9 @@
<div region="center" id="labelGroupList" style=" margin-left: 20px">
<div id="tt" class="easyui-layout" fit="true" style="overflow-y: scroll">
<form name="publishArticleForm" id="publishArticleForm" method="post" >
<input id="checkedId" name="articleId" type="hidden"/>
<input id="articleImages" name="articleImages" type="hidden"/>
<input id="articleSkns" name="articleSkns" type="hidden"/>
<div style="margin-top: 20px;margin-left: 30px">
<table border="0" style="width:95%;margin-top:5px;line-height:30px;" id="tab">
... ... @@ -140,18 +143,19 @@
});
debugger
debugger;
var data = paramObject.mkData;
if (data){
$("#articleUid").combobox("setValue", data.authorUid);
$("#articleUid").combobox('combobox').attr('readonly',true);
// $("#articleUid").combobox('combobox').attr('readonly',true);
$("#checkedId").val( data.articleId);
$("#content").val( data.articleContent);
$("#topic").combobox("setValue", data.topicId);
for (var i=1; i<=data.imgList.length; i++){
$("#imageUpload"+i).imageUpload('setValue',data.imgList[i]);
$("#imageUpload"+i).imageUpload('setValue',data.imgList[i-1]);
}
}
... ...