|
@@ -1,470 +0,0 @@
|
|
|
-package edu.math.diagnosis.controller;
|
|
|
-
|
|
|
-import edu.math.diagnosis.cache.DbCacheFactory;
|
|
|
-import edu.math.diagnosis.cache.instance.OptionCache;
|
|
|
-import edu.math.diagnosis.cache.instance.QuestionCache;
|
|
|
-//import edu.math.diagnosis.dao.CommitRepo;
|
|
|
-import edu.math.diagnosis.dao.UserRepo;
|
|
|
-import edu.math.diagnosis.entity.*;
|
|
|
-import edu.math.diagnosis.model.AuthUser;
|
|
|
-import edu.math.diagnosis.model.ResponseMessage;
|
|
|
-import edu.math.diagnosis.util.NumberUtil;
|
|
|
-import edu.math.diagnosis.util.ObjectUtil;
|
|
|
-import edu.math.diagnosis.util.SecurityUtil;
|
|
|
-import io.swagger.annotations.Api;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
-
|
|
|
-import javax.annotation.Resource;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
-/**
|
|
|
- * @AUTHOR: DaiFengWen
|
|
|
- * @DATE: Create in 2018/7/6 17:55
|
|
|
- * @DESCRIPTION:
|
|
|
- */
|
|
|
-@Api(tags = "试卷提交 马上废弃")
|
|
|
-@RestController
|
|
|
-@RequestMapping("/commit")
|
|
|
-public class CommitController {
|
|
|
-// @Resource
|
|
|
-// CommitRepo commitRepo;
|
|
|
- @Resource
|
|
|
- UserRepo userRepo;
|
|
|
-
|
|
|
- private final OptionCache OptionCache = DbCacheFactory.INSTANCE.getCache(OptionCache.class);
|
|
|
- private final QuestionCache QuestionCache = DbCacheFactory.INSTANCE.getCache(QuestionCache.class);
|
|
|
-
|
|
|
-// @RequestMapping(value = "/paper", method = RequestMethod.POST)
|
|
|
-// public ResponseMessage commitPaper(@RequestBody Paper paper) {
|
|
|
-// AuthUser authUser = SecurityUtil.getCurrentUser();
|
|
|
-// Commit commit = new Commit();
|
|
|
-// paper.getQuestions().forEach((question -> {
|
|
|
-// question.setOptions(null);
|
|
|
-// question.setUpdatetime(null);
|
|
|
-// question.setCreatetime(null);
|
|
|
-// question.setContent(null);
|
|
|
-// question.setWrongDesc(null);
|
|
|
-// }));
|
|
|
-// paper.setCreatetime(null);
|
|
|
-// paper.setUpdatetime(null);
|
|
|
-// String data = ObjectUtil.object2Json(paper);
|
|
|
-// commit.setData(data);
|
|
|
-// long uid = authUser.getUser().getId();
|
|
|
-// long pid = paper.getId();
|
|
|
-// commit.setUid(uid);
|
|
|
-// commit.setPid(pid);
|
|
|
-// double point = calculatePoint(paper);
|
|
|
-// commit.setScore(point);
|
|
|
-// commit.setCreatetime(new Date());
|
|
|
-// commitRepo.saveAndFlush(commit);
|
|
|
-// return ResponseMessage.getInstance(200, NumberUtil.formatDouble(point));
|
|
|
-// }
|
|
|
-
|
|
|
- private double calculatePoint(Paper paper) {
|
|
|
- double result = 0.0;
|
|
|
- List<Question> questions = paper.getQuestions();
|
|
|
- double total = 0;
|
|
|
- for (Question question : questions) {
|
|
|
- double score = (question.getCalculation() + question.getConversion() + question.getInduction() + question.getLanguage() + question.getLogic() + question.getSpace());
|
|
|
- total += score;
|
|
|
- if (judgeQuestion(question)) {
|
|
|
- result += score;
|
|
|
- }
|
|
|
- }
|
|
|
- if (total == 0) {
|
|
|
- return 0;
|
|
|
- } else {
|
|
|
- return (result / total) * 100;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private boolean judgeQuestion(Question question) {
|
|
|
- String ans = question.getAnswer();
|
|
|
- if (StringUtils.isEmpty(ans)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- String[] options = StringUtils.splitByWholeSeparatorPreserveAllTokens(ans, ",");
|
|
|
- if (options.length == question.getCorrectNum()) {
|
|
|
- for (String option : options) {
|
|
|
- long o = Long.parseLong(option);
|
|
|
- QuestionOption questionOption = OptionCache.getById(o);
|
|
|
- if (questionOption == null || !questionOption.isCorrect()) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
- return true;
|
|
|
- } else {
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @RequestMapping(value = "/check", method = RequestMethod.GET)
|
|
|
- public boolean checkPaper(@RequestParam long pid) {
|
|
|
- AuthUser authUser = SecurityUtil.getCurrentUser();
|
|
|
- long uid = authUser.getUser().getId();
|
|
|
-// int cnt = commitRepo.countByUidAndPid(uid, pid);
|
|
|
- int cnt=0;
|
|
|
- return cnt < 1;
|
|
|
- }
|
|
|
-
|
|
|
- public PaperReport generateReport(Paper paper, long uid) {
|
|
|
- UserInfo userInfo = userRepo.getOne(uid);
|
|
|
- PaperReport paperReport = new PaperReport();
|
|
|
- paperReport.setName(userInfo.getName());
|
|
|
- paperReport.setUid(uid);
|
|
|
- paperReport.setPid(paper.getId());
|
|
|
- paperReport.setPaperName(paper.getName());
|
|
|
- paperReport.setGenerateTime(new Date());
|
|
|
- Map<Integer, SectionReport> sectionReportMap = new HashMap<>(4);
|
|
|
- sectionReportMap.put(1, new SectionReport(1));
|
|
|
- sectionReportMap.put(2, new SectionReport(2));
|
|
|
- sectionReportMap.put(3, new SectionReport(3));
|
|
|
- paperReport.setSectionReportMap(sectionReportMap);
|
|
|
- List<Question> questions = paper.getQuestions();
|
|
|
- double total = 0;
|
|
|
- double result = 0.0;
|
|
|
- for (Question question : questions) {
|
|
|
- int section = Math.abs(question.getSection());
|
|
|
- SectionReport sectionReport = sectionReportMap.get(section);
|
|
|
- double score = (question.getCalculation() + question.getConversion() + question.getInduction() + question.getLanguage() + question.getLogic() + question.getSpace());
|
|
|
- fillReportTotalScore(question, paperReport);
|
|
|
- fillReportTotalScore(question, sectionReport);
|
|
|
- total += score;
|
|
|
- double sectionTotalScore = sectionReport.getTotalScore();
|
|
|
- sectionReport.setTotalScore(sectionTotalScore + score);
|
|
|
- QuestionCommit questionCommit = new QuestionCommit();
|
|
|
- questionCommit.setAns(question.getAnswer());
|
|
|
- questionCommit.setQid(question.getId());
|
|
|
- questionCommit.setUsetime(question.getUsetime());
|
|
|
- questionCommit.setCorrect(false);
|
|
|
- sectionReport.getMap().put(question.getId(), questionCommit);
|
|
|
- if (judgeQuestion(question)) {
|
|
|
- questionCommit.setCorrect(true);
|
|
|
- result += score;
|
|
|
- double setionScore = sectionReport.getScore();
|
|
|
- sectionReport.setScore(setionScore + score);
|
|
|
- fillReportScore(question, paperReport);
|
|
|
- fillReportScore(question, sectionReport);
|
|
|
- }
|
|
|
- }
|
|
|
- paperReport.setTotalScore(total);
|
|
|
- paperReport.setScore(result);
|
|
|
- return paperReport;
|
|
|
- }
|
|
|
-
|
|
|
- private double getDoubleValue(Double d) {
|
|
|
- if (d == null) {
|
|
|
- return 0;
|
|
|
- } else {
|
|
|
- return d;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void fillReportTotalScore(Question question, BaseReport report) {
|
|
|
- double totalCalculationScore = getDoubleValue(report.getTotalCalculationScore());
|
|
|
- report.setTotalCalculationScore(totalCalculationScore + question.getCalculation());
|
|
|
-
|
|
|
- double totalConversionScore = getDoubleValue(report.getTotalConversionScore());
|
|
|
- report.setTotalConversionScore(totalConversionScore + question.getConversion());
|
|
|
-
|
|
|
- double totalInductionScore = getDoubleValue(report.getTotalInductionScore());
|
|
|
- report.setTotalInductionScore(totalInductionScore + question.getInduction());
|
|
|
-
|
|
|
- double totalLanguageScore = getDoubleValue(report.getTotalLanguageScore());
|
|
|
- report.setTotalLanguageScore(totalLanguageScore + question.getLanguage());
|
|
|
-
|
|
|
- double totalLogicScore = getDoubleValue(report.getTotalLogicScore());
|
|
|
- report.setTotalLogicScore(totalLogicScore + question.getLogic());
|
|
|
-
|
|
|
- double totalSpaceScore = getDoubleValue(report.getTotalSpaceScore());
|
|
|
- report.setTotalSpaceScore(totalSpaceScore + question.getSpace());
|
|
|
- }
|
|
|
-
|
|
|
- private void fillReportScore(Question question, BaseReport report) {
|
|
|
- double calculationScore = getDoubleValue(report.getCalculationScore());
|
|
|
- report.setCalculationScore(calculationScore + question.getCalculation());
|
|
|
-
|
|
|
- double conversionScore = getDoubleValue(report.getConversionScore());
|
|
|
- report.setConversionScore(conversionScore + question.getConversion());
|
|
|
-
|
|
|
- double inductionScore = getDoubleValue(report.getInductionScore());
|
|
|
- report.setInductionScore(inductionScore + question.getInduction());
|
|
|
-
|
|
|
- double languageScore = getDoubleValue(report.getLanguageScore());
|
|
|
- report.setLanguageScore(languageScore + question.getLanguage());
|
|
|
-
|
|
|
- double logicScore = getDoubleValue(report.getLogicScore());
|
|
|
- report.setLogicScore(logicScore + question.getLogic());
|
|
|
-
|
|
|
- double spaceScore = getDoubleValue(report.getSpaceScore());
|
|
|
- report.setSpaceScore(spaceScore + question.getSpace());
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-class BaseReport {
|
|
|
- private Double totalScore = new Double(0);
|
|
|
- private Double score = new Double(0);
|
|
|
- private Double totalCalculationScore = new Double(0);
|
|
|
- private Double calculationScore = new Double(0);
|
|
|
- private Double totalInductionScore = new Double(0);
|
|
|
- private Double inductionScore = new Double(0);
|
|
|
- private Double totalLogicScore = new Double(0);
|
|
|
- private Double logicScore = new Double(0);
|
|
|
- private Double totalSpaceScore = new Double(0);
|
|
|
- private Double spaceScore = new Double(0);
|
|
|
- private Double totalLanguageScore = new Double(0);
|
|
|
- private Double languageScore = new Double(0);
|
|
|
- private Double totalConversionScore = new Double(0);
|
|
|
- private Double conversionScore = new Double(0);
|
|
|
-
|
|
|
- public Double getTotalScore() {
|
|
|
- return totalScore;
|
|
|
- }
|
|
|
-
|
|
|
- public void setTotalScore(Double totalScore) {
|
|
|
- this.totalScore = totalScore;
|
|
|
- }
|
|
|
-
|
|
|
- public Double getScore() {
|
|
|
- return score;
|
|
|
- }
|
|
|
-
|
|
|
- public void setScore(Double score) {
|
|
|
- this.score = score;
|
|
|
- }
|
|
|
-
|
|
|
- public Double getTotalCalculationScore() {
|
|
|
- return totalCalculationScore;
|
|
|
- }
|
|
|
-
|
|
|
- public void setTotalCalculationScore(Double totalCalculationScore) {
|
|
|
- this.totalCalculationScore = totalCalculationScore;
|
|
|
- }
|
|
|
-
|
|
|
- public Double getCalculationScore() {
|
|
|
- return calculationScore;
|
|
|
- }
|
|
|
-
|
|
|
- public void setCalculationScore(Double calculationScore) {
|
|
|
- this.calculationScore = calculationScore;
|
|
|
- }
|
|
|
-
|
|
|
- public Double getTotalInductionScore() {
|
|
|
- return totalInductionScore;
|
|
|
- }
|
|
|
-
|
|
|
- public void setTotalInductionScore(Double totalInductionScore) {
|
|
|
- this.totalInductionScore = totalInductionScore;
|
|
|
- }
|
|
|
-
|
|
|
- public Double getInductionScore() {
|
|
|
- return inductionScore;
|
|
|
- }
|
|
|
-
|
|
|
- public void setInductionScore(Double inductionScore) {
|
|
|
- this.inductionScore = inductionScore;
|
|
|
- }
|
|
|
-
|
|
|
- public Double getTotalLogicScore() {
|
|
|
- return totalLogicScore;
|
|
|
- }
|
|
|
-
|
|
|
- public void setTotalLogicScore(Double totalLogicScore) {
|
|
|
- this.totalLogicScore = totalLogicScore;
|
|
|
- }
|
|
|
-
|
|
|
- public Double getLogicScore() {
|
|
|
- return logicScore;
|
|
|
- }
|
|
|
-
|
|
|
- public void setLogicScore(Double logicScore) {
|
|
|
- this.logicScore = logicScore;
|
|
|
- }
|
|
|
-
|
|
|
- public Double getTotalSpaceScore() {
|
|
|
- return totalSpaceScore;
|
|
|
- }
|
|
|
-
|
|
|
- public void setTotalSpaceScore(Double totalSpaceScore) {
|
|
|
- this.totalSpaceScore = totalSpaceScore;
|
|
|
- }
|
|
|
-
|
|
|
- public Double getSpaceScore() {
|
|
|
- return spaceScore;
|
|
|
- }
|
|
|
-
|
|
|
- public void setSpaceScore(Double spaceScore) {
|
|
|
- this.spaceScore = spaceScore;
|
|
|
- }
|
|
|
-
|
|
|
- public Double getTotalLanguageScore() {
|
|
|
- return totalLanguageScore;
|
|
|
- }
|
|
|
-
|
|
|
- public void setTotalLanguageScore(Double totalLanguageScore) {
|
|
|
- this.totalLanguageScore = totalLanguageScore;
|
|
|
- }
|
|
|
-
|
|
|
- public Double getLanguageScore() {
|
|
|
- return languageScore;
|
|
|
- }
|
|
|
-
|
|
|
- public void setLanguageScore(Double languageScore) {
|
|
|
- this.languageScore = languageScore;
|
|
|
- }
|
|
|
-
|
|
|
- public Double getTotalConversionScore() {
|
|
|
- return totalConversionScore;
|
|
|
- }
|
|
|
-
|
|
|
- public void setTotalConversionScore(Double totalConversionScore) {
|
|
|
- this.totalConversionScore = totalConversionScore;
|
|
|
- }
|
|
|
-
|
|
|
- public Double getConversionScore() {
|
|
|
- return conversionScore;
|
|
|
- }
|
|
|
-
|
|
|
- public void setConversionScore(Double conversionScore) {
|
|
|
- this.conversionScore = conversionScore;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-class PaperReport extends BaseReport {
|
|
|
- private String name;
|
|
|
- private Long uid;
|
|
|
- private Long pid;
|
|
|
- private String paperName;
|
|
|
- private Date generateTime;
|
|
|
- private Map<Integer, SectionReport> sectionReportMap;
|
|
|
-
|
|
|
- public String getName() {
|
|
|
- return name;
|
|
|
- }
|
|
|
-
|
|
|
- public void setName(String name) {
|
|
|
- this.name = name;
|
|
|
- }
|
|
|
-
|
|
|
- public Long getUid() {
|
|
|
- return uid;
|
|
|
- }
|
|
|
-
|
|
|
- public void setUid(Long uid) {
|
|
|
- this.uid = uid;
|
|
|
- }
|
|
|
-
|
|
|
- public Long getPid() {
|
|
|
- return pid;
|
|
|
- }
|
|
|
-
|
|
|
- public void setPid(Long pid) {
|
|
|
- this.pid = pid;
|
|
|
- }
|
|
|
-
|
|
|
- public String getPaperName() {
|
|
|
- return paperName;
|
|
|
- }
|
|
|
-
|
|
|
- public void setPaperName(String paperName) {
|
|
|
- this.paperName = paperName;
|
|
|
- }
|
|
|
-
|
|
|
- public Date getGenerateTime() {
|
|
|
- return generateTime;
|
|
|
- }
|
|
|
-
|
|
|
- public void setGenerateTime(Date generateTime) {
|
|
|
- this.generateTime = generateTime;
|
|
|
- }
|
|
|
-
|
|
|
- public Map<Integer, SectionReport> getSectionReportMap() {
|
|
|
- return sectionReportMap;
|
|
|
- }
|
|
|
-
|
|
|
- public void setSectionReportMap(Map<Integer, SectionReport> sectionReportMap) {
|
|
|
- this.sectionReportMap = sectionReportMap;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-class SectionReport extends BaseReport {
|
|
|
- private int section;
|
|
|
-
|
|
|
- private Map<Long, QuestionCommit> map;
|
|
|
-
|
|
|
- public SectionReport(int section) {
|
|
|
- this.section = section;
|
|
|
- map = new HashMap<>();
|
|
|
- }
|
|
|
-
|
|
|
- public SectionReport() {
|
|
|
- }
|
|
|
-
|
|
|
- public int getSection() {
|
|
|
- return section;
|
|
|
- }
|
|
|
-
|
|
|
- public void setSection(int section) {
|
|
|
- this.section = section;
|
|
|
- }
|
|
|
-
|
|
|
- public Map<Long, QuestionCommit> getMap() {
|
|
|
- return map;
|
|
|
- }
|
|
|
-
|
|
|
- public void setMap(Map<Long, QuestionCommit> map) {
|
|
|
- this.map = map;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-class QuestionCommit {
|
|
|
- private long qid;
|
|
|
- private String ans;
|
|
|
- private int usetime;
|
|
|
- private String correctAns;
|
|
|
- private boolean correct;
|
|
|
-
|
|
|
- public long getQid() {
|
|
|
- return qid;
|
|
|
- }
|
|
|
-
|
|
|
- public void setQid(long qid) {
|
|
|
- this.qid = qid;
|
|
|
- }
|
|
|
-
|
|
|
- public String getAns() {
|
|
|
- return ans;
|
|
|
- }
|
|
|
-
|
|
|
- public void setAns(String ans) {
|
|
|
- this.ans = ans;
|
|
|
- }
|
|
|
-
|
|
|
- public int getUsetime() {
|
|
|
- return usetime;
|
|
|
- }
|
|
|
-
|
|
|
- public void setUsetime(int usetime) {
|
|
|
- this.usetime = usetime;
|
|
|
- }
|
|
|
-
|
|
|
- public String getCorrectAns() {
|
|
|
- return correctAns;
|
|
|
- }
|
|
|
-
|
|
|
- public void setCorrectAns(String correctAns) {
|
|
|
- this.correctAns = correctAns;
|
|
|
- }
|
|
|
-
|
|
|
- public boolean isCorrect() {
|
|
|
- return correct;
|
|
|
- }
|
|
|
-
|
|
|
- public void setCorrect(boolean correct) {
|
|
|
- this.correct = correct;
|
|
|
- }
|
|
|
-}
|