Просмотр исходного кода

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

wangfan 5 месяцев назад
Родитель
Сommit
72478c5d72

+ 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(int keywordType, int limit);
+    List<SeoKeywords> getKeywordsToSerp(List<String> sideCodesm, int keywordType, int limit);
 
 }

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

@@ -167,22 +167,16 @@
         FROM
         seo_keywords
         WHERE
-        `status` = 1
+        status = 1
         AND
-        'search_status' != 1
-        AND site_code IN (
-        SELECT
-        `code`
-        FROM
-        adweb_site
-        WHERE
-        run_status = 1
-        AND `status` = 1
-        )
+        search_status != 1
+        AND site_code IN
+        <foreach collection="sideCodes" item="sideCode" open="(" separator="," close=")">
+            #{sideCode}
+        </foreach>
         <if test = "keywordType != null">
             AND keyword_type = #{keywordType}
         </if>
-        AND last_search_time <![CDATA[ <]]> CURDATE()
         LIMIT #{limit}
     </select>
 </mapper>

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

@@ -27,6 +27,8 @@ import org.jeecg.modules.adweb.seo.entity.SeoKeywordsSerp;
 import org.jeecg.modules.adweb.seo.mapper.SeoKeywordsMapper;
 import org.jeecg.modules.adweb.seo.service.ISeoKeywordsSerpService;
 import org.jeecg.modules.adweb.seo.service.ISeoKeywordsService;
+import org.jeecg.modules.adweb.site.entity.AdwebSite;
+import org.jeecg.modules.adweb.site.service.IAdwebSiteService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
@@ -61,6 +63,8 @@ public class DataForSEOService {
     @Value("${dataforseo.api-path}")
     private String apiPath;
 
+    @Autowired private IAdwebSiteService adwebSiteService;
+
     @Autowired private SeoKeywordsMapper seoKeywordsMapper;
 
     @Autowired private ISeoKeywordsService seoKeywordsService;
@@ -92,8 +96,21 @@ public class DataForSEOService {
      * @param keywordType 1 - 指定词; 2 - 长尾词
      * @param limit 最大查询条数
      */
-    public void runKeywordsSerpTasks(int keywordType, int limit) {
-        List<SeoKeywords> seoKeywords = seoKeywordsMapper.getKeywordsToSerp(keywordType, limit);
+    public void runKeywordsSerpTasks(List<String> siteCodes, int keywordType, int limit) {
+        if (ListUtil.isEmpty(siteCodes)) {
+            siteCodes =
+                    adwebSiteService
+                            .list(
+                                    new LambdaQueryWrapper<AdwebSite>()
+                                            .eq(AdwebSite::getStatus, 1)
+                                            .eq(AdwebSite::getRunStatus, 1))
+                            .stream()
+                            .map(AdwebSite::getCode)
+                            .toList();
+        }
+
+        List<SeoKeywords> seoKeywords =
+                seoKeywordsMapper.getKeywordsToSerp(siteCodes, keywordType, limit);
 
         if (ListUtil.isEmpty(seoKeywords)) {
             log.info("暂无需要Serp查询的关键词");

+ 27 - 7
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/xxl/DataForSEOJob.java

@@ -1,5 +1,6 @@
 package org.jeecg.modules.xxl;
 
+import com.xxl.job.core.biz.model.ReturnT;
 import com.xxl.job.core.handler.annotation.XxlJob;
 
 import lombok.extern.slf4j.Slf4j;
@@ -9,6 +10,11 @@ import org.jeecg.modules.adweb.seo.service.dataforseo.DataForSEOService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+
 /**
  * DataForSEO Serp查询及同步任务,{@link DataForSEOService}
  *
@@ -21,25 +27,39 @@ public class DataForSEOJob {
     @Autowired private DataForSEOService dataForSEOService;
 
     @XxlJob("runLongTailKeywordsSerpTasksHandler")
-    public void runLongTailKeywordsSerpTasksHandler() {
-        log.info("执行长尾词Serp查询...");
+    public ReturnT<String> runLongTailKeywordsSerpTasksHandler(String param) {
+        log.info("执行长尾词Serp查询..., param = {}", param);
         dataForSEOService.runKeywordsSerpTasks(
-                AdwebConstant.KEYWORD_TYPE_LONG_TAIL, Integer.MAX_VALUE);
+                this.parseSiteCodes(param),
+                AdwebConstant.KEYWORD_TYPE_LONG_TAIL,
+                Integer.MAX_VALUE);
         log.info("执行长尾词Serp查询结束");
+
+        return ReturnT.SUCCESS;
     }
 
     @XxlJob("runAppointKeywordsSerpTasksHandler")
-    public void runAppointKeywordsSerpTasksHandler() {
-        log.info("执行指定词Serp查询...");
+    public ReturnT<String> runAppointKeywordsSerpTasksHandler(String param) {
+        log.info("执行指定词Serp查询..., param = {}", param);
         dataForSEOService.runKeywordsSerpTasks(
-                AdwebConstant.KEYWORD_TYPE_APPOINT, Integer.MAX_VALUE);
+                this.parseSiteCodes(param), AdwebConstant.KEYWORD_TYPE_APPOINT, Integer.MAX_VALUE);
         log.info("执行指定词Serp查询结束");
+
+        return ReturnT.SUCCESS;
     }
 
     @XxlJob("syncKeywordsSerpResultsHandler")
-    public void syncKeywordsSerpResultsHandler() {
+    public ReturnT<String> syncKeywordsSerpResultsHandler(String param) {
         log.info("同步关键词Serp查询结果...");
         dataForSEOService.syncKeywordsSerpResults();
         log.info("同步关键词Serp查询结果结束");
+
+        return ReturnT.SUCCESS;
+    }
+
+    private List<String> parseSiteCodes(String param) {
+        return Objects.nonNull(param)
+                ? Arrays.stream(param.split(",")).map(siteCode -> siteCode.trim()).toList()
+                : Collections.EMPTY_LIST;
     }
 }

+ 4 - 1
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/xxl/GAReportJob.java

@@ -1,5 +1,6 @@
 package org.jeecg.modules.xxl;
 
+import com.xxl.job.core.biz.model.ReturnT;
 import com.xxl.job.core.handler.annotation.XxlJob;
 
 import lombok.extern.slf4j.Slf4j;
@@ -20,9 +21,11 @@ public class GAReportJob {
     @Autowired private GAReportService gaReportService;
 
     @XxlJob("syncGAReportHandler")
-    public void syncGAReportHandler() {
+    public ReturnT<String> syncGAReportHandler(String param) {
         log.info("同步GA报表数据...");
         gaReportService.syncGAReport();
         log.info("同步GA报表数据结束");
+
+        return ReturnT.SUCCESS;
     }
 }

+ 4 - 1
jeecg-module-system/jeecg-system-start/src/test/java/org/jeecg/modules/adweb/seo/service/DataForSEOTest.java

@@ -8,6 +8,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.ActiveProfiles;
 
+import java.util.Collections;
+
 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
 @ActiveProfiles("dev")
 public class DataForSEOTest {
@@ -17,7 +19,8 @@ public class DataForSEOTest {
     @Test
     @Disabled
     public void testRunKeywordsSerpTasks() {
-        dataForSEOService.runKeywordsSerpTasks(AdwebConstant.KEYWORD_TYPE_APPOINT, 10);
+        dataForSEOService.runKeywordsSerpTasks(
+                Collections.EMPTY_LIST, AdwebConstant.KEYWORD_TYPE_APPOINT, 10);
     }
 
     @Test