package it.com.action; import java.io.IOException; import java.io.PrintWriter; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Random; import it.com.bean.Shijuan; import it.com.service.TeacherService; import it.com.service.AnswerService; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import net.sf.json.JSONArray; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; @Controller public class AnswerAction { @Resource AnswerService as; @Resource TeacherService ts; //跳转到首页 int kongzhi=1; @RequestMapping("back_home.action") public ModelAndView back(HttpServletRequest request,HttpSession session){ return new ModelAndView("stu/main.jsp"); } int[] xx = new int[20]; // 根据知识点查找题目(开始答题) @RequestMapping("findquestion.action") public ModelAndView findquestion(HttpServletRequest request,HttpSession session){ listqj.clear(); kongzhi = 1; String knowledge=request.getParameter("knowledge"); String username = session.getAttribute("user").toString(); //获取日期 String dateNowStr = as.getDate(); session.setAttribute("datidate",dateNowStr); //插入试卷 as.insertShijuan(username,dateNowStr); //获取试卷id int shijuanid = as.selectShijuanid(username, dateNowStr); session.setAttribute("datishijuanid", shijuanid); int subjectid=Integer.parseInt(request.getParameter("subjectid")); List<Map> list=ts.findQuestionsByIdknow(knowledge, subjectid); List list1=new ArrayList(); int index=(int)(Math.random()*list.size()); for(int i=0;i<20;i++){ //控制随机数不重复,也就是说一份试卷不会获取相同的试题 for(int j=0;j<20;j++){ while(xx[j]==index){ index=(int)(Math.random()*list.size()); j=-1; break; } } xx[i] = index; //获取list里面随机一条数据 //将其保存在list中 list1.add(list.get(index)); } session.setAttribute("pageSize",ts.countPage()); session.setAttribute("list", list1); String n=request.getParameter("n"); if(n==null) n="1"; return new ModelAndView("stu/showq.jsp?n="+n); } List<Map> listqj = new ArrayList(); // 答题过程中保存所答题目 @RequestMapping("saveAns.action") public ModelAndView saveAns(HttpServletRequest request,HttpSession session){ int shijuanid = 0; int n=Integer.parseInt(request.getParameter("n")); n = n+1; int pageSize=Integer.parseInt(session.getAttribute("pageSize").toString()); shijuanid = Integer.parseInt(session.getAttribute("datishijuanid").toString()); String title = request.getParameter("title").toString(); int count=-1,questionid=0; questionid=Integer.parseInt(request.getParameter("qid")); String trueans = request.getParameter("trueans").toString(); String uri="",ans=""; ans=request.getParameter("ans"); String username = session.getAttribute("user").toString(); int judge = 0; if(trueans.equalsIgnoreCase(ans)){ judge = 1; }else{ judge = 0; } Map map = new HashMap(); map.put("title",title); map.put("username",username); map.put("questionid", questionid); map.put("stuanswer", ans); map.put("judge", judge); map.put("shijuanid", shijuanid); map.put("trueans", trueans); listqj.add(map); request.getSession().setAttribute("listqj",listqj); if(n<=20){ return new ModelAndView("stu/showq.jsp?n="+n); }else{ return new ModelAndView("submitAns.action"); } } // 提交试卷 @RequestMapping("submitAns.action") public ModelAndView submitAns(HttpServletRequest request,HttpSession session){ int pageSize=Integer.parseInt(session.getAttribute("pageSize").toString()); List<Map> list1 = new ArrayList(); String b=""; synchronized (b) { String username = session.getAttribute("user").toString(); for(Map m : listqj){ if(m.get("username").equals(username)){ list1.add(m); } } // System.out.println("list1==="+list1); } String a = " "; int judgeCount = 0; synchronized (a) { for(Map m:list1){ String username = session.getAttribute("user").toString(); if(m.get("username").equals(username)&&m.get("judge").equals(1)){ judgeCount = judgeCount+1; // System.out.println("judgeCount"+judgeCount); } } // System.out.println("judgeCount=="+judgeCount); String username = session.getAttribute("user").toString(); System.out.println("list1=="+list1); if(kongzhi == 1){ as.insertAnswer(list1); }else{ as.updateShijuan(list1); } System.out.println("insertAnswerlist1"+list1); String date = request.getParameter("datidate"); int shijuanid = Integer.parseInt(session.getAttribute("datishijuanid").toString()); System.out.println("insert+shijuanid=="+shijuanid); as.insertGrade(judgeCount, shijuanid); session.setAttribute("resultList", list1); session.setAttribute("judgeCount",judgeCount); System.out.println("listqj.size()===="+listqj.size()); return new ModelAndView("stu/showresult.jsp"); } } // 清除全局list @RequestMapping("clear.action") public ModelAndView clear(HttpSession session){ String username = session.getAttribute("user").toString(); for(Map m: listqj){ if(m.get("username").equals(2)){ listqj.remove(m); System.out.println("yes"); } } // System.out.println("clear==="+listqj); return new ModelAndView("back_home.action"); } // 查找所有成绩 @RequestMapping("selectAllGrade.action") public ModelAndView selectAllGrade(HttpSession session){ String username = session.getAttribute("user").toString(); List<Map> Gradelist = as.selectAllGrade(username); session.setAttribute("Gradelist", Gradelist); return new ModelAndView("stu/showAllGrade.jsp"); } //查看历史的某一份试卷 @RequestMapping("selectshijuan.action") public ModelAndView selectshijuan(HttpSession session,HttpServletRequest request){ String username = session.getAttribute("user").toString(); String date = request.getParameter("date"); System.out.println("user =date="+username+date); int shijuanid = as.selectShijuanid(username, date); System.out.println("shijuanid"+shijuanid); List<Map> listsj = as.selectAnswer(shijuanid); session.setAttribute("listsj", listsj); System.out.println("listsj="+listsj.size()); return new ModelAndView("stu/showsj.jsp"); } //删除某次试卷及答题答案 @RequestMapping("deleteshijuan.action") public ModelAndView deleteshijuan(HttpSession session,HttpServletRequest request){ String date=request.getParameter("date"); int shijuanid=Integer.parseInt(request.getParameter("id")); as.delsj(date, shijuanid); System.out.println("del_success"); return new ModelAndView("selectAllGrade.action"); } //重新答题 @RequestMapping("againAnwser.action") public ModelAndView againAnwser(HttpSession session,HttpServletRequest request){ listqj.clear(); System.out.println("clear=="+listqj); int n=1; String username = session.getAttribute("user").toString(); String date = request.getParameter("date"); int shijuanid = as.selectShijuanid(username, date); List<Map> againlist = as.selectAnswer(shijuanid); System.out.println("againlist=="+againlist.size()); session.setAttribute("list", againlist); session.setAttribute("datishijuanid", shijuanid); session.setAttribute("pageSize", againlist.size()); request.setAttribute("judgeCount",0); kongzhi = 0; return new ModelAndView("stu/showq.jsp?n="+n); } }
最近下载更多
2206371875 LV7
3月14日
hongdongdong LV14
2023年12月3日
lbsers LV5
2023年5月6日
15152729192 LV3
2023年2月20日
唐唐丶 LV34
2023年2月19日
赵宇豪 LV1
2022年12月8日
1532593037 LV8
2022年11月30日
云翳tel青 LV11
2022年11月19日
testuser1234567 LV24
2022年7月21日
mdz123456mao LV3
2022年6月19日