package model import ( "kpt-pasture/util" "time" pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow" ) type EventCalving struct { Id int64 `json:"id"` CowId int64 `json:"cowId"` CowType pasturePb.CowType_Kind `json:"cowType"` CowKind pasturePb.CowKind_Kind `json:"cowKind"` EarNumber string `json:"earNumber"` Lact int32 `json:"lact"` DayAge int32 `json:"dayAge"` PlanDay int64 `json:"planDay"` RealityDay int64 `json:"realityDay"` EndDay int64 `json:"endDay"` Status pasturePb.IsShow_Kind `json:"status"` PenId int32 `json:"penId"` ChildNumber int8 `json:"childNumber"` BullNumber string `json:"bullNumber"` PregnancyAge int64 `json:"pregnancyAge"` CalvingLevel pasturePb.CalvingLevel_Kind `json:"calvingLevel"` OperationId int64 `json:"operationId"` OperationName string `json:"operationName"` DystociaReason pasturePb.DystociaReason_Kind `json:"dystociaReason"` Remarks string `json:"remarks"` CreatedAt int64 `json:"created_at"` UpdatedAt int64 `json:"updated_at"` } func (e *EventCalving) TableName() string { return "event_calving" } func NewEventCalving(cow *Cow) *EventCalving { return &EventCalving{ CowId: cow.Id, CowKind: cow.CowKind, CowType: cow.CowType, EarNumber: cow.EarNumber, PenId: cow.PenId, BullNumber: cow.LastBullNumber, Status: pasturePb.IsShow_No, PlanDay: util.TimeParseLocalUnix(time.Now().Format(LayoutTime)), EndDay: util.TimeParseLocalEndUnix(time.Now().Format(LayoutTime)), } } func NewEventCalvingList(cowList []*Cow) []*EventCalving { eventCalvingList := make([]*EventCalving, 0) for _, cow := range cowList { eventCalvingList = append(eventCalvingList, NewEventCalving(cow)) } return eventCalvingList } type EventCalvingList struct { EventCalving PenName string `json:"pen_name"` StaffMemberName string `json:"staff_member_name"` } type EventCalvingListSlice []*EventCalvingList func (e EventCalvingListSlice) ToPB(req []*CalvingCalf) []*pasturePb.LavingList { var list []*pasturePb.LavingList for _, item := range e { CalfItemList := make([]*pasturePb.CalfItem, 0) for _, v := range req { if v.CalvingId != item.Id { continue } CalfItemList = append(CalfItemList, &pasturePb.CalfItem{ EarNumber: v.EarNumber, Sex: v.Sex, Weight: float32(v.BirthWeight) / 1000, IsAdoption: v.IsAdoption, IsLive: v.IsLive, CreatedAt: int32(v.CreatedAt), UpdatedAt: int32(v.UpdatedAt), PenId: v.PenId, Remarks: v.Remarks, MotherId: int32(v.MotherId), Id: int32(v.Id), }) } list = append(list, &pasturePb.LavingList{ Id: int32(item.Id), CowId: int32(item.CowId), Lact: item.Lact, PenId: item.PenId, PenName: item.PenName, CalvingAt: int32(item.PlanDay), ChildNumber: int32(item.ChildNumber), DaysPregnant: int32(item.PregnancyAge), OperationId: int32(item.OperationId), OperationName: item.OperationName, CalvingLevel: item.CalvingLevel, Remarks: item.Remarks, CreatedAt: int32(item.CreatedAt), UpdatedAt: int32(item.UpdatedAt), DystociaReason: item.DystociaReason, CalfItemList: CalfItemList, }) } return list } type EventCalvingSlice []*EventCalving func (e EventCalvingSlice) ToPB() []*pasturePb.CalvingReportTable { res := make([]*pasturePb.CalvingReportTable, len(e)) for i, v := range e { res[i] = &pasturePb.CalvingReportTable{ StatisticMethod: v.Remarks, Twins: 0, TwinsRate: 0, Bulls: 0, BullsRate: 0, Cows: 0, CowsRate: 0, SurviveCount: 0, SurviveRate: 0, DieCount: 0, DieRate: 0, BullsDieCount: 0, BullsDieRate: 0, CowsDieCount: 0, CowsDieRate: 0, AdoptCount: 0, AdoptRate: 0, PrematureLaborCount: 0, PrematureLaborRate: 0, LateLaborCount: 0, LateLaborRate: 0, NormalLaborCount: 0, } } return res }