WelcomeBedController.java 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. package com.template.controller;
  2. import com.template.api.WelcomeBedControllerAPI;
  3. import com.template.common.utils.ExcelUtils;
  4. import com.template.common.utils.paramUtils;
  5. import com.template.model.enumModel.eFileType;
  6. import com.template.model.pojo.*;
  7. import com.template.model.request.InsertWelcomeBedRequest;
  8. import com.template.model.request.UpdateWelcomeBedRequest;
  9. import com.template.model.result.CommonResult;
  10. import com.template.model.result.PageUtils;
  11. import com.template.model.vo.ListVo;
  12. import com.template.model.vo.StudentPageVo;
  13. import com.template.services.*;
  14. import org.apache.poi.hssf.usermodel.HSSFRow;
  15. import org.apache.poi.hssf.usermodel.HSSFSheet;
  16. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  17. import org.apache.poi.ss.usermodel.DataFormatter;
  18. import org.apache.poi.ss.usermodel.Row;
  19. import org.apache.poi.ss.usermodel.Sheet;
  20. import org.apache.poi.ss.usermodel.Workbook;
  21. import org.apache.poi.xssf.usermodel.XSSFRow;
  22. import org.apache.poi.xssf.usermodel.XSSFSheet;
  23. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  24. import org.springframework.beans.factory.annotation.Autowired;
  25. import org.springframework.util.StringUtils;
  26. import org.springframework.validation.BindingResult;
  27. import org.springframework.web.bind.annotation.RequestMapping;
  28. import org.springframework.web.bind.annotation.RestController;
  29. import org.springframework.web.multipart.MultipartFile;
  30. import javax.servlet.http.HttpServletResponse;
  31. import java.io.IOException;
  32. import java.io.InputStream;
  33. import java.text.ParseException;
  34. import java.util.ArrayList;
  35. import java.util.List;
  36. import java.util.Optional;
  37. import java.util.stream.Collectors;
  38. /**
  39. * <p>
  40. * 前端控制器
  41. * </p>
  42. *
  43. * @author ceshi
  44. * @since 2025-06-13
  45. */
  46. @RestController
  47. public class WelcomeBedController implements WelcomeBedControllerAPI {
  48. @Autowired
  49. private WelcomeOrgService welcomeOrgService;
  50. @Autowired
  51. private WelcomeBedService welcomeBedService;
  52. @Autowired
  53. private WelcomeBuildService welcomeBuildService;
  54. @Autowired
  55. private WelcomeStudentService welcomeStudentService;
  56. @Autowired
  57. private WelcomeDormitoryService welcomeDormitoryService;
  58. @Override
  59. public CommonResult insertBedInfo(InsertWelcomeBedRequest iwbr, BindingResult bindingResult) {
  60. if (bindingResult.hasErrors()) {
  61. String st = paramUtils.getParamError(bindingResult);
  62. return CommonResult.fail(st);
  63. }
  64. WelcomeBed existData = welcomeBedService.queryBedData(iwbr.getSchool(),iwbr.getBuildId(),iwbr.getDormitoryId(),iwbr.getNumber());
  65. if(existData != null){
  66. return CommonResult.fail("该床位号已存在,请勿重复插入!");
  67. }
  68. WelcomeBed wb = new WelcomeBed();
  69. if(StringUtils.hasText(iwbr.getCardNum())){
  70. WelcomeStudent student =welcomeStudentService.queryStudentInfo(iwbr.getCollegeId(),iwbr.getMajorId(),iwbr.getClassstrId(),iwbr.getCardNum());
  71. if(student == null){
  72. return CommonResult.fail("当前学生信息在系统中不存在!");
  73. }
  74. wb.setStudentCard(student.getCardId());
  75. wb.setCollegeId(iwbr.getCollegeId());
  76. wb.setCollege(iwbr.getCollege());
  77. wb.setMajorId(iwbr.getMajorId());
  78. wb.setMajor(iwbr.getMajor());
  79. wb.setClassstrId(iwbr.getClassstrId());
  80. wb.setClassstr(iwbr.getClassstr());
  81. wb.setCardNum(iwbr.getCardNum());
  82. wb.setName(iwbr.getName());
  83. }
  84. wb.setNumber(iwbr.getNumber());
  85. wb.setSchool(iwbr.getSchool());
  86. wb.setSchoolId(iwbr.getSchoolId());
  87. wb.setBuildId(iwbr.getBuildId());
  88. wb.setBuild(iwbr.getBuild());
  89. wb.setDormitoryId(iwbr.getDormitoryId());
  90. wb.setDormitory(iwbr.getDormitory());
  91. wb.setSex(iwbr.getSex());
  92. wb.setIsCheck(StringUtils.hasText(iwbr.getCardNum()) ? 1 : 0);
  93. wb.setRemark(iwbr.getRemark());
  94. int result = welcomeBedService.insertWelcomeBed(wb);
  95. return result > 0 ? CommonResult.ok("添加成功!") : CommonResult.fail("添加失败");
  96. }
  97. @Override
  98. public CommonResult updateBedInfo(UpdateWelcomeBedRequest uwbr, BindingResult bindingResult) throws Exception {
  99. if (bindingResult.hasErrors()) {
  100. String st = paramUtils.getParamError(bindingResult);
  101. return CommonResult.fail(st);
  102. }
  103. WelcomeBed oldData = welcomeBedService.getBedById(uwbr.getId());
  104. if(oldData == null){
  105. return CommonResult.fail("床位信息已失效,编辑失败");
  106. }
  107. WelcomeBed existData = welcomeBedService.queryBedData(uwbr.getSchool(),uwbr.getBuildId(),uwbr.getDormitoryId(),uwbr.getNumber());
  108. if(existData != null && existData.getId().intValue() != uwbr.getId().intValue()){
  109. return CommonResult.fail("该床位号已存在,请勿重复插入!");
  110. }
  111. if(StringUtils.hasText(uwbr.getCardNum())){
  112. WelcomeStudent student =welcomeStudentService.queryStudentInfo(uwbr.getCollegeId(),uwbr.getMajorId(),uwbr.getClassstrId(),uwbr.getCardNum());
  113. if(student == null){
  114. return CommonResult.fail("当前学生信息在系统中不存在!");
  115. }
  116. oldData.setStudentCard(student.getCardId());
  117. oldData.setCollegeId(uwbr.getCollegeId());
  118. oldData.setCollege(uwbr.getCollege());
  119. oldData.setMajorId(uwbr.getMajorId());
  120. oldData.setMajor(uwbr.getMajor());
  121. oldData.setClassstrId(uwbr.getClassstrId());
  122. oldData.setClassstr(uwbr.getClassstr());
  123. oldData.setCardNum(uwbr.getCardNum());
  124. oldData.setName(uwbr.getName());
  125. }
  126. oldData.setNumber(uwbr.getNumber());
  127. oldData.setSchool(uwbr.getSchool());
  128. oldData.setSchoolId(uwbr.getSchoolId());
  129. oldData.setBuildId(uwbr.getBuildId());
  130. oldData.setBuild(uwbr.getBuild());
  131. oldData.setDormitoryId(uwbr.getDormitoryId());
  132. oldData.setDormitory(uwbr.getDormitory());
  133. oldData.setSex(uwbr.getSex());
  134. oldData.setCollegeId(uwbr.getCollegeId());
  135. oldData.setCollege(uwbr.getCollege());
  136. oldData.setMajorId(uwbr.getMajorId());
  137. oldData.setMajor(uwbr.getMajor());
  138. oldData.setClassstrId(uwbr.getClassstrId());
  139. oldData.setClassstr(uwbr.getClassstr());
  140. oldData.setIsCheck(uwbr.getIsCheck());
  141. oldData.setCardNum(uwbr.getCardNum());
  142. oldData.setName(uwbr.getName());
  143. oldData.setRemark(uwbr.getRemark());
  144. int result = welcomeBedService.updateWelcomeBed(oldData);
  145. return result > 0 ? CommonResult.ok("编辑成功!") : CommonResult.fail("编辑失败");
  146. }
  147. @Override
  148. public CommonResult queryPageBeds(int currentPage, int pageCount, Integer schoolId, Integer buildId, Integer dormitoryId, String sex, Integer isCheck, Integer collegeId, Integer majorId, Integer classstrId) {
  149. PageUtils<WelcomeBed> result = welcomeBedService.queryPageWelcomeBeds(currentPage, pageCount, schoolId, buildId, dormitoryId, sex, isCheck, collegeId, majorId, classstrId);
  150. return CommonResult.ok(result);
  151. }
  152. @Override
  153. public CommonResult deleteBedInfo(int id) throws Exception {
  154. int result = welcomeBedService.deleteWelcomeBedById(id);
  155. return result > 0 ? CommonResult.ok() : CommonResult.fail();
  156. }
  157. @Override
  158. public CommonResult importBedExcel(MultipartFile file) throws IOException, ParseException {
  159. System.out.println("导入床位信息");
  160. if (file.isEmpty() || file.getSize() == 0) {
  161. return CommonResult.fail("导入文件不能为空");
  162. }
  163. String ContentType = file.getContentType();
  164. InputStream inputStream = file.getInputStream();
  165. List<WelcomeBed> result = new ArrayList<>();
  166. //xls格式文件
  167. if (ContentType.equals(eFileType.Xls.getValue())) {
  168. CommonResult<List<WelcomeBed>> resultData = readXls(inputStream);
  169. if (!resultData.isSuccess()) {
  170. return resultData;
  171. }
  172. result = resultData.getData();
  173. } else if (ContentType.equals(eFileType.Xlsx.getValue())) {
  174. CommonResult<List<WelcomeBed>> resultData = readXlsx(inputStream);
  175. if (!resultData.isSuccess()) {
  176. return resultData;
  177. }
  178. result = resultData.getData();
  179. } else {
  180. return CommonResult.fail("床位信息数据导入只支持Xls或Xlsx格式文件");
  181. }
  182. List<String> admissNums = result.stream().map(WelcomeBed::getCardNum).distinct().collect(Collectors.toList());
  183. if(admissNums != null && admissNums.size() > 0){
  184. List<WelcomeStudent> students = welcomeStudentService.getDataByAdmissNum(admissNums);
  185. if(students != null && students.size() > 0){
  186. for (WelcomeBed r:result) {
  187. Optional<WelcomeStudent> os = students.stream().filter(e -> e.getAdmissNum().equals(r.getCardNum())).findFirst();
  188. if(os != null && os.isPresent()){
  189. r.setStudentCard(os.get().getCardId());
  190. }
  191. }
  192. }
  193. }
  194. boolean resultBool = welcomeBedService.saveOrUpdateBatch(result);
  195. System.out.println("导入楼栋1");
  196. return resultBool ? CommonResult.ok("导入成功") : CommonResult.fail("导入失败");
  197. }
  198. /**
  199. * xls文件读取方法
  200. *
  201. * @param inputStream
  202. * @return
  203. * @throws IOException
  204. * @throws ParseException
  205. */
  206. private CommonResult<List<WelcomeBed>> readXls(InputStream inputStream) throws IOException, ParseException {
  207. List<WelcomeBed> result = new ArrayList<>();
  208. HSSFWorkbook sheets = new HSSFWorkbook(inputStream);
  209. List<WelcomeBed> wb = welcomeBedService.list(null);
  210. List<WelcomeOrg> wos = welcomeOrgService.list(null);
  211. List<WelcomeBuild> wbils = welcomeBuildService.list(null);
  212. List<WelcomeDormitory> wds = welcomeDormitoryService.list(null);
  213. //读取第一张sheet
  214. HSSFSheet sheetAt = sheets.getSheetAt(0);
  215. DataFormatter dataFormatter = new DataFormatter();
  216. try {
  217. //rowNum = 3 从第三行开始获取值
  218. //sheetAt.getLastRowNum():从0开始统计数量 所以得+1
  219. for (int rowNum = 0; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
  220. HSSFRow row = sheetAt.getRow(rowNum);
  221. if (row != null) {
  222. //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
  223. //所以先使用setCellType()方法先将该单元格的类型设置为STRING
  224. //然后poi会根据字符串读取它
  225. if (rowNum == 0) {
  226. String num = dataFormatter.formatCellValue(row.getCell(0));//序号
  227. if (!num.equals("序号")) {
  228. return CommonResult.fail("导入数据第一列为序号");
  229. }
  230. String school = dataFormatter.formatCellValue(row.getCell(1));//序号
  231. if (!school.equals("校区名称")) {
  232. return CommonResult.fail("导入数据第一列为校区名称");
  233. }
  234. String build = dataFormatter.formatCellValue(row.getCell(2));//校区名称
  235. if (!build.equals("楼栋名称")) {
  236. return CommonResult.fail("导入数据第二列为楼栋名称");
  237. }
  238. String dormitory = dataFormatter.formatCellValue(row.getCell(3));//楼栋名称
  239. if (!dormitory.equals("寝室号")) {
  240. return CommonResult.fail("导入数据第三列为寝室号");
  241. }
  242. String number = dataFormatter.formatCellValue(row.getCell(4));//楼栋性别
  243. if (!number.equals("床位号")) {
  244. return CommonResult.fail("导入数据第四列为床位号");
  245. }
  246. String sex = dataFormatter.formatCellValue(row.getCell(5));//楼栋层数
  247. if (!sex.equals("床位性别")) {
  248. return CommonResult.fail("导入数据第五列为床位性别");
  249. }
  250. String college = dataFormatter.formatCellValue(row.getCell(6));//起始层数
  251. if (!college.equals("所属学院")) {
  252. return CommonResult.fail("导入数据第六列为所属学院");
  253. }
  254. String major = dataFormatter.formatCellValue(row.getCell(7));//备注
  255. if (!major.equals("所属专业")) {
  256. return CommonResult.fail("导入数据第七列为所属专业");
  257. }
  258. String classstr = dataFormatter.formatCellValue(row.getCell(8));//备注
  259. if (!classstr.equals("所属班级")) {
  260. return CommonResult.fail("导入数据第七列为所属班级");
  261. }
  262. String isCheck = dataFormatter.formatCellValue(row.getCell(9));//备注
  263. if (!isCheck.equals("是否入住")) {
  264. return CommonResult.fail("导入数据第七列为是否入住");
  265. }
  266. String admissNum = dataFormatter.formatCellValue(row.getCell(10));//备注
  267. if (!admissNum.equals("录取号")) {
  268. return CommonResult.fail("导入数据第七列为录取号");
  269. }
  270. String name = dataFormatter.formatCellValue(row.getCell(11));//备注
  271. if (!name.equals("姓名")) {
  272. return CommonResult.fail("导入数据第七列为姓名");
  273. }
  274. String remark = dataFormatter.formatCellValue(row.getCell(12));//备注
  275. if (!remark.equals("备注")) {
  276. return CommonResult.fail("导入数据第七列为备注");
  277. }
  278. } else {
  279. WelcomeBed bedData = new WelcomeBed();
  280. String school = dataFormatter.formatCellValue(row.getCell(1));//校区
  281. String build = dataFormatter.formatCellValue(row.getCell(2));//楼栋
  282. String dormitory = dataFormatter.formatCellValue(row.getCell(3));//寝室号
  283. String number = dataFormatter.formatCellValue(row.getCell(4));//床位号
  284. Optional<WelcomeBed> ob = wb.stream().filter(e -> e.getSchool().equals(school) && e.getBuild().equals(build)
  285. && e.getDormitory().equals(dormitory) && e.getNumber().intValue() == Integer.valueOf(number).intValue()).findFirst();
  286. if(ob != null && ob.isPresent()){
  287. bedData.setId(ob.get().getId());
  288. }
  289. String sex = dataFormatter.formatCellValue(row.getCell(5));//楼栋层数
  290. String college = dataFormatter.formatCellValue(row.getCell(6));//起始层数
  291. String major = dataFormatter.formatCellValue(row.getCell(7));//备注
  292. String classstr = dataFormatter.formatCellValue(row.getCell(8));//备注
  293. String isCheck = dataFormatter.formatCellValue(row.getCell(9));//备注
  294. String admissNum = dataFormatter.formatCellValue(row.getCell(10));//备注
  295. String name = dataFormatter.formatCellValue(row.getCell(11));//备注
  296. String remark = dataFormatter.formatCellValue(row.getCell(12));//备注
  297. bedData.setSchool(school);
  298. //楼栋
  299. if(wbils != null && wbils.size() > 0){
  300. Optional<WelcomeBuild> oBuild = wbils.stream().filter(e -> e.getBuild().equals(build)).findFirst();
  301. if(oBuild != null && oBuild.isPresent()){
  302. bedData.setBuild(build);
  303. bedData.setBuildId(oBuild.get().getId());
  304. }
  305. }
  306. //寝室
  307. if(wds != null && wds.size() > 0){
  308. Optional<WelcomeDormitory> oDormitory = wds.stream().filter(e -> e.getDormitory().equals(dormitory)).findFirst();
  309. if(oDormitory != null && oDormitory.isPresent()){
  310. bedData.setDormitory(dormitory);
  311. bedData.setDormitoryId(oDormitory.get().getId());
  312. }
  313. }
  314. bedData.setNumber(Integer.valueOf(number));
  315. bedData.setSex(sex);
  316. //region 院系专业
  317. Optional<WelcomeOrg> owo = wos.stream().filter(e -> e.getName().equals(college)).findFirst();
  318. if (owo != null && owo.isPresent()) {
  319. bedData.setCollege(college);
  320. bedData.setCollegeId(owo.get().getId());
  321. }
  322. Optional<WelcomeOrg> omwo = wos.stream().filter(e -> e.getName().equals(major)).findFirst();
  323. if (omwo != null && omwo.isPresent()) {
  324. bedData.setMajor(major);
  325. bedData.setMajorId(omwo.get().getId());
  326. }
  327. Optional<WelcomeOrg> ocwo = wos.stream().filter(e -> e.getName().equals(classstr)).findFirst();
  328. if (ocwo != null && ocwo.isPresent()) {
  329. bedData.setClassstr(classstr);
  330. bedData.setClassstrId(ocwo.get().getId());
  331. }
  332. //endregion
  333. bedData.setIsCheck(Integer.valueOf(isCheck));
  334. bedData.setCardNum(admissNum);
  335. bedData.setName(name);
  336. bedData.setRemark(remark);
  337. result.add(bedData);
  338. }
  339. }
  340. }
  341. } catch (Exception e) {
  342. return CommonResult.fail("请按模板格式导入数据");
  343. }
  344. return CommonResult.ok(result);
  345. }
  346. /**
  347. * xls文件读取方法
  348. *
  349. * @param inputStream
  350. * @return
  351. * @throws IOException
  352. * @throws ParseException
  353. */
  354. private CommonResult<List<WelcomeBed>> readXlsx(InputStream inputStream) throws IOException, ParseException {
  355. List<WelcomeBed> result = new ArrayList<>();
  356. XSSFWorkbook sheets = new XSSFWorkbook(inputStream);
  357. List<WelcomeBed> wb = welcomeBedService.list(null);
  358. List<WelcomeOrg> wos = welcomeOrgService.list(null);
  359. List<WelcomeBuild> wbils = welcomeBuildService.list(null);
  360. List<WelcomeDormitory> wds = welcomeDormitoryService.list(null);
  361. //读取第一张sheet
  362. XSSFSheet sheetAt = sheets.getSheetAt(0);
  363. DataFormatter dataFormatter = new DataFormatter();
  364. try {
  365. //rowNum = 3 从第三行开始获取值
  366. //sheetAt.getLastRowNum():从0开始统计数量 所以得+1
  367. for (int rowNum = 0; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
  368. XSSFRow row = sheetAt.getRow(rowNum);
  369. if (row != null) {
  370. //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
  371. //所以先使用setCellType()方法先将该单元格的类型设置为STRING
  372. //然后poi会根据字符串读取它
  373. if (rowNum == 0) {
  374. String num = dataFormatter.formatCellValue(row.getCell(0));//序号
  375. if (!num.equals("序号")) {
  376. return CommonResult.fail("导入数据第一列为序号");
  377. }
  378. String school = dataFormatter.formatCellValue(row.getCell(1));//序号
  379. if (!school.equals("校区名称")) {
  380. return CommonResult.fail("导入数据第一列为校区名称");
  381. }
  382. String build = dataFormatter.formatCellValue(row.getCell(2));//校区名称
  383. if (!build.equals("楼栋名称")) {
  384. return CommonResult.fail("导入数据第二列为楼栋名称");
  385. }
  386. String dormitory = dataFormatter.formatCellValue(row.getCell(3));//楼栋名称
  387. if (!dormitory.equals("寝室号")) {
  388. return CommonResult.fail("导入数据第三列为寝室号");
  389. }
  390. String number = dataFormatter.formatCellValue(row.getCell(4));//楼栋性别
  391. if (!number.equals("床位号")) {
  392. return CommonResult.fail("导入数据第四列为床位号");
  393. }
  394. String sex = dataFormatter.formatCellValue(row.getCell(5));//楼栋层数
  395. if (!sex.equals("床位性别")) {
  396. return CommonResult.fail("导入数据第五列为床位性别");
  397. }
  398. String college = dataFormatter.formatCellValue(row.getCell(6));//起始层数
  399. if (!college.equals("所属学院")) {
  400. return CommonResult.fail("导入数据第六列为所属学院");
  401. }
  402. String major = dataFormatter.formatCellValue(row.getCell(7));//备注
  403. if (!major.equals("所属专业")) {
  404. return CommonResult.fail("导入数据第七列为所属专业");
  405. }
  406. String classstr = dataFormatter.formatCellValue(row.getCell(8));//备注
  407. if (!classstr.equals("所属班级")) {
  408. return CommonResult.fail("导入数据第七列为所属班级");
  409. }
  410. String isCheck = dataFormatter.formatCellValue(row.getCell(9));//备注
  411. if (!isCheck.equals("是否入住")) {
  412. return CommonResult.fail("导入数据第七列为是否入住");
  413. }
  414. String admissNum = dataFormatter.formatCellValue(row.getCell(10));//备注
  415. if (!admissNum.equals("录取号")) {
  416. return CommonResult.fail("导入数据第七列为录取号");
  417. }
  418. String name = dataFormatter.formatCellValue(row.getCell(11));//备注
  419. if (!name.equals("姓名")) {
  420. return CommonResult.fail("导入数据第七列为姓名");
  421. }
  422. String remark = dataFormatter.formatCellValue(row.getCell(12));//备注
  423. if (!remark.equals("备注")) {
  424. return CommonResult.fail("导入数据第七列为备注");
  425. }
  426. } else {
  427. WelcomeBed bedData = new WelcomeBed();
  428. String school = dataFormatter.formatCellValue(row.getCell(1));//校区
  429. String build = dataFormatter.formatCellValue(row.getCell(2));//楼栋
  430. String dormitory = dataFormatter.formatCellValue(row.getCell(3));//寝室号
  431. String number = dataFormatter.formatCellValue(row.getCell(4));//床位号
  432. Optional<WelcomeBed> ob = wb.stream().filter(e -> e.getSchool().equals(school) && e.getBuild().equals(build)
  433. && e.getDormitory().equals(dormitory) && e.getNumber().intValue() == Integer.valueOf(number).intValue()).findFirst();
  434. if(ob != null && ob.isPresent()){
  435. bedData.setId(ob.get().getId());
  436. }
  437. String sex = dataFormatter.formatCellValue(row.getCell(5));//楼栋层数
  438. String college = dataFormatter.formatCellValue(row.getCell(6));//起始层数
  439. String major = dataFormatter.formatCellValue(row.getCell(7));//备注
  440. String classstr = dataFormatter.formatCellValue(row.getCell(8));//备注
  441. String isCheck = dataFormatter.formatCellValue(row.getCell(9));//备注
  442. String admissNum = dataFormatter.formatCellValue(row.getCell(10));//备注
  443. String name = dataFormatter.formatCellValue(row.getCell(11));//备注
  444. String remark = dataFormatter.formatCellValue(row.getCell(12));//备注
  445. bedData.setSchool(school);
  446. //楼栋
  447. if(wbils != null && wbils.size() > 0){
  448. Optional<WelcomeBuild> oBuild = wbils.stream().filter(e -> e.getBuild().equals(build)).findFirst();
  449. if(oBuild != null && oBuild.isPresent()){
  450. bedData.setBuild(build);
  451. bedData.setBuildId(oBuild.get().getId());
  452. }
  453. }
  454. //寝室
  455. if(wds != null && wds.size() > 0){
  456. Optional<WelcomeDormitory> oDormitory = wds.stream().filter(e -> e.getDormitory().equals(dormitory)).findFirst();
  457. if(oDormitory != null && oDormitory.isPresent()){
  458. bedData.setDormitory(dormitory);
  459. bedData.setDormitoryId(oDormitory.get().getId());
  460. }
  461. }
  462. bedData.setNumber(Integer.valueOf(number));
  463. bedData.setSex(sex);
  464. //region 院系专业
  465. Optional<WelcomeOrg> owo = wos.stream().filter(e -> e.getName().equals(college)).findFirst();
  466. if (owo != null && owo.isPresent()) {
  467. bedData.setCollege(college);
  468. bedData.setCollegeId(owo.get().getId());
  469. }
  470. Optional<WelcomeOrg> omwo = wos.stream().filter(e -> e.getName().equals(major)).findFirst();
  471. if (omwo != null && omwo.isPresent()) {
  472. bedData.setMajor(major);
  473. bedData.setMajorId(omwo.get().getId());
  474. }
  475. Optional<WelcomeOrg> ocwo = wos.stream().filter(e -> e.getName().equals(classstr)).findFirst();
  476. if (ocwo != null && ocwo.isPresent()) {
  477. bedData.setClassstr(classstr);
  478. bedData.setClassstrId(ocwo.get().getId());
  479. }
  480. //endregion
  481. bedData.setIsCheck(Integer.valueOf(isCheck));
  482. bedData.setCardNum(admissNum);
  483. bedData.setName(name);
  484. bedData.setRemark(remark);
  485. result.add(bedData);
  486. }
  487. }
  488. }
  489. } catch (Exception e) {
  490. return CommonResult.fail("请按模板格式导入数据");
  491. }
  492. return CommonResult.ok(result);
  493. }
  494. @Override
  495. public CommonResult downloadBedExcel() {
  496. return CommonResult.ok("200", "操作成功", "https://chtech.ncjti.edu.cn/alumnus/homeimage/床位信息管理.xlsx");
  497. }
  498. @Override
  499. public void welcomeBedExport(HttpServletResponse response, Integer schoolId, Integer buildId, Integer dormitoryId, String sex, Integer isCheck, Integer collegeId, Integer majorId, Integer classstrId) {
  500. List<WelcomeBed> result = welcomeBedService.queryPageWelcomeBeds(schoolId, buildId, dormitoryId, sex, isCheck, collegeId, majorId, classstrId);
  501. //导出
  502. Workbook workbook = new XSSFWorkbook();
  503. Sheet sheet = workbook.createSheet("床位信息");
  504. Row headerRow = sheet.createRow(0);
  505. headerRow.createCell(0).setCellValue("序号");
  506. headerRow.createCell(1).setCellValue("校区名称");
  507. headerRow.createCell(2).setCellValue("楼栋名称");
  508. headerRow.createCell(3).setCellValue("寝室号");
  509. headerRow.createCell(4).setCellValue("床位号");
  510. headerRow.createCell(5).setCellValue("床位性别");
  511. headerRow.createCell(6).setCellValue("所属学院");
  512. headerRow.createCell(7).setCellValue("所属专业");
  513. headerRow.createCell(8).setCellValue("所属班级");
  514. headerRow.createCell(9).setCellValue("是否入住");
  515. headerRow.createCell(10).setCellValue("录取号");
  516. headerRow.createCell(11).setCellValue("姓名");
  517. headerRow.createCell(12).setCellValue("备注");
  518. for (int i = 0; i < result.size(); i++) {
  519. WelcomeBed bed = result.get(i);
  520. Row dataRow = sheet.createRow(i + 1);
  521. dataRow.createCell(0).setCellValue(i + 1);
  522. dataRow.createCell(1).setCellValue(bed.getSchool());
  523. dataRow.createCell(2).setCellValue(bed.getBuild());
  524. dataRow.createCell(3).setCellValue(bed.getDormitory());
  525. dataRow.createCell(4).setCellValue(bed.getNumber());
  526. dataRow.createCell(5).setCellValue(bed.getSex());
  527. dataRow.createCell(6).setCellValue(bed.getCollege());
  528. dataRow.createCell(7).setCellValue(bed.getMajor());
  529. dataRow.createCell(8).setCellValue(bed.getClassstr());
  530. dataRow.createCell(9).setCellValue(bed.getIsCheck());
  531. dataRow.createCell(10).setCellValue(bed.getCardNum());
  532. dataRow.createCell(11).setCellValue(bed.getName());
  533. dataRow.createCell(12).setCellValue(bed.getRemark());
  534. }
  535. // 将工作簿写入文件
  536. ExcelUtils.excelDownload(workbook, "床位信息.xlsx", response);
  537. }
  538. @Override
  539. public CommonResult submit(WelcomeBed welcomeBed) {
  540. welcomeBedService.updateById(welcomeBed);
  541. return CommonResult.ok();
  542. }
  543. @Override
  544. public CommonResult bedDetails(Integer schoolId, Integer buildId, Integer dormitoryId, String studentCard) {
  545. // 获取未入住的床位
  546. List<WelcomeBed> beds = welcomeBedService.getBedList(schoolId, buildId, dormitoryId, studentCard);
  547. return CommonResult.ok(beds);
  548. }
  549. @Override
  550. public CommonResult queryBedDatas(int dormitoryId) {
  551. List<WelcomeBed> beds = welcomeBedService.queryDormitorys(dormitoryId);
  552. List<ListVo> datas = new ArrayList<>();
  553. for (WelcomeBed bed:beds) {
  554. ListVo data = new ListVo();
  555. data.setId(bed.getId());
  556. data.setName(bed.getName());
  557. datas.add(data);
  558. }
  559. return CommonResult.ok(datas);
  560. }
  561. }