...
|
...
|
@@ -8,11 +8,16 @@ 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.yoho.service.model.social.request.BaseReqBO;
|
|
|
import com.yoho.service.model.social.request.UicUserReqBO;
|
|
|
import com.yoho.service.model.social.response.UserInfoRspBO;
|
|
|
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.*;
|
|
|
import com.yohobuy.platform.dal.guang.IAuthorDAO;
|
|
|
import com.yohobuy.platform.dal.guang.model.Author;
|
|
|
import com.yohobuy.platform.grass.service.IGrassArticleService;
|
|
|
import com.yohobuy.platform.model.common.PageResponseVO;
|
|
|
import com.yohobuy.platform.model.grass.request.GrassArticleReq;
|
...
|
...
|
@@ -22,6 +27,7 @@ import org.apache.commons.lang3.StringUtils; |
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.Resource;
|
...
|
...
|
@@ -49,12 +55,18 @@ public class GrassArticleServiceImpl implements IGrassArticleService{ |
|
|
@Resource
|
|
|
private IGrassLabelDAO grassLabelDAO;
|
|
|
|
|
|
@Resource
|
|
|
private IAuthorDAO authorDAO;
|
|
|
|
|
|
@Autowired
|
|
|
private ServiceCaller serviceCaller;
|
|
|
|
|
|
private final static String BLOCK_TEXT = "text";
|
|
|
private final static String BLOCK_IMAGE = "image";
|
|
|
|
|
|
@Value("${uic.service.url:http://uic.yohoops.org/uic}")
|
|
|
private String uicUrl;
|
|
|
|
|
|
@Override
|
|
|
public void publishArticle(GrassArticleReq req) throws PlatformException {
|
|
|
logger.info("enter publishArticle, req is {}", req);
|
...
|
...
|
@@ -224,15 +236,17 @@ public class GrassArticleServiceImpl implements IGrassArticleService{ |
|
|
Integer articleId = req.getArticleId();
|
|
|
Integer source = req.getSource()==null || req.getSource() == 0 ? null:req.getSource();
|
|
|
Integer authStatus = req.getAuthStatus()==null ||req.getAuthStatus()==8 ? null:req.getAuthStatus();
|
|
|
Integer authorUid =null;
|
|
|
Integer isRecommend = req.getIsRecommend()==null ||req.getIsRecommend()==8 ? null:req.getIsRecommend();
|
|
|
Integer isTop = req.getIsTop()==null ||req.getIsTop()==8 ? null:req.getIsTop();
|
|
|
List<Integer> authorUids =null;
|
|
|
String authName = req.getPublisher();
|
|
|
String startTime = req.getStartTimeStr();
|
|
|
String endTime = req.getEndTimeStr();
|
|
|
Long startTimeInt = null;
|
|
|
Long endTimeInt = null;
|
|
|
if(StringUtils.isNumeric(authName)){
|
|
|
authorUid = Integer.valueOf(authName);
|
|
|
};
|
|
|
if(StringUtils.isNotEmpty(authName)){
|
|
|
authorUids = getUidByNickName(authName);
|
|
|
}
|
|
|
if(StringUtils.isNotEmpty(startTime)){
|
|
|
startTimeInt = Long.valueOf(startTime);
|
|
|
}
|
...
|
...
|
@@ -241,10 +255,10 @@ public class GrassArticleServiceImpl implements IGrassArticleService{ |
|
|
}
|
|
|
int page = req.getPage();
|
|
|
int size = req.getSize();
|
|
|
int total = grassArticleDao.selectArticleCount(articleId, source, authStatus,authorUid,startTimeInt, endTimeInt);
|
|
|
int total = grassArticleDao.selectArticleCount(articleId, source, authStatus,authorUids,isRecommend, isTop,startTimeInt, endTimeInt);
|
|
|
logger.info("getArticleList: grassArticleDao.getArticleCount: articleId is {}, source is {}, total is {}", articleId, source, total);
|
|
|
int offset = (page - 1) * size;
|
|
|
List<GrassArticle> articleList = grassArticleDao.selectArticleList(articleId, source, authStatus,authorUid,startTimeInt, endTimeInt,offset, size);
|
|
|
List<GrassArticle> articleList = grassArticleDao.selectArticleList(articleId, source, authStatus,authorUids,isRecommend, isTop,startTimeInt, endTimeInt,offset, size);
|
|
|
PageResponseVO rsp = new PageResponseVO();
|
|
|
rsp.setList(buildArticleDetail(articleList));
|
|
|
rsp.setTotal(total);
|
...
|
...
|
@@ -253,6 +267,25 @@ public class GrassArticleServiceImpl implements IGrassArticleService{ |
|
|
return rsp;
|
|
|
}
|
|
|
|
|
|
private List<Integer> getUidByNickName(String nickName){
|
|
|
String url = uicUrl + "/UserInfoRest/getUserInfoByNickName";
|
|
|
BaseReqBO<String> uicReq = new BaseReqBO<>();
|
|
|
uicReq.setParam(nickName);
|
|
|
logger.info("getUidByNickName nickName={}, url={}", uicReq.getParam(), url);
|
|
|
try{
|
|
|
UserInfoRspBO[] userInfoRspBOS = serviceCaller.post("uic.getUserInfoByNickName", url, uicReq, UserInfoRspBO[].class, null).get();
|
|
|
if(userInfoRspBOS == null || userInfoRspBOS.length == 0){
|
|
|
return null;
|
|
|
}
|
|
|
//用户的基本信息
|
|
|
List<UserInfoRspBO> userInfoRspBOList = Arrays.asList(userInfoRspBOS);
|
|
|
List<Integer> uids = userInfoRspBOList.stream().map(userInfoRspBO -> userInfoRspBO.getYohoUid()).distinct().collect(Collectors.toList());
|
|
|
return uids;
|
|
|
}catch (Exception e){
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@Database(ForceMaster = true)
|
|
|
public void updateArticle(GrassArticleReq req) throws PlatformException {
|
...
|
...
|
@@ -406,14 +439,26 @@ public class GrassArticleServiceImpl implements IGrassArticleService{ |
|
|
skns.add(product.getProductSkn());
|
|
|
sknMap.put(product.getArticleId(), skns);
|
|
|
});
|
|
|
|
|
|
List<Integer> uids = articleList.stream().filter(article -> article.getAuthorType()==1).map(GrassArticle::getAuthorUid).distinct().collect(Collectors.toList());
|
|
|
List<Integer> authoruids = articleList.stream().filter(article -> article.getAuthorType()==2).map(GrassArticle::getAuthorUid).distinct().collect(Collectors.toList());
|
|
|
//用户的基本信息(昵称 头像等)
|
|
|
Map<Integer,UserInfoRspBO> userInfoMap = getUsersInfo(uids);
|
|
|
Map<Integer,Author> authorInfoMap = getAuthorInfo(authoruids);
|
|
|
List<ArticleDetailRspBo> rspBoList = Lists.newArrayList();
|
|
|
articleList.forEach(article -> {
|
|
|
ArticleDetailRspBo rspBo = new ArticleDetailRspBo();
|
|
|
rspBo.setArticleId(article.getId());
|
|
|
rspBo.setArticleContent(textMap.get(article.getId()));
|
|
|
rspBo.setArticleContent(textMap.get(article.getId()) == null ? "" : textMap.get(article.getId()));
|
|
|
rspBo.setAuthorUid(article.getAuthorUid());
|
|
|
// rspBo.setTopicName(getArticleName(article.getTopicId()));
|
|
|
rspBo.setNickName("");
|
|
|
if(article.getAuthorType() ==2){
|
|
|
Author author = authorInfoMap.get(article.getAuthorUid());
|
|
|
rspBo.setNickName(author == null ? "" : author.getUsername());
|
|
|
}else {
|
|
|
UserInfoRspBO userinfo = userInfoMap.get(article.getAuthorUid());
|
|
|
rspBo.setNickName(userinfo == null ? "" : userinfo.getNickName());
|
|
|
}
|
|
|
rspBo.setCommentCount(article.getCommentCount());
|
|
|
rspBo.setShareCount(article.getShareCount());
|
|
|
rspBo.setFavorCount(article.getFavoriteCount());
|
...
|
...
|
@@ -430,6 +475,42 @@ public class GrassArticleServiceImpl implements IGrassArticleService{ |
|
|
return rspBoList;
|
|
|
}
|
|
|
|
|
|
//调uic 获取用户的基本信息
|
|
|
private Map<Integer,UserInfoRspBO> getUsersInfo(List<Integer> uidList) {
|
|
|
Map<Integer,UserInfoRspBO> resultMap = new HashMap<>();
|
|
|
String url = uicUrl + "/UserInfoRest/getUserInfoListByYohoUid";
|
|
|
UicUserReqBO req = new UicUserReqBO();
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
for(Integer u : uidList){
|
|
|
sb.append(u).append(",");
|
|
|
}
|
|
|
String uids = org.apache.commons.lang.StringUtils.removeEnd(sb.toString(), ",");
|
|
|
req.setUids(uids);
|
|
|
try{
|
|
|
logger.info("getUsersInfo uids={}, url={}", uids, url);
|
|
|
UserInfoRspBO[] userBaseInfo = serviceCaller.post("uic.getUserInfoListByYohoUid", url, req, UserInfoRspBO[].class, null).get();
|
|
|
for(UserInfoRspBO bo : userBaseInfo){
|
|
|
resultMap.put(bo.getUid(), bo);
|
|
|
}
|
|
|
return resultMap;
|
|
|
}catch (Exception e){
|
|
|
return resultMap;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private Map<Integer,Author> getAuthorInfo(List<Integer> uidList) {
|
|
|
Map<Integer,Author> resultMap = new HashMap<>();
|
|
|
if(CollectionUtils.isEmpty(uidList)){
|
|
|
return resultMap;
|
|
|
}
|
|
|
List<Author> authors = authorDAO.selectByUids(uidList);
|
|
|
authors.forEach(author -> {
|
|
|
resultMap.put(author.getUid(), author);
|
|
|
});
|
|
|
return resultMap;
|
|
|
}
|
|
|
|
|
|
private Map<Integer, List<JSONObject>> buildLabelInfoMap(List<GrassArticleLabel> articleLabelList){
|
|
|
Map<Integer, List<JSONObject>> labelRspMap = Maps.newHashMap();
|
|
|
if(CollectionUtils.isEmpty(articleLabelList)){
|
...
|
...
|
|