xuzhiheng před 4 roky
rodič
revize
363631a357

+ 14 - 1
entity/message.go

@@ -20,8 +20,21 @@ type Message struct {
 	Title         string    `xorm:"title" form:"title" json:"title"`
 	MsgType       int       `xorm:"msg_type" form:"msg_type" json:"msg_type"`
 	Link          string    `xorm:"link" form:"link" json:"link"`
-	CiteId        string    `xorm:"cite_id" form:"cite_id" json:"cite_id"`
+	CiteId        int       `xorm:"cite_id" form:"cite_id" json:"cite_id"`
 	Content       string    `xorm:"content" form:"content" json:"content"` // '内容
 	IsRead        int       `xorm:"isRead" form:"isRead" json:"isRead"`    //  '0:未读  1:已读'
 	Isdel         int       `xorm:"isdel" form:"isdel" json:"isdel"`       // 1:未删除  -1:已删除
 }
+
+type Conversation struct {
+	Id          int       `xorm:"id" form:"id" json:"id"`
+	AppId       string    `xorm:"appid" form:"appid" json:"appid"`
+	Key         string    `xorm:"key" form:"key" json:"key"`
+	UserId      string    `xorm:"user_id" form:"user_id" json:"user_id"`
+	ReceiveId   string    `xorm:"receive_id" form:"receive_id" json:"receive_id"`
+	ReceiveName string    `xorm:"receive_name" form:"receive_name" json:"receive_name"`
+	SendId      string    `xorm:"send_id" form:"send_id" json:"send_id"`
+	SendName    string    `xorm:"send_name" form:"send_name" json:"send_name"`
+	Sort        int       `xorm:"sort" form:"sort" json:"sort"`
+	CreateTime  time.Time `xorm:"createtime" form:"createtime" json:"createtime"` // 创建时间
+}

+ 1 - 1
rpc/message.proto

@@ -11,7 +11,7 @@ message SendMsgRequest {
 	string content = 6; //内容
 	int64 msgType = 7; //消息类型 1:客服   2:系统通知  3:营销   4:用户会话
 	string link = 8; //跳转链接
-	string citeId = 9; //引用id
+	int64 citeId = 9; //引用id
 	string appid = 10; //应用标识
 }
 

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

@@ -42,7 +42,7 @@ type SendMsgRequest struct {
 	Content       string `protobuf:"bytes,6,opt,name=content,proto3" json:"content,omitempty"`             //内容
 	MsgType       int64  `protobuf:"varint,7,opt,name=msgType,proto3" json:"msgType,omitempty"`            //消息类型 1:客服   2:系统通知  3:营销   4:用户会话
 	Link          string `protobuf:"bytes,8,opt,name=link,proto3" json:"link,omitempty"`                   //跳转链接
-	CiteId        string `protobuf:"bytes,9,opt,name=citeId,proto3" json:"citeId,omitempty"`               //引用id
+	CiteId        int64  `protobuf:"varint,9,opt,name=citeId,proto3" json:"citeId,omitempty"`              //引用id
 	Appid         string `protobuf:"bytes,10,opt,name=appid,proto3" json:"appid,omitempty"`                //应用标识
 }
 
@@ -134,11 +134,11 @@ func (x *SendMsgRequest) GetLink() string {
 	return ""
 }
 
