|
@@ -46,9 +46,12 @@ type Cow struct {
|
|
|
BirthAt int64 `json:"birthAt"` // 出生时间
|
|
|
AdmissionAt int64 `json:"admissionAt"` // 入场时间
|
|
|
DepartureAt int64 `json:"departureAt"` // 离场时间
|
|
|
+ DeparturePrice float32 `json:"departurePrice"` // 离场价格
|
|
|
+ DepartureAvgWeight int32 `json:"departureAvgWeight"` // 离场平均体重
|
|
|
FirstMatingAt int64 `json:"firstMatingAt"` // 首次配种时间
|
|
|
MatingTimes int32 `json:"matingTimes"` // 配种次数
|
|
|
AbortionTimes int32 `json:"abortionTimes"` // 流产次数
|
|
|
+ PregnancyCheckName string `json:"pregnancyCheckName"` // 孕检名称
|
|
|
WeeklyActive int32 `json:"weeklyActive"` // 每周活跃度
|
|
|
LastEstrusAt int64 `json:"lastEstrusAt"` // 最后一次发情时间
|
|
|
LastCalvingAt int64 `json:"lastCalvingAt"` // 最后一次产犊时间
|
|
@@ -215,6 +218,18 @@ func (c *Cow) UnForbiddenMatingUpdate() {
|
|
|
c.BreedStatus = pasturePb.BreedStatus_UnBreed
|
|
|
}
|
|
|
|
|
|
+// GetAvgDailyWeight 牛只平均日增重
|
|
|
+func (c *Cow) GetAvgDailyWeight() float32 {
|
|
|
+ if c.AdmissionAge <= 0 {
|
|
|
+ c.AdmissionAge = c.GetAdmissionAge()
|
|
|
+ }
|
|
|
+
|
|
|
+ if c.AdmissionAge <= 0 {
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+ return float32(c.CurrentWeight-c.AdmissionWeight) / 1000 / float32(c.AdmissionAge)
|
|
|
+}
|
|
|
+
|
|
|
type CowSlice []*Cow
|
|
|
|
|
|
func (c CowSlice) ToPB(
|
|
@@ -224,6 +239,8 @@ func (c CowSlice) ToPB(
|
|
|
cowSourceMap map[pasturePb.CowSource_Kind]string,
|
|
|
admissionStatusMap map[pasturePb.AdmissionStatus_Kind]string,
|
|
|
healthStatusMap map[pasturePb.HealthStatus_Kind]string,
|
|
|
+ purposeMap map[pasturePb.Purpose_Kind]string,
|
|
|
+ pregnancyAge int32,
|
|
|
) []*pasturePb.CowDetails {
|
|
|
res := make([]*pasturePb.CowDetails, len(c))
|
|
|
for i, v := range c {
|
|
@@ -288,44 +305,111 @@ func (c CowSlice) ToPB(
|
|
|
lastSecondWeightAtFormat = time.Unix(v.LastSecondWeightAt, 0).Format(LayoutDate2)
|
|
|
}
|
|
|
|
|
|
+ departureAtFormat := ""
|
|
|
+ if v.DepartureAt > 0 {
|
|
|
+ departureAtFormat = time.Unix(v.DepartureAt, 0).Format(LayoutDate2)
|
|
|
+ }
|
|
|
+
|
|
|
+ lastForbiddenMatingAtFormat := ""
|
|
|
+ if v.LastForbiddenMatingAt > 0 {
|
|
|
+ lastForbiddenMatingAtFormat = time.Unix(v.LastForbiddenMatingAt, 0).Format(LayoutDate2)
|
|
|
+ }
|
|
|
+
|
|
|
+ lastEstrusAtFormat := ""
|
|
|
+ if v.LastEstrusAt > 0 {
|
|
|
+ lastEstrusAtFormat = time.Unix(v.LastEstrusAt, 0).Format(LayoutDate2)
|
|
|
+ }
|
|
|
+
|
|
|
+ cowTypeName := ""
|
|
|
+ if cn, ok := cowTypeMap[v.CowType]; ok {
|
|
|
+ cowTypeName = cn
|
|
|
+ }
|
|
|
+
|
|
|
+ breedStatusName := ""
|
|
|
+ if bs, ok := breedStatusMap[v.BreedStatus]; ok {
|
|
|
+ breedStatusName = bs
|
|
|
+ }
|
|
|
+
|
|
|
+ cowKindName := ""
|
|
|
+ if ck, ok := cowKindMap[v.CowKind]; ok {
|
|
|
+ cowKindName = ck
|
|
|
+ }
|
|
|
+
|
|
|
+ sourceName := ""
|
|
|
+ if sn, ok := cowSourceMap[v.SourceKind]; ok {
|
|
|
+ sourceName = sn
|
|
|
+ }
|
|
|
+
|
|
|
+ admissionStatusName := ""
|
|
|
+ if as, ok := admissionStatusMap[v.AdmissionStatus]; ok {
|
|
|
+ admissionStatusName = as
|
|
|
+ }
|
|
|
+
|
|
|
+ healthStatusName := ""
|
|
|
+ if hs, ok := healthStatusMap[v.HealthStatus]; ok {
|
|
|
+ healthStatusName = hs
|
|
|
+ }
|
|
|
+
|
|
|
+ pregnancyDate := ""
|
|
|
+ if pregnancyAgeAt := v.GetDaysPregnancy(pregnancyAge); pregnancyAgeAt > 0 {
|
|
|
+ pregnancyDate = time.Unix(int64(pregnancyAge), 0).Local().Format(LayoutDate2)
|
|
|
+ }
|
|
|
+
|
|
|
+ purposeName := ""
|
|
|
+ if pn, ok := purposeMap[v.PurposeKind]; ok {
|
|
|
+ purposeName = pn
|
|
|
+ }
|
|
|
+
|
|
|
res[i] = &pasturePb.CowDetails{
|
|
|
- CowId: int32(v.Id),
|
|
|
- Sex: sex,
|
|
|
- NeckRingNumber: v.NeckRingNumber,
|
|
|
- PenName: v.PenName,
|
|
|
- Lact: v.Lact,
|
|
|
- CowTypeName: cowTypeMap[v.CowType],
|
|
|
- CowType: v.CowType,
|
|
|
- BreedStatusName: breedStatusMap[v.BreedStatus],
|
|
|
- BreedStatus: v.BreedStatus,
|
|
|
- CowKindName: cowKindMap[v.CowKind],
|
|
|
- EarNumber: v.EarNumber,
|
|
|
- BirthWeight: float32(v.BirthWeight) / 1000,
|
|
|
- CurrentWeight: float32(v.CurrentWeight) / 1000,
|
|
|
- CurrentHeight: int32(v.CurrentHeight),
|
|
|
- DayAge: v.DayAge,
|
|
|
- AdmissionAge: v.AdmissionAge,
|
|
|
- SourceName: cowSourceMap[v.SourceKind],
|
|
|
- MotherNumber: v.MotherNumber,
|
|
|
- FatherNumber: v.FatherNumber,
|
|
|
- AdmissionStatusName: admissionStatusMap[v.AdmissionStatus],
|
|
|
- HealthStatusName: healthStatusMap[v.HealthStatus],
|
|
|
- IsPregnantName: isPregnantName,
|
|
|
- AdmissionAtFormat: admissionAtFormat,
|
|
|
- BirthAtFormat: birthAtFormat,
|
|
|
- WeaningAtFormat: weaningAtFormat,
|
|
|
- CalvingAge: v.GetCalvingAge(),
|
|
|
- AbortionAge: v.AbortionAge,
|
|
|
- MatingTimes: v.MatingTimes,
|
|
|
- FirstMatingAtFormat: firstMatingAtFormat,
|
|
|
- LastMatingAtFormat: lastMatingAtFormat,
|
|
|
- LastBullNumber: v.LastBullNumber,
|
|
|
- LastPregnantCheckAtFormat: lastPregnantCheckAtFormat,
|
|
|
- LastWeightAtFormat: lastWeightAtFormat,
|
|
|
- LastCalvingAtFormat: lastCalvingAtFormat,
|
|
|
- LastAbortionAtFormat: lastAbortionAtFormat,
|
|
|
- LastSecondWeight: float32(v.LastSecondWeight) / 1000,
|
|
|
- LastSecondWeightAtFormat: lastSecondWeightAtFormat,
|
|
|
+ CowId: int32(v.Id),
|
|
|
+ Sex: sex,
|
|
|
+ NeckRingNumber: v.NeckRingNumber,
|
|
|
+ PenName: v.PenName,
|
|
|
+ Lact: v.Lact,
|
|
|
+ CowTypeName: cowTypeName,
|
|
|
+ CowType: v.CowType,
|
|
|
+ BreedStatusName: breedStatusName,
|
|
|
+ BreedStatus: v.BreedStatus,
|
|
|
+ CowKindName: cowKindName,
|
|
|
+ EarNumber: v.EarNumber,
|
|
|
+ BirthWeight: float32(v.BirthWeight) / 1000,
|
|
|
+ CurrentWeight: float32(v.CurrentWeight) / 1000,
|
|
|
+ CurrentHeight: int32(v.CurrentHeight),
|
|
|
+ DayAge: v.DayAge,
|
|
|
+ AdmissionAge: v.AdmissionAge,
|
|
|
+ SourceName: sourceName,
|
|
|
+ MotherNumber: v.MotherNumber,
|
|
|
+ FatherNumber: v.FatherNumber,
|
|
|
+ AdmissionStatusName: admissionStatusName,
|
|
|
+ HealthStatusName: healthStatusName,
|
|
|
+ IsPregnantName: isPregnantName,
|
|
|
+ AdmissionAtFormat: admissionAtFormat,
|
|
|
+ BirthAtFormat: birthAtFormat,
|
|
|
+ WeaningAtFormat: weaningAtFormat,
|
|
|
+ CalvingAge: v.GetCalvingAge(),
|
|
|
+ AbortionAge: v.AbortionAge,
|
|
|
+ MatingTimes: v.MatingTimes,
|
|
|
+ AbortionTimes: v.AbortionTimes,
|
|
|
+ FirstMatingAtFormat: firstMatingAtFormat,
|
|
|
+ LastMatingAtFormat: lastMatingAtFormat,
|
|
|
+ LastBullNumber: v.LastBullNumber,
|
|
|
+ LastPregnantCheckAtFormat: lastPregnantCheckAtFormat,
|
|
|
+ LastWeightAtFormat: lastWeightAtFormat,
|
|
|
+ LastCalvingAtFormat: lastCalvingAtFormat,
|
|
|
+ LastAbortionAtFormat: lastAbortionAtFormat,
|
|
|
+ LastSecondWeight: float32(v.LastSecondWeight) / 1000,
|
|
|
+ LastSecondWeightAtFormat: lastSecondWeightAtFormat,
|
|
|
+ DepartureAtFormat: departureAtFormat,
|
|
|
+ DeparturePrice: v.DeparturePrice,
|
|
|
+ DepartureWeight: float32(v.DepartureAvgWeight / 1000),
|
|
|
+ LastForbiddenMatingAtFormat: lastForbiddenMatingAtFormat,
|
|
|
+ LastEstrusAtFormat: lastEstrusAtFormat,
|
|
|
+ PregnancyDate: pregnancyDate,
|
|
|
+ PregnancyCheckTimes: v.PregnancyCheckName,
|
|
|
+ AvgDailyWeight: float32(v.GetAverageDailyWeight()),
|
|
|
+ EleEarNumber: v.EleEarNumber,
|
|
|
+ AdmissionPrice: float32(v.AdmissionWeight / 1000),
|
|
|
+ PurposeName: purposeName,
|
|
|
}
|
|
|
}
|
|
|
return res
|
|
@@ -494,6 +578,16 @@ func (c *Cow) GetDaysPregnant() int32 {
|
|
|
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 {
|
|
@@ -510,18 +604,20 @@ func (c *Cow) GetAdmissionAge() int32 {
|
|
|
return 0
|
|
|
}
|
|
|
|
|
|
-// GetAverageDailyWeight 平均日增重 (最后一次称重 - 第一次称重 ) ÷ 在群天数
|
|
|
+// GetAverageDailyWeight 平均日增重 (最后一次称重 - 入场体重 ) ÷ 在群天数
|
|
|
func (c *Cow) GetAverageDailyWeight() float64 {
|
|
|
- if c.CurrentWeight <= 0 || c.AdmissionAge <= 0 {
|
|
|
+ if c.AdmissionAge <= 0 {
|
|
|
+ c.AdmissionAge = c.GetAdmissionAge()
|
|
|
+ }
|
|
|
+
|
|
|
+ if c.AdmissionAge <= 0 {
|
|
|
return 0
|
|
|
}
|
|
|
- firstWeight := c.BirthWeight
|
|
|
- if c.SourceKind == pasturePb.CowSource_Buy {
|
|
|
- firstWeight = c.AdmissionWeight
|
|
|
|
|
|
+ if c.CurrentWeight-c.AdmissionWeight <= 0 {
|
|
|
+ return 0
|
|
|
}
|
|
|
- res := math.Round(1.0 * float64(c.CurrentWeight-firstWeight) / float64(c.AdmissionAge))
|
|
|
- return res / 1000
|
|
|
+ return float64(c.CurrentWeight-c.AdmissionWeight) / 1000 / float64(c.AdmissionAge)
|
|
|
}
|
|
|
|
|
|
// GetPreviousStageDailyWeight 上一个阶段日增重
|