|
@@ -110,6 +110,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, QuestionEnt
|
|
|
|
|
|
/**
|
|
/**
|
|
* 解决excel数据并保存数据库
|
|
* 解决excel数据并保存数据库
|
|
|
|
+ * 注意日期格式要在转换成文本
|
|
*
|
|
*
|
|
* @param filePath 相对路径
|
|
* @param filePath 相对路径
|
|
* @return
|
|
* @return
|
|
@@ -119,13 +120,15 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, QuestionEnt
|
|
String excelPath = configConstant.serverBasePath + filePath;
|
|
String excelPath = configConstant.serverBasePath + filePath;
|
|
// 读取每一行
|
|
// 读取每一行
|
|
List<List<Object>> rows = ExcelUtils.readExcel(excelPath);
|
|
List<List<Object>> rows = ExcelUtils.readExcel(excelPath);
|
|
|
|
+ int rowSize = rows.size();
|
|
|
|
+ log.info("共{}题", rowSize);
|
|
QuestionEntity question ;
|
|
QuestionEntity question ;
|
|
|
|
|
|
List<String> standard = Arrays.asList("A", "B", "C", "D");
|
|
List<String> standard = Arrays.asList("A", "B", "C", "D");
|
|
|
|
|
|
|
|
|
|
ArrayList<QuestionEntity> result = new ArrayList<>();
|
|
ArrayList<QuestionEntity> result = new ArrayList<>();
|
|
- for (int i = 1; i < rows.size(); i++) {
|
|
|
|
|
|
+ for (int i = 1; i < rowSize; i++) {
|
|
question = new QuestionEntity();
|
|
question = new QuestionEntity();
|
|
List<Object> row = rows.get(i);
|
|
List<Object> row = rows.get(i);
|
|
|
|
|
|
@@ -136,6 +139,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, QuestionEnt
|
|
log.error(errorMsg);
|
|
log.error(errorMsg);
|
|
BaseRuntimeException.getExc(null, errorMsg);
|
|
BaseRuntimeException.getExc(null, errorMsg);
|
|
}
|
|
}
|
|
|
|
+
|
|
JSONObject answerMapper = answerMapper(row, correct);
|
|
JSONObject answerMapper = answerMapper(row, correct);
|
|
// 加密后的正确答案
|
|
// 加密后的正确答案
|
|
String correctStr = answerMapper.getString("correct");
|
|
String correctStr = answerMapper.getString("correct");
|
|
@@ -148,7 +152,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, QuestionEnt
|
|
question.setCorrect(correctStr);
|
|
question.setCorrect(correctStr);
|
|
question.setAnswer(answerMapper.toJSONString());
|
|
question.setAnswer(answerMapper.toJSONString());
|
|
result.add(question);
|
|
result.add(question);
|
|
-
|
|
|
|
|
|
+ log.info("执行第 {} 行完成", i);
|
|
}
|
|
}
|
|
log.info("excel数据解析完成");
|
|
log.info("excel数据解析完成");
|
|
return result;
|
|
return result;
|
|
@@ -165,14 +169,11 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, QuestionEnt
|
|
baseMap.put("D", RandomUtil.randomString(8));
|
|
baseMap.put("D", RandomUtil.randomString(8));
|
|
|
|
|
|
JSONObject answerMap = new JSONObject();
|
|
JSONObject answerMap = new JSONObject();
|
|
- String answerA = (String)row.get(4);
|
|
|
|
- String answerB = (String)row.get(5);
|
|
|
|
- String answerC = (String)row.get(6);
|
|
|
|
- String answerD = (String)row.get(7);
|
|
|
|
- answerMap.put(baseMap.getString("A"), answerA);
|
|
|
|
- answerMap.put(baseMap.getString("B"), answerB);
|
|
|
|
- answerMap.put(baseMap.getString("C"), answerC);
|
|
|
|
- answerMap.put(baseMap.getString("D"), answerD);
|
|
|
|
|
|
+
|
|
|
|
+ answerMap.put(baseMap.getString("A"), row.get(4));
|
|
|
|
+ answerMap.put(baseMap.getString("B"), row.get(5));
|
|
|
|
+ answerMap.put(baseMap.getString("C"), row.get(6));
|
|
|
|
+ answerMap.put(baseMap.getString("D"), row.get(7));
|
|
answerMap.put("correct", baseMap.get(correct));
|
|
answerMap.put("correct", baseMap.get(correct));
|
|
return answerMap;
|
|
return answerMap;
|
|
}
|
|
}
|