|
|
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);
|
|
|
}
|
|
|
//修改文章内容
|
|
|
GrassArticle grassArticle = new GrassArticle();
|
|
|
grassArticle.setId(articleId);
|
|
|
grassArticle.setTopicId(req.getTopicId());
|
|
|
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());
|
|
|
//修改文章主体内容
|
|
|
if(req.getTopicId() !=null){
|
|
|
GrassArticle grassArticle = new GrassArticle();
|
|
|
grassArticle.setId(articleId);
|
|
|
grassArticle.setTopicId(req.getTopicId());
|
|
|
grassArticle.setUpdateTime(DateUtil.getCurrentTimeSeconds());
|
|
|
grassArticleDao.updateByPrimaryKeySelective(grassArticle);
|
|
|
}
|
|
|
|
|
|
//文章内容
|
|
|
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("");
|
...
|
...
|
|