package model import ( "time" pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow" ) type EventCowSameTime struct { Id int64 `json:"id"` CowId int64 `json:"cowId"` CowType pasturePb.CowType_Kind `json:"cowType"` PenId int32 `json:"penId"` PenName string `json:"penName"` Lact int32 `json:"lact"` SameTimeId int64 `json:"sameTimeId"` SameTimeName string `json:"sameTimeName"` SameTimeType pasturePb.SameTimeType_Kind `json:"sameTimeType"` PlanDay int64 `json:"planDay"` EndDay int64 `json:"endDay"` RealityDay int64 `json:"realityDay"` Status pasturePb.IsShow_Kind `json:"status"` DrugsId int64 `json:"drugsId"` Unit pasturePb.Unit_Kind `json:"unit"` Usage int32 `json:"usage"` OperationId int64 `json:"operationId"` OperationName string `json:"operationName"` CreatedAt int64 `json:"createdAt"` UpdatedAt int64 `json:"updatedAt"` } func (s *EventCowSameTime) TableName() string { return "event_cow_same_time" } func NewEventCowSameTime(cow *Cow, planTime int64, sameTime *SameTime, sameTimeType pasturePb.SameTimeType_Kind) *EventCowSameTime { return &EventCowSameTime{ CowId: cow.Id, Lact: cow.Lact, CowType: cow.CowType, PenId: cow.PenId, SameTimeId: sameTime.Id, SameTimeName: sameTime.Name, SameTimeType: sameTimeType, Status: pasturePb.IsShow_No, PlanDay: planTime, EndDay: planTime, } } func NewEventCowSameTimeList(cowList []*Cow, sameTime *SameTime, planTime int64, sameTimeType pasturePb.SameTimeType_Kind) []*EventCowSameTime { res := make([]*EventCowSameTime, len(cowList)) for i, cow := range cowList { res[i] = NewEventCowSameTime(cow, planTime, sameTime, sameTimeType) } return res } type SameTimeItemBody struct { Id int64 `json:"id"` CowId int64 `json:"cowId"` BreedStatus pasturePb.BreedStatus_Kind `json:"breedStatus"` BreedStatusName string `json:"breedStatusName"` CowType pasturePb.CowType_Kind `json:"cowType"` CowTypeName string `json:"cowTypeName"` PenId int32 `json:"penId"` PenName string `json:"penName"` Lact int32 `json:"lact"` CalvingAge int32 `json:"calvingAge"` AbortionAge int32 `json:"abortionAge"` DayAge int32 `json:"dayAge"` Status pasturePb.IsShow_Kind `json:"status"` SameTimeType pasturePb.SameTimeType_Kind `json:"sameTimeType"` LastCalvingAt int64 `json:"lastCalvingAt"` LastAbortionAt int64 `json:"lastAbortionAt"` MatingTimes int32 `json:"matingTimes"` SameTimeName string `json:"sameTimeName"` } type SameTimeBodySlice []*SameTimeItemBody func (s SameTimeBodySlice) ToPB( breedStatusMap map[pasturePb.BreedStatus_Kind]string, penMap map[int32]*Pen, sameTimeTypeMap map[pasturePb.SameTimeType_Kind]string, ) []*pasturePb.SameTimeItems { res := make([]*pasturePb.SameTimeItems, len(s)) for i, v := range s { penName, calvingAtFormat, abortionAtFormat := "", "", "" if pen, ok := penMap[v.PenId]; ok { penName = pen.Name } if v.LastCalvingAt > 0 { calvingAtFormat = time.Unix(v.LastCalvingAt, 0).Format(LayoutDate2) } if v.LastAbortionAt > 0 { abortionAtFormat = time.Unix(v.LastAbortionAt, 0).Format(LayoutDate2) } res[i] = &pasturePb.SameTimeItems{ Id: int32(v.Id), CowId: int32(v.CowId), BreedStatus: v.BreedStatus, BreedStatusName: breedStatusMap[v.BreedStatus], PenName: penName, PenId: v.PenId, Lact: v.Lact, CalvingAge: v.CalvingAge, AbortionAge: v.AbortionAge, DayAge: v.DayAge, Status: v.Status, SameTimeTypeName: sameTimeTypeMap[v.SameTimeType], CalvingAtFormat: calvingAtFormat, AbortionAtFormat: abortionAtFormat, MatingTimes: v.MatingTimes, SameTimeName: v.SameTimeName, } } return res } type EventCowSameTimeSlice []*EventCowSameTime func (s EventCowSameTimeSlice) ToPB(sameTimeTypeMap map[pasturePb.SameTimeType_Kind]string) []*pasturePb.EventSameTime { res := make([]*pasturePb.EventSameTime, len(s)) for i, v := range s { res[i] = &pasturePb.EventSameTime{ CowId: int32(v.CowId), PenId: v.PenId, DrugsId: int32(v.DrugsId), Usage: v.Usage, Lact: v.Lact, SameTimeId: int32(v.SameTimeId), SameTimeType: v.SameTimeType, SameTimeTypeName: sameTimeTypeMap[v.SameTimeType], } } return res }