event_weight.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package model
  2. import (
  3. "time"
  4. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  5. )
  6. type EventWeight struct {
  7. ID int64 `json:"id"`
  8. PastureId int64 `json:"pastureId"`
  9. CowId int64 `json:"cowId"`
  10. EarNumber string `json:"earNumber"`
  11. DayAge int32 `json:"dayAge"`
  12. LactationDay int64 `json:"lactationDay"`
  13. PenId int32 `json:"penId"`
  14. Lact int32 `json:"lact"`
  15. Weight int32 `json:"weight"`
  16. Height int32 `json:"height"`
  17. WeightAt int64 `json:"weightAt"`
  18. Remarks string `json:"remarks"`
  19. OperationId int32 `json:"operationId"`
  20. OperationName string `json:"operationName"`
  21. MessageId int64 `json:"messageId"`
  22. MessageName string `json:"messageName"`
  23. CreatedAt int64 `json:"created_at"`
  24. UpdatedAt int64 `json:"updated_at"`
  25. }
  26. func (c *EventWeight) TableName() string {
  27. return "event_weight"
  28. }
  29. func NewEventWeight(cow *Cow, currentUser *SystemUser, weight, height int32, req *pasturePb.EventWeight) *EventWeight {
  30. return &EventWeight{
  31. PastureId: currentUser.PastureId,
  32. CowId: cow.Id,
  33. EarNumber: cow.EarNumber,
  34. Weight: weight,
  35. Height: height,
  36. Lact: cow.Lact,
  37. DayAge: cow.GetDayAge(),
  38. WeightAt: int64(req.WeightAt),
  39. Remarks: req.Remarks,
  40. MessageId: currentUser.Id,
  41. MessageName: currentUser.Name,
  42. OperationId: req.OperationId,
  43. OperationName: req.OperationName,
  44. }
  45. }
  46. type EventWeightSlice []*EventWeight
  47. func (e EventWeightSlice) ToPB() []*pasturePb.CowGrowthCurveData {
  48. res := make([]*pasturePb.CowGrowthCurveData, len(e))
  49. for i, v := range e {
  50. weightAtFormat := ""
  51. if v.WeightAt > 0 {
  52. weightAtFormat = time.Unix(v.WeightAt, 0).Format(LayoutTime)
  53. }
  54. res[i] = &pasturePb.CowGrowthCurveData{
  55. Weight: float32(v.Weight) / 1000,
  56. WeightAtFormat: weightAtFormat,
  57. AvgWeight: 0, // 平均体重
  58. DayAddWeight: 0, // 日增重
  59. AvgDayAddWeight: 0, // 平均日增重
  60. MonthAddWeight: 0, // 月增重
  61. }
  62. }
  63. }