event_item.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package model
  2. import (
  3. "kpt-pasture/util"
  4. "time"
  5. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  6. )
  7. type EventItem struct {
  8. Id int64 `json:"id"`
  9. CowId int64 `json:"cowId"`
  10. PenId int32 `json:"penId"`
  11. Lact int32 `json:"lact"`
  12. CalendarType pasturePb.CalendarType_Kind `json:"calendarType"`
  13. PlanDay int64 `json:"planDay"`
  14. EndDay int64 `json:"endDay"`
  15. RealityDay int64 `json:"realityDay"`
  16. IsFinish pasturePb.IsShow_Kind `json:"isFinish"`
  17. IsExpire pasturePb.IsShow_Kind `json:"isExpire"`
  18. OperationId int64 `json:"operationId"`
  19. OperationName string `json:"operationName"`
  20. Remarks string `json:"remarks"`
  21. CreatedAt int64 `json:"createdAt"`
  22. UpdatedAt int64 `json:"updatedAt"`
  23. }
  24. func (e *EventItem) TableName() string {
  25. return "event_item"
  26. }
  27. func NewEventItem(cow *Cow, calendarType pasturePb.CalendarType_Kind) *EventItem {
  28. return &EventItem{
  29. CowId: cow.Id,
  30. PenId: cow.PenId,
  31. Lact: cow.Lact,
  32. CalendarType: calendarType,
  33. PlanDay: util.TimeParseLocalUnix(time.Now().Format(LayoutDate2)),
  34. EndDay: util.TimeParseLocalEndUnix(time.Now().Format(LayoutDate2)),
  35. IsFinish: pasturePb.IsShow_Ok,
  36. }
  37. }
  38. func NewEventItemList(cowList []*Cow, calendarType pasturePb.CalendarType_Kind) []*EventItem {
  39. res := make([]*EventItem, len(cowList))
  40. for i, v := range cowList {
  41. res[i] = NewEventItem(v, calendarType)
  42. }
  43. return res
  44. }
  45. type EventItemSlice []*EventItem
  46. func (e EventItemSlice) ToPB(penMap map[int32]*Pen, calendarType map[pasturePb.CalendarType_Kind]string) []*pasturePb.CalendarToDoList {
  47. res := make([]*pasturePb.CalendarToDoList, len(e))
  48. for i, v := range e {
  49. penName := ""
  50. if pen, ok := penMap[v.PenId]; ok {
  51. penName = pen.Name
  52. }
  53. res[i] = &pasturePb.CalendarToDoList{
  54. Id: int32(v.Id),
  55. Lact: v.Lact,
  56. CalendarType: v.CalendarType,
  57. CalendarTypeName: calendarType[v.CalendarType],
  58. PlanDay: time.Unix(v.PlanDay, 0).Format(LayoutDate2),
  59. EndDay: time.Unix(v.EndDay, 0).Format(LayoutDate2),
  60. RealityDay: time.Unix(v.RealityDay, 0).Format(LayoutDate2),
  61. IsFinish: v.IsFinish,
  62. IsExpire: v.IsExpire,
  63. CowId: int32(v.CowId),
  64. PenName: penName,
  65. Remarks: v.Remarks,
  66. }
  67. }
  68. return res
  69. }