Commit ee74ac5c by chenxianqi

updatecode

parent f64ed92d
......@@ -17,7 +17,7 @@ func Run() {
imDataSource = beego.AppConfig.String("kf_mysql_user") + ":"
imDataSource += beego.AppConfig.String("kf_mysql_pwd")
imDataSource += "@tcp(" + beego.AppConfig.String("kf_mysql_host")
imDataSource += ":" + beego.AppConfig.String("kf_mysql_port") + ")/"
imDataSource += ":" + beego.AppConfig.String("kf_mysql_port") + ")/"
imDataSource += beego.AppConfig.String("kf_mysql_db") + "?charset=utf8"
_ = orm.RegisterDataBase(imAliasName, imDriverName, imDataSource, 30)
......@@ -28,6 +28,7 @@ func Run() {
orm.RegisterModel(new(models.KnowledgeBase))
orm.RegisterModel(new(models.Robot))
orm.RegisterModel(new(models.Message))
orm.RegisterModel(new(models.MessageHistory))
orm.RegisterModel(new(models.System))
orm.RegisterModel(new(models.Shortcut))
orm.RegisterModel(new(models.Contact))
......
......@@ -11,7 +11,7 @@ package models
// 7 pong 对方正在输入中
// 8 end 结束消息
// 9 timeout 超时会话关闭
// 10 cancel 撤回消息(暂时还没做预留先)
// 10 cancel 撤回消息
// 11 contacts 用户列表(客服端)
// 12 welcome 欢迎语
// 13 system 系统消息
......@@ -24,6 +24,7 @@ type Message struct {
BizType string `orm:"type(char);column(biz_type)" json:"biz_type"` // 消息类型
Version string `orm:"default(0);type(char);column(version)" json:"version"` // 版本号,预留暂时无用
Timestamp int64 `orm:"type(bigint);column(timestamp)" json:"timestamp"` // 服务端消息消息时间
Sequence int64 `orm:"type(bigint);column(sequence)" json:"sequence"` // 消息入库时间
Key int64 `orm:"type(bigint);column(key)" json:"key"` // key
TransferAccount int64 `orm:"type(bigint);column(transfer_account)" json:"transfer_account"` // 转接到客户的账号
Platform int64 `orm:"type(bigint);column(platform)" json:"platform"` // 此消息来自哪个平台(即渠道)
......
package models
// MessageHistory struct
// BizType 消息类型 先以字符串形式声明吧
// 1 video 视频
// 2 text 文本
// 3 photo 图片
// 4 transfer 转接
// 5 knowledge 知识内容
// 6 handshake 用户请求与握手
// 7 pong 对方正在输入中
// 8 end 结束消息
// 9 timeout 超时会话关闭
// 10 cancel 撤回消息
// 11 contacts 用户列表(客服端)
// 12 welcome 欢迎语
// 13 system 系统消息
// 14 search_knowledge 检索关键词知识库消息
// 15 key 消息key
type MessageHistory struct {
ID int64 `orm:"auto;pk;column(id)" json:"id"` // 消息ID
FromAccount int64 `orm:"type(bigint);column(from_account)" json:"from_account"` // 发送人账号
ToAccount int64 `orm:"type(bigint);column(to_account)" json:"to_account"` // 接收人账号
BizType string `orm:"type(char);column(biz_type)" json:"biz_type"` // 消息类型
Version string `orm:"default(0);type(char);column(version)" json:"version"` // 版本号,预留暂时无用
Timestamp int64 `orm:"type(bigint);column(timestamp)" json:"timestamp"` // 服务端消息消息时间
Sequence int64 `orm:"type(bigint);column(sequence)" json:"sequence"` // 消息入库时间
Key int64 `orm:"type(bigint);column(key)" json:"key"` // key
TransferAccount int64 `orm:"type(bigint);column(transfer_account)" json:"transfer_account"` // 转接到客户的账号
Platform int64 `orm:"type(bigint);column(platform)" json:"platform"` // 此消息来自哪个平台(即渠道)
Payload string `orm:"null;type(text);column(payload)" json:"payload"` // 消息内容
Read int `orm:"default(0);column(read)" json:"read"` // 是否已读消息0已读1未读
}
......@@ -43,4 +43,4 @@
top:0 !important;
min-height: inherit!important;
left:0 !important; right:0 !important; bottom:0 !important; margin: auto !important;
}</style><link href=css/chunk-5853fee7.c946f43e.css rel=prefetch><link href=css/chunk-5abde09c.21a06077.css rel=prefetch><link href=css/chunk-5e6009ff.86cb9867.css rel=prefetch><link href=css/chunk-fc784ea6.548345db.css rel=prefetch><link href=js/chunk-5853fee7.2146cb38.js rel=prefetch><link href=js/chunk-5abde09c.95818801.js rel=prefetch><link href=js/chunk-5e6009ff.ea6c5b91.js rel=prefetch><link href=js/chunk-fc784ea6.1fe629b4.js rel=prefetch><link href=css/app.19de1655.css rel=preload as=style><link href=css/chunk-vendors.5cea36ab.css rel=preload as=style><link href=js/app.4b73fc40.js rel=preload as=script><link href=js/chunk-vendors.a823ad66.js rel=preload as=script><link href=css/chunk-vendors.5cea36ab.css rel=stylesheet><link href=css/app.19de1655.css rel=stylesheet></head><body><noscript><strong>We're sorry but m doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=js/chunk-vendors.a823ad66.js></script><script src=js/app.4b73fc40.js></script></body></html>
\ No newline at end of file
}</style><link href=css/chunk-5853fee7.c946f43e.css rel=prefetch><link href=css/chunk-5abde09c.21a06077.css rel=prefetch><link href=css/chunk-5e6009ff.86cb9867.css rel=prefetch><link href=css/chunk-fc784ea6.548345db.css rel=prefetch><link href=js/chunk-5853fee7.2146cb38.js rel=prefetch><link href=js/chunk-5abde09c.95818801.js rel=prefetch><link href=js/chunk-5e6009ff.1088ebcb.js rel=prefetch><link href=js/chunk-fc784ea6.1fe629b4.js rel=prefetch><link href=css/app.19de1655.css rel=preload as=style><link href=css/chunk-vendors.5cea36ab.css rel=preload as=style><link href=js/app.2783e17d.js rel=preload as=script><link href=js/chunk-vendors.a823ad66.js rel=preload as=script><link href=css/chunk-vendors.5cea36ab.css rel=stylesheet><link href=css/app.19de1655.css rel=stylesheet></head><body><noscript><strong>We're sorry but m doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=js/chunk-vendors.a823ad66.js></script><script src=js/app.2783e17d.js></script></body></html>
\ No newline at end of file
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
package services
import (
"encoding/base64"
"kefu_server/models"
"strconv"
"time"
"github.com/astaxie/beego/logs"
"github.com/astaxie/beego/orm"
......@@ -18,6 +18,7 @@ type MessageRepositoryInterface interface {
GetReadCount(uid int64) (int64, error)
ClearRead(uid int64) (int64, error)
DeleteWhiteMessage(uids []int) int
MoveMessageToHistory() int64
Cancel(fromAccount int64, toAccount int64, key int64) error
}
......@@ -55,6 +56,15 @@ func (r *MessageRepository) Add(message *models.Message) (int64, error) {
return row, err
}
// GetReadCount message read count
func (r *MessageRepository) GetReadCount(uid int64) (int64, error) {
count, err := r.q.Filter("to_account", uid).Filter("read", 1).Count()
if err != nil {
logs.Warn("Add add a message------------", err)
}
return count, err
}
// ClearRead Clear message read
func (r *MessageRepository) ClearRead(uid int64) (int64, error) {
index, err := r.q.Filter("to_account", uid).Update(orm.Params{
......@@ -66,19 +76,32 @@ func (r *MessageRepository) ClearRead(uid int64) (int64, error) {
return index, err
}
// GetReadCount message read count
func (r *MessageRepository) GetReadCount(uid int64) (int64, error) {
count, err := r.q.Filter("to_account", uid).Filter("read", 1).Count()
// MoveMessageToHistory move message history table
func (r *MessageRepository) MoveMessageToHistory() int64 {
fields := "`from_account`,`to_account`,`biz_type`,`version`,`timestamp`,`sequence`,`key`,`transfer_account`,`platform`,`payload`,`read`"
timestampMax := time.Now().Unix() - int64(60*60*24*1) // 30 day
res, err := r.o.Raw("INSERT INTO message_history("+fields+") SELECT "+fields+" FROM message WHERE timestamp < ?", timestampMax).Exec()
if err != nil {
logs.Warn("Add add a message------------", err)
logs.Warn("MoveMessageToHistory move message history table1------------", err)
}
return count, err
rows, _ := res.RowsAffected()
if rows > 0 {
r.q.Filter("timestamp__lt", timestampMax).Delete()
}
if err != nil {
logs.Warn("MoveMessageToHistory move message history table2------------", err)
}
return rows
}
// Delete delete a message
func (r *MessageRepository) Delete(removeRequestDto models.RemoveMessageRequestDto) (int64, error) {
res, err := r.o.Raw("DELETE FROM `message` WHERE from_account = ? AND to_account = ? AND `key` = ?", removeRequestDto.FromAccount, removeRequestDto.ToAccount, removeRequestDto.Key).Exec()
row, _ := res.RowsAffected()
if row == 0 {
r.o.Raw("DELETE FROM `message_history` WHERE from_account = ? AND to_account = ? AND `key` = ?", removeRequestDto.FromAccount, removeRequestDto.ToAccount, removeRequestDto.Key).Exec()
}
if err != nil {
logs.Warn("Delete delete a message------------", err)
return 0, err
......@@ -110,7 +133,7 @@ func (r *MessageRepository) GetUserMessages(messagePaginationDto models.MessageP
start = 0
}
if messageCount.Count > 0 {
_, err := r.o.Raw("SELECT * FROM `message` WHERE (`to_account` = ? OR `from_account` = ?) AND `timestamp` < ? ORDER BY `timestamp` ASC LIMIT ?,?", uid, uid, timestamp, start, end).QueryRows(&messages)
_, err := r.o.Raw("SELECT * FROM `message` WHERE (`to_account` = ? OR `from_account` = ?) AND `timestamp` < ? ORDER BY `sequence` ASC LIMIT ?,?", uid, uid, timestamp, start, end).QueryRows(&messages)
if err != nil {
logs.Warn("GetUserMessages get user messages1------------", err)
return nil, err
......@@ -127,10 +150,6 @@ func (r *MessageRepository) GetUserMessages(messagePaginationDto models.MessageP
messagePaginationDto.List = []models.Message{}
messagePaginationDto.Total = 0
}
for index, msg := range messages {
payload, _ := base64.StdEncoding.DecodeString(msg.Payload)
messages[index].Payload = string(payload)
}
return &messagePaginationDto, nil
}
......@@ -169,7 +188,7 @@ func (r *MessageRepository) GetAdminMessages(messagePaginationDto models.Message
}
if msgCount > 0 {
_, err = r.o.Raw("SELECT * FROM `message` WHERE to_account IN ("+inExp+") AND from_account IN ("+inExp+") AND `timestamp` < ? ORDER BY `timestamp` ASC LIMIT ?,?", accounts, accounts, messagePaginationDto.Timestamp, start, end).QueryRows(&messages)
_, err = r.o.Raw("SELECT * FROM `message` WHERE to_account IN ("+inExp+") AND from_account IN ("+inExp+") AND `timestamp` < ? ORDER BY `sequence` ASC LIMIT ?,?", accounts, accounts, messagePaginationDto.Timestamp, start, end).QueryRows(&messages)
if err != nil {
logs.Warn("GetMessages get one service message list2------------", err)
return nil, err
......@@ -186,9 +205,5 @@ func (r *MessageRepository) GetAdminMessages(messagePaginationDto models.Message
messagePaginationDto.List = []models.Message{}
messagePaginationDto.Total = 0
}
for index, msg := range messages {
payload, _ := base64.StdEncoding.DecodeString(msg.Payload)
messages[index].Payload = string(payload)
}
return &messagePaginationDto, nil
}
......@@ -19,4 +19,5 @@ func clearUser() {
return nil
})
toolbox.AddTask("clearUser", clearUserTk)
}
......@@ -9,4 +9,7 @@ func Run() {
// ClearUser
clearUser()
// moveMessage
moveMessage()
}
package task
import (
"kefu_server/services"
"github.com/astaxie/beego/logs"
"github.com/astaxie/beego/toolbox"
)
// moveMessage tk
func moveMessage() {
// moveMessage day at 5 am
moveMessageTk := toolbox.NewTask("moveMessage", "0 0 05 * * * ", func() error {
length := services.GetMessageRepositoryInstance().MoveMessageToHistory()
logs.Info("定时迁移了", length, "条消息记录到历史表~")
return nil
})
toolbox.AddTask("moveMessage", moveMessageTk)
}
......@@ -115,10 +115,10 @@ export default {
self.$store.commit("onChangeMimcUser", self.$mimcInstance.user)
})
}else if(self.$store.getters.adminInfo.online != 0){
setTimeout(() => self.watchLogin(), 1000)
setTimeout(() => self.watchLogin(), 2000)
}
}catch(err){
setTimeout(() => this.watchLogin(), 1000)
setTimeout(() => this.watchLogin(), 2000)
}
},
},
......
......@@ -328,6 +328,7 @@ export default {
if(!status){
this.$store.dispatch('ON_GET_ME').then(()=>{
if(this.adminInfo.online != 0){
this.onLongTraining()
this.init();
}
})
......@@ -340,9 +341,11 @@ export default {
// 监听连接断开
this.$mimcInstance.addEventListener("disconnect", () => {
console.log("链接断开!")
this.isLogin = false;
this.onLongTraining()
var adminInfo = this.adminInfo
if(adminInfo.online != 0){
this.adminInfo = null;
this.$store.commit("onChangeAdminInfo", null)
this.init();
}else{
adminInfo.online = 0
......@@ -350,6 +353,16 @@ export default {
}
})
},
// onLongTraining
onLongTraining(){
if(this.$mimcInstance.user.isLogin()) return
console.log("长轮训获取新消息..")
// 获取聊天记录
this.$store.dispatch('ON_GET_CONTACTS')
this.getMessageRecord()
this.scrollIntoBottom()
setTimeout(()=> this.onLongTraining(), 2000)
},
// 刷新鼠标动态 mousemove
onMousemoveEvent(){
// 以下其他浏览器的聊天高度
......@@ -756,15 +769,19 @@ export default {
"account": account
})
.then(response => {
let messages = response.data.data.list
for(var i=0; i<messages.length; i++){
messages[i].payload = window.Base64.decode(messages[i].payload)
}
this.getMessageRecordLoading = false
if(response.data.data.list.length < this.getMessageRecordPageSize){
if(messages.length < this.getMessageRecordPageSize){
this.isMessageEnd = true
}
if(this.messageRecord.list.length == 0 || timestamp == 0){
this.$store.commit("onChangeMessageRecord", response.data.data)
this.scrollIntoBottom()
}else{
response.data.data.list = response.data.data.list.concat(this.messageRecord.list)
response.data.data.list = messages.concat(this.messageRecord.list)
this.$store.commit("onChangeMessageRecord", response.data.data)
}
setTimeout(()=>this.$previewRefresh(), 1000)
......
......@@ -14,6 +14,9 @@ export default {
.then(response => {
let newMessage = [];
let messages = response.data.data.list || [];
for(var i=0; i<messages.length; i++){
messages[i].payload = window.Base64.decode(messages[i].payload)
}
if (messages.length < pageSize || messages.length == 0) {
context.commit('updateState', { isLoadMorEnd: true })
}
......
......@@ -382,7 +382,18 @@ export default {
}
})
console.log("重新登录中...");
console.log(this.$mimcInstance.user.isLogin())
},
// onLongTraining
onLongTraining(){
if(!this.isShowTopLoading) return
// 长轮训获取新消息
console.log("长轮训获取新消息..")
this.$store.dispatch("onGetMessages", {
timestamp: 0,
oldMsg: [],
callback: () => this.scrollIntoBottom()
});
setTimeout(()=> this.onLongTraining(), 2000)
},
// handelEvent
handelEvent() {
......@@ -397,6 +408,7 @@ export default {
this.$mimcInstance.user.logout()
this.isShowTopLoading = true;
this.userLogin()
this.onLongTraining()
});
// 状态发生变化
......@@ -407,6 +419,7 @@ export default {
this.isShowTopLoading = false;
}else{
this.userLogin()
this.onLongTraining()
}
console.log("状态发生变化", bindResult, errType, errReason, errDesc);
}
......@@ -567,7 +580,7 @@ export default {
localMessage["percent"] = 0;
localMessage.isShowCancel = true;
setTimeout(() => {
localMessage.isShowCancel = false;
this.updateMessageHideCancel(localMessage)
}, 10000);
self.messages.push(self.handlerMessage(localMessage));
var cacheMsg = Object.assign({}, localMessage);
......@@ -699,6 +712,17 @@ export default {
this.sendTextMessage();
this.$refs.textarea.focus();
},
// 更新消息
updateMessageHideCancel(message){
let messages = this.$store.getters.messages
for(var i =0; i<messages.length; i++){
if(message.key == messages[i].key){
messages[i].isShowCancel = false
break
}
}
this.$store.commit("updateState", { messages });
},
// 发送文本消息
sendTextMessage() {
// 当前用户是否上线
......@@ -716,7 +740,9 @@ export default {
chatValue
);
message.isShowCancel = true;
setTimeout(() => (message.isShowCancel = false), 10000);
setTimeout(() =>{
this.updateMessageHideCancel(message)
}, 10000);
this.messagesPushMemory(message);
this.chatValue = "";
this.handshakeKeywordList = [];
......
......@@ -22,6 +22,7 @@ func MessageInto(message models.Message) {
// message create time
message.Timestamp = time.Now().Unix()
message.Sequence = time.Now().UnixNano()
// content内容转base64
message.Payload = base64.StdEncoding.EncodeToString([]byte(message.Payload))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment