config_data.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. package backend
  2. import (
  3. "context"
  4. "kpt-pasture/model"
  5. "net/http"
  6. xxerr "gitee.com/xuyiping_admin/pkg/xerr"
  7. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  8. )
  9. func (s *StoreEntry) BarnTypeOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  10. configBarnTypeList := make([]*model.ConfigPenType, 0)
  11. if err := s.DB.Table(new(model.ConfigPenType).TableName()).Find(&configBarnTypeList).Error; err != nil {
  12. return nil, err
  13. }
  14. return &pasturePb.ConfigOptionsListResponse{
  15. Code: http.StatusOK,
  16. Message: "ok",
  17. Data: model.ConfigBarnTypeSlice(configBarnTypeList).ToPB2(),
  18. }, nil
  19. }
  20. func (s *StoreEntry) BarnListOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  21. penList := make([]*model.Pen, 0)
  22. if err := s.DB.Table(new(model.Pen).TableName()).
  23. Where("is_delete = ?", pasturePb.IsShow_Ok).
  24. Find(&penList).Error; err != nil {
  25. return nil, err
  26. }
  27. configBarnTypeList := make([]*model.ConfigPenType, 0)
  28. if err := s.DB.Table(new(model.ConfigPenType).TableName()).Find(&configBarnTypeList).Error; err != nil {
  29. return nil, err
  30. }
  31. return &pasturePb.ConfigOptionsListResponse{
  32. Code: http.StatusOK,
  33. Message: "ok",
  34. Data: model.PenSlice(penList).ToPB2(configBarnTypeList),
  35. }, nil
  36. }
  37. func (s *StoreEntry) BreedStatusOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  38. configBreedStatusList := make([]*model.ConfigBreedStatus, 0)
  39. if err := s.DB.Table(new(model.ConfigBreedStatus).TableName()).Find(&configBreedStatusList).Error; err != nil {
  40. return nil, xxerr.WithStack(err)
  41. }
  42. return &pasturePb.ConfigOptionsListResponse{
  43. Code: http.StatusOK,
  44. Message: "ok",
  45. Data: model.ConfigBreedStatusSlice(configBreedStatusList).ToPB2(),
  46. }, nil
  47. }
  48. func (s *StoreEntry) CowKindOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  49. configCowKindList := make([]*model.ConfigCowKind, 0)
  50. if err := s.DB.Table(new(model.ConfigCowKind).TableName()).Find(&configCowKindList).Error; err != nil {
  51. return nil, xxerr.WithStack(err)
  52. }
  53. return &pasturePb.ConfigOptionsListResponse{
  54. Code: http.StatusOK,
  55. Message: "ok",
  56. Data: model.ConfigCowKindSlice(configCowKindList).ToPB2(),
  57. }, nil
  58. }
  59. func (s *StoreEntry) CowSourceOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  60. configCowSourceList := make([]*model.ConfigCowSource, 0)
  61. if err := s.DB.Table(new(model.ConfigCowSource).TableName()).Find(&configCowSourceList).Error; err != nil {
  62. return nil, xxerr.WithStack(err)
  63. }
  64. return &pasturePb.ConfigOptionsListResponse{
  65. Code: http.StatusOK,
  66. Message: "ok",
  67. Data: model.ConfigCowSourceSlice(configCowSourceList).ToPB2(),
  68. }, nil
  69. }
  70. func (s *StoreEntry) CowStatusOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  71. configCowStatusList := make([]*model.ConfigCowStatus, 0)
  72. if err := s.DB.Table(new(model.ConfigCowStatus).TableName()).Find(&configCowStatusList).Error; err != nil {
  73. return nil, xxerr.WithStack(err)
  74. }
  75. return &pasturePb.ConfigOptionsListResponse{
  76. Code: http.StatusOK,
  77. Message: "ok",
  78. Data: model.ConfigCowStatusSlice(configCowStatusList).ToPB2(),
  79. }, nil
  80. }
  81. func (s *StoreEntry) CowTypeOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  82. configCowTypeList := make([]*model.ConfigCowType, 0)
  83. if err := s.DB.Table(new(model.ConfigCowType).TableName()).Find(&configCowTypeList).Error; err != nil {
  84. return nil, xxerr.WithStack(err)
  85. }
  86. return &pasturePb.ConfigOptionsListResponse{
  87. Code: http.StatusOK,
  88. Message: "ok",
  89. Data: model.ConfigCowTypeSlice(configCowTypeList).ToPB2(),
  90. }, nil
  91. }
  92. func (s *StoreEntry) CowTransferPenReasonOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  93. configTransferPenReasonList := make([]*model.ConfigTransferPenReason, 0)
  94. if err := s.DB.Table(new(model.ConfigTransferPenReason).TableName()).Find(&configTransferPenReasonList).Error; err != nil {
  95. return nil, xxerr.WithStack(err)
  96. }
  97. return &pasturePb.ConfigOptionsListResponse{
  98. Code: http.StatusOK,
  99. Message: "ok",
  100. Data: model.ConfigTransferPenReasonSlice(configTransferPenReasonList).ToPB2(),
  101. }, nil
  102. }
  103. func (s *StoreEntry) SystemUserOptions(ctx context.Context, depId int) (*pasturePb.ConfigOptionsListResponse, error) {
  104. systemUserList := make([]*model.SystemUser, 0)
  105. pref := s.DB.Table(new(model.SystemUser).TableName())
  106. if depId != -1 && depId > 0 {
  107. pref = pref.Where("dep_id = ?", depId)
  108. }
  109. if err := pref.Find(&systemUserList).Error; err != nil {
  110. return nil, xxerr.WithStack(err)
  111. }
  112. return &pasturePb.ConfigOptionsListResponse{
  113. Code: http.StatusOK,
  114. Message: "ok",
  115. Data: model.SystemUserSlice(systemUserList).ToPB2(),
  116. }, nil
  117. }
  118. func (s *StoreEntry) SystemBaseConfigOptions(ctx context.Context, optionsName string) (*pasturePb.ConfigOptionsListResponse, error) {
  119. configOptions := make([]*pasturePb.ConfigOptionsList, 0)
  120. switch optionsName {
  121. case "childNumber":
  122. configOptions = append(configOptions,
  123. &pasturePb.ConfigOptionsList{
  124. Value: 1,
  125. Label: "单胎",
  126. Disabled: true,
  127. }, &pasturePb.ConfigOptionsList{
  128. Value: 2,
  129. Label: "双胎",
  130. Disabled: true,
  131. }, &pasturePb.ConfigOptionsList{
  132. Value: 3,
  133. Label: "三胎",
  134. Disabled: true,
  135. }, &pasturePb.ConfigOptionsList{
  136. Value: 4,
  137. Label: "四胎",
  138. Disabled: true,
  139. })
  140. case "calvingLevel":
  141. configOptions = append(configOptions,
  142. &pasturePb.ConfigOptionsList{
  143. Value: int32(pasturePb.CalvingLevel_Natural_Childbirth),
  144. Label: "自然分娩",
  145. Disabled: true,
  146. }, &pasturePb.ConfigOptionsList{
  147. Value: int32(pasturePb.CalvingLevel_Artificial_Midwifery_UnUse),
  148. Label: "人工助产-未使用医疗器械",
  149. Disabled: true,
  150. }, &pasturePb.ConfigOptionsList{
  151. Value: int32(pasturePb.CalvingLevel_Artificial_Midwifery_Use),
  152. Label: "人工助产-使用医疗器械",
  153. Disabled: true,
  154. })
  155. }
  156. return &pasturePb.ConfigOptionsListResponse{
  157. Code: http.StatusOK,
  158. Message: "ok",
  159. Data: configOptions,
  160. }, nil
  161. }