event_cow_same_time.go 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. PastureId int64 `json:"pastureId"`
  9. CowId int64 `json:"cowId"`
  10. EarNumber string `json:"earNumber"`
  11. CowType pasturePb.CowType_Kind `json:"cowType"`
  12. PenId int32 `json:"penId"`
  13. PenName string `json:"penName"`
  14. Lact int32 `json:"lact"`
  15. SameTimeId int64 `json:"sameTimeId"`
  16. SameTimeName string `json:"sameTimeName"`
  17. SameTimeType pasturePb.SameTimeType_Kind `json:"sameTimeType"`
  18. PlanDay int64 `json:"planDay"`
  19. EndDay int64 `json:"endDay"`
  20. RealityDay int64 `json:"realityDay"`
  21. Status pasturePb.IsShow_Kind `json:"status"`
  22. DrugsId int64 `json:"drugsId"`
  23. Unit pasturePb.Unit_Kind `json:"unit"`
  24. Usage float32 `json:"usage"`
  25. Remarks string `json:"remarks"`
  26. OperationId int64 `json:"operationId"`
  27. OperationName string `json:"operationName"`
  28. MessageId int64 `json:"messageId"`
  29. MessageName string `json:"messageName"`
  30. CreatedAt int64 `json:"createdAt"`
  31. UpdatedAt int64 `json:"updatedAt"`
  32. }
  33. func (s *EventCowSameTime) TableName() string {
  34. return "event_cow_same_time"
  35. }
  36. func (s *EventCowSameTime) EventUpdate(drugs *Drugs, usage float32, realityAt int64, remarks string, currentUser, operationUser *SystemUser) {
  37. s.Status = pasturePb.IsShow_Ok
  38. s.DrugsId = drugs.Id
  39. s.Unit = drugs.Unit
  40. s.Usage = usage
  41. s.Remarks = remarks
  42. s.OperationId = operationUser.Id
  43. s.OperationName = operationUser.Name
  44. s.MessageId = currentUser.Id
  45. s.MessageName = currentUser.Name
  46. s.RealityDay = realityAt
  47. }
  48. func NewEventCowSameTime(pastureId int64, cow *Cow, planTime int64, sameTime *SameTime, sameTimeType pasturePb.SameTimeType_Kind) *EventCowSameTime {
  49. return &EventCowSameTime{
  50. PastureId: pastureId,
  51. CowId: cow.Id,
  52. EarNumber: cow.EarNumber,
  53. Lact: cow.Lact,
  54. CowType: cow.CowType,
  55. PenId: cow.PenId,
  56. SameTimeId: sameTime.Id,
  57. SameTimeName: sameTime.Name,
  58. SameTimeType: sameTimeType,
  59. Status: pasturePb.IsShow_No,
  60. PlanDay: planTime,
  61. EndDay: planTime,
  62. }
  63. }
  64. func NewEventCowSameTimeList(pastureId int64, cowList []*Cow, sameTime *SameTime, planTime int64, sameTimeType pasturePb.SameTimeType_Kind) []*EventCowSameTime {
  65. res := make([]*EventCowSameTime, len(cowList))
  66. for i, cow := range cowList {
  67. res[i] = NewEventCowSameTime(pastureId, cow, planTime, sameTime, sameTimeType)
  68. }
  69. return res
  70. }
  71. type SameTimeItemBody struct {
  72. Id int64 `json:"id"`
  73. CowId int64 `json:"cowId"`
  74. EarNumber string `json:"earNumber"`
  75. BreedStatus pasturePb.BreedStatus_Kind `json:"breedStatus"`
  76. BreedStatusName string `json:"breedStatusName"`
  77. CowType pasturePb.CowType_Kind `json:"cowType"`
  78. CowTypeName string `json:"cowTypeName"`
  79. PenId int32 `json:"penId"`
  80. PenName string `json:"penName"`
  81. Lact int32 `json:"lact"`
  82. CalvingAge int32 `json:"calvingAge"`
  83. AbortionAge int32 `json:"abortionAge"`
  84. DayAge int32 `json:"dayAge"`
  85. Status pasturePb.IsShow_Kind `json:"status"`
  86. SameTimeType pasturePb.SameTimeType_Kind `json:"sameTimeType"`
  87. LastCalvingAt int64 `json:"lastCalvingAt"`
  88. LastAbortionAt int64 `json:"lastAbortionAt"`
  89. MatingTimes int32 `json:"matingTimes"`
  90. SameTimeName string `json:"sameTimeName"`
  91. PlanDay int64 `json:"planDay"`
  92. }
  93. type SameTimeBodySlice []*SameTimeItemBody
  94. func (s SameTimeBodySlice) ToPB(
  95. breedStatusMap map[pasturePb.BreedStatus_Kind]string,
  96. sameTimeTypeMap map[pasturePb.SameTimeType_Kind]string,
  97. ) []*pasturePb.SameTimeItems {
  98. res := make([]*pasturePb.SameTimeItems, len(s))
  99. for i, v := range s {
  100. calvingAtFormat, abortionAtFormat, playDayAtFormat := "", "", ""
  101. if v.LastCalvingAt > 0 {
  102. calvingAtFormat = time.Unix(v.LastCalvingAt, 0).Local().Format(LayoutDate2)
  103. }
  104. if v.LastAbortionAt > 0 {
  105. abortionAtFormat = time.Unix(v.LastAbortionAt, 0).Local().Format(LayoutDate2)
  106. }
  107. if v.PlanDay > 0 {
  108. playDayAtFormat = time.Unix(v.PlanDay, 0).Local().Format(LayoutDate2)
  109. }
  110. breedStatusName := ""
  111. if bm, ok := breedStatusMap[v.BreedStatus]; ok {
  112. breedStatusName = bm
  113. }
  114. sameTimeTypeName := ""
  115. if sm, ok := sameTimeTypeMap[v.SameTimeType]; ok {
  116. sameTimeTypeName = sm
  117. }
  118. res[i] = &pasturePb.SameTimeItems{
  119. Id: int32(v.Id),
  120. CowId: int32(v.CowId),
  121. EarNumber: v.EarNumber,
  122. BreedStatus: v.BreedStatus,
  123. BreedStatusName: breedStatusName,
  124. PenName: v.PenName,
  125. PenId: v.PenId,
  126. Lact: v.Lact,
  127. CalvingAge: v.CalvingAge,
  128. AbortionAge: v.AbortionAge,
  129. DayAge: v.DayAge,
  130. Status: v.Status,
  131. SameTimeTypeName: sameTimeTypeName,
  132. SameTimeType: v.SameTimeType,
  133. CalvingAtFormat: calvingAtFormat,
  134. AbortionAtFormat: abortionAtFormat,
  135. MatingTimes: v.MatingTimes,
  136. SameTimeName: v.SameTimeName,
  137. PlanDay: playDayAtFormat,
  138. }
  139. }
  140. return res
  141. }
  142. type EventCowSameTimeSlice []*EventCowSameTime
  143. func (s EventCowSameTimeSlice) ToPB(sameTimeTypeMap map[pasturePb.SameTimeType_Kind]string) []*pasturePb.EventSameTime {
  144. res := make([]*pasturePb.EventSameTime, len(s))
  145. for i, v := range s {
  146. res[i] = &pasturePb.EventSameTime{
  147. CowId: int32(v.CowId),
  148. PenId: v.PenId,
  149. DrugsId: int32(v.DrugsId),
  150. Usage: v.Usage,
  151. Lact: v.Lact,
  152. SameTimeId: int32(v.SameTimeId),
  153. SameTimeType: v.SameTimeType,
  154. SameTimeTypeName: sameTimeTypeMap[v.SameTimeType],
  155. }
  156. }
  157. return res
  158. }