Эх сурвалжийг харах

feat: 数据汇总模块开发

周玉环 1 өдөр өмнө
parent
commit
3b3d805e2f

+ 3 - 0
xinkeaboard-server/b2b2c-investment/src/main/java/com/slodon/b2b2c/investment/constant/InvestmentConst.java

@@ -81,6 +81,9 @@ public class InvestmentConst {
     public static final String UPDATE_BY_FILE = "/update-by-file";
     public static final String FILE = "file";
     public static final String DATA = "data";
+    public static final String PAGE = "page";
+    public static final String TOTAL = "total";
+
 
     public static final String DELETE_SUCCESS = "204\n";
 }

+ 13 - 17
xinkeaboard-server/b2b2c-investment/src/main/java/com/slodon/b2b2c/investment/model/DifyModel.java

@@ -8,10 +8,8 @@ import com.slodon.b2b2c.investment.config.DifyConfig;
 import com.slodon.b2b2c.investment.constant.InvestmentConst;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Component;
-import org.springframework.util.CollectionUtils;
 import org.springframework.util.StringUtils;
 import org.springframework.web.util.UriComponentsBuilder;
-
 import javax.annotation.Resource;
 import java.io.File;
 import java.util.ArrayList;
@@ -19,8 +17,6 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import static org.jacoco.agent.rt.internal_1f1cc91.core.runtime.AgentOptions.OutputMode.file;
-
 /**
  * @author sunshihao
  * @version 1.0
@@ -224,17 +220,17 @@ public class DifyModel {
         if (list == null) {
             list = new ArrayList<>();
         }
-        int currentPage = (page == null || page <= 0) ? 1 : page;
-        int limit = 100;
+        int currentPage = (page == null || page <= InvestmentConst.NUM_ZERO) ? InvestmentConst.NUM_ONE : page;
+        int limit = InvestmentConst.NUM_ONE_HUNDRED;
         HashMap<String, String> header = getCredential();
         String baseUrl = difyConfig.getDifyRoute();
         while (true) {
             UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseUrl)
-                    .queryParam("page", currentPage)
-                    .queryParam("limit", limit);
+                    .queryParam(InvestmentConst.PAGE, currentPage)
+                    .queryParam(InvestmentConst.LIMIT, limit);
 
             if (!StringUtils.isEmpty(keyword)) {
-                builder.queryParam("keyword", keyword);
+                builder.queryParam(InvestmentConst.KEYWORD, keyword);
             }
             if (tagIds != null && tagIds.length > 0) {
                 String tagIdsStr = String.join(",", tagIds);
@@ -246,18 +242,18 @@ public class DifyModel {
                 throw new Exception("HTTP请求返回空响应");
             }
             JSONObject postObject = JSONUtil.parseObj(response);
-            JSONArray dataArray = postObject.getByPath("data", JSONArray.class);
+            JSONArray dataArray = postObject.getByPath(InvestmentConst.DATA, JSONArray.class);
             if (dataArray == null) {
                 throw new Exception("查询知识库失败:data字段为空");
             }
             for (Object o : dataArray) {
                 JSONObject obj = (JSONObject) o;
-                String id = obj.getByPath("id", String.class);
+                String id = obj.getByPath(InvestmentConst.ID, String.class);
                 if (id != null) {
                     list.add(id);
                 }
             }
-            Integer total = postObject.getByPath("total", Integer.class);
+            Integer total = postObject.getByPath(InvestmentConst.TOTAL, Integer.class);
             if (total == null) {
                 throw new Exception("响应中缺少 total 字段");
             }
@@ -281,10 +277,10 @@ public class DifyModel {
         HashMap<String, String> header = getCredential();
         String baseUrl = difyConfig.getDifyRoute()+datasetId+"/documents";
         UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseUrl)
-                .queryParam("page", 1)
-                .queryParam("limit", 100);
+                .queryParam(InvestmentConst.PAGE, InvestmentConst.NUM_ONE)
+                .queryParam(InvestmentConst.LIMIT, InvestmentConst.NUM_ONE_HUNDRED);
         if (!StringUtils.isEmpty(name)) {
-            builder.queryParam("keyword", name);
+            builder.queryParam(InvestmentConst.KEYWORD, name);
         }
         String url = builder.toUriString();
         String response = HttpClientUtil.httpGet(url, header);
@@ -292,13 +288,13 @@ public class DifyModel {
             throw new Exception("HTTP请求返回空响应");
         }
         JSONObject postObject = JSONUtil.parseObj(response);
-        JSONArray dataArray = postObject.getByPath("data", JSONArray.class);
+        JSONArray dataArray = postObject.getByPath(InvestmentConst.DATA, JSONArray.class);
         if (dataArray == null) {
             throw new Exception("查询文章失败:data字段为空");
         }
         for (Object o : dataArray) {
             JSONObject obj = (JSONObject) o;
-            return obj.getByPath("id", String.class);
+            return obj.getByPath(InvestmentConst.ID, String.class);
         }
         return null;
     }