cow.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. package model
  2. import (
  3. "math"
  4. "time"
  5. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  6. )
  7. const NeckRingDataDays = 50 // 默认获取50天的脖环数据
  8. type Cow struct {
  9. Id int64 `json:"id"`
  10. PastureId int64 `json:"pastureId"` // 牧场id
  11. Sex pasturePb.Genders_Kind `json:"sex"` // 性别
  12. NeckRingNumber string `json:"neckRingNumber"` // 脖环号
  13. EarNumber string `json:"earNumber"` // 耳标号
  14. EleEarNumber string `json:"eleEarNumber"` // 电子耳标号
  15. EarOldNumber string `json:"earOldNumber"` // 旧耳标号
  16. PenId int32 `json:"penId"` // 栏舍id
  17. PenName string `json:"penName"` // 栏舍名称
  18. Lact int32 `json:"lact"` // 胎次
  19. DayAge int32 `json:"dayAge"` // 日龄
  20. CalvingAge int32 `json:"calvingAge"` // 产后天使
  21. PregnancyAge int32 `json:"pregnancyAge"` // 怀孕天数 孕检结果有阳性更新,产犊后至0
  22. MatingAge int32 `json:"matingAge"` // 配种天数
  23. AdmissionAge int32 `json:"admissionAge"` // 入场日龄
  24. AbortionAge int32 `json:"abortionAge"` // 流产天数
  25. LactationAge int32 `json:"lactationAge"` // 泌乳天数
  26. DryMilkAge int32 `json:"dryMilkAge"` // 干奶天数
  27. CowType pasturePb.CowType_Kind `json:"cowType"` // 牛只类型
  28. MilkKind pasturePb.CowMilk_Kind `json:"milkKind"` // 牛只奶属性
  29. BreedStatus pasturePb.BreedStatus_Kind `json:"breedStatus"` // 繁殖状态
  30. CowKind pasturePb.CowKind_Kind `json:"cowKind"` // 牛只品种
  31. BirthWeight int64 `json:"birthWeight"` // 出生体重
  32. CurrentWeight int64 `json:"currentWeight"` // 当前体重
  33. CurrentHeight int64 `json:"currentHeight"` // 当前身高
  34. AdmissionWeight int64 `json:"admissionWeight"` // 入场体重
  35. AdmissionPrice float32 `json:"admissionPrice"` // 入场价格
  36. SourceKind pasturePb.CowSource_Kind `json:"sourceKind"` // 来源哪里
  37. PurposeKind pasturePb.Purpose_Kind `json:"purposeKind"` // 用途
  38. FatherNumber string `json:"fatherNumber"` // 父号
  39. MotherNumber string `json:"motherNumber"` // 母号
  40. AdmissionStatus pasturePb.AdmissionStatus_Kind `json:"admissionStatus"` // 在场状态
  41. IsPregnant pasturePb.IsShow_Kind `json:"isPregnant"` // 是否怀孕
  42. IsForbiddenMating pasturePb.IsShow_Kind `json:"isForbiddenMating"` // 是否禁配 1 是 2 否
  43. HealthStatus pasturePb.HealthStatus_Kind `json:"healthStatus"` // 健康状态
  44. WeaningAt int64 `json:"weaningAt"` // 断奶时间
  45. BirthAt int64 `json:"birthAt"` // 出生时间
  46. AdmissionAt int64 `json:"admissionAt"` // 入场时间
  47. DepartureAt int64 `json:"departureAt"` // 离场时间
  48. WeaningWeight int64 `json:"weaningWeight"` // 断奶体重
  49. DeparturePrice float32 `json:"departurePrice"` // 离场价格
  50. DepartureAvgWeight int32 `json:"departureAvgWeight"` // 离场平均体重
  51. FirstMatingAt int64 `json:"firstMatingAt"` // 首次配种时间
  52. AllMatingTimes int32 `json:"allMatingTimes"` // 总配次
  53. AllAbortionTimes int32 `json:"allAbortionTimes"` // 总流产次数
  54. MatingTimes int32 `json:"matingTimes"` // 配种次数
  55. AbortionTimes int32 `json:"abortionTimes"` // 流产次数
  56. PregnancyCheckName string `json:"pregnancyCheckName"` // 孕检名称
  57. WeeklyActive int32 `json:"weeklyActive"` // 每周活跃度
  58. LastEstrusAt int64 `json:"lastEstrusAt"` // 最后一次发情时间
  59. LastCalvingAt int64 `json:"lastCalvingAt"` // 最后一次产犊时间
  60. LastMatingAt int64 `json:"lastMatingAt"` // 最后一次配种时间
  61. LastBullNumber string `json:"lastBullNumber"` // 最后一次配种牛号
  62. LastPregnantCheckAt int64 `json:"lastPregnantCheckAt"` // 最后一次孕检时间
  63. LastDryMilkAt int64 `json:"lastDryMilkAt"` // 最近一次干奶日期
  64. LastForbiddenMatingAt int64 `json:"lastForbiddenMatingAt"` // 最近一次禁配时间
  65. LastSecondWeight int64 `json:"lastSecondWeight"` // 最后第二次称重
  66. LastSecondWeightAt int64 `json:"lastSecondWeightAt"` // 最后第二次称重时间
  67. LastAbortionAt int64 `json:"lastAbortionAt"` // 最近一次流产时间
  68. LastWeightAt int64 `json:"lastWeightAt"` // 最近一次称重时间
  69. BatchNumber string `json:"batchNumber"` // 批次号
  70. CreatedAt int64 `json:"createdAt"`
  71. UpdatedAt int64 `json:"updatedAt"`
  72. }
  73. func (c *Cow) TableName() string {
  74. return "cow"
  75. }
  76. // EventUpdate 牛只基本信息维护
  77. func (c *Cow) EventUpdate(weeklyActive int32) {
  78. c.DayAge = c.GetDayAge() // 日龄
  79. c.CalvingAge = c.GetCalvingAge() // 产后天数
  80. c.PregnancyAge = c.GetDaysPregnant() // 怀孕天数
  81. c.AdmissionAge = c.GetAdmissionAge() // 入场天数
  82. c.AbortionAge = c.GetAbortionAge() // 流产天数
  83. c.WeeklyActive = weeklyActive // 周活动量
  84. c.LactationAge = c.GetLactationAge() // 泌乳天数
  85. c.DryMilkAge = c.GetDryMilkAge() // 干奶天数
  86. c.MatingAge = c.GetMatingAge() // 配后天数
  87. if c.DayAge == 60 {
  88. c.CowType = pasturePb.CowType_Weaned_Calf
  89. }
  90. }
  91. // EventCalvingUpdate 产犊更新
  92. func (c *Cow) EventCalvingUpdate(calvingAt int64) {
  93. c.Lact += 1
  94. c.MatingTimes = 0
  95. c.PregnancyAge = 0
  96. c.AbortionTimes = 0
  97. c.BreedStatus = pasturePb.BreedStatus_Calving
  98. c.IsPregnant = pasturePb.IsShow_No
  99. c.LastCalvingAt = calvingAt
  100. c.CalvingAge = c.GetCalvingAge()
  101. c.CowType = pasturePb.CowType_Breeding_Calf
  102. c.MilkKind = pasturePb.CowMilk_Lactation
  103. }
  104. // EventWeaningUpdate 断奶更新
  105. func (c *Cow) EventWeaningUpdate(weaningAt int64, penId int32, currentWeight int64) {
  106. c.PenId = penId
  107. c.WeaningAt = weaningAt
  108. c.CurrentWeight = currentWeight
  109. c.LastWeightAt = weaningAt
  110. c.WeaningWeight = currentWeight
  111. }
  112. // EventPregnantCheckUpdate 孕检更新
  113. func (c *Cow) EventPregnantCheckUpdate(breedStatus pasturePb.BreedStatus_Kind, pregnantCheckAt int64,
  114. isPregnant pasturePb.IsShow_Kind, pregnancyCheckName string) {
  115. c.BreedStatus = breedStatus
  116. c.LastPregnantCheckAt = pregnantCheckAt
  117. c.IsPregnant = isPregnant
  118. c.PregnancyCheckName = pregnancyCheckName
  119. }
  120. // EventAbortionUpdate 流产更新
  121. func (c *Cow) EventAbortionUpdate(abortionAt int64, isLact pasturePb.IsShow_Kind) {
  122. c.IsPregnant = pasturePb.IsShow_No
  123. c.LastAbortionAt = abortionAt
  124. c.BreedStatus = pasturePb.BreedStatus_Abort
  125. c.AbortionTimes += 1
  126. c.AllAbortionTimes += 1
  127. c.PregnancyAge = 0
  128. if isLact == pasturePb.IsShow_Ok {
  129. c.Lact += 1
  130. }
  131. }
  132. // EventWeightUpdate 称重更新
  133. func (c *Cow) EventWeightUpdate(weight, height, weightAt int64) {
  134. c.LastSecondWeight = c.CurrentWeight
  135. c.LastSecondWeightAt = c.LastWeightAt
  136. c.LastWeightAt = weightAt
  137. c.CurrentWeight = weight
  138. c.CurrentHeight = height
  139. }
  140. // EventHealthStatusUpdate 健康状态更新
  141. func (c *Cow) EventHealthStatusUpdate(healthStatus pasturePb.HealthStatus_Kind) {
  142. c.HealthStatus = healthStatus
  143. }
  144. // EventPenUpdate 更新栏舍
  145. func (c *Cow) EventPenUpdate(pen *Pen) {
  146. c.PenId = pen.Id
  147. c.PenName = pen.Name
  148. if pen.PenType == pasturePb.PenType_Reserve {
  149. c.CowType = pasturePb.CowType_Reserve_Calf
  150. }
  151. }
  152. // EventEarNumberUpdate 更新耳标号
  153. func (c *Cow) EventEarNumberUpdate(newEarNumber string) {
  154. c.EarOldNumber = c.EarNumber
  155. c.EarNumber = newEarNumber
  156. }
  157. // EventDeathUpdate 更新牛只死亡信息
  158. func (c *Cow) EventDeathUpdate(eventAt int64) {
  159. c.AdmissionStatus = pasturePb.AdmissionStatus_Die
  160. c.HealthStatus = pasturePb.HealthStatus_Dead
  161. c.DepartureAt = eventAt
  162. c.NeckRingNumber = ""
  163. }
  164. // EventSaleUpdate 更新牛只销售信息
  165. func (c *Cow) EventSaleUpdate(eventSale *EventSale) {
  166. c.DepartureAt = eventSale.SaleAt
  167. c.NeckRingNumber = ""
  168. c.DeparturePrice = float32(eventSale.SalePrice)
  169. if eventSale.SaleKind == pasturePb.SalesType_Out {
  170. c.HealthStatus = pasturePb.HealthStatus_Out
  171. c.AdmissionStatus = pasturePb.AdmissionStatus_Out
  172. }
  173. if eventSale.SaleKind == pasturePb.SalesType_Sales {
  174. c.AdmissionStatus = pasturePb.AdmissionStatus_Sale
  175. }
  176. if eventSale.SaleCowCount > 0 {
  177. c.DepartureAvgWeight = eventSale.SaleAllWeight / eventSale.SaleCowCount
  178. }
  179. }
  180. // EventMatingUpdate 配种更新
  181. func (c *Cow) EventMatingUpdate(matingAt int64, bullNumber string, isReMating bool) {
  182. c.LastMatingAt = matingAt
  183. c.LastBullNumber = bullNumber
  184. c.IsPregnant = pasturePb.IsShow_No
  185. c.BreedStatus = pasturePb.BreedStatus_Breeding
  186. if c.FirstMatingAt <= 0 {
  187. c.FirstMatingAt = matingAt
  188. }
  189. if !isReMating {
  190. c.MatingTimes += 1
  191. c.AllMatingTimes += 1
  192. }
  193. if c.Lact == 0 {
  194. c.CowType = pasturePb.CowType_Reserve_Calf
  195. }
  196. }
  197. // EstrusUpdate 发情更新
  198. func (c *Cow) EstrusUpdate(estrusAt int64) {
  199. c.LastEstrusAt = estrusAt
  200. }
  201. // EventDryMilkUpdate 干奶更新
  202. func (c *Cow) EventDryMilkUpdate(dryMilkAt int64, pen *Pen) {
  203. c.LastDryMilkAt = dryMilkAt
  204. c.MilkKind = pasturePb.CowMilk_Dry_Milk
  205. c.PenId = pen.Id
  206. c.PenName = pen.Name
  207. }
  208. // ForbiddenMatingUpdate 禁配更新
  209. func (c *Cow) ForbiddenMatingUpdate(forbiddenMatingAt int64) {
  210. c.IsForbiddenMating = pasturePb.IsShow_Ok
  211. c.LastForbiddenMatingAt = forbiddenMatingAt
  212. c.BreedStatus = pasturePb.BreedStatus_No_Mating
  213. }
  214. // UnForbiddenMatingUpdate 解禁配更新
  215. func (c *Cow) UnForbiddenMatingUpdate() {
  216. c.IsForbiddenMating = pasturePb.IsShow_No
  217. c.LastForbiddenMatingAt = 0
  218. c.BreedStatus = pasturePb.BreedStatus_UnBreed
  219. }
  220. // GetAvgDailyWeight 牛只平均日增重
  221. func (c *Cow) GetAvgDailyWeight() float32 {
  222. if c.AdmissionAge <= 0 {
  223. c.AdmissionAge = c.GetAdmissionAge()
  224. }
  225. if c.AdmissionAge <= 0 {
  226. return 0
  227. }
  228. return float32(c.CurrentWeight-c.AdmissionWeight) / 1000 / float32(c.AdmissionAge)
  229. }
  230. // GetDayAge 日龄
  231. func (c *Cow) GetDayAge() int32 {
  232. if c.BirthAt <= 0 {
  233. return 0
  234. }
  235. return int32(math.Floor(float64(time.Now().Local().Unix()-c.BirthAt) / 86400))
  236. }
  237. // GetEventDayAge 获取事件发生的日龄
  238. func (c *Cow) GetEventDayAge(eventAt int64) int32 {
  239. if c.BirthAt <= 0 {
  240. return 0
  241. }
  242. return int32(math.Floor(float64(eventAt-c.BirthAt) / 86400))
  243. }
  244. // GetCalvingAge 产后天数
  245. func (c *Cow) GetCalvingAge() int32 {
  246. if c.LastCalvingAt <= 0 {
  247. return 0
  248. }
  249. return int32(math.Floor(float64(time.Now().Local().Unix()-c.LastCalvingAt) / 86400))
  250. }
  251. // GetDaysPregnant 怀孕天数
  252. func (c *Cow) GetDaysPregnant() int32 {
  253. if c.BreedStatus == pasturePb.BreedStatus_Pregnant &&
  254. c.AdmissionStatus == pasturePb.AdmissionStatus_Admission &&
  255. c.IsPregnant == pasturePb.IsShow_Ok {
  256. return int32(math.Floor(float64(time.Now().Local().Unix()-c.LastMatingAt) / 86400))
  257. }
  258. return 0
  259. }
  260. // GetDaysPregnancy 牛只预产日期
  261. func (c *Cow) GetDaysPregnancy(pregnancyAgeValue int32) int32 {
  262. if c.BreedStatus == pasturePb.BreedStatus_Pregnant &&
  263. c.AdmissionStatus == pasturePb.AdmissionStatus_Admission &&
  264. c.IsPregnant == pasturePb.IsShow_Ok {
  265. return int32(math.Floor(float64(c.LastMatingAt + int64(pregnancyAgeValue)*86400)))
  266. }
  267. return 0
  268. }
  269. // GetLactationDays 泌乳天数
  270. func (c *Cow) GetLactationDays() int32 {
  271. if c.BreedStatus == pasturePb.BreedStatus_Calving && c.AdmissionStatus == pasturePb.AdmissionStatus_Admission {
  272. return int32(math.Floor(float64(time.Now().Local().Unix()-c.LastCalvingAt) / 86400))
  273. }
  274. return 0
  275. }
  276. // GetAdmissionAge 入场天数
  277. func (c *Cow) GetAdmissionAge() int32 {
  278. if c.AdmissionAt > 0 && c.AdmissionStatus == pasturePb.AdmissionStatus_Admission {
  279. return int32(math.Floor(float64(time.Now().Local().Unix()-c.AdmissionAt) / 86400))
  280. }
  281. return 0
  282. }
  283. func (c *Cow) GetEventAdmissionAge(eventAt int64) int32 {
  284. if eventAt > 0 && c.AdmissionStatus == pasturePb.AdmissionStatus_Admission {
  285. return int32(math.Floor(float64(eventAt-c.AdmissionAt) / 86400))
  286. }
  287. return 0
  288. }
  289. // GetAverageDailyWeight 平均日增重(最后一次称重 - 入场体重)÷在群天数
  290. func (c *Cow) GetAverageDailyWeight() float64 {
  291. if c.AdmissionAge <= 0 {
  292. c.AdmissionAge = c.GetAdmissionAge()
  293. }
  294. if c.AdmissionAge <= 0 {
  295. return 0
  296. }
  297. if c.CurrentWeight-c.AdmissionWeight <= 0 {
  298. return 0
  299. }
  300. return float64(c.CurrentWeight-c.AdmissionWeight) / 1000 / float64(c.AdmissionAge)
  301. }
  302. // GetPreviousStageDailyWeight 上一个阶段日增重
  303. func (c *Cow) GetPreviousStageDailyWeight() float64 {
  304. if c.CurrentWeight-c.LastSecondWeight > 0 && c.LastWeightAt-c.LastSecondWeightAt > 0 {
  305. days := int32(math.Floor(float64(c.LastWeightAt-c.LastSecondWeightAt) / 86400))
  306. if days <= 0 {
  307. return float64(c.CurrentWeight - c.LastSecondWeight)
  308. }
  309. dayWeight := math.Round(1.0 * float64(c.CurrentWeight-c.LastSecondWeight) / float64(days))
  310. return dayWeight / 1000
  311. }
  312. return 0
  313. }
  314. // GetAbortionAge 流产天数
  315. func (c *Cow) GetAbortionAge() int32 {
  316. if c.LastAbortionAt > 0 && c.AdmissionStatus == pasturePb.AdmissionStatus_Admission {
  317. return int32(math.Floor(float64(time.Now().Local().Unix()-c.LastAbortionAt) / 86400))
  318. }
  319. return 0
  320. }
  321. // GetLactationAge 泌乳天数
  322. func (c *Cow) GetLactationAge() int32 {
  323. if c.LastCalvingAt <= 0 {
  324. return 0
  325. }
  326. if c.MilkKind == pasturePb.CowMilk_Lactation ||
  327. c.BreedStatus == pasturePb.BreedStatus_Calving ||
  328. c.BreedStatus == pasturePb.BreedStatus_Abort {
  329. return int32(math.Floor(float64(time.Now().Local().Unix()-c.LastCalvingAt) / 86400))
  330. }
  331. return c.LactationAge
  332. }
  333. // GetDryMilkAge 干奶天数
  334. func (c *Cow) GetDryMilkAge() int32 {
  335. if c.MilkKind == pasturePb.CowMilk_Dry_Milk {
  336. return int32(math.Floor(float64(time.Now().Local().Unix()-c.LastDryMilkAt) / 86400))
  337. }
  338. return c.DryMilkAge
  339. }
  340. func (c *Cow) GetMatingAge() int32 {
  341. if c.LastMatingAt <= 0 {
  342. return 0
  343. }
  344. return int32(math.Floor(float64(time.Now().Local().Unix()-c.LastMatingAt) / 86400))
  345. }
  346. type CowSlice []*Cow
  347. func (c CowSlice) ToPB(
  348. cowTypeMap map[pasturePb.CowType_Kind]string,
  349. breedStatusMap map[pasturePb.BreedStatus_Kind]string,
  350. cowKindMap map[pasturePb.CowKind_Kind]string,
  351. cowSourceMap map[pasturePb.CowSource_Kind]string,
  352. admissionStatusMap map[pasturePb.AdmissionStatus_Kind]string,
  353. healthStatusMap map[pasturePb.HealthStatus_Kind]string,
  354. purposeMap map[pasturePb.Purpose_Kind]string,
  355. pregnancyAge int32,
  356. ) []*pasturePb.CowDetails {
  357. res := make([]*pasturePb.CowDetails, len(c))
  358. for i, v := range c {
  359. sex := "公"
  360. if v.Sex == pasturePb.Genders_Female {
  361. sex = "母"
  362. }
  363. lastWeightAtFormat := ""
  364. if v.LastWeightAt > 0 {
  365. lastWeightAtFormat = time.Unix(v.LastWeightAt, 0).Local().Format(LayoutDate2)
  366. }
  367. isPregnantName := ""
  368. if v.IsPregnant == pasturePb.IsShow_Ok {
  369. isPregnantName = "已孕"
  370. } else {
  371. isPregnantName = "未孕"
  372. }
  373. admissionAtFormat := ""
  374. if v.AdmissionAt > 0 {
  375. admissionAtFormat = time.Unix(v.AdmissionAt, 0).Local().Format(LayoutDate2)
  376. }
  377. birthAtFormat := ""
  378. if v.BirthAt > 0 {
  379. birthAtFormat = time.Unix(v.BirthAt, 0).Local().Format(LayoutDate2)
  380. }
  381. weaningAtFormat := ""
  382. if v.WeaningAt > 0 {
  383. weaningAtFormat = time.Unix(v.WeaningAt, 0).Local().Format(LayoutDate2)
  384. }
  385. firstMatingAtFormat := ""
  386. if v.FirstMatingAt > 0 {
  387. firstMatingAtFormat = time.Unix(v.FirstMatingAt, 0).Local().Format(LayoutDate2)
  388. }
  389. lastMatingAtFormat := ""
  390. if v.LastMatingAt > 0 {
  391. lastMatingAtFormat = time.Unix(v.LastMatingAt, 0).Local().Format(LayoutDate2)
  392. }
  393. lastPregnantCheckAtFormat := ""
  394. if v.LastPregnantCheckAt > 0 {
  395. lastPregnantCheckAtFormat = time.Unix(v.LastPregnantCheckAt, 0).Local().Format(LayoutDate2)
  396. }
  397. lastCalvingAtFormat := ""
  398. if v.LastCalvingAt > 0 {
  399. lastCalvingAtFormat = time.Unix(v.LastCalvingAt, 0).Local().Format(LayoutDate2)
  400. }
  401. lastAbortionAtFormat := ""
  402. if v.LastAbortionAt > 0 {
  403. lastAbortionAtFormat = time.Unix(v.LastAbortionAt, 0).Local().Format(LayoutDate2)
  404. }
  405. lastSecondWeightAtFormat := ""
  406. if v.LastSecondWeightAt > 0 {
  407. lastSecondWeightAtFormat = time.Unix(v.LastSecondWeightAt, 0).Local().Format(LayoutDate2)
  408. }
  409. departureAtFormat := ""
  410. if v.DepartureAt > 0 {
  411. departureAtFormat = time.Unix(v.DepartureAt, 0).Local().Format(LayoutDate2)
  412. }
  413. lastForbiddenMatingAtFormat := ""
  414. if v.LastForbiddenMatingAt > 0 {
  415. lastForbiddenMatingAtFormat = time.Unix(v.LastForbiddenMatingAt, 0).Local().Format(LayoutDate2)
  416. }
  417. lastEstrusAtFormat := ""
  418. if v.LastEstrusAt > 0 {
  419. lastEstrusAtFormat = time.Unix(v.LastEstrusAt, 0).Local().Format(LayoutDate2)
  420. }
  421. cowTypeName := ""
  422. if cn, ok := cowTypeMap[v.CowType]; ok {
  423. cowTypeName = cn
  424. }
  425. breedStatusName := ""
  426. if bs, ok := breedStatusMap[v.BreedStatus]; ok {
  427. breedStatusName = bs
  428. }
  429. cowKindName := ""
  430. if ck, ok := cowKindMap[v.CowKind]; ok {
  431. cowKindName = ck
  432. }
  433. sourceName := ""
  434. if sn, ok := cowSourceMap[v.SourceKind]; ok {
  435. sourceName = sn
  436. }
  437. admissionStatusName := ""
  438. if as, ok := admissionStatusMap[v.AdmissionStatus]; ok {
  439. admissionStatusName = as
  440. }
  441. healthStatusName := ""
  442. if hs, ok := healthStatusMap[v.HealthStatus]; ok {
  443. healthStatusName = hs
  444. }
  445. pregnancyDate := ""
  446. if pregnancyAgeAt := v.GetDaysPregnancy(pregnancyAge); pregnancyAgeAt > 0 {
  447. pregnancyDate = time.Unix(int64(pregnancyAge), 0).Local().Format(LayoutDate2)
  448. }
  449. purposeName := ""
  450. if pn, ok := purposeMap[v.PurposeKind]; ok {
  451. purposeName = pn
  452. }
  453. pregnancyCheckTimes := "初检"
  454. if v.PregnancyCheckName == PregnantCheckForSecond {
  455. pregnancyCheckTimes = "复检"
  456. }
  457. res[i] = &pasturePb.CowDetails{
  458. CowId: int32(v.Id),
  459. Sex: sex,
  460. NeckRingNumber: v.NeckRingNumber,
  461. PenName: v.PenName,
  462. Lact: v.Lact,
  463. CowTypeName: cowTypeName,
  464. CowType: v.CowType,
  465. BreedStatusName: breedStatusName,
  466. BreedStatus: v.BreedStatus,
  467. CowKindName: cowKindName,
  468. EarNumber: v.EarNumber,
  469. BirthWeight: float32(v.BirthWeight) / 1000,
  470. CurrentWeight: float32(v.CurrentWeight) / 1000,
  471. CurrentHeight: int32(v.CurrentHeight),
  472. DayAge: v.DayAge,
  473. AdmissionAge: v.AdmissionAge,
  474. SourceName: sourceName,
  475. MotherNumber: v.MotherNumber,
  476. FatherNumber: v.FatherNumber,
  477. AdmissionStatusName: admissionStatusName,
  478. HealthStatusName: healthStatusName,
  479. IsPregnantName: isPregnantName,
  480. AdmissionAtFormat: admissionAtFormat,
  481. BirthAtFormat: birthAtFormat,
  482. WeaningAtFormat: weaningAtFormat,
  483. CalvingAge: v.GetCalvingAge(),
  484. AbortionAge: v.AbortionAge,
  485. MatingTimes: v.MatingTimes,
  486. AbortionTimes: v.AbortionTimes,
  487. FirstMatingAtFormat: firstMatingAtFormat,
  488. LastMatingAtFormat: lastMatingAtFormat,
  489. LastBullNumber: v.LastBullNumber,
  490. LastPregnantCheckAtFormat: lastPregnantCheckAtFormat,
  491. LastWeightAtFormat: lastWeightAtFormat,
  492. LastCalvingAtFormat: lastCalvingAtFormat,
  493. LastAbortionAtFormat: lastAbortionAtFormat,
  494. LastSecondWeight: float32(v.LastSecondWeight) / 1000,
  495. LastSecondWeightAtFormat: lastSecondWeightAtFormat,
  496. DepartureAtFormat: departureAtFormat,
  497. DeparturePrice: v.DeparturePrice,
  498. DepartureWeight: float32(v.DepartureAvgWeight / 1000),
  499. LastForbiddenMatingAtFormat: lastForbiddenMatingAtFormat,
  500. LastEstrusAtFormat: lastEstrusAtFormat,
  501. PregnancyDate: pregnancyDate,
  502. PregnancyCheckTimes: pregnancyCheckTimes,
  503. AvgDailyWeight: float32(v.GetAverageDailyWeight()),
  504. EleEarNumber: v.EleEarNumber,
  505. AdmissionPrice: v.AdmissionPrice,
  506. PurposeName: purposeName,
  507. BatchNumber: v.BatchNumber,
  508. AdmissionWeight: float32(v.AdmissionWeight / 1000),
  509. DepartureAvgWeight: float32(v.DepartureAvgWeight / 1000),
  510. WeaningWeight: float32(v.WeaningWeight / 1000),
  511. }
  512. }
  513. return res
  514. }