package models import ( "eta/eta_forum_task/utils" "time" "github.com/beego/beego/v2/client/orm" ) type EdbUpdateLog struct { Id uint64 `orm:"pk;column(id)"` OpDbName string OpTableName string OpType string OldData string NewData string IsHandle uint8 ModifyTime time.Time CreateTime time.Time } func (EdbUpdateLog) TableName() string { return "edb_update_log" } // 查询未处理的日志列表总数 func GetEdbUpdateLogListCount(dateTime string) (int, error) { o := orm.NewOrmUsingDB("data") sql := `SELECT COUNT(1) FROM edb_update_log WHERE is_handle = 0 and op_table_name != "edb_info" and create_time > ?` var count int64 err := o.Raw(sql, dateTime).QueryRow(&count) if err != nil { return 0, err } return int(count), nil } // 分页获取待处理的日志列表 func GetEdbUpdateLogList(dateTime string, offset int, pageSize int) ([]*EdbUpdateLog, error) { o := orm.NewOrmUsingDB("data") 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 ?, ?` var logs []*EdbUpdateLog _, err := o.Raw(sql, dateTime, offset, pageSize).QueryRows(&logs) if err != nil { return nil, err } return logs, nil } // 批量更新日志状态 func UpdateEdbUpdateLogStatus(logIds []int) error { o := orm.NewOrmUsingDB("data") sql := `UPDATE edb_update_log SET is_handle = 1, modify_time = ? WHERE id IN (`+utils.GetOrmInReplace(len(logIds))+`)` _, err := o.Raw(sql, time.Now(), logIds).Exec() if err != nil { return err } return nil }