考试相关
This commit is contained in:
@@ -39,13 +39,12 @@ public class ClassExamController {
|
||||
public R importSubject(@RequestParam("file") MultipartFile file, @RequestParam("courseId") int courseId) {
|
||||
int num = 0;
|
||||
try (InputStream fis = file.getInputStream()) {
|
||||
List<ClassExamOption> optionList = new ArrayList<>();
|
||||
Long time = System.currentTimeMillis();
|
||||
//解析数据
|
||||
ExcelUtil example = new ExcelUtil();
|
||||
example.processOneSheet(fis);
|
||||
Long endtime = System.currentTimeMillis();
|
||||
LinkedHashMap<String, String> map = example.getRowContents();
|
||||
Iterator<Map.Entry<String, String>> it = map.entrySet().iterator();
|
||||
//处理数据
|
||||
int count = 0;
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<String, String> entry = it.next();
|
||||
@@ -54,20 +53,54 @@ public class ClassExamController {
|
||||
count = Integer.parseInt(rowNo);
|
||||
// System.out.println(pos + ";" + entry.getValue());
|
||||
}
|
||||
List<ClassExamOption> optionList = new ArrayList<>();
|
||||
//先校验数据
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i=2;i<=count;i++){
|
||||
//类型
|
||||
String type = map.containsKey("A"+i)?map.get("A"+i):"";
|
||||
if (type.contains("单选")||type.contains("多选")){
|
||||
}else {
|
||||
sb.append("第"+i+"行题目类型出错\n");
|
||||
}
|
||||
String option1 = map.containsKey("C"+i)?map.get("C"+i):"";
|
||||
if (StringUtils.isBlank(option1)){
|
||||
sb.append("第"+i+"行无选项1\n");
|
||||
}
|
||||
String option2 = map.containsKey("D"+i)?map.get("D"+i):"";
|
||||
if (StringUtils.isBlank(option2)){
|
||||
sb.append("第"+i+"行无选项2\n");
|
||||
}
|
||||
String option3 = map.containsKey("E"+i)?map.get("E"+i):"";
|
||||
if (StringUtils.isBlank(option3)){
|
||||
sb.append("第"+i+"行无选项3\n");
|
||||
}
|
||||
String option4 = map.containsKey("F"+i)?map.get("F"+i):"";
|
||||
if (StringUtils.isBlank(option4)){
|
||||
sb.append("第"+i+"行无选项4\n");
|
||||
}
|
||||
String answer = map.containsKey("I"+i)?map.get("I"+i):"";
|
||||
if (StringUtils.isBlank(answer)){
|
||||
sb.append("第"+i+"行无答案\n");
|
||||
}
|
||||
//题目
|
||||
String content = map.containsKey("B"+i)?map.get("B"+i):"";
|
||||
if (StringUtils.isBlank(content)) {
|
||||
sb.append("第"+i+"行无题目\n");
|
||||
}
|
||||
}
|
||||
if (sb.length() > 0){
|
||||
throw new Exception(sb.toString());
|
||||
}
|
||||
for (int i=2;i<=count;i++){
|
||||
ClassExamSubject subject = new ClassExamSubject();
|
||||
subject.setCourseId(courseId);
|
||||
//类型
|
||||
String type = map.containsKey("A"+i)?map.get("A"+i):"";
|
||||
if (type.contains("单选")){
|
||||
if (map.get("A"+i).contains("单选")){
|
||||
subject.setType(0);
|
||||
}else if (type.contains("多选")){
|
||||
}else if (map.get("A"+i).contains("多选")){
|
||||
subject.setType(1);
|
||||
}else {
|
||||
throw new Exception("第"+i+"题无题目类型");
|
||||
}
|
||||
//题目
|
||||
subject.setContent(map.containsKey("B"+i)?map.get("B"+i):"");
|
||||
subject.setContent(map.get("B"+i));
|
||||
//所属章节
|
||||
subject.setChapter(map.containsKey("N"+i)?map.get("N"+i):"");
|
||||
//音视频序号
|
||||
@@ -78,15 +111,15 @@ public class ClassExamController {
|
||||
subject.setCreateUser(map.containsKey("Q"+i)?map.get("Q"+i):"");
|
||||
classExamSubjectService.save(subject);
|
||||
num++;
|
||||
insertOption(optionList,subject.getId(),map.containsKey("C"+i)?map.get("C"+i):"",map.containsKey("I"+i)?map.get("I"+i):"");
|
||||
insertOption(optionList,subject.getId(),map.containsKey("D"+i)?map.get("D"+i):"",map.containsKey("I"+i)?map.get("I"+i):"");
|
||||
insertOption(optionList,subject.getId(),map.containsKey("E"+i)?map.get("E"+i):"",map.containsKey("I"+i)?map.get("I"+i):"");
|
||||
insertOption(optionList,subject.getId(),map.containsKey("F"+i)?map.get("F"+i):"",map.containsKey("I"+i)?map.get("I"+i):"");
|
||||
insertOption(optionList,subject.getId(),map.containsKey("G"+i)?map.get("G"+i):"",map.containsKey("I"+i)?map.get("I"+i):"");
|
||||
insertOption(optionList,subject.getId(),map.containsKey("H"+i)?map.get("H"+i):"",map.containsKey("I"+i)?map.get("I"+i):"");
|
||||
//插入选项
|
||||
insertOption(optionList,subject.getId(),map.get("C"+i),map.get("I"+i));
|
||||
insertOption(optionList,subject.getId(),map.get("D"+i),map.get("I"+i));
|
||||
insertOption(optionList,subject.getId(),map.get("E"+i),map.get("I"+i));
|
||||
insertOption(optionList,subject.getId(),map.get("F"+i),map.get("I"+i));
|
||||
insertOption(optionList,subject.getId(),map.containsKey("G"+i)?map.get("G"+i):"",map.get("I"+i));
|
||||
insertOption(optionList,subject.getId(),map.containsKey("H"+i)?map.get("H"+i):"",map.get("I"+i));
|
||||
}
|
||||
classExamOptionService.saveBatch(optionList);
|
||||
System.out.println("解析数据" + count + "条;耗时" + (endtime - time) / 1000 + "秒");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
@@ -127,11 +160,10 @@ public class ClassExamController {
|
||||
return R.ok().put("page",classExamSubjectList);
|
||||
}
|
||||
|
||||
//考试题目列表
|
||||
//生成试卷
|
||||
@RequestMapping("/generateExamPaper")
|
||||
public R generateExamPaper(@RequestBody Map<String,Object> params){
|
||||
Object examPaper = classExamService.generateExamPaper(params);
|
||||
return R.ok().put("examPaper",examPaper);
|
||||
return classExamService.generateExamPaper(params);
|
||||
}
|
||||
|
||||
//提交考卷
|
||||
|
||||
Reference in New Issue
Block a user