edb_update_log.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package models
  2. import (
  3. "eta/eta_forum_task/utils"
  4. "time"
  5. "github.com/beego/beego/v2/client/orm"
  6. )
  7. type EdbUpdateLog struct {
  8. Id uint64 `orm:"pk;column(id)"`
  9. OpDbName string
  10. OpTableName string
  11. OpType string
  12. OldData string
  13. NewData string
  14. IsHandle uint8
  15. ModifyTime time.Time
  16. CreateTime time.Time
  17. }
  18. func (EdbUpdateLog) TableName() string {
  19. return "edb_update_log"
  20. }
  21. // 查询未处理的日志列表总数
  22. func GetEdbUpdateLogListCount(dateTime string) (int, error) {
  23. o := orm.NewOrmUsingDB("data")
  24. sql := `SELECT COUNT(1) FROM edb_update_log WHERE is_handle = 0 and op_table_name != "edb_info" and create_time > ?`
  25. var count int64
  26. err := o.Raw(sql, dateTime).QueryRow(&count)
  27. if err != nil {
  28. return 0, err
  29. }
  30. return int(count), nil
  31. }
  32. // 分页获取待处理的日志列表
  33. func GetEdbUpdateLogList(dateTime string, offset int, pageSize int) ([]*EdbUpdateLog, error) {
  34. o := orm.NewOrmUsingDB("data")
  35. sql := `SELECT * FROM edb_update_log WHERE is_handle = 0 and op_table_name != "edb_info" and op_table_name != "edb_data_insert_config" and create_time > ? ORDER BY id ASC LIMIT ?, ?`
  36. var logs []*EdbUpdateLog
  37. _, err := o.Raw(sql, dateTime, offset, pageSize).QueryRows(&logs)
  38. if err != nil {
  39. return nil, err
  40. }
  41. return logs, nil
  42. }
  43. // 批量更新日志状态
  44. func UpdateEdbUpdateLogStatus(logIds []int) error {
  45. o := orm.NewOrmUsingDB("data")
  46. sql := `UPDATE edb_update_log SET is_handle = 1, modify_time = ? WHERE id IN (`+utils.GetOrmInReplace(len(logIds))+`)`
  47. _, err := o.Raw(sql, time.Now(), logIds).Exec()
  48. if err != nil {
  49. return err
  50. }
  51. return nil
  52. }