Parcourir la source

用户给机器人发送信息

WH01243 il y a 3 ans
Parent
commit
1e2035027e

+ 1 - 1
rpc/messagecenter/internal/logic/countlogic.go

@@ -38,7 +38,7 @@ func (l *CountLogic) Count(in *messagecenter.CountReq) (*messagecenter.CountResp
 		messageEntity = messagecenter.MessageEntity{
 		messageEntity = messagecenter.MessageEntity{
 			Title:      quitl.ObjToString(last["title"]),
 			Title:      quitl.ObjToString(last["title"]),
 			Content:    quitl.ObjToString(last["content"]),
 			Content:    quitl.ObjToString(last["content"]),
-			CreateTime: quitl.ObjToString(last["create_time"]),
+			CreateTime: quitl.Int64All(last["create_time"]),
 			Item:       quitl.Int64All(last["item"]),
 			Item:       quitl.Int64All(last["item"]),
 			Type:       quitl.Int64All(last["type"]),
 			Type:       quitl.Int64All(last["type"]),
 			Link:       quitl.ObjToString(last["link"]),
 			Link:       quitl.ObjToString(last["link"]),

+ 2 - 3
rpc/messagecenter/internal/logic/findmessagelogic.go

@@ -30,13 +30,13 @@ func NewFindMessageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FindM
 func (l *FindMessageLogic) FindMessage(in *messagecenter.MessageReq) (*messagecenter.MessageResp, error) {
 func (l *FindMessageLogic) FindMessage(in *messagecenter.MessageReq) (*messagecenter.MessageResp, error) {
 	// todo: add your logic here and delete this line
 	// todo: add your logic here and delete this line
 	m := service.MessaggeService{}
 	m := service.MessaggeService{}
-	data, count := m.FindMessage(in)
+	data := m.FindMessage(in)
 	list := []*messagecenter.MessageEntity{}
 	list := []*messagecenter.MessageEntity{}
 	for _, v := range *data {
 	for _, v := range *data {
 		messageEntity := messagecenter.MessageEntity{
 		messageEntity := messagecenter.MessageEntity{
 			Title:      quitl.ObjToString(v["title"]),
 			Title:      quitl.ObjToString(v["title"]),
 			Content:    quitl.ObjToString(v["content"]),
 			Content:    quitl.ObjToString(v["content"]),
-			CreateTime: quitl.ObjToString(v["create_time"]),
+			CreateTime: quitl.Int64All(v["create_time"]),
 			Item:       quitl.Int64All(v["item"]),
 			Item:       quitl.Int64All(v["item"]),
 			Type:       quitl.Int64All(v["type"]),
 			Type:       quitl.Int64All(v["type"]),
 			Link:       quitl.ObjToString(v["link"]),
 			Link:       quitl.ObjToString(v["link"]),
@@ -52,7 +52,6 @@ func (l *FindMessageLogic) FindMessage(in *messagecenter.MessageReq) (*messagece
 	}
 	}
 	return &messagecenter.MessageResp{
 	return &messagecenter.MessageResp{
 		Data:      list,
 		Data:      list,
-		Count:     count,
 		ErrorCode: 0,
 		ErrorCode: 0,
 	}, nil
 	}, nil
 }
 }

+ 4 - 3
rpc/messagecenter/internal/logic/savemessagelogic.go

@@ -30,7 +30,7 @@ func NewSaveMessageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveM
 func (l *SaveMessageLogic) SaveMessage(in *messagecenter.MessageEntity) (*messagecenter.SaveMessageResp, error) {
 func (l *SaveMessageLogic) SaveMessage(in *messagecenter.MessageEntity) (*messagecenter.SaveMessageResp, error) {
 	// todo: add your logic here and delete this line
 	// todo: add your logic here and delete this line
 	m := service.MessaggeService{}
 	m := service.MessaggeService{}
-	fool, error_message, content, messageId := m.SaveMessage(in)
+	fool, error_message, content, messageId, nowTime := m.SaveMessage(in)
 	error_code := int64(0)
 	error_code := int64(0)
 	if fool {
 	if fool {
 		error_code = int64(0)
 		error_code = int64(0)
@@ -41,8 +41,9 @@ func (l *SaveMessageLogic) SaveMessage(in *messagecenter.MessageEntity) (*messag
 		ErrorCode: error_code,
 		ErrorCode: error_code,
 		ErrorMsg:  error_message,
 		ErrorMsg:  error_message,
 		Data: &messagecenter.MessageEntity{
 		Data: &messagecenter.MessageEntity{
-			Content:   content,
-			MessageId: encrypt.SE.Encode2Hex(quitl.InterfaceToStr(messageId)),
+			Content:    content,
+			MessageId:  encrypt.SE.Encode2Hex(quitl.InterfaceToStr(messageId)),
+			CreateTime: nowTime,
 		},
 		},
 	}, nil
 	}, nil
 }
 }

+ 1 - 1
rpc/messagecenter/messagecenter.proto

@@ -69,7 +69,7 @@ message MessageEntity {
   int64         item = 3;
   int64         item = 3;
   int64         type = 4;
   int64         type = 4;
   string        link = 5;
   string        link = 5;
-  string        create_time = 6;
+  int64         create_time = 6;
   string        appid=7;
   string        appid=7;
   int64         itemType=8;
   int64         itemType=8;
   int64         sendId=9;
   int64         sendId=9;

+ 4 - 4
rpc/messagecenter/messagecenter/messagecenter.pb.go

@@ -694,7 +694,7 @@ type MessageEntity struct {
 	Item       int64  `protobuf:"varint,3,opt,name=item,proto3" json:"item,omitempty"`
 	Item       int64  `protobuf:"varint,3,opt,name=item,proto3" json:"item,omitempty"`
 	Type       int64  `protobuf:"varint,4,opt,name=type,proto3" json:"type,omitempty"`
 	Type       int64  `protobuf:"varint,4,opt,name=type,proto3" json:"type,omitempty"`
 	Link       string `protobuf:"bytes,5,opt,name=link,proto3" json:"link,omitempty"`
 	Link       string `protobuf:"bytes,5,opt,name=link,proto3" json:"link,omitempty"`
-	CreateTime string `protobuf:"bytes,6,opt,name=create_time,json=createTime,proto3" json:"create_time,omitempty"`
+	CreateTime int64  `protobuf:"varint,6,opt,name=create_time,json=createTime,proto3" json:"create_time,omitempty"`
 	Appid      string `protobuf:"bytes,7,opt,name=appid,proto3" json:"appid,omitempty"`
 	Appid      string `protobuf:"bytes,7,opt,name=appid,proto3" json:"appid,omitempty"`
 	ItemType   int64  `protobuf:"varint,8,opt,name=itemType,proto3" json:"itemType,omitempty"`
 	ItemType   int64  `protobuf:"varint,8,opt,name=itemType,proto3" json:"itemType,omitempty"`
 	SendId     int64  `protobuf:"varint,9,opt,name=sendId,proto3" json:"sendId,omitempty"`
 	SendId     int64  `protobuf:"varint,9,opt,name=sendId,proto3" json:"sendId,omitempty"`
@@ -777,11 +777,11 @@ func (x *MessageEntity) GetLink() string {
 	return ""
 	return ""
 }
 }
 
 
-func (x *MessageEntity) GetCreateTime() string {
+func (x *MessageEntity) GetCreateTime() int64 {
 	if x != nil {
 	if x != nil {
 		return x.CreateTime
 		return x.CreateTime
 	}
 	}
-	return ""
+	return 0
 }
 }
 
 
 func (x *MessageEntity) GetAppid() string {
 func (x *MessageEntity) GetAppid() string {
@@ -1362,7 +1362,7 @@ var file_messageCenter_proto_rawDesc = []byte{
 	0x65, 0x6d, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03,
 	0x65, 0x6d, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03,
 	0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6c, 0x69, 0x6e, 0x6b, 0x18, 0x05,
 	0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6c, 0x69, 0x6e, 0x6b, 0x18, 0x05,
 	0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6c, 0x69, 0x6e, 0x6b, 0x12, 0x1f, 0x0a, 0x0b, 0x63, 0x72,
 	0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6c, 0x69, 0x6e, 0x6b, 0x12, 0x1f, 0x0a, 0x0b, 0x63, 0x72,
-	0x65, 0x61, 0x74, 0x65, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52,
+	0x65, 0x61, 0x74, 0x65, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x03, 0x52,
 	0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x61,
 	0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x61,
 	0x70, 0x70, 0x69, 0x64, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x61, 0x70, 0x70, 0x69,
 	0x70, 0x70, 0x69, 0x64, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x61, 0x70, 0x70, 0x69,
 	0x64, 0x12, 0x1a, 0x0a, 0x08, 0x69, 0x74, 0x65, 0x6d, 0x54, 0x79, 0x70, 0x65, 0x18, 0x08, 0x20,
 	0x64, 0x12, 0x1a, 0x0a, 0x08, 0x69, 0x74, 0x65, 0x6d, 0x54, 0x79, 0x70, 0x65, 0x18, 0x08, 0x20,

+ 30 - 28
service/message_mail_box.go

@@ -47,7 +47,7 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
 		data = util.Mysql.SelectBySql(customerSql, in.NewUserId)
 		data = util.Mysql.SelectBySql(customerSql, in.NewUserId)
 		customerMessageId := util.Inhandle(data)
 		customerMessageId := util.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"
+		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.own_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"
 		v = append(v, in.NewUserId, in.NewUserId, in.NewUserId, in.NewUserId, in.NewUserId)
 		v = append(v, in.NewUserId, in.NewUserId, in.NewUserId, in.NewUserId, in.NewUserId)
 	} else {
 	} else {
 		phoneSql := ""
 		phoneSql := ""
@@ -63,18 +63,17 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
 			endTimeSql = " and DATE_FORMAT(c.create_time,'%Y-%m-%d') <= '" + in.EndTime + "' "
 			endTimeSql = " and DATE_FORMAT(c.create_time,'%Y-%m-%d') <= '" + in.EndTime + "' "
 		}
 		}
 		//先获取每个用户最后聊天记录
 		//先获取每个用户最后聊天记录
-		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 or  c.type=6 or  c.type=7 )   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     ) "
+		userSql := " SELECT   MAX( c.id ) as messageId   FROM   socialize_message_mailbox c   LEFT JOIN socialize_chat_session d ON   c.own_type=1 and  c.own_id=d.id   WHERE   c.own_type = 1    AND d.customer_service_id = ?   and ( c.type = 4 OR c.type = 5 or  c.type=6 or  c.type=7 )   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)
 		v = append(v, in.EntUserId)
 		log.Println(userSql, v)
 		log.Println(userSql, v)
 		data = util.Mysql.SelectBySql(userSql, v...)
 		data = util.Mysql.SelectBySql(userSql, v...)
 		if data != nil {
 		if data != nil {
 			customerMessageId := util.Inhandle(data)
 			customerMessageId := util.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,  a.create_time,  (  SELECT   count( h.id )   FROM   socialize_message_mailbox h   WHERE   (  h.type = 4 OR h.type = 5 or  h.type=6 or  h.type=7 )    AND h.own_type = 1    AND  h.own_id = f.id      AND h.isread = 0   ) AS number   FROM  socialize_message_mailbox a  LEFT JOIN base_user b ON  IF  ( a.send_user_type = 1, b.id = a.receive_user_id, b.id = a.send_user_id )  LEFT JOIN socialize_message e ON e.id = a.messag_id  LEFT JOIN socialize_chat_session f ON  IF  ( a.send_user_type = 1, f.id = a.send_user_id, f.id = a.receive_user_id )   WHERE  a.id IN  (" + customerMessageId + ")" + phoneSql + "   ORDER BY  a.create_time DESC"
+			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,  a.create_time,  (  SELECT   count( h.id )   FROM   socialize_message_mailbox h  left join socialize_chat_session i ON a.own_type = 1 AND a.own_id = i.id     WHERE     h.own_type = 1    AND  i.id=f.id      AND h.isread = 0   ) AS number   FROM  socialize_message_mailbox a  LEFT JOIN base_user b ON  a.own_type=2 and b.id = a.own_id    LEFT JOIN socialize_message e ON e.id = a.messag_id  LEFT JOIN socialize_chat_session f ON a.own_type=1 and  a.own_id=f.id   WHERE  a.id IN  (" + customerMessageId + ")" + phoneSql + "   ORDER BY  a.create_time DESC"
 			fmt.Println(in.EntUserId)
 			fmt.Println(in.EntUserId)
 			v = make([]interface{}, 0)
 			v = make([]interface{}, 0)
 		}
 		}
-
 	}
 	}
 	if sqlStr != "" {
 	if sqlStr != "" {
 		fmt.Println(sqlStr, v)
 		fmt.Println(sqlStr, v)
@@ -82,9 +81,10 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
 	}
 	}
 	return
 	return
 }
 }
-func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool, errorMsg string, content string, messageId int64) {
+func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool, errorMsg string, content string, messageId, nowInt int64) {
 	//先插入信息表
 	//先插入信息表
 	//判断会话标识是否属于本人
 	//判断会话标识是否属于本人
+	nowForm := time.Now().Local()
 	if in.ItemType != 2 {
 	if in.ItemType != 2 {
 		userId := int64(0)
 		userId := int64(0)
 		sessionId := int64(0)
 		sessionId := int64(0)
@@ -114,10 +114,10 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
 		//查找会话信息
 		//查找会话信息
 		chatJson := util.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 {
 		if chatJson == nil {
-			return false, "会话标识不存在", "", 0
+			return false, "会话标识不存在", "", 0, nowForm.Unix()
 		} else {
 		} else {
 			if userId != quitl.Int64All((*chatJson)["user_id"]) {
 			if userId != quitl.Int64All((*chatJson)["user_id"]) {
-				return false, "会话标识不属于此用户", "", 0
+				return false, "会话标识不属于此用户", "", 0, nowForm.Unix()
 			}
 			}
 		}
 		}
 	}
 	}
@@ -130,7 +130,7 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
 			"item":          in.ItemType,
 			"item":          in.ItemType,
 			"type":          in.Type,
 			"type":          in.Type,
 			"link":          in.Link,
 			"link":          in.Link,
-			"create_time":   time.Now().Local().Format(util.Date_Full_Layout),
+			"create_time":   nowForm.Format(util.Date_Full_Layout),
 			"create_person": in.SendId,
 			"create_person": in.SendId,
 		}
 		}
 		ok := util.Mysql.InsertByTx(tx, "socialize_message", message)
 		ok := util.Mysql.InsertByTx(tx, "socialize_message", message)
@@ -141,7 +141,7 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
 			"appid":         in.Appid,
 			"appid":         in.Appid,
 			"messag_id":     ok,
 			"messag_id":     ok,
 			"type":          in.ItemType,
 			"type":          in.ItemType,
-			"create_time":   time.Now().Local().Format(util.Date_Full_Layout),
+			"create_time":   nowForm.Format(util.Date_Full_Layout),
 			"isread":        0,
 			"isread":        0,
 			"send_isdel":    0,
 			"send_isdel":    0,
 			"receive_isdel": 0,
 			"receive_isdel": 0,
@@ -153,8 +153,8 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
 				"appid":         in.Appid,
 				"appid":         in.Appid,
 				"messag_id":     ok,
 				"messag_id":     ok,
 				"type":          in.ItemType,
 				"type":          in.ItemType,
-				"create_time":   time.Now().Local().Format(util.Date_Full_Layout),
-				"read_time":     time.Now().Local().Format(util.Date_Full_Layout),
+				"create_time":   nowForm.Format(util.Date_Full_Layout),
+				"read_time":     nowForm.Format(util.Date_Full_Layout),
 				"isread":        1,
 				"isread":        1,
 				"send_isdel":    0,
 				"send_isdel":    0,
 				"receive_isdel": 0,
 				"receive_isdel": 0,
@@ -168,7 +168,7 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
 				messageMailBox["own_id"] = in.NewUserId
 				messageMailBox["own_id"] = in.NewUserId
 				messageMailBox["send_user_id"] = in.ReceiveId
 				messageMailBox["send_user_id"] = in.ReceiveId
 				messageMailBox["receive_user_id"] = in.NewUserId
 				messageMailBox["receive_user_id"] = in.NewUserId
-			} else {
+			} else if in.OwnType == 2 {
 				//客服接受系统信息
 				//客服接受系统信息
 				messageMailBox["own_type"] = 1
 				messageMailBox["own_type"] = 1
 				messageMailBox["send_user_type"] = 2
 				messageMailBox["send_user_type"] = 2
@@ -176,10 +176,19 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
 				messageMailBox["own_id"] = in.SendId
 				messageMailBox["own_id"] = in.SendId
 				messageMailBox["send_user_id"] = in.ReceiveId
 				messageMailBox["send_user_id"] = in.ReceiveId
 				messageMailBox["receive_user_id"] = in.SendId
 				messageMailBox["receive_user_id"] = in.SendId
+
+			} else {
+				//客服接受系统信息
+				messageMailBox["own_type"] = 1
+				messageMailBox["send_user_type"] = 2
+				messageMailBox["receive_user_type"] = 1
+				messageMailBox["own_id"] = in.ReceiveId
+				messageMailBox["send_user_id"] = in.NewUserId
+				messageMailBox["receive_user_id"] = in.ReceiveId
 			}
 			}
 			if in.ItemType == 4 {
 			if in.ItemType == 4 {
 				messageMailBox["isread"] = 1
 				messageMailBox["isread"] = 1
-				messageMailBox["read_time"] = time.Now().Format(util.Date_Full_Layout)
+				messageMailBox["read_time"] = nowForm.Format(util.Date_Full_Layout)
 			}
 			}
 			receiveOk = util.Mysql.InsertByTx(tx, "socialize_message_mailbox", messageMailBox)
 			receiveOk = util.Mysql.InsertByTx(tx, "socialize_message_mailbox", messageMailBox)
 			return ok > 1 && receiveOk > 1
 			return ok > 1 && receiveOk > 1
