|
@@ -1,13 +1,13 @@
|
|
|
package model
|
|
|
|
|
|
import (
|
|
|
- "fmt"
|
|
|
"math"
|
|
|
"time"
|
|
|
|
|
|
pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
|
|
|
)
|
|
|
|
|
|
+const NeckRingDataDays = 50 // 默认获取50天的脖环数据
|
|
|
type Cow struct {
|
|
|
Id int64 `json:"id"`
|
|
|
PastureId int64 `json:"pastureId"` // 牧场id
|
|
@@ -576,410 +576,3 @@ func (c CowSlice) ToPB(
|
|
|
}
|
|
|
return res
|
|
|
}
|
|
|
-
|
|
|
-func (c CowSlice) ToPB2(penWeightSlice PenWeightSlice) []*pasturePb.CowList {
|
|
|
- res := make([]*pasturePb.CowList, len(c))
|
|
|
- for i, v := range c {
|
|
|
- penWeight := penWeightSlice.GetPenWeight(v.PenId)
|
|
|
- penAvgWeight := float32(0)
|
|
|
- cowPenAvgWeightDiffValue := float32(0)
|
|
|
-
|
|
|
- if penWeight != nil {
|
|
|
- penAvgWeight = float32(penWeight.AvgWeight) / 1000
|
|
|
- cowPenAvgWeightDiffValue = float32(v.CurrentWeight-int64(penWeight.AvgWeight)) / 1000
|
|
|
- }
|
|
|
-
|
|
|
- res[i] = &pasturePb.CowList{
|
|
|
- CowId: int32(v.Id),
|
|
|
- DayAge: v.DayAge,
|
|
|
- AverageDailyWeightGain: float32(v.GetAverageDailyWeight()),
|
|
|
- EarNumber: v.EarNumber,
|
|
|
- PenName: v.PenName,
|
|
|
- BirthAt: int32(v.BirthAt),
|
|
|
- BirthWeight: float32(v.BirthWeight) / 1000,
|
|
|
- CurrentWeight: float32(v.CurrentWeight) / 1000,
|
|
|
- LastWeightAt: int32(v.LastWeightAt),
|
|
|
- AdmissionAge: v.AdmissionAge,
|
|
|
- AdmissionWeight: float32(v.AbortionAge) / 1000,
|
|
|
- PreviousStageDailyWeight: float32(v.GetPreviousStageDailyWeight()),
|
|
|
- PenAvgWeight: penAvgWeight,
|
|
|
- CowPenAvgWeightDiffValue: cowPenAvgWeightDiffValue,
|
|
|
- }
|
|
|
- }
|
|
|
- return res
|
|
|
-}
|
|
|
-
|
|
|
-// NewEnterCow 入场新增牛只
|
|
|
-func NewEnterCow(pastureId int64, req *pasturePb.EventEnterRequest, penMap map[int32]*Pen) *Cow {
|
|
|
- var isPregnant = pasturePb.IsShow_No
|
|
|
- if req.BreedStatus == pasturePb.BreedStatus_Pregnant {
|
|
|
- isPregnant = pasturePb.IsShow_Ok
|
|
|
- }
|
|
|
-
|
|
|
- admissionAt := int64(0)
|
|
|
- switch req.CowSource {
|
|
|
- case pasturePb.CowSource_Calving:
|
|
|
- admissionAt = int64(req.BirthAt)
|
|
|
- case pasturePb.CowSource_Transfer_In:
|
|
|
- admissionAt = int64(req.EnterAt)
|
|
|
- case pasturePb.CowSource_Buy:
|
|
|
- admissionAt = int64(req.EnterAt)
|
|
|
- }
|
|
|
-
|
|
|
- breedStatus := pasturePb.BreedStatus_Invalid
|
|
|
- isForbiddenMating := pasturePb.IsShow_No
|
|
|
- cowType := pasturePb.CowType_Invalid
|
|
|
- if req.Sex == pasturePb.Genders_Female {
|
|
|
-
|
|
|
- if req.Lact == 0 && req.MatingAt <= 0 {
|
|
|
- breedStatus = pasturePb.BreedStatus_UnBreed
|
|
|
- cowType = pasturePb.CowType_Reserve_Calf
|
|
|
- }
|
|
|
-
|
|
|
- if req.MatingAt > 0 && (req.PregnantCheckResult != pasturePb.PregnantCheckResult_Pregnant &&
|
|
|
- req.PregnantCheckResult != pasturePb.PregnantCheckResult_UnPregnant) &&
|
|
|
- req.MatingAt >= req.CalvingAt && req.MatingAt >= req.AbortionAt {
|
|
|
- breedStatus = pasturePb.BreedStatus_Breeding
|
|
|
- if req.Lact == 0 {
|
|
|
- cowType = pasturePb.CowType_Reserve_Calf
|
|
|
- } else {
|
|
|
- cowType = pasturePb.CowType_Breeding_Calf
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if req.MatingAt > 0 && req.PregnantCheckResult == pasturePb.PregnantCheckResult_Pregnant &&
|
|
|
- req.MatingAt >= req.CalvingAt && req.MatingAt >= req.AbortionAt {
|
|
|
- breedStatus = pasturePb.BreedStatus_Pregnant
|
|
|
- if req.Lact == 0 {
|
|
|
- cowType = pasturePb.CowType_Reserve_Calf
|
|
|
- } else {
|
|
|
- cowType = pasturePb.CowType_Breeding_Calf
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if req.MatingAt > 0 && req.PregnantCheckResult == pasturePb.PregnantCheckResult_UnPregnant &&
|
|
|
- req.MatingAt >= req.CalvingAt && req.MatingAt >= req.AbortionAt {
|
|
|
- breedStatus = pasturePb.BreedStatus_Empty
|
|
|
- if req.Lact == 0 {
|
|
|
- cowType = pasturePb.CowType_Reserve_Calf
|
|
|
- } else {
|
|
|
- cowType = pasturePb.CowType_Breeding_Calf
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if req.CalvingAt > 0 && req.CalvingAt >= req.MatingAt && req.CalvingAt >= req.AbortionAt {
|
|
|
- breedStatus = pasturePb.BreedStatus_Calving
|
|
|
- cowType = pasturePb.CowType_Breeding_Calf
|
|
|
- }
|
|
|
-
|
|
|
- if req.AbortionAt > 0 && req.AbortionAt >= req.CalvingAt && req.AbortionAt >= req.MatingAt {
|
|
|
- breedStatus = pasturePb.BreedStatus_Abort
|
|
|
- cowType = pasturePb.CowType_Breeding_Calf
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if breedStatus == pasturePb.BreedStatus_No_Mating {
|
|
|
- isForbiddenMating = pasturePb.IsShow_Ok
|
|
|
- }
|
|
|
-
|
|
|
- cow := &Cow{
|
|
|
- PastureId: pastureId,
|
|
|
- Sex: req.Sex,
|
|
|
- EarNumber: req.EarNumber,
|
|
|
- PenId: req.PenId,
|
|
|
- PenName: penMap[req.PenId].Name,
|
|
|
- Lact: req.Lact,
|
|
|
- CowType: cowType,
|
|
|
- BreedStatus: breedStatus,
|
|
|
- CowKind: req.CowKind,
|
|
|
- SourceKind: req.CowSource,
|
|
|
- FatherNumber: req.FatherNumber,
|
|
|
- MotherNumber: req.MotherNumber,
|
|
|
- AdmissionStatus: pasturePb.AdmissionStatus_Admission,
|
|
|
- HealthStatus: pasturePb.HealthStatus_Health,
|
|
|
- PurposeKind: req.PurposeKind,
|
|
|
- EleEarNumber: req.EleEarNumber,
|
|
|
- IsPregnant: isPregnant,
|
|
|
- IsForbiddenMating: isForbiddenMating,
|
|
|
- WeaningAt: int64(req.WeaningAt),
|
|
|
- BirthAt: int64(req.BirthAt),
|
|
|
- AdmissionWeight: int64(req.Weight * 1000),
|
|
|
- FirstMatingAt: int64(req.MatingAt),
|
|
|
- LastMatingAt: int64(req.MatingAt),
|
|
|
- LastPregnantCheckAt: int64(req.PregnancyCheckAt),
|
|
|
- AdmissionAt: admissionAt,
|
|
|
- BirthWeight: int64(req.Weight * 1000),
|
|
|
- LastWeightAt: int64(req.EstrusAt),
|
|
|
- CurrentWeight: int64(req.Weight * 1000),
|
|
|
- LastDryMilkAt: int64(req.DryMilkAt),
|
|
|
- MatingTimes: req.MatingTimes,
|
|
|
- LastCalvingAt: int64(req.CalvingAt),
|
|
|
- LastBullNumber: req.BullNumber,
|
|
|
- LastAbortionAt: int64(req.AbortionAt),
|
|
|
- AdmissionPrice: req.Price,
|
|
|
- BatchNumber: req.BatchNumber,
|
|
|
- NeckRingNumber: req.NeckRingNumber,
|
|
|
- }
|
|
|
- cow.AdmissionAge = cow.GetAdmissionAge()
|
|
|
- cow.DayAge = cow.GetDayAge()
|
|
|
- return cow
|
|
|
-}
|
|
|
-
|
|
|
-// NewCalfCow 产犊新增
|
|
|
-func NewCalfCow(matherInfo *Cow, calf *CalvingCalf) *Cow {
|
|
|
- return &Cow{
|
|
|
- PastureId: calf.PastureId,
|
|
|
- Sex: calf.Sex,
|
|
|
- EarNumber: calf.EarNumber,
|
|
|
- PenId: calf.PenId,
|
|
|
- PenName: calf.PenName,
|
|
|
- CowType: pasturePb.CowType_Lactating_Calf, // 哺乳犊牛
|
|
|
- BreedStatus: pasturePb.BreedStatus_UnBreed, // 未配
|
|
|
- CowKind: matherInfo.CowKind, // 牛只品种
|
|
|
- BirthWeight: calf.BirthWeight,
|
|
|
- BirthAt: calf.BirthAt,
|
|
|
- SourceKind: pasturePb.CowSource_Calving, // 产犊方式
|
|
|
- FatherNumber: matherInfo.LastBullNumber,
|
|
|
- MotherNumber: matherInfo.EarNumber,
|
|
|
- AdmissionStatus: pasturePb.AdmissionStatus_Admission,
|
|
|
- IsPregnant: pasturePb.IsShow_No,
|
|
|
- AdmissionAt: calf.BirthAt,
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-// ExcelEnterCow excel导入入场新增牛只
|
|
|
-func ExcelEnterCow(pastureId int64, req *pasturePb.EventEnterRequest) *Cow {
|
|
|
- var isPregnant = pasturePb.IsShow_No
|
|
|
- if req.BreedStatus == pasturePb.BreedStatus_Pregnant {
|
|
|
- isPregnant = pasturePb.IsShow_Ok
|
|
|
- }
|
|
|
-
|
|
|
- admissionAt := int64(0)
|
|
|
- switch req.CowSource {
|
|
|
- case pasturePb.CowSource_Calving:
|
|
|
- admissionAt = int64(req.BirthAt)
|
|
|
- case pasturePb.CowSource_Transfer_In:
|
|
|
- admissionAt = int64(req.EnterAt)
|
|
|
- case pasturePb.CowSource_Buy:
|
|
|
- admissionAt = int64(req.EnterAt)
|
|
|
- }
|
|
|
-
|
|
|
- breedStatus := pasturePb.BreedStatus_Invalid
|
|
|
- if req.Sex == pasturePb.Genders_Female {
|
|
|
- if req.Lact == 0 && req.MatingAt <= 0 {
|
|
|
- breedStatus = pasturePb.BreedStatus_UnBreed
|
|
|
- }
|
|
|
-
|
|
|
- if req.MatingAt > 0 && (req.PregnantCheckResult != pasturePb.PregnantCheckResult_Pregnant &&
|
|
|
- req.PregnantCheckResult != pasturePb.PregnantCheckResult_UnPregnant) &&
|
|
|
- req.MatingAt >= req.CalvingAt && req.MatingAt >= req.AbortionAt {
|
|
|
- breedStatus = pasturePb.BreedStatus_Breeding
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- if req.MatingAt > 0 && req.PregnantCheckResult == pasturePb.PregnantCheckResult_Pregnant &&
|
|
|
- req.MatingAt >= req.CalvingAt && req.MatingAt >= req.AbortionAt {
|
|
|
- breedStatus = pasturePb.BreedStatus_Pregnant
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- if req.MatingAt > 0 && req.PregnantCheckResult == pasturePb.PregnantCheckResult_UnPregnant &&
|
|
|
- req.MatingAt >= req.CalvingAt && req.MatingAt >= req.AbortionAt {
|
|
|
- breedStatus = pasturePb.BreedStatus_Empty
|
|
|
- }
|
|
|
-
|
|
|
- if req.CalvingAt > 0 && req.CalvingAt >= req.MatingAt && req.CalvingAt >= req.AbortionAt {
|
|
|
- breedStatus = pasturePb.BreedStatus_Calving
|
|
|
- }
|
|
|
-
|
|
|
- if req.AbortionAt > 0 && req.AbortionAt >= req.CalvingAt && req.AbortionAt >= req.MatingAt {
|
|
|
- breedStatus = pasturePb.BreedStatus_Abort
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- cow := &Cow{
|
|
|
- PastureId: pastureId,
|
|
|
- Sex: req.Sex,
|
|
|
- EarNumber: req.EarNumber,
|
|
|
- PenId: req.PenId,
|
|
|
- PenName: req.PenName,
|
|
|
- Lact: req.Lact,
|
|
|
- CowType: req.CowType,
|
|
|
- BreedStatus: breedStatus,
|
|
|
- CowKind: req.CowKind,
|
|
|
- SourceKind: req.CowSource,
|
|
|
- FatherNumber: req.FatherNumber,
|
|
|
- MotherNumber: req.MotherNumber,
|
|
|
- AdmissionStatus: pasturePb.AdmissionStatus_Admission,
|
|
|
- HealthStatus: pasturePb.HealthStatus_Health,
|
|
|
- PurposeKind: req.PurposeKind,
|
|
|
- EleEarNumber: req.EleEarNumber,
|
|
|
- IsPregnant: isPregnant,
|
|
|
- IsForbiddenMating: req.IsForbiddenMatingKind,
|
|
|
- WeaningAt: int64(req.WeaningAt),
|
|
|
- BirthAt: int64(req.BirthAt),
|
|
|
- AdmissionWeight: int64(req.Weight * 1000),
|
|
|
- FirstMatingAt: int64(req.MatingAt),
|
|
|
- LastMatingAt: int64(req.MatingAt),
|
|
|
- LastPregnantCheckAt: int64(req.PregnancyCheckAt),
|
|
|
- AdmissionAt: admissionAt,
|
|
|
- BirthWeight: int64(req.Weight * 1000),
|
|
|
- LastWeightAt: int64(req.EstrusAt),
|
|
|
- CurrentWeight: int64(req.Weight * 1000),
|
|
|
- LastDryMilkAt: int64(req.DryMilkAt),
|
|
|
- MatingTimes: req.MatingTimes,
|
|
|
- LastCalvingAt: int64(req.CalvingAt),
|
|
|
- LastBullNumber: req.BullNumber,
|
|
|
- LastAbortionAt: int64(req.AbortionAt),
|
|
|
- AdmissionPrice: req.Price,
|
|
|
- BatchNumber: req.BatchNumber,
|
|
|
- NeckRingNumber: req.NeckRingNumber,
|
|
|
- }
|
|
|
- cow.AdmissionAge = cow.GetAdmissionAge()
|
|
|
- cow.DayAge = cow.GetDayAge()
|
|
|
- return cow
|
|
|
-}
|
|
|
-
|
|
|
-type BarCowStruct struct {
|
|
|
- Number int32 `json:"number"`
|
|
|
- TypeId pasturePb.CowType_Kind `json:"type_id"`
|
|
|
-}
|
|
|
-
|
|
|
-// BarCowStructSlice 首页牛群结构
|
|
|
-type BarCowStructSlice []*BarCowStruct
|
|
|
-
|
|
|
-func (b BarCowStructSlice) ToPB(cowTypeMap map[pasturePb.CowType_Kind]string, count int32) []*pasturePb.BarCowStruct {
|
|
|
- var pb []*pasturePb.BarCowStruct
|
|
|
- for _, v := range b {
|
|
|
- name := fmt.Sprintf("%s", cowTypeMap[v.TypeId])
|
|
|
- pb = append(pb, &pasturePb.BarCowStruct{Name: name, Value: v.Number})
|
|
|
- }
|
|
|
- return pb
|
|
|
-}
|
|
|
-
|
|
|
-type CowWeightRange struct {
|
|
|
- WeightRange string `json:"weight_range"`
|
|
|
- Count int32 `json:"count"`
|
|
|
-}
|
|
|
-
|
|
|
-func (c CowSlice) WeightRangeToPB(penMap map[int32]*Pen) []*pasturePb.CowList {
|
|
|
- res := make([]*pasturePb.CowList, len(c))
|
|
|
- for i, v := range c {
|
|
|
- penName := ""
|
|
|
- if pen, ok := penMap[v.PenId]; ok {
|
|
|
- penName = pen.Name
|
|
|
- }
|
|
|
- res[i] = &pasturePb.CowList{
|
|
|
- CowId: int32(v.Id),
|
|
|
- DayAge: v.DayAge,
|
|
|
- AverageDailyWeightGain: float32(v.GetAverageDailyWeight()),
|
|
|
- PreviousStageDailyWeight: float32(v.GetPreviousStageDailyWeight()),
|
|
|
- EarNumber: v.EarNumber,
|
|
|
- PenName: penName,
|
|
|
- BirthAt: int32(v.BirthAt),
|
|
|
- BirthWeight: float32(v.BirthWeight) / 1000,
|
|
|
- CurrentWeight: float32(v.CurrentWeight) / 1000,
|
|
|
- LastWeightAt: int32(v.LastWeightAt),
|
|
|
- AdmissionAge: v.AdmissionAge,
|
|
|
- }
|
|
|
- }
|
|
|
- return res
|
|
|
-}
|
|
|
-
|
|
|
-func (c CowSlice) LongTermInfertilityToPB(breedStatusMap map[pasturePb.BreedStatus_Kind]string) []*pasturePb.LongTermInfertility {
|
|
|
- res := make([]*pasturePb.LongTermInfertility, len(c))
|
|
|
- for i, v := range c {
|
|
|
- breedStatusName := ""
|
|
|
- if breedStatus, ok := breedStatusMap[v.BreedStatus]; ok {
|
|
|
- breedStatusName = breedStatus
|
|
|
- }
|
|
|
- lastCalvingAtFormat := ""
|
|
|
- if v.LastCalvingAt > 0 {
|
|
|
- lastCalvingAtFormat = time.Unix(v.LastCalvingAt, 0).Local().Format(LayoutDate2)
|
|
|
- }
|
|
|
- lastAbortionAtFormat := ""
|
|
|
- if v.LastAbortionAt > 0 {
|
|
|
- lastAbortionAtFormat = time.Unix(v.LastAbortionAt, 0).Local().Format(LayoutDate2)
|
|
|
- }
|
|
|
- lastMatingAtFormat := ""
|
|
|
- if v.LastMatingAt > 0 {
|
|
|
- lastMatingAtFormat = time.Unix(v.LastMatingAt, 0).Local().Format(LayoutDate2)
|
|
|
- }
|
|
|
- res[i] = &pasturePb.LongTermInfertility{
|
|
|
- CowId: int32(v.Id),
|
|
|
- EarNumber: v.EarNumber,
|
|
|
- Lact: v.Lact,
|
|
|
- PenId: v.PenId,
|
|
|
- CalvingAge: v.CalvingAge,
|
|
|
- PenName: v.PenName,
|
|
|
- BreedStatusName: breedStatusName,
|
|
|
- BreedStatus: v.BreedStatus,
|
|
|
- LastCalvingAtFormat: lastCalvingAtFormat,
|
|
|
- LastAbortionAtFormat: lastAbortionAtFormat,
|
|
|
- LastMatingAtFormat: lastMatingAtFormat,
|
|
|
- MatingTimes: v.MatingTimes,
|
|
|
- LastBullNumber: v.LastBullNumber,
|
|
|
- AbortionTimes: v.AbortionTimes,
|
|
|
- }
|
|
|
- }
|
|
|
- return res
|
|
|
-}
|
|
|
-
|
|
|
-func (c CowSlice) CanSaleToPB(cowKindMap map[pasturePb.CowKind_Kind]string) []*pasturePb.CanSalesReport {
|
|
|
- res := make([]*pasturePb.CanSalesReport, len(c))
|
|
|
- for i, v := range c {
|
|
|
- cowKindName, lastWeightAtFormat, admissionAtFormat := "", "", ""
|
|
|
- if name, ok := cowKindMap[v.CowKind]; ok {
|
|
|
- cowKindName = name
|
|
|
- }
|
|
|
- if v.LastWeightAt > 0 {
|
|
|
- lastWeightAtFormat = time.Unix(v.LastWeightAt, 0).Local().Format(LayoutDate2)
|
|
|
- }
|
|
|
- if v.AdmissionAt > 0 {
|
|
|
- admissionAtFormat = time.Unix(v.AdmissionAt, 0).Local().Format(LayoutDate2)
|
|
|
- }
|
|
|
- res[i] = &pasturePb.CanSalesReport{
|
|
|
- CowId: int32(v.Id),
|
|
|
- EarNumber: v.EarNumber,
|
|
|
- BatchNumber: v.BatchNumber,
|
|
|
- CowKindName: cowKindName,
|
|
|
- PenName: v.PenName,
|
|
|
- Weight: float32(v.CurrentWeight) / 1000,
|
|
|
- AdmissionAge: v.AdmissionAge,
|
|
|
- EnterWeight: 0,
|
|
|
- EnterPrice: 0,
|
|
|
- LastWeightAtFormat: lastWeightAtFormat,
|
|
|
- DayAvgFeedCost: 0,
|
|
|
- AllFeedCost: 0,
|
|
|
- AllMedicalCharge: 0,
|
|
|
- OtherCost: 0,
|
|
|
- ProfitAndLoss: 0,
|
|
|
- AdmissionAtFormat: admissionAtFormat,
|
|
|
- DayAvgWeight: 0,
|
|
|
- }
|
|
|
- }
|
|
|
- return res
|
|
|
-}
|
|
|
-
|
|
|
-// CowBehaviorCurveResponse 脖环行为数据
|
|
|
-type CowBehaviorCurveResponse struct {
|
|
|
- Code int32 `json:"code"`
|
|
|
- Msg string `json:"msg"`
|
|
|
- Data *CowBehaviorCurveData `json:"data"`
|
|
|
-}
|
|
|
-
|
|
|
-type CowBehaviorCurveData struct {
|
|
|
- OriginalDateList []int32 `json:"originalDateList"` // 原始行为数据
|
|
|
- ChangeDateList []int32 `json:"changeDateList"` // 变化数据
|
|
|
- SumDateList []int32 `json:"sumDateList"` // 累计24小时数据
|
|
|
- SumChewList []int32 `json:"sumChewList"` // 累计24小时咀嚼
|
|
|
- DateTimeList []string `json:"dateTimeList"` // 时间数据
|
|
|
- EstrusList map[pasturePb.EstrusLevel_Kind][]string `json:"estrusList"` // 发情预警
|
|
|
- EventList []*pasturePb.CowEvent `json:"eventList"` // 事件数据
|
|
|
- EventMap map[pasturePb.EventType_Kind]string `json:"eventMap"` // 所有事件
|
|
|
- RuminaChange []int32 `json:"ruminaChange"` // 反刍变化
|
|
|
- LowActivity int32 `json:"lowActivity"` // 低活动量参数
|
|
|
- MiddleActivity int32 `json:"middleActivity"` // 中活动量行数
|
|
|
- IQR1 []int32 `json:"IQR1"` // 1IQR
|
|
|
- IQR3 []int32 `json:"IQR3"` // 3IQR
|
|
|
-}
|