Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Q
qk_backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
quanku
qk_backend
Commits
68c6e9f4
Commit
68c6e9f4
authored
Nov 08, 2023
by
shiyu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
人工介入接口
parent
ab6d0528
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
87 additions
and
1 deletion
+87
-1
ch-admin-api/src/main/java/com/wwdz/ch/admin/controller/SysIMController.java
...in/java/com/wwdz/ch/admin/controller/SysIMController.java
+21
-0
ch-admin-api/src/main/java/com/wwdz/ch/admin/impl/SysIMServiceImpl.java
...rc/main/java/com/wwdz/ch/admin/impl/SysIMServiceImpl.java
+36
-1
ch-admin-api/src/main/java/com/wwdz/ch/admin/service/SysIMService.java
...src/main/java/com/wwdz/ch/admin/service/SysIMService.java
+14
-0
ch-core/src/main/java/com/wwdz/ch/core/util/IMUtil.java
ch-core/src/main/java/com/wwdz/ch/core/util/IMUtil.java
+11
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/ImServiceImpl.java
...-api/src/main/java/com/wwdz/ch/wx/impl/ImServiceImpl.java
+5
-0
No files found.
ch-admin-api/src/main/java/com/wwdz/ch/admin/controller/SysIMController.java
View file @
68c6e9f4
...
@@ -73,4 +73,25 @@ public class SysIMController {
...
@@ -73,4 +73,25 @@ public class SysIMController {
return
sysIMService
.
setChatUserRemark
(
dto
);
return
sysIMService
.
setChatUserRemark
(
dto
);
}
}
@ApiOperation
(
value
=
"人工介入"
)
@PostMapping
(
"/humanIntervene"
)
public
Result
humanIntervene
(
@RequestBody
ConversationRequestDto
dto
)
{
logger
.
info
(
"【请求开始】人工介入,请求参数:{}"
,
JSON
.
toJSONString
(
dto
));
if
(
StringUtils
.
isEmpty
(
dto
.
getFromAccount
())
||
StringUtils
.
isEmpty
(
dto
.
getToAccount
()))
{
return
Result
.
failed
(
ResultCode
.
PARAM_ERROR
);
}
return
sysIMService
.
humanIntervene
(
dto
);
}
@ApiOperation
(
value
=
"结束人工介入"
)
@PostMapping
(
"/stopHumanIntervene"
)
public
Result
stopHumanIntervene
(
@RequestBody
ConversationRequestDto
dto
)
{
logger
.
info
(
"【请求开始】结束人工介入,请求参数:{}"
,
JSON
.
toJSONString
(
dto
));
if
(
StringUtils
.
isEmpty
(
dto
.
getFromAccount
())
||
StringUtils
.
isEmpty
(
dto
.
getToAccount
()))
{
return
Result
.
failed
(
ResultCode
.
PARAM_ERROR
);
}
return
sysIMService
.
stopHumanIntervene
(
dto
);
}
}
}
ch-admin-api/src/main/java/com/wwdz/ch/admin/impl/SysIMServiceImpl.java
View file @
68c6e9f4
...
@@ -7,12 +7,12 @@ import com.wwdz.ch.core.im.api.ConversationApi;
...
@@ -7,12 +7,12 @@ import com.wwdz.ch.core.im.api.ConversationApi;
import
com.wwdz.ch.core.im.api.TLSSigApi
;
import
com.wwdz.ch.core.im.api.TLSSigApi
;
import
com.wwdz.ch.core.type.Result
;
import
com.wwdz.ch.core.type.Result
;
import
com.wwdz.ch.core.util.IMUtil
;
import
com.wwdz.ch.core.util.IMUtil
;
import
com.wwdz.ch.core.util.RedisUtils
;
import
com.wwdz.ch.db.dao.AiAssistantDao
;
import
com.wwdz.ch.db.dao.AiAssistantDao
;
import
com.wwdz.ch.db.dao.UserDao
;
import
com.wwdz.ch.db.dao.UserDao
;
import
com.wwdz.ch.db.domain.AiAssistant
;
import
com.wwdz.ch.db.domain.AiAssistant
;
import
com.wwdz.ch.db.domain.User
;
import
com.wwdz.ch.db.domain.User
;
import
com.wwdz.ch.db.dto.request.ConversationRequestDto
;
import
com.wwdz.ch.db.dto.request.ConversationRequestDto
;
import
com.wwdz.ch.db.dto.request.ImRecordRequestDto
;
import
com.wwdz.ch.db.dto.request.UserRequestDto
;
import
com.wwdz.ch.db.dto.request.UserRequestDto
;
import
com.xxdxxs.utils.JsonUtils
;
import
com.xxdxxs.utils.JsonUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
...
@@ -43,6 +43,9 @@ public class SysIMServiceImpl implements SysIMService {
...
@@ -43,6 +43,9 @@ public class SysIMServiceImpl implements SysIMService {
@Autowired
@Autowired
AiAssistantDao
aiAssistantDao
;
AiAssistantDao
aiAssistantDao
;
@Autowired
RedisUtils
redisUtils
;
@Override
@Override
public
Result
sendChatMsg
(
SendChatMsgRequestDto
dto
)
{
public
Result
sendChatMsg
(
SendChatMsgRequestDto
dto
)
{
try
{
try
{
...
@@ -50,6 +53,8 @@ public class SysIMServiceImpl implements SysIMService {
...
@@ -50,6 +53,8 @@ public class SysIMServiceImpl implements SysIMService {
if
(
dto
.
getIsRealPersonAnswer
()
!=
null
&&
dto
.
getIsRealPersonAnswer
()
==
1
)
{
if
(
dto
.
getIsRealPersonAnswer
()
!=
null
&&
dto
.
getIsRealPersonAnswer
()
==
1
)
{
dto
.
setCloudCustomData
(
JsonUtils
.
fromMap
(
new
HashMap
<
String
,
Object
>(){{
put
(
"realPersonId"
,
dto
.
getRealPersonId
());}}));
dto
.
setCloudCustomData
(
JsonUtils
.
fromMap
(
new
HashMap
<
String
,
Object
>(){{
put
(
"realPersonId"
,
dto
.
getRealPersonId
());}}));
}
}
String
key
=
imUtil
.
getHumanInterveneKey
(
dto
.
getToAccount
(),
dto
.
getFromAccount
());
redisUtils
.
set
(
key
,
System
.
currentTimeMillis
(),
60
*
3
);
Result
result
=
conversationApi
.
sendChatMsg
(
dto
);
Result
result
=
conversationApi
.
sendChatMsg
(
dto
);
return
result
;
return
result
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
...
@@ -80,6 +85,12 @@ public class SysIMServiceImpl implements SysIMService {
...
@@ -80,6 +85,12 @@ public class SysIMServiceImpl implements SysIMService {
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"user"
,
user
);
map
.
put
(
"user"
,
user
);
map
.
put
(
"aiAssistant"
,
aiAssistant
);
map
.
put
(
"aiAssistant"
,
aiAssistant
);
//判断该会话是否有人工介入
if
(
redisUtils
.
hasKey
(
imUtil
.
getHumanInterveneKey
(
dto
.
getFromAccount
(),
dto
.
getToAccount
())))
{
map
.
put
(
"intervened"
,
true
);
}
else
{
map
.
put
(
"intervened"
,
false
);
}
return
Result
.
success
(
map
);
return
Result
.
success
(
map
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
logger
.
error
(
"获取用户信息失败:{}"
,
e
);
logger
.
error
(
"获取用户信息失败:{}"
,
e
);
...
@@ -100,4 +111,28 @@ public class SysIMServiceImpl implements SysIMService {
...
@@ -100,4 +111,28 @@ public class SysIMServiceImpl implements SysIMService {
}
}
return
Result
.
failed
();
return
Result
.
failed
();
}
}
/**
* fromAccount为用户账号
* toAccount为机器人账号
* @param dto
* @return
*/
@Override
public
Result
humanIntervene
(
ConversationRequestDto
dto
)
{
String
key
=
imUtil
.
getHumanInterveneKey
(
dto
.
getFromAccount
(),
dto
.
getToAccount
());
redisUtils
.
set
(
key
,
System
.
currentTimeMillis
(),
60
*
3
);
return
Result
.
success
();
}
@Override
public
Result
stopHumanIntervene
(
ConversationRequestDto
dto
)
{
String
key
=
imUtil
.
getHumanInterveneKey
(
dto
.
getFromAccount
(),
dto
.
getToAccount
());
boolean
flag
=
redisUtils
.
delete
(
key
);
if
(
flag
)
{
return
Result
.
success
();
}
return
Result
.
failed
();
}
}
}
ch-admin-api/src/main/java/com/wwdz/ch/admin/service/SysIMService.java
View file @
68c6e9f4
...
@@ -38,4 +38,18 @@ public interface SysIMService {
...
@@ -38,4 +38,18 @@ public interface SysIMService {
* @return
* @return
*/
*/
Result
setChatUserRemark
(
UserRequestDto
dto
);
Result
setChatUserRemark
(
UserRequestDto
dto
);
/**
* 人工介入
* @param dto
* @return
*/
Result
humanIntervene
(
ConversationRequestDto
dto
);
/**
* 结束人工介入
* @param dto
* @return
*/
Result
stopHumanIntervene
(
ConversationRequestDto
dto
);
}
}
ch-core/src/main/java/com/wwdz/ch/core/util/IMUtil.java
View file @
68c6e9f4
...
@@ -90,4 +90,15 @@ public class IMUtil {
...
@@ -90,4 +90,15 @@ public class IMUtil {
return
url
+
stringBuffer
.
toString
();
return
url
+
stringBuffer
.
toString
();
}
}
/**
* 人工介入在redis中的标识
* @param fromAccount
* @param toAccount
* @return
*/
public
String
getHumanInterveneKey
(
String
fromAccount
,
String
toAccount
)
{
String
key
=
"C2C:INTERVENE:"
+
formatUserId
(
fromAccount
)
+
"_to_"
+
formatUserId
(
toAccount
);
return
key
;
}
}
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/ImServiceImpl.java
View file @
68c6e9f4
...
@@ -140,6 +140,11 @@ public class ImServiceImpl implements IMService {
...
@@ -140,6 +140,11 @@ public class ImServiceImpl implements IMService {
}
}
logger
.
info
(
"=========== userid:{}, 提问ai的消息发送成功 =========="
,
dto
.
getFromAccount
());
logger
.
info
(
"=========== userid:{}, 提问ai的消息发送成功 =========="
,
dto
.
getFromAccount
());
if
(
redisUtils
.
hasKey
(
imUtil
.
getHumanInterveneKey
(
dto
.
getFromAccount
(),
dto
.
getToAccount
())))
{
logger
.
info
(
">>>> 会话: {} to {}, 已有人工介入, 无需机器人回答 <<<<"
,
dto
.
getFromAccount
(),
dto
.
getToAccount
());
return
Result
.
success
();
}
if
(
dto
.
getMsgType
()
==
IMEnum
.
MsgTypeEnum
.
TIMTextElem
.
getCode
())
{
if
(
dto
.
getMsgType
()
==
IMEnum
.
MsgTypeEnum
.
TIMTextElem
.
getCode
())
{
String
question
=
(
String
)
dto
.
getMsgContent
();
String
question
=
(
String
)
dto
.
getMsgContent
();
question
=
question
+
",请回答钱币相关的内容"
;
question
=
question
+
",请回答钱币相关的内容"
;
...
...
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