enum_options.go 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. Msg: "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. Msg: "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. Msg: "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. Msg: "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. Msg: "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. Msg: "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. Msg: "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. Msg: "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. Msg: "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. Msg: "ok",
  111. Data: s.TransferPenEnumList(""),
  112. }, nil
  113. }
  114. func (s *StoreEntry) SystemUserOptions(ctx context.Context, depId int) (*pasturePb.ConfigOptionsListResponse, error) {
  115. _, err := s.GetUserModel(ctx)
  116. if err != nil {
  117. return nil, xerr.WithStack(err)
  118. }
  119. systemUserList := make([]*model.SystemUser, 0)
  120. pref := s.DB.Table(new(model.SystemUser).TableName()).
  121. Where("is_delete = ?", pasturePb.IsShow_Ok).
  122. Where("is_show =? ", pasturePb.IsShow_Ok)
  123. if depId != -1 && depId > 0 {
  124. pref = pref.Where("dept_id = ?", depId)
  125. }
  126. if err = pref.Find(&systemUserList).Error; err != nil {
  127. return nil, xerr.WithStack(err)
  128. }
  129. return &pasturePb.ConfigOptionsListResponse{
  130. Code: http.StatusOK,
  131. Msg: "ok",
  132. Data: model.SystemUserSlice(systemUserList).ToPB2(),
  133. }, nil
  134. }
  135. func (s *StoreEntry) BullOptions(ctx context.Context) (*pasturePb.BullOptionsListResponse, error) {
  136. userModel, err := s.GetUserModel(ctx)
  137. if err != nil {
  138. return nil, xerr.WithStack(err)
  139. }
  140. return &pasturePb.BullOptionsListResponse{
  141. Code: http.StatusOK,
  142. Msg: "ok",
  143. Data: s.BullNumberEnumList("", userModel.AppPasture.Id),
  144. }, nil
  145. }
  146. func (s *StoreEntry) SystemBaseConfigOptions(ctx context.Context, optionsName, isAll string) (*pasturePb.ConfigOptionsListResponse, error) {
  147. if optionsName == "" {
  148. return nil, xerr.New("optionsName is empty")
  149. }
  150. getConfigFuncMap := map[string]func(isAll string) []*pasturePb.ConfigOptionsList{
  151. "childNumber": s.ChildNumberEnumList,
  152. "calvingLevel": s.CalvingLevelEnumList,
  153. "dystociaReason": s.DystociaReasonEnumList,
  154. "drugCategory": s.DrugCategoryEnumList,
  155. "drugUsage": s.DrugUsageEnumList,
  156. "unit": s.UnitEnumList,
  157. "pregnantCheckResult": s.PregnantCheckResultEnumList,
  158. "pregnantCheckMethod": s.PregnantCheckMethodEnumList,
  159. "exposeEstrusType": s.ExposeEstrusTypeEnumList,
  160. "frozenSemenType": s.FrozenSemenTypeEnumList,
  161. "week": s.WeekEnumList,
  162. "month": s.MonthEnumList,
  163. "sameTimeCowType": s.SameTimeCowTypeEnumList,
  164. "sameTimeType": s.SameTimeTypeEnumList,
  165. "immunizationCowType": s.ImmunizationCowTypeEnumList,
  166. "workOrderFrequency": s.WorkOrderFrequencyEnumList,
  167. "workOrderSubUnit": s.WorkOrderSubUnitEnumList,
  168. "workOrderPriority": s.WorkOrderPriorityEnumList,
  169. "workOrderCategory": s.WorkOrderCategoryEnumList,
  170. "immunizationConditions": s.ImmunizationConditionsEnumList,
  171. "abortionReasons": s.AbortionReasonsEnumList,
  172. "healthStatus": s.HealthStatusEnumList,
  173. "calendarType": CalendarTypeEnumList,
  174. "calvingAnalysisMethod": s.CalvingAnalysisMethodEnumList,
  175. "lact": s.LactEnumList,
  176. "diseaseAnalysisMethod": s.DiseaseAnalysisMethodEnumList,
  177. "singleFactorAnalysisMethod": s.SingleFactorAnalysisMethodEnumList,
  178. "lactIntervalSymbol": s.LactIntervalSymbolEnumList,
  179. "multiFactorAnalysisMethod": s.MultiFactorAnalysisMethodEnumList,
  180. "saleCowAnalysisMethod": s.SaleCowAnalysisMethodEnumList,
  181. "neckRingStatus": s.NeckRingStatusEnumList,
  182. "outType": s.OutTypeEnumList,
  183. "auditStatus": s.AuditStatusEnumList,
  184. "pregnantCheckName": s.PregnantCheckNameEnumList,
  185. "unMatingReasons": s.UnMatingReasonsEnumList,
  186. "evenType": s.EventTypeEnumList,
  187. "departureType": s.DepartureTypeEnumList,
  188. "outReason": s.OutReasonEnumList,
  189. "deadReason": s.DeadReasonEnumList,
  190. "categoryKind": s.EventCategoryEnumList,
  191. "indicatorsDetails": s.IndicatorsDetailsList,
  192. }
  193. getConfigFunc, ok := getConfigFuncMap[optionsName]
  194. if !ok {
  195. return nil, fmt.Errorf("invalid optionsName: %s", optionsName)
  196. }
  197. configOptions := getConfigFunc(isAll)
  198. if configOptions == nil {
  199. return nil, fmt.Errorf("failed to retrieve configOptions for %s", optionsName)
  200. }
  201. return &pasturePb.ConfigOptionsListResponse{
  202. Code: http.StatusOK,
  203. Msg: "ok",
  204. Data: configOptions,
  205. }, nil
  206. }