WelcomeStudentController.java 89 KB

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