config_data.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  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) ChildNumberEnumList() []*pasturePb.ConfigOptionsList {
  217. configOptions := make([]*pasturePb.ConfigOptionsList, 0)
  218. configOptions = append(configOptions,
  219. &pasturePb.ConfigOptionsList{
  220. Value: int32(pasturePb.ChildNumber_One),
  221. Label: "单胎",
  222. Disabled: true,
  223. }, &pasturePb.ConfigOptionsList{
  224. Value: int32(pasturePb.ChildNumber_Two),
  225. Label: "双胎",
  226. Disabled: true,
  227. }, &pasturePb.ConfigOptionsList{
  228. Value: int32(pasturePb.ChildNumber_Three),
  229. Label: "三胎",
  230. Disabled: true,
  231. }, &pasturePb.ConfigOptionsList{
  232. Value: int32(pasturePb.ChildNumber_Four),
  233. Label: "四胎",
  234. Disabled: true,
  235. })
  236. return configOptions
  237. }
  238. func (s *StoreEntry) CalvingLevelEnumList() []*pasturePb.ConfigOptionsList {
  239. configOptions := make([]*pasturePb.ConfigOptionsList, 0)
  240. configOptions = append(configOptions,
  241. &pasturePb.ConfigOptionsList{
  242. Value: int32(pasturePb.CalvingLevel_Natural_Childbirth),
  243. Label: "自然分娩",
  244. Disabled: true,
  245. }, &pasturePb.ConfigOptionsList{
  246. Value: int32(pasturePb.CalvingLevel_Artificial_Midwifery1),
  247. Label: "人工助产(1-2人)",
  248. Disabled: true,
  249. }, &pasturePb.ConfigOptionsList{
  250. Value: int32(pasturePb.CalvingLevel_Artificial_Midwifery2),
  251. Label: "人工助产(3人以上)",
  252. Disabled: true,
  253. }, &pasturePb.ConfigOptionsList{
  254. Value: int32(pasturePb.CalvingLevel_Caesarean),
  255. Label: "剖腹产",
  256. Disabled: true,
  257. })
  258. return configOptions
  259. }
  260. func (s *StoreEntry) DystociaReason() []*pasturePb.ConfigOptionsList {
  261. configOptions := make([]*pasturePb.ConfigOptionsList, 0)
  262. configOptions = append(configOptions,
  263. &pasturePb.ConfigOptionsList{
  264. Value: int32(pasturePb.DystociaReason_Malposition),
  265. Label: "胎位不正",
  266. Disabled: true,
  267. }, &pasturePb.ConfigOptionsList{
  268. Value: int32(pasturePb.DystociaReason_Fetal_Overgrowth),
  269. Label: "胎儿过大",
  270. Disabled: true,
  271. }, &pasturePb.ConfigOptionsList{
  272. Value: int32(pasturePb.DystociaReason_Uterine_Atony),
  273. Label: "子宫收缩无力",
  274. Disabled: true,
  275. }, &pasturePb.ConfigOptionsList{
  276. Value: int32(pasturePb.DystociaReason_Pelvic_Stenosis),
  277. Label: "盆骨狭小",
  278. Disabled: true,
  279. }, &pasturePb.ConfigOptionsList{
  280. Value: int32(pasturePb.DystociaReason_Sub_Health),
  281. Label: "母牛亚健康状态",
  282. Disabled: true,
  283. })
  284. return configOptions
  285. }
  286. func (s *StoreEntry) PregnantCheckResult() []*pasturePb.ConfigOptionsList {
  287. configOptions := make([]*pasturePb.ConfigOptionsList, 0)
  288. configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
  289. Value: int32(pasturePb.PregnantCheckResult_InCheck_UnPregnant),
  290. Label: "初检未孕",
  291. Disabled: true,
  292. }, &pasturePb.ConfigOptionsList{
  293. Value: int32(pasturePb.PregnantCheckResult_InCheck_Pregnant),
  294. Label: "初检已孕",
  295. Disabled: true,
  296. }, &pasturePb.ConfigOptionsList{
  297. Value: int32(pasturePb.PregnantCheckResult_Recheck_UnPregnant),
  298. Label: "复检未孕",
  299. Disabled: true,
  300. }, &pasturePb.ConfigOptionsList{
  301. Value: int32(pasturePb.PregnantCheckResult_Recheck_Pregnant),
  302. Label: "初检已孕",
  303. Disabled: true,
  304. })
  305. return configOptions
  306. }
  307. func (s *StoreEntry) PregnantCheckMethod() []*pasturePb.ConfigOptionsList {
  308. configOptions := make([]*pasturePb.ConfigOptionsList, 0)
  309. configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
  310. Value: int32(pasturePb.PregnantCheckMethod_B_Ultrasound),
  311. Label: "B超",
  312. Disabled: true,
  313. }, &pasturePb.ConfigOptionsList{
  314. Value: int32(pasturePb.PregnantCheckMethod_Blood_Testing),
  315. Label: "血检",
  316. Disabled: true,
  317. }, &pasturePb.ConfigOptionsList{
  318. Value: int32(pasturePb.PregnantCheckMethod_Manual_Inspection),
  319. Label: "人工检查",
  320. Disabled: true,
  321. })
  322. return configOptions
  323. }
  324. func (s *StoreEntry) BarnTypeOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  325. return &pasturePb.ConfigOptionsListResponse{
  326. Code: http.StatusOK,
  327. Message: "ok",
  328. Data: s.BarnTypeEnumList(),
  329. }, nil
  330. }
  331. func (s *StoreEntry) BarnListOptions(ctx context.Context, penType int) (*pasturePb.ConfigOptionsListResponse, error) {
  332. penList := make([]*model.Pen, 0)
  333. if err := s.DB.Table(new(model.Pen).TableName()).
  334. Where("is_delete = ?", pasturePb.IsShow_Ok).
  335. Where("pen_type = ?", penType).
  336. Find(&penList).Error; err != nil {
  337. return nil, err
  338. }
  339. return &pasturePb.ConfigOptionsListResponse{
  340. Code: http.StatusOK,
  341. Message: "ok",
  342. Data: model.PenSlice(penList).ToPB2(s.BarnTypeEnumList()),
  343. }, nil
  344. }
  345. func (s *StoreEntry) BreedStatusOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  346. return &pasturePb.ConfigOptionsListResponse{
  347. Code: http.StatusOK,
  348. Message: "ok",
  349. Data: s.BreedStatusEnumList(),
  350. }, nil
  351. }
  352. func (s *StoreEntry) CowKindOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  353. return &pasturePb.ConfigOptionsListResponse{
  354. Code: http.StatusOK,
  355. Message: "ok",
  356. Data: s.CowKindEnumList(),
  357. }, nil
  358. }
  359. func (s *StoreEntry) CowSourceOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  360. return &pasturePb.ConfigOptionsListResponse{
  361. Code: http.StatusOK,
  362. Message: "ok",
  363. Data: s.CowSourceEnumList(),
  364. }, nil
  365. }
  366. func (s *StoreEntry) CowStatusOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  367. return &pasturePb.ConfigOptionsListResponse{
  368. Code: http.StatusOK,
  369. Message: "ok",
  370. Data: s.CowStatusEnumList(),
  371. }, nil
  372. }
  373. func (s *StoreEntry) CowTypeOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  374. return &pasturePb.ConfigOptionsListResponse{
  375. Code: http.StatusOK,
  376. Message: "ok",
  377. Data: s.CowTypeEnumList(),
  378. }, nil
  379. }
  380. func (s *StoreEntry) CowTransferPenReasonOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
  381. return &pasturePb.ConfigOptionsListResponse{
  382. Code: http.StatusOK,
  383. Message: "ok",
  384. Data: s.TransferPenEnumList(),
  385. }, nil
  386. }
  387. func (s *StoreEntry) SystemUserOptions(ctx context.Context, depId int) (*pasturePb.ConfigOptionsListResponse, error) {
  388. systemUserList := make([]*model.SystemUser, 0)
  389. pref := s.DB.Table(new(model.SystemUser).TableName())
  390. if depId != -1 && depId > 0 {
  391. pref = pref.Where("dep_id = ?", depId)
  392. }
  393. if err := pref.Find(&systemUserList).Error; err != nil {
  394. return nil, xxerr.WithStack(err)
  395. }
  396. return &pasturePb.ConfigOptionsListResponse{
  397. Code: http.StatusOK,
  398. Message: "ok",
  399. Data: model.SystemUserSlice(systemUserList).ToPB2(),
  400. }, nil
  401. }
  402. func (s *StoreEntry) SystemBaseConfigOptions(ctx context.Context, optionsName string) (*pasturePb.ConfigOptionsListResponse, error) {
  403. configOptions := make([]*pasturePb.ConfigOptionsList, 0)
  404. switch optionsName {
  405. case "childNumber":
  406. configOptions = s.ChildNumberEnumList()
  407. case "calvingLevel":
  408. configOptions = s.CalvingLevelEnumList()
  409. case "dystociaReason":
  410. configOptions = s.DystociaReason()
  411. }
  412. return &pasturePb.ConfigOptionsListResponse{
  413. Code: http.StatusOK,
  414. Message: "ok",
  415. Data: configOptions,
  416. }, nil
  417. }