edb_data_wind_wsd.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package data_manage
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. )
  6. func ModifyEdbInfoWindWsdDataStatus(source, subSource int, edbInfoId int64, edbCode string) (err error) {
  7. o := orm.NewOrmUsingDB("data")
  8. tableName := GetEdbDataTableNameAndSubSource(source, subSource)
  9. sql := ` UPDATE %s SET edb_info_id=?,modify_time=NOW() WHERE edb_code=? `
  10. sql = fmt.Sprintf(sql, tableName)
  11. _, err = o.Raw(sql, edbInfoId, edbCode).Exec()
  12. return
  13. }
  14. // GetEdbDataList 获取指标的数据(日期正序返回)
  15. func GetEdbDataWsdList(endInfoId int, startDate, endDate string) (list []*EdbDataList, err error) {
  16. tableName := `edb_data_wind_wsd`
  17. var pars []interface{}
  18. sql := `SELECT edb_data_id,edb_info_id,data_time,value,data_timestamp FROM %s WHERE edb_info_id=? `
  19. if startDate != "" {
  20. sql += ` AND data_time>=? `
  21. pars = append(pars, startDate)
  22. }
  23. if endDate != "" {
  24. sql += ` AND data_time<=? `
  25. pars = append(pars, endDate)
  26. }
  27. sql += ` ORDER BY data_time ASC `
  28. sql = fmt.Sprintf(sql, tableName)
  29. o := orm.NewOrmUsingDB("data")
  30. _, err = o.Raw(sql, endInfoId, pars).QueryRows(&list)
  31. return
  32. }
  33. func GetEdbWsdDataCountByCondition(condition string, pars []interface{}, source int) (count int, err error) {
  34. o := orm.NewOrmUsingDB("data")
  35. tableName := `edb_data_wind_wsd`
  36. sql := ` SELECT COUNT(1) AS count FROM %s WHERE 1=1 `
  37. sql = fmt.Sprintf(sql, tableName)
  38. if condition != "" {
  39. sql += condition
  40. }
  41. err = o.Raw(sql, pars).QueryRow(&count)
  42. return
  43. }
  44. func GetEdbWsdDataListByCondition(condition string, pars []interface{}, source, pageSize, startSize int) (item []*EdbData, err error) {
  45. o := orm.NewOrmUsingDB("data")
  46. tableName := `edb_data_wind_wsd`
  47. sql := ` SELECT * FROM %s WHERE 1=1 `
  48. sql = fmt.Sprintf(sql, tableName)
  49. if condition != "" {
  50. sql += condition
  51. }
  52. sql += ` ORDER BY data_time DESC `
  53. sql += ` LIMIT ?,? `
  54. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&item)
  55. return
  56. }