package model import pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow" type EventEstrus struct { Id int64 `json:"id"` CowId int64 `json:"cow_id"` DayAge int32 `json:"day_age"` Lact int8 `json:"lact"` LactationDays int32 `json:"lactation_days"` EstrusAt int64 `json:"estrus_at"` Remarks string `json:"remarks"` StallNumberId int64 `json:"stall_number_id"` OperationId int64 `json:"operation_id"` CreatedAt int64 `json:"created_at"` UpdatedAt int64 `json:"updated_at"` } func (e *EventEstrus) TableName() string { return "event_estrus" } func NewEventEstrus(cow *Cow, currentUser *SystemUser, req *pasturePb.EventEstrus) *EventEstrus { return &EventEstrus{ CowId: cow.Id, DayAge: cow.GetDayAge(), Lact: int8(cow.Lact), LactationDays: cow.GetLactationDays(), EstrusAt: int64(req.EstrusAt), Remarks: req.Remarks, StallNumberId: int64(req.StaffMemberId), OperationId: currentUser.Id, } } type EstrusSlice []*EventEstrus func (e EstrusSlice) ToPB(userList []*SystemUser) []*pasturePb.SearchEstrusList { res := make([]*pasturePb.SearchEstrusList, len(e)) for i, v := range e { staffMemberName, operationName := "", "" for _, u := range userList { if u.Id == v.StallNumberId { staffMemberName = u.Name } if u.Id == v.OperationId { operationName = u.Name } } res[i] = &pasturePb.SearchEstrusList{ Id: int32(v.Id), CowId: int32(v.CowId), DayAge: v.DayAge, Lact: int32(v.Lact), EstrusAt: int32(v.EstrusAt), 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 }