|
@@ -2,6 +2,7 @@ package service
|
|
|
|
|
|
import (
|
|
|
quitl "app.yhyue.com/moapp/jybase/common"
|
|
|
+ "app.yhyue.com/moapp/jybase/encrypt"
|
|
|
util "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/entity"
|
|
|
"bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/rpc/messagecenter/messagecenter"
|
|
|
"database/sql"
|
|
@@ -12,8 +13,9 @@ import (
|
|
|
|
|
|
type MessaggeService struct{}
|
|
|
|
|
|
-//未读消息查询
|
|
|
+// 未读消息查询
|
|
|
func (b MessaggeService) Count(newUserId, userType, entUserId int64, isClean bool) (count int, last map[string]interface{}, err error) {
|
|
|
+ log.Printf("用户id:%d,userType:%d,entUserId:%d,isClean:%v", newUserId, userType, entUserId, isClean)
|
|
|
v := make([]interface{}, 0)
|
|
|
sqlStr := ""
|
|
|
if userType == 1 {
|
|
@@ -80,7 +82,7 @@ func (b MessaggeService) Count(newUserId, userType, entUserId int64, isClean boo
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-//用户列表查询
|
|
|
+// 用户列表查询
|
|
|
func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string]interface{}, err error) {
|
|
|
sqlStr := ""
|
|
|
if in.UserType == 2 {
|
|
@@ -160,9 +162,9 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
|
|
|
userSql := fmt.Sprintf("SELECT MAX( c.id ) as messageId FROM %s c "+
|
|
|
"LEFT JOIN %s d ON c.own_type=1 AND c.own_id=d.id "+
|
|
|
"WHERE c.own_type = 1 "+
|
|
|
- "AND d.customer_service_id = %d "+
|
|
|
+ "AND (d.customer_service_id = %d or d.customer_service_id =0 ) "+
|
|
|
"AND ( c.type = 4 OR c.type = 5 or c.type=6 or c.type=7 ) "+
|
|
|
- "AND d.customer_service_id !=0 %s %s "+
|
|
|
+ " %s %s "+
|
|
|
"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)
|
|
@@ -179,7 +181,7 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
|
|
|
"AND i.ent_id=f.ent_id "+
|
|
|
"AND i.user_id=f.user_id "+
|
|
|
"AND h.isread = 0 "+
|
|
|
- "AND i.customer_service_id= %d ) AS number "+
|
|
|
+ "AND (i.customer_service_id= %d or i.customer_service_id=0) ) AS number "+
|
|
|
"FROM %s a "+
|
|
|
"LEFT JOIN %s b ON if (a.send_user_type=1 ,a.receive_user_id,a.send_user_id)=b.id "+
|
|
|
"LEFT JOIN %s e ON e.id = a.messag_id "+
|
|
@@ -196,7 +198,7 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-//消息保存
|
|
|
+// 消息保存
|
|
|
func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool, errorMsg string, content string, messageId, nowInt int64) {
|
|
|
//先插入信息表
|
|
|
//判断会话标识是否属于本人
|
|
@@ -416,7 +418,7 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
|
|
|
return fool, "", in.Content, messageId, nowForm.Unix()
|
|
|
}
|
|
|
|
|
|
-//历史信息查询
|
|
|
+// 历史信息查询
|
|
|
func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) *[]map[string]interface{} {
|
|
|
sqlStr := ""
|
|
|
lastStr := ""
|
|
@@ -434,7 +436,7 @@ func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) *[]map[string
|
|
|
"LEFT JOIN %s b on a.messag_id=b.id "+
|
|
|
"LEFT JOIN %s c on c.id=a.send_user_id "+
|
|
|
"LEFT JOIN %s d on d.id=a.receive_user_id "+
|
|
|
- "where a.own_id= %d "+
|
|
|
+ "where a.own_id= %d and a.iswithdraw = 0"+
|
|
|
"AND ((a.send_user_id= %d AND a.receive_user_id= %d) or (a.send_user_id= %d AND a.receive_user_id= %d)) "+
|
|
|
"AND a.type=2 %s "+
|
|
|
"ORDER BY a.create_time desc ,a.id asc "+
|
|
@@ -449,7 +451,7 @@ func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) *[]map[string
|
|
|
"FROM %s a "+
|
|
|
"LEFT JOIN %s b ON a.messag_id = b.id "+
|
|
|
"LEFT JOIN %s c ON a.own_type = 1 AND a.own_id=c.id "+
|
|
|
- "WHERE a.own_type = 1 "+
|
|
|
+ "WHERE a.own_type = 1 and a.iswithdraw = 0 "+
|
|
|
"AND (a.type = 5 or a.type=4 or a.type=6 or a.type=7) "+
|
|
|
"AND c.ent_id = %d "+
|
|
|
"AND c.user_id = %d %s "+
|
|
@@ -464,7 +466,7 @@ func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) *[]map[string
|
|
|
"LEFT JOIN %s b ON a.messag_id = b.id "+
|
|
|
"LEFT JOIN %s c ON IF ( a.send_user_type = 1, a.send_user_id, a.receive_user_id ) = c.id AND c.ent_id = %d AND c.user_id = %d "+
|
|
|
"LEFT JOIN %s d on c.ent_id=d.ent_id "+
|
|
|
- "WHERE a.own_type = 2 "+
|
|
|
+ "WHERE a.own_type = 2 and a.iswithdraw = 0 "+
|
|
|
"AND a.own_id = %d "+
|
|
|
"AND c.ent_id = %d "+
|
|
|
"AND c.user_id = %d "+
|
|
@@ -507,14 +509,14 @@ func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) *[]map[string
|
|
|
sqlStr := ""
|
|
|
if in.UserType == 1 {
|
|
|
sqlStr = fmt.Sprintf("UPDATE %s a SET a.isread = 1, a.read_time = now( ) "+
|
|
|
- "WHERE a.own_type = 1 "+
|
|
|
+ "WHERE a.own_type = 1 and a.iswithdraw = 0 "+
|
|
|
"AND a.type IN ( 4,5,6,7) "+
|
|
|
"AND a.isread = 0 "+
|
|
|
"AND a.own_id IN ( SELECT b.id FROM %s b WHERE b.customer_service_id=%d AND b.user_id=%d )",
|
|
|
util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_CHAT_SESSION, in.EntUserId, in.SendId)
|
|
|
} else {
|
|
|
sqlStr = fmt.Sprintf("UPDATE %s a SET a.isread = 1, a.read_time = now( ) "+
|
|
|
- "WHERE a.own_type = 2 "+
|
|
|
+ "WHERE a.own_type = 2 and a.iswithdraw = 0 "+
|
|
|
"AND a.type IN ( 4,5,6,7 ) "+
|
|
|
"AND a.isread = 0 "+
|
|
|
"AND a.own_id =%d ", util.SOCIALIZE_MESSAGE_MAILBOX, in.NewUserId)
|
|
@@ -529,7 +531,7 @@ func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) *[]map[string
|
|
|
return data
|
|
|
}
|
|
|
|
|
|
-//创建会话
|
|
|
+// 创建会话
|
|
|
func (b MessaggeService) CreateChatSession(in *messagecenter.ChatSessionReq) (fool bool, sessionId int64) {
|
|
|
fool = util.Mysql.ExecTx("会话新建", func(tx *sql.Tx) bool {
|
|
|
customerserviceName := in.CustomerserviceName
|
|
@@ -565,7 +567,7 @@ func (b MessaggeService) CreateChatSession(in *messagecenter.ChatSessionReq) (fo
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-//结束会话
|
|
|
+// 结束会话
|
|
|
func (b MessaggeService) CloseChatSession(in *messagecenter.CloseSessionReq) bool {
|
|
|
fool := util.Mysql.ExecTx("关闭会话", func(tx *sql.Tx) bool {
|
|
|
updateMap := map[string]interface{}{
|
|
@@ -577,7 +579,7 @@ func (b MessaggeService) CloseChatSession(in *messagecenter.CloseSessionReq) boo
|
|
|
return fool
|
|
|
}
|
|
|
|
|
|
-//创建会话并保存信息
|
|
|
+// 创建会话并保存信息
|
|
|
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 {
|
|
@@ -604,7 +606,7 @@ func (b *MessaggeService) SaveAutoReplyMsg(userType, entId, entUserId, userId in
|
|
|
}), messageId
|
|
|
}
|
|
|
|
|
|
-//修改未读状态
|
|
|
+// 修改未读状态
|
|
|
func (b MessaggeService) UpdateReadById(in *messagecenter.ReadStateReq) bool {
|
|
|
fool := util.Mysql.ExecTx("已读状态修改", func(tx *sql.Tx) bool {
|
|
|
updateMap := map[string]interface{}{
|
|
@@ -643,3 +645,12 @@ func (b MessaggeService) UpdateReadById(in *messagecenter.ReadStateReq) bool {
|
|
|
})
|
|
|
return fool
|
|
|
}
|
|
|
+
|
|
|
+// WithdrawMessage 撤回消息
|
|
|
+func (b MessaggeService) WithdrawMessage(in *messagecenter.ReadWithdrawReq) bool {
|
|
|
+ messageId := encrypt.SE.Decode4Hex(in.MessageId)
|
|
|
+ nowForm := time.Now().Local()
|
|
|
+
|
|
|
+ return util.Mysql.Update(util.SOCIALIZE_MESSAGE_MAILBOX,
|
|
|
+ map[string]interface{}{"id": messageId}, map[string]interface{}{"messag_id": messageId, "iswithdraw": 1, "withdraw_time": nowForm.Format(util.Date_Full_Layout)})
|
|
|
+}
|