|  | @@ -24,7 +24,8 @@ func (s *StoreEntry) NeckRingWarning(ctx context.Context) (*pasturePb.IndexNeckR
 | 
	
		
			
				|  |  |  		return nil, xerr.WithStack(err)
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	estrusWarningCowList := make([]*model.DashboardNeckRingEstrusWarning, 0)
 | 
	
		
			
				|  |  | +	var count int64
 | 
	
		
			
				|  |  | +	neckRingEstrusList := make([]*model.NeckRingEstrusWarning, 0)
 | 
	
		
			
				|  |  |  	estrusWarningLevelItems := map[int32]int32{
 | 
	
		
			
				|  |  |  		int32(pasturePb.EstrusLevel_Low):    0,
 | 
	
		
			
				|  |  |  		int32(pasturePb.EstrusLevel_Middle): 0,
 | 
	
	
		
			
				|  | @@ -36,28 +37,38 @@ func (s *StoreEntry) NeckRingWarning(ctx context.Context) (*pasturePb.IndexNeckR
 | 
	
		
			
				|  |  |  		return nil, xerr.Customf("系统错误!")
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  	if err = pref.Order("a.level DESC").
 | 
	
		
			
				|  |  | -		Select("a.level, count(a.level) as count").
 | 
	
		
			
				|  |  | -		Group("a.level").
 | 
	
		
			
				|  |  | -		Find(&estrusWarningCowList).Error; err != nil {
 | 
	
		
			
				|  |  | +		Count(&count).
 | 
	
		
			
				|  |  | +		Find(&neckRingEstrusList).Error; err != nil {
 | 
	
		
			
				|  |  |  		return nil, xerr.WithStack(err)
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	/*if err = s.DB.Table(fmt.Sprintf("%s as a", new(model.NeckRingEstrusWarning).TableName())).
 | 
	
		
			
				|  |  | -		Select("a.level, count(a.level) as count").
 | 
	
		
			
				|  |  | -		Where("a.pasture_id = ?", userModel.AppPasture.Id).
 | 
	
		
			
				|  |  | -		Where("a.is_show = ?", pasturePb.IsShow_Ok).
 | 
	
		
			
				|  |  | -		Group("a.level").
 | 
	
		
			
				|  |  | -		Find(&estrusWarningCowList).Error; err != nil {
 | 
	
		
			
				|  |  | -		zaplog.Error("NeckRingWarning", zap.Any("estrusWarningNumber", err))
 | 
	
		
			
				|  |  | -	}*/
 | 
	
		
			
				|  |  |  	countEstrusWarning := 0
 | 
	
		
			
				|  |  | -	for _, v := range estrusWarningCowList {
 | 
	
		
			
				|  |  | -		estrusWarningLevelItems[int32(v.Level)] = estrusWarningLevelItems[v.Count]
 | 
	
		
			
				|  |  | -		countEstrusWarning += int(v.Count)
 | 
	
		
			
				|  |  | +	nowTime := time.Now().Local()
 | 
	
		
			
				|  |  | +	optimumMating := map[string]int32{
 | 
	
		
			
				|  |  | +		"front":  0,
 | 
	
		
			
				|  |  | +		"middle": 0,
 | 
	
		
			
				|  |  | +		"behind": 0,
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +	for _, v := range neckRingEstrusList {
 | 
	
		
			
				|  |  | +		estrusWarningLevelItems[int32(v.Level)] += 1
 | 
	
		
			
				|  |  | +		countEstrusWarning += 1
 | 
	
		
			
				|  |  | +		cowInfo, _ := s.GetCowInfoByEarNumber(ctx, userModel.AppPasture.Id, v.EarNumber)
 | 
	
		
			
				|  |  | +		pzHour := v.CalculatePzHour(cowInfo.Lact)
 | 
	
		
			
				|  |  | +		optimumMatingStartTime := pzHour.Add(-4 * time.Hour)
 | 
	
		
			
				|  |  | +		optimumMatingEndTime := pzHour.Add(4 * time.Hour)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		// 判断当前时间是否在 pzHour-4h 到 pzHour+4h 之间
 | 
	
		
			
				|  |  | +		if nowTime.After(optimumMatingStartTime) && nowTime.Before(optimumMatingEndTime) {
 | 
	
		
			
				|  |  | +			optimumMating["middle"] += 1
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +		if nowTime.After(optimumMatingEndTime) {
 | 
	
		
			
				|  |  | +			optimumMating["behind"] += 1
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +		if nowTime.Before(optimumMatingStartTime) {
 | 
	
		
			
				|  |  | +			optimumMating["front"] += 1
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	zaplog.Info("NeckRingWarning", zap.Any("estrusWarningNumber", estrusWarningCowList), zap.Any("estrusWarningLevelItems", estrusWarningLevelItems))
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |  	abortionCount := int64(0)
 | 
	
		
			
				|  |  |  	pref, err = s.AbortionWarningQuery(ctx, userModel.AppPasture.Id)
 | 
	
		
			
				|  |  |  	if err != nil {
 | 
	
	
		
			
				|  | @@ -85,6 +96,7 @@ func (s *StoreEntry) NeckRingWarning(ctx context.Context) (*pasturePb.IndexNeckR
 | 
	
		
			
				|  |  |  			AbortionWarningNumber:   int32(abortionCount),
 | 
	
		
			
				|  |  |  			StressWarningNumber:     0,
 | 
	
		
			
				|  |  |  			EstrusWarningLevelItems: estrusWarningLevelItems,
 | 
	
		
			
				|  |  | +			OptimumMating:           optimumMating,
 | 
	
		
			
				|  |  |  		},
 | 
	
		
			
				|  |  |  	}, nil
 | 
	
		
			
				|  |  |  
 |