Yi hai 2 meses
pai
achega
0378097dbf
Modificáronse 1 ficheiros con 27 adicións e 24 borrados
  1. 27 24
      module/crontab/neck_ring_handle.go

+ 27 - 24
module/crontab/neck_ring_handle.go

@@ -82,6 +82,7 @@ func (e *Entry) NeckRingOriginalMergeData() (err error) {
 		return nil
 	}
 
+	zaplog.Info("neckActiveHabitList", zap.Any("neckActiveHabitList", neckActiveHabitList))
 	for _, habit := range neckActiveHabitList {
 		//更新脖环牛只相关信息 新数据直接插入
 		historyNeckActiveHabit, ct := e.IsExistNeckActiveHabit(habit.NeckRingNumber, habit.HeatDate, habit.Frameid)
@@ -92,28 +93,29 @@ func (e *Entry) NeckRingOriginalMergeData() (err error) {
 					zap.Any("neckActiveHabit", habit),
 				)
 			}
-			if err = e.UpdateNeckRingOriginalIsShow(habit); err != nil {
-				zaplog.Error("NeckRingOriginalMergeData-2",
-					zap.Any("err", err),
-					zap.Any("neckActiveHabit", habit),
-				)
+		} 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),
+					)
+				}
 			}
-			continue
 		}
-		// 重新计算
-		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 err = e.UpdateNeckRingOriginalIsShow(habit); err != nil {
+			zaplog.Error("NeckRingOriginalMergeData-2",
+				zap.Any("err", err),
+				zap.Any("neckActiveHabit", habit),
+			)
 		}
 	}
 	return nil
@@ -650,11 +652,12 @@ func (e *Entry) UpdateChangeAdJust(pastureId int64, xToday *XToday) error {
 	return nil
 }
 
-func (e *Entry) UpdateNeckRingOriginalIsShow(neckRingList *model.NeckActiveHabit) error {
+func (e *Entry) UpdateNeckRingOriginalIsShow(habit *model.NeckActiveHabit) error {
 	if err := e.DB.Model(new(model.NeckRingOriginal)).
-		Where("neck_ring_number = ?", neckRingList.NeckRingNumber).
-		Where("active_date = ?", neckRingList.HeatDate).
-		Where("frameid IN (?)", util.FrameIds(neckRingList.Frameid)).
+		Where("pasture_id = ?", habit.PastureId).
+		Where("neck_ring_number = ?", habit.NeckRingNumber).
+		Where("active_date = ?", habit.HeatDate).
+		Where("frameid IN (?)", util.FrameIds(habit.Frameid)).
 		Update("is_show", pasturePb.IsShow_Ok).Error; err != nil {
 		return xerr.WithStack(err)
 	}