edb_info.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. }
  42. type EdbInfoSearchData struct {
  43. DataTime string `description:"数据日期"`
  44. Value float64 `description:"数据"`
  45. }
  46. func GetEdbInfoByCondition(condition string, pars []interface{}) (item []*EdbInfoList, err error) {
  47. o := orm.NewOrm()
  48. o.Using("data")
  49. sql := ` SELECT * FROM edb_info WHERE 1=1 `
  50. if condition != "" {
  51. sql += condition
  52. }
  53. sql += ` ORDER BY edb_info_id ASC `
  54. _, err = o.Raw(sql, pars).QueryRows(&item)
  55. return
  56. }
  57. func ModifyEdbDataInfoDate(edbInfoId int, maxDate string) (err error) {
  58. o := orm.NewOrm()
  59. o.Using("data")
  60. sql := ` UPDATE edb_info SET end_date=?,modify_time=NOW() WHERE edb_info_id=? `
  61. _, err = o.Raw(sql, maxDate, edbInfoId).Exec()
  62. return
  63. }
  64. type EdbInfoMaxAndMinInfo struct {
  65. MinDate string `description:"最小日期"`
  66. MaxDate string `description:"最大日期"`
  67. MinValue float64 `description:"最小值"`
  68. MaxValue float64 `description:"最大值"`
  69. }
  70. func GetEdbInfoMaxAndMinInfo(source int, edbCode string) (item *EdbInfoMaxAndMinInfo, err error) {
  71. o := orm.NewOrm()
  72. o.Using("data")
  73. sql := ``
  74. tableName := GetEdbDataTableName(source)
  75. 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=? `
  76. sql = fmt.Sprintf(sql, tableName)
  77. err = o.Raw(sql, edbCode).QueryRow(&item)
  78. return
  79. }
  80. func ModifyEdbInfoMaxAndMinInfo(edbInfoId int, item *EdbInfoMaxAndMinInfo) (err error) {
  81. o := orm.NewOrm()
  82. o.Using("data")
  83. sql := ` UPDATE edb_info SET start_date=?,end_date=?,min_value=?,max_value=?,modify_time=NOW() WHERE edb_info_id=? `
  84. _, err = o.Raw(sql, item.MinDate, item.MaxDate, item.MinValue, item.MaxValue, edbInfoId).Exec()
  85. return
  86. }
  87. //order:1升序,其余值为降序
  88. func GetEdbDataListAll(condition string, pars []interface{}, source, order int) (item []*EdbInfoSearchData, err error) {
  89. o := orm.NewOrm()
  90. o.Using("data")
  91. sql := ``
  92. tableName := GetEdbDataTableName(source)
  93. sql = ` SELECT * FROM %s WHERE 1=1 `
  94. sql = fmt.Sprintf(sql, tableName)
  95. if condition != "" {
  96. sql += condition
  97. }
  98. if order == 1 {
  99. sql += ` ORDER BY data_time ASC `
  100. } else {
  101. sql += ` ORDER BY data_time DESC `
  102. }
  103. _, err = o.Raw(sql, pars).QueryRows(&item)
  104. return
  105. }
  106. func GetEdbInfoById(edbInfoId int) (item *EdbInfo, err error) {
  107. o := orm.NewOrm()
  108. o.Using("data")
  109. sql := ` SELECT * FROM edb_info WHERE edb_info_id=? `
  110. err = o.Raw(sql, edbInfoId).QueryRow(&item)
  111. return
  112. }
  113. func GetQuarterEdbInfo() (item []*EdbInfo, err error) {
  114. o := orm.NewOrm()
  115. o.Using("data")
  116. sql := ` SELECT c.* FROM chart_info AS a
  117. INNER JOIN chart_edb_mapping AS b ON a.chart_info_id=b.chart_info_id
  118. INNER JOIN edb_info AS c ON b.edb_info_id=c.edb_info_id
  119. WHERE a.chart_type=2
  120. GROUP BY b.edb_info_id
  121. ORDER BY b.edb_info_id ASC `
  122. _, err = o.Raw(sql).QueryRows(&item)
  123. return
  124. }