enum_options.go 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. _, 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("FIND_IN_SET('?',pasture_ids) > 0", userModel.AppPasture.Id).
  138. Where("is_delete = ?", pasturePb.IsShow_Ok).
  139. Where("is_show = ? ", pasturePb.IsShow_Ok).
  140. Where("dept_ids = ? ", depId)
  141. /*if depId != -1 && depId > 0 {
  142. pref = pref.Where("FIND_IN_SET('?',dept_ids) > 0", depId)
  143. }*/
  144. if err = pref.Find(&systemUserList).Error; err != nil {
  145. return nil, xerr.WithStack(err)
  146. }
  147. return &pasturePb.ConfigOptionsListResponse{
  148. Code: http.StatusOK,
  149. Msg: "ok",
  150. Data: model.SystemUserSlice(systemUserList).ToPB2(),
  151. }, nil
  152. }
  153. func (s *StoreEntry) BullOptions(ctx context.Context) (*pasturePb.BullOptionsListResponse, error) {
  154. userModel, err := s.GetUserModel(ctx)
  155. if err != nil {
  156. return nil, xerr.WithStack(err)
  157. }
  158. return &pasturePb.BullOptionsListResponse{
  159. Code: http.StatusOK,
  160. Msg: "ok",
  161. Data: s.BullNumberEnumList("", userModel.AppPasture.Id),
  162. }, nil
  163. }
  164. func (s *StoreEntry) SystemBaseConfigOptions(ctx context.Context, optionsName, isAll string) (*pasturePb.ConfigOptionsListResponse, error) {
  165. if optionsName == "" {
  166. return nil, xerr.New("optionsName is empty")
  167. }
  168. getConfigFuncMap := map[string]func(isAll string) []*pasturePb.ConfigOptionsList{
  169. "childNumber": s.ChildNumberEnumList,
  170. "calvingLevel": s.CalvingLevelEnumList,
  171. "dystociaReason": s.DystociaReasonEnumList,
  172. "drugCategory": s.DrugCategoryEnumList,
  173. "drugUsage": s.DrugUsageEnumList,
  174. "unit": s.UnitEnumList,
  175. "pregnantCheckResult": s.PregnantCheckResultEnumList,
  176. "pregnantCheckMethod": s.PregnantCheckMethodEnumList,
  177. "exposeEstrusType": s.ExposeEstrusTypeEnumList,
  178. "frozenSemenType": s.FrozenSemenTypeEnumList,
  179. "week": s.WeekEnumList,
  180. "month": s.MonthEnumList,
  181. "sameTimeCowType": s.SameTimeCowTypeEnumList,
  182. "sameTimeType": s.SameTimeTypeEnumList,
  183. "immunizationCowType": s.ImmunizationCowTypeEnumList,
  184. "workOrderFrequency": s.WorkOrderFrequencyEnumList,
  185. "workOrderSubUnit": s.WorkOrderSubUnitEnumList,
  186. "workOrderPriority": s.WorkOrderPriorityEnumList,
  187. "workOrderCategory": s.WorkOrderCategoryEnumList,
  188. "immunizationConditions": s.ImmunizationConditionsEnumList,
  189. "abortionReasons": s.AbortionReasonsEnumList,
  190. "healthStatus": s.HealthStatusEnumList,
  191. "calendarType": CalendarTypeEnumList,
  192. "calvingAnalysisMethod": s.CalvingAnalysisMethodEnumList,
  193. "lact": s.LactEnumList,
  194. "diseaseAnalysisMethod": s.DiseaseAnalysisMethodEnumList,
  195. "singleFactorAnalysisMethod": s.SingleFactorAnalysisMethodEnumList,
  196. "lactIntervalSymbol": s.LactIntervalSymbolEnumList,
  197. "multiFactorAnalysisMethod": s.MultiFactorAnalysisMethodEnumList,
  198. "saleCowAnalysisMethod": s.SaleCowAnalysisMethodEnumList,
  199. "neckRingIsBind": s.NeckRingIsBindEnumList,
  200. "outType": s.OutTypeEnumList,
  201. "auditStatus": s.AuditStatusEnumList,
  202. "pregnantCheckName": s.PregnantCheckNameEnumList,
  203. "unMatingReasons": s.UnMatingReasonsEnumList,
  204. "evenType": s.EventTypeEnumList,
  205. "outReason": s.OutReasonEnumList,
  206. "deathReason": s.DeathReasonEnumList,
  207. "categoryKind": s.EventCategoryEnumList,
  208. "indicatorsDetails": s.IndicatorsDetailsList,
  209. "purposeKind": s.CowPurposeList,
  210. "forbiddenMatingReasons": s.ForbiddenMatingReasonsEnumList,
  211. "cowOutReason": s.CowOutReasonList,
  212. "deathDestination": s.CowDeathDestinationList,
  213. "warningHealthLevel": s.WarningHealthLevel,
  214. "behavior": s.Behavior,
  215. "matingWindowPeriod": s.MatingWindowPeriodEnumList,
  216. "neckRingError": s.NeckRingErrorEnumList,
  217. }
  218. getConfigFunc, ok := getConfigFuncMap[optionsName]
  219. if !ok {
  220. return nil, fmt.Errorf("invalid optionsName: %s", optionsName)
  221. }
  222. configOptions := getConfigFunc(isAll)
  223. if configOptions == nil {
  224. return nil, fmt.Errorf("failed to retrieve configOptions for %s", optionsName)
  225. }
  226. return &pasturePb.ConfigOptionsListResponse{
  227. Code: http.StatusOK,
  228. Msg: "ok",
  229. Data: configOptions,
  230. }, nil
  231. }