immunization_plan.go 2.5 KB

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