WelcomeStudentController.java 83 KB

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