event_immunization_plan.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 NewEventImmunizationPlan(cow *Cow, 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: cow.PenName,
  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, immunizationPlan *ImmunizationPlan) []*EventImmunizationPlan {
  60. eventImmunizationPlanList := make([]*EventImmunizationPlan, len(cowList))
  61. for i, cow := range cowList {
  62. eventImmunizationPlanList[i] = NewEventImmunizationPlan(cow, immunizationPlan)
  63. }
  64. return eventImmunizationPlanList
  65. }
  66. type EventImmunizationPlanSlice []*EventImmunizationPlan
  67. func (I EventImmunizationPlanSlice) ToPB() []*pasturePb.ImmunizationItems {
  68. res := make([]*pasturePb.ImmunizationItems, len(I))
  69. for i, v := range I {
  70. planDay := ""
  71. if v.PlanDay > 0 {
  72. planDay = time.Unix(v.PlanDay, 0).Format(LayoutDate2)
  73. }
  74. res[i] = &pasturePb.ImmunizationItems{
  75. Id: int32(v.Id),
  76. CowId: int32(v.CowId),
  77. EarNumber: v.EarNumber,
  78. Lact: v.Lact,
  79. PenName: v.PenName,
  80. DayAge: v.DayAge,
  81. PlanDay: planDay,
  82. Status: v.Status,
  83. ImmunizationName: v.PlanName,
  84. ImmunizationId: int32(v.PlanId),
  85. }
  86. }
  87. return res
  88. }