|
@@ -0,0 +1,63 @@
|
|
|
+package backend
|
|
|
+
|
|
|
+import (
|
|
|
+ "context"
|
|
|
+ "kpt-pasture/model"
|
|
|
+ "net/http"
|
|
|
+
|
|
|
+ pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
|
|
|
+)
|
|
|
+
|
|
|
+// GrowthCurve 生长曲线 获取图表数据
|
|
|
+func (s *StoreEntry) GrowthCurve(ctx context.Context, req *pasturePb.SearchGrowthCurvesRequest) (*pasturePb.GrowthCurvesResponse, error) {
|
|
|
+ // 查询数据
|
|
|
+ cowList := make([]*model.Cow, 0)
|
|
|
+ pref := s.DB.Model(new(model.Cow)).Where("is_remove = ?", pasturePb.IsShow_Ok)
|
|
|
+
|
|
|
+ if req.GetCowId() != "" {
|
|
|
+ pref.Where("id IN ?", req.GetCowId())
|
|
|
+ }
|
|
|
+
|
|
|
+ if req.BirthStartDate > 0 && req.BirthEndDate > 0 && req.BirthStartDate <= req.BirthEndDate {
|
|
|
+ pref.Where("birth_at BETWEEN ? AND ?", req.GetBirthStartDate(), req.GetBirthEndDate())
|
|
|
+ }
|
|
|
+
|
|
|
+ if err := pref.Find(&cowList).Error; err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ // 计算图表数据
|
|
|
+ chartsList := &pasturePb.Charts{
|
|
|
+ CowId: make([]int32, 0),
|
|
|
+ Weight: make([]float32, 0),
|
|
|
+ DayAge: make([]int32, 0),
|
|
|
+ }
|
|
|
+ cowData := make([]*pasturePb.CowList, 0)
|
|
|
+ for _, cow := range cowList {
|
|
|
+ currentWeight := float32(cow.CurrentWeight) / 100
|
|
|
+ cowData = append(cowData, &pasturePb.CowList{
|
|
|
+ CowId: int32(cow.Id),
|
|
|
+ EarNumber: cow.EarNumber,
|
|
|
+ DayAge: cow.GetDayAge(),
|
|
|
+ PenName: "",
|
|
|
+ CurrentWeight: currentWeight,
|
|
|
+ BirthAt: int32(cow.BirthAt),
|
|
|
+ BirthWeight: float32(cow.BirthWeight) / 100,
|
|
|
+ LastWeightAt: int32(cow.LastWeightAt),
|
|
|
+ DailyWeightGain: 0,
|
|
|
+ AverageDailyWeightGain: 0,
|
|
|
+ })
|
|
|
+ chartsList.CowId = append(chartsList.CowId, int32(cow.Id))
|
|
|
+ chartsList.Weight = append(chartsList.Weight, currentWeight)
|
|
|
+ chartsList.DayAge = append(chartsList.DayAge, cow.GetDayAge())
|
|
|
+ }
|
|
|
+ // 返回数据
|
|
|
+ return &pasturePb.GrowthCurvesResponse{
|
|
|
+ Code: http.StatusOK,
|
|
|
+ Message: "success",
|
|
|
+ Data: &pasturePb.GrowthCurveData{
|
|
|
+ Table: cowData,
|
|
|
+ Charts: chartsList,
|
|
|
+ },
|
|
|
+ }, nil
|
|
|
+
|
|
|
+}
|