package com.ym.mec.student.interceptor;

import com.ym.mec.auth.api.client.SysUserFeignService;
import com.ym.mec.auth.api.entity.SysUser;
import com.yonge.log.interceptor.AuditLogInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

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

@Component
public class OperationLogInterceptor extends AuditLogInterceptor {

	@Autowired
	@Lazy
	private SysUserFeignService sysUserFeignService;

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
		SysUser sysUser = sysUserFeignService.queryUserInfo();
		if (sysUser != null && sysUser.getId() != null) {
			request.setAttribute("userId",sysUser.getId());
			request.setAttribute("username",sysUser.getRealName());
		}
		super.afterCompletion(request, response, handler, ex);
	}

}
