Authored by liangyi.chen@yoho.cn

增加通知记录

@@ -23,6 +23,7 @@ import com.yohobuy.platform.dal.guang.model.Author; @@ -23,6 +23,7 @@ import com.yohobuy.platform.dal.guang.model.Author;
23 import com.yohobuy.platform.grass.cache.UserInfoCacheHelper; 23 import com.yohobuy.platform.grass.cache.UserInfoCacheHelper;
24 import com.yohobuy.platform.grass.service.IGrassArticleService; 24 import com.yohobuy.platform.grass.service.IGrassArticleService;
25 import com.yohobuy.platform.grass.service.IGrassRefreshCacheService; 25 import com.yohobuy.platform.grass.service.IGrassRefreshCacheService;
  26 +import com.yohobuy.platform.grass.util.MsgInformSceneEnum;
26 import com.yohobuy.platform.model.common.PageResponseVO; 27 import com.yohobuy.platform.model.common.PageResponseVO;
27 import com.yohobuy.platform.model.grass.request.GrassArticleProductBo; 28 import com.yohobuy.platform.model.grass.request.GrassArticleProductBo;
28 import com.yohobuy.platform.model.grass.request.GrassArticleReq; 29 import com.yohobuy.platform.model.grass.request.GrassArticleReq;
@@ -37,6 +38,7 @@ import org.slf4j.LoggerFactory; @@ -37,6 +38,7 @@ import org.slf4j.LoggerFactory;
37 import org.springframework.beans.factory.annotation.Autowired; 38 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.beans.factory.annotation.Value; 39 import org.springframework.beans.factory.annotation.Value;
39 import org.springframework.stereotype.Component; 40 import org.springframework.stereotype.Component;
  41 +import org.springframework.web.bind.annotation.ResponseBody;
