Refactor code

pull/141/head
wenxu12345 3 years ago
parent 18babef78b
commit 45816fa84f

@ -101,7 +101,7 @@ func (s *friendServer) AddFriend(ctx context.Context, req *pbFriend.AddFriendReq
}
//Establish a latest relationship in the friend request table
friendRequest := db.FriendRequest{ReqMsg: req.ReqMsg, HandleResult: 0}
friendRequest := db.FriendRequest{ReqMsg: req.ReqMsg, HandleResult: 0, CreateTime: time.Now()}
utils.CopyStructFields(&friendRequest, req.CommID)
// {openIM001 openIM002 0 test add friend 0001-01-01 00:00:00 +0000 UTC 0001-01-01 00:00:00 +0000 UTC }]
log.NewDebug(req.CommID.OperationID, "UpdateFriendApplication args ", friendRequest)

@ -3,6 +3,7 @@ package im_mysql_model
import (
"Open_IM/pkg/common/db"
"Open_IM/pkg/utils"
"errors"
"time"
)
@ -71,32 +72,43 @@ func UpdateFriendApplication(friendRequest *db.FriendRequest) error {
friendRequest.FromUserID, friendRequest.ToUserID).Update(&friendRequest).Error
}
func InsertFriendApplication(friendRequest *db.FriendRequest, args map[string]interface{}) error {
func InsertFriendApplication(friendRequest *db.FriendRequest) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
friendRequest.CreateTime = time.Now()
args["create_time"] = friendRequest.CreateTime
u := dbConn.Model(friendRequest).Updates(args)
//u := dbConn.Table("friend_requests").Where("from_user_id=? and to_user_id=?",
// friendRequest.FromUserID, friendRequest.ToUserID).Update(&friendRequest)
//u := dbConn.Table("friend_requests").Where("from_user_id=? and to_user_id=?",
// friendRequest.FromUserID, friendRequest.ToUserID).Update(&friendRequest)
if u.RowsAffected != 0 {
if err = dbConn.Table("friend_requests").Create(friendRequest).Error; err == nil {
return nil
}
if friendRequest.CreateTime.Unix() < 0 {
friendRequest.CreateTime = time.Now()
}
if friendRequest.HandleTime.Unix() < 0 {
friendRequest.HandleTime = utils.UnixSecondToTime(0)
}
err = dbConn.Table("friend_requests").Create(friendRequest).Error
if err != nil {
return err
t := dbConn.Model(friendRequest).Select("*").Updates(*friendRequest)
if t.RowsAffected == 0 {
return utils.Wrap(errors.New("RowsAffected == 0"), "no update")
}
return nil
return utils.Wrap(t.Error, "")
//
//friendRequest.CreateTime = time.Now()
//args["create_time"] = friendRequest.CreateTime
//u := dbConn.Model(friendRequest).Updates(args)
////u := dbConn.Table("friend_requests").Where("from_user_id=? and to_user_id=?",
//// friendRequest.FromUserID, friendRequest.ToUserID).Update(&friendRequest)
////u := dbConn.Table("friend_requests").Where("from_user_id=? and to_user_id=?",
//// friendRequest.FromUserID, friendRequest.ToUserID).Update(&friendRequest)
//if u.RowsAffected != 0 {
// return nil
//}
//
//if friendRequest.CreateTime.Unix() < 0 {
// friendRequest.CreateTime = time.Now()
//}
//if friendRequest.HandleTime.Unix() < 0 {
// friendRequest.HandleTime = utils.UnixSecondToTime(0)
//}
//err = dbConn.Table("friend_requests").Create(friendRequest).Error
//if err != nil {
// return err
//}
//return nil
}

Loading…
Cancel
Save