event_dry_milk.go 2.7 KB

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