package model import ( "kpt-pasture/util" "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 int64 `json:"planDay"` RealityDay int64 `json:"realityDay"` EndDay int64 `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, pregnantCheckName string) *EventPregnantCheck { return &EventPregnantCheck{ CowId: cow.Id, DayAge: cow.GetDayAge(), Lact: int8(cow.Lact), PlanDay: util.TimeParseLocalUnix(time.Now().Format(LayoutDate2)), EndDay: util.TimeParseLocalEndUnix(time.Now().Format(LayoutDate2)), PregnantCheckName: pregnantCheckName, Status: pasturePb.IsShow_No, } } func NewEventPregnantCheckList(cowList []*Cow, pregnantCheckName string) []*EventPregnantCheck { res := make([]*EventPregnantCheck, len(cowList)) for i, cow := range cowList { if cow.BreedStatus != pasturePb.BreedStatus_Breeding { continue } res[i] = NewEventPregnantCheck(cow, 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 { result[i] = &pasturePb.SearchPregnantCheckList{ Id: int32(v.Id), CowId: int32(v.CowId), DayAge: v.DayAge, Lact: int32(v.Lact), PregnantCheckAt: int32(v.PlanDay), 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: time.Unix(v.PlanDay, 0).Format(LayoutDate2), CheckName: PregnantCheckNameMap[v.PregnantCheckName], } } return res }