cow.go 20 KB

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