package cn.com.qmth.examcloud.core.questions.starter.config;

import java.util.Optional;

import org.springframework.context.annotation.Configuration;
import org.springframework.data.domain.AuditorAware;

import cn.com.qmth.examcloud.api.commons.security.bean.User;
import cn.com.qmth.examcloud.web.enums.HttpServletRequestAttribute;
import cn.com.qmth.examcloud.web.support.ServletUtil;

@Configuration
public class UserIDAuditorBean implements AuditorAware<Long> {
    @Override
    public Optional<Long> getCurrentAuditor() {
    	User accessUser = (User) ServletUtil.getRequest()
                .getAttribute(HttpServletRequestAttribute.$_ACCESS_USER.name());
        if (null == accessUser) {
        	return Optional.of(-999L);
        }
        return Optional.of(accessUser.getUserId());
    }
}