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
0d550166
Commit
0d550166
authored
Oct 23, 2023
by
shiyu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ai会话保存消息记录
parent
62940cc7
Changes
12
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
2360 additions
and
3 deletions
+2360
-3
ch-core/src/main/java/com/wwdz/ch/core/consts/IMEnum.java
ch-core/src/main/java/com/wwdz/ch/core/consts/IMEnum.java
+38
-0
ch-dao/src/main/java/com/wwdz/ch/db/dao/ImRecordDao.java
ch-dao/src/main/java/com/wwdz/ch/db/dao/ImRecordDao.java
+9
-0
ch-dao/src/main/java/com/wwdz/ch/db/domain/ImRecord.java
ch-dao/src/main/java/com/wwdz/ch/db/domain/ImRecord.java
+327
-0
ch-dao/src/main/java/com/wwdz/ch/db/domain/ImRecordExample.java
.../src/main/java/com/wwdz/ch/db/domain/ImRecordExample.java
+1785
-0
ch-dao/src/main/java/com/wwdz/ch/db/impl/ImRecordDaoImpl.java
...ao/src/main/java/com/wwdz/ch/db/impl/ImRecordDaoImpl.java
+20
-0
ch-dao/src/main/java/com/wwdz/ch/db/mapper/ImRecordMapper.java
...o/src/main/java/com/wwdz/ch/db/mapper/ImRecordMapper.java
+84
-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/api/IMCallbackController.java
...rc/main/java/com/wwdz/ch/wx/api/IMCallbackController.java
+11
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/config/WebMvcConfiguration.java
.../main/java/com/wwdz/ch/wx/config/WebMvcConfiguration.java
+1
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/ImRecordServiceImpl.java
...rc/main/java/com/wwdz/ch/wx/impl/ImRecordServiceImpl.java
+31
-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
+44
-2
ch-wx-api/src/main/java/com/wwdz/ch/wx/service/ImRecordService.java
...src/main/java/com/wwdz/ch/wx/service/ImRecordService.java
+9
-0
No files found.
ch-core/src/main/java/com/wwdz/ch/core/consts/IMEnum.java
View file @
0d550166
...
...
@@ -81,4 +81,42 @@ public class IMEnum {
return
des
;
}
}
/**
* 消息状态
*/
public
enum
MsgStateEnum
{
UNREAD
(
1
,
"未读"
),
READED
(
2
,
"已读"
),
REVOKE
(
3
,
"撤回"
),
FAILED
(
10
,
"发送失败"
),
;
private
int
code
;
private
String
des
;
MsgStateEnum
(
int
code
,
String
des
)
{
this
.
code
=
code
;
this
.
des
=
des
;
}
public
static
String
getNameByCode
(
int
code
)
{
for
(
IMEnum
.
MsgStateEnum
msgStateEnum
:
IMEnum
.
MsgStateEnum
.
values
())
{
if
(
code
==
msgStateEnum
.
getCode
())
{
return
msgStateEnum
.
getDes
();
}
}
return
null
;
}
public
int
getCode
()
{
return
code
;
}
public
String
getDes
()
{
return
des
;
}
}
}
ch-dao/src/main/java/com/wwdz/ch/db/dao/ImRecordDao.java
0 → 100644
View file @
0d550166
package
com.wwdz.ch.db.dao
;
import
com.wwdz.ch.db.domain.ImRecord
;
public
interface
ImRecordDao
{
boolean
create
(
ImRecord
imRecord
);
}
ch-dao/src/main/java/com/wwdz/ch/db/domain/ImRecord.java
0 → 100644
View file @
0d550166
This diff is collapsed.
Click to expand it.
ch-dao/src/main/java/com/wwdz/ch/db/domain/ImRecordExample.java
0 → 100644
View file @
0d550166
This diff is collapsed.
Click to expand it.
ch-dao/src/main/java/com/wwdz/ch/db/impl/ImRecordDaoImpl.java
0 → 100644
View file @
0d550166
package
com.wwdz.ch.db.impl
;
import
com.wwdz.ch.db.dao.ImRecordDao
;
import
com.wwdz.ch.db.domain.ImRecord
;
import
com.wwdz.ch.db.mapper.ImRecordMapper
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Repository
;
@Repository
public
class
ImRecordDaoImpl
implements
ImRecordDao
{
@Autowired
ImRecordMapper
imRecordMapper
;
@Override
public
boolean
create
(
ImRecord
imRecord
)
{
return
imRecordMapper
.
insert
(
imRecord
)
>
0
;
}
}
ch-dao/src/main/java/com/wwdz/ch/db/mapper/ImRecordMapper.java
0 → 100644
View file @
0d550166
package
com.wwdz.ch.db.mapper
;
import
com.wwdz.ch.db.domain.ImRecord
;
import
com.wwdz.ch.db.domain.ImRecordExample
;
import
java.util.List
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
@Mapper
public
interface
ImRecordMapper
{
long
countByExample
(
ImRecordExample
example
);
int
deleteByExample
(
ImRecordExample
example
);
int
deleteByPrimaryKey
(
Long
id
);
int
insert
(
ImRecord
record
);
int
insertSelective
(
ImRecord
record
);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table im_record
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
ImRecord
selectOneByExample
(
ImRecordExample
example
);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table im_record
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
ImRecord
selectOneByExampleSelective
(
@Param
(
"example"
)
ImRecordExample
example
,
@Param
(
"selective"
)
ImRecord
.
Column
...
selective
);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table im_record
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
ImRecord
selectOneByExampleWithBLOBs
(
ImRecordExample
example
);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table im_record
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
List
<
ImRecord
>
selectByExampleSelective
(
@Param
(
"example"
)
ImRecordExample
example
,
@Param
(
"selective"
)
ImRecord
.
Column
...
selective
);
List
<
ImRecord
>
selectByExampleWithBLOBs
(
ImRecordExample
example
);
List
<
ImRecord
>
selectByExample
(
ImRecordExample
example
);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table im_record
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
ImRecord
selectByPrimaryKeySelective
(
@Param
(
"id"
)
Long
id
,
@Param
(
"selective"
)
ImRecord
.
Column
...
selective
);
ImRecord
selectByPrimaryKey
(
Long
id
);
int
updateByExampleSelective
(
@Param
(
"record"
)
ImRecord
record
,
@Param
(
"example"
)
ImRecordExample
example
);
int
updateByExampleWithBLOBs
(
@Param
(
"record"
)
ImRecord
record
,
@Param
(
"example"
)
ImRecordExample
example
);
int
updateByExample
(
@Param
(
"record"
)
ImRecord
record
,
@Param
(
"example"
)
ImRecordExample
example
);
int
updateByPrimaryKeySelective
(
ImRecord
record
);
int
updateByPrimaryKeyWithBLOBs
(
ImRecord
record
);
int
updateByPrimaryKey
(
ImRecord
record
);
}
\ No newline at end of file
ch-dao/src/main/resources/generatorConfig_new.xml
View file @
0d550166
...
...
@@ -72,7 +72,7 @@
<javaClientGenerator
type=
"XMLMAPPER"
targetPackage=
"com.wwdz.ch.db.mapper"
targetProject=
"ch-dao/src/main/java"
/>
<table
tableName=
"
ai_assistant
"
enableCountByExample=
"true"
enableUpdateByExample=
"true"
enableDeleteByExample=
"true"
enableSelectByExample=
"true"
selectByExampleQueryId=
"true"
>
<table
tableName=
"
im_record
"
enableCountByExample=
"true"
enableUpdateByExample=
"true"
enableDeleteByExample=
"true"
enableSelectByExample=
"true"
selectByExampleQueryId=
"true"
>
<generatedKey
column=
"id"
sqlStatement=
"Mysql"
identity=
"true"
/>
</table>
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/api/IMCallbackController.java
0 → 100644
View file @
0d550166
package
com.wwdz.ch.wx.api
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
@RestController
@RequestMapping
(
"/imCallback"
)
public
class
IMCallbackController
{
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/config/WebMvcConfiguration.java
View file @
0d550166
...
...
@@ -40,6 +40,7 @@ public class WebMvcConfiguration implements WebMvcConfigurer {
.
excludePathPatterns
(
"/*.html"
,
"/**/*.html"
,
"/**/*.css"
,
"/**/*.js"
,
"/wx/user/loginByWx"
,
"/wx/user/loginByMobile"
,
"/wx/user/loginRegCaptcha"
,
"/wx/user/updateRegCaptcha"
,
"/wx/user/login"
,
"/wx/user/fillCode"
,
"/officialAccountCallback/**"
,
"/imCallback/**"
,
"/wx/officialAccount/**"
,
"/wx/item/**"
,
"/wx/aiAssistant/**"
,
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/ImRecordServiceImpl.java
0 → 100644
View file @
0d550166
package
com.wwdz.ch.wx.impl
;
import
com.wwdz.ch.core.type.Result
;
import
com.wwdz.ch.db.dao.ImRecordDao
;
import
com.wwdz.ch.db.domain.ImRecord
;
import
com.wwdz.ch.wx.service.ImRecordService
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
@Service
public
class
ImRecordServiceImpl
implements
ImRecordService
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ImRecordServiceImpl
.
class
);
@Autowired
ImRecordDao
imRecordDao
;
@Override
public
Result
create
(
ImRecord
imRecord
)
{
try
{
imRecordDao
.
create
(
imRecord
);
return
Result
.
success
();
}
catch
(
Exception
e
)
{
logger
.
info
(
"保存聊天消息error : {}"
,
e
);
}
return
Result
.
failed
();
}
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/I
M
ServiceImpl.java
→
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/I
m
ServiceImpl.java
View file @
0d550166
...
...
@@ -9,14 +9,19 @@ import com.wwdz.ch.core.type.Result;
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.ImRecordDao
;
import
com.wwdz.ch.db.domain.AiAssistant
;
import
com.wwdz.ch.db.domain.ImRecord
;
import
com.wwdz.ch.wx.api.ChatApi
;
import
com.wwdz.ch.wx.service.IMService
;
import
com.wwdz.ch.wx.service.ImRecordService
;
import
com.xxdxxs.utils.JsonUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.concurrent.TimeUnit
;
...
...
@@ -25,9 +30,9 @@ import java.util.concurrent.TimeUnit;
* 会话
*/
@Service
public
class
I
M
ServiceImpl
implements
IMService
{
public
class
I
m
ServiceImpl
implements
IMService
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
I
M
ServiceImpl
.
class
);
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
I
m
ServiceImpl
.
class
);
@Autowired
ConversationApi
conversationApi
;
...
...
@@ -47,6 +52,9 @@ public class IMServiceImpl implements IMService {
@Autowired
RedisUtils
redisUtils
;
@Autowired
ImRecordService
imRecordService
;
/**
* 新增ai会话,发送默认打招呼的消息
* @param dto
...
...
@@ -112,6 +120,25 @@ public class IMServiceImpl implements IMService {
if
(!
askResult
.
getSuccess
())
{
return
askResult
;
}
//保存提问的消息记录
ImRecord
imRecord
=
new
ImRecord
();
imRecord
.
setFromAccount
(
dto
.
getFromAccount
());
imRecord
.
setToAccount
(
dto
.
getToAccount
());
imRecord
.
setMsgType
(
dto
.
getMsgType
());
//0:成功
imRecord
.
setSendMsgResult
(
0
);
if
(
IMEnum
.
MsgTypeEnum
.
TIMTextElem
.
getCode
()
==
dto
.
getMsgType
())
{
imRecord
.
setMsgContent
(
dto
.
getMsgContent
().
toString
());
}
Date
now
=
new
Date
();
imRecord
.
setMsgTime
(
now
);
imRecord
.
setOnlineOnlyFlag
(
0
);
imRecord
.
setCreateTime
(
now
);
imRecord
.
setUpdateTime
(
now
);
imRecord
.
setState
(
IMEnum
.
MsgStateEnum
.
READED
.
getCode
());
imRecordService
.
create
(
imRecord
);
logger
.
info
(
"=========== userid:{}, 提问ai的消息发送成功 =========="
,
dto
.
getFromAccount
());
if
(
dto
.
getMsgType
()
==
IMEnum
.
MsgTypeEnum
.
TIMTextElem
.
getCode
())
{
String
question
=
(
String
)
dto
.
getMsgContent
();
...
...
@@ -134,6 +161,21 @@ public class IMServiceImpl implements IMService {
logger
.
info
(
"=============== 发送问题的ai答复消息失败 ============="
);
return
answerResult
;
}
//保存ai回答的消息记录
ImRecord
answerImRecord
=
new
ImRecord
();
answerImRecord
.
setFromAccount
(
dto
.
getToAccount
());
answerImRecord
.
setToAccount
(
dto
.
getFromAccount
());
answerImRecord
.
setMsgType
(
IMEnum
.
MsgTypeEnum
.
TIMTextElem
.
getCode
());
answerImRecord
.
setMsgContent
(
answer
);
answerImRecord
.
setOnlineOnlyFlag
(
0
);
Date
answerTime
=
new
Date
();
answerImRecord
.
setSendMsgResult
(
0
);
answerImRecord
.
setMsgTime
(
answerTime
);
answerImRecord
.
setCreateTime
(
answerTime
);
answerImRecord
.
setUpdateTime
(
answerTime
);
answerImRecord
.
setState
(
IMEnum
.
MsgStateEnum
.
READED
.
getCode
());
imRecordService
.
create
(
answerImRecord
);
}
else
{
return
Result
.
failed
(
"目前尚不支持除文本外的消息发送"
);
}
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/service/ImRecordService.java
0 → 100644
View file @
0d550166
package
com.wwdz.ch.wx.service
;
import
com.wwdz.ch.core.type.Result
;
import
com.wwdz.ch.db.domain.ImRecord
;
public
interface
ImRecordService
{
Result
create
(
ImRecord
imRecord
);
}
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