| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482 |
- package com.template.controller;
- import com.alibaba.fastjson.JSON;
- import com.auth0.jwt.interfaces.Claim;
- import com.baomidou.mybatisplus.core.conditions.Wrapper;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.extension.api.R;
- import com.template.annotation.PassToken;
- import com.template.api.WelcomeStudentControllerAPI;
- import com.template.common.utils.ExcelUtils;
- import com.template.common.utils.JWTUtil;
- import com.template.common.utils.paramUtils;
- import com.template.model.enumModel.eFileType;
- import com.template.model.enumModel.eProjectType;
- import com.template.model.pojo.*;
- import com.template.model.request.*;
- import com.template.model.result.CommonResult;
- import com.template.model.result.PageUtils;
- import com.template.model.vo.*;
- import com.template.services.*;
- import io.swagger.annotations.ApiModelProperty;
- import org.apache.poi.hssf.usermodel.HSSFRow;
- import org.apache.poi.hssf.usermodel.HSSFSheet;
- import org.apache.poi.hssf.usermodel.HSSFWorkbook;
- import org.apache.poi.ss.usermodel.DataFormatter;
- import org.apache.poi.ss.usermodel.Row;
- import org.apache.poi.ss.usermodel.Sheet;
- import org.apache.poi.ss.usermodel.Workbook;
- import org.apache.poi.xssf.usermodel.XSSFRow;
- import org.apache.poi.xssf.usermodel.XSSFSheet;
- import org.apache.poi.xssf.usermodel.XSSFWorkbook;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.transaction.annotation.Transactional;
- import org.springframework.util.StringUtils;
- import org.springframework.validation.BindingResult;
- import org.springframework.web.bind.annotation.RestController;
- import org.springframework.web.multipart.MultipartFile;
- import javax.servlet.http.HttpServletResponse;
- import java.io.IOException;
- import java.io.InputStream;
- import java.text.ParseException;
- import java.time.LocalDateTime;
- import java.time.format.DateTimeFormatter;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * <p>
- * 前端控制器
- * </p>
- *
- * @author ceshi
- * @since 2025-06-13
- */
- @RestController
- public class WelcomeStudentController implements WelcomeStudentControllerAPI {
- @Autowired
- private WelcomeStudentService welcomeStudentService;
- @Autowired
- private WelcomeFamilyService welcomeFamilyService;
- @Autowired
- private WelcomeAccompanyService welcomeAccompanyService;
- @Autowired
- private WelcomeBedService welcomeBedService;
- @Autowired
- private WelcomeSettingService welcomeSettingService;
- @Autowired
- private WelcomeArriveSettingService welcomeArriveSettingService;
- @Autowired
- private WelcomeOrgService welcomeOrgService;
- @Autowired
- private WelcomeCityService welcomeCityService;
- @Autowired
- WelcomeSchoolService welcomeSchoolService;
- @Autowired
- WelcomeBuildService welcomeBuildService;
- @Autowired
- WelcomeDormitoryService welcomeDormitoryService;
- @Autowired
- WelcomeVisitorService welcomeVisitorService;
- private static Logger logger = LoggerFactory.getLogger(WelcomeStudentController.class);
- @Override
- @Transactional(rollbackFor = {Exception.class})
- public CommonResult insertStudentInfo(InsertStudentRequest isr, BindingResult bindingResult) throws Exception {
- if (bindingResult.hasErrors()) {
- String st = paramUtils.getParamError(bindingResult);
- return CommonResult.fail(st);
- }
- int existCount = welcomeStudentService.existStudentInfo(isr.getAdmissNum(), isr.getCardId());
- if (existCount > 0) {
- return CommonResult.fail("当前录取号或身份证号已存在!");
- }
- //region 学生信息
- WelcomeStudent ws = new WelcomeStudent();
- ws.setAdmissNum(isr.getAdmissNum());
- ws.setName(isr.getName());
- ws.setPicture(isr.getPicture());
- ws.setCardId(isr.getCardId());
- ws.setSex(isr.getSex());
- ws.setBirthday(isr.getBirthday());
- ws.setSchool(isr.getSchool());
- ws.setSchoolId(isr.getSchoolId());
- ws.setCollege(isr.getCollege());
- ws.setMajor(isr.getMajor());
- ws.setClassstr(isr.getClassstr());
- ws.setCollegeId(isr.getCollegeId());
- ws.setMajorId(isr.getMajorId());
- ws.setClassstrId(isr.getClassstrId());
- ws.setExamNum(isr.getExamNum());
- ws.setEduSystem(isr.getEduSystem());
- ws.setGraduationSchool(isr.getGraduationSchool());
- ws.setBatchValue(isr.getBatchValue());
- ws.setPoliticalStatu(isr.getPoliticalStatu());
- ws.setNationality(isr.getNationality());
- ws.setPhone(isr.getPhone());
- ws.setOprovince(isr.getOprovince());
- ws.setOcity(isr.getOcity());
- ws.setOdistrict(isr.getOdistrict());
- ws.setOprovinceId(isr.getOprovinceId());
- ws.setOcityId(isr.getOcityId());
- ws.setOdistrictId(isr.getOdistrictId());
- ws.setProvinceId(isr.getProvinceId());
- ws.setCityId(isr.getCityId());
- ws.setDistrictId(isr.getDistrictId());
- ws.setProvince(isr.getProvince());
- ws.setCity(isr.getCity());
- ws.setDistrict(isr.getDistrict());
- ws.setAddress(isr.getAddress());
- ws.setTrafficMethod(isr.getTrafficMethod());
- ws.setArrive(isr.getArrive());
- ws.setArrvieDate(isr.getArrvieDate());
- ws.setArriveTime(isr.getArriveTime());
- ws.setArriveTimeId(isr.getArriveTimeId());
- ws.setZipCode(isr.getZipCode());
- ws.setRegisterOntime(isr.getRegisterOntime());
- ws.setIdenType(1);
- //ws.setAmountPayable(isr.getAmountPayable());
- //ws.setPayAmount(isr.getPayAmount());
- //ws.setIsDrive(isr.getIsDrive());
- //ws.setCarNumber(isr.getCarNumber());
- //endregion
- //region 家庭成员数据
- List<WelcomeFamily> wfs = new ArrayList<>();
- if (isr.getFvs() != null && isr.getFvs().size() > 0) {
- for (InsertFamilyRequest family : isr.getFvs()) {
- if(!(StringUtils.hasText(family.getFamilyShip()) && StringUtils.hasText(family.getName())
- && StringUtils.hasText(family.getWorkUnit()) && StringUtils.hasText(family.getPhone()))){
- return CommonResult.fail("家庭成员信息不能为空!");
- }
- WelcomeFamily wf = new WelcomeFamily();
- wf.setStudentCard(ws.getCardId());
- wf.setFamilyShip(family.getFamilyShip());
- wf.setName(family.getName());
- wf.setWorkUnit(family.getWorkUnit());
- wf.setPhone(family.getPhone());
- wfs.add(wf);
- }
- }
- //endregion
- //region 陪同人员数据
- List<WelcomeAccompany> was = new ArrayList<>();
- if (isr.getAvs() != null && isr.getAvs().size() > 0) {
- for (InsertAccompanyRequest accompany : isr.getAvs()) {
- if(!(StringUtils.hasText(accompany.getName()) && StringUtils.hasText(accompany.getPhone()))){
- return CommonResult.fail("陪同人员信息不能为空!");
- }
- WelcomeAccompany wa = new WelcomeAccompany();
- wa.setStudentCard(ws.getCardId());
- wa.setName(accompany.getName());
- wa.setPhone(accompany.getPhone());
- was.add(wa);
- }
- }
- //endregion
- //region 宿舍信息
- WelcomeBed bedData = welcomeBedService.queryBedData(isr.getSchool(), isr.getBuildId(), isr.getDormitoryId(), Integer.valueOf(isr.getBed()));
- if (bedData != null) {
- bedData.setStudentCard(isr.getCardId());
- bedData.setCollege(isr.getCollege());
- bedData.setCollegeId(isr.getCollegeId());
- bedData.setMajor(isr.getMajor());
- bedData.setMajorId(isr.getMajorId());
- bedData.setClassstr(isr.getClassstr());
- bedData.setClassstrId(isr.getClassstrId());
- bedData.setIsCheck(1);
- bedData.setCardNum(isr.getAdmissNum());
- bedData.setName(isr.getName());
- }
- //endregion
- try {
- int studentId = welcomeStudentService.insertWelcomeStudent(ws);
- if (studentId <= 0) {
- logger.error("添加学生失败,参数:" + JSON.toJSON(isr));
- throw new Exception("添加失败!");
- }
- if (wfs != null && wfs.size() > 0) {
- boolean insertBatch = welcomeFamilyService.saveBatch(wfs);
- if (!insertBatch) {
- logger.error("添加家庭成员失败,参数:" + JSON.toJSON(wfs));
- throw new Exception("添加失败!");
- }
- }
- if (was != null && was.size() > 0) {
- boolean insertBatch = welcomeAccompanyService.saveBatch(was);
- if (!insertBatch) {
- logger.error("添加陪同人员失败,参数:" + JSON.toJSON(was));
- throw new Exception("添加失败!");
- }
- }
- int insertStudentDormitory = welcomeBedService.updateWelcomeBed(bedData);
- if (insertStudentDormitory <= 0) {
- logger.error("添加学生床位信息失败,参数:" + JSON.toJSON(bedData));
- throw new Exception("添加失败!");
- }
- } catch (Exception e) {
- logger.error(e.getMessage());
- throw new Exception("添加失败!");
- }
- return CommonResult.ok("添加成功");
- }
- @Override
- public CommonResult updateStudentInfo(updateStudentRequest usr, BindingResult bindingResult) throws Exception {
- if (bindingResult.hasErrors()) {
- String st = paramUtils.getParamError(bindingResult);
- return CommonResult.fail(st);
- }
- WelcomeStudent student = welcomeStudentService.getManageById(usr.getId());
- if (student == null) {
- return CommonResult.fail("学生数据已失效,编辑失败!");
- }
- //region 学生信息
- student.setAdmissNum(usr.getAdmissNum());
- student.setName(usr.getName());
- student.setPicture(usr.getPicture());
- //student.setCardId(usr.getCardId());
- student.setSex(usr.getSex());
- student.setBirthday(usr.getBirthday());
- student.setSchool(usr.getSchool());
- student.setSchoolId(usr.getSchoolId());
- student.setCollege(usr.getCollege());
- student.setMajor(usr.getMajor());
- student.setClassstr(usr.getClassstr());
- student.setCollegeId(usr.getCollegeId());
- student.setMajorId(usr.getMajorId());
- student.setClassstrId(usr.getClassstrId());
- student.setExamNum(usr.getExamNum());
- student.setEduSystem(usr.getEduSystem());
- student.setGraduationSchool(usr.getGraduationSchool());
- student.setBatchValue(usr.getBatchValue());
- student.setPoliticalStatu(usr.getPoliticalStatu());
- student.setNationality(usr.getNationality());
- student.setPhone(usr.getPhone());
- student.setOprovince(usr.getOprovince());
- student.setOcity(usr.getOcity());
- student.setOdistrict(usr.getOdistrict());
- student.setOprovinceId(usr.getOprovinceId());
- student.setOcityId(usr.getOcityId());
- student.setOdistrictId(usr.getOdistrictId());
- student.setProvinceId(usr.getProvinceId());
- student.setCityId(usr.getCityId());
- student.setDistrictId(usr.getDistrictId());
- student.setProvince(usr.getProvince());
- student.setCity(usr.getCity());
- student.setDistrict(usr.getDistrict());
- student.setAddress(usr.getAddress());
- student.setTrafficMethod(usr.getTrafficMethod());
- student.setArrive(usr.getArrive());
- student.setArrvieDate(usr.getArrvieDate());
- student.setArriveTime(usr.getArriveTime());
- student.setArriveTimeId(usr.getArriveTimeId());
- student.setZipCode(usr.getZipCode());
- student.setRegisterOntime(usr.getRegisterOntime());
- student.setIdenType(1);
- //ws.setAmountPayable(isr.getAmountPayable());
- //ws.setPayAmount(isr.getPayAmount());
- //ws.setIsDrive(isr.getIsDrive());
- //ws.setCarNumber(isr.getCarNumber());
- //endregion
- //region 家庭成员数据
- List<WelcomeFamily> wfs = new ArrayList<>();
- if (usr.getFvs() != null && usr.getFvs().size() > 0) {
- for (InsertFamilyRequest family : usr.getFvs()) {
- if(!(StringUtils.hasText(family.getFamilyShip()) && StringUtils.hasText(family.getName())
- && StringUtils.hasText(family.getWorkUnit()) && StringUtils.hasText(family.getPhone()))){
- return CommonResult.fail("家庭成员信息不能为空!");
- }
- WelcomeFamily wf = new WelcomeFamily();
- wf.setStudentCard(student.getCardId());
- wf.setFamilyShip(family.getFamilyShip());
- wf.setName(family.getName());
- wf.setWorkUnit(family.getWorkUnit());
- wf.setPhone(family.getPhone());
- wfs.add(wf);
- }
- }
- //endregion
- //region 陪同人员数据
- List<WelcomeAccompany> was = new ArrayList<>();
- if (usr.getAvs() != null && usr.getAvs().size() > 0) {
- for (InsertAccompanyRequest accompany : usr.getAvs()) {
- if(!(StringUtils.hasText(accompany.getName()) && StringUtils.hasText(accompany.getPhone()))){
- return CommonResult.fail("陪同人员信息不能为空!");
- }
- WelcomeAccompany wa = new WelcomeAccompany();
- wa.setStudentCard(student.getCardId());
- wa.setName(accompany.getName());
- wa.setPhone(accompany.getPhone());
- was.add(wa);
- }
- }
- //endregion
- //region 宿舍信息
- List<WelcomeBed> bedDatas = new ArrayList<>();
- WelcomeBed bedData = welcomeBedService.queryBedData(usr.getSchool(), usr.getBuildId(), usr.getDormitoryId(), Integer.valueOf(usr.getBed()));
- if (bedData != null) {//新床位
- if (!StringUtils.hasText(bedData.getStudentCard())) {
- bedData.setStudentCard(student.getCardId());
- bedData.setCollege(student.getCollege());
- bedData.setCollegeId(student.getCollegeId());
- bedData.setMajor(student.getMajor());
- bedData.setMajorId(student.getMajorId());
- bedData.setClassstr(student.getClassstr());
- bedData.setClassstrId(student.getClassstrId());
- bedData.setIsCheck(1);
- bedData.setCardNum(student.getAdmissNum());
- bedData.setName(student.getName());
- //把旧床位清空
- WelcomeBed obedData = welcomeBedService.getBedByCardId(student.getCardId());
- if (obedData == null) {
- obedData.setStudentCard(null);
- obedData.setCollege(null);
- obedData.setCollegeId(null);
- obedData.setMajor(null);
- obedData.setMajorId(null);
- obedData.setClassstr(null);
- obedData.setClassstrId(null);
- obedData.setIsCheck(0);
- obedData.setCardNum(null);
- obedData.setName(null);
- bedDatas.add(obedData);
- }
- } else {
- bedData.setStudentCard(student.getCardId());
- bedData.setCollege(student.getCollege());
- bedData.setCollegeId(student.getCollegeId());
- bedData.setMajor(student.getMajor());
- bedData.setMajorId(student.getMajorId());
- bedData.setClassstr(student.getClassstr());
- bedData.setClassstrId(student.getClassstrId());
- bedData.setIsCheck(1);
- bedData.setCardNum(student.getAdmissNum());
- bedData.setName(student.getName());
- }
- bedDatas.add(bedData);
- }
- //endregion
- try {
- int studentId = welcomeStudentService.updateWelcomeStudent(student);
- if (studentId <= 0) {
- logger.error("编辑学生失败,参数:" + JSON.toJSON(usr));
- throw new Exception("编辑失败!");
- }
- int deleteF = welcomeFamilyService.deleteWelcomeFamilyByCard(student.getCardId());
- if (wfs != null && wfs.size() > 0) {
- boolean insertBatch = welcomeFamilyService.saveBatch(wfs);
- if (!insertBatch) {
- logger.error("编辑家庭成员失败,参数:" + JSON.toJSON(wfs));
- throw new Exception("编辑失败!");
- }
- }
- int deleteA = welcomeAccompanyService.deleteWelcomeAccompanyByCard(student.getCardId());
- if (was != null && was.size() > 0) {
- boolean insertBatch = welcomeAccompanyService.saveBatch(was);
- if (!insertBatch) {
- logger.error("编辑陪同人员失败,参数:" + JSON.toJSON(was));
- throw new Exception("编辑失败!");
- }
- }
- boolean updateBatch = welcomeBedService.updateBatchById(bedDatas);
- if (!updateBatch) {
- logger.error("添加宿舍信息失败,参数:" + JSON.toJSON(bedDatas));
- throw new Exception("添加失败!");
- }
- } catch (Exception e) {
- logger.error(e.getMessage());
- throw new Exception("编辑失败!");
- }
- return CommonResult.ok("编辑成功");
- }
- @Override
- public CommonResult queryPageStudents(int currentPage, int pageCount, Integer collegeId, Integer majorId, Integer classstrId, String trafficMethod, String name) {
- PageUtils<StudentPageVo> result = welcomeStudentService.queryStudentPageList(currentPage, pageCount, collegeId, majorId, classstrId, trafficMethod, name);
- return CommonResult.ok(result);
- }
- @Override
- public CommonResult queryStudentDetail(int id) {
- StudentDetailVo result = new StudentDetailVo();
- WelcomeStudent ws = welcomeStudentService.getManageById(id);
- if (ws == null) {
- return CommonResult.ok("学生信息已失效,查看失败!");
- }
- //家庭成员
- List<FamilyVo> fvs = new ArrayList<>();
- List<WelcomeFamily> familys = welcomeFamilyService.getManageByCardId(ws.getCardId());
- if (familys != null && familys.size() > 0) {
- for (WelcomeFamily wf : familys) {
- FamilyVo fv = new FamilyVo();
- fv.setId(wf.getId());
- fv.setFamilyShip(wf.getFamilyShip());
- fv.setName(wf.getName());
- fv.setPhone(wf.getPhone());
- fv.setWorkUnit(wf.getWorkUnit());
- fvs.add(fv);
- }
- }
- result.setFvs(fvs);
- //陪同人员
- List<AccompanyVo> avs = new ArrayList<>();
- List<WelcomeAccompany> accompanys = welcomeAccompanyService.getManageByCardId(ws.getCardId());
- if (accompanys != null && accompanys.size() > 0) {
- for (WelcomeAccompany ac : accompanys) {
- AccompanyVo av = new AccompanyVo();
- av.setId(ac.getId());
- av.setName(ac.getName());
- av.setPhone(ac.getPhone());
- avs.add(av);
- }
- }
- result.setAvs(avs);
- //宿舍信息
- WelcomeBed wsd = welcomeBedService.getBedByCardId(ws.getCardId());
- if (wsd != null) {
- result.setBuild(wsd.getBuild());
- result.setBuildId(wsd.getBuildId());
- result.setDormitory(wsd.getDormitory());//寝室号
- result.setDormitoryId(wsd.getDormitoryId());//寝室号
- result.setBed(String.valueOf(wsd.getNumber()));//床位号
- result.setBedId(wsd.getId());//床位号
- }
- //时间段
- List<ArriveTimeVo> atvs = new ArrayList<>();
- List<WelcomeArriveSetting> wass = welcomeArriveSettingService.queryCheckDatas();
- if (wass != null && wass.size() > 0) {
- for (WelcomeArriveSetting was : wass) {
- ArriveTimeVo atv = new ArriveTimeVo();
- atv.setId(was.getId());
- atv.setStartTime(was.getStartTime());
- atv.setEndTime(was.getEndTime());
- atv.setTimeStr(was.getStartTime() + "-" + was.getEndTime());
- atv.setIsCheck((ws.getArriveTimeId() != null && was.getId().equals(ws.getArriveTimeId())) ? 1 : 0);
- atvs.add(atv);
- }
- }
- result.setAtvs(atvs);
- result.setId(ws.getId());
- result.setSchool(ws.getSchool());
- result.setSchoolId(ws.getSchoolId());
- result.setAdmissNum(ws.getAdmissNum());
- result.setName(ws.getName());
- result.setPicture(ws.getPicture());
- result.setCardId(ws.getCardId());
- result.setSex(ws.getSex());
- result.setBirthday(ws.getBirthday());
- result.setCollege(ws.getCollege());
- result.setMajor(ws.getMajor());
- result.setClassstr(ws.getClassstr());
- result.setCollegeId(ws.getCollegeId());
- result.setMajorId(ws.getMajorId());
- result.setClassstrId(ws.getClassstrId());
- result.setExamNum(ws.getExamNum());
- result.setEduSystem(ws.getEduSystem());
- result.setGraduationSchool(ws.getGraduationSchool());
- result.setBatchValue(ws.getBatchValue());
- result.setPoliticalStatu(ws.getPoliticalStatu());
- result.setNationality(ws.getNationality());
- result.setPhone(ws.getPhone());
- result.setOprovinceId(ws.getOprovinceId());
- result.setOprovince(ws.getOprovince());
- result.setOcityId(ws.getOcityId());
- result.setOcity(ws.getOcity());
- result.setOdistrictId(ws.getOdistrictId());
- result.setOdistrict(ws.getOdistrict());
- result.setProvinceId(ws.getProvinceId());
- result.setProvince(ws.getProvince());
- result.setCityId(ws.getCityId());
- result.setCity(ws.getCity());
- result.setDistrictId(ws.getDistrictId());
- result.setDistrict(ws.getDistrict());
- result.setAddress(ws.getAddress());
- result.setRegisterOntime(ws.getRegisterOntime());
- result.setZipCode(ws.getZipCode());
- result.setTrafficMethod(ws.getTrafficMethod());
- result.setArrive(ws.getArrive());
- result.setArrvieDate(ws.getArrvieDate());
- result.setArriveTime(ws.getArriveTime());
- result.setArriveTimeId(ws.getArriveTimeId());
- result.setAmountPayable(ws.getAmountPayable());
- result.setPayAmount(ws.getPayAmount());
- result.setIsDrive(ws.getIsDrive());
- result.setCarNumber(ws.getCarNumber());
- return CommonResult.ok(result);
- }
- @Override
- @Transactional(rollbackFor = {Exception.class})
- public CommonResult infoCollection(InfoCollectionRequest icr, BindingResult bindingResult) throws Exception {
- if (bindingResult.hasErrors()) {
- String st = paramUtils.getParamError(bindingResult);
- return CommonResult.fail(st);
- }
- WelcomeStudent ws = welcomeStudentService.getDataByIdcard(icr.getCardId());
- if (ws == null) {
- ws = new WelcomeStudent();
- }
- ws.setSchool(icr.getSchool());
- ws.setAdmissNum(icr.getAdmissNum());
- ws.setName(icr.getName());
- ws.setPicture(icr.getPicture());
- ws.setCardId(icr.getCardId());
- ws.setSex(icr.getSex());
- ws.setBirthday(icr.getBirthday());
- ws.setCollegeId(icr.getCollegeId());
- ws.setMajorId(icr.getMajorId());
- ws.setClassstrId(icr.getClassstrId());
- ws.setExamNum(icr.getExamNum());
- ws.setEduSystem(icr.getEduSystem());
- ws.setGraduationSchool(icr.getGraduationSchool());
- ws.setBatchValue(icr.getBatchValue());
- ws.setPoliticalStatu(icr.getPoliticalStatu());
- ws.setNationality(icr.getNationality());
- ws.setPhone(icr.getPhone());
- ws.setOprovinceId(icr.getOprovinceId());
- ws.setOprovince(icr.getOprovince());
- ws.setOcityId(icr.getOcityId());
- ws.setOcity(icr.getOcity());
- ws.setOdistrictId(icr.getOdistrictId());
- ws.setOdistrict(icr.getOdistrict());
- ws.setProvinceId(icr.getProvinceId());
- ws.setProvince(icr.getProvince());
- ws.setCityId(icr.getCityId());
- ws.setCity(icr.getCity());
- ws.setDistrictId(icr.getDistrictId());
- ws.setDistrict(icr.getDistrict());
- ws.setAddress(icr.getAddress());
- ws.setRegisterOntime(icr.getRegisterOntime());
- ws.setZipCode(icr.getZipCode());
- ws.setTrafficMethod(icr.getTrafficMethod());
- ws.setArrive(icr.getArrive());
- ws.setArrvieDate(icr.getArrvieDate());
- ws.setArriveTimeId(icr.getArriveTimeId());
- ws.setFillStatus("已填报");
- //家庭成员
- List<WelcomeFamily> wfs = new ArrayList<>();
- if (icr.getFvs() != null && icr.getFvs().size() > 0) {
- for (FamilyVo fv : icr.getFvs()) {
- if(!(StringUtils.hasText(fv.getName()) && StringUtils.hasText(fv.getPhone()) && StringUtils.hasText(fv.getWorkUnit()) && StringUtils.hasText(fv.getFamilyShip()))){
- return CommonResult.fail("家庭成员信息不能为空!");
- }
- WelcomeFamily wf = new WelcomeFamily();
- wf.setName(fv.getName());
- wf.setPhone(fv.getPhone());
- wf.setWorkUnit(fv.getWorkUnit());
- wf.setFamilyShip(fv.getFamilyShip());
- wf.setStudentCard(icr.getCardId());
- wfs.add(wf);
- }
- }
- //陪同人员
- List<WelcomeAccompany> was = new ArrayList<>();
- if (icr.getAvs() != null && icr.getAvs().size() > 0) {
- for (AccompanyVo av : icr.getAvs()) {
- if(!(StringUtils.hasText(av.getName()) && StringUtils.hasText(av.getPhone()))){
- return CommonResult.fail("家庭成员信息不能为空!");
- }
- WelcomeAccompany wa = new WelcomeAccompany();
- wa.setName(av.getName());
- wa.setPhone(av.getPhone());
- wa.setStudentCard(icr.getCardId());
- was.add(wa);
- }
- }
- try {
- System.out.println("信息采集1");
- boolean resultWs = welcomeStudentService.saveOrUpdate(ws);
- System.out.println("信息采集1.2");
- if (!resultWs) {
- System.out.println("信息采集1.1");
- logger.error("采集学生信息失败,ws参数:" + JSON.toJSON(ws));
- throw new Exception("采集学生信息失败!");
- }
- System.out.println("信息采集2");
- boolean resultWf = welcomeFamilyService.saveBatch(wfs);
- System.out.println("信息采集1.3");
- if (!resultWf) {
- System.out.println("信息采集1.4");
- logger.error("采集学生信息失败,wfs参数:" + JSON.toJSON(wfs));
- throw new Exception("采集学生信息失败!");
- }
- System.out.println("信息采集3");
- boolean resultWa = welcomeAccompanyService.saveBatch(was);
- System.out.println("信息采集1.5");
- if (!resultWa) {
- System.out.println("信息采集1.6");
- logger.error("采集学生信息失败,was参数:" + JSON.toJSON(was));
- throw new Exception("采集学生信息失败!");
- }
- } catch (Exception e) {
- logger.error(e.getMessage());
- throw new Exception("采集失败!");
- }
- return CommonResult.ok("采集完成!");
- }
- @Override
- @Transactional(rollbackFor = {Exception.class})
- public CommonResult deleteStudentInfo(int id) throws Exception {
- WelcomeStudent ws = welcomeStudentService.getManageById(id);
- if (ws == null) {
- return CommonResult.fail("学生信息已失效,无法进行删除操作!");
- }
- //把旧床位清空
- WelcomeBed obedData = welcomeBedService.getBedByCardId(ws.getCardId());
- if (obedData != null) {
- obedData.setStudentCard(null);
- obedData.setCollege(null);
- obedData.setCollegeId(null);
- obedData.setMajor(null);
- obedData.setMajorId(null);
- obedData.setClassstr(null);
- obedData.setClassstrId(null);
- obedData.setIsCheck(0);
- obedData.setCardNum(null);
- obedData.setName(null);
- }
- try {
- //删除学生数据
- int deleteStudent = welcomeStudentService.deleteWelcomeStudentById(id);
- if (deleteStudent <= 0) {
- logger.error("删除学生信息失败,id参数:" + JSON.toJSON(id));
- throw new Exception("删除学生信息失败!");
- }
- if (obedData != null) {
- //删除宿舍数据
- int deleteSd = welcomeBedService.updateWelcomeBed(obedData);
- if (deleteSd < 0) {
- logger.error("删除宿舍失败,obedData参数:" + JSON.toJSON(obedData));
- throw new Exception("删除学生信息失败!");
- }
- }
- //删除同行人员
- int deleteWa = welcomeAccompanyService.deleteWelcomeAccompanyByCard(ws.getCardId());
- //删除家庭成员
- int deletef = welcomeFamilyService.deleteWelcomeFamilyByCard(ws.getCardId());
- } catch (Exception e) {
- logger.error(e.getMessage());
- throw new Exception("删除失败!");
- }
- return CommonResult.ok("删除成功");
- }
- @Override
- public CommonResult importStudentExcel(MultipartFile file) throws IOException, ParseException {
- System.out.println("导入学生信息");
- if (file.isEmpty() || file.getSize() == 0) {
- return CommonResult.fail("导入文件不能为空");
- }
- String ContentType = file.getContentType();
- InputStream inputStream = file.getInputStream();
- List<WelcomeStudent> result = new ArrayList<>();
- //xls格式文件
- if (ContentType.equals(eFileType.Xls.getValue())) {
- CommonResult<List<WelcomeStudent>> resultData = readXls(inputStream);
- if (!resultData.isSuccess()) {
- return resultData;
- }
- result = resultData.getData();
- } else if (ContentType.equals(eFileType.Xlsx.getValue())) {
- CommonResult<List<WelcomeStudent>> resultData = readXlsx(inputStream);
- if (!resultData.isSuccess()) {
- return resultData;
- }
- result = resultData.getData();
- } else {
- return CommonResult.fail("学生信息数据导入只支持Xls或Xlsx格式文件");
- }
- List<String> cardIds = result.stream().map(WelcomeStudent::getCardId).collect(Collectors.toList());
- List<WelcomeStudent> existStudents = welcomeStudentService.queryStudentByCardId(cardIds);
- if (existStudents != null && existStudents.size() > 0) {
- for (WelcomeStudent ws : result) {
- Optional<WelcomeStudent> ows = existStudents.stream().filter(e -> e.getCardId().equals(ws.getCardId())).findFirst();
- if (ows != null && ows.isPresent()) {
- ws.setId(ows.get().getId());
- ws.setAdmissNum(ws.getAdmissNum());//录取号
- ws.setName(ws.getName());//姓名
- ws.setCardId(ws.getCardId());//身份证号
- ws.setSchool(ws.getSchool());//校区
- ws.setCollege(ws.getCollege());
- ws.setCollegeId(ws.getCollegeId());
- ws.setMajor(ws.getMajor());
- ws.setMajorId(ws.getMajorId());
- ws.setClassstr(ws.getClassstr());
- ws.setClassstrId(ws.getClassstrId());
- ws.setExamNum(ws.getExamNum());//考生号
- ws.setEduSystem(ws.getEduSystem());//学制
- ws.setGraduationSchool(ws.getGraduationSchool());//毕业中学
- ws.setBatchValue(ws.getBatchValue());//批次
- ws.setPoliticalStatu(ws.getPoliticalStatu());//政治面貌
- ws.setNationality(ws.getNationality());//民族
- ws.setPhone(ws.getPhone());//手机号码
- ws.setOprovince(ws.getOprovince());
- ws.setOprovinceId(ws.getOprovinceId());
- ws.setOcity(ws.getOcity());
- ws.setOcityId(ws.getOcityId());
- ws.setOdistrict(ws.getOdistrict());
- ws.setOdistrictId(ws.getOdistrictId());
- ws.setProvince(ws.getProvince());
- ws.setProvinceId(ws.getProvinceId());
- ws.setCity(ws.getCity());
- ws.setCityId(ws.getCityId());
- ws.setDistrict(ws.getDistrict());
- ws.setDistrictId(ws.getDistrictId());
- ws.setAddress(ws.getAddress());
- ws.setZipCode(ws.getZipCode());
- }
- }
- }
- boolean resultBool = welcomeStudentService.saveOrUpdateBatch(result);
- System.out.println("导入学生1");
- return resultBool ? CommonResult.ok("导入成功") : CommonResult.fail("导入失败");
- }
- /**
- * xls文件读取方法
- *
- * @param inputStream
- * @return
- * @throws IOException
- * @throws ParseException
- */
- private CommonResult<List<WelcomeStudent>> readXls(InputStream inputStream) throws IOException, ParseException {
- List<WelcomeStudent> result = new ArrayList<>();
- HSSFWorkbook sheets = new HSSFWorkbook(inputStream);
- List<WelcomeOrg> ws = welcomeOrgService.list(null);
- List<WelcomeCity> citys = welcomeCityService.list(null);
- //读取第一张sheet
- HSSFSheet sheetAt = sheets.getSheetAt(0);
- DataFormatter dataFormatter = new DataFormatter();
- try {
- //rowNum = 3 从第三行开始获取值
- //sheetAt.getLastRowNum():从0开始统计数量 所以得+1
- for (int rowNum = 0; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
- HSSFRow row = sheetAt.getRow(rowNum);
- if (row != null) {
- //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
- //所以先使用setCellType()方法先将该单元格的类型设置为STRING
- //然后poi会根据字符串读取它
- //第一行数据获取月份
- if (rowNum == 0) {
- String number = dataFormatter.formatCellValue(row.getCell(0));//序号
- if (!number.equals("序号")) {
- return CommonResult.fail("导入数据第一列为序号");
- }
- String assNum = dataFormatter.formatCellValue(row.getCell(1));//录取号
- if (!assNum.equals("录取号")) {
- return CommonResult.fail("导入数据第二列为录取号");
- }
- String name = dataFormatter.formatCellValue(row.getCell(2));//姓名
- if (!name.equals("姓名")) {
- return CommonResult.fail("导入数据第三列为姓名");
- }
- String cardId = dataFormatter.formatCellValue(row.getCell(3));//身份证号
- if (!cardId.equals("身份证号")) {
- return CommonResult.fail("导入数据第四列为身份证号");
- }
- String school = dataFormatter.formatCellValue(row.getCell(4));//校区
- if (!school.equals("校区")) {
- return CommonResult.fail("导入数据第五列为校区");
- }
- String college = dataFormatter.formatCellValue(row.getCell(5));//院系
- if (!college.equals("院系")) {
- return CommonResult.fail("导入数据第六列为院系");
- }
- String major = dataFormatter.formatCellValue(row.getCell(6));//专业
- if (!major.equals("专业")) {
- return CommonResult.fail("导入数据第七列为专业");
- }
- String classstr = dataFormatter.formatCellValue(row.getCell(7));//班级
- if (!classstr.equals("班级")) {
- return CommonResult.fail("导入数据第八列为班级");
- }
- String examNum = dataFormatter.formatCellValue(row.getCell(8));//考生号
- if (!examNum.equals("考生号")) {
- return CommonResult.fail("导入数据第九列为考生号");
- }
- String eduSystem = dataFormatter.formatCellValue(row.getCell(9));//学制
- if (!eduSystem.equals("学制")) {
- return CommonResult.fail("导入数据第十列为学制");
- }
- String graSchool = dataFormatter.formatCellValue(row.getCell(10));//毕业中学
- if (!graSchool.equals("毕业中学")) {
- return CommonResult.fail("导入数据第十一列为毕业中学批次");
- }
- String batchValue = dataFormatter.formatCellValue(row.getCell(11));//批次
- if (!batchValue.equals("批次")) {
- return CommonResult.fail("导入数据第十二列为批次");
- }
- String politicalStatu = dataFormatter.formatCellValue(row.getCell(12));//政治面貌
- if (!politicalStatu.equals("政治面貌")) {
- return CommonResult.fail("导入数据第十三列为政治面貌");
- }
- String nationality = dataFormatter.formatCellValue(row.getCell(13));//民族
- if (!nationality.equals("民族")) {
- return CommonResult.fail("导入数据第十四列为民族");
- }
- String phone = dataFormatter.formatCellValue(row.getCell(14));//手机号码
- if (!phone.equals("手机号码")) {
- return CommonResult.fail("导入数据第十五列为手机号码");
- }
- String nativePlace = dataFormatter.formatCellValue(row.getCell(15));//籍贯
- if (!nativePlace.contains("籍贯")) {
- return CommonResult.fail("导入数据第十六列为籍贯");
- }
- String addressPlace = dataFormatter.formatCellValue(row.getCell(16));//家庭住址
- if (!addressPlace.contains("家庭住址")) {
- return CommonResult.fail("导入数据第十七列为家庭住址");
- }
- String addressDetail = dataFormatter.formatCellValue(row.getCell(17));//详细住址
- if (!addressDetail.equals("详细住址")) {
- return CommonResult.fail("导入数据第十八列为详细住址");
- }
- String zipCode = dataFormatter.formatCellValue(row.getCell(18));//邮编
- if (!zipCode.equals("邮编")) {
- return CommonResult.fail("导入数据第十九列为邮编");
- }
- } else {
- WelcomeStudent studentData = new WelcomeStudent();
- String assNum = dataFormatter.formatCellValue(row.getCell(1));//录取号
- if(!StringUtils.hasText(assNum)){
- break;
- }
- studentData.setAdmissNum(assNum);
- String name = dataFormatter.formatCellValue(row.getCell(2));//姓名
- studentData.setName(name);
- String cardId = dataFormatter.formatCellValue(row.getCell(3));//身份证号
- studentData.setCardId(cardId);
- String school = dataFormatter.formatCellValue(row.getCell(4));//校区
- studentData.setSchool(school);
- //region 院系专业
- String college = dataFormatter.formatCellValue(row.getCell(5));//院系
- Optional<WelcomeOrg> owo = ws.stream().filter(e -> e.getName().equals(college)).findFirst();
- if (owo != null && owo.isPresent()) {
- studentData.setCollege(college);
- studentData.setCollegeId(owo.get().getId());
- }
- String major = dataFormatter.formatCellValue(row.getCell(6));//专业
- Optional<WelcomeOrg> omwo = ws.stream().filter(e -> e.getName().equals(major)).findFirst();
- if (omwo != null && omwo.isPresent()) {
- studentData.setMajor(major);
- studentData.setMajorId(omwo.get().getId());
- }
- String classstr = dataFormatter.formatCellValue(row.getCell(7));//班级
- Optional<WelcomeOrg> ocwo = ws.stream().filter(e -> e.getName().equals(classstr)).findFirst();
- if (ocwo != null && ocwo.isPresent()) {
- studentData.setClassstr(classstr);
- studentData.setClassstrId(ocwo.get().getId());
- }
- //endregion
- String examNum = dataFormatter.formatCellValue(row.getCell(8));//考生号
- studentData.setExamNum(examNum);
- String eduSystem = dataFormatter.formatCellValue(row.getCell(9));//学制
- studentData.setEduSystem(eduSystem);
- String graSchool = dataFormatter.formatCellValue(row.getCell(10));//毕业中学
- studentData.setGraduationSchool(graSchool);
- String batchValue = dataFormatter.formatCellValue(row.getCell(11));//批次
- studentData.setBatchValue(batchValue);
- String politicalStatu = dataFormatter.formatCellValue(row.getCell(12));//政治面貌
- studentData.setPoliticalStatu(politicalStatu);
- String nationality = dataFormatter.formatCellValue(row.getCell(13));//民族
- studentData.setNationality(nationality);
- String phone = dataFormatter.formatCellValue(row.getCell(14));//手机号码
- studentData.setPhone(phone);
- //region 籍贯
- String nativePlace = dataFormatter.formatCellValue(row.getCell(15));//籍贯
- String[] addressDatas = nativePlace.split("/");
- if (citys != null && citys.size() > 0) {
- if (addressDatas != null && addressDatas.length >= 1) {
- if (!addressDatas[0].contains("省")) {
- return CommonResult.fail("录取编号为\" + assNum + \"的籍贯格式应该是 省/市/县");
- }
- Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getDistrictZh().equals(addressDatas[0])).findFirst();
- if (oProvince != null && oProvince.isPresent()) {
- studentData.setOprovince(addressDatas[0]);
- studentData.setOprovinceId(oProvince.get().getId());
- } else {
- return CommonResult.fail("录取编号为" + assNum + "的籍贯格式应该是 省/市/县区");
- }
- }
- if (addressDatas != null && addressDatas.length >= 2) {
- Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getDistrictZh().equals(addressDatas[1])).findFirst();
- if (oProvince != null && oProvince.isPresent()) {
- studentData.setOcity(addressDatas[1]);
- studentData.setOcityId(oProvince.get().getId());
- } else {
- return CommonResult.fail("录取编号为" + assNum + "的籍贯格式应该是 省/市/县区");
- }
- }
- if (addressDatas != null && addressDatas.length >= 3) {
- Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getCityZh().equals(addressDatas[1]) && e.getDistrictZh().equals(addressDatas[2])).findFirst();
- if (oProvince != null && oProvince.isPresent()) {
- studentData.setOdistrict(addressDatas[2]);
- studentData.setOdistrictId(oProvince.get().getId());
- } else {
- return CommonResult.fail("录取编号为" + assNum + "的籍贯格式应该是 省/市/县区");
- }
- }
- }
- //endregion
- //region 家庭住址
- String addressPlace = dataFormatter.formatCellValue(row.getCell(16));//家庭住址
- String[] addressPlaces = addressPlace.split("/");
- if (citys != null && citys.size() > 0) {
- if (addressPlaces != null && addressPlaces.length >= 1) {
- if (!addressPlaces[0].contains("省")) {
- return CommonResult.fail("录取编号为" + assNum + "的家庭住址格式应该是 省/市/县区");
- }
- Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getDistrictZh().equals(addressPlaces[0])).findFirst();
- if (oProvince != null && oProvince.isPresent()) {
- studentData.setProvince(addressPlaces[0]);
- studentData.setProvinceId(oProvince.get().getId());
- } else {
- return CommonResult.fail("录取编号为" + assNum + "的家庭住址格式应该是 省/市/县区");
- }
- }
- if (addressPlaces != null && addressPlaces.length >= 2) {
- Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getDistrictZh().equals(addressPlaces[1])).findFirst();
- if (oProvince != null && oProvince.isPresent()) {
- studentData.setCity(addressPlaces[1]);
- studentData.setCityId(oProvince.get().getId());
- } else {
- return CommonResult.fail("录取编号为" + assNum + "的家庭住址格式应该是 省/市/县区");
- }
- }
- if (addressPlaces != null && addressPlaces.length >= 3) {
- Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getCityZh().equals(addressPlaces[1]) && e.getDistrictZh().equals(addressPlaces[2])).findFirst();
- if (oProvince != null && oProvince.isPresent()) {
- studentData.setDistrict(addressPlaces[2]);
- studentData.setDistrictId(oProvince.get().getId());
- } else {
- return CommonResult.fail("录取编号为" + assNum + "的家庭住址格式应该是 省/市/县区");
- }
- }
- }
- //endregion
- String addressDetail = dataFormatter.formatCellValue(row.getCell(17));//详细住址
- studentData.setAddress(addressDetail);
- String zipCode = dataFormatter.formatCellValue(row.getCell(18));//邮编
- studentData.setZipCode(zipCode);
- studentData.setIdenType(1);
- result.add(studentData);
- }
- }
- }
- } catch (Exception e) {
- return CommonResult.fail("请按模板格式导入数据");
- }
- return CommonResult.ok(result);
- }
- /**
- * xls文件读取方法
- *
- * @param inputStream
- * @return
- * @throws IOException
- * @throws ParseException
- */
- private CommonResult<List<WelcomeStudent>> readXlsx(InputStream inputStream) throws IOException, ParseException {
- List<WelcomeStudent> result = new ArrayList<>();
- XSSFWorkbook sheets = new XSSFWorkbook(inputStream);
- List<WelcomeOrg> ws = welcomeOrgService.list(null);
- List<WelcomeCity> citys = welcomeCityService.list(null);
- //读取第一张sheet
- XSSFSheet sheetAt = sheets.getSheetAt(0);
- DataFormatter dataFormatter = new DataFormatter();
- try {
- //rowNum = 3 从第三行开始获取值
- //sheetAt.getLastRowNum():从0开始统计数量 所以得+1
- for (int rowNum = 0; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
- XSSFRow row = sheetAt.getRow(rowNum);
- if (row != null) {
- //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
- //所以先使用setCellType()方法先将该单元格的类型设置为STRING
- //然后poi会根据字符串读取它
- //第一行数据获取月份
- if (rowNum == 0) {
- String number = dataFormatter.formatCellValue(row.getCell(0));//序号
- if (!number.equals("序号")) {
- return CommonResult.fail("导入数据第一列为序号");
- }
- String assNum = dataFormatter.formatCellValue(row.getCell(1));//录取号
- if (!assNum.equals("录取号")) {
- return CommonResult.fail("导入数据第二列为录取号");
- }
- String name = dataFormatter.formatCellValue(row.getCell(2));//姓名
- if (!name.equals("姓名")) {
- return CommonResult.fail("导入数据第三列为姓名");
- }
- String cardId = dataFormatter.formatCellValue(row.getCell(3));//身份证号
- if (!cardId.equals("身份证号")) {
- return CommonResult.fail("导入数据第四列为身份证号");
- }
- String school = dataFormatter.formatCellValue(row.getCell(4));//校区
- if (!school.equals("校区")) {
- return CommonResult.fail("导入数据第五列为校区");
- }
- String college = dataFormatter.formatCellValue(row.getCell(5));//院系
- if (!college.equals("院系")) {
- return CommonResult.fail("导入数据第六列为院系");
- }
- String major = dataFormatter.formatCellValue(row.getCell(6));//专业
- if (!major.equals("专业")) {
- return CommonResult.fail("导入数据第七列为专业");
- }
- String classstr = dataFormatter.formatCellValue(row.getCell(7));//班级
- if (!classstr.equals("班级")) {
- return CommonResult.fail("导入数据第八列为班级");
- }
- String examNum = dataFormatter.formatCellValue(row.getCell(8));//考生号
- if (!examNum.equals("考生号")) {
- return CommonResult.fail("导入数据第九列为考生号");
- }
- String eduSystem = dataFormatter.formatCellValue(row.getCell(9));//学制
- if (!eduSystem.equals("学制")) {
- return CommonResult.fail("导入数据第十列为学制");
- }
- String graSchool = dataFormatter.formatCellValue(row.getCell(10));//毕业中学
- if (!graSchool.equals("毕业中学")) {
- return CommonResult.fail("导入数据第十一列为毕业中学批次");
- }
- String batchValue = dataFormatter.formatCellValue(row.getCell(11));//批次
- if (!batchValue.equals("批次")) {
- return CommonResult.fail("导入数据第十二列为批次");
- }
- String politicalStatu = dataFormatter.formatCellValue(row.getCell(12));//政治面貌
- if (!politicalStatu.equals("政治面貌")) {
- return CommonResult.fail("导入数据第十三列为政治面貌");
- }
- String nationality = dataFormatter.formatCellValue(row.getCell(13));//民族
- if (!nationality.equals("民族")) {
- return CommonResult.fail("导入数据第十四列为民族");
- }
- String phone = dataFormatter.formatCellValue(row.getCell(14));//手机号码
- if (!phone.equals("手机号码")) {
- return CommonResult.fail("导入数据第十五列为手机号码");
- }
- String nativePlace = dataFormatter.formatCellValue(row.getCell(15));//籍贯
- if (!nativePlace.contains("籍贯")) {
- return CommonResult.fail("导入数据第十六列为籍贯");
- }
- String addressPlace = dataFormatter.formatCellValue(row.getCell(16));//家庭住址
- if (!addressPlace.contains("家庭住址")) {
- return CommonResult.fail("导入数据第十七列为家庭住址");
- }
- String addressDetail = dataFormatter.formatCellValue(row.getCell(17));//详细住址
- if (!addressDetail.equals("详细住址")) {
- return CommonResult.fail("导入数据第十八列为详细住址");
- }
- String zipCode = dataFormatter.formatCellValue(row.getCell(18));//邮编
- if (!zipCode.equals("邮编")) {
- return CommonResult.fail("导入数据第十九列为邮编");
- }
- } else {
- WelcomeStudent studentData = new WelcomeStudent();
- String assNum = dataFormatter.formatCellValue(row.getCell(1));//录取号
- if(!StringUtils.hasText(assNum)){
- break;
- }
- studentData.setAdmissNum(assNum);
- String name = dataFormatter.formatCellValue(row.getCell(2));//姓名
- studentData.setName(name);
- String cardId = dataFormatter.formatCellValue(row.getCell(3));//身份证号
- studentData.setCardId(cardId);
- String school = dataFormatter.formatCellValue(row.getCell(4));//校区
- studentData.setSchool(school);
- //region 院系专业
- String college = dataFormatter.formatCellValue(row.getCell(5));//院系
- Optional<WelcomeOrg> owo = ws.stream().filter(e -> e.getName().equals(college)).findFirst();
- if (owo != null && owo.isPresent()) {
- studentData.setCollege(college);
- studentData.setCollegeId(owo.get().getId());
- }
- String major = dataFormatter.formatCellValue(row.getCell(6));//专业
- Optional<WelcomeOrg> omwo = ws.stream().filter(e -> e.getName().equals(major)).findFirst();
- if (omwo != null && omwo.isPresent()) {
- studentData.setMajor(major);
- studentData.setMajorId(omwo.get().getId());
- }
- String classstr = dataFormatter.formatCellValue(row.getCell(7));//班级
- Optional<WelcomeOrg> ocwo = ws.stream().filter(e -> e.getName().equals(classstr)).findFirst();
- if (ocwo != null && ocwo.isPresent()) {
- studentData.setClassstr(classstr);
- studentData.setClassstrId(ocwo.get().getId());
- }
- //endregion
- String examNum = dataFormatter.formatCellValue(row.getCell(8));//考生号
- studentData.setExamNum(examNum);
- String eduSystem = dataFormatter.formatCellValue(row.getCell(9));//学制
- studentData.setEduSystem(eduSystem);
- String graSchool = dataFormatter.formatCellValue(row.getCell(10));//毕业中学
- studentData.setGraduationSchool(graSchool);
- String batchValue = dataFormatter.formatCellValue(row.getCell(11));//批次
- studentData.setBatchValue(batchValue);
- String politicalStatu = dataFormatter.formatCellValue(row.getCell(12));//政治面貌
- studentData.setPoliticalStatu(politicalStatu);
- String nationality = dataFormatter.formatCellValue(row.getCell(13));//民族
- studentData.setNationality(nationality);
- String phone = dataFormatter.formatCellValue(row.getCell(14));//手机号码
- studentData.setPhone(phone);
- //region 籍贯
- String nativePlace = dataFormatter.formatCellValue(row.getCell(15));//籍贯
- String[] addressDatas = nativePlace.split("/");
- if (citys != null && citys.size() > 0) {
- if (addressDatas != null && addressDatas.length >= 1) {
- if (!addressDatas[0].contains("省")) {
- return CommonResult.fail("录取编号为\" + assNum + \"的籍贯格式应该是 省/市/县区");
- }
- Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getDistrictZh().equals(addressDatas[0])).findFirst();
- if (oProvince != null && oProvince.isPresent()) {
- studentData.setOprovince(addressDatas[0]);
- studentData.setOprovinceId(oProvince.get().getId());
- } else {
- return CommonResult.fail("录取编号为" + assNum + "的籍贯格式应该是 省/市/县区");
- }
- }
- if (addressDatas != null && addressDatas.length >= 2) {
- Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getDistrictZh().equals(addressDatas[1])).findFirst();
- if (oProvince != null && oProvince.isPresent()) {
- studentData.setOcity(addressDatas[1]);
- studentData.setOcityId(oProvince.get().getId());
- } else {
- return CommonResult.fail("录取编号为" + assNum + "的籍贯格式应该是 省/市/县区");
- }
- }
- if (addressDatas != null && addressDatas.length >= 3) {
- Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getCityZh().equals(addressDatas[1]) && e.getDistrictZh().equals(addressDatas[2])).findFirst();
- if (oProvince != null && oProvince.isPresent()) {
- studentData.setOdistrict(addressDatas[2]);
- studentData.setOdistrictId(oProvince.get().getId());
- } else {
- return CommonResult.fail("录取编号为" + assNum + "的籍贯格式应该是 省/市/县区");
- }
- }
- }
- //endregion
- //region 家庭住址
- String addressPlace = dataFormatter.formatCellValue(row.getCell(16));//家庭住址
- String[] addressPlaces = addressPlace.split("/");
- if (citys != null && citys.size() > 0) {
- if (addressPlaces != null && addressPlaces.length >= 1) {
- if (!addressPlaces[0].contains("省")) {
- return CommonResult.fail("录取编号为" + assNum + "的家庭住址格式应该是 省/市/县区");
- }
- Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getDistrictZh().equals(addressPlaces[0])).findFirst();
- if (oProvince != null && oProvince.isPresent()) {
- studentData.setProvince(addressPlaces[0]);
- studentData.setProvinceId(oProvince.get().getId());
- } else {
- return CommonResult.fail("录取编号为" + assNum + "的家庭住址格式应该是 省/市/县区");
- }
- }
- if (addressPlaces != null && addressPlaces.length >= 2) {
- Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getDistrictZh().equals(addressPlaces[1])).findFirst();
- if (oProvince != null && oProvince.isPresent()) {
- studentData.setCity(addressPlaces[1]);
- studentData.setCityId(oProvince.get().getId());
- } else {
- return CommonResult.fail("录取编号为" + assNum + "的家庭住址格式应该是 省/市/县区");
- }
- }
- if (addressPlaces != null && addressPlaces.length >= 3) {
- Optional<WelcomeCity> oProvince = citys.stream().filter(e -> e.getCityZh().equals(addressPlaces[1]) && e.getDistrictZh().equals(addressPlaces[2])).findFirst();
- if (oProvince != null && oProvince.isPresent()) {
- studentData.setDistrict(addressPlaces[2]);
- studentData.setDistrictId(oProvince.get().getId());
- } else {
- return CommonResult.fail("录取编号为" + assNum + "的家庭住址格式应该是 省/市/县区");
- }
- }
- }
- //endregion
- String addressDetail = dataFormatter.formatCellValue(row.getCell(17));//详细住址
- studentData.setAddress(addressDetail);
- String zipCode = dataFormatter.formatCellValue(row.getCell(18));//邮编
- studentData.setZipCode(zipCode);
- studentData.setIdenType(1);
- result.add(studentData);
- }
- }
- }
- } catch (Exception e) {
- return CommonResult.fail("请按模板格式导入数据");
- }
- return CommonResult.ok(result);
- }
- @Override
- public CommonResult downloadStudentExcel() {
- return CommonResult.ok("200", "操作成功", "https://chtech.ncjti.edu.cn/alumnus/homeimage/学生信息管理.xlsx");
- }
- @Override
- public void welcomeStudentExport(HttpServletResponse response, Integer collegeId, Integer majorId, Integer classstrId, String trafficMethod, String name) {
- List<StudentPageVo> result = welcomeStudentService.queryStudentList(collegeId, majorId, classstrId, trafficMethod, name);
- //导出
- Workbook workbook = new XSSFWorkbook();
- Sheet sheet = workbook.createSheet("学生信息");
- Row headerRow = sheet.createRow(0);
- headerRow.createCell(0).setCellValue("序号");
- headerRow.createCell(1).setCellValue("录取号");
- headerRow.createCell(2).setCellValue("姓名");
- headerRow.createCell(3).setCellValue("身份证号");
- headerRow.createCell(4).setCellValue("院系");
- headerRow.createCell(5).setCellValue("专业");
- headerRow.createCell(6).setCellValue("班级");
- headerRow.createCell(7).setCellValue("交通方式");
- headerRow.createCell(8).setCellValue("到站地点");
- headerRow.createCell(9).setCellValue("陪同人数");
- headerRow.createCell(10).setCellValue("填报状态");
- headerRow.createCell(11).setCellValue("应缴金额");
- headerRow.createCell(12).setCellValue("实付金额");
- headerRow.createCell(13).setCellValue("宿舍信息");
- for (int i = 0; i < result.size(); i++) {
- StudentPageVo studentData = result.get(i);
- Row dataRow = sheet.createRow(i + 1);
- dataRow.createCell(0).setCellValue(i + 1);
- dataRow.createCell(1).setCellValue(studentData.getAdmissNum());
- dataRow.createCell(2).setCellValue(studentData.getName());
- dataRow.createCell(3).setCellValue(studentData.getCardId());
- dataRow.createCell(4).setCellValue(studentData.getCollege());
- dataRow.createCell(5).setCellValue(studentData.getMajor());
- dataRow.createCell(6).setCellValue(studentData.getClassstr());
- dataRow.createCell(7).setCellValue(studentData.getTrafficMethod());
- dataRow.createCell(8).setCellValue(studentData.getArrive());
- dataRow.createCell(9).setCellValue(studentData.getAccompanyNum());
- dataRow.createCell(10).setCellValue(studentData.getFillStatus());
- dataRow.createCell(11).setCellValue(String.valueOf(studentData.getAmountPayable()));
- dataRow.createCell(12).setCellValue(String.valueOf(studentData.getPayAmount()));
- dataRow.createCell(13).setCellValue(studentData.getDormitory());
- }
- // 将工作簿写入文件
- ExcelUtils.excelDownload(workbook, "学生信息.xlsx", response);
- }
- @Override
- public CommonResult studentOverview() {
- QueryWrapper<WelcomeStudent> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("iden_type",1);
- queryWrapper.eq("fill_status","已填报");
- // 报到总数
- int studentTotal = welcomeStudentService.count(queryWrapper);
- // 寝室总数
- int dormitoryTotal = welcomeDormitoryService.count(new QueryWrapper<>());
- int payCount=welcomeStudentService.payCount();
- // 已入住寝室数
- LambdaQueryWrapper<WelcomeDormitory> wrapper=new LambdaQueryWrapper<>();
- wrapper.ne(WelcomeDormitory::getStatus,2);
- int count = welcomeDormitoryService.count(wrapper);
- LocalDateTime start = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0);
- LocalDateTime end = start.plusDays(1);
- DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
- Integer visitorTotal=welcomeVisitorService.countTotal(start,end);
- List<WelcomeSetting> wss = welcomeSettingService.list(null);
- Integer carTotal =wss !=null && wss.size() > 0 ? wss.get(0).getCarNum() : 0;
- StudentOverviewVo vo = new StudentOverviewVo();
- vo.setEnrollmentTotal(6532);
- vo.setStudentTotal(studentTotal);
- vo.setPayCount(payCount);
- vo.setDormitoryTotal(dormitoryTotal);
- vo.setCheckInTotal(count);
- vo.setVisitorTotal(visitorTotal);
- vo.setCarTotal(carTotal);
- return CommonResult.ok(vo);
- }
- @Override
- public CommonResult studentRegister() {
- // 获取总数
- Integer count = welcomeStudentService.totalCount();
- List<StudentRegisterVo> vos = welcomeStudentService.studentRegister();
- StudentRegisterVo vo = new StudentRegisterVo();
- vo.setCollegeName("报到总数");
- vo.setCount(count);
- vos.add(vo);
- return CommonResult.ok(vos);
- }
- @Override
- public CommonResult studentTraffic() {
- List<StudentTrafficVo> vos = welcomeStudentService.studentTraffic();
- return CommonResult.ok(vos);
- }
- @Override
- public CommonResult studentSexRatio() {
- Integer manCount = welcomeStudentService.genderCount("男");
- Integer girlCount = welcomeStudentService.genderCount("女");
- StudentSexRatioVo vo = new StudentSexRatioVo();
- vo.setCollegeName("全部");
- vo.setManCount(manCount);
- vo.setGirlCount(girlCount);
- List<StudentSexRatioVo> vos = welcomeStudentService.studentSexRatio();
- vos.add(vo);
- return CommonResult.ok(vos);
- }
- @Override
- public CommonResult studentStay() {
- ArrayList<StudentStayVo> vos = new ArrayList<>();
- List<WelcomeSchool> list = welcomeSchoolService.list(new QueryWrapper<>());
- for (WelcomeSchool welcomeSchool : list) {
- Integer schoolId = welcomeSchool.getId();
- List<WelcomeBuild> builds=welcomeBuildService.getBuild(schoolId);
- for (WelcomeBuild build : builds) {
- Integer buildId = build.getId();
- StudentStayVo vo =welcomeDormitoryService.getTotalCount(buildId);
- vo.setSchoolName(welcomeSchool.getSchool());
- vo.setBuildName(build.getBuild());
- vos.add(vo);
- }
- }
- return CommonResult.ok(vos);
- }
- @Override
- public CommonResult queryStudentByToken( String userId) {
- WelcomeStudent student = welcomeStudentService.getManageById(Integer.valueOf(userId));
- return CommonResult.ok(student);
- }
- }
|