Browse Source

更新楼栋,寝室,床位导入导出

liu 1 year ago
parent
commit
66b7a624df

+ 139 - 123
src/main/java/com/template/controller/WelcomeBedController.java

@@ -66,6 +66,9 @@ public class WelcomeBedController implements WelcomeBedControllerAPI {
     @Autowired
     @Autowired
     private WelcomeDormitoryService welcomeDormitoryService;
     private WelcomeDormitoryService welcomeDormitoryService;
 
 
+    @Autowired
+    private WelcomeSchoolService welcomeSchoolService;
+
     @Override
     @Override
     public CommonResult insertBedInfo(InsertWelcomeBedRequest iwbr, BindingResult bindingResult) {
     public CommonResult insertBedInfo(InsertWelcomeBedRequest iwbr, BindingResult bindingResult) {
         if (bindingResult.hasErrors()) {
         if (bindingResult.hasErrors()) {
@@ -270,6 +273,7 @@ public class WelcomeBedController implements WelcomeBedControllerAPI {
         List<WelcomeOrg> wos = welcomeOrgService.list(null);
         List<WelcomeOrg> wos = welcomeOrgService.list(null);
         List<WelcomeBuild> wbils = welcomeBuildService.list(null);
         List<WelcomeBuild> wbils = welcomeBuildService.list(null);
         List<WelcomeDormitory> wds = welcomeDormitoryService.list(null);
         List<WelcomeDormitory> wds = welcomeDormitoryService.list(null);
+        List<WelcomeSchool> ws = welcomeSchoolService.list(null);
 
 
         //读取第一张sheet
         //读取第一张sheet
         HSSFSheet sheetAt = sheets.getSheetAt(0);
         HSSFSheet sheetAt = sheets.getSheetAt(0);
@@ -287,99 +291,82 @@ public class WelcomeBedController implements WelcomeBedControllerAPI {
                     //所以先使用setCellType()方法先将该单元格的类型设置为STRING
                     //所以先使用setCellType()方法先将该单元格的类型设置为STRING
                     //然后poi会根据字符串读取它
                     //然后poi会根据字符串读取它
                     if (rowNum == 0) {
                     if (rowNum == 0) {
-                        String num = dataFormatter.formatCellValue(row.getCell(0));//序号
-                        if (!num.equals("序号")) {
-                            return CommonResult.fail("导入数据第一列为序号");
-                        }
-                        String school = dataFormatter.formatCellValue(row.getCell(1));//序号
+                        String school = dataFormatter.formatCellValue(row.getCell(0));//校区名称
                         if (!school.equals("校区名称")) {
                         if (!school.equals("校区名称")) {
                             return CommonResult.fail("导入数据第一列为校区名称");
                             return CommonResult.fail("导入数据第一列为校区名称");
                         }
                         }
-                        String build = dataFormatter.formatCellValue(row.getCell(2));//校区名称
+                        String build = dataFormatter.formatCellValue(row.getCell(1));//楼栋名称
                         if (!build.equals("楼栋名称")) {
                         if (!build.equals("楼栋名称")) {
                             return CommonResult.fail("导入数据第二列为楼栋名称");
                             return CommonResult.fail("导入数据第二列为楼栋名称");
                         }
                         }
-                        String dormitory = dataFormatter.formatCellValue(row.getCell(3));//楼栋名称
+                        String dormitory = dataFormatter.formatCellValue(row.getCell(2));//寝室号
                         if (!dormitory.equals("寝室号")) {
                         if (!dormitory.equals("寝室号")) {
                             return CommonResult.fail("导入数据第三列为寝室号");
                             return CommonResult.fail("导入数据第三列为寝室号");
                         }
                         }
-                        String number = dataFormatter.formatCellValue(row.getCell(4));//楼栋性别
+                        String number = dataFormatter.formatCellValue(row.getCell(3));//床位号
                         if (!number.equals("床位号")) {
                         if (!number.equals("床位号")) {
                             return CommonResult.fail("导入数据第四列为床位号");
                             return CommonResult.fail("导入数据第四列为床位号");
                         }
                         }
-                        String sex = dataFormatter.formatCellValue(row.getCell(5));//床位性别
+                        String sex = dataFormatter.formatCellValue(row.getCell(4));//床位性别
                         if (!sex.equals("床位性别")) {
                         if (!sex.equals("床位性别")) {
                             return CommonResult.fail("导入数据第五列为床位性别");
                             return CommonResult.fail("导入数据第五列为床位性别");
                         }
                         }
 
 
-                        String grade = dataFormatter.formatCellValue(row.getCell(6));//所属年级
+                        String grade = dataFormatter.formatCellValue(row.getCell(5));//所属年级
                         if (!grade.equals("所属年级")) {
                         if (!grade.equals("所属年级")) {
-                            return CommonResult.fail("导入数据第列为所属年级");
+                            return CommonResult.fail("导入数据第列为所属年级");
                         }
                         }
-                        String college = dataFormatter.formatCellValue(row.getCell(7));//所属学院
+                        String college = dataFormatter.formatCellValue(row.getCell(6));//所属学院
                         if (!college.equals("所属学院")) {
                         if (!college.equals("所属学院")) {
-                            return CommonResult.fail("导入数据第列为所属学院");
+                            return CommonResult.fail("导入数据第列为所属学院");
                         }
                         }
-                        String major = dataFormatter.formatCellValue(row.getCell(8));//所属专业
+                        String major = dataFormatter.formatCellValue(row.getCell(7));//所属专业
                         if (!major.equals("所属专业")) {
                         if (!major.equals("所属专业")) {
-                            return CommonResult.fail("导入数据第列为所属专业");
+                            return CommonResult.fail("导入数据第列为所属专业");
                         }
                         }
-                        String classstr = dataFormatter.formatCellValue(row.getCell(9));//备注
+                        String classstr = dataFormatter.formatCellValue(row.getCell(8));//所属班级
                         if (!classstr.equals("所属班级")) {
                         if (!classstr.equals("所属班级")) {
-                            return CommonResult.fail("导入数据第列为所属班级");
+                            return CommonResult.fail("导入数据第列为所属班级");
                         }
                         }
-                        String instructor = dataFormatter.formatCellValue(row.getCell(10));//备注
+                        String instructor = dataFormatter.formatCellValue(row.getCell(9));//辅导员
                         if (!instructor.equals("辅导员")) {
                         if (!instructor.equals("辅导员")) {
-                            return CommonResult.fail("导入数据第列为辅导员");
+                            return CommonResult.fail("导入数据第列为辅导员");
                         }
                         }
-                        String isCheck = dataFormatter.formatCellValue(row.getCell(11));//备注
-                        if (!isCheck.equals("是否入住")) {
-                            return CommonResult.fail("导入数据第十列为是否入住");
-                        }
-                        String admissNum = dataFormatter.formatCellValue(row.getCell(12));//备注
-                        if (!admissNum.equals("录取号")) {
-                            return CommonResult.fail("导入数据第十一列为录取号");
-                        }
-                        String name = dataFormatter.formatCellValue(row.getCell(13));//备注
-                        if (!name.equals("姓名")) {
-                            return CommonResult.fail("导入数据第十二列为姓名");
-                        }
-                        String remark = dataFormatter.formatCellValue(row.getCell(14));//备注
+                        String remark = dataFormatter.formatCellValue(row.getCell(10));//备注
                         if (!remark.equals("备注")) {
                         if (!remark.equals("备注")) {
-                            return CommonResult.fail("导入数据第十三列为备注");
-                        }
-                        String retentionState = dataFormatter.formatCellValue(row.getCell(15));//是否保留
-                        if (!retentionState.equals("是否保留")) {
-                            return CommonResult.fail("导入数据第十四列为是否保留");
+                            return CommonResult.fail("导入数据第十一列为备注");
                         }
                         }
 
 
                     } else {
                     } else {
                         WelcomeBed bedData = new WelcomeBed();
                         WelcomeBed bedData = new WelcomeBed();
-
-                        String school = dataFormatter.formatCellValue(row.getCell(1));//校区
-                        String build = dataFormatter.formatCellValue(row.getCell(2));//楼栋
-                        String dormitory = dataFormatter.formatCellValue(row.getCell(3));//寝室号
-                        String number = dataFormatter.formatCellValue(row.getCell(4));//床位号
+                        String school = dataFormatter.formatCellValue(row.getCell(0));//校区
+                        String build = dataFormatter.formatCellValue(row.getCell(1));//楼栋
+                        String dormitory = dataFormatter.formatCellValue(row.getCell(2));//寝室号
+                        String number = dataFormatter.formatCellValue(row.getCell(3));//床位号
                         Optional<WelcomeBed> ob = wb.stream().filter(e -> e.getSchool().equals(school) && e.getBuild().equals(build)
                         Optional<WelcomeBed> ob = wb.stream().filter(e -> e.getSchool().equals(school) && e.getBuild().equals(build)
                                 && e.getDormitory().equals(dormitory) && e.getNumber().intValue() == Integer.valueOf(number).intValue()).findFirst();
                                 && e.getDormitory().equals(dormitory) && e.getNumber().intValue() == Integer.valueOf(number).intValue()).findFirst();
                         if (ob != null && ob.isPresent()) {
                         if (ob != null && ob.isPresent()) {
-                            bedData.setId(ob.get().getId());
+                            return CommonResult.fail("第"+rowNum+1+"行,已存在该床位");
                         }
                         }
 
 
-                        String sex = dataFormatter.formatCellValue(row.getCell(5));//楼栋层数
-                        String grade = dataFormatter.formatCellValue(row.getCell(6));//起始层数
-                        String college = dataFormatter.formatCellValue(row.getCell(7));//起始层数
-                        String major = dataFormatter.formatCellValue(row.getCell(8));//备注
-                        String classstr = dataFormatter.formatCellValue(row.getCell(9));//备注
-                        String instructor = dataFormatter.formatCellValue(row.getCell(10));//辅导员
-                        String isCheck = dataFormatter.formatCellValue(row.getCell(11));//备注
-                        String admissNum = dataFormatter.formatCellValue(row.getCell(12));//备注
-                        String name = dataFormatter.formatCellValue(row.getCell(13));//备注
-                        String remark = dataFormatter.formatCellValue(row.getCell(14));//备注
-                        String retentionState = dataFormatter.formatCellValue(row.getCell(15));//是否保留
-
-
-                        bedData.setSchool(school);
+                        String sex = dataFormatter.formatCellValue(row.getCell(4));//床位性别
+                        String grade = dataFormatter.formatCellValue(row.getCell(5));//所属年级
+                        String college = dataFormatter.formatCellValue(row.getCell(6));//所属学院
+                        String major = dataFormatter.formatCellValue(row.getCell(7));//所属专业
+                        String classstr = dataFormatter.formatCellValue(row.getCell(8));//所属班级
+                        String instructor = dataFormatter.formatCellValue(row.getCell(9));//辅导员
+                        String remark = dataFormatter.formatCellValue(row.getCell(10));//备注
+
+                        //校区
+                        if (ws != null && ws.size() > 0) {
+                            Optional<WelcomeSchool> wsl = ws.stream().filter(e -> e.getSchool().equals(school)).findFirst();
+                            if (wsl != null && wsl.isPresent()) {
+                                bedData.setSchoolId(wsl.get().getId());
+                                bedData.setSchool(school);
+                            } else {
+                                return CommonResult.fail("第" + rowNum + 1 + "行,不存在该校区");
+                            }
+                        }
 
 
                         //楼栋
                         //楼栋
                         if (wbils != null && wbils.size() > 0) {
                         if (wbils != null && wbils.size() > 0) {
@@ -387,6 +374,8 @@ public class WelcomeBedController implements WelcomeBedControllerAPI {
                             if (oBuild != null && oBuild.isPresent()) {
                             if (oBuild != null && oBuild.isPresent()) {
                                 bedData.setBuild(build);
                                 bedData.setBuild(build);
                                 bedData.setBuildId(oBuild.get().getId());
                                 bedData.setBuildId(oBuild.get().getId());
+                            }else {
+                                return CommonResult.fail("第" + rowNum + 1 + "行,不存在该楼栋");
                             }
                             }
                         }
                         }
 
 
@@ -394,8 +383,17 @@ public class WelcomeBedController implements WelcomeBedControllerAPI {
                         if (wds != null && wds.size() > 0) {
                         if (wds != null && wds.size() > 0) {
                             Optional<WelcomeDormitory> oDormitory = wds.stream().filter(e -> e.getDormitory().equals(dormitory)).findFirst();
                             Optional<WelcomeDormitory> oDormitory = wds.stream().filter(e -> e.getDormitory().equals(dormitory)).findFirst();
                             if (oDormitory != null && oDormitory.isPresent()) {
                             if (oDormitory != null && oDormitory.isPresent()) {
+                                if (!oDormitory.get().getSex().equals(sex)) {
+                                    return CommonResult.fail("第" + rowNum + 1 + "行,床位性别和寝室性别不一致");
+                                }
+                                if (!oDormitory.get().getCollege().equals(college)) {
+                                    return CommonResult.fail("第" + rowNum + 1 + "行,床位院系和寝室院系不一致");
+                                }
+
                                 bedData.setDormitory(dormitory);
                                 bedData.setDormitory(dormitory);
                                 bedData.setDormitoryId(oDormitory.get().getId());
                                 bedData.setDormitoryId(oDormitory.get().getId());
+                            }else {
+                                return CommonResult.fail("第" + rowNum + 1 + "行,不存在该寝室号");
                             }
                             }
                         }
                         }
 
 
@@ -407,26 +405,30 @@ public class WelcomeBedController implements WelcomeBedControllerAPI {
                         if (owo != null && owo.isPresent()) {
                         if (owo != null && owo.isPresent()) {
                             bedData.setCollege(college);
                             bedData.setCollege(college);
                             bedData.setCollegeId(owo.get().getId());
                             bedData.setCollegeId(owo.get().getId());
+                        }else {
+                            return CommonResult.fail("第" + rowNum + 1 + "行,不存在该院系");
                         }
                         }
 
 
                         Optional<WelcomeOrg> omwo = wos.stream().filter(e -> e.getName().equals(major)).findFirst();
                         Optional<WelcomeOrg> omwo = wos.stream().filter(e -> e.getName().equals(major)).findFirst();
                         if (omwo != null && omwo.isPresent()) {
                         if (omwo != null && omwo.isPresent()) {
                             bedData.setMajor(major);
                             bedData.setMajor(major);
                             bedData.setMajorId(omwo.get().getId());
                             bedData.setMajorId(omwo.get().getId());
+                        }else {
+                            return CommonResult.fail("第" + rowNum + 1 + "行,不存在该专业");
                         }
                         }
 
 
                         Optional<WelcomeOrg> ocwo = wos.stream().filter(e -> e.getName().equals(classstr)).findFirst();
                         Optional<WelcomeOrg> ocwo = wos.stream().filter(e -> e.getName().equals(classstr)).findFirst();
                         if (ocwo != null && ocwo.isPresent()) {
                         if (ocwo != null && ocwo.isPresent()) {
                             bedData.setClassstr(classstr);
                             bedData.setClassstr(classstr);
                             bedData.setClassstrId(ocwo.get().getId());
                             bedData.setClassstrId(ocwo.get().getId());
+                        }else {
+                            return CommonResult.fail("第" + rowNum + 1 + "行,不存在该班级");
                         }
                         }
                         //endregion
                         //endregion
 
 
-                        bedData.setIsCheck(Integer.valueOf(isCheck));
-                        bedData.setCardNum(admissNum);
-                        bedData.setName(name);
+                        bedData.setIsCheck(0);
                         bedData.setRemark(remark);
                         bedData.setRemark(remark);
-                        bedData.setRetentionState(Integer.valueOf(retentionState));
+                        bedData.setRetentionState(1);
                         bedData.setInstructor(instructor);
                         bedData.setInstructor(instructor);
                         bedData.setGrade(Integer.valueOf(grade));
                         bedData.setGrade(Integer.valueOf(grade));
                         result.add(bedData);
                         result.add(bedData);
@@ -456,7 +458,7 @@ public class WelcomeBedController implements WelcomeBedControllerAPI {
         List<WelcomeOrg> wos = welcomeOrgService.list(null);
         List<WelcomeOrg> wos = welcomeOrgService.list(null);
         List<WelcomeBuild> wbils = welcomeBuildService.list(null);
         List<WelcomeBuild> wbils = welcomeBuildService.list(null);
         List<WelcomeDormitory> wds = welcomeDormitoryService.list(null);
         List<WelcomeDormitory> wds = welcomeDormitoryService.list(null);
-
+        List<WelcomeSchool> ws = welcomeSchoolService.list(null);
         //读取第一张sheet
         //读取第一张sheet
         XSSFSheet sheetAt = sheets.getSheetAt(0);
         XSSFSheet sheetAt = sheets.getSheetAt(0);
         DataFormatter dataFormatter = new DataFormatter();
         DataFormatter dataFormatter = new DataFormatter();
@@ -473,97 +475,82 @@ public class WelcomeBedController implements WelcomeBedControllerAPI {
                     //所以先使用setCellType()方法先将该单元格的类型设置为STRING
                     //所以先使用setCellType()方法先将该单元格的类型设置为STRING
                     //然后poi会根据字符串读取它
                     //然后poi会根据字符串读取它
                     if (rowNum == 0) {
                     if (rowNum == 0) {
-                        String num = dataFormatter.formatCellValue(row.getCell(0));//序号
-                        if (!num.equals("序号")) {
-                            return CommonResult.fail("导入数据第一列为序号");
-                        }
-                        String school = dataFormatter.formatCellValue(row.getCell(1));//序号
+                        String school = dataFormatter.formatCellValue(row.getCell(0));//校区名称
                         if (!school.equals("校区名称")) {
                         if (!school.equals("校区名称")) {
                             return CommonResult.fail("导入数据第一列为校区名称");
                             return CommonResult.fail("导入数据第一列为校区名称");
                         }
                         }
-                        String build = dataFormatter.formatCellValue(row.getCell(2));//校区名称
+                        String build = dataFormatter.formatCellValue(row.getCell(1));//楼栋名称
                         if (!build.equals("楼栋名称")) {
                         if (!build.equals("楼栋名称")) {
                             return CommonResult.fail("导入数据第二列为楼栋名称");
                             return CommonResult.fail("导入数据第二列为楼栋名称");
                         }
                         }
-                        String dormitory = dataFormatter.formatCellValue(row.getCell(3));//楼栋名称
+                        String dormitory = dataFormatter.formatCellValue(row.getCell(2));//寝室号
                         if (!dormitory.equals("寝室号")) {
                         if (!dormitory.equals("寝室号")) {
                             return CommonResult.fail("导入数据第三列为寝室号");
                             return CommonResult.fail("导入数据第三列为寝室号");
                         }
                         }
-                        String number = dataFormatter.formatCellValue(row.getCell(4));//楼栋性别
+                        String number = dataFormatter.formatCellValue(row.getCell(3));//床位号
                         if (!number.equals("床位号")) {
                         if (!number.equals("床位号")) {
                             return CommonResult.fail("导入数据第四列为床位号");
                             return CommonResult.fail("导入数据第四列为床位号");
                         }
                         }
-                        String sex = dataFormatter.formatCellValue(row.getCell(5));//楼栋层数
+                        String sex = dataFormatter.formatCellValue(row.getCell(4));//床位性别
                         if (!sex.equals("床位性别")) {
                         if (!sex.equals("床位性别")) {
                             return CommonResult.fail("导入数据第五列为床位性别");
                             return CommonResult.fail("导入数据第五列为床位性别");
                         }
                         }
-                        String grade = dataFormatter.formatCellValue(row.getCell(6));//起始层数
+
+                        String grade = dataFormatter.formatCellValue(row.getCell(5));//所属年级
                         if (!grade.equals("所属年级")) {
                         if (!grade.equals("所属年级")) {
                             return CommonResult.fail("导入数据第六列为所属年级");
                             return CommonResult.fail("导入数据第六列为所属年级");
                         }
                         }
-
-                        String college = dataFormatter.formatCellValue(row.getCell(7));//起始层数
+                        String college = dataFormatter.formatCellValue(row.getCell(6));//所属学院
                         if (!college.equals("所属学院")) {
                         if (!college.equals("所属学院")) {
-                            return CommonResult.fail("导入数据第列为所属学院");
+                            return CommonResult.fail("导入数据第列为所属学院");
                         }
                         }
-                        String major = dataFormatter.formatCellValue(row.getCell(8));//备注
+                        String major = dataFormatter.formatCellValue(row.getCell(7));//所属专业
                         if (!major.equals("所属专业")) {
                         if (!major.equals("所属专业")) {
-                            return CommonResult.fail("导入数据第列为所属专业");
+                            return CommonResult.fail("导入数据第列为所属专业");
                         }
                         }
-                        String classstr = dataFormatter.formatCellValue(row.getCell(9));//备注
+                        String classstr = dataFormatter.formatCellValue(row.getCell(8));//所属班级
                         if (!classstr.equals("所属班级")) {
                         if (!classstr.equals("所属班级")) {
-                            return CommonResult.fail("导入数据第列为所属班级");
+                            return CommonResult.fail("导入数据第列为所属班级");
                         }
                         }
-                        String instructor = dataFormatter.formatCellValue(row.getCell(10));//备注
+                        String instructor = dataFormatter.formatCellValue(row.getCell(9));//辅导员
                         if (!instructor.equals("辅导员")) {
                         if (!instructor.equals("辅导员")) {
-                            return CommonResult.fail("导入数据第九列为辅导员");
-                        }
-                        String isCheck = dataFormatter.formatCellValue(row.getCell(11));//备注
-                        if (!isCheck.equals("是否入住")) {
-                            return CommonResult.fail("导入数据第十列为是否入住");
+                            return CommonResult.fail("导入数据第十列为辅导员");
                         }
                         }
-                        String admissNum = dataFormatter.formatCellValue(row.getCell(12));//备注
-                        if (!admissNum.equals("录取号")) {
-                            return CommonResult.fail("导入数据第十一列为录取号");
-                        }
-                        String name = dataFormatter.formatCellValue(row.getCell(13));//备注
-                        if (!name.equals("姓名")) {
-                            return CommonResult.fail("导入数据第十二列为姓名");
-                        }
-                        String remark = dataFormatter.formatCellValue(row.getCell(14));//备注
+                        String remark = dataFormatter.formatCellValue(row.getCell(10));//备注
                         if (!remark.equals("备注")) {
                         if (!remark.equals("备注")) {
-                            return CommonResult.fail("导入数据第十三列为备注");
-                        }
-                        String retentionState = dataFormatter.formatCellValue(row.getCell(15));//是否保留
-                        if (!retentionState.equals("是否保留")) {
-                            return CommonResult.fail("导入数据第十四列为是否保留");
+                            return CommonResult.fail("导入数据第十一列为备注");
                         }
                         }
+
                     } else {
                     } else {
                         WelcomeBed bedData = new WelcomeBed();
                         WelcomeBed bedData = new WelcomeBed();
-
-                        String school = dataFormatter.formatCellValue(row.getCell(1));//校区
-                        String build = dataFormatter.formatCellValue(row.getCell(2));//楼栋
-                        String dormitory = dataFormatter.formatCellValue(row.getCell(3));//寝室号
-                        String number = dataFormatter.formatCellValue(row.getCell(4));//床位号
+                        String school = dataFormatter.formatCellValue(row.getCell(0));//校区
+                        String build = dataFormatter.formatCellValue(row.getCell(1));//楼栋
+                        String dormitory = dataFormatter.formatCellValue(row.getCell(2));//寝室号
+                        String number = dataFormatter.formatCellValue(row.getCell(3));//床位号
                         Optional<WelcomeBed> ob = wb.stream().filter(e -> e.getSchool().equals(school) && e.getBuild().equals(build)
                         Optional<WelcomeBed> ob = wb.stream().filter(e -> e.getSchool().equals(school) && e.getBuild().equals(build)
                                 && e.getDormitory().equals(dormitory) && e.getNumber().intValue() == Integer.valueOf(number).intValue()).findFirst();
                                 && e.getDormitory().equals(dormitory) && e.getNumber().intValue() == Integer.valueOf(number).intValue()).findFirst();
                         if (ob != null && ob.isPresent()) {
                         if (ob != null && ob.isPresent()) {
-                            bedData.setId(ob.get().getId());
+                            return CommonResult.fail("第"+rowNum+1+"行,已存在该床位");
                         }
                         }
 
 
-                        String sex = dataFormatter.formatCellValue(row.getCell(5));//楼栋层数
-                        String grade = dataFormatter.formatCellValue(row.getCell(6));//起始层数
-                        String college = dataFormatter.formatCellValue(row.getCell(7));//起始层数
-                        String major = dataFormatter.formatCellValue(row.getCell(8));//备注
-                        String classstr = dataFormatter.formatCellValue(row.getCell(9));//备注
-                        String instructor = dataFormatter.formatCellValue(row.getCell(10));//辅导员
-                        String isCheck = dataFormatter.formatCellValue(row.getCell(11));//备注
-                        String admissNum = dataFormatter.formatCellValue(row.getCell(12));//备注
-                        String name = dataFormatter.formatCellValue(row.getCell(13));//备注
-                        String remark = dataFormatter.formatCellValue(row.getCell(14));//备注
-                        String retentionState = dataFormatter.formatCellValue(row.getCell(15));//是否保留
-
-                        bedData.setSchool(school);
+                        String sex = dataFormatter.formatCellValue(row.getCell(4));//床位性别
+                        String grade = dataFormatter.formatCellValue(row.getCell(5));//所属年级
+                        String college = dataFormatter.formatCellValue(row.getCell(6));//所属学院
+                        String major = dataFormatter.formatCellValue(row.getCell(7));//所属专业
+                        String classstr = dataFormatter.formatCellValue(row.getCell(8));//所属班级
+                        String instructor = dataFormatter.formatCellValue(row.getCell(9));//辅导员
+                        String remark = dataFormatter.formatCellValue(row.getCell(10));//备注
+
+                        //校区
+                        if (ws != null && ws.size() > 0) {
+                            Optional<WelcomeSchool> wsl = ws.stream().filter(e -> e.getSchool().equals(school)).findFirst();
+                            if (wsl != null && wsl.isPresent()) {
+                                bedData.setSchoolId(wsl.get().getId());
+                                bedData.setSchool(school);
+                            } else {
+                                return CommonResult.fail("第" + rowNum + 1 + "行,不存在该校区");
+                            }
+                        }
 
 
                         //楼栋
                         //楼栋
                         if (wbils != null && wbils.size() > 0) {
                         if (wbils != null && wbils.size() > 0) {
@@ -571,6 +558,8 @@ public class WelcomeBedController implements WelcomeBedControllerAPI {
                             if (oBuild != null && oBuild.isPresent()) {
                             if (oBuild != null && oBuild.isPresent()) {
                                 bedData.setBuild(build);
                                 bedData.setBuild(build);
                                 bedData.setBuildId(oBuild.get().getId());
                                 bedData.setBuildId(oBuild.get().getId());
+                            }else {
+                                return CommonResult.fail("第" + rowNum + 1 + "行,不存在该楼栋");
                             }
                             }
                         }
                         }
 
 
@@ -578,8 +567,17 @@ public class WelcomeBedController implements WelcomeBedControllerAPI {
                         if (wds != null && wds.size() > 0) {
                         if (wds != null && wds.size() > 0) {
                             Optional<WelcomeDormitory> oDormitory = wds.stream().filter(e -> e.getDormitory().equals(dormitory)).findFirst();
                             Optional<WelcomeDormitory> oDormitory = wds.stream().filter(e -> e.getDormitory().equals(dormitory)).findFirst();
                             if (oDormitory != null && oDormitory.isPresent()) {
                             if (oDormitory != null && oDormitory.isPresent()) {
+                                if (!oDormitory.get().getSex().equals(sex)) {
+                                    return CommonResult.fail("第" + rowNum + 1 + "行,床位性别和寝室性别不一致");
+                                }
+                                if (!oDormitory.get().getCollege().equals(college)) {
+                                    return CommonResult.fail("第" + rowNum + 1 + "行,床位院系和寝室院系不一致");
+                                }
+
                                 bedData.setDormitory(dormitory);
                                 bedData.setDormitory(dormitory);
                                 bedData.setDormitoryId(oDormitory.get().getId());
                                 bedData.setDormitoryId(oDormitory.get().getId());
+                            }else {
+                                return CommonResult.fail("第" + rowNum + 1 + "行,不存在该寝室号");
                             }
                             }
                         }
                         }
 
 
@@ -591,26 +589,30 @@ public class WelcomeBedController implements WelcomeBedControllerAPI {
                         if (owo != null && owo.isPresent()) {
                         if (owo != null && owo.isPresent()) {
                             bedData.setCollege(college);
                             bedData.setCollege(college);
                             bedData.setCollegeId(owo.get().getId());
                             bedData.setCollegeId(owo.get().getId());
+                        }else {
+                            return CommonResult.fail("第" + rowNum + 1 + "行,不存在该院系");
                         }
                         }
 
 
                         Optional<WelcomeOrg> omwo = wos.stream().filter(e -> e.getName().equals(major)).findFirst();
                         Optional<WelcomeOrg> omwo = wos.stream().filter(e -> e.getName().equals(major)).findFirst();
                         if (omwo != null && omwo.isPresent()) {
                         if (omwo != null && omwo.isPresent()) {
                             bedData.setMajor(major);
                             bedData.setMajor(major);
                             bedData.setMajorId(omwo.get().getId());
                             bedData.setMajorId(omwo.get().getId());
+                        }else {
+                            return CommonResult.fail("第" + rowNum + 1 + "行,不存在该专业");
                         }
                         }
 
 
                         Optional<WelcomeOrg> ocwo = wos.stream().filter(e -> e.getName().equals(classstr)).findFirst();
                         Optional<WelcomeOrg> ocwo = wos.stream().filter(e -> e.getName().equals(classstr)).findFirst();
                         if (ocwo != null && ocwo.isPresent()) {
                         if (ocwo != null && ocwo.isPresent()) {
                             bedData.setClassstr(classstr);
                             bedData.setClassstr(classstr);
                             bedData.setClassstrId(ocwo.get().getId());
                             bedData.setClassstrId(ocwo.get().getId());
+                        }else {
+                            return CommonResult.fail("第" + rowNum + 1 + "行,不存在该班级");
                         }
                         }
                         //endregion
                         //endregion
 
 
-                        bedData.setIsCheck(Integer.valueOf(isCheck));
-                        bedData.setCardNum(admissNum);
-                        bedData.setName(name);
+                        bedData.setIsCheck(0);
                         bedData.setRemark(remark);
                         bedData.setRemark(remark);
-                        bedData.setRetentionState(Integer.valueOf(retentionState));
+                        bedData.setRetentionState(1);
                         bedData.setInstructor(instructor);
                         bedData.setInstructor(instructor);
                         bedData.setGrade(Integer.valueOf(grade));
                         bedData.setGrade(Integer.valueOf(grade));
                         result.add(bedData);
                         result.add(bedData);
@@ -669,10 +671,24 @@ public class WelcomeBedController implements WelcomeBedControllerAPI {
             dataRow.createCell(8).setCellValue(bed.getMajor());
             dataRow.createCell(8).setCellValue(bed.getMajor());
             dataRow.createCell(9).setCellValue(bed.getClassstr());
             dataRow.createCell(9).setCellValue(bed.getClassstr());
             dataRow.createCell(10).setCellValue(bed.getInstructor());
             dataRow.createCell(10).setCellValue(bed.getInstructor());
-            dataRow.createCell(11).setCellValue(bed.getIsCheck());
+            Integer isCheck1 = bed.getIsCheck();
+            String rz="";
+            if (isCheck1==1) {
+                rz="是";
+            }else {
+                rz="否";
+            }
+            dataRow.createCell(11).setCellValue(rz);
             dataRow.createCell(12).setCellValue(bed.getCardNum());
             dataRow.createCell(12).setCellValue(bed.getCardNum());
             dataRow.createCell(13).setCellValue(bed.getName());
             dataRow.createCell(13).setCellValue(bed.getName());
             dataRow.createCell(14).setCellValue(bed.getRemark());
             dataRow.createCell(14).setCellValue(bed.getRemark());
+            Integer retentionState1 = bed.getRetentionState();
+            String bl="";
+            if (1==retentionState1) {
+                bl="否";
+            }else {
+                bl="是";
+            }
             dataRow.createCell(15).setCellValue(bed.getRetentionState());
             dataRow.createCell(15).setCellValue(bed.getRetentionState());
 
 
         }
         }

+ 15 - 6
src/main/java/com/template/controller/WelcomeBuildController.java

@@ -170,7 +170,7 @@ public class WelcomeBuildController implements WelcomeBuildControllerAPI {
     private CommonResult<List<WelcomeBuild>> readXls(InputStream inputStream) throws IOException, ParseException {
     private CommonResult<List<WelcomeBuild>> readXls(InputStream inputStream) throws IOException, ParseException {
         List<WelcomeBuild> result = new ArrayList<>();
         List<WelcomeBuild> result = new ArrayList<>();
         HSSFWorkbook sheets = new HSSFWorkbook(inputStream);
         HSSFWorkbook sheets = new HSSFWorkbook(inputStream);
-
+        List<WelcomeSchool> ws = welcomeSchoolService.list(null);
         List<WelcomeBuild> wb = welcomeBuildService.list(null);
         List<WelcomeBuild> wb = welcomeBuildService.list(null);
 
 
         //读取第一张sheet
         //读取第一张sheet
@@ -222,11 +222,15 @@ public class WelcomeBuildController implements WelcomeBuildControllerAPI {
                         WelcomeBuild buildData = new WelcomeBuild();
                         WelcomeBuild buildData = new WelcomeBuild();
 
 
                         String school = dataFormatter.formatCellValue(row.getCell(1));//校区名称
                         String school = dataFormatter.formatCellValue(row.getCell(1));//校区名称
+                        Optional<WelcomeSchool> wos = ws.stream().filter(e -> e.getSchool().equals(school)).findFirst();
+                        if (wos != null && wos.isPresent()) {
+                            buildData.setSchoolId(wos.get().getId()+"");
+                        }else {
+                            return CommonResult.fail("第"+rowNum+1+"行,不存在该校区");
+                        }
                         String build = dataFormatter.formatCellValue(row.getCell(2));//楼栋名称
                         String build = dataFormatter.formatCellValue(row.getCell(2));//楼栋名称
                         Optional<WelcomeBuild> ob = wb.stream().filter(e -> e.getSchool().equals(school) && e.getBuild().equals(build)).findFirst();
                         Optional<WelcomeBuild> ob = wb.stream().filter(e -> e.getSchool().equals(school) && e.getBuild().equals(build)).findFirst();
                         if (ob != null && ob.isPresent()) {
                         if (ob != null && ob.isPresent()) {
-                            buildData.setId(ob.get().getId());
-                        }else {
                             return CommonResult.fail("第"+rowNum+1+"行,已存在该楼栋");
                             return CommonResult.fail("第"+rowNum+1+"行,已存在该楼栋");
                         }
                         }
 
 
@@ -263,9 +267,10 @@ public class WelcomeBuildController implements WelcomeBuildControllerAPI {
     private CommonResult<List<WelcomeBuild>> readXlsx(InputStream inputStream) throws IOException, ParseException {
     private CommonResult<List<WelcomeBuild>> readXlsx(InputStream inputStream) throws IOException, ParseException {
         List<WelcomeBuild> result = new ArrayList<>();
         List<WelcomeBuild> result = new ArrayList<>();
         XSSFWorkbook sheets = new XSSFWorkbook(inputStream);
         XSSFWorkbook sheets = new XSSFWorkbook(inputStream);
-
+        List<WelcomeSchool> ws = welcomeSchoolService.list(null);
         List<WelcomeBuild> wb = welcomeBuildService.list(null);
         List<WelcomeBuild> wb = welcomeBuildService.list(null);
 
 
+
         //读取第一张sheet
         //读取第一张sheet
         XSSFSheet sheetAt = sheets.getSheetAt(0);
         XSSFSheet sheetAt = sheets.getSheetAt(0);
         DataFormatter dataFormatter = new DataFormatter();
         DataFormatter dataFormatter = new DataFormatter();
@@ -315,11 +320,15 @@ public class WelcomeBuildController implements WelcomeBuildControllerAPI {
                         WelcomeBuild buildData = new WelcomeBuild();
                         WelcomeBuild buildData = new WelcomeBuild();
 
 
                         String school = dataFormatter.formatCellValue(row.getCell(1));//校区名称
                         String school = dataFormatter.formatCellValue(row.getCell(1));//校区名称
+                        Optional<WelcomeSchool> wos = ws.stream().filter(e -> e.getSchool().equals(school)).findFirst();
+                        if (wos != null && wos.isPresent()) {
+                            buildData.setSchoolId(wos.get().getId()+"");
+                        }else {
+                            return CommonResult.fail("第"+rowNum+1+"行,不存在该校区");
+                        }
                         String build = dataFormatter.formatCellValue(row.getCell(2));//楼栋名称
                         String build = dataFormatter.formatCellValue(row.getCell(2));//楼栋名称
                         Optional<WelcomeBuild> ob = wb.stream().filter(e -> e.getSchool().equals(school) && e.getBuild().equals(build)).findFirst();
                         Optional<WelcomeBuild> ob = wb.stream().filter(e -> e.getSchool().equals(school) && e.getBuild().equals(build)).findFirst();
                         if (ob != null && ob.isPresent()) {
                         if (ob != null && ob.isPresent()) {
-                            buildData.setId(ob.get().getId());
-                        }else {
                             return CommonResult.fail("第"+rowNum+1+"行,已存在该楼栋");
                             return CommonResult.fail("第"+rowNum+1+"行,已存在该楼栋");
                         }
                         }
 
 

+ 40 - 8
src/main/java/com/template/controller/WelcomeDormitoryController.java

@@ -65,6 +65,9 @@ public class WelcomeDormitoryController implements WelcomeDormitoryControllerAPI
     @Autowired
     @Autowired
     private WelcomeBedService welcomeBedService;
     private WelcomeBedService welcomeBedService;
 
 
+    @Autowired
+    private WelcomeSchoolService welcomeSchoolService;
+
     @Override
     @Override
     public CommonResult saveDormitory(WelcomeDormitory welcomeDormitory) {
     public CommonResult saveDormitory(WelcomeDormitory welcomeDormitory) {
 
 
@@ -367,6 +370,7 @@ public class WelcomeDormitoryController implements WelcomeDormitoryControllerAPI
         List<WelcomeDormitory> wds = welcomeDormitoryService.list(null);
         List<WelcomeDormitory> wds = welcomeDormitoryService.list(null);
         List<WelcomeBuild> buildDatas = welcomeBuildService.list(null);
         List<WelcomeBuild> buildDatas = welcomeBuildService.list(null);
         List<WelcomeOrg> orgs = welcomeOrgService.list(null);
         List<WelcomeOrg> orgs = welcomeOrgService.list(null);
+        List<WelcomeSchool> ws = welcomeSchoolService.list(null);
 
 
         //读取第一张sheet
         //读取第一张sheet
         HSSFSheet sheetAt = sheets.getSheetAt(0);
         HSSFSheet sheetAt = sheets.getSheetAt(0);
@@ -425,8 +429,6 @@ public class WelcomeDormitoryController implements WelcomeDormitoryControllerAPI
                         WelcomeDormitory wd = new WelcomeDormitory();
                         WelcomeDormitory wd = new WelcomeDormitory();
                         Optional<WelcomeDormitory> owelcomeDormitory = wds.stream().filter(e -> e.getSchool().equals(school) && e.getBuild().equals(build) && e.getDormitory().equals(dormitory)).findFirst();
                         Optional<WelcomeDormitory> owelcomeDormitory = wds.stream().filter(e -> e.getSchool().equals(school) && e.getBuild().equals(build) && e.getDormitory().equals(dormitory)).findFirst();
                         if (owelcomeDormitory != null && owelcomeDormitory.isPresent()) {
                         if (owelcomeDormitory != null && owelcomeDormitory.isPresent()) {
-                            wd.setId(owelcomeDormitory.get().getId());
-                        }else {
                             return CommonResult.fail("第"+rowNum+1+"行,已存在该宿舍");
                             return CommonResult.fail("第"+rowNum+1+"行,已存在该宿舍");
                         }
                         }
 
 
@@ -436,7 +438,15 @@ public class WelcomeDormitoryController implements WelcomeDormitoryControllerAPI
                         String bedNum = dataFormatter.formatCellValue(row.getCell(6));//床位数
                         String bedNum = dataFormatter.formatCellValue(row.getCell(6));//床位数
                         String remark = dataFormatter.formatCellValue(row.getCell(7));//备注
                         String remark = dataFormatter.formatCellValue(row.getCell(7));//备注
 
 
-                        wd.setSchool(school);
+                        Optional<WelcomeSchool> wos = ws.stream().filter(e -> e.getSchool().equals(school)).findFirst();
+                        if (wos != null && wos.isPresent()) {
+                            wd.setSchoolId(wos.get().getId());
+                            wd.setSchool(school);
+                        }else {
+                            return CommonResult.fail("第"+rowNum+1+"行,不存在该校区");
+                        }
+
+
                         Optional<WelcomeBuild> oBuild = buildDatas.stream().filter(e -> e.getSchool().equals(school) && e.getBuild().equals(build)).findFirst();
                         Optional<WelcomeBuild> oBuild = buildDatas.stream().filter(e -> e.getSchool().equals(school) && e.getBuild().equals(build)).findFirst();
                         if (oBuild != null && oBuild.isPresent()) {
                         if (oBuild != null && oBuild.isPresent()) {
                             if (!sex.equals(oBuild.get().getSex())) {
                             if (!sex.equals(oBuild.get().getSex())) {
@@ -491,6 +501,7 @@ public class WelcomeDormitoryController implements WelcomeDormitoryControllerAPI
         List<WelcomeDormitory> wds = welcomeDormitoryService.list(null);
         List<WelcomeDormitory> wds = welcomeDormitoryService.list(null);
         List<WelcomeBuild> buildDatas = welcomeBuildService.list(null);
         List<WelcomeBuild> buildDatas = welcomeBuildService.list(null);
         List<WelcomeOrg> orgs = welcomeOrgService.list(null);
         List<WelcomeOrg> orgs = welcomeOrgService.list(null);
+        List<WelcomeSchool> ws = welcomeSchoolService.list(null);
 
 
         //读取第一张sheet
         //读取第一张sheet
         XSSFSheet sheetAt = sheets.getSheetAt(0);
         XSSFSheet sheetAt = sheets.getSheetAt(0);
@@ -550,8 +561,6 @@ public class WelcomeDormitoryController implements WelcomeDormitoryControllerAPI
                         WelcomeDormitory wd = new WelcomeDormitory();
                         WelcomeDormitory wd = new WelcomeDormitory();
                         Optional<WelcomeDormitory> owelcomeDormitory = wds.stream().filter(e -> e.getSchool().equals(school) && e.getBuild().equals(build) && e.getDormitory().equals(dormitory)).findFirst();
                         Optional<WelcomeDormitory> owelcomeDormitory = wds.stream().filter(e -> e.getSchool().equals(school) && e.getBuild().equals(build) && e.getDormitory().equals(dormitory)).findFirst();
                         if (owelcomeDormitory != null && owelcomeDormitory.isPresent()) {
                         if (owelcomeDormitory != null && owelcomeDormitory.isPresent()) {
-                            wd.setId(owelcomeDormitory.get().getId());
-                        }else {
                             return CommonResult.fail("第"+rowNum+1+"行,已存在该宿舍");
                             return CommonResult.fail("第"+rowNum+1+"行,已存在该宿舍");
                         }
                         }
 
 
@@ -561,7 +570,14 @@ public class WelcomeDormitoryController implements WelcomeDormitoryControllerAPI
                         String bedNum = dataFormatter.formatCellValue(row.getCell(6));//床位数
                         String bedNum = dataFormatter.formatCellValue(row.getCell(6));//床位数
                         String remark = dataFormatter.formatCellValue(row.getCell(7));//备注
                         String remark = dataFormatter.formatCellValue(row.getCell(7));//备注
 
 
-                        wd.setSchool(school);
+                        Optional<WelcomeSchool> wos = ws.stream().filter(e -> e.getSchool().equals(school)).findFirst();
+                        if (wos != null && wos.isPresent()) {
+                            wd.setSchoolId(wos.get().getId());
+                            wd.setSchool(school);
+                        }else {
+                            return CommonResult.fail("第"+rowNum+1+"行,不存在该校区");
+                        }
+
                         Optional<WelcomeBuild> oBuild = buildDatas.stream().filter(e -> e.getSchool().equals(school) && e.getBuild().equals(build)).findFirst();
                         Optional<WelcomeBuild> oBuild = buildDatas.stream().filter(e -> e.getSchool().equals(school) && e.getBuild().equals(build)).findFirst();
                         if (oBuild != null && oBuild.isPresent()) {
                         if (oBuild != null && oBuild.isPresent()) {
                             if (!sex.equals(oBuild.get().getSex())) {
                             if (!sex.equals(oBuild.get().getSex())) {
@@ -636,9 +652,25 @@ public class WelcomeDormitoryController implements WelcomeDormitoryControllerAPI
             dataRow.createCell(5).setCellValue(build.getCollege());
             dataRow.createCell(5).setCellValue(build.getCollege());
             dataRow.createCell(6).setCellValue(build.getBedNumber());
             dataRow.createCell(6).setCellValue(build.getBedNumber());
             dataRow.createCell(7).setCellValue(build.getFreeBedNumber());
             dataRow.createCell(7).setCellValue(build.getFreeBedNumber());
-            dataRow.createCell(8).setCellValue(build.getStatus());
+            Integer status1 = build.getStatus();
+            String zt="";
+            if (status1==1) {
+                zt="满员";
+            }else if (status1==2){
+                zt="全空";
+            }else if (status1==3){
+                zt="缺额";
+            }
+            dataRow.createCell(8).setCellValue(zt);
             dataRow.createCell(9).setCellValue(build.getRemark());
             dataRow.createCell(9).setCellValue(build.getRemark());
-            dataRow.createCell(10).setCellValue(build.getRetentionState());
+            Integer retentionState1 = build.getRetentionState();
+            String bl="";
+            if (1==retentionState1) {
+                bl="否";
+            }else {
+                bl="是";
+            }
+            dataRow.createCell(10).setCellValue(bl);
         }
         }
         // 将工作簿写入文件
         // 将工作簿写入文件
         ExcelUtils.excelDownload(workbook, "寝室信息.xlsx", response);
         ExcelUtils.excelDownload(workbook, "寝室信息.xlsx", response);

+ 1 - 1
src/main/java/com/template/model/vo/WelcomeDormitoryVo.java

@@ -46,6 +46,6 @@ public class WelcomeDormitoryVo {
     @ApiModelProperty(value = "空闲床位数")
     @ApiModelProperty(value = "空闲床位数")
     private Integer freeBedNumber;
     private Integer freeBedNumber;
 
 
-    @ApiModelProperty(value = "保留状态 1:保留,0不保留")
+    @ApiModelProperty(value = "保留状态 1:开放,2保留")
     private Integer retentionState;
     private Integer retentionState;
 }
 }