edb_data_calculate.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package data_manage
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. func GetEdbDataCalculateByCodeAndDate(edbCode string, startDate string) (count int, err error) {
  8. o := orm.NewOrmUsingDB("data")
  9. sql := ` SELECT COUNT(1) AS count FROM edb_data_calculate WHERE edb_code=? AND data_time=? `
  10. err = o.Raw(sql, edbCode, startDate).QueryRow(&count)
  11. return
  12. }
  13. func ModifyEdbDataCalculate(edbInfoId int64, dataTime string, value float64) (err error) {
  14. o := orm.NewOrmUsingDB("data")
  15. sql := ` UPDATE edb_data_calculate SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
  16. _, err = o.Raw(sql, value, edbInfoId, dataTime).Exec()
  17. return
  18. }
  19. func AddEdbDataCalculateBySql(sqlStr string) (err error) {
  20. o := orm.NewOrmUsingDB("data")
  21. _, err = o.Raw(sqlStr).Exec()
  22. return
  23. }
  24. // DeleteEdbDataCalculateBySql 根据删除sql删除指标数据
  25. func DeleteEdbDataCalculateBySql(deleteStr string, edbInfoId int) (err error) {
  26. o := orm.NewOrmUsingDB("data")
  27. _, err = o.Raw(deleteStr, edbInfoId).Exec()
  28. return
  29. }
  30. type EdbInfoCalculateDetail struct {
  31. EdbInfoCalculateId int `orm:"column(edb_info_calculate_id);pk"`
  32. EdbInfoId int `description:"指标id"`
  33. EdbCode string `description:"指标编码"`
  34. FromEdbInfoId int `description:"计算指标id"`
  35. FromEdbCode string `description:"计算指标编码"`
  36. FromEdbName string `description:"计算指标名称"`
  37. FromSource int `description:"计算指标来源"`
  38. FromSourceName string `description:"计算指标来源名称"`
  39. FromTag string `description:"来源指标标签"`
  40. Sort int `description:"计算指标名称排序"`
  41. CreateTime time.Time `description:"创建时间"`
  42. ModifyTime time.Time `description:"修改时间"`
  43. StartDate string `description:"开始日期"`
  44. EndDate string `description:"结束日期"`
  45. }
  46. func GetEdbInfoCalculateDetail(edbInfoId int) (list []*EdbInfoCalculateDetail, err error) {
  47. o := orm.NewOrmUsingDB("data")
  48. sql := ` SELECT a.*,b.start_date,b.end_date FROM edb_info_calculate_mapping AS a
  49. INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
  50. WHERE a.edb_info_id=? ORDER BY sort ASC `
  51. _, err = o.Raw(sql, edbInfoId).QueryRows(&list)
  52. return
  53. }
  54. func GetEdbInfoCalculateMap(edbInfoId, source int) (list []*EdbInfoCalculateDetail, err error) {
  55. o := orm.NewOrmUsingDB("data")
  56. calculateTableName := GetEdbInfoCalculateTableName(source)
  57. sql := ` SELECT a.*,b.start_date,b.end_date,b.edb_type FROM %s AS a
  58. INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
  59. WHERE a.edb_info_id=? ORDER BY sort ASC `
  60. sql = fmt.Sprintf(sql, calculateTableName)
  61. _, err = o.Raw(sql, edbInfoId).QueryRows(&list)
  62. return
  63. }