enum_options.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. package backend
  2. import (
  3. "context"
  4. "kpt-pasture/model"
  5. "net/http"
  6. "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. return &pasturePb.ConfigOptionsListResponse{
  11. Code: http.StatusOK,
  12. Message: "ok",
  13. Data: s.BarnTypeEnumList(),
  14. }, nil
  15. }
  16. func (s *StoreEntry) BarnListOptions(ctx context.Context, penType int) (*pasturePb.ConfigOptionsListResponse, error) {
  17. penList := make([]*model.Pen, 0)
  18. pref := s.DB.Table(new(model.Pen).TableName()).
  19. Where("is_delete = ?", pasturePb.IsShow_Ok)
  20. if penType != -1 {
  21. pref.Where("pen_type = ?", penType)
  22. }
  23. if err := pref.Find(&penList).Error; err != nil {
  24. return nil, err
  25. }
  26. return &pasturePb.ConfigOptionsListResponse{
  27. Code: http.StatusOK,
  28. Message: "ok",
  29. Data: model.PenSlice(penList).ToPB2(s.BarnTypeEnumList()),
  30. }, nil
  31. }
  32. func (s *StoreEntry) DiseaseTypeOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  33. diseaseTypeList := make([]*model.ConfigDiseaseType, 0)
  34. pref := s.DB.Table(new(model.ConfigDiseaseType).TableName()).
  35. Where("is_show =? ", pasturePb.IsShow_Ok)
  36. if err := pref.Find(&diseaseTypeList).Error; err != nil {
  37. return nil, xerr.WithStack(err)
  38. }
  39. return &pasturePb.ConfigOptionsListResponse{
  40. Code: http.StatusOK,
  41. Message: "ok",
  42. Data: model.ConfigDiseaseTypeSlice(diseaseTypeList).ToPB2(),
  43. }, nil
  44. }
  45. func (s *StoreEntry) DiseaseOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  46. diseaseList := make([]*model.Disease, 0)
  47. pref := s.DB.Table(new(model.Disease).TableName()).
  48. Where("is_show =? ", pasturePb.IsShow_Ok)
  49. if err := pref.Find(&diseaseList).Error; err != nil {
  50. return nil, xerr.WithStack(err)
  51. }
  52. return &pasturePb.ConfigOptionsListResponse{
  53. Code: http.StatusOK,
  54. Message: "ok",
  55. Data: model.DiseaseSlice(diseaseList).ToPB2(),
  56. }, nil
  57. }
  58. func (s *StoreEntry) BreedStatusOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  59. return &pasturePb.ConfigOptionsListResponse{
  60. Code: http.StatusOK,
  61. Message: "ok",
  62. Data: s.BreedStatusEnumList(),
  63. }, nil
  64. }
  65. func (s *StoreEntry) CowKindOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  66. return &pasturePb.ConfigOptionsListResponse{
  67. Code: http.StatusOK,
  68. Message: "ok",
  69. Data: s.CowKindEnumList(),
  70. }, nil
  71. }
  72. func (s *StoreEntry) CowSourceOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  73. return &pasturePb.ConfigOptionsListResponse{
  74. Code: http.StatusOK,
  75. Message: "ok",
  76. Data: s.CowSourceEnumList(),
  77. }, nil
  78. }
  79. func (s *StoreEntry) CowTypeOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  80. return &pasturePb.ConfigOptionsListResponse{
  81. Code: http.StatusOK,
  82. Message: "ok",
  83. Data: s.CowTypeEnumList(),
  84. }, nil
  85. }
  86. func (s *StoreEntry) CowTransferPenReasonOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  87. return &pasturePb.ConfigOptionsListResponse{
  88. Code: http.StatusOK,
  89. Message: "ok",
  90. Data: s.TransferPenEnumList(),
  91. }, nil
  92. }
  93. func (s *StoreEntry) SystemUserOptions(ctx context.Context, depId int) (*pasturePb.ConfigOptionsListResponse, error) {
  94. systemUserList := make([]*model.SystemUser, 0)
  95. pref := s.DB.Table(new(model.SystemUser).TableName()).
  96. Where("is_delete = ?", pasturePb.IsShow_Ok).
  97. Where("is_show =? ", pasturePb.IsShow_Ok)
  98. if depId != -1 && depId > 0 {
  99. pref = pref.Where("dept_id = ?", depId)
  100. }
  101. if err := pref.Find(&systemUserList).Error; err != nil {
  102. return nil, xerr.WithStack(err)
  103. }
  104. return &pasturePb.ConfigOptionsListResponse{
  105. Code: http.StatusOK,
  106. Message: "ok",
  107. Data: model.SystemUserSlice(systemUserList).ToPB2(),
  108. }, nil
  109. }
  110. func (s *StoreEntry) BullOptions(ctx context.Context) (*pasturePb.BullOptionsListResponse, error) {
  111. return &pasturePb.BullOptionsListResponse{
  112. Code: http.StatusOK,
  113. Message: "ok",
  114. Data: s.BullNumberEnumList(),
  115. }, nil
  116. }
  117. func (s *StoreEntry) SystemBaseConfigOptions(ctx context.Context, optionsName string) (*pasturePb.ConfigOptionsListResponse, error) {
  118. configOptions := make([]*pasturePb.ConfigOptionsList, 0)
  119. switch optionsName {
  120. case "childNumber":
  121. configOptions = s.ChildNumberEnumList()
  122. case "calvingLevel":
  123. configOptions = s.CalvingLevelEnumList()
  124. case "dystociaReason":
  125. configOptions = s.DystociaReasonEnumList()
  126. case "drugCategory":
  127. configOptions = s.DrugCategoryEnumList()
  128. case "drugUsage":
  129. configOptions = s.DrugUsageEnumList()
  130. case "unit":
  131. configOptions = s.UnitEnumList()
  132. case "pregnantCheckResult":
  133. configOptions = s.PregnantCheckResultEnumList()
  134. case "pregnantCheckMethod":
  135. configOptions = s.PregnantCheckMethodEnumList()
  136. case "exposeEstrusType":
  137. configOptions = s.ExposeEstrusTypeEnumList()
  138. case "frozenSemenType":
  139. configOptions = s.FrozenSemenTypeEnumList()
  140. case "week":
  141. configOptions = s.WeekEnumList()
  142. case "month":
  143. configOptions = s.monthEnumList()
  144. case "sameTimeCowType":
  145. configOptions = s.SemeTimeCowTypeEnumList()
  146. case "immunizationCowType":
  147. configOptions = s.ImmunizationCowTypeEnumList()
  148. case "workOrderFrequency":
  149. configOptions = s.WorkOrderFrequencyEnumList()
  150. case "workOrderSubUnit":
  151. configOptions = s.WorkOrderSubUnitEnumList()
  152. case "workOrderPriority":
  153. configOptions = s.WorkOrderPriorityEnumList()
  154. case "workOrderCategory":
  155. configOptions = s.WorkOrderCategoryEnumList()
  156. case "immunizationConditions":
  157. configOptions = s.ImmunizationConditionsEnumList()
  158. }
  159. return &pasturePb.ConfigOptionsListResponse{
  160. Code: http.StatusOK,
  161. Message: "ok",
  162. Data: configOptions,
  163. }, nil
  164. }