edb_info.go 4.7 KB

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