|
@@ -3,7 +3,6 @@ package service
|
|
|
import (
|
|
|
quitl "app.yhyue.com/moapp/jybase/common"
|
|
|
util "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/entity"
|
|
|
- . "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/rpc/messagecenter/init"
|
|
|
"bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/rpc/messagecenter/messagecenter"
|
|
|
"database/sql"
|
|
|
"fmt"
|
|
@@ -13,9 +12,6 @@ import (
|
|
|
|
|
|
type MessaggeService struct{}
|
|
|
|
|
|
-func (b MessaggeService) Table() string {
|
|
|
- return "socialize_message_mailbox"
|
|
|
-}
|
|
|
func (b MessaggeService) Count(newUserId, userType, entUserId int64) (count int, last map[string]interface{}, err error) {
|
|
|
v := make([]interface{}, 0)
|
|
|
sqlStr := ""
|
|
@@ -27,11 +23,11 @@ func (b MessaggeService) Count(newUserId, userType, entUserId int64) (count int,
|
|
|
v = append(v, newUserId, newUserId)
|
|
|
}
|
|
|
fmt.Println(sqlStr, v)
|
|
|
- rs := Mysql.CountBySql(sqlStr, v...)
|
|
|
+ rs := util.Mysql.CountBySql(sqlStr, v...)
|
|
|
log.Println(rs)
|
|
|
count = int(rs)
|
|
|
//最后一条信息查询
|
|
|
- lastData := Mysql.SelectBySql("SELECT c.* FROM socialize_message_mailbox b left join socialize_message c on b.messag_id=c.id WHERE b.send_user_id != ? AND b.own_id = ? and b.isread=0 AND own_type = 2 ORDER BY create_time DESC LIMIT 0,1", newUserId, newUserId)
|
|
|
+ lastData := util.Mysql.SelectBySql("SELECT c.* FROM socialize_message_mailbox b left join socialize_message c on b.messag_id=c.id WHERE b.send_user_id != ? AND b.own_id = ? and b.isread=0 AND own_type = 2 ORDER BY create_time DESC LIMIT 0,1", newUserId, newUserId)
|
|
|
if len(*lastData) > 0 {
|
|
|
last = (*lastData)[0]
|
|
|
}
|
|
@@ -43,11 +39,11 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
|
|
|
if in.UserType == 2 {
|
|
|
//用户最后一次信息查询
|
|
|
userSql := "SELECT MAX( c.id ) as messageId FROM socialize_message_mailbox c WHERE c.own_id = ? AND c.type = 2 AND c.own_type = 2 GROUP BY ( CASE WHEN c.send_user_id > c.receive_user_id THEN CONCAT( c.send_user_id, c.receive_user_id ) WHEN c.send_user_id < c.receive_user_id THEN CONCAT( c.receive_user_id, c.send_user_id ) END ) "
|
|
|
- data = Mysql.SelectBySql(userSql, in.NewUserId)
|
|
|
+ data = util.Mysql.SelectBySql(userSql, in.NewUserId)
|
|
|
userMessageId := Inhandle(data)
|
|
|
//客服最后一次信息查询
|
|
|
customerSql := " SELECT max( c.id ) as messageId FROM socialize_message_mailbox c LEFT JOIN socialize_chat_session d ON IF ( c.send_user_type = 1, d.id = c.send_user_id, d.id = c.receive_user_id ) WHERE c.own_id = ? AND ( c.type = 4 OR c.type = 5 ) AND c.own_type = 2 and d.user_id=c.own_id GROUP BY d.ent_id "
|
|
|
- data = Mysql.SelectBySql(customerSql, in.NewUserId)
|
|
|
+ data = util.Mysql.SelectBySql(customerSql, in.NewUserId)
|
|
|
customerMessageId := Inhandle(data)
|
|
|
//用户的列表
|
|
|
sqlStr = "SELECT IF ( b.nickname = '', CONCAT(SUBSTR( b.phone, 1, 3 ),'****',SUBSTR( b.phone, 8, 11)), b.nickname ) AS name, b.id, e.title, b.headimg, e.type, e.link, e.content, 2 AS userType, a.create_time, a.type AS itemType, ( SELECT count( h.id ) FROM socialize_message_mailbox h WHERE h.type = 2 AND h.own_id = ? AND h.own_type = 2 AND h.receive_user_id = ? and h.send_user_id=b.id AND h.isread = 0 ) AS number FROM socialize_message_mailbox a LEFT JOIN base_user b ON b.id = a.receive_user_id or b.id = a.send_user_id LEFT JOIN socialize_message e ON e.id = a.messag_id WHERE a.id IN ( " + userMessageId + " ) AND b.id != ? UNION ALL SELECT f.nickname AS name, b.ent_id AS id, e.title,f.headimage AS headimg, e.type, e.link, e.content, 1 AS userType, a.create_time, a.type AS itemType, ( SELECT count( h.id ) FROM socialize_message_mailbox h WHERE ( h.type = 4 OR h.type = 5 ) AND h.own_id = ? AND h.own_type = 2 AND h.send_user_type = 1 and h.receive_user_id = ? AND h.isread = 0 ) AS number FROM socialize_message_mailbox a LEFT JOIN socialize_chat_session b ON IF ( a.send_user_type = 1, b.id = a.send_user_id, b.id = a.receive_user_id ) LEFT JOIN socialize_message e ON e.id = a.messag_id left join socialize_tenant_robot f on f.ent_id=b.ent_id WHERE a.id IN ( " + customerMessageId + " ) ORDER BY create_time DESC"
|
|
@@ -70,7 +66,7 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
|
|
|
userSql := " SELECT MAX( c.id ) as messageId FROM socialize_message_mailbox c LEFT JOIN socialize_chat_session d ON IF ( c.send_user_type = 1, d.id = c.send_user_id, d.id = c.receive_user_id ) WHERE c.own_type = 1 AND d.customer_service_id = ? and ( c.type = 4 OR c.type = 5 ) AND d.customer_service_id !=0 " + startTimeSql + endTimeSql + " 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 ) "
|
|
|
v = append(v, in.EntUserId)
|
|
|
log.Println(userSql, v)
|
|
|
- data = Mysql.SelectBySql(userSql, v...)
|
|
|
+ data = util.Mysql.SelectBySql(userSql, v...)
|
|
|
if data != nil {
|
|
|
customerMessageId := Inhandle(data)
|
|
|
//客服的用户列表
|
|
@@ -82,7 +78,7 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
|
|
|
}
|
|
|
if sqlStr != "" {
|
|
|
fmt.Println(sqlStr, v)
|
|
|
- data = Mysql.SelectBySql(sqlStr, v...)
|
|
|
+ data = util.Mysql.SelectBySql(sqlStr, v...)
|
|
|
}
|
|
|
return
|
|
|
}
|
|
@@ -116,7 +112,7 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (errorCode
|
|
|
break
|
|
|
}
|
|
|
//查找会话信息
|
|
|
- chatJson := Mysql.FindOne("socialize_chat_session", map[string]interface{}{"id": sessionId}, "user_id", "")
|
|
|
+ chatJson := util.Mysql.FindOne("socialize_chat_session", map[string]interface{}{"id": sessionId}, "user_id", "")
|
|
|
if chatJson == nil {
|
|
|
return 1, "会话标识不存在", "", 0
|
|
|
} else {
|
|
@@ -125,7 +121,7 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (errorCode
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- fool := Mysql.ExecTx("聊天信息保存", func(tx *sql.Tx) bool {
|
|
|
+ fool := util.Mysql.ExecTx("聊天信息保存", func(tx *sql.Tx) bool {
|
|
|
//先插入信息表
|
|
|
message := map[string]interface{}{
|
|
|
"appid": in.Appid,
|
|
@@ -137,7 +133,7 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (errorCode
|
|
|
"create_time": time.Now().Local().Format(util.Date_Full_Layout),
|
|
|
"create_person": in.SendId,
|
|
|
}
|
|
|
- ok := Mysql.InsertByTx(tx, "socialize_message", message)
|
|
|
+ ok := util.Mysql.InsertByTx(tx, "socialize_message", message)
|
|
|
if ok <= 0 {
|
|
|
return false
|
|
|
}
|
|
@@ -183,7 +179,7 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (errorCode
|
|
|
messageMailBox["send_user_id"] = in.NewUserId
|
|
|
messageMailBox["receive_user_id"] = in.SendId
|
|
|
}
|
|
|
- receiveOk := Mysql.InsertByTx(tx, "socialize_message_mailbox", messageMailBox)
|
|
|
+ receiveOk := util.Mysql.InsertByTx(tx, "socialize_message_mailbox", messageMailBox)
|
|
|
if receiveOk == 0 {
|
|
|
return false
|
|
|
} else {
|
|
@@ -222,7 +218,7 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (errorCode
|
|
|
messageMailBox["send_user_id"] = in.NewUserId
|
|
|
messageMailBox["receive_user_id"] = in.ReceiveId
|
|
|
}
|
|
|
- sendOk := Mysql.InsertByTx(tx, "socialize_message_mailbox", messageMailBox)
|
|
|
+ sendOk := util.Mysql.InsertByTx(tx, "socialize_message_mailbox", messageMailBox)
|
|
|
if sendOk == 0 {
|
|
|
return false
|
|
|
}
|
|
@@ -268,7 +264,7 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (errorCode
|
|
|
messageMailBox["send_user_id"] = in.NewUserId
|
|
|
messageMailBox["receive_user_id"] = in.ReceiveId
|
|
|
}
|
|
|
- receiveOk := Mysql.InsertByTx(tx, "socialize_message_mailbox", messageMailBox)
|
|
|
+ receiveOk := util.Mysql.InsertByTx(tx, "socialize_message_mailbox", messageMailBox)
|
|
|
if receiveOk == 0 {
|
|
|
return false
|
|
|
}
|
|
@@ -306,11 +302,11 @@ func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) (*[]map[strin
|
|
|
}
|
|
|
log.Println(sqlStr)
|
|
|
log.Println(countSql)
|
|
|
- data := Mysql.SelectBySql(sqlStr)
|
|
|
- count := Mysql.CountBySql(countSql)
|
|
|
+ data := util.Mysql.SelectBySql(sqlStr)
|
|
|
+ count := util.Mysql.CountBySql(countSql)
|
|
|
//自己头像处理
|
|
|
if in.UserType == 2 && count > 0 {
|
|
|
- userData := Mysql.FindOne("base_user", map[string]interface{}{"id": in.NewUserId}, "headimg", "")
|
|
|
+ userData := util.Mysql.FindOne("base_user", map[string]interface{}{"id": in.NewUserId}, "headimg", "")
|
|
|
if userData != nil {
|
|
|
for key := range *data {
|
|
|
(*data)[key]["ownImg"] = (*userData)["headimg"]
|
|
@@ -330,13 +326,13 @@ func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) (*[]map[strin
|
|
|
"type": 2,
|
|
|
"isread": 0,
|
|
|
}
|
|
|
- Mysql.Update("socialize_message_mailbox", updateMap, map[string]interface{}{"isread": 1, "read_time": time.Now().Local().Format(util.Date_Full_Layout)})
|
|
|
+ util.Mysql.Update("socialize_message_mailbox", updateMap, map[string]interface{}{"isread": 1, "read_time": time.Now().Local().Format(util.Date_Full_Layout)})
|
|
|
break
|
|
|
case 4, 5:
|
|
|
if in.UserType == 1 {
|
|
|
- Mysql.UpdateOrDeleteBySql("UPDATE socialize_message_mailbox a SET a.isread = 1, a.read_time = now( ) WHERE a.own_type = 1 AND a.type IN ( 4, 5,6,7) AND a.isread = 0 AND a.own_id IN ( SELECT b.id FROM socialize_chat_session b WHERE b.customer_service_id=? and b.user_id=? )", in.EntUserId, in.SendId)
|
|
|
+ util.Mysql.UpdateOrDeleteBySql("UPDATE socialize_message_mailbox a SET a.isread = 1, a.read_time = now( ) WHERE a.own_type = 1 AND a.type IN ( 4, 5,6,7) AND a.isread = 0 AND a.own_id IN ( SELECT b.id FROM socialize_chat_session b WHERE b.customer_service_id=? and b.user_id=? )", in.EntUserId, in.SendId)
|
|
|
} else {
|
|
|
- Mysql.UpdateOrDeleteBySql("UPDATE socialize_message_mailbox a SET a.isread = 1, a.read_time = now( ) WHERE a.own_type = 2 AND a.type IN ( 4, 5,6,7 ) AND a.isread = 0 AND a.own_id =?", in.NewUserId)
|
|
|
+ util.Mysql.UpdateOrDeleteBySql("UPDATE socialize_message_mailbox a SET a.isread = 1, a.read_time = now( ) WHERE a.own_type = 2 AND a.type IN ( 4, 5,6,7 ) AND a.isread = 0 AND a.own_id =?", in.NewUserId)
|
|
|
}
|
|
|
break
|
|
|
}
|
|
@@ -345,10 +341,10 @@ func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) (*[]map[strin
|
|
|
return data, count
|
|
|
}
|
|
|
func (b MessaggeService) CreateChatSession(in *messagecenter.ChatSessionReq) (errorCode, sessionId int64) {
|
|
|
- fool := Mysql.ExecTx("会话新建", func(tx *sql.Tx) bool {
|
|
|
+ fool := util.Mysql.ExecTx("会话新建", func(tx *sql.Tx) bool {
|
|
|
customerserviceName := in.CustomerserviceName
|
|
|
if in.CustomerServiceId != 0 {
|
|
|
- customerList := Mysql.SelectBySql("select customer_service_name from socialize_tenant_seat where ent_id=" + quitl.InterfaceToStr(in.EntId) + " and customer_service_id=" + quitl.InterfaceToStr(in.CustomerServiceId))
|
|
|
+ customerList := util.Mysql.SelectBySql("select customer_service_name from socialize_tenant_seat where ent_id=" + quitl.InterfaceToStr(in.EntId) + " and customer_service_id=" + quitl.InterfaceToStr(in.CustomerServiceId))
|
|
|
if len(*customerList) > 0 {
|
|
|
customerserviceName = quitl.InterfaceToStr((*customerList)[0]["customer_service_name"])
|
|
|
}
|
|
@@ -362,7 +358,7 @@ func (b MessaggeService) CreateChatSession(in *messagecenter.ChatSessionReq) (er
|
|
|
"user_id": in.UserId,
|
|
|
"customer_service_name": customerserviceName,
|
|
|
}
|
|
|
- sessionId = Mysql.InsertByTx(tx, "socialize_chat_session", chatMession)
|
|
|
+ sessionId = util.Mysql.InsertByTx(tx, "socialize_chat_session", chatMession)
|
|
|
return sessionId > 0
|
|
|
})
|
|
|
if fool {
|
|
@@ -372,11 +368,11 @@ func (b MessaggeService) CreateChatSession(in *messagecenter.ChatSessionReq) (er
|
|
|
}
|
|
|
}
|
|
|
func (b MessaggeService) CloseChatSession(in *messagecenter.CloseSessionReq) (errorCode int64) {
|
|
|
- fool := Mysql.ExecTx("关闭会话", func(tx *sql.Tx) bool {
|
|
|
+ fool := util.Mysql.ExecTx("关闭会话", func(tx *sql.Tx) bool {
|
|
|
updateMap := map[string]interface{}{
|
|
|
"id": in.SessionId,
|
|
|
}
|
|
|
- fool := Mysql.Update("socialize_chat_session", updateMap, map[string]interface{}{"start_time": time.Now().Local().Format(util.Date_Full_Layout)})
|
|
|
+ fool := util.Mysql.Update("socialize_chat_session", updateMap, map[string]interface{}{"start_time": time.Now().Local().Format(util.Date_Full_Layout)})
|
|
|
return fool
|
|
|
})
|
|
|
if fool {
|
|
@@ -402,23 +398,23 @@ func Inhandle(data *[]map[string]interface{}) (messId string) {
|
|
|
}
|
|
|
|
|
|
func (m *MessaggeService) SaveAutoReplyMsg(userType, entId, entUserId, userId int64, content, appId, nowFormat string) bool {
|
|
|
- return Mysql.ExecTx("保存自动回复消息", func(tx *sql.Tx) bool {
|
|
|
+ return util.Mysql.ExecTx("保存自动回复消息", func(tx *sql.Tx) bool {
|
|
|
entUserName := ""
|
|
|
if entUserId > 0 {
|
|
|
- list := Mysql.SelectBySql(`select customer_service_name from socialize_tenant_seat where appid=? and ent_id=? and customer_service_id=?`, appId, entId, entUserId)
|
|
|
+ list := util.Mysql.SelectBySql(`select customer_service_name from socialize_tenant_seat where appid=? and ent_id=? and customer_service_id=?`, appId, entId, entUserId)
|
|
|
if list != nil && len(*list) > 0 {
|
|
|
entUserName, _ = (*list)[0]["customer_service_name"].(string)
|
|
|
}
|
|
|
}
|
|
|
- messageId := Mysql.InsertBySqlByTx(tx, `insert into socialize_message (appid,content,item,type,create_time,create_person) values (?,?,?,?,?,?)`, appId, content, 8, 1, nowFormat, "admin")
|
|
|
- sessionId := 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 := 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)
|
|
|
ok := false
|
|
|
if userType == 1 {
|
|
|
- if 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, sessionId, 1, nowFormat) > 0 {
|
|
|
+ if 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, sessionId, 1, nowFormat) > 0 {
|
|
|
ok = true
|
|
|
}
|
|
|
} else if userType == 2 {
|
|
|
- if 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 {
|
|
|
+ if 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 = true
|
|
|
}
|
|
|
}
|