-func (x *SendMsgRequest) GetCiteId() string {
+func (x *SendMsgRequest) GetCiteId() int64 {
 	if x != nil {
 		return x.CiteId
 	}
-	return ""
+	return 0
 }
 
 func (x *SendMsgRequest) GetAppid() string {
@@ -286,7 +286,7 @@ var file_message_proto_rawDesc = []byte{
 	0x18, 0x0a, 0x07, 0x6d, 0x73, 0x67, 0x54, 0x79, 0x70, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x03,
 	0x52, 0x07, 0x6d, 0x73, 0x67, 0x54, 0x79, 0x70, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6c, 0x69, 0x6e,
 	0x6b, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6c, 0x69, 0x6e, 0x6b, 0x12, 0x16, 0x0a,
-	0x06, 0x63, 0x69, 0x74, 0x65, 0x49, 0x64, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x63,
+	0x06, 0x63, 0x69, 0x74, 0x65, 0x49, 0x64, 0x18, 0x09, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x63,
 	0x69, 0x74, 0x65, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x61, 0x70, 0x70, 0x69, 0x64, 0x18, 0x0a,
 	0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x61, 0x70, 0x70, 0x69, 0x64, 0x22, 0x5f, 0x0a, 0x17, 0x43,
 	0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x65, 0x61, 0x64, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52,

+ 1 - 1
rpc/messageclient/message.go

@@ -14,9 +14,9 @@ import (
 )
 
 type (
-	SendMsgRequest          = message.SendMsgRequest
 	ChangeReadStatusRequest = message.ChangeReadStatusRequest
 	Response                = message.Response
+	SendMsgRequest          = message.SendMsgRequest
 
 	Message interface {
 		// 修改消息阅读状态

+ 31 - 0
rpc/test/send_test.go

@@ -0,0 +1,31 @@
+package test
+
+import (
+	"context"
+	"log"
+	"testing"
+	"time"
+
+	"app.yhyue.com/moapp/MessageCenter/rpc/messageclient"
+	"github.com/tal-tech/go-zero/core/discov"
+	"github.com/tal-tech/go-zero/zrpc"
+)
+
+func Test_SendMsg(t *testing.T) {
+	ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
+	std := messageclient.NewMessage(zrpc.MustNewClient(zrpc.RpcClientConf{Etcd: discov.EtcdConf{Hosts: []string{"127.0.0.1:2379"}, Key: "message.rpc"}}))
+	req := &messageclient.SendMsgRequest{
+		Appid:         "10000",
+		ReceiveUserId: "6042120adca8410f1ef2ec84",
+		ReceiveName:   "rjj",
+		SendUserId:    "5fa3bb6d059e75bcdf8dab6a",
+		SendName:      "xzh",
+		Title:         "超级订阅",
+		Content:       "2333333",
+		Link:          "",
+		CiteId:        int64(3),
+		MsgType:       int64(4),
+	}
+	res, err := std.SendUserMsg(ctx, req)
+	log.Println("err ", err, res)
+}

+ 38 - 1
service/sendMsg.go

@@ -14,6 +14,43 @@ func SendMsg(this message.SendMsgRequest) (int64, string) {
 	defer orm.Close()
 	err := orm.Begin()
 	fmt.Println(err)
+	count, _ := orm.Table("conversation").Select("*").Where("user_id = ? or user_id = ?", this.ReceiveUserId, this.SendUserId).Count()
+	if count < 1 {
+		conversation := entity.Conversation{
+			AppId:       this.Appid,
+			ReceiveId:   this.ReceiveUserId,
+			ReceiveName: this.ReceiveName,
+			SendId:      this.SendUserId,
+			SendName:    this.SendName,
+			CreateTime:  time.Now(),
+			Sort:        0,
+			UserId:      this.SendUserId,
+			Key:         "",
+		}
+		_, err = orm.Table("conversation").Insert(&conversation)
+		if err != nil {
+			log.Panicln("会话创建失败:", err)
+			orm.Rollback()
+			return -1, "会话创建失败"
+		}
+		conversations := entity.Conversation{
+			AppId:       this.Appid,
+			ReceiveId:   this.ReceiveUserId,
+			ReceiveName: this.ReceiveName,
+			SendId:      this.SendUserId,
+			SendName:    this.SendName,
+			CreateTime:  time.Now(),
+			Sort:        0,
+			UserId:      this.ReceiveUserId,
+			Key:         "",
+		}
+		_, err = orm.Table("conversation").Insert(&conversations)
+		if err != nil {
+			log.Panicln("会话创建失败:", err)
+			orm.Rollback()
+			return -1, "会话创建失败"
+		}
+	}
 	message := entity.Message{
 		AppId:         this.Appid,
 		ReceiveUserid: this.ReceiveUserId,
@@ -24,7 +61,7 @@ func SendMsg(this message.SendMsgRequest) (int64, string) {
 		Title:         this.Title,
 		MsgType:       int(this.MsgType),
 		Link:          this.Link,
-		CiteId:        this.CiteId,
+		CiteId:        int(this.CiteId),
 		Content:       this.Content,
 		IsRead:        0,
 		Isdel:         1,