This commit is contained in:
88
internal/service/device/audit.go
Normal file
88
internal/service/device/audit.go
Normal file
@@ -0,0 +1,88 @@
|
||||
package device
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/model"
|
||||
assetAuditSvc "github.com/break/junhong_cmp_fiber/internal/service/asset_audit"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/constants"
|
||||
)
|
||||
|
||||
// AssetAuditService 资产审计服务接口。
|
||||
type AssetAuditService interface {
|
||||
LogOperation(ctx context.Context, log *model.AssetOperationLog)
|
||||
}
|
||||
|
||||
func (s *Service) logDeviceAudit(ctx context.Context, p assetAuditSvc.BuildLogParams) {
|
||||
if s == nil || s.assetAuditService == nil {
|
||||
return
|
||||
}
|
||||
if p.Operator.Type == "" {
|
||||
p.Operator = assetAuditSvc.OperatorFromContext(ctx)
|
||||
}
|
||||
if p.AssetType == "" {
|
||||
p.AssetType = constants.AssetTypeDevice
|
||||
}
|
||||
s.assetAuditService.LogOperation(ctx, assetAuditSvc.BuildLog(ctx, p))
|
||||
}
|
||||
|
||||
func (s *Service) logDeviceOperation(
|
||||
ctx context.Context,
|
||||
operationType string,
|
||||
operationDesc string,
|
||||
resultStatus string,
|
||||
device *model.Device,
|
||||
beforeData map[string]any,
|
||||
afterData map[string]any,
|
||||
batchTotal int,
|
||||
successCount int,
|
||||
failCount int,
|
||||
err error,
|
||||
) {
|
||||
if strings.TrimSpace(operationDesc) == "" {
|
||||
operationDesc = operationType
|
||||
}
|
||||
if strings.TrimSpace(resultStatus) == "" {
|
||||
if err != nil {
|
||||
resultStatus = constants.AssetAuditResultFailed
|
||||
} else {
|
||||
resultStatus = constants.AssetAuditResultSuccess
|
||||
}
|
||||
}
|
||||
|
||||
params := assetAuditSvc.BuildLogParams{
|
||||
OperationType: operationType,
|
||||
OperationDesc: operationDesc,
|
||||
ResultStatus: resultStatus,
|
||||
BeforeData: beforeData,
|
||||
AfterData: afterData,
|
||||
BatchTotal: batchTotal,
|
||||
SuccessCount: successCount,
|
||||
FailCount: failCount,
|
||||
}
|
||||
if device != nil {
|
||||
params.AssetID = device.ID
|
||||
params.AssetIdentifier = device.VirtualNo
|
||||
}
|
||||
if err != nil {
|
||||
params.ErrorCode, params.ErrorMsg = assetAuditSvc.BuildErrorInfo(err)
|
||||
}
|
||||
|
||||
s.logDeviceAudit(ctx, params)
|
||||
}
|
||||
|
||||
func deviceSnapshot(device *model.Device) map[string]any {
|
||||
if device == nil {
|
||||
return nil
|
||||
}
|
||||
return map[string]any{
|
||||
"id": device.ID,
|
||||
"virtual_no": device.VirtualNo,
|
||||
"shop_id": device.ShopID,
|
||||
"status": device.Status,
|
||||
"series_id": device.SeriesID,
|
||||
"enable_polling": device.EnablePolling,
|
||||
"realname_policy": device.RealnamePolicy,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user