edb_info.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. package data_manage
  2. import (
  3. "eta/eta_hub/utils"
  4. "fmt"
  5. "github.com/beego/beego/v2/client/orm"
  6. "strings"
  7. "time"
  8. )
  9. type EdbInfo struct {
  10. EdbInfoId int `orm:"column(edb_info_id);pk"`
  11. EdbInfoType int `description:"指标类型,0:普通指标,1:预测指标"`
  12. SourceName string `description:"来源名称"`
  13. Source int `description:"来源ID"`
  14. EdbCode string `description:"指标编码"`
  15. EdbName string `description:"指标名称"`
  16. EdbNameEn string `description:"英文指标名称"`
  17. EdbNameSource string `description:"指标名称来源"`
  18. Frequency string `description:"频率"`
  19. Unit string `description:"单位"`
  20. UnitEn string `description:"英文单位"`
  21. StartDate string `description:"起始日期"`
  22. EndDate string `description:"终止日期"`
  23. ClassifyId int `description:"分类ID"`
  24. SysUserId int `description:"创建人ID"`
  25. SysUserRealName string `description:"创建人姓名"`
  26. UniqueCode string `description:"指标唯一编码"`
  27. CreateTime time.Time `description:"创建时间"`
  28. ModifyTime time.Time `description:"更新时间"`
  29. MinValue float64 `description:"指标最小值"`
  30. MaxValue float64 `description:"指标最大值"`
  31. CalculateFormula string `description:"计算公式"`
  32. EdbType int `description:"指标类型:1:基础指标,2:计算指标"`
  33. Sort int `description:"排序字段"`
  34. LatestDate string `description:"数据最新日期"`
  35. LatestValue float64 `description:"数据最新值"`
  36. MoveType int `description:"移动方式:1:领先(默认),2:滞后"`
  37. MoveFrequency string `description:"移动频度"`
  38. NoUpdate int8 `description:"是否停止更新,0:继续更新;1:停止更新"`
  39. ServerUrl string `description:"服务器地址"`
  40. ChartImage string `description:"图表图片"`
  41. Calendar string `description:"公历/农历" orm:"default(公历);"`
  42. DataDateType string `orm:"column(data_date_type);size(255);null;default(交易日)"`
  43. ManualSave int `description:"是否有手动保存过上下限: 0-否; 1-是"`
  44. }
  45. func (m *EdbInfo) GetItemsByCondition(cond string, pars []interface{}, fieldArr []string, orderRule string) (items []*EdbInfo, err error) {
  46. o := orm.NewOrmUsingDB("data")
  47. fields := strings.Join(fieldArr, ",")
  48. if len(fieldArr) == 0 {
  49. fields = `*`
  50. }
  51. order := `ORDER BY create_time DESC`
  52. if orderRule != "" {
  53. order = ` ORDER BY ` + orderRule
  54. }
  55. sql := fmt.Sprintf(`SELECT %s FROM edb_info WHERE 1=1 %s %s`, fields, cond, order)
  56. _, err = o.Raw(sql, pars).QueryRows(&items)
  57. return
  58. }
  59. func (m *EdbInfo) GetItemByUniCode(code string) (item *EdbInfo, err error) {
  60. o := orm.NewOrmUsingDB("data")
  61. sql := fmt.Sprintf(`SELECT * FROM edb_info WHERE unique_code = ? LIMIT 1`)
  62. err = o.Raw(sql, code).QueryRow(&item)
  63. return
  64. }
  65. func (m *EdbInfo) GetItemByEdbCode(code string) (item *EdbInfo, err error) {
  66. o := orm.NewOrmUsingDB("data")
  67. sql := fmt.Sprintf(`SELECT * FROM edb_info WHERE edb_code = ? LIMIT 1`)
  68. err = o.Raw(sql, code).QueryRow(&item)
  69. return
  70. }
  71. // EdbInfoItem 指标信息
  72. type EdbInfoItem struct {
  73. EdbInfoId int `description:"指标信息ID"`
  74. UniqueCode string `description:"指标唯一编码"`
  75. EdbCode string `description:"指标编码"`
  76. EdbInfoType int `description:"指标类型: 0-普通指标; 1-预测指标"`
  77. EdbType int `description:"指标类型: 1-基础指标; 2-计算指标"`
  78. EdbName string `description:"指标名称"`
  79. ClassifyId int `description:"分类ID"`
  80. Source int `description:"来源ID"`
  81. SourceName string `description:"来源名称"`
  82. Frequency string `description:"频率"`
  83. Unit string `description:"单位"`
  84. StartDate string `description:"起始日期"`
  85. EndDate string `description:"终止日期"`
  86. MinValue float64 `description:"指标最小值"`
  87. MaxValue float64 `description:"指标最大值"`
  88. LatestDate string `description:"数据最新日期"`
  89. LatestValue float64 `description:"数据最新值"`
  90. ChartImage string `description:"图表图片"`
  91. Calendar string `description:"公历/农历"`
  92. DataDateType string `description:"数据日期类型: 交易日/自然日"`
  93. Sort int `description:"排序"`
  94. NoUpdate int `description:"是否停更: 0-继续更新; 1-停止更新"`
  95. CreateTime string `description:"创建时间"`
  96. ModifyTime string `description:"更新时间"`
  97. EdbData []*EdbDataItem `description:"指标数据"`
  98. }
  99. func FormatEdbInfo2Item(origin *EdbInfo, edbData []*EdbDataItem) (item *EdbInfoItem) {
  100. if origin == nil {
  101. return
  102. }
  103. item = new(EdbInfoItem)
  104. item.EdbInfoId = origin.EdbInfoId
  105. item.EdbInfoType = origin.EdbInfoType
  106. item.SourceName = origin.SourceName
  107. item.Source = origin.Source
  108. item.EdbCode = origin.EdbCode
  109. item.EdbName = origin.EdbName
  110. item.Frequency = origin.Frequency
  111. item.Unit = origin.Unit
  112. item.StartDate = origin.StartDate
  113. item.EndDate = origin.EndDate
  114. item.ClassifyId = origin.ClassifyId
  115. item.UniqueCode = origin.UniqueCode
  116. item.MinValue = origin.MinValue
  117. item.MaxValue = origin.MaxValue
  118. item.EdbType = origin.EdbType
  119. item.Sort = origin.Sort
  120. item.LatestDate = origin.LatestDate
  121. item.LatestValue = origin.LatestValue
  122. item.NoUpdate = int(origin.NoUpdate)
  123. item.ChartImage = origin.ChartImage
  124. item.Calendar = origin.Calendar
  125. item.DataDateType = origin.DataDateType
  126. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  127. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  128. item.EdbData = edbData
  129. return
  130. }