|
@@ -244,41 +244,38 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (errorCode
|
|
|
}
|
|
|
}
|
|
|
func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) (*[]map[string]interface{}, int64) {
|
|
|
+ strat := time.Now().Unix()
|
|
|
sqlStr := ""
|
|
|
countSql := ""
|
|
|
- v := make([]interface{}, 0)
|
|
|
- countV := make([]interface{}, 0)
|
|
|
lastStr := " "
|
|
|
if in.LastId > 0 {
|
|
|
lastStr = " and a.messag_id < " + quitl.InterfaceToStr(in.LastId)
|
|
|
}
|
|
|
switch in.MsgType {
|
|
|
case 2: //点对点聊天
|
|
|
- sqlStr = "SELECT a.messag_id as messageId,b.* ,if(a.own_id = a.send_user_id,1,2) as fool FROM socialize_message_mailbox a LEFT JOIN socialize_message b on a.messag_id=b.id left join base_user c on c.id=a.send_user_id left join base_user d on d.id=a.receive_user_id where a.own_id=? and ((a.send_user_id=? and a.receive_user_id=?) or (a.send_user_id=? and a.receive_user_id=?)) and a.type=2 " + lastStr + " ORDER BY a.create_time desc ,a.id asc limit ? , ? "
|
|
|
- countSql = "SELECT count(b.id) FROM socialize_message_mailbox a LEFT JOIN socialize_message b on a.messag_id=b.id left join base_user c on c.id=a.send_user_id left join base_user d on d.id=a.receive_user_id where a.own_id=? and ((a.send_user_id=? and a.receive_user_id=?) or (a.send_user_id=? and a.receive_user_id=?)) and a.type=2 " + lastStr
|
|
|
- v = append(v, in.NewUserId, in.NewUserId, in.SendId, in.SendId, in.NewUserId, 0, in.PageSize)
|
|
|
- countV = append(countV, in.NewUserId, in.NewUserId, in.SendId, in.SendId, in.NewUserId)
|
|
|
+ sqlStr = "SELECT a.messag_id as messageId,b.* ,if(a.own_id = a.send_user_id,1,2) as fool FROM socialize_message_mailbox a LEFT JOIN socialize_message b on a.messag_id=b.id left join base_user c on c.id=a.send_user_id left join base_user d on d.id=a.receive_user_id where a.own_id= " + quitl.InterfaceToStr(in.NewUserId) + " and ((a.send_user_id= " + quitl.InterfaceToStr(in.NewUserId) + " and a.receive_user_id= " + quitl.InterfaceToStr(in.SendId) + ") or (a.send_user_id= " + quitl.InterfaceToStr(in.SendId) + " and a.receive_user_id= " + quitl.InterfaceToStr(in.NewUserId) + ")) and a.type=2 " + lastStr + " ORDER BY a.create_time desc ,a.id asc limit 0 , " + quitl.InterfaceToStr(in.PageSize)
|
|
|
+ countSql = "SELECT count(b.id) FROM socialize_message_mailbox a LEFT JOIN socialize_message b on a.messag_id=b.id left join base_user c on c.id=a.send_user_id left join base_user d on d.id=a.receive_user_id where a.own_id=" + quitl.InterfaceToStr(in.NewUserId) + " and ((a.send_user_id=" + quitl.InterfaceToStr(in.NewUserId) + " and a.receive_user_id=" + quitl.InterfaceToStr(in.SendId) + ") or (a.send_user_id=" + quitl.InterfaceToStr(in.SendId) + " and a.receive_user_id=" + quitl.InterfaceToStr(in.NewUserId) + ")) and a.type=2 " + lastStr
|
|
|
break
|
|
|
case 4, 5, 6, 7: //客服聊天
|
|
|
if in.UserType == 1 {
|
|
|
//客服聊天记录查看
|
|
|
- sqlStr = "SELECT a.messag_id as messageId,b.*, IF ( a.own_id = a.send_user_id, 1, 2 ) AS fool, a.send_user_type, a.type AS itemType, d.nickname AS robotName, d.headimage AS robotImg, c.customer_service_name AS setName , c.user_id FROM socialize_message_mailbox a LEFT JOIN socialize_message b ON a.messag_id = b.id LEFT JOIN socialize_chat_session c ON IF ( a.send_user_type = 1, c.id = a.send_user_id, c.id = a.receive_user_id ) LEFT JOIN socialize_tenant_robot d ON c.ent_id = d.ent_id WHERE a.own_type = 1 AND c.ent_id = ? AND c.user_id = ? AND (a.type = 5 or a.type=4 or a.type=6 or a.type=7) " + lastStr + " ORDER BY a.create_time desc ,a.id asc limit ? , ? "
|
|
|
- v = append(v, in.EntId, in.SendId, 0, in.PageSize)
|
|
|
- countSql = "SELECT count(b.id) FROM socialize_message_mailbox a LEFT JOIN socialize_message b ON a.messag_id = b.id LEFT JOIN socialize_chat_session c ON IF ( a.send_user_type = 1, c.id = a.send_user_id, c.id = a.receive_user_id ) LEFT JOIN socialize_tenant_robot d ON c.ent_id = d.ent_id WHERE a.own_type = 1 AND c.ent_id = ? AND c.user_id = ? AND (a.type = 5 or a.type=4) " + lastStr
|
|
|
- countV = append(countV, in.EntId, in.SendId)
|
|
|
+ sqlStr = "SELECT a.messag_id as messageId,b.*, IF ( a.own_id = a.send_user_id, 1, 2 ) AS fool, a.send_user_type, a.type AS itemType, d.nickname AS robotName, d.headimage AS robotImg, c.customer_service_name AS setName , c.user_id FROM socialize_message_mailbox a LEFT JOIN socialize_message b ON a.messag_id = b.id LEFT JOIN socialize_chat_session c ON IF ( a.send_user_type = 1, c.id = a.send_user_id, c.id = a.receive_user_id ) LEFT JOIN socialize_tenant_robot d ON c.ent_id = d.ent_id WHERE a.own_type = 1 AND c.ent_id = " + quitl.InterfaceToStr(in.EntId) + " AND c.user_id = " + quitl.InterfaceToStr(in.SendId) + " AND (a.type = 5 or a.type=4 or a.type=6 or a.type=7) " + lastStr + " ORDER BY a.create_time desc ,a.id asc limit 0 , " + quitl.InterfaceToStr(in.PageSize)
|
|
|
+ countSql = "SELECT count(b.id) FROM socialize_message_mailbox a LEFT JOIN socialize_message b ON a.messag_id = b.id LEFT JOIN socialize_chat_session c ON IF ( a.send_user_type = 1, c.id = a.send_user_id, c.id = a.receive_user_id ) LEFT JOIN socialize_tenant_robot d ON c.ent_id = d.ent_id WHERE a.own_type = 1 AND c.ent_id = " + quitl.InterfaceToStr(in.EntId) + " AND c.user_id = " + quitl.InterfaceToStr(in.SendId) + " AND (a.type = 5 or a.type=4 or a.type = 5 or a.type=4 or a.type=6 or a.type=7) " + lastStr
|
|
|
} else {
|
|
|
//用户聊天记录查看
|
|
|
- sqlStr = "SELECT a.messag_id as messageId, b.*, IF ( a.own_id = a.send_user_id, 1, 2 ) AS fool , a.send_user_type, a.type as itemType, d.nickname as robotName, d.headimage as robotImg, c.customer_service_name as setName FROM socialize_message_mailbox a LEFT JOIN socialize_message b ON a.messag_id = b.id LEFT JOIN socialize_chat_session c ON IF ( a.send_user_type = 1, c.id = a.send_user_id, c.id = a.receive_user_id ) left join socialize_tenant_robot d on c.ent_id=d.ent_id WHERE a.own_type = 2 AND c.ent_id =? AND a.own_id =? AND ( a.type = 4 OR a.type = 5 or a.type=6 or a.type=7) " + lastStr + " ORDER BY a.create_time desc ,a.id asc limit ? , ? "
|
|
|
- v = append(v, in.SendId, in.NewUserId, 0, in.PageSize)
|
|
|
- countSql = "SELECT count(a.id) FROM socialize_message_mailbox a LEFT JOIN socialize_message b ON a.messag_id = b.id LEFT JOIN socialize_chat_session c ON IF ( a.send_user_type = 1, c.id = a.send_user_id, c.id = a.receive_user_id ) left join socialize_tenant_robot d on c.ent_id=d.ent_id WHERE a.own_type = 2 AND c.ent_id =? AND a.own_id =? AND ( a.type = 4 OR a.type = 5 or a.type=6 or a.type=7) " + lastStr
|
|
|
- countV = append(countV, in.SendId, in.NewUserId)
|
|
|
+ sqlStr = "SELECT a.messag_id as messageId, b.*, IF ( a.own_id = a.send_user_id, 1, 2 ) AS fool , a.send_user_type, a.type as itemType, d.nickname as robotName, d.headimage as robotImg, c.customer_service_name as setName FROM socialize_message_mailbox a LEFT JOIN socialize_message b ON a.messag_id = b.id LEFT JOIN socialize_chat_session c ON IF ( a.send_user_type = 1, c.id = a.send_user_id, c.id = a.receive_user_id ) left join socialize_tenant_robot d on c.ent_id=d.ent_id WHERE a.own_type = 2 AND c.ent_id = " + quitl.InterfaceToStr(in.SendId) + " AND a.own_id = " + quitl.InterfaceToStr(in.NewUserId) + " AND ( a.type = 4 OR a.type = 5 or a.type=6 or a.type=7) " + lastStr + " ORDER BY a.create_time desc ,a.id asc limit 0 , " + quitl.InterfaceToStr(in.PageSize)
|
|
|
+ countSql = "SELECT count(a.id) FROM socialize_message_mailbox a LEFT JOIN socialize_message b ON a.messag_id = b.id LEFT JOIN socialize_chat_session c ON IF ( a.send_user_type = 1, c.id = a.send_user_id, c.id = a.receive_user_id ) left join socialize_tenant_robot d on c.ent_id=d.ent_id WHERE a.own_type = 2 AND c.ent_id =" + quitl.InterfaceToStr(in.SendId) + " AND a.own_id =" + quitl.InterfaceToStr(in.NewUserId) + " AND ( a.type = 4 OR a.type = 5 or a.type=6 or a.type=7) " + lastStr
|
|
|
}
|
|
|
break
|
|
|
}
|
|
|
- fmt.Println(sqlStr, v)
|
|
|
- fmt.Println(countSql, countV)
|
|
|
- data := Mysql.SelectBySql(sqlStr, v...)
|
|
|
- count := Mysql.CountBySql(countSql, countV...)
|
|
|
+ fmt.Println(sqlStr)
|
|
|
+ fmt.Println(countSql)
|
|
|
+ data := Mysql.SelectBySql(sqlStr)
|
|
|
+ stop1 := time.Now().Unix()
|
|
|
+ log.Println("sqlStr耗时", stop1-strat)
|
|
|
+ count := Mysql.CountBySql(countSql)
|
|
|
+ stop2 := time.Now().Unix()
|
|
|
+ log.Println("countSql耗时", stop2-stop1)
|
|
|
//自己头像处理
|
|
|
if in.UserType == 2 && count > 0 {
|
|
|
userData := Mysql.FindOne("base_user", map[string]interface{}{"id": in.NewUserId}, "headimg", "")
|
|
@@ -289,28 +286,34 @@ func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) (*[]map[strin
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- updateMap := map[string]interface{}{}
|
|
|
- if len(*data) > 0 {
|
|
|
- //未读信息修改
|
|
|
- switch in.MsgType {
|
|
|
- case 2: //点对点聊天
|
|
|
- updateMap = map[string]interface{}{
|
|
|
- "own_type": 2,
|
|
|
- "own_id": in.NewUserId,
|
|
|
- "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)})
|
|
|
- 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)
|
|
|
- } 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)
|
|
|
+ go func() {
|
|
|
+ updateMap := map[string]interface{}{}
|
|
|
+ if len(*data) > 0 {
|
|
|
+ //未读信息修改
|
|
|
+ switch in.MsgType {
|
|
|
+ case 2: //点对点聊天
|
|
|
+ updateMap = map[string]interface{}{
|
|
|
+ "own_type": 2,
|
|
|
+ "own_id": in.NewUserId,
|
|
|
+ "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)})
|
|
|
+ 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)
|
|
|
+ } 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)
|
|
|
+ }
|
|
|
+ break
|
|
|
}
|
|
|
- break
|
|
|
}
|
|
|
- }
|
|
|
+ }()
|
|
|
+
|
|
|
+ stop := time.Now().Unix()
|
|
|
+ log.Println("耗时", stop-strat)
|
|
|
+ log.Println("耗时", stop-stop2)
|
|
|
return data, count
|
|
|
}
|
|
|
func (b MessaggeService) CreateChatSession(in *messagecenter.ChatSessionReq) (errorCode, sessionId int64) {
|