@@ -206,7 +215,7 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
 					messageMailBox["receive_user_id"] = in.NewUserId
 					messageMailBox["receive_user_id"] = in.NewUserId
 					messageMailBox["own_id"] = in.NewUserId
 					messageMailBox["own_id"] = in.NewUserId
 					messageMailBox["isread"] = 1
 					messageMailBox["isread"] = 1
-					messageMailBox["read_time"] = time.Now().Format(util.Date_Full_Layout)
+					messageMailBox["read_time"] = nowForm.Format(util.Date_Full_Layout)
 				}
 				}
 			}
 			}
 		} else {
 		} else {
@@ -222,8 +231,8 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
 			"appid":         in.Appid,
 			"appid":         in.Appid,
 			"messag_id":     ok,
 			"messag_id":     ok,
 			"type":          in.ItemType,
 			"type":          in.ItemType,
-			"create_time":   time.Now().Local().Format(util.Date_Full_Layout),
-			"read_time":     time.Now().Local().Format(util.Date_Full_Layout),
+			"create_time":   nowForm.Format(util.Date_Full_Layout),
+			"read_time":     nowForm.Format(util.Date_Full_Layout),
 			"isread":        1,
 			"isread":        1,
 			"send_isdel":    0,
 			"send_isdel":    0,
 			"receive_isdel": 0,
 			"receive_isdel": 0,
@@ -263,12 +272,10 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
 		receiveOk = util.Mysql.InsertByTx(tx, "socialize_message_mailbox", messageMailBox)
 		receiveOk = util.Mysql.InsertByTx(tx, "socialize_message_mailbox", messageMailBox)
 		return ok > 1 && receiveOk > 1
 		return ok > 1 && receiveOk > 1
 	})
 	})
