immunization_plan.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package model
  2. import (
  3. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  4. )
  5. type ImmunizationPlan struct {
  6. Id int64 `json:"id"`
  7. PastureId int64 `json:"pastureId"`
  8. Name string `json:"name"`
  9. CowType pasturePb.CowType_Kind `json:"cowType"`
  10. Conditions pasturePb.ImmunizationConditions_Kind `json:"conditions"`
  11. Value int64 `json:"value"`
  12. IsShow pasturePb.IsShow_Kind `json:"isShow"`
  13. ImmunizationPlanId int64 `json:"immunizationPlanId"`
  14. ImmunizationPlanName string `json:"immunizationPlanName"`
  15. OperationId int64 `json:"operationId"`
  16. OperationName string `json:"operationName"`
  17. CreatedAt int64 `json:"createdAt"`
  18. UpdatedAt int64 `json:"updatedAt"`
  19. }
  20. func (i *ImmunizationPlan) TableName() string {
  21. return "immunization_plan"
  22. }
  23. func NewImmunizationPlan(pastureId int64, systemUser *SystemUser, req *pasturePb.ImmunizationRequest) *ImmunizationPlan {
  24. return &ImmunizationPlan{
  25. PastureId: pastureId,
  26. Name: req.Name,
  27. CowType: req.CowType,
  28. Conditions: req.Conditions,
  29. Value: int64(req.Value),
  30. ImmunizationPlanId: int64(req.ImmunizationPlanId),
  31. ImmunizationPlanName: req.ImmunizationPlanName,
  32. IsShow: req.IsShow,
  33. OperationId: systemUser.Id,
  34. OperationName: systemUser.Name,
  35. }
  36. }
  37. type ImmunizationPlanSlice []*ImmunizationPlan
  38. func (i ImmunizationPlanSlice) ToPB(cowTypeOptions []*pasturePb.ConfigOptionsList, conditionsOptions []*pasturePb.ConfigOptionsList) []*pasturePb.ImmunizationRequest {
  39. res := make([]*pasturePb.ImmunizationRequest, len(i))
  40. for d, v := range i {
  41. cowTypeName, conditionsName := "", ""
  42. for _, c := range cowTypeOptions {
  43. if c.Value != int32(v.CowType) {
  44. continue
  45. }
  46. cowTypeName = c.Label
  47. }
  48. for _, cd := range conditionsOptions {
  49. if cd.Value != int32(v.Conditions) {
  50. continue
  51. }
  52. conditionsName = cd.Label
  53. }
  54. res[d] = &pasturePb.ImmunizationRequest{
  55. Id: int32(v.Id),
  56. Name: v.Name,
  57. CowType: v.CowType,
  58. CowTypeName: cowTypeName,
  59. Conditions: v.Conditions,
  60. ConditionsName: conditionsName,
  61. Value: int32(v.Value),
  62. IsShow: v.IsShow,
  63. ImmunizationPlanId: int32(v.ImmunizationPlanId),
  64. ImmunizationPlanName: v.ImmunizationPlanName,
  65. OperationId: int32(v.OperationId),
  66. OperationName: v.OperationName,
  67. CreatedAt: int32(v.CreatedAt),
  68. UpdatedAt: int32(v.UpdatedAt),
  69. }
  70. }
  71. return res
  72. }