config_data.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. package backend
  2. import (
  3. "context"
  4. "kpt-pasture/model"
  5. "net/http"
  6. xxerr "gitee.com/xuyiping_admin/pkg/xerr"
  7. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  8. )
  9. func (s *StoreEntry) BarnTypeOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  10. configBarnTypeList := make([]*model.ConfigPenType, 0)
  11. if err := s.DB.Table(new(model.ConfigPenType).TableName()).Find(&configBarnTypeList).Error; err != nil {
  12. return nil, err
  13. }
  14. return &pasturePb.ConfigOptionsListResponse{
  15. Code: http.StatusOK,
  16. Message: "ok",
  17. Data: model.ConfigBarnTypeSlice(configBarnTypeList).ToPB2(),
  18. }, nil
  19. }
  20. func (s *StoreEntry) BarnListOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  21. penList := make([]*model.Pen, 0)
  22. if err := s.DB.Table(new(model.Pen).TableName()).
  23. Where("is_delete = ?", pasturePb.IsShow_Ok).
  24. Find(&penList).Error; err != nil {
  25. return nil, err
  26. }
  27. return &pasturePb.ConfigOptionsListResponse{
  28. Code: http.StatusOK,
  29. Message: "ok",
  30. Data: model.PenSlice(penList).ToPB2(),
  31. }, nil
  32. }
  33. func (s *StoreEntry) BreedStatusOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  34. configBreedStatusList := make([]*model.ConfigBreedStatus, 0)
  35. if err := s.DB.Table(new(model.ConfigBreedStatus).TableName()).Find(&configBreedStatusList).Error; err != nil {
  36. return nil, xxerr.WithStack(err)
  37. }
  38. return &pasturePb.ConfigOptionsListResponse{
  39. Code: http.StatusOK,
  40. Message: "ok",
  41. Data: model.ConfigBreedStatusSlice(configBreedStatusList).ToPB2(),
  42. }, nil
  43. }
  44. func (s *StoreEntry) CowKindOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  45. configCowKindList := make([]*model.ConfigCowKind, 0)
  46. if err := s.DB.Table(new(model.ConfigCowKind).TableName()).Find(&configCowKindList).Error; err != nil {
  47. return nil, xxerr.WithStack(err)
  48. }
  49. return &pasturePb.ConfigOptionsListResponse{
  50. Code: http.StatusOK,
  51. Message: "ok",
  52. Data: model.ConfigCowKindSlice(configCowKindList).ToPB2(),
  53. }, nil
  54. }
  55. func (s *StoreEntry) CowSourceOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  56. configCowSourceList := make([]*model.ConfigCowSource, 0)
  57. if err := s.DB.Table(new(model.ConfigCowSource).TableName()).Find(&configCowSourceList).Error; err != nil {
  58. return nil, xxerr.WithStack(err)
  59. }
  60. return &pasturePb.ConfigOptionsListResponse{
  61. Code: http.StatusOK,
  62. Message: "ok",
  63. Data: model.ConfigCowSourceSlice(configCowSourceList).ToPB2(),
  64. }, nil
  65. }
  66. func (s *StoreEntry) CowStatusOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  67. configCowStatusList := make([]*model.ConfigCowStatus, 0)
  68. if err := s.DB.Table(new(model.ConfigCowStatus).TableName()).Find(&configCowStatusList).Error; err != nil {
  69. return nil, xxerr.WithStack(err)
  70. }
  71. return &pasturePb.ConfigOptionsListResponse{
  72. Code: http.StatusOK,
  73. Message: "ok",
  74. Data: model.ConfigCowStatusSlice(configCowStatusList).ToPB2(),
  75. }, nil
  76. }
  77. func (s *StoreEntry) CowTypeOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  78. configCowTypeList := make([]*model.ConfigCowType, 0)
  79. if err := s.DB.Table(new(model.ConfigCowType).TableName()).Find(&configCowTypeList).Error; err != nil {
  80. return nil, xxerr.WithStack(err)
  81. }
  82. return &pasturePb.ConfigOptionsListResponse{
  83. Code: http.StatusOK,
  84. Message: "ok",
  85. Data: model.ConfigCowTypeSlice(configCowTypeList).ToPB2(),
  86. }, nil
  87. }
  88. func (s *StoreEntry) CowTransferPenReasonOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  89. configTransferPenReasonList := make([]*model.ConfigTransferPenReason, 0)
  90. if err := s.DB.Table(new(model.ConfigTransferPenReason).TableName()).Find(&configTransferPenReasonList).Error; err != nil {
  91. return nil, xxerr.WithStack(err)
  92. }
  93. return &pasturePb.ConfigOptionsListResponse{
  94. Code: http.StatusOK,
  95. Message: "ok",
  96. Data: model.ConfigTransferPenReasonSlice(configTransferPenReasonList).ToPB2(),
  97. }, nil
  98. }
  99. func (s *StoreEntry) SystemUserOptions(ctx context.Context, depId int) (*pasturePb.ConfigOptionsListResponse, error) {
  100. systemUserList := make([]*model.SystemUser, 0)
  101. pref := s.DB.Table(new(model.SystemUser).TableName())
  102. if depId != -1 && depId > 0 {
  103. pref = pref.Where("dep_id = ?", depId)
  104. }
  105. if err := pref.Find(&systemUserList).Error; err != nil {
  106. return nil, xxerr.WithStack(err)
  107. }
  108. return &pasturePb.ConfigOptionsListResponse{
  109. Code: http.StatusOK,
  110. Message: "ok",
  111. Data: model.SystemUserSlice(systemUserList).ToPB2(),
  112. }, nil
  113. }