wangyunpeng пре 1 месец
родитељ
комит
f80ef14f14

+ 18 - 0
api-module/src/main/java/com/tzld/piaoquan/api/component/RecommendApiService.java

@@ -7,6 +7,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 
+import java.util.List;
+
 /**
  * 推荐API服务
  */
@@ -36,6 +38,22 @@ public class RecommendApiService {
         }
         return null;
     }
+    /**
+     * 获取最近N天 rootSourceId
+     */
+    public List<String> getArticleByRootSourceId(String rootSourceIdPrefix, Integer days) {
+        try {
+            String url = recommendApiHost + "/article/getNearDaysRootSourceIds?rootSourceIdPrefix=" + rootSourceIdPrefix + "&days=" + days;
+            String response = httpPoolClient.get(url);
+            JSONObject res = JSONObject.parseObject(response);
+            if (res.getInteger("code") == 0 && res.getJSONArray("data") != null) {
+                return res.getJSONArray("data").toJavaList(String.class);
+            }
+        } catch (Exception e) {
+            log.error("获取文章信息失败, rootSourceIdPrefix={} days={}", rootSourceIdPrefix, days, e);
+        }
+        return null;
+    }
     /**
      * 根据rootSourceId获取合作方文章信息
      */

+ 7 - 0
api-module/src/main/java/com/tzld/piaoquan/api/controller/ExternalController.java

@@ -36,4 +36,11 @@ public class ExternalController {
         return CommonResponse.success();
     }
 
+    @ApiOperation(value = "历史数据导入")
+    @GetMapping("/job/initExternalChannelHistory")
+    public CommonResponse<Null> initExternalChannelHistory(@RequestParam String days) {
+        job.initExternalChannelHistory(days);
+        return CommonResponse.success();
+    }
+
 }

+ 37 - 17
api-module/src/main/java/com/tzld/piaoquan/api/job/ExternalChannelProcessJob.java

@@ -846,16 +846,16 @@ public class ExternalChannelProcessJob {
             int totalCount = 0;
 
             // 初始化所有已支持的渠道
-            totalCount += initChannelHistory(ChannelType.MINIAPP_TOULIU, startDate);
-            totalCount += initChannelHistory(ChannelType.GZH_COOPERATE_JIZHUAN, startDate);
-            totalCount += initChannelHistory(ChannelType.QW_COOPERATE, startDate);
-            totalCount += initChannelHistory(ChannelType.GZH_TOULIU, startDate);
-            totalCount += initChannelHistory(ChannelType.FWH_COOPERATE_DAILY, startDate);
-            totalCount += initChannelHistory(ChannelType.FWH_TOULIU_DAILY, startDate);
-            totalCount += initChannelHistory(ChannelType.FWH_TOULIU_REPLY, startDate);
-            totalCount += initChannelHistory(ChannelType.GZH_COOPERATE_DAILY, startDate);
-            totalCount += initChannelHistory(ChannelType.GZH_BUY_ACCOUNT, startDate);
-            totalCount += initChannelHistory(ChannelType.GZH_OPERATION_DAILY, startDate);
+            totalCount += initChannelHistory(ChannelType.MINIAPP_TOULIU, startDate, days);
+            totalCount += initChannelHistory(ChannelType.GZH_COOPERATE_JIZHUAN, startDate, days);
+            totalCount += initChannelHistory(ChannelType.QW_COOPERATE, startDate, days);
+            totalCount += initChannelHistory(ChannelType.GZH_TOULIU, startDate, days);
+            totalCount += initChannelHistory(ChannelType.FWH_COOPERATE_DAILY, startDate, days);
+            totalCount += initChannelHistory(ChannelType.FWH_TOULIU_DAILY, startDate, days);
+            totalCount += initChannelHistory(ChannelType.FWH_TOULIU_REPLY, startDate, days);
+            totalCount += initChannelHistory(ChannelType.GZH_COOPERATE_DAILY, startDate, days);
+            totalCount += initChannelHistory(ChannelType.GZH_BUY_ACCOUNT, startDate, days);
+            totalCount += initChannelHistory(ChannelType.GZH_OPERATION_DAILY, startDate, days);
 
             log.info("历史数据初始化完成, 共插入{}条记录", totalCount);
             return new ReturnT<>(ReturnT.SUCCESS_CODE, "初始化完成,共插入" + totalCount + "条记录");
@@ -872,7 +872,7 @@ public class ExternalChannelProcessJob {
      * @param startDate   起始日期
      * @return 插入的记录数
      */
-    private int initChannelHistory(ChannelType channelType, Date startDate) {
+    private int initChannelHistory(ChannelType channelType, Date startDate, int days) {
         log.info("初始化渠道历史数据, channelType={}, startDate={}", channelType, startDate);
 
         List<String> rootSourceIds = new ArrayList<>();
@@ -906,20 +906,20 @@ public class ExternalChannelProcessJob {
                 rootSourceIds = queryRootSourceIdsFromCgiReply(PREFIX_FWHTOULIU_TENCENTGZH, startDate);
                 break;
             case FWH_TOULIU_DAILY:
-                // 服务号投流-Daily:从cgi_reply_bucket_data查询fwhtouliu_开头(非fwhtouliu_tencentgzh)
-                // 从aigc查询
+                // 服务号投流-Daily:从aigc getNearDaysRootSourceIds接口查询fwhtouliu_开头
+                rootSourceIds = queryRootSourceIdsFromAigc(PREFIX_FWHTOULIU, days);
                 break;
             case GZH_COOPERATE_DAILY:
                 // 公众号合作-Daily:从content_platform_gzh_plan_video查询longArticles_开头
                 rootSourceIds = queryRootSourceIdsFromGzhPlanVideo(PREFIX_LONGARTICLES, startDate);
                 break;
             case GZH_BUY_ACCOUNT:
-                // 公众号买号:需确认数据来源
-                // 从aigc查询
+                // 公众号买号:从aigc getNearDaysRootSourceIds接口查询longArticles_inner_开头
+                rootSourceIds = queryRootSourceIdsFromAigc(PREFIX_LONGARTICLES, days);
                 break;
             case GZH_OPERATION_DAILY:
-                // 公众号代运营-Daily:需确认数据来源
-                // 从aigc查询
+                // 公众号代运营-Daily:从aigc getNearDaysRootSourceIds接口查询longArticles_inner_开头
+                rootSourceIds = queryRootSourceIdsFromAigc(PREFIX_LONGARTICLES, days);
                 break;
             default:
                 return 0;
@@ -958,6 +958,26 @@ public class ExternalChannelProcessJob {
         return insertedCount;
     }
 
+    /**
+     * 从aigc getNearDaysRootSourceIds接口查询指定前缀的rootSourceId列表
+     *
+     * @param prefix 前缀
+     * @param days   天数
+     * @return rootSourceId列表
+     */
+    private List<String> queryRootSourceIdsFromAigc(String prefix, int days) {
+        List<String> result = new ArrayList<>();
+        try {
+            List<String> list = recommendApiService.getArticleByRootSourceId(prefix, days);
+            if (!CollectionUtils.isEmpty(list)) {
+                result = list;
+            }
+        } catch (Exception e) {
+            log.error("从aigc查询历史数据失败, prefix={}, days={}", prefix, days, e);
+        }
+        return result;
+    }
+
     /**
      * 从cgi_reply_bucket_data表查询指定前缀的rootSourceId列表
      *