package model import ( "strings" pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow" ) type EventAbortion struct { Id int64 `json:"id"` PastureId int64 `json:"pastureId"` CowId int64 `json:"cowId"` EarNumber string `json:"earNumber"` Lact int32 `json:"lact"` CowType pasturePb.CowType_Kind `json:"cowType"` DayAge int32 `json:"dayAge"` PregnantAge int32 `json:"pregnantAge"` AbortionAt int64 `json:"abortionAt"` IsAfterbirth pasturePb.IsShow_Kind `json:"isAfterbirth"` IsLact pasturePb.IsShow_Kind `json:"isLact"` Photos string `json:"photos"` AbortionReasons pasturePb.AbortionReasons_Kind `json:"abortionReasons"` AbortionReasonsName string `json:"abortionReasonsName"` Remarks string `json:"remarks"` IsAppend pasturePb.IsShow_Kind `json:"isAppend"` OperationId int64 `json:"operationId"` OperationName string `json:"operationName"` CreatedAt int64 `json:"createdAt"` UpdatedAt int64 `json:"updatedAt"` } func (e *EventAbortion) TableName() string { return "event_abortion" } func NewEventAbortion(pastureId int64, cow *Cow, item *pasturePb.EventAbortionItem, isAppend pasturePb.IsShow_Kind) *EventAbortion { return &EventAbortion{ PastureId: pastureId, CowId: cow.Id, EarNumber: cow.EarNumber, Lact: cow.Lact, CowType: cow.CowType, PregnantAge: cow.GetDaysPregnant(), DayAge: cow.DayAge, AbortionAt: int64(item.AbortionAt), IsAfterbirth: item.IsAfterbirth, IsLact: item.IsLact, Photos: strings.Join(item.Photos, ","), AbortionReasons: item.AbortionReasons, AbortionReasonsName: item.AbortionReasonsName, Remarks: item.Remarks, IsAppend: isAppend, OperationId: int64(item.OperationId), OperationName: item.OperationName, } } type AbortionSlice []*EventAbortion func (a AbortionSlice) ToPB() []*pasturePb.EventAbortionItem { res := make([]*pasturePb.EventAbortionItem, len(a)) for i, v := range a { res[i] = &pasturePb.EventAbortionItem{ Id: int32(v.Id), CowId: int32(v.CowId), EarNumber: v.EarNumber, DayAge: v.DayAge, Lact: v.Lact, AbortionAt: int32(v.AbortionAt), IsAfterbirth: v.IsAfterbirth, IsLact: v.IsLact, Photos: strings.Split(v.Photos, ","), AbortionReasons: v.AbortionReasons, AbortionReasonsName: v.AbortionReasonsName, PregnancyAge: v.PregnantAge, Remarks: v.Remarks, OperationId: int32(v.OperationId), OperationName: v.OperationName, CreatedAt: int32(v.CreatedAt), UpdatedAt: int32(v.UpdatedAt), } } return res }