event_cow_same_time.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. package model
  2. import (
  3. "time"
  4. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  5. )
  6. type EventCowSameTime struct {
  7. Id int64 `json:"id"`
  8. CowId int64 `json:"cowId"`
  9. CowType pasturePb.CowType_Kind `json:"cowType"`
  10. PenId int32 `json:"penId"`
  11. PenName string `json:"penName"`
  12. Lact int32 `json:"lact"`
  13. SameTimeId int64 `json:"sameTimeId"`
  14. SameTimeName string `json:"sameTimeName"`
  15. SameTimeType pasturePb.SameTimeType_Kind `json:"sameTimeType"`
  16. PlanDay int64 `json:"planDay"`
  17. EndDay int64 `json:"endDay"`
  18. RealityDay int64 `json:"realityDay"`
  19. Status pasturePb.IsShow_Kind `json:"status"`
  20. DrugsId int64 `json:"drugsId"`
  21. Unit pasturePb.Unit_Kind `json:"unit"`
  22. Usage int32 `json:"usage"`
  23. OperationId int64 `json:"operationId"`
  24. OperationName string `json:"operationName"`
  25. CreatedAt int64 `json:"createdAt"`
  26. UpdatedAt int64 `json:"updatedAt"`
  27. }
  28. func (s *EventCowSameTime) TableName() string {
  29. return "event_cow_same_time"
  30. }
  31. func NewEventCowSameTime(cow *Cow, planTime int64, sameTime *SameTime, sameTimeType pasturePb.SameTimeType_Kind) *EventCowSameTime {
  32. return &EventCowSameTime{
  33. CowId: cow.Id,
  34. Lact: cow.Lact,
  35. CowType: cow.CowType,
  36. PenId: cow.PenId,
  37. SameTimeId: sameTime.Id,
  38. SameTimeName: sameTime.Name,
  39. SameTimeType: sameTimeType,
  40. Status: pasturePb.IsShow_No,
  41. PlanDay: planTime,
  42. EndDay: planTime,
  43. }
  44. }
  45. func NewEventCowSameTimeList(cowList []*Cow, sameTime *SameTime, planTime int64, sameTimeType pasturePb.SameTimeType_Kind) []*EventCowSameTime {
  46. res := make([]*EventCowSameTime, len(cowList))
  47. for i, cow := range cowList {
  48. res[i] = NewEventCowSameTime(cow, planTime, sameTime, sameTimeType)
  49. }
  50. return res
  51. }
  52. type SameTimeItemBody struct {
  53. Id int64 `json:"id"`
  54. CowId int64 `json:"cowId"`
  55. BreedStatus pasturePb.BreedStatus_Kind `json:"breedStatus"`
  56. BreedStatusName string `json:"breedStatusName"`
  57. CowType pasturePb.CowType_Kind `json:"cowType"`
  58. CowTypeName string `json:"cowTypeName"`
  59. PenId int32 `json:"penId"`
  60. PenName string `json:"penName"`
  61. Lact int32 `json:"lact"`
  62. CalvingAge int32 `json:"calvingAge"`
  63. AbortionAge int32 `json:"abortionAge"`
  64. DayAge int32 `json:"dayAge"`
  65. Status pasturePb.IsShow_Kind `json:"status"`
  66. SameTimeType pasturePb.SameTimeType_Kind `json:"sameTimeType"`
  67. LastCalvingAt int64 `json:"lastCalvingAt"`
  68. LastAbortionAt int64 `json:"lastAbortionAt"`
  69. MatingTimes int32 `json:"matingTimes"`
  70. SameTimeName string `json:"sameTimeName"`
  71. }
  72. type SameTimeBodySlice []*SameTimeItemBody
  73. func (s SameTimeBodySlice) ToPB(
  74. breedStatusMap map[pasturePb.BreedStatus_Kind]string,
  75. penMap map[int32]*Pen,
  76. sameTimeTypeMap map[pasturePb.SameTimeType_Kind]string,
  77. ) []*pasturePb.SameTimeItems {
  78. res := make([]*pasturePb.SameTimeItems, len(s))
  79. for i, v := range s {
  80. penName, calvingAtFormat, abortionAtFormat := "", "", ""
  81. if pen, ok := penMap[v.PenId]; ok {
  82. penName = pen.Name
  83. }
  84. if v.LastCalvingAt > 0 {
  85. calvingAtFormat = time.Unix(v.LastCalvingAt, 0).Format(LayoutDate2)
  86. }
  87. if v.LastAbortionAt > 0 {
  88. abortionAtFormat = time.Unix(v.LastAbortionAt, 0).Format(LayoutDate2)
  89. }
  90. res[i] = &pasturePb.SameTimeItems{
  91. Id: int32(v.Id),
  92. CowId: int32(v.CowId),
  93. BreedStatus: v.BreedStatus,
  94. BreedStatusName: breedStatusMap[v.BreedStatus],
  95. PenName: penName,
  96. PenId: v.PenId,
  97. Lact: v.Lact,
  98. CalvingAge: v.CalvingAge,
  99. AbortionAge: v.AbortionAge,
  100. DayAge: v.DayAge,
  101. Status: v.Status,
  102. SameTimeTypeName: sameTimeTypeMap[v.SameTimeType],
  103. CalvingAtFormat: calvingAtFormat,
  104. AbortionAtFormat: abortionAtFormat,
  105. MatingTimes: v.MatingTimes,
  106. SameTimeName: v.SameTimeName,
  107. }
  108. }
  109. return res
  110. }
  111. type EventCowSameTimeSlice []*EventCowSameTime
  112. func (s EventCowSameTimeSlice) ToPB(sameTimeTypeMap map[pasturePb.SameTimeType_Kind]string) []*pasturePb.EventSameTime {
  113. res := make([]*pasturePb.EventSameTime, len(s))
  114. for i, v := range s {
  115. res[i] = &pasturePb.EventSameTime{
  116. CowId: int32(v.CowId),
  117. PenId: v.PenId,
  118. DrugsId: int32(v.DrugsId),
  119. Usage: v.Usage,
  120. Lact: v.Lact,
  121. SameTimeId: int32(v.SameTimeId),
  122. SameTimeType: v.SameTimeType,
  123. SameTimeTypeName: sameTimeTypeMap[v.SameTimeType],
  124. }
  125. }
  126. return res
  127. }