|
@@ -1,9 +1,42 @@
|
|
|
package com.template.controller;
|
|
package com.template.controller;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+import com.template.api.WelcomeBedControllerAPI;
|
|
|
|
|
+import com.template.common.utils.ExcelUtils;
|
|
|
|
|
+import com.template.common.utils.paramUtils;
|
|
|
|
|
+import com.template.model.enumModel.eFileType;
|
|
|
|
|
+import com.template.model.pojo.*;
|
|
|
|
|
+import com.template.model.request.InsertWelcomeBedRequest;
|
|
|
|
|
+import com.template.model.request.UpdateWelcomeBedRequest;
|
|
|
|
|
+import com.template.model.result.CommonResult;
|
|
|
|
|
+import com.template.model.result.PageUtils;
|
|
|
|
|
+import com.template.model.vo.StudentPageVo;
|
|
|
|
|
+import com.template.services.*;
|
|
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFRow;
|
|
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFSheet;
|
|
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
|
|
+import org.apache.poi.ss.usermodel.DataFormatter;
|
|
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
|
|
+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.validation.BindingResult;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
+
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
|
+import java.io.InputStream;
|
|
|
|
|
+import java.text.ParseException;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Optional;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* <p>
|
|
* <p>
|
|
@@ -14,7 +47,544 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
* @since 2025-06-13
|
|
* @since 2025-06-13
|
|
|
*/
|
|
*/
|
|
|
@RestController
|
|
@RestController
|
|
|
-public class WelcomeBedController {
|
|
|
|
|
|
|
+public class WelcomeBedController implements WelcomeBedControllerAPI {
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private WelcomeOrgService welcomeOrgService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private WelcomeBedService welcomeBedService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private WelcomeBuildService welcomeBuildService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private WelcomeStudentService welcomeStudentService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private WelcomeDormitoryService welcomeDormitoryService;
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public CommonResult insertBedInfo(InsertWelcomeBedRequest iwbr, BindingResult bindingResult) {
|
|
|
|
|
+ if (bindingResult.hasErrors()) {
|
|
|
|
|
+ String st = paramUtils.getParamError(bindingResult);
|
|
|
|
|
+ return CommonResult.fail(st);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ WelcomeBed existData = welcomeBedService.queryBedData(iwbr.getSchool(),iwbr.getBuildId(),iwbr.getDormitoryId(),iwbr.getNumber());
|
|
|
|
|
+ if(existData != null){
|
|
|
|
|
+ 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();
|
|
|
|
|
+ wb.setNumber(iwbr.getNumber());
|
|
|
|
|
+ wb.setStudentCard(student.getCardId());
|
|
|
|
|
+ wb.setSchool(iwbr.getSchool());
|
|
|
|
|
+ wb.setBuildId(iwbr.getBuildId());
|
|
|
|
|
+ wb.setBuild(iwbr.getBuild());
|
|
|
|
|
+ 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.setRemark(iwbr.getRemark());
|
|
|
|
|
+
|
|
|
|
|
+ int result = welcomeBedService.insertWelcomeBed(wb);
|
|
|
|
|
+ return result > 0 ? CommonResult.ok("添加成功!") : CommonResult.fail("添加失败");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public CommonResult updateBedInfo(UpdateWelcomeBedRequest uwbr, BindingResult bindingResult) throws Exception {
|
|
|
|
|
+ if (bindingResult.hasErrors()) {
|
|
|
|
|
+ String st = paramUtils.getParamError(bindingResult);
|
|
|
|
|
+ return CommonResult.fail(st);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ WelcomeBed oldData = welcomeBedService.getBedById(uwbr.getId());
|
|
|
|
|
+ if(oldData == null){
|
|
|
|
|
+ return CommonResult.fail("床位信息已失效,编辑失败");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ WelcomeBed existData = welcomeBedService.queryBedData(uwbr.getSchool(),uwbr.getBuildId(),uwbr.getDormitoryId(),uwbr.getNumber());
|
|
|
|
|
+ if(existData != null && existData.getId().intValue() != uwbr.getId().intValue()){
|
|
|
|
|
+ return CommonResult.fail("该床位号已存在,请勿重复插入!");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ WelcomeStudent student =welcomeStudentService.queryStudentInfo(uwbr.getCollegeId(),uwbr.getMajorId(),uwbr.getClassstrId(),uwbr.getCardNum());
|
|
|
|
|
+ if(student == null){
|
|
|
|
|
+ return CommonResult.fail("当前学生信息在系统中不存在!");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ oldData.setNumber(uwbr.getNumber());
|
|
|
|
|
+ oldData.setStudentCard(student.getCardId());
|
|
|
|
|
+ oldData.setSchool(uwbr.getSchool());
|
|
|
|
|
+ oldData.setBuildId(uwbr.getBuildId());
|
|
|
|
|
+ oldData.setBuild(uwbr.getBuild());
|
|
|
|
|
+ oldData.setDormitoryId(uwbr.getDormitoryId());
|
|
|
|
|
+ oldData.setDormitory(uwbr.getDormitory());
|
|
|
|
|
+ oldData.setSex(uwbr.getSex());
|
|
|
|
|
+ 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.setIsCheck(uwbr.getIsCheck());
|
|
|
|
|
+ oldData.setCardNum(uwbr.getCardNum());
|
|
|
|
|
+ oldData.setName(uwbr.getName());
|
|
|
|
|
+ oldData.setRemark(uwbr.getRemark());
|
|
|
|
|
+
|
|
|
|
|
+ int result = welcomeBedService.updateWelcomeBed(oldData);
|
|
|
|
|
+ return result > 0 ? CommonResult.ok("编辑成功!") : CommonResult.fail("编辑失败");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public CommonResult queryPageBeds(int currentPage, int pageCount, String school, Integer buildId, Integer dormitoryId, String sex, Integer isCheck, Integer collegeId, Integer majorId, Integer classstrId) {
|
|
|
|
|
+ PageUtils<WelcomeBed> result = welcomeBedService.queryPageWelcomeBeds(currentPage, pageCount, school, buildId, dormitoryId, sex, isCheck, collegeId, majorId, classstrId);
|
|
|
|
|
+ return CommonResult.ok(result);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public CommonResult deleteBedInfo(int id) throws Exception {
|
|
|
|
|
+ int result = welcomeBedService.deleteWelcomeBedById(id);
|
|
|
|
|
+ return result > 0 ? CommonResult.ok() : CommonResult.fail();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public CommonResult importBedExcel(MultipartFile file) throws IOException, ParseException {
|
|
|
|
|
+ System.out.println("导入床位信息");
|
|
|
|
|
+ if (file.isEmpty() || file.getSize() == 0) {
|
|
|
|
|
+ return CommonResult.fail("导入文件不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ String ContentType = file.getContentType();
|
|
|
|
|
+ InputStream inputStream = file.getInputStream();
|
|
|
|
|
+ List<WelcomeBed> result = new ArrayList<>();
|
|
|
|
|
+
|
|
|
|
|
+ //xls格式文件
|
|
|
|
|
+ if (ContentType.equals(eFileType.Xls.getValue())) {
|
|
|
|
|
+
|
|
|
|
|
+ CommonResult<List<WelcomeBed>> resultData = readXls(inputStream);
|
|
|
|
|
+ if (!resultData.isSuccess()) {
|
|
|
|
|
+ return resultData;
|
|
|
|
|
+ }
|
|
|
|
|
+ result = resultData.getData();
|
|
|
|
|
+
|
|
|
|
|
+ } else if (ContentType.equals(eFileType.Xlsx.getValue())) {
|
|
|
|
|
+ CommonResult<List<WelcomeBed>> resultData = readXlsx(inputStream);
|
|
|
|
|
+ if (!resultData.isSuccess()) {
|
|
|
|
|
+ return resultData;
|
|
|
|
|
+ }
|
|
|
|
|
+ result = resultData.getData();
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return CommonResult.fail("床位信息数据导入只支持Xls或Xlsx格式文件");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<String> admissNums = result.stream().map(WelcomeBed::getCardNum).distinct().collect(Collectors.toList());
|
|
|
|
|
+ if(admissNums != null && admissNums.size() > 0){
|
|
|
|
|
+ List<WelcomeStudent> students = welcomeStudentService.getDataByAdmissNum(admissNums);
|
|
|
|
|
+ if(students != null && students.size() > 0){
|
|
|
|
|
+ for (WelcomeBed r:result) {
|
|
|
|
|
+ Optional<WelcomeStudent> os = students.stream().filter(e -> e.getAdmissNum().equals(r.getCardNum())).findFirst();
|
|
|
|
|
+ if(os != null && os.isPresent()){
|
|
|
|
|
+ r.setStudentCard(os.get().getCardId());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ boolean resultBool = welcomeBedService.saveOrUpdateBatch(result);
|
|
|
|
|
+
|
|
|
|
|
+ System.out.println("导入楼栋1");
|
|
|
|
|
+ return resultBool ? CommonResult.ok("导入成功") : CommonResult.fail("导入失败");
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * xls文件读取方法
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param inputStream
|
|
|
|
|
+ * @return
|
|
|
|
|
+ * @throws IOException
|
|
|
|
|
+ * @throws ParseException
|
|
|
|
|
+ */
|
|
|
|
|
+ private CommonResult<List<WelcomeBed>> readXls(InputStream inputStream) throws IOException, ParseException {
|
|
|
|
|
+ List<WelcomeBed> result = new ArrayList<>();
|
|
|
|
|
+ HSSFWorkbook sheets = new HSSFWorkbook(inputStream);
|
|
|
|
|
+
|
|
|
|
|
+ List<WelcomeBed> wb = welcomeBedService.list(null);
|
|
|
|
|
+ List<WelcomeOrg> wos = welcomeOrgService.list(null);
|
|
|
|
|
+ List<WelcomeBuild> wbils = welcomeBuildService.list(null);
|
|
|
|
|
+ List<WelcomeDormitory> wds = welcomeDormitoryService.list(null);
|
|
|
|
|
+
|
|
|
|
|
+ //读取第一张sheet
|
|
|
|
|
+ HSSFSheet sheetAt = sheets.getSheetAt(0);
|
|
|
|
|
+ DataFormatter dataFormatter = new DataFormatter();
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ //rowNum = 3 从第三行开始获取值
|
|
|
|
|
+ //sheetAt.getLastRowNum():从0开始统计数量 所以得+1
|
|
|
|
|
+ for (int rowNum = 0; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
|
|
|
|
|
+
|
|
|
|
|
+ HSSFRow row = sheetAt.getRow(rowNum);
|
|
|
|
|
+
|
|
|
|
|
+ if (row != null) {
|
|
|
|
|
+ //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
|
|
|
|
|
+ //所以先使用setCellType()方法先将该单元格的类型设置为STRING
|
|
|
|
|
+ //然后poi会根据字符串读取它
|
|
|
|
|
+ if (rowNum == 0) {
|
|
|
|
|
+ String num = dataFormatter.formatCellValue(row.getCell(0));//序号
|
|
|
|
|
+ if (!num.equals("序号")) {
|
|
|
|
|
+ return CommonResult.fail("导入数据第一列为序号");
|
|
|
|
|
+ }
|
|
|
|
|
+ String school = dataFormatter.formatCellValue(row.getCell(1));//序号
|
|
|
|
|
+ if (!school.equals("校区名称")) {
|
|
|
|
|
+ return CommonResult.fail("导入数据第一列为校区名称");
|
|
|
|
|
+ }
|
|
|
|
|
+ String build = dataFormatter.formatCellValue(row.getCell(2));//校区名称
|
|
|
|
|
+ if (!build.equals("楼栋名称")) {
|
|
|
|
|
+ return CommonResult.fail("导入数据第二列为楼栋名称");
|
|
|
|
|
+ }
|
|
|
|
|
+ String dormitory = dataFormatter.formatCellValue(row.getCell(3));//楼栋名称
|
|
|
|
|
+ if (!dormitory.equals("寝室号")) {
|
|
|
|
|
+ return CommonResult.fail("导入数据第三列为寝室号");
|
|
|
|
|
+ }
|
|
|
|
|
+ String number = dataFormatter.formatCellValue(row.getCell(4));//楼栋性别
|
|
|
|
|
+ if (!number.equals("床位号")) {
|
|
|
|
|
+ return CommonResult.fail("导入数据第四列为床位号");
|
|
|
|
|
+ }
|
|
|
|
|
+ String sex = dataFormatter.formatCellValue(row.getCell(5));//楼栋层数
|
|
|
|
|
+ if (!sex.equals("床位性别")) {
|
|
|
|
|
+ return CommonResult.fail("导入数据第五列为床位性别");
|
|
|
|
|
+ }
|
|
|
|
|
+ String college = dataFormatter.formatCellValue(row.getCell(6));//起始层数
|
|
|
|
|
+ if (!college.equals("所属学院")) {
|
|
|
|
|
+ return CommonResult.fail("导入数据第六列为所属学院");
|
|
|
|
|
+ }
|
|
|
|
|
+ String major = dataFormatter.formatCellValue(row.getCell(7));//备注
|
|
|
|
|
+ if (!major.equals("所属专业")) {
|
|
|
|
|
+ return CommonResult.fail("导入数据第七列为所属专业");
|
|
|
|
|
+ }
|
|
|
|
|
+ String classstr = dataFormatter.formatCellValue(row.getCell(8));//备注
|
|
|
|
|
+ if (!classstr.equals("所属班级")) {
|
|
|
|
|
+ return CommonResult.fail("导入数据第七列为所属班级");
|
|
|
|
|
+ }
|
|
|
|
|
+ String isCheck = dataFormatter.formatCellValue(row.getCell(9));//备注
|
|
|
|
|
+ if (!isCheck.equals("是否入住")) {
|
|
|
|
|
+ return CommonResult.fail("导入数据第七列为是否入住");
|
|
|
|
|
+ }
|
|
|
|
|
+ String admissNum = dataFormatter.formatCellValue(row.getCell(10));//备注
|
|
|
|
|
+ if (!admissNum.equals("录取号")) {
|
|
|
|
|
+ return CommonResult.fail("导入数据第七列为录取号");
|
|
|
|
|
+ }
|
|
|
|
|
+ String name = dataFormatter.formatCellValue(row.getCell(11));//备注
|
|
|
|
|
+ if (!name.equals("姓名")) {
|
|
|
|
|
+ return CommonResult.fail("导入数据第七列为姓名");
|
|
|
|
|
+ }
|
|
|
|
|
+ String remark = dataFormatter.formatCellValue(row.getCell(12));//备注
|
|
|
|
|
+ if (!remark.equals("备注")) {
|
|
|
|
|
+ return CommonResult.fail("导入数据第七列为备注");
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ 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));//床位号
|
|
|
|
|
+ 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();
|
|
|
|
|
+ if(ob != null && ob.isPresent()){
|
|
|
|
|
+ bedData.setId(ob.get().getId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String sex = 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 isCheck = dataFormatter.formatCellValue(row.getCell(9));//备注
|
|
|
|
|
+ String admissNum = dataFormatter.formatCellValue(row.getCell(10));//备注
|
|
|
|
|
+ String name = dataFormatter.formatCellValue(row.getCell(11));//备注
|
|
|
|
|
+ String remark = dataFormatter.formatCellValue(row.getCell(12));//备注
|
|
|
|
|
+
|
|
|
|
|
+ bedData.setSchool(school);
|
|
|
|
|
+
|
|
|
|
|
+ //楼栋
|
|
|
|
|
+ if(wbils != null && wbils.size() > 0){
|
|
|
|
|
+ Optional<WelcomeBuild> oBuild = wbils.stream().filter(e -> e.getBuild().equals(build)).findFirst();
|
|
|
|
|
+ if(oBuild != null && oBuild.isPresent()){
|
|
|
|
|
+ bedData.setBuild(build);
|
|
|
|
|
+ bedData.setBuildId(oBuild.get().getId());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //寝室
|
|
|
|
|
+ if(wds != null && wds.size() > 0){
|
|
|
|
|
+ Optional<WelcomeDormitory> oDormitory = wds.stream().filter(e -> e.getDormitory().equals(dormitory)).findFirst();
|
|
|
|
|
+ if(oDormitory != null && oDormitory.isPresent()){
|
|
|
|
|
+ bedData.setDormitory(dormitory);
|
|
|
|
|
+ bedData.setDormitoryId(oDormitory.get().getId());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ bedData.setNumber(Integer.valueOf(number));
|
|
|
|
|
+ bedData.setSex(sex);
|
|
|
|
|
+
|
|
|
|
|
+ //region 院系专业
|
|
|
|
|
+ Optional<WelcomeOrg> owo = wos.stream().filter(e -> e.getName().equals(college)).findFirst();
|
|
|
|
|
+ if (owo != null && owo.isPresent()) {
|
|
|
|
|
+ bedData.setCollege(college);
|
|
|
|
|
+ bedData.setCollegeId(owo.get().getId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Optional<WelcomeOrg> omwo = wos.stream().filter(e -> e.getName().equals(major)).findFirst();
|
|
|
|
|
+ if (omwo != null && omwo.isPresent()) {
|
|
|
|
|
+ bedData.setMajor(major);
|
|
|
|
|
+ bedData.setMajorId(omwo.get().getId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Optional<WelcomeOrg> ocwo = wos.stream().filter(e -> e.getName().equals(classstr)).findFirst();
|
|
|
|
|
+ if (ocwo != null && ocwo.isPresent()) {
|
|
|
|
|
+ bedData.setClassstr(classstr);
|
|
|
|
|
+ bedData.setClassstrId(ocwo.get().getId());
|
|
|
|
|
+ }
|
|
|
|
|
+ //endregion
|
|
|
|
|
+
|
|
|
|
|
+ bedData.setIsCheck(Integer.valueOf(isCheck));
|
|
|
|
|
+ bedData.setCardNum(admissNum);
|
|
|
|
|
+ bedData.setName(name);
|
|
|
|
|
+ bedData.setRemark(remark);
|
|
|
|
|
+ result.add(bedData);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ return CommonResult.fail("请按模板格式导入数据");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return CommonResult.ok(result);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * xls文件读取方法
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param inputStream
|
|
|
|
|
+ * @return
|
|
|
|
|
+ * @throws IOException
|
|
|
|
|
+ * @throws ParseException
|
|
|
|
|
+ */
|
|
|
|
|
+ private CommonResult<List<WelcomeBed>> readXlsx(InputStream inputStream) throws IOException, ParseException {
|
|
|
|
|
+ List<WelcomeBed> result = new ArrayList<>();
|
|
|
|
|
+ XSSFWorkbook sheets = new XSSFWorkbook(inputStream);
|
|
|
|
|
+
|
|
|
|
|
+ List<WelcomeBed> wb = welcomeBedService.list(null);
|
|
|
|
|
+ List<WelcomeOrg> wos = welcomeOrgService.list(null);
|
|
|
|
|
+ List<WelcomeBuild> wbils = welcomeBuildService.list(null);
|
|
|
|
|
+ List<WelcomeDormitory> wds = welcomeDormitoryService.list(null);
|
|
|
|
|
+
|
|
|
|
|
+ //读取第一张sheet
|
|
|
|
|
+ XSSFSheet sheetAt = sheets.getSheetAt(0);
|
|
|
|
|
+ DataFormatter dataFormatter = new DataFormatter();
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ //rowNum = 3 从第三行开始获取值
|
|
|
|
|
+ //sheetAt.getLastRowNum():从0开始统计数量 所以得+1
|
|
|
|
|
+ for (int rowNum = 0; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
|
|
|
|
|
+
|
|
|
|
|
+ XSSFRow row = sheetAt.getRow(rowNum);
|
|
|
|
|
+
|
|
|
|
|
+ if (row != null) {
|
|
|
|
|
+ //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
|
|
|
|
|
+ //所以先使用setCellType()方法先将该单元格的类型设置为STRING
|
|
|
|
|
+ //然后poi会根据字符串读取它
|
|
|
|
|
+ if (rowNum == 0) {
|
|
|
|
|
+ String num = dataFormatter.formatCellValue(row.getCell(0));//序号
|
|
|
|
|
+ if (!num.equals("序号")) {
|
|
|
|
|
+ return CommonResult.fail("导入数据第一列为序号");
|
|
|
|
|
+ }
|
|
|
|
|
+ String school = dataFormatter.formatCellValue(row.getCell(1));//序号
|
|
|
|
|
+ if (!school.equals("校区名称")) {
|
|
|
|
|
+ return CommonResult.fail("导入数据第一列为校区名称");
|
|
|
|
|
+ }
|
|
|
|
|
+ String build = dataFormatter.formatCellValue(row.getCell(2));//校区名称
|
|
|
|
|
+ if (!build.equals("楼栋名称")) {
|
|
|
|
|
+ return CommonResult.fail("导入数据第二列为楼栋名称");
|
|
|
|
|
+ }
|
|
|
|
|
+ String dormitory = dataFormatter.formatCellValue(row.getCell(3));//楼栋名称
|
|
|
|
|
+ if (!dormitory.equals("寝室号")) {
|
|
|
|
|
+ return CommonResult.fail("导入数据第三列为寝室号");
|
|
|
|
|
+ }
|
|
|
|
|
+ String number = dataFormatter.formatCellValue(row.getCell(4));//楼栋性别
|
|
|
|
|
+ if (!number.equals("床位号")) {
|
|
|
|
|
+ return CommonResult.fail("导入数据第四列为床位号");
|
|
|
|
|
+ }
|
|
|
|
|
+ String sex = dataFormatter.formatCellValue(row.getCell(5));//楼栋层数
|
|
|
|
|
+ if (!sex.equals("床位性别")) {
|
|
|
|
|
+ return CommonResult.fail("导入数据第五列为床位性别");
|
|
|
|
|
+ }
|
|
|
|
|
+ String college = dataFormatter.formatCellValue(row.getCell(6));//起始层数
|
|
|
|
|
+ if (!college.equals("所属学院")) {
|
|
|
|
|
+ return CommonResult.fail("导入数据第六列为所属学院");
|
|
|
|
|
+ }
|
|
|
|
|
+ String major = dataFormatter.formatCellValue(row.getCell(7));//备注
|
|
|
|
|
+ if (!major.equals("所属专业")) {
|
|
|
|
|
+ return CommonResult.fail("导入数据第七列为所属专业");
|
|
|
|
|
+ }
|
|
|
|
|
+ String classstr = dataFormatter.formatCellValue(row.getCell(8));//备注
|
|
|
|
|
+ if (!classstr.equals("所属班级")) {
|
|
|
|
|
+ return CommonResult.fail("导入数据第七列为所属班级");
|
|
|
|
|
+ }
|
|
|
|
|
+ String isCheck = dataFormatter.formatCellValue(row.getCell(9));//备注
|
|
|
|
|
+ if (!isCheck.equals("是否入住")) {
|
|
|
|
|
+ return CommonResult.fail("导入数据第七列为是否入住");
|
|
|
|
|
+ }
|
|
|
|
|
+ String admissNum = dataFormatter.formatCellValue(row.getCell(10));//备注
|
|
|
|
|
+ if (!admissNum.equals("录取号")) {
|
|
|
|
|
+ return CommonResult.fail("导入数据第七列为录取号");
|
|
|
|
|
+ }
|
|
|
|
|
+ String name = dataFormatter.formatCellValue(row.getCell(11));//备注
|
|
|
|
|
+ if (!name.equals("姓名")) {
|
|
|
|
|
+ return CommonResult.fail("导入数据第七列为姓名");
|
|
|
|
|
+ }
|
|
|
|
|
+ String remark = dataFormatter.formatCellValue(row.getCell(12));//备注
|
|
|
|
|
+ if (!remark.equals("备注")) {
|
|
|
|
|
+ return CommonResult.fail("导入数据第七列为备注");
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ 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));//床位号
|
|
|
|
|
+ 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();
|
|
|
|
|
+ if(ob != null && ob.isPresent()){
|
|
|
|
|
+ bedData.setId(ob.get().getId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String sex = 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 isCheck = dataFormatter.formatCellValue(row.getCell(9));//备注
|
|
|
|
|
+ String admissNum = dataFormatter.formatCellValue(row.getCell(10));//备注
|
|
|
|
|
+ String name = dataFormatter.formatCellValue(row.getCell(11));//备注
|
|
|
|
|
+ String remark = dataFormatter.formatCellValue(row.getCell(12));//备注
|
|
|
|
|
+
|
|
|
|
|
+ bedData.setSchool(school);
|
|
|
|
|
+
|
|
|
|
|
+ //楼栋
|
|
|
|
|
+ if(wbils != null && wbils.size() > 0){
|
|
|
|
|
+ Optional<WelcomeBuild> oBuild = wbils.stream().filter(e -> e.getBuild().equals(build)).findFirst();
|
|
|
|
|
+ if(oBuild != null && oBuild.isPresent()){
|
|
|
|
|
+ bedData.setBuild(build);
|
|
|
|
|
+ bedData.setBuildId(oBuild.get().getId());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //寝室
|
|
|
|
|
+ if(wds != null && wds.size() > 0){
|
|
|
|
|
+ Optional<WelcomeDormitory> oDormitory = wds.stream().filter(e -> e.getDormitory().equals(dormitory)).findFirst();
|
|
|
|
|
+ if(oDormitory != null && oDormitory.isPresent()){
|
|
|
|
|
+ bedData.setDormitory(dormitory);
|
|
|
|
|
+ bedData.setDormitoryId(oDormitory.get().getId());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ bedData.setNumber(Integer.valueOf(number));
|
|
|
|
|
+ bedData.setSex(sex);
|
|
|
|
|
+
|
|
|
|
|
+ //region 院系专业
|
|
|
|
|
+ Optional<WelcomeOrg> owo = wos.stream().filter(e -> e.getName().equals(college)).findFirst();
|
|
|
|
|
+ if (owo != null && owo.isPresent()) {
|
|
|
|
|
+ bedData.setCollege(college);
|
|
|
|
|
+ bedData.setCollegeId(owo.get().getId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Optional<WelcomeOrg> omwo = wos.stream().filter(e -> e.getName().equals(major)).findFirst();
|
|
|
|
|
+ if (omwo != null && omwo.isPresent()) {
|
|
|
|
|
+ bedData.setMajor(major);
|
|
|
|
|
+ bedData.setMajorId(omwo.get().getId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Optional<WelcomeOrg> ocwo = wos.stream().filter(e -> e.getName().equals(classstr)).findFirst();
|
|
|
|
|
+ if (ocwo != null && ocwo.isPresent()) {
|
|
|
|
|
+ bedData.setClassstr(classstr);
|
|
|
|
|
+ bedData.setClassstrId(ocwo.get().getId());
|
|
|
|
|
+ }
|
|
|
|
|
+ //endregion
|
|
|
|
|
+
|
|
|
|
|
+ bedData.setIsCheck(Integer.valueOf(isCheck));
|
|
|
|
|
+ bedData.setCardNum(admissNum);
|
|
|
|
|
+ bedData.setName(name);
|
|
|
|
|
+ bedData.setRemark(remark);
|
|
|
|
|
+ result.add(bedData);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ return CommonResult.fail("请按模板格式导入数据");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return CommonResult.ok(result);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public CommonResult downloadBedExcel() {
|
|
|
|
|
+ return CommonResult.ok("200", "操作成功", "https://chtech.ncjti.edu.cn/alumnus/homeimage/床位信息管理.xlsx");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void welcomeBedExport(HttpServletResponse response, String school, Integer buildId, Integer dormitoryId, String sex, Integer isCheck, Integer collegeId, Integer majorId, Integer classstrId) {
|
|
|
|
|
+ List<WelcomeBed> result = welcomeBedService.queryPageWelcomeBeds(school, buildId, dormitoryId, sex, isCheck, collegeId, majorId, classstrId);
|
|
|
|
|
+
|
|
|
|
|
+ //导出
|
|
|
|
|
+ Workbook workbook = new XSSFWorkbook();
|
|
|
|
|
+ Sheet sheet = workbook.createSheet("床位信息");
|
|
|
|
|
|
|
|
|
|
+ Row headerRow = sheet.createRow(0);
|
|
|
|
|
+ headerRow.createCell(0).setCellValue("序号");
|
|
|
|
|
+ headerRow.createCell(1).setCellValue("校区名称");
|
|
|
|
|
+ headerRow.createCell(2).setCellValue("楼栋名称");
|
|
|
|
|
+ headerRow.createCell(3).setCellValue("寝室号");
|
|
|
|
|
+ headerRow.createCell(4).setCellValue("床位号");
|
|
|
|
|
+ headerRow.createCell(5).setCellValue("床位性别");
|
|
|
|
|
+ headerRow.createCell(6).setCellValue("所属学院");
|
|
|
|
|
+ headerRow.createCell(7).setCellValue("所属专业");
|
|
|
|
|
+ headerRow.createCell(8).setCellValue("所属班级");
|
|
|
|
|
+ headerRow.createCell(9).setCellValue("是否入住");
|
|
|
|
|
+ headerRow.createCell(10).setCellValue("录取号");
|
|
|
|
|
+ headerRow.createCell(11).setCellValue("姓名");
|
|
|
|
|
+ headerRow.createCell(12).setCellValue("备注");
|
|
|
|
|
+ for (int i = 0; i < result.size(); i++) {
|
|
|
|
|
+ WelcomeBed bed = result.get(i);
|
|
|
|
|
+ Row dataRow = sheet.createRow(i + 1);
|
|
|
|
|
+ dataRow.createCell(0).setCellValue(i + 1);
|
|
|
|
|
+ dataRow.createCell(1).setCellValue(bed.getSchool());
|
|
|
|
|
+ dataRow.createCell(2).setCellValue(bed.getBuild());
|
|
|
|
|
+ dataRow.createCell(3).setCellValue(bed.getDormitory());
|
|
|
|
|
+ dataRow.createCell(4).setCellValue(bed.getNumber());
|
|
|
|
|
+ dataRow.createCell(5).setCellValue(bed.getSex());
|
|
|
|
|
+ dataRow.createCell(6).setCellValue(bed.getCollege());
|
|
|
|
|
+ dataRow.createCell(7).setCellValue(bed.getMajor());
|
|
|
|
|
+ dataRow.createCell(8).setCellValue(bed.getClassstr());
|
|
|
|
|
+ dataRow.createCell(9).setCellValue(bed.getIsCheck());
|
|
|
|
|
+ dataRow.createCell(10).setCellValue(bed.getCardNum());
|
|
|
|
|
+ dataRow.createCell(11).setCellValue(bed.getName());
|
|
|
|
|
+ dataRow.createCell(12).setCellValue(bed.getRemark());
|
|
|
|
|
+ }
|
|
|
|
|
+ // 将工作簿写入文件
|
|
|
|
|
+ ExcelUtils.excelDownload(workbook, "床位信息.xlsx", response);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|