| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833 | package backendimport (	"bytes"	"context"	"encoding/json"	"errors"	"fmt"	"kpt-tmr-group/model"	"kpt-tmr-group/pkg/logger/zaplog"	"kpt-tmr-group/pkg/xerr"	operationPb "kpt-tmr-group/proto/go/backend/operation"	"net/http"	"sort"	"sync"	"gorm.io/gorm"	"github.com/xuri/excelize/v2"	"go.uber.org/zap")type PastureClientHandler func(ctx context.Context, pastureId int64, body interface{}) error// PastureDetailById 获取指定牧场详情func (s *StoreEntry) PastureDetailById(ctx context.Context, pastureId int64) (*model.GroupPasture, error) {	result := &model.GroupPasture{Id: pastureId}	if err := s.DB.Where("is_delete = ? and is_show = ?", operationPb.IsShow_OK, operationPb.IsShow_OK).First(result).Error; err != nil {		return nil, xerr.WithStack(err)	}	return result, nil}func (s *StoreEntry) PastureHttpClient(ctx context.Context, apiUrl string, pastureId int64, body, response interface{}) (*model.GroupPasture, error) {	pastureDetail, err := s.PastureDetailById(ctx, pastureId)	if err != nil {		if errors.Is(err, gorm.ErrRecordNotFound) {			return nil, xerr.Customf("该牧场不存在")		}		zaplog.Error("PastureHttpClient", zap.Any("Err", err), zap.Int64("pastureId", pastureId))		return nil, 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)	}	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 pastureDetail, nil}// SearchFormulaEstimateList 配方评估func (s *StoreEntry) SearchFormulaEstimateList(ctx context.Context, req *operationPb.SearchFormulaEstimateRequest) (*model.PastureCommonResponse, error) {	groupPasture, err := s.GetGroupPastureListById(ctx, int64(req.PastureId))	if err != nil {		return nil, xerr.WithStack(err)	}	if groupPasture.PastureId > 0 {		req.PastureId = int32(groupPasture.PastureId)	}	body := &model.PastureCommonRequest{		Name:       req.ApiName,		Page:       req.Pagination.Page,		Offset:     req.Pagination.PageOffset,		PageCount:  req.Pagination.PageSize,		ReturnType: "Map",		ParamMaps: &model.FormulaEstimateParams{			PastureId: fmt.Sprintf("%d", req.PastureId),			StartTime: req.StartTime,			StopTime:  req.EndTime,			Search:    fmt.Sprintf("%d", req.SearchType),			TempletId: fmt.Sprintf("%d", req.TemplateId),			Barid:     fmt.Sprintf("%d", req.BarnId),		},	}	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}// SearchInventoryStatistics 库存管理-库存统计func (s *StoreEntry) SearchInventoryStatistics(ctx context.Context, req *operationPb.SearchInventoryStatisticsRequest) (*model.PastureCommonResponse, error) {	groupPasture, err := s.GetGroupPastureListById(ctx, int64(req.PastureId))	if err != nil {		return nil, xerr.WithStack(err)	}	if groupPasture.PastureId > 0 {		req.PastureId = int32(groupPasture.PastureId)	}	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)	}	return response, nil}// InventoryStatisticsExcelExport 库存管理-库存统计-报表导出func (s *StoreEntry) InventoryStatisticsExcelExport(ctx context.Context, req *operationPb.SearchInventoryStatisticsRequest) (*bytes.Buffer, error) {	result, err := s.SearchInventoryStatistics(ctx, req)	if err != nil {		return nil, xerr.WithStack(err)	}	b, _ := json.Marshal(result.Data.List)	inventoryStatisticsList := make([]*model.InventoryStatisticsList, 0)	if err = json.Unmarshal(b, &inventoryStatisticsList); err != nil {		return nil, xerr.Customf("牧场端返回数据错误")	}	file := excelize.NewFile()	defer file.Close()	streamWriter, err := file.NewStreamWriter(model.DefaultSheetName)	if err != nil {		return nil, xerr.WithStack(err)	}	// 表头	titles := map[string][]interface{}{		"A1": {"饲料名称", "期初", nil, "用料", nil, nil, nil, "期末"},		"A2": {nil, "期初库存(kg)", "期初金额(元)", "入库重量(kg)", "系统出库重量(kg)", "人工用料重量(kg)", "损耗重量", "期末库存(kg)", "期末金额(kg)"},	}	for cell, values := range titles {		if err = streamWriter.SetRow(cell, values); err != nil {			return nil, xerr.WithStack(err)		}	}	for i, item := range inventoryStatisticsList {		cell, err := excelize.CoordinatesToCellName(1, i+3)		if err != nil {			zaplog.Error("InventoryStatisticsExcelExport CoordinatesToCellName", zap.Any("Err", err))			continue		}		row := make([]interface{}, 0)		row = append(row, item.FeedName, item.StartSum, item.StartPrice, item.LaidSum, item.UseSumXT, item.UseSumRG, item.UseSumXH, item.StopSum, item.StopPrice)		if err = streamWriter.SetRow(cell, row); err != nil {			return nil, xerr.WithStack(err)		}	}	hvCell := map[string]string{		"A1": "A2",		"B1": "C1",		"D1": "G1",		"H1": "I1",	}	// 合并单元格	for h, v := range hvCell {		if err = streamWriter.MergeCell(h, v); err != nil {			return nil, xerr.WithStack(err)		}	}	// 修改样式	/*style1, err := file.NewStyle(&excelize.Style{		Fill:      excelize.Fill{Type: "pattern", Color: []string{"#DFEBF6"}, Pattern: 1},		Alignment: &excelize.Alignment{Horizontal: "center"},	})	if err != nil {		return nil, xerr.WithStack(err)	}	style1, err := file.NewStyle(&excelize.Style{		//Fill:      excelize.Fill{Type: "pattern", Color: []string{"#DFEBF6"}, Pattern: 1},		Alignment: &excelize.Alignment{Horizontal: "center"},	})	if err != nil {		return nil, xerr.WithStack(err)	}	if err = file.SetCellStyle(model.DefaultSheetName, "A1", "A1", style1); err != nil {		return nil, xerr.WithStack(err)	}*/	if err = streamWriter.Flush(); err != nil {		return nil, xerr.WithStack(err)	}	return file.WriteToBuffer()}// SearchUserMaterialsStatistics 库存管理-用料分析func (s *StoreEntry) SearchUserMaterialsStatistics(ctx context.Context, req *operationPb.SearchUserMaterialsStatisticsRequest) (*model.PastureCommonResponse, error) {	groupPasture, err := s.GetGroupPastureListById(ctx, int64(req.PastureId))	if err != nil {		return nil, xerr.WithStack(err)	}	if groupPasture.PastureId > 0 {		req.PastureId = int32(groupPasture.PastureId)	}	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{		List: &model.UserMaterialsList{},	}}	if _, err := s.PastureHttpClient(ctx, model.UrlReportForm, int64(req.PastureId), body, response); err != nil {		return nil, xerr.WithStack(err)	}	return response, nil}func (s *StoreEntry) UserMaterialsStatisticsExcelExport(ctx context.Context, req *operationPb.SearchUserMaterialsStatisticsRequest) (*bytes.Buffer, error) {	result, err := s.SearchUserMaterialsStatistics(ctx, req)	if err != nil {		return nil, xerr.WithStack(err)	}	b, _ := json.Marshal(result.Data.List)	userMaterialsList := &model.UserMaterialsList{}	if err = json.Unmarshal(b, userMaterialsList); err != nil {		return nil, xerr.Customf("牧场端返回数据错误")	}	file := excelize.NewFile()	defer file.Close()	streamWriter, err := file.NewStreamWriter(model.DefaultSheetName)	if err != nil {		return nil, xerr.WithStack(err)	}	// 表数据	excelValuesList := map[int][]interface{}{}	cProp := make([]string, 0)	for _, data2 := range userMaterialsList.Data2 {		excelValuesList[1] = append(excelValuesList[1], data2.Label)		for _, c := range data2.Children {			excelValuesList[2] = append(excelValuesList[2], c.Label)			cProp = append(cProp, c.Prop)		}	}	for cell, values := range excelValuesList {		if err = streamWriter.SetRow(fmt.Sprintf("A%d", cell), values); err != nil {			return nil, xerr.WithStack(err)		}		delete(excelValuesList, cell)	}	for i, data1 := range userMaterialsList.Data1 {		data1Map, ok := data1.(map[string]interface{})		if ok {			for _, prop := range cProp {				newValue := ""				if value, yes := data1Map[prop]; yes {					if value != nil {						switch v := value.(type) {						case string:							newValue = v						case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64:							newValue = fmt.Sprintf("%d", v)						default:							newValue = fmt.Sprintf("%v", v)						}					}					excelValuesList[i+3] = append(excelValuesList[i+3], newValue)				}			}		}	}	excelValuesKeys := make([]int, 0)	for k, _ := range excelValuesList {		excelValuesKeys = append(excelValuesKeys, k)	}	sort.Ints(excelValuesKeys)	for _, v := range excelValuesKeys {		if err = streamWriter.SetRow(fmt.Sprintf("A%d", v), excelValuesList[v]); err != nil {			return nil, xerr.WithStack(err)		}	}	if err = streamWriter.Flush(); err != nil {		return nil, xerr.WithStack(err)	}	return file.WriteToBuffer()}// SearchPriceStatistics 库存管理-价格分析func (s *StoreEntry) SearchPriceStatistics(ctx context.Context, req *operationPb.SearchPriceStatisticsRequest) (*model.PastureCommonResponse, error) {	groupPasture, err := s.GetGroupPastureListById(ctx, int64(req.PastureId))	if err != nil {		return nil, xerr.WithStack(err)	}	if groupPasture.PastureId > 0 {		req.PastureId = int32(groupPasture.PastureId)	}	body := &model.PastureCommonRequest{		Name:       req.ApiName,		Page:       req.Pagination.Page,		Offset:     req.Pagination.PageOffset,		PageCount:  req.Pagination.PageSize,		ReturnType: "Map",		ParamMaps: &model.PriceStatisticsParams{			PastureId: fmt.Sprintf("%d", req.PastureId),			StartTime: req.StartTime,			StopTime:  req.EndTime,			FeedName:  req.FeedName,		},	}	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.FeedStatisticsResponse, error) {	res := &model.FeedStatisticsResponse{		Code: http.StatusOK,		Msg:  "ok",		Data: &model.FeedStatisticsData{			List: make(map[string]interface{}),		},	}	if len(req.PastureId) <= 0 {		return res, nil	}	if req.CattleCategoryId > 0 {		cattleList := s.ForageEnumList(ctx).Data.CattleParentCategory		for _, v := range cattleList {			if v.Value == operationPb.CattleCategoryParent_Kind(req.CattleCategoryId) {				req.CattleCategoryName = v.Label				break			}		}	}	times := ""	if req.ClassNumber > 0 {		times = fmt.Sprintf("%d", req.ClassNumber)	}	wg := sync.WaitGroup{}	wg.Add(len(req.PastureId))	for _, v := range req.PastureId {		go func(pastureId int32) {			defer wg.Done()			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", pastureId),					StartTime: req.StartTime,					StopTime:  req.StartTime,					Date:      req.StartTime,					FeedTName: req.FormulaTemplate,					BarName:   req.BarnName,					CowClass:  req.CattleCategoryName,					Times:     times,				},			}			response := &model.PastureCommonResponse{				Data: &model.PastureCommonData{},			}			groupPasture, err := s.PastureHttpClient(ctx, model.UrlDataByName, int64(pastureId), body, response)			if err != nil {				zaplog.Error("SearchFeedStatistics",					zap.Any("pastureId", pastureId),					zap.Any("url", model.UrlDataByName),					zap.Any("body", body),					zap.Any("response", response))				return			}			if response.Code == http.StatusOK && response.Data.List != nil {				if req.ApiName == "getFeedEfficiencySC" {					feedStatisticsConversions := FeedStatisticsConversions(response.Data.List)					feedStatisticsConversions.PastureName = groupPasture.Name					res.Data.List[groupPasture.Name] = FeedStatisticsConversions(response.Data.List)				} else {					res.Data.List[groupPasture.Name] = response.Data.List				}			}		}(v)	}	wg.Wait()	return res, nil}// FeedStatisticsConversions 数据转换func FeedStatisticsConversions(req interface{}) *model.FeedStatisticsConversions {	feedStatisticsList := &model.FeedStatisticsConversions{}	if data, ok := req.([]interface{}); ok && len(data) > 0 {		value := data[0]		if v, yes := value.(map[string]interface{}); yes {			if d, t := v["TMR干物质"]; t {				feedStatisticsList.TmrDryMatter = d.(string)			}			if d, t := v["barname"]; t {				feedStatisticsList.BarName = d.(string)			}			if d, t := v["产奶量"]; t {				feedStatisticsList.MilkYield = d.(string)			}			if d, t := v["今日剩料量"]; t {				feedStatisticsList.TodayLeftovers = d.(string)			}			if d, t := v["公斤奶饲料成本"]; t {				feedStatisticsList.FeedCosts = d.(float64)			}			if d, t := v["剩料率"]; t {				feedStatisticsList.LeftoverRate = d.(string)			}			if d, t := v["实际干物质采食量"]; t {				feedStatisticsList.ActualDryMatterIntake = d.(string)			}			if d, t := v["实际成本"]; t {				feedStatisticsList.ActualCost = d.(string)			}			if d, t := v["实际牛头数"]; t {				feedStatisticsList.ActualNumberOfCattle = d.(string)			}			if d, t := v["应混料量"]; t {				feedStatisticsList.AmountToBeMixed = d.(string)			}			if d, t := v["混料时间"]; t {				feedStatisticsList.MixingTime = d.(string)			}			if d, t := v["牲畜类别"]; t {				feedStatisticsList.CategoryCattleName = d.(string)			}			if d, t := v["理论干物质"]; t {				feedStatisticsList.TheoreticalDryMatter = d.(string)			}			if d, t := v["转投剩料量"]; t {				feedStatisticsList.LeftoverMaterial = d.(float64)			}			if d, t := v["配方干物质采食量"]; t {				feedStatisticsList.FormulatedDryMatterIntake = d.(string)			}			if d, t := v["配方成本"]; t {				feedStatisticsList.CostOfFormulation = d.(string)			}			if d, t := v["采食率"]; t {				feedStatisticsList.FoodIntakeRate = d.(string)			}			if d, t := v["饲料转化率"]; t {				feedStatisticsList.FeedConversionRatio = d.(float64)			}		}	}	return feedStatisticsList}// FeedChartStatistics 饲喂效率图表分析func (s *StoreEntry) FeedChartStatistics(ctx context.Context, req *operationPb.FeedChartStatisticsRequest) (*model.PastureCommonResponse, error) {	groupPasture, err := s.GetGroupPastureListById(ctx, int64(req.PastureId))	if err != nil {		return nil, xerr.WithStack(err)	}	if groupPasture.PastureId > 0 {		req.PastureId = int32(groupPasture.PastureId)	}	body := &model.FeedChartParams{		ParamMaps: &model.ParamMaps{			PastureId: fmt.Sprintf("%d", req.PastureId),			StartTime: req.StartTime,			StopTime:  req.StartTime,			Status:    req.Status,		},	}	url, ok := model.UrlChart[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}// CowsAnalysis 饲喂效率-牛群评估func (s *StoreEntry) CowsAnalysis(ctx context.Context, req *operationPb.CowsAnalysisRequest) (*model.PastureCommonResponse, error) {	groupPasture, err := s.GetGroupPastureListById(ctx, int64(req.PastureId))	if err != nil {		return nil, xerr.WithStack(err)	}	if groupPasture.PastureId > 0 {		req.PastureId = int32(groupPasture.PastureId)	}	body := &model.PastureCommonRequest{		Name:       req.ApiName,		Page:       req.Pagination.Page,		Offset:     req.Pagination.PageOffset,		PageCount:  req.Pagination.PageSize,		ReturnType: "Map",		ParamMaps: &model.MixFeedStatisticsParams{			PastureId: fmt.Sprintf("%d", req.PastureId),			StartTime: req.StartTime,			StopTime:  req.StartTime,		},	}	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}// SearchAccuracyAggStatistics 准确性分析-汇总分析func (s *StoreEntry) SearchAccuracyAggStatistics(ctx context.Context, req *operationPb.AccuracyAggStatisticsRequest) (*model.PastureCommonResponse, error) {	groupPasture, err := s.GetGroupPastureListById(ctx, int64(req.PastureId))	if err != nil {		return nil, xerr.WithStack(err)	}	if groupPasture.PastureId > 0 {		req.PastureId = int32(groupPasture.PastureId)	}	body := &model.FeedChartParams{		ParamMaps: &model.AccuracyAggParams{			PastureId: fmt.Sprintf("%d", req.PastureId),			StartTime: req.StartTime,			StopTime:  req.EndTime,			FName:     req.Fname,			Sort:      req.Sort,			Status:    req.Status,			Times:     req.Times,			Genre:     req.Genre,			IsDate:    req.Isdate,			Hlwc1:     req.Hlwc1,			Hlwc2:     req.Hlwc2,			Hlzq1:     req.Hlzq1,			Hlzq2:     req.Hlzq2,			Hlzql1:    req.Hlzql1,			Hlzql2:    req.Hlzql2,			Slwc1:     req.Slwc1,			Slwc2:     req.Slwc2,			Slzq1:     req.Slzq1,			Slzq2:     req.Slzq2,			Slzql1:    req.Slzql1,			Slzql2:    req.Slzql2,			Error:     req.IsError,		},	}	response := &model.PastureCommonResponse{Data: &model.PastureCommonData{}}	if _, err := s.PastureHttpClient(ctx, model.UrlSummary, int64(req.PastureId), body, response); err != nil {		return nil, xerr.WithStack(err)	}	return response, nil}// SearchMixFeedStatistics 准确性分析-混料统计func (s *StoreEntry) SearchMixFeedStatistics(ctx context.Context, req *operationPb.MixFeedStatisticsRequest) (*model.PastureCommonResponse, error) {	groupPasture, err := s.GetGroupPastureListById(ctx, int64(req.PastureId))	if err != nil {		return nil, xerr.WithStack(err)	}	if groupPasture.PastureId > 0 {		req.PastureId = int32(groupPasture.PastureId)	}	times := ""	if req.ClassNumber > 0 {		times = fmt.Sprintf("%d", req.ClassNumber)	}	body := &model.PastureCommonRequest{		Name:       req.ApiName,		Page:       req.Pagination.Page,		Offset:     req.Pagination.PageOffset,		PageCount:  req.Pagination.PageSize,		ReturnType: "Map",		ParamMaps: &model.MixFeedStatisticsParams{			PastureId:   fmt.Sprintf("%d", req.PastureId),			StartTime:   req.StartTime,			StopTime:    req.StartTime,			TmrTName:    req.EquipmentName,			ProjName:    req.TrainNumber,			Times:       times,			ButtonType:  req.ButtonType,			TempletName: req.FormulationName,			Isuse:       req.IsUse,			Hlwc1:       req.Hlwc1,			Hlwc2:       req.Hlwc2,			Hlzq1:       req.Hlzq1,			Hlzq2:       req.Hlzq2,			Hlzql1:      req.Hlzql1,			Hlzql2:      req.Hlzql2,			Error:       req.IsError,		},	}	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}// SearchSprinkleStatistics 准确性分析-撒料统计func (s *StoreEntry) SearchSprinkleStatistics(ctx context.Context, req *operationPb.SprinkleStatisticsRequest) (*model.PastureCommonResponse, error) {	groupPasture, err := s.GetGroupPastureListById(ctx, int64(req.PastureId))	if err != nil {		return nil, xerr.WithStack(err)	}	if groupPasture.PastureId > 0 {		req.PastureId = int32(groupPasture.PastureId)	}	times := ""	if req.ClassNumber > 0 {		times = fmt.Sprintf("%d", req.ClassNumber)	}	body := &model.PastureCommonRequest{		Name:       req.ApiName,		Page:       req.Pagination.Page,		Offset:     req.Pagination.PageOffset,		PageCount:  req.Pagination.PageSize,		ReturnType: "Map",		ParamMaps: &model.SprinkleStatisticsParams{			PastureId:   fmt.Sprintf("%d", req.PastureId),			StartTime:   req.StartTime,			StopTime:    req.StartTime,			TmrTName:    req.EquipmentName,			ProjName:    req.TrainNumber,			Times:       times,			ButtonType:  req.ButtonType,			TempletName: req.FormulationName,			Isuse:       req.IsUse,			Fname:       req.BarnName,			Slwc1:       req.Slwc1,			Slwc2:       req.Slwc2,			Slzq2:       req.Slzq2,			Slzq1:       req.Slzq1,			Slzql1:      req.Slzql1,			Slzql2:      req.Slzql2,			Error:       req.IsError,		},	}	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}// SearchProcessAnalysis 过程分析func (s *StoreEntry) SearchProcessAnalysis(ctx context.Context, req *operationPb.ProcessAnalysisRequest) (*model.PastureCommonResponse, error) {	groupPasture, err := s.GetGroupPastureListById(ctx, int64(req.PastureId))	if err != nil {		return nil, xerr.WithStack(err)	}	if groupPasture.PastureId > 0 {		req.PastureId = int32(groupPasture.PastureId)	}	body := &model.PastureCommonRequest{		Name:       req.ApiName,		Page:       req.Pagination.Page,		Offset:     req.Pagination.PageOffset,		PageCount:  req.Pagination.PageSize,		ReturnType: "Map",		ParamMaps: &model.ProcessAnalysisParams{			PastureId:   fmt.Sprintf("%d", req.PastureId),			StartTime:   req.StartTime,			StopTime:    req.StartTime,			TmrTName:    req.TmrName,			IsCompleted: "",			LpPlanType:  fmt.Sprintf("%d", req.PlanType),			FClassId:    req.MixFeedType,			Hlzq1:       req.Hlzq1,			Hlzq2:       req.Hlzq2,			Hlwc1:       req.Hlwc1,			Hlwc2:       req.Hlwc2,			Slwc1:       req.Slwc1,			Slwc2:       req.Slwc2,			Slzq2:       req.Slzq2,			Slzq1:       req.Slzq1,			Error:       req.ErrorRange,		},	}	response := &model.PastureCommonResponse{Data: &model.PastureCommonData{}}	if _, err := s.PastureHttpClient(ctx, model.UrlProcess, int64(req.PastureId), body, response); err != nil {		return nil, xerr.WithStack(err)	}	return response, nil}// GetDataByName 共同接口func (s *StoreEntry) GetDataByName(ctx context.Context, req *operationPb.GetDataByNameRequest) (*model.PastureCommonResponse, error) {	groupPasture, err := s.GetGroupPastureListById(ctx, int64(req.PastureId))	if err != nil {		return nil, xerr.WithStack(err)	}	if groupPasture.PastureId > 0 {		req.PastureId = int32(groupPasture.PastureId)	}	body := &model.PastureCommonRequest{		Name: req.ApiName,		ParamMaps: &model.GetDataByNameParams{			PastureId: fmt.Sprintf("%d", req.PastureId),			StartTime: req.StartTime,			StopTime:  req.StartTime,		},	}	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}// GetTrainNumber 获取班次func (s *StoreEntry) GetTrainNumber(ctx context.Context, req *operationPb.TrainNumberRequest) (*operationPb.TrainNumberResponse, error) {	groupPasture, err := s.GetGroupPastureListById(ctx, int64(req.PastureId))	if err != nil {		return nil, xerr.WithStack(err)	}	if groupPasture.PastureId > 0 {		req.PastureId = int32(groupPasture.PastureId)	}	body := &model.PastureCommonRequest{		Name:       req.ApiName,		Page:       req.Pagination.Page,		Offset:     req.Pagination.PageOffset,		PageCount:  req.Pagination.PageSize,		ReturnType: "Map",		ParamMaps: &model.TrainNumberParams{			PastureId: fmt.Sprintf("%d", req.PastureId),			InfoRName: req.InfoName,		},	}	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)	}	result := &operationPb.TrainNumberResponse{		Code: http.StatusOK,		Msg:  "ok",		Data: &operationPb.TrainNumberData{List: make([]*operationPb.FormulaOptionEnum, 0)},	}	if response.Data.List == nil {		return result, nil	}	b, _ := json.Marshal(response.Data.List)	trainNumberList := make([]*model.TrainNumberList, 0)	if err := json.Unmarshal(b, &trainNumberList); err != nil {		return nil, xerr.WithStack(err)	}	formulaOption := make([]*operationPb.FormulaOptionEnum, 0)	if len(trainNumberList) > 0 {		infoValue := trainNumberList[0].InfoValue		switch infoValue {		case "1":			formulaOption = append(formulaOption, &operationPb.FormulaOptionEnum{				Value: 1,				Label: "第一班",			})		case "2":			formulaOption = append(formulaOption, &operationPb.FormulaOptionEnum{				Value: 1,				Label: "第一班",			}, &operationPb.FormulaOptionEnum{				Value: 2,				Label: "第二班",			})		case "3":			formulaOption = append(formulaOption, &operationPb.FormulaOptionEnum{				Value: 1,				Label: "第一班",			}, &operationPb.FormulaOptionEnum{				Value: 2,				Label: "第二班",			}, &operationPb.FormulaOptionEnum{				Value: 3,				Label: "第三班",			})		}	}	result.Data.List = formulaOption	return result, nil}
 |