edb_data_calculate.go 3.1 KB

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