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