|
@@ -1,5 +1,15 @@
|
|
|
package cn.com.qmth.scancloud.tools.service.impl;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+
|
|
|
import cn.com.qmth.scancloud.tools.config.SysProperty;
|
|
|
import cn.com.qmth.scancloud.tools.enums.ExamMode;
|
|
|
import cn.com.qmth.scancloud.tools.enums.ExamType;
|
|
@@ -10,17 +20,6 @@ import cn.com.qmth.scancloud.tools.utils.FileHelper;
|
|
|
import cn.com.qmth.scancloud.tools.utils.HttpHelper;
|
|
|
import cn.com.qmth.scancloud.tools.utils.JsonHelper;
|
|
|
import cn.com.qmth.scancloud.tools.utils.StatusException;
|
|
|
-import org.apache.commons.collections4.CollectionUtils;
|
|
|
-import org.apache.commons.collections4.MapUtils;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
-
|
|
|
-import java.io.File;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* 考试导入
|
|
@@ -48,13 +47,6 @@ public class ExamImportTask extends AbstractTask {
|
|
|
throw new StatusException("导入模板目前仅支持后缀名为“.txt”的文件!");
|
|
|
}
|
|
|
|
|
|
- // 自定义模板 列分隔符
|
|
|
- String templateSeparator = StringUtils.isNotEmpty(SysProperty.TEMPLATE_SEPARATOR)
|
|
|
- ? SysProperty.TEMPLATE_SEPARATOR
|
|
|
- : "|";
|
|
|
- // 自定义模板 列与索引位置
|
|
|
- Map<String, Integer> templateColumns = JsonHelper.toMap(SysProperty.TEMPLATE_COLUMNS, Integer.class);
|
|
|
-
|
|
|
File file = new File(SysProperty.DATA_FILE);
|
|
|
List<String> lines = FileHelper.readAllLines(file);
|
|
|
if (CollectionUtils.isEmpty(lines)) {
|
|
@@ -64,7 +56,7 @@ public class ExamImportTask extends AbstractTask {
|
|
|
|
|
|
List<Exam> list = new ArrayList<>();
|
|
|
for (int n = 0; n < lines.size(); n++) {
|
|
|
- Exam data = this.parseValues(n, lines.get(n), templateColumns, templateSeparator);
|
|
|
+ Exam data = this.parseValues(n, lines.get(n), SysProperty.TEMPLATE_SEPARATOR);
|
|
|
if (data != null) {
|
|
|
data.setSchoolId(schoolId);
|
|
|
data.setSchoolName(schoolName);
|
|
@@ -87,7 +79,7 @@ public class ExamImportTask extends AbstractTask {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private Exam parseValues(int index, String line, Map<String, Integer> templateColumns, String templateSeparator) {
|
|
|
+ private Exam parseValues(int index, String line, String templateSeparator) {
|
|
|
if (StringUtils.isBlank(line)) {
|
|
|
return null;
|
|
|
}
|
|
@@ -100,23 +92,10 @@ public class ExamImportTask extends AbstractTask {
|
|
|
String examName = null;
|
|
|
ExamType examType = null;
|
|
|
|
|
|
- if (MapUtils.isEmpty(templateColumns)) {
|
|
|
- // 默认模板:考试ID|考试名称|考试类型
|
|
|
- examId = this.parseLong(values[0]);
|
|
|
- examName = values[1];
|
|
|
- examType = ExamType.findByName(values[2]);
|
|
|
- } else {
|
|
|
- // 自定义模板
|
|
|
- if (templateColumns.get("考试ID") != null) {
|
|
|
- examId = this.parseLong(values[templateColumns.get("考试ID")]);
|
|
|
- }
|
|
|
- if (templateColumns.get("考试名称") != null) {
|
|
|
- examName = values[templateColumns.get("考试名称")];
|
|
|
- }
|
|
|
- if (templateColumns.get("考试类型") != null) {
|
|
|
- examType = ExamType.findByName(values[templateColumns.get("考试类型")]);
|
|
|
- }
|
|
|
- }
|
|
|
+ // 默认模板:考试ID|考试名称|考试类型
|
|
|
+ examId = this.parseLong(values[0]);
|
|
|
+ examName = values[1];
|
|
|
+ examType = ExamType.findByName(values[2]);
|
|
|
|
|
|
if (examId == null) {
|
|
|
throw new StatusException(String.format("【第%s行】“考试ID”字段值有误! %s", index + 1, line));
|