1
|
package com.yohobuy.platform.grass.service.impl;
|
1
|
package com.yohobuy.platform.grass.service.impl;
|
2
|
|
2
|
|
|
|
3
|
+import com.alibaba.fastjson.JSON;
|
|
|
4
|
+import com.alibaba.fastjson.JSONObject;
|
3
|
import com.google.common.collect.Lists;
|
5
|
import com.google.common.collect.Lists;
|
4
|
import com.google.common.collect.Maps;
|
6
|
import com.google.common.collect.Maps;
|
|
|
7
|
+import com.yoho.core.dal.datasource.annotation.Database;
|
5
|
import com.yohobuy.platform.common.exception.PlatformException;
|
8
|
import com.yohobuy.platform.common.exception.PlatformException;
|
6
|
import com.yohobuy.platform.common.util.DateUtil;
|
9
|
import com.yohobuy.platform.common.util.DateUtil;
|
7
|
import com.yohobuy.platform.dal.grass.IGrassArticleBlockDao;
|
10
|
import com.yohobuy.platform.dal.grass.IGrassArticleBlockDao;
|
|
@@ -66,8 +69,11 @@ public class GrassArticleServiceImpl implements IGrassArticleService{ |
|
@@ -66,8 +69,11 @@ public class GrassArticleServiceImpl implements IGrassArticleService{ |
66
|
int contentOrder =0;
|
69
|
int contentOrder =0;
|
67
|
for (String url : urls) {
|
70
|
for (String url : urls) {
|
68
|
GrassArticleBlock content = new GrassArticleBlock();
|
71
|
GrassArticleBlock content = new GrassArticleBlock();
|
|
|
72
|
+ JSONObject data = new JSONObject();
|
|
|
73
|
+ data.put("template_name", "image");
|
|
|
74
|
+ data.put("data", url);
|
69
|
content.setArticleId(article.getId());
|
75
|
content.setArticleId(article.getId());
|
70
|
- content.setContentData(url);
|
76
|
+ content.setContentData(data.toJSONString());
|
71
|
content.setCreateTime(DateUtil.getCurrentTimeSeconds());
|
77
|
content.setCreateTime(DateUtil.getCurrentTimeSeconds());
|
72
|
content.setTemplateKey("image");
|
78
|
content.setTemplateKey("image");
|
73
|
content.setOrderBy(contentOrder);
|
79
|
content.setOrderBy(contentOrder);
|
|
@@ -75,8 +81,11 @@ public class GrassArticleServiceImpl implements IGrassArticleService{ |
|
@@ -75,8 +81,11 @@ public class GrassArticleServiceImpl implements IGrassArticleService{ |
75
|
contentList.add(content);
|
81
|
contentList.add(content);
|
76
|
}
|
82
|
}
|
77
|
GrassArticleBlock content = new GrassArticleBlock();
|
83
|
GrassArticleBlock content = new GrassArticleBlock();
|
|
|
84
|
+ JSONObject data = new JSONObject();
|
|
|
85
|
+ data.put("template_name", "text");
|
|
|
86
|
+ data.put("data", req.getContent());
|
78
|
content.setArticleId(article.getId());
|
87
|
content.setArticleId(article.getId());
|
79
|
- content.setContentData(req.getContent());
|
88
|
+ content.setContentData(data.toJSONString());
|
80
|
content.setCreateTime(DateUtil.getCurrentTimeSeconds());
|
89
|
content.setCreateTime(DateUtil.getCurrentTimeSeconds());
|
81
|
content.setTemplateKey("text");
|
90
|
content.setTemplateKey("text");
|
82
|
content.setOrderBy(contentOrder);
|
91
|
content.setOrderBy(contentOrder);
|
|
@@ -146,6 +155,7 @@ public class GrassArticleServiceImpl implements IGrassArticleService{ |
|
@@ -146,6 +155,7 @@ public class GrassArticleServiceImpl implements IGrassArticleService{ |
146
|
}
|
155
|
}
|
147
|
|
156
|
|
148
|
@Override
|
157
|
@Override
|
|
|
158
|
+ @Database(ForceMaster = true)
|
149
|
public void updateArticle(GrassArticleReq req) throws PlatformException {
|
159
|
public void updateArticle(GrassArticleReq req) throws PlatformException {
|
150
|
Integer type= req.getOperateType();
|
160
|
Integer type= req.getOperateType();
|
151
|
logger.info("enter updateArticle, req is {}",req);
|
161
|
logger.info("enter updateArticle, req is {}",req);
|
|
@@ -174,49 +184,61 @@ public class GrassArticleServiceImpl implements IGrassArticleService{ |
|
@@ -174,49 +184,61 @@ public class GrassArticleServiceImpl implements IGrassArticleService{ |
174
|
if(articleId == null){
|
184
|
if(articleId == null){
|
175
|
throw new PlatformException("articleId is null", 402);
|
185
|
throw new PlatformException("articleId is null", 402);
|
176
|
}
|
186
|
}
|
177
|
- //修改文章内容
|
|
|
178
|
- GrassArticle grassArticle = new GrassArticle();
|
|
|
179
|
- grassArticle.setId(articleId);
|
|
|
180
|
- grassArticle.setTopicId(req.getTopicId());
|
|
|
181
|
- grassArticleDao.updateByPrimaryKeySelective(grassArticle);
|
|
|
182
|
- //文章图片
|
|
|
183
|
- List<GrassArticleBlock> imageList = grassArticleBlockDao.selectByArticleId(articleId);
|
|
|
184
|
- List<String> dbImageList = imageList.stream().filter(Objects::nonNull).filter(content ->"image".equals(content.getTemplateKey()) ).map(GrassArticleBlock::getContentData).collect(Collectors.toList());
|
187
|
+ //修改文章主体内容
|
|
|
188
|
+ if(req.getTopicId() !=null){
|
|
|
189
|
+ GrassArticle grassArticle = new GrassArticle();
|
|
|
190
|
+ grassArticle.setId(articleId);
|
|
|
191
|
+ grassArticle.setTopicId(req.getTopicId());
|
|
|
192
|
+ grassArticle.setUpdateTime(DateUtil.getCurrentTimeSeconds());
|
|
|
193
|
+ grassArticleDao.updateByPrimaryKeySelective(grassArticle);
|
|
|
194
|
+ }
|
|
|
195
|
+
|
|
|
196
|
+ //文章内容
|
|
|
197
|
+ grassArticleBlockDao.deleteByArticleId(articleId);
|
|
|
198
|
+
|
|
|
199
|
+ //图片内容
|
185
|
List<String> reqlist = req.getArticleImages() == null ? Lists.newArrayList() : Lists.newArrayList(req.getArticleImages().split(","));
|
200
|
List<String> reqlist = req.getArticleImages() == null ? Lists.newArrayList() : Lists.newArrayList(req.getArticleImages().split(","));
|
186
|
- List<String> newimgList = reqlist.stream().filter(s -> !dbImageList.contains(s)).collect(Collectors.toList());
|
|
|
187
|
- List<GrassArticleBlock> deleteList = imageList.stream().filter(content -> content!=null&&!reqlist.contains(content.getContentData())).collect(Collectors.toList());
|
|
|
188
|
//新增
|
201
|
//新增
|
189
|
List<GrassArticleBlock> addList = Lists.newArrayList();
|
202
|
List<GrassArticleBlock> addList = Lists.newArrayList();
|
190
|
- int contentOrder = imageList.size();
|
|
|
191
|
- for (String src : newimgList) {
|
203
|
+ int contentOrder = 0;
|
|
|
204
|
+ for (String src : reqlist) {
|
192
|
GrassArticleBlock content = new GrassArticleBlock();
|
205
|
GrassArticleBlock content = new GrassArticleBlock();
|
|
|
206
|
+ JSONObject data = new JSONObject();
|
|
|
207
|
+ data.put("template_name", "image");
|
|
|
208
|
+ data.put("data", src);
|
193
|
content.setArticleId(articleId);
|
209
|
content.setArticleId(articleId);
|
194
|
- content.setContentData(src);
|
210
|
+ content.setContentData(data.toJSONString());
|
195
|
content.setCreateTime(DateUtil.getCurrentTimeSeconds());
|
211
|
content.setCreateTime(DateUtil.getCurrentTimeSeconds());
|
|
|
212
|
+ content.setTemplateKey("image");
|
196
|
content.setOrderBy(contentOrder);
|
213
|
content.setOrderBy(contentOrder);
|
197
|
contentOrder++;
|
214
|
contentOrder++;
|
198
|
addList.add(content);
|
215
|
addList.add(content);
|
199
|
}
|
216
|
}
|
|
|
217
|
+ //文字内容
|
|
|
218
|
+ if(StringUtils.isNotEmpty(req.getContent())){
|
|
|
219
|
+ GrassArticleBlock content = new GrassArticleBlock();
|
|
|
220
|
+ JSONObject data = new JSONObject();
|
|
|
221
|
+ data.put("template_name", "text");
|
|
|
222
|
+ data.put("data", req.getContent());
|
|
|
223
|
+ content.setArticleId(articleId);
|
|
|
224
|
+ content.setContentData(data.toJSONString());
|
|
|
225
|
+ content.setCreateTime(DateUtil.getCurrentTimeSeconds());
|
|
|
226
|
+ content.setTemplateKey("text");
|
|
|
227
|
+ content.setOrderBy(contentOrder);
|
|
|
228
|
+ addList.add(content);
|
|
|
229
|
+ }
|
|
|
230
|
+
|
200
|
if(CollectionUtils.isNotEmpty(addList)){
|
231
|
if(CollectionUtils.isNotEmpty(addList)){
|
201
|
grassArticleBlockDao.insertArticleContents(addList);
|
232
|
grassArticleBlockDao.insertArticleContents(addList);
|
202
|
}
|
233
|
}
|
203
|
- //删除
|
|
|
204
|
- List<Integer> delList = deleteList.stream().filter(Objects::nonNull).map(GrassArticleBlock::getArticleId).collect(Collectors.toList());
|
|
|
205
|
- if(CollectionUtils.isNotEmpty(delList)){
|
|
|
206
|
- grassArticleBlockDao.deleteArticleContentByIds(delList, DateUtil.getCurrentTimeSeconds());
|
|
|
207
|
- }
|
|
|
208
|
-
|
|
|
209
|
|
234
|
|
210
|
//商品
|
235
|
//商品
|
211
|
- List<GrassArticleProduct> sknList = grassArticleProductDao.selectByArticleId(articleId);
|
|
|
212
|
- List<Integer> dbSknList = sknList.stream().filter(Objects::nonNull).map(GrassArticleProduct::getProductSkn).collect(Collectors.toList());
|
236
|
+ grassArticleProductDao.deleteByArticleId(articleId);
|
213
|
List<String> reqSknlist = req.getArticleSkns() == null ? Lists.newArrayList() : Lists.newArrayList(req.getArticleSkns().split(","));
|
237
|
List<String> reqSknlist = req.getArticleSkns() == null ? Lists.newArrayList() : Lists.newArrayList(req.getArticleSkns().split(","));
|
214
|
- List<String> newSknList = reqSknlist.stream().filter(s -> !dbSknList.contains(Integer.valueOf(s))).collect(Collectors.toList());
|
|
|
215
|
- List<GrassArticleProduct> delSknList = sknList.stream().filter(skn -> skn !=null && !reqlist.contains(String.valueOf(skn.getProductSkn()))).collect(Collectors.toList());
|
|
|
216
|
//新增
|
238
|
//新增
|
217
|
List<GrassArticleProduct> addSknList = Lists.newArrayList();
|
239
|
List<GrassArticleProduct> addSknList = Lists.newArrayList();
|
218
|
- int orderBy = sknList.size();
|
|
|
219
|
- for (String skn : newSknList) {
|
240
|
+ int orderBy = 0;
|
|
|
241
|
+ for (String skn : reqSknlist) {
|
220
|
GrassArticleProduct grassArticleSkn = new GrassArticleProduct();
|
242
|
GrassArticleProduct grassArticleSkn = new GrassArticleProduct();
|
221
|
grassArticleSkn.setArticleId(articleId);
|
243
|
grassArticleSkn.setArticleId(articleId);
|
222
|
grassArticleSkn.setProductSkn(Integer.valueOf(skn));
|
244
|
grassArticleSkn.setProductSkn(Integer.valueOf(skn));
|
|
@@ -224,14 +246,11 @@ public class GrassArticleServiceImpl implements IGrassArticleService{ |
|
@@ -224,14 +246,11 @@ public class GrassArticleServiceImpl implements IGrassArticleService{ |
224
|
grassArticleSkn.setOrderBy(orderBy);
|
246
|
grassArticleSkn.setOrderBy(orderBy);
|
225
|
orderBy++;
|
247
|
orderBy++;
|
226
|
addSknList.add(grassArticleSkn);
|
248
|
addSknList.add(grassArticleSkn);
|
227
|
- }if(CollectionUtils.isNotEmpty(addList)){
|
|
|
228
|
- grassArticleProductDao.insertArticleSkns(addSknList);
|
|
|
229
|
}
|
249
|
}
|
230
|
- //删除
|
|
|
231
|
- List<Integer> delSknIds = delSknList.stream().filter(Objects::nonNull).map(GrassArticleProduct::getArticleId).collect(Collectors.toList());
|
|
|
232
|
- if(CollectionUtils.isNotEmpty(delSknIds)){
|
|
|
233
|
- grassArticleProductDao.deleteArticleSkns(delSknIds, DateUtil.getCurrentTimeSeconds());
|
250
|
+ if(CollectionUtils.isNotEmpty(addSknList)){
|
|
|
251
|
+ grassArticleProductDao.insertArticleSkns(addSknList);
|
234
|
}
|
252
|
}
|
|
|
253
|
+
|
235
|
}
|
254
|
}
|
236
|
}
|
255
|
}
|
237
|
|
256
|
|
|
@@ -243,11 +262,13 @@ public class GrassArticleServiceImpl implements IGrassArticleService{ |
|
@@ -243,11 +262,13 @@ public class GrassArticleServiceImpl implements IGrassArticleService{ |
243
|
List<Integer> topicIds = articleList.stream().map(GrassArticle::getTopicId).collect(Collectors.toList());
|
262
|
List<Integer> topicIds = articleList.stream().map(GrassArticle::getTopicId).collect(Collectors.toList());
|
244
|
List<GrassArticleBlock> grassArticleContentList = grassArticleBlockDao.selectByArticleIds(ids);
|
263
|
List<GrassArticleBlock> grassArticleContentList = grassArticleBlockDao.selectByArticleIds(ids);
|
245
|
List<GrassArticleProduct> grassArticlePoductList = grassArticleProductDao.selectByArticleIds(ids);
|
264
|
List<GrassArticleProduct> grassArticlePoductList = grassArticleProductDao.selectByArticleIds(ids);
|
246
|
- GrassArticleBlock grassArticleContent = grassArticleContentList.stream().filter(content -> "text".equals(content.getTemplateKey())).findFirst().orElse(null);
|
265
|
+ List<GrassArticleBlock> textContent = grassArticleContentList.stream().filter(content -> "text".equals(content.getTemplateKey())).collect(Collectors.toList());
|
|
|
266
|
+
|
247
|
if(CollectionUtils.isNotEmpty(topicIds)){
|
267
|
if(CollectionUtils.isNotEmpty(topicIds)){
|
248
|
List<String> topics = Lists.newArrayList();
|
268
|
List<String> topics = Lists.newArrayList();
|
249
|
}
|
269
|
}
|
250
|
Map<Integer, List<String>> imgMap = Maps.newHashMap();
|
270
|
Map<Integer, List<String>> imgMap = Maps.newHashMap();
|
|
|
271
|
+ Map<Integer,String> textMap = Maps.newHashMap();
|
251
|
Map<Integer, List<Integer>> sknMap = Maps.newHashMap();
|
272
|
Map<Integer, List<Integer>> sknMap = Maps.newHashMap();
|
252
|
grassArticleContentList.forEach(content ->{
|
273
|
grassArticleContentList.forEach(content ->{
|
253
|
if ("image".equals(content.getTemplateKey())) {
|
274
|
if ("image".equals(content.getTemplateKey())) {
|
|
@@ -255,11 +276,21 @@ public class GrassArticleServiceImpl implements IGrassArticleService{ |
|
@@ -255,11 +276,21 @@ public class GrassArticleServiceImpl implements IGrassArticleService{ |
255
|
if(images == null){
|
276
|
if(images == null){
|
256
|
images = Lists.newArrayList();
|
277
|
images = Lists.newArrayList();
|
257
|
}
|
278
|
}
|
258
|
- images.add(content.getContentData());
|
279
|
+ JSONObject data = JSON.parseObject(content.getContentData());
|
|
|
280
|
+ images.add(data.getString("data"));
|
259
|
imgMap.put(content.getArticleId(), images);
|
281
|
imgMap.put(content.getArticleId(), images);
|
260
|
}
|
282
|
}
|
261
|
|
283
|
|
262
|
});
|
284
|
});
|
|
|
285
|
+ textContent.forEach(content ->{
|
|
|
286
|
+ if ("text".equals(content.getTemplateKey())) {
|
|
|
287
|
+ String text = textMap.get(content.getArticleId());
|
|
|
288
|
+ JSONObject data = JSON.parseObject(content.getContentData());
|
|
|
289
|
+ text = data.getString("data");
|
|
|
290
|
+ textMap.put(content.getArticleId(), text);
|
|
|
291
|
+ }
|
|
|
292
|
+
|
|
|
293
|
+ });
|
263
|
grassArticlePoductList.forEach(product -> {
|
294
|
grassArticlePoductList.forEach(product -> {
|
264
|
List<Integer> skns = sknMap.get(product.getArticleId());
|
295
|
List<Integer> skns = sknMap.get(product.getArticleId());
|
265
|
if(skns == null){
|
296
|
if(skns == null){
|
|
@@ -272,7 +303,7 @@ public class GrassArticleServiceImpl implements IGrassArticleService{ |
|
@@ -272,7 +303,7 @@ public class GrassArticleServiceImpl implements IGrassArticleService{ |
272
|
articleList.forEach(article -> {
|
303
|
articleList.forEach(article -> {
|
273
|
ArticleDetailRspBo rspBo = new ArticleDetailRspBo();
|
304
|
ArticleDetailRspBo rspBo = new ArticleDetailRspBo();
|
274
|
rspBo.setArticleId(article.getId());
|
305
|
rspBo.setArticleId(article.getId());
|
275
|
- rspBo.setArticleContent(grassArticleContent ==null ? "": grassArticleContent.getContentData());
|
306
|
+ rspBo.setArticleContent(textMap.get(article.getId()));
|
276
|
rspBo.setAuthorUid(article.getAuthorUid());
|
307
|
rspBo.setAuthorUid(article.getAuthorUid());
|
277
|
rspBo.setTopicId(article.getTopicId());
|
308
|
rspBo.setTopicId(article.getTopicId());
|
278
|
rspBo.setNickName("");
|
309
|
rspBo.setNickName("");
|