package model import ( "time" pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow" ) type EventPregnantCheck struct { Id int64 `json:"id"` CowId int64 `json:"cowId"` DayAge int32 `json:"dayAge"` Lact int8 `json:"lact"` MatingAge int32 `json:"matingAge"` PlanDay string `json:"planDay"` RealityDay string `json:"realityDay"` EndDay string `json:"endDay"` PregnantCheckName string `json:"pregnantCheckName"` PregnantCheckResult pasturePb.PregnantCheckResult_Kind `json:"pregnantCheckResult"` PregnantCheckMethod pasturePb.PregnantCheckMethod_Kind `json:"pregnantCheckMethod"` Status pasturePb.IsShow_Kind `json:"status"` OperationId int64 `json:"operationId"` OperationName string `json:"operationName"` Remarks string `json:"remarks"` CreatedAt int64 `json:"createdAt"` UpdatedAt int64 `json:"updatedAt"` } func (e *EventPregnantCheck) TableName() string { return "event_pregnant_check" } func NewEventPregnantCheck(cow *Cow, pregnantCheckAt int64, pregnantCheckName string) *EventPregnantCheck { return &EventPregnantCheck{ CowId: cow.Id, DayAge: cow.GetDayAge(), Lact: int8(cow.Lact), PlanDay: time.Unix(pregnantCheckAt, 0).Format(LayoutTime), EndDay: time.Unix(pregnantCheckAt, 0).Format(LayoutTime), PregnantCheckName: pregnantCheckName, Status: pasturePb.IsShow_No, } } func NewEventPregnantCheckList(cowList []*Cow, pregnantCheckAt int64, pregnantCheckName string) []*EventPregnantCheck { res := make([]*EventPregnantCheck, len(cowList)) for i, cow := range cowList { if cow.BreedStatus != pasturePb.BreedStatus_Breeding { continue } res[i] = NewEventPregnantCheck(cow, pregnantCheckAt, pregnantCheckName) } return res } type EventPregnantCheckSlice []*EventPregnantCheck func (e EventPregnantCheckSlice) ToPB( pregnantCheckResultMap map[pasturePb.PregnantCheckResult_Kind]string, pregnantCheckMethodMap map[pasturePb.PregnantCheckMethod_Kind]string, ) []*pasturePb.SearchPregnantCheckList { result := make([]*pasturePb.SearchPregnantCheckList, len(e)) for i, v := range e { pregnantCheckAt, _ := time.Parse(LayoutTime, v.PlanDay) result[i] = &pasturePb.SearchPregnantCheckList{ Id: int32(v.Id), CowId: int32(v.CowId), DayAge: v.DayAge, Lact: int32(v.Lact), PregnantCheckAt: int32(pregnantCheckAt.Unix()), PregnantCheckResult: v.PregnantCheckResult, PregnantCheckResultName: pregnantCheckResultMap[v.PregnantCheckResult], PregnantCheckMethod: v.PregnantCheckMethod, PregnantCheckMethodName: pregnantCheckMethodMap[v.PregnantCheckMethod], Remarks: v.Remarks, OperationId: int32(v.OperationId), OperationName: v.OperationName, CreatedAt: int32(v.CreatedAt), UpdatedAt: int32(v.UpdatedAt), } } return result } type PregnantCheckHeader struct { Id string `json:"id"` CowId string `json:"cowId"` CowType string `json:"cowType"` DayAge string `json:"dayAge"` Lact string `json:"lact"` PlanDay string `json:"planDay"` PenName string `json:"penName"` CheckName string `json:"checkName"` } type PregnantCheckBody struct { Id int64 `json:"id"` CowId int64 `json:"cowId"` CowType pasturePb.CowType_Kind `json:"cowType"` DayAge int64 `json:"dayAge"` Lact int32 `json:"lact"` PlanDay string `json:"planDay"` PenName string `json:"penName"` CheckName string `json:"checkName"` } func (e EventPregnantCheckSlice) ToPB2() []*PregnantCheckBody { res := make([]*PregnantCheckBody, len(e)) for i, v := range e { res[i] = &PregnantCheckBody{ Id: v.Id, CowId: v.CowId, DayAge: int64(v.DayAge), Lact: int32(v.Lact), PlanDay: v.PlanDay, CheckName: PregnantCheckNameMap[v.PregnantCheckName], } } return res }