event_mating.go 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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 int32 `json:"dayAge"`
  10. Lact int32 `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. MessageId int64 `json:"messageId"`
  28. MessageName string `json:"messageName"`
  29. Remarks string `json:"remarks"`
  30. CreatedAt int64 `json:"createdAt"`
  31. UpdatedAt int64 `json:"updatedAt"`
  32. }
  33. func (e *EventMating) TableName() string {
  34. return "event_mating"
  35. }
  36. func NewEventMating(cow *Cow, planDay int64) *EventMating {
  37. return &EventMating{
  38. CowId: cow.Id,
  39. Lact: cow.Lact,
  40. CowType: cow.CowType,
  41. CowKind: cow.CowKind,
  42. CalvingAt: cow.CalvingAt,
  43. PlanDay: planDay,
  44. EndDay: planDay,
  45. MatingResult: pasturePb.MatingResult_Invalid,
  46. ExposeEstrusType: pasturePb.ExposeEstrusType_Same_Time,
  47. Status: pasturePb.IsShow_No,
  48. }
  49. }
  50. // NewEventMating2 自然发情的牛只
  51. func NewEventMating2(cow *Cow, req *pasturePb.EventMating) *EventMating {
  52. return &EventMating{
  53. CowId: cow.Id,
  54. Lact: cow.Lact,
  55. DayAge: cow.GetDayAge(),
  56. CowType: cow.CowType,
  57. CowKind: cow.CowKind,
  58. CalvingAt: cow.CalvingAt,
  59. PlanDay: int64(req.MatingAt),
  60. RealityDay: int64(req.MatingAt),
  61. EndDay: int64(req.MatingAt),
  62. MatingResult: pasturePb.MatingResult_Invalid,
  63. ExposeEstrusType: pasturePb.ExposeEstrusType_Natural_Estrus,
  64. Status: pasturePb.IsShow_Ok,
  65. MatingNumber: 1,
  66. OperationId: int64(req.OperationId),
  67. OperationName: req.OperationName,
  68. FrozenSemenNumber: req.FrozenSemenNumber,
  69. FrozenSemenCount: req.FrozenSemenCount,
  70. Remarks: req.Remarks,
  71. }
  72. }
  73. func NewEventMatingList(cowList []*Cow, planDay int64) []*EventMating {
  74. var matingList []*EventMating
  75. for _, cow := range cowList {
  76. matingList = append(matingList, NewEventMating(cow, planDay))
  77. }
  78. return matingList
  79. }
  80. type EventMatingSlice []*EventMating
  81. func (e EventMatingSlice) ToPB(exposeEstrusTypeMap map[pasturePb.ExposeEstrusType_Kind]string) []*pasturePb.SearchMatingList {
  82. res := make([]*pasturePb.SearchMatingList, len(e))
  83. for i, v := range e {
  84. res[i] = &pasturePb.SearchMatingList{
  85. Id: int32(v.Id),
  86. CowId: int32(v.CowId),
  87. DayAge: int32(v.DayAge),
  88. Lact: int32(v.Lact),
  89. CalvingAge: v.CalvingAge,
  90. PlanDay: time.Unix(v.PlanDay, 0).Format(LayoutDate2),
  91. RealityDay: time.Unix(v.RealityDay, 0).Format(LayoutDate2),
  92. ExposeEstrusType: v.ExposeEstrusType,
  93. ExposeEstrusTypeName: exposeEstrusTypeMap[v.ExposeEstrusType],
  94. FrozenSemenNumber: v.FrozenSemenNumber,
  95. Remarks: v.Remarks,
  96. OperationId: int32(v.OperationId),
  97. OperationName: v.OperationName,
  98. CreatedAt: int32(v.CreatedAt),
  99. UpdatedAt: int32(v.UpdatedAt),
  100. }
  101. }
  102. return res
  103. }
  104. type CowMatingHeader struct {
  105. Id string `json:"id"`
  106. CowId string `json:"cowId"`
  107. PlanDay string `json:"planDay"`
  108. Lact string `json:"lact"`
  109. Status string `json:"status"`
  110. BreedStatusName string `json:"breedStatusName"`
  111. BreedStatus string `json:"breedStatus"`
  112. CowTypeName string `json:"cowTypeName"`
  113. PenName string `json:"penName"`
  114. DayAge string `json:"dayAge"`
  115. CalvingAge string `json:"calvingAge"`
  116. AbortionAge string `json:"abortionAge"`
  117. }
  118. type CowMatingBody struct {
  119. Id int64 `json:"id"`
  120. CowId int64 `json:"cowId"`
  121. BreedStatus pasturePb.BreedStatus_Kind `json:"breedStatus"`
  122. BreedStatusName string `json:"breedStatusName"`
  123. CowType pasturePb.CowType_Kind `json:"cowType"`
  124. CowTypeName string `json:"cowTypeName"`
  125. PenId int32 `json:"penId"`
  126. PenName string `json:"penName"`
  127. Lact int32 `json:"lact"`
  128. CalvingAge int32 `json:"calvingAge"`
  129. AbortionAge int32 `json:"abortionAge"`
  130. DayAge int32 `json:"dayAge"`
  131. Status pasturePb.IsShow_Kind `json:"status"`
  132. }
  133. type CowMatingBodySlice []*CowMatingBody
  134. func (s CowMatingBodySlice) ToPB(
  135. cowTypeMap map[pasturePb.CowType_Kind]string,
  136. breedStatusMap map[pasturePb.BreedStatus_Kind]string,
  137. penMap map[int32]*Pen,
  138. ) []*CowMatingBody {
  139. res := make([]*CowMatingBody, len(s))
  140. for i, v := range s {
  141. res[i] = &CowMatingBody{
  142. Id: v.Id,
  143. CowId: v.CowId,
  144. CowType: v.CowType,
  145. CowTypeName: cowTypeMap[v.CowType],
  146. BreedStatus: v.BreedStatus,
  147. BreedStatusName: breedStatusMap[v.BreedStatus],
  148. PenName: penMap[v.PenId].Name,
  149. PenId: v.PenId,
  150. Lact: v.Lact,
  151. CalvingAge: v.CalvingAge,
  152. AbortionAge: v.AbortionAge,
  153. DayAge: v.DayAge,
  154. Status: v.Status,
  155. }
  156. }
  157. return res
  158. }
  159. type MatingTimelyChart struct {
  160. CalvingAge int32 `json:"calvingAge"`
  161. RealityDay string `json:"realityDay"`
  162. LactGroup string `json:"lactGroup"`
  163. }
  164. func (e EventMatingSlice) ToPB2() []*pasturePb.CowList {
  165. res := make([]*pasturePb.CowList, len(e))
  166. for i, v := range e {
  167. calvingAt, matingAtFormat := "", ""
  168. if v.CalvingAt > 0 {
  169. calvingAt = time.Unix(v.CalvingAt, 0).Format(LayoutDate2)
  170. }
  171. if v.RealityDay > 0 {
  172. matingAtFormat = time.Unix(v.RealityDay, 0).Format(LayoutDate2)
  173. }
  174. res[i] = &pasturePb.CowList{
  175. CowId: int32(v.CowId),
  176. DayAge: int32(v.DayAge),
  177. CalvingAge: v.CalvingAge,
  178. MatingAtFormat: matingAtFormat,
  179. CalvingAtFormat: calvingAt,
  180. Lact: int32(v.Lact),
  181. }
  182. }
  183. return res
  184. }
  185. type MatingTimelyResponse struct {
  186. Code int32 `json:"code"`
  187. Message string `json:"message"`
  188. Data *MatingTimelyData `json:"data"`
  189. }
  190. type MatingTimelyData struct {
  191. CowList []*pasturePb.CowList `json:"cowList"`
  192. Chart *CowMatingChart `json:"chart"`
  193. }
  194. type CowMatingChart struct {
  195. Lact0 [][]string `json:"lact0"`
  196. Lact1 [][]string `json:"lact1"`
  197. Lact2 [][]string `json:"lact2"`
  198. Lact3 [][]string `json:"lact3"`
  199. }