package model import ( "kpt-pasture/util" pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow" ) type EventDryMilk struct { Id int64 `json:"id"` PastureId int64 `json:"pastureId"` CowId int64 `json:"cowId"` EarNumber string `json:"earNumber"` Lact int32 `json:"lact"` PenId int32 `json:"penId"` PenName string `json:"penName"` PlanDay int64 `json:"planDay"` RealityDay int64 `json:"realityDay"` EndDay int64 `json:"endDay"` Status pasturePb.IsShow_Kind `json:"status"` Remarks string `json:"remarks"` 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 *EventDryMilk) TableName() string { return "event_dry_milk" } func (e *EventDryMilk) EventDryMilkUpdate(cow *Cow, dryMilkAt int64, pen *Pen, operation, message *SystemUser, remarks string) { e.Lact = cow.Lact e.RealityDay = dryMilkAt e.Remarks = remarks e.Status = pasturePb.IsShow_Ok e.OperationId = operation.Id e.OperationName = operation.Name e.MessageId = message.Id e.MessageName = message.Name e.PenId = pen.Id e.PenName = pen.Name } func NewEventDryMilk(pastureId int64, cow *Cow, startDay, endDay string) *EventDryMilk { return &EventDryMilk{ PastureId: pastureId, CowId: cow.Id, EarNumber: cow.EarNumber, Lact: cow.Lact, PlanDay: util.TimeParseLocalUnix(startDay), EndDay: util.TimeParseLocalUnix(endDay), Status: pasturePb.IsShow_No, } } func NewEventDryMilkList(pastureId int64, cowList []*Cow, startDay, endDay string) []*EventDryMilk { eventDryMilkList := make([]*EventDryMilk, 0) for _, cow := range cowList { eventDryMilkList = append(eventDryMilkList, NewEventDryMilk(pastureId, cow, startDay, endDay)) } return eventDryMilkList } type EventDryMilkSlice []*EventDryMilk func (e EventDryMilkSlice) ToPB() []*pasturePb.EventMilkItem { res := make([]*pasturePb.EventMilkItem, len(e)) for i, v := range e { res[i] = &pasturePb.EventMilkItem{ Id: int32(v.Id), CowId: int32(v.CowId), EarNumber: v.EarNumber, Lact: v.Lact, PenName: v.PenName, DryMilkAt: int32(v.RealityDay), OperationName: v.OperationName, Remarks: v.Remarks, } } return res }