|
@@ -24,6 +24,7 @@ import org.apache.poi.xssf.usermodel.XSSFRow;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
import org.springframework.validation.BindingResult;
|
|
import org.springframework.validation.BindingResult;
|
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestHeader;
|
|
import org.springframework.web.bind.annotation.RequestHeader;
|
|
@@ -561,7 +562,7 @@ public class SmartScoreController implements SmartScoreControllerAPI {
|
|
|
if (subjectScore != null && subjectScore.isPresent()) {
|
|
if (subjectScore != null && subjectScore.isPresent()) {
|
|
|
dataRow.createCell(j).setCellValue(subjectScore.get().getScore());//分数
|
|
dataRow.createCell(j).setCellValue(subjectScore.get().getScore());//分数
|
|
|
dataRow.getCell(j).setCellStyle(style);
|
|
dataRow.getCell(j).setCellStyle(style);
|
|
|
- }else{
|
|
|
|
|
|
|
+ } else {
|
|
|
dataRow.createCell(j).setCellStyle(style);
|
|
dataRow.createCell(j).setCellStyle(style);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -640,6 +641,21 @@ public class SmartScoreController implements SmartScoreControllerAPI {
|
|
|
if (grades == null) {
|
|
if (grades == null) {
|
|
|
return CommonResult.fail("系统年级数据为空,导入失败");
|
|
return CommonResult.fail("系统年级数据为空,导入失败");
|
|
|
}
|
|
}
|
|
|
|
|
+ //获取科目
|
|
|
|
|
+ List<SmartSubject> subjects = smartSubjectService.list(null);
|
|
|
|
|
+ if (subjects == null) {
|
|
|
|
|
+ return CommonResult.fail("科目数据为空,导入失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ //考试类型
|
|
|
|
|
+ List<SmartExamtype> examtypes = smartExamtypeService.list(null);
|
|
|
|
|
+ if (examtypes == null) {
|
|
|
|
|
+ return CommonResult.fail("考试类型数据为空,导入失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ //学期
|
|
|
|
|
+ List<SmartSemester> semesters = smartSemesterService.list(null);
|
|
|
|
|
+ if (semesters == null) {
|
|
|
|
|
+ return CommonResult.fail("学期数据为空,导入失败");
|
|
|
|
|
+ }
|
|
|
//获取班级
|
|
//获取班级
|
|
|
List<SmartClass> classes = smartClassService.list(null);
|
|
List<SmartClass> classes = smartClassService.list(null);
|
|
|
if (classes == null) {
|
|
if (classes == null) {
|
|
@@ -649,102 +665,113 @@ public class SmartScoreController implements SmartScoreControllerAPI {
|
|
|
DataFormatter dataFormatter = new DataFormatter();
|
|
DataFormatter dataFormatter = new DataFormatter();
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
|
|
+ HSSFRow titleRow = sheetAt.getRow(1);
|
|
|
//sheetAt.getLastRowNum():从0开始统计数量 所以得+1
|
|
//sheetAt.getLastRowNum():从0开始统计数量 所以得+1
|
|
|
- for (int rowNum = 0; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
|
|
|
|
|
-
|
|
|
|
|
- HSSFRow row = sheetAt.getRow(rowNum);
|
|
|
|
|
|
|
+ for (int rowNum = 1; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
|
|
|
|
|
|
|
|
|
|
+ HSSFRow row = sheetAt.getRow(1);
|
|
|
//判断每一列单元格是否符合规则
|
|
//判断每一列单元格是否符合规则
|
|
|
- if (rowNum == 0) {
|
|
|
|
|
- String semester = dataFormatter.formatCellValue(row.getCell(0));//学期
|
|
|
|
|
- if (!semester.equals("学期")) {
|
|
|
|
|
- return CommonResult.fail("导入数据第一列为学期");
|
|
|
|
|
|
|
+ if (rowNum == 1) {
|
|
|
|
|
+ String name = dataFormatter.formatCellValue(titleRow.getCell(0));//姓名
|
|
|
|
|
+ if (!name.equals("姓名")) {
|
|
|
|
|
+ return CommonResult.fail("导入数据第一列为姓名");
|
|
|
}
|
|
}
|
|
|
- String grade = dataFormatter.formatCellValue(row.getCell(1));//年级
|
|
|
|
|
- if (!grade.equals("年级")) {
|
|
|
|
|
- return CommonResult.fail("导入数据第二列为年级");
|
|
|
|
|
|
|
+ String cardNo = dataFormatter.formatCellValue(titleRow.getCell(1));//学号
|
|
|
|
|
+ if (!cardNo.equals("学号")) {
|
|
|
|
|
+ return CommonResult.fail("导入数据第二列为学号");
|
|
|
}
|
|
}
|
|
|
- String schoolClass = dataFormatter.formatCellValue(row.getCell(2));//班级
|
|
|
|
|
|
|
+ String schoolClass = dataFormatter.formatCellValue(titleRow.getCell(2));//班级
|
|
|
if (!schoolClass.equals("班级")) {
|
|
if (!schoolClass.equals("班级")) {
|
|
|
return CommonResult.fail("导入数据第三列为班级");
|
|
return CommonResult.fail("导入数据第三列为班级");
|
|
|
}
|
|
}
|
|
|
- String subject = dataFormatter.formatCellValue(row.getCell(3));//学科
|
|
|
|
|
- if (!subject.equals("学科")) {
|
|
|
|
|
- return CommonResult.fail("导入数据第四列为学科");
|
|
|
|
|
|
|
+ String grade = dataFormatter.formatCellValue(titleRow.getCell(3));//年级
|
|
|
|
|
+ if (!grade.equals("年级")) {
|
|
|
|
|
+ return CommonResult.fail("导入数据第四列为年级");
|
|
|
}
|
|
}
|
|
|
- String examType = dataFormatter.formatCellValue(row.getCell(4));//考试类型
|
|
|
|
|
|
|
+ String examType = dataFormatter.formatCellValue(titleRow.getCell(4));//考试类型
|
|
|
if (!examType.equals("考试类型")) {
|
|
if (!examType.equals("考试类型")) {
|
|
|
- return CommonResult.fail("导入数据第四列为考试类型");
|
|
|
|
|
- }
|
|
|
|
|
- String name = dataFormatter.formatCellValue(row.getCell(5));//姓名
|
|
|
|
|
- if (!name.equals("姓名")) {
|
|
|
|
|
- return CommonResult.fail("导入数据第四列为姓名");
|
|
|
|
|
- }
|
|
|
|
|
- String cardNo = dataFormatter.formatCellValue(row.getCell(6));//学号
|
|
|
|
|
- if (!cardNo.equals("学号")) {
|
|
|
|
|
- return CommonResult.fail("导入数据第四列为学号");
|
|
|
|
|
- }
|
|
|
|
|
- String score = dataFormatter.formatCellValue(row.getCell(7));//成绩
|
|
|
|
|
- if (!score.equals("成绩")) {
|
|
|
|
|
- return CommonResult.fail("导入数据第四列为成绩");
|
|
|
|
|
|
|
+ return CommonResult.fail("导入数据第五列为考试类型");
|
|
|
}
|
|
}
|
|
|
- } else {
|
|
|
|
|
- SmartScore data = new SmartScore();
|
|
|
|
|
- String semester = dataFormatter.formatCellValue(row.getCell(0));//学期
|
|
|
|
|
- String grade = dataFormatter.formatCellValue(row.getCell(1));//年级
|
|
|
|
|
- String schoolClass = dataFormatter.formatCellValue(row.getCell(2));//班级
|
|
|
|
|
- String subject = dataFormatter.formatCellValue(row.getCell(3));//学科
|
|
|
|
|
- String examType = dataFormatter.formatCellValue(row.getCell(4));//考试类型
|
|
|
|
|
- String name = dataFormatter.formatCellValue(row.getCell(5));//姓名
|
|
|
|
|
- String cardNo = dataFormatter.formatCellValue(row.getCell(6));//学号
|
|
|
|
|
- String score = dataFormatter.formatCellValue(row.getCell(7));//成绩
|
|
|
|
|
-
|
|
|
|
|
- SmartSemester semesterStr = smartSemesterService.querySemesterByName(semester);
|
|
|
|
|
- if (semesterStr == null) {
|
|
|
|
|
- return CommonResult.fail(semester + "学期数据无效,导入失败!");
|
|
|
|
|
|
|
+ String semester = dataFormatter.formatCellValue(titleRow.getCell(5));//学期
|
|
|
|
|
+ if (!semester.equals("学期")) {
|
|
|
|
|
+ return CommonResult.fail("导入数据第六列为学期");
|
|
|
}
|
|
}
|
|
|
|
|
+ } else if (rowNum > 2) {
|
|
|
|
|
|
|
|
- //数据重复性判断 学期 + 学号 + 科目
|
|
|
|
|
- String existData = semester + cardNo + subject;
|
|
|
|
|
- scoreNames.add(existData);
|
|
|
|
|
- if (scoreNames.stream().distinct().count() != scoreNames.size()) {
|
|
|
|
|
- return CommonResult.fail("导入的Excel中的" + existData + "存在重复数据");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ String name = dataFormatter.formatCellValue(row.getCell(0));//姓名
|
|
|
|
|
+ String cardNo = dataFormatter.formatCellValue(row.getCell(1));//学号
|
|
|
|
|
|
|
|
- //重复数据提示
|
|
|
|
|
- long exist = scores.stream().filter(e -> e.getSemester().equals(semester) && e.getCardNo().equals(cardNo) && e.getSubjectId().equals(eSubjectStatu.integerOf(subject))).count();
|
|
|
|
|
- if (exist > 0) {
|
|
|
|
|
- return CommonResult.fail(existData + "成绩数据在系统中已存在,请勿重复导入");
|
|
|
|
|
|
|
+ Optional<SmartUser> user = users.stream().filter(e -> e.getCardNo().equals(cardNo)).findFirst();
|
|
|
|
|
+ if (!(user != null && user.isPresent())) {
|
|
|
|
|
+ return CommonResult.fail("当前系统中不存在" + name + "的学生信息,无法导入成绩");
|
|
|
}
|
|
}
|
|
|
|
|
+ Integer userId = user.get().getId();
|
|
|
|
|
|
|
|
- data.setSemester(semester);
|
|
|
|
|
- data.setSemesterId(semesterStr.getId());
|
|
|
|
|
- data.setGrade(grade);
|
|
|
|
|
|
|
+ String grade = dataFormatter.formatCellValue(row.getCell(3));//年级
|
|
|
Optional<SmartGrade> nowGrade = grades.stream().filter(e -> e.getName().equals(grade)).findFirst();
|
|
Optional<SmartGrade> nowGrade = grades.stream().filter(e -> e.getName().equals(grade)).findFirst();
|
|
|
if (!(nowGrade != null && nowGrade.isPresent())) {
|
|
if (!(nowGrade != null && nowGrade.isPresent())) {
|
|
|
return CommonResult.fail(name + "的年级数据失效,导入失败");
|
|
return CommonResult.fail(name + "的年级数据失效,导入失败");
|
|
|
}
|
|
}
|
|
|
- data.setGradeId(nowGrade.get().getId());
|
|
|
|
|
|
|
+ Integer gradeId = nowGrade.get().getId();
|
|
|
|
|
|
|
|
|
|
+ String schoolClass = dataFormatter.formatCellValue(row.getCell(2));//班级
|
|
|
Optional<SmartClass> nowClass = classes.stream().filter(e -> e.getName().equals(schoolClass)).findFirst();
|
|
Optional<SmartClass> nowClass = classes.stream().filter(e -> e.getName().equals(schoolClass)).findFirst();
|
|
|
if (!(nowClass != null && nowClass.isPresent())) {
|
|
if (!(nowClass != null && nowClass.isPresent())) {
|
|
|
return CommonResult.fail(name + "的班级数据失效,导入失败");
|
|
return CommonResult.fail(name + "的班级数据失效,导入失败");
|
|
|
}
|
|
}
|
|
|
- data.setSchoolClassId(nowClass.get().getId());
|
|
|
|
|
- data.setSchoolClass(schoolClass);
|
|
|
|
|
- data.setCardNo(cardNo);
|
|
|
|
|
- data.setName(name);
|
|
|
|
|
- Optional<SmartUser> user = users.stream().filter(e -> e.getCardNo().equals(cardNo)).findFirst();
|
|
|
|
|
- if (user != null && user.isPresent()) {
|
|
|
|
|
- data.setUserId(user.get().getId());
|
|
|
|
|
- } else {
|
|
|
|
|
- return CommonResult.fail("当前系统中不存在" + name + "的学生信息,无法导入成绩");
|
|
|
|
|
|
|
+ Integer schoolClassId = nowClass.get().getId();
|
|
|
|
|
+
|
|
|
|
|
+ String examType = dataFormatter.formatCellValue(row.getCell(4));//考试类型
|
|
|
|
|
+ Optional<SmartExamtype> examtype = examtypes.stream().filter(e -> e.getGradeId().equals(gradeId) && e.getName().equals(examType)).findFirst();
|
|
|
|
|
+ if (!(examtype != null && examtype.isPresent())) {
|
|
|
|
|
+ return CommonResult.fail(name + "的考试类型数据失效,导入失败");
|
|
|
}
|
|
}
|
|
|
- data.setSubjectId(eSubjectStatu.integerOf(subject));
|
|
|
|
|
- data.setExamType(eExamType.integerOf(examType));
|
|
|
|
|
- data.setScore(Double.valueOf(score));
|
|
|
|
|
|
|
+ Integer examTypeId = examtype.get().getId();
|
|
|
|
|
|
|
|
- result.add(data);
|
|
|
|
|
|
|
+ String semesterStr = dataFormatter.formatCellValue(row.getCell(5));//学期
|
|
|
|
|
+ Optional<SmartSemester> semester = semesters.stream().filter(e -> e.getName().equals(semesterStr)).findFirst();
|
|
|
|
|
+ if (!(semester != null && semester.isPresent())) {
|
|
|
|
|
+ return CommonResult.fail(name + "的学期数据失效,导入失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ Integer semesterId = semester.get().getId();
|
|
|
|
|
+
|
|
|
|
|
+ int sds = titleRow.getLastCellNum();
|
|
|
|
|
+ for (int i = 6; i < titleRow.getLastCellNum(); i++) {
|
|
|
|
|
+ String score = dataFormatter.formatCellValue(row.getCell(i));//成绩
|
|
|
|
|
+ if (StringUtils.hasText(score)) {
|
|
|
|
|
+ String subjectStr = dataFormatter.formatCellValue(titleRow.getCell(i));//科目
|
|
|
|
|
+ Optional<SmartSubject> subject = subjects.stream().filter(e -> e.getName().equals(subjectStr)).findFirst();
|
|
|
|
|
+ if (subject != null && subject.isPresent()) {
|
|
|
|
|
+ //数据重复性判断 学期 + 学号 + 科目
|
|
|
|
|
+ String existData = semester + cardNo + subject;
|
|
|
|
|
+ scoreNames.add(existData);
|
|
|
|
|
+ if (scoreNames.stream().distinct().count() != scoreNames.size()) {
|
|
|
|
|
+ return CommonResult.fail("导入的Excel中的" + existData + "存在重复数据");
|
|
|
|
|
+ }
|
|
|
|
|
+ //重复数据提示
|
|
|
|
|
+ long exist = scores.stream().filter(e -> e.getSemester().equals(semester) && e.getCardNo().equals(cardNo) && e.getSubjectId().equals(subject.get().getId())).count();
|
|
|
|
|
+ if (exist > 0) {
|
|
|
|
|
+ return CommonResult.fail(existData + "成绩数据在系统中已存在,请勿重复导入");
|
|
|
|
|
+ }
|
|
|
|
|
+ SmartScore data = new SmartScore();
|
|
|
|
|
+ data.setSemesterId(semesterId);
|
|
|
|
|
+ data.setSemester(semesterStr);
|
|
|
|
|
+ data.setGradeId(gradeId);
|
|
|
|
|
+ data.setGrade(grade);
|
|
|
|
|
+ data.setSchoolClassId(schoolClassId);
|
|
|
|
|
+ data.setSchoolClass(schoolClass);
|
|
|
|
|
+ data.setCardNo(cardNo);
|
|
|
|
|
+ data.setName(name);
|
|
|
|
|
+ data.setUserId(userId);
|
|
|
|
|
+ data.setSubjectId(subject.get().getId());
|
|
|
|
|
+ data.setExamType(examTypeId);
|
|
|
|
|
+ data.setScore(Double.valueOf(score));
|
|
|
|
|
+ result.add(data);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return CommonResult.fail(subjectStr + "科目数据在系统中不存在,导入失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
@@ -777,6 +804,21 @@ public class SmartScoreController implements SmartScoreControllerAPI {
|
|
|
if (grades == null) {
|
|
if (grades == null) {
|
|
|
return CommonResult.fail("系统年级数据为空,导入失败");
|
|
return CommonResult.fail("系统年级数据为空,导入失败");
|
|
|
}
|
|
}
|
|
|
|
|
+ //获取科目
|
|
|
|
|
+ List<SmartSubject> subjects = smartSubjectService.list(null);
|
|
|
|
|
+ if (subjects == null) {
|
|
|
|
|
+ return CommonResult.fail("科目数据为空,导入失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ //考试类型
|
|
|
|
|
+ List<SmartExamtype> examtypes = smartExamtypeService.list(null);
|
|
|
|
|
+ if (examtypes == null) {
|
|
|
|
|
+ return CommonResult.fail("考试类型数据为空,导入失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ //学期
|
|
|
|
|
+ List<SmartSemester> semesters = smartSemesterService.list(null);
|
|
|
|
|
+ if (semesters == null) {
|
|
|
|
|
+ return CommonResult.fail("学期数据为空,导入失败");
|
|
|
|
|
+ }
|
|
|
//获取班级
|
|
//获取班级
|
|
|
List<SmartClass> classes = smartClassService.list(null);
|
|
List<SmartClass> classes = smartClassService.list(null);
|
|
|
if (classes == null) {
|
|
if (classes == null) {
|
|
@@ -786,102 +828,114 @@ public class SmartScoreController implements SmartScoreControllerAPI {
|
|
|
DataFormatter dataFormatter = new DataFormatter();
|
|
DataFormatter dataFormatter = new DataFormatter();
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
|
|
+ XSSFRow titleRow = sheetAt.getRow(1);
|
|
|
//sheetAt.getLastRowNum():从0开始统计数量 所以得+1
|
|
//sheetAt.getLastRowNum():从0开始统计数量 所以得+1
|
|
|
- for (int rowNum = 0; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
|
|
|
|
|
|
|
+ for (int rowNum = 1; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
|
|
|
|
|
|
|
|
XSSFRow row = sheetAt.getRow(rowNum);
|
|
XSSFRow row = sheetAt.getRow(rowNum);
|
|
|
|
|
|
|
|
//判断每一列单元格是否符合规则
|
|
//判断每一列单元格是否符合规则
|
|
|
- if (rowNum == 0) {
|
|
|
|
|
- String semester = dataFormatter.formatCellValue(row.getCell(0));//学期
|
|
|
|
|
- if (!semester.equals("学期")) {
|
|
|
|
|
- return CommonResult.fail("导入数据第一列为学期");
|
|
|
|
|
|
|
+ if (rowNum == 1) {
|
|
|
|
|
+ String name = dataFormatter.formatCellValue(titleRow.getCell(0));//姓名
|
|
|
|
|
+ if (!name.equals("姓名")) {
|
|
|
|
|
+ return CommonResult.fail("导入数据第一列为姓名");
|
|
|
}
|
|
}
|
|
|
- String grade = dataFormatter.formatCellValue(row.getCell(1));//年级
|
|
|
|
|
- if (!grade.equals("年级")) {
|
|
|
|
|
- return CommonResult.fail("导入数据第二列为年级");
|
|
|
|
|
|
|
+ String cardNo = dataFormatter.formatCellValue(titleRow.getCell(1));//学号
|
|
|
|
|
+ if (!cardNo.equals("学号")) {
|
|
|
|
|
+ return CommonResult.fail("导入数据第二列为学号");
|
|
|
}
|
|
}
|
|
|
- String schoolClass = dataFormatter.formatCellValue(row.getCell(2));//班级
|
|
|
|
|
|
|
+ String schoolClass = dataFormatter.formatCellValue(titleRow.getCell(2));//班级
|
|
|
if (!schoolClass.equals("班级")) {
|
|
if (!schoolClass.equals("班级")) {
|
|
|
return CommonResult.fail("导入数据第三列为班级");
|
|
return CommonResult.fail("导入数据第三列为班级");
|
|
|
}
|
|
}
|
|
|
- String subject = dataFormatter.formatCellValue(row.getCell(3));//学科
|
|
|
|
|
- if (!subject.equals("学科")) {
|
|
|
|
|
- return CommonResult.fail("导入数据第四列为学科");
|
|
|
|
|
|
|
+ String grade = dataFormatter.formatCellValue(titleRow.getCell(3));//年级
|
|
|
|
|
+ if (!grade.equals("年级")) {
|
|
|
|
|
+ return CommonResult.fail("导入数据第四列为年级");
|
|
|
}
|
|
}
|
|
|
- String examType = dataFormatter.formatCellValue(row.getCell(4));//考试类型
|
|
|
|
|
|
|
+ String examType = dataFormatter.formatCellValue(titleRow.getCell(4));//考试类型
|
|
|
if (!examType.equals("考试类型")) {
|
|
if (!examType.equals("考试类型")) {
|
|
|
- return CommonResult.fail("导入数据第四列为考试类型");
|
|
|
|
|
- }
|
|
|
|
|
- String name = dataFormatter.formatCellValue(row.getCell(5));//姓名
|
|
|
|
|
- if (!name.equals("姓名")) {
|
|
|
|
|
- return CommonResult.fail("导入数据第四列为姓名");
|
|
|
|
|
- }
|
|
|
|
|
- String cardNo = dataFormatter.formatCellValue(row.getCell(6));//学号
|
|
|
|
|
- if (!cardNo.equals("学号")) {
|
|
|
|
|
- return CommonResult.fail("导入数据第四列为学号");
|
|
|
|
|
- }
|
|
|
|
|
- String score = dataFormatter.formatCellValue(row.getCell(7));//成绩
|
|
|
|
|
- if (!score.equals("成绩")) {
|
|
|
|
|
- return CommonResult.fail("导入数据第四列为成绩");
|
|
|
|
|
|
|
+ return CommonResult.fail("导入数据第五列为考试类型");
|
|
|
}
|
|
}
|
|
|
- } else {
|
|
|
|
|
- SmartScore data = new SmartScore();
|
|
|
|
|
- String semester = dataFormatter.formatCellValue(row.getCell(0));//学期
|
|
|
|
|
- String grade = dataFormatter.formatCellValue(row.getCell(1));//年级
|
|
|
|
|
- String schoolClass = dataFormatter.formatCellValue(row.getCell(2));//班级
|
|
|
|
|
- String subject = dataFormatter.formatCellValue(row.getCell(3));//学科
|
|
|
|
|
- String examType = dataFormatter.formatCellValue(row.getCell(4));//考试类型
|
|
|
|
|
- String name = dataFormatter.formatCellValue(row.getCell(5));//姓名
|
|
|
|
|
- String cardNo = dataFormatter.formatCellValue(row.getCell(6));//学号
|
|
|
|
|
- String score = dataFormatter.formatCellValue(row.getCell(7));//成绩
|
|
|
|
|
-
|
|
|
|
|
- SmartSemester semesterStr = smartSemesterService.querySemesterByName(semester);
|
|
|
|
|
- if (semesterStr == null) {
|
|
|
|
|
- return CommonResult.fail(semester + "学期数据无效,导入失败!");
|
|
|
|
|
|
|
+ String semester = dataFormatter.formatCellValue(titleRow.getCell(5));//学期
|
|
|
|
|
+ if (!semester.equals("学期")) {
|
|
|
|
|
+ return CommonResult.fail("导入数据第六列为学期");
|
|
|
}
|
|
}
|
|
|
|
|
+ } else if (rowNum > 2) {
|
|
|
|
|
|
|
|
- //数据重复性判断 学期 + 学号 + 科目
|
|
|
|
|
- String existData = semester + cardNo + subject;
|
|
|
|
|
- scoreNames.add(existData);
|
|
|
|
|
- if (scoreNames.stream().distinct().count() != scoreNames.size()) {
|
|
|
|
|
- return CommonResult.fail("导入的Excel中的" + existData + "存在重复数据");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ String name = dataFormatter.formatCellValue(row.getCell(0));//姓名
|
|
|
|
|
+ String cardNo = dataFormatter.formatCellValue(row.getCell(1));//学号
|
|
|
|
|
|
|
|
- //重复数据提示
|
|
|
|
|
- long exist = scores.stream().filter(e -> e.getSemester().equals(semester) && e.getCardNo().equals(cardNo) && e.getSubjectId().equals(eSubjectStatu.integerOf(subject))).count();
|
|
|
|
|
- if (exist > 0) {
|
|
|
|
|
- return CommonResult.fail(existData + "成绩数据在系统中已存在,请勿重复导入");
|
|
|
|
|
|
|
+ Optional<SmartUser> user = users.stream().filter(e -> e.getCardNo().equals(cardNo)).findFirst();
|
|
|
|
|
+ if (!(user != null && user.isPresent())) {
|
|
|
|
|
+ return CommonResult.fail("当前系统中不存在" + name + "的学生信息,无法导入成绩");
|
|
|
}
|
|
}
|
|
|
|
|
+ Integer userId = user.get().getId();
|
|
|
|
|
|
|
|
- data.setSemester(semester);
|
|
|
|
|
- data.setSemesterId(semesterStr.getId());
|
|
|
|
|
- data.setGrade(grade);
|
|
|
|
|
|
|
+ String grade = dataFormatter.formatCellValue(row.getCell(3));//年级
|
|
|
Optional<SmartGrade> nowGrade = grades.stream().filter(e -> e.getName().equals(grade)).findFirst();
|
|
Optional<SmartGrade> nowGrade = grades.stream().filter(e -> e.getName().equals(grade)).findFirst();
|
|
|
if (!(nowGrade != null && nowGrade.isPresent())) {
|
|
if (!(nowGrade != null && nowGrade.isPresent())) {
|
|
|
return CommonResult.fail(name + "的年级数据失效,导入失败");
|
|
return CommonResult.fail(name + "的年级数据失效,导入失败");
|
|
|
}
|
|
}
|
|
|
- data.setGradeId(nowGrade.get().getId());
|
|
|
|
|
|
|
+ Integer gradeId = nowGrade.get().getId();
|
|
|
|
|
|
|
|
|
|
+ String schoolClass = dataFormatter.formatCellValue(row.getCell(2));//班级
|
|
|
Optional<SmartClass> nowClass = classes.stream().filter(e -> e.getName().equals(schoolClass)).findFirst();
|
|
Optional<SmartClass> nowClass = classes.stream().filter(e -> e.getName().equals(schoolClass)).findFirst();
|
|
|
if (!(nowClass != null && nowClass.isPresent())) {
|
|
if (!(nowClass != null && nowClass.isPresent())) {
|
|
|
return CommonResult.fail(name + "的班级数据失效,导入失败");
|
|
return CommonResult.fail(name + "的班级数据失效,导入失败");
|
|
|
}
|
|
}
|
|
|
- data.setSchoolClassId(nowClass.get().getId());
|
|
|
|
|
- data.setSchoolClass(schoolClass);
|
|
|
|
|
- data.setCardNo(cardNo);
|
|
|
|
|
- data.setName(name);
|
|
|
|
|
- Optional<SmartUser> user = users.stream().filter(e -> e.getCardNo().equals(cardNo)).findFirst();
|
|
|
|
|
- if (user != null && user.isPresent()) {
|
|
|
|
|
- data.setUserId(user.get().getId());
|
|
|
|
|
- } else {
|
|
|
|
|
- return CommonResult.fail("当前系统中不存在" + name + "的学生信息,无法导入成绩");
|
|
|
|
|
|
|
+ Integer schoolClassId = nowClass.get().getId();
|
|
|
|
|
+
|
|
|
|
|
+ String examType = dataFormatter.formatCellValue(row.getCell(4));//考试类型
|
|
|
|
|
+ Optional<SmartExamtype> examtype = examtypes.stream().filter(e -> e.getGradeId().equals(gradeId) && e.getName().equals(examType)).findFirst();
|
|
|
|
|
+ if (!(examtype != null && examtype.isPresent())) {
|
|
|
|
|
+ return CommonResult.fail(name + "的考试类型数据失效,导入失败");
|
|
|
}
|
|
}
|
|
|
- data.setSubjectId(eSubjectStatu.integerOf(subject));
|
|
|
|
|
- data.setExamType(eExamType.integerOf(examType));
|
|
|
|
|
- data.setScore(Double.valueOf(score));
|
|
|
|
|
|
|
+ Integer examTypeId = examtype.get().getId();
|
|
|
|
|
|
|
|
- result.add(data);
|
|
|
|
|
|
|
+ String semesterStr = dataFormatter.formatCellValue(row.getCell(5));//学期
|
|
|
|
|
+ Optional<SmartSemester> semester = semesters.stream().filter(e -> e.getName().equals(semesterStr)).findFirst();
|
|
|
|
|
+ if (!(semester != null && semester.isPresent())) {
|
|
|
|
|
+ return CommonResult.fail(name + "的学期数据失效,导入失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ Integer semesterId = semester.get().getId();
|
|
|
|
|
+
|
|
|
|
|
+ int sds = titleRow.getLastCellNum();
|
|
|
|
|
+ for (int i = 6; i < titleRow.getLastCellNum(); i++) {
|
|
|
|
|
+ String score = dataFormatter.formatCellValue(row.getCell(i));//成绩
|
|
|
|
|
+ if (StringUtils.hasText(score)) {
|
|
|
|
|
+ String subjectStr = dataFormatter.formatCellValue(titleRow.getCell(i));//科目
|
|
|
|
|
+ Optional<SmartSubject> subject = subjects.stream().filter(e -> e.getName().equals(subjectStr)).findFirst();
|
|
|
|
|
+ if (subject != null && subject.isPresent()) {
|
|
|
|
|
+ //数据重复性判断 学期 + 学号 + 科目
|
|
|
|
|
+ String existData = semester + cardNo + subject;
|
|
|
|
|
+ scoreNames.add(existData);
|
|
|
|
|
+ if (scoreNames.stream().distinct().count() != scoreNames.size()) {
|
|
|
|
|
+ return CommonResult.fail("导入的Excel中的" + existData + "存在重复数据");
|
|
|
|
|
+ }
|
|
|
|
|
+ //重复数据提示
|
|
|
|
|
+ long exist = scores.stream().filter(e -> e.getSemester().equals(semester) && e.getCardNo().equals(cardNo) && e.getSubjectId().equals(subject.get().getId())).count();
|
|
|
|
|
+ if (exist > 0) {
|
|
|
|
|
+ return CommonResult.fail(existData + "成绩数据在系统中已存在,请勿重复导入");
|
|
|
|
|
+ }
|
|
|
|
|
+ SmartScore data = new SmartScore();
|
|
|
|
|
+ data.setSemesterId(semesterId);
|
|
|
|
|
+ data.setSemester(semesterStr);
|
|
|
|
|
+ data.setGradeId(gradeId);
|
|
|
|
|
+ data.setGrade(grade);
|
|
|
|
|
+ data.setSchoolClassId(schoolClassId);
|
|
|
|
|
+ data.setSchoolClass(schoolClass);
|
|
|
|
|
+ data.setCardNo(cardNo);
|
|
|
|
|
+ data.setName(name);
|
|
|
|
|
+ data.setUserId(userId);
|
|
|
|
|
+ data.setSubjectId(subject.get().getId());
|
|
|
|
|
+ data.setExamType(examTypeId);
|
|
|
|
|
+ data.setScore(Double.valueOf(score));
|
|
|
|
|
+ result.add(data);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return CommonResult.fail(subjectStr + "科目数据在系统中不存在,导入失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|