|
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
|
import com.tzld.piaoquan.api.common.enums.ReplyStrategyServiceEnum;
|
|
import com.tzld.piaoquan.api.common.enums.ReplyStrategyServiceEnum;
|
|
|
|
+import com.tzld.piaoquan.api.common.enums.StrategyStatusEnum;
|
|
import com.tzld.piaoquan.api.component.TouLiuHttpClient;
|
|
import com.tzld.piaoquan.api.component.TouLiuHttpClient;
|
|
import com.tzld.piaoquan.api.dao.mapper.AlgGhAutoreplyVideoRankDataMapper;
|
|
import com.tzld.piaoquan.api.dao.mapper.AlgGhAutoreplyVideoRankDataMapper;
|
|
import com.tzld.piaoquan.api.dao.mapper.CgiReplyBucketDataMapper;
|
|
import com.tzld.piaoquan.api.dao.mapper.CgiReplyBucketDataMapper;
|
|
@@ -40,6 +41,9 @@ public class ThirdPartyPushMessageStrategyV1 implements ReplyStrategyService {
|
|
*/
|
|
*/
|
|
private static final String bucketStrategyConfig = "{\"3rd-party-base\":[0,1,2,3,4,5,6],\"3rd-party-explore1\":[7],\"3rd-party-explore2\":[8,9]}";
|
|
private static final String bucketStrategyConfig = "{\"3rd-party-base\":[0,1,2,3,4,5,6],\"3rd-party-explore1\":[7],\"3rd-party-explore2\":[8,9]}";
|
|
|
|
|
|
|
|
+
|
|
|
|
+ private static final String manualConfig = "{\"manual\":[0,1,2,3,4,5,6,7,8,9]}";
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 自动回复使用小程序Id
|
|
* 自动回复使用小程序Id
|
|
*/
|
|
*/
|
|
@@ -61,8 +65,13 @@ public class ThirdPartyPushMessageStrategyV1 implements ReplyStrategyService {
|
|
public ReplyBucketData getResult(BucketDataParam bucketDataParam) {
|
|
public ReplyBucketData getResult(BucketDataParam bucketDataParam) {
|
|
log.info("ThirdPartyPushMessageStrategyV1 start");
|
|
log.info("ThirdPartyPushMessageStrategyV1 start");
|
|
// 0 获取策略key
|
|
// 0 获取策略key
|
|
- JSONObject bucketStrategyConfigJsonObject = JSON.parseObject(bucketStrategyConfig);
|
|
|
|
- Set<String> keyedSet = bucketStrategyConfigJsonObject.keySet();
|
|
|
|
|
|
+ JSONObject configJsonObject;
|
|
|
|
+ if (Objects.equals(StrategyStatusEnum.DEFAULT.status, bucketDataParam.getStrategyStatus())) {
|
|
|
|
+ configJsonObject = JSON.parseObject(manualConfig);
|
|
|
|
+ } else {
|
|
|
|
+ configJsonObject = JSON.parseObject(bucketStrategyConfig);
|
|
|
|
+ }
|
|
|
|
+ Set<String> keyedSet = configJsonObject.keySet();
|
|
// 1 处理文章--算法引擎--排序文章数据
|
|
// 1 处理文章--算法引擎--排序文章数据
|
|
// getWenzhangData();
|
|
// getWenzhangData();
|
|
// 2 处理小程序--读取离线数据表--获取策略排序小程序数据
|
|
// 2 处理小程序--读取离线数据表--获取策略排序小程序数据
|
|
@@ -73,7 +82,7 @@ public class ThirdPartyPushMessageStrategyV1 implements ReplyStrategyService {
|
|
// 3 入库读表
|
|
// 3 入库读表
|
|
insertSmallData(smallDataCgiReplyList, keyedSet, bucketDataParam);
|
|
insertSmallData(smallDataCgiReplyList, keyedSet, bucketDataParam);
|
|
// 4 组装分桶数据
|
|
// 4 组装分桶数据
|
|
- return getReplyBucketData(bucketStrategyConfigJsonObject, keyedSet, bucketDataParam.getGhId());
|
|
|
|
|
|
+ return getReplyBucketData(configJsonObject, keyedSet, bucketDataParam.getGhId());
|
|
}
|
|
}
|
|
|
|
|
|
private ReplyBucketData getReplyBucketData(JSONObject bucketStrategyConfigJsonObject, Set<String> keyedSet, String ghId) {
|
|
private ReplyBucketData getReplyBucketData(JSONObject bucketStrategyConfigJsonObject, Set<String> keyedSet, String ghId) {
|
|
@@ -208,41 +217,72 @@ public class ThirdPartyPushMessageStrategyV1 implements ReplyStrategyService {
|
|
// base作为人工控制
|
|
// base作为人工控制
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
- // 获取最新dt的策略
|
|
|
|
- String dtVersion = algGhAutoreplyVideoRankDataMapper.selectLatestDtVersionByStrategyKeyAndGhId(key, bucketDataParam.getGhId());
|
|
|
|
- if (StringUtils.isEmpty(dtVersion)) {
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- // 判断当前的dtVersion是否已经处理过了
|
|
|
|
- CgiReplyBucketDataExample cgiReplyBucketDataExample = new CgiReplyBucketDataExample();
|
|
|
|
- cgiReplyBucketDataExample.createCriteria().andIsDeleteEqualTo(0).andStrategyDtEqualTo(dtVersion).andStrategyEqualTo(key).andGhIdEqualTo(bucketDataParam.getGhId());
|
|
|
|
- long count = cgiReplyBucketDataMapper.countByExample(cgiReplyBucketDataExample);
|
|
|
|
- if (count != 0) {
|
|
|
|
- // 说明已处理过该dtVersion数据
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- // 获取最新dt数据
|
|
|
|
- List<AlgGhAutoreplyVideoRankData> dtVersionStrategyData = getDtVersionStrategyData(key, dtVersion, bucketDataParam.getGhId());
|
|
|
|
- List<Long> videoIds = dtVersionStrategyData.stream().map(AlgGhAutoreplyVideoRankData::getVideoId).collect(Collectors.toList());
|
|
|
|
- Map<Long, String> videoDetailMap = touLiuHttpClient.getVideoDetailRequest(videoIds);
|
|
|
|
- result.addAll(dtVersionStrategyData.stream().map(x -> {
|
|
|
|
- CgiReplyBucketData cgiReplyBucketData = new CgiReplyBucketData();
|
|
|
|
- cgiReplyBucketData.setStrategy(key);
|
|
|
|
- cgiReplyBucketData.setSort(x.getSort());
|
|
|
|
- cgiReplyBucketData.setStrategyDt(x.getDtVersion());
|
|
|
|
- cgiReplyBucketData.setGhId(x.getGhId());
|
|
|
|
- cgiReplyBucketData.setMsgType(1);
|
|
|
|
- cgiReplyBucketData.setTitle(x.getTitle());
|
|
|
|
- String cover = videoDetailMap.get(x.getVideoId());
|
|
|
|
- if (StringUtils.isNotEmpty(cover)) {
|
|
|
|
- cgiReplyBucketData.setCoverUrl(cover);
|
|
|
|
- } else {
|
|
|
|
- cgiReplyBucketData.setCoverUrl(CDN_URL + x.getCoverUrl());
|
|
|
|
|
|
+ if (Objects.equals(StrategyStatusEnum.DEFAULT.status, bucketDataParam.getStrategyStatus())) {
|
|
|
|
+ if (CollectionUtils.isEmpty(bucketDataParam.getVideos())) {
|
|
|
|
+ return null;
|
|
}
|
|
}
|
|
- cgiReplyBucketData.setMiniAppId(SMALL_APP_Id);
|
|
|
|
- cgiReplyBucketData.setMiniVideoId(x.getVideoId());
|
|
|
|
- return cgiReplyBucketData;
|
|
|
|
- }).collect(Collectors.toList()));
|
|
|
|
|
|
+ CgiReplyBucketDataExample cgiReplyBucketDataExample = new CgiReplyBucketDataExample();
|
|
|
|
+ cgiReplyBucketDataExample.createCriteria().andIsDeleteEqualTo(0).andStrategyEqualTo(key)
|
|
|
|
+ .andGhIdEqualTo(bucketDataParam.getGhId()).andMiniVideoIdIn(bucketDataParam.getVideos());
|
|
|
|
+ long count = cgiReplyBucketDataMapper.countByExample(cgiReplyBucketDataExample);
|
|
|
|
+ if (count == bucketDataParam.getVideos().size()) {
|
|
|
|
+ // 已经存在就不处理
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ Map<Long, VideoDetail> videoDetailMap = touLiuHttpClient.getVideoDetailRequest(bucketDataParam.getVideos());
|
|
|
|
+ int sort = 1;
|
|
|
|
+ for (Long videoId : bucketDataParam.getVideos()) {
|
|
|
|
+ CgiReplyBucketData cgiReplyBucketData = new CgiReplyBucketData();
|
|
|
|
+ cgiReplyBucketData.setStrategy(key);
|
|
|
|
+ cgiReplyBucketData.setSort(sort);
|
|
|
|
+ cgiReplyBucketData.setGhId(bucketDataParam.getGhId());
|
|
|
|
+ cgiReplyBucketData.setMsgType(1);
|
|
|
|
+ VideoDetail videoDetail = videoDetailMap.get(videoId);
|
|
|
|
+ if (videoDetail != null && StringUtils.isNotEmpty(videoDetail.getCover())) {
|
|
|
|
+ cgiReplyBucketData.setCoverUrl(videoDetail.getCover());
|
|
|
|
+ }
|
|
|
|
+ if (videoDetail != null && StringUtils.isNotEmpty(videoDetail.getTitle())) {
|
|
|
|
+ cgiReplyBucketData.setTitle(videoDetail.getTitle());
|
|
|
|
+ }
|
|
|
|
+ cgiReplyBucketData.setMiniAppId(SMALL_APP_Id);
|
|
|
|
+ cgiReplyBucketData.setMiniVideoId(videoId);
|
|
|
|
+ result.add(cgiReplyBucketData);
|
|
|
|
+ sort++;
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ // 获取最新dt的策略
|
|
|
|
+ String dtVersion = algGhAutoreplyVideoRankDataMapper.selectLatestDtVersionByStrategyKeyAndGhId(key, bucketDataParam.getGhId());
|
|
|
|
+ // 判断当前的dtVersion是否已经处理过了
|
|
|
|
+ CgiReplyBucketDataExample cgiReplyBucketDataExample = new CgiReplyBucketDataExample();
|
|
|
|
+ cgiReplyBucketDataExample.createCriteria().andIsDeleteEqualTo(0).andStrategyDtEqualTo(dtVersion).andStrategyEqualTo(key).andGhIdEqualTo(bucketDataParam.getGhId());
|
|
|
|
+ long count = cgiReplyBucketDataMapper.countByExample(cgiReplyBucketDataExample);
|
|
|
|
+ if (count != 0) {
|
|
|
|
+ // 说明已处理过该dtVersion数据
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ // 获取最新dt数据
|
|
|
|
+ List<AlgGhAutoreplyVideoRankData> dtVersionStrategyData = getDtVersionStrategyData(key, dtVersion, bucketDataParam.getGhId());
|
|
|
|
+ List<Long> videoIds = dtVersionStrategyData.stream().map(AlgGhAutoreplyVideoRankData::getVideoId).collect(Collectors.toList());
|
|
|
|
+ Map<Long, VideoDetail> videoDetailMap = touLiuHttpClient.getVideoDetailRequest(videoIds);
|
|
|
|
+ result.addAll(dtVersionStrategyData.stream().map(x -> {
|
|
|
|
+ CgiReplyBucketData cgiReplyBucketData = new CgiReplyBucketData();
|
|
|
|
+ cgiReplyBucketData.setStrategy(key);
|
|
|
|
+ cgiReplyBucketData.setSort(x.getSort());
|
|
|
|
+ cgiReplyBucketData.setStrategyDt(x.getDtVersion());
|
|
|
|
+ cgiReplyBucketData.setGhId(x.getGhId());
|
|
|
|
+ cgiReplyBucketData.setMsgType(1);
|
|
|
|
+ cgiReplyBucketData.setTitle(x.getTitle());
|
|
|
|
+ VideoDetail videoDetail = videoDetailMap.get(x.getVideoId());
|
|
|
|
+ if (videoDetail != null && StringUtils.isNotEmpty(videoDetail.getCover())) {
|
|
|
|
+ cgiReplyBucketData.setCoverUrl(videoDetail.getCover());
|
|
|
|
+ } else {
|
|
|
|
+ cgiReplyBucketData.setCoverUrl(CDN_URL + x.getCoverUrl());
|
|
|
|
+ }
|
|
|
|
+ cgiReplyBucketData.setMiniAppId(SMALL_APP_Id);
|
|
|
|
+ cgiReplyBucketData.setMiniVideoId(x.getVideoId());
|
|
|
|
+ return cgiReplyBucketData;
|
|
|
|
+ }).collect(Collectors.toList()));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
// 获取最新数据版本
|
|
// 获取最新数据版本
|
|
return CollectionUtils.isEmpty(result) ? null : result;
|
|
return CollectionUtils.isEmpty(result) ? null : result;
|