edb_info.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. package data_manage
  2. import (
  3. "eta_gn/eta_chart_lib/global"
  4. "eta_gn/eta_chart_lib/utils"
  5. "gorm.io/gorm"
  6. "time"
  7. )
  8. type EdbInfo struct {
  9. EdbInfoId int `gorm:"column:edb_info_id;primaryKey" description:"指标ID" orm:"column(edb_info_id);pk"`
  10. EdbInfoType int `gorm:"column:edb_info_type" description:"指标类型,0:普通指标,1:预测指标"`
  11. SourceName string `gorm:"column:source_name" description:"来源名称"`
  12. Source int `gorm:"column:source" description:"来源id"`
  13. EdbCode string `gorm:"column:edb_code" description:"指标编码"`
  14. EdbName string `gorm:"column:edb_name" description:"指标名称"`
  15. EdbNameEn string `gorm:"column:edb_name_en" description:"英文指标名称"`
  16. EdbNameSource string `gorm:"column:edb_name_source" description:"指标名称来源"`
  17. Frequency string `gorm:"column:frequency" description:"频率"`
  18. Unit string `gorm:"column:unit" description:"单位"`
  19. UnitEn string `gorm:"column:unit_en" description:"英文单位"`
  20. StartDate string `gorm:"column:start_date" description:"起始日期"`
  21. EndDate string `gorm:"column:end_date" description:"终止日期"`
  22. ClassifyId int `gorm:"column:classify_id" description:"分类id"`
  23. SysUserId int `gorm:"column:sys_user_id"`
  24. SysUserRealName string `gorm:"column:sys_user_real_name"`
  25. UniqueCode string `gorm:"column:unique_code" description:"指标唯一编码"`
  26. CreateTime time.Time `gorm:"column:create_time"`
  27. ModifyTime time.Time `gorm:"column:modify_time"`
  28. MinValue float64 `gorm:"column:min_value" description:"指标最小值"`
  29. MaxValue float64 `gorm:"column:max_value" description:"指标最大值"`
  30. CalculateFormula string `gorm:"column:calculate_formula" description:"计算公式"`
  31. EdbType int `gorm:"column:edb_type" description:"指标类型:1:基础指标,2:计算指标"`
  32. Sort int `gorm:"column:sort" description:"排序字段"`
  33. LatestDate string `gorm:"column:latest_date" description:"数据最新日期"`
  34. LatestValue float64 `gorm:"column:latest_value" description:"数据最新值"`
  35. MoveType int `gorm:"column:move_type" description:"移动方式:1:领先(默认),2:滞后"`
  36. MoveFrequency string `gorm:"column:move_frequency" description:"移动频度"`
  37. NoUpdate int8 `gorm:"column:no_update" description:"是否停止更新,0:继续更新;1:停止更新"`
  38. DataDateType string `gorm:"column:data_date_type;size(255);null;default:交易日" description:"数据日期类型"`
  39. SubSource int `gorm:"column:sub_source" description:"子数据来源:0:经济数据库,1:日期序列"`
  40. SubSourceName string `gorm:"column:sub_source_name" description:"子数据来源名称"`
  41. IndicatorCode string `gorm:"column:indicator_code" description:"指标代码"`
  42. StockCode string `gorm:"column:stock_code" 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 := global.DmSQL["data"]
  53. sql := ` SELECT * FROM edb_info WHERE edb_info_id=? `
  54. err = o.Raw(sql, edbInfoId).First(&item).Error
  55. return
  56. }
  57. func GetEdbInfoByIdList(edbInfoIdList []int) (items []*EdbInfo, err error) {
  58. num := len(edbInfoIdList)
  59. if num <= 0 {
  60. return
  61. }
  62. o := global.DmSQL["data"]
  63. sql := ` SELECT * FROM edb_info WHERE edb_info_id in (` + utils.GetGormInReplace(num) + `) `
  64. err = o.Raw(sql, edbInfoIdList).Find(&items).Error
  65. return
  66. }
  67. func GetRefreshEdbInfoFromBase(edbInfoId, source int) (baseEdbInfoArr, calculateInfoArr []*EdbInfo, err error) {
  68. calculateList, err := GetEdbInfoCalculateMap(edbInfoId, source)
  69. if err != nil && !utils.IsErrNoRow(err) {
  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. type TraceEdbInfoResp struct {
  92. EdbInfoId int `description:"指标id"`
  93. EdbInfoType int `description:"指标类型: 0-普通指标; 1-预测指标"`
  94. EdbName string `description:"指标名称"`
  95. EdbType int `description:"指标类型: 1-基础指标; 2-计算指标"`
  96. RuleTitle string `description:"指标规则"`
  97. UniqueCode string `description:"唯一编码"`
  98. ClassifyId int `description:"分类ID"`
  99. Child []TraceEdbInfoResp `description:"下级来源"`
  100. EdbInfo *EdbInfo `description:"指标信息" json:"-"`
  101. }
  102. func (e *EdbInfo) AfterFind(db *gorm.DB) (err error) {
  103. tmpLatestDate, err := time.Parse(utils.FormatDateWallWithLoc, e.LatestDate)
  104. if err != nil {
  105. return nil
  106. }
  107. tmpStartDate, err := time.Parse(utils.FormatDateWallWithLoc, e.StartDate)
  108. if err != nil {
  109. return nil
  110. }
  111. tmpEndDate, err := time.Parse(utils.FormatDateWallWithLoc, e.EndDate)
  112. if err != nil {
  113. return nil
  114. }
  115. e.LatestDate = utils.TimeTransferString(utils.FormatDate, tmpLatestDate)
  116. e.StartDate = utils.TimeTransferString(utils.FormatDate, tmpStartDate)
  117. e.EndDate = utils.TimeTransferString(utils.FormatDate, tmpEndDate)
  118. return nil
  119. }