enum_options.go 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. package backend
  2. import (
  3. "context"
  4. "fmt"
  5. "kpt-pasture/model"
  6. "net/http"
  7. "gitee.com/xuyiping_admin/pkg/xerr"
  8. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  9. )
  10. func (s *StoreEntry) BarnTypeOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  11. return &pasturePb.ConfigOptionsListResponse{
  12. Code: http.StatusOK,
  13. Message: "ok",
  14. Data: s.BarnTypeEnumList(),
  15. }, nil
  16. }
  17. func (s *StoreEntry) BarnListOptions(ctx context.Context, penType int, isAll string) (*pasturePb.ConfigOptionsListResponse, error) {
  18. penList := make([]*model.Pen, 0)
  19. pref := s.DB.Table(new(model.Pen).TableName()).
  20. Where("is_delete = ?", pasturePb.IsShow_Ok)
  21. if penType != -1 {
  22. pref.Where("pen_type = ?", penType)
  23. }
  24. if err := pref.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(s.BarnTypeEnumList(), isAll),
  31. }, nil
  32. }
  33. func (s *StoreEntry) DiseaseTypeOptions(ctx context.Context, isChildren string) (*pasturePb.ConfigOptionsListResponse, error) {
  34. diseaseTypeList := make([]*model.ConfigDiseaseType, 0)
  35. pref := s.DB.Table(new(model.ConfigDiseaseType).TableName()).
  36. Where("is_show =? ", pasturePb.IsShow_Ok)
  37. if err := pref.Find(&diseaseTypeList).Error; err != nil {
  38. return nil, xerr.WithStack(err)
  39. }
  40. diseaseList := make([]*model.Disease, 0)
  41. if isChildren == model.IsAllYes {
  42. if err := s.DB.Table(new(model.Disease).TableName()).
  43. Where("is_show =? ", pasturePb.IsShow_Ok).Find(&diseaseList).Error; err != nil {
  44. return nil, xerr.WithStack(err)
  45. }
  46. }
  47. return &pasturePb.ConfigOptionsListResponse{
  48. Code: http.StatusOK,
  49. Message: "ok",
  50. Data: model.ConfigDiseaseTypeSlice(diseaseTypeList).ToPB2(diseaseList),
  51. }, nil
  52. }
  53. func (s *StoreEntry) DiseaseOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  54. diseaseList := make([]*model.Disease, 0)
  55. pref := s.DB.Table(new(model.Disease).TableName()).
  56. Where("is_show =? ", pasturePb.IsShow_Ok)
  57. if err := pref.Find(&diseaseList).Error; err != nil {
  58. return nil, xerr.WithStack(err)
  59. }
  60. return &pasturePb.ConfigOptionsListResponse{
  61. Code: http.StatusOK,
  62. Message: "ok",
  63. Data: model.DiseaseSlice(diseaseList).ToPB2(),
  64. }, nil
  65. }
  66. func (s *StoreEntry) PrescriptionOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  67. prescriptionList := make([]*model.Prescription, 0)
  68. pref := s.DB.Table(new(model.Prescription).TableName()).
  69. Where("is_show =? ", pasturePb.IsShow_Ok)
  70. if err := pref.Find(&prescriptionList).Error; err != nil {
  71. return nil, xerr.WithStack(err)
  72. }
  73. return &pasturePb.ConfigOptionsListResponse{
  74. Code: http.StatusOK,
  75. Message: "ok",
  76. Data: model.PrescriptionSlice(prescriptionList).ToPB2(),
  77. }, nil
  78. }
  79. func (s *StoreEntry) BreedStatusOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  80. return &pasturePb.ConfigOptionsListResponse{
  81. Code: http.StatusOK,
  82. Message: "ok",
  83. Data: s.BreedStatusEnumList(),
  84. }, nil
  85. }
  86. func (s *StoreEntry) CowKindOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  87. return &pasturePb.ConfigOptionsListResponse{
  88. Code: http.StatusOK,
  89. Message: "ok",
  90. Data: s.CowKindEnumList(),
  91. }, nil
  92. }
  93. func (s *StoreEntry) CowSourceOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  94. return &pasturePb.ConfigOptionsListResponse{
  95. Code: http.StatusOK,
  96. Message: "ok",
  97. Data: s.CowSourceEnumList(),
  98. }, nil
  99. }
  100. func (s *StoreEntry) CowTypeOptions(ctx context.Context, optionName, isAll string) (*pasturePb.ConfigOptionsListResponse, error) {
  101. return &pasturePb.ConfigOptionsListResponse{
  102. Code: http.StatusOK,
  103. Message: "ok",
  104. Data: s.CowTypeEnumList(optionName, isAll),
  105. }, nil
  106. }
  107. func (s *StoreEntry) CowTransferPenReasonOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  108. return &pasturePb.ConfigOptionsListResponse{
  109. Code: http.StatusOK,
  110. Message: "ok",
  111. Data: s.TransferPenEnumList(""),
  112. }, nil
  113. }
  114. func (s *StoreEntry) SystemUserOptions(ctx context.Context, depId int) (*pasturePb.ConfigOptionsListResponse, error) {
  115. systemUserList := make([]*model.SystemUser, 0)
  116. pref := s.DB.Table(new(model.SystemUser).TableName()).
  117. Where("is_delete = ?", pasturePb.IsShow_Ok).
  118. Where("is_show =? ", pasturePb.IsShow_Ok)
  119. if depId != -1 && depId > 0 {
  120. pref = pref.Where("dept_id = ?", depId)
  121. }
  122. if err := pref.Find(&systemUserList).Error; err != nil {
  123. return nil, xerr.WithStack(err)
  124. }
  125. return &pasturePb.ConfigOptionsListResponse{
  126. Code: http.StatusOK,
  127. Message: "ok",
  128. Data: model.SystemUserSlice(systemUserList).ToPB2(),
  129. }, nil
  130. }
  131. func (s *StoreEntry) BullOptions(ctx context.Context) (*pasturePb.BullOptionsListResponse, error) {
  132. return &pasturePb.BullOptionsListResponse{
  133. Code: http.StatusOK,
  134. Message: "ok",
  135. Data: s.BullNumberEnumList(""),
  136. }, nil
  137. }
  138. func (s *StoreEntry) SystemBaseConfigOptions(ctx context.Context, optionsName, isAll string) (*pasturePb.ConfigOptionsListResponse, error) {
  139. if optionsName == "" {
  140. return nil, xerr.New("optionsName is empty")
  141. }
  142. getConfigFuncMap := map[string]func(isAll string) []*pasturePb.ConfigOptionsList{
  143. "childNumber": s.ChildNumberEnumList,
  144. "calvingLevel": s.CalvingLevelEnumList,
  145. "dystociaReason": s.DystociaReasonEnumList,
  146. "drugCategory": s.DrugCategoryEnumList,
  147. "drugUsage": s.DrugUsageEnumList,
  148. "unit": s.UnitEnumList,
  149. "pregnantCheckResult": s.PregnantCheckResultEnumList,
  150. "pregnantCheckMethod": s.PregnantCheckMethodEnumList,
  151. "exposeEstrusType": s.ExposeEstrusTypeEnumList,
  152. "frozenSemenType": s.FrozenSemenTypeEnumList,
  153. "week": s.WeekEnumList,
  154. "month": s.MonthEnumList,
  155. "sameTimeCowType": s.SameTimeCowTypeEnumList,
  156. "sameTimeType": s.SameTimeTypeEnumList,
  157. "immunizationCowType": s.ImmunizationCowTypeEnumList,
  158. "workOrderFrequency": s.WorkOrderFrequencyEnumList,
  159. "workOrderSubUnit": s.WorkOrderSubUnitEnumList,
  160. "workOrderPriority": s.WorkOrderPriorityEnumList,
  161. "workOrderCategory": s.WorkOrderCategoryEnumList,
  162. "immunizationConditions": s.ImmunizationConditionsEnumList,
  163. "abortionReasons": s.AbortionReasonsEnumList,
  164. "healthStatus": s.HealthStatusEnumList,
  165. "calendarType": CalendarTypeEnumList,
  166. "calvingAnalysisMethod": s.CalvingAnalysisMethodEnumList,
  167. "lact": s.LactEnumList,
  168. "diseaseAnalysisMethod": s.DiseaseAnalysisMethodEnumList,
  169. "singleFactorAnalysisMethod": s.SingleFactorAnalysisMethodEnumList,
  170. "lactIntervalSymbol": s.LactIntervalSymbolEnumList,
  171. "multiFactorAnalysisMethod": s.MultiFactorAnalysisMethodEnumList,
  172. "saleCowAnalysisMethod": s.SaleCowAnalysisMethodEnumList,
  173. "neckRingStatus": s.NeckRingStatusEnumList,
  174. "outType": s.OutTypeEnumList,
  175. "auditStatus": s.AuditStatusEnumList,
  176. "pregnantCheckName": s.PregnantCheckNameEnumList,
  177. "unMatingReasons": s.UnMatingReasonsEnumList,
  178. }
  179. getConfigFunc, ok := getConfigFuncMap[optionsName]
  180. if !ok {
  181. return nil, fmt.Errorf("invalid optionsName: %s", optionsName)
  182. }
  183. configOptions := getConfigFunc(isAll)
  184. if configOptions == nil {
  185. return nil, fmt.Errorf("failed to retrieve configOptions for %s", optionsName)
  186. }
  187. return &pasturePb.ConfigOptionsListResponse{
  188. Code: http.StatusOK,
  189. Message: "ok",
  190. Data: configOptions,
  191. }, nil
  192. }