Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pms-dispatch-assistant
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
姜耀祖
pms-dispatch-assistant
Commits
72adaf97
Commit
72adaf97
authored
Apr 22, 2025
by
赵灿灿
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
保存对话
parent
11f6222f
Pipeline
#21060
passed with stages
in 3 minutes and 27 seconds
Changes
9
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
1342 additions
and
0 deletions
+1342
-0
ChatService.java
.../dispatchassistant/domain/langchain/chat/ChatService.java
+85
-0
Conversations.java
...atchassistant/domain/langchain/history/Conversations.java
+135
-0
ConversationsCriteria.java
...stant/domain/langchain/history/ConversationsCriteria.java
+144
-0
IConversationsRepository.java
...nt/domain/langchain/history/IConversationsRepository.java
+80
-0
IMessagesRepository.java
...sistant/domain/langchain/history/IMessagesRepository.java
+78
-0
Messages.java
.../dispatchassistant/domain/langchain/history/Messages.java
+121
-0
MessagesCriteria.java
...hassistant/domain/langchain/history/MessagesCriteria.java
+145
-0
ConversationsRepository.java
...ant/infractructure/langchain/ConversationsRepository.java
+280
-0
MessagesRepository.java
...ssistant/infractructure/langchain/MessagesRepository.java
+274
-0
No files found.
src/main/java/com/infoepoch/pms/dispatchassistant/domain/langchain/chat/ChatService.java
View file @
72adaf97
package
com
.
infoepoch
.
pms
.
dispatchassistant
.
domain
.
langchain
.
chat
;
package
com
.
infoepoch
.
pms
.
dispatchassistant
.
domain
.
langchain
.
chat
;
import
com.infoepoch.pms.dispatchassistant.common.component.SnowFlake
;
import
com.infoepoch.pms.dispatchassistant.common.exception.ValidationException
;
import
com.infoepoch.pms.dispatchassistant.common.exception.ValidationException
;
import
com.infoepoch.pms.dispatchassistant.common.utils.JsonUtils
;
import
com.infoepoch.pms.dispatchassistant.common.utils.JsonUtils
;
import
com.infoepoch.pms.dispatchassistant.common.utils.RestTemplateUtils
;
import
com.infoepoch.pms.dispatchassistant.common.utils.RestTemplateUtils
;
import
com.infoepoch.pms.dispatchassistant.controller.basic.Auth
;
import
com.infoepoch.pms.dispatchassistant.domain.basic.store.KeyValueStoreService
;
import
com.infoepoch.pms.dispatchassistant.domain.basic.store.KeyValueStoreService
;
import
com.infoepoch.pms.dispatchassistant.domain.basic.user.User
;
import
com.infoepoch.pms.dispatchassistant.domain.langchain.ChatConstants
;
import
com.infoepoch.pms.dispatchassistant.domain.langchain.ChatConstants
;
import
com.infoepoch.pms.dispatchassistant.domain.langchain.chat.chat.ChatRequest
;
import
com.infoepoch.pms.dispatchassistant.domain.langchain.chat.chat.ChatRequest
;
import
com.infoepoch.pms.dispatchassistant.domain.langchain.chat.knowledgeBaseChat.KnowledgeBaseChatRequest
;
import
com.infoepoch.pms.dispatchassistant.domain.langchain.chat.knowledgeBaseChat.KnowledgeBaseChatRequest
;
import
com.infoepoch.pms.dispatchassistant.domain.langchain.history.*
;
import
io.micrometer.core.instrument.util.StringUtils
;
import
io.micrometer.core.instrument.util.StringUtils
;
import
lombok.Data
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
@Service
@Service
...
@@ -23,6 +30,14 @@ public class ChatService {
...
@@ -23,6 +30,14 @@ public class ChatService {
@Autowired
@Autowired
private
KeyValueStoreService
keyValueStoreService
;
private
KeyValueStoreService
keyValueStoreService
;
@Autowired
private
Auth
auth
;
@Autowired
private
IConversationsRepository
iConversationsRepository
;
@Autowired
private
IMessagesRepository
iMessagesRepository
;
/**
/**
* 与LLM模型对话
* 与LLM模型对话
*
*
...
@@ -94,4 +109,74 @@ public class ChatService {
...
@@ -94,4 +109,74 @@ public class ChatService {
}
}
}
}
/**
* @param dialogId
* 新增会话
*/
private
Conversations
saveConversations
(
String
dialogId
,
String
question
,
String
aiType
)
{
Conversations
conversations
=
null
;
try
{
ConversationsCriteria
conversationsCriteria
=
new
ConversationsCriteria
();
conversationsCriteria
.
setSessionId
(
dialogId
);
List
<
Conversations
>
conversationsList
=
iConversationsRepository
.
selectByCriteria
(
conversationsCriteria
);
if
(
conversationsList
==
null
)
{
User
user
=
auth
.
getUserReq
();
conversations
=
new
Conversations
();
conversations
.
setId
(
SnowFlake
.
instant
().
nextId
().
toString
());
conversations
.
setUserId
(
user
.
getId
());
conversations
.
setUserName
(
user
.
getUsername
());
conversations
.
setName
(
user
.
getFullname
());
conversations
.
setFirstQuestion
(
question
);
conversations
.
setAiType
(
aiType
);
conversations
.
setSessionId
(
dialogId
);
conversations
.
setRecordTime
(
new
Date
());
iConversationsRepository
.
insert
(
conversations
);
}
else
conversations
=
conversationsList
.
get
(
0
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
conversations
;
}
//新增问题信息
private
Messages
insertQuestionMessage
(
Conversations
conversations
,
Messages
questionMes
)
{
//查找当前对话的父对话
MessagesCriteria
messagesCriteria
=
new
MessagesCriteria
();
messagesCriteria
.
setSessionId
(
conversations
.
getSessionId
());
messagesCriteria
.
setCid
(
conversations
.
getId
());
Messages
messagesLast
=
iMessagesRepository
.
selectOneByCriteria
(
messagesCriteria
);
try
{
if
(
messagesLast
!=
null
)
{
questionMes
.
setParentMsgId
(
messagesLast
.
getId
());
}
String
id
=
SnowFlake
.
instant
().
nextId
().
toString
();
questionMes
.
setId
(
id
);
questionMes
.
setCid
(
conversations
.
getId
());
questionMes
.
setSessionId
(
conversations
.
getSessionId
());
questionMes
.
setRecordTime
(
new
Date
());
iMessagesRepository
.
insert
(
questionMes
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
questionMes
;
}
//新增回答信息
private
Messages
insertMessage
(
Conversations
conversations
,
Messages
contMes
)
{
try
{
String
id
=
SnowFlake
.
instant
().
nextId
().
toString
();
contMes
.
setId
(
id
);
contMes
.
setCid
(
conversations
.
getId
());
contMes
.
setSessionId
(
conversations
.
getSessionId
());
contMes
.
setRecordTime
(
new
Date
());
iMessagesRepository
.
insert
(
contMes
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
contMes
;
}
}
}
src/main/java/com/infoepoch/pms/dispatchassistant/domain/langchain/history/Conversations.java
0 → 100644
View file @
72adaf97
package
com
.
infoepoch
.
pms
.
dispatchassistant
.
domain
.
langchain
.
history
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
java.util.Date
;
/**
* generated by code-generator
*
*/
public
class
Conversations
{
/**
* 主键
*/
private
String
id
;
/**
* 用户ID
*/
private
String
userId
;
/**
* 用户名
*/
private
String
userName
;
/**
* 用户姓名
*/
private
String
name
;
/**
* 会话id
*/
private
String
sessionId
;
/**
* 第一次提的问题
*/
private
String
firstQuestion
;
/**
* 状态(1:进行中, 0:已结束)
*/
private
String
status
;
/**
* 创建时间
*/
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
private
Date
recordTime
;
/**
* 更新时间
*/
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
private
Date
updateTime
;
/**
* 智能体专业类型
*/
private
String
aiType
;
/**
* 条件1
*/
private
String
condition1
;
public
String
getId
()
{
return
id
;
}
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
public
String
getUserId
()
{
return
userId
;
}
public
void
setUserId
(
String
userId
)
{
this
.
userId
=
userId
;
}
public
String
getUserName
()
{
return
userName
;
}
public
void
setUserName
(
String
userName
)
{
this
.
userName
=
userName
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getSessionId
()
{
return
sessionId
;
}
public
void
setSessionId
(
String
sessionId
)
{
this
.
sessionId
=
sessionId
;
}
public
String
getFirstQuestion
()
{
return
firstQuestion
;
}
public
void
setFirstQuestion
(
String
firstQuestion
)
{
this
.
firstQuestion
=
firstQuestion
;
}
public
String
getStatus
()
{
return
status
;
}
public
void
setStatus
(
String
status
)
{
this
.
status
=
status
;
}
public
Date
getRecordTime
()
{
return
recordTime
;
}
public
void
setRecordTime
(
Date
recordTime
)
{
this
.
recordTime
=
recordTime
;
}
public
Date
getUpdateTime
()
{
return
updateTime
;
}
public
void
setUpdateTime
(
Date
updateTime
)
{
this
.
recordTime
=
updateTime
;
}
public
String
getAiType
()
{
return
aiType
;
}
public
void
setAiType
(
String
aiType
)
{
this
.
aiType
=
aiType
;
}
public
String
getCondition1
()
{
return
condition1
;
}
public
void
setCondition1
(
String
condition1
)
{
this
.
condition1
=
condition1
;
}
}
src/main/java/com/infoepoch/pms/dispatchassistant/domain/langchain/history/ConversationsCriteria.java
0 → 100644
View file @
72adaf97
package
com
.
infoepoch
.
pms
.
dispatchassistant
.
domain
.
langchain
.
history
;
import
com.infoepoch.pms.dispatchassistant.common.component.AbstractCriteria
;
/**
* generated by code-generator
* 查询条件类
*/
public
class
ConversationsCriteria
extends
AbstractCriteria
{
//region 样例
//public boolean byId() {
// return this.andMap.containsKey("Id");
//}
//
//private String id;
//
//public String getId() {
// if (byId())
// return id;
// return null;
//}
//
//public void setId(String value) {
// this.id = value;
// this.andMap.put("Id", value);
//}
//endregion
//region 用户ID
public
boolean
byUserId
()
{
return
this
.
andMap
.
containsKey
(
"UserId"
);
}
private
String
userId
;
public
String
getUserId
()
{
if
(
byUserId
())
return
userId
;
return
null
;
}
public
void
setUserId
(
String
value
)
{
this
.
userId
=
value
;
this
.
andMap
.
put
(
"UserId"
,
value
);
}
//endregion
//region 用户名
public
boolean
byUserName
()
{
return
this
.
andMap
.
containsKey
(
"UserName"
);
}
private
String
userName
;
public
String
getUserName
()
{
if
(
byUserName
())
return
userName
;
return
null
;
}
public
void
setUserName
(
String
value
)
{
this
.
userName
=
value
;
this
.
andMap
.
put
(
"UserName"
,
value
);
}
//endregion
//region 用户姓名
public
boolean
byName
()
{
return
this
.
andMap
.
containsKey
(
"Name"
);
}
private
String
name
;
public
String
getName
()
{
if
(
byName
())
return
name
;
return
null
;
}
public
void
setName
(
String
value
)
{
this
.
name
=
value
;
this
.
andMap
.
put
(
"Name"
,
value
);
}
//endregion
//region 会话id
public
boolean
bySessionId
()
{
return
this
.
andMap
.
containsKey
(
"SessionId"
);
}
private
String
sessionId
;
public
String
getSessionId
()
{
if
(
bySessionId
())
return
sessionId
;
return
null
;
}
public
void
setSessionId
(
String
value
)
{
this
.
sessionId
=
value
;
this
.
andMap
.
put
(
"SessionId"
,
value
);
}
//endregion
//region 智能体专业类型
public
boolean
byAiType
()
{
return
this
.
andMap
.
containsKey
(
"AiType"
);
}
private
String
aiType
;
public
String
getAiType
()
{
if
(
byAiType
())
return
aiType
;
return
null
;
}
public
void
setAiType
(
String
value
)
{
this
.
aiType
=
value
;
this
.
andMap
.
put
(
"AiType"
,
value
);
}
//endregion
//region 条件1
public
boolean
byCondition1
()
{
return
this
.
andMap
.
containsKey
(
"Condition1"
);
}
private
String
condition1
;
public
String
getCondition1
()
{
if
(
byCondition1
())
return
condition1
;
return
null
;
}
public
void
setCondition1
(
String
value
)
{
this
.
condition1
=
value
;
this
.
andMap
.
put
(
"Condition1"
,
value
);
}
//endregion
}
\ No newline at end of file
src/main/java/com/infoepoch/pms/dispatchassistant/domain/langchain/history/IConversationsRepository.java
0 → 100644
View file @
72adaf97
package
com
.
infoepoch
.
pms
.
dispatchassistant
.
domain
.
langchain
.
history
;
import
java.util.List
;
/**
* generated by code-generator
* 仓储接口
*/
public
interface
IConversationsRepository
{
/**
* 表序列id
*/
Long
sequenceId
();
/**
* 新增
* @param: [entity]
*/
boolean
insert
(
Conversations
entity
);
/**
* 更新
* @param: [entity]
*/
boolean
update
(
Conversations
entity
);
/**
* 批量新增
* @param: [entitys]
*/
int
[]
batchInsert
(
List
<
Conversations
>
entitys
);
/**
* 批量更新
* @param: [entitys]
*/
int
[]
batchUpdate
(
List
<
Conversations
>
entitys
);
/**
* 删除
* @param: [id]
*/
boolean
delete
(
String
id
);
// region select
/**
* 根据Id查询
* @param: [id]
*/
Conversations
selectById
(
String
id
);
/**
* 根据查询条件查询单个对象
* @param: [criteria]
*/
Conversations
selectOneByCriteria
(
ConversationsCriteria
criteria
);
/**
* 根据查询条件查询对象集合
* @param: [criteria]
*/
List
<
Conversations
>
selectByCriteria
(
ConversationsCriteria
criteria
);
/**
* 根据查询条件分页查询对象结合
* @param: [criteria, pageNum, pageSize]
*/
List
<
Conversations
>
selectCriteriaByPage
(
ConversationsCriteria
criteria
,
int
pageNum
,
int
pageSize
);
/**
* 根据条件查询对象总记录数
* @param: [criteria]
*/
Integer
selectCountByCriteria
(
ConversationsCriteria
criteria
);
// endregion
}
src/main/java/com/infoepoch/pms/dispatchassistant/domain/langchain/history/IMessagesRepository.java
0 → 100644
View file @
72adaf97
package
com
.
infoepoch
.
pms
.
dispatchassistant
.
domain
.
langchain
.
history
;
import
java.util.List
;
/**
* generated by code-generator
* 仓储接口
*/
public
interface
IMessagesRepository
{
/**
* 表序列id
*/
Long
sequenceId
();
/**
* 新增
* @param: [entity]
*/
boolean
insert
(
Messages
entity
);
/**
* 更新
* @param: [entity]
*/
boolean
update
(
Messages
entity
);
/**
* 批量新增
* @param: [entitys]
*/
int
[]
batchInsert
(
List
<
Messages
>
entitys
);
/**
* 批量更新
* @param: [entitys]
*/
int
[]
batchUpdate
(
List
<
Messages
>
entitys
);
/**
* 删除
* @param: [id]
*/
boolean
delete
(
String
id
);
// region select
/**
* 根据Id查询
* @param: [id]
*/
Messages
selectById
(
String
id
);
/**
* 根据查询条件查询单个对象
* @param: [criteria]
*/
Messages
selectOneByCriteria
(
MessagesCriteria
criteria
);
/**
* 根据查询条件查询对象集合
* @param: [criteria]
*/
List
<
Messages
>
selectByCriteria
(
MessagesCriteria
criteria
);
/**
* 根据查询条件分页查询对象结合
* @param: [criteria, pageNum, pageSize]
*/
List
<
Messages
>
selectCriteriaByPage
(
MessagesCriteria
criteria
,
int
pageNum
,
int
pageSize
);
/**
* 根据条件查询对象总记录数
* @param: [criteria]
*/
Integer
selectCountByCriteria
(
MessagesCriteria
criteria
);
// endregion
}
src/main/java/com/infoepoch/pms/dispatchassistant/domain/langchain/history/Messages.java
0 → 100644
View file @
72adaf97
package
com
.
infoepoch
.
pms
.
dispatchassistant
.
domain
.
langchain
.
history
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
java.math.BigDecimal
;
import
java.util.Date
;
/**
* generated by code-generator
*
*/
public
class
Messages
{
/**
* 主键
*/
private
String
id
;
/**
* 会话表主键
*/
private
String
cid
;
/**
* 会话id
*/
private
String
sessionId
;
/**
* 请求id
*/
private
String
requestId
;
/**
* 角色'user','assistant'
*/
private
String
role
;
/**
* 消息内容
*/
private
String
content
;
/**
* 父消息id
*/
private
String
parentMsgId
;
/**
* 关键词提取结果(用于快速检索上下文)
*/
private
String
keyWords
;
/**
* 使用的AI模型
*/
private
String
modelName
;
/**
* 记录时间
*/
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
private
Date
recordTime
;
public
String
getId
()
{
return
id
;
}
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
public
String
getCid
()
{
return
cid
;
}
public
void
setCid
(
String
cid
)
{
this
.
cid
=
cid
;
}
public
String
getSessionId
()
{
return
sessionId
;
}
public
void
setSessionId
(
String
sessionId
)
{
this
.
sessionId
=
sessionId
;
}
public
String
getRequestId
()
{
return
requestId
;
}
public
void
setRequestId
(
String
requestId
)
{
this
.
requestId
=
requestId
;
}
public
String
getRole
()
{
return
role
;
}
public
void
setRole
(
String
role
)
{
this
.
role
=
role
;
}
public
String
getContent
()
{
return
content
;
}
public
void
setContent
(
String
content
)
{
this
.
content
=
content
;
}
public
String
getParentMsgId
()
{
return
parentMsgId
;
}
public
void
setParentMsgId
(
String
parentMsgId
)
{
this
.
parentMsgId
=
parentMsgId
;
}
public
String
getKeyWords
()
{
return
keyWords
;
}
public
void
setKeyWords
(
String
keyWords
)
{
this
.
keyWords
=
keyWords
;
}
public
String
getModelName
()
{
return
modelName
;
}
public
void
setModelName
(
String
modelName
)
{
this
.
modelName
=
modelName
;
}
public
Date
getRecordTime
()
{
return
recordTime
;
}
public
void
setRecordTime
(
Date
recordTime
)
{
this
.
recordTime
=
recordTime
;
}
}
\ No newline at end of file
src/main/java/com/infoepoch/pms/dispatchassistant/domain/langchain/history/MessagesCriteria.java
0 → 100644
View file @
72adaf97
package
com
.
infoepoch
.
pms
.
dispatchassistant
.
domain
.
langchain
.
history
;
import
com.infoepoch.pms.dispatchassistant.common.component.AbstractCriteria
;
/**
* generated by code-generator
* 查询条件类
*/
public
class
MessagesCriteria
extends
AbstractCriteria
{
//region 样例
//public boolean byId() {
// return this.andMap.containsKey("Id");
//}
//
//private String id;
//
//public String getId() {
// if (byId())
// return id;
// return null;
//}
//
//public void setId(String value) {
// this.id = value;
// this.andMap.put("Id", value);
//}
//endregion
//region 主键
public
boolean
byId
()
{
return
this
.
andMap
.
containsKey
(
"Id"
);
}
private
String
id
;
public
String
getId
()
{
if
(
byId
())
return
id
;
return
null
;
}
public
void
setId
(
String
value
)
{
this
.
id
=
value
;
this
.
andMap
.
put
(
"Id"
,
value
);
}
//endregion
//region 会话表主键
public
boolean
byCid
()
{
return
this
.
andMap
.
containsKey
(
"Cid"
);
}
private
String
cid
;
public
String
getCid
()
{
if
(
byCid
())
return
cid
;
return
null
;
}
public
void
setCid
(
String
value
)
{
this
.
cid
=
value
;
this
.
andMap
.
put
(
"Cid"
,
value
);
}
//endregion
//region 会话id
public
boolean
bySessionId
()
{
return
this
.
andMap
.
containsKey
(
"SessionId"
);
}
private
String
sessionId
;
public
String
getSessionId
()
{
if
(
bySessionId
())
return
sessionId
;
return
null
;
}
public
void
setSessionId
(
String
value
)
{
this
.
sessionId
=
value
;
this
.
andMap
.
put
(
"SessionId"
,
value
);
}
//endregion
//region 请求id
public
boolean
byRequestId
()
{
return
this
.
andMap
.
containsKey
(
"RequestId"
);
}
private
String
requestId
;
public
String
getRequestId
()
{
if
(
byRequestId
())
return
requestId
;
return
null
;
}
public
void
setRequestId
(
String
value
)
{
this
.
requestId
=
value
;
this
.
andMap
.
put
(
"RequestId"
,
value
);
}
//endregion
//region 角色'user','assistant'
public
boolean
byRole
()
{
return
this
.
andMap
.
containsKey
(
"Role"
);
}
private
String
role
;
public
String
getRole
()
{
if
(
byRole
())
return
role
;
return
null
;
}
public
void
setRole
(
String
value
)
{
this
.
role
=
value
;
this
.
andMap
.
put
(
"Role"
,
value
);
}
//endregion
//region 父消息id
public
boolean
byParentMsgId
()
{
return
this
.
andMap
.
containsKey
(
"ParentMsgId"
);
}
private
String
parentMsgId
;
public
String
getParentMsgId
()
{
if
(
byParentMsgId
())
return
parentMsgId
;
return
null
;
}
public
void
setParentMsgId
(
String
value
)
{
this
.
parentMsgId
=
value
;
this
.
andMap
.
put
(
"ParentMsgId"
,
value
);
}
//endregion
}
src/main/java/com/infoepoch/pms/dispatchassistant/infractructure/langchain/ConversationsRepository.java
0 → 100644
View file @
72adaf97
This diff is collapsed.
Click to expand it.
src/main/java/com/infoepoch/pms/dispatchassistant/infractructure/langchain/MessagesRepository.java
0 → 100644
View file @
72adaf97
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment