package com.zhpb.gdyd_zhpb_zgf.service.impl;

import com.zhpb.gdyd_zhpb_zgf.entity.mysql.ModelRequestLog;
import com.zhpb.gdyd_zhpb_zgf.repository.mysql.ModelRequestLogRepository;
import com.zhpb.gdyd_zhpb_zgf.service.ModelRequestLogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service
public class ModelRequestLogServiceImpl implements ModelRequestLogService {

    private static final Logger logger = LoggerFactory.getLogger(ModelRequestLogServiceImpl.class);

    private final ModelRequestLogRepository modelRequestLogRepository;

    public ModelRequestLogServiceImpl(ModelRequestLogRepository modelRequestLogRepository) {
        this.modelRequestLogRepository = modelRequestLogRepository;
    }

    @Override
    public void record(ModelRequestLog log) {
        if (log == null) {
            return;
        }
        try {
            if (log.getRequestTime() == null) {
                log.setRequestTime(java.time.LocalDateTime.now());
            }
            modelRequestLogRepository.save(log);
        } catch (Exception e) {
            logger.warn("记录模型请求日志失败: {}", e.getMessage());
        }
    }
}


