edb_source_stat.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package data_stat
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // EdbSourceStat 数据源统计表
  7. type EdbSourceStat struct {
  8. Id int `orm:"column(id);pk"`
  9. SourceName string `description:"来源名称"`
  10. Source int `description:"来源id"`
  11. TerminalCode string `description:"终端编码,用于配置在机器上"`
  12. EdbNum int `description:"指标总数"`
  13. EdbNewNum int `description:"今日新增指标数"`
  14. EdbDelNum int `description:"今日删除指标数"`
  15. NeedRefreshNum int `description:"今日需刷新指标"`
  16. HasRefreshNum int `description:"今日发起刷新任务指标数"`
  17. UpdateSuccessNum int `description:"今日已更新成功指标数"`
  18. UpdateFailedNum int `description:"今日已更新失败指标数"`
  19. RefreshSuccessNum int `description:"今日已刷新成功指标数"`
  20. RefreshFailedNum int `description:"今日已刷新失败指标数"`
  21. CreateTime time.Time `description:"创建时间"`
  22. ModifyTime time.Time `description:"修改时间"`
  23. }
  24. func GetEdbSourceStatByCondition(condition string, pars []interface{}) (item []*EdbSourceStat, err error) {
  25. o := orm.NewOrm()
  26. sql := ` SELECT * FROM edb_source_stat WHERE 1=1 `
  27. if condition != "" {
  28. sql += condition
  29. }
  30. _, err = o.Raw(sql, pars).QueryRows(&item)
  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. }