夏文涛 1 год назад
Родитель
Сommit
c8269be47b
1 измененных файлов с 32 добавлено и 18 удалено
  1. 32 18
      src/main/java/com/template/controller/WelcomeBedController.java

+ 32 - 18
src/main/java/com/template/controller/WelcomeBedController.java

@@ -23,6 +23,7 @@ import org.apache.poi.xssf.usermodel.XSSFRow;
 import org.apache.poi.xssf.usermodel.XSSFSheet;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.StringUtils;
 import org.springframework.validation.BindingResult;
 import org.springframework.web.bind.annotation.RequestMapping;
 
@@ -72,14 +73,25 @@ public class WelcomeBedController implements WelcomeBedControllerAPI {
             return CommonResult.fail("该床位号已存在,请勿重复插入!");
         }
 
-        WelcomeStudent student =welcomeStudentService.queryStudentInfo(iwbr.getCollegeId(),iwbr.getMajorId(),iwbr.getClassstrId(),iwbr.getCardNum());
-        if(student == null){
-            return CommonResult.fail("当前学生信息在系统中不存在!");
+        WelcomeBed wb = new WelcomeBed();
+
+        if(StringUtils.hasText(iwbr.getCardNum())){
+            WelcomeStudent student =welcomeStudentService.queryStudentInfo(iwbr.getCollegeId(),iwbr.getMajorId(),iwbr.getClassstrId(),iwbr.getCardNum());
+            if(student == null){
+                return CommonResult.fail("当前学生信息在系统中不存在!");
+            }
+            wb.setStudentCard(student.getCardId());
+            wb.setCollegeId(iwbr.getCollegeId());
+            wb.setCollege(iwbr.getCollege());
+            wb.setMajorId(iwbr.getMajorId());
+            wb.setMajor(iwbr.getMajor());
+            wb.setClassstrId(iwbr.getClassstrId());
+            wb.setClassstr(iwbr.getClassstr());
+            wb.setCardNum(iwbr.getCardNum());
+            wb.setName(iwbr.getName());
         }
 
-        WelcomeBed wb = new WelcomeBed();
         wb.setNumber(iwbr.getNumber());
-        wb.setStudentCard(student.getCardId());
         wb.setSchool(iwbr.getSchool());
         wb.setSchoolId(iwbr.getSchoolId());
         wb.setBuildId(iwbr.getBuildId());
@@ -87,15 +99,7 @@ public class WelcomeBedController implements WelcomeBedControllerAPI {
         wb.setDormitoryId(iwbr.getDormitoryId());
         wb.setDormitory(iwbr.getDormitory());
         wb.setSex(iwbr.getSex());
-        wb.setCollegeId(iwbr.getCollegeId());
-        wb.setCollege(iwbr.getCollege());
-        wb.setMajorId(iwbr.getMajorId());
-        wb.setMajor(iwbr.getMajor());
-        wb.setClassstrId(iwbr.getClassstrId());
-        wb.setClassstr(iwbr.getClassstr());
-        wb.setIsCheck(iwbr.getIsCheck());
-        wb.setCardNum(iwbr.getCardNum());
-        wb.setName(iwbr.getName());
+        wb.setIsCheck(StringUtils.hasText(iwbr.getCardNum()) ? 1 : 0);
         wb.setRemark(iwbr.getRemark());
 
         int result = welcomeBedService.insertWelcomeBed(wb);
@@ -119,13 +123,23 @@ public class WelcomeBedController implements WelcomeBedControllerAPI {
             return CommonResult.fail("该床位号已存在,请勿重复插入!");
         }
 
-        WelcomeStudent student =welcomeStudentService.queryStudentInfo(uwbr.getCollegeId(),uwbr.getMajorId(),uwbr.getClassstrId(),uwbr.getCardNum());
-        if(student == null){
-            return CommonResult.fail("当前学生信息在系统中不存在!");
+        if(StringUtils.hasText(uwbr.getCardNum())){
+            WelcomeStudent student =welcomeStudentService.queryStudentInfo(uwbr.getCollegeId(),uwbr.getMajorId(),uwbr.getClassstrId(),uwbr.getCardNum());
+            if(student == null){
+                return CommonResult.fail("当前学生信息在系统中不存在!");
+            }
+            oldData.setStudentCard(student.getCardId());
+            oldData.setCollegeId(uwbr.getCollegeId());
+            oldData.setCollege(uwbr.getCollege());
+            oldData.setMajorId(uwbr.getMajorId());
+            oldData.setMajor(uwbr.getMajor());
+            oldData.setClassstrId(uwbr.getClassstrId());
+            oldData.setClassstr(uwbr.getClassstr());
+            oldData.setCardNum(uwbr.getCardNum());
+            oldData.setName(uwbr.getName());
         }
 
         oldData.setNumber(uwbr.getNumber());
-        oldData.setStudentCard(student.getCardId());
         oldData.setSchool(uwbr.getSchool());
         oldData.setSchoolId(uwbr.getSchoolId());
         oldData.setBuildId(uwbr.getBuildId());