config_data.go 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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, penType int) (*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. Where("pen_type = ?", penType).
  25. Find(&penList).Error; err != nil {
  26. return nil, err
  27. }
  28. configBarnTypeList := make([]*model.ConfigPenType, 0)
  29. if err := s.DB.Table(new(model.ConfigPenType).TableName()).Find(&configBarnTypeList).Error; err != nil {
  30. return nil, err
  31. }
  32. return &pasturePb.ConfigOptionsListResponse{
  33. Code: http.StatusOK,
  34. Message: "ok",
  35. Data: model.PenSlice(penList).ToPB2(configBarnTypeList),
  36. }, nil
  37. }
  38. func (s *StoreEntry) BreedStatusOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  39. configBreedStatusList := make([]*model.ConfigBreedStatus, 0)
  40. if err := s.DB.Table(new(model.ConfigBreedStatus).TableName()).Find(&configBreedStatusList).Error; err != nil {
  41. return nil, xxerr.WithStack(err)
  42. }
  43. return &pasturePb.ConfigOptionsListResponse{
  44. Code: http.StatusOK,
  45. Message: "ok",
  46. Data: model.ConfigBreedStatusSlice(configBreedStatusList).ToPB2(),
  47. }, nil
  48. }
  49. func (s *StoreEntry) CowKindOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  50. configCowKindList := make([]*model.ConfigCowKind, 0)
  51. if err := s.DB.Table(new(model.ConfigCowKind).TableName()).Find(&configCowKindList).Error; err != nil {
  52. return nil, xxerr.WithStack(err)
  53. }
  54. return &pasturePb.ConfigOptionsListResponse{
  55. Code: http.StatusOK,
  56. Message: "ok",
  57. Data: model.ConfigCowKindSlice(configCowKindList).ToPB2(),
  58. }, nil
  59. }
  60. func (s *StoreEntry) CowSourceOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  61. configCowSourceList := make([]*model.ConfigCowSource, 0)
  62. if err := s.DB.Table(new(model.ConfigCowSource).TableName()).Find(&configCowSourceList).Error; err != nil {
  63. return nil, xxerr.WithStack(err)
  64. }
  65. return &pasturePb.ConfigOptionsListResponse{
  66. Code: http.StatusOK,
  67. Message: "ok",
  68. Data: model.ConfigCowSourceSlice(configCowSourceList).ToPB2(),
  69. }, nil
  70. }
  71. func (s *StoreEntry) CowStatusOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  72. configCowStatusList := make([]*model.ConfigCowStatus, 0)
  73. if err := s.DB.Table(new(model.ConfigCowStatus).TableName()).Find(&configCowStatusList).Error; err != nil {
  74. return nil, xxerr.WithStack(err)
  75. }
  76. return &pasturePb.ConfigOptionsListResponse{
  77. Code: http.StatusOK,
  78. Message: "ok",
  79. Data: model.ConfigCowStatusSlice(configCowStatusList).ToPB2(),
  80. }, nil
  81. }
  82. func (s *StoreEntry) CowTypeOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  83. configCowTypeList := make([]*model.ConfigCowType, 0)
  84. if err := s.DB.Table(new(model.ConfigCowType).TableName()).Find(&configCowTypeList).Error; err != nil {
  85. return nil, xxerr.WithStack(err)
  86. }
  87. return &pasturePb.ConfigOptionsListResponse{
  88. Code: http.StatusOK,
  89. Message: "ok",
  90. Data: model.ConfigCowTypeSlice(configCowTypeList).ToPB2(),
  91. }, nil
  92. }
  93. func (s *StoreEntry) CowTransferPenReasonOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  94. configTransferPenReasonList := make([]*model.ConfigTransferPenReason, 0)
  95. if err := s.DB.Table(new(model.ConfigTransferPenReason).TableName()).Find(&configTransferPenReasonList).Error; err != nil {
  96. return nil, xxerr.WithStack(err)
  97. }
  98. return &pasturePb.ConfigOptionsListResponse{
  99. Code: http.StatusOK,
  100. Message: "ok",
  101. Data: model.ConfigTransferPenReasonSlice(configTransferPenReasonList).ToPB2(),
  102. }, nil
  103. }
  104. func (s *StoreEntry) SystemUserOptions(ctx context.Context, depId int) (*pasturePb.ConfigOptionsListResponse, error) {
  105. systemUserList := make([]*model.SystemUser, 0)
  106. pref := s.DB.Table(new(model.SystemUser).TableName())
  107. if depId != -1 && depId > 0 {
  108. pref = pref.Where("dep_id = ?", depId)
  109. }
  110. if err := pref.Find(&systemUserList).Error; err != nil {
  111. return nil, xxerr.WithStack(err)
  112. }
  113. return &pasturePb.ConfigOptionsListResponse{
  114. Code: http.StatusOK,
  115. Message: "ok",
  116. Data: model.SystemUserSlice(systemUserList).ToPB2(),
  117. }, nil
  118. }
  119. func (s *StoreEntry) SystemBaseConfigOptions(ctx context.Context, optionsName string) (*pasturePb.ConfigOptionsListResponse, error) {
  120. configOptions := make([]*pasturePb.ConfigOptionsList, 0)
  121. switch optionsName {
  122. case "childNumber":
  123. configOptions = append(configOptions,
  124. &pasturePb.ConfigOptionsList{
  125. Value: 1,
  126. Label: "单胎",
  127. Disabled: true,
  128. }, &pasturePb.ConfigOptionsList{
  129. Value: 2,
  130. Label: "双胎",
  131. Disabled: true,
  132. }, &pasturePb.ConfigOptionsList{
  133. Value: 3,
  134. Label: "三胎",
  135. Disabled: true,
  136. }, &pasturePb.ConfigOptionsList{
  137. Value: 4,
  138. Label: "四胎",
  139. Disabled: true,
  140. })
  141. case "calvingLevel":
  142. configOptions = append(configOptions,
  143. &pasturePb.ConfigOptionsList{
  144. Value: int32(pasturePb.CalvingLevel_Natural_Childbirth),
  145. Label: "自然分娩",
  146. Disabled: true,
  147. }, &pasturePb.ConfigOptionsList{
  148. Value: int32(pasturePb.CalvingLevel_Artificial_Midwifery1),
  149. Label: "人工助产(1-2人)",
  150. Disabled: true,
  151. }, &pasturePb.ConfigOptionsList{
  152. Value: int32(pasturePb.CalvingLevel_Artificial_Midwifery2),
  153. Label: "人工助产(3人以上)",
  154. Disabled: true,
  155. }, &pasturePb.ConfigOptionsList{
  156. Value: int32(pasturePb.CalvingLevel_Caesarean),
  157. Label: "剖腹产",
  158. Disabled: true,
  159. })
  160. case "dystociaReason":
  161. configOptions = append(configOptions,
  162. &pasturePb.ConfigOptionsList{
  163. Value: int32(pasturePb.DystociaReason_Malposition),
  164. Label: "胎位不正",
  165. Disabled: true,
  166. }, &pasturePb.ConfigOptionsList{
  167. Value: int32(pasturePb.DystociaReason_Fetal_Overgrowth),
  168. Label: "胎儿过大",
  169. Disabled: true,
  170. }, &pasturePb.ConfigOptionsList{
  171. Value: int32(pasturePb.DystociaReason_Uterine_Atony),
  172. Label: "子宫收缩无力",
  173. Disabled: true,
  174. }, &pasturePb.ConfigOptionsList{
  175. Value: int32(pasturePb.DystociaReason_Pelvic_Stenosis),
  176. Label: "盆骨狭小",
  177. Disabled: true,
  178. }, &pasturePb.ConfigOptionsList{
  179. Value: int32(pasturePb.DystociaReason_Sub_Health),
  180. Label: "母牛亚健康状态",
  181. Disabled: true,
  182. })
  183. }
  184. return &pasturePb.ConfigOptionsListResponse{
  185. Code: http.StatusOK,
  186. Message: "ok",
  187. Data: configOptions,
  188. }, nil
  189. }