edb_info.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. package data_manage
  2. import (
  3. "fmt"
  4. "rdluck_tools/orm"
  5. "time"
  6. )
  7. type EdbInfo struct {
  8. EdbInfoId int `orm:"column(edb_info_id);pk"`
  9. SourceName string `description:"来源名称"`
  10. Source int `description:"来源id"`
  11. EdbCode string `description:"指标编码"`
  12. EdbName string `description:"指标名称"`
  13. EdbNameSource string `description:"指标名称来源"`
  14. Frequency string `description:"频率"`
  15. Unit string `description:"单位"`
  16. StartDate string `description:"起始日期"`
  17. EndDate string `description:"终止日期"`
  18. ClassifyId int `description:"分类id"`
  19. SysUserId int
  20. SysUserRealName string
  21. UniqueCode string `description:"指标唯一编码"`
  22. CreateTime time.Time
  23. ModifyTime time.Time
  24. MinValue float64 `description:"指标最小值"`
  25. MaxValue float64 `description:"指标最大值"`
  26. CalculateFormula string `description:"计算公式"`
  27. }
  28. type EdbInfoList struct {
  29. EdbInfoId int `orm:"column(edb_info_id);pk"`
  30. SourceName string `description:"来源名称"`
  31. Source int `description:"来源id"`
  32. EdbCode string `description:"指标编码"`
  33. EdbName string `description:"指标名称"`
  34. Frequency string `description:"频率"`
  35. Unit string `description:"单位"`
  36. StartDate time.Time `description:"起始日期"`
  37. EndDate time.Time `description:"终止日期"`
  38. ClassifyId int `description:"分类id"`
  39. UniqueCode string `description:"指标唯一编码"`
  40. CalculateFormula string `description:"计算公式"`
  41. ModifyTime string `description:"更新时间"`
  42. }
  43. type EdbInfoSearchData struct {
  44. DataTime string `description:"数据日期"`
  45. Value float64 `description:"数据"`
  46. }
  47. func GetEdbInfoByCondition(condition string, pars []interface{}, order int) (item []*EdbInfoList, err error) {
  48. o := orm.NewOrm()
  49. o.Using("data")
  50. sql := ` SELECT * FROM edb_info WHERE 1=1 `
  51. if condition != "" {
  52. sql += condition
  53. }
  54. if order == 1 {
  55. sql += ` ORDER BY end_date ASC `
  56. } else {
  57. sql += ` ORDER BY edb_info_id ASC `
  58. }
  59. _, err = o.Raw(sql, pars).QueryRows(&item)
  60. return
  61. }
  62. func ModifyEdbDataInfoDate(edbInfoId int, maxDate string) (err error) {
  63. o := orm.NewOrm()
  64. o.Using("data")
  65. sql := ` UPDATE edb_info SET end_date=?,modify_time=NOW() WHERE edb_info_id=? `
  66. _, err = o.Raw(sql, maxDate, edbInfoId).Exec()
  67. return
  68. }
  69. type EdbInfoMaxAndMinInfo struct {
  70. MinDate string `description:"最小日期"`
  71. MaxDate string `description:"最大日期"`
  72. MinValue float64 `description:"最小值"`
  73. MaxValue float64 `description:"最大值"`
  74. }
  75. func GetEdbInfoMaxAndMinInfo(source int, edbCode string) (item *EdbInfoMaxAndMinInfo, err error) {
  76. o := orm.NewOrm()
  77. o.Using("data")
  78. sql := ``
  79. tableName := GetEdbDataTableName(source)
  80. sql = ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date,MIN(value) AS min_value,MAX(value) AS max_value FROM %s WHERE edb_code=? `
  81. sql = fmt.Sprintf(sql, tableName)
  82. err = o.Raw(sql, edbCode).QueryRow(&item)
  83. return
  84. }
  85. func ModifyEdbInfoMaxAndMinInfo(edbInfoId int, item *EdbInfoMaxAndMinInfo) (err error) {
  86. o := orm.NewOrm()
  87. o.Using("data")
  88. sql := ` UPDATE edb_info SET start_date=?,end_date=?,min_value=?,max_value=?,modify_time=NOW() WHERE edb_info_id=? `
  89. _, err = o.Raw(sql, item.MinDate, item.MaxDate, item.MinValue, item.MaxValue, edbInfoId).Exec()
  90. return
  91. }
  92. //order:1升序,其余值为降序
  93. func GetEdbDataListAll(condition string, pars []interface{}, source, order int) (item []*EdbInfoSearchData, err error) {
  94. o := orm.NewOrm()
  95. o.Using("data")
  96. sql := ``
  97. tableName := GetEdbDataTableName(source)
  98. sql = ` SELECT * FROM %s WHERE 1=1 `
  99. sql = fmt.Sprintf(sql, tableName)
  100. if condition != "" {
  101. sql += condition
  102. }
  103. if order == 1 {
  104. sql += ` ORDER BY data_time ASC `
  105. } else {
  106. sql += ` ORDER BY data_time DESC `
  107. }
  108. _, err = o.Raw(sql, pars).QueryRows(&item)
  109. return
  110. }
  111. func GetEdbInfoById(edbInfoId int) (item *EdbInfo, err error) {
  112. o := orm.NewOrm()
  113. o.Using("data")
  114. sql := ` SELECT * FROM edb_info WHERE edb_info_id=? `
  115. err = o.Raw(sql, edbInfoId).QueryRow(&item)
  116. return
  117. }
  118. func GetQuarterEdbInfo() (item []*EdbInfo, err error) {
  119. o := orm.NewOrm()
  120. o.Using("data")
  121. sql := ` SELECT c.* FROM chart_info AS a
  122. INNER JOIN chart_edb_mapping AS b ON a.chart_info_id=b.chart_info_id
  123. INNER JOIN edb_info AS c ON b.edb_info_id=c.edb_info_id
  124. WHERE a.chart_type=2
  125. GROUP BY b.edb_info_id
  126. ORDER BY b.edb_info_id ASC `
  127. _, err = o.Raw(sql).QueryRows(&item)
  128. return
  129. }