|
@@ -6,11 +6,13 @@ import cn.cslg.pas.common.model.dify.*;
|
|
import cn.cslg.pas.common.model.dify.GenerateClaimDTO;
|
|
import cn.cslg.pas.common.model.dify.GenerateClaimDTO;
|
|
import cn.cslg.pas.common.model.dify.confessionSession.AddConfessionSessionDTO;
|
|
import cn.cslg.pas.common.model.dify.confessionSession.AddConfessionSessionDTO;
|
|
import cn.cslg.pas.common.model.dify.confessionSession.UpdateConfessionSessionDTO;
|
|
import cn.cslg.pas.common.model.dify.confessionSession.UpdateConfessionSessionDTO;
|
|
|
|
+import cn.cslg.pas.common.model.dify.generateDiscoveryResult.DiscoryResultVO;
|
|
import cn.cslg.pas.common.utils.*;
|
|
import cn.cslg.pas.common.utils.*;
|
|
import cn.cslg.pas.common.utils.ClaimUtils.ClaimSplitUtils;
|
|
import cn.cslg.pas.common.utils.ClaimUtils.ClaimSplitUtils;
|
|
import cn.cslg.pas.common.vo.PatentRightParams;
|
|
import cn.cslg.pas.common.vo.PatentRightParams;
|
|
import cn.cslg.pas.domain.business.ReportTemple;
|
|
import cn.cslg.pas.domain.business.ReportTemple;
|
|
import cn.cslg.pas.domain.business.TechnicalCase;
|
|
import cn.cslg.pas.domain.business.TechnicalCase;
|
|
|
|
+import cn.cslg.pas.domain.dify.AssoConfessionConversation;
|
|
import cn.cslg.pas.domain.dify.AssoConfessionSessionFile;
|
|
import cn.cslg.pas.domain.dify.AssoConfessionSessionFile;
|
|
import cn.cslg.pas.domain.dify.ConfessionSession;
|
|
import cn.cslg.pas.domain.dify.ConfessionSession;
|
|
import cn.cslg.pas.domain.report.AssoProjectConfession;
|
|
import cn.cslg.pas.domain.report.AssoProjectConfession;
|
|
@@ -19,9 +21,7 @@ import cn.cslg.pas.exception.XiaoShiException;
|
|
import cn.cslg.pas.mapper.dify.ConfessionSessionMapper;
|
|
import cn.cslg.pas.mapper.dify.ConfessionSessionMapper;
|
|
import cn.cslg.pas.service.business.ReportTempleService;
|
|
import cn.cslg.pas.service.business.ReportTempleService;
|
|
import cn.cslg.pas.service.business.TechnicalCaseService;
|
|
import cn.cslg.pas.service.business.TechnicalCaseService;
|
|
-import cn.cslg.pas.service.dify.ConfessionSessionService;
|
|
|
|
-import cn.cslg.pas.service.dify.DifySessionService;
|
|
|
|
-import cn.cslg.pas.service.dify.GenerateInstructionService;
|
|
|
|
|
|
+import cn.cslg.pas.service.dify.*;
|
|
import cn.cslg.pas.service.report.AssoProjectConfessionService;
|
|
import cn.cslg.pas.service.report.AssoProjectConfessionService;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
@@ -81,6 +81,8 @@ public class DifyService {
|
|
private String fileDownloadUrl;
|
|
private String fileDownloadUrl;
|
|
@Value("${DIFY.cliamKey}")
|
|
@Value("${DIFY.cliamKey}")
|
|
private String cliamKey;
|
|
private String cliamKey;
|
|
|
|
+ @Value("${DIFY.discoveryResultKey}")
|
|
|
|
+ private String discoveryResultKey;
|
|
private final DifySessionService difySessionService;
|
|
private final DifySessionService difySessionService;
|
|
private final TechnicalCaseService technicalCaseService;
|
|
private final TechnicalCaseService technicalCaseService;
|
|
private final AssoProjectConfessionService assoProjectConfessionService;
|
|
private final AssoProjectConfessionService assoProjectConfessionService;
|
|
@@ -100,11 +102,15 @@ public class DifyService {
|
|
@Autowired
|
|
@Autowired
|
|
@Lazy
|
|
@Lazy
|
|
private GenerateInstructionService generateInstructionService;
|
|
private GenerateInstructionService generateInstructionService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private AssoConfessionConversationService assoConfessionConversationService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private AssoConfessionSessionFileService assoConfessionSessionFileService;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 调用文件系统删除文件接口
|
|
* 调用文件系统删除文件接口
|
|
*/
|
|
*/
|
|
- public String chatMessage(DifyChatMessageDTO difyChatMessageDTO,String key) throws IOException {
|
|
|
|
|
|
+ public String chatMessage(DifyChatMessageDTO difyChatMessageDTO, String key) throws IOException {
|
|
String param = new Gson().toJson(difyChatMessageDTO);
|
|
String param = new Gson().toJson(difyChatMessageDTO);
|
|
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
|
|
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
|
|
OkHttpClient okHttpClient = new OkHttpClient.Builder()
|
|
OkHttpClient okHttpClient = new OkHttpClient.Builder()
|
|
@@ -131,14 +137,19 @@ public class DifyService {
|
|
.writeTimeout(600, TimeUnit.SECONDS)
|
|
.writeTimeout(600, TimeUnit.SECONDS)
|
|
.readTimeout(600, TimeUnit.SECONDS)
|
|
.readTimeout(600, TimeUnit.SECONDS)
|
|
.build();
|
|
.build();
|
|
|
|
+ Integer type =difyChatMessageDTO.getType();
|
|
String path = "messages?conversation_id=" + difyChatMessageDTO.getConversationId() + "&user=" + difyChatMessageDTO.getUser() + "&limit=" + difyChatMessageDTO.getLimit();
|
|
String path = "messages?conversation_id=" + difyChatMessageDTO.getConversationId() + "&user=" + difyChatMessageDTO.getUser() + "&limit=" + difyChatMessageDTO.getLimit();
|
|
if (difyChatMessageDTO.getFirstId() != null) {
|
|
if (difyChatMessageDTO.getFirstId() != null) {
|
|
path += "&first_id=" + difyChatMessageDTO.getFirstId();
|
|
path += "&first_id=" + difyChatMessageDTO.getFirstId();
|
|
}
|
|
}
|
|
|
|
+ String key =apiKey;
|
|
|
|
+ if(type!=null&&type.equals(4)){
|
|
|
|
+ key=discoveryResultKey;
|
|
|
|
+ }
|
|
Request request = new Request.Builder()
|
|
Request request = new Request.Builder()
|
|
.url(url + path)
|
|
.url(url + path)
|
|
.get()
|
|
.get()
|
|
- .addHeader("Authorization", "Bearer " + apiKey)
|
|
|
|
|
|
+ .addHeader("Authorization", "Bearer " + key)
|
|
.build();
|
|
.build();
|
|
return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
|
|
return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
|
|
}
|
|
}
|
|
@@ -185,7 +196,7 @@ public class DifyService {
|
|
|
|
|
|
String param = new Gson().toJson(difyChatMessageDTO);
|
|
String param = new Gson().toJson(difyChatMessageDTO);
|
|
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
|
|
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
|
|
- Request request = this.getChatMessageRequest(requestBody);
|
|
|
|
|
|
+ Request request = this.getChatMessageRequest(requestBody,apiKey);
|
|
return Flux.create(emitter -> {
|
|
return Flux.create(emitter -> {
|
|
client.newCall(request).enqueue(new Callback() {
|
|
client.newCall(request).enqueue(new Callback() {
|
|
@Override
|
|
@Override
|
|
@@ -264,16 +275,16 @@ public class DifyService {
|
|
return url;
|
|
return url;
|
|
}
|
|
}
|
|
|
|
|
|
- public Request getChatMessageRequest(RequestBody requestBody) {
|
|
|
|
|
|
+ public Request getChatMessageRequest(RequestBody requestBody,String key) {
|
|
Request request = new Request.Builder()
|
|
Request request = new Request.Builder()
|
|
.url(url + "chat-messages")
|
|
.url(url + "chat-messages")
|
|
- .addHeader("Authorization", "Bearer " + apiKey).addHeader(HttpHeaders.CONTENT_TYPE, "application/json")
|
|
|
|
|
|
+ .addHeader("Authorization", "Bearer " + key).addHeader(HttpHeaders.CONTENT_TYPE, "application/json")
|
|
.post(requestBody)
|
|
.post(requestBody)
|
|
.build();
|
|
.build();
|
|
return request;
|
|
return request;
|
|
}
|
|
}
|
|
|
|
|
|
- public JSONObject stopMessage(String taskId) throws IOException {
|
|
|
|
|
|
+ public JSONObject stopMessage(String taskId,Integer type) throws IOException {
|
|
OkHttpClient client = new OkHttpClient.Builder()
|
|
OkHttpClient client = new OkHttpClient.Builder()
|
|
.connectTimeout(60, TimeUnit.SECONDS)
|
|
.connectTimeout(60, TimeUnit.SECONDS)
|
|
.writeTimeout(60, TimeUnit.SECONDS)
|
|
.writeTimeout(60, TimeUnit.SECONDS)
|
|
@@ -283,9 +294,13 @@ public class DifyService {
|
|
difyChatMessageDTO.setUser("1");
|
|
difyChatMessageDTO.setUser("1");
|
|
String param = new Gson().toJson(difyChatMessageDTO);
|
|
String param = new Gson().toJson(difyChatMessageDTO);
|
|
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
|
|
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
|
|
|
|
+ String key =apiKey;
|
|
|
|
+ if(type!=null&&type.equals(4)){
|
|
|
|
+ key=discoveryResultKey;
|
|
|
|
+ }
|
|
Request request = new Request.Builder()
|
|
Request request = new Request.Builder()
|
|
.url(url + "chat-messages/" + taskId + "/stop")
|
|
.url(url + "chat-messages/" + taskId + "/stop")
|
|
- .addHeader("Authorization", "Bearer " + apiKey).addHeader(HttpHeaders.CONTENT_TYPE, "application/json")
|
|
|
|
|
|
+ .addHeader("Authorization", "Bearer " + key).addHeader(HttpHeaders.CONTENT_TYPE, "application/json")
|
|
.post(requestBody)
|
|
.post(requestBody)
|
|
.build();
|
|
.build();
|
|
String json = Objects.requireNonNull(client.newCall(request).execute().body()).string();
|
|
String json = Objects.requireNonNull(client.newCall(request).execute().body()).string();
|
|
@@ -325,7 +340,7 @@ public class DifyService {
|
|
.build();
|
|
.build();
|
|
String param = new Gson().toJson(difyChatMessageDTO);
|
|
String param = new Gson().toJson(difyChatMessageDTO);
|
|
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
|
|
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
|
|
- Request request = this.getChatMessageRequest(requestBody);
|
|
|
|
|
|
+ Request request = this.getChatMessageRequest(requestBody,apiKey);
|
|
String res = Objects.requireNonNull(client.newCall(request).execute().body()).string();
|
|
String res = Objects.requireNonNull(client.newCall(request).execute().body()).string();
|
|
JSONObject jsonObject = JSONObject.parseObject(res);
|
|
JSONObject jsonObject = JSONObject.parseObject(res);
|
|
String inventionPoint = jsonObject.get("answer").toString();
|
|
String inventionPoint = jsonObject.get("answer").toString();
|
|
@@ -524,9 +539,9 @@ public class DifyService {
|
|
|
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
Map<String, Object> map = new HashMap<>();
|
|
map.put("fileUrl", fileUrl);
|
|
map.put("fileUrl", fileUrl);
|
|
- map.put("patent_fileUrls",patentFileUrls);
|
|
|
|
- map.put("app_file_guid",appFileGuid);
|
|
|
|
- map.put("modify_file_guid",modifyFileGuid);
|
|
|
|
|
|
+ map.put("patent_fileUrls", patentFileUrls);
|
|
|
|
+ map.put("app_file_guid", appFileGuid);
|
|
|
|
+ map.put("modify_file_guid", modifyFileGuid);
|
|
map.put("patent_files", new ArrayList<>());
|
|
map.put("patent_files", new ArrayList<>());
|
|
map.put("changeClaim", vo.getChangeClaim());
|
|
map.put("changeClaim", vo.getChangeClaim());
|
|
map.put("claim", vo.getClaim());
|
|
map.put("claim", vo.getClaim());
|
|
@@ -581,7 +596,7 @@ public class DifyService {
|
|
}
|
|
}
|
|
try {
|
|
try {
|
|
JSONObject jsonObject = JSON.parseObject(line);
|
|
JSONObject jsonObject = JSON.parseObject(line);
|
|
- String sessionConversationId = jsonObject.get("conversation_id").toString();
|
|
|
|
|
|
+ String sessionConversationId = jsonObject.get("conversation_id").toString();
|
|
String event = jsonObject.get("event").toString();
|
|
String event = jsonObject.get("event").toString();
|
|
if (StringUtils.isEmpty(runId)) {
|
|
if (StringUtils.isEmpty(runId)) {
|
|
if (StringUtils.isNotEmpty(sessionConversationId)) {
|
|
if (StringUtils.isNotEmpty(sessionConversationId)) {
|
|
@@ -630,7 +645,7 @@ public class DifyService {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
- public void generateDoc(String conversationName,Integer confessionSessionId,JSONObject object) {
|
|
|
|
|
|
+ public void generateDoc(String conversationName, Integer confessionSessionId, JSONObject object) {
|
|
Map<String, Object> map = new HashMap<>();
|
|
Map<String, Object> map = new HashMap<>();
|
|
String reason = object.getString("reason");
|
|
String reason = object.getString("reason");
|
|
String num = object.getString("num");
|
|
String num = object.getString("num");
|
|
@@ -759,7 +774,7 @@ public class DifyService {
|
|
String background = generateClaimDTO.getBackground();
|
|
String background = generateClaimDTO.getBackground();
|
|
|
|
|
|
DifyChatMessageDTO difyChatMessageDTO = new DifyChatMessageDTO();
|
|
DifyChatMessageDTO difyChatMessageDTO = new DifyChatMessageDTO();
|
|
- String userId ="1";
|
|
|
|
|
|
+ String userId = "1";
|
|
// String userId = loginUtils.getId().toString();
|
|
// String userId = loginUtils.getId().toString();
|
|
Map<String, Object> map = new HashMap<>();
|
|
Map<String, Object> map = new HashMap<>();
|
|
map.put("claim", claim);
|
|
map.put("claim", claim);
|
|
@@ -784,17 +799,23 @@ public class DifyService {
|
|
|
|
|
|
return res;
|
|
return res;
|
|
}
|
|
}
|
|
- public Flux<String> chatMessageReFux(DifyChatMessageDTO difyChatMessageDTO,String key) {
|
|
|
|
- Integer projectId = chatMessageDTO.getProjectId();
|
|
|
|
|
|
+
|
|
|
|
+ public Flux<String> discoveryResultDialogue(ChatMessageDTO chatMessageDTO) {
|
|
Integer confessionSessionId = chatMessageDTO.getConfessionSessionId();
|
|
Integer confessionSessionId = chatMessageDTO.getConfessionSessionId();
|
|
String conversationId = chatMessageDTO.getConversationId();
|
|
String conversationId = chatMessageDTO.getConversationId();
|
|
String userId = loginUtils.getId().toString();
|
|
String userId = loginUtils.getId().toString();
|
|
String query = chatMessageDTO.getQuery();
|
|
String query = chatMessageDTO.getQuery();
|
|
|
|
+ Integer type = chatMessageDTO.getType();
|
|
|
|
+ if (type == null || query == null || query.trim().equals("")) {
|
|
|
|
+ throw new XiaoShiException(ExceptionEnum.BUSINESS_CHECK, "请按要求输入参数");
|
|
|
|
+ }
|
|
if (conversationId == null) {
|
|
if (conversationId == null) {
|
|
- conversationId = difySessionService.getSessionId(projectId, userId);
|
|
|
|
|
|
+ conversationId = assoConfessionConversationService.getConversationId(confessionSessionId, type);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
String temConversationId = conversationId;
|
|
String temConversationId = conversationId;
|
|
|
|
+ String temConversationId3=conversationId;
|
|
OkHttpClient client = new OkHttpClient.Builder()
|
|
OkHttpClient client = new OkHttpClient.Builder()
|
|
.connectTimeout(600, TimeUnit.SECONDS)
|
|
.connectTimeout(600, TimeUnit.SECONDS)
|
|
.writeTimeout(600, TimeUnit.SECONDS)
|
|
.writeTimeout(600, TimeUnit.SECONDS)
|
|
@@ -804,18 +825,18 @@ public class DifyService {
|
|
DifyChatMessageDTO difyChatMessageDTO = new DifyChatMessageDTO();
|
|
DifyChatMessageDTO difyChatMessageDTO = new DifyChatMessageDTO();
|
|
Map<String, Object> map = new HashMap<>();
|
|
Map<String, Object> map = new HashMap<>();
|
|
String fileContent = "";
|
|
String fileContent = "";
|
|
- String inventionPoint = "";
|
|
|
|
- if (projectId != null) {
|
|
|
|
- fileContent = this.getConfression(projectId);
|
|
|
|
- inventionPoint = this.getInventPoint(projectId);
|
|
|
|
- } else if (confessionSessionId != null) {
|
|
|
|
- ConfessionSession confessionSession = confessionSessionService.getById(confessionSessionId);
|
|
|
|
- fileContent = fileDownloadUrl + confessionSession.getGuid();
|
|
|
|
- inventionPoint = confessionSession.getInventionPoint();
|
|
|
|
- }
|
|
|
|
|
|
|
|
- map.put("file_path", fileContent);
|
|
|
|
- map.put("invention_point", inventionPoint);
|
|
|
|
|
|
+ ConfessionSession confessionSession = confessionSessionService.getById(confessionSessionId);
|
|
|
|
+
|
|
|
|
+ List<String> guids = assoConfessionSessionFileService.getFileGuid(confessionSessionId, 0);
|
|
|
|
+ if (guids == null || guids.size() == 0) {
|
|
|
|
+ throw new XiaoShiException(ExceptionEnum.BUSINESS_ERROR, "数据错误,未检测到交底书");
|
|
|
|
+ }
|
|
|
|
+ fileContent = fileDownloadUrl + guids.get(0);
|
|
|
|
+ map.put("file_path", fileContent);
|
|
|
|
+
|
|
|
|
+ map.put("data_Result", confessionSession.getResultContent());
|
|
|
|
+ map.put("ask_type", type.toString());
|
|
difyChatMessageDTO.setInputs(map);
|
|
difyChatMessageDTO.setInputs(map);
|
|
difyChatMessageDTO.setConversationId(conversationId);
|
|
difyChatMessageDTO.setConversationId(conversationId);
|
|
difyChatMessageDTO.setResponseMode("streaming");
|
|
difyChatMessageDTO.setResponseMode("streaming");
|
|
@@ -825,7 +846,8 @@ public class DifyService {
|
|
|
|
|
|
String param = new Gson().toJson(difyChatMessageDTO);
|
|
String param = new Gson().toJson(difyChatMessageDTO);
|
|
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
|
|
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
|
|
- Request request = this.getChatMessageRequest(requestBody);
|
|
|
|
|
|
+ Request request = this.getChatMessageRequest(requestBody,discoveryResultKey);
|
|
|
|
+
|
|
return Flux.create(emitter -> {
|
|
return Flux.create(emitter -> {
|
|
client.newCall(request).enqueue(new Callback() {
|
|
client.newCall(request).enqueue(new Callback() {
|
|
@Override
|
|
@Override
|
|
@@ -857,15 +879,11 @@ public class DifyService {
|
|
try {
|
|
try {
|
|
JSONObject jsonObject = JSON.parseObject(line);
|
|
JSONObject jsonObject = JSON.parseObject(line);
|
|
temConversationId2 = jsonObject.get("conversation_id").toString();
|
|
temConversationId2 = jsonObject.get("conversation_id").toString();
|
|
- if (projectId != null) {
|
|
|
|
- difySessionService.addDifySession(projectId, userId, temConversationId2);
|
|
|
|
- }
|
|
|
|
- if (confessionSessionId != null) {
|
|
|
|
- UpdateConfessionSessionDTO updateConfessionSessionDTO = new UpdateConfessionSessionDTO();
|
|
|
|
- updateConfessionSessionDTO.setConfessionSessionId(confessionSessionId);
|
|
|
|
- updateConfessionSessionDTO.setConversationId(temConversationId2);
|
|
|
|
- confessionSessionService.updateConfessionSession(updateConfessionSessionDTO);
|
|
|
|
- }
|
|
|
|
|
|
+ AssoConfessionConversation assoConfessionConversation = new AssoConfessionConversation();
|
|
|
|
+ assoConfessionConversation.setConfessionId(confessionSessionId);
|
|
|
|
+ assoConfessionConversation.setConversationId(temConversationId2);
|
|
|
|
+ assoConfessionConversation.setType(type);
|
|
|
|
+ assoConfessionConversation.insert();
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
}
|
|
}
|
|
|
|
|