Browse Source

Merge branch 'feature/20241012-change-reply-base' of Server/long-article-recommend into master

fengzhoutian 9 months ago
parent
commit
688e2947c6

+ 31 - 2
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/strategy/reply/impl/BuckStrategyV1.java

@@ -3,9 +3,9 @@ package com.tzld.longarticle.recommend.server.service.strategy.reply.impl;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.tzld.longarticle.recommend.server.common.enums.cgi.ReplyStrategyServiceEnum;
-import com.tzld.longarticle.recommend.server.model.cgi.*;
 import com.tzld.longarticle.recommend.server.mapper.crawler.AlgGhAutoreplyVideoRankDataMapper;
 import com.tzld.longarticle.recommend.server.mapper.crawler.CgiReplyBucketDataMapper;
+import com.tzld.longarticle.recommend.server.model.cgi.*;
 import com.tzld.longarticle.recommend.server.repository.model.AlgGhAutoreplyVideoRankData;
 import com.tzld.longarticle.recommend.server.repository.model.AlgGhAutoreplyVideoRankDataExample;
 import com.tzld.longarticle.recommend.server.repository.model.CgiReplyBucketData;
@@ -15,6 +15,7 @@ import com.tzld.longarticle.recommend.server.service.strategy.reply.ReplyStrateg
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
@@ -37,6 +38,9 @@ public class BuckStrategyV1 implements ReplyStrategyService {
      */
     private static final String bucketStrategyConfig = "{\"stg0909-base\":[5,6],\"stg0909-explore1\":[7],\"stg0909-explore2\":[8,9]}";
 
+    @Value("${bucketStrategyConfig:{}}")
+    private String bucketStrategyConfigV2;
+
     /**
      * 自动回复使用小程序Id
      */
@@ -56,7 +60,7 @@ public class BuckStrategyV1 implements ReplyStrategyService {
     @Override
     public ReplyBucketData getResult(BucketDataParam bucketDataParam) {
         // 0 获取策略key
-        JSONObject bucketStrategyConfigJsonObject = JSON.parseObject(bucketStrategyConfig);
+        JSONObject bucketStrategyConfigJsonObject = getStrategyConfig(bucketDataParam.getGhId());
         Set<String> keyedSet = bucketStrategyConfigJsonObject.keySet();
         // 1 处理文章--算法引擎--排序文章数据
 //        getWenzhangData();
@@ -71,11 +75,32 @@ public class BuckStrategyV1 implements ReplyStrategyService {
         return getReplyBucketData(bucketStrategyConfigJsonObject, keyedSet, bucketDataParam.getGhId());
     }
 
+    private JSONObject getStrategyConfig(String ghId) {
+        JSONObject allStrategyConfigs = JSON.parseObject(bucketStrategyConfigV2);
+        JSONObject currentGhIdStrategyConfig = null;
+        if (allStrategyConfigs.containsKey(ghId)) {
+            currentGhIdStrategyConfig = allStrategyConfigs.getJSONObject(ghId);
+        } else if (allStrategyConfigs.containsKey("default")) {
+            currentGhIdStrategyConfig = allStrategyConfigs.getJSONObject("default");
+        } else {
+            log.error("invalid strategy config: default key does not exist");
+            throw new RuntimeException("Default strategy config does not exist");
+        }
+        // check param
+        if (!currentGhIdStrategyConfig.containsKey("base")) {
+            throw new RuntimeException("Strategy config does not have manual base");
+        }
+        return currentGhIdStrategyConfig;
+    }
+
     private ReplyBucketData getReplyBucketData(JSONObject bucketStrategyConfigJsonObject, Set<String> keyedSet, String ghId) {
         // 策略小程序数据
         ReplyBucketData replyBucketData = new ReplyBucketData();
         List<GroupData> groupDataList = new ArrayList<>();
         for (String key : keyedSet) {
+            if ("base".equals(key)) {
+                continue;
+            }
             CgiReplyBucketDataExample cgiReplyBucketDataExample = new CgiReplyBucketDataExample();
             cgiReplyBucketDataExample.createCriteria().andIsDeleteEqualTo(0).andStrategyEqualTo(key).andGhIdEqualTo(ghId);
             cgiReplyBucketDataExample.setOrderByClause("sort");
@@ -110,6 +135,10 @@ public class BuckStrategyV1 implements ReplyStrategyService {
         }
         // 获取人工实验数据
         List<GroupData> groupDataBaseList = httpClientService.sendPenGongBaseRequest(ghId);
+        int baseBucketNum = bucketStrategyConfigJsonObject.getJSONArray("base").size();
+        if (groupDataBaseList.size() > baseBucketNum) {
+            groupDataBaseList = groupDataBaseList.subList(0, baseBucketNum);
+        }
         if (!CollectionUtils.isEmpty(groupDataBaseList)) {
             GroupData groupData = groupDataBaseList.get(0);
             List<MsgData> msgDataList = groupData.getMsgDataList();