|
@@ -5,12 +5,15 @@ import cn.cslg.pas.common.model.dify.ChatMessageDTO;
|
|
|
import cn.cslg.pas.common.model.dify.DifyChatMessageDTO;
|
|
|
import cn.cslg.pas.common.model.dify.DifyHistoryMessageDTO;
|
|
|
|
|
|
+import cn.cslg.pas.common.model.dify.confessionSession.UpdateConfessionSessionDTO;
|
|
|
import cn.cslg.pas.common.utils.CacheUtils;
|
|
|
import cn.cslg.pas.common.utils.DataUtils;
|
|
|
import cn.cslg.pas.common.utils.LoginUtils;
|
|
|
import cn.cslg.pas.domain.business.TechnicalCase;
|
|
|
+import cn.cslg.pas.domain.dify.ConfessionSession;
|
|
|
import cn.cslg.pas.domain.report.AssoProjectConfession;
|
|
|
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.report.AssoProjectConfessionService;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
@@ -63,6 +66,7 @@ public class DifyService {
|
|
|
private CacheUtils cacheUtils;
|
|
|
@Autowired
|
|
|
private LoginUtils loginUtils;
|
|
|
+ private final ConfessionSessionService confessionSessionService;
|
|
|
|
|
|
/**
|
|
|
* 调用文件系统删除文件接口
|
|
@@ -109,6 +113,7 @@ public class DifyService {
|
|
|
|
|
|
public Flux<String> getOkhttp(ChatMessageDTO chatMessageDTO) {
|
|
|
Integer projectId = chatMessageDTO.getProjectId();
|
|
|
+ Integer confessionSessionId = chatMessageDTO.getConfessionSessionId();
|
|
|
String conversationId = chatMessageDTO.getConversationId();
|
|
|
String userId = loginUtils.getId().toString();
|
|
|
String query = chatMessageDTO.getQuery();
|
|
@@ -125,8 +130,17 @@ public class DifyService {
|
|
|
|
|
|
DifyChatMessageDTO difyChatMessageDTO = new DifyChatMessageDTO();
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
- String fileContent = this.getConfression(projectId);
|
|
|
- String inventionPoint = this.getInventPoint(projectId);
|
|
|
+ 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);
|
|
|
difyChatMessageDTO.setInputs(map);
|
|
@@ -148,6 +162,7 @@ public class DifyService {
|
|
|
|
|
|
@Override
|
|
|
public void onResponse(Call call, Response response) throws IOException {
|
|
|
+
|
|
|
if (!response.isSuccessful()) {
|
|
|
emitter.error(new IOException("Unexpected code: " + response));
|
|
|
return;
|
|
@@ -165,11 +180,20 @@ public class DifyService {
|
|
|
if (line.startsWith(prefixToRemove)) {
|
|
|
line = line.substring(prefixToRemove.length());
|
|
|
}
|
|
|
- if (temConversationId2 == null) {
|
|
|
+ if (temConversationId2 == null || temConversationId2.isEmpty()) {
|
|
|
try {
|
|
|
JSONObject jsonObject = JSON.parseObject(line);
|
|
|
temConversationId2 = jsonObject.get("conversation_id").toString();
|
|
|
- difySessionService.addDifySession(projectId, userId, temConversationId2);
|
|
|
+ if (projectId != null) {
|
|
|
+ difySessionService.addDifySession(projectId, userId, temConversationId2);
|
|
|
+ }
|
|
|
+ if (confessionSessionId != null) {
|
|
|
+ UpdateConfessionSessionDTO updateConfessionSessionDTO = new UpdateConfessionSessionDTO();
|
|
|
+ updateConfessionSessionDTO.setConversationName("新会话");
|
|
|
+ updateConfessionSessionDTO.setConfessionSessionId(confessionSessionId);
|
|
|
+ updateConfessionSessionDTO.setConversationId(temConversationId2);
|
|
|
+ confessionSessionService.updateConfessionSession(updateConfessionSessionDTO);
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
}
|
|
|
|
|
@@ -240,12 +264,20 @@ public class DifyService {
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Map<String, Object> generateInventionPoint(ChatMessageDTO chatMessageDTO) throws IOException {
|
|
|
Integer projectId = chatMessageDTO.getProjectId();
|
|
|
+ Integer confessionSessionId = chatMessageDTO.getConfessionSessionId();
|
|
|
String query = "生成发明点";
|
|
|
String userId = loginUtils.getId().toString();
|
|
|
String conversationId = chatMessageDTO.getConversationId();
|
|
|
DifyChatMessageDTO difyChatMessageDTO = new DifyChatMessageDTO();
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
- String fileContent = this.getConfression(projectId);
|
|
|
+ String fileContent="";
|
|
|
+ if(confessionSessionId!=null){
|
|
|
+ ConfessionSession confessionSession=confessionSessionService.getById(confessionSessionId);
|
|
|
+ fileContent=fileDownloadUrl+confessionSession.getGuid();
|
|
|
+ }
|
|
|
+ else if(projectId!=null) {
|
|
|
+ fileContent = this.getConfression(projectId);
|
|
|
+ }
|
|
|
map.put("file_path", fileContent);
|
|
|
difyChatMessageDTO.setInputs(map);
|
|
|
difyChatMessageDTO.setConversationId(conversationId);
|
|
@@ -267,14 +299,21 @@ public class DifyService {
|
|
|
JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
String inventionPoint = jsonObject.get("answer").toString();
|
|
|
inventionPoint = DataUtils.getMarkDownText(inventionPoint);
|
|
|
-// if (conversationId == null) {
|
|
|
-// conversationId = jsonObject.get("conversation_id").toString();
|
|
|
-// difySessionService.addDifySession(projectId, userId, conversationId);
|
|
|
-// }
|
|
|
Map<String, Object> map1 = new HashMap<>();
|
|
|
map1.put("invention_point", inventionPoint);
|
|
|
- technicalCaseService.updateInventionPoint(projectId, inventionPoint);
|
|
|
+ if (projectId != null) {
|
|
|
+ technicalCaseService.updateInventionPoint(projectId, inventionPoint);
|
|
|
+ }
|
|
|
+ if (confessionSessionId != null) {
|
|
|
+ UpdateConfessionSessionDTO updateConfessionSessionDTO = new UpdateConfessionSessionDTO();
|
|
|
+ updateConfessionSessionDTO.setConfessionSessionId(confessionSessionId);
|
|
|
+ updateConfessionSessionDTO.setInventionPoint(inventionPoint);
|
|
|
+ confessionSessionService.updateConfessionSession(updateConfessionSessionDTO);
|
|
|
+ }
|
|
|
map1.put("conversation_id", conversationId);
|
|
|
+
|
|
|
+ map1.put("projectId",projectId);
|
|
|
+ map1.put("confessionSessionId",confessionSessionId);
|
|
|
return map1;
|
|
|
}
|
|
|
}
|