|
|
package com.yohobuy.platform.grass.service.impl;
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.yohobuy.platform.common.exception.PlatformException;
|
|
|
import com.yohobuy.platform.common.util.DateUtil;
|
|
|
import com.yohobuy.platform.dal.grass.IGrassArticleDao;
|
|
|
import com.yohobuy.platform.dal.grass.IGrassArticleImageDao;
|
|
|
import com.yohobuy.platform.dal.grass.IGrassArticleSknDao;
|
|
|
import com.yohobuy.platform.dal.grass.model.GrassArticle;
|
|
|
import com.yohobuy.platform.dal.grass.model.GrassArticleImage;
|
|
|
import com.yohobuy.platform.dal.grass.model.GrassArticleSkn;
|
|
|
import com.yohobuy.platform.grass.service.IGrassArticleService;
|
|
|
import com.yohobuy.platform.model.grass.request.GrassArticleReq;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
*/
|
|
|
@Component
|
|
|
public class GrassArticleServiceImpl implements IGrassArticleService{
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(GrassArticleServiceImpl.class);
|
|
|
|
|
|
@Resource
|
|
|
private IGrassArticleDao grassArticleDao;
|
|
|
@Resource
|
|
|
private IGrassArticleImageDao grassArticleImageDao;
|
|
|
@Resource
|
|
|
private IGrassArticleSknDao grassArticleSknDao;
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public void publishArticle(GrassArticleReq req) throws PlatformException {
|
|
|
logger.info("enter publishArticle, req is {}", req);
|
|
|
publishCheck(req);
|
|
|
|
|
|
GrassArticle article = new GrassArticle();
|
|
|
article.setAuthorUid(req.getArticleUid());
|
|
|
article.setArticleContent(req.getContent());
|
|
|
article.setPublishTime(DateUtil.getCurrentTimeSeconds());
|
|
|
article.setTopicId(req.getTopicId());
|
|
|
try{
|
|
|
grassArticleDao.insertArticleSeletive(article);
|
|
|
logger.info("insert grass article success, uid is {}, ariticle id is {}", article.getAuthorUid(), article.getId());
|
|
|
}catch (Exception e){
|
|
|
logger.warn("insert grass article fail, uid is {}, e is {}",req.getArticleUid(), e );
|
|
|
throw new PlatformException("publish article failed", 402);
|
|
|
}
|
|
|
|
|
|
try{
|
|
|
List<GrassArticleImage> imageList = Lists.newArrayList();
|
|
|
|
|
|
for (String img: req.getArticleImages()) {
|
|
|
GrassArticleImage image = new GrassArticleImage();
|
|
|
image.setArticleId(article.getGuangArticleId());
|
|
|
image.setImgSrc(img);
|
|
|
image.setCreateTime(DateUtil.getCurrentTimeSeconds());
|
|
|
imageList.add(image);
|
|
|
}
|
|
|
grassArticleImageDao.insertArticleImgs(imageList);
|
|
|
logger.info("insert grass article images success, ariticle id is {}, imageList size is {}", article.getId(), imageList.size());
|
|
|
}catch (Exception e){
|
|
|
logger.warn("insert article images fail,ariticle id is {}, e is {}",article.getId(), e );
|
|
|
}
|
|
|
|
|
|
try{
|
|
|
List<GrassArticleSkn> sknList = Lists.newArrayList();
|
|
|
for (String skn: req.getArticleSkns()) {
|
|
|
GrassArticleSkn grassArticleSkn = new GrassArticleSkn();
|
|
|
grassArticleSkn.setArticleId(article.getGuangArticleId());
|
|
|
grassArticleSkn.setProductSkn(Integer.valueOf(skn));
|
|
|
grassArticleSkn.setCreateTime(DateUtil.getCurrentTimeSeconds());
|
|
|
sknList.add(grassArticleSkn);
|
|
|
}
|
|
|
grassArticleSknDao.insertArticleSkns(sknList);
|
|
|
logger.info("insert grass article skns success, ariticle id is {}, sknList size is {}", article.getId(), sknList.size());
|
|
|
}catch (Exception e){
|
|
|
logger.warn("insert article skns fail,ariticle id is {}, e is {}",article.getId(), e );
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
private void publishCheck(GrassArticleReq req) throws PlatformException {
|
|
|
if(req.getArticleUid() ==null){
|
|
|
logger.info("publishCheck uid is null");
|
|
|
throw new PlatformException("publish uid is null", 403);
|
|
|
}
|
|
|
if(req.getArticleImages() ==null || req.getArticleImages().size()< 1){
|
|
|
logger.info("publishCheck images is null");
|
|
|
throw new PlatformException("publish images is null", 403);
|
|
|
}
|
|
|
if(req.getArticleSkns() ==null || req.getArticleSkns().size()< 1){
|
|
|
logger.info("publishCheck skn is null");
|
|
|
throw new PlatformException("publish skn is null", 403);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
} |
...
|
...
|
|