Browse Source

crontab: update

Yi 1 week ago
parent
commit
6b1cbfdc51

+ 2 - 2
module/crontab/estrus_warning.go

@@ -37,13 +37,13 @@ func (e *Entry) UpdateNeckRingWarning(pastureId int64) (err error) {
 
 	// 计算时间范围
 	now := time.Now()
-	startTime := now.Add(-24 * time.Hour)
+	startTime := now.AddDate(0, 0, -1)
 	neckRingEstrusList := make([]*model.NeckRingEstrus, 0)
 	if err = e.DB.Table(fmt.Sprintf("%s as a", new(model.NeckRingEstrus).TableName())).
 		Select("a.*").
 		Joins("JOIN cow as b ON a.cow_id = b.id AND a.pasture_id = b.pasture_id").
 		Where("a.pasture_id = ?", pastureId).
-		Where("a.active_time >= ?", startTime.Format(model.LayoutTime)).
+		Where("a.active_time >= ?", fmt.Sprintf("%s 00:00:00", startTime.Format(model.LayoutDate2))).
 		Where("a.active_level >= ?", pasturePb.EstrusLevel_Low).
 		Where("a.check_result IN (?)", []pasturePb.CheckResult_Kind{pasturePb.CheckResult_Pending, pasturePb.CheckResult_Correct}).
 		Where("a.is_show = ?", pasturePb.IsShow_Ok).

+ 9 - 3
module/crontab/neck_ring_calculate.go

@@ -93,7 +93,7 @@ func (e *Entry) FirstFilterUpdate(pastureId int64, xToDay *XToday) (processIds [
 	}
 	newNeckActiveHabitList := make([]*model.NeckActiveHabit, 0)
 	if err = e.DB.Model(new(model.NeckActiveHabit)).
-		Where("heat_date >= ?", time.Now().AddDate(0, 0, -1).Format(model.LayoutDate2)).
+		Where("heat_date >= ?", time.Now().AddDate(0, 0, -7).Format(model.LayoutDate2)).
 		Where("pasture_id = ?", pastureId).
 		Where("is_show = ?", pasturePb.IsShow_No).
 		Where(e.DB.Where("high >= ?", xToDay.High).Or("rumina >= ?", xToDay.Rumina)).
@@ -242,6 +242,9 @@ func (e *Entry) SecondUpdateChangeFilter(pastureId int64, processIds []int64, xT
 			discount *= 0.5
 		}
 		ruminaFilter = float64(secondFilterData.RuminaFilter)*(1-discount) + float64(v.ChangeRumina)*discount
+		if ruminaFilter > 50 {
+			ruminaFilter = 50
+		}
 
 		chewFilter := float64(v.ChewFilter)
 		chewFilterDiscount := float64(1)
@@ -249,13 +252,16 @@ func (e *Entry) SecondUpdateChangeFilter(pastureId int64, processIds []int64, xT
 			chewFilterDiscount = 0.5
 		}
 		chewFilter = float64(secondFilterData.ChewFilter)*(1-xRuminaDisc*chewFilterDiscount) + float64(v.ChangeChew)*xRuminaDisc*chewFilterDiscount
+		if chewFilter > 50 {
+			chewFilter = 50
+		}
 		if err := e.DB.Model(new(model.NeckActiveHabit)).
 			Select("change_filter", "rumina_filter", "chew_filter").
 			Where("id = ?", v.Id).
 			Updates(map[string]interface{}{
 				"change_filter": int32(changeFilter),
-				"rumina_filter": int32(math.Min(50, ruminaFilter)),
-				"chew_filter":   int32(math.Min(50, chewFilter)),
+				"rumina_filter": int32(ruminaFilter),
+				"chew_filter":   int32(chewFilter),
 			}).Error; err != nil {
 			zaplog.Error("SecondUpdateChangeFilter", zap.Any("error", err), zap.Any("secondFilterData", secondFilterData))
 		}

+ 5 - 12
module/crontab/neck_ring_estus_test.go

@@ -5,6 +5,7 @@ import (
 	"fmt"
 	"kpt-pasture/model"
 	"kpt-pasture/util"
+	"math"
 	"sort"
 	"testing"
 	"time"
@@ -6098,16 +6099,8 @@ func TestRecalculate(t *testing.T) {
 }
 
 func TestIndex(t *testing.T) {
-	ActiveTime := "2025-03-13 13:00:00"
-	loc, _ := time.LoadLocation("Local")
-	activeTime, _ := time.ParseInLocation(model.LayoutTime, ActiveTime, loc)
-	fmt.Println("activeTime", activeTime.Unix())
-	for i := 0; i < 7; i++ {
-		hours := time.Now().Sub(activeTime).Hours()
-		if i != model.DefaultRecordCount && int64(hours) < 8 {
-			fmt.Println("i", i, "hours", int64(hours))
-		} else {
-			fmt.Println("j", i, "hours", int64(hours))
-		}
-	}
+	ruminaFilter := float64(100)
+	ruminaFilter1 := float64(58)
+	fmt.Println(int32(math.Min(50, ruminaFilter)))
+	fmt.Println(int32(math.Min(50, ruminaFilter1)))
 }