failture record recover

This commit is contained in:
mubai
2025-03-22 23:05:02 +08:00
parent fab3fb73e7
commit c1e28380d0
18 changed files with 496 additions and 120 deletions

View File

@@ -1,6 +1,7 @@
package system
import (
"fmt"
"gorm.io/gorm"
"log"
"server/config"
@@ -50,15 +51,18 @@ func FailureRecordList(vo RecordRequestVo) []FailureRecord {
if vo.OriginId != "" {
qw.Where("origin_id = ?", vo.OriginId)
}
if !vo.BeginTime.IsZero() && !vo.EndTime.IsZero() {
qw.Where("created_at BETWEEN ? AND ? ", vo.BeginTime, vo.EndTime)
}
//if vo.CollectType >= 0 {
// qw.Where("collect_type = ?", vo.CollectType)
//}
//if vo.Hour != 0 {
// qw.Where("hour = ?", vo.Hour)
//}
//if vo.Status >= 0 {
// qw.Where("status = ?", vo.Status)
//}
if vo.Status >= 0 {
qw.Where("status = ?", vo.Status)
}
// 获取分页数据
GetPage(qw, vo.Paging)
@@ -114,3 +118,19 @@ func RetryRecord(id uint, status int64) error {
return db.Mdb.Model(&FailureRecord{}).Where("update_at > ?", fr.UpdatedAt).Update("status", 0).Error
}
// DelDoneRecord 删除已处理的记录信息 -- 逻辑删除
func DelDoneRecord() {
if err := db.Mdb.Where("status = ?", 0).Delete(&FailureRecord{}).Error; err != nil {
log.Println("Delete failure record failed:", err)
}
}
// TruncateRecordTable 截断 record table
func TruncateRecordTable() {
var s FailureRecord
err := db.Mdb.Exec(fmt.Sprintf("TRUNCATE Table %s", s.TableName())).Error
if err != nil {
log.Println("TRUNCATE TABLE Error: ", err)
}
}

View File

@@ -73,19 +73,19 @@ func FilmZero() {
db.Rdb.Del(db.Cxt, db.Rdb.Keys(db.Cxt, "OriginalResource*").Val()...)
db.Rdb.Del(db.Cxt, db.Rdb.Keys(db.Cxt, "Search*").Val()...)
// 删除mysql中留存的检索表
var s *SearchInfo
var s SearchInfo
//db.Mdb.Exec(fmt.Sprintf(`drop table if exists %s`, s.TableName()))
// 截断数据表 truncate table users
if ExistSearchTable() {
db.Mdb.Exec(fmt.Sprintf(`TRUNCATE table %s`, s.TableName()))
db.Mdb.Exec(fmt.Sprintf("TRUNCATE table %s", s.TableName()))
}
}
// ResetSearchTable 重置Search表
func ResetSearchTable() {
// 删除 Search 表
var s *SearchInfo
db.Mdb.Exec(fmt.Sprintf(`drop table if exists %s`, s.TableName()))
var s SearchInfo
db.Mdb.Exec(fmt.Sprintf("drop table if exists %s", s.TableName()))
// 重新创建 Search 表
CreateSearchTable()
}
@@ -230,6 +230,7 @@ func CreateSearchTable() {
}
}
// ExistSearchTable 是否存在Search Table
func ExistSearchTable() bool {
// 1. 判断表中是否存在当前表
return db.Mdb.Migrator().HasTable(&SearchInfo{})
@@ -237,7 +238,7 @@ func ExistSearchTable() bool {
// AddSearchIndex search表中数据保存完毕后 将常用字段添加索引提高查询效率
func AddSearchIndex() {
var s *SearchInfo
var s SearchInfo
tableName := s.TableName()
// 添加索引
db.Mdb.Exec(fmt.Sprintf("CREATE UNIQUE INDEX idx_mid ON %s (mid)", tableName))
@@ -331,8 +332,8 @@ func ExistSearchInfo(mid int64) bool {
// TunCateSearchTable 截断SearchInfo数据表
func TunCateSearchTable() {
var searchInfo *SearchInfo
err := db.Mdb.Exec(fmt.Sprint("TRUNCATE TABLE ", searchInfo.TableName())).Error
var searchInfo SearchInfo
err := db.Mdb.Exec(fmt.Sprintf("TRUNCATE TABLE %s", searchInfo.TableName())).Error
if err != nil {
log.Println("TRUNCATE TABLE Error: ", err)
}

View File

@@ -36,7 +36,7 @@ func CreateUserTable() {
// 如果不存在则创建表 并设置自增ID初始值为10000
if !ExistUserTable() {
err := db.Mdb.AutoMigrate(u)
db.Mdb.Exec(fmt.Sprintf("alter table %s auto_Increment=%d", u.TableName(), config.UserIdInitialVal))
db.Mdb.Exec(fmt.Sprintf("alter table %s auto_Increment = %s", u.TableName(), config.UserIdInitialVal))
if err != nil {
log.Println("Create Table SearchInfo Failed: ", err)
}

View File

@@ -1,5 +1,7 @@
package system
import "time"
// SearchTagsVO 搜索标签请求参数
type SearchTagsVO struct {
Pid int64 `json:"pid"`
@@ -34,6 +36,12 @@ type FilmTaskOptions struct {
Name string `json:"name"`
}
type Option struct {
Name string `json:"name"`
Value any `json:"value"`
}
type OptionGroup map[string][]Option
// CollectParams 数据采集所需要的参数
type CollectParams struct {
Id string `json:"id"` // 资源站id
@@ -116,9 +124,11 @@ type MovieDetailVo struct {
}
type RecordRequestVo struct {
OriginId string `json:"originId"` // 源站点ID
CollectType int `json:"collectType"` // 采集类型
Hour int `json:"hour"` // 采集时长
Status int `json:"status"` // 状态
Paging *Page `json:"paging"` // 分页参数
OriginId string `json:"originId"` // 源站点ID
CollectType int `json:"collectType"` // 采集类型
Hour int `json:"hour"` // 采集时长
Status int `json:"status"` // 状态
BeginTime time.Time `json:"beginTime"` // 起始时间
EndTime time.Time `json:"endTime"` // 结束时间
Paging *Page `json:"paging"` // 分页参数
}