edb_source_stat.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package data_stat
  2. import (
  3. "eta_gn/eta_index_lib/global"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. // EdbSourceStat 数据源统计表
  8. type EdbSourceStat struct {
  9. Id int `gorm:"primaryKey;autoIncrement;column:id" description:"ID"`
  10. SourceName string `gorm:"column:source_name" description:"来源名称"`
  11. Source int `gorm:"column:source" description:"来源id"`
  12. TerminalCode string `gorm:"column:terminal_code" description:"终端编码,用于配置在机器上"`
  13. EdbNum int `gorm:"column:edb_num" description:"指标总数"`
  14. EdbNewNum int `gorm:"column:edb_new_num" description:"今日新增指标数"`
  15. EdbDelNum int `gorm:"column:edb_del_num" description:"今日删除指标数"`
  16. NeedRefreshNum int `gorm:"column:need_refresh_num" description:"今日需刷新指标"`
  17. HasRefreshNum int `gorm:"column:has_refresh_num" description:"今日发起刷新任务指标数"`
  18. UpdateSuccessNum int `gorm:"column:update_success_num" description:"今日已更新成功指标数"`
  19. UpdateFailedNum int `gorm:"column:update_failed_num" description:"今日已更新失败指标数"`
  20. RefreshSuccessNum int `gorm:"column:refresh_success_num" description:"今日已刷新成功指标数"`
  21. RefreshFailedNum int `gorm:"column:refresh_failed_num" description:"今日已刷新失败指标数"`
  22. CreateTime time.Time `gorm:"column:create_time" description:"创建时间"`
  23. ModifyTime time.Time `gorm:"column:modify_time" description:"修改时间"`
  24. }
  25. func GetEdbSourceStatByCondition(condition string, pars []interface{}) (item []*EdbSourceStat, err error) {
  26. sql := ` SELECT * FROM edb_source_stat WHERE 1=1 `
  27. if condition != "" {
  28. sql += condition
  29. }
  30. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&item).Error
  31. return
  32. }
  33. // Add 新增
  34. func (r *EdbSourceStat) Add(list []*EdbSourceStat) (err error) {
  35. o := orm.NewOrm()
  36. _, err = o.InsertMulti(len(list), list)
  37. return
  38. }
  39. // UpdateEdbSourceStatMulti 批量更新
  40. func UpdateEdbSourceStatMulti(list []*EdbSourceStat) (err error) {
  41. o := orm.NewOrm()
  42. sql := `UPDATE edb_source_stat
  43. SET
  44. edb_num=?,
  45. edb_new_num=?,
  46. edb_del_num=?,
  47. need_refresh_num=?,
  48. has_refresh_num=?,
  49. update_success_num=?,
  50. update_failed_num=?,
  51. refresh_success_num=?,
  52. refresh_failed_num=?,
  53. modify_time=?
  54. WHERE
  55. id = ?`
  56. p, err := o.Raw(sql).Prepare()
  57. if err != nil {
  58. return
  59. }
  60. defer func() {
  61. _ = p.Close() // 别忘记关闭 statement
  62. }()
  63. for _, v := range list {
  64. _, err = p.Exec(v.EdbNum, v.EdbNewNum, v.EdbDelNum, v.NeedRefreshNum, v.HasRefreshNum, v.UpdateSuccessNum, v.UpdateFailedNum, v.RefreshSuccessNum, v.RefreshFailedNum, v.ModifyTime, v.Id)
  65. if err != nil {
  66. return
  67. }
  68. }
  69. return
  70. }