|
@@ -22,6 +22,7 @@ type Cow struct {
|
|
|
DayAge int32 `json:"dayAge"` // 日龄
|
|
|
CalvingAge int32 `json:"calvingAge"` // 产后天使
|
|
|
PregnancyAge int32 `json:"pregnancyAge"` // 怀孕天数 孕检结果有阳性更新,产犊后至0
|
|
|
+ MatingAge int32 `json:"matingAge"` // 配种天数
|
|
|
AdmissionAge int32 `json:"admissionAge"` // 入场日龄
|
|
|
AbortionAge int32 `json:"abortionAge"` // 流产天数
|
|
|
LactationAge int32 `json:"lactationAge"` // 泌乳天数
|
|
@@ -50,6 +51,8 @@ type Cow struct {
|
|
|
DeparturePrice float32 `json:"departurePrice"` // 离场价格
|
|
|
DepartureAvgWeight int32 `json:"departureAvgWeight"` // 离场平均体重
|
|
|
FirstMatingAt int64 `json:"firstMatingAt"` // 首次配种时间
|
|
|
+ AllMatingTimes int32 `json:"allMatingTimes"` // 总配次
|
|
|
+ AllAbortionTimes int32 `json:"allAbortionTimes"` // 总流产次数
|
|
|
MatingTimes int32 `json:"matingTimes"` // 配种次数
|
|
|
AbortionTimes int32 `json:"abortionTimes"` // 流产次数
|
|
|
PregnancyCheckName string `json:"pregnancyCheckName"` // 孕检名称
|
|
@@ -86,6 +89,7 @@ func (c *Cow) EventUpdate(weeklyActive int32) {
|
|
|
c.WeeklyActive = weeklyActive
|
|
|
c.LactationAge = c.GetLactationAge()
|
|
|
c.DryMilkAge = c.GetDryMilkAge()
|
|
|
+ c.MatingAge = c.GetMatingAge()
|
|
|
}
|
|
|
|
|
|
// EventCalvingUpdate 产犊更新
|
|
@@ -125,6 +129,7 @@ func (c *Cow) EventAbortionUpdate(abortionAt int64, isLact pasturePb.IsShow_Kind
|
|
|
c.LastAbortionAt = abortionAt
|
|
|
c.BreedStatus = pasturePb.BreedStatus_Abort
|
|
|
c.AbortionTimes += 1
|
|
|
+ c.AllAbortionTimes += 1
|
|
|
if isLact == pasturePb.IsShow_Ok {
|
|
|
c.Lact += 1
|
|
|
}
|
|
@@ -177,7 +182,7 @@ func (c *Cow) EventSaleUpdate(eventSale *EventSale) {
|
|
|
c.NeckRingNumber = ""
|
|
|
c.DeparturePrice = float32(eventSale.SalePrice)
|
|
|
if eventSale.SaleCowCount > 0 {
|
|
|
- c.DepartureAvgWeight = int32(eventSale.SaleAllWeight / eventSale.SaleCowCount)
|
|
|
+ c.DepartureAvgWeight = eventSale.SaleAllWeight / eventSale.SaleCowCount
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -192,6 +197,7 @@ func (c *Cow) EventMatingUpdate(matingAt int64, bullNumber string, isReMating bo
|
|
|
c.BreedStatus = pasturePb.BreedStatus_Breeding
|
|
|
if !isReMating {
|
|
|
c.MatingTimes += 1
|
|
|
+ c.AllMatingTimes += 1
|
|
|
}
|
|
|
if c.Lact == 0 {
|
|
|
c.CowType = pasturePb.CowType_Reserve_Calf
|
|
@@ -237,6 +243,124 @@ func (c *Cow) GetAvgDailyWeight() float32 {
|
|
|
return float32(c.CurrentWeight-c.AdmissionWeight) / 1000 / float32(c.AdmissionAge)
|
|
|
}
|
|
|
|
|
|
+// GetDayAge 日龄
|
|
|
+func (c *Cow) GetDayAge() int32 {
|
|
|
+ if c.BirthAt <= 0 {
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+ return int32(math.Floor(float64(time.Now().Local().Unix()-c.BirthAt) / 86400))
|
|
|
+}
|
|
|
+
|
|
|
+// GetCalvingAge 产后天数
|
|
|
+func (c *Cow) GetCalvingAge() int32 {
|
|
|
+ if c.LastCalvingAt <= 0 {
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+ return int32(math.Floor(float64(time.Now().Local().Unix()-c.LastCalvingAt) / 86400))
|
|
|
+}
|
|
|
+
|
|
|
+// GetDaysPregnant 怀孕天数
|
|
|
+func (c *Cow) GetDaysPregnant() int32 {
|
|
|
+ if c.BreedStatus == pasturePb.BreedStatus_Pregnant &&
|
|
|
+ c.AdmissionStatus == pasturePb.AdmissionStatus_Admission &&
|
|
|
+ c.IsPregnant == pasturePb.IsShow_Ok {
|
|
|
+ return int32(math.Floor(float64(time.Now().Local().Unix()-c.LastMatingAt) / 86400))
|
|
|
+ }
|
|
|
+ return 0
|
|
|
+}
|
|
|
+
|
|
|
+// GetDaysPregnancy 牛只预产日期
|
|
|
+func (c *Cow) GetDaysPregnancy(pregnancyAgeValue int32) int32 {
|
|
|
+ if c.BreedStatus == pasturePb.BreedStatus_Pregnant &&
|
|
|
+ c.AdmissionStatus == pasturePb.AdmissionStatus_Admission &&
|
|
|
+ c.IsPregnant == pasturePb.IsShow_Ok {
|
|
|
+ return int32(math.Floor(float64(c.LastMatingAt + int64(pregnancyAgeValue)*86400)))
|
|
|
+ }
|
|
|
+ return 0
|
|
|
+}
|
|
|
+
|
|
|
+// GetLactationDays 泌乳天数
|
|
|
+func (c *Cow) GetLactationDays() int32 {
|
|
|
+ if c.BreedStatus == pasturePb.BreedStatus_Calving && c.AdmissionStatus == pasturePb.AdmissionStatus_Admission {
|
|
|
+ return int32(math.Floor(float64(time.Now().Local().Unix()-c.LastCalvingAt) / 86400))
|
|
|
+ }
|
|
|
+ return 0
|
|
|
+}
|
|
|
+
|
|
|
+// GetAdmissionAge 入场天数
|
|
|
+func (c *Cow) GetAdmissionAge() int32 {
|
|
|
+ if c.AdmissionAt > 0 && c.AdmissionStatus == pasturePb.AdmissionStatus_Admission {
|
|
|
+ return int32(math.Floor(float64(time.Now().Local().Unix()-c.AdmissionAt) / 86400))
|
|
|
+ }
|
|
|
+ return 0
|
|
|
+}
|
|
|
+
|
|
|
+// GetAverageDailyWeight 平均日增重(最后一次称重 - 入场体重)÷在群天数
|
|
|
+func (c *Cow) GetAverageDailyWeight() float64 {
|
|
|
+ if c.AdmissionAge <= 0 {
|
|
|
+ c.AdmissionAge = c.GetAdmissionAge()
|
|
|
+ }
|
|
|
+
|
|
|
+ if c.AdmissionAge <= 0 {
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+
|
|
|
+ if c.CurrentWeight-c.AdmissionWeight <= 0 {
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+ return float64(c.CurrentWeight-c.AdmissionWeight) / 1000 / float64(c.AdmissionAge)
|
|
|
+}
|
|
|
+
|
|
|
+// GetPreviousStageDailyWeight 上一个阶段日增重
|
|
|
+func (c *Cow) GetPreviousStageDailyWeight() float64 {
|
|
|
+ if c.CurrentWeight-c.LastSecondWeight > 0 && c.LastWeightAt-c.LastSecondWeightAt > 0 {
|
|
|
+ days := int32(math.Floor(float64(c.LastWeightAt-c.LastSecondWeightAt) / 86400))
|
|
|
+ if days <= 0 {
|
|
|
+ return float64(c.CurrentWeight - c.LastSecondWeight)
|
|
|
+ }
|
|
|
+ dayWeight := math.Round(1.0 * float64(c.CurrentWeight-c.LastSecondWeight) / float64(days))
|
|
|
+ return dayWeight / 1000
|
|
|
+ }
|
|
|
+ return 0
|
|
|
+}
|
|
|
+
|
|
|
+// GetAbortionAge 流产天数
|
|
|
+func (c *Cow) GetAbortionAge() int32 {
|
|
|
+ if c.LastAbortionAt > 0 && c.AdmissionStatus == pasturePb.AdmissionStatus_Admission {
|
|
|
+ return int32(math.Floor(float64(time.Now().Local().Unix()-c.LastAbortionAt) / 86400))
|
|
|
+ }
|
|
|
+ return 0
|
|
|
+}
|
|
|
+
|
|
|
+// GetLactationAge 泌乳天数
|
|
|
+func (c *Cow) GetLactationAge() int32 {
|
|
|
+ if c.LastCalvingAt <= 0 {
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+
|
|
|
+ if c.MilkKind == pasturePb.CowMilk_Lactation ||
|
|
|
+ c.BreedStatus == pasturePb.BreedStatus_Calving ||
|
|
|
+ c.BreedStatus == pasturePb.BreedStatus_Abort {
|
|
|
+ return int32(math.Floor(float64(time.Now().Local().Unix()-c.LastCalvingAt) / 86400))
|
|
|
+ }
|
|
|
+ return c.LactationAge
|
|
|
+}
|
|
|
+
|
|
|
+// GetDryMilkAge 干奶天数
|
|
|
+func (c *Cow) GetDryMilkAge() int32 {
|
|
|
+ if c.MilkKind == pasturePb.CowMilk_Dry_Milk {
|
|
|
+ return int32(math.Floor(float64(time.Now().Local().Unix()-c.LastDryMilkAt) / 86400))
|
|
|
+ }
|
|
|
+ return c.DryMilkAge
|
|
|
+}
|
|
|
+
|
|
|
+func (c *Cow) GetMatingAge() int32 {
|
|
|
+ if c.LastMatingAt <= 0 {
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+ return int32(math.Floor(float64(time.Now().Local().Unix()-c.LastMatingAt) / 86400))
|
|
|
+}
|
|
|
+
|
|
|
type CowSlice []*Cow
|
|
|
|
|
|
func (c CowSlice) ToPB(
|
|
@@ -612,117 +736,6 @@ func (b BarCowStructSlice) ToPB(cowTypeMap map[pasturePb.CowType_Kind]string, co
|
|
|
return pb
|
|
|
}
|
|
|
|
|
|
-// GetDayAge 日龄
|
|
|
-func (c *Cow) GetDayAge() int32 {
|
|
|
- if c.BirthAt <= 0 {
|
|
|
- return 0
|
|
|
- }
|
|
|
- return int32(math.Floor(float64(time.Now().Local().Unix()-c.BirthAt) / 86400))
|
|
|
-}
|
|
|
-
|
|
|
-// GetCalvingAge 产后天数
|
|
|
-func (c *Cow) GetCalvingAge() int32 {
|
|
|
- if c.LastCalvingAt <= 0 {
|
|
|
- return 0
|
|
|
- }
|
|
|
- return int32(math.Floor(float64(time.Now().Local().Unix()-c.LastCalvingAt) / 86400))
|
|
|
-}
|
|
|
-
|
|
|
-// GetDaysPregnant 怀孕天数
|
|
|
-func (c *Cow) GetDaysPregnant() int32 {
|
|
|
- if c.BreedStatus == pasturePb.BreedStatus_Pregnant &&
|
|
|
- c.AdmissionStatus == pasturePb.AdmissionStatus_Admission &&
|
|
|
- c.IsPregnant == pasturePb.IsShow_Ok {
|
|
|
- return int32(math.Floor(float64(time.Now().Local().Unix()-c.LastMatingAt) / 86400))
|
|
|
- }
|
|
|
- return 0
|
|
|
-}
|
|
|
-
|
|
|
-// GetDaysPregnancy 牛只预产日期
|
|
|
-func (c *Cow) GetDaysPregnancy(pregnancyAgeValue int32) int32 {
|
|
|
- if c.BreedStatus == pasturePb.BreedStatus_Pregnant &&
|
|
|
- c.AdmissionStatus == pasturePb.AdmissionStatus_Admission &&
|
|
|
- c.IsPregnant == pasturePb.IsShow_Ok {
|
|
|
- return int32(math.Floor(float64(c.LastMatingAt + int64(pregnancyAgeValue)*86400)))
|
|
|
- }
|
|
|
- return 0
|
|
|
-}
|
|
|
-
|
|
|
-// GetLactationDays 泌乳天数
|
|
|
-func (c *Cow) GetLactationDays() int32 {
|
|
|
- if c.BreedStatus == pasturePb.BreedStatus_Calving && c.AdmissionStatus == pasturePb.AdmissionStatus_Admission {
|
|
|
- return int32(math.Floor(float64(time.Now().Local().Unix()-c.LastCalvingAt) / 86400))
|
|
|
- }
|
|
|
- return 0
|
|
|
-}
|
|
|
-
|
|
|
-// GetAdmissionAge 入场天数
|
|
|
-func (c *Cow) GetAdmissionAge() int32 {
|
|
|
- if c.AdmissionAt > 0 && c.AdmissionStatus == pasturePb.AdmissionStatus_Admission {
|
|
|
- return int32(math.Floor(float64(time.Now().Local().Unix()-c.AdmissionAt) / 86400))
|
|
|
- }
|
|
|
- return 0
|
|
|
-}
|
|
|
-
|
|
|
-// GetAverageDailyWeight 平均日增重(最后一次称重 - 入场体重)÷在群天数
|
|
|
-func (c *Cow) GetAverageDailyWeight() float64 {
|
|
|
- if c.AdmissionAge <= 0 {
|
|
|
- c.AdmissionAge = c.GetAdmissionAge()
|
|
|
- }
|
|
|
-
|
|
|
- if c.AdmissionAge <= 0 {
|
|
|
- return 0
|
|
|
- }
|
|
|
-
|
|
|
- if c.CurrentWeight-c.AdmissionWeight <= 0 {
|
|
|
- return 0
|
|
|
- }
|
|
|
- return float64(c.CurrentWeight-c.AdmissionWeight) / 1000 / float64(c.AdmissionAge)
|
|
|
-}
|
|
|
-
|
|
|
-// GetPreviousStageDailyWeight 上一个阶段日增重
|
|
|
-func (c *Cow) GetPreviousStageDailyWeight() float64 {
|
|
|
- if c.CurrentWeight-c.LastSecondWeight > 0 && c.LastWeightAt-c.LastSecondWeightAt > 0 {
|
|
|
- days := int32(math.Floor(float64(c.LastWeightAt-c.LastSecondWeightAt) / 86400))
|
|
|
- if days <= 0 {
|
|
|
- return float64(c.CurrentWeight - c.LastSecondWeight)
|
|
|
- }
|
|
|
- dayWeight := math.Round(1.0 * float64(c.CurrentWeight-c.LastSecondWeight) / float64(days))
|
|
|
- return dayWeight / 1000
|
|
|
- }
|
|
|
- return 0
|
|
|
-}
|
|
|
-
|
|
|
-// GetAbortionAge 流产天数
|
|
|
-func (c *Cow) GetAbortionAge() int32 {
|
|
|
- if c.LastAbortionAt > 0 && c.AdmissionStatus == pasturePb.AdmissionStatus_Admission {
|
|
|
- return int32(math.Floor(float64(time.Now().Local().Unix()-c.LastAbortionAt) / 86400))
|
|
|
- }
|
|
|
- return 0
|
|
|
-}
|
|
|
-
|
|
|
-// GetLactationAge 泌乳天数
|
|
|
-func (c *Cow) GetLactationAge() int32 {
|
|
|
- if c.LastCalvingAt <= 0 {
|
|
|
- return 0
|
|
|
- }
|
|
|
-
|
|
|
- if c.MilkKind == pasturePb.CowMilk_Lactation ||
|
|
|
- c.BreedStatus == pasturePb.BreedStatus_Calving ||
|
|
|
- c.BreedStatus == pasturePb.BreedStatus_Abort {
|
|
|
- return int32(math.Floor(float64(time.Now().Local().Unix()-c.LastCalvingAt) / 86400))
|
|
|
- }
|
|
|
- return c.LactationAge
|
|
|
-}
|
|
|
-
|
|
|
-// GetDryMilkAge 干奶天数
|
|
|
-func (c *Cow) GetDryMilkAge() int32 {
|
|
|
- if c.MilkKind == pasturePb.CowMilk_Dry_Milk {
|
|
|
- return int32(math.Floor(float64(time.Now().Local().Unix()-c.LastDryMilkAt) / 86400))
|
|
|
- }
|
|
|
- return c.DryMilkAge
|
|
|
-}
|
|
|
-
|
|
|
type CowWeightRange struct {
|
|
|
WeightRange string `json:"weight_range"`
|
|
|
Count int32 `json:"count"`
|