package com.jwipc.log.factory;

import com.jwipc.log.logic.ThirdApiLogLogic;
import com.jwipc.log.logic.util.SpringContextHolderHandle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.LocalDateTime;
import java.util.TimerTask;

/**
 * @author shenyang.ou
 * @date 2024/3/18 15:56
 * @desc 日志操作任务创建工厂
 */
public class ApiLogTaskFactory {
    private static Logger logger = LoggerFactory.getLogger(ApiLogTaskFactory.class);
    public static TimerTask saveLog(final String code, final String name, final Integer Type, final String infRequestParams, final String infResponse, final String infInfo, final LocalDateTime beginDateTime ) {
        return new TimerTask() {
            @Override
            public void run() {
                try {
                    ThirdApiLogLogic thirdApiLogLogic = (ThirdApiLogLogic) SpringContextHolderHandle.getBean(Class.forName("com.jwipc.log.logic.ThirdApiLogLogic"));
                    thirdApiLogLogic.saveLog(code,name,Type,infRequestParams,infResponse,infInfo,beginDateTime);
                } catch (Exception e) {
                    logger.error("创建api操作日志异常!", e);
                }
            }
        };
    }

    public static TimerTask saveCallLog(final String code, final String name, final Integer Type, final String infRequestParams, final String infResponse, final String infInfo, final LocalDateTime beginDateTime ) {
        return new TimerTask() {
            @Override
            public void run() {
                try {
                    ThirdApiLogLogic thirdApiLogLogic = (ThirdApiLogLogic) SpringContextHolderHandle.getBean(Class.forName("com.jwipc.log.logic.ThirdApiLogLogic"));
                    thirdApiLogLogic.saveCallLog(code,name,Type,infRequestParams,infResponse,infInfo,beginDateTime);
                } catch (Exception e) {
                    logger.error("创建api操作日志异常!", e);
                }
            }
        };
    }
}