40 42
41 import javax.annotation.Resource; 43 import javax.annotation.Resource;
42 import java.util.*; 44 import java.util.*;
@@ -76,6 +78,8 @@ public class GrassArticleServiceImpl implements IGrassArticleService { @@ -76,6 +78,8 @@ public class GrassArticleServiceImpl implements IGrassArticleService {
76 private IGrassTopicDAO grassTopicDAO; 78 private IGrassTopicDAO grassTopicDAO;
77 @Resource 79 @Resource
78 private IAuthorDAO authorDAO; 80 private IAuthorDAO authorDAO;
  81 + @Resource
  82 + private IGrassInformRecordDao grassInformRecordDao;
79 83
80 @Autowired 84 @Autowired
81 private ServiceCaller serviceCaller; 85 private ServiceCaller serviceCaller;
@@ -474,9 +478,27 @@ public class GrassArticleServiceImpl implements IGrassArticleService { @@ -474,9 +478,27 @@ public class GrassArticleServiceImpl implements IGrassArticleService {
474 } 478 }
475 //Add 从没推荐到推荐,发送站内信通知 479 //Add 从没推荐到推荐,发送站内信通知
476 if (isRecommend == 1 && articleInfo.getIsRecommend() == 0) { 480 if (isRecommend == 1 && articleInfo.getIsRecommend() == 0) {
477 - //TODO 站内信通知只发送一次 获取文章内容  
478 - sendInBoxMessageFroRecommendAndAuth(req , GrassInboxBusinessTypeEnum.SYSTEM_RECOMMEND_ARTICLE.  
479 - getBusinessType()); 481 + //文章推荐站内信通知只发送一次 发送过不会再发送
  482 + List<GrassInformRecord> grassInformRecords = grassInformRecordDao.selectByArticleIdAndUidAndSceneType(req.getArticleId(),
  483 + articleInfo.getAuthorUid(), MsgInformSceneEnum.ARTICLE_RECOMMEND_INFORM.getType());
  484 + if(CollectionUtils.isEmpty(grassInformRecords)){
  485 + //文章推荐通知发送成功后,通知记录表留下记录
  486 + JSONObject result = sendInBoxMessageFroRecommendAndAuth(req , GrassInboxBusinessTypeEnum.SYSTEM_RECOMMEND_ARTICLE.
  487 + getBusinessType());
  488 + int code = result.getIntValue("code");
  489 + if(code == 200){
  490 + logger.info("Article Recommend Send Message Success ArticleId is {}" , req.getArticleId());
  491 + GrassInformRecord grassInformRecord = new GrassInformRecord();
  492 + grassInformRecord.setArticleId(req.getArticleId());
  493 + grassInformRecord.setUid(articleInfo.getAuthorUid());
  494 + grassInformRecord.setSceneType(MsgInformSceneEnum.ARTICLE_RECOMMEND_INFORM.getType());
  495 + grassInformRecord.setCreateTime(com.yoho.core.common.utils.DateUtil.getCurrentTimeSecond());
  496 + grassInformRecordDao.insert(grassInformRecord);
  497 + }
  498 + }else{
  499 + logger.info("The Article Recommend Inform had send once , articleId is {} , uid is {]" ,
  500 + req.getArticleId() , articleInfo.getAuthorUid());
  501 + }
480 } 502 }
481 } 503 }
482 if (isTop != null) { 504 if (isTop != null) {
@@ -611,12 +633,12 @@ public class GrassArticleServiceImpl implements IGrassArticleService { @@ -611,12 +633,12 @@ public class GrassArticleServiceImpl implements IGrassArticleService {
611 } 633 }
612 634
613 //审核不通过以及文章被推荐时发送站内信通知 635 //审核不通过以及文章被推荐时发送站内信通知
614 - private void sendInBoxMessageFroRecommendAndAuth(GrassArticleReq grassArticleReq , Integer businessType) { 636 + private JSONObject sendInBoxMessageFroRecommendAndAuth(GrassArticleReq grassArticleReq , Integer businessType) {
615 logger.info("enter articleRecommend sendInBoxMessageFroRecommend."); 637 logger.info("enter articleRecommend sendInBoxMessageFroRecommend.");
616 GrassArticle article = grassArticleDao.selectByPrimaryKey(grassArticleReq.getArticleId()); 638 GrassArticle article = grassArticleDao.selectByPrimaryKey(grassArticleReq.getArticleId());
617 if(article == null){ 639 if(article == null){
618 logger.warn("article is not exist"); 640 logger.warn("article is not exist");
619 - return; 641 + return new JSONObject();
620 } 642 }
621 List<GrassInBoxAddReq> addReqList = new ArrayList<>(); 643 List<GrassInBoxAddReq> addReqList = new ArrayList<>();
622 GrassInBoxAddReq addReq = new GrassInBoxAddReq(); 644 GrassInBoxAddReq addReq = new GrassInBoxAddReq();
@@ -624,16 +646,21 @@ public class GrassArticleServiceImpl implements IGrassArticleService { @@ -624,16 +646,21 @@ public class GrassArticleServiceImpl implements IGrassArticleService {
624 addReq.setOptUid(grassArticleReq.getRecommendAccount() == null ? 0 : Integer.valueOf 646 addReq.setOptUid(grassArticleReq.getRecommendAccount() == null ? 0 : Integer.valueOf
625 (grassArticleReq.getRecommendAccount())); 647 (grassArticleReq.getRecommendAccount()));
626 if (article.getArticleType() == GrassArticle.AUTHORTYPE_EDITOR) { 648 if (article.getArticleType() == GrassArticle.AUTHORTYPE_EDITOR) {
627 - return;//小编用户不发消息 649 + return new JSONObject();//小编用户不发消息
628 } 650 }
629 addReq.setBusinessType(businessType); 651 addReq.setBusinessType(businessType);
630 addReq.setUid(article.getAuthorUid()); 652 addReq.setUid(article.getAuthorUid());
631 List<GrassArticleBlock> grassArticleContentList = grassArticleBlockDao.selectByArticleId(article.getId()); 653 List<GrassArticleBlock> grassArticleContentList = grassArticleBlockDao.selectByArticleId(article.getId());
632 String text = ""; 654 String text = "";
633 - for (GrassArticleBlock contentBlock : grassArticleContentList) {  
634 - if ("text".equals(contentBlock.getTemplateKey())) {  
635 - JSONObject data = JSON.parseObject(contentBlock.getContentData());  
636 - text = JSON.parseObject(data.getString("data")).getString("text"); 655 + //针对长文章,文章内容取title
  656 + if(article.getSort() != null && article.getSort() == 2){
  657 + text = article.getArticleTitle();
  658 + }else{
  659 + for (GrassArticleBlock contentBlock : grassArticleContentList) {
  660 + if ("text".equals(contentBlock.getTemplateKey())) {
  661 + JSONObject data = JSON.parseObject(contentBlock.getContentData());
  662 + text = JSON.parseObject(data.getString("data")).getString("text");
  663 + }
637 } 664 }
638 } 665 }
639 String noteContent = (StringUtils.isBlank(text)||text.length()<15?text: text.substring(0,15))+"..."; 666 String noteContent = (StringUtils.isBlank(text)||text.length()<15?text: text.substring(0,15))+"...";
@@ -651,15 +678,19 @@ public class GrassArticleServiceImpl implements IGrassArticleService { @@ -651,15 +678,19 @@ public class GrassArticleServiceImpl implements IGrassArticleService {
651 addReq.setParams(params); 678 addReq.setParams(params);
652 addReqList.add(addReq); 679 addReqList.add(addReq);
653 if (CollectionUtils.isEmpty(addReqList)) { 680 if (CollectionUtils.isEmpty(addReqList)) {
654 - return; 681 + return new JSONObject();
655 } 682 }
656 try { 683 try {
657 logger.info("before gateway.addBatchGrassInBox.addReqList size is {}", addReqList.size()); 684 logger.info("before gateway.addBatchGrassInBox.addReqList size is {}", addReqList.size());
658 String url = apiUrl + "/guang/api/addBatchInBox/?client_type=h5"; 685 String url = apiUrl + "/guang/api/addBatchInBox/?client_type=h5";
659 - serviceCaller.post("gateway.addBatchGrassInBox", url, addReqList, String.class, null); 686 + JSONObject result = serviceCaller.post("gateway.addBatchGrassInBox", url, addReqList,
  687 + JSONObject.class, null).get();
  688 + return result;
660 } catch (Exception e) { 689 } catch (Exception e) {
661 logger.info("failed addBatchInBox, error is {}", e); 690 logger.info("failed addBatchInBox, error is {}", e);
662 } 691 }
  692 + return new JSONObject();
  693 +
663 } 694 }
664 695
665 //来自晒单的文章 被推荐 696 //来自晒单的文章 被推荐
1 package com.yohobuy.platform.grass.util; 1 package com.yohobuy.platform.grass.util;
2 2
3 -public enum TblCrawlerEnum {  
4 - WECHAT(1, "微信公众号"),  
5 - MICROBLOG(2, "微博"); 3 +public enum MsgInformSceneEnum {
  4 + ARTICLE_RECOMMEND_INFORM(1, "文章推荐通知");
6 5
7 private Integer type; 6 private Integer type;
8 private String name; 7 private String name;
9 8
10 - private TblCrawlerEnum(Integer type, String name) { 9 + private MsgInformSceneEnum(Integer type, String name) {
11 this.type = type; 10 this.type = type;
12 this.name = name; 11 this.name = name;
13 } 12 }
14 13
15 public static String getNameByType(int type) { 14 public static String getNameByType(int type) {
16 - for (TblCrawlerEnum e : values()) { 15 + for (MsgInformSceneEnum e : values()) {
17 if (type == e.getType()) { 16 if (type == e.getType()) {
18 return e.getName(); 17 return e.getName();
19 } 18 }
@@ -357,6 +357,7 @@ datasources: @@ -357,6 +357,7 @@ datasources:
357 - com.yohobuy.platform.dal.grass.IGrassTopicGroupDAO 357 - com.yohobuy.platform.dal.grass.IGrassTopicGroupDAO
358 - com.yohobuy.platform.dal.grass.IGrassArticleTopicDao 358 - com.yohobuy.platform.dal.grass.IGrassArticleTopicDao
359 - com.yohobuy.platform.dal.grass.IGrassVirtualGroupDao 359 - com.yohobuy.platform.dal.grass.IGrassVirtualGroupDao
  360 + - com.yohobuy.platform.dal.grass.IGrassInformRecordDao
360 361
361 yhb_promotion: 362 yhb_promotion:
362 servers: 363 servers:
@@ -355,6 +355,7 @@ datasources: @@ -355,6 +355,7 @@ datasources:
355 - com.yohobuy.platform.dal.grass.IGrassTopicGroupDAO 355 - com.yohobuy.platform.dal.grass.IGrassTopicGroupDAO
356 - com.yohobuy.platform.dal.grass.IGrassArticleTopicDao 356 - com.yohobuy.platform.dal.grass.IGrassArticleTopicDao
357 - com.yohobuy.platform.dal.grass.IGrassVirtualGroupDao 357 - com.yohobuy.platform.dal.grass.IGrassVirtualGroupDao
  358 + - com.yohobuy.platform.dal.grass.IGrassInformRecordDao
358 359
359 yhb_promotion: 360 yhb_promotion:
360 servers: 361 servers: