event_immunization_plan.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. package model
  2. import (
  3. "kpt-pasture/util"
  4. "time"
  5. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  6. )
  7. type EventImmunizationPlan struct {
  8. Id int64 `json:"id"`
  9. PastureId int64 `json:"pastureId"`
  10. CowId int64 `json:"cowId"`
  11. EarNumber string `json:"earNumber"`
  12. Lact int32 `json:"lact"`
  13. DayAge int32 `json:"dayAge"`
  14. CowType pasturePb.CowType_Kind `json:"cowType"`
  15. CowKind pasturePb.CowKind_Kind `json:"cowKind"`
  16. PenId int32 `json:"penId"`
  17. PenName string `json:"penName"`
  18. PlanId int64 `json:"planId"`
  19. PlanName string `json:"planName"`
  20. PlanDay int64 `json:"planDay"`
  21. RealityDay int64 `json:"realityDay"`
  22. EndDay int64 `json:"endDay"`
  23. Status pasturePb.IsShow_Kind `json:"status"`
  24. DrugsId int64 `json:"drugsId"`
  25. DrugsName string `json:"drugsName"`
  26. Unit pasturePb.Unit_Kind `json:"unit"`
  27. UnitName string `json:"unitName"`
  28. Usage int32 `json:"usage"`
  29. Remarks string `json:"remarks"`
  30. OperationId int64 `json:"operationId"`
  31. OperationName string `json:"operationName"`
  32. MessageId int64 `json:"messageId"`
  33. MessageName string `json:"messageName"`
  34. CreatedAt int64 `json:"createdAt"`
  35. UpdatedAt int64 `json:"updatedAt"`
  36. }
  37. func (e *EventImmunizationPlan) TableName() string {
  38. return "event_immunization_plan"
  39. }
  40. func (e *EventImmunizationPlan) EventUpdate(immunizationAt int64, cowInfo *Cow, drugs *Drugs, usage int32, operationUser, currUser *SystemUser, remark string) {
  41. e.OperationId = operationUser.Id
  42. e.OperationName = operationUser.Name
  43. e.MessageId = currUser.Id
  44. e.MessageName = currUser.Name
  45. e.RealityDay = immunizationAt
  46. e.Remarks = remark
  47. e.Lact = cowInfo.Lact
  48. e.DayAge = cowInfo.DayAge
  49. e.EarNumber = cowInfo.EarNumber
  50. e.Status = pasturePb.IsShow_Ok
  51. e.DrugsId = drugs.Id
  52. e.DrugsName = drugs.Name
  53. e.Unit = drugs.Unit
  54. e.UnitName = drugs.UnitName
  55. e.Usage = usage
  56. }
  57. func NewEventImmunizationPlan(cow *Cow, immunizationPlan *ImmunizationPlan) *EventImmunizationPlan {
  58. todayTime := time.Now()
  59. todayStartTime := util.TimeParseLocalUnix(todayTime.Format(LayoutDate2))
  60. todayEndTime := util.TimeParseLocalEndUnix(todayTime.AddDate(0, 0, 6).Format(LayoutDate2))
  61. return &EventImmunizationPlan{
  62. PastureId: immunizationPlan.PastureId,
  63. CowId: cow.Id,
  64. EarNumber: cow.EarNumber,
  65. Lact: cow.Lact,
  66. DayAge: cow.DayAge,
  67. CowKind: cow.CowKind,
  68. CowType: cow.CowType,
  69. PenId: cow.PenId,
  70. PenName: cow.PenName,
  71. PlanId: immunizationPlan.Id,
  72. PlanName: immunizationPlan.Name,
  73. PlanDay: todayStartTime,
  74. EndDay: todayEndTime,
  75. Status: pasturePb.IsShow_No,
  76. }
  77. }
  78. func NewCowImmunizationPlanList(cowList []*Cow, immunizationPlan *ImmunizationPlan) []*EventImmunizationPlan {
  79. eventImmunizationPlanList := make([]*EventImmunizationPlan, len(cowList))
  80. for i, cow := range cowList {
  81. eventImmunizationPlanList[i] = NewEventImmunizationPlan(cow, immunizationPlan)
  82. }
  83. return eventImmunizationPlanList
  84. }
  85. type EventImmunizationPlanSlice []*EventImmunizationPlan
  86. func (e EventImmunizationPlanSlice) ToPB() []*pasturePb.ImmunizationItems {
  87. res := make([]*pasturePb.ImmunizationItems, len(e))
  88. for i, v := range e {
  89. planDay := ""
  90. if v.PlanDay > 0 {
  91. planDay = time.Unix(v.PlanDay, 0).Format(LayoutDate2)
  92. }
  93. res[i] = &pasturePb.ImmunizationItems{
  94. Id: int32(v.Id),
  95. CowId: int32(v.CowId),
  96. EarNumber: v.EarNumber,
  97. Lact: v.Lact,
  98. PenName: v.PenName,
  99. DayAge: v.DayAge,
  100. PlanDay: planDay,
  101. Status: v.Status,
  102. ImmunizationName: v.PlanName,
  103. ImmunizationId: int32(v.PlanId),
  104. }
  105. }
  106. return res
  107. }
  108. func (e EventImmunizationPlanSlice) ToPB2() []*pasturePb.ImmunizationItem {
  109. res := make([]*pasturePb.ImmunizationItem, len(e))
  110. for i, v := range e {
  111. res[i] = &pasturePb.ImmunizationItem{
  112. Id: int32(v.Id),
  113. ImmunizationAt: int32(v.RealityDay),
  114. OperationId: int32(v.OperationId),
  115. OperationName: v.OperationName,
  116. Remarks: v.Remarks,
  117. CowIds: make([]int32, 0),
  118. DrugsId: int32(v.DrugsId),
  119. DrugsName: v.DrugsName,
  120. Unit: v.Unit,
  121. UnitName: v.UnitName,
  122. Usage: v.Usage,
  123. PlanId: int32(v.PlanId),
  124. PlanName: v.PlanName,
  125. CowId: int32(v.CowId),
  126. EarNumber: v.EarNumber,
  127. }
  128. }
  129. return res
  130. }