暂存提交
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package com.baiyue.audit.repository;
|
||||
|
||||
import com.baiyue.audit.dto.AuditIngestRequest;
|
||||
import com.baiyue.audit.entity.AuditLogEntity;
|
||||
import com.baiyue.audit.mapper.AuditLogMapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* 审计事件持久化仓储,负责将内部审计请求映射并追加写入审计日志表。
|
||||
*/
|
||||
@Repository
|
||||
public class AuditEventRepository {
|
||||
private final AuditLogMapper mapper;
|
||||
|
||||
public AuditEventRepository(AuditLogMapper mapper) {
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
public void save(AuditIngestRequest event) {
|
||||
AuditLogEntity entity = new AuditLogEntity();
|
||||
entity.setEventType(event.eventType());
|
||||
entity.setResourceType(event.resourceType());
|
||||
entity.setResourceId(event.resourceId());
|
||||
entity.setDescription(event.description());
|
||||
entity.setRequestId(event.requestId());
|
||||
entity.setTraceId(event.traceId());
|
||||
entity.setTenantId(event.tenantId());
|
||||
entity.setOperatorTenantId(event.operatorTenantId());
|
||||
entity.setUserId(event.userId());
|
||||
entity.setUsername(event.username());
|
||||
entity.setAppCode(event.appCode());
|
||||
entity.setClientType(event.clientType());
|
||||
entity.setHttpMethod(event.httpMethod());
|
||||
entity.setRequestUri(event.requestUri());
|
||||
entity.setClientIp(event.clientIp());
|
||||
entity.setDurationMs(event.durationMs());
|
||||
entity.setSuccess(event.success());
|
||||
entity.setErrorCode(event.errorCode());
|
||||
entity.setErrorMessage(event.errorMessage());
|
||||
entity.setBeforeData(jsonOrNull(event.beforeData()));
|
||||
entity.setAfterData(jsonOrNull(event.afterData()));
|
||||
entity.setOccurredAt(event.occurredAt());
|
||||
entity.setServiceName(event.serviceName());
|
||||
mapper.insert(entity);
|
||||
}
|
||||
|
||||
private static String jsonOrNull(String value) {
|
||||
return value == null ? "null" : value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user