event_immunization_plan.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. OperationId int64 `json:"operationId"`
  25. OperationName string `json:"operationName"`
  26. DrugsId int64 `json:"drugsId"`
  27. DrugsName string `json:"drugsName"`
  28. Unit pasturePb.Unit_Kind `json:"unit"`
  29. UnitName string `json:"unitName"`
  30. Usage int32 `json:"usage"`
  31. Remarks string `json:"remarks"`
  32. CreatedAt int64 `json:"createdAt"`
  33. UpdatedAt int64 `json:"updatedAt"`
  34. }
  35. func (c *EventImmunizationPlan) TableName() string {
  36. return "event_immunization_plan"
  37. }
  38. func NewCowImmunizationPlan(cow *Cow, pen *Pen, immunizationPlan *ImmunizationPlan) *EventImmunizationPlan {
  39. todayTime := time.Now().Format(LayoutDate2)
  40. todayStartTime := util.TimeParseLocalUnix(todayTime)
  41. todayEndTime := util.TimeParseLocalEndUnix(todayTime)
  42. return &EventImmunizationPlan{
  43. PastureId: immunizationPlan.PastureId,
  44. CowId: cow.Id,
  45. EarNumber: cow.EarNumber,
  46. Lact: cow.Lact,
  47. DayAge: cow.DayAge,
  48. CowKind: cow.CowKind,
  49. CowType: cow.CowType,
  50. PenId: cow.PenId,
  51. PenName: pen.Name,
  52. PlanId: immunizationPlan.Id,
  53. PlanName: immunizationPlan.Name,
  54. PlanDay: todayStartTime,
  55. EndDay: todayEndTime,
  56. Status: pasturePb.IsShow_No,
  57. }
  58. }
  59. func NewCowImmunizationPlanList(cowList []*Cow, penMap map[int32]*Pen, immunizationPlan *ImmunizationPlan) []*EventImmunizationPlan {
  60. cowImmunizationPlanList := make([]*EventImmunizationPlan, len(cowList))
  61. for i, cow := range cowList {
  62. pen := penMap[cow.PenId]
  63. cowImmunizationPlanList[i] = NewCowImmunizationPlan(cow, pen, immunizationPlan)
  64. }
  65. return cowImmunizationPlanList
  66. }
  67. type EventImmunizationPlanSlice []*EventImmunizationPlan
  68. func (I EventImmunizationPlanSlice) ToPB() []*pasturePb.ImmunizationItems {
  69. res := make([]*pasturePb.ImmunizationItems, len(I))
  70. for i, v := range I {
  71. res[i] = &pasturePb.ImmunizationItems{
  72. Id: int32(v.Id),
  73. CowId: int32(v.CowId),
  74. EarNumber: v.EarNumber,
  75. PenId: v.PenId,
  76. Lact: v.Lact,
  77. PenName: v.PenName,
  78. DayAge: v.DayAge,
  79. PlanDay: time.Unix(v.PlanDay, 0).Format(LayoutDate2),
  80. Status: v.Status,
  81. ImmunizationName: v.PlanName,
  82. ImmunizationId: int32(v.PlanId),
  83. Remarks: v.Remarks,
  84. OperatorId: int32(v.OperationId),
  85. OperatorName: v.OperationName,
  86. DrugId: int32(v.DrugsId),
  87. DrugName: v.DrugsName,
  88. Unit: v.Unit,
  89. UnitName: v.UnitName,
  90. Usage: v.Usage,
  91. CreatedAt: int32(v.CreatedAt),
  92. UpdatedAt: int32(v.UpdatedAt),
  93. }
  94. }
  95. return res
  96. }