package model import pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow" type EventCalving struct { Id int64 `json:"int_64"` CowId int64 `json:"cow_id"` EarNumber string `json:"ear_number"` Lact int32 `json:"lact"` DayAge int32 `json:"day_age"` PenId int32 `json:"pen_id"` CalvingAt int64 `json:"calving_at"` ChildNumber int8 `json:"child_number"` BullId int64 `json:"bull_id"` DaysPregnant int32 `json:"days_pregnant"` CalvingLevel pasturePb.CalvingLevel_Kind `json:"calving_level"` StaffMemberId int64 `json:"staff_member_id"` DystociaReason pasturePb.DystociaReason_Kind `json:"dystocia_reason"` 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, req *pasturePb.EventCalving) *EventCalving { return &EventCalving{ CowId: cow.Id, EarNumber: cow.EarNumber, Lact: cow.Lact, DayAge: cow.GetDayAge(), PenId: int32(cow.PenId), CalvingAt: int64(req.CalvingAt), BullId: cow.LastBullId, CalvingLevel: req.CalvingLevel, DystociaReason: req.DystociaReason, DaysPregnant: cow.GetDaysPregnant(), ChildNumber: int8(req.ChildNumber), Remarks: req.Remarks, StaffMemberId: int64(req.StaffMemberId), } } 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.BrithWeight) / 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.CalvingAt), ChildNumber: int32(item.ChildNumber), DaysPregnant: item.DaysPregnant, StaffMemberId: int32(item.StaffMemberId), StaffMemberName: item.StaffMemberName, CalvingLevel: item.CalvingLevel, Remarks: item.Remarks, CreatedAt: int32(item.CreatedAt), UpdatedAt: int32(item.UpdatedAt), DystociaReason: item.DystociaReason, CalfItemList: CalfItemList, }) } return list }