|
@@ -6,14 +6,15 @@ import (
|
|
|
"encoding/json"
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
- operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
|
|
|
- "gitee.com/xuyiping_admin/pkg/logger/zaplog"
|
|
|
- "gitee.com/xuyiping_admin/pkg/xerr"
|
|
|
"kpt-tmr-group/model"
|
|
|
"net/http"
|
|
|
"sort"
|
|
|
"sync"
|
|
|
|
|
|
+ operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
|
|
|
+ "gitee.com/xuyiping_admin/pkg/logger/zaplog"
|
|
|
+ "gitee.com/xuyiping_admin/pkg/xerr"
|
|
|
+
|
|
|
"gorm.io/gorm"
|
|
|
|
|
|
"github.com/xuri/excelize/v2"
|
|
@@ -32,27 +33,27 @@ func (s *StoreEntry) PastureDetailById(ctx context.Context, pastureId int64) (*m
|
|
|
return result, nil
|
|
|
}
|
|
|
|
|
|
-func (s *StoreEntry) PastureHttpClient(ctx context.Context, apiUrl string, pastureId int64, body, response interface{}) (*model.GroupPasture, error) {
|
|
|
+func (s *StoreEntry) PastureHttpClient(ctx context.Context, apiUrl string, pastureId int64, body, response interface{}) error {
|
|
|
pastureDetail, err := s.PastureDetailById(ctx, pastureId)
|
|
|
if err != nil {
|
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
- return nil, xerr.Customf("该牧场不存在")
|
|
|
+ return xerr.Customf("该牧场不存在")
|
|
|
}
|
|
|
zaplog.Error("PastureHttpClient", zap.Any("Err", err), zap.Int64("pastureId", pastureId))
|
|
|
- return nil, xerr.Customf("该牧场数据错误,Err:%s", err)
|
|
|
+ return xerr.Customf("该牧场数据错误,Err:%s", err)
|
|
|
}
|
|
|
pastureClient := model.NewPastureClient(pastureDetail)
|
|
|
url := fmt.Sprintf("%s/%s", pastureDetail.Domain, apiUrl)
|
|
|
result, err := pastureClient.DoPost(url, body)
|
|
|
if err != nil {
|
|
|
- return pastureDetail, xerr.WithStack(err)
|
|
|
+ return xerr.WithStack(err)
|
|
|
}
|
|
|
|
|
|
zaplog.Info("PastureHttpClient", zap.String("url", url), zap.Any("request", body), zap.String("response", string(result)))
|
|
|
if err = json.Unmarshal(result, response); err != nil {
|
|
|
- return pastureDetail, xerr.WithStack(err)
|
|
|
+ return xerr.WithStack(err)
|
|
|
}
|
|
|
- return pastureDetail, nil
|
|
|
+ return nil
|
|
|
}
|
|
|
|
|
|
// SearchFormulaEstimateList 配方评估
|
|
@@ -82,7 +83,7 @@ func (s *StoreEntry) SearchFormulaEstimateList(ctx context.Context, req *operati
|
|
|
},
|
|
|
}
|
|
|
response := &model.PastureCommonResponse{Data: &model.PastureCommonData{}}
|
|
|
- if _, err = s.PastureHttpClient(ctx, model.UrlDataByName, int64(req.PastureId), body, response); err != nil {
|
|
|
+ if err = s.PastureHttpClient(ctx, model.UrlDataByName, int64(req.PastureId), body, response); err != nil {
|
|
|
return nil, xerr.WithStack(err)
|
|
|
}
|
|
|
return response, nil
|
|
@@ -117,7 +118,7 @@ func (s *StoreEntry) SearchInventoryStatistics(ctx context.Context, req *operati
|
|
|
List: make([]*model.InventoryStatisticsList, 0),
|
|
|
},
|
|
|
}
|
|
|
- if _, err := s.PastureHttpClient(ctx, model.UrlDataByName, int64(req.PastureId), body, response); err != nil {
|
|
|
+ if err = s.PastureHttpClient(ctx, model.UrlDataByName, int64(req.PastureId), body, response); err != nil {
|
|
|
return nil, xerr.WithStack(err)
|
|
|
}
|
|
|
return response, nil
|
|
@@ -239,7 +240,7 @@ func (s *StoreEntry) SearchUserMaterialsStatistics(ctx context.Context, req *ope
|
|
|
response := &model.PastureCommonResponse{Data: &model.PastureCommonData{
|
|
|
List: &model.UserMaterialsList{},
|
|
|
}}
|
|
|
- if _, err = s.PastureHttpClient(ctx, model.UrlReportForm, int64(req.PastureId), body, response); err != nil {
|
|
|
+ if err = s.PastureHttpClient(ctx, model.UrlReportForm, int64(req.PastureId), body, response); err != nil {
|
|
|
return nil, xerr.WithStack(err)
|
|
|
}
|
|
|
return response, nil
|
|
@@ -349,7 +350,7 @@ func (s *StoreEntry) SearchPriceStatistics(ctx context.Context, req *operationPb
|
|
|
},
|
|
|
}
|
|
|
response := &model.PastureCommonResponse{Data: &model.PastureCommonData{}}
|
|
|
- if _, err = s.PastureHttpClient(ctx, model.UrlReportForm, int64(req.PastureId), body, response); err != nil {
|
|
|
+ if err = s.PastureHttpClient(ctx, model.UrlReportForm, int64(req.PastureId), body, response); err != nil {
|
|
|
return nil, xerr.WithStack(err)
|
|
|
}
|
|
|
return response, nil
|
|
@@ -406,7 +407,7 @@ func (s *StoreEntry) SearchFeedStatistics(ctx context.Context, req *operationPb.
|
|
|
Data: &model.PastureCommonData{},
|
|
|
}
|
|
|
|
|
|
- if _, err = s.PastureHttpClient(ctx, model.UrlDataByName, int64(pastureId), body, response); err != nil {
|
|
|
+ if err = s.PastureHttpClient(ctx, model.UrlDataByName, int64(pastureId), body, response); err != nil {
|
|
|
zaplog.Error("SearchFeedStatistics",
|
|
|
zap.Any("pastureId", pastureId),
|
|
|
zap.Any("url", model.UrlDataByName),
|
|
@@ -525,7 +526,7 @@ func (s *StoreEntry) FeedChartStatistics(ctx context.Context, req *operationPb.F
|
|
|
return nil, xerr.Customf("错误的接口类型:%s", req.ApiType)
|
|
|
}
|
|
|
response := &model.PastureCommonResponse{Data: &model.PastureCommonData{}}
|
|
|
- if _, err = s.PastureHttpClient(ctx, url, int64(req.PastureId), body, response); err != nil {
|
|
|
+ if err = s.PastureHttpClient(ctx, url, int64(req.PastureId), body, response); err != nil {
|
|
|
return nil, xerr.WithStack(err)
|
|
|
}
|
|
|
return response, nil
|
|
@@ -555,7 +556,7 @@ func (s *StoreEntry) CowsAnalysis(ctx context.Context, req *operationPb.CowsAnal
|
|
|
},
|
|
|
}
|
|
|
response := &model.PastureCommonResponse{Data: &model.PastureCommonData{}}
|
|
|
- if _, err = s.PastureHttpClient(ctx, model.UrlDataByName, int64(req.PastureId), body, response); err != nil {
|
|
|
+ if err = s.PastureHttpClient(ctx, model.UrlDataByName, int64(req.PastureId), body, response); err != nil {
|
|
|
return nil, xerr.WithStack(err)
|
|
|
}
|
|
|
return response, nil
|
|
@@ -577,7 +578,7 @@ func (s *StoreEntry) SearchAccuracyAggStatistics(ctx context.Context, req *opera
|
|
|
}
|
|
|
|
|
|
response := &model.PastureCommonResponse{Data: &model.PastureCommonData{}}
|
|
|
- if _, err = s.PastureHttpClient(ctx, model.UrlSummary, int64(req.PastureId), body, response); err != nil {
|
|
|
+ if err = s.PastureHttpClient(ctx, model.UrlSummary, int64(req.PastureId), body, response); err != nil {
|
|
|
return nil, xerr.WithStack(err)
|
|
|
}
|
|
|
return response, nil
|
|
@@ -603,7 +604,7 @@ func (s *StoreEntry) SearchMixFeedStatistics(ctx context.Context, req *operation
|
|
|
ParamMaps: model.NewMixFeedStatisticsParams(int64(pastureId), req),
|
|
|
}
|
|
|
response := &model.PastureCommonResponse{Data: &model.PastureCommonData{}}
|
|
|
- if _, err = s.PastureHttpClient(ctx, model.UrlDataByName, int64(req.PastureId), body, response); err != nil {
|
|
|
+ if err = s.PastureHttpClient(ctx, model.UrlDataByName, int64(req.PastureId), body, response); err != nil {
|
|
|
return nil, xerr.WithStack(err)
|
|
|
}
|
|
|
return response, nil
|
|
@@ -629,7 +630,7 @@ func (s *StoreEntry) SearchSprinkleStatistics(ctx context.Context, req *operatio
|
|
|
ParamMaps: model.NewSprinkleStatisticsParams(int64(pastureId), req),
|
|
|
}
|
|
|
response := &model.PastureCommonResponse{Data: &model.PastureCommonData{}}
|
|
|
- if _, err := s.PastureHttpClient(ctx, model.UrlDataByName, int64(req.PastureId), body, response); err != nil {
|
|
|
+ if err = s.PastureHttpClient(ctx, model.UrlDataByName, int64(req.PastureId), body, response); err != nil {
|
|
|
return nil, xerr.WithStack(err)
|
|
|
}
|
|
|
return response, nil
|
|
@@ -655,7 +656,7 @@ func (s *StoreEntry) SearchProcessAnalysis(ctx context.Context, req *operationPb
|
|
|
ParamMaps: model.NewProcessAnalysisParams(int64(pastureId), req),
|
|
|
}
|
|
|
response := &model.PastureCommonResponse{Data: &model.PastureCommonData{}}
|
|
|
- if _, err = s.PastureHttpClient(ctx, model.UrlProcess, int64(req.PastureId), body, response); err != nil {
|
|
|
+ if err = s.PastureHttpClient(ctx, model.UrlProcess, int64(req.PastureId), body, response); err != nil {
|
|
|
return nil, xerr.WithStack(err)
|
|
|
}
|
|
|
|
|
@@ -688,7 +689,7 @@ func (s *StoreEntry) AnalysisMixedSprinkleDetail(ctx context.Context, req *opera
|
|
|
if req.ApiName == "getprocessAnalysisTB" {
|
|
|
apiURl = model.UrlReportForm
|
|
|
}
|
|
|
- if _, err = s.PastureHttpClient(ctx, apiURl, int64(req.PastureId), body, response); err != nil {
|
|
|
+ if err = s.PastureHttpClient(ctx, apiURl, int64(req.PastureId), body, response); err != nil {
|
|
|
return nil, xerr.WithStack(err)
|
|
|
}
|
|
|
return response, nil
|
|
@@ -714,7 +715,7 @@ func (s *StoreEntry) GetDataByName(ctx context.Context, req *operationPb.GetData
|
|
|
},
|
|
|
}
|
|
|
response := &model.PastureCommonResponse{Data: &model.PastureCommonData{}}
|
|
|
- if _, err = s.PastureHttpClient(ctx, model.UrlDataByName, int64(req.PastureId), body, response); err != nil {
|
|
|
+ if err = s.PastureHttpClient(ctx, model.UrlDataByName, int64(req.PastureId), body, response); err != nil {
|
|
|
return nil, xerr.WithStack(err)
|
|
|
}
|
|
|
return response, nil
|
|
@@ -743,7 +744,7 @@ func (s *StoreEntry) GetTrainNumber(ctx context.Context, req *operationPb.TrainN
|
|
|
},
|
|
|
}
|
|
|
response := &model.PastureCommonResponse{Data: &model.PastureCommonData{}}
|
|
|
- if _, err := s.PastureHttpClient(ctx, model.UrlDataByName, int64(req.PastureId), body, response); err != nil {
|
|
|
+ if err = s.PastureHttpClient(ctx, model.UrlDataByName, int64(req.PastureId), body, response); err != nil {
|
|
|
return nil, xerr.WithStack(err)
|
|
|
}
|
|
|
|