WelcomeStudentController.java 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435
  1. package com.template.controller;
  2. import com.alibaba.fastjson.JSON;
  3. import com.baomidou.mybatisplus.core.conditions.Wrapper;
  4. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  5. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  6. import com.baomidou.mybatisplus.extension.api.R;
  7. import com.template.api.WelcomeStudentControllerAPI;
  8. import com.template.common.utils.ExcelUtils;
  9. import com.template.common.utils.paramUtils;
  10. import com.template.model.enumModel.eFileType;
  11. import com.template.model.enumModel.eProjectType;
  12. import com.template.model.pojo.*;
  13. import com.template.model.request.*;
  14. import com.template.model.result.CommonResult;
  15. import com.template.model.result.PageUtils;
  16. import com.template.model.vo.*;
  17. import com.template.services.*;
  18. import io.swagger.annotations.ApiModelProperty;
  19. import org.apache.poi.hssf.usermodel.HSSFRow;
  20. import org.apache.poi.hssf.usermodel.HSSFSheet;
  21. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  22. import org.apache.poi.ss.usermodel.DataFormatter;
  23. import org.apache.poi.ss.usermodel.Row;
  24. import org.apache.poi.ss.usermodel.Sheet;
  25. import org.apache.poi.ss.usermodel.Workbook;
  26. import org.apache.poi.xssf.usermodel.XSSFRow;
  27. import org.apache.poi.xssf.usermodel.XSSFSheet;
  28. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  29. import org.slf4j.Logger;
  30. import org.slf4j.LoggerFactory;
  31. import org.springframework.beans.factory.annotation.Autowired;
  32. import org.springframework.transaction.annotation.Transactional;
  33. import org.springframework.util.StringUtils;
  34. import org.springframework.validation.BindingResult;
  35. import org.springframework.web.bind.annotation.RestController;
  36. import org.springframework.web.multipart.MultipartFile;
  37. import javax.servlet.http.HttpServletResponse;
  38. import java.io.IOException;
  39. import java.io.InputStream;
  40. import java.text.ParseException;
  41. import java.time.LocalDateTime;
  42. import java.time.format.DateTimeFormatter;
  43. import java.util.ArrayList;
  44. import java.util.List;
  45. import java.util.Locale;
  46. import java.util.Optional;
  47. import java.util.stream.Collectors;
  48. /**
  49. * <p>
  50. * 前端控制器
  51. * </p>
  52. *
  53. * @author ceshi
  54. * @since 2025-06-13
  55. */
  56. @RestController
  57. public class WelcomeStudentController implements WelcomeStudentControllerAPI {
  58. @Autowired
  59. private WelcomeStudentService welcomeStudentService;
  60. @Autowired
  61. private WelcomeFamilyService welcomeFamilyService;
  62. @Autowired
  63. private WelcomeAccompanyService welcomeAccompanyService;
  64. @Autowired
  65. private WelcomeBedService welcomeBedService;
  66. @Autowired
  67. private WelcomeArriveSettingService welcomeArriveSettingService;
  68. @Autowired
  69. private WelcomeOrgService welcomeOrgService;
  70. @Autowired
  71. private WelcomeCityService welcomeCityService;
  72. @Autowired
  73. WelcomeSchoolService welcomeSchoolService;
  74. @Autowired
  75. WelcomeBuildService welcomeBuildService;
  76. @Autowired
  77. WelcomeDormitoryService welcomeDormitoryService;
  78. @Autowired
  79. WelcomeVisitorService welcomeVisitorService;
  80. private static Logger logger = LoggerFactory.getLogger(WelcomeStudentController.class);
  81. @Override
  82. @Transactional(rollbackFor = {Exception.class})
  83. public CommonResult insertStudentInfo(InsertStudentRequest isr, BindingResult bindingResult) throws Exception {
  84. if (bindingResult.hasErrors()) {
  85. String st = paramUtils.getParamError(bindingResult);
  86. return CommonResult.fail(st);
  87. }
  88. int existCount = welcomeStudentService.existStudentInfo(isr.getAdmissNum(), isr.getCardId());
  89. if (existCount > 0) {
  90. return CommonResult.fail("当前录取号或身份证号已存在!");
  91. }
  92. //region 学生信息
  93. WelcomeStudent ws = new WelcomeStudent();
  94. ws.setAdmissNum(isr.getAdmissNum());
  95. ws.setName(isr.getName());
  96. ws.setPicture(isr.getPicture());
  97. ws.setCardId(isr.getCardId());
  98. ws.setSex(isr.getSex());
  99. ws.setBirthday(isr.getBirthday());
  100. ws.setSchool(isr.getSchool());
  101. ws.setCollege(isr.getCollege());
  102. ws.setMajor(isr.getMajor());
  103. ws.setClassstr(isr.getClassstr());
  104. ws.setCollegeId(isr.getCollegeId());
  105. ws.setMajorId(isr.getMajorId());
  106. ws.setClassstrId(isr.getClassstrId());
  107. ws.setExamNum(isr.getExamNum());
  108. ws.setEduSystem(isr.getEduSystem());
  109. ws.setGraduationSchool(isr.getGraduationSchool());
  110. ws.setBatchValue(isr.getBatchValue());
  111. ws.setPoliticalStatu(isr.getPoliticalStatu());
  112. ws.setNationality(isr.getNationality());
  113. ws.setPhone(isr.getPhone());
  114. ws.setOprovinceId(isr.getOprovinceId());
  115. ws.setOcityId(isr.getOcityId());
  116. ws.setOdistrictId(isr.getOdistrictId());
  117. ws.setProvinceId(isr.getProvinceId());
  118. ws.setCityId(isr.getCityId());
  119. ws.setDistrictId(isr.getDistrictId());
  120. ws.setAddress(isr.getAddress());
  121. ws.setTrafficMethod(isr.getTrafficMethod());
  122. ws.setArrive(isr.getArrive());
  123. ws.setArrvieDate(isr.getArrvieDate());
  124. ws.setArriveTime(isr.getArriveTime());
  125. ws.setZipCode(isr.getZipCode());
  126. ws.setRegisterOntime(isr.getRegisterOntime());
  127. //ws.setAmountPayable(isr.getAmountPayable());
  128. //ws.setPayAmount(isr.getPayAmount());
  129. //ws.setIsDrive(isr.getIsDrive());
  130. //ws.setCarNumber(isr.getCarNumber());
  131. //endregion
  132. //region 家庭成员数据
  133. List<WelcomeFamily> wfs = new ArrayList<>();
  134. if (isr.getFamilys() != null && isr.getFamilys().size() > 0) {
  135. for (InsertFamilyRequest family : isr.getFamilys()) {
  136. if(!(StringUtils.hasText(family.getFamilyShip()) && StringUtils.hasText(family.getName())
  137. && StringUtils.hasText(family.getWorkUnit()) && StringUtils.hasText(family.getPhone()))){
  138. return CommonResult.fail("家庭成员信息不能为空!");
  139. }
  140. WelcomeFamily wf = new WelcomeFamily();
  141. wf.setStudentCard(ws.getCardId());
  142. wf.setFamilyShip(family.getFamilyShip());
  143. wf.setName(family.getName());
  144. wf.setWorkUnit(family.getWorkUnit());
  145. wf.setPhone(family.getPhone());
  146. wfs.add(wf);
  147. }
  148. }
  149. //endregion
  150. //region 陪同人员数据
  151. List<WelcomeAccompany> was = new ArrayList<>();
  152. if (isr.getAccompanys() != null && isr.getAccompanys().size() > 0) {
  153. for (InsertAccompanyRequest accompany : isr.getAccompanys()) {
  154. if(!(StringUtils.hasText(accompany.getName()) && StringUtils.hasText(accompany.getPhone()))){
  155. return CommonResult.fail("陪同人员信息不能为空!");
  156. }
  157. WelcomeAccompany wa = new WelcomeAccompany();
  158. wa.setStudentCard(ws.getCardId());
  159. wa.setName(accompany.getName());
  160. wa.setPhone(accompany.getPhone());
  161. was.add(wa);
  162. }
  163. }
  164. //endregion
  165. //region 宿舍信息
  166. WelcomeBed bedData = welcomeBedService.queryBedData(isr.getSchool(), isr.getBuildId(), isr.getDormitoryId(), Integer.valueOf(isr.getBed()));
  167. if (bedData != null) {
  168. bedData.setStudentCard(isr.getCardId());
  169. bedData.setCollege(isr.getCollege());
  170. bedData.setCollegeId(isr.getCollegeId());
  171. bedData.setMajor(isr.getMajor());
  172. bedData.setMajorId(isr.getMajorId());
  173. bedData.setClassstr(isr.getClassstr());
  174. bedData.setClassstrId(isr.getClassstrId());
  175. bedData.setIsCheck(1);
  176. bedData.setCardNum(isr.getAdmissNum());
  177. bedData.setName(isr.getName());
  178. }
  179. //endregion
  180. try {
  181. int studentId = welcomeStudentService.insertWelcomeStudent(ws);
  182. if (studentId <= 0) {
  183. logger.error("添加学生失败,参数:" + JSON.toJSON(isr));
  184. throw new Exception("添加失败!");
  185. }
  186. if (wfs != null && wfs.size() > 0) {
  187. boolean insertBatch = welcomeFamilyService.saveBatch(wfs);
  188. if (!insertBatch) {
  189. logger.error("添加家庭成员失败,参数:" + JSON.toJSON(wfs));
  190. throw new Exception("添加失败!");
  191. }
  192. }
  193. if (was != null && was.size() > 0) {
  194. boolean insertBatch = welcomeAccompanyService.saveBatch(was);
  195. if (!insertBatch) {
  196. logger.error("添加陪同人员失败,参数:" + JSON.toJSON(was));
  197. throw new Exception("添加失败!");
  198. }
  199. }
  200. int insertStudentDormitory = welcomeBedService.updateWelcomeBed(bedData);
  201. if (insertStudentDormitory <= 0) {
  202. logger.error("添加学生床位信息失败,参数:" + JSON.toJSON(bedData));
  203. throw new Exception("添加失败!");
  204. }
  205. } catch (Exception e) {
  206. logger.error(e.getMessage());
  207. throw new Exception("添加失败!");
  208. }
  209. return CommonResult.ok("添加成功");
  210. }
  211. @Override
  212. public CommonResult updateStudentInfo(updateStudentRequest usr, BindingResult bindingResult) throws Exception {
  213. if (bindingResult.hasErrors()) {
  214. String st = paramUtils.getParamError(bindingResult);
  215. return CommonResult.fail(st);
  216. }
  217. WelcomeStudent student = welcomeStudentService.getManageById(usr.getId());
  218. if (student == null) {
  219. return CommonResult.fail("学生数据已失效,编辑失败!");
  220. }
  221. //region 学生信息
  222. student.setAdmissNum(usr.getAdmissNum());
  223. student.setName(usr.getName());
  224. student.setPicture(usr.getPicture());
  225. //student.setCardId(usr.getCardId());
  226. student.setSex(usr.getSex());
  227. student.setBirthday(usr.getBirthday());
  228. student.setSchool(usr.getSchool());
  229. student.setCollege(usr.getCollege());
  230. student.setMajor(usr.getMajor());
  231. student.setClassstr(usr.getClassstr());
  232. student.setCollegeId(usr.getCollegeId());
  233. student.setMajorId(usr.getMajorId());
  234. student.setClassstrId(usr.getClassstrId());
  235. student.setExamNum(usr.getExamNum());
  236. student.setEduSystem(usr.getEduSystem());
  237. student.setGraduationSchool(usr.getGraduationSchool());
  238. student.setBatchValue(usr.getBatchValue());
  239. student.setPoliticalStatu(usr.getPoliticalStatu());
  240. student.setNationality(usr.getNationality());
  241. student.setPhone(usr.getPhone());
  242. student.setOprovinceId(usr.getOprovinceId());
  243. student.setOcityId(usr.getOcityId());
  244. student.setOdistrictId(usr.getOdistrictId());
  245. student.setProvinceId(usr.getProvinceId());
  246. student.setCityId(usr.getCityId());
  247. student.setDistrictId(usr.getDistrictId());
  248. student.setAddress(usr.getAddress());
  249. student.setTrafficMethod(usr.getTrafficMethod());
  250. student.setArrive(usr.getArrive());
  251. student.setArrvieDate(usr.getArrvieDate());
  252. student.setArriveTime(usr.getArriveTime());
  253. student.setZipCode(usr.getZipCode());
  254. student.setRegisterOntime(usr.getRegisterOntime());
  255. //ws.setAmountPayable(isr.getAmountPayable());
  256. //ws.setPayAmount(isr.getPayAmount());
  257. //ws.setIsDrive(isr.getIsDrive());
  258. //ws.setCarNumber(isr.getCarNumber());
  259. //endregion
  260. //region 家庭成员数据
  261. List<WelcomeFamily> wfs = new ArrayList<>();
  262. if (usr.getFamilys() != null && usr.getFamilys().size() > 0) {
  263. for (InsertFamilyRequest family : usr.getFamilys()) {
  264. if(!(StringUtils.hasText(family.getFamilyShip()) && StringUtils.hasText(family.getName())
  265. && StringUtils.hasText(family.getWorkUnit()) && StringUtils.hasText(family.getPhone()))){
  266. return CommonResult.fail("家庭成员信息不能为空!");
  267. }
  268. WelcomeFamily wf = new WelcomeFamily();
  269. wf.setStudentCard(student.getCardId());
  270. wf.setFamilyShip(family.getFamilyShip());
  271. wf.setName(family.getName());
  272. wf.setWorkUnit(family.getWorkUnit());
  273. wf.setPhone(family.getPhone());
  274. wfs.add(wf);
  275. }
  276. }
  277. //endregion
  278. //region 陪同人员数据
  279. List<WelcomeAccompany> was = new ArrayList<>();
  280. if (usr.getAccompanys() != null && usr.getAccompanys().size() > 0) {
  281. for (InsertAccompanyRequest accompany : usr.getAccompanys()) {
  282. if(!(StringUtils.hasText(accompany.getName()) && StringUtils.hasText(accompany.getPhone()))){
  283. return CommonResult.fail("陪同人员信息不能为空!");
  284. }
  285. WelcomeAccompany wa = new WelcomeAccompany();
  286. wa.setStudentCard(student.getCardId());
  287. wa.setName(accompany.getName());
  288. wa.setPhone(accompany.getPhone());
  289. was.add(wa);
  290. }
  291. }
  292. //endregion
  293. //region 宿舍信息
  294. List<WelcomeBed> bedDatas = new ArrayList<>();
  295. WelcomeBed bedData = welcomeBedService.queryBedData(usr.getSchool(), usr.getBuildId(), usr.getDormitoryId(), Integer.valueOf(usr.getBed()));
  296. if (bedData != null) {//新床位
  297. if (!StringUtils.hasText(bedData.getStudentCard())) {
  298. bedData.setStudentCard(student.getCardId());
  299. bedData.setCollege(student.getCollege());
  300. bedData.setCollegeId(student.getCollegeId());
  301. bedData.setMajor(student.getMajor());
  302. bedData.setMajorId(student.getMajorId());
  303. bedData.setClassstr(student.getClassstr());
  304. bedData.setClassstrId(student.getClassstrId());
  305. bedData.setIsCheck(1);
  306. bedData.setCardNum(student.getAdmissNum());
  307. bedData.setName(student.getName());
  308. //把旧床位清空
  309. WelcomeBed obedData = welcomeBedService.getBedByCardId(student.getCardId());
  310. if (obedData == null) {
  311. obedData.setStudentCard(null);
  312. obedData.setCollege(null);
  313. obedData.setCollegeId(null);
  314. obedData.setMajor(null);
  315. obedData.setMajorId(null);
  316. obedData.setClassstr(null);
  317. obedData.setClassstrId(null);
  318. obedData.setIsCheck(0);
  319. obedData.setCardNum(null);
  320. obedData.setName(null);
  321. bedDatas.add(obedData);
  322. }
  323. } else {
  324. bedData.setStudentCard(student.getCardId());
  325. bedData.setCollege(student.getCollege());
  326. bedData.setCollegeId(student.getCollegeId());
  327. bedData.setMajor(student.getMajor());
  328. bedData.setMajorId(student.getMajorId());
  329. bedData.setClassstr(student.getClassstr());
  330. bedData.setClassstrId(student.getClassstrId());
  331. bedData.setIsCheck(1);
  332. bedData.setCardNum(student.getAdmissNum());
  333. bedData.setName(student.getName());
  334. }
  335. bedDatas.add(bedData);
  336. }
  337. //endregion
  338. try {
  339. int studentId = welcomeStudentService.updateWelcomeStudent(student);
  340. if (studentId <= 0) {
  341. logger.error("编辑学生失败,参数:" + JSON.toJSON(usr));
  342. throw new Exception("编辑失败!");
  343. }
  344. int deleteF = welcomeFamilyService.deleteWelcomeFamilyByCard(student.getCardId());
  345. if (wfs != null && wfs.size() > 0) {
  346. boolean insertBatch = welcomeFamilyService.saveBatch(wfs);
  347. if (!insertBatch) {
  348. logger.error("编辑家庭成员失败,参数:" + JSON.toJSON(wfs));
  349. throw new Exception("编辑失败!");
  350. }
  351. }
  352. int deleteA = welcomeAccompanyService.deleteWelcomeAccompanyByCard(student.getCardId());
  353. if (was != null && was.size() > 0) {
  354. boolean insertBatch = welcomeAccompanyService.saveBatch(was);
  355. if (!insertBatch) {
  356. logger.error("编辑陪同人员失败,参数:" + JSON.toJSON(was));
  357. throw new Exception("编辑失败!");
  358. }
  359. }
  360. boolean updateBatch = welcomeBedService.updateBatchById(bedDatas);
  361. if (!updateBatch) {
  362. logger.error("添加宿舍信息失败,参数:" + JSON.toJSON(bedDatas));
  363. throw new Exception("添加失败!");
  364. }
  365. } catch (Exception e) {
  366. logger.error(e.getMessage());
  367. throw new Exception("编辑失败!");
  368. }
  369. return CommonResult.ok("编辑成功");
  370. }
  371. @Override
  372. public CommonResult queryPageStudents(int currentPage, int pageCount, Integer collegeId, Integer majorId, Integer classstrId, String trafficMethod, String name) {
  373. PageUtils<StudentPageVo> result = welcomeStudentService.queryStudentPageList(currentPage, pageCount, collegeId, majorId, classstrId, trafficMethod, name);
  374. return CommonResult.ok(result);
  375. }
  376. @Override
  377. public CommonResult queryStudentDetail(int id) {
  378. StudentDetailVo result = new StudentDetailVo();
  379. WelcomeStudent ws = welcomeStudentService.getManageById(id);
  380. if (ws == null) {
  381. return CommonResult.ok("学生信息已失效,查看失败!");
  382. }
  383. //家庭成员
  384. List<FamilyVo> fvs = new ArrayList<>();
  385. List<WelcomeFamily> familys = welcomeFamilyService.getManageByCardId(ws.getCardId());
  386. if (familys != null && familys.size() > 0) {
  387. for (WelcomeFamily wf : familys) {
  388. FamilyVo fv = new FamilyVo();
  389. fv.setId(wf.getId());
  390. fv.setFamilyShip(wf.getFamilyShip());
  391. fv.setName(wf.getName());
  392. fv.setPhone(wf.getPhone());
  393. fv.setWorkUnit(wf.getWorkUnit());
  394. fvs.add(fv);
  395. }
  396. }
  397. result.setFvs(fvs);
  398. //陪同人员
  399. List<AccompanyVo> avs = new ArrayList<>();
  400. List<WelcomeAccompany> accompanys = welcomeAccompanyService.getManageByCardId(ws.getCardId());
  401. if (accompanys != null && accompanys.size() > 0) {
  402. for (WelcomeAccompany ac : accompanys) {
  403. AccompanyVo av = new AccompanyVo();
  404. av.setId(ac.getId());
  405. av.setName(ac.getName());
  406. av.setPhone(ac.getPhone());
  407. avs.add(av);
  408. }
  409. }
  410. result.setAvs(avs);
  411. //宿舍信息
  412. WelcomeBed wsd = welcomeBedService.getBedByCardId(ws.getCardId());
  413. if (wsd != null) {
  414. result.setBuild(wsd.getBuild());
  415. result.setBuildId(wsd.getBuild());
  416. result.setDormitory(wsd.getDormitory());//寝室号
  417. result.setDormitoryId(wsd.getDormitoryId());//寝室号
  418. result.setBed(String.valueOf(wsd.getNumber()));//床位号
  419. result.setBedId(wsd.getId());//床位号
  420. }
  421. //时间段
  422. List<ArriveTimeVo> atvs = new ArrayList<>();
  423. List<WelcomeArriveSetting> wass = welcomeArriveSettingService.queryCheckDatas();
  424. if (wass != null && wass.size() > 0) {
  425. for (WelcomeArriveSetting was : wass) {
  426. ArriveTimeVo atv = new ArriveTimeVo();
  427. atv.setId(was.getId());
  428. atv.setStartTime(was.getStartTime());
  429. atv.setEndTime(was.getEndTime());
  430. atv.setTimeStr(was.getStartTime() + "-" + was.getEndTime());
  431. atv.setIsCheck((ws.getArriveTimeId() != null && was.getId().equals(ws.getArriveTimeId())) ? 1 : 0);
  432. atvs.add(atv);
  433. }
  434. }
  435. result.setAtvs(atvs);
  436. result.setId(ws.getId());
  437. result.setSchool(ws.getSchool());
  438. result.setAdmissNum(ws.getAdmissNum());
  439. result.setName(ws.getName());
  440. result.setPicture(ws.getPicture());
  441. result.setCardId(ws.getCardId());
  442. result.setSex(ws.getSex());
  443. result.setBirthday(ws.getBirthday());
  444. result.setCollege(ws.getCollege());
  445. result.setMajor(ws.getMajor());
  446. result.setClassstr(ws.getClassstr());
  447. result.setCollegeId(ws.getCollegeId());
  448. result.setMajorId(ws.getMajorId());
  449. result.setClassstrId(ws.getClassstrId());
  450. result.setExamNum(ws.getExamNum());
  451. result.setEduSystem(ws.getEduSystem());
  452. result.setGraduationSchool(ws.getGraduationSchool());
  453. result.setBatchValue(ws.getBatchValue());
  454. result.setPoliticalStatu(ws.getPoliticalStatu());
  455. result.setNationality(ws.getNationality());
  456. result.setPhone(ws.getPhone());
  457. result.setOprovinceId(ws.getOprovinceId());
  458. result.setOprovince(ws.getOprovince());
  459. result.setOcityId(ws.getOcityId());
  460. result.setOcity(ws.getOcity());
  461. result.setOdistrictId(ws.getOdistrictId());
  462. result.setOdistrict(ws.getOdistrict());
  463. result.setProvinceId(ws.getProvinceId());
  464. result.setProvince(ws.getProvince());
  465. result.setCityId(ws.getCityId());
  466. result.setCity(ws.getCity());
  467. result.setDistrictId(ws.getDistrictId());
  468. result.setDistrict(ws.getDistrict());
  469. result.setAddress(ws.getAddress());
  470. result.setRegisterOntime(ws.getRegisterOntime());
  471. result.setZipCode(ws.getZipCode());
  472. result.setTrafficMethod(ws.getTrafficMethod());
  473. result.setArrive(ws.getArrive());
  474. result.setArrvieDate(ws.getArrvieDate());
  475. result.setArriveTimeId(ws.getArriveTimeId());
  476. result.setAmountPayable(ws.getAmountPayable());
  477. result.setPayAmount(ws.getPayAmount());
  478. result.setIsDrive(ws.getIsDrive());
  479. result.setCarNumber(ws.getCarNumber());
  480. return CommonResult.ok(result);
  481. }
  482. @Override
  483. @Transactional(rollbackFor = {Exception.class})
  484. public CommonResult infoCollection(InfoCollectionRequest icr, BindingResult bindingResult) throws Exception {
  485. if (bindingResult.hasErrors()) {
  486. String st = paramUtils.getParamError(bindingResult);
  487. return CommonResult.fail(st);
  488. }
  489. WelcomeStudent ws = welcomeStudentService.getDataByIdcard(icr.getCardId());
  490. if (ws == null) {
  491. ws = new WelcomeStudent();
  492. }
  493. ws.setSchool(icr.getSchool());
  494. ws.setAdmissNum(icr.getAdmissNum());
  495. ws.setName(icr.getName());
  496. ws.setPicture(icr.getPicture());
  497. ws.setCardId(icr.getCardId());
  498. ws.setSex(icr.getSex());
  499. ws.setBirthday(icr.getBirthday());
  500. ws.setCollegeId(icr.getCollegeId());
  501. ws.setMajorId(icr.getMajorId());
  502. ws.setClassstrId(icr.getClassstrId());
  503. ws.setExamNum(icr.getExamNum());
  504. ws.setEduSystem(icr.getEduSystem());
  505. ws.setGraduationSchool(icr.getGraduationSchool());
  506. ws.setBatchValue(icr.getBatchValue());
  507. ws.setPoliticalStatu(icr.getPoliticalStatu());
  508. ws.setNationality(icr.getNationality());
  509. ws.setPhone(icr.getPhone());
  510. ws.setOprovinceId(icr.getOprovinceId());
  511. ws.setOprovince(icr.getOprovince());
  512. ws.setOcityId(icr.getOcityId());
  513. ws.setOcity(icr.getOcity());
  514. ws.setOdistrictId(icr.getOdistrictId());
  515. ws.setOdistrict(icr.getOdistrict());
  516. ws.setProvinceId(icr.getProvinceId());
  517. ws.setProvince(icr.getProvince());
  518. ws.setCityId(icr.getCityId());
  519. ws.setCity(icr.getCity());
  520. ws.setDistrictId(icr.getDistrictId());
  521. ws.setDistrict(icr.getDistrict());
  522. ws.setAddress(icr.getAddress());
  523. ws.setRegisterOntime(icr.getRegisterOntime());
  524. ws.setZipCode(icr.getZipCode());
  525. ws.setTrafficMethod(icr.getTrafficMethod());
  526. ws.setArrive(icr.getArrive());
  527. ws.setArrvieDate(icr.getArrvieDate());
  528. ws.setArriveTimeId(icr.getArriveTimeId());
  529. ws.setFillStatus("已填报");
  530. //家庭成员
  531. List<WelcomeFamily> wfs = new ArrayList<>();
  532. if (icr.getFvs() != null && icr.getFvs().size() > 0) {
  533. for (FamilyVo fv : icr.getFvs()) {
  534. if(!(StringUtils.hasText(fv.getName()) && StringUtils.hasText(fv.getPhone()) && StringUtils.hasText(fv.getWorkUnit()) && StringUtils.hasText(fv.getFamilyShip()))){
  535. return CommonResult.fail("家庭成员信息不能为空!");
  536. }
  537. WelcomeFamily wf = new WelcomeFamily();
  538. wf.setName(fv.getName());
  539. wf.setPhone(fv.getPhone());
  540. wf.setWorkUnit(fv.getWorkUnit());
  541. wf.setFamilyShip(fv.getFamilyShip());
  542. wf.setStudentCard(icr.getCardId());
  543. wfs.add(wf);
  544. }
  545. }
  546. //陪同人员
  547. List<WelcomeAccompany> was = new ArrayList<>();
  548. if (icr.getAvs() != null && icr.getAvs().size() > 0) {
  549. for (AccompanyVo av : icr.getAvs()) {
  550. if(!(StringUtils.hasText(av.getName()) && StringUtils.hasText(av.getPhone()))){
  551. return CommonResult.fail("家庭成员信息不能为空!");
  552. }
  553. WelcomeAccompany wa = new WelcomeAccompany();
  554. wa.setName(av.getName());
  555. wa.setPhone(av.getPhone());
  556. wa.setStudentCard(icr.getCardId());
  557. was.add(wa);
  558. }
  559. }
  560. try {
  561. System.out.println("信息采集1");
  562. boolean resultWs = welcomeStudentService.saveOrUpdate(ws);
  563. System.out.println("信息采集1.2");
  564. if (!resultWs) {
  565. System.out.println("信息采集1.1");
  566. logger.error("采集学生信息失败,ws参数:" + JSON.toJSON(ws));
  567. throw new Exception("采集学生信息失败!");
  568. }
  569. System.out.println("信息采集2");
  570. boolean resultWf = welcomeFamilyService.saveBatch(wfs);
  571. System.out.println("信息采集1.3");
  572. if (!resultWf) {
  573. System.out.println("信息采集1.4");
  574. logger.error("采集学生信息失败,wfs参数:" + JSON.toJSON(wfs));
  575. throw new Exception("采集学生信息失败!");
  576. }
  577. System.out.println("信息采集3");
  578. boolean resultWa = welcomeAccompanyService.saveBatch(was);
  579. System.out.println("信息采集1.5");
  580. if (!resultWa) {
  581. System.out.println("信息采集1.6");
  582. logger.error("采集学生信息失败,was参数:" + JSON.toJSON(was));
  583. throw new Exception("采集学生信息失败!");
  584. }
  585. } catch (Exception e) {
  586. logger.error(e.getMessage());
  587. throw new Exception("采集失败!");
  588. }
  589. return CommonResult.ok("采集完成!");
  590. }
  591. @Override
  592. @Transactional(rollbackFor = {Exception.class})
  593. public CommonResult deleteStudentInfo(int id) throws Exception {
  594. WelcomeStudent ws = welcomeStudentService.getManageById(id);
  595. if (ws == null) {
  596. return CommonResult.fail("学生信息已失效,无法进行删除操作!");
  597. }
  598. //把旧床位清空
  599. WelcomeBed obedData = welcomeBedService.getBedByCardId(ws.getCardId());
  600. if (obedData != null) {
  601. obedData.setStudentCard(null);
  602. obedData.setCollege(null);
  603. obedData.setCollegeId(null);
  604. obedData.setMajor(null);
  605. obedData.setMajorId(null);
  606. obedData.setClassstr(null);
  607. obedData.setClassstrId(null);
  608. obedData.setIsCheck(0);
  609. obedData.setCardNum(null);
  610. obedData.setName(null);
  611. }
  612. try {
  613. //删除学生数据
  614. int deleteStudent = welcomeStudentService.deleteWelcomeStudentById(id);
  615. if (deleteStudent <= 0) {
  616. logger.error("删除学生信息失败,id参数:" + JSON.toJSON(id));
  617. throw new Exception("删除学生信息失败!");
  618. }
  619. if (obedData != null) {
  620. //删除宿舍数据
  621. int deleteSd = welcomeBedService.updateWelcomeBed(obedData);
  622. if (deleteSd < 0) {
  623. logger.error("删除宿舍失败,obedData参数:" + JSON.toJSON(obedData));
  624. throw new Exception("删除学生信息失败!");
  625. }
  626. }
  627. //删除同行人员
  628. int deleteWa = welcomeAccompanyService.deleteWelcomeAccompanyByCard(ws.getCardId());
  629. //删除家庭成员
  630. int deletef = welcomeFamilyService.deleteWelcomeFamilyByCard(ws.getCardId());
  631. } catch (Exception e) {
  632. logger.error(e.getMessage());
  633. throw new Exception("删除失败!");
  634. }
  635. return CommonResult.ok("删除成功");
  636. }
  637. @Override
  638. public CommonResult importStudentExcel(MultipartFile file) throws IOException, ParseException {
  639. System.out.println("导入学生信息");
  640. if (file.isEmpty() || file.getSize() == 0) {
  641. return CommonResult.fail("导入文件不能为空");
  642. }
  643. String ContentType = file.getContentType();
  644. InputStream inputStream = file.getInputStream();
  645. List<WelcomeStudent> result = new ArrayList<>();
  646. //xls格式文件
  647. if (ContentType.equals(eFileType.Xls.getValue())) {
  648. CommonResult<List<WelcomeStudent>> resultData = readXls(inputStream);
  649. if (!resultData.isSuccess()) {
  650. return resultData;
  651. }
  652. result = resultData.getData();
  653. } else if (ContentType.equals(eFileType.Xlsx.getValue())) {
  654. CommonResult<List<WelcomeStudent>> resultData = readXlsx(inputStream);
  655. if (!resultData.isSuccess()) {
  656. return resultData;
  657. }
  658. result = resultData.getData();
  659. } else {
  660. return CommonResult.fail("学生信息数据导入只支持Xls或Xlsx格式文件");
  661. }
  662. List<String> cardIds = result.stream().map(WelcomeStudent::getCardId).collect(Collectors.toList());
  663. List<WelcomeStudent> existStudents = welcomeStudentService.queryStudentByCardId(cardIds);
  664. if (existStudents != null && existStudents.size() > 0) {
  665. for (WelcomeStudent ws : result) {
  666. Optional<WelcomeStudent> ows = existStudents.stream().filter(e -> e.getCardId().equals(ws.getCardId())).findFirst();
  667. if (ows != null && ows.isPresent()) {
  668. ws.setId(ws.getId());
  669. ws.setAdmissNum(ws.getAdmissNum());//录取号
  670. ws.setName(ws.getName());//姓名
  671. ws.setCardId(ws.getCardId());//身份证号
  672. ws.setSchool(ws.getSchool());//校区
  673. ws.setCollege(ws.getCollege());
  674. ws.setCollegeId(ws.getCollegeId());
  675. ws.setMajor(ws.getMajor());
  676. ws.setMajorId(ws.getMajorId());
  677. ws.setClassstr(ws.getClassstr());
  678. ws.setClassstrId(ws.getClassstrId());
  679. ws.setExamNum(ws.getExamNum());//考生号
  680. ws.setEduSystem(ws.getEduSystem());//学制
  681. ws.setGraduationSchool(ws.getGraduationSchool());//毕业中学
  682. ws.setBatchValue(ws.getBatchValue());//批次
  683. ws.setPoliticalStatu(ws.getPoliticalStatu());//政治面貌
  684. ws.setNationality(ws.getNationality());//民族
  685. ws.setPhone(ws.getPhone());//手机号码
  686. ws.setOprovince(ws.getOprovince());
  687. ws.setOprovinceId(ws.getOprovinceId());
  688. ws.setOcity(ws.getOcity());
  689. ws.setOcityId(ws.getOcityId());
  690. ws.setOdistrict(ws.getOdistrict());
  691. ws.setOdistrictId(ws.getOdistrictId());
  692. ws.setProvince(ws.getProvince());
  693. ws.setProvinceId(ws.getProvinceId());
  694. ws.setCity(ws.getCity());
  695. ws.setCityId(ws.getCityId());
  696. ws.setDistrict(ws.getDistrict());
  697. ws.setDistrictId(ws.getDistrictId());
  698. ws.setAddress(ws.getAddress());
  699. ws.setZipCode(ws.getZipCode());
  700. }
  701. }
  702. }
  703. boolean resultBool = welcomeStudentService.saveOrUpdateBatch(result);
  704. System.out.println("导入学生1");
  705. return resultBool ? CommonResult.ok("导入成功") : CommonResult.fail("导入失败");
  706. }
  707. /**
  708. * xls文件读取方法
  709. *
  710. * @param inputStream
  711. * @return
  712. * @throws IOException
  713. * @throws ParseException
  714. */
  715. private CommonResult<List<WelcomeStudent>> readXls(InputStream inputStream) throws IOException, ParseException {
  716. List<WelcomeStudent> result = new ArrayList<>();
  717. HSSFWorkbook sheets = new HSSFWorkbook(inputStream);
  718. List<WelcomeOrg> ws = welcomeOrgService.list(null);
  719. List<WelcomeCity> citys = welcomeCityService.list(null);
  720. //读取第一张sheet
  721. HSSFSheet sheetAt = sheets.getSheetAt(0);
  722. DataFormatter dataFormatter = new DataFormatter();
  723. try {
  724. //rowNum = 3 从第三行开始获取值
  725. //sheetAt.getLastRowNum():从0开始统计数量 所以得+1
  726. for (int rowNum = 0; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
  727. HSSFRow row = sheetAt.getRow(rowNum);
  728. if (row != null) {
  729. //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
  730. //所以先使用setCellType()方法先将该单元格的类型设置为STRING
  731. //然后poi会根据字符串读取它
  732. //第一行数据获取月份
  733. if (rowNum == 0) {
  734. String number = dataFormatter.formatCellValue(row.getCell(0));//序号
  735. if (!number.equals("序号")) {
  736. return CommonResult.fail("导入数据第一列为序号");
  737. }
  738. String assNum = dataFormatter.formatCellValue(row.getCell(1));//录取号
  739. if (!assNum.equals("录取号")) {
  740. return CommonResult.fail("导入数据第二列为录取号");
  741. }
  742. String name = dataFormatter.formatCellValue(row.getCell(2));//姓名
  743. if (!name.equals("姓名")) {
  744. return CommonResult.fail("导入数据第三列为姓名");
  745. }
  746. String cardId = dataFormatter.formatCellValue(row.getCell(3));//身份证号
  747. if (!cardId.equals("身份证号")) {
  748. return CommonResult.fail("导入数据第四列为身份证号");
  749. }
  750. String school = dataFormatter.formatCellValue(row.getCell(4));//校区
  751. if (!school.equals("校区")) {
  752. return CommonResult.fail("导入数据第五列为校区");
  753. }
  754. String college = dataFormatter.formatCellValue(row.getCell(5));//院系
  755. if (!college.equals("院系")) {
  756. return CommonResult.fail("导入数据第六列为院系");
  757. }
  758. String major = dataFormatter.formatCellValue(row.getCell(6));//专业
  759. if (!major.equals("专业")) {
  760. return CommonResult.fail("导入数据第七列为专业");
  761. }
  762. String classstr = dataFormatter.formatCellValue(row.getCell(7));//班级
  763. if (!classstr.equals("班级")) {
  764. return CommonResult.fail("导入数据第八列为班级");
  765. }
  766. String examNum = dataFormatter.formatCellValue(row.getCell(8));//考生号
  767. if (!examNum.equals("考生号")) {
  768. return CommonResult.fail("导入数据第九列为考生号");
  769. }
  770. String eduSystem = dataFormatter.formatCellValue(row.getCell(9));//学制
  771. if (!eduSystem.equals("学制")) {
  772. return CommonResult.fail("导入数据第十列为学制");
  773. }
  774. String graSchool = dataFormatter.formatCellValue(row.getCell(10));//毕业中学
  775. if (!graSchool.equals("毕业中学")) {
  776. return CommonResult.fail("导入数据第十一列为毕业中学批次");
  777. }
  778. String batchValue = dataFormatter.formatCellValue(row.getCell(11));//批次
  779. if (!batchValue.equals("批次")) {
  780. return CommonResult.fail("导入数据第十一列为批次");
  781. }
  782. String politicalStatu = dataFormatter.formatCellValue(row.getCell(12));//政治面貌
  783. if (!politicalStatu.equals("政治面貌")) {
  784. return CommonResult.fail("导入数据第十一列为政治面貌");
  785. }
  786. String nationality = dataFormatter.formatCellValue(row.getCell(13));//民族
  787. if (!nationality.equals("民族")) {
  788. return CommonResult.fail("导入数据第十一列为民族");
  789. }
  790. String phone = dataFormatter.formatCellValue(row.getCell(14));//手机号码
  791. if (!phone.equals("手机号码")) {
  792. return CommonResult.fail("导入数据第十一列为手机号码");
  793. }
  794. String nativePlace = dataFormatter.formatCellValue(row.getCell(15));//籍贯
  795. if (!nativePlace.equals("籍贯")) {
  796. return CommonResult.fail("导入数据第十一列为籍贯");
  797. }
  798. String addressPlace = dataFormatter.formatCellValue(row.getCell(16));//家庭住址
  799. if (!addressPlace.equals("家庭住址")) {
  800. return CommonResult.fail("导入数据第十一列为家庭住址");
  801. }
  802. String addressDetail = dataFormatter.formatCellValue(row.getCell(17));//详细住址
  803. if (!addressDetail.equals("详细住址")) {
  804. return CommonResult.fail("导入数据第十一列为详细住址");
  805. }
  806. String zipCode = dataFormatter.formatCellValue(row.getCell(18));//邮编
  807. if (!zipCode.equals("邮编")) {
  808. return CommonResult.fail("导入数据第十一列为邮编");
  809. }
  810. } else {
  811. WelcomeStudent studentData = new WelcomeStudent();
  812. String assNum = dataFormatter.formatCellValue(row.getCell(1));//录取号
  813. studentData.setAdmissNum(assNum);
  814. String name = dataFormatter.formatCellValue(row.getCell(2));//姓名
  815. studentData.setName(name);
  816. String cardId = dataFormatter.formatCellValue(row.getCell(3));//身份证号
  817. studentData.setCardId(cardId);
  818. String school = dataFormatter.formatCellValue(row.getCell(4));//校区
  819. studentData.setSchool(school);
  820. //region 院系专业
  821. String college = dataFormatter.formatCellValue(row.getCell(5));//院系
  822. Optional<WelcomeOrg> owo = ws.stream().filter(e -> e.getName().equals(college)).findFirst();
  823. if (owo != null && owo.isPresent()) {
  824. studentData.setCollege(college);
  825. studentData.setCollegeId(owo.get().getId());
  826. }
  827. String major = dataFormatter.formatCellValue(row.getCell(6));//专业
  828. Optional<WelcomeOrg> omwo = ws.stream().filter(e -> e.getName().equals(major)).findFirst();
  829. if (omwo != null && omwo.isPresent()) {
  830. studentData.setMajor(major);
  831. studentData.setMajorId(omwo.get().getId());
  832. }
  833. String classstr = dataFormatter.formatCellValue(row.getCell(7));//班级
  834. Optional<WelcomeOrg> ocwo = ws.stream().filter(e -> e.getName().equals(classstr)).findFirst();
  835. if (ocwo != null && ocwo.isPresent()) {
  836. studentData.setClassstr(classstr);
  837. studentData.setClassstrId(ocwo.get().getId());
  838. }
  839. //endregion
  840. String examNum = dataFormatter.formatCellValue(row.getCell(8));//考生号
  841. studentData.setExamNum(examNum);
  842. String eduSystem = dataFormatter.formatCellValue(row.getCell(9));//学制
  843. studentData.setEduSystem(eduSystem);
  844. String graSchool = dataFormatter.formatCellValue(row.getCell(10));//毕业中学
  845. studentData.setGraduationSchool(graSchool);
  846. String batchValue = dataFormatter.formatCellValue(row.getCell(11));//批次
  847. studentData.setBatchValue(batchValue);
  848. String politicalStatu = dataFormatter.formatCellValue(row.getCell(12));//政治面貌
  849. studentData.setPoliticalStatu(politicalStatu);
  850. String nationality = dataFormatter.formatCellValue(row.getCell(13));//民族
  851. studentData.setNationality(nationality);
  852. String phone = dataFormatter.formatCellValue(row.getCell(14));//手机号码
  853. studentData.setPhone(phone);
  854. //region 籍贯
  855. String nativePlace = dataFormatter.formatCellValue(row.getCell(15));//籍贯
  856. String[] addressDatas = nativePlace.split("/");
  857. if (citys != null && citys.size() > 0) {
  858. if (addressDatas != null && addressDatas.length >= 1) {
  859. if (!addressDatas[0].contains("省")) {
  860. return CommonResult.fail("录取编号为\" + assNum + \"的籍贯格式应该是 省/市/县");
  861. }
  862. Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getDistrictZh().equals(addressDatas[0])).findFirst();
  863. if (oProvince != null && oProvince.isPresent()) {
  864. studentData.setOprovince(addressDatas[0]);
  865. studentData.setOprovinceId(oProvince.get().getId());
  866. } else {
  867. return CommonResult.fail("录取编号为" + assNum + "的籍贯格式应该是 省/市/县");
  868. }
  869. }
  870. if (addressDatas != null && addressDatas.length >= 2) {
  871. Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getDistrictZh().equals(addressDatas[1])).findFirst();
  872. if (oProvince != null && oProvince.isPresent()) {
  873. studentData.setOcity(addressDatas[1]);
  874. studentData.setOcityId(oProvince.get().getId());
  875. } else {
  876. return CommonResult.fail("录取编号为" + assNum + "的籍贯格式应该是 省/市/县");
  877. }
  878. }
  879. if (addressDatas != null && addressDatas.length >= 3) {
  880. Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getCityZh().equals(addressDatas[1]) && e.getDistrictZh().equals(addressDatas[2])).findFirst();
  881. if (oProvince != null && oProvince.isPresent()) {
  882. studentData.setOdistrict(addressDatas[2]);
  883. studentData.setOdistrictId(oProvince.get().getId());
  884. } else {
  885. return CommonResult.fail("录取编号为" + assNum + "的籍贯格式应该是 省/市/县");
  886. }
  887. }
  888. }
  889. //endregion
  890. //region 家庭住址
  891. String addressPlace = dataFormatter.formatCellValue(row.getCell(16));//家庭住址
  892. String[] addressPlaces = addressPlace.split("/");
  893. if (citys != null && citys.size() > 0) {
  894. if (addressPlaces != null && addressPlaces.length >= 1) {
  895. if (!addressPlaces[0].contains("省")) {
  896. return CommonResult.fail("录取编号为" + assNum + "的家庭住址格式应该是 省/市/县");
  897. }
  898. Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getDistrictZh().equals(addressPlaces[0])).findFirst();
  899. if (oProvince != null && oProvince.isPresent()) {
  900. studentData.setProvince(addressPlaces[0]);
  901. studentData.setProvinceId(oProvince.get().getId());
  902. } else {
  903. return CommonResult.fail("录取编号为" + assNum + "的家庭住址格式应该是 省/市/县");
  904. }
  905. }
  906. if (addressPlaces != null && addressPlaces.length >= 2) {
  907. Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getDistrictZh().equals(addressPlaces[1])).findFirst();
  908. if (oProvince != null && oProvince.isPresent()) {
  909. studentData.setCity(addressPlaces[1]);
  910. studentData.setCityId(oProvince.get().getId());
  911. } else {
  912. return CommonResult.fail("录取编号为" + assNum + "的家庭住址格式应该是 省/市/县");
  913. }
  914. }
  915. if (addressPlaces != null && addressPlaces.length >= 3) {
  916. Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getCityZh().equals(addressPlaces[1]) && e.getDistrictZh().equals(addressPlaces[2])).findFirst();
  917. if (oProvince != null && oProvince.isPresent()) {
  918. studentData.setDistrict(addressPlaces[2]);
  919. studentData.setDistrictId(oProvince.get().getId());
  920. } else {
  921. return CommonResult.fail("录取编号为" + assNum + "的家庭住址格式应该是 省/市/县");
  922. }
  923. }
  924. }
  925. //endregion
  926. String addressDetail = dataFormatter.formatCellValue(row.getCell(17));//详细住址
  927. studentData.setAddress(addressDetail);
  928. String zipCode = dataFormatter.formatCellValue(row.getCell(18));//邮编
  929. studentData.setZipCode(zipCode);
  930. result.add(studentData);
  931. }
  932. }
  933. }
  934. } catch (Exception e) {
  935. return CommonResult.fail("请按模板格式导入数据");
  936. }
  937. return CommonResult.ok(result);
  938. }
  939. /**
  940. * xls文件读取方法
  941. *
  942. * @param inputStream
  943. * @return
  944. * @throws IOException
  945. * @throws ParseException
  946. */
  947. private CommonResult<List<WelcomeStudent>> readXlsx(InputStream inputStream) throws IOException, ParseException {
  948. List<WelcomeStudent> result = new ArrayList<>();
  949. XSSFWorkbook sheets = new XSSFWorkbook(inputStream);
  950. List<WelcomeOrg> ws = welcomeOrgService.list(null);
  951. List<WelcomeCity> citys = welcomeCityService.list(null);
  952. //读取第一张sheet
  953. XSSFSheet sheetAt = sheets.getSheetAt(0);
  954. DataFormatter dataFormatter = new DataFormatter();
  955. try {
  956. //rowNum = 3 从第三行开始获取值
  957. //sheetAt.getLastRowNum():从0开始统计数量 所以得+1
  958. for (int rowNum = 0; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
  959. XSSFRow row = sheetAt.getRow(rowNum);
  960. if (row != null) {
  961. //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
  962. //所以先使用setCellType()方法先将该单元格的类型设置为STRING
  963. //然后poi会根据字符串读取它
  964. //第一行数据获取月份
  965. if (rowNum == 0) {
  966. String number = dataFormatter.formatCellValue(row.getCell(0));//序号
  967. if (!number.equals("序号")) {
  968. return CommonResult.fail("导入数据第一列为序号");
  969. }
  970. String assNum = dataFormatter.formatCellValue(row.getCell(1));//录取号
  971. if (!assNum.equals("录取号")) {
  972. return CommonResult.fail("导入数据第二列为录取号");
  973. }
  974. String name = dataFormatter.formatCellValue(row.getCell(2));//姓名
  975. if (!name.equals("姓名")) {
  976. return CommonResult.fail("导入数据第三列为姓名");
  977. }
  978. String cardId = dataFormatter.formatCellValue(row.getCell(3));//身份证号
  979. if (!cardId.equals("身份证号")) {
  980. return CommonResult.fail("导入数据第四列为身份证号");
  981. }
  982. String school = dataFormatter.formatCellValue(row.getCell(4));//校区
  983. if (!school.equals("校区")) {
  984. return CommonResult.fail("导入数据第五列为校区");
  985. }
  986. String college = dataFormatter.formatCellValue(row.getCell(5));//院系
  987. if (!college.equals("院系")) {
  988. return CommonResult.fail("导入数据第六列为院系");
  989. }
  990. String major = dataFormatter.formatCellValue(row.getCell(6));//专业
  991. if (!major.equals("专业")) {
  992. return CommonResult.fail("导入数据第七列为专业");
  993. }
  994. String classstr = dataFormatter.formatCellValue(row.getCell(7));//班级
  995. if (!classstr.equals("班级")) {
  996. return CommonResult.fail("导入数据第八列为班级");
  997. }
  998. String examNum = dataFormatter.formatCellValue(row.getCell(8));//考生号
  999. if (!examNum.equals("考生号")) {
  1000. return CommonResult.fail("导入数据第九列为考生号");
  1001. }
  1002. String eduSystem = dataFormatter.formatCellValue(row.getCell(9));//学制
  1003. if (!eduSystem.equals("学制")) {
  1004. return CommonResult.fail("导入数据第十列为学制");
  1005. }
  1006. String graSchool = dataFormatter.formatCellValue(row.getCell(10));//毕业中学
  1007. if (!graSchool.equals("毕业中学")) {
  1008. return CommonResult.fail("导入数据第十一列为毕业中学批次");
  1009. }
  1010. String batchValue = dataFormatter.formatCellValue(row.getCell(11));//批次
  1011. if (!batchValue.equals("批次")) {
  1012. return CommonResult.fail("导入数据第十一列为批次");
  1013. }
  1014. String politicalStatu = dataFormatter.formatCellValue(row.getCell(12));//政治面貌
  1015. if (!politicalStatu.equals("政治面貌")) {
  1016. return CommonResult.fail("导入数据第十一列为政治面貌");
  1017. }
  1018. String nationality = dataFormatter.formatCellValue(row.getCell(13));//民族
  1019. if (!nationality.equals("民族")) {
  1020. return CommonResult.fail("导入数据第十一列为民族");
  1021. }
  1022. String phone = dataFormatter.formatCellValue(row.getCell(14));//手机号码
  1023. if (!phone.equals("手机号码")) {
  1024. return CommonResult.fail("导入数据第十一列为手机号码");
  1025. }
  1026. String nativePlace = dataFormatter.formatCellValue(row.getCell(15));//籍贯
  1027. if (!nativePlace.equals("籍贯")) {
  1028. return CommonResult.fail("导入数据第十一列为籍贯");
  1029. }
  1030. String addressPlace = dataFormatter.formatCellValue(row.getCell(16));//家庭住址
  1031. if (!addressPlace.equals("家庭住址")) {
  1032. return CommonResult.fail("导入数据第十一列为家庭住址");
  1033. }
  1034. String addressDetail = dataFormatter.formatCellValue(row.getCell(17));//详细住址
  1035. if (!addressDetail.equals("详细住址")) {
  1036. return CommonResult.fail("导入数据第十一列为详细住址");
  1037. }
  1038. String zipCode = dataFormatter.formatCellValue(row.getCell(18));//邮编
  1039. if (!zipCode.equals("邮编")) {
  1040. return CommonResult.fail("导入数据第十一列为邮编");
  1041. }
  1042. } else {
  1043. WelcomeStudent studentData = new WelcomeStudent();
  1044. String assNum = dataFormatter.formatCellValue(row.getCell(1));//录取号
  1045. studentData.setAdmissNum(assNum);
  1046. String name = dataFormatter.formatCellValue(row.getCell(2));//姓名
  1047. studentData.setName(name);
  1048. String cardId = dataFormatter.formatCellValue(row.getCell(3));//身份证号
  1049. studentData.setCardId(cardId);
  1050. String school = dataFormatter.formatCellValue(row.getCell(4));//校区
  1051. studentData.setSchool(school);
  1052. //region 院系专业
  1053. String college = dataFormatter.formatCellValue(row.getCell(5));//院系
  1054. Optional<WelcomeOrg> owo = ws.stream().filter(e -> e.getName().equals(college)).findFirst();
  1055. if (owo != null && owo.isPresent()) {
  1056. studentData.setCollege(college);
  1057. studentData.setCollegeId(owo.get().getId());
  1058. }
  1059. String major = dataFormatter.formatCellValue(row.getCell(6));//专业
  1060. Optional<WelcomeOrg> omwo = ws.stream().filter(e -> e.getName().equals(major)).findFirst();
  1061. if (omwo != null && omwo.isPresent()) {
  1062. studentData.setMajor(major);
  1063. studentData.setMajorId(omwo.get().getId());
  1064. }
  1065. String classstr = dataFormatter.formatCellValue(row.getCell(7));//班级
  1066. Optional<WelcomeOrg> ocwo = ws.stream().filter(e -> e.getName().equals(classstr)).findFirst();
  1067. if (ocwo != null && ocwo.isPresent()) {
  1068. studentData.setClassstr(classstr);
  1069. studentData.setClassstrId(ocwo.get().getId());
  1070. }
  1071. //endregion
  1072. String examNum = dataFormatter.formatCellValue(row.getCell(8));//考生号
  1073. studentData.setExamNum(examNum);
  1074. String eduSystem = dataFormatter.formatCellValue(row.getCell(9));//学制
  1075. studentData.setEduSystem(eduSystem);
  1076. String graSchool = dataFormatter.formatCellValue(row.getCell(10));//毕业中学
  1077. studentData.setGraduationSchool(graSchool);
  1078. String batchValue = dataFormatter.formatCellValue(row.getCell(11));//批次
  1079. studentData.setBatchValue(batchValue);
  1080. String politicalStatu = dataFormatter.formatCellValue(row.getCell(12));//政治面貌
  1081. studentData.setPoliticalStatu(politicalStatu);
  1082. String nationality = dataFormatter.formatCellValue(row.getCell(13));//民族
  1083. studentData.setNationality(nationality);
  1084. String phone = dataFormatter.formatCellValue(row.getCell(14));//手机号码
  1085. studentData.setPhone(phone);
  1086. //region 籍贯
  1087. String nativePlace = dataFormatter.formatCellValue(row.getCell(15));//籍贯
  1088. String[] addressDatas = nativePlace.split("/");
  1089. if (citys != null && citys.size() > 0) {
  1090. if (addressDatas != null && addressDatas.length >= 1) {
  1091. if (!addressDatas[0].contains("省")) {
  1092. return CommonResult.fail("录取编号为\" + assNum + \"的籍贯格式应该是 省/市/县");
  1093. }
  1094. Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getDistrictZh().equals(addressDatas[0])).findFirst();
  1095. if (oProvince != null && oProvince.isPresent()) {
  1096. studentData.setOprovince(addressDatas[0]);
  1097. studentData.setOprovinceId(oProvince.get().getId());
  1098. } else {
  1099. return CommonResult.fail("录取编号为" + assNum + "的籍贯格式应该是 省/市/县");
  1100. }
  1101. }
  1102. if (addressDatas != null && addressDatas.length >= 2) {
  1103. Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getDistrictZh().equals(addressDatas[1])).findFirst();
  1104. if (oProvince != null && oProvince.isPresent()) {
  1105. studentData.setOcity(addressDatas[1]);
  1106. studentData.setOcityId(oProvince.get().getId());
  1107. } else {
  1108. return CommonResult.fail("录取编号为" + assNum + "的籍贯格式应该是 省/市/县");
  1109. }
  1110. }
  1111. if (addressDatas != null && addressDatas.length >= 3) {
  1112. Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getCityZh().equals(addressDatas[1]) && e.getDistrictZh().equals(addressDatas[2])).findFirst();
  1113. if (oProvince != null && oProvince.isPresent()) {
  1114. studentData.setOdistrict(addressDatas[2]);
  1115. studentData.setOdistrictId(oProvince.get().getId());
  1116. } else {
  1117. return CommonResult.fail("录取编号为" + assNum + "的籍贯格式应该是 省/市/县");
  1118. }
  1119. }
  1120. }
  1121. //endregion
  1122. //region 家庭住址
  1123. String addressPlace = dataFormatter.formatCellValue(row.getCell(16));//家庭住址
  1124. String[] addressPlaces = addressPlace.split("/");
  1125. if (citys != null && citys.size() > 0) {
  1126. if (addressPlaces != null && addressPlaces.length >= 1) {
  1127. if (!addressPlaces[0].contains("省")) {
  1128. return CommonResult.fail("录取编号为" + assNum + "的家庭住址格式应该是 省/市/县");
  1129. }
  1130. Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getDistrictZh().equals(addressPlaces[0])).findFirst();
  1131. if (oProvince != null && oProvince.isPresent()) {
  1132. studentData.setProvince(addressPlaces[0]);
  1133. studentData.setProvinceId(oProvince.get().getId());
  1134. } else {
  1135. return CommonResult.fail("录取编号为" + assNum + "的家庭住址格式应该是 省/市/县");
  1136. }
  1137. }
  1138. if (addressPlaces != null && addressPlaces.length >= 2) {
  1139. Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getDistrictZh().equals(addressPlaces[1])).findFirst();
  1140. if (oProvince != null && oProvince.isPresent()) {
  1141. studentData.setCity(addressPlaces[1]);
  1142. studentData.setCityId(oProvince.get().getId());
  1143. } else {
  1144. return CommonResult.fail("录取编号为" + assNum + "的家庭住址格式应该是 省/市/县");
  1145. }
  1146. }
  1147. if (addressPlaces != null && addressPlaces.length >= 3) {
  1148. Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getCityZh().equals(addressPlaces[1]) && e.getDistrictZh().equals(addressPlaces[2])).findFirst();
  1149. if (oProvince != null && oProvince.isPresent()) {
  1150. studentData.setDistrict(addressPlaces[2]);
  1151. studentData.setDistrictId(oProvince.get().getId());
  1152. } else {
  1153. return CommonResult.fail("录取编号为" + assNum + "的家庭住址格式应该是 省/市/县");
  1154. }
  1155. }
  1156. }
  1157. //endregion
  1158. String addressDetail = dataFormatter.formatCellValue(row.getCell(17));//详细住址
  1159. studentData.setAddress(addressDetail);
  1160. String zipCode = dataFormatter.formatCellValue(row.getCell(18));//邮编
  1161. studentData.setZipCode(zipCode);
  1162. result.add(studentData);
  1163. }
  1164. }
  1165. }
  1166. } catch (Exception e) {
  1167. return CommonResult.fail("请按模板格式导入数据");
  1168. }
  1169. return CommonResult.ok(result);
  1170. }
  1171. @Override
  1172. public CommonResult downloadStudentExcel() {
  1173. return CommonResult.ok("200", "操作成功", "https://chtech.ncjti.edu.cn/alumnus/homeimage/学生信息管理.xlsx");
  1174. }
  1175. @Override
  1176. public void welcomeStudentExport(HttpServletResponse response, Integer collegeId, Integer majorId, Integer classstrId, String trafficMethod, String name) {
  1177. List<StudentPageVo> result = welcomeStudentService.queryStudentList(collegeId, majorId, classstrId, trafficMethod, name);
  1178. //导出
  1179. Workbook workbook = new XSSFWorkbook();
  1180. Sheet sheet = workbook.createSheet("学生信息");
  1181. Row headerRow = sheet.createRow(0);
  1182. headerRow.createCell(0).setCellValue("序号");
  1183. headerRow.createCell(1).setCellValue("录取号");
  1184. headerRow.createCell(2).setCellValue("姓名");
  1185. headerRow.createCell(3).setCellValue("身份证号");
  1186. headerRow.createCell(4).setCellValue("院系");
  1187. headerRow.createCell(5).setCellValue("专业");
  1188. headerRow.createCell(6).setCellValue("班级");
  1189. headerRow.createCell(7).setCellValue("交通方式");
  1190. headerRow.createCell(8).setCellValue("到站地点");
  1191. headerRow.createCell(9).setCellValue("陪同人数");
  1192. headerRow.createCell(10).setCellValue("填报状态");
  1193. headerRow.createCell(11).setCellValue("应缴金额");
  1194. headerRow.createCell(12).setCellValue("实付金额");
  1195. headerRow.createCell(13).setCellValue("宿舍信息");
  1196. for (int i = 0; i < result.size(); i++) {
  1197. StudentPageVo studentData = result.get(i);
  1198. Row dataRow = sheet.createRow(i + 1);
  1199. dataRow.createCell(0).setCellValue(i + 1);
  1200. dataRow.createCell(1).setCellValue(studentData.getAdmissNum());
  1201. dataRow.createCell(2).setCellValue(studentData.getName());
  1202. dataRow.createCell(3).setCellValue(studentData.getCardId());
  1203. dataRow.createCell(4).setCellValue(studentData.getCollege());
  1204. dataRow.createCell(5).setCellValue(studentData.getMajor());
  1205. dataRow.createCell(6).setCellValue(studentData.getClassstr());
  1206. dataRow.createCell(7).setCellValue(studentData.getTrafficMethod());
  1207. dataRow.createCell(8).setCellValue(studentData.getArrive());
  1208. dataRow.createCell(9).setCellValue(studentData.getAccompanyNum());
  1209. dataRow.createCell(10).setCellValue(studentData.getFillStatus());
  1210. dataRow.createCell(11).setCellValue(String.valueOf(studentData.getAmountPayable()));
  1211. dataRow.createCell(12).setCellValue(String.valueOf(studentData.getPayAmount()));
  1212. dataRow.createCell(13).setCellValue(studentData.getDormitory());
  1213. }
  1214. // 将工作簿写入文件
  1215. ExcelUtils.excelDownload(workbook, "学生信息.xlsx", response);
  1216. }
  1217. @Override
  1218. public CommonResult studentOverview() {
  1219. // 报到总数
  1220. int studentTotal = welcomeStudentService.count(new QueryWrapper<>());
  1221. // 寝室总数
  1222. int dormitoryTotal = welcomeDormitoryService.count(new QueryWrapper<>());
  1223. // 已入住寝室数
  1224. LambdaQueryWrapper<WelcomeDormitory> wrapper=new LambdaQueryWrapper<>();
  1225. wrapper.ne(WelcomeDormitory::getStatus,2);
  1226. int count = welcomeDormitoryService.count(wrapper);
  1227. LocalDateTime start = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0);
  1228. LocalDateTime end = start.plusDays(1);
  1229. DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  1230. Integer visitorTotal=welcomeVisitorService.countTotal(start,end);
  1231. StudentOverviewVo vo = new StudentOverviewVo();
  1232. vo.setStudentTotal(studentTotal);
  1233. vo.setDormitoryTotal(dormitoryTotal);
  1234. vo.setCheckInTotal(count);
  1235. vo.setVisitorTotal(visitorTotal);
  1236. return CommonResult.ok(vo);
  1237. }
  1238. @Override
  1239. public CommonResult studentRegister() {
  1240. // 获取总数
  1241. Integer count = welcomeStudentService.totalCount();
  1242. List<StudentRegisterVo> vos = welcomeStudentService.studentRegister();
  1243. StudentRegisterVo vo = new StudentRegisterVo();
  1244. vo.setCollegeName("报到总数");
  1245. vo.setCount(count);
  1246. vos.add(vo);
  1247. return CommonResult.ok(vos);
  1248. }
  1249. @Override
  1250. public CommonResult studentTraffic() {
  1251. List<StudentTrafficVo> vos = welcomeStudentService.studentTraffic();
  1252. return CommonResult.ok(vos);
  1253. }
  1254. @Override
  1255. public CommonResult studentSexRatio() {
  1256. Integer manCount = welcomeStudentService.genderCount("男");
  1257. Integer girlCount = welcomeStudentService.genderCount("女");
  1258. StudentSexRatioVo vo = new StudentSexRatioVo();
  1259. vo.setCollegeName("全部");
  1260. vo.setManCount(manCount);
  1261. vo.setGirlCount(girlCount);
  1262. List<StudentSexRatioVo> vos = welcomeStudentService.studentSexRatio();
  1263. vos.add(vo);
  1264. return CommonResult.ok(vos);
  1265. }
  1266. @Override
  1267. public CommonResult studentStay() {
  1268. ArrayList<StudentStayVo> vos = new ArrayList<>();
  1269. List<WelcomeSchool> list = welcomeSchoolService.list(new QueryWrapper<>());
  1270. for (WelcomeSchool welcomeSchool : list) {
  1271. Integer schoolId = welcomeSchool.getId();
  1272. List<WelcomeBuild> builds=welcomeBuildService.getBuild(schoolId);
  1273. for (WelcomeBuild build : builds) {
  1274. Integer buildId = build.getId();
  1275. StudentStayVo vo =welcomeDormitoryService.getTotalCount(buildId);
  1276. vo.setSchoolName(welcomeSchool.getSchool());
  1277. vo.setBuildName(build.getBuild());
  1278. vos.add(vo);
  1279. }
  1280. }
  1281. return CommonResult.ok(vos);
  1282. }
  1283. }