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
4319e361
Commit
4319e361
authored
Oct 19, 2023
by
shiyu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ai会话
parent
d15af2cf
Changes
17
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
151 additions
and
52 deletions
+151
-52
ch-core/src/main/java/com/wwdz/ch/core/entity/im/SendChatMsgRequestDto.java
...ava/com/wwdz/ch/core/entity/im/SendChatMsgRequestDto.java
+6
-0
ch-core/src/main/java/com/wwdz/ch/core/im/api/ChatUserApi.java
...re/src/main/java/com/wwdz/ch/core/im/api/ChatUserApi.java
+2
-20
ch-core/src/main/java/com/wwdz/ch/core/im/api/ConversationApi.java
...rc/main/java/com/wwdz/ch/core/im/api/ConversationApi.java
+3
-27
ch-core/src/main/java/com/wwdz/ch/core/util/IMUtil.java
ch-core/src/main/java/com/wwdz/ch/core/util/IMUtil.java
+26
-0
ch-core/src/main/resources/application-dev.yml
ch-core/src/main/resources/application-dev.yml
+1
-0
ch-core/src/main/resources/application-prod.yml
ch-core/src/main/resources/application-prod.yml
+1
-0
ch-dao/src/main/java/com/wwdz/ch/db/dao/AiAssistantDao.java
ch-dao/src/main/java/com/wwdz/ch/db/dao/AiAssistantDao.java
+4
-0
ch-dao/src/main/java/com/wwdz/ch/db/dto/request/AiDefaultQuestionRequestDto.java
...m/wwdz/ch/db/dto/request/AiDefaultQuestionRequestDto.java
+11
-0
ch-dao/src/main/java/com/wwdz/ch/db/impl/AiAssistantDaoImpl.java
...src/main/java/com/wwdz/ch/db/impl/AiAssistantDaoImpl.java
+10
-0
ch-dao/src/main/resources/generatorConfig_new.xml
ch-dao/src/main/resources/generatorConfig_new.xml
+1
-1
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/AiAssistantServiceImpl.java
...main/java/com/wwdz/ch/wx/impl/AiAssistantServiceImpl.java
+3
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/AiDefaultQuestionServiceImpl.java
...ava/com/wwdz/ch/wx/impl/AiDefaultQuestionServiceImpl.java
+28
-1
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/IMServiceImpl.java
...-api/src/main/java/com/wwdz/ch/wx/impl/IMServiceImpl.java
+17
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/UserServiceImpl.java
...pi/src/main/java/com/wwdz/ch/wx/impl/UserServiceImpl.java
+20
-2
ch-wx-api/src/main/java/com/wwdz/ch/wx/service/IMService.java
...x-api/src/main/java/com/wwdz/ch/wx/service/IMService.java
+6
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/web/IMController.java
ch-wx-api/src/main/java/com/wwdz/ch/wx/web/IMController.java
+11
-0
ch-wx-api/src/test/java/com/wwdz/ch/wx/api/ChatApiTest.java
ch-wx-api/src/test/java/com/wwdz/ch/wx/api/ChatApiTest.java
+1
-1
No files found.
ch-core/src/main/java/com/wwdz/ch/core/entity/im/SendChatMsgRequestDto.java
View file @
4319e361
...
@@ -7,6 +7,12 @@ import lombok.Data;
...
@@ -7,6 +7,12 @@ import lombok.Data;
@Data
@Data
public
class
SendChatMsgRequestDto
implements
Entity
{
public
class
SendChatMsgRequestDto
implements
Entity
{
/**
* 发送消息的请求id
* 用于停止AI回答
*/
private
String
reqId
;
/**
/**
* 1:把消息同步到 From_Account 在线终端和漫游上
* 1:把消息同步到 From_Account 在线终端和漫游上
* 2:消息不同步至 From_Account
* 2:消息不同步至 From_Account
...
...
ch-core/src/main/java/com/wwdz/ch/core/im/api/ChatUserApi.java
View file @
4319e361
...
@@ -54,16 +54,7 @@ public class ChatUserApi {
...
@@ -54,16 +54,7 @@ public class ChatUserApi {
* @return
* @return
*/
*/
public
Result
importUser
(
User
user
)
{
public
Result
importUser
(
User
user
)
{
String
userSig
=
tlsSigApi
.
getUserSig
(
ADMIN_ID
);
String
url
=
imUtil
.
formatIMUrl
(
ACCOUNT_URL
);
Random
random
=
new
Random
(
4294967295L
);
long
randomNum
=
random
.
nextInt
();
StringBuffer
stringBuffer
=
new
StringBuffer
();
stringBuffer
.
append
(
"?sdkappid="
+
SDKAppID
);
stringBuffer
.
append
(
"&identifier="
+
ADMIN_ID
);
stringBuffer
.
append
(
"&usersig="
+
userSig
);
stringBuffer
.
append
(
"&random="
+
randomNum
);
stringBuffer
.
append
(
"&contenttype=json"
);
String
url
=
ACCOUNT_URL
+
stringBuffer
.
toString
();
logger
.
info
(
"============== IM导入用户请求url : {}"
,
url
);
logger
.
info
(
"============== IM导入用户请求url : {}"
,
url
);
OkHttpUtil
okHttpUtil
=
OkHttpUtil
.
builder
().
url
(
url
);
OkHttpUtil
okHttpUtil
=
OkHttpUtil
.
builder
().
url
(
url
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
...
@@ -93,16 +84,7 @@ public class ChatUserApi {
...
@@ -93,16 +84,7 @@ public class ChatUserApi {
* @return
* @return
*/
*/
public
Result
importAiUser
(
AiAssistant
aiAssistant
)
{
public
Result
importAiUser
(
AiAssistant
aiAssistant
)
{
String
userSig
=
tlsSigApi
.
getUserSig
(
ADMIN_ID
);
String
url
=
imUtil
.
formatIMUrl
(
ACCOUNT_URL
);
Random
random
=
new
Random
(
4294967295L
);
long
randomNum
=
random
.
nextInt
();
StringBuffer
stringBuffer
=
new
StringBuffer
();
stringBuffer
.
append
(
"?sdkappid="
+
SDKAppID
);
stringBuffer
.
append
(
"&identifier="
+
ADMIN_ID
);
stringBuffer
.
append
(
"&usersig="
+
userSig
);
stringBuffer
.
append
(
"&random="
+
randomNum
);
stringBuffer
.
append
(
"&contenttype=json"
);
String
url
=
ACCOUNT_URL
+
stringBuffer
.
toString
();
logger
.
info
(
"============== IM导入用户请求url : {}"
,
url
);
logger
.
info
(
"============== IM导入用户请求url : {}"
,
url
);
OkHttpUtil
okHttpUtil
=
OkHttpUtil
.
builder
().
url
(
url
);
OkHttpUtil
okHttpUtil
=
OkHttpUtil
.
builder
().
url
(
url
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
...
...
ch-core/src/main/java/com/wwdz/ch/core/im/api/ConversationApi.java
View file @
4319e361
...
@@ -17,7 +17,6 @@ import org.slf4j.LoggerFactory;
...
@@ -17,7 +17,6 @@ import org.slf4j.LoggerFactory;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.*
;
import
java.util.*
;
...
@@ -29,16 +28,10 @@ public class ConversationApi {
...
@@ -29,16 +28,10 @@ public class ConversationApi {
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ConversationApi
.
class
);
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ConversationApi
.
class
);
private
static
final
String
ACCOUNT
_URL
=
"https://console.tim.qq.com/v4/openim/sendmsg"
;
private
static
final
String
SEND_MSG
_URL
=
"https://console.tim.qq.com/v4/openim/sendmsg"
;
private
static
final
String
GET_CHAT_LIST_URL
=
"https://console.tim.qq.com/v4/recentcontact/get_list"
;
private
static
final
String
GET_CHAT_LIST_URL
=
"https://console.tim.qq.com/v4/recentcontact/get_list"
;
@Value
(
"${dts.im.adminid}"
)
private
String
ADMIN_ID
;
@Value
(
"${dts.im.SDKAppID}"
)
private
Long
SDKAppID
;
@Autowired
@Autowired
TLSSigApi
tlsSigApi
;
TLSSigApi
tlsSigApi
;
...
@@ -51,16 +44,9 @@ public class ConversationApi {
...
@@ -51,16 +44,9 @@ public class ConversationApi {
* @return
* @return
*/
*/
public
Result
sendChatMsg
(
SendChatMsgRequestDto
sendChatMsgRequestDto
)
{
public
Result
sendChatMsg
(
SendChatMsgRequestDto
sendChatMsgRequestDto
)
{
String
userSig
=
tlsSigApi
.
getUserSig
(
ADMIN_ID
);
Random
random
=
new
Random
(
4294967295L
);
Random
random
=
new
Random
(
4294967295L
);
int
randomNum
=
random
.
nextInt
();
int
randomNum
=
random
.
nextInt
();
StringBuffer
stringBuffer
=
new
StringBuffer
();
String
url
=
imUtil
.
formatIMUrl
(
SEND_MSG_URL
);
stringBuffer
.
append
(
"?sdkappid="
+
SDKAppID
);
stringBuffer
.
append
(
"&identifier="
+
ADMIN_ID
);
stringBuffer
.
append
(
"&usersig="
+
userSig
);
stringBuffer
.
append
(
"&random="
+
randomNum
);
stringBuffer
.
append
(
"&contenttype=json"
);
String
url
=
ACCOUNT_URL
+
stringBuffer
.
toString
();
OkHttpUtil
okHttpUtil
=
OkHttpUtil
.
builder
().
url
(
url
);
OkHttpUtil
okHttpUtil
=
OkHttpUtil
.
builder
().
url
(
url
);
IMChatMsg
imChatMsg
=
imUtil
.
convert
(
sendChatMsgRequestDto
);
IMChatMsg
imChatMsg
=
imUtil
.
convert
(
sendChatMsgRequestDto
);
//消息同步至发送方
//消息同步至发送方
...
@@ -89,18 +75,8 @@ public class ConversationApi {
...
@@ -89,18 +75,8 @@ public class ConversationApi {
* @return
* @return
*/
*/
public
Result
getChatList
(
IMChatRequestDto
imChatRequestDto
)
{
public
Result
getChatList
(
IMChatRequestDto
imChatRequestDto
)
{
String
userSig
=
tlsSigApi
.
getUserSig
(
ADMIN_ID
);
String
url
=
imUtil
.
formatIMUrl
(
GET_CHAT_LIST_URL
);
Random
random
=
new
Random
(
4294967295L
);
int
randomNum
=
random
.
nextInt
();
StringBuffer
stringBuffer
=
new
StringBuffer
();
stringBuffer
.
append
(
"?sdkappid="
+
SDKAppID
);
stringBuffer
.
append
(
"&identifier="
+
ADMIN_ID
);
stringBuffer
.
append
(
"&usersig="
+
userSig
);
stringBuffer
.
append
(
"&random="
+
randomNum
);
stringBuffer
.
append
(
"&contenttype=json"
);
String
url
=
GET_CHAT_LIST_URL
+
stringBuffer
.
toString
();
OkHttpUtil
okHttpUtil
=
OkHttpUtil
.
builder
().
url
(
url
);
OkHttpUtil
okHttpUtil
=
OkHttpUtil
.
builder
().
url
(
url
);
Map
<
String
,
Object
>
paramMap
=
new
HashMap
<>();
Map
<
String
,
Object
>
paramMap
=
new
HashMap
<>();
paramMap
.
put
(
"From_Account"
,
imUtil
.
formatUserId
(
imChatRequestDto
.
getUserId
()
+
""
));
paramMap
.
put
(
"From_Account"
,
imUtil
.
formatUserId
(
imChatRequestDto
.
getUserId
()
+
""
));
paramMap
.
put
(
"TimeStamp"
,
imChatRequestDto
.
getTimeStamp
());
paramMap
.
put
(
"TimeStamp"
,
imChatRequestDto
.
getTimeStamp
());
...
...
ch-core/src/main/java/com/wwdz/ch/core/util/IMUtil.java
View file @
4319e361
...
@@ -3,12 +3,15 @@ package com.wwdz.ch.core.util;
...
@@ -3,12 +3,15 @@ package com.wwdz.ch.core.util;
import
com.wwdz.ch.core.consts.IMEnum
;
import
com.wwdz.ch.core.consts.IMEnum
;
import
com.wwdz.ch.core.entity.im.SendChatMsgRequestDto
;
import
com.wwdz.ch.core.entity.im.SendChatMsgRequestDto
;
import
com.wwdz.ch.core.entity.im.IMChatMsg
;
import
com.wwdz.ch.core.entity.im.IMChatMsg
;
import
com.wwdz.ch.core.im.api.TLSSigApi
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Random
;
@Component
@Component
public
class
IMUtil
{
public
class
IMUtil
{
...
@@ -16,6 +19,15 @@ public class IMUtil {
...
@@ -16,6 +19,15 @@ public class IMUtil {
@Value
(
"${dts.im.prefix}"
)
@Value
(
"${dts.im.prefix}"
)
private
String
PREFIX
;
private
String
PREFIX
;
@Value
(
"${dts.im.adminid}"
)
private
String
ADMIN_ID
;
@Value
(
"${dts.im.SDKAppID}"
)
private
Long
SDKAppID
;
@Autowired
TLSSigApi
tlsSigApi
;
/**
/**
* 格式化用户id
* 格式化用户id
* 转换为im对话中的用户id
* 转换为im对话中的用户id
...
@@ -54,4 +66,18 @@ public class IMUtil {
...
@@ -54,4 +66,18 @@ public class IMUtil {
imChatMsg
.
setMsgBody
(
Arrays
.
asList
(
msgContentMap
));
imChatMsg
.
setMsgBody
(
Arrays
.
asList
(
msgContentMap
));
return
imChatMsg
;
return
imChatMsg
;
}
}
public
String
formatIMUrl
(
String
url
)
{
String
userSig
=
tlsSigApi
.
getUserSig
(
ADMIN_ID
);
Random
random
=
new
Random
(
4294967295L
);
int
randomNum
=
random
.
nextInt
();
StringBuffer
stringBuffer
=
new
StringBuffer
();
stringBuffer
.
append
(
"?sdkappid="
+
SDKAppID
);
stringBuffer
.
append
(
"&identifier="
+
ADMIN_ID
);
stringBuffer
.
append
(
"&usersig="
+
userSig
);
stringBuffer
.
append
(
"&random="
+
randomNum
);
stringBuffer
.
append
(
"&contenttype=json"
);
return
url
+
stringBuffer
.
toString
();
}
}
}
ch-core/src/main/resources/application-dev.yml
View file @
4319e361
...
@@ -28,6 +28,7 @@ dts:
...
@@ -28,6 +28,7 @@ dts:
secret
:
b5873a44e46efd086015a51e171e6e09fdeb4dce778752c891e63ed17aa1a81e
secret
:
b5873a44e46efd086015a51e171e6e09fdeb4dce778752c891e63ed17aa1a81e
prefix
:
cjxc-applet-dev_
prefix
:
cjxc-applet-dev_
adminid
:
cjxc
adminid
:
cjxc
default-ai-code
:
ai10000
#通知相关配置
#通知相关配置
notify
:
notify
:
...
...
ch-core/src/main/resources/application-prod.yml
View file @
4319e361
...
@@ -27,6 +27,7 @@ dts:
...
@@ -27,6 +27,7 @@ dts:
secret
:
b5873a44e46efd086015a51e171e6e09fdeb4dce778752c891e63ed17aa1a81e
secret
:
b5873a44e46efd086015a51e171e6e09fdeb4dce778752c891e63ed17aa1a81e
prefix
:
cjxc-applet_
prefix
:
cjxc-applet_
adminid
:
cjxc
adminid
:
cjxc
default-ai-code
:
ai10000
#通知相关配置
#通知相关配置
notify
:
notify
:
...
...
ch-dao/src/main/java/com/wwdz/ch/db/dao/AiAssistantDao.java
View file @
4319e361
...
@@ -9,4 +9,8 @@ public interface AiAssistantDao {
...
@@ -9,4 +9,8 @@ public interface AiAssistantDao {
List
<
AiAssistant
>
findList
(
AiAssistantRequestDto
dto
);
List
<
AiAssistant
>
findList
(
AiAssistantRequestDto
dto
);
AiAssistant
findByCode
(
String
code
);
AiAssistant
findByCode
(
String
code
);
AiAssistant
findByType
(
Integer
type
);
}
}
ch-dao/src/main/java/com/wwdz/ch/db/dto/request/AiDefaultQuestionRequestDto.java
View file @
4319e361
...
@@ -6,9 +6,20 @@ import lombok.Data;
...
@@ -6,9 +6,20 @@ import lombok.Data;
@Data
@Data
public
class
AiDefaultQuestionRequestDto
extends
BaseRequestDto
implements
Entity
{
public
class
AiDefaultQuestionRequestDto
extends
BaseRequestDto
implements
Entity
{
/**
* 当前用户id
*/
private
Long
userId
;
/**
/**
* 问题类型
* 问题类型
*/
*/
private
Integer
type
;
private
Integer
type
;
/**
* 是否换一批问题
* 1是; 0否
*/
private
Integer
isChangeList
;
}
}
ch-dao/src/main/java/com/wwdz/ch/db/impl/AiAssistantDaoImpl.java
View file @
4319e361
...
@@ -21,6 +21,8 @@ public class AiAssistantDaoImpl implements AiAssistantDao {
...
@@ -21,6 +21,8 @@ public class AiAssistantDaoImpl implements AiAssistantDao {
@Override
@Override
public
List
<
AiAssistant
>
findList
(
AiAssistantRequestDto
dto
)
{
public
List
<
AiAssistant
>
findList
(
AiAssistantRequestDto
dto
)
{
AiAssistantExample
aiAssistantExample
=
new
AiAssistantExample
();
AiAssistantExample
aiAssistantExample
=
new
AiAssistantExample
();
//排除默认机器人
aiAssistantExample
.
createCriteria
().
andTypeNotEqualTo
(
0
);
PageHelper
.
startPage
(
dto
.
getPage
(),
dto
.
getLimit
());
PageHelper
.
startPage
(
dto
.
getPage
(),
dto
.
getLimit
());
return
aiAssistantMapper
.
selectByExample
(
aiAssistantExample
);
return
aiAssistantMapper
.
selectByExample
(
aiAssistantExample
);
}
}
...
@@ -31,4 +33,12 @@ public class AiAssistantDaoImpl implements AiAssistantDao {
...
@@ -31,4 +33,12 @@ public class AiAssistantDaoImpl implements AiAssistantDao {
aiAssistantExample
.
createCriteria
().
andCodeEqualTo
(
code
);
aiAssistantExample
.
createCriteria
().
andCodeEqualTo
(
code
);
return
aiAssistantMapper
.
selectOneByExample
(
aiAssistantExample
);
return
aiAssistantMapper
.
selectOneByExample
(
aiAssistantExample
);
}
}
@Override
public
AiAssistant
findByType
(
Integer
type
)
{
AiAssistantExample
aiAssistantExample
=
new
AiAssistantExample
();
aiAssistantExample
.
createCriteria
().
andTypeEqualTo
(
type
);
return
aiAssistantMapper
.
selectOneByExample
(
aiAssistantExample
);
}
}
}
ch-dao/src/main/resources/generatorConfig_new.xml
View file @
4319e361
...
@@ -72,7 +72,7 @@
...
@@ -72,7 +72,7 @@
<javaClientGenerator
type=
"XMLMAPPER"
targetPackage=
"com.wwdz.ch.db.mapper"
<javaClientGenerator
type=
"XMLMAPPER"
targetPackage=
"com.wwdz.ch.db.mapper"
targetProject=
"ch-dao/src/main/java"
/>
targetProject=
"ch-dao/src/main/java"
/>
<table
tableName=
"
category_temp
"
enableCountByExample=
"true"
enableUpdateByExample=
"true"
enableDeleteByExample=
"true"
enableSelectByExample=
"true"
selectByExampleQueryId=
"true"
>
<table
tableName=
"
ai_assistant
"
enableCountByExample=
"true"
enableUpdateByExample=
"true"
enableDeleteByExample=
"true"
enableSelectByExample=
"true"
selectByExampleQueryId=
"true"
>
<generatedKey
column=
"id"
sqlStatement=
"Mysql"
identity=
"true"
/>
<generatedKey
column=
"id"
sqlStatement=
"Mysql"
identity=
"true"
/>
</table>
</table>
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/AiAssistantServiceImpl.java
View file @
4319e361
...
@@ -18,6 +18,7 @@ import com.xxdxxs.utils.EntityMapper;
...
@@ -18,6 +18,7 @@ import com.xxdxxs.utils.EntityMapper;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
...
@@ -41,6 +42,8 @@ public class AiAssistantServiceImpl implements AiAssistantService {
...
@@ -41,6 +42,8 @@ public class AiAssistantServiceImpl implements AiAssistantService {
@Autowired
@Autowired
IMUtil
imUtil
;
IMUtil
imUtil
;
@Value
(
"${dts.im.default-ai-code}"
)
private
String
DEFAULT_AI_CODE
;
@Override
@Override
public
Result
findList
(
AiAssistantRequestDto
dto
)
{
public
Result
findList
(
AiAssistantRequestDto
dto
)
{
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/AiDefaultQuestionServiceImpl.java
View file @
4319e361
package
com.wwdz.ch.wx.impl
;
package
com.wwdz.ch.wx.impl
;
import
com.wwdz.ch.core.type.Result
;
import
com.wwdz.ch.core.type.Result
;
import
com.wwdz.ch.core.util.RedisUtils
;
import
com.wwdz.ch.db.dao.AiAssistantDao
;
import
com.wwdz.ch.db.dao.AiDefaultQuestionDao
;
import
com.wwdz.ch.db.dao.AiDefaultQuestionDao
;
import
com.wwdz.ch.db.domain.AiAssistant
;
import
com.wwdz.ch.db.domain.AiAssistant
;
import
com.wwdz.ch.db.domain.AiDefaultQuestion
;
import
com.wwdz.ch.db.domain.AiDefaultQuestion
;
import
com.wwdz.ch.db.dto.request.AiDefaultQuestionRequestDto
;
import
com.wwdz.ch.db.dto.request.AiDefaultQuestionRequestDto
;
import
com.wwdz.ch.wx.service.AiAssistantService
;
import
com.wwdz.ch.wx.service.AiDefaultQuestionService
;
import
com.wwdz.ch.wx.service.AiDefaultQuestionService
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
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.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.TimeUnit
;
/**
/**
* ai助手默认问题
* ai助手默认问题
...
@@ -20,15 +27,35 @@ public class AiDefaultQuestionServiceImpl implements AiDefaultQuestionService {
...
@@ -20,15 +27,35 @@ public class AiDefaultQuestionServiceImpl implements AiDefaultQuestionService {
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
AiDefaultQuestionServiceImpl
.
class
);
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
AiDefaultQuestionServiceImpl
.
class
);
private
static
final
String
AI_DEFAULT_QUESTION_KEY_PREFIX
=
"AI-DEFAULT-QUESTION:"
;
@Autowired
@Autowired
AiDefaultQuestionDao
aiDefaultQuestionDao
;
AiDefaultQuestionDao
aiDefaultQuestionDao
;
@Autowired
RedisUtils
redisUtils
;
@Autowired
AiAssistantDao
aiAssistantDao
;
@Override
@Override
public
Result
findList
(
AiDefaultQuestionRequestDto
dto
)
{
public
Result
findList
(
AiDefaultQuestionRequestDto
dto
)
{
try
{
try
{
String
key
=
AI_DEFAULT_QUESTION_KEY_PREFIX
+
dto
.
getUserId
();
if
(
redisUtils
.
hasKey
(
key
)
&&
dto
.
getIsChangeList
()
==
0
){
return
Result
.
success
();
}
List
<
AiDefaultQuestion
>
aiDefaultQuestionList
=
aiDefaultQuestionDao
.
findList
(
dto
);
List
<
AiDefaultQuestion
>
aiDefaultQuestionList
=
aiDefaultQuestionDao
.
findList
(
dto
);
return
Result
.
success
(
aiDefaultQuestionList
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"data"
,
aiDefaultQuestionList
);
//查询ai机器人简介
AiAssistant
aiAssistant
=
aiAssistantDao
.
findByType
(
dto
.
getType
());
map
.
put
(
"profile"
,
aiAssistant
.
getProfile
());
//一小时内打开会话不重复返回默认问题
redisUtils
.
set
(
key
,
null
,
1
,
TimeUnit
.
HOURS
);
return
Result
.
success
(
map
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
logger
.
error
(
"查询ai默认问题列表error : {}"
,
e
);
logger
.
error
(
"查询ai默认问题列表error : {}"
,
e
);
}
}
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/IMServiceImpl.java
View file @
4319e361
...
@@ -7,6 +7,7 @@ import com.wwdz.ch.core.im.api.ConversationApi;
...
@@ -7,6 +7,7 @@ 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.domain.AiAssistant
;
import
com.wwdz.ch.db.domain.AiAssistant
;
import
com.wwdz.ch.wx.api.ChatApi
;
import
com.wwdz.ch.wx.api.ChatApi
;
...
@@ -18,6 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -18,6 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.concurrent.TimeUnit
;
/**
/**
* 会话
* 会话
...
@@ -42,6 +44,9 @@ public class IMServiceImpl implements IMService {
...
@@ -42,6 +44,9 @@ public class IMServiceImpl implements IMService {
@Autowired
@Autowired
ChatApi
chatApi
;
ChatApi
chatApi
;
@Autowired
RedisUtils
redisUtils
;
/**
/**
* 新增ai会话,发送默认打招呼的消息
* 新增ai会话,发送默认打招呼的消息
* @param dto
* @param dto
...
@@ -119,6 +124,11 @@ public class IMServiceImpl implements IMService {
...
@@ -119,6 +124,11 @@ public class IMServiceImpl implements IMService {
answerDto
.
setToAccount
(
dto
.
getFromAccount
());
answerDto
.
setToAccount
(
dto
.
getFromAccount
());
answerDto
.
setMsgType
(
IMEnum
.
MsgTypeEnum
.
TIMTextElem
.
getCode
());
answerDto
.
setMsgType
(
IMEnum
.
MsgTypeEnum
.
TIMTextElem
.
getCode
());
answerDto
.
setMsgContent
(
answer
);
answerDto
.
setMsgContent
(
answer
);
//判断该AI回答是否已被停止
if
(
redisUtils
.
hasKey
(
dto
.
getReqId
())){
return
Result
.
success
(
"回答已被终止"
);
}
Result
answerResult
=
conversationApi
.
sendChatMsg
(
answerDto
);
Result
answerResult
=
conversationApi
.
sendChatMsg
(
answerDto
);
if
(!
answerResult
.
getSuccess
())
{
if
(!
answerResult
.
getSuccess
())
{
logger
.
info
(
"=============== 发送问题的ai答复消息失败 ============="
);
logger
.
info
(
"=============== 发送问题的ai答复消息失败 ============="
);
...
@@ -127,10 +137,17 @@ public class IMServiceImpl implements IMService {
...
@@ -127,10 +137,17 @@ public class IMServiceImpl implements IMService {
}
else
{
}
else
{
return
Result
.
failed
(
"目前尚不支持除文本外的消息发送"
);
return
Result
.
failed
(
"目前尚不支持除文本外的消息发送"
);
}
}
logger
.
info
(
"=============== AI的回答信息发送成功 ==============="
);
return
Result
.
success
();
return
Result
.
success
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
logger
.
error
(
"发送聊天消息失败:{}"
,
e
);
logger
.
error
(
"发送聊天消息失败:{}"
,
e
);
}
}
return
Result
.
failed
();
return
Result
.
failed
();
}
}
@Override
public
Result
stopAiAnswer
(
SendChatMsgRequestDto
dto
)
{
redisUtils
.
set
(
dto
.
getReqId
(),
false
,
10
,
TimeUnit
.
SECONDS
);
return
Result
.
success
();
}
}
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/UserServiceImpl.java
View file @
4319e361
...
@@ -2,6 +2,7 @@ package com.wwdz.ch.wx.impl;
...
@@ -2,6 +2,7 @@ package com.wwdz.ch.wx.impl;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.wwdz.ch.core.consts.ResultCode
;
import
com.wwdz.ch.core.consts.ResultCode
;
import
com.wwdz.ch.core.im.api.ChatUserApi
;
import
com.wwdz.ch.core.notify.AliSmsSender
;
import
com.wwdz.ch.core.notify.AliSmsSender
;
import
com.wwdz.ch.core.notify.NotifyService
;
import
com.wwdz.ch.core.notify.NotifyService
;
import
com.wwdz.ch.core.notify.SmsResult
;
import
com.wwdz.ch.core.notify.SmsResult
;
...
@@ -55,7 +56,8 @@ public class UserServiceImpl implements UserService {
...
@@ -55,7 +56,8 @@ public class UserServiceImpl implements UserService {
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
UserServiceImpl
.
class
);
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
UserServiceImpl
.
class
);
//默认的ai机器人编码,用于ai助手的聊天,该机器人永远在会话列表中置顶
//默认的ai机器人编码,用于ai助手的聊天,该机器人永远在会话列表中置顶
private
static
final
String
DEFAULT_AI_CODE
=
"ai10000"
;
@Value
(
"${dts.im.default-ai-code}"
)
private
String
DEFAULT_AI_CODE
;
@Autowired
@Autowired
private
UserDao
userDao
;
private
UserDao
userDao
;
...
@@ -63,32 +65,42 @@ public class UserServiceImpl implements UserService {
...
@@ -63,32 +65,42 @@ public class UserServiceImpl implements UserService {
private
UserTokenManager
userTokenManager
;
private
UserTokenManager
userTokenManager
;
@Autowired
@Autowired
private
NotifyService
notifyService
;
private
NotifyService
notifyService
;
@Autowired
@Autowired
private
ApplicationContext
applicationContext
;
private
ApplicationContext
applicationContext
;
@Autowired
@Autowired
private
WxLoginManager
wxLoginManager
;
private
WxLoginManager
wxLoginManager
;
@Autowired
@Autowired
private
AlipayLoginManager
alipayLoginManager
;
private
AlipayLoginManager
alipayLoginManager
;
@Autowired
@Autowired
private
TikTokLoginManager
tikTokLoginManager
;
private
TikTokLoginManager
tikTokLoginManager
;
@Autowired
@Autowired
private
RedisUtil
redisUtil
;
private
RedisUtil
redisUtil
;
@Value
(
"${avatar-url}"
)
@Value
(
"${avatar-url}"
)
private
String
avatarUrl
;
private
String
avatarUrl
;
@Autowired
@Autowired
private
AliSmsSender
aliSmsSender
;
private
AliSmsSender
aliSmsSender
;
@Autowired
@Autowired
private
InviteRecordService
inviteRecordService
;
private
InviteRecordService
inviteRecordService
;
@Autowired
@Autowired
private
SwitchService
switchService
;
private
SwitchService
switchService
;
@Autowired
@Autowired
private
ItemCommonService
itemCommonService
;
private
ItemCommonService
itemCommonService
;
@Autowired
@Autowired
private
FollowFansRecordService
followFansRecordService
;
private
FollowFansRecordService
followFansRecordService
;
@Autowired
ChatUserApi
chatUserApi
;
@Override
@Override
...
@@ -508,6 +520,12 @@ public class UserServiceImpl implements UserService {
...
@@ -508,6 +520,12 @@ public class UserServiceImpl implements UserService {
user
.
setLastLoginIp
(
IpUtil
.
client
(
request
));
user
.
setLastLoginIp
(
IpUtil
.
client
(
request
));
user
.
setShareUserId
(
0L
);
user
.
setShareUserId
(
0L
);
userDao
.
insert
(
user
);
userDao
.
insert
(
user
);
//把新增用户同步到IM
Result
synUserResult
=
chatUserApi
.
importUser
(
user
);
if
(
synUserResult
.
getSuccess
())
{
logger
.
info
(
"新增用户同步至IM成功"
);
}
}
else
{
}
else
{
// 注册过的用户修改最后登录的时间以及绑定微信openid和支付宝user_id
// 注册过的用户修改最后登录的时间以及绑定微信openid和支付宝user_id
if
(
org
.
springframework
.
util
.
StringUtils
.
hasLength
(
dto
.
getWxOpenId
()))
{
if
(
org
.
springframework
.
util
.
StringUtils
.
hasLength
(
dto
.
getWxOpenId
()))
{
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/service/IMService.java
View file @
4319e361
...
@@ -43,4 +43,10 @@ public interface IMService {
...
@@ -43,4 +43,10 @@ public interface IMService {
* @return
* @return
*/
*/
Result
sendAiChatMsg
(
SendChatMsgRequestDto
dto
);
Result
sendAiChatMsg
(
SendChatMsgRequestDto
dto
);
/**
* 停止AI回答
*/
Result
stopAiAnswer
(
SendChatMsgRequestDto
dto
);
}
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/web/IMController.java
View file @
4319e361
...
@@ -87,6 +87,17 @@ public class IMController {
...
@@ -87,6 +87,17 @@ public class IMController {
}
}
return
imService
.
sendAiChatMsg
(
dto
);
return
imService
.
sendAiChatMsg
(
dto
);
}
}
@ApiOperation
(
value
=
"停止ai回答"
)
@PostMapping
(
"/stopAiAnswer"
)
public
Result
stopAiAnswer
(
@RequestBody
SendChatMsgRequestDto
dto
)
{
logger
.
info
(
"【请求开始】停止ai回答,请求参数:{}"
,
JSON
.
toJSONString
(
dto
));
if
(
StringUtils
.
isEmpty
(
dto
.
getReqId
()))
{
return
Result
.
failed
(
"reqId不能为空"
);
}
return
imService
.
stopAiAnswer
(
dto
);
}
}
}
ch-wx-api/src/test/java/com/wwdz/ch/wx/api/ChatApiTest.java
View file @
4319e361
...
@@ -90,7 +90,7 @@ public class ChatApiTest {
...
@@ -90,7 +90,7 @@ public class ChatApiTest {
public
void
sendChatMsg
()
{
public
void
sendChatMsg
()
{
SendChatMsgRequestDto
sendChatMsgRequestDto
=
new
SendChatMsgRequestDto
();
SendChatMsgRequestDto
sendChatMsgRequestDto
=
new
SendChatMsgRequestDto
();
sendChatMsgRequestDto
.
setToAccount
(
"241"
);
sendChatMsgRequestDto
.
setToAccount
(
"241"
);
sendChatMsgRequestDto
.
setFromAccount
(
"
ai10000
"
);
sendChatMsgRequestDto
.
setFromAccount
(
"
273
"
);
sendChatMsgRequestDto
.
setMsgType
(
IMEnum
.
MsgTypeEnum
.
TIMTextElem
.
getCode
());
sendChatMsgRequestDto
.
setMsgType
(
IMEnum
.
MsgTypeEnum
.
TIMTextElem
.
getCode
());
long
timestamp
=
System
.
currentTimeMillis
();
long
timestamp
=
System
.
currentTimeMillis
();
String
msgContent
=
timestamp
+
" >> ai测试消息的数据, 是否可以接收到"
;
String
msgContent
=
timestamp
+
" >> ai测试消息的数据, 是否可以接收到"
;
...
...
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