|
@@ -19,6 +19,7 @@ import cn.com.qmth.stmms.ms.core.repository.*;
|
|
|
import cn.com.qmth.stmms.ms.core.vo.Subject;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
|
+import org.mockito.internal.exceptions.ExceptionIncludingMockitoWarnings;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -229,7 +230,14 @@ public class DataUploadService {
|
|
|
}
|
|
|
|
|
|
@Transactional
|
|
|
- public List<ExcelError> uploadStudents(Long workId, final boolean isAbsent, InputStream inputStream) {
|
|
|
+ public List<ExcelError> uploadStudents(Long workId, final boolean isAbsent, InputStream inputStream) throws Exception {
|
|
|
+ //有采集数据,不能导入
|
|
|
+ List<Paper> papers = paperRepo.findByWorkId(workId);
|
|
|
+ if (papers != null && papers.size() > 0) {
|
|
|
+ throw new Exception("已有采集数据,不能导入考生数据");
|
|
|
+ }
|
|
|
+ examQuestionRepo.deleteByWorkId(workId);
|
|
|
+
|
|
|
ExcelReader excelReader = new ExcelReader(StudentDTO.class);
|
|
|
List<ExcelError> excelErrors = excelReader.reader(inputStream, new ExcelReaderHandle() {
|
|
|
|
|
@@ -312,6 +320,10 @@ public class DataUploadService {
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
+ String errors = errorsString(excelErrors);
|
|
|
+ if(errors.length() > 0) {
|
|
|
+ throw new Exception(errors);
|
|
|
+ }
|
|
|
return excelErrors;
|
|
|
}
|
|
|
|
|
@@ -439,6 +451,10 @@ public class DataUploadService {
|
|
|
if (Objects.nonNull(excelErrors) && excelErrors.size() > 0) {
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
}
|
|
|
+ String errors = errorsString(excelErrors);
|
|
|
+ if(errors.length() > 0) {
|
|
|
+ throw new Exception(errors);
|
|
|
+ }
|
|
|
return excelErrors;
|
|
|
}
|
|
|
|
|
@@ -510,7 +526,13 @@ public class DataUploadService {
|
|
|
}
|
|
|
|
|
|
@Transactional
|
|
|
- public List<ExcelError> uploadStudentRelate(Long workId, InputStream inputStream) {
|
|
|
+ public List<ExcelError> uploadStudentRelate(Long workId, InputStream inputStream) throws Exception {
|
|
|
+ //已进入分档,不能导入
|
|
|
+ List<MarkSubject> list = markSubjectRepo.findAllByWorkIdAndStageNot(workId, MarkStage.INIT.ordinal());
|
|
|
+ if (list != null && list.size() > 0) {
|
|
|
+ throw new Exception("已有进入分档阶段,不能导入关联考生数据");
|
|
|
+ }
|
|
|
+
|
|
|
ExcelReader excelReader = new ExcelReader(StudentRelateDTO.class);
|
|
|
List<ExcelError> excelErrors = excelReader.reader(inputStream, obj -> {
|
|
|
try {
|
|
@@ -551,6 +573,10 @@ public class DataUploadService {
|
|
|
return excelError;
|
|
|
}
|
|
|
});
|
|
|
+ String errors = errorsString(excelErrors);
|
|
|
+ if(errors.length() > 0) {
|
|
|
+ throw new Exception(errors);
|
|
|
+ }
|
|
|
return excelErrors;
|
|
|
}
|
|
|
|
|
@@ -605,4 +631,23 @@ public class DataUploadService {
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 拼接导入异常信息
|
|
|
+ * @param excelErrors
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String errorsString(List<ExcelError> excelErrors) {
|
|
|
+ StringJoiner sj = new StringJoiner(";");
|
|
|
+ if(!excelErrors.isEmpty() && excelErrors.size() > 0){
|
|
|
+ int forint = excelErrors.size() < 10 ? excelErrors.size() : 9 ;
|
|
|
+ for (int i = 0; i < forint; i++) {
|
|
|
+ ExcelError excelError = excelErrors.get(i);
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ sb.append("第").append(excelError.getRow()).append("行,").append(excelError.getExcelErrorType());
|
|
|
+ sj.add(sb.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return sj.toString();
|
|
|
+ }
|
|
|
}
|