user_info.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package user
  4. import (
  5. "context"
  6. "encoding/json"
  7. "fmt"
  8. "gorm.io/gorm"
  9. "property-household/errors"
  10. dbmodel "property-household/model"
  11. pb_v1 "property-household/pb/v1"
  12. "property-household/utils"
  13. "git.getensh.com/common/gopkgs/database"
  14. "git.getensh.com/common/gopkgs/logger"
  15. "go.uber.org/zap"
  16. "google.golang.org/grpc/status"
  17. )
  18. // 获取用户信息
  19. func UserInfo(ctx context.Context, req *pb_v1.UserInfoRequest) (reply *pb_v1.UserInfoReply, err error) {
  20. reply = &pb_v1.UserInfoReply{}
  21. // 捕获各个task中的异常并返回给调用者
  22. defer func() {
  23. if r := recover(); r != nil {
  24. err = fmt.Errorf("%+v", r)
  25. e := &status.Status{}
  26. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  27. logger.Error("err",
  28. zap.String("system_err", err.Error()),
  29. zap.Stack("stacktrace"))
  30. }
  31. }
  32. }()
  33. if req.Uid < 1{
  34. return nil, errors.ParamsError
  35. }
  36. user := &dbmodel.TUser{}
  37. where := map[string]interface{}{
  38. "id":req.Uid,
  39. }
  40. err = user.Find(database.DB(), where)
  41. if err != nil && err != gorm.ErrRecordNotFound {
  42. return nil, errors.DataBaseError
  43. }
  44. if user.ID == 0 {
  45. return nil, errors.UserNotExist
  46. }
  47. reply.RealName = user.RealName
  48. reply.IdType = user.IdType
  49. reply.IdNumber = user.IdNumber
  50. decrypt := utils.CertDecrypt(user.IdNumber)
  51. if decrypt != "" {
  52. reply.IdNumber = decrypt
  53. }
  54. return reply, nil
  55. }