config_data.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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) BarnTypeEnumList() []*pasturePb.ConfigOptionsList {
  10. barnTypeList := make([]*pasturePb.ConfigOptionsList, 0)
  11. barnTypeList = append(barnTypeList, &pasturePb.ConfigOptionsList{
  12. Value: int32(pasturePb.PenType_Lactating_Calves),
  13. Label: "哺乳犊牛舍",
  14. Disabled: true,
  15. }, &pasturePb.ConfigOptionsList{
  16. Value: int32(pasturePb.PenType_Weaned_Calves),
  17. Label: "断奶犊牛舍",
  18. Disabled: true,
  19. }, &pasturePb.ConfigOptionsList{
  20. Value: int32(pasturePb.PenType_Youth),
  21. Label: "育成牛舍",
  22. Disabled: true,
  23. }, &pasturePb.ConfigOptionsList{
  24. Value: int32(pasturePb.PenType_Nurturing),
  25. Label: "育成牛舍",
  26. Disabled: true,
  27. }, &pasturePb.ConfigOptionsList{
  28. Value: int32(pasturePb.PenType_Lactation),
  29. Label: "泌乳牛舍",
  30. Disabled: true,
  31. }, &pasturePb.ConfigOptionsList{
  32. Value: int32(pasturePb.PenType_Peripartum),
  33. Label: "围产牛舍",
  34. Disabled: true,
  35. }, &pasturePb.ConfigOptionsList{
  36. Value: int32(pasturePb.PenType_Dry_Milking),
  37. Label: "干奶牛舍",
  38. Disabled: true,
  39. }, &pasturePb.ConfigOptionsList{
  40. Value: int32(pasturePb.PenType_Sick_Cow),
  41. Label: "病牛舍",
  42. Disabled: true,
  43. }, &pasturePb.ConfigOptionsList{
  44. Value: int32(pasturePb.PenType_Eliminate),
  45. Label: "淘汰牛舍",
  46. Disabled: true,
  47. })
  48. return barnTypeList
  49. }
  50. func (s *StoreEntry) BreedStatusEnumList() []*pasturePb.ConfigOptionsList {
  51. breedStatusList := make([]*pasturePb.ConfigOptionsList, 0)
  52. breedStatusList = append(breedStatusList, &pasturePb.ConfigOptionsList{
  53. Value: int32(pasturePb.BreedStatus_Unmarried),
  54. Label: "未配",
  55. Disabled: true,
  56. }, &pasturePb.ConfigOptionsList{
  57. Value: int32(pasturePb.BreedStatus_InCheck_Unpregnant),
  58. Label: "初检无胎",
  59. Disabled: true,
  60. }, &pasturePb.ConfigOptionsList{
  61. Value: int32(pasturePb.BreedStatus_InCheck_Pregnant),
  62. Label: "初检有胎",
  63. Disabled: true,
  64. }, &pasturePb.ConfigOptionsList{
  65. Value: int32(pasturePb.BreedStatus_Recheck_Unpregnant),
  66. Label: "复检无胎",
  67. Disabled: true,
  68. }, &pasturePb.ConfigOptionsList{
  69. Value: int32(pasturePb.BreedStatus_Recheck_Pregnant),
  70. Label: "复检有胎",
  71. Disabled: true,
  72. }, &pasturePb.ConfigOptionsList{
  73. Value: int32(pasturePb.BreedStatus_Pause_Pregnant),
  74. Label: "停配",
  75. Disabled: true,
  76. }, &pasturePb.ConfigOptionsList{
  77. Value: int32(pasturePb.BreedStatus_No_Pregnant),
  78. Label: "禁配",
  79. Disabled: true,
  80. })
  81. return breedStatusList
  82. }
  83. func (s *StoreEntry) CowKindEnumList() []*pasturePb.ConfigOptionsList {
  84. cowKindList := make([]*pasturePb.ConfigOptionsList, 0)
  85. cowKindList = append(cowKindList, &pasturePb.ConfigOptionsList{
  86. Value: int32(pasturePb.CowKind_HST),
  87. Label: "荷斯坦",
  88. Disabled: true,
  89. }, &pasturePb.ConfigOptionsList{
  90. Value: int32(pasturePb.CowKind_JSN),
  91. Label: "娟姗牛",
  92. Disabled: true,
  93. }, &pasturePb.ConfigOptionsList{
  94. Value: int32(pasturePb.CowKind_SHN),
  95. Label: "三河牛",
  96. Disabled: true,
  97. }, &pasturePb.ConfigOptionsList{
  98. Value: int32(pasturePb.CowKind_XJHN),
  99. Label: "新疆褐牛",
  100. Disabled: true,
  101. }, &pasturePb.ConfigOptionsList{
  102. Value: int32(pasturePb.CowKind_MN),
  103. Label: "牦牛",
  104. Disabled: true,
  105. }, &pasturePb.ConfigOptionsList{
  106. Value: int32(pasturePb.CowKind_XMTEN),
  107. Label: "西门塔尔牛",
  108. Disabled: true,
  109. })
  110. return cowKindList
  111. }
  112. func (s *StoreEntry) CowSourceEnumList() []*pasturePb.ConfigOptionsList {
  113. cowSourceList := make([]*pasturePb.ConfigOptionsList, 0)
  114. cowSourceList = append(cowSourceList, &pasturePb.ConfigOptionsList{
  115. Value: int32(pasturePb.CowSource_Calving),
  116. Label: "产犊",
  117. Disabled: true,
  118. }, &pasturePb.ConfigOptionsList{
  119. Value: int32(pasturePb.CowSource_Transfer_In),
  120. Label: "调入",
  121. Disabled: true,
  122. }, &pasturePb.ConfigOptionsList{
  123. Value: int32(pasturePb.CowSource_Buy),
  124. Label: "购买",
  125. Disabled: true,
  126. })
  127. return cowSourceList
  128. }
  129. func (s *StoreEntry) CowStatusEnumList() []*pasturePb.ConfigOptionsList {
  130. cowStatusList := make([]*pasturePb.ConfigOptionsList, 0)
  131. cowStatusList = append(cowStatusList, &pasturePb.ConfigOptionsList{
  132. Value: int32(pasturePb.CowStatus_Calving),
  133. Label: "产犊",
  134. Disabled: true,
  135. }, &pasturePb.ConfigOptionsList{
  136. Value: int32(pasturePb.CowStatus_Empty),
  137. Label: "空怀",
  138. Disabled: true,
  139. }, &pasturePb.ConfigOptionsList{
  140. Value: int32(pasturePb.CowStatus_Breeding),
  141. Label: "配种",
  142. Disabled: true,
  143. }, &pasturePb.ConfigOptionsList{
  144. Value: int32(pasturePb.CowStatus_Pregnant),
  145. Label: "怀孕",
  146. Disabled: true,
  147. }, &pasturePb.ConfigOptionsList{
  148. Value: int32(pasturePb.CowStatus_Dry_Milk),
  149. Label: "干奶",
  150. Disabled: true,
  151. }, &pasturePb.ConfigOptionsList{
  152. Value: int32(pasturePb.CowStatus_Peripartum),
  153. Label: "围产",
  154. Disabled: true,
  155. }, &pasturePb.ConfigOptionsList{
  156. Value: int32(pasturePb.CowStatus_No_Pregnant),
  157. Label: "禁配",
  158. Disabled: true,
  159. })
  160. return cowStatusList
  161. }
  162. func (s *StoreEntry) CowTypeEnumList() []*pasturePb.ConfigOptionsList {
  163. cowTypeList := make([]*pasturePb.ConfigOptionsList, 0)
  164. cowTypeList = append(cowTypeList, &pasturePb.ConfigOptionsList{
  165. Value: int32(pasturePb.CowType_Lactating_Calf),
  166. Label: "哺乳犊牛",
  167. Disabled: true,
  168. }, &pasturePb.ConfigOptionsList{
  169. Value: int32(pasturePb.CowType_Weaned_Calf),
  170. Label: "断奶犊牛",
  171. Disabled: true,
  172. }, &pasturePb.ConfigOptionsList{
  173. Value: int32(pasturePb.CowType_Youth),
  174. Label: "青年牛",
  175. Disabled: true,
  176. }, &pasturePb.ConfigOptionsList{
  177. Value: int32(pasturePb.CowType_Nurturing),
  178. Label: "育成牛",
  179. Disabled: true,
  180. }, &pasturePb.ConfigOptionsList{
  181. Value: int32(pasturePb.CowType_Lactation),
  182. Label: "泌乳牛",
  183. Disabled: true,
  184. }, &pasturePb.ConfigOptionsList{
  185. Value: int32(pasturePb.CowType_Dry_Milk),
  186. Label: "干奶牛",
  187. Disabled: true,
  188. })
  189. return cowTypeList
  190. }
  191. func (s *StoreEntry) TransferPenEnumList() []*pasturePb.ConfigOptionsList {
  192. transferPenList := make([]*pasturePb.ConfigOptionsList, 0)
  193. transferPenList = append(transferPenList, &pasturePb.ConfigOptionsList{
  194. Value: int32(pasturePb.TransferPenReason_Normal),
  195. Label: "正常转群",
  196. Disabled: true,
  197. }, &pasturePb.ConfigOptionsList{
  198. Value: int32(pasturePb.TransferPenReason_Feed),
  199. Label: "饲喂转群",
  200. Disabled: true,
  201. }, &pasturePb.ConfigOptionsList{
  202. Value: int32(pasturePb.TransferPenReason_Dry_Milk),
  203. Label: "干奶转群",
  204. Disabled: true,
  205. }, &pasturePb.ConfigOptionsList{
  206. Value: int32(pasturePb.TransferPenReason_Pregnant),
  207. Label: "怀孕转群",
  208. Disabled: true,
  209. }, &pasturePb.ConfigOptionsList{
  210. Value: int32(pasturePb.TransferPenReason_Overantibody),
  211. Label: "过抗转群",
  212. Disabled: true,
  213. })
  214. return transferPenList
  215. }
  216. func (s *StoreEntry) BarnTypeOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  217. return &pasturePb.ConfigOptionsListResponse{
  218. Code: http.StatusOK,
  219. Message: "ok",
  220. Data: s.BarnTypeEnumList(),
  221. }, nil
  222. }
  223. func (s *StoreEntry) BarnListOptions(ctx context.Context, penType int) (*pasturePb.ConfigOptionsListResponse, error) {
  224. penList := make([]*model.Pen, 0)
  225. if err := s.DB.Table(new(model.Pen).TableName()).
  226. Where("is_delete = ?", pasturePb.IsShow_Ok).
  227. Where("pen_type = ?", penType).
  228. Find(&penList).Error; err != nil {
  229. return nil, err
  230. }
  231. return &pasturePb.ConfigOptionsListResponse{
  232. Code: http.StatusOK,
  233. Message: "ok",
  234. Data: model.PenSlice(penList).ToPB2(s.BarnTypeEnumList()),
  235. }, nil
  236. }
  237. func (s *StoreEntry) BreedStatusOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  238. return &pasturePb.ConfigOptionsListResponse{
  239. Code: http.StatusOK,
  240. Message: "ok",
  241. Data: s.BreedStatusEnumList(),
  242. }, nil
  243. }
  244. func (s *StoreEntry) CowKindOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  245. return &pasturePb.ConfigOptionsListResponse{
  246. Code: http.StatusOK,
  247. Message: "ok",
  248. Data: s.CowKindEnumList(),
  249. }, nil
  250. }
  251. func (s *StoreEntry) CowSourceOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  252. return &pasturePb.ConfigOptionsListResponse{
  253. Code: http.StatusOK,
  254. Message: "ok",
  255. Data: s.CowSourceEnumList(),
  256. }, nil
  257. }
  258. func (s *StoreEntry) CowStatusOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  259. return &pasturePb.ConfigOptionsListResponse{
  260. Code: http.StatusOK,
  261. Message: "ok",
  262. Data: s.CowStatusEnumList(),
  263. }, nil
  264. }
  265. func (s *StoreEntry) CowTypeOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  266. return &pasturePb.ConfigOptionsListResponse{
  267. Code: http.StatusOK,
  268. Message: "ok",
  269. Data: s.CowTypeEnumList(),
  270. }, nil
  271. }
  272. func (s *StoreEntry) CowTransferPenReasonOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  273. return &pasturePb.ConfigOptionsListResponse{
  274. Code: http.StatusOK,
  275. Message: "ok",
  276. Data: s.TransferPenEnumList(),
  277. }, nil
  278. }
  279. func (s *StoreEntry) SystemUserOptions(ctx context.Context, depId int) (*pasturePb.ConfigOptionsListResponse, error) {
  280. systemUserList := make([]*model.SystemUser, 0)
  281. pref := s.DB.Table(new(model.SystemUser).TableName())
  282. if depId != -1 && depId > 0 {
  283. pref = pref.Where("dep_id = ?", depId)
  284. }
  285. if err := pref.Find(&systemUserList).Error; err != nil {
  286. return nil, xxerr.WithStack(err)
  287. }
  288. return &pasturePb.ConfigOptionsListResponse{
  289. Code: http.StatusOK,
  290. Message: "ok",
  291. Data: model.SystemUserSlice(systemUserList).ToPB2(),
  292. }, nil
  293. }
  294. func (s *StoreEntry) SystemBaseConfigOptions(ctx context.Context, optionsName string) (*pasturePb.ConfigOptionsListResponse, error) {
  295. configOptions := make([]*pasturePb.ConfigOptionsList, 0)
  296. switch optionsName {
  297. case "childNumber":
  298. configOptions = append(configOptions,
  299. &pasturePb.ConfigOptionsList{
  300. Value: int32(pasturePb.ChildNumber_One),
  301. Label: "单胎",
  302. Disabled: true,
  303. }, &pasturePb.ConfigOptionsList{
  304. Value: int32(pasturePb.ChildNumber_Two),
  305. Label: "双胎",
  306. Disabled: true,
  307. }, &pasturePb.ConfigOptionsList{
  308. Value: int32(pasturePb.ChildNumber_Three),
  309. Label: "三胎",
  310. Disabled: true,
  311. }, &pasturePb.ConfigOptionsList{
  312. Value: int32(pasturePb.ChildNumber_Four),
  313. Label: "四胎",
  314. Disabled: true,
  315. })
  316. case "calvingLevel":
  317. configOptions = append(configOptions,
  318. &pasturePb.ConfigOptionsList{
  319. Value: int32(pasturePb.CalvingLevel_Natural_Childbirth),
  320. Label: "自然分娩",
  321. Disabled: true,
  322. }, &pasturePb.ConfigOptionsList{
  323. Value: int32(pasturePb.CalvingLevel_Artificial_Midwifery1),
  324. Label: "人工助产(1-2人)",
  325. Disabled: true,
  326. }, &pasturePb.ConfigOptionsList{
  327. Value: int32(pasturePb.CalvingLevel_Artificial_Midwifery2),
  328. Label: "人工助产(3人以上)",
  329. Disabled: true,
  330. }, &pasturePb.ConfigOptionsList{
  331. Value: int32(pasturePb.CalvingLevel_Caesarean),
  332. Label: "剖腹产",
  333. Disabled: true,
  334. })
  335. case "dystociaReason":
  336. configOptions = append(configOptions,
  337. &pasturePb.ConfigOptionsList{
  338. Value: int32(pasturePb.DystociaReason_Malposition),
  339. Label: "胎位不正",
  340. Disabled: true,
  341. }, &pasturePb.ConfigOptionsList{
  342. Value: int32(pasturePb.DystociaReason_Fetal_Overgrowth),
  343. Label: "胎儿过大",
  344. Disabled: true,
  345. }, &pasturePb.ConfigOptionsList{
  346. Value: int32(pasturePb.DystociaReason_Uterine_Atony),
  347. Label: "子宫收缩无力",
  348. Disabled: true,
  349. }, &pasturePb.ConfigOptionsList{
  350. Value: int32(pasturePb.DystociaReason_Pelvic_Stenosis),
  351. Label: "盆骨狭小",
  352. Disabled: true,
  353. }, &pasturePb.ConfigOptionsList{
  354. Value: int32(pasturePb.DystociaReason_Sub_Health),
  355. Label: "母牛亚健康状态",
  356. Disabled: true,
  357. })
  358. }
  359. return &pasturePb.ConfigOptionsListResponse{
  360. Code: http.StatusOK,
  361. Message: "ok",
  362. Data: configOptions,
  363. }, nil
  364. }