|
@@ -24,8 +24,10 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import javax.imageio.ImageIO;
|
|
|
import java.awt.image.BufferedImage;
|
|
|
import java.io.*;
|
|
|
+import java.lang.reflect.Field;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
import java.util.Random;
|
|
|
|
|
|
/**
|
|
@@ -161,6 +163,9 @@ public class DataUploadService {
|
|
|
if (student == null && !isAbsent) {
|
|
|
student = new Student(dto.getName(), dto.getExamNumber(), dto.getAreaName(), dto.getAreaCode(),
|
|
|
workId, dto.getExamRoom(), dto.getSourceName());
|
|
|
+ if (!checkObjFieldIsNotNull(student)) {
|
|
|
+ throw new RuntimeException("考生信息缺失");
|
|
|
+ }
|
|
|
studentRepo.save(student);
|
|
|
} else if (student != null) {
|
|
|
if (isAbsent) {
|
|
@@ -186,6 +191,9 @@ public class DataUploadService {
|
|
|
student.setExamRoom(dto.getExamRoom());
|
|
|
student.setSourceName(dto.getSourceName());
|
|
|
}
|
|
|
+ if (!checkObjFieldIsNotNull(student)) {
|
|
|
+ throw new RuntimeException("考生信息缺失");
|
|
|
+ }
|
|
|
studentRepo.save(student);
|
|
|
}
|
|
|
return null;
|
|
@@ -268,4 +276,27 @@ public class DataUploadService {
|
|
|
}
|
|
|
return random;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验学生导入所有属性
|
|
|
+ *
|
|
|
+ * @param obj
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private boolean checkObjFieldIsNotNull(Object obj) {
|
|
|
+ for (Field field : obj.getClass().getDeclaredFields()) {
|
|
|
+ if (Objects.equals("id", field.getName())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ field.setAccessible(true);
|
|
|
+ try {
|
|
|
+ if (field.get(obj) == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ } catch (IllegalAccessException e) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|