add birthStr field

pull/351/head
wangchuxiao 2 years ago
parent 16b3ea8b7e
commit 2610a27894

@ -28,8 +28,13 @@ func (rpc *rpcAuth) UserRegister(_ context.Context, req *pbAuth.UserRegisterReq)
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
var user db.User
utils.CopyStructFields(&user, req.UserInfo)
if req.UserInfo.Birth != 0 {
user.Birth = utils.UnixSecondToTime(int64(req.UserInfo.Birth))
if req.UserInfo.BirthStr != "" {
time, err := utils.TimeStringToTime(req.UserInfo.BirthStr)
if err != nil {
log.NewError(req.OperationID, "TimeStringToTime failed ", err.Error(), req.UserInfo.BirthStr)
return &pbAuth.UserRegisterResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrArgs.ErrCode, ErrMsg: "TimeStringToTime failed:" + err.Error()}}, nil
}
user.Birth = time
}
log.Debug(req.OperationID, "copy ", user, req.UserInfo)
err := imdb.UserRegister(user)

@ -125,7 +125,6 @@ func syncPeerUserConversation(conversation *pbConversation.Conversation, operati
func (s *userServer) GetUserInfo(ctx context.Context, req *pbUser.GetUserInfoReq) (*pbUser.GetUserInfoResp, error) {
log.NewInfo(req.OperationID, "GetUserInfo args ", req.String())
var userInfoList []*sdkws.UserInfo
if len(req.UserIDList) > 0 {
for _, userID := range req.UserIDList {
@ -136,7 +135,7 @@ func (s *userServer) GetUserInfo(ctx context.Context, req *pbUser.GetUserInfoReq
continue
}
utils.CopyStructFields(&userInfo, user)
userInfo.Birth = uint32(user.Birth.Unix())
userInfo.BirthStr = utils.TimeToString(user.Birth)
userInfoList = append(userInfoList, &userInfo)
}
} else {
@ -411,8 +410,14 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI
}
var user db.User
utils.CopyStructFields(&user, req.UserInfo)
if req.UserInfo.Birth != 0 {
user.Birth = utils.UnixSecondToTime(int64(req.UserInfo.Birth))
if req.UserInfo.BirthStr != "" {
time, err := utils.TimeStringToTime(req.UserInfo.BirthStr)
if err != nil {
log.NewError(req.OperationID, "TimeStringToTime failed ", err.Error(), req.UserInfo.BirthStr)
return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrArgs.ErrCode, ErrMsg: "TimeStringToTime failed:" + err.Error()}}, nil
}
user.Birth = time
}
err := imdb.UpdateUserInfo(user)
@ -600,7 +605,7 @@ func (s *userServer) GetUsers(ctx context.Context, req *pbUser.GetUsersReq) (*pb
var user sdkws.UserInfo
utils.CopyStructFields(&user, userDB)
user.CreateTime = uint32(userDB.CreateTime.Unix())
user.Birth = uint32(userDB.Birth.Unix())
user.BirthStr = utils.TimeToString(userDB.Birth)
resp.UserList = append(resp.UserList, &pbUser.CmsUser{User: &user})
}
@ -628,7 +633,7 @@ func (s *userServer) GetUsers(ctx context.Context, req *pbUser.GetUsersReq) (*pb
func (s *userServer) AddUser(ctx context.Context, req *pbUser.AddUserReq) (*pbUser.AddUserResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbUser.AddUserResp{CommonResp: &pbUser.CommonResp{}}
err := imdb.AddUser(req.UserInfo.UserID, req.UserInfo.PhoneNumber, req.UserInfo.Nickname, req.UserInfo.Email, req.UserInfo.Gender, req.UserInfo.FaceURL, req.UserInfo.Birth)
err := imdb.AddUser(req.UserInfo.UserID, req.UserInfo.PhoneNumber, req.UserInfo.Nickname, req.UserInfo.Email, req.UserInfo.Gender, req.UserInfo.FaceURL, req.UserInfo.BirthStr)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "AddUser", err.Error(), req.String())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode

@ -17,6 +17,7 @@ type ApiUserInfo struct {
CreateTime int64 `json:"createTime"`
LoginLimit int32 `json:"loginLimit" binding:"omitempty"`
Ex string `json:"ex" binding:"omitempty,max=1024"`
BirthStr string `json:"birthStr" binding:"omitempty"`
}
//type Conversation struct {

@ -7,7 +7,6 @@ import (
"Open_IM/pkg/utils"
"errors"
"fmt"
"strconv"
"time"
)
@ -116,10 +115,10 @@ func GetUsers(showNumber, pageNumber int32) ([]db.User, error) {
return users, err
}
func AddUser(userID string, phoneNumber string, name string, email string, gender int32, faceURL string, birth uint32) error {
_birth, _err := time.ParseInLocation("2006-01-02", strconv.Itoa(int(birth)), time.Local)
if _err != nil {
_birth = time.Now()
func AddUser(userID string, phoneNumber string, name string, email string, gender int32, faceURL string, birth string) error {
_birth, err := utils.TimeStringToTime(birth)
if err != nil {
return err
}
user := db.User{
UserID: userID,

@ -146,14 +146,15 @@ func GroupRequestDBCopyOpenIM(dst *open_im_sdk.GroupRequest, src *db.GroupReques
func UserOpenIMCopyDB(dst *db.User, src *open_im_sdk.UserInfo) {
utils.CopyStructFields(dst, src)
dst.Birth = utils.UnixSecondToTime(int64(src.Birth))
dst.Birth, _ = utils.TimeStringToTime(src.BirthStr)
dst.CreateTime = utils.UnixSecondToTime(int64(src.CreateTime))
}
func UserDBCopyOpenIM(dst *open_im_sdk.UserInfo, src *db.User) {
utils.CopyStructFields(dst, src)
dst.CreateTime = uint32(src.CreateTime.Unix())
dst.Birth = uint32(src.Birth.Unix())
//dst.Birth = uint32(src.Birth.Unix())
dst.BirthStr = utils.TimeToString(src.Birth)
}
func UserDBCopyOpenIMPublicUser(dst *open_im_sdk.PublicUserInfo, src *db.User) {

File diff suppressed because it is too large Load Diff

@ -75,6 +75,7 @@ message UserInfo{
uint32 createTime = 9;
int32 appMangerLevel = 10;
int32 globalRecvMsgOpt = 11;
string birthStr = 12;
}
message FriendInfo{
@ -157,6 +158,7 @@ message OrganizationUser {
string email = 9;
uint32 createTime = 10;
string ex = 11;
string birthStr = 12;
}
message DepartmentMember {

@ -83,3 +83,7 @@ func TimeStringToTime(timeString string) (time.Time, error) {
t, err := time.Parse("2006-01-02", timeString)
return t, err
}
func TimeToString(t time.Time) string {
return t.Format("2006-01-02")
}

Loading…
Cancel
Save