-	return fool, "", in.Content, messageId
-
+	return fool, "", in.Content, messageId, nowForm.Unix()
 }
 }
-func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) (*[]map[string]interface{}, int64) {
+func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) *[]map[string]interface{} {
 	sqlStr := ""
 	sqlStr := ""
-	countSql := ""
 	lastStr := "  "
 	lastStr := "  "
 	if in.LastId > 0 {
 	if in.LastId > 0 {
 		if in.Sort == "asc" {
 		if in.Sort == "asc" {
@@ -280,26 +287,21 @@ func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) (*[]map[strin
 	switch in.MsgType {
 	switch in.MsgType {
 	case 2: //点对点聊天
 	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= " + 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)
 		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
 		break
 	case 4, 5, 6, 7: //客服聊天
 	case 4, 5, 6, 7: //客服聊天
 		if in.UserType == 1 {
 		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 )  AND c.ent_id =  " + quitl.InterfaceToStr(in.EntId) + "   AND c.user_id =  " + quitl.InterfaceToStr(in.SendId) + "   LEFT JOIN socialize_tenant_robot d ON c.ent_id = d.ent_id      WHERE   a.own_type = 1      AND (a.type = 5 or a.type=4 or  a.type=6 or  a.type=7)   AND c.ent_id =  " + quitl.InterfaceToStr(in.EntId) + "   AND c.user_id =  " + quitl.InterfaceToStr(in.SendId) + 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 )   AND c.ent_id = " + quitl.InterfaceToStr(in.EntId) + "   AND c.user_id = " + quitl.InterfaceToStr(in.SendId) + "  LEFT JOIN socialize_tenant_robot d ON c.ent_id = d.ent_id       WHERE   a.own_type = 1       AND (a.type = 5 or a.type=4 or a.type = 5  or  a.type=6 or  a.type=7)   AND c.ent_id = " + quitl.InterfaceToStr(in.EntId) + "   AND c.user_id = " + quitl.InterfaceToStr(in.SendId) + "" + lastStr
+			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,   '' AS robotName,   '' 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      a.own_type = 1  and  a.own_id=c.id    WHERE   a.own_type = 1      AND (a.type = 5 or a.type=4 or  a.type=6 or  a.type=7)   AND c.ent_id =  " + quitl.InterfaceToStr(in.EntId) + "   AND c.user_id =  " + quitl.InterfaceToStr(in.SendId) + lastStr + "  ORDER BY a.create_time desc ,a.id   asc limit 0 , " + quitl.InterfaceToStr(in.PageSize)
 		} else {
 		} 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 ) and  c.ent_id =" + quitl.InterfaceToStr(in.SendId) + " AND c.user_id = " + quitl.InterfaceToStr(in.NewUserId) + "     left join  socialize_tenant_robot d on  c.ent_id=d.ent_id    WHERE   a.own_type = 2    AND a.own_id = " + quitl.InterfaceToStr(in.NewUserId) + "  and  c.ent_id =" + quitl.InterfaceToStr(in.SendId) + " AND c.user_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)
 			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 ) and  c.ent_id =" + quitl.InterfaceToStr(in.SendId) + " AND c.user_id = " + quitl.InterfaceToStr(in.NewUserId) + "     left join  socialize_tenant_robot d on  c.ent_id=d.ent_id    WHERE   a.own_type = 2    AND a.own_id = " + quitl.InterfaceToStr(in.NewUserId) + "  and  c.ent_id =" + quitl.InterfaceToStr(in.SendId) + " AND c.user_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 ) and  c.ent_id = " + quitl.InterfaceToStr(in.SendId) + " AND c.user_id = " + quitl.InterfaceToStr(in.NewUserId) + "     left join  socialize_tenant_robot d on  c.ent_id=d.ent_id      WHERE   a.own_type = 2      AND a.own_id =" + quitl.InterfaceToStr(in.NewUserId) + "    AND ( a.type = 4 OR a.type = 5  or a.type=6 or  a.type=7)   and  c.ent_id = " + quitl.InterfaceToStr(in.SendId) + " AND c.user_id = " + quitl.InterfaceToStr(in.NewUserId) + "" + lastStr
 		}
 		}
 		break
 		break
 	}
 	}
 	log.Println(sqlStr)
 	log.Println(sqlStr)
