cow.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. package model
  2. import (
  3. "fmt"
  4. "kpt-pasture/util"
  5. "math"
  6. "time"
  7. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  8. )
  9. type Cow struct {
  10. Id int64 `json:"id"`
  11. PastureId int64 `json:"pastureId"` // 牧场id
  12. Sex pasturePb.Genders_Kind `json:"sex"` // 性别
  13. NeckRingNumber string `json:"neckRingNumber"` // 脖环号
  14. EarNumber string `json:"earNumber"` // 耳标号
  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. AdmissionAge int32 `json:"admissionAge"` // 入场日龄
  23. AbortionAge int32 `json:"abortionAge"` // 流产天数
  24. CowType pasturePb.CowType_Kind `json:"cowType"` // 牛只类型
  25. BreedStatus pasturePb.BreedStatus_Kind `json:"breedStatus"` // 繁殖状态
  26. CowKind pasturePb.CowKind_Kind `json:"cowKind"` // 牛只品种
  27. BirthWeight int64 `json:"birthWeight"` // 出生体重
  28. CurrentWeight int64 `json:"currentWeight"` // 当前体重
  29. AdmissionWeight int64 `json:"admissionWeight"` // 入场体重
  30. SourceId pasturePb.CowSource_Kind `json:"sourceId"` // 来源哪里
  31. FatherNumber string `json:"fatherNumber"` // 父号
  32. MotherNumber string `json:"motherNumber"` // 母号
  33. AdmissionStatus pasturePb.AdmissionStatus_Kind `json:"admissionStatus"` // 在场状态
  34. IsPregnant pasturePb.IsShow_Kind `json:"isPregnant"` // 是否怀孕
  35. HealthStatus pasturePb.HealthStatus_Kind `json:"healthStatus"` // 健康状态
  36. WeaningAt int64 `json:"weaningAt"` // 断奶时间
  37. BirthAt int64 `json:"birthAt"` // 出生时间
  38. AdmissionAt int64 `json:"admissionAt"` // 入场时间
  39. DepartureAt int64 `json:"departureAt"` // 离场时间
  40. FirstMatingAt int64 `json:"firstMatingAt"` // 首次配种时间
  41. MatingTimes int32 `json:"matingTimes"` // 配种次数
  42. AbortionTimes int32 `json:"abortionTimes"` // 流产次数
  43. WeeklyActive int32 `json:"weeklyActive"` // 每周活跃度
  44. LastEstrusAt int64 `json:"lastEstrusAt"` // 最后一次发情时间
  45. LastCalvingAt int64 `json:"lastCalvingAt"` // 最后一次产犊时间
  46. LastMatingAt int64 `json:"lastMatingAt"` // 最后一次配种时间
  47. LastBullNumber string `json:"lastBullNumber"` // 最后一次配种牛号
  48. LastPregnantCheckAt int64 `json:"lastPregnantCheckAt"` // 最后一次孕检时间
  49. LastDryMilkAt int64 `json:"lastDryMilkAt"` // 最近一次干奶日期
  50. LastSecondWeight int64 `json:"lastSecondWeight"` // 最后第二次称重
  51. LastSecondWeightAt int64 `json:"lastSecondWeightAt"` // 最后第二次称重时间
  52. LastAbortionAt int64 `json:"lastAbortionAt"` // 最近一次流产时间
  53. LastWeightAt int64 `json:"lastWeightAt"` // 最近一次称重时间
  54. CreatedAt int64 `json:"createdAt"`
  55. UpdatedAt int64 `json:"updatedAt"`
  56. }
  57. func (c *Cow) TableName() string {
  58. return "cow"
  59. }
  60. func (c *Cow) EventInfoUpdate() {
  61. c.DayAge = c.GetDayAge()
  62. c.CalvingAge = c.GetCalvingAge()
  63. c.PregnancyAge = c.GetDaysPregnant()
  64. c.AdmissionAge = c.GetAdmissionAge()
  65. c.AbortionAge = c.GetAbortionAge()
  66. if c.DayAge == 60 {
  67. c.CowType = pasturePb.CowType_Weaned_Calf
  68. }
  69. }
  70. // EventCalvingUpdate 产犊更新
  71. func (c *Cow) EventCalvingUpdate(calvingAt int64) {
  72. c.Lact += 1
  73. c.MatingTimes = 0
  74. c.PregnancyAge = 0
  75. c.AbortionTimes = 0
  76. c.BreedStatus = pasturePb.BreedStatus_Calving
  77. c.IsPregnant = pasturePb.IsShow_No
  78. c.LastCalvingAt = calvingAt
  79. c.CalvingAge = c.GetCalvingAge()
  80. c.CowType = pasturePb.CowType_Breeding_Calf
  81. }
  82. // EventWeaningUpdate 断奶更新
  83. func (c *Cow) EventWeaningUpdate(weaningAt int64, penId int32, currentWeight int64) {
  84. c.PenId = penId
  85. c.WeaningAt = weaningAt
  86. c.CurrentWeight = currentWeight
  87. c.LastWeightAt = weaningAt
  88. }
  89. // EventPregnantCheckUpdate 孕检更新
  90. func (c *Cow) EventPregnantCheckUpdate(breedStatus pasturePb.BreedStatus_Kind, pregnantCheckAt int64, isPregnant pasturePb.IsShow_Kind) {
  91. c.BreedStatus = breedStatus
  92. c.LastPregnantCheckAt = pregnantCheckAt
  93. c.IsPregnant = isPregnant
  94. }
  95. // EventAbortionUpdate 流产更新
  96. func (c *Cow) EventAbortionUpdate(abortionAt int64) {
  97. c.IsPregnant = pasturePb.IsShow_No
  98. c.LastAbortionAt = abortionAt
  99. c.BreedStatus = pasturePb.BreedStatus_Abort
  100. c.AbortionTimes += 1
  101. }
  102. // EventWeightUpdate 称重更新
  103. func (c *Cow) EventWeightUpdate(weight int64, weightAt int64) {
  104. c.LastSecondWeight = c.CurrentWeight
  105. c.LastSecondWeightAt = c.LastWeightAt
  106. c.LastWeightAt = weightAt
  107. c.CurrentWeight = weight
  108. }
  109. // EventHealthStatusUpdate 健康状态更新
  110. func (c *Cow) EventHealthStatusUpdate(healthStatus pasturePb.HealthStatus_Kind) {
  111. c.HealthStatus = healthStatus
  112. }
  113. // EventPenUpdate 更新栏舍
  114. func (c *Cow) EventPenUpdate(pen *Pen) {
  115. c.PenId = pen.Id
  116. c.PenName = pen.Name
  117. }
  118. // EventEarNumberUpdate 更新耳标号
  119. func (c *Cow) EventEarNumberUpdate(newEarNumber string) {
  120. c.EarOldNumber = c.EarNumber
  121. c.EarNumber = newEarNumber
  122. }
  123. // EventDepartureUpdate 更新牛只离场信息
  124. func (c *Cow) EventDepartureUpdate(departureAt int64, departureType pasturePb.DepartureType_Kind) {
  125. if departureType == pasturePb.DepartureType_Death {
  126. c.AdmissionStatus = pasturePb.AdmissionStatus_Die
  127. c.HealthStatus = pasturePb.HealthStatus_Dead
  128. }
  129. if departureType == pasturePb.DepartureType_Out {
  130. c.AdmissionStatus = pasturePb.AdmissionStatus_Out
  131. c.HealthStatus = pasturePb.HealthStatus_Out
  132. }
  133. c.DepartureAt = departureAt
  134. }
  135. // EventMatingUpdate 配种更新
  136. func (c *Cow) EventMatingUpdate(matingAt int64, bullNumber string, isReMating bool) {
  137. c.LastMatingAt = matingAt
  138. if c.FirstMatingAt <= 0 {
  139. c.FirstMatingAt = matingAt
  140. }
  141. c.LastBullNumber = bullNumber
  142. c.IsPregnant = pasturePb.IsShow_No
  143. c.BreedStatus = pasturePb.BreedStatus_Breeding
  144. if !isReMating {
  145. c.MatingTimes += 1
  146. }
  147. }
  148. type CowSlice []*Cow
  149. func (c CowSlice) ToPB(
  150. penMap map[int32]*Pen,
  151. cowTypeMap map[pasturePb.CowType_Kind]string,
  152. breedStatusMap map[pasturePb.BreedStatus_Kind]string,
  153. cowKindMap map[pasturePb.CowKind_Kind]string,
  154. cowSourceMap map[pasturePb.CowSource_Kind]string,
  155. admissionStatusMap map[pasturePb.AdmissionStatus_Kind]string,
  156. healthStatusMap map[pasturePb.HealthStatus_Kind]string,
  157. ) []*pasturePb.CowDetails {
  158. res := make([]*pasturePb.CowDetails, len(c))
  159. for i, v := range c {
  160. penName := ""
  161. if pen, ok := penMap[v.PenId]; ok {
  162. penName = pen.Name
  163. }
  164. sex := "公"
  165. if v.Sex == pasturePb.Genders_Female {
  166. sex = "母"
  167. }
  168. lastWeightAtFormat := ""
  169. if v.LastWeightAt > 0 {
  170. lastWeightAtFormat = time.Unix(v.LastWeightAt, 0).Format(LayoutDate2)
  171. }
  172. isPregnantName := ""
  173. if v.IsPregnant == pasturePb.IsShow_Ok {
  174. isPregnantName = "已孕"
  175. } else {
  176. isPregnantName = "未孕"
  177. }
  178. admissionAtFormat := ""
  179. if v.AdmissionAt > 0 {
  180. admissionAtFormat = time.Unix(v.AdmissionAt, 0).Format(LayoutDate2)
  181. }
  182. birthAtFormat := ""
  183. if v.BirthAt > 0 {
  184. birthAtFormat = time.Unix(v.BirthAt, 0).Format(LayoutDate2)
  185. }
  186. weaningAtFormat := ""
  187. if v.WeaningAt > 0 {
  188. weaningAtFormat = time.Unix(v.WeaningAt, 0).Format(LayoutDate2)
  189. }
  190. firstMatingAtFormat := ""
  191. if v.FirstMatingAt > 0 {
  192. firstMatingAtFormat = time.Unix(v.FirstMatingAt, 0).Format(LayoutDate2)
  193. }
  194. lastMatingAtFormat := ""
  195. if v.LastMatingAt > 0 {
  196. lastMatingAtFormat = time.Unix(v.LastMatingAt, 0).Format(LayoutDate2)
  197. }
  198. lastPregnantCheckAtFormat := ""
  199. if v.LastPregnantCheckAt > 0 {
  200. lastPregnantCheckAtFormat = time.Unix(v.LastPregnantCheckAt, 0).Format(LayoutDate2)
  201. }
  202. lastCalvingAtFormat := ""
  203. if v.LastCalvingAt > 0 {
  204. lastCalvingAtFormat = time.Unix(v.LastCalvingAt, 0).Format(LayoutDate2)
  205. }
  206. lastAbortionAtFormat := ""
  207. if v.LastAbortionAt > 0 {
  208. lastAbortionAtFormat = time.Unix(v.LastAbortionAt, 0).Format(LayoutDate2)
  209. }
  210. lastSecondWeightAtFormat := ""
  211. if v.LastSecondWeightAt > 0 {
  212. lastSecondWeightAtFormat = time.Unix(v.LastSecondWeightAt, 0).Format(LayoutDate2)
  213. }
  214. res[i] = &pasturePb.CowDetails{
  215. CowId: int32(v.Id),
  216. Sex: sex,
  217. NeckRingNumber: v.NeckRingNumber,
  218. PenName: penName,
  219. Lact: v.Lact,
  220. CowTypeName: cowTypeMap[v.CowType],
  221. BreedStatusName: breedStatusMap[v.BreedStatus],
  222. CowKindName: cowKindMap[v.CowKind],
  223. EarNumber: v.EarNumber,
  224. BirthWeight: float32(v.BirthWeight) / 1000,
  225. CurrentWeight: float32(v.CurrentWeight) / 1000,
  226. DayAge: v.DayAge,
  227. SourceName: cowSourceMap[v.SourceId],
  228. MotherNumber: v.MotherNumber,
  229. FatherNumber: v.FatherNumber,
  230. AdmissionStatusName: admissionStatusMap[v.AdmissionStatus],
  231. HealthStatusName: healthStatusMap[v.HealthStatus],
  232. IsPregnantName: isPregnantName,
  233. AdmissionAtFormat: admissionAtFormat,
  234. BirthAtFormat: birthAtFormat,
  235. WeaningAtFormat: weaningAtFormat,
  236. CalvingAge: v.GetCalvingAge(),
  237. AbortionAge: v.AbortionAge,
  238. MatingTimes: v.MatingTimes,
  239. FirstMatingAtFormat: firstMatingAtFormat,
  240. LastMatingAtFormat: lastMatingAtFormat,
  241. LastBullNumber: v.LastBullNumber,
  242. LastPregnantCheckAtFormat: lastPregnantCheckAtFormat,
  243. LastWeightAtFormat: lastWeightAtFormat,
  244. LastCalvingAtFormat: lastCalvingAtFormat,
  245. LastAbortionAtFormat: lastAbortionAtFormat,
  246. LastSecondWeight: float32(v.LastSecondWeight) / 1000,
  247. LastSecondWeightAtFormat: lastSecondWeightAtFormat,
  248. }
  249. }
  250. return res
  251. }
  252. func (c CowSlice) ToPB2(penMap map[int32]*Pen, penWeightSlice PenWeightSlice) []*pasturePb.CowList {
  253. res := make([]*pasturePb.CowList, len(c))
  254. for i, v := range c {
  255. penName := ""
  256. if pen, ok := penMap[v.PenId]; ok {
  257. penName = pen.Name
  258. }
  259. penWeight := penWeightSlice.GetPenWeight(v.PenId)
  260. lastWeightDay := util.Ceil(float64(v.LastWeightAt-v.LastSecondWeightAt) / 86400)
  261. penAvgWeight := float32(0)
  262. previousStageDailyWeight := float32(0)
  263. cowPenAvgWeightDiffValue := float32(0)
  264. if penWeight != nil {
  265. penAvgWeight = float32(penWeight.AvgWeight) / 1000
  266. cowPenAvgWeightDiffValue = float32(v.CurrentWeight-int64(penWeight.AvgWeight)) / 1000
  267. if lastWeightDay > 0 {
  268. previousStageDailyWeight = float32(v.CurrentWeight-v.LastSecondWeight) / 1000 / float32(lastWeightDay)
  269. }
  270. }
  271. res[i] = &pasturePb.CowList{
  272. CowId: int32(v.Id),
  273. DayAge: v.DayAge,
  274. AverageDailyWeightGain: float32(v.GetAverageDailyWeight()),
  275. EarNumber: v.EarNumber,
  276. PenName: penName,
  277. BirthAt: int32(v.BirthAt),
  278. BirthWeight: float32(v.BirthWeight) / 1000,
  279. CurrentWeight: float32(v.CurrentWeight) / 1000,
  280. LastWeightAt: int32(v.LastWeightAt),
  281. AdmissionAge: v.AdmissionAge,
  282. AdmissionWeight: float32(v.AbortionAge) / 1000,
  283. PreviousStageDailyWeight: previousStageDailyWeight,
  284. PenAvgWeight: penAvgWeight,
  285. CowPenAvgWeightDiffValue: cowPenAvgWeightDiffValue,
  286. }
  287. }
  288. return res
  289. }
  290. // NewEnterCow 入场新增牛只
  291. func NewEnterCow(pastureId int64, req *pasturePb.EventEnterRequest, penMap map[int32]*Pen) *Cow {
  292. var isPregnant = pasturePb.IsShow_No
  293. if req.BreedStatus == pasturePb.BreedStatus_Pregnant {
  294. isPregnant = pasturePb.IsShow_Ok
  295. }
  296. admissionAt := int64(0)
  297. switch req.CowSource {
  298. case pasturePb.CowSource_Calving:
  299. admissionAt = int64(req.BirthAt)
  300. case pasturePb.CowSource_Transfer_In:
  301. admissionAt = int64(req.EnterAt)
  302. case pasturePb.CowSource_Buy:
  303. admissionAt = int64(req.EnterAt)
  304. }
  305. return &Cow{
  306. PastureId: pastureId,
  307. Sex: req.Sex,
  308. EarNumber: req.EarNumber,
  309. PenId: req.PenId,
  310. PenName: penMap[req.PenId].Name,
  311. Lact: req.Lact,
  312. CowType: req.CowType,
  313. BreedStatus: req.BreedStatus,
  314. CowKind: req.CowKind,
  315. SourceId: req.CowSource,
  316. FatherNumber: req.FatherNumber,
  317. MotherNumber: req.MotherNumber,
  318. AdmissionStatus: pasturePb.AdmissionStatus_Admission,
  319. HealthStatus: pasturePb.HealthStatus_Health,
  320. IsPregnant: isPregnant,
  321. WeaningAt: int64(req.WeaningAt),
  322. BirthAt: int64(req.BirthAt),
  323. AdmissionWeight: int64(req.Weight * 1000),
  324. FirstMatingAt: int64(req.MatingAt),
  325. LastMatingAt: int64(req.MatingAt),
  326. LastPregnantCheckAt: int64(req.PregnancyCheckAt),
  327. AdmissionAt: admissionAt,
  328. BirthWeight: int64(req.Weight * 1000),
  329. LastWeightAt: int64(req.EstrusAt),
  330. CurrentWeight: int64(req.Weight * 1000),
  331. }
  332. }
  333. // NewCalfCow 产犊新增
  334. func NewCalfCow(motherNumber, fatherNumber string, calf *CalvingCalf) *Cow {
  335. return &Cow{
  336. PastureId: calf.PastureId,
  337. Sex: calf.Sex,
  338. EarNumber: calf.EarNumber,
  339. PenId: calf.PenId,
  340. PenName: calf.PenName,
  341. CowType: pasturePb.CowType_Lactating_Calf, // 哺乳犊牛
  342. BreedStatus: pasturePb.BreedStatus_UnBreed, // 未配
  343. CowKind: calf.CowKind, // 牛只品种
  344. BirthWeight: calf.BirthWeight,
  345. BirthAt: calf.BirthAt,
  346. SourceId: pasturePb.CowSource_Calving, // 产犊方式
  347. FatherNumber: fatherNumber,
  348. MotherNumber: motherNumber,
  349. AdmissionStatus: pasturePb.AdmissionStatus_Admission,
  350. IsPregnant: pasturePb.IsShow_No,
  351. AdmissionAt: calf.BirthAt,
  352. }
  353. }
  354. type BarCowStruct struct {
  355. Number int32 `json:"number"`
  356. TypeId pasturePb.CowType_Kind `json:"type_id"`
  357. }
  358. // BarCowStructSlice 首页牛群结构
  359. type BarCowStructSlice []*BarCowStruct
  360. func (b BarCowStructSlice) ToPB(cowTypeMap map[pasturePb.CowType_Kind]string, count int32) []*pasturePb.BarCowStruct {
  361. var pb []*pasturePb.BarCowStruct
  362. for _, v := range b {
  363. name := fmt.Sprintf("%s", cowTypeMap[v.TypeId])
  364. pb = append(pb, &pasturePb.BarCowStruct{Name: name, Value: v.Number})
  365. }
  366. return pb
  367. }
  368. // GetDayAge 日龄
  369. func (c *Cow) GetDayAge() int32 {
  370. if c.BirthAt <= 0 {
  371. return 0
  372. }
  373. return int32(math.Floor(float64(time.Now().Unix()-c.BirthAt) / 86400))
  374. }
  375. // GetCalvingAge 产后天数
  376. func (c *Cow) GetCalvingAge() int32 {
  377. if c.LastCalvingAt <= 0 {
  378. return 0
  379. }
  380. return int32(math.Floor(float64(time.Now().Unix()-c.LastCalvingAt) / 86400))
  381. }
  382. // GetDaysPregnant 怀孕天数
  383. func (c *Cow) GetDaysPregnant() int32 {
  384. if c.BreedStatus == pasturePb.BreedStatus_Pregnant &&
  385. c.AdmissionStatus == pasturePb.AdmissionStatus_Admission &&
  386. c.IsPregnant == pasturePb.IsShow_Ok {
  387. return int32(math.Floor(float64(time.Now().Unix()-c.LastMatingAt) / 86400))
  388. }
  389. return 0
  390. }
  391. // GetLactationDays 泌乳天数
  392. func (c *Cow) GetLactationDays() int32 {
  393. if c.BreedStatus == pasturePb.BreedStatus_Calving && c.AdmissionStatus == pasturePb.AdmissionStatus_Admission {
  394. return int32(math.Floor(float64(time.Now().Unix()-c.LastCalvingAt) / 86400))
  395. }
  396. return 0
  397. }
  398. // GetAdmissionAge 入场天数
  399. func (c *Cow) GetAdmissionAge() int32 {
  400. if c.AdmissionAt > 0 && c.AdmissionStatus == pasturePb.AdmissionStatus_Admission {
  401. return int32(math.Floor(float64(time.Now().Unix()-c.AdmissionAt) / 86400))
  402. }
  403. return 0
  404. }
  405. // GetAverageDailyWeight 平均日增重 (最后一次称重 - 第一次称重 ) ÷ 在群天数
  406. func (c *Cow) GetAverageDailyWeight() float64 {
  407. if c.CurrentWeight <= 0 || c.AdmissionAge <= 0 {
  408. return 0
  409. }
  410. firstWeight := c.BirthWeight
  411. if c.SourceId == pasturePb.CowSource_Buy {
  412. firstWeight = c.AdmissionWeight
  413. }
  414. res := math.Round(1.0 * float64(c.CurrentWeight-firstWeight) / float64(c.AdmissionAge))
  415. return res / 1000
  416. }
  417. // GetPreviousStageDailyWeight 上一个阶段日增重
  418. func (c *Cow) GetPreviousStageDailyWeight() float64 {
  419. if c.CurrentWeight-c.LastSecondWeight > 0 && c.LastWeightAt-c.LastSecondWeightAt > 0 {
  420. days := int32(math.Floor(float64(c.LastWeightAt-c.LastSecondWeightAt) / 86400))
  421. if days <= 0 {
  422. return float64(c.CurrentWeight - c.LastSecondWeight)
  423. }
  424. dayWeight := math.Round(1.0 * float64(c.CurrentWeight-c.LastSecondWeight) / float64(days))
  425. return dayWeight / 1000
  426. }
  427. return 0
  428. }
  429. // GetAbortionAge 流产天数
  430. func (c *Cow) GetAbortionAge() int32 {
  431. if c.LastAbortionAt > 0 && c.AdmissionStatus == pasturePb.AdmissionStatus_Admission {
  432. return int32(math.Floor(float64(time.Now().Unix()-c.LastAbortionAt) / 86400))
  433. }
  434. return 0
  435. }
  436. type CowWeightRange struct {
  437. WeightRange string `json:"weight_range"`
  438. Count int32 `json:"count"`
  439. }
  440. func (c CowSlice) WeightRangeToPB(penMap map[int32]*Pen) []*pasturePb.CowList {
  441. res := make([]*pasturePb.CowList, len(c))
  442. for i, v := range c {
  443. penName := ""
  444. if pen, ok := penMap[v.PenId]; ok {
  445. penName = pen.Name
  446. }
  447. res[i] = &pasturePb.CowList{
  448. CowId: int32(v.Id),
  449. DayAge: v.DayAge,
  450. AverageDailyWeightGain: float32(v.GetAverageDailyWeight()),
  451. PreviousStageDailyWeight: float32(v.GetPreviousStageDailyWeight()),
  452. EarNumber: v.EarNumber,
  453. PenName: penName,
  454. BirthAt: int32(v.BirthAt),
  455. BirthWeight: float32(v.BirthWeight) / 1000,
  456. CurrentWeight: float32(v.CurrentWeight) / 1000,
  457. LastWeightAt: int32(v.LastWeightAt),
  458. }
  459. }
  460. return res
  461. }
  462. // CowBehaviorCurveResponse 脖环行为数据
  463. type CowBehaviorCurveResponse struct {
  464. Code int32 `json:"code"`
  465. Msg string `json:"msg"`
  466. Data *CowBehaviorCurveData `json:"data"`
  467. }
  468. type CowBehaviorCurveData struct {
  469. OriginalDateList []int32 `json:"originalDateList"` // 原始行为数据
  470. ChangeDateList []int32 `json:"changeDateList"` // 变化数据
  471. SumDateList []int32 `json:"sumDateList"` // 累计24小时数据
  472. DateTimeList []string `json:"dateTimeList"` // 时间数据
  473. EstrusList map[pasturePb.EstrusLevel_Kind][]string `json:"estrusList"` // 发情预警
  474. EventList map[string][]string `json:"eventList"` // 事件数据
  475. EventMap map[pasturePb.EventType_Kind]string `json:"eventMap"` // 所有事件
  476. }