package com.jwipc.sys.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jwipc.sys.entity.AuditLog;
import com.jwipc.sys.mapper.AuditLogMapper;
import com.jwipc.sys.model.po.AuditLogPO;
import com.jwipc.sys.model.query.AuditLogQuery;
import com.jwipc.sys.service.IAuditLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 系统审计日志表 服务实现类
 * </p>
 *
 * @author qzc
 * @since 2025-11-20
 */
@Service
public class AuditLogServiceImpl extends ServiceImpl<AuditLogMapper, AuditLog> implements IAuditLogService {

    @Override
    @Async("auditLogExecutor")
    public void saveAuditLogAsync(AuditLog auditLog) {
        try {
            baseMapper.insert(auditLog);
        } catch (Exception e) {
            // 记录到错误日志或实现重试机制
            System.err.println("日志保存失败: " + auditLog + ", 错误: " + e.getMessage());
        }
    }

    @Override
    public List<AuditLogPO> findPageByQuery(Page<AuditLog> dbPage, AuditLogQuery query) {
        if (dbPage==null){
            return baseMapper.findPageByQuery(query);
        }
        return baseMapper.findPageByQuery(dbPage,query);
    }
}