-	log.Println(countSql)
 	data := util.Mysql.SelectBySql(sqlStr)
 	data := util.Mysql.SelectBySql(sqlStr)
-	count := util.Mysql.CountBySql(countSql)
 	//自己头像处理
 	//自己头像处理
-	if in.UserType == 2 && count > 0 {
+	if in.UserType == 2 {
 		userData := util.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 {
 		if userData != nil {
 			for key := range *data {
 			for key := range *data {
@@ -332,7 +334,7 @@ func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) (*[]map[strin
 			}
 			}
 		}
 		}
 	}()
 	}()
-	return data, count
+	return data
 }
 }
 func (b MessaggeService) CreateChatSession(in *messagecenter.ChatSessionReq) (fool bool, sessionId int64) {
 func (b MessaggeService) CreateChatSession(in *messagecenter.ChatSessionReq) (fool bool, sessionId int64) {
 	fool = util.Mysql.ExecTx("会话新建", func(tx *sql.Tx) bool {
 	fool = util.Mysql.ExecTx("会话新建", func(tx *sql.Tx) bool {

+ 4 - 6
service/message_mail_box_test.go

@@ -155,11 +155,11 @@ func TestMessaggeService_FindMessage(t *testing.T) {
 		{
 		{
 			name: "客服获取历史信息查询",
 			name: "客服获取历史信息查询",
 			args: args{in: &messagecenter.MessageReq{
 			args: args{in: &messagecenter.MessageReq{
-				MsgType:   4,
+				MsgType:   5,
 				UserType:  1,
 				UserType:  1,
 				SendId:    10,
 				SendId:    10,
 				PageSize:  10,
 				PageSize:  10,
-				NewUserId: 10,
+				NewUserId: 4338,
 				EntId:     1,
 				EntId:     1,
 			}},
 			}},
 			want1: 0,
 			want1: 0,
@@ -241,13 +241,11 @@ func TestMessaggeService_FindMessage(t *testing.T) {
 	for _, tt := range tests {
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
 		t.Run(tt.name, func(t *testing.T) {
 			b := MessaggeService{}
 			b := MessaggeService{}
-			got, got1 := b.FindMessage(tt.args.in)
+			got := b.FindMessage(tt.args.in)
 			if !reflect.DeepEqual(got, tt.want) {
 			if !reflect.DeepEqual(got, tt.want) {
 				t.Errorf("FindMessage() got = %v, want %v", 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)
-			}
+
 		})
 		})
 	}
 	}
 }
 }