package com.yonge.cooleshow.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.yonge.cooleshow.auth.api.entity.SysUser;
import com.yonge.cooleshow.auth.service.SysUserService;
import com.yonge.cooleshow.common.security.AuthUser;
import com.yonge.cooleshow.common.security.SecurityUtils;
import com.yonge.toolset.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;
	}

}
