package trade_analysis import ( "eta/eta_api/global" "eta/eta_api/models/data_manage" "eta/eta_api/utils" "fmt" ) // 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) { tx := global.DbMap[utils.DbNameIndex].Begin() defer func() { if err != nil { _ = tx.Rollback() } else { _ = tx.Commit() } }() // 新增图表 e := tx.Create(chartInfo).Error if e != nil { err = fmt.Errorf("insert chart err: %v", e) return } // 新增图例 if len(seriesList) > 0 { for _, s := range seriesList { s.ChartInfoId = chartInfo.ChartInfoId } e = tx.CreateInBatches(seriesList, utils.MultiAddNum).Error if e != nil { err = fmt.Errorf("insert multi series err: %v", e) return } } // 图表关联 if multiChartMapping != nil { multiChartMapping.ChartInfoId = chartInfo.ChartInfoId e = tx.Create(multiChartMapping).Error if e != nil { err = fmt.Errorf("insert multi chart mapping err: %v", e) return } } return }