immunization_plan.go 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. Name string `json:"name"`
  8. CowType pasturePb.CowType_Kind `json:"cowType"`
  9. Conditions pasturePb.ImmunizationConditions_Kind `json:"conditions"`
  10. Value int64 `json:"value"`
  11. IsShow pasturePb.IsShow_Kind `json:"isShow"`
  12. ImmunizationPlanId int64 `json:"immunizationPlanId"`
  13. ImmunizationPlanName string `json:"immunizationPlanName"`
  14. OperationId int64 `json:"operationId"`
  15. OperationName string `json:"operationName"`
  16. CreatedAt int64 `json:"createdAt"`
  17. UpdatedAt int64 `json:"updatedAt"`
  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. ImmunizationPlanId: int64(req.ImmunizationPlanId),
  29. ImmunizationPlanName: req.ImmunizationPlanName,
  30. IsShow: req.IsShow,
  31. OperationId: systemUser.Id,
  32. OperationName: systemUser.Name,
  33. }
  34. }
  35. type ImmunizationPlanSlice []*ImmunizationPlan
  36. func (i ImmunizationPlanSlice) ToPB(cowTypeOptions []*pasturePb.ConfigOptionsList, conditionsOptions []*pasturePb.ConfigOptionsList) []*pasturePb.ImmunizationRequest {
  37. res := make([]*pasturePb.ImmunizationRequest, len(i))
  38. for d, v := range i {
  39. cowTypeName, conditionsName := "", ""
  40. for _, c := range cowTypeOptions {
  41. if c.Value != int32(v.CowType) {
  42. continue
  43. }
  44. cowTypeName = c.Label
  45. }
  46. for _, cd := range conditionsOptions {
  47. if cd.Value != int32(v.Conditions) {
  48. continue
  49. }
  50. conditionsName = cd.Label
  51. }
  52. res[d] = &pasturePb.ImmunizationRequest{
  53. Id: int32(v.Id),
  54. Name: v.Name,
  55. CowType: v.CowType,
  56. CowTypeName: cowTypeName,
  57. Conditions: v.Conditions,
  58. ConditionsName: conditionsName,
  59. Value: int32(v.Value),
  60. IsShow: v.IsShow,
  61. ImmunizationPlanId: int32(v.ImmunizationPlanId),
  62. ImmunizationPlanName: v.ImmunizationPlanName,
  63. OperationId: int32(v.OperationId),
  64. OperationName: v.OperationName,
  65. CreatedAt: int32(v.CreatedAt),
  66. UpdatedAt: int32(v.UpdatedAt),
  67. }
  68. }
  69. return res
  70. }