event_mating.go 9.7 KB

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