yumeng 6 годин тому
батько
коміт
0311c5271c

+ 15 - 23
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/data/service/impl/KuaiShouMaterialReportServiceImpl.java

@@ -28,15 +28,10 @@ import java.util.Map;
 public class KuaiShouMaterialReportServiceImpl implements IKuaiShouMaterialReportService {
 
     /**
-     * 视频素材报表维度
+     * 视频素材报表维度(图片维度view_type=16的API不返回可用素材ID,不拉取)
      */
     private static final int VIEW_TYPE_VIDEO = 5;
 
-    /**
-     * 图片素材报表维度
-     */
-    private static final int VIEW_TYPE_IMAGE = 16;
-
     @Autowired
     private IKuaiShouErrorLogService errorLogService;
 
@@ -48,17 +43,15 @@ public class KuaiShouMaterialReportServiceImpl implements IKuaiShouMaterialRepor
 
     @Override
     public void queryMaterialReportDaily(String accessToken, Long advertiserId, String startDate, String endDate, int page) {
-        // 视频素材报表(view_type=5)与图片素材报表(view_type=16)各拉一遍
-        queryMaterialReport(accessToken, advertiserId, startDate, endDate, page, VIEW_TYPE_VIDEO, null);
-        queryMaterialReport(accessToken, advertiserId, startDate, endDate, page, VIEW_TYPE_IMAGE, null);
+        // 仅拉取视频素材报表(view_type=5)
+        queryMaterialReport(accessToken, advertiserId, startDate, endDate, page, null);
     }
 
     @Override
     public void getMaterialDailyRetry(Long errorId, Long advertiserId, String accessToken, String startDate, String endDate, Integer page, Integer isSend) {
         int curPage = page == null ? 1 : page;
-        boolean videoOk = queryMaterialReport(accessToken, advertiserId, startDate, endDate, curPage, VIEW_TYPE_VIDEO, errorId);
-        boolean imageOk = queryMaterialReport(accessToken, advertiserId, startDate, endDate, curPage, VIEW_TYPE_IMAGE, errorId);
-        if (videoOk && imageOk && errorId != null) {
+        boolean ok = queryMaterialReport(accessToken, advertiserId, startDate, endDate, curPage, errorId);
+        if (ok && errorId != null) {
             errorLogService.deleteInfoByErrorId(errorId);
             if (isSend != null && isSend == 1) {
                 AlertUtils.sendMessage(advertiserId, startDate, endDate, 2, "daily", 1, "material");
@@ -69,11 +62,10 @@ public class KuaiShouMaterialReportServiceImpl implements IKuaiShouMaterialRepor
     /**
      * 拉取素材报表并入库
      *
-     * @param viewType 5-视频素材报表 16-图片素材报表
-     * @param errorId  非空表示重试路径(失败不重复记错误日志)
+     * @param errorId 非空表示重试路径(失败不重复记错误日志)
      * @return 本次拉取是否成功
      */
-    private boolean queryMaterialReport(String accessToken, Long advertiserId, String startDate, String endDate, int page, int viewType, Long errorId) {
+    private boolean queryMaterialReport(String accessToken, Long advertiserId, String startDate, String endDate, int page, Long errorId) {
         String url = KuaishouLinkConstants.KS_PREFIX + KuaishouLinkConstants.V1_MATERIAL_REPORT;
         Map<String, String> headers = new HashMap<>();
         headers.put("Content-Type", "application/json");
@@ -87,14 +79,14 @@ public class KuaiShouMaterialReportServiceImpl implements IKuaiShouMaterialRepor
         }
         param.put("advertiser_id", advertiserId);
         param.put("temporal_granularity", "DAILY");
-        param.put("view_type", viewType);
+        param.put("view_type", VIEW_TYPE_VIDEO);
         param.put("page_size", 2000);
         param.put("page", page);
         boolean acquired = rateLimitUtil.acquire(url);
         String result = acquired ? HttpUtils.httpPostRequest(url, param, headers) : null;
         if (Check.isNull(result)) {
             String errMsg = acquired ? "返回结果为空" : "频控等待超时";
-            log.error("获取快手素材日报报表异常:{},accountId:{},viewType:{}", errMsg, advertiserId, viewType);
+            log.error("获取快手素材日报报表异常:{},accountId:{}", errMsg, advertiserId);
             if (errorId == null) {
                 errorLogService.addError(advertiserId, startDate, endDate, "material", "daily", errMsg, 2);
             }
@@ -104,7 +96,7 @@ public class KuaiShouMaterialReportServiceImpl implements IKuaiShouMaterialRepor
         Integer code = resultJson.getInteger("code");
         String message = resultJson.getString("message");
         if (null != code && code != 0) {
-            log.error("获取快手素材日报报表异常:{},accountId:{},viewType:{}", message, advertiserId, viewType);
+            log.error("获取快手素材日报报表异常:{},accountId:{}", message, advertiserId);
             if (errorId == null) {
                 errorLogService.addError(advertiserId, startDate, endDate, "material", "daily", message, 2);
             }
@@ -135,9 +127,9 @@ public class KuaiShouMaterialReportServiceImpl implements IKuaiShouMaterialRepor
                 if (aigcMaterial instanceof Boolean) {
                     detailJson.put("aigc_material", String.valueOf(aigcMaterial));
                 }
-                // 视频行取photo_id、图片行取pic_id,统一映射为material_id;素材类型随view_type入库
-                detailJson.put("material_id", VIEW_TYPE_VIDEO == viewType ? detailJson.get("photo_id") : detailJson.get("pic_id"));
-                detailJson.put("material_type", viewType);
+                // 视频行的photo_id映射为material_id;素材类型固定为视频(5)
+                detailJson.put("material_id", detailJson.get("photo_id"));
+                detailJson.put("material_type", VIEW_TYPE_VIDEO);
                 KuaishouMaterialReportDaily materialReportDaily = JSONObject.toJavaObject(detailJson, KuaishouMaterialReportDaily.class);
                 materialReportDaily.setAdvertiserId(advertiserId);
                 addList.add(materialReportDaily);
@@ -147,9 +139,9 @@ public class KuaiShouMaterialReportServiceImpl implements IKuaiShouMaterialRepor
             materialReportMapper.replaceBatcKuaiShouMaterialReportDaily(addList);
         }
         if (!Check.isNull(details) && details.size() >= 2000) {
-            return queryMaterialReport(accessToken, advertiserId, startDate, endDate, page + 1, viewType, errorId);
+            return queryMaterialReport(accessToken, advertiserId, startDate, endDate, page + 1, errorId);
         }
-        log.info("【{}】录入快手素材日报数据完成,viewType:{}", advertiserId, viewType);
+        log.info("【{}】录入快手素材日报数据完成", advertiserId);
         return true;
     }
 }