list.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Copyright 2019 githup.com. All rights reserved.
  2. // Use of this source code is governed by githup.com.
  3. package provider
  4. import (
  5. "context"
  6. "github.com/jaryhe/gopkgs/database"
  7. "github.com/jinzhu/gorm"
  8. "smart-government-management/errors"
  9. dbmodel "smart-government-management/model"
  10. pb_v1 "smart-government-management/pb/v1"
  11. "github.com/jaryhe/gopkgs/logger"
  12. "go.uber.org/zap"
  13. )
  14. var layout = "2006-01-02 15:04:05"
  15. func ProviderList(ctx context.Context, req *pb_v1.ProviderListRequest)(reply *pb_v1.ProviderListReply, err error) {
  16. p := &dbmodel.TProvider{}
  17. and := map[string]interface{}{}
  18. or := map[string]interface{}{}
  19. if req.Filter != "" {
  20. or["name like"] = "%"+req.Filter+"%"
  21. or["social_code like"] = "%"+req.Filter+"%"
  22. }
  23. if len(req.FilterStatus) > 0 {
  24. and["status in"] = req.FilterStatus
  25. }
  26. total, err := p.Count(database.DB(), and, or)
  27. if err != nil {
  28. logger.Error("ProviderList",
  29. zap.String("err", err.Error()))
  30. return nil, errors.DataBaseError
  31. }
  32. reply = &pb_v1.ProviderListReply{
  33. Total:total,
  34. Page:req.Page,
  35. PageSize:int32(dbmodel.PageSize),
  36. }
  37. if total == 0 {
  38. return reply, nil
  39. }
  40. list, err := p.List(database.DB(), and, or, req.Page)
  41. if err != nil && err != gorm.ErrRecordNotFound{
  42. logger.Error("ProviderList",
  43. zap.String("err", err.Error()))
  44. return nil, errors.DataBaseError
  45. }
  46. reply.List = make([]*pb_v1.ProviderItem, len(list))
  47. for i, v := range list {
  48. reply.List[i] = &pb_v1.ProviderItem{}
  49. reply.List[i].Id = v.Id
  50. reply.List[i].Name = v.Name
  51. reply.List[i].SocialCode = v.SocialCode
  52. reply.List[i].ApplyTime = v.CreatedAt.Format(layout)
  53. reply.List[i].Status = v.Status
  54. reply.List[i].BusinessContact = v.BusinessContact
  55. reply.List[i].BusinessContactPhone = v.BusinessContactPhone
  56. reply.List[i].Feedback = v.Feedback
  57. reply.List[i].EmergencyContactPhone = v.EmergencyContactPhone
  58. reply.List[i].EmergencyContact = v.EmergencyContact
  59. reply.List[i].IdCert = v.IdCert
  60. reply.List[i].BusinessResponsiblePhone = v.BusinessResponsiblePhone
  61. reply.List[i].BusinessResponsible = v.BusinessResponsible
  62. if v.EnterpriseLocation == 0 {
  63. reply.List[i].EnterpriseLocation = "省内"
  64. } else {
  65. reply.List[i].EnterpriseLocation = "省外"
  66. }
  67. reply.List[i].UserName = v.UserName
  68. reply.List[i].LegalPerson = v.LegalPerson
  69. if v.BusinessLicense != "" {
  70. reply.List[i].BusinessLicense = v.BusinessLicense
  71. } else {
  72. reply.List[i].BusinessLicense = "[]"
  73. }
  74. if v.BusinessResponsibleLetter != "" {
  75. reply.List[i].BusinessResponsibleLetter = v.BusinessResponsibleLetter
  76. } else {
  77. reply.List[i].BusinessResponsibleLetter = "[]"
  78. }
  79. if v.IntegrityManagementLetter != "" {
  80. reply.List[i].IntegrityManagementLetter = v.IntegrityManagementLetter
  81. } else {
  82. reply.List[i].IntegrityManagementLetter = "[]"
  83. }
  84. if v.LegalPersonLetter != "" {
  85. reply.List[i].LegalPersonLetter = v.LegalPersonLetter
  86. } else {
  87. reply.List[i].LegalPersonLetter = "[]"
  88. }
  89. if v.Status == 1 || v.Status == 2 {
  90. reply.List[i].ApproveTime = v.ApproveTime.Format(layout)
  91. }
  92. }
  93. return reply, nil
  94. }