|
@@ -0,0 +1,228 @@
|
|
|
+package xiangyu
|
|
|
+
|
|
|
+import (
|
|
|
+ "encoding/json"
|
|
|
+ "errors"
|
|
|
+ "eta/eta_bridge/global"
|
|
|
+ "fmt"
|
|
|
+ "io"
|
|
|
+ "net/http"
|
|
|
+ "net/url"
|
|
|
+ "strings"
|
|
|
+)
|
|
|
+
|
|
|
+type PostGetIndexDataParamReq struct {
|
|
|
+ PageNum int `json:"pageNum" description:"页码,先取第一页,看一下总条数,然后根据总条数给返回"`
|
|
|
+ PageSize int `json:"pageSize" description:"单页条数,自己填,一页要多少条,最大2000条"`
|
|
|
+ AssetCd string `json:"assetCd" description:"资产编码,与资产包编码二选一填写,该类业务数据在数仓中的唯一编码,该编码由数仓提供给项目组"`
|
|
|
+ AssetPkgCd string `json:"assetPkgCd" description:"资产包编码,与资产编码二选一填写,传入该参数时,将返回该资产包内的所有资产,该编码由数仓提供给项目组"`
|
|
|
+ DataDt string `json:"dataDt" description:"数据日期,如2022年5月25日的铝的市价,数据日期则为20220525"`
|
|
|
+ StartDt string `json:"startDt" description:"启始时间,格式 YYYYMMDD 如:20211010;不为空时,将过滤出数据日期>=startDate 的数据行"`
|
|
|
+ EndDt string `json:"endDt" description:"结束时间,格式 YYYYMMDD 如:20211010;不为空时,将过滤出数据日期<=endDate 的数据行"`
|
|
|
+ Sort string `json:"sort" description:"排序字段,默认为0正序;按数据日期字段排序,0为正序 1为倒序"`
|
|
|
+ DataSourceType string `json:"dataSourceType" description:"内部来源系统参数,可只获取对应数据源数据,不传则默认获取所有数据源信息;参数含义:① CY产研平台;② RPA;③ KSF 金仕达;④CRM参数例子: CY,RPA,KSF,CRM (参数传递字符串列表,通过逗号分隔)"`
|
|
|
+ InfoLastUpdateStartTime string `json:"infoLastUpdateStartTime" description:"资产信息数据落到数仓时间,参数:YYYYMMDD HH24:MI:SS 如:20240229 18:00:00 不为空时,将过滤出 资产信息入库时间>=infoLastUpdateStartTime 的数据行"`
|
|
|
+ InfoLastUpdateEndTime string `json:"infoLastUpdateEndTime" description:"资产信息数据落到数仓时间,参数:YYYYMMDD HH24:MI:SS 如:20240229 18:00:00 不为空时,将过滤出 资产信息入库时间<=infoLastUpdateStartTime 的数据行"`
|
|
|
+ DetailLastUpdateStartTime string `json:"detailLastUpdateStartTime" description:"明细数据落到数仓启始时间,参数:YYYYMMDD HH24:MI:SS 如:20240229 18:00:00 不为空时,将过滤出 资产详细信息入库时间>=detailLastUpdateStartTime 的数据行,建议延迟15分钟抽取"`
|
|
|
+ DetailLastUpdateEndTime string `json:"detailLastUpdateEndTime" description:"明细数据落到数仓结束时间,参数:YYYYMMDD HH24:MI:SS 如:20240229 18:00:00 不为空时,将过滤出 资产详细信息入库时间<=detailLastUpdateStartTime 的数据行,建议延迟15分钟抽取"`
|
|
|
+
|
|
|
+ //CommonParameters In0 `json:"commonParameters" description:"公共参数"`
|
|
|
+}
|
|
|
+
|
|
|
+func structToURLParams(req interface{}) (string, error) {
|
|
|
+ // 首先,将结构体转换为map[string]interface{}
|
|
|
+ marshaledBytes, err := json.Marshal(req)
|
|
|
+ if err != nil {
|
|
|
+ return "", err
|
|
|
+ }
|
|
|
+
|
|
|
+ var params map[string]interface{}
|
|
|
+ err = json.Unmarshal(marshaledBytes, ¶ms)
|
|
|
+ if err != nil {
|
|
|
+ return "", err
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建url.Values,它是一个键值对的集合,用于构建URL查询字符串
|
|
|
+ values := url.Values{}
|
|
|
+ for key, value := range params {
|
|
|
+ values.Set(key, fmt.Sprintf("%v", value))
|
|
|
+ }
|
|
|
+
|
|
|
+ // 返回查询字符串
|
|
|
+ return values.Encode(), nil
|
|
|
+}
|
|
|
+
|
|
|
+// CrmBaseResp
|
|
|
+// @Description: Crm基础信息返回
|
|
|
+type CrmBaseResp struct {
|
|
|
+ ErrCode int `json:"errCode"`
|
|
|
+ RequestId string `json:"requestId"`
|
|
|
+ ErrMsg string `json:"errMsg"`
|
|
|
+ ApiLog interface{} `json:"apiLog"`
|
|
|
+}
|
|
|
+
|
|
|
+// GetCrmDataResp
|
|
|
+// @Description: CRM数据接口返回
|
|
|
+type GetCrmDataResp struct {
|
|
|
+ CrmBaseResp
|
|
|
+ Data CrmDataResp `json:"data"`
|
|
|
+}
|
|
|
+
|
|
|
+// CrmDataResp
|
|
|
+// @Description: 实际数据返回
|
|
|
+type CrmDataResp struct {
|
|
|
+ TotalNum int `json:"totalNum"`
|
|
|
+ PageSize int `json:"pageSize"`
|
|
|
+ Rows []CrmDataItemResp `json:"rows"`
|
|
|
+ PageNum int `json:"pageNum"`
|
|
|
+}
|
|
|
+
|
|
|
+// CrmDataItemResp
|
|
|
+// @Description: 指标数据返回
|
|
|
+type CrmDataItemResp struct {
|
|
|
+ Price float64 `json:"price"`
|
|
|
+ DataDt string `json:"datadt"`
|
|
|
+ UpdateTime string `json:"updatetime"`
|
|
|
+ AssetCd string `json:"assetcd"`
|
|
|
+ MarketName string `json:"marketname"`
|
|
|
+ AreaName string `json:"areaname"`
|
|
|
+ AssetName string `json:"assetname"`
|
|
|
+ Currency interface{} `json:"currency"`
|
|
|
+ MaterialName string `json:"materialname"`
|
|
|
+ SpecName string `json:"specname"`
|
|
|
+ BreedName string `json:"breedname"`
|
|
|
+ UnitName string `json:"unitname"`
|
|
|
+ SourceName string `json:"sourcename"`
|
|
|
+ FrequencyName string `json:"frequencyname"`
|
|
|
+ CountryName string `json:"countryname"`
|
|
|
+ ProvinceName string `json:"provincename"`
|
|
|
+ CityName string `json:"cityname"`
|
|
|
+ CountyName string `json:"countyname"`
|
|
|
+ CompanyName string `json:"companyname"`
|
|
|
+ Description string `json:"description"`
|
|
|
+ BeginDate string `json:"begindate"`
|
|
|
+ EndDate string `json:"enddate"`
|
|
|
+ CreateTime string `json:"createtime"`
|
|
|
+ Status interface{} `json:"status"`
|
|
|
+ PublishRuleName string `json:"publishrulename"`
|
|
|
+ AuthKind *string `json:"authkind"`
|
|
|
+ SmallClassName interface{} `json:"smallclassname"`
|
|
|
+ DataSource string `json:"datasource"`
|
|
|
+ DataSourceType string `json:"datasourcetype"`
|
|
|
+ OrginSysSource interface{} `json:"orginsyssource"`
|
|
|
+ SourceType interface{} `json:"sourcetype"`
|
|
|
+ DeptCd string `json:"deptcd"`
|
|
|
+ DutyDept string `json:"dutydept"`
|
|
|
+ DerivativeType string `json:"derivativetype"`
|
|
|
+ StkCode string `json:"stkcode"`
|
|
|
+ StkName string `json:"stkname"`
|
|
|
+ MetricName string `json:"metricname"`
|
|
|
+ AssetInfoStockInTime string `json:"asset_info_stock_in_time" description:"资产信息数据落到数仓时间,参数:YYYYMMDD HH24:MI:SS;如:20240229 18:00:00"`
|
|
|
+ DetailDataStockInTime string `json:"detail_data_stock_in_time" description:"明细数据落到数仓时间,参数:YYYYMMDD HH24:MI:SS;如:20240229 18:00:00"`
|
|
|
+}
|
|
|
+
|
|
|
+// PostGetCrmData
|
|
|
+// @Description: 获取CRM数据
|
|
|
+// @author: Roc
|
|
|
+// @datetime 2024-05-14 16:45:40
|
|
|
+// @param req PostGetIndexDataParamReq
|
|
|
+// @return dataResp *CrmDataResp
|
|
|
+// @return err error
|
|
|
+func PostGetCrmData(req PostGetIndexDataParamReq) (dataResp CrmDataResp, err error) {
|
|
|
+ urlPath := `/xmxygtest/dasc/test/mpdata/index/data`
|
|
|
+ //req.CommonParameters = In0{
|
|
|
+ // PageTotal: "",
|
|
|
+ // PageNo: "",
|
|
|
+ // DocType: "数仓市价服务",
|
|
|
+ // Property: "",
|
|
|
+ // //DocCode: getDocCode(),
|
|
|
+ // Source: global.CONFIG.Xiangyu.SystemCode,
|
|
|
+ // Target: global.CONFIG.Xiangyu.IndexCrmTarget,
|
|
|
+ //}
|
|
|
+
|
|
|
+ queryString, err := structToURLParams(req)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("Error:", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ urlPath += "?" + queryString
|
|
|
+
|
|
|
+ postData, err := json.Marshal(req)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ result, err := HttpPostXmxyg(urlPath, string(postData))
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var resp *GetCrmDataResp
|
|
|
+ // 解析响应结果
|
|
|
+ err = json.Unmarshal(result, &resp)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if resp.ErrCode != 0 {
|
|
|
+ err = errors.New(fmt.Sprintf("响应代码:%d,错误信息:%s", resp.ErrCode, resp.ErrMsg))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ dataResp = resp.Data
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// HttpPostXmxyg
|
|
|
+// @Description: post请求
|
|
|
+// @author: Roc
|
|
|
+// @datetime 2024-02-27 18:45:30
|
|
|
+// @param urlPath string
|
|
|
+// @param postData string
|
|
|
+// @return []byte
|
|
|
+// @return error
|
|
|
+func HttpPostXmxyg(urlPath, postData string) ([]byte, error) {
|
|
|
+ if global.CONFIG.Xiangyu.IndexCrmHost == `` {
|
|
|
+ return nil, errors.New("crm数据平台地址为空")
|
|
|
+ }
|
|
|
+ // 请求地址
|
|
|
+ postUrl := global.CONFIG.Xiangyu.IndexCrmHost + urlPath
|
|
|
+
|
|
|
+ body := io.NopCloser(strings.NewReader(postData))
|
|
|
+ client := &http.Client{}
|
|
|
+ req, err := http.NewRequest("POST", postUrl, body)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ req.Header.Set("content-Type", "application/json; charset=utf-8")
|
|
|
+ req.Header.Set("Accept-Encoding", "application/json; charset=utf-8")
|
|
|
+ req.Header.Set("Accept", "application/json; charset=utf-8")
|
|
|
+
|
|
|
+ // 鉴权
|
|
|
+ req.SetBasicAuth(global.CONFIG.Xiangyu.IndexSyncAuthUserName, global.CONFIG.Xiangyu.IndexSyncAuthPwd)
|
|
|
+
|
|
|
+ // 秘钥
|
|
|
+ if global.CONFIG.Xiangyu.IndexKey != `` {
|
|
|
+ req.Header.Set("deipaaskeyauth", global.CONFIG.Xiangyu.IndexKey)
|
|
|
+ }
|
|
|
+
|
|
|
+ resp, err := client.Do(req)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ defer resp.Body.Close()
|
|
|
+ result, err := io.ReadAll(resp.Body)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ // 日志记录
|
|
|
+ global.FILE_LOG.Debug("crm数据平台:地址:" + postUrl + ";\n请求参数:" + postData + ";\n返回参数:" + string(result))
|
|
|
+
|
|
|
+ // 解析返回参数,判断是否是json
|
|
|
+ if !json.Valid(result) {
|
|
|
+ err = errors.New("返回参数不是json格式")
|
|
|
+ }
|
|
|
+
|
|
|
+ return result, err
|
|
|
+}
|