| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635 |
- 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.ListVo;
- 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.util.StringUtils;
- import org.springframework.validation.BindingResult;
- import org.springframework.web.bind.annotation.RequestMapping;
- 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>
- *
- * @author ceshi
- * @since 2025-06-13
- */
- @RestController
- 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("该床位号已存在,请勿重复插入!");
- }
- 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());
- }
- wb.setNumber(iwbr.getNumber());
- wb.setSchool(iwbr.getSchool());
- wb.setSchoolId(iwbr.getSchoolId());
- wb.setBuildId(iwbr.getBuildId());
- wb.setBuild(iwbr.getBuild());
- wb.setDormitoryId(iwbr.getDormitoryId());
- wb.setDormitory(iwbr.getDormitory());
- wb.setSex(iwbr.getSex());
- wb.setIsCheck(StringUtils.hasText(iwbr.getCardNum()) ? 1 : 0);
- 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("该床位号已存在,请勿重复插入!");
- }
- 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.setSchool(uwbr.getSchool());
- oldData.setSchoolId(uwbr.getSchoolId());
- 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, Integer schoolId, Integer buildId, Integer dormitoryId, String sex, Integer isCheck, Integer collegeId, Integer majorId, Integer classstrId) {
- PageUtils<WelcomeBed> result = welcomeBedService.queryPageWelcomeBeds(currentPage, pageCount, schoolId, 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, Integer schoolId, Integer buildId, Integer dormitoryId, String sex, Integer isCheck, Integer collegeId, Integer majorId, Integer classstrId) {
- List<WelcomeBed> result = welcomeBedService.queryPageWelcomeBeds(schoolId, 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);
- }
- @Override
- public CommonResult submit(WelcomeBed welcomeBed) {
- welcomeBedService.updateById(welcomeBed);
- return CommonResult.ok();
- }
- @Override
- public CommonResult bedDetails(Integer schoolId, Integer buildId, Integer dormitoryId, String studentCard) {
- // 获取未入住的床位
- List<WelcomeBed> beds = welcomeBedService.getBedList(schoolId, buildId, dormitoryId, studentCard);
- return CommonResult.ok(beds);
- }
- @Override
- public CommonResult queryBedDatas(int dormitoryId) {
- List<WelcomeBed> beds = welcomeBedService.queryDormitorys(dormitoryId);
- List<ListVo> datas = new ArrayList<>();
- for (WelcomeBed bed:beds) {
- ListVo data = new ListVo();
- data.setId(bed.getId());
- data.setName(bed.getName());
- datas.add(data);
- }
- return CommonResult.ok(datas);
- }
- }
|