WelcomeStudentController.java 93 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917
  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. if(ws.getIsPay() == null){
  690. ws.setIsPay(0);
  691. }
  692. try {
  693. System.out.println("信息采集1");
  694. if (ws.getId() != null) {
  695. int update = welcomeStudentService.updateWelcomeStudent(ws);
  696. if (update < 0) {
  697. System.out.println("信息采集1.1");
  698. logger.error("采集学生信息失败,ws参数:" + JSON.toJSON(ws));
  699. throw new Exception("采集学生信息失败!");
  700. //return CommonResult.fail("采集学生信息失败1");
  701. }
  702. } else {
  703. int insert = welcomeStudentService.insertWelcomeStudent(ws);
  704. if (insert < 0) {
  705. System.out.println("信息采集1.2");
  706. logger.error("采集学生信息失败,ws参数:" + JSON.toJSON(ws));
  707. throw new Exception("采集学生信息失败!");
  708. //return CommonResult.fail("采集学生信息失败1");
  709. }
  710. }
  711. System.out.println("信息采集2");
  712. if (wfs != null && wfs.size() > 0) {
  713. int deleteF = welcomeFamilyService.deleteWelcomeFamilyByCard(ws.getCardId());
  714. boolean resultWf = welcomeFamilyService.saveBatch(wfs);
  715. System.out.println("信息采集1.3");
  716. if (!resultWf) {
  717. System.out.println("信息采集1.4");
  718. logger.error("采集学生信息失败,wfs参数:" + JSON.toJSON(wfs));
  719. throw new Exception("采集学生信息失败!");
  720. //return CommonResult.fail("采集学生信息失败2");
  721. }
  722. }
  723. System.out.println("信息采集3");
  724. if (was != null && was.size() > 0) {
  725. int deleteF = welcomeAccompanyService.deleteWelcomeAccompanyByCard(ws.getCardId());
  726. boolean resultWa = welcomeAccompanyService.saveBatch(was);
  727. System.out.println("信息采集1.5");
  728. if (!resultWa) {
  729. System.out.println("信息采集1.6");
  730. logger.error("采集学生信息失败,was参数:" + JSON.toJSON(was));
  731. throw new Exception("采集学生信息失败!");
  732. //return CommonResult.fail("采集学生信息失败3");
  733. }
  734. }
  735. } catch (Exception e) {
  736. logger.error(e.getMessage());
  737. throw new Exception("采集失败!");
  738. //return CommonResult.fail("采集学生信息失败4");
  739. }
  740. System.out.println("信息采集1.7");
  741. return CommonResult.ok("采集完成!");
  742. }
  743. @Override
  744. @Transactional(rollbackFor = {Exception.class})
  745. public CommonResult deleteStudentInfo(int id) throws Exception {
  746. System.out.println("删除了学生信息:" + id);
  747. WelcomeStudent ws = welcomeStudentService.getManageById(id);
  748. if (ws == null) {
  749. return CommonResult.fail("学生信息已失效,无法进行删除操作!");
  750. }
  751. //把旧床位清空
  752. WelcomeBed obedData = welcomeBedService.getBedByCardId(ws.getCardId());
  753. // if (obedData != null) {
  754. // obedData.setStudentCard(null);
  755. // obedData.setIsCheck(0);
  756. // obedData.setCardNum(null);
  757. // obedData.setName(null);
  758. // }
  759. try {
  760. //删除学生数据
  761. int deleteStudent = welcomeStudentService.deleteWelcomeStudentById(id);
  762. if (deleteStudent <= 0) {
  763. logger.error("删除学生信息失败,id参数:" + JSON.toJSON(id));
  764. throw new Exception("删除学生信息失败!");
  765. }
  766. if (obedData != null) {
  767. //删除宿舍数据
  768. // int deleteSd = welcomeBedService.updateWelcomeBed(obedData);
  769. // if (deleteSd < 0) {
  770. // logger.error("删除宿舍失败,obedData参数:" + JSON.toJSON(obedData));
  771. // throw new Exception("删除学生信息失败!");
  772. // }
  773. welcomeBedService.updateData(obedData.getId());
  774. // 修改寝室信息
  775. WelcomeDormitory welcomeDormitory = welcomeDormitoryService.getById(obedData.getDormitoryId());
  776. if (ObjectUtils.isNotEmpty(welcomeDormitory)) {
  777. Integer freeBedNumber = welcomeDormitory.getFreeBedNumber();
  778. Integer bedNumber = welcomeDormitory.getBedNumber();
  779. freeBedNumber = freeBedNumber + 1;
  780. if (bedNumber.equals(freeBedNumber)) {
  781. welcomeDormitory.setFreeBedNumber(freeBedNumber);
  782. welcomeDormitory.setStatus(1);
  783. } else if (bedNumber > freeBedNumber) {
  784. welcomeDormitory.setFreeBedNumber(freeBedNumber);
  785. welcomeDormitory.setStatus(3);
  786. }
  787. welcomeDormitoryService.updateById(welcomeDormitory);
  788. }
  789. }
  790. //删除同行人员
  791. int deleteWa = welcomeAccompanyService.deleteWelcomeAccompanyByCard(ws.getCardId());
  792. //删除家庭成员
  793. int deletef = welcomeFamilyService.deleteWelcomeFamilyByCard(ws.getCardId());
  794. } catch (Exception e) {
  795. logger.error(e.getMessage());
  796. throw new Exception("删除失败!");
  797. }
  798. return CommonResult.ok("删除成功");
  799. }
  800. @Override
  801. public CommonResult importStudentExcel(MultipartFile file) throws IOException, ParseException {
  802. System.out.println("导入学生信息");
  803. if (file.isEmpty() || file.getSize() == 0) {
  804. return CommonResult.fail("导入文件不能为空");
  805. }
  806. String ContentType = file.getContentType();
  807. InputStream inputStream = file.getInputStream();
  808. List<WelcomeStudent> result = new ArrayList<>();
  809. //xls格式文件
  810. if (ContentType.equals(eFileType.Xls.getValue())) {
  811. CommonResult<List<WelcomeStudent>> resultData = readXls(inputStream);
  812. if (!resultData.isSuccess()) {
  813. return resultData;
  814. }
  815. result = resultData.getData();
  816. } else if (ContentType.equals(eFileType.Xlsx.getValue())) {
  817. CommonResult<List<WelcomeStudent>> resultData = readXlsx(inputStream);
  818. if (!resultData.isSuccess()) {
  819. return resultData;
  820. }
  821. result = resultData.getData();
  822. } else {
  823. return CommonResult.fail("学生信息数据导入只支持Xls或Xlsx格式文件");
  824. }
  825. StringBuilder sb = new StringBuilder();
  826. List<String> cardIds = result.stream().map(WelcomeStudent::getCardId).collect(Collectors.toList());
  827. List<WelcomeStudent> existStudents = welcomeStudentService.queryStudentByCardId(cardIds);
  828. if (existStudents != null && existStudents.size() > 0) {
  829. for (WelcomeStudent ws : result) {
  830. Optional<WelcomeStudent> ows = existStudents.stream().filter(e -> e.getCardId().equals(ws.getCardId())).findFirst();
  831. if (ows != null && ows.isPresent()) {
  832. sb.append(ows.get().getName() + ows.get().getCardId() + "数据在数据库中已存在;");
  833. ws.setId(ows.get().getId());
  834. ws.setAdmissNum(ws.getAdmissNum());//录取号
  835. ws.setName(ws.getName());//姓名
  836. ws.setCardId(ws.getCardId());//身份证号
  837. ws.setSchool(ws.getSchool());//校区
  838. ws.setSchoolId(eSchool.stringOf(ws.getSchool()));//校区
  839. ws.setCollege(ws.getCollege());
  840. ws.setCollegeId(ws.getCollegeId());
  841. ws.setMajor(ws.getMajor());
  842. ws.setMajorId(ws.getMajorId());
  843. ws.setClassstr(ws.getClassstr());
  844. ws.setClassstrId(ws.getClassstrId());
  845. ws.setExamNum(ws.getExamNum());//考生号
  846. ws.setEduSystem(ws.getEduSystem());//学制
  847. ws.setGraduationSchool(ws.getGraduationSchool());//毕业中学
  848. ws.setBatchValue(ws.getBatchValue());//批次
  849. ws.setPoliticalStatu(ws.getPoliticalStatu());//政治面貌
  850. ws.setNationality(ws.getNationality());//民族
  851. ws.setPhone(ws.getPhone());//手机号码
  852. ws.setOprovince(ws.getOprovince());
  853. ws.setOprovinceId(ws.getOprovinceId());
  854. ws.setOcity(ws.getOcity());
  855. ws.setOcityId(ws.getOcityId());
  856. ws.setOdistrict(ws.getOdistrict());
  857. ws.setOdistrictId(ws.getOdistrictId());
  858. ws.setProvince(ws.getProvince());
  859. ws.setProvinceId(ws.getProvinceId());
  860. ws.setCity(ws.getCity());
  861. ws.setCityId(ws.getCityId());
  862. ws.setDistrict(ws.getDistrict());
  863. ws.setDistrictId(ws.getDistrictId());
  864. ws.setAddress(ws.getAddress());
  865. ws.setZipCode(ws.getZipCode());
  866. ws.setIsPay(0);
  867. }
  868. }
  869. }
  870. boolean resultBool = welcomeStudentService.saveOrUpdateBatch(result);
  871. System.out.println("导入学生1");
  872. return resultBool ? CommonResult.ok("导入成功:" + sb.toString()) : CommonResult.fail("导入失败");
  873. }
  874. /**
  875. * xls文件读取方法
  876. *
  877. * @param inputStream
  878. * @return
  879. * @throws IOException
  880. * @throws ParseException
  881. */
  882. private CommonResult<List<WelcomeStudent>> readXls(InputStream inputStream) throws IOException, ParseException {
  883. List<WelcomeStudent> result = new ArrayList<>();
  884. HSSFWorkbook sheets = new HSSFWorkbook(inputStream);
  885. List<WelcomeOrg> ws = welcomeOrgService.list(null);
  886. List<WelcomeCity> citys = welcomeCityService.list(null);
  887. //读取第一张sheet
  888. HSSFSheet sheetAt = sheets.getSheetAt(0);
  889. DataFormatter dataFormatter = new DataFormatter();
  890. try {
  891. //rowNum = 3 从第三行开始获取值
  892. //sheetAt.getLastRowNum():从0开始统计数量 所以得+1
  893. for (int rowNum = 0; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
  894. HSSFRow row = sheetAt.getRow(rowNum);
  895. if (row != null) {
  896. //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
  897. //所以先使用setCellType()方法先将该单元格的类型设置为STRING
  898. //然后poi会根据字符串读取它
  899. //第一行数据获取月份
  900. if (rowNum == 0) {
  901. String number = dataFormatter.formatCellValue(row.getCell(0));//序号
  902. if (!number.equals("序号")) {
  903. return CommonResult.fail("导入数据第一列为序号");
  904. }
  905. String assNum = dataFormatter.formatCellValue(row.getCell(1));//录取号
  906. if (!assNum.equals("录取号")) {
  907. return CommonResult.fail("导入数据第二列为录取号");
  908. }
  909. String name = dataFormatter.formatCellValue(row.getCell(2));//姓名
  910. if (!name.equals("姓名")) {
  911. return CommonResult.fail("导入数据第三列为姓名");
  912. }
  913. String cardId = dataFormatter.formatCellValue(row.getCell(3));//身份证号
  914. if (!cardId.equals("身份证号")) {
  915. return CommonResult.fail("导入数据第四列为身份证号");
  916. }
  917. String school = dataFormatter.formatCellValue(row.getCell(4));//校区
  918. if (!school.equals("校区")) {
  919. return CommonResult.fail("导入数据第五列为校区");
  920. }
  921. String college = dataFormatter.formatCellValue(row.getCell(5));//院系
  922. if (!college.equals("院系")) {
  923. return CommonResult.fail("导入数据第六列为院系");
  924. }
  925. String major = dataFormatter.formatCellValue(row.getCell(6));//专业
  926. if (!major.equals("专业")) {
  927. return CommonResult.fail("导入数据第七列为专业");
  928. }
  929. String classstr = dataFormatter.formatCellValue(row.getCell(7));//班级
  930. if (!classstr.equals("班级")) {
  931. return CommonResult.fail("导入数据第八列为班级");
  932. }
  933. String examNum = dataFormatter.formatCellValue(row.getCell(8));//考生号
  934. if (!examNum.equals("考生号")) {
  935. return CommonResult.fail("导入数据第九列为考生号");
  936. }
  937. String eduSystem = dataFormatter.formatCellValue(row.getCell(9));//学制
  938. if (!eduSystem.equals("学制")) {
  939. return CommonResult.fail("导入数据第十列为学制");
  940. }
  941. String graSchool = dataFormatter.formatCellValue(row.getCell(10));//毕业中学
  942. if (!graSchool.equals("毕业中学")) {
  943. return CommonResult.fail("导入数据第十一列为毕业中学批次");
  944. }
  945. String batchValue = dataFormatter.formatCellValue(row.getCell(11));//批次
  946. if (!batchValue.equals("批次")) {
  947. return CommonResult.fail("导入数据第十二列为批次");
  948. }
  949. String politicalStatu = dataFormatter.formatCellValue(row.getCell(12));//政治面貌
  950. if (!politicalStatu.equals("政治面貌")) {
  951. return CommonResult.fail("导入数据第十三列为政治面貌");
  952. }
  953. String nationality = dataFormatter.formatCellValue(row.getCell(13));//民族
  954. if (!nationality.equals("民族")) {
  955. return CommonResult.fail("导入数据第十四列为民族");
  956. }
  957. String phone = dataFormatter.formatCellValue(row.getCell(14));//手机号码
  958. if (!phone.equals("手机号码")) {
  959. return CommonResult.fail("导入数据第十五列为手机号码");
  960. }
  961. String nativePlace = dataFormatter.formatCellValue(row.getCell(15));//籍贯
  962. if (!nativePlace.contains("籍贯")) {
  963. return CommonResult.fail("导入数据第十六列为籍贯");
  964. }
  965. String addressPlace = dataFormatter.formatCellValue(row.getCell(16));//家庭住址
  966. if (!addressPlace.contains("家庭住址")) {
  967. return CommonResult.fail("导入数据第十七列为家庭住址");
  968. }
  969. String addressDetail = dataFormatter.formatCellValue(row.getCell(17));//详细住址
  970. if (!addressDetail.equals("详细住址")) {
  971. return CommonResult.fail("导入数据第十八列为详细住址");
  972. }
  973. String zipCode = dataFormatter.formatCellValue(row.getCell(18));//邮编
  974. if (!zipCode.equals("邮编")) {
  975. return CommonResult.fail("导入数据第十九列为邮编");
  976. }
  977. } else {
  978. WelcomeStudent studentData = new WelcomeStudent();
  979. String assNum = dataFormatter.formatCellValue(row.getCell(1));//录取号
  980. if (!StringUtils.hasText(assNum)) {
  981. break;
  982. }
  983. studentData.setAdmissNum(assNum);
  984. String name = dataFormatter.formatCellValue(row.getCell(2));//姓名
  985. studentData.setName(name);
  986. String cardId = dataFormatter.formatCellValue(row.getCell(3));//身份证号
  987. //region 校验身份证号 并根据身份证号获取出生年月和性别
  988. boolean isValidate = CardUtils.validateIdCard(cardId);//身份证是否合法
  989. if (!isValidate) {
  990. return CommonResult.fail("录取编号为" + assNum + "的身份证不合法");
  991. }
  992. String sex = CardUtils.getSexByIdCard(cardId);
  993. if (sex != null) {
  994. studentData.setSex(sex);
  995. }
  996. String birthday = CardUtils.getBirthdayByIdCard(cardId);
  997. if (birthday != null) {
  998. studentData.setBirthday(birthday);
  999. }
  1000. //endregion
  1001. studentData.setCardId(cardId);
  1002. String school = dataFormatter.formatCellValue(row.getCell(4));//校区
  1003. studentData.setSchool(school);
  1004. studentData.setSchoolId(eSchool.stringOf(school));
  1005. //region 院系专业
  1006. String college = dataFormatter.formatCellValue(row.getCell(5));//院系
  1007. Optional<WelcomeOrg> owo = ws.stream().filter(e -> e.getName().equals(college)).findFirst();
  1008. if (owo != null && owo.isPresent()) {
  1009. studentData.setCollege(college);
  1010. studentData.setCollegeId(owo.get().getId());
  1011. }
  1012. String major = dataFormatter.formatCellValue(row.getCell(6));//专业
  1013. Optional<WelcomeOrg> omwo = ws.stream().filter(e -> owo != null && owo.isPresent() && e.getParentId().intValue() == owo.get().getId().intValue() && e.getName().equals(major)).findFirst();
  1014. if (omwo != null && omwo.isPresent()) {
  1015. studentData.setMajor(major);
  1016. studentData.setMajorId(omwo.get().getId());
  1017. }
  1018. String classstr = dataFormatter.formatCellValue(row.getCell(7));//班级
  1019. Optional<WelcomeOrg> ocwo = ws.stream().filter(e -> omwo != null && omwo.isPresent() && e.getParentId().intValue() == omwo.get().getId().intValue() && e.getName().equals(classstr)).findFirst();
  1020. if (ocwo != null && ocwo.isPresent()) {
  1021. studentData.setClassstr(classstr);
  1022. studentData.setClassstrId(ocwo.get().getId());
  1023. }
  1024. //endregion
  1025. String examNum = dataFormatter.formatCellValue(row.getCell(8));//考生号
  1026. studentData.setExamNum(examNum);
  1027. String eduSystem = dataFormatter.formatCellValue(row.getCell(9));//学制
  1028. studentData.setEduSystem(eduSystem);
  1029. String graSchool = dataFormatter.formatCellValue(row.getCell(10));//毕业中学
  1030. studentData.setGraduationSchool(graSchool);
  1031. String batchValue = dataFormatter.formatCellValue(row.getCell(11));//批次
  1032. studentData.setBatchValue(batchValue);
  1033. String politicalStatu = dataFormatter.formatCellValue(row.getCell(12));//政治面貌
  1034. studentData.setPoliticalStatu(politicalStatu);
  1035. String nationality = dataFormatter.formatCellValue(row.getCell(13));//民族
  1036. studentData.setNationality(nationality);
  1037. String phone = dataFormatter.formatCellValue(row.getCell(14));//手机号码
  1038. studentData.setPhone(phone);
  1039. //region 籍贯
  1040. String nativePlace = dataFormatter.formatCellValue(row.getCell(15));//籍贯
  1041. String[] addressDatas = nativePlace.split("/");
  1042. if (citys != null && citys.size() > 0) {
  1043. if (addressDatas != null && addressDatas.length >= 1) {
  1044. if (!addressDatas[0].contains("省")) {
  1045. return CommonResult.fail("录取编号为\" + assNum + \"的籍贯格式应该是 省/市/县");
  1046. }
  1047. Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getDistrictZh().equals(addressDatas[0])).findFirst();
  1048. if (oProvince != null && oProvince.isPresent()) {
  1049. studentData.setOprovince(addressDatas[0]);
  1050. studentData.setOprovinceId(oProvince.get().getId());
  1051. } else {
  1052. return CommonResult.fail("录取编号为" + assNum + "的籍贯格式应该是 省/市/县区");
  1053. }
  1054. }
  1055. if (addressDatas != null && addressDatas.length >= 2) {
  1056. Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getDistrictZh().equals(addressDatas[1])).findFirst();
  1057. if (oProvince != null && oProvince.isPresent()) {
  1058. studentData.setOcity(addressDatas[1]);
  1059. studentData.setOcityId(oProvince.get().getId());
  1060. } else {
  1061. return CommonResult.fail("录取编号为" + assNum + "的籍贯格式应该是 省/市/县区");
  1062. }
  1063. }
  1064. if (addressDatas != null && addressDatas.length >= 3) {
  1065. Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getCityZh().equals(addressDatas[1]) && addressDatas[2].contains(e.getDistrictZh())).findFirst();
  1066. if (oProvince != null && oProvince.isPresent()) {
  1067. studentData.setOdistrict(addressDatas[2]);
  1068. studentData.setOdistrictId(oProvince.get().getId());
  1069. } else {
  1070. return CommonResult.fail("录取编号为" + assNum + "的籍贯格式应该是 省/市/县区");
  1071. }
  1072. }
  1073. }
  1074. //endregion
  1075. //region 家庭住址
  1076. String addressPlace = dataFormatter.formatCellValue(row.getCell(16));//家庭住址
  1077. String[] addressPlaces = addressPlace.split("/");
  1078. if (citys != null && citys.size() > 0) {
  1079. if (addressPlaces != null && addressPlaces.length >= 1) {
  1080. if (!addressPlaces[0].contains("省")) {
  1081. return CommonResult.fail("录取编号为" + assNum + "的家庭住址格式应该是 省/市/县区");
  1082. }
  1083. Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getDistrictZh().equals(addressPlaces[0])).findFirst();
  1084. if (oProvince != null && oProvince.isPresent()) {
  1085. studentData.setProvince(addressPlaces[0]);
  1086. studentData.setProvinceId(oProvince.get().getId());
  1087. } else {
  1088. return CommonResult.fail("录取编号为" + assNum + "的家庭住址格式应该是 省/市/县区");
  1089. }
  1090. }
  1091. if (addressPlaces != null && addressPlaces.length >= 2) {
  1092. Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getDistrictZh().equals(addressPlaces[1])).findFirst();
  1093. if (oProvince != null && oProvince.isPresent()) {
  1094. studentData.setCity(addressPlaces[1]);
  1095. studentData.setCityId(oProvince.get().getId());
  1096. } else {
  1097. return CommonResult.fail("录取编号为" + assNum + "的家庭住址格式应该是 省/市/县区");
  1098. }
  1099. }
  1100. if (addressPlaces != null && addressPlaces.length >= 3) {
  1101. Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getCityZh().equals(addressPlaces[1]) && addressPlaces[2].contains(e.getDistrictZh())).findFirst();
  1102. if (oProvince != null && oProvince.isPresent()) {
  1103. studentData.setDistrict(addressPlaces[2]);
  1104. studentData.setDistrictId(oProvince.get().getId());
  1105. } else {
  1106. return CommonResult.fail("录取编号为" + assNum + "的家庭住址格式应该是 省/市/县区");
  1107. }
  1108. }
  1109. }
  1110. //endregion
  1111. String addressDetail = dataFormatter.formatCellValue(row.getCell(17));//详细住址
  1112. studentData.setAddress(addressDetail);
  1113. String zipCode = dataFormatter.formatCellValue(row.getCell(18));//邮编
  1114. studentData.setZipCode(zipCode);
  1115. studentData.setIdenType(1);
  1116. studentData.setFillStatus("未填报");
  1117. result.add(studentData);
  1118. }
  1119. }
  1120. }
  1121. } catch (Exception e) {
  1122. return CommonResult.fail("请按模板格式导入数据");
  1123. }
  1124. return CommonResult.ok(result);
  1125. }
  1126. /**
  1127. * xls文件读取方法
  1128. *
  1129. * @param inputStream
  1130. * @return
  1131. * @throws IOException
  1132. * @throws ParseException
  1133. */
  1134. private CommonResult<List<WelcomeStudent>> readXlsx(InputStream inputStream) throws IOException, ParseException {
  1135. List<WelcomeStudent> result = new ArrayList<>();
  1136. XSSFWorkbook sheets = new XSSFWorkbook(inputStream);
  1137. List<WelcomeOrg> ws = welcomeOrgService.list(null);
  1138. List<WelcomeCity> citys = welcomeCityService.list(null);
  1139. //读取第一张sheet
  1140. XSSFSheet sheetAt = sheets.getSheetAt(0);
  1141. DataFormatter dataFormatter = new DataFormatter();
  1142. try {
  1143. //rowNum = 3 从第三行开始获取值
  1144. //sheetAt.getLastRowNum():从0开始统计数量 所以得+1
  1145. for (int rowNum = 0; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
  1146. XSSFRow row = sheetAt.getRow(rowNum);
  1147. if (row != null) {
  1148. //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
  1149. //所以先使用setCellType()方法先将该单元格的类型设置为STRING
  1150. //然后poi会根据字符串读取它
  1151. //第一行数据获取月份
  1152. if (rowNum == 0) {
  1153. String number = dataFormatter.formatCellValue(row.getCell(0));//序号
  1154. if (!number.equals("序号")) {
  1155. return CommonResult.fail("导入数据第一列为序号");
  1156. }
  1157. String assNum = dataFormatter.formatCellValue(row.getCell(1));//录取号
  1158. if (!assNum.equals("录取号")) {
  1159. return CommonResult.fail("导入数据第二列为录取号");
  1160. }
  1161. String name = dataFormatter.formatCellValue(row.getCell(2));//姓名
  1162. if (!name.equals("姓名")) {
  1163. return CommonResult.fail("导入数据第三列为姓名");
  1164. }
  1165. String cardId = dataFormatter.formatCellValue(row.getCell(3));//身份证号
  1166. if (!cardId.equals("身份证号")) {
  1167. return CommonResult.fail("导入数据第四列为身份证号");
  1168. }
  1169. String school = dataFormatter.formatCellValue(row.getCell(4));//校区
  1170. if (!school.equals("校区")) {
  1171. return CommonResult.fail("导入数据第五列为校区");
  1172. }
  1173. String college = dataFormatter.formatCellValue(row.getCell(5));//院系
  1174. if (!college.equals("院系")) {
  1175. return CommonResult.fail("导入数据第六列为院系");
  1176. }
  1177. String major = dataFormatter.formatCellValue(row.getCell(6));//专业
  1178. if (!major.equals("专业")) {
  1179. return CommonResult.fail("导入数据第七列为专业");
  1180. }
  1181. String classstr = dataFormatter.formatCellValue(row.getCell(7));//班级
  1182. if (!classstr.equals("班级")) {
  1183. return CommonResult.fail("导入数据第八列为班级");
  1184. }
  1185. String examNum = dataFormatter.formatCellValue(row.getCell(8));//考生号
  1186. if (!examNum.equals("考生号")) {
  1187. return CommonResult.fail("导入数据第九列为考生号");
  1188. }
  1189. String eduSystem = dataFormatter.formatCellValue(row.getCell(9));//学制
  1190. if (!eduSystem.equals("学制")) {
  1191. return CommonResult.fail("导入数据第十列为学制");
  1192. }
  1193. String graSchool = dataFormatter.formatCellValue(row.getCell(10));//毕业中学
  1194. if (!graSchool.equals("毕业中学")) {
  1195. return CommonResult.fail("导入数据第十一列为毕业中学批次");
  1196. }
  1197. String batchValue = dataFormatter.formatCellValue(row.getCell(11));//批次
  1198. if (!batchValue.equals("批次")) {
  1199. return CommonResult.fail("导入数据第十二列为批次");
  1200. }
  1201. String politicalStatu = dataFormatter.formatCellValue(row.getCell(12));//政治面貌
  1202. if (!politicalStatu.equals("政治面貌")) {
  1203. return CommonResult.fail("导入数据第十三列为政治面貌");
  1204. }
  1205. String nationality = dataFormatter.formatCellValue(row.getCell(13));//民族
  1206. if (!nationality.equals("民族")) {
  1207. return CommonResult.fail("导入数据第十四列为民族");
  1208. }
  1209. String phone = dataFormatter.formatCellValue(row.getCell(14));//手机号码
  1210. if (!phone.equals("手机号码")) {
  1211. return CommonResult.fail("导入数据第十五列为手机号码");
  1212. }
  1213. String nativePlace = dataFormatter.formatCellValue(row.getCell(15));//籍贯
  1214. if (!nativePlace.contains("籍贯")) {
  1215. return CommonResult.fail("导入数据第十六列为籍贯");
  1216. }
  1217. String addressPlace = dataFormatter.formatCellValue(row.getCell(16));//家庭住址
  1218. if (!addressPlace.contains("家庭住址")) {
  1219. return CommonResult.fail("导入数据第十七列为家庭住址");
  1220. }
  1221. String addressDetail = dataFormatter.formatCellValue(row.getCell(17));//详细住址
  1222. if (!addressDetail.equals("详细住址")) {
  1223. return CommonResult.fail("导入数据第十八列为详细住址");
  1224. }
  1225. String zipCode = dataFormatter.formatCellValue(row.getCell(18));//邮编
  1226. if (!zipCode.equals("邮编")) {
  1227. return CommonResult.fail("导入数据第十九列为邮编");
  1228. }
  1229. } else {
  1230. WelcomeStudent studentData = new WelcomeStudent();
  1231. String assNum = dataFormatter.formatCellValue(row.getCell(1));//录取号
  1232. if (!StringUtils.hasText(assNum)) {
  1233. break;
  1234. }
  1235. studentData.setAdmissNum(assNum);
  1236. String name = dataFormatter.formatCellValue(row.getCell(2));//姓名
  1237. studentData.setName(name);
  1238. String cardId = dataFormatter.formatCellValue(row.getCell(3));//身份证号
  1239. //region 校验身份证号 并根据身份证号获取出生年月和性别
  1240. boolean isValidate = CardUtils.validateIdCard(cardId);//身份证是否合法
  1241. if (!isValidate) {
  1242. return CommonResult.fail("录取编号为" + assNum + "的身份证不合法");
  1243. }
  1244. String sex = CardUtils.getSexByIdCard(cardId);
  1245. if (sex != null) {
  1246. studentData.setSex(sex);
  1247. }
  1248. String birthday = CardUtils.getBirthdayByIdCard(cardId);
  1249. if (birthday != null) {
  1250. studentData.setBirthday(birthday);
  1251. }
  1252. //endregion
  1253. studentData.setCardId(cardId);
  1254. String school = dataFormatter.formatCellValue(row.getCell(4));//校区
  1255. studentData.setSchool(school);
  1256. studentData.setSchoolId(eSchool.stringOf(school));
  1257. //region 院系专业
  1258. String college = dataFormatter.formatCellValue(row.getCell(5));//院系
  1259. Optional<WelcomeOrg> owo = ws.stream().filter(e -> e.getName().equals(college)).findFirst();
  1260. if (owo != null && owo.isPresent()) {
  1261. studentData.setCollege(college);
  1262. studentData.setCollegeId(owo.get().getId());
  1263. }
  1264. String major = dataFormatter.formatCellValue(row.getCell(6));//专业
  1265. Optional<WelcomeOrg> omwo = ws.stream().filter(e -> owo != null && owo.isPresent() && e.getParentId().intValue() == owo.get().getId().intValue() && e.getName().equals(major)).findFirst();
  1266. if (omwo != null && omwo.isPresent()) {
  1267. studentData.setMajor(major);
  1268. studentData.setMajorId(omwo.get().getId());
  1269. }
  1270. String classstr = dataFormatter.formatCellValue(row.getCell(7));//班级
  1271. Optional<WelcomeOrg> ocwo = ws.stream().filter(e -> omwo != null && omwo.isPresent() && e.getParentId().intValue() == omwo.get().getId().intValue() && e.getName().equals(classstr)).findFirst();
  1272. if (ocwo != null && ocwo.isPresent()) {
  1273. studentData.setClassstr(classstr);
  1274. studentData.setClassstrId(ocwo.get().getId());
  1275. }
  1276. //endregion
  1277. String examNum = dataFormatter.formatCellValue(row.getCell(8));//考生号
  1278. studentData.setExamNum(examNum);
  1279. String eduSystem = dataFormatter.formatCellValue(row.getCell(9));//学制
  1280. studentData.setEduSystem(eduSystem);
  1281. String graSchool = dataFormatter.formatCellValue(row.getCell(10));//毕业中学
  1282. studentData.setGraduationSchool(graSchool);
  1283. String batchValue = dataFormatter.formatCellValue(row.getCell(11));//批次
  1284. studentData.setBatchValue(batchValue);
  1285. String politicalStatu = dataFormatter.formatCellValue(row.getCell(12));//政治面貌
  1286. studentData.setPoliticalStatu(politicalStatu);
  1287. String nationality = dataFormatter.formatCellValue(row.getCell(13));//民族
  1288. studentData.setNationality(nationality);
  1289. String phone = dataFormatter.formatCellValue(row.getCell(14));//手机号码
  1290. studentData.setPhone(phone);
  1291. //region 籍贯
  1292. String nativePlace = dataFormatter.formatCellValue(row.getCell(15));//籍贯
  1293. String[] addressDatas = nativePlace.split("/");
  1294. if (citys != null && citys.size() > 0) {
  1295. if (addressDatas != null && addressDatas.length >= 1) {
  1296. if (!addressDatas[0].contains("省")) {
  1297. return CommonResult.fail("录取编号为\" + assNum + \"的籍贯格式应该是 省/市/县区");
  1298. }
  1299. Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getDistrictZh().equals(addressDatas[0])).findFirst();
  1300. if (oProvince != null && oProvince.isPresent()) {
  1301. studentData.setOprovince(addressDatas[0]);
  1302. studentData.setOprovinceId(oProvince.get().getId());
  1303. } else {
  1304. return CommonResult.fail("录取编号为" + assNum + "的籍贯格式应该是 省/市/县区");
  1305. }
  1306. }
  1307. if (addressDatas != null && addressDatas.length >= 2) {
  1308. Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getDistrictZh().equals(addressDatas[1])).findFirst();
  1309. if (oProvince != null && oProvince.isPresent()) {
  1310. studentData.setOcity(addressDatas[1]);
  1311. studentData.setOcityId(oProvince.get().getId());
  1312. } else {
  1313. return CommonResult.fail("录取编号为" + assNum + "的籍贯格式应该是 省/市/县区");
  1314. }
  1315. }
  1316. if (addressDatas != null && addressDatas.length >= 3) {
  1317. Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getCityZh().equals(addressDatas[1]) && addressDatas[2].contains(e.getDistrictZh())).findFirst();
  1318. if (oProvince != null && oProvince.isPresent()) {
  1319. studentData.setOdistrict(addressDatas[2]);
  1320. studentData.setOdistrictId(oProvince.get().getId());
  1321. } else {
  1322. return CommonResult.fail("录取编号为" + assNum + "的籍贯格式应该是 省/市/县区");
  1323. }
  1324. }
  1325. }
  1326. //endregion
  1327. //region 家庭住址
  1328. String addressPlace = dataFormatter.formatCellValue(row.getCell(16));//家庭住址
  1329. String[] addressPlaces = addressPlace.split("/");
  1330. if (citys != null && citys.size() > 0) {
  1331. if (addressPlaces != null && addressPlaces.length >= 1) {
  1332. if (!addressPlaces[0].contains("省")) {
  1333. return CommonResult.fail("录取编号为" + assNum + "的家庭住址格式应该是 省/市/县区");
  1334. }
  1335. Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getDistrictZh().equals(addressPlaces[0])).findFirst();
  1336. if (oProvince != null && oProvince.isPresent()) {
  1337. studentData.setProvince(addressPlaces[0]);
  1338. studentData.setProvinceId(oProvince.get().getId());
  1339. } else {
  1340. return CommonResult.fail("录取编号为" + assNum + "的家庭住址格式应该是 省/市/县区");
  1341. }
  1342. }
  1343. if (addressPlaces != null && addressPlaces.length >= 2) {
  1344. Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getDistrictZh().equals(addressPlaces[1])).findFirst();
  1345. if (oProvince != null && oProvince.isPresent()) {
  1346. studentData.setCity(addressPlaces[1]);
  1347. studentData.setCityId(oProvince.get().getId());
  1348. } else {
  1349. return CommonResult.fail("录取编号为" + assNum + "的家庭住址格式应该是 省/市/县区");
  1350. }
  1351. }
  1352. if (addressPlaces != null && addressPlaces.length >= 3) {
  1353. Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getCityZh().equals(addressPlaces[1]) && addressPlaces[2].contains(e.getDistrictZh())).findFirst();
  1354. if (oProvince != null && oProvince.isPresent()) {
  1355. studentData.setDistrict(addressPlaces[2]);
  1356. studentData.setDistrictId(oProvince.get().getId());
  1357. } else {
  1358. return CommonResult.fail("录取编号为" + assNum + "的家庭住址格式应该是 省/市/县区");
  1359. }
  1360. }
  1361. }
  1362. //endregion
  1363. String addressDetail = dataFormatter.formatCellValue(row.getCell(17));//详细住址
  1364. studentData.setAddress(addressDetail);
  1365. String zipCode = dataFormatter.formatCellValue(row.getCell(18));//邮编
  1366. studentData.setZipCode(zipCode);
  1367. studentData.setIdenType(1);
  1368. studentData.setFillStatus("未填报");
  1369. result.add(studentData);
  1370. }
  1371. }
  1372. }
  1373. } catch (Exception e) {
  1374. return CommonResult.fail("请按模板格式导入数据");
  1375. }
  1376. return CommonResult.ok(result);
  1377. }
  1378. @Override
  1379. public CommonResult downloadStudentExcel() {
  1380. return CommonResult.ok("200", "操作成功", "https://chtech.ncjti.edu.cn/welcome/homeimage/学生信息管理.xlsx");
  1381. }
  1382. @Override
  1383. public void welcomeStudentExport(String userId, HttpServletResponse response, Integer collegeId, Integer majorId, Integer classstrId, String trafficMethod, String name) {
  1384. Workbook workbook = new XSSFWorkbook();
  1385. Sheet sheet = workbook.createSheet("学生信息");
  1386. WelcomeAccount wa = welcomeAccountService.getManageById(userId);
  1387. if (wa == null) {
  1388. System.out.println("当前账户已失效,无权限查看");
  1389. ExcelUtils.excelDownload(workbook, "学生信息.xlsx", response);
  1390. }
  1391. List<String> collegeIds = Arrays.asList(wa.getCollegeId().split(","));
  1392. if (collegeId != null && collegeId.intValue() > 0) {
  1393. if (!collegeIds.contains(String.valueOf(collegeId))) {
  1394. ExcelUtils.excelDownload(workbook, "学生信息.xlsx", response);
  1395. } else {
  1396. collegeIds = new ArrayList<>();
  1397. collegeIds.add(String.valueOf(collegeId));
  1398. }
  1399. }
  1400. List<StudentPageVo> result = welcomeStudentService.queryStudentList(collegeIds, majorId, classstrId, trafficMethod, name);
  1401. //导出
  1402. Row headerRow = sheet.createRow(0);
  1403. headerRow.createCell(0).setCellValue("序号");
  1404. headerRow.createCell(1).setCellValue("录取号");
  1405. headerRow.createCell(2).setCellValue("姓名");
  1406. headerRow.createCell(3).setCellValue("身份证号");
  1407. headerRow.createCell(4).setCellValue("院系");
  1408. headerRow.createCell(5).setCellValue("专业");
  1409. headerRow.createCell(6).setCellValue("班级");
  1410. headerRow.createCell(7).setCellValue("交通方式");
  1411. headerRow.createCell(8).setCellValue("到站地点");
  1412. headerRow.createCell(9).setCellValue("陪同人数");
  1413. headerRow.createCell(10).setCellValue("填报状态");
  1414. headerRow.createCell(11).setCellValue("应缴金额");
  1415. headerRow.createCell(12).setCellValue("实付金额");
  1416. headerRow.createCell(13).setCellValue("宿舍信息");
  1417. for (int i = 0; i < result.size(); i++) {
  1418. StudentPageVo studentData = result.get(i);
  1419. Row dataRow = sheet.createRow(i + 1);
  1420. dataRow.createCell(0).setCellValue(i + 1);
  1421. dataRow.createCell(1).setCellValue(studentData.getAdmissNum());
  1422. dataRow.createCell(2).setCellValue(studentData.getName());
  1423. dataRow.createCell(3).setCellValue(studentData.getCardId());
  1424. dataRow.createCell(4).setCellValue(studentData.getCollege());
  1425. dataRow.createCell(5).setCellValue(studentData.getMajor());
  1426. dataRow.createCell(6).setCellValue(studentData.getClassstr());
  1427. dataRow.createCell(7).setCellValue(studentData.getTrafficMethod());
  1428. dataRow.createCell(8).setCellValue(studentData.getArrive());
  1429. dataRow.createCell(9).setCellValue(studentData.getAccompanyNum());
  1430. dataRow.createCell(10).setCellValue(studentData.getFillStatus());
  1431. dataRow.createCell(11).setCellValue(String.valueOf(studentData.getAmountPayable()));
  1432. dataRow.createCell(12).setCellValue(String.valueOf(studentData.getPayAmount()));
  1433. dataRow.createCell(13).setCellValue(studentData.getDormitory());
  1434. }
  1435. // 将工作簿写入文件
  1436. ExcelUtils.excelDownload(workbook, "学生信息.xlsx", response);
  1437. }
  1438. @Override
  1439. public CommonResult studentOverview() {
  1440. // 录取总数
  1441. // LambdaQueryWrapper<WelcomeStudent> queryWrapper=new LambdaQueryWrapper<>();
  1442. // queryWrapper.eq(WelcomeStudent::getIdenType,1);
  1443. int enrollmentTotal = 6352;//welcomeStudentService.count(queryWrapper);
  1444. // 缴费人数
  1445. int payCount = welcomeStudentService.payCount();
  1446. // 已入住寝室数
  1447. LambdaQueryWrapper<WelcomeBed> wrapper = new LambdaQueryWrapper<>();
  1448. wrapper.eq(WelcomeBed::getIsCheck, 1)
  1449. .eq(WelcomeBed::getRetentionState, 1);
  1450. int checkInBedTotal = welcomeBedService.count(wrapper);
  1451. // 报到率
  1452. // BigDecimal total = new BigDecimal(enrollmentTotal);
  1453. // BigDecimal bedTotal = new BigDecimal(checkInBedTotal);
  1454. // BigDecimal bigDecimal = bedTotal.divide(total).setScale(4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));
  1455. Double result = ((double) checkInBedTotal / enrollmentTotal) * 100;
  1456. String registrationRate = String.format("%.2f", result);
  1457. LocalDateTime start = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0);
  1458. LocalDateTime end = start.plusDays(1);
  1459. DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  1460. String startTime = start.format(dateTimeFormatter1);
  1461. String endTime = end.format(dateTimeFormatter1);
  1462. Integer mVisitorTotal = welcomeVisitorService.countTotal(startTime, endTime, 1);
  1463. Integer hVisitorTotal = welcomeVisitorService.countTotal(startTime, endTime, 2);
  1464. List<WelcomeSetting> wss = welcomeSettingService.list(null);
  1465. // 墨轩湖总车辆数
  1466. Integer mCarTotal = wss != null && wss.size() > 0 ? (wss.get(0).getMxhCarNum() == null ? 0 : wss.get(0).getMxhCarNum()) : 0;
  1467. // 黄家湖总车辆数
  1468. Integer hCarTotal = wss != null && wss.size() > 0 ? (wss.get(0).getHjhCarNum() == null ? 0 : wss.get(0).getHjhCarNum()) : 0;
  1469. StudentOverviewVo vo = new StudentOverviewVo();
  1470. vo.setEnrollmentTotal(enrollmentTotal);
  1471. vo.setPayCount(payCount);
  1472. vo.setCheckInBedTotal(checkInBedTotal);
  1473. vo.setRegistrationRate(registrationRate);
  1474. vo.setHCarTotal(hCarTotal - hVisitorTotal);
  1475. vo.setHVisitorTotal(hVisitorTotal);
  1476. vo.setMCarTotal(mCarTotal - mVisitorTotal);
  1477. vo.setMVisitorTotal(mVisitorTotal);
  1478. return CommonResult.ok(vo);
  1479. }
  1480. @Override
  1481. public CommonResult studentRegister() {
  1482. // 获取总数
  1483. Integer count = welcomeStudentService.totalCount();
  1484. List<StudentRegisterVo> vos = welcomeStudentService.studentRegister();
  1485. StudentRegisterVo vo = new StudentRegisterVo();
  1486. vo.setCollegeName("报到总数");
  1487. vo.setCount(count);
  1488. vos.add(vo);
  1489. return CommonResult.ok(vos);
  1490. }
  1491. @Override
  1492. public CommonResult studentTraffic() {
  1493. List<StudentTrafficVo> vos = welcomeStudentService.studentTraffic();
  1494. return CommonResult.ok(vos);
  1495. }
  1496. @Override
  1497. public CommonResult studentSexRatio() {
  1498. Integer manCount = welcomeStudentService.genderCount("男");
  1499. Integer girlCount = welcomeStudentService.genderCount("女");
  1500. StudentSexRatioVo vo = new StudentSexRatioVo();
  1501. vo.setCollegeName("全部");
  1502. vo.setManCount(manCount);
  1503. vo.setGirlCount(girlCount);
  1504. List<StudentSexRatioVo> vos = welcomeStudentService.studentSexRatio();
  1505. vos.add(vo);
  1506. return CommonResult.ok(vos);
  1507. }
  1508. @Override
  1509. public CommonResult studentStay() {
  1510. ArrayList<StudentStayVo> vos = new ArrayList<>();
  1511. List<WelcomeSchool> list = welcomeSchoolService.list(new QueryWrapper<>());
  1512. for (WelcomeSchool welcomeSchool : list) {
  1513. Integer schoolId = welcomeSchool.getId();
  1514. List<WelcomeBuild> builds = welcomeBuildService.getBuild(schoolId);
  1515. for (WelcomeBuild build : builds) {
  1516. Integer buildId = build.getId();
  1517. StudentStayVo vo = welcomeDormitoryService.getTotalCount(buildId);
  1518. vo.setSchoolName(welcomeSchool.getSchool());
  1519. vo.setBuildName(build.getBuild());
  1520. vos.add(vo);
  1521. }
  1522. }
  1523. return CommonResult.ok(vos);
  1524. }
  1525. @Override
  1526. public CommonResult queryStudentByToken(String userId) {
  1527. WelcomeStudent student = welcomeStudentService.getManageById(Integer.valueOf(userId));
  1528. if (student == null) {
  1529. return CommonResult.fail("558", "学生信息已失效,查询失败");
  1530. }
  1531. //家庭成员
  1532. List<FamilyVo> fvs = new ArrayList<>();
  1533. List<WelcomeFamily> familys = welcomeFamilyService.getManageByCardId(student.getCardId());
  1534. if (familys != null && familys.size() > 0) {
  1535. for (WelcomeFamily wf : familys) {
  1536. FamilyVo fv = new FamilyVo();
  1537. fv.setId(wf.getId());
  1538. fv.setFamilyShip(wf.getFamilyShip());
  1539. fv.setName(wf.getName());
  1540. fv.setPhone(wf.getPhone());
  1541. fv.setWorkUnit(wf.getWorkUnit());
  1542. fvs.add(fv);
  1543. }
  1544. }
  1545. student.setFvs(fvs);
  1546. //陪同人员
  1547. List<AccompanyVo> avs = new ArrayList<>();
  1548. List<WelcomeAccompany> accompanys = welcomeAccompanyService.getManageByCardId(student.getCardId());
  1549. if (accompanys != null && accompanys.size() > 0) {
  1550. for (WelcomeAccompany ac : accompanys) {
  1551. AccompanyVo av = new AccompanyVo();
  1552. av.setId(ac.getId());
  1553. av.setName(ac.getName());
  1554. av.setPhone(ac.getPhone());
  1555. avs.add(av);
  1556. }
  1557. }
  1558. student.setAvs(avs);
  1559. //时间段
  1560. List<ArriveTimeVo> atvs = new ArrayList<>();
  1561. List<WelcomeArriveSetting> wass = welcomeArriveSettingService.queryCheckDatas();
  1562. if (wass != null && wass.size() > 0) {
  1563. for (WelcomeArriveSetting was : wass) {
  1564. ArriveTimeVo atv = new ArriveTimeVo();
  1565. atv.setId(was.getId());
  1566. atv.setStartTime(was.getStartTime());
  1567. atv.setEndTime(was.getEndTime());
  1568. atv.setTimeStr(was.getStartTime() + "-" + was.getEndTime());
  1569. atv.setIsCheck((student.getArriveTimeId() != null && was.getId().equals(student.getArriveTimeId())) ? 1 : 0);
  1570. atvs.add(atv);
  1571. }
  1572. }
  1573. student.setAtvs(atvs);
  1574. if (!(student.getIsPay() != null && student.getIsPay().intValue() == 1)) {
  1575. List<JsonPayVo> payInfos = WelcomePayController.queryStudentPayInfo(student.getAdmissNum(), TimeExchange.getYear());
  1576. BigDecimal payAmount = new BigDecimal(BigInteger.ZERO);//实缴金额
  1577. BigDecimal yjPayAmount = new BigDecimal(BigInteger.ZERO);//应缴金额
  1578. for (JsonPayVo pi : payInfos) {
  1579. payAmount = payAmount.add(pi.getSJJE());
  1580. yjPayAmount = yjPayAmount.add(pi.getYJJE());
  1581. }
  1582. student.setPayAmount(payAmount);
  1583. student.setAmountPayable(yjPayAmount);
  1584. if (payInfos != null && payInfos.size() > 0) {
  1585. List<WelcomePaySetting> paySettings = welcomePaySettingService.queryPaySettings(student.getSchool());
  1586. if (paySettings != null && paySettings.size() > 0) {
  1587. for (WelcomePaySetting pay : paySettings) {
  1588. BigDecimal money = pay.getPayAmount();
  1589. if (pay.getMethod().equals("全部")) {
  1590. BigDecimal totalSj = new BigDecimal(BigInteger.ZERO);
  1591. for (JsonPayVo jpv : payInfos) {
  1592. totalSj = totalSj.add(jpv.getSJJE());
  1593. }
  1594. if (totalSj.compareTo(money) >= 0) {
  1595. student.setIsPay(1);
  1596. }
  1597. }
  1598. Optional<JsonPayVo> ojpv = payInfos.stream().filter(e -> e.getSFXMMC().equals(pay.getMethod())).findFirst();
  1599. if (ojpv != null && ojpv.isPresent()) {
  1600. if (ojpv.get().getSJJE().compareTo(money) >= 0) {
  1601. student.setIsPay(1);
  1602. }
  1603. }
  1604. }
  1605. } else {
  1606. student.setIsPay(0);
  1607. }
  1608. } else {
  1609. student.setIsPay(0);
  1610. }
  1611. if (payInfos != null && payInfos.size() > 0) {
  1612. int update = welcomeStudentService.updateWelcomeStudent(student);
  1613. if (update < 0) {
  1614. logger.error("获取支付信息导致学校信息查询失败");
  1615. return CommonResult.fail("查询失败");
  1616. }
  1617. }
  1618. }
  1619. if(student.getIsPay() == null){
  1620. student.setIsPay(0);
  1621. }
  1622. long expired = 1000 * 60 * 60 * 24 * 365;
  1623. TokenDateVo token = JWTUtil.getToken(student.getCardId(), student.getId(), expired);
  1624. student.setToken(token.getToken());
  1625. return CommonResult.ok(student);
  1626. }
  1627. @Override
  1628. public CommonResult queryStudentInfo(String admissNum) {
  1629. WelcomeStudent ws = welcomeStudentService.getDataByNum(admissNum);
  1630. if (ws == null) {
  1631. return CommonResult.fail("558", "当前学生信息已失效,查询失败");
  1632. }
  1633. //家庭成员
  1634. List<FamilyVo> fvs = new ArrayList<>();
  1635. List<WelcomeFamily> familys = welcomeFamilyService.getManageByCardId(ws.getCardId());
  1636. if (familys != null && familys.size() > 0) {
  1637. for (WelcomeFamily wf : familys) {
  1638. FamilyVo fv = new FamilyVo();
  1639. fv.setId(wf.getId());
  1640. fv.setFamilyShip(wf.getFamilyShip());
  1641. fv.setName(wf.getName());
  1642. fv.setPhone(wf.getPhone());
  1643. fv.setWorkUnit(wf.getWorkUnit());
  1644. fvs.add(fv);
  1645. }
  1646. }
  1647. ws.setFvs(fvs);
  1648. //陪同人员
  1649. List<AccompanyVo> avs = new ArrayList<>();
  1650. List<WelcomeAccompany> accompanys = welcomeAccompanyService.getManageByCardId(ws.getCardId());
  1651. if (accompanys != null && accompanys.size() > 0) {
  1652. for (WelcomeAccompany ac : accompanys) {
  1653. AccompanyVo av = new AccompanyVo();
  1654. av.setId(ac.getId());
  1655. av.setName(ac.getName());
  1656. av.setPhone(ac.getPhone());
  1657. avs.add(av);
  1658. }
  1659. }
  1660. ws.setAvs(avs);
  1661. //时间段
  1662. List<ArriveTimeVo> atvs = new ArrayList<>();
  1663. List<WelcomeArriveSetting> wass = welcomeArriveSettingService.queryCheckDatas();
  1664. if (wass != null && wass.size() > 0) {
  1665. for (WelcomeArriveSetting was : wass) {
  1666. ArriveTimeVo atv = new ArriveTimeVo();
  1667. atv.setId(was.getId());
  1668. atv.setStartTime(was.getStartTime());
  1669. atv.setEndTime(was.getEndTime());
  1670. atv.setTimeStr(was.getStartTime() + "-" + was.getEndTime());
  1671. atv.setIsCheck((ws.getArriveTimeId() != null && was.getId().equals(ws.getArriveTimeId())) ? 1 : 0);
  1672. atvs.add(atv);
  1673. }
  1674. }
  1675. ws.setAtvs(atvs);
  1676. List<PayDetailVO> pdvs = new ArrayList<>();
  1677. System.out.println("进支付比较");
  1678. List<JsonPayVo> payInfos = WelcomePayController.queryStudentPayInfo(ws.getAdmissNum(), TimeExchange.getYear());
  1679. BigDecimal payAmount = new BigDecimal(BigInteger.ZERO);//实缴金额
  1680. BigDecimal yjPayAmount = new BigDecimal(BigInteger.ZERO);//应缴金额
  1681. for (JsonPayVo pi : payInfos) {
  1682. payAmount = payAmount.add(pi.getSJJE());
  1683. yjPayAmount = yjPayAmount.add(pi.getYJJE());
  1684. PayDetailVO pdv = new PayDetailVO();
  1685. pdv.setPayName(pi.getSFXMMC());
  1686. pdv.setYJJE(pi.getYJJE());
  1687. pdv.setSJJE(pi.getSJJE());
  1688. pdvs.add(pdv);
  1689. }
  1690. ws.setPayAmount(payAmount);
  1691. ws.setAmountPayable(yjPayAmount);
  1692. System.out.println("进支付比较1" + JSON.toJSON(payInfos));
  1693. if (payInfos != null && payInfos.size() > 0) {
  1694. System.out.println("进支付比较2");
  1695. List<WelcomePaySetting> paySettings = welcomePaySettingService.queryPaySettings(ws.getSchool());
  1696. System.out.println("进支付比较3" + JSON.toJSON(paySettings));
  1697. if (paySettings != null && paySettings.size() > 0) {
  1698. System.out.println("进支付比较4");
  1699. for (WelcomePaySetting pay : paySettings) {
  1700. System.out.println("进支付比较5");
  1701. BigDecimal money = pay.getPayAmount();
  1702. if (pay.getMethod().equals("全部")) {
  1703. BigDecimal totalSj = new BigDecimal(BigInteger.ZERO);
  1704. for (JsonPayVo jpv : payInfos) {
  1705. totalSj = totalSj.add(jpv.getSJJE());
  1706. }
  1707. if (totalSj.compareTo(money) >= 0) {
  1708. ws.setIsPay(1);
  1709. }
  1710. }
  1711. Optional<JsonPayVo> ojpv = payInfos.stream().filter(e -> e.getSFXMMC().equals(pay.getMethod())).findFirst();
  1712. if (ojpv != null && ojpv.isPresent()) {
  1713. if (ojpv.get().getSJJE().compareTo(money) >= 0) {
  1714. ws.setIsPay(1);
  1715. }
  1716. }
  1717. }
  1718. } else {
  1719. ws.setIsPay(0);
  1720. }
  1721. } else {
  1722. ws.setIsPay(0);
  1723. }
  1724. if(ws.getIsPay() == null){
  1725. ws.setIsPay(0);
  1726. }
  1727. if (!(ws.getIsPay() != null && ws.getIsPay().intValue() == 1)) {
  1728. int updateResult = welcomeStudentService.updateWelcomeStudent(ws);
  1729. if (updateResult < 0) {
  1730. return CommonResult.fail("查询支付信息失败");
  1731. }
  1732. }
  1733. PayInfoVO result = new PayInfoVO();
  1734. result.setId(ws.getId());
  1735. result.setName(ws.getName());
  1736. result.setAdmissNum(ws.getAdmissNum());
  1737. result.setIsPay(ws.getIsPay());
  1738. result.setPays(pdvs);
  1739. return CommonResult.ok(result);
  1740. }
  1741. }