WelcomeStudentController.java 72 KB

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