package com.th.demo.tools;

import com.th.demo.model.system.SysLog;
import com.th.demo.model.system.SysUser;
import com.th.demo.service.impl.system.SysLogServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Date;

@Component
public class LogTool {

	@Autowired
	public SysLogServiceImpl sysLogServiceImpl;

	public static LogTool logTool;

	@PostConstruct
	public void init() {
		logTool = this;
	}

	public static void log(String userId, String jmId, String logType,
                           String logInfo) {
		SysLog sysLog = new SysLog();
		SysUser user = new SysUser();
		user.setId(userId);
		sysLog.setUser(user);
		sysLog.setLogJmId(jmId);
		sysLog.setLogType(logType);
		sysLog.setLogInfo(logInfo);
		sysLog.setAddTime(new Date());

		logTool.sysLogServiceImpl.add(sysLog);
	}
}
