This commit is contained in:
@@ -9,14 +9,11 @@ import (
|
||||
"github.com/break/junhong_cmp_fiber/internal/model"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/constants"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/logger"
|
||||
"go.uber.org/zap"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// AssetOperationLogStore 资产操作日志存储接口。
|
||||
type AssetOperationLogStore interface {
|
||||
Create(ctx context.Context, log *model.AssetOperationLog) error
|
||||
ListByAssetPaged(
|
||||
ctx context.Context,
|
||||
assetType string,
|
||||
@@ -28,11 +25,6 @@ type AssetOperationLogStore interface {
|
||||
) ([]*model.AssetOperationLog, int64, error)
|
||||
}
|
||||
|
||||
// OperationLogger 资产审计记录接口。
|
||||
type OperationLogger interface {
|
||||
LogOperation(ctx context.Context, log *model.AssetOperationLog)
|
||||
}
|
||||
|
||||
// Service 资产审计服务。
|
||||
type Service struct {
|
||||
store AssetOperationLogStore
|
||||
@@ -57,24 +49,6 @@ func NewService(store AssetOperationLogStore, db *gorm.DB) *Service {
|
||||
}
|
||||
}
|
||||
|
||||
// LogOperation 记录资产操作日志(异步写入,不阻塞主流程)。
|
||||
func (s *Service) LogOperation(ctx context.Context, log *model.AssetOperationLog) {
|
||||
if s == nil || s.store == nil || log == nil {
|
||||
return
|
||||
}
|
||||
|
||||
go func() {
|
||||
if err := s.store.Create(context.Background(), log); err != nil {
|
||||
logger.GetAppLogger().Error("写入资产操作日志失败",
|
||||
zap.String("asset_type", log.AssetType),
|
||||
zap.Uint("asset_id", log.AssetID),
|
||||
zap.String("operation_type", log.OperationType),
|
||||
zap.String("result_status", log.ResultStatus),
|
||||
zap.Error(err))
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// ListByAsset 按资产分页查询操作日志。
|
||||
func (s *Service) ListByAsset(ctx context.Context, params ListByAssetParams) (*dto.AssetOperationLogListResponse, error) {
|
||||
if s == nil || s.store == nil {
|
||||
|
||||
Reference in New Issue
Block a user