102 lines
2.8 KiB
Go
102 lines
2.8 KiB
Go
package system
|
||
|
||
import (
|
||
"context"
|
||
"errors"
|
||
"time"
|
||
)
|
||
|
||
var (
|
||
ErrErrorNotFound = errors.New("错误日志不存在")
|
||
)
|
||
|
||
// SysError 错误日志实体
|
||
type SysError struct {
|
||
ID int64
|
||
Form string
|
||
Info string
|
||
Level string
|
||
Solution string
|
||
Status string
|
||
CreatedAt time.Time
|
||
UpdatedAt time.Time
|
||
}
|
||
|
||
// ErrorSearchReq 错误日志搜索请求
|
||
type ErrorSearchReq struct {
|
||
Page int
|
||
PageSize int
|
||
Form *string
|
||
Info *string
|
||
CreatedAtRange []time.Time
|
||
}
|
||
|
||
// ErrorRepo 错误日志仓储接口
|
||
type ErrorRepo interface {
|
||
Create(ctx context.Context, sysError *SysError) error
|
||
Delete(ctx context.Context, id string) error
|
||
DeleteByIds(ctx context.Context, ids []string) error
|
||
Update(ctx context.Context, sysError *SysError) error
|
||
GetById(ctx context.Context, id string) (*SysError, error)
|
||
GetList(ctx context.Context, req *ErrorSearchReq) ([]*SysError, int64, error)
|
||
UpdateStatus(ctx context.Context, id string, status string) error
|
||
UpdateSolution(ctx context.Context, id string, status string, solution string) error
|
||
}
|
||
|
||
// ErrorUsecase 错误日志用例
|
||
type ErrorUsecase struct {
|
||
repo ErrorRepo
|
||
}
|
||
|
||
// NewErrorUsecase 创建错误日志用例
|
||
func NewErrorUsecase(repo ErrorRepo) *ErrorUsecase {
|
||
return &ErrorUsecase{repo: repo}
|
||
}
|
||
|
||
// CreateSysError 创建错误日志
|
||
func (uc *ErrorUsecase) CreateSysError(ctx context.Context, sysError *SysError) error {
|
||
return uc.repo.Create(ctx, sysError)
|
||
}
|
||
|
||
// DeleteSysError 删除错误日志
|
||
func (uc *ErrorUsecase) DeleteSysError(ctx context.Context, id string) error {
|
||
return uc.repo.Delete(ctx, id)
|
||
}
|
||
|
||
// DeleteSysErrorByIds 批量删除错误日志
|
||
func (uc *ErrorUsecase) DeleteSysErrorByIds(ctx context.Context, ids []string) error {
|
||
return uc.repo.DeleteByIds(ctx, ids)
|
||
}
|
||
|
||
// UpdateSysError 更新错误日志
|
||
func (uc *ErrorUsecase) UpdateSysError(ctx context.Context, sysError *SysError) error {
|
||
return uc.repo.Update(ctx, sysError)
|
||
}
|
||
|
||
// GetSysError 根据ID获取错误日志
|
||
func (uc *ErrorUsecase) GetSysError(ctx context.Context, id string) (*SysError, error) {
|
||
return uc.repo.GetById(ctx, id)
|
||
}
|
||
|
||
// GetSysErrorInfoList 分页获取错误日志列表
|
||
func (uc *ErrorUsecase) GetSysErrorInfoList(ctx context.Context, req *ErrorSearchReq) ([]*SysError, int64, error) {
|
||
return uc.repo.GetList(ctx, req)
|
||
}
|
||
|
||
// GetSysErrorSolution 异步处理错误(触发AI生成解决方案)
|
||
func (uc *ErrorUsecase) GetSysErrorSolution(ctx context.Context, id string) error {
|
||
// 立即更新为处理中
|
||
if err := uc.repo.UpdateStatus(ctx, id, "处理中"); err != nil {
|
||
return err
|
||
}
|
||
|
||
// 异步处理(简化版本,不调用LLM)
|
||
go func(errorId string) {
|
||
// 这里可以集成AI服务生成解决方案
|
||
// 目前简化为直接标记处理完成
|
||
_ = uc.repo.UpdateStatus(context.Background(), errorId, "处理完成")
|
||
}(id)
|
||
|
||
return nil
|
||
}
|