Authored by liangyi.chen@yoho.cn

增加通知记录

... ... @@ -23,6 +23,7 @@ import com.yohobuy.platform.dal.guang.model.Author;
import com.yohobuy.platform.grass.cache.UserInfoCacheHelper;
import com.yohobuy.platform.grass.service.IGrassArticleService;
import com.yohobuy.platform.grass.service.IGrassRefreshCacheService;
import com.yohobuy.platform.grass.util.MsgInformSceneEnum;
import com.yohobuy.platform.model.common.PageResponseVO;
import com.yohobuy.platform.model.grass.request.GrassArticleProductBo;
import com.yohobuy.platform.model.grass.request.GrassArticleReq;
... ... @@ -37,6 +38,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.*;
... ... @@ -76,6 +78,8 @@ public class GrassArticleServiceImpl implements IGrassArticleService {
private IGrassTopicDAO grassTopicDAO;
@Resource
private IAuthorDAO authorDAO;
@Resource
private IGrassInformRecordDao grassInformRecordDao;
@Autowired
private ServiceCaller serviceCaller;
... ... @@ -474,9 +478,27 @@ public class GrassArticleServiceImpl implements IGrassArticleService {
}
//Add 从没推荐到推荐,发送站内信通知
if (isRecommend == 1 && articleInfo.getIsRecommend() == 0) {
//TODO 站内信通知只发送一次 获取文章内容
sendInBoxMessageFroRecommendAndAuth(req , GrassInboxBusinessTypeEnum.SYSTEM_RECOMMEND_ARTICLE.
getBusinessType());
//文章推荐站内信通知只发送一次 发送过不会再发送
List<GrassInformRecord> grassInformRecords = grassInformRecordDao.selectByArticleIdAndUidAndSceneType(req.getArticleId(),
articleInfo.getAuthorUid(), MsgInformSceneEnum.ARTICLE_RECOMMEND_INFORM.getType());
if(CollectionUtils.isEmpty(grassInformRecords)){
//文章推荐通知发送成功后,通知记录表留下记录
JSONObject result = sendInBoxMessageFroRecommendAndAuth(req , GrassInboxBusinessTypeEnum.SYSTEM_RECOMMEND_ARTICLE.
getBusinessType());
int code = result.getIntValue("code");
if(code == 200){
logger.info("Article Recommend Send Message Success ArticleId is {}" , req.getArticleId());
GrassInformRecord grassInformRecord = new GrassInformRecord();
grassInformRecord.setArticleId(req.getArticleId());
grassInformRecord.setUid(articleInfo.getAuthorUid());
grassInformRecord.setSceneType(MsgInformSceneEnum.ARTICLE_RECOMMEND_INFORM.getType());
grassInformRecord.setCreateTime(com.yoho.core.common.utils.DateUtil.getCurrentTimeSecond());
grassInformRecordDao.insert(grassInformRecord);
}
}else{
logger.info("The Article Recommend Inform had send once , articleId is {} , uid is {]" ,
req.getArticleId() , articleInfo.getAuthorUid());
}
}
}
if (isTop != null) {
... ... @@ -611,12 +633,12 @@ public class GrassArticleServiceImpl implements IGrassArticleService {
}
//审核不通过以及文章被推荐时发送站内信通知
private void sendInBoxMessageFroRecommendAndAuth(GrassArticleReq grassArticleReq , Integer businessType) {
private JSONObject sendInBoxMessageFroRecommendAndAuth(GrassArticleReq grassArticleReq , Integer businessType) {
logger.info("enter articleRecommend sendInBoxMessageFroRecommend.");
GrassArticle article = grassArticleDao.selectByPrimaryKey(grassArticleReq.getArticleId());
if(article == null){
logger.warn("article is not exist");
return;
return new JSONObject();
}
List<GrassInBoxAddReq> addReqList = new ArrayList<>();
GrassInBoxAddReq addReq = new GrassInBoxAddReq();
... ... @@ -624,16 +646,21 @@ public class GrassArticleServiceImpl implements IGrassArticleService {
addReq.setOptUid(grassArticleReq.getRecommendAccount() == null ? 0 : Integer.valueOf
(grassArticleReq.getRecommendAccount()));
if (article.getArticleType() == GrassArticle.AUTHORTYPE_EDITOR) {
return;//小编用户不发消息
return new JSONObject();//小编用户不发消息
}
addReq.setBusinessType(businessType);
addReq.setUid(article.getAuthorUid());
List<GrassArticleBlock> grassArticleContentList = grassArticleBlockDao.selectByArticleId(article.getId());
String text = "";
for (GrassArticleBlock contentBlock : grassArticleContentList) {
if ("text".equals(contentBlock.getTemplateKey())) {
JSONObject data = JSON.parseObject(contentBlock.getContentData());
text = JSON.parseObject(data.getString("data")).getString("text");
//针对长文章,文章内容取title
if(article.getSort() != null && article.getSort() == 2){
text = article.getArticleTitle();
}else{
for (GrassArticleBlock contentBlock : grassArticleContentList) {
if ("text".equals(contentBlock.getTemplateKey())) {
JSONObject data = JSON.parseObject(contentBlock.getContentData());
text = JSON.parseObject(data.getString("data")).getString("text");
}
}
}
String noteContent = (StringUtils.isBlank(text)||text.length()<15?text: text.substring(0,15))+"...";
... ... @@ -651,15 +678,19 @@ public class GrassArticleServiceImpl implements IGrassArticleService {
addReq.setParams(params);
addReqList.add(addReq);
if (CollectionUtils.isEmpty(addReqList)) {
return;
return new JSONObject();
}
try {
logger.info("before gateway.addBatchGrassInBox.addReqList size is {}", addReqList.size());
String url = apiUrl + "/guang/api/addBatchInBox/?client_type=h5";
serviceCaller.post("gateway.addBatchGrassInBox", url, addReqList, String.class, null);
JSONObject result = serviceCaller.post("gateway.addBatchGrassInBox", url, addReqList,
JSONObject.class, null).get();
return result;
} catch (Exception e) {
logger.info("failed addBatchInBox, error is {}", e);
}
return new JSONObject();
}
//来自晒单的文章 被推荐
... ...
package com.yohobuy.platform.grass.util;
public enum TblCrawlerEnum {
WECHAT(1, "微信公众号"),
MICROBLOG(2, "微博");
public enum MsgInformSceneEnum {
ARTICLE_RECOMMEND_INFORM(1, "文章推荐通知");
private Integer type;
private String name;
private TblCrawlerEnum(Integer type, String name) {
private MsgInformSceneEnum(Integer type, String name) {
this.type = type;
this.name = name;
}
public static String getNameByType(int type) {
for (TblCrawlerEnum e : values()) {
for (MsgInformSceneEnum e : values()) {
if (type == e.getType()) {
return e.getName();
}
... ...
... ... @@ -357,6 +357,7 @@ datasources:
- com.yohobuy.platform.dal.grass.IGrassTopicGroupDAO
- com.yohobuy.platform.dal.grass.IGrassArticleTopicDao
- com.yohobuy.platform.dal.grass.IGrassVirtualGroupDao
- com.yohobuy.platform.dal.grass.IGrassInformRecordDao
yhb_promotion:
servers:
... ...
... ... @@ -355,6 +355,7 @@ datasources:
- com.yohobuy.platform.dal.grass.IGrassTopicGroupDAO
- com.yohobuy.platform.dal.grass.IGrassArticleTopicDao
- com.yohobuy.platform.dal.grass.IGrassVirtualGroupDao
- com.yohobuy.platform.dal.grass.IGrassInformRecordDao
yhb_promotion:
servers:
... ...