package model import ( "math" "time" pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow" ) type EventEnter struct { Id int64 `json:"id"` BatchNumber string `json:"batch_number"` EarNumber string `json:"ear_number"` CowId int64 `json:"cow_id"` Sex pasturePb.Genders_Kind `json:"sex"` BirthAt int64 `json:"birth_at"` CowSourceId pasturePb.CowSource_Kind `json:"cow_source_id"` OldEarNumber string `json:"old_ear_number"` CowType pasturePb.CowType_Kind `json:"cow_type"` BreedStatus pasturePb.BreedStatus_Kind `json:"breed_status"` Lact int32 `json:"lact"` DayAge int32 `json:"day_age"` PenId int32 `json:"pen_id"` CowKind pasturePb.CowKind_Kind `json:"cow_kind"` FatherId int64 `json:"father_id"` MotherId int64 `json:"mother_id"` MatingAt int64 `json:"mating_at"` PregnancyCheckAt int64 `json:"pregnancy_check_at"` DryMilkAt int64 `json:"dry_milk_at"` WeaningAt int64 `json:"weaning_at"` EstrusAt int64 `json:"estrus_at"` EnterAt int64 `json:"enter_at"` Remarks string `json:"remarks"` Weight int64 `json:"weight"` Price int64 `json:"price"` OperationId int64 `json:"operation_id"` StaffMemberId int64 `json:"staff_member_id"` CreatedAt int64 `json:"created_at"` UpdatedAt int64 `json:"updated_at"` } func (e *EventEnter) TableName() string { return "event_enter" } func NewEventEnter(cowId, operationId int64, req *pasturePb.EventEnterData) *EventEnter { return &EventEnter{ EarNumber: req.EarNumber, CowId: cowId, Sex: req.Sex, BirthAt: int64(req.BirthAt), CowSourceId: req.CowSourceId, CowType: req.CowTypeId, BreedStatus: req.BreedStatusId, Lact: req.Lact, DayAge: int32(math.Floor(float64(int32(time.Now().Unix())-req.BirthAt) / 86400)), PenId: req.PenId, CowKind: req.CowKindId, FatherId: int64(req.FatherId), MotherId: int64(req.MotherId), MatingAt: int64(req.MatingAt), PregnancyCheckAt: int64(req.PregnancyCheckAt), DryMilkAt: int64(req.DryMilkAt), WeaningAt: int64(req.WeaningAt), EstrusAt: int64(req.EstrusAt), EnterAt: int64(req.EnterAt), Remarks: req.Remarks, Weight: int64(req.Weight * 100), Price: int64(req.Price * 100), StaffMemberId: int64(req.StaffMemberId), OperationId: operationId, } } type EventEnterSlice []*EventEnter func (e EventEnterSlice) ToPB() []*pasturePb.EventEnterData { res := make([]*pasturePb.EventEnterData, len(e)) for i, d := range e { res[i] = &pasturePb.EventEnterData{ Id: int32(d.Id), EarNumber: d.EarNumber, CowId: int32(d.CowId), Sex: d.Sex, BirthAt: int32(d.BirthAt), CowSourceId: d.CowSourceId, CowTypeId: d.CowType, BreedStatusId: d.BreedStatus, Lact: d.Lact, PenId: d.PenId, CowKindId: d.CowKind, FatherId: int32(d.FatherId), MotherId: int32(d.MotherId), MatingAt: int32(d.MatingAt), PregnancyCheckAt: int32(d.PregnancyCheckAt), DryMilkAt: int32(d.DryMilkAt), WeaningAt: int32(d.WeaningAt), EstrusAt: int32(d.EstrusAt), EnterAt: int32(d.EnterAt), Weight: float32(d.Weight) / 100, Price: float32(d.Price) / 100, Remarks: d.Remarks, CreatedAt: int32(d.CreatedAt), UpdatedAt: int32(d.UpdatedAt), } } return res }