package cn.com.qmth.stmms.admin.log;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.com.qmth.stmms.admin.exam.BaseExamController;
import cn.com.qmth.stmms.biz.exam.query.OperationLogSearchQuery;
import cn.com.qmth.stmms.biz.exam.service.ExamService;
import cn.com.qmth.stmms.biz.exam.service.OperationLogService;
import cn.com.qmth.stmms.common.domain.WebUser;
import cn.com.qmth.stmms.common.enums.LogType;
import cn.com.qmth.stmms.common.utils.RequestUtils;

@Controller
@RequestMapping("/admin/operation/log")
public class OperationLogController extends BaseExamController {

    protected static Logger log = LoggerFactory.getLogger(OperationLogController.class);

    @Autowired
    private OperationLogService logService;

    @Autowired
    private ExamService examService;

    @RequestMapping
    public String list(HttpServletRequest request, Model model, OperationLogSearchQuery query) {
        WebUser wu = RequestUtils.getWebUser(request);
        int examId = getSessionExamId(request);
        query.setExamId(examId);
        query.setSchoolId(wu.getUser().getSchoolId());
        query.orderByCreateTime();
        query = logService.findByQuery(query);
        model.addAttribute("query", query);
        model.addAttribute("examList", examService.findBySchoolId(wu.getUser().getSchoolId()));
        model.addAttribute("typeList", LogType.values());
        return "modules/log/logList";
    }

}
