warehouse.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package trade_analysis
  2. import (
  3. "eta/eta_api/models/data_manage"
  4. "eta/eta_api/utils"
  5. "fmt"
  6. "github.com/beego/beego/v2/client/orm"
  7. )
  8. // WarehouseExtraConfig 建仓图表配置
  9. type WarehouseExtraConfig struct {
  10. MultipleGraphConfigId int `description:"多图配置ID"`
  11. WarehouseChartType int `description:"图表类型: 1-多单图; 2-空单图; 3-净多单图"`
  12. Exchange string `description:"交易所标识"`
  13. ClassifyName string `description:"品种名称"`
  14. Contracts []string `description:"合约代码"`
  15. Companies []string `description:"期货公司, 不超过5个"`
  16. PredictRatio float64 `description:"预估参数, 0-1之间"`
  17. }
  18. // WarehouseChartPars 建仓单表配置
  19. type WarehouseChartPars struct {
  20. WarehouseChartType int `description:"图表类型: 1-多单图; 2-空单图; 3-净多单图"`
  21. DateType int `description:"日期类型"`
  22. DateTypeNum int `description:"日期类型=25(N月)时的N值"`
  23. StartDate string `description:"自定义开始日期"`
  24. EndDate string `description:"自定义结束日期"`
  25. //ChartThemeId int `description:"图表主题ID"`
  26. ChartEdbInfoList []*data_manage.ChartSaveItem `description:"指标及配置信息"`
  27. //SourcesFrom *data_manage.ChartInfoSourcesFrom `description:"图表来源"`
  28. }
  29. // WarehouseChartDataResp 图表详情返回信息
  30. type WarehouseChartDataResp struct {
  31. WarehouseExtraConfig
  32. MultiEdbMappings []*WarehouseEdbSaveItem
  33. }
  34. // WarehouseEdbSaveItem 建仓指标保存
  35. type WarehouseEdbSaveItem struct {
  36. EdbInfoId int `description:"指标ID"`
  37. EdbName string `description:"指标名称"`
  38. Unit string `description:"单位"`
  39. Frequency string `description:"频度"`
  40. ClassifyId int `description:"指标库分类ID"`
  41. UniqueFlag string `description:"唯一标识"`
  42. //ExtraConfig string `description:"配置信息-JSON"`
  43. }
  44. type WarehouseEdbSaveRespItem struct {
  45. WarehouseEdbSaveItem
  46. Tips string `description:"提示信息"`
  47. ErrMsg string `description:"错误信息"`
  48. }
  49. // CreateWarehouseChart 新增建仓图表
  50. func CreateWarehouseChart(chartInfo *data_manage.ChartInfo, seriesList []*data_manage.ChartSeries, multiChartMapping *data_manage.MultipleGraphConfigChartMapping) (err error) {
  51. o := orm.NewOrmUsingDB("data")
  52. tx, e := o.Begin()
  53. if e != nil {
  54. err = fmt.Errorf("orm begin err: %s", e.Error())
  55. return
  56. }
  57. defer func() {
  58. if err != nil {
  59. _ = tx.Rollback()
  60. return
  61. }
  62. _ = tx.Commit()
  63. }()
  64. // 新增图表
  65. id, e := tx.Insert(chartInfo)
  66. if e != nil {
  67. err = fmt.Errorf("insert chart err: %v", e)
  68. return
  69. }
  70. newId := int(id)
  71. chartInfo.ChartInfoId = newId
  72. // 新增图例
  73. if len(seriesList) > 0 {
  74. for _, s := range seriesList {
  75. s.ChartInfoId = newId
  76. }
  77. _, e = tx.InsertMulti(utils.MultiAddNum, seriesList)
  78. if e != nil {
  79. err = fmt.Errorf("insert multi series err: %v", e)
  80. return
  81. }
  82. }
  83. // 图表关联
  84. if multiChartMapping != nil {
  85. multiChartMapping.ChartInfoId = newId
  86. _, e = tx.Insert(multiChartMapping)
  87. if e != nil {
  88. err = fmt.Errorf("insert multi chart mapping err: %v", e)
  89. return
  90. }
  91. }
  92. return
  93. }