info.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package company
  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. "property-company/consts"
  14. "property-company/errors"
  15. dbmodel "property-company/model"
  16. pb_v1 "property-company/pb/v1"
  17. )
  18. //
  19. func CompanyInfo(ctx context.Context, req *pb_v1.CompanyInfoRequest) (reply *pb_v1.CompanyInfoReply, err error) {
  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. if req.Id < 1 {
  33. return nil, errors.DataBaseError
  34. }
  35. p := dbmodel.TCompany{}
  36. where := map[string]interface{}{
  37. "id":req.Id,
  38. }
  39. err = p.Find(database.DB(), where)
  40. if err != nil && err != gorm.ErrRecordNotFound {
  41. return nil, errors.DataBaseError
  42. }
  43. if p.ID == 0 {
  44. return nil, errors.ErrRecordNotFound
  45. }
  46. reply = &pb_v1.CompanyInfoReply{
  47. Applicant:p.Applicant,
  48. ApplicantPhone:p.ApplicantPhone,
  49. CompanyName:p.CompanyName,
  50. CompanyPhone:p.CompanyPhone,
  51. ApplicantDuty:p.ApplicantDuty,
  52. LegalPerson:p.LegalPerson,
  53. CompanyAddr:p.CompanyAddr,
  54. SocialCode:p.SocialCode,
  55. BusinessLicense:p.BusinessLicense,
  56. ApplicantIdentification:p.ApplicantIdentification,
  57. CreatedAt:p.CreatedAt.Format(consts.DateTimeLayout),
  58. ApproveStatus:int32(p.ApproveStatus),
  59. LicenseType:int32(p.LicenseType),
  60. FreeGardenCount:int32(p.FreeGardenCount),
  61. GardenCount:int32(p.GardenCount),
  62. Username:p.User,
  63. Password:"******",
  64. Expire:int32(p.Expire),
  65. ApprovedAt:"",
  66. Site:p.Site,
  67. Logo:p.Logo,
  68. Desc:p.Desc,
  69. }
  70. if p.ApproveStatus > consts.ApproveStatusWait {
  71. reply.ApprovedAt = p.ApprovedAt.Format(consts.DateTimeLayout)
  72. }
  73. return reply, nil
  74. }