|
@@ -42,7 +42,7 @@ func (e *Entry) UpdateCowEstrus() (err error) {
|
|
|
|
|
|
func (e *Entry) EntryCowEstrus(pastureId int64) (err error) {
|
|
|
xToday := &XToday{}
|
|
|
- systemConfigureList, err := e.GetSystemNeckRingConfigure(pastureId)
|
|
|
+ systemConfigureList, err := e.FindSystemNeckRingConfigure(pastureId)
|
|
|
if err != nil {
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
@@ -81,7 +81,6 @@ func (e *Entry) CowEstrusWarning(pastureId int64, xToday *XToday, nowTime time.T
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- zaplog.Info("CowEstrusWarning", zap.Any("neckActiveHabitList", neckActiveHabitList))
|
|
|
neckActiveHabitMap := make(map[int64][]*model.NeckActiveHabit)
|
|
|
for _, habit := range neckActiveHabitList {
|
|
|
cft := calculateCFT(habit)
|
|
@@ -96,19 +95,21 @@ func (e *Entry) CowEstrusWarning(pastureId int64, xToday *XToday, nowTime time.T
|
|
|
neckActiveHabitMap[habit.CowId] = append(neckActiveHabitMap[habit.CowId], habit)
|
|
|
}
|
|
|
|
|
|
- zaplog.Info("CowEstrusWarning", zap.Any("neckActiveHabitMap", neckActiveHabitMap))
|
|
|
neckRingEstrusList := make([]*model.NeckRingEstrus, 0)
|
|
|
for cowId, cowHabitList := range neckActiveHabitMap {
|
|
|
|
|
|
before3Data := e.GetBeforeThreeDaysCowEstrus(cowId, nowTime.AddDate(0, 0, -2).Format(model.LayoutTime))
|
|
|
+
|
|
|
|
|
|
- cowEstrus := e.GetTwoEstrus(pastureId, cowId, nowTime.AddDate(0, 0, -100).Format(model.LayoutTime), nowTime.AddDate(0, 0, -2).Format(model.LayoutTime))
|
|
|
- activeDateTime, _ := util.TimeParseLocal(model.LayoutTime, cowEstrus.ActiveDate)
|
|
|
- if activeDateTime.Unix() >= nowTime.AddDate(0, 0, -25).Unix() && activeDateTime.Unix() <= nowTime.AddDate(0, 0, -18).Unix() {
|
|
|
- cowEstrus.HadJust = XAdjust21
|
|
|
- }
|
|
|
- if activeDateTime.Unix() >= nowTime.AddDate(0, 0, -50).Unix() && activeDateTime.Unix() <= nowTime.AddDate(0, 0, -36).Unix() {
|
|
|
- cowEstrus.HadJust = XAdjust42
|
|
|
+ cow21Estrus := e.GetTwoEstrus(pastureId, cowId, nowTime.AddDate(0, 0, -100).Format(model.LayoutTime), nowTime.AddDate(0, 0, -2).Format(model.LayoutTime))
|
|
|
+ if cow21Estrus.ActiveDate != "" {
|
|
|
+ activeDateTime, _ := util.TimeParseLocal(model.LayoutTime, cow21Estrus.ActiveDate)
|
|
|
+ if activeDateTime.Unix() >= nowTime.AddDate(0, 0, -25).Unix() && activeDateTime.Unix() <= nowTime.AddDate(0, 0, -18).Unix() {
|
|
|
+ cow21Estrus.HadJust = XAdjust21
|
|
|
+ }
|
|
|
+ if activeDateTime.Unix() >= nowTime.AddDate(0, 0, -50).Unix() && activeDateTime.Unix() <= nowTime.AddDate(0, 0, -36).Unix() {
|
|
|
+ cow21Estrus.HadJust = XAdjust42
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
maxCft := float32(0)
|
|
@@ -130,11 +131,13 @@ func (e *Entry) CowEstrusWarning(pastureId int64, xToday *XToday, nowTime time.T
|
|
|
}
|
|
|
|
|
|
b48 := float64(0)
|
|
|
- t3, _ := util.TimeParseLocal(model.LayoutTime, before3Data.ActiveTime)
|
|
|
- b48 = t3.Sub(lastActiveDate).Hours()
|
|
|
+ if len(before3Data.ActiveTime) > 0 {
|
|
|
+ t3, _ := util.TimeParseLocal(model.LayoutTime, before3Data.ActiveTime)
|
|
|
+ b48 = t3.Sub(lastActiveDate).Hours()
|
|
|
+ }
|
|
|
|
|
|
- if (int32(maxCft) > before3Data.DayHigh || before3Data.CowId == 0 || b48 > B48) && int32(maxCft)+cowEstrus.HadJust > xToday.ActiveLow {
|
|
|
- level := calculateActiveLevel(maxCft, cowEstrus, xToday)
|
|
|
+ if (int32(maxCft) > before3Data.DayHigh || before3Data.CowId == 0 || b48 > B48) && int32(maxCft)+cow21Estrus.HadJust > xToday.ActiveLow {
|
|
|
+ level := calculateActiveLevel(maxCft, cow21Estrus, xToday)
|
|
|
cowInfo := e.FindCowInfoByCowId(cowId)
|
|
|
if cowInfo == nil {
|
|
|
zaplog.Error("CowEstrusWarning", zap.Any("FindCowInfoByCowId", cowId))
|
|
@@ -144,10 +147,15 @@ func (e *Entry) CowEstrusWarning(pastureId int64, xToday *XToday, nowTime time.T
|
|
|
if cowInfo != nil && cowInfo.IsPregnant == pasturePb.IsShow_Ok && level == pasturePb.EstrusLevel_Low {
|
|
|
isShow = pasturePb.IsShow_No
|
|
|
}
|
|
|
- dayHigh := int32(maxCft) + cowEstrus.HadJust
|
|
|
- lastEstrusDate := cowEstrus.ActiveDate
|
|
|
- checkResult := getResult(before3Data, maxCft, cowEstrus)
|
|
|
+ dayHigh := int32(maxCft) + cow21Estrus.HadJust
|
|
|
+ lastEstrusDate := cow21Estrus.ActiveDate
|
|
|
+ checkResult := getResult(before3Data, maxCft, cow21Estrus)
|
|
|
isPeak := pasturePb.IsShow_Ok
|
|
|
+ activeTime := lastActiveDate.Format(model.LayoutTime)
|
|
|
+
|
|
|
+ if e.HistoryNeckRingEstrus(pastureId, cowInfo.NeckRingNumber, activeTime) {
|
|
|
+ continue
|
|
|
+ }
|
|
|
|
|
|
zaplog.Info("CowEstrusWarning",
|
|
|
zap.Any("level", level),
|
|
@@ -158,15 +166,15 @@ func (e *Entry) CowEstrusWarning(pastureId int64, xToday *XToday, nowTime time.T
|
|
|
zap.Any("lastEstrusDate", lastEstrusDate),
|
|
|
zap.Any("activeDate", lastActiveDate),
|
|
|
zap.Any("dayHigh", dayHigh),
|
|
|
- zap.Any("cft", maxCft),
|
|
|
+ zap.Any("maxCft", maxCft),
|
|
|
zap.Any("before3Data", before3Data),
|
|
|
- zap.Any("cowEstrus", cowEstrus),
|
|
|
+ zap.Any("cowEstrus", cow21Estrus),
|
|
|
zap.Any("cowInfo", cowInfo),
|
|
|
zap.Any("cowHabitList", cowHabitList),
|
|
|
)
|
|
|
- newNeckRingEstrus := model.NewNeckRingEstrus(pastureId, cowInfo, level, checkResult, isShow)
|
|
|
+ newNeckRingEstrus := model.NewNeckRingEstrus(pastureId, cowInfo, level, int32(maxCft), checkResult, isShow)
|
|
|
newNeckRingEstrus.LastTime = lastEstrusDate
|
|
|
- newNeckRingEstrus.ActiveTime = lastActiveDate.Format(model.LayoutTime)
|
|
|
+ newNeckRingEstrus.ActiveTime = activeTime
|
|
|
newNeckRingEstrus.DayHigh = dayHigh
|
|
|
newNeckRingEstrus.MaxHigh = maxHigh
|
|
|
newNeckRingEstrus.IsPeak = isPeak
|
|
@@ -284,6 +292,18 @@ func (e *Entry) FindCowEstrusFirstTime1(pastureId, cowId int64, xToday time.Time
|
|
|
return firstTimeEventEstrus
|
|
|
}
|
|
|
|
|
|
+func (e *Entry) HistoryNeckRingEstrus(pastureId int64, neckRingNumber string, activeTime string) bool {
|
|
|
+ var count int64
|
|
|
+ if err := e.DB.Model(new(model.NeckRingEstrus)).
|
|
|
+ Where("pasture_id = ?", pastureId).
|
|
|
+ Where("neck_ring_number = ?", neckRingNumber).
|
|
|
+ Where("active_time = ?", activeTime).
|
|
|
+ Count(&count).Error; err != nil {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ return count > 0
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
func calculateCFT(habit *model.NeckActiveHabit) (cft float32) {
|
|
|
if habit.ChangeAdjust >= 10 {
|