WelcomeStudentController.java 91 KB

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