package com.ym.mec.auth.interceptor;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.auth.service.SysUserService;
import com.ym.mec.common.security.AuthUser;
import com.ym.mec.common.security.SecurityUtils;
import com.yonge.log.interceptor.AuditLogInterceptor;

@Component
public class OperationLogInterceptor extends AuditLogInterceptor {

	@Autowired
	private SysUserService sysUserService;

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws ServletException, IOException {
		AuthUser authUser = SecurityUtils.getUser();
		if (authUser != null) {
			SysUser sysUser = sysUserService.get(authUser.getUserId());

			if (sysUser != null) {
				setUsername(sysUser.getRealName(), sysUser.getId());
			}
		}
		return true;
	}

}
