Просмотр исходного кода

pasture: 排行榜和配方使用概况

Yi 1 год назад
Родитель
Сommit
fd39c11c57

+ 1 - 0
backend/operation/feed_formula.proto

@@ -77,6 +77,7 @@ message FeedFormulaUsageRequest {
     int32 feed_formula_id = 1;        // 饲料配方id
     string start_time = 2;            // 开始时间
     string end_time = 3;              // 结束时间
+    int32 pasture_id = 4;            // 牧场id
 }
 
 // 配方使用概况

+ 10 - 6
module/backend/dashboard_service.go

@@ -191,8 +191,6 @@ func (s *StoreEntry) SearchAnalysisAccuracy(ctx context.Context, req *operationP
 	mixedFodderAccurateRatio, mixedFodderCorrectRatio, sprinkleFodderAccurateRatio, sprinkleFodderCorrectRatio :=
 		&model.CommonValueRatio{}, &model.CommonValueRatio{}, &model.CommonValueRatio{}, &model.CommonValueRatio{}
 	maTitleValueList, mcTitleValueList, saTitleValueList, scTitleValueList := make([]float64, 0), make([]float64, 0), make([]float64, 0), make([]float64, 0)
-	mTopOneName := ""
-
 	dayTimeList := tool.TimeBetween(req.StartDate, req.EndDate)
 	for pastureId, data := range pastureAnalysisAccuracy {
 		groupPasture, err := s.GetGroupPastureListById(ctx, pastureId)
@@ -258,29 +256,35 @@ func (s *StoreEntry) SearchAnalysisAccuracy(ctx context.Context, req *operationP
 		sprinkleFodderCorrectRatio.PastureName = append(sprinkleFodderCorrectRatio.PastureName, groupPasture.Name)
 	}
 
+	pastureTopDataList, err := s.TopPasture(ctx, req)
+	if err != nil {
+		zaplog.Error("SearchAnalysisAccuracy", zap.Any("TopPasture", err), zap.Any("request", req))
+		return nil, xerr.WithStack(err)
+	}
+
 	sort.Float64s(maTitleValueList)
 	mixedFodderAccurateRatio.MaxValue = fmt.Sprintf("%.2f", maTitleValueList[len(maTitleValueList)-1])
 	mixedFodderAccurateRatio.MinValue = fmt.Sprintf("%.2f", maTitleValueList[0])
 	mixedFodderAccurateRatio.MiddleValue = fmt.Sprintf("%.2f", tool.Median(maTitleValueList))
-	mixedFodderAccurateRatio.TopOneName = mTopOneName
+	mixedFodderAccurateRatio.TopOneName = pastureTopDataList.Data.MixedFodderAccurateRatio[0].PastureName
 
 	sort.Float64s(mcTitleValueList)
 	mixedFodderCorrectRatio.MaxValue = fmt.Sprintf("%.2f", mcTitleValueList[len(mcTitleValueList)-1])
 	mixedFodderCorrectRatio.MinValue = fmt.Sprintf("%.2f", mcTitleValueList[0])
 	mixedFodderCorrectRatio.MiddleValue = fmt.Sprintf("%.2f", tool.Median(mcTitleValueList))
-	mixedFodderCorrectRatio.TopOneName = mTopOneName
+	mixedFodderCorrectRatio.TopOneName = pastureTopDataList.Data.MixedFodderCorrectRatio[0].PastureName
 
 	sort.Float64s(saTitleValueList)
 	sprinkleFodderAccurateRatio.MaxValue = fmt.Sprintf("%.2f", saTitleValueList[len(saTitleValueList)-1])
 	sprinkleFodderAccurateRatio.MinValue = fmt.Sprintf("%.2f", saTitleValueList[0])
 	sprinkleFodderAccurateRatio.MiddleValue = fmt.Sprintf("%.2f", tool.Median(saTitleValueList))
-	sprinkleFodderAccurateRatio.TopOneName = mTopOneName
+	sprinkleFodderAccurateRatio.TopOneName = pastureTopDataList.Data.SprinkleFodderAccurateRatio[0].PastureName
 
 	sort.Float64s(scTitleValueList)
 	sprinkleFodderCorrectRatio.MaxValue = fmt.Sprintf("%.2f", scTitleValueList[len(scTitleValueList)-1])
 	sprinkleFodderCorrectRatio.MinValue = fmt.Sprintf("%.2f", scTitleValueList[0])
 	sprinkleFodderCorrectRatio.MiddleValue = fmt.Sprintf("%.2f", tool.Median(scTitleValueList))
-	sprinkleFodderCorrectRatio.TopOneName = mTopOneName
+	sprinkleFodderCorrectRatio.TopOneName = pastureTopDataList.Data.SprinkleFodderCorrectRatio[0].PastureName
 
 	chart := &model.Chart{
 		MixedFodderAccurateRatio:    mixedFodderAccurateRatio,

+ 21 - 3
module/backend/feed_service.go

@@ -402,6 +402,12 @@ func (s *StoreEntry) FeedFormulaUsage(ctx context.Context, req *operationPb.Feed
 		return xerr.WithStack(err)
 	}
 
+	res := &operationPb.FeedFormulaUsageResponse{
+		Code: http.StatusOK,
+		Msg:  "ok",
+		Data: make([]*operationPb.FeedFormulaUsageList, 0),
+	}
+
 	wg := sync.WaitGroup{}
 	wg.Add(len(feedFormulaDistributeLogList))
 
@@ -414,19 +420,31 @@ func (s *StoreEntry) FeedFormulaUsage(ctx context.Context, req *operationPb.Feed
 				return
 			}
 
+			req.PastureId = int32(groupDetail.PastureId)
 			response := &operationPb.PastureFeedFormulaUsageResponse{}
-			if _, err = s.PastureHttpClient(ctx, model.FeedUsageURl, groupDetail.Id, nil, response); err != nil {
+			if _, err = s.PastureHttpClient(ctx, model.FeedUsageURl, groupDetail.Id, req, response); err != nil {
 				zaplog.Error("FeedFormulaUsage", zap.Any("PastureDetailById", err))
 				return
 			}
 
 			if response.Code == http.StatusOK {
-
+				data := &operationPb.FeedFormulaUsageList{
+					PastureId:                   int32(groupDetail.Id),
+					PastureName:                 groupDetail.Name,
+					MixedFodderAccurateRatio:    response.Data.MixedFodderAccurateRatio,
+					MixedFodderCorrectRatio:     response.Data.MixedFodderCorrectRatio,
+					SprinkleFodderAccurateRatio: response.Data.SprinkleFodderAccurateRatio,
+					SprinkleFodderCorrectRatio:  response.Data.SprinkleFodderCorrectRatio,
+					AddFeedTime:                 response.Data.AddFeedTime,
+					SprinkleTime:                response.Data.SprinkleTime,
+					StirTime:                    response.Data.StirTime,
+					LastEditTime:                response.Data.LastEditTime,
+				}
+				res.Data = append(res.Data, data)
 			} else {
 				zaplog.Error("FeedFormulaUsage-http", zap.Any("response", response))
 				return
 			}
-
 		}(list)
 	}
 

+ 19 - 9
proto/go/backend/operation/feed_formula.pb.go

@@ -617,6 +617,7 @@ type FeedFormulaUsageRequest struct {
 	FeedFormulaId int32  `protobuf:"varint,1,opt,name=feed_formula_id,json=feedFormulaId,proto3" json:"feed_formula_id,omitempty"` // 饲料配方id
 	StartTime     string `protobuf:"bytes,2,opt,name=start_time,json=startTime,proto3" json:"start_time,omitempty"`                // 开始时间
 	EndTime       string `protobuf:"bytes,3,opt,name=end_time,json=endTime,proto3" json:"end_time,omitempty"`                      // 结束时间
+	PastureId     int32  `protobuf:"varint,4,opt,name=pasture_id,json=pastureId,proto3" json:"pasture_id,omitempty"`               // 牧场id
 }
 
 func (x *FeedFormulaUsageRequest) Reset() {
@@ -672,6 +673,13 @@ func (x *FeedFormulaUsageRequest) GetEndTime() string {
 	return ""
 }
 
+func (x *FeedFormulaUsageRequest) GetPastureId() int32 {
+	if x != nil {
+		return x.PastureId
+	}
+	return 0
+}
+
 // 配方使用概况
 type FeedFormulaUsageResponse struct {
 	state         protoimpl.MessageState
@@ -1191,15 +1199,17 @@ var file_backend_operation_feed_formula_proto_rawDesc = []byte{
 	0x05, 0x52, 0x0a, 0x70, 0x61, 0x73, 0x74, 0x75, 0x72, 0x65, 0x49, 0x64, 0x73, 0x12, 0x28, 0x0a,
 	0x10, 0x66, 0x65, 0x65, 0x64, 0x5f, 0x66, 0x6f, 0x72, 0x6d, 0x75, 0x6c, 0x61, 0x5f, 0x69, 0x64,
 	0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x05, 0x52, 0x0e, 0x66, 0x65, 0x65, 0x64, 0x46, 0x6f, 0x72,
-	0x6d, 0x75, 0x6c, 0x61, 0x49, 0x64, 0x73, 0x22, 0x7b, 0x0a, 0x17, 0x46, 0x65, 0x65, 0x64, 0x46,
-	0x6f, 0x72, 0x6d, 0x75, 0x6c, 0x61, 0x55, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65,
-	0x73, 0x74, 0x12, 0x26, 0x0a, 0x0f, 0x66, 0x65, 0x65, 0x64, 0x5f, 0x66, 0x6f, 0x72, 0x6d, 0x75,
-	0x6c, 0x61, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0d, 0x66, 0x65, 0x65,
-	0x64, 0x46, 0x6f, 0x72, 0x6d, 0x75, 0x6c, 0x61, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x73, 0x74,
-	0x61, 0x72, 0x74, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09,
-	0x73, 0x74, 0x61, 0x72, 0x74, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x19, 0x0a, 0x08, 0x65, 0x6e, 0x64,
-	0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x65, 0x6e, 0x64,
-	0x54, 0x69, 0x6d, 0x65, 0x22, 0x7d, 0x0a, 0x18, 0x46, 0x65, 0x65, 0x64, 0x46, 0x6f, 0x72, 0x6d,
+	0x6d, 0x75, 0x6c, 0x61, 0x49, 0x64, 0x73, 0x22, 0x9a, 0x01, 0x0a, 0x17, 0x46, 0x65, 0x65, 0x64,
+	0x46, 0x6f, 0x72, 0x6d, 0x75, 0x6c, 0x61, 0x55, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75,
+	0x65, 0x73, 0x74, 0x12, 0x26, 0x0a, 0x0f, 0x66, 0x65, 0x65, 0x64, 0x5f, 0x66, 0x6f, 0x72, 0x6d,
+	0x75, 0x6c, 0x61, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0d, 0x66, 0x65,
+	0x65, 0x64, 0x46, 0x6f, 0x72, 0x6d, 0x75, 0x6c, 0x61, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x73,
+	0x74, 0x61, 0x72, 0x74, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
+	0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x19, 0x0a, 0x08, 0x65, 0x6e,
+	0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x65, 0x6e,
+	0x64, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x70, 0x61, 0x73, 0x74, 0x75, 0x72, 0x65,
+	0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x70, 0x61, 0x73, 0x74, 0x75,
+	0x72, 0x65, 0x49, 0x64, 0x22, 0x7d, 0x0a, 0x18, 0x46, 0x65, 0x65, 0x64, 0x46, 0x6f, 0x72, 0x6d,
 	0x75, 0x6c, 0x61, 0x55, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
 	0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04,
 	0x63, 0x6f, 0x64, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28,