package model import ( "kpt-pasture/util" "time" pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow" ) type EventMating struct { Id int64 `json:"id"` PastureId int64 `json:"pastureId"` CowId int64 `json:"cowId"` EarNumber string `json:"earNumber"` DayAge int32 `json:"dayAge"` Lact int32 `json:"lact"` PenId int32 `json:"penId"` PenName string `json:"penName"` 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"` MatingTimes int32 `json:"matingTimes"` MatingResult pasturePb.MatingResult_Kind `json:"matingResult"` MatingResultAt int64 `json:"matingResultAt"` ExposeEstrusType pasturePb.ExposeEstrusType_Kind `json:"exposeEstrusType"` FrozenSemenNumber string `json:"frozenSemenNumber"` OperationId int64 `json:"operationId"` OperationName string `json:"operationName"` MessageId int64 `json:"messageId"` MessageName string `json:"messageName"` Remarks string `json:"remarks"` EventEstrusId int64 `json:"eventEstrusId"` CreatedAt int64 `json:"createdAt"` UpdatedAt int64 `json:"updatedAt"` } func (e *EventMating) TableName() string { return "event_mating" } func (e *EventMating) EventUpdate(matingAt int64, bullNumber string, isReMating bool, operationUser, currentUser *SystemUser) { e.MatingResult = pasturePb.MatingResult_Unknown e.Status = pasturePb.IsShow_Ok e.RealityDay = matingAt e.FrozenSemenNumber = bullNumber e.OperationName = operationUser.Name e.OperationId = operationUser.Id e.MessageName = currentUser.Name e.MessageId = currentUser.Id if !isReMating { e.MatingTimes += 1 } } // EventReMatingUpdate 复配更新 func (e *EventMating) EventReMatingUpdate(matingAt int64) { e.MatingResult = pasturePb.MatingResult_ReMatch e.Status = pasturePb.IsShow_Ok e.MatingResultAt = matingAt } // EventMatingResultUpdate 配种结果更新 func (e *EventMating) EventMatingResultUpdate(matingResult pasturePb.MatingResult_Kind, resultAt int64) { e.MatingResult = matingResult e.MatingResultAt = resultAt } // IsReMating 判断是不是复配 func (e *EventMating) IsReMating(cow *Cow, matingAt int64) bool { lastMatingAt := time.Unix(cow.LastMatingAt, 0) currentMatingAt := time.Unix(matingAt, 0) daysBetween := util.DaysBetween(currentMatingAt.Unix(), lastMatingAt.Unix()) if (daysBetween == 1 || daysBetween == 0) && e.Status == pasturePb.IsShow_Ok && e.MatingResult == pasturePb.MatingResult_Unknown { return true } return false } // IsMatingUpdate 判断是不是更新配种信息 func (e *EventMating) IsMatingUpdate() bool { if e.Status == pasturePb.IsShow_No && e.MatingResult == pasturePb.MatingResult_Unknown { return true } return false } // IsEmptyMating 判断上次配种结果是不是空怀 func (e *EventMating) IsEmptyMating(cow *Cow, matingAt int64) bool { lastMatingAt := time.Unix(cow.LastMatingAt, 0) currentMatingAt := time.Unix(matingAt, 0) daysBetween := util.DaysBetween(currentMatingAt.Unix(), lastMatingAt.Unix()) if (e.MatingResult == pasturePb.MatingResult_Unknown || e.MatingResult == pasturePb.MatingResult_ReMatch) && daysBetween >= 2 { return true } return false } func NewEventMating(pastureId int64, cow *Cow, planDay int64, exposeEstrusType pasturePb.ExposeEstrusType_Kind) *EventMating { return &EventMating{ PastureId: pastureId, CowId: cow.Id, EarNumber: cow.EarNumber, Lact: cow.Lact, PenId: cow.PenId, PenName: cow.PenName, CowType: cow.CowType, CowKind: cow.CowKind, DayAge: cow.DayAge, CalvingAt: cow.LastMatingAt, PlanDay: planDay, EndDay: planDay, MatingResult: pasturePb.MatingResult_Unknown, ExposeEstrusType: exposeEstrusType, Status: pasturePb.IsShow_No, } } // NewEventMatingNaturalEstrus 自然发情的牛只 func NewEventMatingNaturalEstrus(pastureId int64, cow *Cow, req *pasturePb.EventMating, currentUser *SystemUser) *EventMating { return &EventMating{ PastureId: pastureId, CowId: cow.Id, EarNumber: cow.EarNumber, Lact: cow.Lact, DayAge: cow.GetDayAge(), CowType: cow.CowType, CowKind: cow.CowKind, CalvingAt: cow.LastMatingAt, PlanDay: int64(req.MatingAt), RealityDay: int64(req.MatingAt), EndDay: int64(req.MatingAt), MatingResult: pasturePb.MatingResult_Unknown, ExposeEstrusType: pasturePb.ExposeEstrusType_Natural_Estrus, Status: pasturePb.IsShow_Ok, OperationId: int64(req.OperationId), OperationName: req.OperationName, MessageId: currentUser.Id, MessageName: currentUser.Name, FrozenSemenNumber: req.FrozenSemenNumber, Remarks: req.Remarks, MatingTimes: cow.MatingTimes + 1, } } // NewEventMatingList 同期配种 func NewEventMatingList(pastureId int64, cowList []*Cow, planDay int64, exposeEstrusType pasturePb.ExposeEstrusType_Kind) []*EventMating { var matingList []*EventMating for _, cow := range cowList { matingList = append(matingList, NewEventMating(pastureId, cow, planDay, exposeEstrusType)) } 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), EarNumber: v.EarNumber, DayAge: v.DayAge, Lact: 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 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"` Msg string `json:"msg"` 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"` } // MultiFactorPregnancyRateResponse 多维度受胎率 type MultiFactorPregnancyRateResponse struct { Code int32 `json:"code"` Msg string `json:"msg"` Data *MultiFactorPregnancyRateData `json:"data"` } // MultiFactorPregnancyRateList 多维度受胎率分析 type MultiFactorPregnancyRateList struct { StatisticMethod1 string `json:"statisticMethod1"` // 统计方式名称1 (月度、品种) StatisticMethod2 string `json:"statisticMethod2"` // 统计方式名称2 (月度、品种) PregnantRate float32 `json:"pregnantRate"` // 受胎率%(怀孕数 / 怀孕数 + 空怀数) PregnantCount int32 `json:"pregnantCount"` // 怀孕总数 EmptyPregnantCount int32 `json:"emptyPregnantCount"` // 空怀数 OtherCount int32 `json:"otherCount"` // 其他数 (配种后结果未知的个数,小于等于三次配种后,尚未孕检已经淘汰的个数) AbortionCount int32 `json:"abortionCount"` // 流产数 (已经怀孕后流产的个数) TotalCount int32 `json:"totalCount"` // 合计( 怀孕总数+空怀数+其他数) SpcRate float32 `json:"spcRate"` // spc(1 / 受胎率) Months string `json:"months"` // 月份 OperationName string `json:"operationName"` // 配种员名称 Bull string `json:"bull"` // 公牛 Lact string `json:"lact"` // 胎次 MatingTimes string `json:"matingTimes"` // 配次 ExposeEstrusType string `json:"exposeEstrusType"` // 发情揭发方式 Week string `json:"week"` // 周 } type MultiFactorPregnancyRateData struct { Total int32 `json:"total"` PageSize int32 `json:"pageSize"` Page int32 `json:"page"` List []*MultiFactorPregnancyRateList `json:"list"` Chart *MultiFactorPregnancyRateChart `json:"chart"` } type MultiFactorPregnancyRateChart struct { Header []string `json:"header"` // 标题头 PregnantRateMap map[string]map[string]string `json:"pregnantRateMap"` KepMap []string `json:"kepMap"` } type CowPregnantMonth struct { Month string `json:"month"` CowCount int32 `json:"cowCount"` }