edb_info.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package data_manage
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_task/utils"
  6. "rdluck_tools/orm"
  7. "strconv"
  8. "time"
  9. )
  10. type EdbInfoList struct {
  11. EdbInfoId int `orm:"column(edb_info_id);pk"`
  12. SourceName string `description:"来源名称"`
  13. Source int `description:"来源id"`
  14. EdbCode string `description:"指标编码"`
  15. EdbName string `description:"指标名称"`
  16. Frequency string `description:"频率"`
  17. Unit string `description:"单位"`
  18. StartDate time.Time `description:"起始日期"`
  19. EndDate time.Time `description:"终止日期"`
  20. ClassifyId int `description:"分类id"`
  21. UniqueCode string `description:"指标唯一编码"`
  22. }
  23. func GetEdbInfoByCondition(condition string, pars []interface{}) (item []*EdbInfoList, err error) {
  24. o := orm.NewOrm()
  25. o.Using("data")
  26. sql := ` SELECT * FROM edb_info WHERE 1=1 `
  27. if condition != "" {
  28. sql += condition
  29. }
  30. _,err = o.Raw(sql, pars).QueryRows(&item)
  31. return
  32. }
  33. func ModifyEdbDataInfoDate(edbInfoId int, maxDate string) (err error) {
  34. o := orm.NewOrm()
  35. o.Using("data")
  36. sql := ` UPDATE edb_info SET end_date=?,modify_time=NOW() WHERE edb_info_id=? `
  37. _, err = o.Raw(sql, maxDate, edbInfoId).Exec()
  38. return
  39. }
  40. type EdbInfoMaxAndMinInfo struct {
  41. MinDate string `description:"最小日期"`
  42. MaxDate string `description:"最大日期"`
  43. MinValue float64 `description:"最小值"`
  44. MaxValue float64 `description:"最大值"`
  45. }
  46. func GetEdbInfoMaxAndMinInfo(source int, edbCode string) (item *EdbInfoMaxAndMinInfo, err error) {
  47. o := orm.NewOrm()
  48. o.Using("data")
  49. sql := ``
  50. tableName := ``
  51. if source == utils.DATA_SOURCE_THS {
  52. tableName = `edb_data_ths`
  53. } else if source == utils.DATA_SOURCE_WIND {
  54. tableName = `edb_data_wind`
  55. } else if source == utils.DATA_SOURCE_PB {
  56. tableName = `edb_data_pb`
  57. } else {
  58. errors.New("无效的渠道:" + strconv.Itoa(source))
  59. return
  60. }
  61. 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=? `
  62. sql = fmt.Sprintf(sql, tableName)
  63. fmt.Println("sql:", sql)
  64. err = o.Raw(sql, edbCode).QueryRow(&item)
  65. return
  66. }
  67. func ModifyEdbInfoMaxAndMinInfo(edbInfoId int, item *EdbInfoMaxAndMinInfo) (err error) {
  68. o := orm.NewOrm()
  69. o.Using("data")
  70. sql := ` UPDATE edb_info SET start_date=?,end_date=?,min_value=?,max_value=?,modify_time=NOW() WHERE edb_info_id=? `
  71. _, err = o.Raw(sql, item.MinDate, item.MaxDate, item.MinValue, item.MaxValue, edbInfoId).Exec()
  72. return
  73. }