feat: 错误重试记忆DAO与DTO
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
"model-gateway/consts/public"
|
||||
"model-gateway/model/entity"
|
||||
|
||||
"gitea.redpowerfuture.com/red-future/common/db/gfdb"
|
||||
)
|
||||
|
||||
var ErrorMemory = &errorMemoryDao{}
|
||||
|
||||
type errorMemoryDao struct{}
|
||||
|
||||
// GetByKey 按记忆键查询(未命中返回 (nil, nil))
|
||||
func (d *errorMemoryDao) GetByKey(ctx context.Context, key string) (res *entity.ErrorMemory, err error) {
|
||||
r, err := gfdb.DB(ctx, public.DbNameModelGateway).Model(ctx, public.TableNameErrorMemory).
|
||||
Where(entity.ErrorMemoryCol.MemoryKey, key).
|
||||
One()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Struct(&res)
|
||||
return
|
||||
}
|
||||
|
||||
// Upsert 存在则更新 retryable/reason/analyzed_by,不存在则插入
|
||||
func (d *errorMemoryDao) Upsert(ctx context.Context, m *entity.ErrorMemory) (err error) {
|
||||
model := gfdb.DB(ctx, public.DbNameModelGateway).Model(ctx, public.TableNameErrorMemory)
|
||||
n, err := model.Where(entity.ErrorMemoryCol.MemoryKey, m.MemoryKey).Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if n > 0 {
|
||||
_, err = model.Where(entity.ErrorMemoryCol.MemoryKey, m.MemoryKey).Data(map[string]any{
|
||||
entity.ErrorMemoryCol.Retryable: m.Retryable,
|
||||
entity.ErrorMemoryCol.Reason: m.Reason,
|
||||
entity.ErrorMemoryCol.AnalyzedBy: m.AnalyzedBy,
|
||||
}).Update()
|
||||
return
|
||||
}
|
||||
_, err = model.Insert(m)
|
||||
return
|
||||
}
|
||||
|
||||
// List 分页查询(按 id 倒序)
|
||||
func (d *errorMemoryDao) List(ctx context.Context, page, pageSize int) (list []entity.ErrorMemory, total int64, err error) {
|
||||
model := gfdb.DB(ctx, public.DbNameModelGateway).Model(ctx, public.TableNameErrorMemory)
|
||||
n, err := model.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
total = int64(n)
|
||||
err = model.Page(page, pageSize).OrderDesc(entity.ErrorMemoryCol.Id).Scan(&list)
|
||||
return
|
||||
}
|
||||
|
||||
// Delete 按 id 删除(软删除)
|
||||
func (d *errorMemoryDao) Delete(ctx context.Context, id int64) (err error) {
|
||||
_, err = gfdb.DB(ctx, public.DbNameModelGateway).Model(ctx, public.TableNameErrorMemory).
|
||||
Where(entity.ErrorMemoryCol.Id, id).Delete()
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"gitea.redpowerfuture.com/red-future/common/beans"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
// GetErrorMemoryListReq 错误重试记忆列表
|
||||
type GetErrorMemoryListReq struct {
|
||||
g.Meta `path:"/errorMemory/list" method:"get" tags:"错误记忆" summary:"错误重试记忆列表" dc:"查看错误→可重试结论记忆"`
|
||||
*beans.Page `json:"page"`
|
||||
}
|
||||
|
||||
type GetErrorMemoryListRes struct {
|
||||
List []ErrorMemoryItem `json:"list" dc:"记忆条目"`
|
||||
Total int64 `json:"total" dc:"总数"`
|
||||
}
|
||||
|
||||
type ErrorMemoryItem struct {
|
||||
Id int64 `json:"id"`
|
||||
MemoryKey string `json:"memoryKey"`
|
||||
Upstream string `json:"upstream"`
|
||||
ErrorCode string `json:"errorCode"`
|
||||
MsgFingerprint string `json:"msgFingerprint"`
|
||||
Retryable bool `json:"retryable"`
|
||||
Reason string `json:"reason"`
|
||||
AnalyzedBy string `json:"analyzedBy"`
|
||||
}
|
||||
|
||||
// DeleteErrorMemoryReq 删除错误重试记忆
|
||||
type DeleteErrorMemoryReq struct {
|
||||
g.Meta `path:"/errorMemory/delete" method:"post" tags:"错误记忆" summary:"删除错误重试记忆" dc:"手动清理永久记忆条目"`
|
||||
Id int64 `json:"id" v:"required#id不能为空" dc:"记忆ID"`
|
||||
}
|
||||
Reference in New Issue
Block a user