|
@@ -56,11 +56,11 @@ import com.qmth.boot.core.exception.StatusException;
|
|
import com.qmth.boot.core.retrofit.utils.SignatureInfo;
|
|
import com.qmth.boot.core.retrofit.utils.SignatureInfo;
|
|
import com.qmth.boot.tools.excel.ExcelReader;
|
|
import com.qmth.boot.tools.excel.ExcelReader;
|
|
import com.qmth.boot.tools.excel.enums.ExcelType;
|
|
import com.qmth.boot.tools.excel.enums.ExcelType;
|
|
-import com.qmth.boot.tools.io.IOUtils;
|
|
|
|
import com.qmth.boot.tools.signature.SignatureType;
|
|
import com.qmth.boot.tools.signature.SignatureType;
|
|
import com.qmth.boot.tools.uuid.FastUUID;
|
|
import com.qmth.boot.tools.uuid.FastUUID;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.io.FileUtils;
|
|
import org.apache.commons.io.FileUtils;
|
|
|
|
+import org.apache.commons.io.IOUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -79,9 +79,9 @@ import java.util.stream.Collectors;
|
|
@Service
|
|
@Service
|
|
public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> implements StudentService {
|
|
public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> implements StudentService {
|
|
|
|
|
|
- private static final String[] BREACH_EXCEL_HEADER = new String[]{"准考证号", "违纪码"};
|
|
|
|
|
|
+ private static final String[] BREACH_EXCEL_HEADER = new String[] { "准考证号", "违纪码" };
|
|
|
|
|
|
- private static final String[] CUST_STATUS_EXCEL_HEADER = new String[]{"准考证号", "考生状态"};
|
|
|
|
|
|
+ private static final String[] CUST_STATUS_EXCEL_HEADER = new String[] { "准考证号", "考生状态" };
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(StudentService.class);
|
|
private static final Logger log = LoggerFactory.getLogger(StudentService.class);
|
|
|
|
|
|
@@ -149,7 +149,7 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
@Transactional
|
|
@Transactional
|
|
// @Lockable(name = LockType.STUDENT, key = "#id")
|
|
// @Lockable(name = LockType.STUDENT, key = "#id")
|
|
public void updateStudentAndPaper(@NotNull User user, @NotNull Long id,
|
|
public void updateStudentAndPaper(@NotNull User user, @NotNull Long id,
|
|
- @NotNull List<StudentPaperEntity> studentPaperList) {
|
|
|
|
|
|
+ @NotNull List<StudentPaperEntity> studentPaperList) {
|
|
for (StudentPaperEntity studentPaper : studentPaperList) {
|
|
for (StudentPaperEntity studentPaper : studentPaperList) {
|
|
studentPaper.setStudentId(id);
|
|
studentPaper.setStudentId(id);
|
|
}
|
|
}
|
|
@@ -696,7 +696,7 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
@Transactional
|
|
@Transactional
|
|
@Override
|
|
@Override
|
|
public void updateUploadStatus(@NotNull Long id, @NotNull UploadStatus fileUploadStatus,
|
|
public void updateUploadStatus(@NotNull Long id, @NotNull UploadStatus fileUploadStatus,
|
|
- @NotNull UploadStatus dataUploadStatus) {
|
|
|
|
|
|
+ @NotNull UploadStatus dataUploadStatus) {
|
|
LambdaUpdateWrapper<StudentEntity> lw = new LambdaUpdateWrapper<>();
|
|
LambdaUpdateWrapper<StudentEntity> lw = new LambdaUpdateWrapper<>();
|
|
lw.set(StudentEntity::getDataUploadStatus, dataUploadStatus);
|
|
lw.set(StudentEntity::getDataUploadStatus, dataUploadStatus);
|
|
lw.set(StudentEntity::getFileUploadStatus, fileUploadStatus);
|
|
lw.set(StudentEntity::getFileUploadStatus, fileUploadStatus);
|
|
@@ -1223,8 +1223,8 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
}
|
|
}
|
|
|
|
|
|
private void disposeStudent(ExportCetVo student, ExamEntity exam, List<PaperPageCetVo> pages,
|
|
private void disposeStudent(ExportCetVo student, ExamEntity exam, List<PaperPageCetVo> pages,
|
|
- List<PaperCetVo> papers, String imageTransferDir, Map<String, List<QuestionEntity>> structs,
|
|
|
|
- Map<Integer, AnswerCardEntity> cardMap) {
|
|
|
|
|
|
+ List<PaperCetVo> papers, String imageTransferDir, Map<String, List<QuestionEntity>> structs,
|
|
|
|
+ Map<Integer, AnswerCardEntity> cardMap) {
|
|
int subject = Integer.valueOf(student.getSubjectCode());
|
|
int subject = Integer.valueOf(student.getSubjectCode());
|
|
if (subject > 2) {
|
|
if (subject > 2) {
|
|
if (student.getExamStatus().equals(ExamStatus.ABSENT)) {
|
|
if (student.getExamStatus().equals(ExamStatus.ABSENT)) {
|
|
@@ -1305,7 +1305,7 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
}
|
|
}
|
|
|
|
|
|
private void setCardStatus(ExportCetVo student, AnswerCardEntity card, List<PaperPageCetVo> pages,
|
|
private void setCardStatus(ExportCetVo student, AnswerCardEntity card, List<PaperPageCetVo> pages,
|
|
- Map<Long, PaperCetVo> pmap) {
|
|
|
|
|
|
+ Map<Long, PaperCetVo> pmap) {
|
|
int subject = Integer.valueOf(student.getSubjectCode());
|
|
int subject = Integer.valueOf(student.getSubjectCode());
|
|
if (subject > 2) {
|
|
if (subject > 2) {
|
|
setCardStatusSmall(student, card, pages, pmap);
|
|
setCardStatusSmall(student, card, pages, pmap);
|
|
@@ -1315,7 +1315,7 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
}
|
|
}
|
|
|
|
|
|
private void setCardStatusSmall(ExportCetVo student, AnswerCardEntity card, List<PaperPageCetVo> pages,
|
|
private void setCardStatusSmall(ExportCetVo student, AnswerCardEntity card, List<PaperPageCetVo> pages,
|
|
- Map<Long, PaperCetVo> pmap) {
|
|
|
|
|
|
+ Map<Long, PaperCetVo> pmap) {
|
|
PaperPageCetVo p = pages.get(0);
|
|
PaperPageCetVo p = pages.get(0);
|
|
if (ExamStatus.ABSENT.equals(student.getExamStatus())) {
|
|
if (ExamStatus.ABSENT.equals(student.getExamStatus())) {
|
|
if (pmap.get(p.getPaperId()).getQuestionFilled()) {
|
|
if (pmap.get(p.getPaperId()).getQuestionFilled()) {
|
|
@@ -1330,7 +1330,7 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
}
|
|
}
|
|
|
|
|
|
private void setCardStatusCet(ExportCetVo student, AnswerCardEntity card, List<PaperPageCetVo> pages,
|
|
private void setCardStatusCet(ExportCetVo student, AnswerCardEntity card, List<PaperPageCetVo> pages,
|
|
- Map<Long, PaperCetVo> pmap) {
|
|
|
|
|
|
+ Map<Long, PaperCetVo> pmap) {
|
|
if (card.getPaperCount() == 1) {
|
|
if (card.getPaperCount() == 1) {
|
|
PaperPageCetVo p = pages.get(0);
|
|
PaperPageCetVo p = pages.get(0);
|
|
if (ExamStatus.ABSENT.equals(student.getExamStatus())) {
|
|
if (ExamStatus.ABSENT.equals(student.getExamStatus())) {
|
|
@@ -1423,7 +1423,7 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
}
|
|
}
|
|
|
|
|
|
private String getCetAnswer(Map<String, List<QuestionEntity>> structs, List<PaperPageCetVo> pages, Long examId,
|
|
private String getCetAnswer(Map<String, List<QuestionEntity>> structs, List<PaperPageCetVo> pages, Long examId,
|
|
- String subjectCode) {
|
|
|
|
|
|
+ String subjectCode) {
|
|
List<String> answers = new ArrayList<String>();
|
|
List<String> answers = new ArrayList<String>();
|
|
List<QuestionEntity> struct = structs.get(examId + "-" + subjectCode);
|
|
List<QuestionEntity> struct = structs.get(examId + "-" + subjectCode);
|
|
if (struct == null) {
|
|
if (struct == null) {
|
|
@@ -1870,7 +1870,9 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
}
|
|
}
|
|
return ret;
|
|
return ret;
|
|
} finally {
|
|
} finally {
|
|
- IOUtils.closeQuietly(inputStream);
|
|
|
|
|
|
+ if (inputStream != null) {
|
|
|
|
+ inputStream.close();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -2321,7 +2323,7 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
File temDir = new File("temp/" + FastUUID.get() + "/");
|
|
File temDir = new File("temp/" + FastUUID.get() + "/");
|
|
try {
|
|
try {
|
|
temDir.mkdirs();
|
|
temDir.mkdirs();
|
|
- File excel = new File(temDir.getAbsolutePath() + "/breach.xlsx");
|
|
|
|
|
|
+ File excel = new File(temDir.getAbsolutePath() + "/breach.txt");
|
|
try {
|
|
try {
|
|
file.transferTo(excel);
|
|
file.transferTo(excel);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
@@ -2389,52 +2391,50 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
}
|
|
}
|
|
|
|
|
|
private ImportBreachResult breachImportCheck(Long examId, String subjectCode, InputStream in) {
|
|
private ImportBreachResult breachImportCheck(Long examId, String subjectCode, InputStream in) {
|
|
- List<String[]> lineList = null;
|
|
|
|
- ExcelReader reader = ExcelReader.create(ExcelType.XLSX, in, 0);
|
|
|
|
|
|
+ List<String> lineList = null;
|
|
try {
|
|
try {
|
|
- lineList = reader.getDataArrayList();
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- throw new ParameterException("Excel 解析失败");
|
|
|
|
- }
|
|
|
|
- if (!Arrays.equals(BREACH_EXCEL_HEADER, reader.getColumnNames())) {
|
|
|
|
- throw new ParameterException("Excel表头错误");
|
|
|
|
- }
|
|
|
|
- if (CollectionUtils.isEmpty(lineList)) {
|
|
|
|
- throw new ParameterException("Excel无内容");
|
|
|
|
- }
|
|
|
|
- if (500001 < lineList.size()) {
|
|
|
|
- throw new ParameterException("数据行数不能超过500000");
|
|
|
|
|
|
+ lineList = IOUtils.readLines(in, "UTF-8");
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ throw new StatusException("读取文件出错", e);
|
|
}
|
|
}
|
|
ImportBreachResult ret = new ImportBreachResult();
|
|
ImportBreachResult ret = new ImportBreachResult();
|
|
List<String> failRecords = new ArrayList<>();
|
|
List<String> failRecords = new ArrayList<>();
|
|
ret.setErrMsg(failRecords);
|
|
ret.setErrMsg(failRecords);
|
|
Set<String> examNumberSet = new HashSet<>();
|
|
Set<String> examNumberSet = new HashSet<>();
|
|
for (int i = 0; i < lineList.size(); i++) {
|
|
for (int i = 0; i < lineList.size(); i++) {
|
|
- String[] line = lineList.get(i);
|
|
|
|
-
|
|
|
|
|
|
+ String lineString = lineList.get(i);
|
|
|
|
+ if (StringUtils.isBlank(lineString)) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
StringBuilder msg = new StringBuilder();
|
|
StringBuilder msg = new StringBuilder();
|
|
-
|
|
|
|
- String examNumber = trimAndNullIfBlank(line[0]);
|
|
|
|
- if (StringUtils.isBlank(examNumber)) {
|
|
|
|
- msg.append(" 准考证号不能为空");
|
|
|
|
|
|
+ String[] line = lineString.split(",");
|
|
|
|
+ if (line.length != 3) {
|
|
|
|
+ msg.append(" 格式错误");
|
|
} else {
|
|
} else {
|
|
- StudentEntity s = findByExamAndSubjectCodeAndExamNumber(examId, subjectCode, examNumber);
|
|
|
|
- if (s == null) {
|
|
|
|
- msg.append(" 准考证号未找到");
|
|
|
|
|
|
+ String examNumber = trimAndNullIfBlank(line[0]);
|
|
|
|
+ if (StringUtils.isBlank(examNumber)) {
|
|
|
|
+ msg.append(" 准考证号不能为空");
|
|
} else {
|
|
} else {
|
|
- if (examNumberSet.contains(examNumber)) {
|
|
|
|
- msg.append(" 准考证号重复");
|
|
|
|
|
|
+ StudentEntity s = findByExamAndSubjectCodeAndExamNumber(examId, subjectCode, examNumber);
|
|
|
|
+ if (s == null) {
|
|
|
|
+ msg.append(" 准考证号未找到");
|
|
} else {
|
|
} else {
|
|
- examNumberSet.add(examNumber);
|
|
|
|
|
|
+ if (examNumberSet.contains(examNumber)) {
|
|
|
|
+ msg.append(" 准考证号重复");
|
|
|
|
+ } else {
|
|
|
|
+ examNumberSet.add(examNumber);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
|
|
- String breach = trimAndNullIfBlank(line[1]);
|
|
|
|
- if (StringUtils.isNotBlank(breach)) {
|
|
|
|
- ret.setBreachCount(ret.getBreachCount() + 1);
|
|
|
|
|
|
+ String breach = trimAndNullIfBlank(line[1]);
|
|
|
|
+ if (StringUtils.isNotBlank(breach)) {
|
|
|
|
+ ret.setBreachCount(ret.getBreachCount() + 1);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (msg.length() > 0) {
|
|
|
|
+ failRecords.add(errorMsg(i + 2, msg.toString()));
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(failRecords)) {
|
|
if (CollectionUtils.isNotEmpty(failRecords)) {
|
|
@@ -2445,13 +2445,17 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private String errorMsg(int lineNum, String msg) {
|
|
|
|
+ return "第" + lineNum + "行 " + msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public ImportBreachResult custStatusImport(Long examId, String subjectCode, MultipartFile file) {
|
|
public ImportBreachResult custStatusImport(Long examId, String subjectCode, MultipartFile file) {
|
|
// 暂存临时文件
|
|
// 暂存临时文件
|
|
File temDir = new File("temp/" + FastUUID.get() + "/");
|
|
File temDir = new File("temp/" + FastUUID.get() + "/");
|
|
try {
|
|
try {
|
|
temDir.mkdirs();
|
|
temDir.mkdirs();
|
|
- File excel = new File(temDir.getAbsolutePath() + "/cust-status.xlsx");
|
|
|
|
|
|
+ File excel = new File(temDir.getAbsolutePath() + "/cust-status.txt");
|
|
try {
|
|
try {
|
|
file.transferTo(excel);
|
|
file.transferTo(excel);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
@@ -2519,52 +2523,51 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
}
|
|
}
|
|
|
|
|
|
private ImportBreachResult custStatusImportCheck(Long examId, String subjectCode, InputStream in) {
|
|
private ImportBreachResult custStatusImportCheck(Long examId, String subjectCode, InputStream in) {
|
|
- List<String[]> lineList = null;
|
|
|
|
- ExcelReader reader = ExcelReader.create(ExcelType.XLSX, in, 0);
|
|
|
|
|
|
+ List<String> lineList = null;
|
|
try {
|
|
try {
|
|
- lineList = reader.getDataArrayList();
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- throw new ParameterException("Excel 解析失败");
|
|
|
|
- }
|
|
|
|
- if (!Arrays.equals(CUST_STATUS_EXCEL_HEADER, reader.getColumnNames())) {
|
|
|
|
- throw new ParameterException("Excel表头错误");
|
|
|
|
- }
|
|
|
|
- if (CollectionUtils.isEmpty(lineList)) {
|
|
|
|
- throw new ParameterException("Excel无内容");
|
|
|
|
- }
|
|
|
|
- if (500001 < lineList.size()) {
|
|
|
|
- throw new ParameterException("数据行数不能超过500000");
|
|
|
|
|
|
+ lineList = IOUtils.readLines(in, "UTF-8");
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ throw new StatusException("读取文件出错", e);
|
|
}
|
|
}
|
|
ImportBreachResult ret = new ImportBreachResult();
|
|
ImportBreachResult ret = new ImportBreachResult();
|
|
List<String> failRecords = new ArrayList<>();
|
|
List<String> failRecords = new ArrayList<>();
|
|
ret.setErrMsg(failRecords);
|
|
ret.setErrMsg(failRecords);
|
|
Set<String> examNumberSet = new HashSet<>();
|
|
Set<String> examNumberSet = new HashSet<>();
|
|
for (int i = 0; i < lineList.size(); i++) {
|
|
for (int i = 0; i < lineList.size(); i++) {
|
|
- String[] line = lineList.get(i);
|
|
|
|
-
|
|
|
|
|
|
+ String lineString = lineList.get(i);
|
|
|
|
+ if (StringUtils.isBlank(lineString)) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
StringBuilder msg = new StringBuilder();
|
|
StringBuilder msg = new StringBuilder();
|
|
-
|
|
|
|
- String examNumber = trimAndNullIfBlank(line[0]);
|
|
|
|
- if (StringUtils.isBlank(examNumber)) {
|
|
|
|
- msg.append(" 准考证号不能为空");
|
|
|
|
|
|
+ String[] line = lineString.split(",");
|
|
|
|
+ if (line.length != 3) {
|
|
|
|
+ msg.append(" 格式错误");
|
|
} else {
|
|
} else {
|
|
- StudentEntity s = findByExamAndSubjectCodeAndExamNumber(examId, subjectCode, examNumber);
|
|
|
|
- if (s == null) {
|
|
|
|
- msg.append(" 准考证号未找到");
|
|
|
|
|
|
+
|
|
|
|
+ String examNumber = trimAndNullIfBlank(line[0]);
|
|
|
|
+ if (StringUtils.isBlank(examNumber)) {
|
|
|
|
+ msg.append(" 准考证号不能为空");
|
|
} else {
|
|
} else {
|
|
- if (examNumberSet.contains(examNumber)) {
|
|
|
|
- msg.append(" 准考证号重复");
|
|
|
|
|
|
+ StudentEntity s = findByExamAndSubjectCodeAndExamNumber(examId, subjectCode, examNumber);
|
|
|
|
+ if (s == null) {
|
|
|
|
+ msg.append(" 准考证号未找到");
|
|
} else {
|
|
} else {
|
|
- examNumberSet.add(examNumber);
|
|
|
|
|
|
+ if (examNumberSet.contains(examNumber)) {
|
|
|
|
+ msg.append(" 准考证号重复");
|
|
|
|
+ } else {
|
|
|
|
+ examNumberSet.add(examNumber);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
|
|
- String breach = trimAndNullIfBlank(line[1]);
|
|
|
|
- if (StringUtils.isNotBlank(breach)) {
|
|
|
|
- ret.setBreachCount(ret.getBreachCount() + 1);
|
|
|
|
|
|
+ String breach = trimAndNullIfBlank(line[1]);
|
|
|
|
+ if (StringUtils.isNotBlank(breach)) {
|
|
|
|
+ ret.setBreachCount(ret.getBreachCount() + 1);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (msg.length() > 0) {
|
|
|
|
+ failRecords.add(errorMsg(i + 2, msg.toString()));
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(failRecords)) {
|
|
if (CollectionUtils.isNotEmpty(failRecords)) {
|