event_dry_milk.go 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package model
  2. import (
  3. "kpt-pasture/util"
  4. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  5. )
  6. type EventDryMilk 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. Lact int32 `json:"lact"`
  13. PenId int32 `json:"penId"`
  14. PenName string `json:"penName"`
  15. PlanDay int64 `json:"planDay"`
  16. RealityDay int64 `json:"realityDay"`
  17. EndDay int64 `json:"endDay"`
  18. Status pasturePb.IsShow_Kind `json:"status"`
  19. Remarks string `json:"remarks"`
  20. OperationId int64 `json:"operationId"`
  21. OperationName string `json:"operationName"`
  22. MessageId int64 `json:"messageId"`
  23. MessageName string `json:"messageName"`
  24. CreatedAt int64 `json:"createdAt"`
  25. UpdatedAt int64 `json:"updatedAt"`
  26. }
  27. func (e *EventDryMilk) TableName() string {
  28. return "event_dry_milk"
  29. }
  30. func (e *EventDryMilk) EventDryMilkUpdate(cow *Cow, dryMilkAt int64, pen *Pen, operation, message *SystemUser, remarks string) {
  31. e.Lact = cow.Lact
  32. e.RealityDay = dryMilkAt
  33. e.Remarks = remarks
  34. e.Status = pasturePb.IsShow_Ok
  35. e.OperationId = operation.Id
  36. e.OperationName = operation.Name
  37. e.MessageId = message.Id
  38. e.MessageName = message.Name
  39. e.PenId = pen.Id
  40. e.PenName = pen.Name
  41. e.DayAge = cow.GetEventDayAge(dryMilkAt)
  42. }
  43. func NewEventDryMilk(pastureId int64, cow *Cow, startDay, endDay string) *EventDryMilk {
  44. return &EventDryMilk{
  45. PastureId: pastureId,
  46. CowId: cow.Id,
  47. EarNumber: cow.EarNumber,
  48. Lact: cow.Lact,
  49. PlanDay: util.TimeParseLocalUnix(startDay),
  50. EndDay: util.TimeParseLocalUnix(endDay),
  51. Status: pasturePb.IsShow_No,
  52. }
  53. }
  54. func NewEventDryMilkList(pastureId int64, cowList []*Cow, startDay, endDay string) []*EventDryMilk {
  55. eventDryMilkList := make([]*EventDryMilk, 0)
  56. for _, cow := range cowList {
  57. eventDryMilkList = append(eventDryMilkList, NewEventDryMilk(pastureId, cow, startDay, endDay))
  58. }
  59. return eventDryMilkList
  60. }
  61. type EventDryMilkSlice []*EventDryMilk
  62. func (e EventDryMilkSlice) ToPB() []*pasturePb.EventMilkItem {
  63. res := make([]*pasturePb.EventMilkItem, len(e))
  64. for i, v := range e {
  65. res[i] = &pasturePb.EventMilkItem{
  66. Id: int32(v.Id),
  67. CowId: int32(v.CowId),
  68. EarNumber: v.EarNumber,
  69. Lact: v.Lact,
  70. PenName: v.PenName,
  71. DryMilkAt: int32(v.RealityDay),
  72. OperationName: v.OperationName,
  73. Remarks: v.Remarks,
  74. }
  75. }
  76. return res
  77. }