|
|
package com.yohobuy.platform.grass.service.impl;
|
|
|
|
|
|
|
|
|
import com.yoho.core.config.ConfigReader;
|
|
|
import com.yoho.core.rest.client.ServiceCaller;
|
|
|
import com.yoho.service.model.sns.model.enums.GrassInboxBusinessTypeEnum;
|
|
|
import com.yoho.service.model.sns.request.GrassInBoxAddReq;
|
|
|
import com.yohobuy.platform.common.enums.GrassUserTypeEnum;
|
|
|
import com.yohobuy.platform.common.enums.GrassVirtualUserGroupEnum;
|
|
|
import com.yohobuy.platform.dal.grass.*;
|
|
|
import com.yohobuy.platform.dal.grass.model.GrassArticle;
|
|
|
import com.yohobuy.platform.dal.grass.model.GrassArticlePraise;
|
|
|
import com.yohobuy.platform.dal.grass.model.GrassUserAchieve;
|
|
|
import com.yohobuy.platform.dal.grass.model.GrassUserAttention;
|
|
|
import com.yohobuy.platform.dal.grass.model.*;
|
|
|
import com.yohobuy.platform.grass.service.IGrassVirtualService;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang.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.*;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
import static com.yoho.tools.common.utils.RandomUtil.getRandom;
|
|
|
|
...
|
...
|
@@ -46,13 +46,17 @@ public class GrassUserVirtualImpl implements IGrassVirtualService{ |
|
|
|
|
|
public static final long INTERVAL = 60 * 60 * 1000l;//1小时
|
|
|
|
|
|
// public static final long INTERVAL = 1 * 60 * 60 * 1000l;//1小时
|
|
|
@Value("${api.yoho.url:http://api.yoho.cn}")
|
|
|
private String apiUrl;
|
|
|
|
|
|
@Autowired
|
|
|
private ServiceCaller serviceCaller;
|
|
|
|
|
|
/**
|
|
|
* 种草文章--增加点赞数
|
|
|
* 1)审核通过、被推荐,推荐时间 在72小时以内的文章
|
|
|
* 1)审核通过、被推荐,推荐时间 在72小时以内的文章(时间可配)
|
|
|
* 2)随机点赞
|
|
|
* 3)第一次点赞的,发送站内信,取消点赞,此次再点赞的,不发站内信(二期修改)
|
|
|
*/
|
|
|
@Override
|
|
|
public void addVirtualPraise() {
|
...
|
...
|
@@ -68,40 +72,102 @@ public class GrassUserVirtualImpl implements IGrassVirtualService{ |
|
|
return ;
|
|
|
}
|
|
|
|
|
|
Map<Integer,GrassArticle > articleInfoMap = articleList.stream().collect(Collectors.toMap(GrassArticle::getId, obj -> obj));
|
|
|
List<Integer> articleIds = articleList.stream().map(GrassArticle::getId).distinct().collect(Collectors.toList());
|
|
|
logger.info("addVirtualPraise, update articleList size={}, articleIds={} ", articleList.size(), articleIds);
|
|
|
//点赞阈值
|
|
|
String threshold = configReader.getString("platform.grass.virtualpraise.threshold","");
|
|
|
String s[] = StringUtils.split(threshold,",");
|
|
|
int min = Integer.valueOf(s[0]);
|
|
|
int max = Integer.valueOf(s[1]);
|
|
|
//虚拟马甲用户
|
|
|
List<Integer> allVirtualUids = grassVirtualUserDao.selectVirtualsByGroup(GrassVirtualUserGroupEnum.COMMON.getValue());
|
|
|
//可用马甲(普通马甲 社区大号 外部刷评论马甲)
|
|
|
List<Integer> groupList = Arrays.asList(new Integer[]{1,4,6});
|
|
|
List<Integer> allVirtualUids = grassVirtualUserDao.selectVirtualsByGroupList(groupList);
|
|
|
if(CollectionUtils.isEmpty(allVirtualUids)){
|
|
|
logger.warn("addVirtualPraise no virtual user ");
|
|
|
return;
|
|
|
}
|
|
|
//这些文章已有的点赞明细
|
|
|
//1)这些文章已有的点赞明细(剔除掉已经点赞的马甲,曾经点赞取消的马甲 也需要特殊处理)
|
|
|
List<GrassArticlePraise> praiseList = grassArticlePraiseDao.selectByArticles(articleIds);
|
|
|
Map<Integer,List<Integer>> articlePraiseMap = new HashMap<>();
|
|
|
Map<Integer,List<Integer>> canceledPraiseMap = new HashMap<>();
|
|
|
for(GrassArticlePraise praise : praiseList){
|
|
|
Integer articleId = praise.getArticleId();
|
|
|
if(articlePraiseMap.get(articleId) == null){
|
|
|
articlePraiseMap.put(articleId, new ArrayList<>());
|
|
|
Integer status = praise.getStatus();
|
|
|
Integer uid = praise.getUid();
|
|
|
if(status == 0 ){//正常的点赞
|
|
|
if(articlePraiseMap.get(articleId) == null){
|
|
|
articlePraiseMap.put(articleId, new ArrayList<>());
|
|
|
}
|
|
|
articlePraiseMap.get(articleId).add(uid);
|
|
|
}
|
|
|
if(status == 1){//点赞被取消了
|
|
|
if(canceledPraiseMap.get(articleId) == null){
|
|
|
canceledPraiseMap.put(articleId,new ArrayList<>());
|
|
|
}
|
|
|
canceledPraiseMap.get(articleId).add(uid);
|
|
|
}
|
|
|
articlePraiseMap.get(articleId).add(praise.getUid());
|
|
|
}
|
|
|
|
|
|
Map<Integer,GrassUserAchieve> commonMap = new HashMap<>();
|
|
|
Map<Integer,GrassUserAchieve> guangMap = new HashMap<>();
|
|
|
List<GrassArticlePraise> newPraiseList = new ArrayList<>();
|
|
|
//2)点赞逻辑,要区分逛的作者 和 普通作者
|
|
|
Map<Integer,GrassUserAchieve> commonUserAchieveMap = new HashMap<>();
|
|
|
Map<Integer,GrassUserAchieve> guangUserAchieveMap = new HashMap<>();
|
|
|
//新增的点赞明细
|
|
|
List<GrassArticlePraise> newPariseDetail = new ArrayList<>();
|
|
|
//被取消的点赞,只需要update状态就可以了,并且不需要发站内信
|
|
|
List<GrassArticlePraise> updateDetailList = new ArrayList<>();
|
|
|
|
|
|
//普通用户发布的文章
|
|
|
List<GrassArticle> commonArtcileList = articleList.stream().filter(obj -> obj.getAuthorType() == null || obj.getAuthorType() == GrassUserTypeEnum.COMMON.getValue() )
|
|
|
.collect(Collectors.toList());
|
|
|
//逛作者发布的文章
|
|
|
List<GrassArticle> guangArtcileList = articleList.stream().filter(obj -> obj.getAuthorType() != null && obj.getAuthorType() == GrassUserTypeEnum.GUANG.getValue() )
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
//1)普通文章点赞处理
|
|
|
doVirtualPraise(commonArtcileList,articlePraiseMap,canceledPraiseMap,allVirtualUids,s,currentTime,commonUserAchieveMap,1,newPariseDetail,updateDetailList);
|
|
|
//2)逛文章点赞处理
|
|
|
doVirtualPraise(guangArtcileList,articlePraiseMap,canceledPraiseMap,allVirtualUids,s,currentTime,guangUserAchieveMap,2,newPariseDetail,updateDetailList);
|
|
|
|
|
|
if(CollectionUtils.isEmpty(newPariseDetail) && CollectionUtils.isEmpty(updateDetailList)){
|
|
|
logger.info("addOrUpdateVirtualPraise list is empty");
|
|
|
return;
|
|
|
}
|
|
|
List<GrassUserAchieve> userAchieveList = new ArrayList<>();
|
|
|
userAchieveList.addAll(commonUserAchieveMap.values());
|
|
|
userAchieveList.addAll(guangUserAchieveMap.values());
|
|
|
logger.info("start to addVirtualPraise,praiseDetailList={}",newPariseDetail);
|
|
|
logger.info("start to updateVirtualPraise,updateDetailList={}",updateDetailList);
|
|
|
logger.info("start to addVirtualPraise,articleList={}",articleList);
|
|
|
logger.info("start to addOrUpdateUserAchieve,userAchieveList={}",userAchieveList);
|
|
|
|
|
|
//点赞
|
|
|
//1)新增点赞明细表
|
|
|
if(CollectionUtils.isNotEmpty(newPariseDetail)){
|
|
|
grassArticlePraiseDao.batchInsert(newPariseDetail);
|
|
|
}
|
|
|
|
|
|
//2)更新点赞文章表(更改状态)
|
|
|
if(CollectionUtils.isNotEmpty(updateDetailList)){
|
|
|
grassArticlePraiseDao.batchUpdatePraiseStatus(updateDetailList);
|
|
|
}
|
|
|
//3)更新文章表(批量更新文章表)
|
|
|
grassArticleDao.batchUpdatePraiseCount(articleList);
|
|
|
logger.info("addVirtualPraise update grassArticle success!");
|
|
|
//4)批量更新作者表(新增或者update)
|
|
|
userAchieveDAO.batchUpdatePraise(userAchieveList);
|
|
|
//5)发送站内信(通知作者 文章获赞)---后期增加
|
|
|
sendAddPariseMessage(newPariseDetail,articleInfoMap);
|
|
|
logger.info("addVirtualPraise success!");
|
|
|
}
|
|
|
|
|
|
//点赞逻辑
|
|
|
private void doVirtualPraise(List<GrassArticle> articleList, Map<Integer,List<Integer>> articlePraiseMap, Map<Integer,List<Integer>> canceledPraiseMap,
|
|
|
List<Integer> allVirtualUids, String[] s,long currentTime,
|
|
|
Map<Integer,GrassUserAchieve> userMap,Integer authorType,
|
|
|
List<GrassArticlePraise> newPariseDetail, List<GrassArticlePraise> updateDetailList) {
|
|
|
int min = Integer.valueOf(s[0]);
|
|
|
int max = Integer.valueOf(s[1]);
|
|
|
for(GrassArticle article : articleList){
|
|
|
Integer articleId = article.getId();
|
|
|
int authorUid = article.getAuthorUid();
|
|
|
int authorType = article.getAuthorType() == null ? 1 : article.getAuthorType() ;
|
|
|
|
|
|
//选择虚拟马甲
|
|
|
List<Integer> oldPraiseList = articlePraiseMap.get(articleId);
|
|
|
List<Integer> tempList = new ArrayList<>();
|
...
|
...
|
@@ -124,10 +190,16 @@ public class GrassUserVirtualImpl implements IGrassVirtualService{ |
|
|
praiseDetail.setCreateTime((int) (currentTime/1000l));
|
|
|
praiseDetail.setUpdateTime((int) (currentTime/1000l));
|
|
|
praiseDetail.setStatus(0);//0 --点赞 1 ---取消
|
|
|
newPraiseList.add(praiseDetail);
|
|
|
//已经存在点赞,但是被取消的情况
|
|
|
List<Integer> canceledList = canceledPraiseMap.get(articleId);
|
|
|
if(CollectionUtils.isNotEmpty(canceledList) && canceledList.contains(virtualUid)){//当前马甲以前点赞过
|
|
|
updateDetailList.add(praiseDetail);
|
|
|
}else{
|
|
|
//新增的点赞明细
|
|
|
newPariseDetail.add(praiseDetail);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
//2)更新文章获赞总数
|
|
|
article.setPraiseCount(random);//增加点赞数
|
|
|
article.setUpdateTime(currentTime);
|
...
|
...
|
@@ -135,52 +207,106 @@ public class GrassUserVirtualImpl implements IGrassVirtualService{ |
|
|
//3)更新作者 获赞总数
|
|
|
//同一个作者 必须要累加计数 否则更新结果不正确
|
|
|
GrassUserAchieve userAchieve = new GrassUserAchieve();
|
|
|
if(authorType == GrassUserTypeEnum.COMMON.getValue() && commonMap.get(authorUid)!=null){
|
|
|
//求和
|
|
|
userAchieve = commonMap.get(authorUid);
|
|
|
userAchieve.setPraiseAmount(userAchieve.getPraiseAmount() + random);
|
|
|
continue;
|
|
|
}
|
|
|
if(authorType == GrassUserTypeEnum.GUANG.getValue() && guangMap.get(authorUid)!=null){
|
|
|
if(userMap.get(authorUid)!=null){
|
|
|
//求和
|
|
|
userAchieve = guangMap.get(authorUid);
|
|
|
userAchieve = userMap.get(authorUid);
|
|
|
userAchieve.setPraiseAmount(userAchieve.getPraiseAmount() + random);
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
userAchieve.setUid(authorUid);
|
|
|
userAchieve.setUserType(authorType);
|
|
|
userAchieve.setUpdateTime((int) (currentTime / 1000l));
|
|
|
//新增加的点赞数
|
|
|
userAchieve.setPraiseAmount(random);
|
|
|
if(authorType == GrassUserTypeEnum.COMMON.getValue()){
|
|
|
commonMap.put(authorUid, userAchieve);
|
|
|
userMap.put(authorUid, userAchieve);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void sendAddPariseMessage(List<GrassArticlePraise> pariseDetail,Map<Integer,GrassArticle> articleInfoMap) {
|
|
|
if(CollectionUtils.isEmpty(pariseDetail)){
|
|
|
return;
|
|
|
}
|
|
|
//批量插入的时候没有获取到id(依赖版本较低,获取不到),重查一遍
|
|
|
List<GrassArticlePraise> newPariseDetail = grassArticlePraiseDao.selectByArticleAndUids(pariseDetail);
|
|
|
List<GrassInBoxAddReq> reqList = new ArrayList<>();
|
|
|
//发送站内信(第一次点赞的时候发送)
|
|
|
for(GrassArticlePraise newPraise : newPariseDetail){
|
|
|
Integer id = newPraise.getId();
|
|
|
Integer artcileId = newPraise.getArticleId();
|
|
|
Integer uid = newPraise.getUid();
|
|
|
GrassArticle grassArticle = articleInfoMap.get(artcileId);
|
|
|
//如果不是有货的作者,也不发送站内信
|
|
|
if(id == null || artcileId == null || uid == null || grassArticle == null){
|
|
|
continue;
|
|
|
}
|
|
|
if(authorType == GrassUserTypeEnum.GUANG.getValue()){
|
|
|
guangMap.put(authorUid, userAchieve);
|
|
|
Integer authorUid = grassArticle.getAuthorUid();
|
|
|
Integer authorType = grassArticle.getAuthorType();
|
|
|
if(authorType == GrassUserTypeEnum.GUANG.getValue()){//非有货用户,不发送站内信
|
|
|
continue;
|
|
|
}
|
|
|
//发送站内信
|
|
|
GrassInBoxAddReq req = new GrassInBoxAddReq();
|
|
|
req.setUid(authorUid);
|
|
|
req.setAttachValue(String.valueOf(id));
|
|
|
req.setBusinessType(GrassInboxBusinessTypeEnum.SYSTEM_PRAISE_ARTICLE.getBusinessType());
|
|
|
req.setOptUid(uid);
|
|
|
req.setParams("");
|
|
|
reqList.add(req);
|
|
|
}
|
|
|
|
|
|
List<GrassUserAchieve> userPraiseList = new ArrayList<>();
|
|
|
userPraiseList.addAll(commonMap.values());
|
|
|
userPraiseList.addAll(guangMap.values());
|
|
|
logger.info("start to addVirtualPraise,newPraiseList={}",newPraiseList);
|
|
|
logger.info("start to addVirtualPraise,articleList={}",articleList);
|
|
|
logger.info("start to addVirtualPraise,userPraiseList={}",userPraiseList);
|
|
|
//更新点赞明细表
|
|
|
grassArticlePraiseDao.batchInsertOrUpdate(newPraiseList);
|
|
|
//更新文章表(批量更新文章表)
|
|
|
grassArticleDao.batchUpdatePraiseCount(articleList);
|
|
|
logger.info("addVirtualPraise update grassArticle success!");
|
|
|
//批量更新作者表(新增或者update)
|
|
|
userAchieveDAO.batchUpdatePraise(userPraiseList);
|
|
|
logger.info("addVirtualPraise success!");
|
|
|
sendMessage(reqList);
|
|
|
}
|
|
|
|
|
|
private void sendMessage(List<GrassInBoxAddReq> reqList) {
|
|
|
//(调sns接口,批量发送站内信)
|
|
|
try{
|
|
|
String url = apiUrl + "?method=app.grass.addBatchInBoxNew";
|
|
|
logger.info("before addBatchInBoxNew, url is: {}, req is {}", url, reqList);
|
|
|
serviceCaller.post("app.clearGrassCache", url, reqList, String.class, null);
|
|
|
}catch (Exception e){
|
|
|
logger.info("failed refreshGrassCache, req is {}, error is {}", reqList , e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
private void sendAddFansMessage(List<GrassUserAttention> attentions) {
|
|
|
if(CollectionUtils.isEmpty(attentions)){
|
|
|
logger.info("sendAddFansMessage list is empty");
|
|
|
return;
|
|
|
}
|
|
|
List<GrassUserAttention> newAttentions = grassUserAttentionDao.selectByAuthorAndUids(attentions);
|
|
|
List<GrassInBoxAddReq> reqList = new ArrayList<>();
|
|
|
//发送站内信(第一次成为粉丝的时候才发送)
|
|
|
for(GrassUserAttention attention : newAttentions){
|
|
|
Integer id = attention.getId();
|
|
|
Integer authorUid = attention.getFollowUid();//作者uid
|
|
|
Integer fanUid = attention.getUid();
|
|
|
if(id == null || authorUid == null || fanUid == null ){
|
|
|
continue;
|
|
|
}
|
|
|
if(attention.getAuthorType() == GrassUserTypeEnum.GUANG.getValue()){//逛作者不需要发站内信
|
|
|
continue;
|
|
|
}
|
|
|
//发送站内信
|
|
|
GrassInBoxAddReq req = new GrassInBoxAddReq();
|
|
|
req.setUid(authorUid);
|
|
|
req.setAttachValue(String.valueOf(id));
|
|
|
req.setBusinessType(GrassInboxBusinessTypeEnum.SYSTEM_ATTENTION_USER.getBusinessType());
|
|
|
req.setOptUid(fanUid);
|
|
|
req.setParams("");
|
|
|
reqList.add(req);
|
|
|
}
|
|
|
sendMessage(reqList);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 种草作者--增加粉丝
|
|
|
* 1)审核通过、被推荐,推荐时间 在72小时以内的文章 的作者
|
|
|
* 1)审核通过、被推荐,推荐时间 在72小时以内的文章 的作者(时间可配)
|
|
|
* 2)随机增粉
|
|
|
* 3)首次成为作者粉丝,发送站内信(不push消息),取消,此次再次关注的,不发站内信
|
|
|
*/
|
|
|
|
|
|
@Override
|
...
|
...
|
@@ -206,8 +332,9 @@ public class GrassUserVirtualImpl implements IGrassVirtualService{ |
|
|
int min = Integer.valueOf(s[0]);
|
|
|
int max = Integer.valueOf(s[1]);
|
|
|
|
|
|
//所有的马甲用户 status =1属于普通组的马甲
|
|
|
List<Integer> allVirtualUids = grassVirtualUserDao.selectVirtualsByGroup(GrassVirtualUserGroupEnum.COMMON.getValue());
|
|
|
//马甲用户(普通马甲 社区大号 外部刷评论马甲),并且状态开启
|
|
|
List<Integer> groupList = Arrays.asList(new Integer[]{1,4,6});
|
|
|
List<Integer> allVirtualUids = grassVirtualUserDao.selectVirtualsByGroupList(groupList);
|
|
|
if(CollectionUtils.isEmpty(allVirtualUids)){
|
|
|
logger.warn("addVirtualFans no virtual user ");
|
|
|
return;
|
...
|
...
|
@@ -218,11 +345,9 @@ public class GrassUserVirtualImpl implements IGrassVirtualService{ |
|
|
Set<Integer> commonUid = articleList.stream().
|
|
|
filter(obj -> obj.getAuthorType() == GrassUserTypeEnum.COMMON.getValue()).map(GrassArticle::getAuthorUid)
|
|
|
.collect(Collectors.toSet());
|
|
|
|
|
|
Set<Integer> guangUid = articleList.stream().
|
|
|
filter(obj -> obj.getAuthorType() == GrassUserTypeEnum.GUANG.getValue()).map(GrassArticle::getAuthorUid)
|
|
|
.collect(Collectors.toSet());
|
|
|
|
|
|
List<Integer> allUids = new ArrayList<>();
|
|
|
allUids.addAll(commonUid);
|
|
|
allUids.addAll(guangUid);
|
...
|
...
|
@@ -230,7 +355,9 @@ public class GrassUserVirtualImpl implements IGrassVirtualService{ |
|
|
//这些作者已有的粉丝信息
|
|
|
List<GrassUserAttention> fansList = grassUserAttentionDao.selectFansByUids(allUids);
|
|
|
Map<Integer,List<Integer>> commonUserFansMap = new HashMap<>();
|
|
|
Map<Integer,List<Integer>> commonUserCanceledFansMap = new HashMap<>();
|
|
|
Map<Integer,List<Integer>> guangUserFansMap = new HashMap<>();
|
|
|
Map<Integer,List<Integer>> guangUserCanceledFansMap = new HashMap<>();
|
|
|
|
|
|
//(普通作者的粉丝 && 逛小编的粉丝)--已有的粉丝
|
|
|
//粉丝本身一定是有货用户,不需要区分类型
|
...
|
...
|
@@ -238,24 +365,40 @@ public class GrassUserVirtualImpl implements IGrassVirtualService{ |
|
|
int authorUid = temp.getFollowUid();//作者
|
|
|
int fanUid = temp.getUid();//粉丝
|
|
|
int authorType = temp.getAuthorType() == null ? 1 : temp.getAuthorType();
|
|
|
if(authorType == GrassUserTypeEnum.COMMON.getValue()){
|
|
|
//1)普通作者, 已被关注--剔除这些uid
|
|
|
if(authorType == GrassUserTypeEnum.COMMON.getValue() && temp.getStatus() == 0){
|
|
|
if(commonUserFansMap.get(authorUid) == null){
|
|
|
commonUserFansMap.put(authorUid, new ArrayList<>());
|
|
|
}
|
|
|
commonUserFansMap.get(authorUid).add(fanUid);
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
if(authorType == GrassUserTypeEnum.GUANG.getValue()){
|
|
|
//2)普通作者, 取消关注--后续特殊处理
|
|
|
if(authorType == GrassUserTypeEnum.COMMON.getValue() && temp.getStatus() == 1){
|
|
|
if(commonUserCanceledFansMap.get(authorUid) == null){
|
|
|
commonUserCanceledFansMap.put(authorUid, new ArrayList<>());
|
|
|
}
|
|
|
commonUserCanceledFansMap.get(authorUid).add(fanUid);
|
|
|
continue;
|
|
|
}
|
|
|
//3)逛作者, 已被关注--剔除这些uid
|
|
|
if(authorType == GrassUserTypeEnum.GUANG.getValue() && temp.getStatus() == 0){
|
|
|
if(guangUserFansMap.get(authorUid) == null){
|
|
|
guangUserFansMap.put(authorUid, new ArrayList<>());
|
|
|
}
|
|
|
guangUserFansMap.get(authorUid).add(fanUid);
|
|
|
}
|
|
|
|
|
|
//3)逛作者, 取消关注--后续特殊处理
|
|
|
if(authorType == GrassUserTypeEnum.GUANG.getValue() && temp.getStatus() == 1){
|
|
|
if(guangUserCanceledFansMap.get(authorUid) == null){
|
|
|
guangUserCanceledFansMap.put(authorUid, new ArrayList<>());
|
|
|
}
|
|
|
guangUserCanceledFansMap.get(authorUid).add(fanUid);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
List<GrassUserAttention> userAttentions = new ArrayList<>();
|
|
|
List<GrassUserAttention> newUserAttentions = new ArrayList<>();
|
|
|
List<GrassUserAttention> updateUserAttentions = new ArrayList<>();
|
|
|
List<GrassUserAchieve> userAchieveFansList = new ArrayList<>();
|
|
|
//普通作者--增粉数据
|
|
|
for(Integer authorUid : commonUid){
|
...
|
...
|
@@ -267,8 +410,11 @@ public class GrassUserVirtualImpl implements IGrassVirtualService{ |
|
|
tempList.removeAll(oldFansList);
|
|
|
}
|
|
|
Set<Integer> randomUidList = getRandomFans(tempList, min, max);
|
|
|
List<Integer> canceledList = commonUserCanceledFansMap.get(authorUid);
|
|
|
//随机增粉
|
|
|
addFans(randomUidList,authorUid,GrassUserTypeEnum.COMMON.getValue(),userAttentions, userAchieveFansList,currentTime);
|
|
|
addFans(randomUidList,authorUid,GrassUserTypeEnum.COMMON.getValue(),
|
|
|
newUserAttentions, updateUserAttentions,
|
|
|
userAchieveFansList,currentTime,canceledList);
|
|
|
}
|
|
|
|
|
|
//逛作者--增粉数据
|
...
|
...
|
@@ -281,18 +427,23 @@ public class GrassUserVirtualImpl implements IGrassVirtualService{ |
|
|
tempList.removeAll(oldFansList);
|
|
|
}
|
|
|
Set<Integer> randomUidList = getRandomFans(tempList, min, max);
|
|
|
List<Integer> canceledList = guangUserCanceledFansMap.get(authorUid);
|
|
|
//随机增粉
|
|
|
addFans(randomUidList,authorUid,GrassUserTypeEnum.GUANG.getValue(),userAttentions, userAchieveFansList,currentTime);
|
|
|
addFans(randomUidList,authorUid,GrassUserTypeEnum.GUANG.getValue(),
|
|
|
newUserAttentions,updateUserAttentions, userAchieveFansList,currentTime,canceledList);
|
|
|
}
|
|
|
|
|
|
//更新数据库
|
|
|
//批量新增粉丝明细表
|
|
|
if(CollectionUtils.isEmpty(userAttentions)){
|
|
|
if(CollectionUtils.isEmpty(newUserAttentions) && CollectionUtils.isEmpty(updateUserAttentions)){
|
|
|
logger.info("addVirtualFans success, no update! userAttentions is empty ");
|
|
|
return ;
|
|
|
}
|
|
|
|
|
|
//马甲的关注数
|
|
|
List<GrassUserAttention> userAttentions = new ArrayList<>();
|
|
|
userAttentions.addAll(newUserAttentions);
|
|
|
userAttentions.addAll(updateUserAttentions);
|
|
|
Map<Integer, Long> attMap = userAttentions.stream()
|
|
|
.collect(Collectors.groupingBy(GrassUserAttention::getUid,Collectors.counting()));
|
|
|
|
...
|
...
|
@@ -308,24 +459,38 @@ public class GrassUserVirtualImpl implements IGrassVirtualService{ |
|
|
userAchieveAttList.add(user);
|
|
|
}
|
|
|
|
|
|
|
|
|
logger.info("addVirtualFans update grassUserAttention,userAttentions={}", userAttentions);
|
|
|
logger.info("addVirtualFans insert grassUserAttention,newUserAttentions={}", newUserAttentions);
|
|
|
logger.info("addVirtualFans update grassUserAttention,updateUserAttentions={}", updateUserAttentions);
|
|
|
logger.info("addVirtualFans update userAchieve userAchieveFansList={}",userAchieveFansList);
|
|
|
logger.info("addVirtualFans update userAchieve userAchieveAttList={}",userAchieveAttList);
|
|
|
//1)更新关注明细表
|
|
|
grassUserAttentionDao.batchInsert(userAttentions);
|
|
|
logger.info("addVirtualFans update grassUserAttention success!");
|
|
|
//2)批量更新作者表,增加作者对应的粉丝数
|
|
|
//1)新增关注明细表
|
|
|
if(CollectionUtils.isNotEmpty(newUserAttentions)){
|
|
|
grassUserAttentionDao.batchInsert(newUserAttentions);
|
|
|
logger.info("addVirtualFans batchInsert grassUserAttention success!");
|
|
|
}
|
|
|
|
|
|
//2)批量更新关注明细(之前取消了,现在再关注)
|
|
|
if(CollectionUtils.isNotEmpty(updateUserAttentions)){
|
|
|
grassUserAttentionDao.batchUpdate(updateUserAttentions);
|
|
|
logger.info("addVirtualFans batchUpdate grassUserAttention success!");
|
|
|
}
|
|
|
|
|
|
//3)批量更新作者表,增加作者对应的粉丝数
|
|
|
userAchieveDAO.batchUpdateFans(userAchieveFansList);
|
|
|
logger.info("addVirtualFans batchUpdateFans success!");
|
|
|
//3)批量更新作者表,增加粉丝对应的关注数
|
|
|
//4)批量更新作者表,增加粉丝对应的关注数
|
|
|
userAchieveDAO.batchInsertOrUpAttentions(userAchieveAttList);
|
|
|
//5)发送站内信
|
|
|
sendAddFansMessage(newUserAttentions);
|
|
|
logger.info("addVirtualFans success!");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//增粉数据
|
|
|
private void addFans(Set<Integer> randomUidList, Integer authorUid, int authorType, List<GrassUserAttention> userAttentions, List<GrassUserAchieve> userAchieveList,Long currentTime) {
|
|
|
private void addFans(Set<Integer> randomUidList, Integer authorUid, int authorType,
|
|
|
List<GrassUserAttention> newUserAttentions,List<GrassUserAttention> updateUserAttentions,
|
|
|
List<GrassUserAchieve> userAchieveList,Long currentTime,List<Integer> canceledList) {
|
|
|
if(CollectionUtils.isEmpty(randomUidList)){
|
|
|
logger.info("addVirtualFans randomUidList is empty, authorUid={}, ",authorUid);
|
|
|
return ;
|
...
|
...
|
@@ -333,7 +498,6 @@ public class GrassUserVirtualImpl implements IGrassVirtualService{ |
|
|
|
|
|
//粉丝明细表
|
|
|
for(Integer randomUid : randomUidList){
|
|
|
//粉丝明细表
|
|
|
GrassUserAttention attention = new GrassUserAttention();
|
|
|
attention.setFollowUid(authorUid);
|
|
|
attention.setAuthorType(authorType);
|
...
|
...
|
@@ -342,9 +506,13 @@ public class GrassUserVirtualImpl implements IGrassVirtualService{ |
|
|
attention.setUpdateTime((int) (currentTime / 1000l));
|
|
|
attention.setAttentionType(1);//1-关注用户
|
|
|
attention.setStatus(0);//0 --正常 1删除
|
|
|
userAttentions.add(attention);
|
|
|
//粉丝明细表
|
|
|
if(CollectionUtils.isNotEmpty(canceledList) && canceledList.contains(randomUid)){
|
|
|
updateUserAttentions.add(attention);
|
|
|
}else{
|
|
|
newUserAttentions.add(attention);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//作者的粉丝需要增加
|
|
|
//粉丝总数表(一条数据)
|
|
|
GrassUserAchieve userAchieve = new GrassUserAchieve();
|
...
|
...
|
|