27 lines
808 B
Java
27 lines
808 B
Java
package com.baiyue.audit.service;
|
|
import jakarta.annotation.Resource;
|
|
|
|
import com.baiyue.audit.dto.AuditIngestRequest;
|
|
import com.baiyue.audit.repository.AuditEventRepository;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.util.StringUtils;
|
|
|
|
import java.util.UUID;
|
|
|
|
/**
|
|
* 审计事件写入应用服务,在事务内接收并持久化不可变业务审计记录。
|
|
*/
|
|
@Service
|
|
public class AuditIngestService {
|
|
@Resource
|
|
private AuditEventRepository repository;
|
|
|
|
|
|
@Transactional
|
|
public boolean ingest(AuditIngestRequest event) {
|
|
String eventId = StringUtils.hasText(event.eventId()) ? event.eventId() : UUID.randomUUID().toString();
|
|
return repository.save(event, eventId);
|
|
}
|
|
}
|