| 
					
				 | 
			
			
				@@ -95,18 +95,19 @@ func (e *Entry) NeckRingOriginalMergeData() (err error) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		} else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			// 重新计算 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			newNeckActiveHabit := e.againRecalculate(historyNeckActiveHabit) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-			if newNeckActiveHabit != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-				if err = e.DB.Model(new(model.NeckActiveHabit)). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-					Select("rumina", "intake", "inactive", "gasp", "other", "high", "active", "is_show"). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-					Where("id = ?", historyNeckActiveHabit.Id). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-					Updates(newNeckActiveHabit).Error; err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-					zaplog.Error("NeckRingOriginalMergeData-3", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-						zap.Any("err", err), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-						zap.Any("ct", ct), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-						zap.Any("historyNeckActiveHabit", historyNeckActiveHabit), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-						zap.Any("newNeckActiveHabit", newNeckActiveHabit), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-					) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if newNeckActiveHabit == nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				continue 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if err = e.DB.Model(new(model.NeckActiveHabit)). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				Select("rumina", "intake", "inactive", "gasp", "other", "high", "active", "is_show", "record_count"). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				Where("id = ?", historyNeckActiveHabit.Id). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				Updates(newNeckActiveHabit).Error; err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				zaplog.Error("NeckRingOriginalMergeData-3", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					zap.Any("err", err), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					zap.Any("ct", ct), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					zap.Any("historyNeckActiveHabit", historyNeckActiveHabit), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					zap.Any("newNeckActiveHabit", newNeckActiveHabit), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -264,6 +265,10 @@ func (e *Entry) EntryUpdateActiveHabit(pastureId int64) (err error) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		if err = e.WeeklyUpdateActiveHabit(pastureId, processIds, xToday); err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			zaplog.Error("NeckRingCalculate", zap.Any("WeeklyUpdateActiveHabit", err), zap.Any("xToday", xToday)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if err = e.Before3DaysNeckActiveHabit(pastureId, processIds, xToday); err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			zaplog.Error("NeckRingCalculate", zap.Any("Before3DaysNeckActiveHabit", err), zap.Any("xToday", xToday)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		// 二次更新滤波 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		if err = e.SecondUpdateChangeFilter(pastureId, xToday); err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			zaplog.Error("NeckRingCalculate", zap.Any("SecondUpdateChangeFilter", err), zap.Any("xToday", xToday)) 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -422,8 +427,6 @@ func (e *Entry) WeeklyUpdateActiveHabit(pastureId int64, processIds []int64, xTo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		sumHabitData := e.FindSumHabitData(pastureId, v.NeckRingNumber, v.HeatDate, v.Frameid, xToDay) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		before3DaysNeckActiveHabit := e.FindBefore3DaysNeckActiveHabit(pastureId, v.NeckRingNumber, v.HeatDate, v.Frameid) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		// 更新过滤值 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		if err = e.DB.Model(new(model.NeckActiveHabit)). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			Select( 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -432,23 +435,21 @@ func (e *Entry) WeeklyUpdateActiveHabit(pastureId int64, processIds []int64, xTo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 				"change_high", "change_rumina", "change_chew", "before_three_sum_rumina", "before_three_sum_intake", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			).Where("id = ?", v.Id). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			Updates(map[string]interface{}{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-				"week_high_habit":         weekHabitData.WeekHighHabit, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-				"week_rumina_habit":       weekHabitData.WeekRuminaHabit, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-				"week_chew_habit":         weekHabitData.WeekChewHabit, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-				"week_intake_habit":       weekHabitData.WeekIntakeHabit, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-				"week_inactive_habit":     weekHabitData.WeekIntakeHabit, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-				"sum_rumina":              sumHabitData.SumRumina, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-				"sum_intake":              sumHabitData.SumIntake, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-				"sum_inactive":            sumHabitData.SumInactive, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-				"sum_active":              sumHabitData.SumActive, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-				"sum_max_high":            sumHabitData.SumMaxHigh, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-				"sum_min_high":            sumHabitData.SumMinHigh, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-				"sum_min_chew":            sumHabitData.SumMinChew, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-				"change_high":             v.ChangeHigh, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-				"change_rumina":           v.ChangeRumina, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-				"change_chew":             v.ChangeChew, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-				"before_three_sum_rumina": before3DaysNeckActiveHabit.SumRumina, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-				"before_three_sum_intake": before3DaysNeckActiveHabit.SumIntake, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				"week_high_habit":     weekHabitData.WeekHighHabit, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				"week_rumina_habit":   weekHabitData.WeekRuminaHabit, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				"week_chew_habit":     weekHabitData.WeekChewHabit, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				"week_intake_habit":   weekHabitData.WeekIntakeHabit, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				"week_inactive_habit": weekHabitData.WeekIntakeHabit, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				"sum_rumina":          sumHabitData.SumRumina, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				"sum_intake":          sumHabitData.SumIntake, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				"sum_inactive":        sumHabitData.SumInactive, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				"sum_active":          sumHabitData.SumActive, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				"sum_max_high":        sumHabitData.SumMaxHigh, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				"sum_min_high":        sumHabitData.SumMinHigh, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				"sum_min_chew":        sumHabitData.SumMinChew, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				"change_high":         v.ChangeHigh, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				"change_rumina":       v.ChangeRumina, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				"change_chew":         v.ChangeChew, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			}).Error; err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			zaplog.Error("WeeklyUpdateActiveHabit", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 				zap.Error(err), 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -460,6 +461,34 @@ func (e *Entry) WeeklyUpdateActiveHabit(pastureId int64, processIds []int64, xTo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	return err 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+func (e *Entry) Before3DaysNeckActiveHabit(pastureId int64, processIds []int64, xToDay *XToday) (err error) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	newNeckActiveHabitList := make([]*model.NeckActiveHabit, 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if err = e.DB.Model(new(model.NeckActiveHabit)). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		Where("id IN (?)", processIds). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		Order("heat_date,neck_ring_number,frameid"). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		Find(&newNeckActiveHabitList).Error; err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return xerr.WithStack(err) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	for _, v := range newNeckActiveHabitList { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		before3DaysNeckActiveHabit := e.FindBefore3DaysNeckActiveHabit(pastureId, v.NeckRingNumber, v.HeatDate, v.Frameid) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		// 更新过滤值 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if err = e.DB.Model(new(model.NeckActiveHabit)). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			Select("before_three_sum_rumina", "before_three_sum_intake"). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			Where("id = ?", v.Id). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			Updates(map[string]interface{}{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				"before_three_sum_rumina": before3DaysNeckActiveHabit.SumRumina, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				"before_three_sum_intake": before3DaysNeckActiveHabit.SumIntake, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			}).Error; err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			zaplog.Error("Before3DaysNeckActiveHabit", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				zap.Error(err), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				zap.Any("NeckActiveHabit", v), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				zap.Any("pastureId", pastureId), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	return nil 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 // SecondUpdateChangeFilter 第二次更新变化趋势滤波 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 func (e *Entry) SecondUpdateChangeFilter(pastureId int64, xToday *XToday) (err error) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	newChangeFilterList := make([]*ChangeFilterData, 0) 
			 |