|  | @@ -1,6 +1,7 @@
 | 
	
		
			
				|  |  |  package model
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import (
 | 
	
		
			
				|  |  | +	"math"
 | 
	
		
			
				|  |  |  	"time"
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
 | 
	
	
		
			
				|  | @@ -51,7 +52,7 @@ func NewEventWeight(pastureId int64, cow *Cow, currentUser *SystemUser, item *pa
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  type EventWeightSlice []*EventWeight
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -func (e EventWeightSlice) ToPB() *pasturePb.CowGrowthCurveData {
 | 
	
		
			
				|  |  | +func (e EventWeightSlice) ToPB(cowInfo *Cow, eventCowLogList []*EventCowLog) *pasturePb.CowGrowthCurveData {
 | 
	
		
			
				|  |  |  	res := &pasturePb.CowGrowthCurveData{
 | 
	
		
			
				|  |  |  		Chart: &pasturePb.CowBehaviorCurveChart{
 | 
	
		
			
				|  |  |  			Headers:   make([]string, 0),
 | 
	
	
		
			
				|  | @@ -60,22 +61,58 @@ func (e EventWeightSlice) ToPB() *pasturePb.CowGrowthCurveData {
 | 
	
		
			
				|  |  |  		},
 | 
	
		
			
				|  |  |  		Table: make([]*pasturePb.CowBehaviorCurveTable, len(e)),
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  	for i, v := range e {
 | 
	
		
			
				|  |  |  		weightAtFormat := ""
 | 
	
		
			
				|  |  |  		if v.WeightAt > 0 {
 | 
	
		
			
				|  |  |  			weightAtFormat = time.Unix(v.WeightAt, 0).Local().Format(LayoutDate2)
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  | +		weight := float32(0)
 | 
	
		
			
				|  |  | +		if v.Weight > 0 {
 | 
	
		
			
				|  |  | +			weight = float32(v.Weight) / 1000
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  		avgWeight := float32(0)
 | 
	
		
			
				|  |  |  		if i > 0 {
 | 
	
		
			
				|  |  |  			avgWeight = float32(v.Weight-e[i-1].Weight) / float32(v.WeightAt-e[i-1].WeightAt) / 24 / 1000
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +		// 阶段日增重
 | 
	
		
			
				|  |  | +		stageDayAddWeight, monthAvgAddWeight := float32(0), float32(0)
 | 
	
		
			
				|  |  | +		if i > 0 {
 | 
	
		
			
				|  |  | +			stageWeight := float64(v.Weight-e[i-1].Weight) / 1000
 | 
	
		
			
				|  |  | +			t1 := time.Unix(v.WeightAt, 0).Local().Truncate(24 * time.Hour)
 | 
	
		
			
				|  |  | +			t2 := time.Unix(e[i-1].WeightAt, 0).Local().Truncate(24 * time.Hour)
 | 
	
		
			
				|  |  | +			diff := t1.Sub(t2)
 | 
	
		
			
				|  |  | +			days := int32(diff.Hours() / 24)
 | 
	
		
			
				|  |  | +			stageDayAddWeight = float32(math.Round(stageWeight/float64(days)*100) / 100)
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		if stageDayAddWeight > 0 {
 | 
	
		
			
				|  |  | +			monthAvgAddWeight = stageDayAddWeight * 30
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  |  		res.Table[i] = &pasturePb.CowBehaviorCurveTable{
 | 
	
		
			
				|  |  | -			Weight:         float32(v.Weight) / 1000,
 | 
	
		
			
				|  |  | -			WeightAtFormat: weightAtFormat,
 | 
	
		
			
				|  |  | -			AvgWeight:      avgWeight,
 | 
	
		
			
				|  |  | +			Weight:            weight,
 | 
	
		
			
				|  |  | +			AvgWeight:         avgWeight,
 | 
	
		
			
				|  |  | +			StageDayAddWeight: stageDayAddWeight,
 | 
	
		
			
				|  |  | +			MonthAvgAddWeight: monthAvgAddWeight,
 | 
	
		
			
				|  |  | +			WeightAtFormat:    weightAtFormat,
 | 
	
		
			
				|  |  | +			AdmissionAge:      cowInfo.AdmissionAge,
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +		res.Chart.Headers = append(res.Chart.Headers, weightAtFormat)
 | 
	
		
			
				|  |  | +		res.Chart.Weight = append(res.Chart.Weight, weight)
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	for _, event := range eventCowLogList {
 | 
	
		
			
				|  |  | +		dateTime := ""
 | 
	
		
			
				|  |  | +		if event.EventAt > 0 {
 | 
	
		
			
				|  |  | +			dateTime = time.Unix(event.EventAt, 0).Local().Format(LayoutDate2)
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  | +		res.Chart.EventList = append(res.Chart.EventList, &pasturePb.EventHappen{
 | 
	
		
			
				|  |  | +			Name:          event.EventTypeName,
 | 
	
		
			
				|  |  | +			DateTime:      dateTime,
 | 
	
		
			
				|  |  | +			EventTypeKind: event.EventType,
 | 
	
		
			
				|  |  | +		})
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	return res
 |