|
@@ -0,0 +1,810 @@
|
|
|
|
|
+package com.takai.ai.service.impl;
|
|
|
|
|
+
|
|
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
|
|
+import com.alibaba.fastjson2.JSONArray;
|
|
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
|
|
+import com.takai.ai.domain.TakaiSysOss;
|
|
|
|
|
+import com.takai.ai.domain.entity.*;
|
|
|
|
|
+import com.takai.ai.mapper.*;
|
|
|
|
|
+import com.takai.ai.service.ITakaiAiService;
|
|
|
|
|
+import com.takai.ai.utils.MinioUtil;
|
|
|
|
|
+import com.takai.ai.utils.SnowflakeDigitGenerator;
|
|
|
|
|
+import com.takai.common.annotation.DataSource;
|
|
|
|
|
+import com.takai.common.config.DeepseekConfig;
|
|
|
|
|
+import com.takai.common.enums.DataSourceType;
|
|
|
|
|
+import com.takai.ai.domain.dto.TakaiDialogReqDTO;
|
|
|
|
|
+import com.takai.ai.domain.dto.TakaiDialogRespDTO;
|
|
|
|
|
+import com.takai.ai.domain.dto.TakaiQuestionDTO;
|
|
|
|
|
+import com.takai.common.utils.StringUtils;
|
|
|
|
|
+import com.takai.common.utils.uuid.IdUtils;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import okhttp3.*;
|
|
|
|
|
+import okhttp3.sse.EventSource;
|
|
|
|
|
+import okhttp3.sse.EventSourceListener;
|
|
|
|
|
+import okhttp3.sse.EventSources;
|
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
+import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
|
|
|
|
+
|
|
|
|
|
+import javax.validation.constraints.NotNull;
|
|
|
|
|
+import java.io.File;
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 高井 业务层处理
|
|
|
|
|
+ *
|
|
|
|
|
+ * @author takai
|
|
|
|
|
+ */
|
|
|
|
|
+@Slf4j
|
|
|
|
|
+@Service
|
|
|
|
|
+@DataSource(DataSourceType.MASTER)
|
|
|
|
|
+public class TakaiAiServiceImpl implements ITakaiAiService {
|
|
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(TakaiAiServiceImpl.class);
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private TakaiDialogMapper takaiDialogMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private TakaiApplicationMapper takaiApplicationMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private TakaiQuestionMapper takaiQuestionMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private TakaiKnowledgeMapper takaiKnowledgeMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private TakaiDocumentMapper takaiDocumentMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private TakaiSysOssConfigMapper takaiSysOssConfigMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private TakaiSysOssMapper takaiSysOssMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private MinioUtil minioUtil;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private TakaiDocumentSettingsMapper takaiDocumentSettingsMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private DeepseekConfig deepseekConfig;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private TakaiAppInfoMapper takaiAppInfoMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private TakaiMediaReplacementMapper takaiMediaReplacementMapper;
|
|
|
|
|
+
|
|
|
|
|
+ public static final String START_SIGN = "【";
|
|
|
|
|
+ public static final String END_SIGN = "】";
|
|
|
|
|
+ public static final String SYMBOL = "【示意图序号";
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public SseEmitter sseInvoke(TakaiSseInfoParams sseParams) {
|
|
|
|
|
+ SseEmitter sseEmitter = new SseEmitter(0L);
|
|
|
|
|
+ String url = deepseekConfig.getBaseurl() + deepseekConfig.getChat();
|
|
|
|
|
+ TakaiAppInfo info = takaiAppInfoMapper.selectAppInfoByAppId(sseParams.getAppId());
|
|
|
|
|
+ JSONObject json = JSONObject.parseObject(info.getAppInfo());
|
|
|
|
|
+ json.put("query", "在上海建科集团业务管理平台中,登记和退款流程是什么样的。");
|
|
|
|
|
+ json.put("embeddingId", "multilingual-e5-large-instruct");
|
|
|
|
|
+
|
|
|
|
|
+ RequestBody requestBody = FormBody.create(MediaType.parse("application/json; charset=utf-8"), json.toJSONString());
|
|
|
|
|
+ Request request = buildPostRequest(url, requestBody);
|
|
|
|
|
+ // 使用EventSourceListener处理来自服务器的SSE事件
|
|
|
|
|
+ EventSourceListener listener = new EventSourceListener() {
|
|
|
|
|
+ private String preData = "";
|
|
|
|
|
+ //图片识别
|
|
|
|
|
+ private String symbolData = "";
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onOpen(@NotNull EventSource eventSource, @NotNull Response response) {
|
|
|
|
|
+ log.info("deepseek Connection opened. Headers: {}", response.headers());
|
|
|
|
|
+ log.info("deepseek Request URL: {}", response.request().url());
|
|
|
|
|
+ }
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClosed(@NotNull EventSource eventSource) {
|
|
|
|
|
+ log.info("deepseek Connection closed.");
|
|
|
|
|
+ sseEmitter.complete();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onEvent(@NotNull EventSource eventSource, String id, String type, @NotNull String data) {
|
|
|
|
|
+ if(StringUtils.isEmpty(data)){
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ String newData = data.substring(preData.length());
|
|
|
|
|
+ preData = data;
|
|
|
|
|
+ if (newData.indexOf(START_SIGN) > -1 || symbolData.length() > 0) {
|
|
|
|
|
+ symbolData = symbolData + newData;
|
|
|
|
|
+ //接收到了完整的图片标识
|
|
|
|
|
+ if (newData.indexOf(END_SIGN) > -1) {
|
|
|
|
|
+ //是图片
|
|
|
|
|
+ if (symbolData.indexOf(SYMBOL) > -1) {
|
|
|
|
|
+ String documentId = symbolData.substring(SYMBOL.length() + 1, symbolData.lastIndexOf("_"));
|
|
|
|
|
+ TakaiMediaReplacement mrParams = TakaiMediaReplacement.builder()
|
|
|
|
|
+ .documentId(documentId)
|
|
|
|
|
+ .originText(symbolData)
|
|
|
|
|
+ .mediaType("image").build();
|
|
|
|
|
+ TakaiMediaReplacement mrVo = takaiMediaReplacementMapper.selectTargetMedia(mrParams);
|
|
|
|
|
+ symbolData = mrVo.getMediaUrl();
|
|
|
|
|
+ }
|
|
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
|
|
+ json.put("id", id);
|
|
|
|
|
+ json.put("event", "add");
|
|
|
|
|
+ json.put("data", symbolData);
|
|
|
|
|
+ log.info("deepseek返回信息:" + json);
|
|
|
|
|
+ symbolData = "";
|
|
|
|
|
+ send(sseEmitter, json);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+// if(com.takai.common.utils.StringUtils.isNotEmpty(type) && "finish".equals(type)){
|
|
|
|
|
+// if(com.takai.common.utils.StringUtils.isNotEmpty(data)){
|
|
|
|
|
+// JSONObject json = new JSONObject();
|
|
|
|
|
+// json.put("id", id);
|
|
|
|
|
+// json.put("event", "add");
|
|
|
|
|
+// json.put("data", data);
|
|
|
|
|
+// log.info("deepseek返回切片消息:" + data);
|
|
|
|
|
+// send(sseEmitter, json);
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
|
|
+ json.put("id", id);
|
|
|
|
|
+ json.put("event", type);
|
|
|
|
|
+ json.put("data", newData);
|
|
|
|
|
+ log.info("deepseek返回信息:" + json);
|
|
|
|
|
+ send(sseEmitter, json);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onFailure(@NotNull EventSource eventSource, Throwable t, Response response) {
|
|
|
|
|
+ if (response != null) {
|
|
|
|
|
+ log.error("deepseek Connection failed. Response code: {}, message: {}, body: {}",
|
|
|
|
|
+ response.code(), response.message(), response.body() != null ? response.body().toString() : "null");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.error("deepseek Connection failed with no response", t);
|
|
|
|
|
+ }
|
|
|
|
|
+ sseEmitter.completeWithError(t);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void send(SseEmitter sseEmitter, Object obj) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ sseEmitter.send(obj);
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ log.error("deepseek 推送数据失败", e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ OkHttpClient client = buildOkHttpClient();
|
|
|
|
|
+ EventSource.Factory factory = EventSources.createFactory(client);
|
|
|
|
|
+ factory.newEventSource(request, listener);
|
|
|
|
|
+ return sseEmitter;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<String> asyncCompletions(TakaiCompletionsParams params) {
|
|
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
|
|
+ TakaiApplication vo = takaiApplicationMapper.selectTargetApplication(TakaiApplication.builder().appId(params.getAppId()).build());
|
|
|
|
|
+ TakaiPromptInfo info = new TakaiPromptInfo();
|
|
|
|
|
+ info.setContent(deepseekConfig.getPrompt());
|
|
|
|
|
+ info.setRole("user");
|
|
|
|
|
+ params.getMessages().add(info);
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
|
|
+ jsonObject.put("model", "DeepSeek-R1-Distill-Qwen-14B");
|
|
|
|
|
+ jsonObject.put("messages", params.getMessages());
|
|
|
|
|
+ JSONObject result = getasyncCompletions(jsonObject);
|
|
|
|
|
+ if(result != null && result.getInteger("code") == 200){
|
|
|
|
|
+ JSONArray array = result.getJSONArray("data");
|
|
|
|
|
+ list.addAll(array.toJavaList(String.class));
|
|
|
|
|
+ }
|
|
|
|
|
+ return list;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private JSONObject getasyncCompletions(JSONObject jsonObject){
|
|
|
|
|
+ String url = deepseekConfig.getBaseurl() + deepseekConfig.getAsyncCompletions();
|
|
|
|
|
+ RequestBody requestBody = FormBody.create(MediaType.parse("application/json; charset=utf-8"), jsonObject.toJSONString());
|
|
|
|
|
+ Request request = buildPostRequest(url, requestBody);
|
|
|
|
|
+ OkHttpClient client = buildOkHttpClient();
|
|
|
|
|
+ try {
|
|
|
|
|
+ Response response = client.newCall(request).execute();
|
|
|
|
|
+ if (response.isSuccessful()) {
|
|
|
|
|
+ String body = response.body().string();
|
|
|
|
|
+ if(isJsonObject(body)){
|
|
|
|
|
+ return JSON.parseObject(body);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }catch (IOException e) {
|
|
|
|
|
+ log.info("deepseek Request URL: {}", e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<TakaiDialogRespDTO> getDialogDetail(String dialogId) {
|
|
|
|
|
+ List<TakaiDialogRespDTO> detail = takaiDialogMapper.selectDialogDetail(dialogId);
|
|
|
|
|
+ return detail;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void saveDialog(TakaiDialogReqDTO dialogReqDTO) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<Object> getDialogList(String appId) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void DelDialogDetail(String id) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void updateDialog(TakaiDialogReqDTO dialogReqDTO) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<TakaiDialogRespDTO> exportExcel(String dialogId) {
|
|
|
|
|
+ return takaiDialogMapper.selectDialogExport(dialogId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public int createKnowledge(TakaiKnowledgeParams knowledge) {
|
|
|
|
|
+ SnowflakeDigitGenerator snowflakeDigitGenerator = new SnowflakeDigitGenerator(1, 1);
|
|
|
|
|
+ long knowledgeId = snowflakeDigitGenerator.nextId();
|
|
|
|
|
+
|
|
|
|
|
+ String url = deepseekConfig.getBaseurl() + deepseekConfig.getCreateKnowledge();
|
|
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
|
|
+ jsonObject.put("knowledge_id", "a" + knowledgeId);
|
|
|
|
|
+ jsonObject.put("embedding_id", knowledge.getEmbeddingId());
|
|
|
|
|
+
|
|
|
|
|
+ RequestBody requestBody = FormBody.create(MediaType.parse("application/json; charset=utf-8"), jsonObject.toJSONString());
|
|
|
|
|
+ Request request = buildPostRequest(url, requestBody);
|
|
|
|
|
+ OkHttpClient client = buildOkHttpClient();
|
|
|
|
|
+ try {
|
|
|
|
|
+ Response response = client.newCall(request).execute();
|
|
|
|
|
+ if (response.isSuccessful()) {
|
|
|
|
|
+ String body = response.body().string();
|
|
|
|
|
+ JSONObject obj = JSON.parseObject(body);
|
|
|
|
|
+ Integer code = obj.getInteger("code");
|
|
|
|
|
+ if (code == 200) {
|
|
|
|
|
+ TakaiKnowledge params = TakaiKnowledge.builder()
|
|
|
|
|
+ .knowledgeId("a" + knowledgeId)
|
|
|
|
|
+ .name(knowledge.getName())
|
|
|
|
|
+ .embeddingId(knowledge.getEmbeddingId())
|
|
|
|
|
+ .description(knowledge.getDescription())
|
|
|
|
|
+ .build();
|
|
|
|
|
+ int i = takaiKnowledgeMapper.insertKnowledge(params);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ logger.error("创建知识库调用python接口失败,返回状态码:{}", response.code());
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ logger.error("创建知识库调用python接口失败", e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public int updateKnowledge(TakaiKnowledgeParams knowledge, String knowledgeId) {
|
|
|
|
|
+ TakaiKnowledge params = TakaiKnowledge.builder().knowledgeId(knowledgeId)
|
|
|
|
|
+ .name(knowledge.getName())
|
|
|
|
|
+ .description(knowledge.getDescription())
|
|
|
|
|
+ .embeddingId(knowledge.getEmbeddingId())
|
|
|
|
|
+ .build();
|
|
|
|
|
+ return takaiKnowledgeMapper.updateKnowledge(params);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public TakaiKnowledge detailKnowledge(String knowledgeId) {
|
|
|
|
|
+ TakaiKnowledge vo = TakaiKnowledge.builder().knowledgeId(knowledgeId).build();
|
|
|
|
|
+ return takaiKnowledgeMapper.selectTargetKnowledge(vo);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public int delKnowledge(String knowledgeId) {
|
|
|
|
|
+ String url = deepseekConfig.getBaseurl() + deepseekConfig.getDeleteKnowledge() + "/" + knowledgeId;
|
|
|
|
|
+ Request request = buildDeleteRequest(url);
|
|
|
|
|
+ OkHttpClient client = buildOkHttpClient();
|
|
|
|
|
+ Response response = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ response = client.newCall(request).execute();
|
|
|
|
|
+ if (response.isSuccessful()) {
|
|
|
|
|
+ String body = response.body().string();
|
|
|
|
|
+ JSONObject obj = JSON.parseObject(body);
|
|
|
|
|
+ Integer code = obj.getInteger("code");
|
|
|
|
|
+ if (code == 200) {
|
|
|
|
|
+// TakaiKnowledge info = takaiKnowledgeMapper.selectTargetKnowledge(TakaiKnowledge.builder().knowledgeId(knowledgeId).build());
|
|
|
|
|
+ int i = takaiKnowledgeMapper.delKnowledge(knowledgeId);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ logger.error("删除知识库调用python接口失败", e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public int uploadDocument(MultipartFile files, String knowledgeId) {
|
|
|
|
|
+ TakaiSysOss result = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ result = minioUtil.uploadMultiple(files);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ logger.error("上传文件失败", e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (result != null) {
|
|
|
|
|
+ SnowflakeDigitGenerator documentIdGenerator = new SnowflakeDigitGenerator(1, 1);
|
|
|
|
|
+ long documentId = documentIdGenerator.nextId();
|
|
|
|
|
+
|
|
|
|
|
+ TakaiDocumentSettings settings = new TakaiDocumentSettings();
|
|
|
|
|
+ settings.setDocumentId("a" + documentId);
|
|
|
|
|
+ settings.setKnowledgeId(knowledgeId);
|
|
|
|
|
+ boolean flag = analysisFile(result, settings, "upload");
|
|
|
|
|
+
|
|
|
|
|
+ if (flag) {
|
|
|
|
|
+ // 保存知识信息
|
|
|
|
|
+ TakaiDocument document = TakaiDocument.builder()
|
|
|
|
|
+ .documentId("a" + documentId)
|
|
|
|
|
+ .knowledgeId(knowledgeId)
|
|
|
|
|
+ .customSeparator(String.format("[\"%s\"", "\\n") + "]")
|
|
|
|
|
+ .sentenceSize("300")
|
|
|
|
|
+ .name(result.getOriginalName())
|
|
|
|
|
+ .url(result.getUrl()).build();
|
|
|
|
|
+ int documentIdInsert = takaiDocumentMapper.insertDocument(document);
|
|
|
|
|
+ int ossInsert = 0;
|
|
|
|
|
+ int settingInsert = 0;
|
|
|
|
|
+ if (documentIdInsert > 0) {
|
|
|
|
|
+ // oss保存到数据库
|
|
|
|
|
+ ossInsert = takaiSysOssMapper.insertSysOss(result);
|
|
|
|
|
+ if (ossInsert > 0) {
|
|
|
|
|
+ // 保存知识设置信息
|
|
|
|
|
+ SnowflakeDigitGenerator snowflakeDigitGenerator = new SnowflakeDigitGenerator(1, 1);
|
|
|
|
|
+ long id = snowflakeDigitGenerator.nextId();
|
|
|
|
|
+ TakaiDocumentSettings dSettings = new TakaiDocumentSettings();
|
|
|
|
|
+ dSettings.setId(String.valueOf(id));
|
|
|
|
|
+ dSettings.setKnowledgeId(knowledgeId);
|
|
|
|
|
+ dSettings.setDocumentId("a" + documentId);
|
|
|
|
|
+ dSettings.setSetSlice("0"); // 默认 按标题段落切片
|
|
|
|
|
+ dSettings.setSetAnalyze("1"); // 默认 图片转换成标识符
|
|
|
|
|
+ settingInsert = takaiDocumentSettingsMapper.insertDocumentSettings(dSettings);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (documentIdInsert > 0 && ossInsert > 0 && settingInsert > 0) {
|
|
|
|
|
+ return 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public int updateDocument(TakaiDocumentParams documentParams, String documentId) {
|
|
|
|
|
+ int i = takaiDocumentMapper.updateDocument(TakaiDocument.builder()
|
|
|
|
|
+ .documentId(documentId)
|
|
|
|
|
+ .name(documentParams.getName())
|
|
|
|
|
+ .build());
|
|
|
|
|
+ return i;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<TakaiDocument> documentList(TakaiDocumentParams documentParams) {
|
|
|
|
|
+ return takaiDocumentMapper.selectDocumentList(TakaiDocument.builder().knowledgeId(documentParams.getKnowledge_id()).build());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public TakaiDocument documentDetail(String documentId) {
|
|
|
|
|
+ return takaiDocumentMapper.selectTargetDocument(TakaiDocument.builder().documentId(documentId).build());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public int delDocument(String documentId) {
|
|
|
|
|
+ return takaiDocumentMapper.delDocument(documentId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void uploadUrl(TakaiDocumentObject object) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public int createApplication(TakaiApplicationParams params) {
|
|
|
|
|
+ SnowflakeDigitGenerator snowflakeDigitGenerator = new SnowflakeDigitGenerator(1, 1);
|
|
|
|
|
+ long appId = snowflakeDigitGenerator.nextId();
|
|
|
|
|
+ TakaiApplication info = TakaiApplication.builder().appId(String.valueOf(appId))
|
|
|
|
|
+ .name(params.getName())
|
|
|
|
|
+ .desc(params.getDesc())
|
|
|
|
|
+ .model(params.getModel())
|
|
|
|
|
+ .knowledgeIds(params.getKnowledge_ids().toString())
|
|
|
|
|
+ .topP(params.getTop_p())
|
|
|
|
|
+ .temperature(params.getTemperature())
|
|
|
|
|
+ .maxToken(params.getMax_token())
|
|
|
|
|
+ .prompt(params.getPrompt())
|
|
|
|
|
+ .knowledgeInfo(params.getKnowledge_info())
|
|
|
|
|
+ .sliceCount(params.getSlice_count())
|
|
|
|
|
+ .build();
|
|
|
|
|
+ int i = takaiApplicationMapper.insertApplication(info);
|
|
|
|
|
+ if (i > 0) {
|
|
|
|
|
+ logger.info("create application success, id:{}, name:{}", appId, params.getName());
|
|
|
|
|
+ TakaiAppInfo appInfo = new TakaiAppInfo();
|
|
|
|
|
+ appInfo.setAppId(String.valueOf(appId));
|
|
|
|
|
+ appInfo.setAppInfo(String.valueOf(JSONObject.from(info).toJSONString()));
|
|
|
|
|
+ takaiAppInfoMapper.insertAppInfo(appInfo);
|
|
|
|
|
+
|
|
|
|
|
+ List<String> list = params.getQuestionList();
|
|
|
|
|
+ if (!list.isEmpty() && list.size() > 0) {
|
|
|
|
|
+ for (String str : list) {
|
|
|
|
|
+ if (org.apache.commons.lang3.StringUtils.isNotBlank(str)) {
|
|
|
|
|
+ String uuid = IdUtils.simpleUUID();
|
|
|
|
|
+ TakaiQuestion question = TakaiQuestion.builder().id(uuid).question(str).appId(String.valueOf(appId)).build();
|
|
|
|
|
+ takaiQuestionMapper.insertQuestion(question);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return i;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public int updateApplication(TakaiApplicationParams params, String appId) {
|
|
|
|
|
+ TakaiApplication info = TakaiApplication.builder().appId(appId)
|
|
|
|
|
+ .name(params.getName())
|
|
|
|
|
+ .desc(params.getDesc())
|
|
|
|
|
+ .model(params.getModel())
|
|
|
|
|
+ .knowledgeIds(params.getKnowledge_ids().toString())
|
|
|
|
|
+ .topP(params.getTop_p())
|
|
|
|
|
+ .temperature(params.getTemperature())
|
|
|
|
|
+ .maxToken(params.getMax_token())
|
|
|
|
|
+ .prompt(params.getPrompt())
|
|
|
|
|
+ .knowledgeInfo(params.getKnowledge_info())
|
|
|
|
|
+ .sliceCount(params.getSlice_count())
|
|
|
|
|
+ .build();
|
|
|
|
|
+ int i = takaiApplicationMapper.updateApplication(info);
|
|
|
|
|
+ if (1 > 0) {
|
|
|
|
|
+ TakaiAppInfo appInfo = new TakaiAppInfo();
|
|
|
|
|
+ appInfo.setAppId(appId);
|
|
|
|
|
+ appInfo.setAppInfo(String.valueOf(JSONObject.from(info).toJSONString()));
|
|
|
|
|
+ takaiAppInfoMapper.updateAppInfoByAppId(appInfo);
|
|
|
|
|
+ logger.info("update application success, id:{}, name:{}", appId, params.getName());
|
|
|
|
|
+ //预设问题写入数据库
|
|
|
|
|
+ takaiQuestionMapper.delQuestionByAppId(appId);
|
|
|
|
|
+ List<String> list = params.getQuestionList();
|
|
|
|
|
+ if (!list.isEmpty() && list.size() > 0) {
|
|
|
|
|
+ for (String str : list) {
|
|
|
|
|
+ if (org.apache.commons.lang3.StringUtils.isNotBlank(str)) {
|
|
|
|
|
+ String uuid = IdUtils.simpleUUID();
|
|
|
|
|
+ TakaiQuestion question = TakaiQuestion.builder().id(uuid).question(str).appId(String.valueOf(appId)).build();
|
|
|
|
|
+ takaiQuestionMapper.insertQuestion(question);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return i;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<TakaiApplication> getApplicationList() {
|
|
|
|
|
+ return takaiApplicationMapper.selectApplicationList(null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public JSONObject selectApplication(String appId) {
|
|
|
|
|
+ JSONObject object = new JSONObject();
|
|
|
|
|
+ TakaiApplication application = TakaiApplication.builder().appId(appId).build();
|
|
|
|
|
+ TakaiApplication takaiApplication = takaiApplicationMapper.selectTargetApplication(application);
|
|
|
|
|
+ List<TakaiQuestionDTO> list = takaiQuestionMapper.getQuestionList(appId);
|
|
|
|
|
+ object.put("detail", takaiApplication);
|
|
|
|
|
+ object.put("questionlist", list);
|
|
|
|
|
+ return object;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public int delApplication(String appId) {
|
|
|
|
|
+ int i = takaiApplicationMapper.delApplication(appId);
|
|
|
|
|
+ if (i > 0) {
|
|
|
|
|
+ takaiAppInfoMapper.delAppInfoByAppId(appId);
|
|
|
|
|
+ takaiQuestionMapper.delQuestionByAppId(appId);
|
|
|
|
|
+ }
|
|
|
|
|
+ return i;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<TakaiQuestionDTO> selectQuestionByAppId(String appId) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<TakaiKnowledge> queryKnowledgeList() {
|
|
|
|
|
+ return takaiKnowledgeMapper.selectKnowledgeList(null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<Object> selectDialogListByAppId(String appId, String userId) {
|
|
|
|
|
+ List<TakaiDialogRespDTO> list = takaiDialogMapper.selectDialog(appId, userId);
|
|
|
|
|
+ List<Object> result = setDialogList(list);
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public TakaiDocumentSettings documentSetting(String documentId) {
|
|
|
|
|
+ return takaiDocumentSettingsMapper.selectById(documentId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public int updateDocumentSetting(TakaiDocumentSettings documentSettings, String documentId) {
|
|
|
|
|
+ if (StringUtils.isNotEmpty(documentSettings.getSetSlice()) && !"3".equals(documentSettings.getSetSlice())) {
|
|
|
|
|
+ documentSettings.setDocumentId(documentId);
|
|
|
|
|
+ int i = takaiDocumentSettingsMapper.updateDocumentSettings(documentSettings);
|
|
|
|
|
+ return i;
|
|
|
|
|
+ }
|
|
|
|
|
+ TakaiSysOss ossVo = new TakaiSysOss();
|
|
|
|
|
+ TakaiDocumentSettings settings = new TakaiDocumentSettings();
|
|
|
|
|
+ TakaiDocumentSettings settingsVo = takaiDocumentSettingsMapper.selectById(documentId);
|
|
|
|
|
+ settings.setDocumentId(documentId);
|
|
|
|
|
+ settings.setKnowledgeId(settingsVo.getKnowledgeId());
|
|
|
|
|
+ settings.setSetSlice(documentSettings.getSetSlice());
|
|
|
|
|
+ settings.setSliceValue(documentSettings.getSliceValue());
|
|
|
|
|
+ settings.setSetAnalyze(documentSettings.getSetAnalyze());
|
|
|
|
|
+ TakaiDocument document = takaiDocumentMapper.selectTargetDocument(TakaiDocument.builder().documentId(documentId).build());
|
|
|
|
|
+ ossVo.setUrl(document.getUrl());
|
|
|
|
|
+ ossVo.setOriginalName(document.getName());
|
|
|
|
|
+ boolean status = analysisFile(ossVo, settings, "update");
|
|
|
|
|
+ if (status) {
|
|
|
|
|
+ logger.info("update document setting success, id:{}", documentId);
|
|
|
|
|
+ documentSettings.setDocumentId(documentId);
|
|
|
|
|
+ int i = takaiDocumentSettingsMapper.updateDocumentSettings(documentSettings);
|
|
|
|
|
+ return i;
|
|
|
|
|
+ }
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public JSONObject getSliceList(TakaiSliceParams params) {
|
|
|
|
|
+ String url = deepseekConfig.getBaseurl() + deepseekConfig.getSlicePage();
|
|
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
|
|
+ jsonObject.put("document_id", "f62059be-a119-47ee-b07e-20970257e033");
|
|
|
|
|
+ jsonObject.put("knowledge_id", "milvus_hybrid");
|
|
|
|
|
+ jsonObject.put("text", params.getText());
|
|
|
|
|
+ jsonObject.put("pageNum", params.getPageNum());
|
|
|
|
|
+ jsonObject.put("pageSize", params.getPageSize());
|
|
|
|
|
+
|
|
|
|
|
+ RequestBody requestBody = FormBody.create(MediaType.parse("application/json; charset=utf-8"), jsonObject.toJSONString());
|
|
|
|
|
+ Request request = buildPostRequest(url, requestBody);
|
|
|
|
|
+
|
|
|
|
|
+ OkHttpClient client = buildOkHttpClient();
|
|
|
|
|
+ Response response = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ response = client.newCall(request).execute();
|
|
|
|
|
+ if (response.isSuccessful()) {
|
|
|
|
|
+ String body = response.body().string();
|
|
|
|
|
+ JSONObject obj = JSON.parseObject(body);
|
|
|
|
|
+ Integer code = obj.getInteger("code");
|
|
|
|
|
+ if (code == 200) {
|
|
|
|
|
+ return obj;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ logger.info("获取切片列表调用python接口失败,返回状态码:{}", response.code());
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ logger.error("获取切片列表调用python接口失败", e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public int deleteSlice(String sliceId, String knowledgeId) {
|
|
|
|
|
+ TakaiKnowledge knowledge = takaiKnowledgeMapper.selectTargetKnowledge(TakaiKnowledge.builder().knowledgeId(knowledgeId).build());
|
|
|
|
|
+
|
|
|
|
|
+ String url = deepseekConfig.getBaseurl() + deepseekConfig.getDeleteSlice() + "/" + sliceId + "/milvus_hybrid";
|
|
|
|
|
+ Request request = buildDeleteRequest(url);
|
|
|
|
|
+ OkHttpClient client = buildOkHttpClient();
|
|
|
|
|
+ Response response = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ response = client.newCall(request).execute();
|
|
|
|
|
+ if (response.isSuccessful()) {
|
|
|
|
|
+ String body = response.body().string();
|
|
|
|
|
+ JSONObject obj = JSON.parseObject(body);
|
|
|
|
|
+ Integer code = obj.getInteger("code");
|
|
|
|
|
+ if (code == 200) {
|
|
|
|
|
+ return 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ logger.error("删除切片调用python接口失败", e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public JSONObject getSliceDetail(String sliceId, String knowledgeId) {
|
|
|
|
|
+ String url = deepseekConfig.getBaseurl() + deepseekConfig.getSliceDetail() + "/milvus_hybrid" + "/" + sliceId;
|
|
|
|
|
+ Request request = buildGetRequest(url);
|
|
|
|
|
+
|
|
|
|
|
+ OkHttpClient client = buildOkHttpClient();
|
|
|
|
|
+ try {
|
|
|
|
|
+ Response response = client.newCall(request).execute();
|
|
|
|
|
+ if (response.isSuccessful()) {
|
|
|
|
|
+ String body = response.body().string();
|
|
|
|
|
+ log.info("查询切片详情返回:" + body);
|
|
|
|
|
+ return JSON.parseObject(body);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ logger.info("获取切片详情调用python接口失败,返回状态码:{}", response.code());
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ log.error("查询切片详情调用python接口失败", e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public int updateSliceInfo(TakaiSliceUpdateParams params) {
|
|
|
|
|
+ String url = deepseekConfig.getBaseurl() + deepseekConfig.getUpdateSlice();
|
|
|
|
|
+ JSONObject object = new JSONObject();
|
|
|
|
|
+ object.put("knowledge_id", "milvus_hybrid");
|
|
|
|
|
+ object.put("slice_id", params.getSliceId());
|
|
|
|
|
+ object.put("slice_text", params.getSliceText());
|
|
|
|
|
+ RequestBody requestBody = FormBody.create(MediaType.parse("application/json; charset=utf-8"), object.toJSONString());
|
|
|
|
|
+
|
|
|
|
|
+ Request request = buildPutRequest(url, requestBody);
|
|
|
|
|
+ OkHttpClient client = buildOkHttpClient();
|
|
|
|
|
+ try {
|
|
|
|
|
+ Response response = client.newCall(request).execute();
|
|
|
|
|
+ if (response.isSuccessful()) {
|
|
|
|
|
+ String body = response.body().string();
|
|
|
|
|
+ JSONObject obj = JSON.parseObject(body);
|
|
|
|
|
+ Integer code = obj.getInteger("code");
|
|
|
|
|
+ if (code == 200) {
|
|
|
|
|
+ return 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ logger.error("更新切片信息调用python接口失败", e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private boolean analysisFile(TakaiSysOss result, TakaiDocumentSettings settings, String flag) {
|
|
|
|
|
+ TakaiKnowledge knowledge = takaiKnowledgeMapper.selectTargetKnowledge(TakaiKnowledge.builder().knowledgeId(settings.getKnowledgeId()).build());
|
|
|
|
|
+ String url = deepseekConfig.getBaseurl() + deepseekConfig.getUploadKnowledge();
|
|
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
|
|
+ json.put("knowledge_id", settings.getKnowledgeId());
|
|
|
|
|
+ json.put("document_id", settings.getDocumentId());
|
|
|
|
|
+ json.put("embedding_id", knowledge == null ? "" : knowledge.getEmbeddingId());
|
|
|
|
|
+ json.put("name", result.getOriginalName());
|
|
|
|
|
+ json.put("url", result.getUrl());
|
|
|
|
|
+ if ("upload".equals(flag)) {
|
|
|
|
|
+ json.put("set_slice", "0");
|
|
|
|
|
+ json.put("slice_value", null);
|
|
|
|
|
+ json.put("set_analyze", "1");
|
|
|
|
|
+ json.put("flag", "upload");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ json.put("set_slice", settings.getSetSlice());
|
|
|
|
|
+ json.put("slice_value", settings.getSliceValue());
|
|
|
|
|
+ json.put("set_analyze", settings.getSetAnalyze());
|
|
|
|
|
+ json.put("flag", "update");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), json.toJSONString());
|
|
|
|
|
+ Request request = buildPostRequest(url, requestBody);
|
|
|
|
|
+ OkHttpClient client = buildOkHttpClient();
|
|
|
|
|
+ Response response = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ response = client.newCall(request).execute();
|
|
|
|
|
+ if (response.isSuccessful()) {
|
|
|
|
|
+ String body = response.body().string();
|
|
|
|
|
+ JSONObject obj = JSON.parseObject(body);
|
|
|
|
|
+ Integer code = obj.getInteger("code");
|
|
|
|
|
+ if (code == 200) {
|
|
|
|
|
+ logger.info("上传文档调用python接口成功,返回内容:{}", body);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ logger.error("上传文档调用python接口失败返回code:{}", response.code());
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ logger.error("上传文档调用python接口失败", e.getMessage());
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<Object> setDialogList(List<TakaiDialogRespDTO> list) {
|
|
|
|
|
+ //根据时间分组降序排序
|
|
|
|
|
+ NavigableMap<LocalDateTime, List<TakaiDialogRespDTO>> groupList = list.stream().collect(Collectors.groupingBy(TakaiDialogRespDTO::getCreate_time, TreeMap::new, Collectors.toList())).descendingMap();
|
|
|
|
|
+ List<Object> obj = new ArrayList();
|
|
|
|
|
+ if(!groupList.isEmpty()){
|
|
|
|
|
+ for(Map.Entry<LocalDateTime, List<TakaiDialogRespDTO>> entry: groupList.entrySet()){
|
|
|
|
|
+ List<TakaiDialogRespDTO> aList = entry.getValue();
|
|
|
|
|
+ List<TakaiDialogRespDTO> detailList = takaiDialogMapper.selectDialogExport(aList.get(0).getId());
|
|
|
|
|
+ Map<String, Object> map = new HashMap();
|
|
|
|
|
+ map.put("dialog_name", aList.get(0).getDialog_name());
|
|
|
|
|
+ map.put("length", detailList.size());
|
|
|
|
|
+ map.put("create_time", aList.get(0).getCreate_time());
|
|
|
|
|
+ map.put("did", aList.get(0).getDid());
|
|
|
|
|
+ map.put("id", aList.get(0).getId());
|
|
|
|
|
+ obj.add(map);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return obj;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String getMimeType(File file) {
|
|
|
|
|
+ if (!file.exists()) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String fileName = file.getName().toLowerCase();
|
|
|
|
|
+ if (fileName.endsWith(".pdf")) {
|
|
|
|
|
+ return "application/json";
|
|
|
|
|
+ } else if (fileName.endsWith(".doc") || fileName.endsWith(".docx")) {
|
|
|
|
|
+ return "application/msword";
|
|
|
|
|
+ } else if (fileName.endsWith(".txt")) {
|
|
|
|
|
+ return "text/plain";
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private OkHttpClient buildOkHttpClient() {
|
|
|
|
|
+ return new OkHttpClient.Builder()
|
|
|
|
|
+ .connectTimeout(10, TimeUnit.SECONDS)
|
|
|
|
|
+ .writeTimeout(50, TimeUnit.SECONDS)
|
|
|
|
|
+ .readTimeout(10, TimeUnit.MINUTES)
|
|
|
|
|
+ .build();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Request buildGetRequest(String url) {
|
|
|
|
|
+ return new Request.Builder()
|
|
|
|
|
+ .addHeader("User-Agent", "insomnia/10.3.1")
|
|
|
|
|
+ .url(url).get().build();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Request buildPostRequest(String url, RequestBody requestBody) {
|
|
|
|
|
+ return new Request.Builder()
|
|
|
|
|
+ .addHeader("User-Agent", "insomnia/10.3.1")
|
|
|
|
|
+ .addHeader("Content-Type", "application/json")
|
|
|
|
|
+ .url(url).post(requestBody).build();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Request buildPutRequest(String url, RequestBody requestBody) {
|
|
|
|
|
+ return new Request.Builder()
|
|
|
|
|
+ .addHeader("User-Agent", "insomnia/10.3.1")
|
|
|
|
|
+ .url(url).put(requestBody).build();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Request buildDeleteRequest(String url) {
|
|
|
|
|
+ return new Request.Builder()
|
|
|
|
|
+ .addHeader("Content-Type", "multipart/form-data")
|
|
|
|
|
+ .addHeader("User-Agent", "insomnia/10.3.1")
|
|
|
|
|
+ .url(url).delete().build();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Request buildUploadPostRequest(String url, RequestBody requestBody) {
|
|
|
|
|
+ return new Request.Builder()
|
|
|
|
|
+ .addHeader("User-Agent", "insomnia/10.3.1")
|
|
|
|
|
+ .addHeader("Content-Type", "application/json")
|
|
|
|
|
+ .url(url).post(requestBody).build();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private boolean isJsonObject(String data){
|
|
|
|
|
+ try {
|
|
|
|
|
+ JSON.parseObject(data);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|