Commit 6de2192e5b03fe32e57e7227b3d57ef35d052051
1 parent
1102ee1e
答案统计
Showing
4 changed files
with
61 additions
and
42 deletions
resources/mybatis1/sunvote/HomeworkProblemMapper.xml
... | ... | @@ -94,6 +94,16 @@ |
94 | 94 | HOMEWORKPROBLEM_ID = #{HOMEWORKPROBLEM_ID} |
95 | 95 | </select> |
96 | 96 | |
97 | + <select id="findByCodeAndRank" parameterType="pd" resultType="pd"> | |
98 | + select | |
99 | + <include refid="Field"></include> | |
100 | + from | |
101 | + <include refid="tableName"></include> | |
102 | + where | |
103 | + CODE = #{CODE}, | |
104 | + and RANK = #{RANK} | |
105 | + </select> | |
106 | + | |
97 | 107 | <!-- 列表 --> |
98 | 108 | <select id="datalistPage" parameterType="page" resultType="pd"> |
99 | 109 | select | ... | ... |
src/com/fh/controller/sunvote/homework/HomeworkController.java
... | ... | @@ -44,7 +44,8 @@ import com.fh.util.StringUtil; |
44 | 44 | import com.google.gson.Gson; |
45 | 45 | |
46 | 46 | /** |
47 | - * 说明:作业 创建人:FH Q313596790 创建时间:2019-03-07 | |
47 | + * 说明:作业 创建人:FH Q313596790 | |
48 | + * 创建时间:2019-03-07 | |
48 | 49 | */ |
49 | 50 | @Controller |
50 | 51 | @RequestMapping(value = "/homework") |
... | ... | @@ -406,53 +407,47 @@ public class HomeworkController extends BaseController { |
406 | 407 | String index = pageData.getString("INDEX"); |
407 | 408 | int indexint = Integer.parseInt(index); |
408 | 409 | List<PageData> data = homeworkReporkService.findNoAnswerByHomeworkID(pageData); |
409 | - List<PageData> result = new ArrayList(); | |
410 | - PageData aresult = new PageData(); | |
411 | - aresult.put("ANSWER", "A"); | |
412 | - PageData bresult = new PageData(); | |
413 | - bresult.put("ANSWER", "B"); | |
414 | - PageData cresult = new PageData(); | |
415 | - cresult.put("ANSWER", "C"); | |
416 | - PageData dresult = new PageData(); | |
417 | - dresult.put("ANSWER", "D"); | |
418 | - PageData eresult = new PageData(); | |
419 | - eresult.put("ANSWER", ""); | |
420 | - result.add(aresult); | |
421 | - result.add(bresult); | |
422 | - result.add(cresult); | |
423 | - result.add(dresult); | |
424 | - result.add(eresult); | |
425 | - for(PageData pd : data){ | |
426 | - String answer = pd.getString("ANSWER"); | |
427 | - if(!StringUtils.isEmpty(answer)){ | |
428 | - String[] answers = answer.split(";"); | |
429 | - if(answers.length >= indexint -1){ | |
430 | - String ans = answers[indexint - 1]; | |
431 | - String[] anss = ans.split(","); | |
432 | - if(anss != null && anss.length == 2){ | |
433 | - PageData tresult = null; | |
434 | - for(PageData ptd : result){ | |
435 | - if(anss[0].toUpperCase().equals(anss[0].toUpperCase())){ | |
436 | - tresult = ptd; | |
410 | + pageData = homeworkService.findById(pageData); | |
411 | + pageData.put("RANK", indexint); | |
412 | + pageData = homeworkproblemService.findByCodeAndRank(pageData); | |
413 | + pageData.remove("HOMEWORKPROBLEM_ID"); | |
414 | + pageData.remove("HOMEWORK_ID"); | |
415 | + pageData.remove("CODE"); | |
416 | + pageData.remove("RANK"); | |
417 | + pageData.remove("NAME"); | |
418 | + pageData.remove("TYPE"); | |
419 | + String optionNumStr = pageData.getString("OPTION_NUM"); | |
420 | + String rightAnswer = pageData.getString("RIGHT_ANSWER"); | |
421 | + rightAnswer = rightAnswer.toUpperCase(); | |
422 | + int optionNum = Integer.parseInt(optionNumStr); | |
423 | + | |
424 | + List<List<String>> resultData = new ArrayList(); | |
425 | + for (int i = 0; i < optionNum; i++) { | |
426 | + List<String> optionAnswer = new ArrayList(); | |
427 | + resultData.add(optionAnswer); | |
428 | + for (PageData pd : data) { | |
429 | + String answer = pd.getString("ANSWER"); | |
430 | + if (!StringUtils.isEmpty(answer)) { | |
431 | + String[] answers = answer.split(";"); | |
432 | + if (answers.length >= indexint - 1) { | |
433 | + String ans = answers[indexint - 1]; | |
434 | + String[] anss = ans.split(","); | |
435 | + if (anss != null && anss.length == 2) { | |
436 | + char option = (char)('A' + i) ; | |
437 | + if(anss[0] != null){ | |
438 | + if(anss[0].contains("" + option)){ | |
439 | + optionAnswer.add(pd.getString("STUDENT_NAME")); | |
440 | + } | |
437 | 441 | } |
438 | 442 | } |
439 | - if(tresult == null){ | |
440 | - tresult = new PageData(); | |
441 | - result.add(tresult); | |
442 | - } | |
443 | - List<String> list = (List)tresult.get("STUDENTS"); | |
444 | - if(list == null){ | |
445 | - list = new ArrayList(); | |
446 | - } | |
447 | - list.add(pd.getString("STUDENT_NAME")); | |
448 | - tresult.put("ANSWER", anss[0].toUpperCase()); | |
449 | - tresult.put("STUDENTS", list); | |
450 | - tresult.put("RIGHT", !"0".equals(anss[1])); | |
451 | 443 | } |
452 | 444 | } |
453 | 445 | } |
454 | 446 | } |
455 | - return new Gson().toJson(result); | |
447 | + Map<String,Object> map = new HashMap(); | |
448 | + map.put("ANSWER", rightAnswer); | |
449 | + map.put("DATA", resultData); | |
450 | + return new Gson().toJson(map); | |
456 | 451 | |
457 | 452 | } |
458 | 453 | ... | ... |
src/com/fh/service/sunvote/homeworkproblem/HomeworkProblemManager.java
... | ... | @@ -64,6 +64,12 @@ public interface HomeworkProblemManager{ |
64 | 64 | */ |
65 | 65 | public PageData findById(PageData pd)throws Exception; |
66 | 66 | |
67 | + /**通过id获取数据 | |
68 | + * @param pd | |
69 | + * @throws Exception | |
70 | + */ | |
71 | + public PageData findByCodeAndRank(PageData pd)throws Exception; | |
72 | + | |
67 | 73 | /**批量删除 |
68 | 74 | * @param ArrayDATA_IDS |
69 | 75 | * @throws Exception | ... | ... |
src/com/fh/service/sunvote/homeworkproblem/impl/HomeworkProblemService.java
... | ... | @@ -90,6 +90,14 @@ public class HomeworkProblemService implements HomeworkProblemManager{ |
90 | 90 | return (PageData)dao.findForObject("HomeworkProblemMapper.findById", pd); |
91 | 91 | } |
92 | 92 | |
93 | + /**通过id获取数据 | |
94 | + * @param pd | |
95 | + * @throws Exception | |
96 | + */ | |
97 | + public PageData findByCodeAndRank(PageData pd)throws Exception{ | |
98 | + return (PageData)dao.findForObject("HomeworkProblemMapper.findByCodeAndRank", pd); | |
99 | + } | |
100 | + | |
93 | 101 | /**批量删除 |
94 | 102 | * @param ArrayDATA_IDS |
95 | 103 | * @throws Exception | ... | ... |