edb_info.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package data_manage
  2. import (
  3. "eta/eta_chart_lib/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. type EdbInfo struct {
  8. EdbInfoId int `orm:"column(edb_info_id);pk"`
  9. EdbInfoType int `description:"指标类型,0:普通指标,1:预测指标"`
  10. SourceName string `description:"来源名称"`
  11. Source int `description:"来源id"`
  12. EdbCode string `description:"指标编码"`
  13. EdbName string `description:"指标名称"`
  14. EdbNameEn string `description:"英文指标名称"`
  15. EdbNameSource string `description:"指标名称来源"`
  16. Frequency string `description:"频率"`
  17. Unit string `description:"单位"`
  18. UnitEn string `description:"英文单位"`
  19. StartDate string `description:"起始日期"`
  20. EndDate string `description:"终止日期"`
  21. ClassifyId int `description:"分类id"`
  22. SysUserId int
  23. SysUserRealName string
  24. UniqueCode string `description:"指标唯一编码"`
  25. CreateTime time.Time
  26. ModifyTime time.Time
  27. MinValue float64 `description:"指标最小值"`
  28. MaxValue float64 `description:"指标最大值"`
  29. CalculateFormula string `description:"计算公式"`
  30. EdbType int `description:"指标类型:1:基础指标,2:计算指标"`
  31. Sort int `description:"排序字段"`
  32. LatestDate string `description:"数据最新日期"`
  33. LatestValue float64 `description:"数据最新值"`
  34. MoveType int `description:"移动方式:1:领先(默认),2:滞后"`
  35. MoveFrequency string `description:"移动频度"`
  36. NoUpdate int8 `description:"是否停止更新,0:继续更新;1:停止更新"`
  37. DataDateType string `orm:"column(data_date_type);size(255);null;default(交易日)"`
  38. SubSource int `description:"子数据来源:0:经济数据库,1:日期序列"`
  39. SubSourceName string `description:"子数据来源名称"`
  40. IndicatorCode string `description:"指标代码"`
  41. StockCode string `description:"证券代码"`
  42. }
  43. type EdbInfoMaxAndMinInfo struct {
  44. MinDate string `description:"最小日期"`
  45. MaxDate string `description:"最大日期"`
  46. MinValue float64 `description:"最小值"`
  47. MaxValue float64 `description:"最大值"`
  48. LatestValue float64 `description:"最新值"`
  49. }
  50. func GetEdbInfoById(edbInfoId int) (item *EdbInfo, err error) {
  51. o := orm.NewOrmUsingDB("data")
  52. sql := ` SELECT * FROM edb_info WHERE edb_info_id=? `
  53. err = o.Raw(sql, edbInfoId).QueryRow(&item)
  54. return
  55. }
  56. // GetEdbInfoByIdList 根据指标id集合 获取 指标列表
  57. func GetEdbInfoByIdList(edbInfoIdList []int) (items []*EdbInfo, err error) {
  58. num := len(edbInfoIdList)
  59. if num <= 0 {
  60. return
  61. }
  62. o := orm.NewOrmUsingDB("data")
  63. sql := ` SELECT * FROM edb_info WHERE edb_info_id in (` + utils.GetOrmInReplace(num) + `) `
  64. _, err = o.Raw(sql, edbInfoIdList).QueryRows(&items)
  65. return
  66. }
  67. func GetRefreshEdbInfoFromBase(edbInfoId, source int) (baseEdbInfoArr, calculateInfoArr []*EdbInfo, err error) {
  68. calculateList, err := GetEdbInfoCalculateMap(edbInfoId, source)
  69. if err != nil && err.Error() != utils.ErrNoRow() {
  70. return
  71. }
  72. for _, item := range calculateList {
  73. if item.EdbInfoId == edbInfoId { // 如果查出来关联的指标就是自己的话,那么就过滤
  74. continue
  75. }
  76. if item.EdbType == 1 {
  77. baseEdbInfoArr = append(baseEdbInfoArr, item)
  78. } else {
  79. calculateInfoArr = append(calculateInfoArr, item)
  80. newBaseEdbInfoArr, newCalculateInfoArr, _ := GetRefreshEdbInfoFromBase(item.EdbInfoId, item.Source)
  81. baseEdbInfoArr = append(baseEdbInfoArr, newBaseEdbInfoArr...)
  82. calculateInfoArr = append(calculateInfoArr, newCalculateInfoArr...)
  83. }
  84. }
  85. return
  86. }
  87. type EdbInfoSearchData struct {
  88. DataTime string `description:"数据日期"`
  89. Value float64 `description:"数据"`
  90. }
  91. // TraceEdbInfoResp 指标追溯数据返回
  92. type TraceEdbInfoResp struct {
  93. EdbInfoId int `description:"指标id"`
  94. EdbInfoType int `description:"指标类型: 0-普通指标; 1-预测指标"`
  95. EdbName string `description:"指标名称"`
  96. EdbType int `description:"指标类型: 1-基础指标; 2-计算指标"`
  97. RuleTitle string `description:"指标规则"`
  98. UniqueCode string `description:"唯一编码"`
  99. ClassifyId int `description:"分类ID"`
  100. Child []TraceEdbInfoResp `description:"下级来源"`
  101. EdbInfo *EdbInfo `description:"指标信息" json:"-"`
  102. }