event_mating.go 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. package model
  2. import (
  3. "time"
  4. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  5. )
  6. type EventMating struct {
  7. Id int64 `json:"id"`
  8. CowId int64 `json:"cowId"`
  9. DayAge int64 `json:"dayAge"`
  10. Lact int8 `json:"lact"`
  11. CowType pasturePb.CowType_Kind `json:"cowType"`
  12. CowKind pasturePb.CowKind_Kind `json:"cowKind"`
  13. CalvingAge int32 `json:"calvingAge"`
  14. PlanDay int64 `json:"planDay"`
  15. EndDay int64 `json:"endDay"`
  16. CalvingAt int64 `json:"calvingAt"`
  17. RealityDay int64 `json:"realityDay"`
  18. Status pasturePb.IsShow_Kind `json:"status"`
  19. MatingNumber int64 `json:"matingNumber"`
  20. MatingResult pasturePb.MatingResult_Kind `json:"matingResult"`
  21. MatingResultAt int64 `json:"matingResultAt"`
  22. ExposeEstrusType pasturePb.ExposeEstrusType_Kind `json:"exposeEstrusType"`
  23. FrozenSemenNumber string `json:"frozenSemenNumber"`
  24. FrozenSemenCount int32 `json:"frozenSemenCount"`
  25. OperationId int64 `json:"operationId"`
  26. OperationName string `json:"operationName"`
  27. Remarks string `json:"remarks"`
  28. CreatedAt int64 `json:"createdAt"`
  29. UpdatedAt int64 `json:"updatedAt"`
  30. }
  31. func (e *EventMating) TableName() string {
  32. return "event_mating"
  33. }
  34. func NewEventMating(cow *Cow, planDay int64) *EventMating {
  35. return &EventMating{
  36. CowId: cow.Id,
  37. Lact: int8(cow.Lact),
  38. CowType: cow.CowType,
  39. CowKind: cow.CowKind,
  40. CalvingAt: cow.CalvingAt,
  41. PlanDay: planDay,
  42. EndDay: planDay,
  43. MatingResult: pasturePb.MatingResult_Invalid,
  44. ExposeEstrusType: pasturePb.ExposeEstrusType_Same_Time,
  45. Status: pasturePb.IsShow_No,
  46. }
  47. }
  48. func NewEventMatingList(cowList []*Cow, planDay int64) []*EventMating {
  49. var matingList []*EventMating
  50. for _, cow := range cowList {
  51. matingList = append(matingList, NewEventMating(cow, planDay))
  52. }
  53. return matingList
  54. }
  55. type EventMatingSlice []*EventMating
  56. func (e EventMatingSlice) ToPB(exposeEstrusTypeMap map[pasturePb.ExposeEstrusType_Kind]string) []*pasturePb.SearchMatingList {
  57. res := make([]*pasturePb.SearchMatingList, len(e))
  58. for i, v := range e {
  59. res[i] = &pasturePb.SearchMatingList{
  60. Id: int32(v.Id),
  61. CowId: int32(v.CowId),
  62. DayAge: int32(v.DayAge),
  63. Lact: int32(v.Lact),
  64. CalvingAge: v.CalvingAge,
  65. PlanDay: time.Unix(v.PlanDay, 0).Format(LayoutDate2),
  66. RealityDay: time.Unix(v.RealityDay, 0).Format(LayoutDate2),
  67. ExposeEstrusType: v.ExposeEstrusType,
  68. ExposeEstrusTypeName: exposeEstrusTypeMap[v.ExposeEstrusType],
  69. FrozenSemenNumber: v.FrozenSemenNumber,
  70. Remarks: v.Remarks,
  71. OperationId: int32(v.OperationId),
  72. OperationName: v.OperationName,
  73. CreatedAt: int32(v.CreatedAt),
  74. UpdatedAt: int32(v.UpdatedAt),
  75. }
  76. }
  77. return res
  78. }
  79. type CowMatingHeader struct {
  80. Id string `json:"id"`
  81. CowId string `json:"cowId"`
  82. PlanDay string `json:"planDay"`
  83. Lact string `json:"lact"`
  84. Status string `json:"status"`
  85. BreedStatusName string `json:"breedStatusName"`
  86. BreedStatus string `json:"breedStatus"`
  87. CowTypeName string `json:"cowTypeName"`
  88. PenName string `json:"penName"`
  89. DayAge string `json:"dayAge"`
  90. CalvingAge string `json:"calvingAge"`
  91. AbortionAge string `json:"abortionAge"`
  92. }
  93. type CowMatingBody struct {
  94. Id int64 `json:"id"`
  95. CowId int64 `json:"cowId"`
  96. BreedStatus pasturePb.BreedStatus_Kind `json:"breedStatus"`
  97. BreedStatusName string `json:"breedStatusName"`
  98. CowType pasturePb.CowType_Kind `json:"cowType"`
  99. CowTypeName string `json:"cowTypeName"`
  100. PenId int32 `json:"penId"`
  101. PenName string `json:"penName"`
  102. Lact int32 `json:"lact"`
  103. CalvingAge int32 `json:"calvingAge"`
  104. AbortionAge int32 `json:"abortionAge"`
  105. DayAge int32 `json:"dayAge"`
  106. Status pasturePb.IsShow_Kind `json:"status"`
  107. }
  108. type CowMatingBodySlice []*CowMatingBody
  109. func (s CowMatingBodySlice) ToPB(
  110. cowTypeMap map[pasturePb.CowType_Kind]string,
  111. breedStatusMap map[pasturePb.BreedStatus_Kind]string,
  112. penMap map[int32]*Pen,
  113. ) []*CowMatingBody {
  114. res := make([]*CowMatingBody, len(s))
  115. for i, v := range s {
  116. res[i] = &CowMatingBody{
  117. Id: v.Id,
  118. CowId: v.CowId,
  119. CowType: v.CowType,
  120. CowTypeName: cowTypeMap[v.CowType],
  121. BreedStatus: v.BreedStatus,
  122. BreedStatusName: breedStatusMap[v.BreedStatus],
  123. PenName: penMap[v.PenId].Name,
  124. PenId: v.PenId,
  125. Lact: v.Lact,
  126. CalvingAge: v.CalvingAge,
  127. AbortionAge: v.AbortionAge,
  128. DayAge: v.DayAge,
  129. Status: v.Status,
  130. }
  131. }
  132. return res
  133. }
  134. type MatingTimelyChart struct {
  135. CalvingAge int32 `json:"calvingAge"`
  136. RealityDay string `json:"realityDay"`
  137. LactGroup string `json:"lactGroup"`
  138. }
  139. func (e EventMatingSlice) ToPB2() []*pasturePb.CowList {
  140. res := make([]*pasturePb.CowList, len(e))
  141. for i, v := range e {
  142. res[i] = &pasturePb.CowList{
  143. CowId: int32(v.CowId),
  144. DayAge: int32(v.DayAge),
  145. CalvingAge: v.CalvingAge,
  146. MatingAtFormat: time.Unix(v.RealityDay, 0).Format(LayoutDate2),
  147. CalvingAtFormat: time.Unix(v.CalvingAt, 0).Format(LayoutDate2),
  148. }
  149. }
  150. return res
  151. }
  152. type MatingTimelyResponse struct {
  153. Code int32 `json:"code"`
  154. Message string `json:"message"`
  155. Data *MatingTimelyData `json:"data"`
  156. }
  157. type MatingTimelyData struct {
  158. CowList []*pasturePb.CowList `json:"cowList"`
  159. Chart *CowMatingChart `json:"chart"`
  160. }
  161. type CowMatingChart struct {
  162. Lact0 [][]string `json:"lact0"`
  163. Lact1 [][]string `json:"lact1"`
  164. Lact2 [][]string `json:"lact2"`
  165. Lact3 [][]string `json:"lact3"`
  166. }