123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402 |
- 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"`
- }
- // PushIndexReq
- // @Description: 指标推送请求
- type PushIndexReq struct {
- In0 In0 `json:"in0"`
- Parameters PushIndexParamReq `json:"parameters" description:"业务报文"`
- }
- // PushIndexParamReq
- // @Description: 业务报文
- type PushIndexParamReq struct {
- SerialID string `json:"serialID" description:"流水号"`
- TableCode string `json:"tableCode" description:"数据表编码"`
- Total int `json:"total" description:"本次落表数据总数"`
- IsEmailWarn int `json:"isEmailWarn" description:"是否发送预警邮件,(1-是 0-否)"`
- Data []PushIndexItemReq `json:"data" description:"报文体,指标数据列表"`
- }
- // PushIndexItemReq
- // @Description: 指标数据结构
- type PushIndexItemReq 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 PushIndexDataResp struct {
- Out struct {
- ReturnCode string `json:"returnCode"`
- ReturnMsg string `json:"returnMsg"`
- Data int `json:"data"`
- } `json:"out"`
- }
- // PushIndexData
- // @Description: 指标信息推送
- // @author: Roc
- // @datetime 2024-02-28 17:45:03
- // @param data PushIndexParamReq
- // @return resp *PushDataResp
- // @return err error
- func PushIndexData(data PushBaseParamReq) (resp *PushIndexDataResp, err error) {
- urlPath := `/DAQ/CY/ProxyServices/pushMarketPricePS`
- req := PushBaseReq{
- In0: In0{
- PageTotal: "",
- PageNo: "",
- DocType: "pushMarketPricePS",
- Property: "",
- //DocCode: getDocCode(),
- Source: global.CONFIG.Xiangyu.SystemCode,
- Target: global.CONFIG.Xiangyu.IndexSyncTarget,
- },
- 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
- }
- // PushIndexValueReq
- // @Description: 指标日期值推送请求
- type PushIndexValueReq struct {
- In0 In0 `json:"in0"`
- Parameters PushIndexValueParamReq `json:"parameters" description:"业务报文"`
- }
- // PushIndexValueParamReq
- // @Description: 业务报文
- type PushIndexValueParamReq struct {
- SerialID string `json:"serialID" description:"流水号"`
- TableCode string `json:"tableCode" description:"数据表编码"`
- Total int `json:"total" description:"本次落表数据总数"`
- IsEmailWarn int `json:"isEmailWarn" description:"是否发送预警邮件,(1-是 0-否)"`
- Data []PushIndexValueItemReq `json:"data" description:"报文体,指标日期值数据列表"`
- }
- // PushIndexValueItemReq
- // @Description: 指标日期值数据结构
- type PushIndexValueItemReq struct {
- Id string `json:"id"`
- IndexCode string `json:"index_code" description:"指标代码"`
- Value string `json:"value" description:"数值"`
- BusinessDate string `json:"business_date" description:"业务日期(数据日期)"`
- CreateTime string `json:"create_time" description:"数据进入ETA的时间"`
- UpdateTime string `json:"update_time" description:"eta库中修改数据的时间"`
- Status string `json:"status" description:"逻辑删除使用,0-禁用,1-启用"`
- }
- // PushEdbValue
- // @Description: 获取token信息
- // @author: Roc
- // @datetime 2024-01-23 15:40:56
- // @param code string
- // @return resp *GetTokenResp
- // @return err error
- func PushEdbValue(data PushBaseParamReq) (resp *PushIndexDataResp, err error) {
- urlPath := `/DAQ/CY/ProxyServices/pushMarketPricePS`
- req := PushBaseReq{
- In0: In0{
- PageTotal: "",
- PageNo: "",
- DocType: "pushMarketPricePS",
- Property: "",
- //DocCode: getDocCode(),
- Source: global.CONFIG.Xiangyu.SystemCode,
- Target: global.CONFIG.Xiangyu.IndexSyncTarget,
- },
- 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
- }
- // PushBaseReq
- // @Description: 基础请求
- type PushBaseReq struct {
- In0 In0 `json:"in0"`
- Parameters PushBaseParamReq `json:"parameters" description:"业务报文"`
- }
- // PushBaseParamReq
- // @Description: 基础业务报文
- type PushBaseParamReq struct {
- SerialID string `json:"serialID" description:"流水号"`
- TableCode string `json:"tableCode" description:"数据表编码"`
- Total int `json:"total" description:"本次落表数据总数"`
- IsEmailWarn int `json:"isEmailWarn" description:"是否发送预警邮件,(1-是 0-否)"`
- Data interface{} `json:"data" description:"报文体,指标日期值数据列表"`
- }
- // PushClassifyItemReq
- // @Description: 指标分类数据结构
- type PushClassifyItemReq struct {
- ClassifyId int `json:"classify_id" description:"自增id"`
- ClassifyType int `json:"classify_type" description:"分类类型,0:普通指标分类,1:预测指标分类"`
- ClassifyName string `json:"classify_name" description:"分类名称"`
- ParentId int `json:"parent_id" description:"父级id"`
- HasData int `json:"has_data" description:"是否存在指标数据,1:有,2:无"`
- CreateTime string `json:"create_time" description:"创建时间"`
- UpdateTime string `json:"update_time" description:"修改时间"`
- SysUserId int `json:"sys_user_id" description:"创建人id"`
- SysUserRealName string `json:"sys_user_real_name" description:"创建人姓名"`
- Level int `json:"level" description:"层级"`
- UniqueCode string `json:"unique_code" description:"唯一编码"`
- SortColumn int `json:"sort_column" description:"排序字段,越小越靠前,默认值:10"`
- }
- // PushClassify
- // @Description: 推送指标分类
- // @author: Roc
- // @datetime 2024-01-23 15:40:56
- // @param code string
- // @return resp *GetTokenResp
- // @return err error
- func PushClassify(data PushBaseParamReq) (resp *PushIndexDataResp, err error) {
- urlPath := `/DAQ/CY/ProxyServices/pushMarketPricePS`
- req := PushBaseReq{
- In0: In0{
- PageTotal: "",
- PageNo: "",
- DocType: "pushMarketPricePS",
- Property: "",
- //DocCode: getDocCode(),
- Source: global.CONFIG.Xiangyu.SystemCode,
- Target: global.CONFIG.Xiangyu.IndexSyncTarget,
- },
- 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
- }
- // PushBase
- // @Description: 基础推送接口
- // @author: Roc
- // @datetime 2024-01-23 15:40:56
- // @param code string
- // @return resp *GetTokenResp
- // @return err error
- func PushBase(data PushBaseParamReq) (resp *PushIndexDataResp, err error) {
- urlPath := `/DAQ/CY/ProxyServices/pushMarketPricePS`
- req := PushBaseReq{
- In0: In0{
- PageTotal: "",
- PageNo: "",
- DocType: "pushMarketPricePS",
- Property: "",
- //DocCode: getDocCode(),
- Source: global.CONFIG.Xiangyu.SystemCode,
- Target: global.CONFIG.Xiangyu.IndexSyncTarget,
- },
- 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
- }
- // PushEdbClassifyItemReq
- // @Description: 指标与目录的关系请求结构
- type PushEdbClassifyItemReq struct {
- Id string `json:"id" description:"唯一主键"`
- ClassifyId int `json:"classify_id" description:"目录分类ID"`
- IndexCode string `json:"index_code" description:"指标ID"`
- CreateTime string `json:"create_time" description:"创建时间"`
- CreateUser string `json:"create_user" description:"创建人"`
- UpdateTime string `json:"update_time" description:"修改时间"`
- UpdateUser string `json:"update_user" description:"修改人"`
- }
- // 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.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("指标同步服务:地址:" + postUrl + ";\n请求参数:" + postData + ";\n返回参数:" + string(result))
- // 解析返回参数,判断是否是json
- if !json.Valid(result) {
- err = errors.New("返回参数不是json格式")
- }
- return result, err
- }
|