WelcomeStudentController.java 92 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904
  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.core.metadata.IPage;
  8. import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
  9. import com.baomidou.mybatisplus.extension.api.R;
  10. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  11. import com.template.annotation.PassToken;
  12. import com.template.api.WelcomeStudentControllerAPI;
  13. import com.template.common.utils.*;
  14. import com.template.model.enumModel.eFileType;
  15. import com.template.model.enumModel.eProjectType;
  16. import com.template.model.enumModel.eSchool;
  17. import com.template.model.pojo.*;
  18. import com.template.model.request.*;
  19. import com.template.model.result.CommonResult;
  20. import com.template.model.result.PageUtils;
  21. import com.template.model.vo.*;
  22. import com.template.services.*;
  23. import io.swagger.annotations.ApiModelProperty;
  24. import org.apache.poi.hssf.usermodel.HSSFRow;
  25. import org.apache.poi.hssf.usermodel.HSSFSheet;
  26. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  27. import org.apache.poi.ss.usermodel.DataFormatter;
  28. import org.apache.poi.ss.usermodel.Row;
  29. import org.apache.poi.ss.usermodel.Sheet;
  30. import org.apache.poi.ss.usermodel.Workbook;
  31. import org.apache.poi.xssf.usermodel.XSSFRow;
  32. import org.apache.poi.xssf.usermodel.XSSFSheet;
  33. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  34. import org.slf4j.Logger;
  35. import org.slf4j.LoggerFactory;
  36. import org.springframework.beans.factory.annotation.Autowired;
  37. import org.springframework.transaction.annotation.Transactional;
  38. import org.springframework.util.StringUtils;
  39. import org.springframework.validation.BindingResult;
  40. import org.springframework.web.bind.annotation.RestController;
  41. import org.springframework.web.multipart.MultipartFile;
  42. import javax.servlet.http.HttpServletResponse;
  43. import java.io.IOException;
  44. import java.io.InputStream;
  45. import java.math.BigDecimal;
  46. import java.math.BigInteger;
  47. import java.math.RoundingMode;
  48. import java.text.ParseException;
  49. import java.time.LocalDateTime;
  50. import java.time.format.DateTimeFormatter;
  51. import java.util.*;
  52. import java.util.stream.Collectors;
  53. /**
  54. * <p>
  55. * 前端控制器
  56. * </p>
  57. *
  58. * @author ceshi
  59. * @since 2025-06-13
  60. */
  61. @RestController
  62. public class WelcomeStudentController implements WelcomeStudentControllerAPI {
  63. @Autowired
  64. private WelcomeStudentService welcomeStudentService;
  65. @Autowired
  66. private WelcomeFamilyService welcomeFamilyService;
  67. @Autowired
  68. private WelcomeAccompanyService welcomeAccompanyService;
  69. @Autowired
  70. private WelcomeBedService welcomeBedService;
  71. @Autowired
  72. private WelcomeAccountService welcomeAccountService;
  73. @Autowired
  74. private WelcomeSettingService welcomeSettingService;
  75. @Autowired
  76. private WelcomeArriveSettingService welcomeArriveSettingService;
  77. @Autowired
  78. private WelcomeOrgService welcomeOrgService;
  79. @Autowired
  80. private WelcomeCityService welcomeCityService;
  81. @Autowired
  82. private WelcomeSchoolService welcomeSchoolService;
  83. @Autowired
  84. private WelcomeBuildService welcomeBuildService;
  85. @Autowired
  86. private WelcomeDormitoryService welcomeDormitoryService;
  87. @Autowired
  88. private WelcomeVisitorService welcomeVisitorService;
  89. @Autowired
  90. private WelcomePaySettingService welcomePaySettingService;
  91. private static Logger logger = LoggerFactory.getLogger(WelcomeStudentController.class);
  92. @Override
  93. @Transactional(rollbackFor = {Exception.class})
  94. public CommonResult insertStudentInfo(InsertStudentRequest isr, BindingResult bindingResult) throws Exception {
  95. if (bindingResult.hasErrors()) {
  96. String st = paramUtils.getParamError(bindingResult);
  97. return CommonResult.fail(st);
  98. }
  99. int existCount = welcomeStudentService.existStudentInfo(isr.getAdmissNum(), isr.getCardId());
  100. if (existCount > 0) {
  101. return CommonResult.fail("当前录取号或身份证号已存在!");
  102. }
  103. //region 学生信息
  104. WelcomeStudent ws = new WelcomeStudent();
  105. ws.setAdmissNum(isr.getAdmissNum());
  106. ws.setName(isr.getName());
  107. ws.setPicture(isr.getPicture());
  108. ws.setCardId(isr.getCardId());
  109. //region 校验身份证号 并根据身份证号获取出生年月和性别
  110. boolean isValidate = CardUtils.validateIdCard(isr.getCardId());//身份证是否合法
  111. if(!isValidate){
  112. return CommonResult.fail("身份证不合法");
  113. }
  114. String sex = CardUtils.getSexByIdCard(isr.getCardId());
  115. if(!StringUtils.hasText(isr.getSex())){
  116. ws.setSex(sex);
  117. }else {
  118. ws.setSex(isr.getSex());
  119. }
  120. String birthday = CardUtils.getBirthdayByIdCard(isr.getCardId());
  121. if(!StringUtils.hasText(isr.getBirthday())){
  122. ws.setBirthday(birthday);
  123. }else {
  124. ws.setBirthday(isr.getBirthday());
  125. }
  126. //endregion
  127. ws.setSchool(isr.getSchool());
  128. ws.setSchoolId(isr.getSchoolId());
  129. ws.setCollege(isr.getCollege());
  130. ws.setMajor(isr.getMajor());
  131. ws.setClassstr(isr.getClassstr());
  132. ws.setCollegeId(isr.getCollegeId());
  133. ws.setMajorId(isr.getMajorId());
  134. ws.setClassstrId(isr.getClassstrId());
  135. ws.setExamNum(isr.getExamNum());
  136. ws.setEduSystem(isr.getEduSystem());
  137. ws.setGraduationSchool(isr.getGraduationSchool());
  138. ws.setBatchValue(isr.getBatchValue());
  139. ws.setPoliticalStatu(isr.getPoliticalStatu());
  140. ws.setNationality(isr.getNationality());
  141. ws.setPhone(isr.getPhone());
  142. ws.setOprovince(isr.getOprovince());
  143. ws.setOcity(isr.getOcity());
  144. ws.setOdistrict(isr.getOdistrict());
  145. ws.setOprovinceId(isr.getOprovinceId());
  146. ws.setOcityId(isr.getOcityId());
  147. ws.setOdistrictId(isr.getOdistrictId());
  148. ws.setProvinceId(isr.getProvinceId());
  149. ws.setCityId(isr.getCityId());
  150. ws.setDistrictId(isr.getDistrictId());
  151. ws.setProvince(isr.getProvince());
  152. ws.setCity(isr.getCity());
  153. ws.setDistrict(isr.getDistrict());
  154. ws.setAddress(isr.getAddress());
  155. ws.setTrafficMethod(isr.getTrafficMethod());
  156. ws.setArrive(isr.getArrive());
  157. ws.setArrvieDate(isr.getArrvieDate());
  158. ws.setArriveTime(isr.getArriveTime());
  159. ws.setArriveTimeId(isr.getArriveTimeId());
  160. ws.setZipCode(isr.getZipCode());
  161. ws.setRegisterOntime(isr.getRegisterOntime());
  162. ws.setIdenType(1);
  163. ws.setIsPay(0);
  164. ws.setFillStatus("未填报");
  165. //ws.setAmountPayable(isr.getAmountPayable());
  166. //ws.setPayAmount(isr.getPayAmount());
  167. //ws.setIsDrive(isr.getIsDrive());
  168. //ws.setCarNumber(isr.getCarNumber());
  169. //endregion
  170. //region 家庭成员数据
  171. List<WelcomeFamily> wfs = new ArrayList<>();
  172. if (isr.getFvs() != null && isr.getFvs().size() > 0) {
  173. for (InsertFamilyRequest family : isr.getFvs()) {
  174. if (!(StringUtils.hasText(family.getFamilyShip()) && StringUtils.hasText(family.getName())
  175. && StringUtils.hasText(family.getWorkUnit()) && StringUtils.hasText(family.getPhone()))) {
  176. return CommonResult.fail("家庭成员信息不能为空!");
  177. }
  178. WelcomeFamily wf = new WelcomeFamily();
  179. wf.setStudentCard(ws.getCardId());
  180. wf.setFamilyShip(family.getFamilyShip());
  181. wf.setName(family.getName());
  182. wf.setWorkUnit(family.getWorkUnit());
  183. wf.setPhone(family.getPhone());
  184. wfs.add(wf);
  185. }
  186. }
  187. //endregion
  188. // //region 陪同人员数据
  189. // List<WelcomeAccompany> was = new ArrayList<>();
  190. // if (isr.getAvs() != null && isr.getAvs().size() > 0) {
  191. // for (InsertAccompanyRequest accompany : isr.getAvs()) {
  192. // if (!(StringUtils.hasText(accompany.getName()) && StringUtils.hasText(accompany.getPhone()))) {
  193. // return CommonResult.fail("陪同人员信息不能为空!");
  194. // }
  195. // WelcomeAccompany wa = new WelcomeAccompany();
  196. // wa.setStudentCard(ws.getCardId());
  197. // wa.setName(accompany.getName());
  198. // wa.setPhone(accompany.getPhone());
  199. // was.add(wa);
  200. // }
  201. // }
  202. //
  203. // //endregion
  204. //
  205. // //region 宿舍信息
  206. // WelcomeBed bedData = welcomeBedService.queryBedData(isr.getSchool(), isr.getBuildId(), isr.getDormitoryId(), Integer.valueOf(isr.getBed()));
  207. // if (bedData != null) {
  208. // if (StringUtils.hasText(bedData.getStudentCard())) {
  209. // return CommonResult.fail("当前床位已被他人入住,无法入住");
  210. // }
  211. // bedData.setStudentCard(isr.getCardId());
  212. // bedData.setCollege(isr.getCollege());
  213. // bedData.setCollegeId(isr.getCollegeId());
  214. // bedData.setMajor(isr.getMajor());
  215. // bedData.setMajorId(isr.getMajorId());
  216. // bedData.setClassstr(isr.getClassstr());
  217. // bedData.setClassstrId(isr.getClassstrId());
  218. // bedData.setIsCheck(1);
  219. // bedData.setCardNum(isr.getAdmissNum());
  220. // bedData.setName(isr.getName());
  221. // }
  222. //
  223. // //endregion
  224. try {
  225. int studentId = welcomeStudentService.insertWelcomeStudent(ws);
  226. if (studentId <= 0) {
  227. logger.error("添加学生失败,参数:" + JSON.toJSON(isr));
  228. throw new Exception("添加失败!");
  229. }
  230. if (wfs != null && wfs.size() > 0) {
  231. boolean insertBatch = welcomeFamilyService.saveBatch(wfs);
  232. if (!insertBatch) {
  233. logger.error("添加家庭成员失败,参数:" + JSON.toJSON(wfs));
  234. throw new Exception("添加失败!");
  235. }
  236. }
  237. // if (was != null && was.size() > 0) {
  238. // boolean insertBatch = welcomeAccompanyService.saveBatch(was);
  239. // if (!insertBatch) {
  240. // logger.error("添加陪同人员失败,参数:" + JSON.toJSON(was));
  241. // throw new Exception("添加失败!");
  242. // }
  243. // }
  244. //
  245. // int insertStudentDormitory = welcomeBedService.updateWelcomeBed(bedData);
  246. // if (insertStudentDormitory <= 0) {
  247. // logger.error("添加学生床位信息失败,参数:" + JSON.toJSON(bedData));
  248. // throw new Exception("添加失败!");
  249. // }
  250. } catch (Exception e) {
  251. logger.error(e.getMessage());
  252. throw new Exception("添加失败!");
  253. }
  254. return CommonResult.ok("添加成功");
  255. }
  256. @Override
  257. public CommonResult updateStudentInfo(updateStudentRequest usr, BindingResult bindingResult) throws Exception {
  258. if (bindingResult.hasErrors()) {
  259. String st = paramUtils.getParamError(bindingResult);
  260. return CommonResult.fail(st);
  261. }
  262. WelcomeStudent student = welcomeStudentService.getManageById(usr.getId());
  263. if (student == null) {
  264. return CommonResult.fail("学生数据已失效,编辑失败!");
  265. }
  266. //region 学生信息
  267. student.setAdmissNum(usr.getAdmissNum());
  268. student.setName(usr.getName());
  269. student.setPicture(usr.getPicture());
  270. //student.setCardId(usr.getCardId());
  271. student.setSex(usr.getSex());
  272. student.setBirthday(usr.getBirthday());
  273. student.setSchool(usr.getSchool());
  274. student.setSchoolId(usr.getSchoolId());
  275. student.setCollege(usr.getCollege());
  276. student.setMajor(usr.getMajor());
  277. student.setClassstr(usr.getClassstr());
  278. student.setCollegeId(usr.getCollegeId());
  279. student.setMajorId(usr.getMajorId());
  280. student.setClassstrId(usr.getClassstrId());
  281. student.setExamNum(usr.getExamNum());
  282. student.setEduSystem(usr.getEduSystem());
  283. student.setGraduationSchool(usr.getGraduationSchool());
  284. student.setBatchValue(usr.getBatchValue());
  285. student.setPoliticalStatu(usr.getPoliticalStatu());
  286. student.setNationality(usr.getNationality());
  287. student.setPhone(usr.getPhone());
  288. student.setOprovince(usr.getOprovince());
  289. student.setOcity(usr.getOcity());
  290. student.setOdistrict(usr.getOdistrict());
  291. student.setOprovinceId(usr.getOprovinceId());
  292. student.setOcityId(usr.getOcityId());
  293. student.setOdistrictId(usr.getOdistrictId());
  294. student.setProvinceId(usr.getProvinceId());
  295. student.setCityId(usr.getCityId());
  296. student.setDistrictId(usr.getDistrictId());
  297. student.setProvince(usr.getProvince());
  298. student.setCity(usr.getCity());
  299. student.setDistrict(usr.getDistrict());
  300. student.setAddress(usr.getAddress());
  301. student.setTrafficMethod(usr.getTrafficMethod());
  302. student.setArrive(usr.getArrive());
  303. student.setArrvieDate(usr.getArrvieDate());
  304. student.setArriveTime(usr.getArriveTime());
  305. student.setArriveTimeId(usr.getArriveTimeId());
  306. student.setZipCode(usr.getZipCode());
  307. student.setRegisterOntime(usr.getRegisterOntime());
  308. student.setIdenType(1);
  309. //ws.setAmountPayable(isr.getAmountPayable());
  310. //ws.setPayAmount(isr.getPayAmount());
  311. //ws.setIsDrive(isr.getIsDrive());
  312. //ws.setCarNumber(isr.getCarNumber());
  313. //endregion
  314. //region 家庭成员数据
  315. List<WelcomeFamily> wfs = new ArrayList<>();
  316. if (usr.getFvs() != null && usr.getFvs().size() > 0) {
  317. for (InsertFamilyRequest family : usr.getFvs()) {
  318. if (!(StringUtils.hasText(family.getFamilyShip()) && StringUtils.hasText(family.getName())
  319. && StringUtils.hasText(family.getWorkUnit()) && StringUtils.hasText(family.getPhone()))) {
  320. return CommonResult.fail("家庭成员信息不能为空!");
  321. }
  322. WelcomeFamily wf = new WelcomeFamily();
  323. wf.setStudentCard(student.getCardId());
  324. wf.setFamilyShip(family.getFamilyShip());
  325. wf.setName(family.getName());
  326. wf.setWorkUnit(family.getWorkUnit());
  327. wf.setPhone(family.getPhone());
  328. wfs.add(wf);
  329. }
  330. }
  331. //endregion
  332. // //region 陪同人员数据
  333. // List<WelcomeAccompany> was = new ArrayList<>();
  334. // if (usr.getAvs() != null && usr.getAvs().size() > 0) {
  335. // for (InsertAccompanyRequest accompany : usr.getAvs()) {
  336. // if (!(StringUtils.hasText(accompany.getName()) && StringUtils.hasText(accompany.getPhone()))) {
  337. // return CommonResult.fail("陪同人员信息不能为空!");
  338. // }
  339. // WelcomeAccompany wa = new WelcomeAccompany();
  340. // wa.setStudentCard(student.getCardId());
  341. // wa.setName(accompany.getName());
  342. // wa.setPhone(accompany.getPhone());
  343. // was.add(wa);
  344. // }
  345. // }
  346. //
  347. // //endregion
  348. //
  349. // //region 宿舍信息
  350. // List<WelcomeBed> bedDatas = new ArrayList<>();
  351. // WelcomeBed bedData = welcomeBedService.queryBedData(usr.getSchool(), usr.getBuildId(), usr.getDormitoryId(), Integer.valueOf(usr.getBed()));
  352. // if (bedData != null) {//新床位
  353. // if (StringUtils.hasText(bedData.getStudentCard()) && !bedData.getStudentCard().equals(student.getCardId())) {
  354. // return CommonResult.fail("当前床位已被他人入住,无法入住");
  355. // }
  356. // if (!StringUtils.hasText(bedData.getStudentCard())) {
  357. // bedData.setStudentCard(student.getCardId());
  358. // bedData.setCollege(student.getCollege());
  359. // bedData.setCollegeId(student.getCollegeId());
  360. // bedData.setMajor(student.getMajor());
  361. // bedData.setMajorId(student.getMajorId());
  362. // bedData.setClassstr(student.getClassstr());
  363. // bedData.setClassstrId(student.getClassstrId());
  364. // bedData.setIsCheck(1);
  365. // bedData.setCardNum(student.getAdmissNum());
  366. // bedData.setName(student.getName());
  367. //
  368. // //把旧床位清空
  369. // WelcomeBed obedData = welcomeBedService.getBedByCardId(student.getCardId());
  370. // if (obedData == null) {
  371. // obedData = new WelcomeBed();
  372. // obedData.setStudentCard(null);
  373. // obedData.setCollege(null);
  374. // obedData.setCollegeId(null);
  375. // obedData.setMajor(null);
  376. // obedData.setMajorId(null);
  377. // obedData.setClassstr(null);
  378. // obedData.setClassstrId(null);
  379. // obedData.setIsCheck(0);
  380. // obedData.setCardNum(null);
  381. // obedData.setName(null);
  382. // bedDatas.add(obedData);
  383. // }
  384. // } else {
  385. // bedData.setStudentCard(student.getCardId());
  386. // bedData.setCollege(student.getCollege());
  387. // bedData.setCollegeId(student.getCollegeId());
  388. // bedData.setMajor(student.getMajor());
  389. // bedData.setMajorId(student.getMajorId());
  390. // bedData.setClassstr(student.getClassstr());
  391. // bedData.setClassstrId(student.getClassstrId());
  392. // bedData.setIsCheck(1);
  393. // bedData.setCardNum(student.getAdmissNum());
  394. // bedData.setName(student.getName());
  395. // }
  396. // bedDatas.add(bedData);
  397. //
  398. // }
  399. //
  400. // //endregion
  401. try {
  402. int studentId = welcomeStudentService.updateWelcomeStudent(student);
  403. if (studentId <= 0) {
  404. logger.error("编辑学生失败,参数:" + JSON.toJSON(usr));
  405. throw new Exception("编辑失败!");
  406. }
  407. int deleteF = welcomeFamilyService.deleteWelcomeFamilyByCard(student.getCardId());
  408. if (wfs != null && wfs.size() > 0) {
  409. boolean insertBatch = welcomeFamilyService.saveBatch(wfs);
  410. if (!insertBatch) {
  411. logger.error("编辑家庭成员失败,参数:" + JSON.toJSON(wfs));
  412. throw new Exception("编辑失败!");
  413. }
  414. }
  415. // int deleteA = welcomeAccompanyService.deleteWelcomeAccompanyByCard(student.getCardId());
  416. // if (was != null && was.size() > 0) {
  417. // boolean insertBatch = welcomeAccompanyService.saveBatch(was);
  418. // if (!insertBatch) {
  419. // logger.error("编辑陪同人员失败,参数:" + JSON.toJSON(was));
  420. // throw new Exception("编辑失败!");
  421. // }
  422. // }
  423. //
  424. // boolean updateBatch = welcomeBedService.updateBatchById(bedDatas);
  425. // if (!updateBatch) {
  426. // logger.error("添加宿舍信息失败,参数:" + JSON.toJSON(bedDatas));
  427. // throw new Exception("添加失败!");
  428. // }
  429. } catch (Exception e) {
  430. logger.error(e.getMessage());
  431. throw new Exception("编辑失败!");
  432. }
  433. return CommonResult.ok("编辑成功");
  434. }
  435. @Override
  436. public CommonResult queryPageStudents(String userId,int currentPage, int pageCount, Integer collegeId, Integer majorId, Integer classstrId, String trafficMethod, String name) {
  437. IPage<StudentPageVo> pages = new Page<>();
  438. PageUtils<StudentPageVo> result =new PageUtils<>(pages);
  439. WelcomeAccount wa = welcomeAccountService.getManageById(userId);
  440. if (wa == null) {
  441. return CommonResult.fail("当前账户已失效,无权限查看");
  442. }
  443. List<String> collegeIds = Arrays.asList(wa.getCollegeId().split(","));
  444. if(collegeId != null && collegeId.intValue() > 0){
  445. if (!collegeIds.contains(String.valueOf(collegeId))) {
  446. pages.setCurrent(currentPage);
  447. pages.setSize(pageCount);
  448. return CommonResult.ok(result);
  449. }else {
  450. collegeIds = new ArrayList<>();
  451. collegeIds.add(String.valueOf(collegeId));
  452. }
  453. }
  454. result = welcomeStudentService.queryStudentPageList(currentPage, pageCount, collegeIds, majorId, classstrId, trafficMethod, name);
  455. return CommonResult.ok(result);
  456. }
  457. @Override
  458. public CommonResult queryStudentDetail(int id) {
  459. StudentDetailVo result = new StudentDetailVo();
  460. WelcomeStudent ws = welcomeStudentService.getManageById(id);
  461. if (ws == null) {
  462. return CommonResult.ok("学生信息已失效,查看失败!");
  463. }
  464. //家庭成员
  465. List<FamilyVo> fvs = new ArrayList<>();
  466. List<WelcomeFamily> familys = welcomeFamilyService.getManageByCardId(ws.getCardId());
  467. if (familys != null && familys.size() > 0) {
  468. for (WelcomeFamily wf : familys) {
  469. FamilyVo fv = new FamilyVo();
  470. fv.setId(wf.getId());
  471. fv.setFamilyShip(wf.getFamilyShip());
  472. fv.setName(wf.getName());
  473. fv.setPhone(wf.getPhone());
  474. fv.setWorkUnit(wf.getWorkUnit());
  475. fvs.add(fv);
  476. }
  477. }
  478. result.setFvs(fvs);
  479. //陪同人员
  480. List<AccompanyVo> avs = new ArrayList<>();
  481. List<WelcomeAccompany> accompanys = welcomeAccompanyService.getManageByCardId(ws.getCardId());
  482. if (accompanys != null && accompanys.size() > 0) {
  483. for (WelcomeAccompany ac : accompanys) {
  484. AccompanyVo av = new AccompanyVo();
  485. av.setId(ac.getId());
  486. av.setName(ac.getName());
  487. av.setPhone(ac.getPhone());
  488. avs.add(av);
  489. }
  490. }
  491. result.setAvs(avs);
  492. //宿舍信息
  493. WelcomeBed wsd = welcomeBedService.getBedByCardId(ws.getCardId());
  494. if (wsd != null) {
  495. result.setBuild(wsd.getBuild());
  496. result.setBuildId(wsd.getBuildId());
  497. result.setDormitory(wsd.getDormitory());//寝室号
  498. result.setDormitoryId(wsd.getDormitoryId());//寝室号
  499. result.setBed(String.valueOf(wsd.getNumber()));//床位号
  500. result.setBedId(wsd.getId());//床位号
  501. }
  502. //时间段
  503. List<ArriveTimeVo> atvs = new ArrayList<>();
  504. List<WelcomeArriveSetting> wass = welcomeArriveSettingService.queryCheckDatas();
  505. if (wass != null && wass.size() > 0) {
  506. for (WelcomeArriveSetting was : wass) {
  507. ArriveTimeVo atv = new ArriveTimeVo();
  508. atv.setId(was.getId());
  509. atv.setStartTime(was.getStartTime());
  510. atv.setEndTime(was.getEndTime());
  511. atv.setTimeStr(was.getStartTime() + "-" + was.getEndTime());
  512. atv.setIsCheck((ws.getArriveTimeId() != null && was.getId().equals(ws.getArriveTimeId())) ? 1 : 0);
  513. atvs.add(atv);
  514. }
  515. }
  516. result.setAtvs(atvs);
  517. result.setId(ws.getId());
  518. result.setSchool(ws.getSchool());
  519. result.setSchoolId(ws.getSchoolId());
  520. result.setAdmissNum(ws.getAdmissNum());
  521. result.setName(ws.getName());
  522. result.setPicture(ws.getPicture());
  523. result.setCardId(ws.getCardId());
  524. result.setSex(ws.getSex());
  525. result.setBirthday(ws.getBirthday());
  526. result.setCollege(ws.getCollege());
  527. result.setMajor(ws.getMajor());
  528. result.setClassstr(ws.getClassstr());
  529. result.setCollegeId(ws.getCollegeId());
  530. result.setMajorId(ws.getMajorId());
  531. result.setClassstrId(ws.getClassstrId());
  532. result.setExamNum(ws.getExamNum());
  533. result.setEduSystem(ws.getEduSystem());
  534. result.setGraduationSchool(ws.getGraduationSchool());
  535. result.setBatchValue(ws.getBatchValue());
  536. result.setPoliticalStatu(ws.getPoliticalStatu());
  537. result.setNationality(ws.getNationality());
  538. result.setPhone(ws.getPhone());
  539. result.setOprovinceId(ws.getOprovinceId());
  540. result.setOprovince(ws.getOprovince());
  541. result.setOcityId(ws.getOcityId());
  542. result.setOcity(ws.getOcity());
  543. result.setOdistrictId(ws.getOdistrictId());
  544. result.setOdistrict(ws.getOdistrict());
  545. result.setProvinceId(ws.getProvinceId());
  546. result.setProvince(ws.getProvince());
  547. result.setCityId(ws.getCityId());
  548. result.setCity(ws.getCity());
  549. result.setDistrictId(ws.getDistrictId());
  550. result.setDistrict(ws.getDistrict());
  551. result.setAddress(ws.getAddress());
  552. result.setRegisterOntime(ws.getRegisterOntime());
  553. result.setZipCode(ws.getZipCode());
  554. result.setTrafficMethod(ws.getTrafficMethod());
  555. result.setArrive(ws.getArrive());
  556. result.setArrvieDate(ws.getArrvieDate());
  557. result.setArriveTime(ws.getArriveTime());
  558. result.setArriveTimeId(ws.getArriveTimeId());
  559. result.setAmountPayable(ws.getAmountPayable());
  560. result.setPayAmount(ws.getPayAmount());
  561. result.setIsDrive(ws.getIsDrive());
  562. result.setCarNumber(ws.getCarNumber());
  563. return CommonResult.ok(result);
  564. }
  565. @Override
  566. @Transactional(rollbackFor = {Exception.class})
  567. public CommonResult infoCollection(InfoCollectionRequest icr, BindingResult bindingResult) throws Exception {
  568. logger.info("采集学生信息失败,icr参数:" + JSON.toJSON(icr));
  569. if (bindingResult.hasErrors()) {
  570. String st = paramUtils.getParamError(bindingResult);
  571. return CommonResult.fail(st);
  572. }
  573. WelcomeStudent ws = welcomeStudentService.getDataByIdcardOrNum(icr.getAdmissNum(), icr.getCardId());
  574. if (ws == null) {
  575. ws = new WelcomeStudent();
  576. }
  577. ws.setSchool(icr.getSchool());
  578. ws.setAdmissNum(icr.getAdmissNum());
  579. ws.setName(icr.getName());
  580. ws.setPicture(icr.getPicture());
  581. //ws.setCardId(icr.getCardId());
  582. ws.setSex(icr.getSex());
  583. ws.setBirthday(icr.getBirthday());
  584. ws.setCollegeId(icr.getCollegeId());
  585. ws.setMajorId(icr.getMajorId());
  586. ws.setClassstrId(icr.getClassstrId());
  587. ws.setExamNum(icr.getExamNum());
  588. ws.setEduSystem(icr.getEduSystem());
  589. ws.setGraduationSchool(icr.getGraduationSchool());
  590. ws.setBatchValue(icr.getBatchValue());
  591. ws.setPoliticalStatu(icr.getPoliticalStatu());
  592. ws.setNationality(icr.getNationality());
  593. ws.setPhone(icr.getPhone());
  594. ws.setOprovinceId(icr.getOprovinceId());
  595. ws.setOprovince(icr.getOprovince());
  596. ws.setOcityId(icr.getOcityId());
  597. ws.setOcity(icr.getOcity());
  598. ws.setOdistrictId(icr.getOdistrictId());
  599. ws.setOdistrict(icr.getOdistrict());
  600. ws.setProvinceId(icr.getProvinceId());
  601. ws.setProvince(icr.getProvince());
  602. ws.setCityId(icr.getCityId());
  603. ws.setCity(icr.getCity());
  604. ws.setDistrictId(icr.getDistrictId());
  605. ws.setDistrict(icr.getDistrict());
  606. ws.setAddress(icr.getAddress());
  607. ws.setRegisterOntime(icr.getRegisterOntime());
  608. ws.setZipCode(icr.getZipCode());
  609. ws.setTrafficMethod(icr.getTrafficMethod());
  610. ws.setArrive(icr.getArrive());
  611. ws.setArrvieDate(icr.getArrvieDate());
  612. ws.setArriveTime(icr.getArriveTime());
  613. ws.setArriveTimeId(icr.getArriveTimeId());
  614. ws.setFillStatus("已填报");
  615. //家庭成员
  616. List<WelcomeFamily> wfs = new ArrayList<>();
  617. if (icr.getFvs() != null && icr.getFvs().size() > 0) {
  618. for (FamilyVo fv : icr.getFvs()) {
  619. if (!(StringUtils.hasText(fv.getName()) && StringUtils.hasText(fv.getPhone()) && StringUtils.hasText(fv.getWorkUnit()) && StringUtils.hasText(fv.getFamilyShip()))) {
  620. return CommonResult.fail("家庭成员信息不能为空!");
  621. }
  622. WelcomeFamily wf = new WelcomeFamily();
  623. wf.setName(fv.getName());
  624. wf.setPhone(fv.getPhone());
  625. wf.setWorkUnit(fv.getWorkUnit());
  626. wf.setFamilyShip(fv.getFamilyShip());
  627. wf.setStudentCard(ws.getCardId());
  628. wfs.add(wf);
  629. }
  630. }
  631. //陪同人员
  632. List<WelcomeAccompany> was = new ArrayList<>();
  633. if (icr.getAvs() != null && icr.getAvs().size() > 0) {
  634. for (AccompanyVo av : icr.getAvs()) {
  635. if (!(StringUtils.hasText(av.getName()) && StringUtils.hasText(av.getPhone()))) {
  636. return CommonResult.fail("家庭成员信息不能为空!");
  637. }
  638. WelcomeAccompany wa = new WelcomeAccompany();
  639. wa.setName(av.getName());
  640. wa.setPhone(av.getPhone());
  641. wa.setStudentCard(ws.getCardId());
  642. was.add(wa);
  643. }
  644. }
  645. if (!(ws.getIsPay() != null && ws.getIsPay().intValue() == 1)) {
  646. System.out.println("进支付比较");
  647. List<JsonPayVo> payInfos = WelcomePayController.queryStudentPayInfo(ws.getAdmissNum(), TimeExchange.getYear());
  648. BigDecimal payAmount = new BigDecimal(BigInteger.ZERO);//实缴金额
  649. BigDecimal yjPayAmount = new BigDecimal(BigInteger.ZERO);//应缴金额
  650. for (JsonPayVo pi : payInfos) {
  651. payAmount = payAmount.add(pi.getSJJE());
  652. yjPayAmount = yjPayAmount.add(pi.getYJJE());
  653. }
  654. ws.setPayAmount(payAmount);
  655. ws.setAmountPayable(yjPayAmount);
  656. System.out.println("进支付比较1" + JSON.toJSON(payInfos));
  657. if (payInfos != null && payInfos.size() > 0) {
  658. System.out.println("进支付比较2");
  659. List<WelcomePaySetting> paySettings = welcomePaySettingService.queryPaySettings(ws.getSchool());
  660. System.out.println("进支付比较3" + JSON.toJSON(paySettings));
  661. if (paySettings != null && paySettings.size() > 0) {
  662. System.out.println("进支付比较4");
  663. for (WelcomePaySetting pay : paySettings) {
  664. System.out.println("进支付比较5");
  665. BigDecimal money = pay.getPayAmount();
  666. if (pay.getMethod().equals("全部")) {
  667. BigDecimal totalSj = new BigDecimal(BigInteger.ZERO);
  668. for (JsonPayVo jpv : payInfos) {
  669. totalSj = totalSj.add(jpv.getSJJE());
  670. }
  671. if (totalSj.compareTo(money) >= 0) {
  672. ws.setIsPay(1);
  673. }
  674. }
  675. Optional<JsonPayVo> ojpv = payInfos.stream().filter(e -> e.getSFXMMC().equals(pay.getMethod())).findFirst();
  676. if (ojpv != null && ojpv.isPresent()) {
  677. if (ojpv.get().getSJJE().compareTo(money) >= 0) {
  678. ws.setIsPay(1);
  679. }
  680. }
  681. }
  682. } else {
  683. ws.setIsPay(0);
  684. }
  685. } else {
  686. ws.setIsPay(0);
  687. }
  688. }
  689. try {
  690. System.out.println("信息采集1");
  691. if (ws.getId() != null) {
  692. int update = welcomeStudentService.updateWelcomeStudent(ws);
  693. if (update < 0) {
  694. System.out.println("信息采集1.1");
  695. logger.error("采集学生信息失败,ws参数:" + JSON.toJSON(ws));
  696. throw new Exception("采集学生信息失败!");
  697. //return CommonResult.fail("采集学生信息失败1");
  698. }
  699. } else {
  700. int insert = welcomeStudentService.insertWelcomeStudent(ws);
  701. if (insert < 0) {
  702. System.out.println("信息采集1.2");
  703. logger.error("采集学生信息失败,ws参数:" + JSON.toJSON(ws));
  704. throw new Exception("采集学生信息失败!");
  705. //return CommonResult.fail("采集学生信息失败1");
  706. }
  707. }
  708. System.out.println("信息采集2");
  709. if (wfs != null && wfs.size() > 0) {
  710. int deleteF = welcomeFamilyService.deleteWelcomeFamilyByCard(ws.getCardId());
  711. boolean resultWf = welcomeFamilyService.saveBatch(wfs);
  712. System.out.println("信息采集1.3");
  713. if (!resultWf) {
  714. System.out.println("信息采集1.4");
  715. logger.error("采集学生信息失败,wfs参数:" + JSON.toJSON(wfs));
  716. throw new Exception("采集学生信息失败!");
  717. //return CommonResult.fail("采集学生信息失败2");
  718. }
  719. }
  720. System.out.println("信息采集3");
  721. if (was != null && was.size() > 0) {
  722. int deleteF = welcomeAccompanyService.deleteWelcomeAccompanyByCard(ws.getCardId());
  723. boolean resultWa = welcomeAccompanyService.saveBatch(was);
  724. System.out.println("信息采集1.5");
  725. if (!resultWa) {
  726. System.out.println("信息采集1.6");
  727. logger.error("采集学生信息失败,was参数:" + JSON.toJSON(was));
  728. throw new Exception("采集学生信息失败!");
  729. //return CommonResult.fail("采集学生信息失败3");
  730. }
  731. }
  732. } catch (Exception e) {
  733. logger.error(e.getMessage());
  734. throw new Exception("采集失败!");
  735. //return CommonResult.fail("采集学生信息失败4");
  736. }
  737. System.out.println("信息采集1.7");
  738. return CommonResult.ok("采集完成!");
  739. }
  740. @Override
  741. @Transactional(rollbackFor = {Exception.class})
  742. public CommonResult deleteStudentInfo(int id) throws Exception {
  743. System.out.println("删除了学生信息:"+id);
  744. WelcomeStudent ws = welcomeStudentService.getManageById(id);
  745. if (ws == null) {
  746. return CommonResult.fail("学生信息已失效,无法进行删除操作!");
  747. }
  748. //把旧床位清空
  749. WelcomeBed obedData = welcomeBedService.getBedByCardId(ws.getCardId());
  750. // if (obedData != null) {
  751. // obedData.setStudentCard(null);
  752. // obedData.setIsCheck(0);
  753. // obedData.setCardNum(null);
  754. // obedData.setName(null);
  755. // }
  756. try {
  757. //删除学生数据
  758. int deleteStudent = welcomeStudentService.deleteWelcomeStudentById(id);
  759. if (deleteStudent <= 0) {
  760. logger.error("删除学生信息失败,id参数:" + JSON.toJSON(id));
  761. throw new Exception("删除学生信息失败!");
  762. }
  763. if (obedData != null) {
  764. //删除宿舍数据
  765. // int deleteSd = welcomeBedService.updateWelcomeBed(obedData);
  766. // if (deleteSd < 0) {
  767. // logger.error("删除宿舍失败,obedData参数:" + JSON.toJSON(obedData));
  768. // throw new Exception("删除学生信息失败!");
  769. // }
  770. welcomeBedService.updateData(obedData.getId());
  771. // 修改寝室信息
  772. WelcomeDormitory welcomeDormitory = welcomeDormitoryService.getById(obedData.getDormitoryId());
  773. if (ObjectUtils.isNotEmpty(welcomeDormitory)) {
  774. Integer freeBedNumber = welcomeDormitory.getFreeBedNumber();
  775. Integer bedNumber = welcomeDormitory.getBedNumber();
  776. freeBedNumber = freeBedNumber + 1;
  777. if (bedNumber.equals(freeBedNumber)) {
  778. welcomeDormitory.setFreeBedNumber(freeBedNumber);
  779. welcomeDormitory.setStatus(1);
  780. } else if (bedNumber > freeBedNumber) {
  781. welcomeDormitory.setFreeBedNumber(freeBedNumber);
  782. welcomeDormitory.setStatus(3);
  783. }
  784. welcomeDormitoryService.updateById(welcomeDormitory);
  785. }
  786. }
  787. //删除同行人员
  788. int deleteWa = welcomeAccompanyService.deleteWelcomeAccompanyByCard(ws.getCardId());
  789. //删除家庭成员
  790. int deletef = welcomeFamilyService.deleteWelcomeFamilyByCard(ws.getCardId());
  791. } catch (Exception e) {
  792. logger.error(e.getMessage());
  793. throw new Exception("删除失败!");
  794. }
  795. return CommonResult.ok("删除成功");
  796. }
  797. @Override
  798. public CommonResult importStudentExcel(MultipartFile file) throws IOException, ParseException {
  799. System.out.println("导入学生信息");
  800. if (file.isEmpty() || file.getSize() == 0) {
  801. return CommonResult.fail("导入文件不能为空");
  802. }
  803. String ContentType = file.getContentType();
  804. InputStream inputStream = file.getInputStream();
  805. List<WelcomeStudent> result = new ArrayList<>();
  806. //xls格式文件
  807. if (ContentType.equals(eFileType.Xls.getValue())) {
  808. CommonResult<List<WelcomeStudent>> resultData = readXls(inputStream);
  809. if (!resultData.isSuccess()) {
  810. return resultData;
  811. }
  812. result = resultData.getData();
  813. } else if (ContentType.equals(eFileType.Xlsx.getValue())) {
  814. CommonResult<List<WelcomeStudent>> resultData = readXlsx(inputStream);
  815. if (!resultData.isSuccess()) {
  816. return resultData;
  817. }
  818. result = resultData.getData();
  819. } else {
  820. return CommonResult.fail("学生信息数据导入只支持Xls或Xlsx格式文件");
  821. }
  822. StringBuilder sb = new StringBuilder();
  823. List<String> cardIds = result.stream().map(WelcomeStudent::getCardId).collect(Collectors.toList());
  824. List<WelcomeStudent> existStudents = welcomeStudentService.queryStudentByCardId(cardIds);
  825. if (existStudents != null && existStudents.size() > 0) {
  826. for (WelcomeStudent ws : result) {
  827. Optional<WelcomeStudent> ows = existStudents.stream().filter(e -> e.getCardId().equals(ws.getCardId())).findFirst();
  828. if (ows != null && ows.isPresent()) {
  829. sb.append(ows.get().getName() + ows.get().getCardId()+"数据在数据库中已存在;");
  830. ws.setId(ows.get().getId());
  831. ws.setAdmissNum(ws.getAdmissNum());//录取号
  832. ws.setName(ws.getName());//姓名
  833. ws.setCardId(ws.getCardId());//身份证号
  834. ws.setSchool(ws.getSchool());//校区
  835. ws.setSchoolId(eSchool.stringOf(ws.getSchool()));//校区
  836. ws.setCollege(ws.getCollege());
  837. ws.setCollegeId(ws.getCollegeId());
  838. ws.setMajor(ws.getMajor());
  839. ws.setMajorId(ws.getMajorId());
  840. ws.setClassstr(ws.getClassstr());
  841. ws.setClassstrId(ws.getClassstrId());
  842. ws.setExamNum(ws.getExamNum());//考生号
  843. ws.setEduSystem(ws.getEduSystem());//学制
  844. ws.setGraduationSchool(ws.getGraduationSchool());//毕业中学
  845. ws.setBatchValue(ws.getBatchValue());//批次
  846. ws.setPoliticalStatu(ws.getPoliticalStatu());//政治面貌
  847. ws.setNationality(ws.getNationality());//民族
  848. ws.setPhone(ws.getPhone());//手机号码
  849. ws.setOprovince(ws.getOprovince());
  850. ws.setOprovinceId(ws.getOprovinceId());
  851. ws.setOcity(ws.getOcity());
  852. ws.setOcityId(ws.getOcityId());
  853. ws.setOdistrict(ws.getOdistrict());
  854. ws.setOdistrictId(ws.getOdistrictId());
  855. ws.setProvince(ws.getProvince());
  856. ws.setProvinceId(ws.getProvinceId());
  857. ws.setCity(ws.getCity());
  858. ws.setCityId(ws.getCityId());
  859. ws.setDistrict(ws.getDistrict());
  860. ws.setDistrictId(ws.getDistrictId());
  861. ws.setAddress(ws.getAddress());
  862. ws.setZipCode(ws.getZipCode());
  863. ws.setIsPay(0);
  864. }
  865. }
  866. }
  867. boolean resultBool = welcomeStudentService.saveOrUpdateBatch(result);
  868. System.out.println("导入学生1");
  869. return resultBool ? CommonResult.ok("导入成功:"+ sb.toString()) : CommonResult.fail("导入失败");
  870. }
  871. /**
  872. * xls文件读取方法
  873. *
  874. * @param inputStream
  875. * @return
  876. * @throws IOException
  877. * @throws ParseException
  878. */
  879. private CommonResult<List<WelcomeStudent>> readXls(InputStream inputStream) throws IOException, ParseException {
  880. List<WelcomeStudent> result = new ArrayList<>();
  881. HSSFWorkbook sheets = new HSSFWorkbook(inputStream);
  882. List<WelcomeOrg> ws = welcomeOrgService.list(null);
  883. List<WelcomeCity> citys = welcomeCityService.list(null);
  884. //读取第一张sheet
  885. HSSFSheet sheetAt = sheets.getSheetAt(0);
  886. DataFormatter dataFormatter = new DataFormatter();
  887. try {
  888. //rowNum = 3 从第三行开始获取值
  889. //sheetAt.getLastRowNum():从0开始统计数量 所以得+1
  890. for (int rowNum = 0; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
  891. HSSFRow row = sheetAt.getRow(rowNum);
  892. if (row != null) {
  893. //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
  894. //所以先使用setCellType()方法先将该单元格的类型设置为STRING
  895. //然后poi会根据字符串读取它
  896. //第一行数据获取月份
  897. if (rowNum == 0) {
  898. String number = dataFormatter.formatCellValue(row.getCell(0));//序号
  899. if (!number.equals("序号")) {
  900. return CommonResult.fail("导入数据第一列为序号");
  901. }
  902. String assNum = dataFormatter.formatCellValue(row.getCell(1));//录取号
  903. if (!assNum.equals("录取号")) {
  904. return CommonResult.fail("导入数据第二列为录取号");
  905. }
  906. String name = dataFormatter.formatCellValue(row.getCell(2));//姓名
  907. if (!name.equals("姓名")) {
  908. return CommonResult.fail("导入数据第三列为姓名");
  909. }
  910. String cardId = dataFormatter.formatCellValue(row.getCell(3));//身份证号
  911. if (!cardId.equals("身份证号")) {
  912. return CommonResult.fail("导入数据第四列为身份证号");
  913. }
  914. String school = dataFormatter.formatCellValue(row.getCell(4));//校区
  915. if (!school.equals("校区")) {
  916. return CommonResult.fail("导入数据第五列为校区");
  917. }
  918. String college = dataFormatter.formatCellValue(row.getCell(5));//院系
  919. if (!college.equals("院系")) {
  920. return CommonResult.fail("导入数据第六列为院系");
  921. }
  922. String major = dataFormatter.formatCellValue(row.getCell(6));//专业
  923. if (!major.equals("专业")) {
  924. return CommonResult.fail("导入数据第七列为专业");
  925. }
  926. String classstr = dataFormatter.formatCellValue(row.getCell(7));//班级
  927. if (!classstr.equals("班级")) {
  928. return CommonResult.fail("导入数据第八列为班级");
  929. }
  930. String examNum = dataFormatter.formatCellValue(row.getCell(8));//考生号
  931. if (!examNum.equals("考生号")) {
  932. return CommonResult.fail("导入数据第九列为考生号");
  933. }
  934. String eduSystem = dataFormatter.formatCellValue(row.getCell(9));//学制
  935. if (!eduSystem.equals("学制")) {
  936. return CommonResult.fail("导入数据第十列为学制");
  937. }
  938. String graSchool = dataFormatter.formatCellValue(row.getCell(10));//毕业中学
  939. if (!graSchool.equals("毕业中学")) {
  940. return CommonResult.fail("导入数据第十一列为毕业中学批次");
  941. }
  942. String batchValue = dataFormatter.formatCellValue(row.getCell(11));//批次
  943. if (!batchValue.equals("批次")) {
  944. return CommonResult.fail("导入数据第十二列为批次");
  945. }
  946. String politicalStatu = dataFormatter.formatCellValue(row.getCell(12));//政治面貌
  947. if (!politicalStatu.equals("政治面貌")) {
  948. return CommonResult.fail("导入数据第十三列为政治面貌");
  949. }
  950. String nationality = dataFormatter.formatCellValue(row.getCell(13));//民族
  951. if (!nationality.equals("民族")) {
  952. return CommonResult.fail("导入数据第十四列为民族");
  953. }
  954. String phone = dataFormatter.formatCellValue(row.getCell(14));//手机号码
  955. if (!phone.equals("手机号码")) {
  956. return CommonResult.fail("导入数据第十五列为手机号码");
  957. }
  958. String nativePlace = dataFormatter.formatCellValue(row.getCell(15));//籍贯
  959. if (!nativePlace.contains("籍贯")) {
  960. return CommonResult.fail("导入数据第十六列为籍贯");
  961. }
  962. String addressPlace = dataFormatter.formatCellValue(row.getCell(16));//家庭住址
  963. if (!addressPlace.contains("家庭住址")) {
  964. return CommonResult.fail("导入数据第十七列为家庭住址");
  965. }
  966. String addressDetail = dataFormatter.formatCellValue(row.getCell(17));//详细住址
  967. if (!addressDetail.equals("详细住址")) {
  968. return CommonResult.fail("导入数据第十八列为详细住址");
  969. }
  970. String zipCode = dataFormatter.formatCellValue(row.getCell(18));//邮编
  971. if (!zipCode.equals("邮编")) {
  972. return CommonResult.fail("导入数据第十九列为邮编");
  973. }
  974. } else {
  975. WelcomeStudent studentData = new WelcomeStudent();
  976. String assNum = dataFormatter.formatCellValue(row.getCell(1));//录取号
  977. if (!StringUtils.hasText(assNum)) {
  978. break;
  979. }
  980. studentData.setAdmissNum(assNum);
  981. String name = dataFormatter.formatCellValue(row.getCell(2));//姓名
  982. studentData.setName(name);
  983. String cardId = dataFormatter.formatCellValue(row.getCell(3));//身份证号
  984. //region 校验身份证号 并根据身份证号获取出生年月和性别
  985. boolean isValidate = CardUtils.validateIdCard(cardId);//身份证是否合法
  986. if(!isValidate){
  987. return CommonResult.fail("录取编号为" + assNum + "的身份证不合法");
  988. }
  989. String sex = CardUtils.getSexByIdCard(cardId);
  990. if(sex != null){
  991. studentData.setSex(sex);
  992. }
  993. String birthday = CardUtils.getBirthdayByIdCard(cardId);
  994. if(birthday != null){
  995. studentData.setBirthday(birthday);
  996. }
  997. //endregion
  998. studentData.setCardId(cardId);
  999. String school = dataFormatter.formatCellValue(row.getCell(4));//校区
  1000. studentData.setSchool(school);
  1001. studentData.setSchoolId(eSchool.stringOf(school));
  1002. //region 院系专业
  1003. String college = dataFormatter.formatCellValue(row.getCell(5));//院系
  1004. Optional<WelcomeOrg> owo = ws.stream().filter(e -> e.getName().equals(college)).findFirst();
  1005. if (owo != null && owo.isPresent()) {
  1006. studentData.setCollege(college);
  1007. studentData.setCollegeId(owo.get().getId());
  1008. }
  1009. String major = dataFormatter.formatCellValue(row.getCell(6));//专业
  1010. Optional<WelcomeOrg> omwo = ws.stream().filter(e -> e.getName().equals(major)).findFirst();
  1011. if (omwo != null && omwo.isPresent()) {
  1012. studentData.setMajor(major);
  1013. studentData.setMajorId(omwo.get().getId());
  1014. }
  1015. String classstr = dataFormatter.formatCellValue(row.getCell(7));//班级
  1016. Optional<WelcomeOrg> ocwo = ws.stream().filter(e -> e.getName().equals(classstr)).findFirst();
  1017. if (ocwo != null && ocwo.isPresent()) {
  1018. studentData.setClassstr(classstr);
  1019. studentData.setClassstrId(ocwo.get().getId());
  1020. }
  1021. //endregion
  1022. String examNum = dataFormatter.formatCellValue(row.getCell(8));//考生号
  1023. studentData.setExamNum(examNum);
  1024. String eduSystem = dataFormatter.formatCellValue(row.getCell(9));//学制
  1025. studentData.setEduSystem(eduSystem);
  1026. String graSchool = dataFormatter.formatCellValue(row.getCell(10));//毕业中学
  1027. studentData.setGraduationSchool(graSchool);
  1028. String batchValue = dataFormatter.formatCellValue(row.getCell(11));//批次
  1029. studentData.setBatchValue(batchValue);
  1030. String politicalStatu = dataFormatter.formatCellValue(row.getCell(12));//政治面貌
  1031. studentData.setPoliticalStatu(politicalStatu);
  1032. String nationality = dataFormatter.formatCellValue(row.getCell(13));//民族
  1033. studentData.setNationality(nationality);
  1034. String phone = dataFormatter.formatCellValue(row.getCell(14));//手机号码
  1035. studentData.setPhone(phone);
  1036. //region 籍贯
  1037. String nativePlace = dataFormatter.formatCellValue(row.getCell(15));//籍贯
  1038. String[] addressDatas = nativePlace.split("/");
  1039. if (citys != null && citys.size() > 0) {
  1040. if (addressDatas != null && addressDatas.length >= 1) {
  1041. if (!addressDatas[0].contains("省")) {
  1042. return CommonResult.fail("录取编号为\" + assNum + \"的籍贯格式应该是 省/市/县");
  1043. }
  1044. Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getDistrictZh().equals(addressDatas[0])).findFirst();
  1045. if (oProvince != null && oProvince.isPresent()) {
  1046. studentData.setOprovince(addressDatas[0]);
  1047. studentData.setOprovinceId(oProvince.get().getId());
  1048. } else {
  1049. return CommonResult.fail("录取编号为" + assNum + "的籍贯格式应该是 省/市/县区");
  1050. }
  1051. }
  1052. if (addressDatas != null && addressDatas.length >= 2) {
  1053. Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getDistrictZh().equals(addressDatas[1])).findFirst();
  1054. if (oProvince != null && oProvince.isPresent()) {
  1055. studentData.setOcity(addressDatas[1]);
  1056. studentData.setOcityId(oProvince.get().getId());
  1057. } else {
  1058. return CommonResult.fail("录取编号为" + assNum + "的籍贯格式应该是 省/市/县区");
  1059. }
  1060. }
  1061. if (addressDatas != null && addressDatas.length >= 3) {
  1062. Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getCityZh().equals(addressDatas[1]) && e.getDistrictZh().equals(addressDatas[2])).findFirst();
  1063. if (oProvince != null && oProvince.isPresent()) {
  1064. studentData.setOdistrict(addressDatas[2]);
  1065. studentData.setOdistrictId(oProvince.get().getId());
  1066. } else {
  1067. return CommonResult.fail("录取编号为" + assNum + "的籍贯格式应该是 省/市/县区");
  1068. }
  1069. }
  1070. }
  1071. //endregion
  1072. //region 家庭住址
  1073. String addressPlace = dataFormatter.formatCellValue(row.getCell(16));//家庭住址
  1074. String[] addressPlaces = addressPlace.split("/");
  1075. if (citys != null && citys.size() > 0) {
  1076. if (addressPlaces != null && addressPlaces.length >= 1) {
  1077. if (!addressPlaces[0].contains("省")) {
  1078. return CommonResult.fail("录取编号为" + assNum + "的家庭住址格式应该是 省/市/县区");
  1079. }
  1080. Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getDistrictZh().equals(addressPlaces[0])).findFirst();
  1081. if (oProvince != null && oProvince.isPresent()) {
  1082. studentData.setProvince(addressPlaces[0]);
  1083. studentData.setProvinceId(oProvince.get().getId());
  1084. } else {
  1085. return CommonResult.fail("录取编号为" + assNum + "的家庭住址格式应该是 省/市/县区");
  1086. }
  1087. }
  1088. if (addressPlaces != null && addressPlaces.length >= 2) {
  1089. Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getDistrictZh().equals(addressPlaces[1])).findFirst();
  1090. if (oProvince != null && oProvince.isPresent()) {
  1091. studentData.setCity(addressPlaces[1]);
  1092. studentData.setCityId(oProvince.get().getId());
  1093. } else {
  1094. return CommonResult.fail("录取编号为" + assNum + "的家庭住址格式应该是 省/市/县区");
  1095. }
  1096. }
  1097. if (addressPlaces != null && addressPlaces.length >= 3) {
  1098. Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getCityZh().equals(addressPlaces[1]) && e.getDistrictZh().equals(addressPlaces[2])).findFirst();
  1099. if (oProvince != null && oProvince.isPresent()) {
  1100. studentData.setDistrict(addressPlaces[2]);
  1101. studentData.setDistrictId(oProvince.get().getId());
  1102. } else {
  1103. return CommonResult.fail("录取编号为" + assNum + "的家庭住址格式应该是 省/市/县区");
  1104. }
  1105. }
  1106. }
  1107. //endregion
  1108. String addressDetail = dataFormatter.formatCellValue(row.getCell(17));//详细住址
  1109. studentData.setAddress(addressDetail);
  1110. String zipCode = dataFormatter.formatCellValue(row.getCell(18));//邮编
  1111. studentData.setZipCode(zipCode);
  1112. studentData.setIdenType(1);
  1113. studentData.setFillStatus("未填报");
  1114. result.add(studentData);
  1115. }
  1116. }
  1117. }
  1118. } catch (Exception e) {
  1119. return CommonResult.fail("请按模板格式导入数据");
  1120. }
  1121. return CommonResult.ok(result);
  1122. }
  1123. /**
  1124. * xls文件读取方法
  1125. *
  1126. * @param inputStream
  1127. * @return
  1128. * @throws IOException
  1129. * @throws ParseException
  1130. */
  1131. private CommonResult<List<WelcomeStudent>> readXlsx(InputStream inputStream) throws IOException, ParseException {
  1132. List<WelcomeStudent> result = new ArrayList<>();
  1133. XSSFWorkbook sheets = new XSSFWorkbook(inputStream);
  1134. List<WelcomeOrg> ws = welcomeOrgService.list(null);
  1135. List<WelcomeCity> citys = welcomeCityService.list(null);
  1136. //读取第一张sheet
  1137. XSSFSheet sheetAt = sheets.getSheetAt(0);
  1138. DataFormatter dataFormatter = new DataFormatter();
  1139. try {
  1140. //rowNum = 3 从第三行开始获取值
  1141. //sheetAt.getLastRowNum():从0开始统计数量 所以得+1
  1142. for (int rowNum = 0; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
  1143. XSSFRow row = sheetAt.getRow(rowNum);
  1144. if (row != null) {
  1145. //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
  1146. //所以先使用setCellType()方法先将该单元格的类型设置为STRING
  1147. //然后poi会根据字符串读取它
  1148. //第一行数据获取月份
  1149. if (rowNum == 0) {
  1150. String number = dataFormatter.formatCellValue(row.getCell(0));//序号
  1151. if (!number.equals("序号")) {
  1152. return CommonResult.fail("导入数据第一列为序号");
  1153. }
  1154. String assNum = dataFormatter.formatCellValue(row.getCell(1));//录取号
  1155. if (!assNum.equals("录取号")) {
  1156. return CommonResult.fail("导入数据第二列为录取号");
  1157. }
  1158. String name = dataFormatter.formatCellValue(row.getCell(2));//姓名
  1159. if (!name.equals("姓名")) {
  1160. return CommonResult.fail("导入数据第三列为姓名");
  1161. }
  1162. String cardId = dataFormatter.formatCellValue(row.getCell(3));//身份证号
  1163. if (!cardId.equals("身份证号")) {
  1164. return CommonResult.fail("导入数据第四列为身份证号");
  1165. }
  1166. String school = dataFormatter.formatCellValue(row.getCell(4));//校区
  1167. if (!school.equals("校区")) {
  1168. return CommonResult.fail("导入数据第五列为校区");
  1169. }
  1170. String college = dataFormatter.formatCellValue(row.getCell(5));//院系
  1171. if (!college.equals("院系")) {
  1172. return CommonResult.fail("导入数据第六列为院系");
  1173. }
  1174. String major = dataFormatter.formatCellValue(row.getCell(6));//专业
  1175. if (!major.equals("专业")) {
  1176. return CommonResult.fail("导入数据第七列为专业");
  1177. }
  1178. String classstr = dataFormatter.formatCellValue(row.getCell(7));//班级
  1179. if (!classstr.equals("班级")) {
  1180. return CommonResult.fail("导入数据第八列为班级");
  1181. }
  1182. String examNum = dataFormatter.formatCellValue(row.getCell(8));//考生号
  1183. if (!examNum.equals("考生号")) {
  1184. return CommonResult.fail("导入数据第九列为考生号");
  1185. }
  1186. String eduSystem = dataFormatter.formatCellValue(row.getCell(9));//学制
  1187. if (!eduSystem.equals("学制")) {
  1188. return CommonResult.fail("导入数据第十列为学制");
  1189. }
  1190. String graSchool = dataFormatter.formatCellValue(row.getCell(10));//毕业中学
  1191. if (!graSchool.equals("毕业中学")) {
  1192. return CommonResult.fail("导入数据第十一列为毕业中学批次");
  1193. }
  1194. String batchValue = dataFormatter.formatCellValue(row.getCell(11));//批次
  1195. if (!batchValue.equals("批次")) {
  1196. return CommonResult.fail("导入数据第十二列为批次");
  1197. }
  1198. String politicalStatu = dataFormatter.formatCellValue(row.getCell(12));//政治面貌
  1199. if (!politicalStatu.equals("政治面貌")) {
  1200. return CommonResult.fail("导入数据第十三列为政治面貌");
  1201. }
  1202. String nationality = dataFormatter.formatCellValue(row.getCell(13));//民族
  1203. if (!nationality.equals("民族")) {
  1204. return CommonResult.fail("导入数据第十四列为民族");
  1205. }
  1206. String phone = dataFormatter.formatCellValue(row.getCell(14));//手机号码
  1207. if (!phone.equals("手机号码")) {
  1208. return CommonResult.fail("导入数据第十五列为手机号码");
  1209. }
  1210. String nativePlace = dataFormatter.formatCellValue(row.getCell(15));//籍贯
  1211. if (!nativePlace.contains("籍贯")) {
  1212. return CommonResult.fail("导入数据第十六列为籍贯");
  1213. }
  1214. String addressPlace = dataFormatter.formatCellValue(row.getCell(16));//家庭住址
  1215. if (!addressPlace.contains("家庭住址")) {
  1216. return CommonResult.fail("导入数据第十七列为家庭住址");
  1217. }
  1218. String addressDetail = dataFormatter.formatCellValue(row.getCell(17));//详细住址
  1219. if (!addressDetail.equals("详细住址")) {
  1220. return CommonResult.fail("导入数据第十八列为详细住址");
  1221. }
  1222. String zipCode = dataFormatter.formatCellValue(row.getCell(18));//邮编
  1223. if (!zipCode.equals("邮编")) {
  1224. return CommonResult.fail("导入数据第十九列为邮编");
  1225. }
  1226. } else {
  1227. WelcomeStudent studentData = new WelcomeStudent();
  1228. String assNum = dataFormatter.formatCellValue(row.getCell(1));//录取号
  1229. if (!StringUtils.hasText(assNum)) {
  1230. break;
  1231. }
  1232. studentData.setAdmissNum(assNum);
  1233. String name = dataFormatter.formatCellValue(row.getCell(2));//姓名
  1234. studentData.setName(name);
  1235. String cardId = dataFormatter.formatCellValue(row.getCell(3));//身份证号
  1236. //region 校验身份证号 并根据身份证号获取出生年月和性别
  1237. boolean isValidate = CardUtils.validateIdCard(cardId);//身份证是否合法
  1238. if(!isValidate){
  1239. return CommonResult.fail("录取编号为" + assNum + "的身份证不合法");
  1240. }
  1241. String sex = CardUtils.getSexByIdCard(cardId);
  1242. if(sex != null){
  1243. studentData.setSex(sex);
  1244. }
  1245. String birthday = CardUtils.getBirthdayByIdCard(cardId);
  1246. if(birthday != null){
  1247. studentData.setBirthday(birthday);
  1248. }
  1249. //endregion
  1250. studentData.setCardId(cardId);
  1251. String school = dataFormatter.formatCellValue(row.getCell(4));//校区
  1252. studentData.setSchool(school);
  1253. studentData.setSchoolId(eSchool.stringOf(school));
  1254. //region 院系专业
  1255. String college = dataFormatter.formatCellValue(row.getCell(5));//院系
  1256. Optional<WelcomeOrg> owo = ws.stream().filter(e -> e.getName().equals(college)).findFirst();
  1257. if (owo != null && owo.isPresent()) {
  1258. studentData.setCollege(college);
  1259. studentData.setCollegeId(owo.get().getId());
  1260. }
  1261. String major = dataFormatter.formatCellValue(row.getCell(6));//专业
  1262. Optional<WelcomeOrg> omwo = ws.stream().filter(e -> e.getName().equals(major)).findFirst();
  1263. if (omwo != null && omwo.isPresent()) {
  1264. studentData.setMajor(major);
  1265. studentData.setMajorId(omwo.get().getId());
  1266. }
  1267. String classstr = dataFormatter.formatCellValue(row.getCell(7));//班级
  1268. Optional<WelcomeOrg> ocwo = ws.stream().filter(e -> e.getName().equals(classstr)).findFirst();
  1269. if (ocwo != null && ocwo.isPresent()) {
  1270. studentData.setClassstr(classstr);
  1271. studentData.setClassstrId(ocwo.get().getId());
  1272. }
  1273. //endregion
  1274. String examNum = dataFormatter.formatCellValue(row.getCell(8));//考生号
  1275. studentData.setExamNum(examNum);
  1276. String eduSystem = dataFormatter.formatCellValue(row.getCell(9));//学制
  1277. studentData.setEduSystem(eduSystem);
  1278. String graSchool = dataFormatter.formatCellValue(row.getCell(10));//毕业中学
  1279. studentData.setGraduationSchool(graSchool);
  1280. String batchValue = dataFormatter.formatCellValue(row.getCell(11));//批次
  1281. studentData.setBatchValue(batchValue);
  1282. String politicalStatu = dataFormatter.formatCellValue(row.getCell(12));//政治面貌
  1283. studentData.setPoliticalStatu(politicalStatu);
  1284. String nationality = dataFormatter.formatCellValue(row.getCell(13));//民族
  1285. studentData.setNationality(nationality);
  1286. String phone = dataFormatter.formatCellValue(row.getCell(14));//手机号码
  1287. studentData.setPhone(phone);
  1288. //region 籍贯
  1289. String nativePlace = dataFormatter.formatCellValue(row.getCell(15));//籍贯
  1290. String[] addressDatas = nativePlace.split("/");
  1291. if (citys != null && citys.size() > 0) {
  1292. if (addressDatas != null && addressDatas.length >= 1) {
  1293. if (!addressDatas[0].contains("省")) {
  1294. return CommonResult.fail("录取编号为\" + assNum + \"的籍贯格式应该是 省/市/县区");
  1295. }
  1296. Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getDistrictZh().equals(addressDatas[0])).findFirst();
  1297. if (oProvince != null && oProvince.isPresent()) {
  1298. studentData.setOprovince(addressDatas[0]);
  1299. studentData.setOprovinceId(oProvince.get().getId());
  1300. } else {
  1301. return CommonResult.fail("录取编号为" + assNum + "的籍贯格式应该是 省/市/县区");
  1302. }
  1303. }
  1304. if (addressDatas != null && addressDatas.length >= 2) {
  1305. Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getDistrictZh().equals(addressDatas[1])).findFirst();
  1306. if (oProvince != null && oProvince.isPresent()) {
  1307. studentData.setOcity(addressDatas[1]);
  1308. studentData.setOcityId(oProvince.get().getId());
  1309. } else {
  1310. return CommonResult.fail("录取编号为" + assNum + "的籍贯格式应该是 省/市/县区");
  1311. }
  1312. }
  1313. if (addressDatas != null && addressDatas.length >= 3) {
  1314. Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getCityZh().equals(addressDatas[1]) && e.getDistrictZh().equals(addressDatas[2])).findFirst();
  1315. if (oProvince != null && oProvince.isPresent()) {
  1316. studentData.setOdistrict(addressDatas[2]);
  1317. studentData.setOdistrictId(oProvince.get().getId());
  1318. } else {
  1319. return CommonResult.fail("录取编号为" + assNum + "的籍贯格式应该是 省/市/县区");
  1320. }
  1321. }
  1322. }
  1323. //endregion
  1324. //region 家庭住址
  1325. String addressPlace = dataFormatter.formatCellValue(row.getCell(16));//家庭住址
  1326. String[] addressPlaces = addressPlace.split("/");
  1327. if (citys != null && citys.size() > 0) {
  1328. if (addressPlaces != null && addressPlaces.length >= 1) {
  1329. if (!addressPlaces[0].contains("省")) {
  1330. return CommonResult.fail("录取编号为" + assNum + "的家庭住址格式应该是 省/市/县区");
  1331. }
  1332. Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getDistrictZh().equals(addressPlaces[0])).findFirst();
  1333. if (oProvince != null && oProvince.isPresent()) {
  1334. studentData.setProvince(addressPlaces[0]);
  1335. studentData.setProvinceId(oProvince.get().getId());
  1336. } else {
  1337. return CommonResult.fail("录取编号为" + assNum + "的家庭住址格式应该是 省/市/县区");
  1338. }
  1339. }
  1340. if (addressPlaces != null && addressPlaces.length >= 2) {
  1341. Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getDistrictZh().equals(addressPlaces[1])).findFirst();
  1342. if (oProvince != null && oProvince.isPresent()) {
  1343. studentData.setCity(addressPlaces[1]);
  1344. studentData.setCityId(oProvince.get().getId());
  1345. } else {
  1346. return CommonResult.fail("录取编号为" + assNum + "的家庭住址格式应该是 省/市/县区");
  1347. }
  1348. }
  1349. if (addressPlaces != null && addressPlaces.length >= 3) {
  1350. Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getCityZh().equals(addressPlaces[1]) && e.getDistrictZh().equals(addressPlaces[2])).findFirst();
  1351. if (oProvince != null && oProvince.isPresent()) {
  1352. studentData.setDistrict(addressPlaces[2]);
  1353. studentData.setDistrictId(oProvince.get().getId());
  1354. } else {
  1355. return CommonResult.fail("录取编号为" + assNum + "的家庭住址格式应该是 省/市/县区");
  1356. }
  1357. }
  1358. }
  1359. //endregion
  1360. String addressDetail = dataFormatter.formatCellValue(row.getCell(17));//详细住址
  1361. studentData.setAddress(addressDetail);
  1362. String zipCode = dataFormatter.formatCellValue(row.getCell(18));//邮编
  1363. studentData.setZipCode(zipCode);
  1364. studentData.setIdenType(1);
  1365. studentData.setFillStatus("未填报");
  1366. result.add(studentData);
  1367. }
  1368. }
  1369. }
  1370. } catch (Exception e) {
  1371. return CommonResult.fail("请按模板格式导入数据");
  1372. }
  1373. return CommonResult.ok(result);
  1374. }
  1375. @Override
  1376. public CommonResult downloadStudentExcel() {
  1377. return CommonResult.ok("200", "操作成功", "https://chtech.ncjti.edu.cn/welcome/homeimage/学生信息管理.xlsx");
  1378. }
  1379. @Override
  1380. public void welcomeStudentExport(String userId,HttpServletResponse response, Integer collegeId, Integer majorId, Integer classstrId, String trafficMethod, String name) {
  1381. Workbook workbook = new XSSFWorkbook();
  1382. Sheet sheet = workbook.createSheet("学生信息");
  1383. WelcomeAccount wa = welcomeAccountService.getManageById(userId);
  1384. if (wa == null) {
  1385. System.out.println("当前账户已失效,无权限查看");
  1386. ExcelUtils.excelDownload(workbook, "学生信息.xlsx", response);
  1387. }
  1388. List<String> collegeIds = Arrays.asList(wa.getCollegeId().split(","));
  1389. if(collegeId != null && collegeId.intValue() > 0){
  1390. if (!collegeIds.contains(String.valueOf(collegeId))) {
  1391. ExcelUtils.excelDownload(workbook, "学生信息.xlsx", response);
  1392. }else {
  1393. collegeIds = new ArrayList<>();
  1394. collegeIds.add(String.valueOf(collegeId));
  1395. }
  1396. }
  1397. List<StudentPageVo> result = welcomeStudentService.queryStudentList(collegeIds, majorId, classstrId, trafficMethod, name);
  1398. //导出
  1399. Row headerRow = sheet.createRow(0);
  1400. headerRow.createCell(0).setCellValue("序号");
  1401. headerRow.createCell(1).setCellValue("录取号");
  1402. headerRow.createCell(2).setCellValue("姓名");
  1403. headerRow.createCell(3).setCellValue("身份证号");
  1404. headerRow.createCell(4).setCellValue("院系");
  1405. headerRow.createCell(5).setCellValue("专业");
  1406. headerRow.createCell(6).setCellValue("班级");
  1407. headerRow.createCell(7).setCellValue("交通方式");
  1408. headerRow.createCell(8).setCellValue("到站地点");
  1409. headerRow.createCell(9).setCellValue("陪同人数");
  1410. headerRow.createCell(10).setCellValue("填报状态");
  1411. headerRow.createCell(11).setCellValue("应缴金额");
  1412. headerRow.createCell(12).setCellValue("实付金额");
  1413. headerRow.createCell(13).setCellValue("宿舍信息");
  1414. for (int i = 0; i < result.size(); i++) {
  1415. StudentPageVo studentData = result.get(i);
  1416. Row dataRow = sheet.createRow(i + 1);
  1417. dataRow.createCell(0).setCellValue(i + 1);
  1418. dataRow.createCell(1).setCellValue(studentData.getAdmissNum());
  1419. dataRow.createCell(2).setCellValue(studentData.getName());
  1420. dataRow.createCell(3).setCellValue(studentData.getCardId());
  1421. dataRow.createCell(4).setCellValue(studentData.getCollege());
  1422. dataRow.createCell(5).setCellValue(studentData.getMajor());
  1423. dataRow.createCell(6).setCellValue(studentData.getClassstr());
  1424. dataRow.createCell(7).setCellValue(studentData.getTrafficMethod());
  1425. dataRow.createCell(8).setCellValue(studentData.getArrive());
  1426. dataRow.createCell(9).setCellValue(studentData.getAccompanyNum());
  1427. dataRow.createCell(10).setCellValue(studentData.getFillStatus());
  1428. dataRow.createCell(11).setCellValue(String.valueOf(studentData.getAmountPayable()));
  1429. dataRow.createCell(12).setCellValue(String.valueOf(studentData.getPayAmount()));
  1430. dataRow.createCell(13).setCellValue(studentData.getDormitory());
  1431. }
  1432. // 将工作簿写入文件
  1433. ExcelUtils.excelDownload(workbook, "学生信息.xlsx", response);
  1434. }
  1435. @Override
  1436. public CommonResult studentOverview() {
  1437. // 录取总数
  1438. // LambdaQueryWrapper<WelcomeStudent> queryWrapper=new LambdaQueryWrapper<>();
  1439. // queryWrapper.eq(WelcomeStudent::getIdenType,1);
  1440. int enrollmentTotal = 6352;//welcomeStudentService.count(queryWrapper);
  1441. // 缴费人数
  1442. int payCount = welcomeStudentService.payCount();
  1443. // 已入住寝室数
  1444. LambdaQueryWrapper<WelcomeBed> wrapper = new LambdaQueryWrapper<>();
  1445. wrapper.eq(WelcomeBed::getIsCheck, 1)
  1446. .eq(WelcomeBed::getRetentionState, 1);
  1447. int checkInBedTotal = welcomeBedService.count(wrapper);
  1448. // 报到率
  1449. // BigDecimal total = new BigDecimal(enrollmentTotal);
  1450. // BigDecimal bedTotal = new BigDecimal(checkInBedTotal);
  1451. // BigDecimal bigDecimal = bedTotal.divide(total).setScale(4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));
  1452. Double result = ((double)checkInBedTotal / enrollmentTotal) * 100;
  1453. String registrationRate = String.format("%.2f", result);
  1454. LocalDateTime start = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0);
  1455. LocalDateTime end = start.plusDays(1);
  1456. DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  1457. String startTime = start.format(dateTimeFormatter1);
  1458. String endTime = end.format(dateTimeFormatter1);
  1459. Integer mVisitorTotal = welcomeVisitorService.countTotal(startTime, endTime, 1);
  1460. Integer hVisitorTotal = welcomeVisitorService.countTotal(startTime, endTime, 2);
  1461. List<WelcomeSetting> wss = welcomeSettingService.list(null);
  1462. // 墨轩湖总车辆数
  1463. Integer mCarTotal = wss != null && wss.size() > 0 ? (wss.get(0).getMxhCarNum() == null ? 0 : wss.get(0).getMxhCarNum()) : 0;
  1464. // 黄家湖总车辆数
  1465. Integer hCarTotal = wss != null && wss.size() > 0 ? (wss.get(0).getHjhCarNum() == null ? 0 : wss.get(0).getHjhCarNum()) : 0;
  1466. StudentOverviewVo vo = new StudentOverviewVo();
  1467. vo.setEnrollmentTotal(enrollmentTotal);
  1468. vo.setPayCount(payCount);
  1469. vo.setCheckInBedTotal(checkInBedTotal);
  1470. vo.setRegistrationRate(registrationRate);
  1471. vo.setHCarTotal(hCarTotal - hVisitorTotal);
  1472. vo.setHVisitorTotal(hVisitorTotal);
  1473. vo.setMCarTotal(mCarTotal - mVisitorTotal);
  1474. vo.setMVisitorTotal(mVisitorTotal);
  1475. return CommonResult.ok(vo);
  1476. }
  1477. @Override
  1478. public CommonResult studentRegister() {
  1479. // 获取总数
  1480. Integer count = welcomeStudentService.totalCount();
  1481. List<StudentRegisterVo> vos = welcomeStudentService.studentRegister();
  1482. StudentRegisterVo vo = new StudentRegisterVo();
  1483. vo.setCollegeName("报到总数");
  1484. vo.setCount(count);
  1485. vos.add(vo);
  1486. return CommonResult.ok(vos);
  1487. }
  1488. @Override
  1489. public CommonResult studentTraffic() {
  1490. List<StudentTrafficVo> vos = welcomeStudentService.studentTraffic();
  1491. return CommonResult.ok(vos);
  1492. }
  1493. @Override
  1494. public CommonResult studentSexRatio() {
  1495. Integer manCount = welcomeStudentService.genderCount("男");
  1496. Integer girlCount = welcomeStudentService.genderCount("女");
  1497. StudentSexRatioVo vo = new StudentSexRatioVo();
  1498. vo.setCollegeName("全部");
  1499. vo.setManCount(manCount);
  1500. vo.setGirlCount(girlCount);
  1501. List<StudentSexRatioVo> vos = welcomeStudentService.studentSexRatio();
  1502. vos.add(vo);
  1503. return CommonResult.ok(vos);
  1504. }
  1505. @Override
  1506. public CommonResult studentStay() {
  1507. ArrayList<StudentStayVo> vos = new ArrayList<>();
  1508. List<WelcomeSchool> list = welcomeSchoolService.list(new QueryWrapper<>());
  1509. for (WelcomeSchool welcomeSchool : list) {
  1510. Integer schoolId = welcomeSchool.getId();
  1511. List<WelcomeBuild> builds = welcomeBuildService.getBuild(schoolId);
  1512. for (WelcomeBuild build : builds) {
  1513. Integer buildId = build.getId();
  1514. StudentStayVo vo = welcomeDormitoryService.getTotalCount(buildId);
  1515. vo.setSchoolName(welcomeSchool.getSchool());
  1516. vo.setBuildName(build.getBuild());
  1517. vos.add(vo);
  1518. }
  1519. }
  1520. return CommonResult.ok(vos);
  1521. }
  1522. @Override
  1523. public CommonResult queryStudentByToken(String userId) {
  1524. WelcomeStudent student = welcomeStudentService.getManageById(Integer.valueOf(userId));
  1525. if(student == null){
  1526. return CommonResult.fail("558","学生信息已失效,查询失败");
  1527. }
  1528. //家庭成员
  1529. List<FamilyVo> fvs = new ArrayList<>();
  1530. List<WelcomeFamily> familys = welcomeFamilyService.getManageByCardId(student.getCardId());
  1531. if (familys != null && familys.size() > 0) {
  1532. for (WelcomeFamily wf : familys) {
  1533. FamilyVo fv = new FamilyVo();
  1534. fv.setId(wf.getId());
  1535. fv.setFamilyShip(wf.getFamilyShip());
  1536. fv.setName(wf.getName());
  1537. fv.setPhone(wf.getPhone());
  1538. fv.setWorkUnit(wf.getWorkUnit());
  1539. fvs.add(fv);
  1540. }
  1541. }
  1542. student.setFvs(fvs);
  1543. //陪同人员
  1544. List<AccompanyVo> avs = new ArrayList<>();
  1545. List<WelcomeAccompany> accompanys = welcomeAccompanyService.getManageByCardId(student.getCardId());
  1546. if (accompanys != null && accompanys.size() > 0) {
  1547. for (WelcomeAccompany ac : accompanys) {
  1548. AccompanyVo av = new AccompanyVo();
  1549. av.setId(ac.getId());
  1550. av.setName(ac.getName());
  1551. av.setPhone(ac.getPhone());
  1552. avs.add(av);
  1553. }
  1554. }
  1555. student.setAvs(avs);
  1556. //时间段
  1557. List<ArriveTimeVo> atvs = new ArrayList<>();
  1558. List<WelcomeArriveSetting> wass = welcomeArriveSettingService.queryCheckDatas();
  1559. if (wass != null && wass.size() > 0) {
  1560. for (WelcomeArriveSetting was : wass) {
  1561. ArriveTimeVo atv = new ArriveTimeVo();
  1562. atv.setId(was.getId());
  1563. atv.setStartTime(was.getStartTime());
  1564. atv.setEndTime(was.getEndTime());
  1565. atv.setTimeStr(was.getStartTime() + "-" + was.getEndTime());
  1566. atv.setIsCheck((student.getArriveTimeId() != null && was.getId().equals(student.getArriveTimeId())) ? 1 : 0);
  1567. atvs.add(atv);
  1568. }
  1569. }
  1570. student.setAtvs(atvs);
  1571. if (!(student.getIsPay() != null && student.getIsPay().intValue() == 1)) {
  1572. List<JsonPayVo> payInfos = WelcomePayController.queryStudentPayInfo(student.getAdmissNum(), TimeExchange.getYear());
  1573. BigDecimal payAmount = new BigDecimal(BigInteger.ZERO);//实缴金额
  1574. BigDecimal yjPayAmount = new BigDecimal(BigInteger.ZERO);//应缴金额
  1575. for (JsonPayVo pi : payInfos) {
  1576. payAmount = payAmount.add(pi.getSJJE());
  1577. yjPayAmount = yjPayAmount.add(pi.getYJJE());
  1578. }
  1579. student.setPayAmount(payAmount);
  1580. student.setAmountPayable(yjPayAmount);
  1581. if (payInfos != null && payInfos.size() > 0) {
  1582. List<WelcomePaySetting> paySettings = welcomePaySettingService.queryPaySettings(student.getSchool());
  1583. if (paySettings != null && paySettings.size() > 0) {
  1584. for (WelcomePaySetting pay : paySettings) {
  1585. BigDecimal money = pay.getPayAmount();
  1586. if (pay.getMethod().equals("全部")) {
  1587. BigDecimal totalSj = new BigDecimal(BigInteger.ZERO);
  1588. for (JsonPayVo jpv : payInfos) {
  1589. totalSj = totalSj.add(jpv.getSJJE());
  1590. }
  1591. if (totalSj.compareTo(money) >= 0) {
  1592. student.setIsPay(1);
  1593. }
  1594. }
  1595. Optional<JsonPayVo> ojpv = payInfos.stream().filter(e -> e.getSFXMMC().equals(pay.getMethod())).findFirst();
  1596. if (ojpv != null && ojpv.isPresent()) {
  1597. if (ojpv.get().getSJJE().compareTo(money) >= 0) {
  1598. student.setIsPay(1);
  1599. }
  1600. }
  1601. }
  1602. } else {
  1603. student.setIsPay(0);
  1604. }
  1605. } else {
  1606. student.setIsPay(0);
  1607. }
  1608. if (payInfos != null && payInfos.size() > 0) {
  1609. int update = welcomeStudentService.updateWelcomeStudent(student);
  1610. if (update < 0) {
  1611. logger.error("获取支付信息导致学校信息查询失败");
  1612. return CommonResult.fail("查询失败");
  1613. }
  1614. }
  1615. }
  1616. return CommonResult.ok(student);
  1617. }
  1618. @Override
  1619. public CommonResult queryStudentInfo(String admissNum) {
  1620. WelcomeStudent ws = welcomeStudentService.getDataByNum(admissNum);
  1621. if (ws == null) {
  1622. return CommonResult.fail("558","当前学生信息已失效,查询失败");
  1623. }
  1624. //家庭成员
  1625. List<FamilyVo> fvs = new ArrayList<>();
  1626. List<WelcomeFamily> familys = welcomeFamilyService.getManageByCardId(ws.getCardId());
  1627. if (familys != null && familys.size() > 0) {
  1628. for (WelcomeFamily wf : familys) {
  1629. FamilyVo fv = new FamilyVo();
  1630. fv.setId(wf.getId());
  1631. fv.setFamilyShip(wf.getFamilyShip());
  1632. fv.setName(wf.getName());
  1633. fv.setPhone(wf.getPhone());
  1634. fv.setWorkUnit(wf.getWorkUnit());
  1635. fvs.add(fv);
  1636. }
  1637. }
  1638. ws.setFvs(fvs);
  1639. //陪同人员
  1640. List<AccompanyVo> avs = new ArrayList<>();
  1641. List<WelcomeAccompany> accompanys = welcomeAccompanyService.getManageByCardId(ws.getCardId());
  1642. if (accompanys != null && accompanys.size() > 0) {
  1643. for (WelcomeAccompany ac : accompanys) {
  1644. AccompanyVo av = new AccompanyVo();
  1645. av.setId(ac.getId());
  1646. av.setName(ac.getName());
  1647. av.setPhone(ac.getPhone());
  1648. avs.add(av);
  1649. }
  1650. }
  1651. ws.setAvs(avs);
  1652. //时间段
  1653. List<ArriveTimeVo> atvs = new ArrayList<>();
  1654. List<WelcomeArriveSetting> wass = welcomeArriveSettingService.queryCheckDatas();
  1655. if (wass != null && wass.size() > 0) {
  1656. for (WelcomeArriveSetting was : wass) {
  1657. ArriveTimeVo atv = new ArriveTimeVo();
  1658. atv.setId(was.getId());
  1659. atv.setStartTime(was.getStartTime());
  1660. atv.setEndTime(was.getEndTime());
  1661. atv.setTimeStr(was.getStartTime() + "-" + was.getEndTime());
  1662. atv.setIsCheck((ws.getArriveTimeId() != null && was.getId().equals(ws.getArriveTimeId())) ? 1 : 0);
  1663. atvs.add(atv);
  1664. }
  1665. }
  1666. ws.setAtvs(atvs);
  1667. List<PayDetailVO> pdvs = new ArrayList<>();
  1668. System.out.println("进支付比较");
  1669. List<JsonPayVo> payInfos = WelcomePayController.queryStudentPayInfo(ws.getAdmissNum(), TimeExchange.getYear());
  1670. BigDecimal payAmount = new BigDecimal(BigInteger.ZERO);//实缴金额
  1671. BigDecimal yjPayAmount = new BigDecimal(BigInteger.ZERO);//应缴金额
  1672. for (JsonPayVo pi : payInfos) {
  1673. payAmount = payAmount.add(pi.getSJJE());
  1674. yjPayAmount = yjPayAmount.add(pi.getYJJE());
  1675. PayDetailVO pdv = new PayDetailVO();
  1676. pdv.setPayName(pi.getSFXMMC());
  1677. pdv.setYJJE(pi.getYJJE());
  1678. pdv.setSJJE(pi.getSJJE());
  1679. pdvs.add(pdv);
  1680. }
  1681. ws.setPayAmount(payAmount);
  1682. ws.setAmountPayable(yjPayAmount);
  1683. System.out.println("进支付比较1" + JSON.toJSON(payInfos));
  1684. if (payInfos != null && payInfos.size() > 0) {
  1685. System.out.println("进支付比较2");
  1686. List<WelcomePaySetting> paySettings = welcomePaySettingService.queryPaySettings(ws.getSchool());
  1687. System.out.println("进支付比较3" + JSON.toJSON(paySettings));
  1688. if (paySettings != null && paySettings.size() > 0) {
  1689. System.out.println("进支付比较4");
  1690. for (WelcomePaySetting pay : paySettings) {
  1691. System.out.println("进支付比较5");
  1692. BigDecimal money = pay.getPayAmount();
  1693. if (pay.getMethod().equals("全部")) {
  1694. BigDecimal totalSj = new BigDecimal(BigInteger.ZERO);
  1695. for (JsonPayVo jpv : payInfos) {
  1696. totalSj = totalSj.add(jpv.getSJJE());
  1697. }
  1698. if (totalSj.compareTo(money) >= 0) {
  1699. ws.setIsPay(1);
  1700. }
  1701. }
  1702. Optional<JsonPayVo> ojpv = payInfos.stream().filter(e -> e.getSFXMMC().equals(pay.getMethod())).findFirst();
  1703. if (ojpv != null && ojpv.isPresent()) {
  1704. if (ojpv.get().getSJJE().compareTo(money) >= 0) {
  1705. ws.setIsPay(1);
  1706. }
  1707. }
  1708. }
  1709. } else {
  1710. ws.setIsPay(0);
  1711. }
  1712. } else {
  1713. ws.setIsPay(0);
  1714. }
  1715. if (!(ws.getIsPay() != null && ws.getIsPay().intValue() == 1)) {
  1716. int updateResult = welcomeStudentService.updateWelcomeStudent(ws);
  1717. if (updateResult < 0) {
  1718. return CommonResult.fail("查询支付信息失败");
  1719. }
  1720. }
  1721. PayInfoVO result = new PayInfoVO();
  1722. result.setId(ws.getId());
  1723. result.setName(ws.getName());
  1724. result.setAdmissNum(ws.getAdmissNum());
  1725. result.setIsPay(ws.getIsPay());
  1726. result.setPays(pdvs);
  1727. return CommonResult.ok(result);
  1728. }
  1729. }