package cn.novalon.manage.sys.handler;

import cn.novalon.manage.common.handler.ExceptionLogService;
import cn.novalon.manage.sys.core.domain.SysExceptionLog;
import cn.novalon.manage.sys.core.service.ISysExceptionLogService;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;

/**
 * 异常日志服务实现
 * 
 * 文件定义：实现异常日志记录接口，使用sys模块的异常日志服务
 * 涉及业务：异常日志记录、错误追踪
 * 算法：使用响应式编程实现异步日志记录
 * 
 * @author 张翔
 * @date 2026-03-13
 */
@Service
public class ExceptionLogServiceImpl implements ExceptionLogService {

    private final ISysExceptionLogService exceptionLogService;

    public ExceptionLogServiceImpl(ISysExceptionLogService exceptionLogService) {
        this.exceptionLogService = exceptionLogService;
    }

    @Override
    public Mono<Void> logException(String title, String exceptionName, String exceptionMsg, 
                                  String methodName, String ip, String stackTrace) {
        SysExceptionLog exceptionLog = new SysExceptionLog();
        exceptionLog.setTitle(title);
        exceptionLog.setExceptionName(exceptionName);
        exceptionLog.setExceptionMsg(exceptionMsg);
        exceptionLog.setMethodName(methodName);
        exceptionLog.setIp(ip);
        exceptionLog.setCreateTime(java.time.LocalDateTime.now());
        exceptionLog.setExceptionStack(stackTrace);

        return exceptionLogService.save(exceptionLog).then();
    }
}
