liu 1 anno fa
parent
commit
06790421a6

+ 25 - 31
src/main/java/com/template/controller/WelcomeDormitoryController.java

@@ -39,6 +39,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.text.ParseException;
 import java.util.ArrayList;
+import java.util.Calendar;
 import java.util.List;
 import java.util.Optional;
 import java.util.stream.Collectors;
@@ -400,6 +401,8 @@ public class WelcomeDormitoryController implements WelcomeDormitoryControllerAPI
         HSSFSheet sheetAt = sheets.getSheetAt(0);
         DataFormatter dataFormatter = new DataFormatter();
 
+        Calendar calendar = Calendar.getInstance();
+        int year = calendar.get(Calendar.YEAR);
         try {
             //rowNum = 3 从第三行开始获取值
             //sheetAt.getLastRowNum():从0开始统计数量 所以得+1
@@ -429,21 +432,17 @@ public class WelcomeDormitoryController implements WelcomeDormitoryControllerAPI
                         if (!sex.equals("寝室性别")) {
                             return CommonResult.fail("导入数据第四列为寝室性别");
                         }
-                        String grade = dataFormatter.formatCellValue(row.getCell(4));//所属年级
-                        if (!grade.equals("所属年级")) {
-                            return CommonResult.fail("导入数据第五列为所属年级");
-                        }
-                        String college = dataFormatter.formatCellValue(row.getCell(5));//所属学院
+                        String college = dataFormatter.formatCellValue(row.getCell(4));//所属学院
                         if (!college.equals("所属学院")) {
-                            return CommonResult.fail("导入数据第列为所属学院");
+                            return CommonResult.fail("导入数据第五列为所属学院");
                         }
-                        String bedNum = dataFormatter.formatCellValue(row.getCell(6));//床位数
+                        String bedNum = dataFormatter.formatCellValue(row.getCell(5));//床位数
                         if (!bedNum.equals("床位数")) {
-                            return CommonResult.fail("导入数据第列为床位数");
+                            return CommonResult.fail("导入数据第列为床位数");
                         }
-                        String remark = dataFormatter.formatCellValue(row.getCell(7));//备注
+                        String remark = dataFormatter.formatCellValue(row.getCell(6));//备注
                         if (!remark.equals("备注")) {
-                            return CommonResult.fail("导入数据第列为备注");
+                            return CommonResult.fail("导入数据第列为备注");
                         }
 
                     } else {
@@ -457,10 +456,9 @@ public class WelcomeDormitoryController implements WelcomeDormitoryControllerAPI
                         }
 
                         String sex = dataFormatter.formatCellValue(row.getCell(3));//寝室性别
-                        String grade = dataFormatter.formatCellValue(row.getCell(4));//所属年级
-                        String college = dataFormatter.formatCellValue(row.getCell(5));//所属学院
-                        String bedNum = dataFormatter.formatCellValue(row.getCell(6));//床位数
-                        String remark = dataFormatter.formatCellValue(row.getCell(7));//备注
+                        String college = dataFormatter.formatCellValue(row.getCell(4));//所属学院
+                        String bedNum = dataFormatter.formatCellValue(row.getCell(5));//床位数
+                        String remark = dataFormatter.formatCellValue(row.getCell(6));//备注
 
                         Optional<WelcomeSchool> wos = ws.stream().filter(e -> e.getSchool().equals(school)).findFirst();
                         if (wos != null && wos.isPresent()) {
@@ -502,7 +500,7 @@ public class WelcomeDormitoryController implements WelcomeDormitoryControllerAPI
                         wd.setStatus(2);
                         wd.setRemark(remark);
                         wd.setRetentionState(1);
-                        wd.setGrade(Integer.valueOf(grade));
+                        wd.setGrade(year);
                         result.add(wd);
                     }
                 }
@@ -534,7 +532,8 @@ public class WelcomeDormitoryController implements WelcomeDormitoryControllerAPI
         //读取第一张sheet
         XSSFSheet sheetAt = sheets.getSheetAt(0);
         DataFormatter dataFormatter = new DataFormatter();
-
+        Calendar calendar = Calendar.getInstance();
+        int year = calendar.get(Calendar.YEAR);
         try {
             //rowNum = 3 从第三行开始获取值
             //sheetAt.getLastRowNum():从0开始统计数量 所以得+1
@@ -564,21 +563,17 @@ public class WelcomeDormitoryController implements WelcomeDormitoryControllerAPI
                         if (!sex.equals("寝室性别")) {
                             return CommonResult.fail("导入数据第四列为寝室性别");
                         }
-                        String grade = dataFormatter.formatCellValue(row.getCell(4));//所属年级
-                        if (!grade.equals("所属年级")) {
-                            return CommonResult.fail("导入数据第五列为所属年级");
-                        }
-                        String college = dataFormatter.formatCellValue(row.getCell(5));//所属学院
+                        String college = dataFormatter.formatCellValue(row.getCell(4));//所属学院
                         if (!college.equals("所属学院")) {
-                            return CommonResult.fail("导入数据第列为所属学院");
+                            return CommonResult.fail("导入数据第五列为所属学院");
                         }
-                        String bedNum = dataFormatter.formatCellValue(row.getCell(6));//床位数
+                        String bedNum = dataFormatter.formatCellValue(row.getCell(5));//床位数
                         if (!bedNum.equals("床位数")) {
-                            return CommonResult.fail("导入数据第列为床位数");
+                            return CommonResult.fail("导入数据第列为床位数");
                         }
-                        String remark = dataFormatter.formatCellValue(row.getCell(7));//备注
+                        String remark = dataFormatter.formatCellValue(row.getCell(6));//备注
                         if (!remark.equals("备注")) {
-                            return CommonResult.fail("导入数据第列为备注");
+                            return CommonResult.fail("导入数据第列为备注");
                         }
 
 
@@ -593,10 +588,9 @@ public class WelcomeDormitoryController implements WelcomeDormitoryControllerAPI
                         }
 
                         String sex = dataFormatter.formatCellValue(row.getCell(3));//寝室性别
-                        String grade = dataFormatter.formatCellValue(row.getCell(4));//所属年级
-                        String college = dataFormatter.formatCellValue(row.getCell(5));//所属学院
-                        String bedNum = dataFormatter.formatCellValue(row.getCell(6));//床位数
-                        String remark = dataFormatter.formatCellValue(row.getCell(7));//备注
+                        String college = dataFormatter.formatCellValue(row.getCell(4));//所属学院
+                        String bedNum = dataFormatter.formatCellValue(row.getCell(5));//床位数
+                        String remark = dataFormatter.formatCellValue(row.getCell(6));//备注
 
                         Optional<WelcomeSchool> wos = ws.stream().filter(e -> e.getSchool().equals(school)).findFirst();
                         if (wos != null && wos.isPresent()) {
@@ -637,7 +631,7 @@ public class WelcomeDormitoryController implements WelcomeDormitoryControllerAPI
                         wd.setStatus(2);
                         wd.setRemark(remark);
                         wd.setRetentionState(1);
-                        wd.setGrade(Integer.valueOf(grade));
+                        wd.setGrade(year);
                         result.add(wd);
                     }
                 }