enum_options.go 9.2 KB

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