Browse Source

Merge branch 'serp' of wangfan/adweb3-server into master

wangfan 5 months ago
parent
commit
48a5161d94

+ 1 - 1
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/seo/mapper/SeoKeywordsMapper.java

@@ -64,6 +64,6 @@ public interface SeoKeywordsMapper extends BaseMapper<SeoKeywords> {
      *
      * @return 关键词列表
      */
-    List<SeoKeywords> getKeywordsToSerp(List<String> sideCodesm, int keywordType, int limit);
+    List<SeoKeywords> getKeywordsToSerp(List<String> sideCodes, int keywordType, int limit);
 
 }

+ 1 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/seo/mapper/xml/SeoKeywordsMapper.xml

@@ -177,6 +177,7 @@
         <if test = "keywordType != null">
             AND keyword_type = #{keywordType}
         </if>
+        AND last_search_time <![CDATA[ <]]> CURDATE()
         LIMIT #{limit}
     </select>
 </mapper>

+ 10 - 3
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/seo/service/dataforseo/DataForSEOService.java

@@ -50,6 +50,8 @@ public class DataForSEOService {
     private static final int MAX_TASKS_PER_SERP_REQUEST = 100;
     private static final int SERP_STATUS_CODE_SUCCESS = 20000;
     private static final int SERP_STATUS_CODE_TASK_CREATED = 20100;
+    private static final int SERP_STATUS_CODE_TASK_HANDED = 40601;
+    private static final int SERP_STATUS_CODE_TASK_IN_QUEUE = 40602;
 
     // Google一页显示搜索结果数量
     private static final int GOOGLE_SEARCH_PAGE_SIZE = 10;
@@ -223,11 +225,16 @@ public class DataForSEOService {
                     serpApi.googleOrganicTaskGetRegular(taskId).getTasks().get(0);
             log.info("获取DataForSEO Serp任务,response = {}", JSONUtil.toJsonStr(serpTask));
             if (serpTask.getStatusCode() != SERP_STATUS_CODE_SUCCESS) {
-                log.warn(
+                log.info(
                         "DataForSEO Serp任务 {} 状态为 {} {}",
                         taskId,
                         serpTask.getStatusCode(),
                         serpTask.getStatusMessage());
+                // Serp task正在处理中...
+                if (Arrays.asList(SERP_STATUS_CODE_TASK_HANDED, SERP_STATUS_CODE_TASK_IN_QUEUE)
+                        .contains(serpTask.getStatusCode())) {
+                    return true;
+                }
                 throw new ApiException(serpTask.getStatusMessage());
             }
             SerpGoogleOrganicTaskGetRegularResultInfo serpResult = serpTask.getResult().get(0);
@@ -246,8 +253,8 @@ public class DataForSEOService {
                     CommonUtil.getTopPrivateDomain(seoKeyword.getDomain()); // 顶级域名
             OrganicSerpElementItem serpItem =
                     serpResult.getItems().stream()
-                            .map(item -> (OrganicSerpElementItem) item)
-                            .filter(item -> item.getType().equalsIgnoreCase("organic"))
+                            .filter(OrganicSerpElementItem.class::isInstance)
+                            .map(OrganicSerpElementItem.class::cast)
                             .filter(item -> item.getDomain().contains(topPrivateDomain)) // 根据域名匹配
                             .findAny()
                             .orElse(null);