|
|
package com.yohobuy.platform.grass.service.impl;
|
|
|
|
|
|
import com.yoho.core.common.utils.DateUtil;
|
|
|
import com.yoho.core.rest.client.ServiceCaller;
|
|
|
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.helper.UserHelper;
|
|
|
import com.yohobuy.platform.dal.common.BeanConvertUtil;
|
|
|
import com.yohobuy.platform.dal.grass.IGrassArticleCommentDao;
|
...
|
...
|
@@ -12,13 +16,14 @@ import com.yohobuy.platform.model.grass.request.ArticleCommentModifyStatusReq; |
|
|
import com.yohobuy.platform.model.grass.request.ArticleCommentQueryReq;
|
|
|
import com.yohobuy.platform.model.grass.response.ArticleCommentQueryRsp;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
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.Service;
|
|
|
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -29,38 +34,97 @@ public class GrassArticleCommentServiceImpl implements IGrassArticleCommentServi |
|
|
private static final Logger logger = LoggerFactory.getLogger(GrassArticleCommentServiceImpl.class);
|
|
|
@Autowired
|
|
|
private IGrassArticleCommentDao grassArticleCommentDao;
|
|
|
@Autowired
|
|
|
private ServiceCaller serviceCaller;
|
|
|
@Value("${uic.service.url:http://uic.yohoops.org/uic}")
|
|
|
private String uicUrl;
|
|
|
|
|
|
@Override
|
|
|
public PageResponseVO<ArticleCommentQueryRsp> queryComment(ArticleCommentQueryReq req) {
|
|
|
PageResponseVO<ArticleCommentQueryRsp> result = new PageResponseVO<>();
|
|
|
logger.info("queryComment:before selectTotalByCommentQueryReq,param is {}",req);
|
|
|
int total = grassArticleCommentDao.selectTotalByCommentQueryReq(req.getStatus(),req.getUid(),req.getDestId(),req.getBeginTime(),req.getEndTime(),
|
|
|
GrassArticleCommentQueryDo.ColumnType.ARTICLE.getValue());
|
|
|
result.setTotal(total);
|
|
|
PageResponseVO<ArticleCommentQueryRsp> result = new PageResponseVO<>();
|
|
|
result.setSize(req.getSize());
|
|
|
result.setPage(req.getPage());
|
|
|
|
|
|
List<Integer> uids = new ArrayList<>();
|
|
|
if(StringUtils.isNotBlank(req.getNickname())){
|
|
|
List<UserInfoRspBO> userInfoRspBOList = queryUsersByNickName(req.getNickname());
|
|
|
List<Integer> cUids = userInfoRspBOList == null ? null : userInfoRspBOList.stream().map(obj ->obj.getYohoUid()).collect(Collectors.toList());
|
|
|
if(CollectionUtils.isEmpty(cUids)){
|
|
|
return result;
|
|
|
}
|
|
|
uids.addAll(cUids);
|
|
|
}
|
|
|
if(req.getUid() != null){
|
|
|
uids.add(req.getUid());
|
|
|
}
|
|
|
uids = uids.isEmpty()?null:uids;
|
|
|
int total = grassArticleCommentDao.selectTotalByCommentQueryReq(req.getStatus(),uids,req.getDestId(),req.getBeginTime(),req.getEndTime(),
|
|
|
GrassArticleCommentQueryDo.ColumnType.ARTICLE.getValue());
|
|
|
result.setTotal(total);
|
|
|
|
|
|
if(total == 0){
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
List<ArticleCommentQueryRsp> commentQueryRspList = BeanConvertUtil.convertList(grassArticleCommentDao.selectByCommentQueryReq(req.getStatus(),req.getUid(),req.getDestId(),
|
|
|
List<ArticleCommentQueryRsp> commentQueryRspList = BeanConvertUtil.convertList(grassArticleCommentDao.selectByCommentQueryReq(req.getStatus(),uids,req.getDestId(),
|
|
|
req.getBeginTime(),req.getEndTime(),GrassArticleCommentQueryDo.ColumnType.ARTICLE.getValue(),req.getStart(),req.getSize()),ArticleCommentQueryRsp.class);
|
|
|
if(CollectionUtils.isEmpty(commentQueryRspList)){
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
List<Integer> ids = commentQueryRspList.stream().map(com->com.getId()).collect(Collectors.toList());
|
|
|
List<Integer> rspUids = commentQueryRspList.stream().map(comm->comm.getUid()).collect(Collectors.toList());
|
|
|
Map<Integer,UserInfoRspBO> userInfoRspBOMap = getUsersInfo(rspUids);
|
|
|
Map<Integer,ChildCommentTotalBo> childMap = BeanConvertUtil.convertMap(grassArticleCommentDao.selectChildTotalMapByIds(ids),ChildCommentTotalBo.class);
|
|
|
commentQueryRspList.forEach(com->{
|
|
|
ChildCommentTotalBo bo = childMap.get(com.getId());
|
|
|
if(bo != null){
|
|
|
com.setChildTotal(bo.getTotal());
|
|
|
}
|
|
|
UserInfoRspBO userInfoRspBO = userInfoRspBOMap.get(com.getUid());
|
|
|
if(null != userInfoRspBO){
|
|
|
com.setNickname(userInfoRspBO.getNickName());
|
|
|
}
|
|
|
});
|
|
|
|
|
|
result.setList(commentQueryRspList);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
//调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);
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
private List<UserInfoRspBO> queryUsersByNickName(String nickname){
|
|
|
String url = uicUrl + "/UserInfoRest/getUserInfoByNickName";
|
|
|
BaseReqBO<String> uicReq = new BaseReqBO<>();
|
|
|
uicReq.setParam(nickname);
|
|
|
logger.info("queryUsersByNickName before uic.getUserInfoByNickName, nickName={}, url={}", uicReq.getParam(), url);
|
|
|
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);
|
|
|
return userInfoRspBOList;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void modifyStatus(ArticleCommentModifyStatusReq req) {
|
|
|
Integer reviewerId = new UserHelper().getUserId();
|
...
|
...
|
|