enum_options.go 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. userModel, err := s.GetUserModel(ctx)
  19. if err != nil {
  20. return nil, xerr.WithStack(err)
  21. }
  22. penList := make([]*model.Pen, 0)
  23. pref := s.DB.Table(new(model.Pen).TableName()).
  24. Where("pasture_id = ?", userModel.AppPasture.Id).
  25. Where("is_delete = ?", pasturePb.IsShow_Ok)
  26. if penType != -1 {
  27. pref.Where("pen_type = ?", penType)
  28. }
  29. if err = pref.Find(&penList).Error; err != nil {
  30. return nil, err
  31. }
  32. return &pasturePb.ConfigOptionsListResponse{
  33. Code: http.StatusOK,
  34. Msg: "ok",
  35. Data: model.PenSlice(penList).ToPB2(s.BarnTypeEnumList(), isAll),
  36. }, nil
  37. }
  38. func (s *StoreEntry) DiseaseTypeOptions(ctx context.Context, isChildren string) (*pasturePb.ConfigOptionsListResponse, error) {
  39. diseaseTypeList := make([]*model.ConfigDiseaseType, 0)
  40. pref := s.DB.Table(new(model.ConfigDiseaseType).TableName()).
  41. Where("is_show =? ", pasturePb.IsShow_Ok)
  42. if err := pref.Find(&diseaseTypeList).Error; err != nil {
  43. return nil, xerr.WithStack(err)
  44. }
  45. diseaseList := make([]*model.Disease, 0)
  46. if isChildren == model.IsAllYes {
  47. if err := s.DB.Table(new(model.Disease).TableName()).
  48. Where("is_show =? ", pasturePb.IsShow_Ok).Find(&diseaseList).Error; err != nil {
  49. return nil, xerr.WithStack(err)
  50. }
  51. }
  52. return &pasturePb.ConfigOptionsListResponse{
  53. Code: http.StatusOK,
  54. Msg: "ok",
  55. Data: model.ConfigDiseaseTypeSlice(diseaseTypeList).ToPB2(diseaseList),
  56. }, nil
  57. }
  58. func (s *StoreEntry) DiseaseOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  59. userModel, err := s.GetUserModel(ctx)
  60. if err != nil {
  61. return nil, xerr.WithStack(err)
  62. }
  63. diseaseList := make([]*model.Disease, 0)
  64. pref := s.DB.Table(new(model.Disease).TableName()).
  65. Where("is_show =? ", pasturePb.IsShow_Ok).
  66. Where("pasture_id =? ", userModel.AppPasture.Id)
  67. if err = pref.Find(&diseaseList).Error; err != nil {
  68. return nil, xerr.WithStack(err)
  69. }
  70. return &pasturePb.ConfigOptionsListResponse{
  71. Code: http.StatusOK,
  72. Msg: "ok",
  73. Data: model.DiseaseSlice(diseaseList).ToPB2(),
  74. }, nil
  75. }
  76. func (s *StoreEntry) PrescriptionOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  77. userModel, err := s.GetUserModel(ctx)
  78. if err != nil {
  79. return nil, xerr.WithStack(err)
  80. }
  81. prescriptionList := make([]*model.Prescription, 0)
  82. pref := s.DB.Table(new(model.Prescription).TableName()).
  83. Where("pasture_id = ? ", userModel.AppPasture.Id).
  84. Where("is_show = ? ", pasturePb.IsShow_Ok)
  85. if err = pref.Find(&prescriptionList).Error; err != nil {
  86. return nil, xerr.WithStack(err)
  87. }
  88. return &pasturePb.ConfigOptionsListResponse{
  89. Code: http.StatusOK,
  90. Msg: "ok",
  91. Data: model.PrescriptionSlice(prescriptionList).ToPB2(),
  92. }, nil
  93. }
  94. func (s *StoreEntry) BreedStatusOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  95. return &pasturePb.ConfigOptionsListResponse{
  96. Code: http.StatusOK,
  97. Msg: "ok",
  98. Data: s.BreedStatusEnumList(),
  99. }, nil
  100. }
  101. func (s *StoreEntry) CowKindOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  102. return &pasturePb.ConfigOptionsListResponse{
  103. Code: http.StatusOK,
  104. Msg: "ok",
  105. Data: s.CowKindEnumList(),
  106. }, nil
  107. }
  108. func (s *StoreEntry) CowSourceOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  109. return &pasturePb.ConfigOptionsListResponse{
  110. Code: http.StatusOK,
  111. Msg: "ok",
  112. Data: s.CowSourceEnumList(),
  113. }, nil
  114. }
  115. func (s *StoreEntry) CowTypeOptions(ctx context.Context, optionName, isAll string) (*pasturePb.ConfigOptionsListResponse, error) {
  116. return &pasturePb.ConfigOptionsListResponse{
  117. Code: http.StatusOK,
  118. Msg: "ok",
  119. Data: s.CowTypeEnumList(optionName, isAll),
  120. }, nil
  121. }
  122. func (s *StoreEntry) CowTransferPenReasonOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  123. return &pasturePb.ConfigOptionsListResponse{
  124. Code: http.StatusOK,
  125. Msg: "ok",
  126. Data: s.TransferPenEnumList(""),
  127. }, nil
  128. }
  129. // SystemUserOptions 系统用户下拉框 todo 待优化
  130. func (s *StoreEntry) SystemUserOptions(ctx context.Context, depId int) (*pasturePb.ConfigOptionsListResponse, error) {
  131. userModel, err := s.GetUserModel(ctx)
  132. if err != nil {
  133. return nil, xerr.WithStack(err)
  134. }
  135. systemUserList := make([]*model.SystemUser, 0)
  136. pref := s.DB.Table(new(model.SystemUser).TableName()).
  137. Where("pasture_id = ?", userModel.AppPasture.Id).
  138. Where("is_delete = ?", pasturePb.IsShow_Ok).
  139. Where("is_show =? ", pasturePb.IsShow_Ok)
  140. if depId != -1 && depId > 0 {
  141. pref = pref.Where("FIND_IN_SET('?',dept_ids) > ?", depId, 0)
  142. }
  143. if err = pref.Find(&systemUserList).Error; err != nil {
  144. return nil, xerr.WithStack(err)
  145. }
  146. return &pasturePb.ConfigOptionsListResponse{
  147. Code: http.StatusOK,
  148. Msg: "ok",
  149. Data: model.SystemUserSlice(systemUserList).ToPB2(),
  150. }, nil
  151. }
  152. func (s *StoreEntry) BullOptions(ctx context.Context) (*pasturePb.BullOptionsListResponse, error) {
  153. userModel, err := s.GetUserModel(ctx)
  154. if err != nil {
  155. return nil, xerr.WithStack(err)
  156. }
  157. return &pasturePb.BullOptionsListResponse{
  158. Code: http.StatusOK,
  159. Msg: "ok",
  160. Data: s.BullNumberEnumList("", userModel.AppPasture.Id),
  161. }, nil
  162. }
  163. func (s *StoreEntry) SystemBaseConfigOptions(ctx context.Context, optionsName, isAll string) (*pasturePb.ConfigOptionsListResponse, error) {
  164. if optionsName == "" {
  165. return nil, xerr.New("optionsName is empty")
  166. }
  167. getConfigFuncMap := map[string]func(isAll string) []*pasturePb.ConfigOptionsList{
  168. "childNumber": s.ChildNumberEnumList,
  169. "calvingLevel": s.CalvingLevelEnumList,
  170. "dystociaReason": s.DystociaReasonEnumList,
  171. "drugCategory": s.DrugCategoryEnumList,
  172. "drugUsage": s.DrugUsageEnumList,
  173. "unit": s.UnitEnumList,
  174. "pregnantCheckResult": s.PregnantCheckResultEnumList,
  175. "pregnantCheckMethod": s.PregnantCheckMethodEnumList,
  176. "exposeEstrusType": s.ExposeEstrusTypeEnumList,
  177. "frozenSemenType": s.FrozenSemenTypeEnumList,
  178. "week": s.WeekEnumList,
  179. "month": s.MonthEnumList,
  180. "sameTimeCowType": s.SameTimeCowTypeEnumList,
  181. "sameTimeType": s.SameTimeTypeEnumList,
  182. "immunizationCowType": s.ImmunizationCowTypeEnumList,
  183. "workOrderFrequency": s.WorkOrderFrequencyEnumList,
  184. "workOrderSubUnit": s.WorkOrderSubUnitEnumList,
  185. "workOrderPriority": s.WorkOrderPriorityEnumList,
  186. "workOrderCategory": s.WorkOrderCategoryEnumList,
  187. "immunizationConditions": s.ImmunizationConditionsEnumList,
  188. "abortionReasons": s.AbortionReasonsEnumList,
  189. "healthStatus": s.HealthStatusEnumList,
  190. "calendarType": CalendarTypeEnumList,
  191. "calvingAnalysisMethod": s.CalvingAnalysisMethodEnumList,
  192. "lact": s.LactEnumList,
  193. "diseaseAnalysisMethod": s.DiseaseAnalysisMethodEnumList,
  194. "singleFactorAnalysisMethod": s.SingleFactorAnalysisMethodEnumList,
  195. "lactIntervalSymbol": s.LactIntervalSymbolEnumList,
  196. "multiFactorAnalysisMethod": s.MultiFactorAnalysisMethodEnumList,
  197. "saleCowAnalysisMethod": s.SaleCowAnalysisMethodEnumList,
  198. "neckRingIsBind": s.NeckRingIsBindEnumList,
  199. "outType": s.OutTypeEnumList,
  200. "auditStatus": s.AuditStatusEnumList,
  201. "pregnantCheckName": s.PregnantCheckNameEnumList,
  202. "unMatingReasons": s.UnMatingReasonsEnumList,
  203. "evenType": s.EventTypeEnumList,
  204. "outReason": s.OutReasonEnumList,
  205. "deathReason": s.DeathReasonEnumList,
  206. "categoryKind": s.EventCategoryEnumList,
  207. "indicatorsDetails": s.IndicatorsDetailsList,
  208. "purposeKind": s.CowPurposeList,
  209. "forbiddenMatingReasons": s.ForbiddenMatingReasonsEnumList,
  210. "cowOutReason": s.CowOutReasonList,
  211. "deathDestination": s.CowDeathDestinationList,
  212. "warningHealthLevel": s.WarningHealthLevel,
  213. "behavior": s.Behavior,
  214. "matingWindowPeriod": s.MatingWindowPeriodEnumList,
  215. "neckRingError": s.NeckRingErrorEnumList,
  216. }
  217. getConfigFunc, ok := getConfigFuncMap[optionsName]
  218. if !ok {
  219. return nil, fmt.Errorf("invalid optionsName: %s", optionsName)
  220. }
  221. configOptions := getConfigFunc(isAll)
  222. if configOptions == nil {
  223. return nil, fmt.Errorf("failed to retrieve configOptions for %s", optionsName)
  224. }
  225. return &pasturePb.ConfigOptionsListResponse{
  226. Code: http.StatusOK,
  227. Msg: "ok",
  228. Data: configOptions,
  229. }, nil
  230. }