package model import ( "time" pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow" ) type EventMating struct { Id int64 `json:"id"` CowId int64 `json:"cowId"` DayAge int32 `json:"dayAge"` Lact int32 `json:"lact"` CowType pasturePb.CowType_Kind `json:"cowType"` CowKind pasturePb.CowKind_Kind `json:"cowKind"` CalvingAge int32 `json:"calvingAge"` PlanDay int64 `json:"planDay"` EndDay int64 `json:"endDay"` CalvingAt int64 `json:"calvingAt"` RealityDay int64 `json:"realityDay"` Status pasturePb.IsShow_Kind `json:"status"` MatingNumber int64 `json:"matingNumber"` MatingResult pasturePb.MatingResult_Kind `json:"matingResult"` MatingResultAt int64 `json:"matingResultAt"` ExposeEstrusType pasturePb.ExposeEstrusType_Kind `json:"exposeEstrusType"` FrozenSemenNumber string `json:"frozenSemenNumber"` FrozenSemenCount int32 `json:"frozenSemenCount"` OperationId int64 `json:"operationId"` OperationName string `json:"operationName"` MessageId int64 `json:"messageId"` MessageName string `json:"messageName"` Remarks string `json:"remarks"` CreatedAt int64 `json:"createdAt"` UpdatedAt int64 `json:"updatedAt"` } func (e *EventMating) TableName() string { return "event_mating" } func NewEventMating(cow *Cow, planDay int64) *EventMating { return &EventMating{ CowId: cow.Id, Lact: cow.Lact, CowType: cow.CowType, CowKind: cow.CowKind, CalvingAt: cow.CalvingAt, PlanDay: planDay, EndDay: planDay, MatingResult: pasturePb.MatingResult_Invalid, ExposeEstrusType: pasturePb.ExposeEstrusType_Same_Time, Status: pasturePb.IsShow_No, } } // NewEventMating2 自然发情的牛只 func NewEventMating2(cow *Cow, req *pasturePb.EventMating) *EventMating { return &EventMating{ CowId: cow.Id, Lact: cow.Lact, DayAge: cow.GetDayAge(), CowType: cow.CowType, CowKind: cow.CowKind, CalvingAt: cow.CalvingAt, PlanDay: int64(req.MatingAt), RealityDay: int64(req.MatingAt), EndDay: int64(req.MatingAt), MatingResult: pasturePb.MatingResult_Invalid, ExposeEstrusType: pasturePb.ExposeEstrusType_Natural_Estrus, Status: pasturePb.IsShow_Ok, MatingNumber: 1, OperationId: int64(req.OperationId), OperationName: req.OperationName, FrozenSemenNumber: req.FrozenSemenNumber, FrozenSemenCount: req.FrozenSemenCount, Remarks: req.Remarks, } } func NewEventMatingList(cowList []*Cow, planDay int64) []*EventMating { var matingList []*EventMating for _, cow := range cowList { matingList = append(matingList, NewEventMating(cow, planDay)) } return matingList } type EventMatingSlice []*EventMating func (e EventMatingSlice) ToPB(exposeEstrusTypeMap map[pasturePb.ExposeEstrusType_Kind]string) []*pasturePb.SearchMatingList { res := make([]*pasturePb.SearchMatingList, len(e)) for i, v := range e { res[i] = &pasturePb.SearchMatingList{ Id: int32(v.Id), CowId: int32(v.CowId), DayAge: int32(v.DayAge), Lact: int32(v.Lact), CalvingAge: v.CalvingAge, PlanDay: time.Unix(v.PlanDay, 0).Format(LayoutDate2), RealityDay: time.Unix(v.RealityDay, 0).Format(LayoutDate2), ExposeEstrusType: v.ExposeEstrusType, ExposeEstrusTypeName: exposeEstrusTypeMap[v.ExposeEstrusType], FrozenSemenNumber: v.FrozenSemenNumber, Remarks: v.Remarks, OperationId: int32(v.OperationId), OperationName: v.OperationName, CreatedAt: int32(v.CreatedAt), UpdatedAt: int32(v.UpdatedAt), } } return res } type CowMatingHeader struct { Id string `json:"id"` CowId string `json:"cowId"` PlanDay string `json:"planDay"` Lact string `json:"lact"` Status string `json:"status"` BreedStatusName string `json:"breedStatusName"` BreedStatus string `json:"breedStatus"` CowTypeName string `json:"cowTypeName"` PenName string `json:"penName"` DayAge string `json:"dayAge"` CalvingAge string `json:"calvingAge"` AbortionAge string `json:"abortionAge"` } type CowMatingBody struct { Id int64 `json:"id"` CowId int64 `json:"cowId"` BreedStatus pasturePb.BreedStatus_Kind `json:"breedStatus"` BreedStatusName string `json:"breedStatusName"` CowType pasturePb.CowType_Kind `json:"cowType"` CowTypeName string `json:"cowTypeName"` PenId int32 `json:"penId"` PenName string `json:"penName"` Lact int32 `json:"lact"` CalvingAge int32 `json:"calvingAge"` AbortionAge int32 `json:"abortionAge"` DayAge int32 `json:"dayAge"` Status pasturePb.IsShow_Kind `json:"status"` } type CowMatingBodySlice []*CowMatingBody func (s CowMatingBodySlice) ToPB( cowTypeMap map[pasturePb.CowType_Kind]string, breedStatusMap map[pasturePb.BreedStatus_Kind]string, penMap map[int32]*Pen, ) []*CowMatingBody { res := make([]*CowMatingBody, len(s)) for i, v := range s { res[i] = &CowMatingBody{ Id: v.Id, CowId: v.CowId, CowType: v.CowType, CowTypeName: cowTypeMap[v.CowType], BreedStatus: v.BreedStatus, BreedStatusName: breedStatusMap[v.BreedStatus], PenName: penMap[v.PenId].Name, PenId: v.PenId, Lact: v.Lact, CalvingAge: v.CalvingAge, AbortionAge: v.AbortionAge, DayAge: v.DayAge, Status: v.Status, } } return res } type MatingTimelyChart struct { CalvingAge int32 `json:"calvingAge"` RealityDay string `json:"realityDay"` LactGroup string `json:"lactGroup"` } func (e EventMatingSlice) ToPB2() []*pasturePb.CowList { res := make([]*pasturePb.CowList, len(e)) for i, v := range e { calvingAt, matingAtFormat := "", "" if v.CalvingAt > 0 { calvingAt = time.Unix(v.CalvingAt, 0).Format(LayoutDate2) } if v.RealityDay > 0 { matingAtFormat = time.Unix(v.RealityDay, 0).Format(LayoutDate2) } res[i] = &pasturePb.CowList{ CowId: int32(v.CowId), DayAge: int32(v.DayAge), CalvingAge: v.CalvingAge, MatingAtFormat: matingAtFormat, CalvingAtFormat: calvingAt, Lact: int32(v.Lact), } } return res } type MatingTimelyResponse struct { Code int32 `json:"code"` Message string `json:"message"` Data *MatingTimelyData `json:"data"` } type MatingTimelyData struct { CowList []*pasturePb.CowList `json:"cowList"` Chart *CowMatingChart `json:"chart"` } type CowMatingChart struct { Lact0 [][]string `json:"lact0"` Lact1 [][]string `json:"lact1"` Lact2 [][]string `json:"lact2"` Lact3 [][]string `json:"lact3"` }