From 72146c08ae9f9d04bf0e33053382568cbea869ff Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 8 Apr 2022 19:18:00 +0800 Subject: [PATCH 1/7] getui --- internal/push/getui/push.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/push/getui/push.go b/internal/push/getui/push.go index 253830373..fbdf3c778 100644 --- a/internal/push/getui/push.go +++ b/internal/push/getui/push.go @@ -126,6 +126,7 @@ func (g *Getui) Auth(operationID string, timeStamp int64) (token string, expireT Appkey: config.Config.Push.Getui.AppKey, } respAuth := AuthResp{} + err = g.request(AuthURL, reqAuth, "", &respAuth, operationID) if err != nil { return "", 0, err @@ -160,7 +161,9 @@ func (g *Getui) request(url string, content interface{}, token string, returnStr return err } log.NewInfo(operationID, "getui", utils.GetSelfFuncName(), "resp, ", string(result)) - if err := json.Unmarshal(result, returnStruct); err != nil { + commonResp := GetuiCommonResp{} + commonResp.Data = returnStruct + if err := json.Unmarshal(result, commonResp); err != nil { return err } return nil From fadbb91287bfdb7925aae10b02dc4fa8fdb6c268 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 8 Apr 2022 19:31:13 +0800 Subject: [PATCH 2/7] getui --- internal/push/getui/push.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/push/getui/push.go b/internal/push/getui/push.go index fbdf3c778..9b57c24ee 100644 --- a/internal/push/getui/push.go +++ b/internal/push/getui/push.go @@ -163,7 +163,7 @@ func (g *Getui) request(url string, content interface{}, token string, returnStr log.NewInfo(operationID, "getui", utils.GetSelfFuncName(), "resp, ", string(result)) commonResp := GetuiCommonResp{} commonResp.Data = returnStruct - if err := json.Unmarshal(result, commonResp); err != nil { + if err := json.Unmarshal(result, &commonResp); err != nil { return err } return nil From e0d612c92f6db72b28c7c9b121306bf4820fe060 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Mon, 11 Apr 2022 10:35:33 +0800 Subject: [PATCH 3/7] getui --- internal/push/getui/push.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/push/getui/push.go b/internal/push/getui/push.go index 9b57c24ee..1e391a406 100644 --- a/internal/push/getui/push.go +++ b/internal/push/getui/push.go @@ -75,6 +75,7 @@ func newGetuiClient() *Getui { func (g *Getui) Push(userIDList []string, alert, detailContent, platform, operationID string) (resp string, err error) { token, err := db.DB.GetGetuiToken() + log.NewDebug(operationID, utils.GetSelfFuncName(), "token:", token) if err != nil { log.NewError(operationID, utils.OperationIDGenerator(), "GetGetuiToken failed", err.Error()) } @@ -83,7 +84,7 @@ func (g *Getui) Push(userIDList []string, alert, detailContent, platform, operat if err != nil { return "", utils.Wrap(err, "Auth failed") } - log.NewInfo(operationID, "getui", utils.GetSelfFuncName(), token, expireTime, err) + log.NewDebug(operationID, "getui", utils.GetSelfFuncName(), token, expireTime, err) err = db.DB.SetGetuiToken(token, 60*60*23) if err != nil { return "", utils.Wrap(err, "Auth failed") @@ -148,7 +149,7 @@ func (g *Getui) request(url string, content interface{}, token string, returnStr return err } if token != "" { - req.Header.Set(token, token) + req.Header.Set("token", token) } req.Header.Set("content-type", "application/json") resp, err := client.Do(req) From 81a6e4b46cd51e005d729754b743d7e63374323d Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Mon, 11 Apr 2022 11:31:20 +0800 Subject: [PATCH 4/7] getui --- internal/push/getui/push.go | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/internal/push/getui/push.go b/internal/push/getui/push.go index 1e391a406..323df2a3a 100644 --- a/internal/push/getui/push.go +++ b/internal/push/getui/push.go @@ -53,8 +53,9 @@ type PushReq struct { Audience struct { Cid []string `json:"cid"` } `json:"audience"` - PushMssage struct { - Notification Notification `json:"notification"` + PushMessage struct { + Notification Notification `json:"notification,omitempty"` + Transmission string `json:"transmission,omitempty"` } `json:"push_message"` } @@ -62,8 +63,8 @@ type Notification struct { Title string `json:"title"` Body string `json:"body"` ClickType string `json:"click_type"` - Intent string `json:"intent"` - Url string `json:"url"` + //Intent string `json:"intent,omitempty"` + //Url string `json:"url,omitempty"` } type PushResp struct { @@ -96,14 +97,10 @@ func (g *Getui) Push(userIDList []string, alert, detailContent, platform, operat Cid []string `json:"cid"` }{Cid: []string{userIDList[0]}}, } - pushReq.PushMssage.Notification = Notification{ + pushReq.PushMessage.Notification = Notification{ Title: alert, Body: alert, - ClickType: "none", - } - if config.Config.Push.Getui.Intent != "" { - pushReq.PushMssage.Notification.Intent = config.Config.Push.Getui.Intent - pushReq.PushMssage.Notification.ClickType = "intent" + ClickType: "startapp", } pushResp := PushResp{} err = g.request(PushURL, pushReq, token, &pushResp, operationID) From 3085fffb4939f562278c1e27da817b85b4fb4b0b Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Mon, 11 Apr 2022 14:08:23 +0800 Subject: [PATCH 5/7] add department db --- pkg/common/db/model_struct.go | 47 +++++++++++ pkg/common/db/mysql.go | 152 +++------------------------------- 2 files changed, 60 insertions(+), 139 deletions(-) diff --git a/pkg/common/db/model_struct.go b/pkg/common/db/model_struct.go index 72396e9a1..41053b1c3 100644 --- a/pkg/common/db/model_struct.go +++ b/pkg/common/db/model_struct.go @@ -222,3 +222,50 @@ type Conversation struct { func (Conversation) TableName() string { return "conversations" } + +type Department struct { + DepartmentID string `gorm:"column:department_id;primary_key;size:64" json:"departmentID"` + FaceURL string `gorm:"column:face_url;size:255" json:"faceURL"` + Name string `gorm:"column:name;size:256" json:"name" binding:"required"` + ParentID string `gorm:"column:parent_id;size:64" json:"parentID" binding:"required"` + Order int32 `gorm:"column:order" json:"order" ` + DepartmentType int32 `gorm:"column:department_type" json:"departmentType"` + CreateTime time.Time `gorm:"column:create_time" json:"createTime"` + Ex string `gorm:"column:ex;type:varchar(1024)" json:"ex"` +} + +func (Department) TableName() string { + return "departments" +} + +type DepartmentUser struct { + UserID string `gorm:"column:user_id;primary_key;size:64"` + Nickname string `gorm:"column:nickname;size:256"` + EnglishName string `gorm:"column:english_name;size:256"` + FaceURL string `gorm:"column:face_url;size:256"` + Gender int32 `gorm:"column:gender"` + mobile string `gorm:"column:mobile;size:32"` + telephone string `gorm:"column:telephone;size:32"` + Birth time.Time `gorm:"column:birth"` + Email string `gorm:"column:email;size:64"` + CreateTime time.Time `gorm:"column:create_time"` + Ex string `gorm:"column:ex;size:1024"` +} + +func (DepartmentUser) TableName() string { + return "Department_users" +} + +type DepartmentMember struct { + userID string `gorm:"column:user_id;primary_key;size:64"` + DepartmentID string `gorm:"column:department_id;primary_key;size:64"` + Order int32 `gorm:"column:order" json:"order"` + Position string `gorm:"column:position;size:256" json:"position"` + Leader int32 `gorm:"column:leader" json:"leader"` + Status int32 `gorm:"column:status" json:"status"` + Ex string `gorm:"column:ex;type:varchar(1024)" json:"ex"` +} + +func (DepartmentMember) TableName() string { + return "department_members" +} diff --git a/pkg/common/db/mysql.go b/pkg/common/db/mysql.go index 32cf7458b..92ad6d309 100644 --- a/pkg/common/db/mysql.go +++ b/pkg/common/db/mysql.go @@ -82,169 +82,43 @@ func initMysqlDB() { fmt.Println("CreateTable GroupMember") db.CreateTable(&GroupMember{}) } - if !db.HasTable(&GroupRequest{}) { fmt.Println("CreateTable GroupRequest") db.CreateTable(&GroupRequest{}) } - if !db.HasTable(&User{}) { fmt.Println("CreateTable User") db.CreateTable(&User{}) } - if !db.HasTable(&Black{}) { fmt.Println("CreateTable Black") db.CreateTable(&Black{}) } if !db.HasTable(&ChatLog{}) { - fmt.Println("CreateTable Black") + fmt.Println("CreateTable ChatLog") db.CreateTable(&ChatLog{}) } if !db.HasTable(&Register{}) { - fmt.Println("CreateTable Black") + fmt.Println("CreateTable Register") db.CreateTable(&Register{}) } if !db.HasTable(&Conversation{}) { - fmt.Println("CreateTable Black") + fmt.Println("CreateTable Conversation") db.CreateTable(&Conversation{}) } - - return - - sqlTable := "CREATE TABLE IF NOT EXISTS `user` (" + - " `uid` varchar(64) NOT NULL," + - " `name` varchar(64) DEFAULT NULL," + - " `icon` varchar(1024) DEFAULT NULL," + - " `gender` tinyint(4) unsigned zerofill DEFAULT NULL," + - " `mobile` varchar(32) DEFAULT NULL," + - " `birth` varchar(16) DEFAULT NULL," + - " `email` varchar(64) DEFAULT NULL," + - " `ex` varchar(1024) DEFAULT NULL," + - " `create_time` datetime DEFAULT NULL," + - " PRIMARY KEY (`uid`)," + - " UNIQUE KEY `uk_uid` (`uid`)" + - " ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;" - err = db.Exec(sqlTable).Error - if err != nil { - panic(err.Error()) - } - - sqlTable = "CREATE TABLE IF NOT EXISTS `friend` (" + - " `owner_id` varchar(64) NOT NULL," + - " `friend_id` varchar(64) NOT NULL," + - " `comment` varchar(255) DEFAULT NULL," + - " `friend_flag` int(11) NOT NULL," + - " `create_time` datetime NOT NULL," + - " PRIMARY KEY (`owner_id`,`friend_id`) USING BTREE" + - " ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;" - err = db.Exec(sqlTable).Error - if err != nil { - panic(err.Error()) + if db.HasTable(&Department{}) { + fmt.Println("CreateTable Department") + db.CreateTable(&Department{}) } - - sqlTable = "CREATE TABLE IF NOT EXISTS `friend_request` (" + - " `req_id` varchar(64) NOT NULL," + - " `user_id` varchar(64) NOT NULL," + - " `flag` int(11) NOT NULL DEFAULT '0'," + - " `req_message` varchar(255) DEFAULT NULL," + - " `create_time` datetime NOT NULL," + - " PRIMARY KEY (`user_id`,`req_id`) USING BTREE" + - " ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;" - err = db.Exec(sqlTable).Error - if err != nil { - panic(err.Error()) + if db.HasTable(&DepartmentUser{}) { + fmt.Println("CreateTable DepartmentUser") + db.CreateTable(&DepartmentUser{}) } - - sqlTable = "CREATE TABLE IF NOT EXISTS `user_black_list` (" + - " `owner_id` varchar(64) NOT NULL," + - " `block_id` varchar(64) NOT NULL," + - " `create_time` datetime NOT NULL," + - " PRIMARY KEY (`owner_id`,`block_id`) USING BTREE" + - " ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;" - err = db.Exec(sqlTable).Error - if err != nil { - panic(err.Error()) + if db.HasTable(&DepartmentMember{}) { + fmt.Println("CreateTable DepartmentMember") + db.CreateTable(&DepartmentMember{}) } - - sqlTable = "CREATE TABLE IF NOT EXISTS `group` (" + - " `group_id` varchar(64) NOT NULL," + - " `name` varchar(255) DEFAULT NULL," + - " `introduction` varchar(255) DEFAULT NULL," + - " `notification` varchar(255) DEFAULT NULL," + - " `face_url` varchar(255) DEFAULT NULL," + - " `create_time` datetime DEFAULT NULL," + - " `ex` varchar(255) DEFAULT NULL," + - " PRIMARY KEY (`group_id`)" + - " ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;" - err = db.Exec(sqlTable).Error - if err != nil { - panic(err.Error()) - } - - sqlTable = "CREATE TABLE IF NOT EXISTS `group_member` (" + - " `group_id` varchar(64) NOT NULL," + - " `uid` varchar(64) NOT NULL," + - " `nickname` varchar(255) DEFAULT NULL," + - " `user_group_face_url` varchar(255) DEFAULT NULL," + - " `administrator_level` int(11) NOT NULL," + - " `join_time` datetime NOT NULL," + - " PRIMARY KEY (`group_id`,`uid`) USING BTREE" + - " ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;" - err = db.Exec(sqlTable).Error - if err != nil { - panic(err.Error()) - } - - sqlTable = "CREATE TABLE IF NOT EXISTS `group_request` (" + - " `id` int(11) NOT NULL AUTO_INCREMENT," + - " `group_id` varchar(64) NOT NULL," + - " `from_user_id` varchar(255) NOT NULL," + - " `to_user_id` varchar(255) NOT NULL," + - " `flag` int(10) NOT NULL DEFAULT '0'," + - " `req_msg` varchar(255) DEFAULT ''," + - " `handled_msg` varchar(255) DEFAULT ''," + - " `create_time` datetime NOT NULL," + - " `from_user_nickname` varchar(255) DEFAULT ''," + - " `to_user_nickname` varchar(255) DEFAULT NULL," + - " `from_user_face_url` varchar(255) DEFAULT ''," + - " `to_user_face_url` varchar(255) DEFAULT ''," + - " `handled_user` varchar(255) DEFAULT ''," + - " PRIMARY KEY (`id`)" + - " ) ENGINE=InnoDB AUTO_INCREMENT=38 DEFAULT CHARSET=utf8mb4;" - err = db.Exec(sqlTable).Error - if err != nil { - panic(err.Error()) - } - - sqlTable = "CREATE TABLE IF NOT EXISTS `chat_log` (" + - " `msg_id` varchar(128) NOT NULL," + - " `send_id` varchar(255) NOT NULL," + - " `session_type` int(11) NOT NULL," + - " `recv_id` varchar(255) NOT NULL," + - " `content_type` int(11) NOT NULL," + - " `msg_from` int(11) NOT NULL," + - " `content` varchar(1000) NOT NULL," + - " `remark` varchar(100) DEFAULT NULL," + - " `sender_platform_id` int(11) NOT NULL," + - " `send_time` datetime NOT NULL," + - " PRIMARY KEY (`msg_id`) USING BTREE" + - " ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;" - err = db.Exec(sqlTable).Error - if err != nil { - panic(err.Error()) - } - - sqlTable = "CREATE TABLE IF NOT EXISTS `register` (" + - " `account` varchar(255) NOT NULL," + - " `password` varchar(255) NOT NULL," + - " PRIMARY KEY (`account`) USING BTREE" + - " ) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;" - err = db.Exec(sqlTable).Error - if err != nil { - panic(err.Error()) - } - + return } func (m *mysqlDB) DefaultGormDB() (*gorm.DB, error) { From edcc215774086f95177528b55b2d3b9cd1139f95 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Mon, 11 Apr 2022 14:41:09 +0800 Subject: [PATCH 6/7] getui --- internal/push/getui/push.go | 31 ++++++++++++++++++++++--------- pkg/common/http/http_resp.go | 4 ++-- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/internal/push/getui/push.go b/internal/push/getui/push.go index 323df2a3a..d95aca887 100644 --- a/internal/push/getui/push.go +++ b/internal/push/getui/push.go @@ -68,6 +68,7 @@ type Notification struct { } type PushResp struct { + GetuiCommonResp } func newGetuiClient() *Getui { @@ -81,14 +82,10 @@ func (g *Getui) Push(userIDList []string, alert, detailContent, platform, operat log.NewError(operationID, utils.OperationIDGenerator(), "GetGetuiToken failed", err.Error()) } if token == "" || err != nil { - token, expireTime, err := g.Auth(operationID, time.Now().UnixNano()/1e6) + token, err = g.getTokenAndSave2Redis(operationID) if err != nil { - return "", utils.Wrap(err, "Auth failed") - } - log.NewDebug(operationID, "getui", utils.GetSelfFuncName(), token, expireTime, err) - err = db.DB.SetGetuiToken(token, 60*60*23) - if err != nil { - return "", utils.Wrap(err, "Auth failed") + log.NewError(operationID, utils.GetSelfFuncName(), "getTokenAndSave2Redis failed", err.Error()) + return "", utils.Wrap(err, "") } } pushReq := PushReq{ @@ -107,8 +104,12 @@ func (g *Getui) Push(userIDList []string, alert, detailContent, platform, operat if err != nil { return "", utils.Wrap(err, "push failed") } + log.NewDebug(operationID, utils.GetSelfFuncName(), "resp: ", pushResp) + if pushResp.Code == 10001 { + _, _ = g.getTokenAndSave2Redis(operationID) + } respBytes, err := json.Marshal(pushResp) - return string(respBytes), err + return string(respBytes), utils.Wrap(err, "") } func (g *Getui) Auth(operationID string, timeStamp int64) (token string, expireTime int64, err error) { @@ -124,7 +125,6 @@ func (g *Getui) Auth(operationID string, timeStamp int64) (token string, expireT Appkey: config.Config.Push.Getui.AppKey, } respAuth := AuthResp{} - err = g.request(AuthURL, reqAuth, "", &respAuth, operationID) if err != nil { return "", 0, err @@ -166,3 +166,16 @@ func (g *Getui) request(url string, content interface{}, token string, returnStr } return nil } + +func (g *Getui) getTokenAndSave2Redis(operationID string) (token string, err error) { + token, expireTime, err := g.Auth(operationID, time.Now().UnixNano()/1e6) + if err != nil { + return "", utils.Wrap(err, "Auth failed") + } + log.NewDebug(operationID, "getui", utils.GetSelfFuncName(), token, expireTime, err) + err = db.DB.SetGetuiToken(token, 60*60*23) + if err != nil { + return "", utils.Wrap(err, "Auth failed") + } + return token, nil +} diff --git a/pkg/common/http/http_resp.go b/pkg/common/http/http_resp.go index 8292b6884..cdbf04463 100644 --- a/pkg/common/http/http_resp.go +++ b/pkg/common/http/http_resp.go @@ -38,6 +38,6 @@ func RespHttp200(ctx *gin.Context, err error, data interface{}) { } // warp error -func WrapError(err constant.ErrInfo, msg ...string) error { - return status.Error(codes.Code(err.ErrCode), err.ErrMsg+msg[0]) +func WrapError(err constant.ErrInfo) error { + return status.Error(codes.Code(err.ErrCode), err.ErrMsg) } From 13473eeb4d35d0c9894711c82133680130e26847 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Mon, 11 Apr 2022 14:44:58 +0800 Subject: [PATCH 7/7] getui --- internal/rpc/group/group.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go index 6fa270394..b4520e92a 100644 --- a/internal/rpc/group/group.go +++ b/internal/rpc/group/group.go @@ -656,7 +656,7 @@ func (s *groupServer) GetGroupById(_ context.Context, req *pbGroup.GetGroupByIdR }} group, err := imdb.GetGroupById(req.GroupId) if err != nil { - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "GetGroupById error", err.Error()) + log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupById error", err.Error()) return resp, http.WrapError(constant.ErrDB) } resp.CMSGroup.GroupInfo = &open_im_sdk.GroupInfo{