package model import pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow" type EventDeath struct { Id int64 `json:"id"` PastureId int64 `json:"pastureId"` EarNumber string `json:"earNumber"` CowId int64 `json:"cowId"` Lact int32 `json:"lact"` DayAge int32 `json:"dayAge"` PregnancyAge int32 `json:"pregnancyAge"` CalvingAge int32 `json:"calvingAge"` AdmissionAge int32 `json:"admissionAge"` DeathReasonKind pasturePb.DeathReason_Kind `json:"deathReasonKind"` DeathReasonName string `json:"deathReasonName"` DeathDestinationKind pasturePb.DeathDestination_Kind `json:"deathDestinationKind"` DeathDestinationName string `json:"deathDestinationName"` DeathAt int64 `json:"deathAt"` Remarks string `json:"remarks"` Weight int32 `json:"weight"` OperationId int64 `json:"operationId"` OperationName string `json:"operationName"` MessageId int64 `json:"messageId"` MessageName string `json:"messageName"` CreatedAt int64 `json:"createdAt"` UpdatedAt int64 `json:"updatedAt"` } func (e *EventDeath) TableName() string { return "event_death" } func NewEventDeath(pastureId int64, cow *Cow, req *pasturePb.EventDeath, currentUser, operationUser *SystemUser) *EventDeath { return &EventDeath{ PastureId: pastureId, CowId: cow.Id, EarNumber: cow.EarNumber, Lact: cow.Lact, DayAge: cow.GetDayAge(), DeathAt: int64(req.DeathAt), DeathReasonKind: req.DeathReasonKind, DeathReasonName: req.DeathReasonName, Remarks: req.Remarks, Weight: int32(req.Weight * 1000), DeathDestinationKind: req.DeathDestinationKind, DeathDestinationName: req.DeathDestinationName, OperationId: operationUser.Id, OperationName: operationUser.Name, MessageId: currentUser.Id, MessageName: currentUser.Name, } } type EventDeathSlice []*EventDeath func (e EventDeathSlice) ToPB() []*pasturePb.EventDeath { res := make([]*pasturePb.EventDeath, len(e)) for i, v := range e { res[i] = &pasturePb.EventDeath{ Id: int32(v.Id), EarNumber: v.EarNumber, DeathReasonKind: v.DeathReasonKind, DeathReasonName: v.DeathReasonName, DeathAt: int32(v.DeathAt), OperationId: int32(v.OperationId), OperationName: v.OperationName, Remarks: v.Remarks, Weight: float32(v.Weight / 1000), DeathDestinationKind: v.DeathDestinationKind, DeathDestinationName: v.DeathDestinationName, CreatedAt: int32(v.CreatedAt), UpdatedAt: int32(v.UpdatedAt), } } return res } type EventDeathModel struct { Cow *Cow EventDeath *EventDeath NeckRing *NeckRing }