WH01243 3 anni fa
parent
commit
bdeda34c58
4 ha cambiato i file con 359 aggiunte e 39 eliminazioni
  1. 8 0
      entity/db.go
  2. 3 6
      rpc/messagecenter/init/init.go
  3. 29 33
      service/message_mail_box.go
  4. 319 0
      service/message_mail_box_test.go

+ 8 - 0
entity/db.go

@@ -1,5 +1,9 @@
 package entity
 
+import (
+	"app.yhyue.com/moapp/jybase/mysql"
+)
+
 type MysqlMainStruct struct {
 	DbName       string `json:"dbName"`
 	Address      string `json:"address"`
@@ -8,3 +12,7 @@ type MysqlMainStruct struct {
 	MaxOpenConns int    `json:"maxOpenConns"`
 	MaxIdleConns int    `json:"maxIdleConns"`
 }
+
+var (
+	Mysql *mysql.Mysql
+)

+ 3 - 6
rpc/messagecenter/init/init.go

@@ -19,17 +19,14 @@ var logc entity.Logc
 
 var C config.Config
 
-var (
-	Mysql *mysql.Mysql
-)
-
 func init() {
+	log.Println(11111111)
 	conf.MustLoad(*configF, &C)
 	//初始化mysql
 	mm := C.MysqlMain
 	if mm.Address != "" {
 		log.Println("--初始化 mysql--")
-		Mysql = &mysql.Mysql{
+		entity.Mysql = &mysql.Mysql{
 			Address:      mm.Address,
 			UserName:     mm.UserName,
 			PassWord:     mm.PassWord,
@@ -37,7 +34,7 @@ func init() {
 			MaxOpenConns: mm.MaxOpenConns,
 			MaxIdleConns: mm.MaxIdleConns,
 		}
-		Mysql.Init()
+		entity.Mysql.Init()
 
 	}
 

+ 29 - 33
service/message_mail_box.go

@@ -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
 			}
 		}

+ 319 - 0
service/message_mail_box_test.go

@@ -0,0 +1,319 @@
+package service
+
+import (
+	"app.yhyue.com/moapp/jybase/mysql"
+	"bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/entity"
+	"bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/rpc/messagecenter/messagecenter"
+	"reflect"
+	"testing"
+)
+
+func initMysql() {
+	entity.Mysql = &mysql.Mysql{
+		Address:      "192.168.3.217:4000",
+		UserName:     "root",
+		PassWord:     "=PDT49#80Z!RVv52_z",
+		DBName:       "base_service",
+		MaxOpenConns: 5,
+		MaxIdleConns: 5,
+	}
+	entity.Mysql.Init()
+}
+func init() {
+	initMysql()
+}
+func TestInhandle(t *testing.T) {
+	type args struct {
+		data *[]map[string]interface{}
+	}
+	tests := []struct {
+		name       string
+		args       args
+		wantMessId string
+	}{
+		// TODO: Add test cases.
+
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			if gotMessId := Inhandle(tt.args.data); gotMessId != tt.wantMessId {
+				t.Errorf("Inhandle() = %v, want %v", gotMessId, tt.wantMessId)
+			}
+		})
+	}
+}
+
+func TestMessaggeService_CloseChatSession(t *testing.T) {
+	type args struct {
+		in *messagecenter.CloseSessionReq
+	}
+	tests := []struct {
+		name          string
+		args          args
+		wantErrorCode int64
+	}{
+		// TODO: Add test cases.
+		{
+			name: "关闭会话",
+			args: args{
+				in: &messagecenter.CloseSessionReq{
+					SessionId: 4626,
+				},
+			}},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			b := MessaggeService{}
+			if gotErrorCode := b.CloseChatSession(tt.args.in); gotErrorCode != tt.wantErrorCode {
+				t.Errorf("CloseChatSession() = %v, want %v", gotErrorCode, tt.wantErrorCode)
+			}
+		})
+	}
+}
+
+func TestMessaggeService_Count(t *testing.T) {
+	type args struct {
+		newUserId int64
+		userType  int64
+		entUserId int64
+	}
+	tests := []struct {
+		name      string
+		args      args
+		wantCount int
+		wantLast  map[string]interface{}
+		wantErr   bool
+	}{
+		// TODO: Add test cases.
+		{
+			name: "未读信息总数",
+			args: args{
+				newUserId: 831,
+				userType:  2,
+			},
+			wantCount: 0,
+		},
+	}
+
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			b := MessaggeService{}
+			gotCount, gotLast, err := b.Count(tt.args.newUserId, tt.args.userType, tt.args.entUserId)
+			if (err != nil) != tt.wantErr {
+				t.Errorf("Count() error = %v, wantErr %v", err, tt.wantErr)
+				return
+			}
+			if gotCount != tt.wantCount {
+				t.Errorf("Count() gotCount = %v, want %v", gotCount, tt.wantCount)
+			}
+			if !reflect.DeepEqual(gotLast, tt.wantLast) {
+				t.Errorf("Count() gotLast = %v, want %v", gotLast, tt.wantLast)
+			}
+		})
+	}
+}
+
+func TestMessaggeService_CreateChatSession(t *testing.T) {
+	type args struct {
+		in *messagecenter.ChatSessionReq
+	}
+	tests := []struct {
+		name          string
+		args          args
+		wantErrorCode int64
+		wantSessionId int64
+	}{
+		// TODO: Add test cases.
+		{
+			name: "会话新建",
+			args: args{
+				in: &messagecenter.ChatSessionReq{
+					EntId:               14184,
+					UserId:              4962,
+					CustomerServiceId:   121,
+					AppId:               "10000",
+					CustomerserviceName: "客服1",
+				},
+			},
+			wantSessionId: 0,
+			wantErrorCode: 0,
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			b := MessaggeService{}
+			gotErrorCode, gotSessionId := b.CreateChatSession(tt.args.in)
+			if gotErrorCode != tt.wantErrorCode {
+				t.Errorf("CreateChatSession() gotErrorCode = %v, want %v", gotErrorCode, tt.wantErrorCode)
+			}
+			if gotSessionId != tt.wantSessionId {
+				t.Errorf("CreateChatSession() gotSessionId = %v, want %v", gotSessionId, tt.wantSessionId)
+			}
+		})
+	}
+}
+
+func TestMessaggeService_FindMessage(t *testing.T) {
+	type args struct {
+		in *messagecenter.MessageReq
+	}
+	tests := []struct {
+		name  string
+		args  args
+		want  *[]map[string]interface{}
+		want1 int64
+	}{
+		// TODO: Add test cases.
+		{
+			name: "历史信息查询",
+			args: args{in: &messagecenter.MessageReq{
+				MsgType:   4,
+				UserType:  1,
+				SendId:    1180,
+				PageSize:  10,
+				NewUserId: 831,
+			}},
+			want1: 0,
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			b := MessaggeService{}
+			got, got1 := b.FindMessage(tt.args.in)
+			if !reflect.DeepEqual(got, tt.want) {
+				t.Errorf("FindMessage() got = %v, want %v", got, tt.want)
+			}
+			if got1 != tt.want1 {
+				t.Errorf("FindMessage() got1 = %v, want %v", got1, tt.want1)
+			}
+		})
+	}
+}
+
+func TestMessaggeService_SaveAutoReplyMsg(t *testing.T) {
+	type args struct {
+		userType  int64
+		entId     int64
+		entUserId int64
+		userId    int64
+		content   string
+		appId     string
+		nowFormat string
+	}
+	tests := []struct {
+		name string
+		args args
+		want bool
+	}{
+		// TODO: Add test cases.
+		{
+			name: "会话保存以及消息保存",
+			args: args{
+				userType:  0,
+				entId:     0,
+				entUserId: 0,
+				userId:    0,
+				content:   "",
+				appId:     "",
+				nowFormat: "",
+			},
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			m := &MessaggeService{}
+			if got := m.SaveAutoReplyMsg(tt.args.userType, tt.args.entId, tt.args.entUserId, tt.args.userId, tt.args.content, tt.args.appId, tt.args.nowFormat); got != tt.want {
+				t.Errorf("SaveAutoReplyMsg() = %v, want %v", got, tt.want)
+			}
+		})
+	}
+}
+
+func TestMessaggeService_SaveMessage(t *testing.T) {
+	type args struct {
+		in *messagecenter.MessageEntity
+	}
+	tests := []struct {
+		name          string
+		args          args
+		wantErrorCode int64
+		wantErrorMsg  string
+		wantContent   string
+		wantMessageId int64
+	}{
+		// TODO: Add test cases.
+		{name: "消息保存",
+			args: args{
+				in: &messagecenter.MessageEntity{
+					Title:     "11",
+					Content:   "问在吗?",
+					Item:      8,
+					ItemType:  6,
+					Link:      "1111",
+					Appid:     "10000",
+					ReceiveId: 2,
+					SendId:    4626,
+					OwnType:   int64(2),
+					Type:      1,
+				},
+			},
+		}}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			b := MessaggeService{}
+			gotErrorCode, gotErrorMsg, gotContent, gotMessageId := b.SaveMessage(tt.args.in)
+			if gotErrorCode != tt.wantErrorCode {
+				t.Errorf("SaveMessage() gotErrorCode = %v, want %v", gotErrorCode, tt.wantErrorCode)
+			}
+			if gotErrorMsg != tt.wantErrorMsg {
+				t.Errorf("SaveMessage() gotErrorMsg = %v, want %v", gotErrorMsg, tt.wantErrorMsg)
+			}
+			if gotContent != tt.wantContent {
+				t.Errorf("SaveMessage() gotContent = %v, want %v", gotContent, tt.wantContent)
+			}
+			if gotMessageId != tt.wantMessageId {
+				t.Errorf("SaveMessage() gotMessageId = %v, want %v", gotMessageId, tt.wantMessageId)
+			}
+		})
+	}
+}
+
+func TestMessaggeService_UserList(t *testing.T) {
+	type args struct {
+		in *messagecenter.UserReq
+	}
+	tests := []struct {
+		name     string
+		args     args
+		wantData *[]map[string]interface{}
+		wantErr  bool
+	}{
+		// TODO: Add test cases.
+		{
+			name: "用户列表查询",
+			args: args{
+				in: &messagecenter.UserReq{
+					Phone:     "",
+					UserType:  1,
+					StartTime: "",
+					EndTime:   "",
+					NewUserId: 42941,
+					EntUserId: 42711,
+				},
+			},
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			b := MessaggeService{}
+			gotData, err := b.UserList(tt.args.in)
+			if (err != nil) != tt.wantErr {
+				t.Errorf("UserList() error = %v, wantErr %v", err, tt.wantErr)
+				return
+			}
+			if !reflect.DeepEqual(gotData, tt.wantData) {
+				t.Errorf("UserList() gotData = %v, want %v", gotData, tt.wantData)
+			}
+		})
+	}
+}