config_data_base.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. package backend
  2. import (
  3. "kpt-pasture/model"
  4. "gitee.com/xuyiping_admin/pkg/logger/zaplog"
  5. "go.uber.org/zap"
  6. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  7. )
  8. func (s *StoreEntry) DeathReasonEnumList(userModel *model.UserModel, isAll string) []*pasturePb.ConfigOptionsList {
  9. dataList := make([]*model.ConfigDeathReason, 0)
  10. pref := s.DB.Model(new(model.ConfigDeathReason)).
  11. Where("is_show =? ", pasturePb.IsShow_Ok).
  12. Where("pasture_id =? ", userModel.AppPasture.Id)
  13. if isAll == model.IsAllYes {
  14. pref = pref.Where("kind >= ?", pasturePb.DeathReason_Invalid)
  15. } else {
  16. pref = pref.Where("kind > ?", pasturePb.DeathReason_Invalid)
  17. }
  18. if err := pref.Order("kind ASC").
  19. Find(&dataList).Error; err != nil {
  20. zaplog.Error("DeathReasonEnumList", zap.Any("err", err))
  21. return make([]*pasturePb.ConfigOptionsList, 0)
  22. }
  23. return model.ConfigDeathReasonSlice(dataList).ToPB(userModel)
  24. }
  25. func (s *StoreEntry) MatingResultEnumList(userModel *model.UserModel, isAll string) []*pasturePb.ConfigOptionsList {
  26. dataList := make([]*model.ConfigMatingResult, 0)
  27. pref := s.DB.Model(new(model.ConfigMatingResult)).
  28. Where("is_show =? ", pasturePb.IsShow_Ok).
  29. Where("pasture_id =? ", userModel.AppPasture.Id)
  30. if isAll == model.IsAllYes {
  31. pref = pref.Where("kind >= ?", pasturePb.MatingResult_Invalid)
  32. } else {
  33. pref = pref.Where("kind > ?", pasturePb.MatingResult_Invalid)
  34. }
  35. if err := pref.Order("kind ASC").
  36. Find(&dataList).Error; err != nil {
  37. zaplog.Error("MatingResultEnumList", zap.Any("err", err))
  38. return make([]*pasturePb.ConfigOptionsList, 0)
  39. }
  40. return model.ConfigMatingResultSlice(dataList).ToPB(userModel)
  41. }
  42. func (s *StoreEntry) EventCategoryEnumList(userModel *model.UserModel, isAll string) []*pasturePb.ConfigOptionsList {
  43. dataList := make([]*model.ConfigEventCategory, 0)
  44. pref := s.DB.Model(new(model.ConfigEventCategory)).
  45. Where("is_show =? ", pasturePb.IsShow_Ok).
  46. Where("pasture_id =? ", userModel.AppPasture.Id)
  47. if isAll == model.IsAllYes {
  48. pref = pref.Where("kind >= ?", pasturePb.EventCategory_Invalid)
  49. } else {
  50. pref = pref.Where("kind > ?", pasturePb.EventCategory_Invalid)
  51. }
  52. if err := pref.Order("kind ASC").
  53. Find(&dataList).Error; err != nil {
  54. zaplog.Error("EventCategoryEnumList", zap.Any("err", err))
  55. return make([]*pasturePb.ConfigOptionsList, 0)
  56. }
  57. return model.ConfigEventCategorySlice(dataList).ToPB(userModel)
  58. }
  59. func (s *StoreEntry) IndicatorsCategoryEnumList(userModel *model.UserModel, isAll string) []*pasturePb.ConfigOptionsList {
  60. dataList := make([]*model.ConfigIndicatorsCategory, 0)
  61. pref := s.DB.Model(new(model.ConfigIndicatorsCategory)).
  62. Where("is_show =? ", pasturePb.IsShow_Ok).
  63. Where("pasture_id =? ", userModel.AppPasture.Id)
  64. if isAll == model.IsAllYes {
  65. pref = pref.Where("kind >= ?", pasturePb.IndicatorType_Invalid)
  66. } else {
  67. pref = pref.Where("kind > ?", pasturePb.IndicatorType_Invalid)
  68. }
  69. if err := pref.Order("kind ASC").
  70. Find(&dataList).Error; err != nil {
  71. zaplog.Error("IndicatorsCategoryEnumList", zap.Any("err", err))
  72. return make([]*pasturePb.ConfigOptionsList, 0)
  73. }
  74. return model.ConfigIndicatorsCategorySlice(dataList).ToPB(userModel)
  75. }
  76. func (s *StoreEntry) IndicatorsDetailsList(userModel *model.UserModel, isAll string) []*pasturePb.ConfigOptionsList {
  77. configOptions := make([]*pasturePb.ConfigOptionsList, 0)
  78. if isAll == model.IsAllYes {
  79. configOptions = append(configOptions,
  80. &pasturePb.ConfigOptionsList{
  81. Value: int32(0),
  82. Label: "全部",
  83. Disabled: true,
  84. })
  85. }
  86. indicatorsDetailsList, _ := s.FindIndicatorsDetailsList()
  87. if len(indicatorsDetailsList) <= 0 {
  88. return configOptions
  89. }
  90. for _, v := range indicatorsDetailsList {
  91. configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
  92. Label: v.Name,
  93. Disabled: true,
  94. Props: v.Kind,
  95. })
  96. }
  97. return configOptions
  98. }
  99. func (s *StoreEntry) CowPurposeList(userModel *model.UserModel, isAll string) []*pasturePb.ConfigOptionsList {
  100. dataList := make([]*model.ConfigCowPurpose, 0)
  101. pref := s.DB.Model(new(model.ConfigCowPurpose)).
  102. Where("is_show =? ", pasturePb.IsShow_Ok).
  103. Where("pasture_id =? ", userModel.AppPasture.Id)
  104. if isAll == model.IsAllYes {
  105. pref = pref.Where("kind >= ?", pasturePb.Purpose_Invalid)
  106. } else {
  107. pref = pref.Where("kind > ?", pasturePb.Purpose_Invalid)
  108. }
  109. if err := pref.Order("kind ASC").
  110. Find(&dataList).Error; err != nil {
  111. zaplog.Error("CowPurposeList", zap.Any("err", err))
  112. return make([]*pasturePb.ConfigOptionsList, 0)
  113. }
  114. return model.ConfigCowPurposeSlice(dataList).ToPB(userModel)
  115. }
  116. func (s *StoreEntry) CowOutReasonEnumList(userModel *model.UserModel, isAll string) []*pasturePb.ConfigOptionsList {
  117. dataList := make([]*model.ConfigCowOutReason, 0)
  118. pref := s.DB.Model(new(model.ConfigCowOutReason)).
  119. Where("is_show =? ", pasturePb.IsShow_Ok).
  120. Where("pasture_id =? ", userModel.AppPasture.Id)
  121. if isAll == model.IsAllYes {
  122. pref = pref.Where("kind >= ?", pasturePb.OutReasons_Invalid)
  123. } else {
  124. pref = pref.Where("kind > ?", pasturePb.OutReasons_Invalid)
  125. }
  126. if err := pref.Order("kind ASC").
  127. Find(&dataList).Error; err != nil {
  128. zaplog.Error("CowOutReasonList", zap.Any("err", err))
  129. return make([]*pasturePb.ConfigOptionsList, 0)
  130. }
  131. return model.ConfigCowOutReasonSlice(dataList).ToPB(userModel)
  132. }
  133. func (s *StoreEntry) CowDeathDestinationList(userModel *model.UserModel, isAll string) []*pasturePb.ConfigOptionsList {
  134. dataList := make([]*model.ConfigCowDeathDestination, 0)
  135. pref := s.DB.Model(new(model.ConfigCowDeathDestination)).
  136. Where("is_show =? ", pasturePb.IsShow_Ok).
  137. Where("pasture_id =? ", userModel.AppPasture.Id)
  138. if isAll == model.IsAllYes {
  139. pref = pref.Where("kind >= ?", pasturePb.DeathDestination_Invalid)
  140. } else {
  141. pref = pref.Where("kind > ?", pasturePb.DeathDestination_Invalid)
  142. }
  143. if err := pref.Order("kind ASC").
  144. Find(&dataList).Error; err != nil {
  145. zaplog.Error("CowDeathDestinationList", zap.Any("err", err))
  146. return make([]*pasturePb.ConfigOptionsList, 0)
  147. }
  148. return model.ConfigCowDeathDestinationSlice(dataList).ToPB(userModel)
  149. }