|
@@ -3,6 +3,7 @@ package service
|
|
|
import (
|
|
|
quitl "app.yhyue.com/moapp/jybase/common"
|
|
|
util "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/entity"
|
|
|
+ IC "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/rpc/messagecenter/init"
|
|
|
"bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/rpc/messagecenter/messagecenter"
|
|
|
"database/sql"
|
|
|
"fmt"
|
|
@@ -49,7 +50,7 @@ func (b MessaggeService) Count(newUserId, userType, entUserId int64, isClean boo
|
|
|
|
|
|
}
|
|
|
log.Println(sqlStr, v)
|
|
|
- rs := util.Mysql.CountBySql(sqlStr, v...)
|
|
|
+ rs := IC.BaseMysql.CountBySql(sqlStr, v...)
|
|
|
log.Println(rs)
|
|
|
count = int(rs)
|
|
|
//最后一条信息查询
|
|
@@ -62,19 +63,19 @@ func (b MessaggeService) Count(newUserId, userType, entUserId int64, isClean boo
|
|
|
"ORDER BY create_time DESC "+
|
|
|
"LIMIT 0,1", util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_MESSAGE,
|
|
|
newUserId, newUserId)
|
|
|
- lastData := util.Mysql.SelectBySql(sqlStr)
|
|
|
+ lastData := IC.BaseMysql.SelectBySql(sqlStr)
|
|
|
if len(*lastData) > 0 {
|
|
|
last = (*lastData)[0]
|
|
|
if userType == 1 {
|
|
|
- util.SetData(userType, entUserId, map[string]interface{}{"data": last, "count": count}, util.SurvivalTime)
|
|
|
+ util.SetData(userType, entUserId, map[string]interface{}{"data": last, "count": count}, IC.SurvivalTime)
|
|
|
} else {
|
|
|
- util.SetData(userType, newUserId, map[string]interface{}{"data": last, "count": count}, util.SurvivalTime)
|
|
|
+ util.SetData(userType, newUserId, map[string]interface{}{"data": last, "count": count}, IC.SurvivalTime)
|
|
|
}
|
|
|
} else {
|
|
|
if userType == 1 {
|
|
|
- util.SetData(userType, entUserId, map[string]interface{}{"data": map[string]interface{}{}, "count": count}, util.SurvivalTime)
|
|
|
+ util.SetData(userType, entUserId, map[string]interface{}{"data": map[string]interface{}{}, "count": count}, IC.SurvivalTime)
|
|
|
} else {
|
|
|
- util.SetData(userType, newUserId, map[string]interface{}{"data": map[string]interface{}{}, "count": count}, util.SurvivalTime)
|
|
|
+ util.SetData(userType, newUserId, map[string]interface{}{"data": map[string]interface{}{}, "count": count}, IC.SurvivalTime)
|
|
|
}
|
|
|
}
|
|
|
return
|
|
@@ -94,7 +95,7 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
|
|
|
"WHEN c.send_user_id < c.receive_user_id "+
|
|
|
"THEN CONCAT( c.receive_user_id, c.send_user_id ) END ) ", in.NewUserId,
|
|
|
)
|
|
|
- data = util.Mysql.SelectBySql(userSql)
|
|
|
+ data = IC.BaseMysql.SelectBySql(userSql)
|
|
|
userMessageId := util.Inhandle(data)
|
|
|
//客服最后一次信息查询
|
|
|
customerSql := fmt.Sprintf("SELECT MAX( c.id ) as messageId FROM %s c "+
|
|
@@ -104,7 +105,7 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
|
|
|
"AND c.own_type = 2 "+
|
|
|
"AND d.user_id=c.own_id "+
|
|
|
"GROUP BY d.ent_id ", util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_CHAT_SESSION, in.NewUserId)
|
|
|
- data = util.Mysql.SelectBySql(customerSql)
|
|
|
+ data = IC.BaseMysql.SelectBySql(customerSql)
|
|
|
customerMessageId := util.Inhandle(data)
|
|
|
//用户的列表
|
|
|
sqlStr = fmt.Sprintf("SELECT "+
|
|
@@ -166,7 +167,7 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
|
|
|
"GROUP BY ( CASE WHEN c.send_user_type =2 THEN CONCAT( c.send_user_id ) WHEN c.send_user_type =1 THEN CONCAT( c.receive_user_id ) END ) ",
|
|
|
util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_CHAT_SESSION,
|
|
|
in.EntUserId, startTimeSql, endTimeSql)
|
|
|
- data = util.Mysql.SelectBySql(userSql)
|
|
|
+ data = IC.BaseMysql.SelectBySql(userSql)
|
|
|
if data != nil {
|
|
|
customerMessageId := util.Inhandle(data)
|
|
|
//客服的用户列表
|
|
@@ -191,7 +192,7 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
|
|
|
}
|
|
|
if sqlStr != "" {
|
|
|
log.Println(sqlStr)
|
|
|
- data = util.Mysql.SelectBySql(sqlStr)
|
|
|
+ data = IC.BaseMysql.SelectBySql(sqlStr)
|
|
|
}
|
|
|
return
|
|
|
}
|
|
@@ -231,7 +232,7 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
|
|
|
break
|
|
|
}
|
|
|
//查找会话信息
|
|
|
- chatJson := util.Mysql.FindOne(util.SOCIALIZE_CHAT_SESSION, map[string]interface{}{"id": sessionId}, "user_id", "")
|
|
|
+ chatJson := IC.BaseMysql.FindOne(util.SOCIALIZE_CHAT_SESSION, map[string]interface{}{"id": sessionId}, "user_id", "")
|
|
|
if chatJson == nil {
|
|
|
return false, "会话标识不存在", "", 0, nowForm.Unix()
|
|
|
} else {
|
|
@@ -240,7 +241,7 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- fool = util.Mysql.ExecTx("聊天信息保存", func(tx *sql.Tx) bool {
|
|
|
+ fool = IC.BaseMysql.ExecTx("聊天信息保存", func(tx *sql.Tx) bool {
|
|
|
//先插入信息表
|
|
|
create_time := nowForm.Format(util.Date_Full_Layout)
|
|
|
userType := int64(1)
|
|
@@ -261,7 +262,7 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
|
|
|
"create_time": create_time,
|
|
|
"content": in.Content,
|
|
|
}
|
|
|
- ok := util.Mysql.InsertByTx(tx, util.SOCIALIZE_MESSAGE, message)
|
|
|
+ ok := IC.BaseMysql.InsertByTx(tx, util.SOCIALIZE_MESSAGE, message)
|
|
|
receiveOk := int64(0)
|
|
|
messageId = ok
|
|
|
data["id"] = ok
|
|
@@ -315,7 +316,7 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
|
|
|
messageMailBox["send_user_id"] = in.NewUserId
|
|
|
messageMailBox["receive_user_id"] = in.ReceiveId
|
|
|
}
|
|
|
- receiveOk = util.Mysql.InsertByTx(tx, util.SOCIALIZE_MESSAGE_MAILBOX, messageMailBox)
|
|
|
+ receiveOk = IC.BaseMysql.InsertByTx(tx, util.SOCIALIZE_MESSAGE_MAILBOX, messageMailBox)
|
|
|
return ok > 1 && receiveOk > 1
|
|
|
}
|
|
|
if in.ItemType == 4 || in.ItemType == 5 {
|
|
@@ -359,7 +360,7 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
|
|
|
userType = 2
|
|
|
userId = in.ReceiveId
|
|
|
}
|
|
|
- receiveOk = util.Mysql.InsertByTx(tx, util.SOCIALIZE_MESSAGE_MAILBOX, messageMailBox)
|
|
|
+ receiveOk = IC.BaseMysql.InsertByTx(tx, util.SOCIALIZE_MESSAGE_MAILBOX, messageMailBox)
|
|
|
messageMailBox = map[string]interface{}{
|
|
|
"appid": in.Appid,
|
|
|
"messag_id": ok,
|
|
@@ -402,14 +403,14 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
|
|
|
messageMailBox["send_user_id"] = in.NewUserId
|
|
|
messageMailBox["receive_user_id"] = in.ReceiveId
|
|
|
}
|
|
|
- receiveOk = util.Mysql.InsertByTx(tx, util.SOCIALIZE_MESSAGE_MAILBOX, messageMailBox)
|
|
|
+ receiveOk = IC.BaseMysql.InsertByTx(tx, util.SOCIALIZE_MESSAGE_MAILBOX, messageMailBox)
|
|
|
if ok > 1 && receiveOk > 1 {
|
|
|
pc_a, err := util.GetData(userType, userId)
|
|
|
count := 1
|
|
|
if err == nil && pc_a != nil {
|
|
|
count += pc_a.Count
|
|
|
}
|
|
|
- util.SetData(userType, userId, map[string]interface{}{"data": data, "count": count}, util.SurvivalTime)
|
|
|
+ util.SetData(userType, userId, map[string]interface{}{"data": data, "count": count}, IC.SurvivalTime)
|
|
|
}
|
|
|
return ok > 1 && receiveOk > 1
|
|
|
})
|
|
@@ -477,10 +478,10 @@ func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) *[]map[string
|
|
|
break
|
|
|
}
|
|
|
log.Println(sqlStr)
|
|
|
- data := util.Mysql.SelectBySql(sqlStr)
|
|
|
+ data := IC.BaseMysql.SelectBySql(sqlStr)
|
|
|
//自己头像处理
|
|
|
if in.UserType == 2 {
|
|
|
- userData := util.Mysql.FindOne(util.BASE_USER, map[string]interface{}{"id": in.NewUserId}, "headimg", "")
|
|
|
+ userData := IC.BaseMysql.FindOne(util.BASE_USER, map[string]interface{}{"id": in.NewUserId}, "headimg", "")
|
|
|
if userData != nil {
|
|
|
for key := range *data {
|
|
|
(*data)[key]["ownImg"] = (*userData)["headimg"]
|
|
@@ -501,7 +502,7 @@ func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) *[]map[string
|
|
|
"type": 2,
|
|
|
"isread": 0,
|
|
|
}
|
|
|
- util.Mysql.Update(util.SOCIALIZE_MESSAGE_MAILBOX, updateMap, map[string]interface{}{"isread": 1, "read_time": time.Now().Local().Format(util.Date_Full_Layout)})
|
|
|
+ IC.BaseMysql.Update(util.SOCIALIZE_MESSAGE_MAILBOX, updateMap, map[string]interface{}{"isread": 1, "read_time": time.Now().Local().Format(util.Date_Full_Layout)})
|
|
|
break
|
|
|
case 4, 5:
|
|
|
sqlStr := ""
|
|
@@ -519,7 +520,7 @@ func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) *[]map[string
|
|
|
"AND a.isread = 0 "+
|
|
|
"AND a.own_id =%d ", util.SOCIALIZE_MESSAGE_MAILBOX, in.NewUserId)
|
|
|
}
|
|
|
- util.Mysql.UpdateOrDeleteBySql(sqlStr)
|
|
|
+ IC.BaseMysql.UpdateOrDeleteBySql(sqlStr)
|
|
|
break
|
|
|
}
|
|
|
//redis缓存处理
|
|
@@ -531,20 +532,20 @@ func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) *[]map[string
|
|
|
|
|
|
//创建会话
|
|
|
func (b MessaggeService) CreateChatSession(in *messagecenter.ChatSessionReq) (fool bool, sessionId int64) {
|
|
|
- fool = util.Mysql.ExecTx("会话新建", func(tx *sql.Tx) bool {
|
|
|
+ fool = IC.BaseMysql.ExecTx("会话新建", func(tx *sql.Tx) bool {
|
|
|
customerserviceName := in.CustomerserviceName
|
|
|
if in.CustomerServiceId != 0 {
|
|
|
sqlStr := fmt.Sprintf("select customer_service_name from %s "+
|
|
|
"where ent_id= %d "+
|
|
|
"AND customer_service_id= %d ",
|
|
|
util.SOCIALIZE_CHAT_SESSION, in.EntId, in.CustomerServiceId)
|
|
|
- customerList := util.Mysql.SelectBySql(sqlStr)
|
|
|
+ customerList := IC.BaseMysql.SelectBySql(sqlStr)
|
|
|
if len(*customerList) > 0 {
|
|
|
customerserviceName = quitl.InterfaceToStr((*customerList)[0]["customer_service_name"])
|
|
|
}
|
|
|
}
|
|
|
//查询企业是否存在
|
|
|
- count := util.Mysql.Count(util.SOCIALIZE_TENANT_ROBOT, map[string]interface{}{
|
|
|
+ count := IC.BaseMysql.Count(util.SOCIALIZE_TENANT_ROBOT, map[string]interface{}{
|
|
|
"ent_id": in.EntId,
|
|
|
})
|
|
|
if count < 1 {
|
|
@@ -559,7 +560,7 @@ func (b MessaggeService) CreateChatSession(in *messagecenter.ChatSessionReq) (fo
|
|
|
"user_id": in.UserId,
|
|
|
"customer_service_name": customerserviceName,
|
|
|
}
|
|
|
- sessionId = util.Mysql.InsertByTx(tx, util.SOCIALIZE_CHAT_SESSION, chatMession)
|
|
|
+ sessionId = IC.BaseMysql.InsertByTx(tx, util.SOCIALIZE_CHAT_SESSION, chatMession)
|
|
|
return sessionId > 0
|
|
|
})
|
|
|
return
|
|
@@ -567,11 +568,11 @@ func (b MessaggeService) CreateChatSession(in *messagecenter.ChatSessionReq) (fo
|
|
|
|
|
|
//结束会话
|
|
|
func (b MessaggeService) CloseChatSession(in *messagecenter.CloseSessionReq) bool {
|
|
|
- fool := util.Mysql.ExecTx("关闭会话", func(tx *sql.Tx) bool {
|
|
|
+ fool := IC.BaseMysql.ExecTx("关闭会话", func(tx *sql.Tx) bool {
|
|
|
updateMap := map[string]interface{}{
|
|
|
"id": in.SessionId,
|
|
|
}
|
|
|
- fool := util.Mysql.Update(util.SOCIALIZE_CHAT_SESSION, updateMap, map[string]interface{}{"start_time": time.Now().Local().Format(util.Date_Full_Layout)})
|
|
|
+ fool := IC.BaseMysql.Update(util.SOCIALIZE_CHAT_SESSION, updateMap, map[string]interface{}{"start_time": time.Now().Local().Format(util.Date_Full_Layout)})
|
|
|
return fool
|
|
|
})
|
|
|
return fool
|
|
@@ -580,25 +581,25 @@ func (b MessaggeService) CloseChatSession(in *messagecenter.CloseSessionReq) boo
|
|
|
//创建会话并保存信息
|
|
|
func (b *MessaggeService) SaveAutoReplyMsg(userType, entId, entUserId, userId int64, content, appId, nowFormat string) (bool, int64) {
|
|
|
messageId := int64(0)
|
|
|
- return util.Mysql.ExecTx("保存自动回复消息", func(tx *sql.Tx) bool {
|
|
|
+ return IC.BaseMysql.ExecTx("保存自动回复消息", func(tx *sql.Tx) bool {
|
|
|
entUserName := ""
|
|
|
if entUserId > 0 {
|
|
|
- list := util.Mysql.SelectBySql(`select ? from socialize_tenant_seat where appid=? AND ent_id=? AND customer_service_id=?`, util.SOCIALIZE_CHAT_SESSION, appId, entId, entUserId)
|
|
|
+ list := IC.BaseMysql.SelectBySql(`select ? from socialize_tenant_seat where appid=? AND ent_id=? AND customer_service_id=?`, util.SOCIALIZE_CHAT_SESSION, appId, entId, entUserId)
|
|
|
if list != nil && len(*list) > 0 {
|
|
|
entUserName, _ = (*list)[0]["customer_service_name"].(string)
|
|
|
}
|
|
|
}
|
|
|
- messageId = util.Mysql.InsertBySqlByTx(tx, `insert into socialize_message (appid,content,item,type,create_time,create_person) values (?,?,?,?,?,?)`, appId, content, 8, 1, nowFormat, "admin")
|
|
|
- sessionId := util.Mysql.InsertBySqlByTx(tx, `insert into socialize_chat_session (appid,type,ent_id,customer_service_id,customer_service_name,user_id,start_time,end_time) values (?,?,?,?,?,?,?,?)`, appId, 1, entId, entUserId, entUserName, userId, nowFormat, nowFormat)
|
|
|
+ messageId = IC.BaseMysql.InsertBySqlByTx(tx, `insert into socialize_message (appid,content,item,type,create_time,create_person) values (?,?,?,?,?,?)`, appId, content, 8, 1, nowFormat, "admin")
|
|
|
+ sessionId := IC.BaseMysql.InsertBySqlByTx(tx, `insert into socialize_chat_session (appid,type,ent_id,customer_service_id,customer_service_name,user_id,start_time,end_time) values (?,?,?,?,?,?,?,?)`, appId, 1, entId, entUserId, entUserName, userId, nowFormat, nowFormat)
|
|
|
ok := false
|
|
|
if userType == 0 {
|
|
|
- ok1 := util.Mysql.InsertBySqlByTx(tx, `insert into socialize_message_mailbox (appid,messag_id,type,send_user_id,send_user_type,receive_user_id,receive_user_type,own_id,own_type,create_time,isread,read_time) values (?,?,?,?,?,?,?,?,?,?,?,?)`, appId, messageId, 7, sessionId, 1, userId, 2, sessionId, 1, nowFormat, 1, nowFormat) > 0
|
|
|
- ok2 := util.Mysql.InsertBySqlByTx(tx, `insert into socialize_message_mailbox (appid,messag_id,type,send_user_id,send_user_type,receive_user_id,receive_user_type,own_id,own_type,create_time) values (?,?,?,?,?,?,?,?,?,?)`, appId, messageId, 7, sessionId, 1, userId, 2, userId, 2, nowFormat) > 0
|
|
|
+ ok1 := IC.BaseMysql.InsertBySqlByTx(tx, `insert into socialize_message_mailbox (appid,messag_id,type,send_user_id,send_user_type,receive_user_id,receive_user_type,own_id,own_type,create_time,isread,read_time) values (?,?,?,?,?,?,?,?,?,?,?,?)`, appId, messageId, 7, sessionId, 1, userId, 2, sessionId, 1, nowFormat, 1, nowFormat) > 0
|
|
|
+ ok2 := IC.BaseMysql.InsertBySqlByTx(tx, `insert into socialize_message_mailbox (appid,messag_id,type,send_user_id,send_user_type,receive_user_id,receive_user_type,own_id,own_type,create_time) values (?,?,?,?,?,?,?,?,?,?)`, appId, messageId, 7, sessionId, 1, userId, 2, userId, 2, nowFormat) > 0
|
|
|
ok = ok1 && ok2
|
|
|
} else if userType == 1 {
|
|
|
- ok = util.Mysql.InsertBySqlByTx(tx, `insert into socialize_message_mailbox (appid,messag_id,type,send_user_id,send_user_type,receive_user_id,receive_user_type,own_id,own_type,create_time,isread,read_time) values (?,?,?,?,?,?,?,?,?,?,?,?)`, appId, messageId, 7, sessionId, 1, userId, 2, sessionId, 1, nowFormat, 1, nowFormat) > 0
|
|
|
+ ok = IC.BaseMysql.InsertBySqlByTx(tx, `insert into socialize_message_mailbox (appid,messag_id,type,send_user_id,send_user_type,receive_user_id,receive_user_type,own_id,own_type,create_time,isread,read_time) values (?,?,?,?,?,?,?,?,?,?,?,?)`, appId, messageId, 7, sessionId, 1, userId, 2, sessionId, 1, nowFormat, 1, nowFormat) > 0
|
|
|
} else if userType == 2 {
|
|
|
- ok = util.Mysql.InsertBySqlByTx(tx, `insert into socialize_message_mailbox (appid,messag_id,type,send_user_id,send_user_type,receive_user_id,receive_user_type,own_id,own_type,create_time) values (?,?,?,?,?,?,?,?,?,?)`, appId, messageId, 7, sessionId, 1, userId, 2, userId, 2, nowFormat) > 0
|
|
|
+ ok = IC.BaseMysql.InsertBySqlByTx(tx, `insert into socialize_message_mailbox (appid,messag_id,type,send_user_id,send_user_type,receive_user_id,receive_user_type,own_id,own_type,create_time) values (?,?,?,?,?,?,?,?,?,?)`, appId, messageId, 7, sessionId, 1, userId, 2, userId, 2, nowFormat) > 0
|
|
|
}
|
|
|
return messageId > 0 && sessionId > 0 && ok
|
|
|
}), messageId
|
|
@@ -606,15 +607,15 @@ func (b *MessaggeService) SaveAutoReplyMsg(userType, entId, entUserId, userId in
|
|
|
|
|
|
//修改未读状态
|
|
|
func (b MessaggeService) UpdateReadById(in *messagecenter.ReadStateReq) bool {
|
|
|
- fool := util.Mysql.ExecTx("已读状态修改", func(tx *sql.Tx) bool {
|
|
|
+ fool := IC.BaseMysql.ExecTx("已读状态修改", func(tx *sql.Tx) bool {
|
|
|
updateMap := map[string]interface{}{
|
|
|
"messag_id": in.MessageId,
|
|
|
"isread": 0,
|
|
|
}
|
|
|
- fool := util.Mysql.Update(util.SOCIALIZE_MESSAGE_MAILBOX, updateMap, map[string]interface{}{"read_time": time.Now().Local().Format(util.Date_Full_Layout), "isread": 1})
|
|
|
+ fool := IC.BaseMysql.Update(util.SOCIALIZE_MESSAGE_MAILBOX, updateMap, map[string]interface{}{"read_time": time.Now().Local().Format(util.Date_Full_Layout), "isread": 1})
|
|
|
if fool {
|
|
|
//查询此条信息拥有者
|
|
|
- data := util.Mysql.FindOne(util.SOCIALIZE_MESSAGE_MAILBOX, updateMap, "receive_user_type", "")
|
|
|
+ data := IC.BaseMysql.FindOne(util.SOCIALIZE_MESSAGE_MAILBOX, updateMap, "receive_user_type", "")
|
|
|
if data != nil {
|
|
|
userType := int64(1)
|
|
|
userId := int64(0)
|
|
@@ -630,9 +631,9 @@ func (b MessaggeService) UpdateReadById(in *messagecenter.ReadStateReq) bool {
|
|
|
if err == nil && pc_a != nil {
|
|
|
//id一致
|
|
|
if in.MessageId == pc_a.Data["id"] {
|
|
|
- util.SetData(userType, userId, map[string]interface{}{"data": map[string]interface{}{}, "count": pc_a.Count - 1}, util.SurvivalTime)
|
|
|
+ util.SetData(userType, userId, map[string]interface{}{"data": map[string]interface{}{}, "count": pc_a.Count - 1}, IC.SurvivalTime)
|
|
|
} else {
|
|
|
- util.SetData(userType, userId, map[string]interface{}{"data": data, "count": pc_a.Count - 1}, util.SurvivalTime)
|
|
|
+ util.SetData(userType, userId, map[string]interface{}{"data": data, "count": pc_a.Count - 1}, IC.SurvivalTime)
|
|
|
}
|
|
|
}
|
|
|
}
|