package com.zsElectric.boot.charging.service.impl;

import com.zsElectric.boot.charging.entity.ThirdPartyApiLog;
import com.zsElectric.boot.charging.mapper.ThirdPartyApiLogMapper;
import com.zsElectric.boot.charging.service.ThirdPartyApiLogService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * 第三方接口请求日志服务实现
 *
 * @author system
 * @since 2025-01-02
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class ThirdPartyApiLogServiceImpl implements ThirdPartyApiLogService {

    private final ThirdPartyApiLogMapper thirdPartyApiLogMapper;

    @Override
    public void saveLog(ThirdPartyApiLog apiLog) {
        try {
            thirdPartyApiLogMapper.insert(apiLog);
        } catch (Exception e) {
            log.error("保存第三方接口日志失败: {}", e.getMessage(), e);
        }
    }

    @Async
    @Override
    public void saveLogAsync(ThirdPartyApiLog apiLog) {
        saveLog(apiLog);
    }
}
