package model import ( pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow" ) type ImmunizationPlan struct { Id int64 `json:"id"` Name string `json:"name"` CowType pasturePb.CowType_Kind `json:"cowType"` Conditions pasturePb.ImmunizationConditions_Kind `json:"conditions"` Value int64 `json:"value"` IsShow pasturePb.IsShow_Kind `json:"isShow"` ImmunizationPlanId int64 `json:"immunizationPlanId"` ImmunizationPlanName string `json:"immunizationPlanName"` OperationId int64 `json:"operationId"` OperationName string `json:"operationName"` CreatedAt int64 `json:"createdAt"` UpdatedAt int64 `json:"updatedAt"` } func (i *ImmunizationPlan) TableName() string { return "immunization_plan" } func NewImmunizationPlan(systemUser *SystemUser, req *pasturePb.ImmunizationRequest) *ImmunizationPlan { return &ImmunizationPlan{ Name: req.Name, CowType: req.CowType, Conditions: req.Conditions, Value: int64(req.Value), ImmunizationPlanId: int64(req.ImmunizationPlanId), ImmunizationPlanName: req.ImmunizationPlanName, IsShow: req.IsShow, OperationId: systemUser.Id, OperationName: systemUser.Name, } } type ImmunizationPlanSlice []*ImmunizationPlan func (i ImmunizationPlanSlice) ToPB(cowTypeOptions []*pasturePb.ConfigOptionsList, conditionsOptions []*pasturePb.ConfigOptionsList) []*pasturePb.ImmunizationRequest { res := make([]*pasturePb.ImmunizationRequest, len(i)) for d, v := range i { cowTypeName, conditionsName := "", "" for _, c := range cowTypeOptions { if c.Value != int32(v.CowType) { continue } cowTypeName = c.Label } for _, cd := range conditionsOptions { if cd.Value != int32(v.Conditions) { continue } conditionsName = cd.Label } res[d] = &pasturePb.ImmunizationRequest{ Id: int32(v.Id), Name: v.Name, CowType: v.CowType, CowTypeName: cowTypeName, Conditions: v.Conditions, ConditionsName: conditionsName, Value: int32(v.Value), IsShow: v.IsShow, ImmunizationPlanId: int32(v.ImmunizationPlanId), ImmunizationPlanName: v.ImmunizationPlanName, OperationId: int32(v.OperationId), OperationName: v.OperationName, CreatedAt: int32(v.CreatedAt), UpdatedAt: int32(v.UpdatedAt), } } return res }