...
|
...
|
@@ -4,16 +4,15 @@ import com.alibaba.fastjson.JSON; |
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.google.common.collect.Maps;
|
|
|
import com.google.common.collect.Sets;
|
|
|
import com.yoho.core.dal.datasource.annotation.Database;
|
|
|
import com.yoho.core.rest.client.ServiceCaller;
|
|
|
import com.yoho.error.ServiceError;
|
|
|
import com.yohobuy.platform.common.exception.PlatformException;
|
|
|
import com.yohobuy.platform.common.helper.ImagesHelper;
|
|
|
import com.yohobuy.platform.common.util.DateUtil;
|
|
|
import com.yohobuy.platform.dal.grass.*;
|
|
|
import com.yohobuy.platform.dal.grass.model.GrassArticle;
|
|
|
import com.yohobuy.platform.dal.grass.model.GrassArticleBlock;
|
|
|
import com.yohobuy.platform.dal.grass.model.GrassArticleProduct;
|
|
|
import com.yohobuy.platform.dal.grass.model.GrassTopic;
|
|
|
import com.yohobuy.platform.dal.grass.model.*;
|
|
|
import com.yohobuy.platform.grass.service.IGrassArticleService;
|
|
|
import com.yohobuy.platform.model.common.PageResponseVO;
|
|
|
import com.yohobuy.platform.model.grass.request.GrassArticleReq;
|
...
|
...
|
@@ -26,9 +25,7 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -48,8 +45,9 @@ public class GrassArticleServiceImpl implements IGrassArticleService{ |
|
|
private IGrassVirtualUserDao grassVirtualUserDao;
|
|
|
|
|
|
@Resource
|
|
|
private IGrassTopicDAO grassTopicDAO;
|
|
|
|
|
|
private IGrassArticleLabelDao grassArticleLabelDao;
|
|
|
@Resource
|
|
|
private IGrassLabelDAO grassLabelDAO;
|
|
|
@Autowired
|
|
|
private ServiceCaller serviceCaller;
|
|
|
|
...
|
...
|
@@ -65,7 +63,6 @@ public class GrassArticleServiceImpl implements IGrassArticleService{ |
|
|
GrassArticle article = new GrassArticle();
|
|
|
article.setAuthorUid(req.getAuthorUid());
|
|
|
article.setCreateTime(now);
|
|
|
article.setTopicId(req.getTopicId());
|
|
|
try{
|
|
|
grassArticleDao.insertArticleSeletive(article);
|
|
|
logger.info("insert grass article success, uid is {}, ariticle id is {}", article.getAuthorUid(), article.getId());
|
...
|
...
|
@@ -126,7 +123,36 @@ public class GrassArticleServiceImpl implements IGrassArticleService{ |
|
|
logger.warn("insert article skns fail,ariticle id is {}, e is {}",article.getId(), e );
|
|
|
}
|
|
|
|
|
|
//构建lables 数据
|
|
|
List<Integer> labels = Lists.newArrayList();
|
|
|
if(StringUtils.isNotEmpty(req.getLabelIds())){
|
|
|
labels = Arrays.stream(req.getLabelIds().split(",")).map(Integer::valueOf).collect(Collectors.toList());
|
|
|
if(labels.size() > 5){
|
|
|
logger.info("publishArticle , article products more than most publish number");
|
|
|
// throw new ServiceException(ServiceError.GRASS_ARTICLE_LABLES_MORE);
|
|
|
}
|
|
|
|
|
|
List<GrassArticleLabel> grassArticleLabels = buildArticleLabels(article.getId(), labels);
|
|
|
try{
|
|
|
if(CollectionUtils.isNotEmpty(grassArticleLabels)){
|
|
|
grassArticleLabelDao.insertArticleLabels(grassArticleLabels);
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
logger.warn("publishArticle ,grassArticleLableDao insertArticleLables error, uid is {}, e is {}", req.getAuthorUid(), e);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private List<GrassArticleLabel> buildArticleLabels(int articleId, List<Integer> lableList ){
|
|
|
List<GrassArticleLabel> grassArticleLables = Lists.newArrayList();
|
|
|
for (Integer lableId : lableList) {
|
|
|
GrassArticleLabel grassArticleLable = new GrassArticleLabel();
|
|
|
grassArticleLable.setArticleId(articleId);
|
|
|
grassArticleLable.setLabelId(lableId);
|
|
|
grassArticleLable.setCreateTime(System.currentTimeMillis());
|
|
|
grassArticleLables.add(grassArticleLable);
|
|
|
}
|
|
|
return grassArticleLables;
|
|
|
}
|
|
|
|
|
|
private String getBlock(String templatName, String data){
|
...
|
...
|
@@ -249,7 +275,6 @@ public class GrassArticleServiceImpl implements IGrassArticleService{ |
|
|
if(req.getTopicId() !=null){
|
|
|
GrassArticle grassArticle = new GrassArticle();
|
|
|
grassArticle.setId(articleId);
|
|
|
grassArticle.setTopicId(req.getTopicId());
|
|
|
grassArticle.setUpdateTime(System.currentTimeMillis());
|
|
|
grassArticleDao.updateByPrimaryKeySelective(grassArticle);
|
|
|
}
|
...
|
...
|
@@ -330,10 +355,11 @@ public class GrassArticleServiceImpl implements IGrassArticleService{ |
|
|
List<Integer> ids = articleList.stream().map(GrassArticle::getId).collect(Collectors.toList());
|
|
|
List<GrassArticleBlock> grassArticleContentList = grassArticleBlockDao.selectByArticleIds(ids);
|
|
|
List<GrassArticleProduct> grassArticlePoductList = grassArticleProductDao.selectByArticleIds(ids);
|
|
|
|
|
|
List<GrassArticleLabel> labelList = grassArticleLabelDao.selectByArticleIdList(ids);
|
|
|
Map<Integer, List<String>> imgMap = Maps.newHashMap();
|
|
|
Map<Integer,String> textMap = Maps.newHashMap();
|
|
|
Map<Integer, List<Integer>> sknMap = Maps.newHashMap();
|
|
|
Map<Integer, List<JSONObject>> labelMap = buildLabelInfoMap(labelList);
|
|
|
grassArticleContentList.forEach(content ->{
|
|
|
if ("image".equals(content.getTemplateKey())) {
|
|
|
List<String> images = imgMap.get(content.getArticleId());
|
...
|
...
|
@@ -368,7 +394,6 @@ public class GrassArticleServiceImpl implements IGrassArticleService{ |
|
|
rspBo.setArticleId(article.getId());
|
|
|
rspBo.setArticleContent(textMap.get(article.getId()));
|
|
|
rspBo.setAuthorUid(article.getAuthorUid());
|
|
|
rspBo.setTopicId(article.getTopicId());
|
|
|
// rspBo.setTopicName(getArticleName(article.getTopicId()));
|
|
|
rspBo.setNickName("");
|
|
|
rspBo.setCommentCount(article.getCommentCount());
|
...
|
...
|
@@ -379,6 +404,7 @@ public class GrassArticleServiceImpl implements IGrassArticleService{ |
|
|
rspBo.setAuthStatus(article.getAuthStatus());
|
|
|
rspBo.setSource(article.getArticleType());
|
|
|
rspBo.setImgList(imgMap.get(article.getId()));
|
|
|
rspBo.setLabelList(labelMap.get(article.getId()));
|
|
|
rspBo.setIsTop(article.getIsTop());
|
|
|
rspBo.setIsRecommend(article.getIsRecommend());
|
|
|
rspBoList.add(rspBo);
|
...
|
...
|
@@ -386,13 +412,32 @@ public class GrassArticleServiceImpl implements IGrassArticleService{ |
|
|
return rspBoList;
|
|
|
}
|
|
|
|
|
|
private String getArticleName(int id){
|
|
|
GrassTopic topic = grassTopicDAO.selectByPrimaryKey(id);
|
|
|
if(topic != null){
|
|
|
return topic.getTopicName();
|
|
|
private Map<Integer, List<JSONObject>> buildLabelInfoMap(List<GrassArticleLabel> articleLabelList){
|
|
|
Map<Integer, List<JSONObject>> labelRspMap = Maps.newHashMap();
|
|
|
if(CollectionUtils.isEmpty(articleLabelList)){
|
|
|
return labelRspMap;
|
|
|
}
|
|
|
return "";
|
|
|
List<Integer> lableIdList = articleLabelList.stream().map(GrassArticleLabel::getLabelId).distinct().collect(Collectors.toList());
|
|
|
List<GrassLabel> lableList = grassLabelDAO.selectBatchByIds(Sets.newHashSet(lableIdList));
|
|
|
Map<Integer, String> labelInfoMap = new HashMap<>();
|
|
|
lableList.forEach(grassLabel -> {
|
|
|
labelInfoMap.put(grassLabel.getId(), grassLabel.getLabelName()); }
|
|
|
);
|
|
|
articleLabelList.forEach(grassArticleLable -> {
|
|
|
List<JSONObject> list = labelRspMap.get(grassArticleLable.getArticleId());
|
|
|
if(list == null){
|
|
|
list = Lists.newArrayList();
|
|
|
}
|
|
|
JSONObject rspBO = new JSONObject();
|
|
|
rspBO.put("id",grassArticleLable.getLabelId());
|
|
|
rspBO.put("name",labelInfoMap.get(grassArticleLable.getLabelId()));
|
|
|
list.add(rspBO);
|
|
|
labelRspMap.put(grassArticleLable.getArticleId(), list);
|
|
|
});
|
|
|
|
|
|
return labelRspMap;
|
|
|
}
|
|
|
|
|
|
private void publishCheck(GrassArticleReq req) throws PlatformException {
|
|
|
if(req.getAuthorUid() ==null){
|
|
|
logger.info("publishCheck uid is null");
|
...
|
...
|
|