基于javaweb+mysql的ssm在线考试系统(java+ssm+mysql+jsp)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SSM在线考试系统(java+ssm+mysql+jsp)
运行环境:jdk1.8、Mysql5.7、Tomcat8.5、IDEA/Eclipse
功能简介:在线考试、历史回顾、个人成绩查询等。
管理员和教师功能有:学院管理、班级管理、课程管理、教师、学生管理、统计分析、试卷试题管理、考试安排管理、历史考试管理等
subject.setOptionA(trimChar(subject.getOptionA()));
subject.setOptionB(trimChar(subject.getOptionB()));
subject.setOptionC(trimChar(subject.getOptionC()));
subject.setOptionD(trimChar(subject.getOptionD()));
}
int row = subjectInfoService.isAddSubject(subject);
response.getWriter().print("试题添加成功!");
}
/**
* 删除试题
*
* @param subjectId
* @param response
* @throws IOException
*/
@RequestMapping(value = "/delSubject", method = RequestMethod.POST)
public void delSubject(@RequestParam("subjectId") Integer subjectId, HttpServletResponse response)
throws IOException {
logger.info("删除试题 " + subjectId);
int row = subjectInfoService.isDelSubject(subjectId);
if (row > 0) {
response.getWriter().print("t");
} else {
response.getWriter().print("f");
}
}
/**
* 修改试题 -- 获取待修改试题信息
*
* @param subjectId
* @return
*/
@RequestMapping("/subject/{subjectId}")
public ModelAndView updateSubject(@PathVariable("subjectId") Integer subjectId) {
logger.info("修改试题 " + subjectId + " 的信息(获取试题信息)");
SubjectInfo subject = subjectInfoService.getSubjectWithId(subjectId);
subjectSum += 1;
}
/** 需要添加试题集合 */
map.put("subjectIds", subjectIds);
} else {
logger.error("试题集合为空,不能进行添加试题操作!");
response.getWriter().print("需要添加的试题为空,操作失败!");
return;
}
logger.info("添加试题集合到试卷 " + examPaperId);
// 总分和题目数量信息
Map<String, Object> scoreWithNum = new HashMap<String, Object>();
scoreWithNum.put("subjectNum", subjectSum);
scoreWithNum.put("score", scoreSum);
scoreWithNum.put("examPaperId", examPaperId);
/** 修改试卷总分 */
examPaperInfoService.isUpdateExamPaperScore(scoreWithNum);
/** 修改试卷试题总量 */
examPaperInfoService.isUpdateExamPaperSubjects(scoreWithNum);
/** 添加试题到试卷中 */
esmService.isAddESM(map);
session.setAttribute("ids",null);
response.getWriter().print("试题已成功添加到试卷中!");
}
/**
* 手动添加试题到试卷时 向 Session中存入试题信息
*
* @param subjectId
* 试题编号
* @param examPaperId
* 试卷编号
* @param score
* 试题分数
* @param handle
* 操作标识, 自动 OR 手动
* @param session
* @param response
* @throws IOException
*/
@RequestMapping("/getChooseSubId")
public void getChooseSubjectId(@RequestParam("subjectId") Integer subjectId,
@RequestParam("examPaperId") Integer examPaperId, @RequestParam("score") Integer score,
@RequestParam(value = "handle", required = false) Integer handle, HttpSession session,
HttpServletResponse response) throws IOException {
List<String> ids = null;
/*
* 添加到 Session 中需先判断该试题是否已经存在该试卷中 如果存在,则不进行添加;反之添加
List<SubjectInfo> subjects = subjectInfoService.getSubjects(map);
model.addObject("subjects", subjects);
// 获取试题总量
int subjectTotal = subjectInfoService.getSubjectTotal();
// 计算总页数
int pageTotal = 1;
if (subjectTotal % pageShow == 0)
pageTotal = subjectTotal / pageShow;
else
pageTotal = subjectTotal / pageShow + 1;
model.addObject("pageTotal", pageTotal);
model.addObject("pageNow", startPage);
// 是否为需要进行手动添加试题到试卷而发起的请求
if (handAdd != null && handAdd == 1) {
model.addObject("handAdd", "1");
}
// 如果是手动添加试题到试卷,则需要返回试卷编号, 且返回当前已经选择试题数量
if (examPaperId != null) {
model.addObject("examPaperId", examPaperId);
List<String> ids = (List<String>) session.getAttribute("ids");
if (ids == null) {
model.addObject("choosed", 0);
} else {
model.addObject("choosed", ids.size());
}
}
return model;
}
/**
* 添加试题
*
* @param subject
* @param response
* @throws IOException
*/
@RequestMapping(value = "/addSubject", method = RequestMethod.POST)
public void addSubject(SubjectInfo subject, HttpServletResponse response) throws IOException {
if (subject != null) {
subject.setSubjectName(trimChar(subject.getSubjectName()));
subject.setRightResult(trimChar(subject.getRightResult()));
subject.setOptionA(trimChar(subject.getOptionA()));
subject.setOptionB(trimChar(subject.getOptionB()));
subject.setOptionC(trimChar(subject.getOptionC()));
subject.setOptionD(trimChar(subject.getOptionD()));
}
* 上传文件
* @return 保存路径
*/
private String saveUploadFile(MultipartFile file, String rootPath) {
String fileName = file.getOriginalFilename();
logger.info("保存上传文件 " + fileName + " 到 " + rootPath);
try {
file.transferTo(new File(rootPath + "/" + fileName));
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return rootPath + "/" + fileName;
}
/**
* 只将试题上传到数据库
*
* @param subjects
* @param subjectsMap
*/
private void importSubejctOnly(List<SubjectInfo> subjects, Map<String, Object> subjectsMap) {
try {
if (subjects != null && subjects.size() > 0) {
// 添加试题
int row = subjectInfoService.isAddSubjects(subjectsMap);
logger.info("只将 excel 中的试题添加到数据库成功 SIZE " + subjects.size());
} else {
logger.info("上传试题文件中不存在试题,或解析失败");
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 处理 试题 添加到 试卷
*
* @param subjects
* 试题集合
* @param examPaperId
* 对应试卷编号
*/
private void dispatcherExamPaperAndSubject(List<SubjectInfo> subjects, Integer examPaperId) {
List<Integer> subjectIds = new ArrayList<Integer>();
// 试题总量统计
int count = 0;
logger.info("修改试题 " + subjectId + " 的信息(获取试题信息)");
SubjectInfo subject = subjectInfoService.getSubjectWithId(subjectId);
ModelAndView model = new ModelAndView("/admin/subject-test");
model.addObject("subject", subject);
List<GradeInfo> grades = gradeInfoService.getGrades();
model.addObject("grades", grades);
model.addObject("courses", courseInfoService.getCourses(null));
return model;
}
/**
* 修改试题
*
* @param subject
* @param response
* @throws IOException
*/
@RequestMapping(value = "/updateSubject", method = RequestMethod.POST)
public void updateSubject(SubjectInfo subject, HttpServletResponse response) throws IOException {
logger.info("修改试题 " + subject.getSubjectId() + " 的信息(正式)");
if (subject != null) {
subject.setSubjectName(trimChar(subject.getSubjectName()));
subject.setRightResult(trimChar(subject.getRightResult()));
subject.setOptionA(trimChar(subject.getOptionA()));
subject.setOptionB(trimChar(subject.getOptionB()));
subject.setOptionC(trimChar(subject.getOptionC()));
subject.setOptionD(trimChar(subject.getOptionD()));
}
int row = subjectInfoService.isUpdateSubject(subject);
if (row > 0) {
response.getWriter().print("试题修改成功!");
} else {
response.getWriter().print("试题修改失败!");
}
}
/**
* 初始化 导入 excel 试题信息
*
* @return
*/
*/
@RequestMapping(value = "/preUpdateep/{examPlanId}", method = RequestMethod.GET)
public ModelAndView preUpdateep(@PathVariable("examPlanId") Integer examPlanId) {
ModelAndView model = new ModelAndView();
model.setViewName("/admin/examPlanedit");
// 获取所有班级信息
List<ClassInfo> classes = classInfoService.getClasses(null);
model.addObject("classes", classes);
// 获取所有科目信息
List<CourseInfo> courses = courseInfoService.getCourses(null);
model.addObject("courses", courses);
// 获取所有的试卷信息 -- 纯净的(简单的)
List<ExamPaperInfo> examPapers = examPaperInfoService.getExamPapersClear();
model.addObject("examPapers", examPapers);
// 获取当前修改对象
ExamPlanInfo examPlanWithUpdate = examPlanInfoService.getExamPlanById(examPlanId);
logger.info("获取要修改的待考记录:" + examPlanWithUpdate);
model.addObject("examPlan", examPlanWithUpdate);
return model;
}
/**
* 修改待考信息
*
* @param examPlan
* 待考记录
* @return
*/
@RequestMapping(value = "preUpdateep/examPlan", method = RequestMethod.PUT)
public String isUpdateExamPlan(ExamPlanInfo examPlan) {
logger.info("修改待考记录:" + examPlan);
examPlanInfoService.isUpdateExamPlan(examPlan);
return "redirect:../examPlans";
}
/**
* 查询学生待考信息
*
* @param classId
* 学生所在班级编号
* @param gradeId
* 学生所在系部百年好
* @param studentId
* 学生编号
* @return
*/
@RequestMapping("/willexams")
public ModelAndView getStudentWillExam(@RequestParam("classId") Integer classId,
// 条件处理
if (subjectId != null)
subject.setSubjectId(subjectId);
if (courseId != null)
course.setCourseId(courseId);
if (gradeId != null)
grade.setGradeId(gradeId);
Map<String, Object> map = new HashMap<String, Object>();
// 计算当前查询起始数据索引
int startIndex = (startPage - 1) * pageShow;
// map.put("subject", subject);
map.put("startIndex", startIndex);
map.put("pageShow", pageShow);
List<SubjectInfo> subjects = subjectInfoService.getSubjects(map);
model.addObject("subjects", subjects);
// 获取试题总量
int subjectTotal = subjectInfoService.getSubjectTotal();
// 计算总页数
int pageTotal = 1;
if (subjectTotal % pageShow == 0)
pageTotal = subjectTotal / pageShow;
else
pageTotal = subjectTotal / pageShow + 1;
model.addObject("pageTotal", pageTotal);
model.addObject("pageNow", startPage);
// 是否为需要进行手动添加试题到试卷而发起的请求
if (handAdd != null && handAdd == 1) {
model.addObject("handAdd", "1");
}
// 如果是手动添加试题到试卷,则需要返回试卷编号, 且返回当前已经选择试题数量
if (examPaperId != null) {
model.addObject("examPaperId", examPaperId);
List<String> ids = (List<String>) session.getAttribute("ids");
if (ids == null) {
model.addObject("choosed", 0);
} else {
model.addObject("choosed", ids.size());
}
}
return model;
}
model.addObject("teachers", teachers);
model.addObject("grades", grades);
return model;
}
/**
* 修改班级信息
*
* @param classInfo
* 班级信息
* @param request
* @param lastTeacherId
* 上一个班主任编号,修改其 班主任状态
* @return
*/
@RequestMapping(value = "edit/class/class", method = RequestMethod.POST)
public String isUpdateClass(ClassInfo classInfo, HttpServletRequest request,
@RequestParam(value = "lastTeacher", required = false) Integer lastTeacherId) {
ClassInfo byClassName = classInfoService.findByClassName(classInfo.getClassName());
if(byClassName!=null){
if(!byClassName.getClassId().equals(classInfo.getClassId())){
request.setAttribute("error", "该班级名称已存在!");
return "../../error";
}
}
// 修改上一教师不为班主任状态
if (lastTeacherId != null) {
String returnMsg = isChangeTeacherWork(0, lastTeacherId);
if (returnMsg != null) {
request.setAttribute("error", "修改教师班主任状态 对应教师编号有误");
return "../error";
}
}
// 修改当前教师为班主任状态
String returnMsg = isChangeTeacherWork(1, classInfo.getTeacher().getTeacherId());
if (returnMsg != null) {
request.setAttribute("error", "修改教师班主任状态 对应教师编号有误");
return "../error";
}
* @return
*/
@RequestMapping(value = "preUpdateep/examPlan", method = RequestMethod.PUT)
public String isUpdateExamPlan(ExamPlanInfo examPlan) {
logger.info("修改待考记录:" + examPlan);
examPlanInfoService.isUpdateExamPlan(examPlan);
return "redirect:../examPlans";
}
/**
* 查询学生待考信息
*
* @param classId
* 学生所在班级编号
* @param gradeId
* 学生所在系部百年好
* @param studentId
* 学生编号
* @return
*/
@RequestMapping("/willexams")
public ModelAndView getStudentWillExam(@RequestParam("classId") Integer classId,
@RequestParam("gradeId") Integer gradeId,
@RequestParam(value = "studentId", required = false) Integer studentId) {
logger.info("查询学生 " + studentId + "(NULL-未指定)待考信息 班级:" + classId + ", 系部:" + gradeId);
ModelAndView model = new ModelAndView();
model.setViewName("/reception/examCenter");
Map<String, Object> map = new HashMap<String, Object>();
map.put("classId", classId);
map.put("gradeId", gradeId);
List<ExamPlanInfo> examPlans = examPlanInfoService.getStudentWillExam(map);
model.addObject("examPlans", examPlans);
model.addObject("gradeId", gradeId);
return model;
}
/**
* 定时刷新考试安排记录,将过期考试移除 周一至周五 每隔15分钟刷新一次
*/
@Scheduled(cron = "0 */15 * * * MON-FRI")
public void refreshExamPlan() {
List<ExamPlanInfo> examPlans = examPlanInfoService.getExamPlans(null);
model.addObject("classId", classId);
model.addObject("gradeId", gradeId);
return model;
}
}
/**
* 获取学生历史考试记录
* @param studentId 学生编号
* @return
*/
@RequestMapping("/history/{studentId}")
public ModelAndView getExamHistoryInfo(@PathVariable("studentId") Integer studentId) {
ModelAndView model = new ModelAndView();
if (studentId == null) {
logger.error("学生编号 为空");
model.setViewName("error");
return model;
}
logger.info("学生 "+studentId+" 获取考试历史记录");
//获取历史考试信息记录集合
List<ExamHistoryPaper> ehps = examHistoryPaperService.getExamHistoryToStudent(studentId);
model.addObject("ehps", ehps);
model.setViewName("/reception/examHistory");
return model;
}
/**
* 考生提交考试
* @param studentId
* @param examPaperId
* @param classId
* @param gradeId
* @return
*/
@RequestMapping(value="/submit", method={RequestMethod.POST, RequestMethod.GET})
public String examSubmit(
@RequestParam("studentId") Integer studentId,
@RequestParam("examPaperId") Integer examPaperId,
/**
* 查询学生待考信息
*
* @param classId
* 学生所在班级编号
* @param gradeId
* 学生所在系部百年好
* @param studentId
* 学生编号
* @return
*/
@RequestMapping("/willexams")
public ModelAndView getStudentWillExam(@RequestParam("classId") Integer classId,
@RequestParam("gradeId") Integer gradeId,
@RequestParam(value = "studentId", required = false) Integer studentId) {
logger.info("查询学生 " + studentId + "(NULL-未指定)待考信息 班级:" + classId + ", 系部:" + gradeId);
ModelAndView model = new ModelAndView();
model.setViewName("/reception/examCenter");
Map<String, Object> map = new HashMap<String, Object>();
map.put("classId", classId);
map.put("gradeId", gradeId);
List<ExamPlanInfo> examPlans = examPlanInfoService.getStudentWillExam(map);
model.addObject("examPlans", examPlans);
model.addObject("gradeId", gradeId);
return model;
}
/**
* 定时刷新考试安排记录,将过期考试移除 周一至周五 每隔15分钟刷新一次
*/
@Scheduled(cron = "0 */15 * * * MON-FRI")
public void refreshExamPlan() {
List<ExamPlanInfo> examPlans = examPlanInfoService.getExamPlans(null);
logger.info("刷新待考记录, SIZE " + examPlans.size());
if (examPlans.size() > 0) {
for (ExamPlanInfo examPlanInfo : examPlans) {
String beginTime = examPlanInfo.getBeginTime();
int examPaperTime = examPlanInfo.getExamPaper().getExamPaperTime();
/** 验证是否可移除 */
if (validateExamPaerBeOverdue(beginTime, examPaperTime)) {
logger.info("待考试卷 " + examPlanInfo.getExamPaper().getExamPaperId() + " 已经过期,即将移除");
// 移除过期考试安排
int row = examPlanInfoService.isRemoveExamPlan(examPlanInfo.getExamPlanId());
} else {
/**
*
* <p>
* Title: ExamHistoryInfoHandler
* </p>
* <p>
* Description:
* </p>
*/
@Controller
public class ExamHistoryInfoHandler {
@Autowired
private ExamHistoryPaperService examHistoryPaperService;
private Logger logger = Logger.getLogger(ExamHistoryInfoHandler.class);
@RequestMapping("/historys")
public ModelAndView examHistorys() {
List<ExamHistoryInfo> historys = examHistoryPaperService.getExamHistoryToTeacher();
ModelAndView model = new ModelAndView("admin/examHistorys");
logger.info("教师 查询历史考试信息 SIZE " + historys.size());
model.addObject("historys", historys);
return model;
}
/**
* 查询个人成绩
* @param modelAndView
* @return
*/
@RequestMapping("/findMyScore")
public ModelAndView findMyScore(ModelAndView modelAndView, HttpServletRequest request){
StudentInfo studentInfo = (StudentInfo) request.getSession().getAttribute("loginStudent");
if (studentInfo==null) {
modelAndView.setViewName("error");
modelAndView.addObject("error","会话失效或还未登录,请登录!");
return modelAndView;
}
List<ExamHistoryInfo> myScore = examHistoryPaperService.findMyScore(studentInfo.getStudentId());
/**
*
* <p>
* Title: ExamSubjectMiddleInfoHandler
* </p>
* <p>
* Description: 试卷试题--关联
* </p>
*/
@Controller
@Scope("prototype")
@SuppressWarnings("all")
public class ExamSubjectMiddleInfoHandler {
@Autowired
private ExamSubjectMiddleInfoService esmService;
@Autowired
private ExamPaperInfoService examPaperInfoService;
@Autowired
private SubjectInfoService subjectInfoService;
@Autowired
private ExamSubjectMiddleInfo esm;
@Autowired
private ExamPaperInfo examPaper;
@Autowired
private SubjectInfo subject;
@Autowired
private CourseInfo course;
@Autowired
private GradeInfo grade;
@Autowired
private Gson gson;
}
package com.yuanlrc.online.exam.controller;
/**
*
* <p>
* Title: ExamChooseInfoHandler
* </p>
* <p>
* Description: 试卷试题答案选择
* </p>
*/
@Controller
public class ExamChooseInfoHandler {
@Autowired
private ExamChooseInfoService examChooseInfoService;
@Autowired
private ExamChooseInfo examChoose;
private Logger logger = Logger.getLogger(ExamChooseInfoHandler.class);
/**
* 记录考生考试选择答案
*
* @param studentId
* 考生编号
* @param examPaperId
* 考试试卷编号
* @param subjectId
ModelAndView model = new ModelAndView();
model.setViewName("/admin/student/students");
//查询条件处理
StudentInfo student = new StudentInfo();
if (studentId != null)
student.setStudentId(studentId);
if (classId != null) {
classInfo.setClassId(classId);
student.setClassInfo(classInfo);
}
if (gradeId != null) {
grade.setGradeId(gradeId);
student.setGrade(grade);
}
Map<String, Object> map = new HashMap<String, Object>();
//计算当前查询起始数据索引
int startIndex = (startPage-1) * pageShow;
map.put("student", student);
map.put("startIndex", startIndex);
map.put("pageShow", pageShow);
List<StudentInfo> students = studentInfoService.getStudents(map);
model.addObject("students", students);
//获取学生总量
int studentTotal = studentInfoService.getStudentTotal();
//计算总页数
int pageTotal = 1;
if (studentTotal % pageShow == 0)
pageTotal = studentTotal / pageShow;
else
pageTotal = studentTotal / pageShow + 1;
model.addObject("pageTotal", pageTotal);
model.addObject("pageNow", startPage);
return model;
}
/**
* 根据编号获取学生信息
* @param studentId
* @return
* <p>
* Title: ExamChooseInfoHandler
* </p>
* <p>
* Description: 试卷试题答案选择
* </p>
*/
@Controller
public class ExamChooseInfoHandler {
@Autowired
private ExamChooseInfoService examChooseInfoService;
@Autowired
private ExamChooseInfo examChoose;
private Logger logger = Logger.getLogger(ExamChooseInfoHandler.class);
/**
* 记录考生考试选择答案
*
* @param studentId
* 考生编号
* @param examPaperId
* 考试试卷编号
* @param subjectId
* 当前选择试题编号
* @param index
* 前台控制索引
* @param chooseAswer
* 选择答案
* @param response
* @throws IOException
*/
@RequestMapping(value = "/choose", method = RequestMethod.POST)
public void examChooseHandler(@RequestParam("studentId") Integer studentId,
@RequestParam("examPaperId") Integer examPaperId, @RequestParam("subjectId") Integer subjectId,
@RequestParam(value = "index", required = false) Integer index,
@RequestParam("chooseAswer") String chooseAswer, HttpServletResponse response) throws IOException {
logger.info("考生 " + studentId + " 在试卷 " + examPaperId + " 中试题 " + subjectId + " 选择了答案 " + chooseAswer + " 序号 "
+ index);
// 判断该考生是否已经选择过该试题
Map<String, Object> map = new HashMap<String, Object>();
map.put("studentId", studentId);
map.put("examPaperId", examPaperId);
if (isUpdate != null) {
int row = courseInfoService.isUpdateCourse(course);
}
// 添加
else {
int row = courseInfoService.isAddCourse(course);
}
return "redirect:/courses";
}
/**
* 删除科目
*
* @param courseId
* 待删除科目编号
* @return
*/
@RequestMapping(value = "/course/{courseId}", method = RequestMethod.DELETE)
public String isDelTeacher(@PathVariable("courseId") Integer courseId) {
int row = courseInfoService.isDelCourse(courseId);
return "redirect:/courses";
}
/**
* 预添加科目信息
*
* @return
*/
@RequestMapping("/preAddCourse")
public ModelAndView preAddCourse() {
ModelAndView model = new ModelAndView();
model.setViewName("/admin/course/courseedit");
/** 获取系部集合 */
List<GradeInfo> grades = gradeInfoService.getGrades();
model.addObject("grades", grades);
return model;
}
}
package com.yuanlrc.online.exam.controller;
private ExamChooseInfo examChoose;
private Logger logger = Logger.getLogger(ExamChooseInfoHandler.class);
/**
* 记录考生考试选择答案
*
* @param studentId
* 考生编号
* @param examPaperId
* 考试试卷编号
* @param subjectId
* 当前选择试题编号
* @param index
* 前台控制索引
* @param chooseAswer
* 选择答案
* @param response
* @throws IOException
*/
@RequestMapping(value = "/choose", method = RequestMethod.POST)
public void examChooseHandler(@RequestParam("studentId") Integer studentId,
@RequestParam("examPaperId") Integer examPaperId, @RequestParam("subjectId") Integer subjectId,
@RequestParam(value = "index", required = false) Integer index,
@RequestParam("chooseAswer") String chooseAswer, HttpServletResponse response) throws IOException {
logger.info("考生 " + studentId + " 在试卷 " + examPaperId + " 中试题 " + subjectId + " 选择了答案 " + chooseAswer + " 序号 "
+ index);
// 判断该考生是否已经选择过该试题
Map<String, Object> map = new HashMap<String, Object>();
map.put("studentId", studentId);
map.put("examPaperId", examPaperId);
map.put("subjectId", subjectId);
examChoose = examChooseInfoService.getChooseWithIds(map);
logger.info("考生是否选择过试题 " + subjectId + " " + examChoose + " (NULL-否)");
if (examChoose == null) {
logger.info("考生 " + studentId + " 尚未选择试题 " + subjectId + " 添加选择记录 答案 " + chooseAswer);
map.put("chooseResult", chooseAswer);
/** 添加选择记录 */
examChooseInfoService.addChoose(map);
} else if (examChoose.getChooseId() != null && examChoose != null) {
logger.info("考生 " + studentId + " 已经选择试题 " + subjectId + " 修改选择记录 答案 " + examChoose.getChooseResult()
+ " 更新为 " + chooseAswer);
/*
* 如果选择了和上次相同的答案,则不做修改操作 优化 -- 前台判断选择了相同答案则不发出请求
*/
if (!chooseAswer.equals(examChoose.getChooseResult())) {
examChoose.setChooseResult(chooseAswer);
/** 当前选择答案和之前选择答案不同 修改答案记录 */
examChooseInfoService.updateChooseWithIds(examChoose);
} else {
* Description:
* </p>
*/
@Controller
public class ExamHistoryInfoHandler {
@Autowired
private ExamHistoryPaperService examHistoryPaperService;
private Logger logger = Logger.getLogger(ExamHistoryInfoHandler.class);
@RequestMapping("/historys")
public ModelAndView examHistorys() {
List<ExamHistoryInfo> historys = examHistoryPaperService.getExamHistoryToTeacher();
ModelAndView model = new ModelAndView("admin/examHistorys");
logger.info("教师 查询历史考试信息 SIZE " + historys.size());
model.addObject("historys", historys);
return model;
}
/**
* 查询个人成绩
* @param modelAndView
* @return
*/
@RequestMapping("/findMyScore")
public ModelAndView findMyScore(ModelAndView modelAndView, HttpServletRequest request){
StudentInfo studentInfo = (StudentInfo) request.getSession().getAttribute("loginStudent");
if (studentInfo==null) {
modelAndView.setViewName("error");
modelAndView.addObject("error","会话失效或还未登录,请登录!");
return modelAndView;
}
List<ExamHistoryInfo> myScore = examHistoryPaperService.findMyScore(studentInfo.getStudentId());
modelAndView.setViewName("reception/news");
modelAndView.addObject("scoreList",myScore);
return modelAndView;
}
}
package com.yuanlrc.online.exam.controller;
}
/**
* 修改系部信息
*
* @param grade
* @param request
* @return
*/
@RequestMapping(value = "/grade/update/grade", method = RequestMethod.PUT)
public String isUpdateGrade(GradeInfo grade, HttpServletRequest request) {
if(grade==null){
request.setAttribute("error","请填写正确的系部信息");
return "/error";
}
GradeInfo byName = gradeInfoService.findByName(grade.getGradeName());
if(byName!=null){
Integer gradeId = byName.getGradeId();
if(!gradeId.equals(grade.getGradeId())){
request.setAttribute("error","该系部名称已存在!");
return "/error";
}
}
int row = gradeInfoService.isUpdateGrade(grade);
if (row < 1) {
logger.error("系部修改失败");
request.setAttribute("error", "系部修改失败,请稍后再试!");
return "/error";
}
return "redirect:/grades";
}
/**
* 删除系部
*
* @param gradeId
* @param request
* @return
*/
@RequestMapping(value = "grade/del/{gradeId}", method = RequestMethod.DELETE)
public String isDelGrade(@PathVariable("gradeId") Integer gradeId, HttpServletRequest request) {
logger.info("删除系部 " + gradeId);
int row = gradeInfoService.isDelGrade(gradeId);
if (row < 1) {
logger.error("系部删除失败");
if (courseId != null)
course.setCourseId(courseId);
if (gradeId != null)
grade.setGradeId(gradeId);
subject.setCourse(course);
subject.setGrade(grade);
esm.setExamPaper(examPaper);
esm.setSubject(subject);
logger.info("查询试卷试题信息 With " + esm);
List<ExamSubjectMiddleInfo> esms = esmService.getExamPaperWithSubject(esm);
response.getWriter().print(gson.toJson(esms));
}
/**
* 手动添加试题 手动将选择的试题添加到指定试卷中 -- 正式添加处理
*
* @param examPaperId
* 试卷编号
* @param session
* @param response
* @throws Exception
*/
@RequestMapping(value = "/handAdd", method = { RequestMethod.GET, RequestMethod.POST })
public void isHandAddSubjectToExamPaper(@RequestParam(value = "examPaperId") Integer examPaperId,
HttpSession session, HttpServletResponse response) throws Exception {
// 添加试题总分统计
int scoreSum = 0;
// 添加试题总量统计
int subjectSum = 0;
Map<String, Object> map = new HashMap<String, Object>();
map.put("examPaperId", examPaperId);
ArrayList<Integer> subjectIds = new ArrayList<Integer>();
// 试题信息
List<String> ids = (List<String>) session.getAttribute("ids");
if (ids != null) {
for (String is : ids) {
// 分割试题编号和分数
String[] idAndScore = is.split(",");
subjectIds.add(Integer.parseInt(idAndScore[0]));
examPaper.setDivision(division);
int row = examPaperInfoService.isAddExamPaper(examPaper);
logger.info("添加的新试卷 编号 " + examPaper.getExamPaperId());
dispatcherExamPaperAndSubject(subjects, examPaper.getExamPaperId());
}
if (subjects.size() == 0) {
model.addObject("success",
"操作处理失败,共添加 <b style='color:red;'>" + subjects.size() + "</b> 道题, 请检查上传数据正确性!");
} else {
model.addObject("success", "操作处理成功,共添加 " + subjects.size() + " 道题");
}
} catch (Exception e) {
e.printStackTrace();
model.setViewName("error");
model.addObject("error", "上传失败, 请检查上传数据合理性或联系管理员!");
} finally {
/** 删除上传文件 */
deleteUploadFile(savePath);
}
return model;
}
/**
* 保存上传 excel 文件
*
* @param file
* 上传文件
* @return 保存路径
*/
private String saveUploadFile(MultipartFile file, String rootPath) {
String fileName = file.getOriginalFilename();
logger.info("保存上传文件 " + fileName + " 到 " + rootPath);
try {
file.transferTo(new File(rootPath + "/" + fileName));
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
response.getWriter().print(StudentExamInfoCharts.createStudentExamLineJson(stuExamInfos));
}
}
package com.yuanlrc.online.exam.controller;
/**
*
* <p>
* Title: ExamChooseInfoHandler
* </p>
* <p>
* Description: 试卷试题答案选择
* </p>
*/
@Controller
public class ExamChooseInfoHandler {
@Autowired
private ExamChooseInfoService examChooseInfoService;
@Autowired
private ExamChooseInfo examChoose;
private Logger logger = Logger.getLogger(ExamChooseInfoHandler.class);
/**
* 记录考生考试选择答案
*
* @param studentId
* 考生编号
* @param examPaperId
* 考试试卷编号
* @param subjectId
* 当前选择试题编号
/**
*
* <p>
* Title: ExamPlanInfoHandler
* </p>
* <p>
* Description: 考试安排
* </p>
*/
@Controller
@SuppressWarnings("all")
public class ExamPlanInfoHandler {
@Autowired
private ExamPlanInfoService examPlanInfoService;
@Autowired
private ClassInfoService classInfoService;
@Autowired
private CourseInfoService courseInfoService;
@Autowired
private ExamPaperInfoService examPaperInfoService;
@Autowired
private ExamPaperInfo examPaper;
@Autowired
private GradeInfo grade;
private Logger logger = Logger.getLogger(ExamPlanInfoHandler.class);
/**
* 获取所有待考记录
*
* @return
*/
@RequestMapping("/examPlans")
public ModelAndView getExamPlans() {
ModelAndView model = new ModelAndView();
/**
* 修改系部信息
*
* @param grade
* @param request
* @return
*/
@RequestMapping(value = "/grade/update/grade", method = RequestMethod.PUT)
public String isUpdateGrade(GradeInfo grade, HttpServletRequest request) {
if(grade==null){
request.setAttribute("error","请填写正确的系部信息");
return "/error";
}
GradeInfo byName = gradeInfoService.findByName(grade.getGradeName());
if(byName!=null){
Integer gradeId = byName.getGradeId();
if(!gradeId.equals(grade.getGradeId())){
request.setAttribute("error","该系部名称已存在!");
return "/error";
}
}
int row = gradeInfoService.isUpdateGrade(grade);
if (row < 1) {
logger.error("系部修改失败");
request.setAttribute("error", "系部修改失败,请稍后再试!");
return "/error";
}
return "redirect:/grades";
}
/**
* 删除系部
*
* @param gradeId
* @param request
* @return
*/
@RequestMapping(value = "grade/del/{gradeId}", method = RequestMethod.DELETE)
public String isDelGrade(@PathVariable("gradeId") Integer gradeId, HttpServletRequest request) {
logger.info("删除系部 " + gradeId);
int row = gradeInfoService.isDelGrade(gradeId);
if (row < 1) {
logger.error("系部删除失败");
* @param subjectNum
* 试卷试题数量
* @param examPaperScore
* 试卷总分
* @param examPaperTime
* 试卷规定考试时间
* @param division
* 分科情况
* @param examPaperEasy
* 难易程度
* @param gradeId
* 系部编号
* @return
*/
@RequestMapping(value = "/examPaper/examPaper", method = RequestMethod.POST)
public String isUpdateOrAddCourse(@RequestParam(value = "examPaperId", required = false) Integer examPaperId,
@RequestParam(value = "isupdate", required = false) Integer isUpdate,
@RequestParam(value = "examPaperName", required = false) String examPaperName,
@RequestParam("subjectNum") Integer subjectNum, @RequestParam("examPaperScore") Integer examPaperScore,
@RequestParam("examPaperTime") Integer examPaperTime, @RequestParam("division") Integer division,
@RequestParam("examPaperEasy") Integer examPaperEasy, @RequestParam("gradeId") Integer gradeId) {
examPaper.setExamPaperId(examPaperId);
examPaper.setExamPaperName(examPaperName);
examPaper.setSubjectNum(subjectNum);
examPaper.setExamPaperScore(examPaperScore);
examPaper.setExamPaperTime(examPaperTime);
examPaper.setDivision(division);
examPaper.setExamPaperEasy(examPaperEasy);
grade.setGradeId(gradeId);
examPaper.setGrade(grade);
if (isUpdate != null) {
logger.info("修改试卷 " + examPaper + " 的信息");
int row = examPaperInfoService.isUpdateExamPaper(examPaper);
} else {
logger.info("添加试卷 " + examPaper + " 的信息");
int row = examPaperInfoService.isAddExamPaper(examPaper);
}
return "redirect:/examPapers";
}
/**
* 删除试卷
*
* @param examPaperId
* 待删除试卷编号
* @return
*/
@RequestMapping(value = "/examPaper/{examPaperId}", method = RequestMethod.DELETE)
public String isDelTeacher(@PathVariable("examPaperId") Integer examPaperId, Model model) {
logger.info("删除试卷 " + examPaperId);