package model import pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow" type EventMating struct { Id int64 `json:"id"` CowId int64 `json:"cow_id"` DayAge int64 `json:"day_age"` Lact int8 `json:"lact"` LactationDays int32 `json:"lactation_days"` ExposeEstrusType pasturePb.ExposeEstrusType_Kind `json:"expose_estrus_type"` MatingAt int64 `json:"mating_at"` BullId string `json:"bull_id"` FrozenSemenNumber string `json:"frozen_semen_number"` StallNumberId int64 `json:"stall_number_id"` OperationId int64 `json:"operation_id"` Remarks string `json:"remarks"` CreatedAt int64 `json:"created_at"` UpdatedAt int64 `json:"updated_at"` } func (e *EventMating) TableName() string { return "event_mating" } func NewEventMating(cow *Cow, currentUser *SystemUser, req *pasturePb.EventMating) *EventMating { return &EventMating{ CowId: cow.Id, DayAge: int64(cow.GetDayAge()), Lact: int8(cow.Lact), LactationDays: cow.GetLactationDays(), ExposeEstrusType: req.ExposeEstrusType, MatingAt: int64(req.MatingAt), BullId: req.BullId, FrozenSemenNumber: req.FrozenSemenNumber, StallNumberId: int64(req.StaffMemberId), OperationId: currentUser.Id, Remarks: req.Remarks, } } type EventMatingSlice []*EventMating func (e EventMatingSlice) ToPB(user []*SystemUser, exposeEstrusTypeMap map[pasturePb.ExposeEstrusType_Kind]string) []*pasturePb.SearchMatingList { res := make([]*pasturePb.SearchMatingList, len(e)) for i, v := range e { operationName, staffMemberName := "", "" for _, u := range user { if v.OperationId == u.Id { operationName = u.Name } if v.StallNumberId == u.Id { staffMemberName = u.Name } } res[i] = &pasturePb.SearchMatingList{ Id: int32(v.Id), CowId: int32(v.CowId), DayAge: int32(v.DayAge), Lact: int32(v.Lact), ExposeEstrusType: v.ExposeEstrusType, ExposeEstrusTypeName: exposeEstrusTypeMap[v.ExposeEstrusType], MatingAt: int32(v.MatingAt), BullId: v.BullId, FrozenSemenNumber: v.FrozenSemenNumber, LactationDays: v.LactationDays, StaffMemberId: int32(v.StallNumberId), StaffMemberName: staffMemberName, Remarks: v.Remarks, OperationId: int32(v.OperationId), OperationName: operationName, CreatedAt: int32(v.CreatedAt), UpdatedAt: int32(v.UpdatedAt), } } return res }