|
@@ -14,6 +14,10 @@ import (
|
|
|
"strings"
|
|
|
)
|
|
|
|
|
|
+type PastureClientHandler func(ctx context.Context, pastureId int64, body interface{}) error
|
|
|
+
|
|
|
+// type eventHandler func(ev map[string]interface{}, openID string, appID string, enterpriseID int, cts int64, conn redis.Conn) error
|
|
|
+
|
|
|
// PastureDetailById 获取指定牧场详情
|
|
|
func (s *StoreEntry) PastureDetailById(ctx context.Context, pastureId int64) (*model.GroupPasture, error) {
|
|
|
result := &model.GroupPasture{Id: pastureId}
|
|
@@ -23,20 +27,36 @@ func (s *StoreEntry) PastureDetailById(ctx context.Context, pastureId int64) (*m
|
|
|
return result, nil
|
|
|
}
|
|
|
|
|
|
-// SearchFormulaEstimateList 配方评估
|
|
|
-func (s *StoreEntry) SearchFormulaEstimateList(ctx context.Context, req *operationPb.SearchFormulaEstimateRequest) (*model.FormulaEstimateResponse, error) {
|
|
|
- pastureDetail, err := s.PastureDetailById(ctx, int64(req.PastureId))
|
|
|
+func (s *StoreEntry) PastureHttpClient(ctx context.Context, apiUrl string, pastureId int64, body interface{}, response interface{}) error {
|
|
|
+ pastureDetail, err := s.PastureDetailById(ctx, pastureId)
|
|
|
if err != nil {
|
|
|
- zaplog.Error("SearchFormulaEstimateList", zap.Any("Err", err), zap.Any("req", req))
|
|
|
- return nil, xerr.Customf("该牧场数据错误")
|
|
|
+ zaplog.Error("SearchFormulaEstimateList", zap.Any("Err", err), zap.Int64("pastureId", pastureId))
|
|
|
+ return xerr.Customf("该牧场数据错误,Err:%s", err)
|
|
|
}
|
|
|
+
|
|
|
pastureClient := model.NewPastureClient(pastureDetail)
|
|
|
- body := &model.FormulaEstimateRequest{
|
|
|
- Name: req.Name,
|
|
|
+ url := fmt.Sprintf("%s/%s", pastureDetail.Domain, apiUrl)
|
|
|
+
|
|
|
+ result, err := pastureClient.DoPost(url, body)
|
|
|
+ if err != nil {
|
|
|
+ return xerr.WithStack(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ if err = json.Unmarshal(result, response); err != nil {
|
|
|
+ return xerr.WithStack(err)
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+// SearchFormulaEstimateList 配方评估
|
|
|
+func (s *StoreEntry) SearchFormulaEstimateList(ctx context.Context, req *operationPb.SearchFormulaEstimateRequest) (*model.PastureCommonResponse, error) {
|
|
|
+ body := &model.PastureCommonRequest{
|
|
|
+ Name: req.ApiName,
|
|
|
Page: req.Pagination.Page,
|
|
|
Offset: req.Pagination.PageOffset,
|
|
|
PageCount: req.Pagination.PageSize,
|
|
|
- ReturnType: "map",
|
|
|
+ ReturnType: "Map",
|
|
|
ParamMaps: &model.FormulaEstimateParams{
|
|
|
PastureId: fmt.Sprintf("%d", req.PastureId),
|
|
|
StartTime: req.StartTime,
|
|
@@ -47,23 +67,106 @@ func (s *StoreEntry) SearchFormulaEstimateList(ctx context.Context, req *operati
|
|
|
Barid: fmt.Sprintf("%d", req.BarnId),
|
|
|
},
|
|
|
}
|
|
|
- url := fmt.Sprintf("%s/%s", pastureDetail.Domain, "authdata/GetDataByName")
|
|
|
- result, err := pastureClient.DoPost(url, body)
|
|
|
- if err != nil {
|
|
|
+ response := &model.PastureCommonResponse{Data: &model.PastureCommonData{}}
|
|
|
+ if err := s.PastureHttpClient(ctx, model.UrlDataByName, int64(req.PastureId), body, response); err != nil {
|
|
|
return nil, xerr.WithStack(err)
|
|
|
}
|
|
|
- response := &model.FormulaEstimateResponse{}
|
|
|
- if err = json.Unmarshal(result, response); err != nil {
|
|
|
+ return response, nil
|
|
|
+}
|
|
|
+
|
|
|
+// SearchInventoryStatistics 库存管理-库存统计
|
|
|
+func (s *StoreEntry) SearchInventoryStatistics(ctx context.Context, req *operationPb.SearchInventoryStatisticsRequest) (*model.PastureCommonResponse, error) {
|
|
|
+ body := &model.PastureCommonRequest{
|
|
|
+ Name: req.ApiName,
|
|
|
+ Page: req.Pagination.Page,
|
|
|
+ Offset: req.Pagination.PageOffset,
|
|
|
+ PageCount: req.Pagination.PageSize,
|
|
|
+ ReturnType: "Map",
|
|
|
+ ParamMaps: &model.InventoryStatisticsParams{
|
|
|
+ PastureId: fmt.Sprintf("%d", req.PastureId),
|
|
|
+ StartTime: req.StartTime,
|
|
|
+ StopTime: req.EndTime,
|
|
|
+ FeedName: req.FeedName,
|
|
|
+ },
|
|
|
+ }
|
|
|
+ response := &model.PastureCommonResponse{
|
|
|
+ Data: &model.PastureCommonData{
|
|
|
+ List: make([]*model.InventoryStatisticsList, 0),
|
|
|
+ },
|
|
|
+ }
|
|
|
+ if err := s.PastureHttpClient(ctx, model.UrlDataByName, int64(req.PastureId), body, response); err != nil {
|
|
|
return nil, xerr.WithStack(err)
|
|
|
}
|
|
|
- if response.Code == 400 {
|
|
|
- if response.Msg == "登录超时" {
|
|
|
+ return response, nil
|
|
|
+}
|
|
|
|
|
|
- } else {
|
|
|
- return nil, xerr.WithStack(err)
|
|
|
- }
|
|
|
+// SearchUserMaterialsStatistics 库存管理-用料分析
|
|
|
+func (s *StoreEntry) SearchUserMaterialsStatistics(ctx context.Context, req *operationPb.SearchUserMaterialsStatisticsRequest) (*model.PastureCommonResponse, error) {
|
|
|
+ body := &model.PastureCommonRequest{
|
|
|
+ Name: req.ApiName,
|
|
|
+ Page: req.Pagination.Page,
|
|
|
+ Offset: req.Pagination.PageOffset,
|
|
|
+ PageCount: req.Pagination.PageSize,
|
|
|
+ ReturnType: "Map",
|
|
|
+ Checked: req.ErrorCheck,
|
|
|
+ ParamMaps: &model.UserMaterialsStatisticsParams{
|
|
|
+ PastureId: fmt.Sprintf("%d", req.PastureId),
|
|
|
+ StartTime: req.StartTime,
|
|
|
+ StopTime: req.EndTime,
|
|
|
+ FeedName: req.FeedName,
|
|
|
+ Typea: fmt.Sprintf("%d", req.TypeCheck),
|
|
|
+ },
|
|
|
+ }
|
|
|
+ response := &model.PastureCommonResponse{Data: &model.PastureCommonData{}}
|
|
|
+ if err := s.PastureHttpClient(ctx, model.UrlReportForm, int64(req.PastureId), body, response); err != nil {
|
|
|
+ return nil, xerr.WithStack(err)
|
|
|
}
|
|
|
+ return response, nil
|
|
|
+}
|
|
|
|
|
|
+// SearchFeedStatistics 饲喂效率-效率统计
|
|
|
+func (s *StoreEntry) SearchFeedStatistics(ctx context.Context, req *operationPb.SearchFeedStatisticsRequest) (*model.PastureCommonResponse, error) {
|
|
|
+ body := &model.PastureCommonRequest{
|
|
|
+ Name: req.ApiName,
|
|
|
+ Page: req.Pagination.Page,
|
|
|
+ Offset: req.Pagination.PageOffset,
|
|
|
+ PageCount: req.Pagination.PageSize,
|
|
|
+ ReturnType: "Map",
|
|
|
+ ParamMaps: &model.FeedStatisticsParams{
|
|
|
+ PastureId: fmt.Sprintf("%d", req.PastureId),
|
|
|
+ StartTime: req.StartTime,
|
|
|
+ StopTime: req.StartTime,
|
|
|
+ FeedName: req.FormulaTemplate,
|
|
|
+ BarName: req.BarnName,
|
|
|
+ CowClass: req.CattleCategoryName,
|
|
|
+ Times: fmt.Sprintf("%d", req.ClassNumber),
|
|
|
+ },
|
|
|
+ }
|
|
|
+ response := &model.PastureCommonResponse{Data: &model.PastureCommonData{}}
|
|
|
+ if err := s.PastureHttpClient(ctx, model.UrlDataByName, int64(req.PastureId), body, response); err != nil {
|
|
|
+ return nil, xerr.WithStack(err)
|
|
|
+ }
|
|
|
+ return response, nil
|
|
|
+}
|
|
|
+
|
|
|
+// FeedChartStatistics 饲喂效率图表分析
|
|
|
+func (s *StoreEntry) FeedChartStatistics(ctx context.Context, req *operationPb.FeedChartStatisticsRequest) (*model.PastureCommonResponse, error) {
|
|
|
+ body := &model.FeedChartParams{
|
|
|
+ ParamMaps: &model.ParamMaps{
|
|
|
+ PastureId: fmt.Sprintf("%d", req.PastureId),
|
|
|
+ StartTime: req.StartTime,
|
|
|
+ StopTime: req.StartTime,
|
|
|
+ Status: req.Status,
|
|
|
+ },
|
|
|
+ }
|
|
|
+ url, ok := model.FeedCharUrl[req.ApiType]
|
|
|
+ if !ok {
|
|
|
+ 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 {
|
|
|
+ return nil, xerr.WithStack(err)
|
|
|
+ }
|
|
|
return response, nil
|
|
|
}
|
|
|
|