...
|
...
|
@@ -6,6 +6,7 @@ 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.util.StringUtil;
|
|
|
import com.yohobuy.platform.dal.grass.*;
|
|
|
import com.yohobuy.platform.dal.grass.model.*;
|
|
|
import com.yohobuy.platform.grass.service.IGrassVirtualService;
|
...
|
...
|
@@ -52,32 +53,23 @@ public class GrassUserVirtualImpl implements IGrassVirtualService{ |
|
|
@Autowired
|
|
|
private ServiceCaller serviceCaller;
|
|
|
|
|
|
private static final int publishPraise = 1;
|
|
|
|
|
|
private static final int recPraise = 2;
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 种草文章--增加点赞数
|
|
|
* 1)审核通过、被推荐,推荐时间 在72小时以内的文章(时间可配)
|
|
|
* 2)随机点赞
|
|
|
* 3)第一次点赞的,发送站内信,取消点赞,此次再点赞的,不发站内信(二期修改)
|
|
|
* 点赞规则
|
|
|
* 1)文章审核通过系统自动加赞
|
|
|
普通用户:内容发布后,审核时间不超过xxx小时,系统加 X(上限)~Y(下限)个赞(随着时间的推移,每次增加的点赞数线性减少)
|
|
|
重点用户:与普通用户加赞策略相同,仅点赞的上下限不同
|
|
|
2)文章被推荐 系统自动加赞
|
|
|
普通用户:内容被推荐后,推荐时间不超过xxx小时,系统加 X(上限)~Y(下限)个赞(随着时间的推移,每次增加的点赞数线性减少)
|
|
|
重点用户:与普通用户加赞策略相同,仅点赞的上下限不同
|
|
|
*/
|
|
|
@Override
|
|
|
public void addVirtualPraise() {
|
|
|
public void addVirtualPraiseNew() {
|
|
|
logger.info("enter addVirtualPraise ");
|
|
|
long currentTime = System.currentTimeMillis();
|
|
|
//时间间隔
|
|
|
int timeConfig = configReader.getInt("platform.grass.virtual.time.interval", 1);
|
|
|
logger.info("addVirtualPraise virtual.time.interval is {}", timeConfig);
|
|
|
long startTime = currentTime - timeConfig * INTERVAL;
|
|
|
List<GrassArticle> articleList = grassArticleDao.selectByRecommendTime(startTime,currentTime);
|
|
|
if(CollectionUtils.isEmpty(articleList)){
|
|
|
logger.info("addVirtualPraise articleList is empty");
|
|
|
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,",");
|
|
|
//可用马甲(普通马甲 社区大号 外部刷评论马甲)
|
|
|
List<Integer> groupList = Arrays.asList(new Integer[]{1,4,6});
|
|
|
List<Integer> allVirtualUids = grassVirtualUserDao.selectVirtualsByGroupList(groupList);
|
...
|
...
|
@@ -85,65 +77,136 @@ public class GrassUserVirtualImpl implements IGrassVirtualService{ |
|
|
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();
|
|
|
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);
|
|
|
}
|
|
|
//重点用户 vs 普通用户(点赞策略是不同的)---KOL/官方号/大号/编辑)
|
|
|
List<Integer> specialGroupList = Arrays.asList(new Integer[]{7,3,4,2});
|
|
|
List<Integer> specialAuthors = grassVirtualUserDao.selectAllSpecialUser(specialGroupList);
|
|
|
//发布、审核通过的文章点赞策略
|
|
|
List<GrassArticlePraise> newPraiseDetailForPub = addPraiseForPublish(allVirtualUids,specialAuthors);
|
|
|
//被推荐的文章点赞策略
|
|
|
List<GrassArticlePraise> newPraiseDetailForRec = addPraiseForRec(allVirtualUids,specialAuthors);
|
|
|
newPraiseDetailForPub.addAll(newPraiseDetailForRec);
|
|
|
//新增加的点赞--发送站内信
|
|
|
sendAddPariseMessage(newPraiseDetailForPub);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 发布文章--审核通过--点赞策略
|
|
|
* @param allVirtualUids --马甲用户
|
|
|
* @param specialAuthors --重点用户
|
|
|
* 配置项:1)审核时间不超过xxx小时(不超过该时长的才被点赞);2)普通用户点赞上下限;3)重点用户点赞上下限
|
|
|
* @return
|
|
|
*/
|
|
|
private List<GrassArticlePraise> addPraiseForPublish(List<Integer> allVirtualUids, List<Integer> specialAuthors) {
|
|
|
//1)可配参数
|
|
|
int timeInterval = configReader.getInt("platform.grass.virtual.time.pubInterval", 0);
|
|
|
if(timeInterval == 0){
|
|
|
logger.warn("addVirtualPraise publishInterval is 0");
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
long currentTime = System.currentTimeMillis();
|
|
|
long startTime = currentTime - timeInterval * INTERVAL;
|
|
|
//符合条件的文章
|
|
|
List<GrassArticle> articleList = grassArticleDao.selectByAuthTime(startTime,currentTime);
|
|
|
if(CollectionUtils.isEmpty(articleList)){
|
|
|
logger.info("addPraiseForPublish articleList is empty");
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
//2)已有的点赞信息(正常的点赞,排除掉; 取消 再点赞的,不发站内信)
|
|
|
List<Integer> articleIds = articleList.stream().map(GrassArticle::getId).distinct().collect(Collectors.toList());
|
|
|
List<GrassArticlePraise> praiseList = grassArticlePraiseDao.selectByArticles(articleIds);
|
|
|
|
|
|
//2)点赞逻辑,要区分逛的作者 和 普通作者
|
|
|
Map<Integer,GrassUserAchieve> commonUserAchieveMap = new HashMap<>();
|
|
|
Map<Integer,GrassUserAchieve> guangUserAchieveMap = new HashMap<>();
|
|
|
//新增的点赞明细
|
|
|
//3)点赞逻辑,要区分逛的作者 和 普通作者
|
|
|
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());
|
|
|
List<GrassArticlePraise> newPariseDetail = new ArrayList<>();
|
|
|
//被取消的点赞,只需要update状态就可以了,并且不需要发站内信
|
|
|
List<GrassArticlePraise> updateDetailList = new ArrayList<>();
|
|
|
List<GrassUserAchieve> userAchieveList = new ArrayList<>();
|
|
|
List<GrassArticle> updateArticleList = new ArrayList<>();
|
|
|
//4)普通作者发布的文章点赞(要考虑 重点用户,策略有所不同)
|
|
|
doVirtualPraise(commonArtcileList,praiseList,allVirtualUids,currentTime,userAchieveList,GrassUserTypeEnum.COMMON.getValue(),
|
|
|
newPariseDetail,updateDetailList,specialAuthors,publishPraise,updateArticleList);
|
|
|
//4)逛作者文章点赞处理(不存在重点用户)
|
|
|
doVirtualPraise(guangArtcileList,praiseList,allVirtualUids,currentTime,userAchieveList,GrassUserTypeEnum.GUANG.getValue(),
|
|
|
newPariseDetail,updateDetailList,specialAuthors,publishPraise,updateArticleList);
|
|
|
|
|
|
if(CollectionUtils.isEmpty(newPariseDetail) && CollectionUtils.isEmpty(updateDetailList)){
|
|
|
logger.info("addOrUpdateVirtualPraise list is empty");
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
//入库操作
|
|
|
updatePraiseData(newPariseDetail, updateDetailList,updateArticleList,userAchieveList);
|
|
|
return newPariseDetail;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 推荐文章点赞策略
|
|
|
* @param allVirtualUids 马甲用户
|
|
|
* @param specialAuthors 重点用户
|
|
|
* @return
|
|
|
*/
|
|
|
private List<GrassArticlePraise> addPraiseForRec(List<Integer> allVirtualUids, List<Integer> specialAuthors) {
|
|
|
//1)可配参数
|
|
|
int timeInterval = configReader.getInt("platform.grass.virtual.time.recInterval", 0);
|
|
|
if(timeInterval == 0){
|
|
|
logger.warn("addPraiseForRec config recInterval is 0");
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
long currentTime = System.currentTimeMillis();
|
|
|
long startTime = currentTime - timeInterval * INTERVAL;
|
|
|
//需要被点赞的文章
|
|
|
List<GrassArticle> articleList = grassArticleDao.selectByRecommendTime(startTime,currentTime);
|
|
|
if(CollectionUtils.isEmpty(articleList)){
|
|
|
logger.info("addVirtualPraise articleList is empty");
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
//2)已有的点赞信息(正常的点赞,排除掉; 取消 再点赞的,不发站内信)
|
|
|
List<Integer> articleIds = articleList.stream().map(GrassArticle::getId).distinct().collect(Collectors.toList());
|
|
|
List<GrassArticlePraise> praiseList = grassArticlePraiseDao.selectByArticles(articleIds);
|
|
|
|
|
|
//普通用户发布的文章
|
|
|
//3)点赞逻辑,要区分逛的作者 和 普通作者
|
|
|
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);
|
|
|
List<GrassArticlePraise> newPariseDetail = new ArrayList<>();
|
|
|
//被取消的点赞,只需要update状态就可以了,并且不需要发站内信
|
|
|
List<GrassArticlePraise> updateDetailList = new ArrayList<>();
|
|
|
List<GrassUserAchieve> userAchieveList = new ArrayList<>();
|
|
|
List<GrassArticle> updateArticleList = new ArrayList<>();//需要增加点赞的文章
|
|
|
//4)普通作者发布的文章点赞(要考虑 重点用户,策略有所不同)
|
|
|
doVirtualPraise(commonArtcileList,praiseList,allVirtualUids,currentTime,userAchieveList,1,newPariseDetail,updateDetailList,specialAuthors,recPraise,updateArticleList);
|
|
|
//4)逛作者文章点赞处理(全当做普通用户处理,普通用户策略)
|
|
|
doVirtualPraise(guangArtcileList,praiseList,allVirtualUids,currentTime,userAchieveList,2,newPariseDetail,updateDetailList,specialAuthors,recPraise,updateArticleList);
|
|
|
|
|
|
if(CollectionUtils.isEmpty(newPariseDetail) && CollectionUtils.isEmpty(updateDetailList)){
|
|
|
logger.info("addOrUpdateVirtualPraise list is empty");
|
|
|
return;
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
List<GrassUserAchieve> userAchieveList = new ArrayList<>();
|
|
|
userAchieveList.addAll(commonUserAchieveMap.values());
|
|
|
userAchieveList.addAll(guangUserAchieveMap.values());
|
|
|
updatePraiseData(newPariseDetail, updateDetailList,updateArticleList,userAchieveList);
|
|
|
return newPariseDetail;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 点赞数据收集,入库操作
|
|
|
* @param newPariseDetail
|
|
|
* @param updateDetailList
|
|
|
* @param articleList
|
|
|
* @param userAchieveList
|
|
|
*/
|
|
|
private void updatePraiseData(List<GrassArticlePraise> newPariseDetail,List<GrassArticlePraise> updateDetailList,
|
|
|
List<GrassArticle> articleList,List<GrassUserAchieve> userAchieveList) {
|
|
|
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);
|
...
|
...
|
@@ -153,18 +216,182 @@ public class GrassUserVirtualImpl implements IGrassVirtualService{ |
|
|
logger.info("addVirtualPraise update grassArticle success!");
|
|
|
//4)批量更新作者表(新增或者update)
|
|
|
userAchieveDAO.batchUpdatePraise(userAchieveList);
|
|
|
//5)发送站内信(通知作者 文章获赞)---后期增加
|
|
|
sendAddPariseMessage(newPariseDetail,articleInfoMap);
|
|
|
logger.info("addVirtualPraise success!");
|
|
|
}
|
|
|
|
|
|
|
|
|
// /**
|
|
|
// * 种草文章--增加点赞数---一期
|
|
|
// * 1)审核通过、被推荐,推荐时间 在72小时以内的文章(时间可配)
|
|
|
// * 2)随机点赞
|
|
|
// * 3)第一次点赞的,发送站内信,取消点赞,此次再点赞的,不发站内信(二期修改)
|
|
|
// */
|
|
|
// @Override
|
|
|
// public void addVirtualPraise() {
|
|
|
//
|
|
|
// logger.info("enter addVirtualPraise ");
|
|
|
// long currentTime = System.currentTimeMillis();
|
|
|
// //时间间隔
|
|
|
// int timeConfig = configReader.getInt("platform.grass.virtual.time.interval", 1);
|
|
|
// logger.info("addVirtualPraise virtual.time.interval is {}", timeConfig);
|
|
|
// long startTime = currentTime - timeConfig * INTERVAL;
|
|
|
// List<GrassArticle> articleList = grassArticleDao.selectByRecommendTime(startTime,currentTime);
|
|
|
// if(CollectionUtils.isEmpty(articleList)){
|
|
|
// logger.info("addVirtualPraise articleList is empty");
|
|
|
// 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,",");
|
|
|
//
|
|
|
// //1)这些文章已有的点赞明细(正常的点赞 && 被取消的点赞--》被取消过的 这种是不发站内信的)
|
|
|
// List<GrassArticlePraise> praiseList = grassArticlePraiseDao.selectByArticles(articleIds);
|
|
|
// Map<Integer,List<Integer>> articlePraisedMap = new HashMap<>();
|
|
|
// Map<Integer,List<Integer>> canceledPraiseMap = new HashMap<>();
|
|
|
// getOldPraiseInfo(praiseList,articlePraisedMap,canceledPraiseMap);
|
|
|
//
|
|
|
// //2)点赞逻辑,要区分逛的作者 和 普通作者
|
|
|
// Map<Integer,GrassUserAchieve> commonUserAchieveMap = new HashMap<>();
|
|
|
// Map<Integer,GrassUserAchieve> guangUserAchieveMap = new HashMap<>();
|
|
|
// //新增的点赞明细
|
|
|
// List<GrassArticlePraise> newPariseDetailList = 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,newPariseDetailList,canceledPraiseMap,allVirtualUids,s,currentTime,commonUserAchieveMap,1,newPariseDetail,updateDetailList);
|
|
|
// //2)逛文章点赞处理
|
|
|
// doVirtualPraise(guangArtcileList,newPariseDetailList,canceledPraiseMap,allVirtualUids,s,currentTime,guangUserAchieveMap,2,newPariseDetail,updateDetailList);
|
|
|
//
|
|
|
// if(CollectionUtils.isEmpty(newPariseDetailList) && 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={}",newPariseDetailList);
|
|
|
// 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(newPariseDetailList)){
|
|
|
// grassArticlePraiseDao.batchInsert(newPariseDetailList);
|
|
|
// }
|
|
|
//
|
|
|
// //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(newPariseDetailList,articleInfoMap);
|
|
|
// logger.info("addVirtualPraise success!");
|
|
|
// }
|
|
|
|
|
|
private void getOldPraiseInfo(List<GrassArticlePraise> praiseList, Map<Integer, List<Integer>> articlePraisedMap, Map<Integer, List<Integer>> canceledPraiseMap) {
|
|
|
for(GrassArticlePraise praise : praiseList){
|
|
|
Integer articleId = praise.getArticleId();
|
|
|
Integer status = praise.getStatus();
|
|
|
Integer uid = praise.getUid();
|
|
|
if(status == 0 ){//正常的点赞
|
|
|
if(articlePraisedMap.get(articleId) == null){
|
|
|
articlePraisedMap.put(articleId, new ArrayList<>());
|
|
|
}
|
|
|
articlePraisedMap.get(articleId).add(uid);
|
|
|
}
|
|
|
if(status == 1){//点赞被取消了
|
|
|
if(canceledPraiseMap.get(articleId) == null){
|
|
|
canceledPraiseMap.put(articleId,new ArrayList<>());
|
|
|
}
|
|
|
canceledPraiseMap.get(articleId).add(uid);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//点赞逻辑
|
|
|
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]);
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
* @param articleList --文章信息
|
|
|
* @param allVirtualUids --虚拟马甲
|
|
|
* @param currentTime
|
|
|
* @param userAchieveList --个人基本信息
|
|
|
* @param authorType
|
|
|
* @param newPariseDetail
|
|
|
* @param updateDetailList
|
|
|
* @param specialAuthors
|
|
|
*/
|
|
|
private void doVirtualPraise(List<GrassArticle> articleList, List<GrassArticlePraise> praiseList,
|
|
|
List<Integer> allVirtualUids, long currentTime,
|
|
|
List<GrassUserAchieve> userAchieveList, Integer authorType,
|
|
|
List<GrassArticlePraise> newPariseDetail, List<GrassArticlePraise> updateDetailList,
|
|
|
List<Integer> specialAuthors, int praiseType,
|
|
|
List<GrassArticle> updateArticleList) {
|
|
|
if(CollectionUtils.isEmpty(articleList)){
|
|
|
return;
|
|
|
}
|
|
|
//1)基本配置
|
|
|
String commonConfig = "";
|
|
|
String specialConfig = "";
|
|
|
int timeConfig = 0;
|
|
|
switch (praiseType){
|
|
|
case publishPraise:
|
|
|
//发布文章点赞策略
|
|
|
commonConfig = configReader.getString("platform.grass.virtualpraise.pubThreshold","");
|
|
|
specialConfig = configReader.getString("platform.grass.virtualpraise.pubSpecialthreshold","");
|
|
|
timeConfig = configReader.getInt("platform.grass.virtual.time.pubInterval", 0);
|
|
|
break;
|
|
|
case recPraise:
|
|
|
//推荐文章点赞策略
|
|
|
commonConfig = configReader.getString("platform.grass.virtualpraise.recThreshold","");
|
|
|
specialConfig = configReader.getString("platform.grass.virtualpraise.recSpecialThreshold","");
|
|
|
timeConfig = configReader.getInt("platform.grass.virtual.time.recInterval", 0);
|
|
|
break;
|
|
|
default:
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if(StringUtils.isEmpty(commonConfig)|| StringUtils.isEmpty(specialConfig) || timeConfig == 0){
|
|
|
logger.warn("doVirtualPraise config is empty");
|
|
|
return;
|
|
|
}
|
|
|
String[] commonStrategy = StringUtils.split(commonConfig, ",");
|
|
|
String [] specialStrategy = StringUtils.split(specialConfig, ",");
|
|
|
//普通用户的点赞策略(线性函数)
|
|
|
int start = Integer.valueOf(commonStrategy[0]);//起始(0,start)
|
|
|
int end = Integer.valueOf(commonStrategy[1]);//终结(timeConfig,end)
|
|
|
//重点用户的点赞策略(线性函数)
|
|
|
int startSpecial = Integer.valueOf(specialStrategy[0]);//起始点(0,startSpecial)
|
|
|
int endSpecial = Integer.valueOf(specialStrategy[1]);//终结(timeConfig,endSpecial)
|
|
|
//两个坐标点 --线性函数 y=kx + b
|
|
|
double k = ((end - start)*1d) / (timeConfig * 1d);
|
|
|
double b = start;
|
|
|
double kSpecial = ((endSpecial - startSpecial)*1d) / (timeConfig * 1d);
|
|
|
double bSpecial = startSpecial;
|
|
|
|
|
|
//3)基础数据--原有的点赞(正常的点赞--排除; 取消的点赞--不要发站内信)
|
|
|
Map<Integer,List<Integer>> articlePraiseMap = new HashMap<>();
|
|
|
Map<Integer,List<Integer>> canceledPraiseMap = new HashMap<>();
|
|
|
getOldPraiseInfo(praiseList,articlePraiseMap,canceledPraiseMap);
|
|
|
Map<Integer,GrassUserAchieve> userAchieveMap = new HashMap<>();
|
|
|
//4)处理点赞
|
|
|
for(GrassArticle article : articleList){
|
|
|
Integer articleId = article.getId();
|
|
|
int authorUid = article.getAuthorUid();
|
...
|
...
|
@@ -175,7 +402,29 @@ public class GrassUserVirtualImpl implements IGrassVirtualService{ |
|
|
if(CollectionUtils.isNotEmpty(oldPraiseList)){
|
|
|
tempList.removeAll(oldPraiseList);
|
|
|
}
|
|
|
Set<Integer> randomUidList = getRandomFans(tempList, min, max);
|
|
|
if(CollectionUtils.isEmpty(tempList)){//这篇文章没有可用的马甲
|
|
|
continue;
|
|
|
}
|
|
|
double time ;
|
|
|
if(praiseType == publishPraise ){
|
|
|
if(article.getAuthTime() == null || article.getAuthTime() == 0){
|
|
|
logger.warn("doVirtualPraise authTime is null, articleId={}",articleId);
|
|
|
continue;
|
|
|
}
|
|
|
time = ((currentTime - article.getAuthTime()) * 1d)/(1000d * 60 * 60 );//小时
|
|
|
}else {
|
|
|
if(article.getRecommendTime() == null || article.getRecommendTime() == 0){
|
|
|
logger.warn("doVirtualPraise recommendTime is null, articleId={}",articleId);
|
|
|
continue;
|
|
|
}
|
|
|
time = ((currentTime - article.getRecommendTime()) * 1d)/(1000d * 60 * 60 );//小时
|
|
|
}
|
|
|
Set<Integer> randomUidList;
|
|
|
if(authorType == GrassUserTypeEnum.COMMON.getValue() && specialAuthors.contains(authorUid)){//有货的用户,并且是重点用户,采用的线性函数有所不同
|
|
|
randomUidList = getPraiseUids(tempList, kSpecial, bSpecial, time);
|
|
|
}else{
|
|
|
randomUidList = getPraiseUids(tempList, k, b, time);
|
|
|
}
|
|
|
if(CollectionUtils.isEmpty(randomUidList)){
|
|
|
article.setPraiseCount(0);//新增加的点赞数是0
|
|
|
logger.info("addVirtualPraise randomUidList is empty articleId={},authorUid={}",articleId,authorUid);
|
...
|
...
|
@@ -201,26 +450,88 @@ public class GrassUserVirtualImpl implements IGrassVirtualService{ |
|
|
}
|
|
|
|
|
|
//2)更新文章获赞总数
|
|
|
article.setPraiseCount(random);//增加点赞数
|
|
|
article.setUpdateTime(currentTime);
|
|
|
|
|
|
GrassArticle updateArticle = new GrassArticle();
|
|
|
updateArticle.setPraiseCount(random);//增加的赞
|
|
|
updateArticle.setUpdateTime(currentTime);
|
|
|
updateArticle.setId(articleId);
|
|
|
updateArticleList.add(updateArticle);
|
|
|
//3)更新作者 获赞总数
|
|
|
//同一个作者 必须要累加计数 否则更新结果不正确
|
|
|
GrassUserAchieve userAchieve = new GrassUserAchieve();
|
|
|
if(userMap.get(authorUid)!=null){
|
|
|
//求和
|
|
|
userAchieve = userMap.get(authorUid);
|
|
|
userAchieve.setPraiseAmount(userAchieve.getPraiseAmount() + random);
|
|
|
if(userAchieveMap.get(authorUid)!=null){
|
|
|
userAchieve = userAchieveMap.get(authorUid);
|
|
|
userAchieve.setPraiseAmount(userAchieve.getPraiseAmount() + random); //求和
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
userAchieve.setUid(authorUid);
|
|
|
userAchieve.setUserType(authorType);
|
|
|
userAchieve.setUpdateTime((int) (currentTime / 1000l));
|
|
|
//新增加的点赞数
|
|
|
userAchieve.setPraiseAmount(random);
|
|
|
userMap.put(authorUid, userAchieve);
|
|
|
userAchieveMap.put(authorUid, userAchieve);
|
|
|
}
|
|
|
userAchieveList.addAll(userAchieveMap.values());
|
|
|
}
|
|
|
|
|
|
//随着时间的推移,增加的点赞数 逐步减少--》y= kx + b
|
|
|
//x 是距离当前的时间(分钟为单位,比小时更精确)
|
|
|
private Set<Integer> getPraiseUids(List<Integer> virtualList,double k,double b, double x ) {
|
|
|
if(virtualList.isEmpty()){//没有可选的马甲粉丝
|
|
|
return new HashSet<>();
|
|
|
}
|
|
|
//数量--随着时间的推移,线性的
|
|
|
double numDouble = k * x + b;
|
|
|
int num = new Double(numDouble).intValue();//需要增加的点
|
|
|
int totalVitual = virtualList.size();
|
|
|
Set<Integer> set = new HashSet<>();
|
|
|
if(totalVitual <= num){
|
|
|
set = virtualList.stream().collect(Collectors.toSet());
|
|
|
return set;
|
|
|
}
|
|
|
for(int i = 0 ; i < num; i++){
|
|
|
int index = getRandom(0, virtualList.size() - 1);
|
|
|
Integer uid = virtualList.get(index);//随机得到的粉丝uid
|
|
|
virtualList.remove(uid);
|
|
|
set.add(uid);
|
|
|
}
|
|
|
return set;
|
|
|
}
|
|
|
|
|
|
private void sendAddPariseMessage(List<GrassArticlePraise> pariseDetail) {
|
|
|
if(CollectionUtils.isEmpty(pariseDetail)){
|
|
|
return;
|
|
|
}
|
|
|
//批量插入的时候没有获取到id(依赖版本较低,获取不到),重查一遍
|
|
|
List<GrassArticlePraise> newPariseDetail = grassArticlePraiseDao.selectByArticleAndUids(pariseDetail);
|
|
|
List<Integer> articleIds = newPariseDetail.stream().map(GrassArticlePraise::getArticleId).collect(Collectors.toList());
|
|
|
Map<Integer,GrassArticle> articleInfoMap = grassArticleDao.selectMapByIds(articleIds);
|
|
|
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;
|
|
|
}
|
|
|
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);
|
|
|
}
|
|
|
|
|
|
sendMessage(reqList);
|
|
|
}
|
|
|
|
|
|
private void sendAddPariseMessage(List<GrassArticlePraise> pariseDetail,Map<Integer,GrassArticle> articleInfoMap) {
|
...
|
...
|
|