enum_options.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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) CowStatusOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  80. return &pasturePb.ConfigOptionsListResponse{
  81. Code: http.StatusOK,
  82. Message: "ok",
  83. Data: s.CowStatusEnumList(),
  84. }, nil
  85. }
  86. func (s *StoreEntry) CowTypeOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  87. return &pasturePb.ConfigOptionsListResponse{
  88. Code: http.StatusOK,
  89. Message: "ok",
  90. Data: s.CowTypeEnumList(),
  91. }, nil
  92. }
  93. func (s *StoreEntry) CowTransferPenReasonOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  94. return &pasturePb.ConfigOptionsListResponse{
  95. Code: http.StatusOK,
  96. Message: "ok",
  97. Data: s.TransferPenEnumList(),
  98. }, nil
  99. }
  100. func (s *StoreEntry) SystemUserOptions(ctx context.Context, depId int) (*pasturePb.ConfigOptionsListResponse, error) {
  101. systemUserList := make([]*model.SystemUser, 0)
  102. pref := s.DB.Table(new(model.SystemUser).TableName()).
  103. Where("is_delete = ?", pasturePb.IsShow_Ok).
  104. Where("is_show =? ", pasturePb.IsShow_Ok)
  105. if depId != -1 && depId > 0 {
  106. pref = pref.Where("dept_id = ?", depId)
  107. }
  108. if err := pref.Find(&systemUserList).Error; err != nil {
  109. return nil, xerr.WithStack(err)
  110. }
  111. return &pasturePb.ConfigOptionsListResponse{
  112. Code: http.StatusOK,
  113. Message: "ok",
  114. Data: model.SystemUserSlice(systemUserList).ToPB2(),
  115. }, nil
  116. }
  117. func (s *StoreEntry) BullOptions(ctx context.Context) (*pasturePb.BullOptionsListResponse, error) {
  118. return &pasturePb.BullOptionsListResponse{
  119. Code: http.StatusOK,
  120. Message: "ok",
  121. Data: s.BullNumberEnumList(),
  122. }, nil
  123. }
  124. func (s *StoreEntry) SystemBaseConfigOptions(ctx context.Context, optionsName string) (*pasturePb.ConfigOptionsListResponse, error) {
  125. configOptions := make([]*pasturePb.ConfigOptionsList, 0)
  126. switch optionsName {
  127. case "childNumber":
  128. configOptions = s.ChildNumberEnumList()
  129. case "calvingLevel":
  130. configOptions = s.CalvingLevelEnumList()
  131. case "dystociaReason":
  132. configOptions = s.DystociaReasonEnumList()
  133. case "drugCategory":
  134. configOptions = s.DrugCategoryEnumList()
  135. case "drugUsage":
  136. configOptions = s.DrugUsageEnumList()
  137. case "unit":
  138. configOptions = s.UnitEnumList()
  139. case "pregnantCheckResult":
  140. configOptions = s.PregnantCheckResultEnumList()
  141. case "pregnantCheckMethod":
  142. configOptions = s.PregnantCheckMethodEnumList()
  143. case "exposeEstrusType":
  144. configOptions = s.ExposeEstrusTypeEnumList()
  145. case "frozenSemenType":
  146. configOptions = s.FrozenSemenTypeEnumList()
  147. case "week":
  148. configOptions = s.WeekEnumList()
  149. case "month":
  150. configOptions = s.monthEnumList()
  151. case "sameTimeCowType":
  152. configOptions = s.SemeTimeCowTypeEnumList()
  153. case "immunizationCowType":
  154. configOptions = s.ImmunizationCowTypeEnumList()
  155. case "workOrderFrequency":
  156. configOptions = s.WorkOrderFrequencyEnumList()
  157. case "workOrderSubUnit":
  158. configOptions = s.WorkOrderSubUnitEnumList()
  159. case "workOrderPriority":
  160. configOptions = s.WorkOrderPriorityEnumList()
  161. case "workOrderCategory":
  162. configOptions = s.WorkOrderCategoryEnumList()
  163. case "immunizationConditions":
  164. configOptions = s.ImmunizationConditionsEnumList()
  165. }
  166. return &pasturePb.ConfigOptionsListResponse{
  167. Code: http.StatusOK,
  168. Message: "ok",
  169. Data: configOptions,
  170. }, nil
  171. }