소스 검색

crontab: neckRing calculate update

Yi 1 개월 전
부모
커밋
9c75d0b9cf
2개의 변경된 파일18개의 추가작업 그리고 2개의 파일을 삭제
  1. 2 1
      module/crontab/estrus_warning.go
  2. 16 1
      module/crontab/neck_ring_calculate.go

+ 2 - 1
module/crontab/estrus_warning.go

@@ -120,7 +120,8 @@ func (e *Entry) UpdateHighChange(pastureId, minId int64) {
 				if err = e.DB.Model(new(model.NeckRingEstrusWarning)).
 				if err = e.DB.Model(new(model.NeckRingEstrusWarning)).
 					Where("neck_ring_estrus_id = ?", v.NeckRingEstrusId).
 					Where("neck_ring_estrus_id = ?", v.NeckRingEstrusId).
 					Where("cow_id = ?", v.CowId).
 					Where("cow_id = ?", v.CowId).
-					Where("pasture_id = ?", pastureId).Delete(new(model.NeckRingEstrusWarning)).Error; err != nil {
+					Where("pasture_id = ?", pastureId).
+					Delete(new(model.NeckRingEstrusWarning)).Error; err != nil {
 					zaplog.Error("UpdateHighChange", zap.Any("Delete", err), zap.Any("v", v))
 					zaplog.Error("UpdateHighChange", zap.Any("Delete", err), zap.Any("v", v))
 				}
 				}
 				continue
 				continue

+ 16 - 1
module/crontab/neck_ring_calculate.go

@@ -86,8 +86,15 @@ func (e *Entry) FirstFilterUpdate(pastureId int64, xToDay *XToday) (processIds [
 	if limit <= 0 {
 	if limit <= 0 {
 		limit = defaultLimit
 		limit = defaultLimit
 	}
 	}
+
+	heatDate := time.Now().Local().AddDate(0, 0, -30).Format(model.LayoutDate2)
+	querySql := `SELECT * FROM neck_active_habit WHERE pasture_id = ? AND is_show = ? AND heat_date >= ? AND high >= ?
+			UNION
+				 SELECT * FROM neck_active_habit WHERE pasture_id = ? AND is_show = ? AND heat_date >= ? AND rumina >= ?
+			ORDER BY heat_date, neck_ring_number, frameid LIMIT ?`
+
 	newNeckActiveHabitList := make([]*model.NeckActiveHabit, 0)
 	newNeckActiveHabitList := make([]*model.NeckActiveHabit, 0)
-	if err = e.DB.Model(new(model.NeckActiveHabit)).
+	/*if err = e.DB.Model(new(model.NeckActiveHabit)).
 		Where("heat_date >= ?", time.Now().Local().AddDate(0, 0, -30).Format(model.LayoutDate2)).
 		Where("heat_date >= ?", time.Now().Local().AddDate(0, 0, -30).Format(model.LayoutDate2)).
 		Where("pasture_id = ?", pastureId).
 		Where("pasture_id = ?", pastureId).
 		Where("is_show = ?", pasturePb.IsShow_No).
 		Where("is_show = ?", pasturePb.IsShow_No).
@@ -96,6 +103,14 @@ func (e *Entry) FirstFilterUpdate(pastureId int64, xToDay *XToday) (processIds [
 		Limit(int(limit)).
 		Limit(int(limit)).
 		Find(&newNeckActiveHabitList).Error; err != nil {
 		Find(&newNeckActiveHabitList).Error; err != nil {
 		return nil, xerr.WithStack(err)
 		return nil, xerr.WithStack(err)
+	}*/
+	if err = e.DB.Raw(
+		querySql,
+		pastureId, pasturePb.IsShow_No, heatDate, xToDay.High,
+		pastureId, pasturePb.IsShow_No, heatDate, xToDay.Rumina,
+		limit,
+	).Find(&newNeckActiveHabitList).Error; err != nil {
+		return nil, xerr.WithStack(err)
 	}
 	}
 
 
 	// 活动量滤波
 	// 活动量滤波