info.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package contact
  4. import (
  5. "context"
  6. "encoding/json"
  7. "fmt"
  8. "git.getensh.com/common/gopkgs/database"
  9. "git.getensh.com/common/gopkgs/logger"
  10. "go.uber.org/zap"
  11. "google.golang.org/grpc/status"
  12. "gorm.io/gorm"
  13. "xingjia-management-gateway/apis"
  14. "xingjia-management-gateway/errors"
  15. dbmodel "xingjia-management-gateway/model"
  16. )
  17. //
  18. func ContactInfo(ctx context.Context, req *apis.ContactInfoRequest) (reply *apis.ContactInfoReply, err error) {
  19. reply = &apis.ContactInfoReply{}
  20. // 捕获各个task中的异常并返回给调用者
  21. defer func() {
  22. if r := recover(); r != nil {
  23. err = fmt.Errorf("%+v", r)
  24. e := &status.Status{}
  25. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  26. logger.Error("err",
  27. zap.String("system_err", err.Error()),
  28. zap.Stack("stacktrace"))
  29. }
  30. }
  31. }()
  32. p := dbmodel.TContact{}
  33. where := map[string]interface{}{
  34. "id": 1,
  35. }
  36. err = p.Find(database.DB(), where)
  37. if err != nil && err != gorm.ErrRecordNotFound {
  38. return nil, errors.DataBaseError
  39. }
  40. reply.Addr = p.Addr
  41. reply.Phone = p.Phone
  42. reply.Email = p.Email
  43. reply.Id = p.ID
  44. return reply, nil
  45. }