|
@@ -0,0 +1,140 @@
|
|
|
+package services
|
|
|
+
|
|
|
+import (
|
|
|
+ "encoding/json"
|
|
|
+ "eta/eta_mini_api/utils"
|
|
|
+ "fmt"
|
|
|
+ "io"
|
|
|
+ "net/http"
|
|
|
+ "time"
|
|
|
+
|
|
|
+ "github.com/rdlucklib/rdluck_tools/paging"
|
|
|
+)
|
|
|
+
|
|
|
+type ChartInfoView struct {
|
|
|
+ ChartInfoId int `orm:"column(chart_info_id);pk"`
|
|
|
+ ChartName string `description:"来源名称"`
|
|
|
+ ChartNameEn string `description:"英文图表名称"`
|
|
|
+ Unit string `description:"中文单位名称"`
|
|
|
+ UnitEn string `description:"英文单位名称"`
|
|
|
+ ChartClassifyId int `description:"图表分类id"`
|
|
|
+ ChartClassifyName string `description:"图表名称"`
|
|
|
+ SysUserId int
|
|
|
+ SysUserRealName string
|
|
|
+ UniqueCode string `description:"图表唯一编码"`
|
|
|
+ CreateTime time.Time
|
|
|
+ ModifyTime time.Time
|
|
|
+ DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"`
|
|
|
+ StartDate string `description:"自定义开始日期"`
|
|
|
+ EndDate string `description:"自定义结束日期"`
|
|
|
+ IsSetName int `description:"设置名称"`
|
|
|
+ EdbInfoIds string `description:"指标id"`
|
|
|
+ ChartType int `description:"生成样式:1:曲线图,2:季节性图"`
|
|
|
+ Calendar string `description:"公历/农历"`
|
|
|
+ SeasonStartDate string `description:"季节性图开始日期"`
|
|
|
+ SeasonEndDate string `description:"季节性图开始日期"`
|
|
|
+ ChartImage string `description:"图表图片"`
|
|
|
+ Sort int `description:"排序字段,数字越小越排前面"`
|
|
|
+ IsAdd bool `description:"true:已加入我的图库,false:未加入我的图库"`
|
|
|
+ MyChartId int
|
|
|
+ MyChartClassifyId string `description:"我的图表分类,多个用逗号隔开"`
|
|
|
+ ChartClassify []*ChartClassifyView
|
|
|
+ EdbEndDate string `description:"指标最新更新日期"`
|
|
|
+ XMin string `description:"图表X轴最小值"`
|
|
|
+ XMax string `description:"图表X轴最大值"`
|
|
|
+ LeftMin string `description:"图表左侧最小值"`
|
|
|
+ LeftMax string `description:"图表左侧最大值"`
|
|
|
+ RightMin string `description:"图表右侧最小值"`
|
|
|
+ RightMax string `description:"图表右侧最大值"`
|
|
|
+ Right2Min string `description:"图表右侧最小值"`
|
|
|
+ Right2Max string `description:"图表右侧最大值"`
|
|
|
+ MinMaxSave int `description:"是否手动保存过上下限:0-否;1-是"`
|
|
|
+ IsEdit bool `description:"是否有编辑权限"`
|
|
|
+ IsEnChart bool `description:"是否展示英文标识"`
|
|
|
+ WarnMsg string `description:"错误信息"`
|
|
|
+ Disabled int `description:"是否禁用,0:启用,1:禁用,默认:0"`
|
|
|
+ BarConfig string `description:"柱方图的配置,json数据" json:"-"`
|
|
|
+ Source int `description:"1:ETA图库;2:商品价格曲线;3:相关性图表"`
|
|
|
+ //CorrelationLeadUnit string `description:"相关性图表-领先单位"`
|
|
|
+ ExtraConfig string `description:"图表额外配置,json数据"`
|
|
|
+ ChartSource string `description:"图表来源str"`
|
|
|
+ ChartSourceEn string `description:"图表来源(英文)"`
|
|
|
+ Button ChartViewButton `description:"操作按钮"`
|
|
|
+ SeasonExtraConfig string `description:"季节性图表中的配置,json数据"`
|
|
|
+ StartYear int `description:"当选择的日期类型为最近N年类型时,即date_type=20, 用start_year表示N"`
|
|
|
+ ChartThemeId int `description:"图表应用主题ID"`
|
|
|
+ ChartThemeStyle string `description:"图表应用主题样式"`
|
|
|
+ SourcesFrom string `description:"图表来源"`
|
|
|
+ Instructions string `description:"图表说明"`
|
|
|
+ MarkersLines string `description:"标识线"`
|
|
|
+ MarkersAreas string `description:"标识区"`
|
|
|
+ IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
|
|
|
+ HaveOperaAuth bool `description:"是否有数据权限,默认:false"`
|
|
|
+ ForumChartInfoId int `description:"社区的图表ID"`
|
|
|
+}
|
|
|
+
|
|
|
+type ChartClassifyView struct {
|
|
|
+ ChartClassifyId int `orm:"column(chart_classify_id);pk"`
|
|
|
+ ChartClassifyName string `description:"分类名称"`
|
|
|
+ ParentId int `description:"父级id"`
|
|
|
+}
|
|
|
+
|
|
|
+type ChartViewButton struct {
|
|
|
+ IsEdit bool `description:"是否有编辑权限"`
|
|
|
+ IsEnChart bool `description:"是否展示英文标识"`
|
|
|
+ IsAdd bool `description:"true:已加入我的图库,false:未加入我的图库"`
|
|
|
+ IsCopy bool `description:"是否有另存为按钮"`
|
|
|
+ IsSetName int `description:"设置名称"`
|
|
|
+}
|
|
|
+
|
|
|
+type ChartListResp struct {
|
|
|
+ List []*ChartInfoView
|
|
|
+ Paging *paging.PagingItem
|
|
|
+}
|
|
|
+
|
|
|
+type ChartResp[T any] struct {
|
|
|
+ Ret int
|
|
|
+ Data T
|
|
|
+ Msg string
|
|
|
+ ErrMsg string
|
|
|
+}
|
|
|
+
|
|
|
+func GetChartList(currentIndex, pageSize int) (resp *ChartResp[ChartListResp], err error) {
|
|
|
+ url := utils.ETA_MINI_BRIDGE_URL + "/chart/list?"
|
|
|
+ url += fmt.Sprintf("PageSize=%d&CurrentIndex=%d", pageSize, currentIndex)
|
|
|
+ fmt.Println(url)
|
|
|
+ client := &http.Client{}
|
|
|
+ // 提交请求
|
|
|
+ req, err := http.NewRequest("GET", url, nil)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ nonce := utils.GetRandStringNoSpecialChar(16)
|
|
|
+ timestamp := time.Now().Format(utils.FormatDateTimeUnSpace)
|
|
|
+ signature := utils.GetSign(nonce, timestamp, utils.ETA_MINI_APPID, utils.ETA_MINI_APP_SECRET)
|
|
|
+ //增加header选项
|
|
|
+ req.Header.Add("Nonce", nonce)
|
|
|
+ req.Header.Add("Timestamp", timestamp)
|
|
|
+ req.Header.Add("Appid", utils.ETA_MINI_APPID)
|
|
|
+ req.Header.Add("Signature", signature)
|
|
|
+ req.Header.Set("Content-Type", "application/json")
|
|
|
+
|
|
|
+ response, err := client.Do(req)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ defer response.Body.Close()
|
|
|
+
|
|
|
+ body, err := io.ReadAll(response.Body)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ utils.FileLog.Info("result:" + string(body))
|
|
|
+ err = json.Unmarshal(body, &resp)
|
|
|
+ if err != nil {
|
|
|
+ return resp, err
|
|
|
+ }
|
|
|
+ return resp, nil
|
|
|
+
|
|
|
+}
|