event_mating.go 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. PenId int32 `json:"penId"`
  12. CowType pasturePb.CowType_Kind `json:"cowType"`
  13. CowKind pasturePb.CowKind_Kind `json:"cowKind"`
  14. CalvingAge int32 `json:"calvingAge"`
  15. PlanDay int64 `json:"planDay"`
  16. EndDay int64 `json:"endDay"`
  17. CalvingAt int64 `json:"calvingAt"`
  18. RealityDay int64 `json:"realityDay"`
  19. Status pasturePb.IsShow_Kind `json:"status"`
  20. MatingTimes int32 `json:"matingTimes"`
  21. MatingResult pasturePb.MatingResult_Kind `json:"matingResult"`
  22. MatingResultAt int64 `json:"matingResultAt"`
  23. ExposeEstrusType pasturePb.ExposeEstrusType_Kind `json:"exposeEstrusType"`
  24. FrozenSemenNumber string `json:"frozenSemenNumber"`
  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. PenId: cow.PenId,
  41. CowType: cow.CowType,
  42. CowKind: cow.CowKind,
  43. CalvingAt: cow.LastMatingAt,
  44. PlanDay: planDay,
  45. EndDay: planDay,
  46. MatingResult: pasturePb.MatingResult_Unknown,
  47. ExposeEstrusType: pasturePb.ExposeEstrusType_Same_Time,
  48. Status: pasturePb.IsShow_No,
  49. }
  50. }
  51. // NewEventMating2 自然发情的牛只
  52. func NewEventMating2(cow *Cow, req *pasturePb.EventMating, currentUser *SystemUser) *EventMating {
  53. return &EventMating{
  54. CowId: cow.Id,
  55. Lact: cow.Lact,
  56. DayAge: cow.GetDayAge(),
  57. CowType: cow.CowType,
  58. CowKind: cow.CowKind,
  59. CalvingAt: cow.LastMatingAt,
  60. PlanDay: int64(req.MatingAt),
  61. RealityDay: int64(req.MatingAt),
  62. EndDay: int64(req.MatingAt),
  63. MatingResult: pasturePb.MatingResult_Unknown,
  64. ExposeEstrusType: pasturePb.ExposeEstrusType_Natural_Estrus,
  65. Status: pasturePb.IsShow_Ok,
  66. OperationId: int64(req.OperationId),
  67. OperationName: req.OperationName,
  68. MessageId: currentUser.Id,
  69. MessageName: currentUser.Name,
  70. FrozenSemenNumber: req.FrozenSemenNumber,
  71. Remarks: req.Remarks,
  72. }
  73. }
  74. func NewEventMatingList(cowList []*Cow, planDay int64) []*EventMating {
  75. var matingList []*EventMating
  76. for _, cow := range cowList {
  77. matingList = append(matingList, NewEventMating(cow, planDay))
  78. }
  79. return matingList
  80. }
  81. type EventMatingSlice []*EventMating
  82. func (e EventMatingSlice) ToPB(exposeEstrusTypeMap map[pasturePb.ExposeEstrusType_Kind]string) []*pasturePb.SearchMatingList {
  83. res := make([]*pasturePb.SearchMatingList, len(e))
  84. for i, v := range e {
  85. res[i] = &pasturePb.SearchMatingList{
  86. Id: int32(v.Id),
  87. CowId: int32(v.CowId),
  88. DayAge: int32(v.DayAge),
  89. Lact: int32(v.Lact),
  90. CalvingAge: v.CalvingAge,
  91. PlanDay: time.Unix(v.PlanDay, 0).Format(LayoutDate2),
  92. RealityDay: time.Unix(v.RealityDay, 0).Format(LayoutDate2),
  93. ExposeEstrusType: v.ExposeEstrusType,
  94. ExposeEstrusTypeName: exposeEstrusTypeMap[v.ExposeEstrusType],
  95. FrozenSemenNumber: v.FrozenSemenNumber,
  96. Remarks: v.Remarks,
  97. OperationId: int32(v.OperationId),
  98. OperationName: v.OperationName,
  99. CreatedAt: int32(v.CreatedAt),
  100. UpdatedAt: int32(v.UpdatedAt),
  101. }
  102. }
  103. return res
  104. }
  105. type CowMatingBody struct {
  106. Id int64 `json:"id"`
  107. CowId int64 `json:"cowId"`
  108. BreedStatus pasturePb.BreedStatus_Kind `json:"breedStatus"`
  109. BreedStatusName string `json:"breedStatusName"`
  110. CowType pasturePb.CowType_Kind `json:"cowType"`
  111. CowTypeName string `json:"cowTypeName"`
  112. PenId int32 `json:"penId"`
  113. PenName string `json:"penName"`
  114. Lact int32 `json:"lact"`
  115. CalvingAge int32 `json:"calvingAge"`
  116. AbortionAge int32 `json:"abortionAge"`
  117. DayAge int32 `json:"dayAge"`
  118. Status pasturePb.IsShow_Kind `json:"status"`
  119. }
  120. type CowMatingBodySlice []*CowMatingBody
  121. func (s CowMatingBodySlice) ToPB(
  122. cowTypeMap map[pasturePb.CowType_Kind]string,
  123. breedStatusMap map[pasturePb.BreedStatus_Kind]string,
  124. penMap map[int32]*Pen,
  125. ) []*CowMatingBody {
  126. res := make([]*CowMatingBody, len(s))
  127. for i, v := range s {
  128. res[i] = &CowMatingBody{
  129. Id: v.Id,
  130. CowId: v.CowId,
  131. CowType: v.CowType,
  132. CowTypeName: cowTypeMap[v.CowType],
  133. BreedStatus: v.BreedStatus,
  134. BreedStatusName: breedStatusMap[v.BreedStatus],
  135. PenName: penMap[v.PenId].Name,
  136. PenId: v.PenId,
  137. Lact: v.Lact,
  138. CalvingAge: v.CalvingAge,
  139. AbortionAge: v.AbortionAge,
  140. DayAge: v.DayAge,
  141. Status: v.Status,
  142. }
  143. }
  144. return res
  145. }
  146. type MatingTimelyChart struct {
  147. CalvingAge int32 `json:"calvingAge"`
  148. RealityDay string `json:"realityDay"`
  149. LactGroup string `json:"lactGroup"`
  150. }
  151. func (e EventMatingSlice) ToPB2() []*pasturePb.CowList {
  152. res := make([]*pasturePb.CowList, len(e))
  153. for i, v := range e {
  154. calvingAt, matingAtFormat := "", ""
  155. if v.CalvingAt > 0 {
  156. calvingAt = time.Unix(v.CalvingAt, 0).Format(LayoutDate2)
  157. }
  158. if v.RealityDay > 0 {
  159. matingAtFormat = time.Unix(v.RealityDay, 0).Format(LayoutDate2)
  160. }
  161. res[i] = &pasturePb.CowList{
  162. CowId: int32(v.CowId),
  163. DayAge: int32(v.DayAge),
  164. CalvingAge: v.CalvingAge,
  165. MatingAtFormat: matingAtFormat,
  166. CalvingAtFormat: calvingAt,
  167. Lact: int32(v.Lact),
  168. }
  169. }
  170. return res
  171. }
  172. type MatingTimelyResponse struct {
  173. Code int32 `json:"code"`
  174. Message string `json:"message"`
  175. Data *MatingTimelyData `json:"data"`
  176. }
  177. type MatingTimelyData struct {
  178. CowList []*pasturePb.CowList `json:"cowList"`
  179. Chart *CowMatingChart `json:"chart"`
  180. }
  181. type CowMatingChart struct {
  182. Lact0 [][]string `json:"lact0"`
  183. Lact1 [][]string `json:"lact1"`
  184. Lact2 [][]string `json:"lact2"`
  185. Lact3 [][]string `json:"lact3"`
  186. }
  187. // MultiFactorPregnancyRateResponse 多维度受胎率
  188. type MultiFactorPregnancyRateResponse struct {
  189. Code int32 `json:"code"`
  190. Message string `json:"message"`
  191. Data *MultiFactorPregnancyRateData `json:"data"`
  192. }
  193. // MultiFactorPregnancyRateList 多维度受胎率分析
  194. type MultiFactorPregnancyRateList struct {
  195. StatisticMethod1 string `json:"statisticMethod1"` // 统计方式名称1 (月度、品种)
  196. StatisticMethod2 string `json:"statisticMethod2"` // 统计方式名称2 (月度、品种)
  197. PregnantRate float32 `json:"pregnantRate"` // 受胎率%(怀孕数 / 怀孕数 + 空怀数)
  198. PregnantCount int32 `json:"pregnantCount"` // 怀孕总数
  199. EmptyPregnantCount int32 `json:"emptyPregnantCount"` // 空怀数
  200. OtherCount int32 `json:"otherCount"` // 其他数 (配种后结果未知的个数,小于等于三次配种后,尚未孕检已经淘汰的个数)
  201. AbortionCount int32 `json:"abortionCount"` // 流产数 (已经怀孕后流产的个数)
  202. TotalCount int32 `json:"totalCount"` // 合计( 怀孕总数+空怀数+其他数)
  203. SpcRate float32 `json:"spcRate"` // spc(1 / 受胎率)
  204. Months string `json:"months"` // 月份
  205. OperationName string `json:"operationName"` // 配种员名称
  206. Bull string `json:"bull"` // 公牛
  207. Lact string `json:"lact"` // 胎次
  208. MatingTimes string `json:"matingTimes"` // 配次
  209. ExposeEstrusType string `json:"exposeEstrusType"` // 发情揭发方式
  210. Week string `json:"week"` // 周
  211. }
  212. type MultiFactorPregnancyRateData struct {
  213. Total int32 `json:"total"`
  214. PageSize int32 `json:"pageSize"`
  215. Page int32 `json:"page"`
  216. List []*MultiFactorPregnancyRateList `json:"list"`
  217. Chart *MultiFactorPregnancyRateChart `json:"chart"`
  218. }
  219. type MultiFactorPregnancyRateChart struct {
  220. Header []string `json:"header"` // 标题头
  221. PregnantRateMap map[string]map[string]string `json:"pregnantRateMap"`
  222. KepMap []string `json:"kepMap"`
  223. }