package com.aucma.system.utils;

import com.aucma.common.utils.spring.SpringUtils;
import com.aucma.system.domain.SysPortLog;
import com.aucma.system.service.ISysPortLogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.TimerTask;

/**
 * 处理并记录日志文件
 * 
 * @author ruoyi
 */
public class PortLogUtils
{
    private static final Logger logger = LoggerFactory.getLogger(PortLogUtils.class);

    /**
     * 保存接口日志
     * @param factoryCode 工厂编码
     * @param logTitle 接口标题
     * @param logMethod 方法名称
     * @param operationParam 请求参数
     * @param resultOne 返回消息
     * @param errorMsg 错误消息
     */
    public static void savePortLog(String factoryCode, String logTitle, String logMethod, String operationParam, String resultOne , String errorMsg)
    {
        try {
            TimerTask timerTask = new TimerTask() {
                @Override
                public void run() {
                    SysPortLog sysPortLog = new SysPortLog();
                    sysPortLog.setFactoryCode(factoryCode);
                    sysPortLog.setLogTitle(logTitle);
                    sysPortLog.setLogMethod(logMethod);
                    sysPortLog.setOperationParam(operationParam);
                    sysPortLog.setResultOne(resultOne);
                    sysPortLog.setErrorMsg(errorMsg);
                    SpringUtils.getBean(ISysPortLogService.class).insertSysPortLog(sysPortLog);
                }
            };
            timerTask.run();
        } catch (Exception e) {
            logger.error("保存MES接口日志错误：" + e.getMessage());
        }
    }

}
