Browse Source

cow: detail update

Yi 4 ngày trước cách đây
mục cha
commit
b3597d24fe
2 tập tin đã thay đổi với 12 bổ sung13 xóa
  1. 2 0
      model/neck_active_habit.go
  2. 10 13
      module/backend/cow.go

+ 2 - 0
model/neck_active_habit.go

@@ -18,6 +18,8 @@ const (
 	DefaultFilterCorrect = 100
 	DefaultWeeklyActive  = 1500
 	DefaultRecordCount   = 6
+	LowActivity          = 62
+	MiddleActivity       = 80
 )
 
 type NeckActiveHabit struct {

+ 10 - 13
module/backend/cow.go

@@ -258,8 +258,8 @@ func (s *StoreEntry) BehaviorCurve(ctx context.Context, req *pasturePb.CowBehavi
 		}
 		data.EventMap[k] = v
 	}
-	data.LowActivity = 62
-	data.MiddleActivity = 80
+	data.LowActivity = model.LowActivity
+	data.MiddleActivity = model.MiddleActivity
 	// 牛只事件列表
 	eventLogList := make([]*model.EventCowLog, 0)
 	eventLog := &model.EventCowLog{CowId: cowInfo.Id}
@@ -295,25 +295,22 @@ func (s *StoreEntry) BehaviorCurve(ctx context.Context, req *pasturePb.CowBehavi
 	}
 
 	// 发情数据
-	estrusList := make([]*model.EventEstrus, 0)
-	if err = s.DB.Table(new(model.EventEstrus).TableName()).
+	estrusList := make([]*model.NeckRingEstrus, 0)
+	if err = s.DB.Model(new(model.NeckRingEstrus)).
+		Select("max(id) as id,active_level,active_time,is_peak").
 		Where("cow_id = ?", cowInfo.Id).
 		Where("pasture_id = ?", userModel.AppPasture.Id).
-		Where("reality_day BETWEEN ? AND ?", startDataTime, endDataTime).
-		Order("reality_day").
+		Where("active_time BETWEEN ? AND ?", fmt.Sprintf("%s 00:00:00", startDataTime), fmt.Sprintf("%s 23:59:59", endDataTime)).
+		Where("is_peak = ?", pasturePb.IsShow_Ok).
 		Find(&estrusList).Error; err != nil {
 		return nil, xerr.WithStack(err)
 	}
 
 	for _, v := range estrusList {
-		if data.EstrusList[v.Level] == nil {
-			data.EstrusList[v.Level] = make([]string, 0)
-		}
-		if v.RealityDay > 0 {
-			// 格式化为到小时的字符串
-			hourStr := time.Unix(v.RealityDay, 0).Local().Format(model.LayoutHour)
-			data.EstrusList[v.Level] = append(data.EstrusList[v.Level], hourStr)
+		if data.EstrusList[v.ActiveLevel] == nil {
+			data.EstrusList[v.ActiveLevel] = make([]string, 0)
 		}
+		data.EstrusList[v.ActiveLevel] = append(data.EstrusList[v.ActiveLevel], strings.TrimSuffix(v.ActiveTime, ":00:00"))
 	}
 
 	return &model.CowBehaviorCurveResponse{