Yi 1 сар өмнө
parent
commit
0206844d85

+ 9 - 5
module/crontab/estrus_warning.go

@@ -83,7 +83,7 @@ func (e *Entry) UpdateNeckRingWarningIsPeak(pastureId, minId int64) {
 		Select("1").
 		Where("a.id >= ?", minId).
 		Where("a.cow_id = b.cow_id").
-		Where("a.created_at > UNIX_TIMESTAMP(b.date_time)")
+		Where("a.active_time > b.date_time")
 
 	if err := e.DB.Table(fmt.Sprintf("%s as b", new(model.NeckRingEstrusWarning).TableName())).
 		Where("b.pasture_id = ?", pastureId).
@@ -91,6 +91,14 @@ func (e *Entry) UpdateNeckRingWarningIsPeak(pastureId, minId int64) {
 		Update("is_peak", pasturePb.IsShow_Ok).Error; err != nil {
 		zaplog.Error("UpdateNeckRingWarningIsPeak", zap.Any("err", err))
 	}
+
+	if err := e.DB.Table(fmt.Sprintf("%s as b", new(model.NeckRingEstrus).TableName())).
+		Joins(fmt.Sprintf("JOIN %s as a on b.neck_ring_estrus_id = a.id", new(model.NeckRingEstrusWarning).TableName())).
+		Where("b.pasture_id = ?", pastureId).
+		Where("a.is_peak = ?", pasturePb.IsShow_Ok).
+		Update("is_peak", pasturePb.IsShow_Ok).Error; err != nil {
+		zaplog.Error("UpdateNeckRingWarningIsPeak", zap.Any("err", err))
+	}
 }
 
 func (e *Entry) UpdateHighChange(pastureId, minId int64) {
@@ -136,12 +144,8 @@ func (e *Entry) UpdateHighChange(pastureId, minId int64) {
 
 func (e *Entry) GroupAndProcessData(records []*model.NeckRingEstrus) []*model.NeckRingEstrusWarning {
 	groups := make(map[int64]*model.GroupEstrusData)
-
 	// 分组处理
 	for _, record := range records {
-		// 从关联的Cow表获取信息(这里需要根据实际关联方式调整)
-		// 假设已通过JOIN获取到CowID等信息
-		// 实际实现可能需要预加载Cow信息
 		key := record.CowId
 		if _, exist := groups[key]; !exist {
 			groups[key] = &model.GroupEstrusData{