|
@@ -0,0 +1,183 @@
|
|
|
+package xiangyu
|
|
|
+
|
|
|
+import (
|
|
|
+ "encoding/json"
|
|
|
+ "errors"
|
|
|
+ "eta/eta_bridge/global"
|
|
|
+ "fmt"
|
|
|
+ "io"
|
|
|
+ "net/http"
|
|
|
+ "strings"
|
|
|
+)
|
|
|
+
|
|
|
+// IndexErrResp
|
|
|
+// @Description: 错误信息返回
|
|
|
+type IndexErrResp struct {
|
|
|
+ ErrCode string `json:"errcode" description:"失败编码 1001:缺少参数client_id, 2001:缺少参数access_token, 2006:缺少参数uid, 2002:参数access _token,不正确或过期, 1005:参数client_id非法"`
|
|
|
+ Msg string `json:"msg" description:"失败信息"`
|
|
|
+}
|
|
|
+
|
|
|
+// PushResp
|
|
|
+// @Description: push数据返回
|
|
|
+type PushResp struct {
|
|
|
+ IndexErrResp
|
|
|
+ AccessToken string `json:"access_token"`
|
|
|
+ RefreshToken string `json:"refresh_token"`
|
|
|
+ Uid string `json:"uid"`
|
|
|
+ ExpiresIn int `json:"expires_in"`
|
|
|
+}
|
|
|
+
|
|
|
+type PushDataReq struct {
|
|
|
+ In0 In0 `json:"in0"`
|
|
|
+ Parameters PushDataParamReq `json:"parameters" description:"业务报文"`
|
|
|
+}
|
|
|
+
|
|
|
+// PushDataParamReq
|
|
|
+// @Description: 业务报文
|
|
|
+type PushDataParamReq struct {
|
|
|
+ SerialID string `json:"serialID" description:"流水号"`
|
|
|
+ TableCode string `json:"tableCode" description:"数据表编码"`
|
|
|
+ Total int `json:"total" description:"本次落表数据总数"`
|
|
|
+ IsEmailWarn int `json:"isEmailWarn" description:"是否发送预警邮件,(1-是 0-否)"`
|
|
|
+ Data []PushDataParamDataReq `json:"data" description:"报文体,指标数据列表"`
|
|
|
+}
|
|
|
+
|
|
|
+// PushDataParamDataReq
|
|
|
+// @Description: 指标数据结构
|
|
|
+type PushDataParamDataReq struct {
|
|
|
+ SourceIndexCode string `json:"source_index_code" description:"上游来源指标ID"`
|
|
|
+ IndexCode string `json:"Index_code" description:""`
|
|
|
+ IndexName string `json:"index_name" description:""`
|
|
|
+ IndexShortName string `json:"index_short_name" description:""`
|
|
|
+ FrequenceName string `json:"frequence_name" description:""`
|
|
|
+ UnitName string `json:"unit_name" description:""`
|
|
|
+ //CountryName string `json:"country_name" description:""`
|
|
|
+ //ProvinceName string `json:"province_name" description:""`
|
|
|
+ //AreaName string `json:"area_name" description:""`
|
|
|
+ //CityName string `json:"city_name" description:""`
|
|
|
+ //CountyName string `json:"county_name" description:""`
|
|
|
+ //RegionName string `json:"region_name" description:""`
|
|
|
+ //CompanyName string `json:"company_name" description:""`
|
|
|
+ //BreedName string `json:"breed_name" description:""`
|
|
|
+ //MaterialName string `json:"material_name" description:""`
|
|
|
+ //SpecName string `json:"spec_name" description:""`
|
|
|
+ //MarketName string `json:"market_name" description:""`
|
|
|
+ //DerivativeType string `json:"derivative_type" description:""`
|
|
|
+ //ContractName string `json:"contract_name" description:""`
|
|
|
+ //AuthKindName string `json:"auth_kind_name" description:""`
|
|
|
+ //CustomSmallClassName string `json:"custom_small_class_name" description:""`
|
|
|
+ AssetBeginDate string `json:"asset_begin_date" description:""`
|
|
|
+ AssetEndDate string `json:"asset_end_date" description:""`
|
|
|
+ CreateUser string `json:"create_user" description:""`
|
|
|
+ IndexCreateTime string `json:"index_create_time" description:""`
|
|
|
+ UpdateUser string `json:"update_user" description:""`
|
|
|
+ DetailUpdateTime string `json:"detail_update_time" description:""`
|
|
|
+ IndexUpdateTime string `json:"index_update_time" description:""`
|
|
|
+ //DutyDept string `json:"duty_dept" description:""`
|
|
|
+ //BusinessDept string `json:"business_dept" description:""`
|
|
|
+ OrginSource string `json:"orgin_source" description:""`
|
|
|
+ OrginSysSource string `json:"orgin_sys_source" description:""`
|
|
|
+ SysSource string `json:"sys_source" description:""`
|
|
|
+ SourceType string `json:"source_type" description:""`
|
|
|
+ Status int `json:"status" description:""`
|
|
|
+}
|
|
|
+
|
|
|
+type PushDataResp struct {
|
|
|
+ Out struct {
|
|
|
+ ReturnCode string `json:"returnCode"`
|
|
|
+ ReturnMsg string `json:"returnMsg"`
|
|
|
+ Data int `json:"data"`
|
|
|
+ } `json:"out"`
|
|
|
+}
|
|
|
+
|
|
|
+// GetToken
|
|
|
+// @Description: 获取token信息
|
|
|
+// @author: Roc
|
|
|
+// @datetime 2024-01-23 15:40:56
|
|
|
+// @param code string
|
|
|
+// @return resp *GetTokenResp
|
|
|
+// @return err error
|
|
|
+func PushData(data PushDataParamReq) (resp *PushDataResp, err error) {
|
|
|
+ urlPath := `/DAQ/CY/ProxyServices/pushMarketPricePS`
|
|
|
+ req := PushDataReq{
|
|
|
+ In0: In0{
|
|
|
+ PageTotal: "",
|
|
|
+ PageNo: "",
|
|
|
+ DocType: "pushMarketPricePS",
|
|
|
+ Property: "",
|
|
|
+ //DocCode: getDocCode(),
|
|
|
+ Source: global.CONFIG.Xiangyu.SystemCode,
|
|
|
+ Target: global.CONFIG.Xiangyu.UserSyncTarget,
|
|
|
+ },
|
|
|
+ Parameters: data,
|
|
|
+ }
|
|
|
+
|
|
|
+ postData, err := json.Marshal(req)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ result, err := HttpPostIndex(urlPath, string(postData))
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 解析响应结果
|
|
|
+ err = json.Unmarshal(result, &resp)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if resp.Out.ReturnCode != "S" {
|
|
|
+ err = errors.New(fmt.Sprintf("响应代码:%s,错误信息:%s", resp.Out.ReturnCode, resp.Out.ReturnMsg))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// HttpPostIndex
|
|
|
+// @Description: post请求
|
|
|
+// @author: Roc
|
|
|
+// @datetime 2024-02-27 18:45:30
|
|
|
+// @param urlPath string
|
|
|
+// @param postData string
|
|
|
+// @return []byte
|
|
|
+// @return error
|
|
|
+func HttpPostIndex(urlPath, postData string) ([]byte, error) {
|
|
|
+ if global.CONFIG.Xiangyu.IndexSyncHost == `` {
|
|
|
+ return nil, errors.New("数仓同步接口地址为空")
|
|
|
+ }
|
|
|
+ // 请求地址
|
|
|
+ postUrl := global.CONFIG.Xiangyu.IndexSyncHost + 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.Header.Set("Authorization", global.CONFIG.Xiangyu.IndexSyncAuth)
|
|
|
+
|
|
|
+ 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("指标同步服务:地址:" + postUrl + ";\n请求参数:" + postData + ";\n返回参数:" + string(result))
|
|
|
+
|
|
|
+ // 解析返回参数,判断是否是json
|
|
|
+ if !json.Valid(result) {
|
|
|
+ err = errors.New("返回参数不是json格式")
|
|
|
+ }
|
|
|
+
|
|
|
+ return result, err
|
|
|
+}
|