123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- package trade_analysis
- import (
- "eta/eta_api/models/data_manage"
- "eta/eta_api/utils"
- "fmt"
- "github.com/beego/beego/v2/client/orm"
- )
- // WarehouseExtraConfig 建仓图表配置
- type WarehouseExtraConfig struct {
- MultipleGraphConfigId int `description:"多图配置ID"`
- WarehouseChartType int `description:"图表类型: 1-多单图; 2-空单图; 3-净多单图"`
- Exchange string `description:"交易所标识"`
- ClassifyName string `description:"品种名称"`
- Contracts []string `description:"合约代码"`
- Companies []string `description:"期货公司, 不超过5个"`
- PredictRatio float64 `description:"预估参数, 0-1之间"`
- }
- // WarehouseChartPars 建仓单表配置
- type WarehouseChartPars struct {
- WarehouseChartType int `description:"图表类型: 1-多单图; 2-空单图; 3-净多单图"`
- DateType int `description:"日期类型"`
- DateTypeNum int `description:"日期类型=25(N月)时的N值"`
- StartDate string `description:"自定义开始日期"`
- EndDate string `description:"自定义结束日期"`
- //ChartThemeId int `description:"图表主题ID"`
- ChartEdbInfoList []*data_manage.ChartSaveItem `description:"指标及配置信息"`
- //SourcesFrom *data_manage.ChartInfoSourcesFrom `description:"图表来源"`
- }
- // WarehouseChartDataResp 图表详情返回信息
- type WarehouseChartDataResp struct {
- WarehouseExtraConfig
- MultiEdbMappings []*WarehouseEdbSaveItem
- }
- // WarehouseEdbSaveItem 建仓指标保存
- type WarehouseEdbSaveItem struct {
- EdbInfoId int `description:"指标ID"`
- EdbName string `description:"指标名称"`
- Unit string `description:"单位"`
- Frequency string `description:"频度"`
- ClassifyId int `description:"指标库分类ID"`
- UniqueFlag string `description:"唯一标识"`
- //ExtraConfig string `description:"配置信息-JSON"`
- }
- type WarehouseEdbSaveRespItem struct {
- WarehouseEdbSaveItem
- Tips string `description:"提示信息"`
- ErrMsg string `description:"错误信息"`
- }
- // CreateWarehouseChart 新增建仓图表
- func CreateWarehouseChart(chartInfo *data_manage.ChartInfo, seriesList []*data_manage.ChartSeries, multiChartMapping *data_manage.MultipleGraphConfigChartMapping) (err error) {
- o := orm.NewOrmUsingDB("data")
- tx, e := o.Begin()
- if e != nil {
- err = fmt.Errorf("orm begin err: %s", e.Error())
- return
- }
- defer func() {
- if err != nil {
- _ = tx.Rollback()
- return
- }
- _ = tx.Commit()
- }()
- // 新增图表
- id, e := tx.Insert(chartInfo)
- if e != nil {
- err = fmt.Errorf("insert chart err: %v", e)
- return
- }
- newId := int(id)
- chartInfo.ChartInfoId = newId
- // 新增图例
- if len(seriesList) > 0 {
- for _, s := range seriesList {
- s.ChartInfoId = newId
- }
- _, e = tx.InsertMulti(utils.MultiAddNum, seriesList)
- if e != nil {
- err = fmt.Errorf("insert multi series err: %v", e)
- return
- }
- }
- // 图表关联
- if multiChartMapping != nil {
- multiChartMapping.ChartInfoId = newId
- _, e = tx.Insert(multiChartMapping)
- if e != nil {
- err = fmt.Errorf("insert multi chart mapping err: %v", e)
- return
- }
- }
- return
- }
|