edb_data_calculate.go 3.1 KB

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