package com.template.controller; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.template.annotation.AWelcomeLevelLog; import com.template.annotation.AWelcomeLog; import com.template.annotation.AWelcomeLogMode; import com.template.annotation.AWelcomeTypeLog; import com.template.api.WelcomeStudentControllerAPI; import com.template.common.utils.*; import com.template.model.enumModel.eFileType; import com.template.model.enumModel.eSchool; import com.template.model.pojo.*; import com.template.model.request.InfoCollectionRequest; import com.template.model.request.InsertFamilyRequest; import com.template.model.request.InsertStudentRequest; import com.template.model.request.updateStudentRequest; import com.template.model.result.CommonResult; import com.template.model.result.PageUtils; import com.template.model.vo.*; import com.template.services.*; import io.swagger.models.auth.In; 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.math.BigDecimal; import java.math.BigInteger; import java.text.ParseException; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.*; import java.util.stream.Collectors; /** *

* 前端控制器 *

* * @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 WelcomeAccountService welcomeAccountService; @Autowired private WelcomeSettingService welcomeSettingService; @Autowired private WelcomeArriveSettingService welcomeArriveSettingService; @Autowired private WelcomeOrgService welcomeOrgService; @Autowired private WelcomeCityService welcomeCityService; @Autowired private WelcomeSchoolService welcomeSchoolService; @Autowired private WelcomeBuildService welcomeBuildService; @Autowired private WelcomeDormitoryService welcomeDormitoryService; @Autowired private WelcomeVisitorService welcomeVisitorService; @Autowired private WelcomePaySettingService welcomePaySettingService; private static Logger logger = LoggerFactory.getLogger(WelcomeStudentController.class); @Override @AWelcomeLog("新增学生信息管理") @AWelcomeTypeLog("新增") @AWelcomeLogMode("学生信息管理") @AWelcomeLevelLog("信息") @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); } if (!isr.getBatchValue().equals("本科") && !isr.getBatchValue().equals("专升本") && !isr.getBatchValue().equals("专科")) { return CommonResult.fail("层次为本科或专升本或专科"); } 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(StringUtils.hasText(isr.getPicture()) ? isr.getPicture() : "https://chtech.ncjti.edu.cn/welcome/homeimage/newStudentHeadImage.jpg"); ws.setCardId(isr.getCardId()); //region 校验身份证号 并根据身份证号获取出生年月和性别 boolean isValidate = CardUtils.validateIdCard(isr.getCardId());//身份证是否合法 if (!isValidate) { return CommonResult.fail("身份证不合法"); } String sex = CardUtils.getSexByIdCard(isr.getCardId()); if (!StringUtils.hasText(isr.getSex())) { ws.setSex(sex); } else { ws.setSex(isr.getSex()); } String birthday = CardUtils.getBirthdayByIdCard(isr.getCardId()); if (!StringUtils.hasText(isr.getBirthday())) { ws.setBirthday(birthday); } else { ws.setBirthday(isr.getBirthday()); } //endregion 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.setIsPay(0); ws.setFillStatus("未填报"); ws.setIsRegistered(2); //ws.setAmountPayable(isr.getAmountPayable()); //ws.setPayAmount(isr.getPayAmount()); //ws.setIsDrive(isr.getIsDrive()); //ws.setCarNumber(isr.getCarNumber()); //endregion //region 家庭成员数据 List 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 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) { // if (StringUtils.hasText(bedData.getStudentCard())) { // return CommonResult.fail("当前床位已被他人入住,无法入住"); // } // 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 @AWelcomeLog("编辑学生信息管理") @AWelcomeTypeLog("编辑") @AWelcomeLogMode("学生信息管理") @AWelcomeLevelLog("信息") 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("学生数据已失效,编辑失败!"); } if (!usr.getBatchValue().equals("本科") && !usr.getBatchValue().equals("专升本") && !usr.getBatchValue().equals("专科")) { return CommonResult.fail("层次为本科或专升本或专科"); } //region 学生信息 student.setAdmissNum(usr.getAdmissNum()); student.setName(usr.getName()); student.setPicture(StringUtils.hasText(usr.getPicture()) ? usr.getPicture() : "https://chtech.ncjti.edu.cn/welcome/homeimage/newStudentHeadImage.jpg"); //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 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 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 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.getStudentCard().equals(student.getCardId())) { // return CommonResult.fail("当前床位已被他人入住,无法入住"); // } // 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 = new WelcomeBed(); // 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(String userId, int currentPage, int pageCount, Integer collegeId, Integer majorId, Integer classstrId, String trafficMethod, String name, String fillStatus, Integer isRegistered, Integer isPay, Integer isCheck, String school, String batchValue, Integer carNumber, Integer yearId) throws ParseException { String nstartTime = null; String nendTime = null; boolean isNowYear = false; boolean lastYear = TimeExchange.CompareDate(TimeExchange.getDate(), TimeExchange.getYear() + "-07-01", "yyyy-MM-dd"); if (yearId == null) { Integer yearInt = Integer.valueOf(TimeExchange.getYear()); //当前时间小于本年度的7月1日 说明要查去年的数据 if (lastYear) { nstartTime = (yearInt - 1) + "-06-01"; nendTime = yearInt + "-06-01"; } else {//今年 isNowYear = true; nstartTime = yearInt + "-06-01"; nendTime = (yearInt + 1) + "-06-01"; } } else { nstartTime = yearId + "-06-01"; nendTime = (yearId + 1) + "-06-01"; } IPage pages = new Page<>(); PageUtils result = new PageUtils<>(pages); WelcomeAccount wa = welcomeAccountService.getManageById(userId); if (wa == null) { return CommonResult.fail("当前账户已失效,无权限查看"); } List collegeIds = Arrays.asList(wa.getCollegeId().split(",")); if (collegeId != null && collegeId.intValue() > 0) { if (!collegeIds.contains(String.valueOf(collegeId))) { pages.setCurrent(currentPage); pages.setSize(pageCount); return CommonResult.ok(result); } else { collegeIds = new ArrayList<>(); collegeIds.add(String.valueOf(collegeId)); } } result = welcomeStudentService.queryStudentPageList(currentPage, pageCount, collegeIds, majorId, classstrId, trafficMethod, name, fillStatus, isRegistered, isPay, isCheck, school, batchValue, carNumber, nstartTime, nendTime); if (result != null && result.getList() != null && result.getList().size() > 0) { List students = result.getList().stream().filter(e -> e.getIsPay().intValue() == 0).collect(Collectors.toList()); //只处理本学期的未达标人员的数据同步一下支付数据 if (students != null && students.size() > 0 && isNowYear) { List pdvs = new ArrayList<>(); List ids = new ArrayList<>(); for (StudentPageVo student : students) { List payInfos = WelcomePayController.queryStudentPayInfo(student.getAdmissNum(), TimeExchange.getYear()); BigDecimal payAmount = new BigDecimal(BigInteger.ZERO);//实缴金额 BigDecimal yjPayAmount = new BigDecimal(BigInteger.ZERO);//应缴金额 BigDecimal dkAmount = new BigDecimal(BigInteger.ZERO);//贷款金额 for (JsonPayVo pi : payInfos) { dkAmount = dkAmount.add(pi.getDKJE()); payAmount = payAmount.add(pi.getSJJE()); yjPayAmount = yjPayAmount.add(pi.getYJJE()); } BigDecimal studentPay = payAmount.add(dkAmount); student.setPayAmount(studentPay); student.setAmountPayable(yjPayAmount); System.out.println("进支付比较1" + JSON.toJSON(payInfos)); if (payInfos != null && payInfos.size() > 0) { System.out.println("进支付比较2"); WelcomePaySetting paySettings = welcomePaySettingService.queryPaySettingById(student.getCollegeId(), student.getMajorId(), student.getBatchValue(), nstartTime, nendTime); System.out.println("进支付比较3" + JSON.toJSON(paySettings)); if (paySettings != null) { System.out.println("进支付比较4"); if (studentPay.compareTo(paySettings.getPayAmount()) >= 0) { student.setIsPay(1); ids.add(student.getId()); PayDetailsVo pdv = new PayDetailsVo(); pdv.setId(student.getId()); pdv.setPayAmount(studentPay); pdv.setAmountPayable(yjPayAmount); pdvs.add(pdv); } else { student.setIsPay(0); } } else { student.setIsPay(0); } } else { student.setIsPay(0); } } if (ids != null && ids.size() > 0) { List studentDatas = welcomeStudentService.queryStudents(ids); if(studentDatas != null && studentDatas.size() > 0){ for (WelcomeStudent ws:studentDatas){ Optional opdv = pdvs.stream().filter(e -> e.getId().intValue() == ws.getId().intValue()).findFirst(); if(opdv != null && opdv.isPresent()){ ws.setAmountPayable(opdv.get().getAmountPayable()); ws.setPayAmount(opdv.get().getPayAmount()); } ws.setIsPay(1); } boolean update = welcomeStudentService.updateBatchById(studentDatas); if (!update) { logger.error("获取支付信息导致学校信息查询失败"); return CommonResult.fail("查询失败"); } } } } } 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 fvs = new ArrayList<>(); List 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 avs = new ArrayList<>(); List 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 atvs = new ArrayList<>(); List 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(StringUtils.hasText(ws.getPicture()) ? ws.getPicture() : "https://chtech.ncjti.edu.cn/welcome/homeimage/newStudentHeadImage.jpg"); 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()); // 当前学生表里的车牌号为空 WelcomeVisitorVO byCurUser = welcomeVisitorService.getByCurUser(ws.getCardId()); if (ObjectUtils.isNotEmpty(byCurUser)) { result.setCarNumber(byCurUser.getCarNumber()); } return CommonResult.ok(result); } @Override @AWelcomeLog("采集学生信息管理") @AWelcomeTypeLog("编辑") @AWelcomeLogMode("学生信息管理") @AWelcomeLevelLog("信息") @Transactional(rollbackFor = {Exception.class}) public CommonResult infoCollection(InfoCollectionRequest icr, BindingResult bindingResult) throws Exception { logger.info("采集学生信息失败,icr参数:" + JSON.toJSON(icr)); if (bindingResult.hasErrors()) { String st = paramUtils.getParamError(bindingResult); return CommonResult.fail(st); } if (!icr.getBatchValue().equals("本科") && !icr.getBatchValue().equals("专升本") && !icr.getBatchValue().equals("专科")) { return CommonResult.fail("层次为本科或专升本或专科"); } WelcomeStudent ws = welcomeStudentService.getDataByIdcardOrNum(icr.getAdmissNum(), icr.getCardId()); if (ws == null) { ws = new WelcomeStudent(); } ws.setSchool(icr.getSchool()); ws.setAdmissNum(icr.getAdmissNum()); ws.setName(icr.getName()); ws.setPicture(StringUtils.hasText(icr.getPicture()) ? icr.getPicture() : "https://chtech.ncjti.edu.cn/welcome/homeimage/newStudentHeadImage.jpg"); //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.setArriveTime(icr.getArriveTime()); ws.setArriveTimeId(icr.getArriveTimeId()); ws.setFillStatus("已填报"); //家庭成员 List 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(ws.getCardId()); wfs.add(wf); } } //陪同人员 List 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(ws.getCardId()); was.add(wa); } } if (!(ws.getIsPay() != null && ws.getIsPay().intValue() == 1)) { System.out.println("进支付比较"); List payInfos = WelcomePayController.queryStudentPayInfo(ws.getAdmissNum(), TimeExchange.getYear()); BigDecimal payAmount = new BigDecimal(BigInteger.ZERO);//实缴金额 BigDecimal yjPayAmount = new BigDecimal(BigInteger.ZERO);//应缴金额 BigDecimal dkAmount = new BigDecimal(BigInteger.ZERO);//贷款金额 for (JsonPayVo pi : payInfos) { dkAmount = dkAmount.add(pi.getDKJE()); payAmount = payAmount.add(pi.getSJJE()); yjPayAmount = yjPayAmount.add(pi.getYJJE()); } BigDecimal studentPay = payAmount.add(dkAmount); ws.setPayAmount(studentPay); ws.setAmountPayable(yjPayAmount); System.out.println("进支付比较1" + JSON.toJSON(payInfos)); if (payInfos != null && payInfos.size() > 0) { System.out.println("进支付比较2"); String nstartTime = null; String nendTime = null; boolean lastYear = TimeExchange.CompareDate(TimeExchange.getDate(), TimeExchange.getYear() + "-07-01", "yyyy-MM-dd"); Integer yearInt = Integer.valueOf(TimeExchange.getYear()); //当前时间小于本年度的7月1日 说明要查去年的数据 if (lastYear) { nstartTime = (yearInt - 1) + "-06-01"; nendTime = yearInt + "-06-01"; } else { nstartTime = yearInt + "-06-01"; nendTime = (yearInt + 1) + "-06-01"; } WelcomePaySetting paySettings = welcomePaySettingService.queryPaySettingById(ws.getCollegeId(), ws.getMajorId(), ws.getBatchValue(), nstartTime, nendTime); System.out.println("进支付比较3" + JSON.toJSON(paySettings)); if (paySettings != null) { System.out.println("进支付比较4"); if (studentPay.compareTo(paySettings.getPayAmount()) >= 0) { ws.setIsPay(1); } else { ws.setIsPay(0); } } else { ws.setIsPay(0); } } else { ws.setIsPay(0); } } if (ws.getIsPay() == null) { ws.setIsPay(0); } try { System.out.println("信息采集1"); if (ws.getId() != null) { int update = welcomeStudentService.updateWelcomeStudent(ws); if (update < 0) { System.out.println("信息采集1.1"); logger.error("采集学生信息失败,ws参数:" + JSON.toJSON(ws)); throw new Exception("采集学生信息失败!"); //return CommonResult.fail("采集学生信息失败1"); } } else { int insert = welcomeStudentService.insertWelcomeStudent(ws); if (insert < 0) { System.out.println("信息采集1.2"); logger.error("采集学生信息失败,ws参数:" + JSON.toJSON(ws)); throw new Exception("采集学生信息失败!"); //return CommonResult.fail("采集学生信息失败1"); } } System.out.println("信息采集2"); if (wfs != null && wfs.size() > 0) { int deleteF = welcomeFamilyService.deleteWelcomeFamilyByCard(ws.getCardId()); 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("采集学生信息失败!"); //return CommonResult.fail("采集学生信息失败2"); } } System.out.println("信息采集3"); if (was != null && was.size() > 0) { int deleteF = welcomeAccompanyService.deleteWelcomeAccompanyByCard(ws.getCardId()); 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("采集学生信息失败!"); //return CommonResult.fail("采集学生信息失败3"); } } } catch (Exception e) { logger.error(e.getMessage()); throw new Exception("采集失败!"); //return CommonResult.fail("采集学生信息失败4"); } System.out.println("信息采集1.7"); return CommonResult.ok("采集完成!"); } @Override @AWelcomeLog("删除学生信息管理") @AWelcomeTypeLog("删除") @AWelcomeLogMode("学生信息管理") @AWelcomeLevelLog("警告") @Transactional(rollbackFor = {Exception.class}) public CommonResult deleteStudentInfo(int id) throws Exception { System.out.println("删除了学生信息:" + id); WelcomeStudent ws = welcomeStudentService.getManageById(id); if (ws == null) { return CommonResult.fail("学生信息已失效,无法进行删除操作!"); } //把旧床位清空 WelcomeBed obedData = welcomeBedService.getBedByCardId(ws.getCardId()); // if (obedData != null) { // obedData.setStudentCard(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("删除学生信息失败!"); // } welcomeBedService.updateData(obedData.getId()); // 修改寝室信息 WelcomeDormitory welcomeDormitory = welcomeDormitoryService.getById(obedData.getDormitoryId()); if (ObjectUtils.isNotEmpty(welcomeDormitory)) { Integer freeBedNumber = welcomeDormitory.getFreeBedNumber(); Integer bedNumber = welcomeDormitory.getBedNumber(); freeBedNumber = freeBedNumber + 1; if (bedNumber.equals(freeBedNumber)) { welcomeDormitory.setFreeBedNumber(freeBedNumber); welcomeDormitory.setStatus(1); } else if (bedNumber > freeBedNumber) { welcomeDormitory.setFreeBedNumber(freeBedNumber); welcomeDormitory.setStatus(3); } welcomeDormitoryService.updateById(welcomeDormitory); } } //删除同行人员 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 @AWelcomeLog("导入学生信息管理") @AWelcomeTypeLog("导入") @AWelcomeLogMode("学生信息管理") @AWelcomeLevelLog("信息") 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 result = new ArrayList<>(); //xls格式文件 if (ContentType.equals(eFileType.Xls.getValue())) { CommonResult> resultData = readXls(inputStream); if (!resultData.isSuccess()) { return resultData; } result = resultData.getData(); } else if (ContentType.equals(eFileType.Xlsx.getValue())) { CommonResult> resultData = readXlsx(inputStream); if (!resultData.isSuccess()) { return resultData; } result = resultData.getData(); } else { return CommonResult.fail("学生信息数据导入只支持Xls或Xlsx格式文件"); } StringBuilder sb = new StringBuilder(); List cardIds = result.stream().map(WelcomeStudent::getCardId).collect(Collectors.toList()); List existStudents = welcomeStudentService.queryStudentByCardId(cardIds); if (existStudents != null && existStudents.size() > 0) { for (WelcomeStudent ws : result) { Optional ows = existStudents.stream().filter(e -> e.getCardId().equals(ws.getCardId())).findFirst(); if (ows != null && ows.isPresent()) { sb.append(ows.get().getName() + ows.get().getCardId() + "数据在数据库中已存在;"); ws.setId(ows.get().getId()); ws.setAdmissNum(ws.getAdmissNum());//录取号 ws.setName(ws.getName());//姓名 ws.setCardId(ws.getCardId());//身份证号 ws.setSchool(ws.getSchool());//校区 ws.setSchoolId(eSchool.stringOf(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()); ws.setIsPay(0); ws.setPicture("https://chtech.ncjti.edu.cn/welcome/homeimage/studentImage/" + ws.getCardId() + ".jpg"); } } } boolean resultBool = welcomeStudentService.saveOrUpdateBatch(result); System.out.println("导入学生1"); return resultBool ? CommonResult.ok("导入成功:" + sb.toString()) : CommonResult.fail("导入失败"); } /** * xls文件读取方法 * * @param inputStream * @return * @throws IOException * @throws ParseException */ private CommonResult> readXls(InputStream inputStream) throws IOException, ParseException { List result = new ArrayList<>(); HSSFWorkbook sheets = new HSSFWorkbook(inputStream); List ws = welcomeOrgService.list(null); List 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));//身份证号 //region 校验身份证号 并根据身份证号获取出生年月和性别 boolean isValidate = CardUtils.validateIdCard(cardId);//身份证是否合法 if (!isValidate) { return CommonResult.fail("录取编号为" + assNum + "的身份证不合法"); } String sex = CardUtils.getSexByIdCard(cardId); if (sex != null) { studentData.setSex(sex); } String birthday = CardUtils.getBirthdayByIdCard(cardId); if (birthday != null) { studentData.setBirthday(birthday); } //endregion studentData.setCardId(cardId); String school = dataFormatter.formatCellValue(row.getCell(4));//校区 studentData.setSchool(school); studentData.setSchoolId(eSchool.stringOf(school)); //region 院系专业 String college = dataFormatter.formatCellValue(row.getCell(5));//院系 Optional 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 omwo = ws.stream().filter(e -> owo != null && owo.isPresent() && e.getParentId().intValue() == owo.get().getId().intValue() && 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 ocwo = ws.stream().filter(e -> omwo != null && omwo.isPresent() && e.getParentId().intValue() == omwo.get().getId().intValue() && 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));//层次 if (!batchValue.equals("本科") && !batchValue.equals("专升本") && !batchValue.equals("专科")) { return CommonResult.fail("层次为本科或专升本或专科"); } 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 && StringUtils.hasText(nativePlace)) { if (!addressDatas[0].contains("省")) { return CommonResult.fail("录取编号为\" + assNum + \"的籍贯格式应该是 省/市/县"); } Optional 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 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 oProvince = citys.stream().filter(e -> e.getCityZh().equals(addressDatas[1]) && addressDatas[2].contains(e.getDistrictZh())).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 && StringUtils.hasText(addressPlace)) { if (!addressPlaces[0].contains("省")) { return CommonResult.fail("录取编号为" + assNum + "的家庭住址格式应该是 省/市/县区"); } Optional 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 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 oProvince = citys.stream().filter(e -> e.getCityZh().equals(addressPlaces[1]) && addressPlaces[2].contains(e.getDistrictZh())).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); studentData.setFillStatus("未填报"); studentData.setIsRegistered(2); studentData.setIsPay(0); //studentData.setPicture("https://chtech.ncjti.edu.cn/welcome/homeimage/newStudentHeadImage.jpg"); studentData.setPicture("https://chtech.ncjti.edu.cn/welcome/homeimage/studentImage/" + studentData.getCardId() + ".jpg"); result.add(studentData); } } } } catch (Exception e) { return CommonResult.fail("请按模板格式导入数据"); } return CommonResult.ok(result); } /** * xls文件读取方法 * * @param inputStream * @return * @throws IOException * @throws ParseException */ private CommonResult> readXlsx(InputStream inputStream) throws IOException, ParseException { List result = new ArrayList<>(); XSSFWorkbook sheets = new XSSFWorkbook(inputStream); List ws = welcomeOrgService.list(null); List 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));//身份证号 //region 校验身份证号 并根据身份证号获取出生年月和性别 boolean isValidate = CardUtils.validateIdCard(cardId);//身份证是否合法 if (!isValidate) { return CommonResult.fail("录取编号为" + assNum + "的身份证不合法"); } String sex = CardUtils.getSexByIdCard(cardId); if (sex != null) { studentData.setSex(sex); } String birthday = CardUtils.getBirthdayByIdCard(cardId); if (birthday != null) { studentData.setBirthday(birthday); } //endregion studentData.setCardId(cardId); String school = dataFormatter.formatCellValue(row.getCell(4));//校区 studentData.setSchool(school); studentData.setSchoolId(eSchool.stringOf(school)); //region 院系专业 String college = dataFormatter.formatCellValue(row.getCell(5));//院系 Optional 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 omwo = ws.stream().filter(e -> owo != null && owo.isPresent() && e.getParentId().intValue() == owo.get().getId().intValue() && 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 ocwo = ws.stream().filter(e -> omwo != null && omwo.isPresent() && e.getParentId().intValue() == omwo.get().getId().intValue() && 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));//层次 if (!batchValue.equals("本科") && !batchValue.equals("专升本") && !batchValue.equals("专科")) { return CommonResult.fail("层次为本科或专升本或专科"); } 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 && StringUtils.hasText(nativePlace)) { if (!addressDatas[0].contains("省")) { return CommonResult.fail("录取编号为\" + assNum + \"的籍贯格式应该是 省/市/县区"); } Optional 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 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 oProvince = citys.stream().filter(e -> e.getCityZh().equals(addressDatas[1]) && addressDatas[2].contains(e.getDistrictZh())).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 && StringUtils.hasText(addressPlace)) { if (!addressPlaces[0].contains("省")) { return CommonResult.fail("录取编号为" + assNum + "的家庭住址格式应该是 省/市/县区"); } Optional 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 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 oProvince = citys.stream().filter(e -> e.getCityZh().equals(addressPlaces[1]) && addressPlaces[2].contains(e.getDistrictZh())).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); studentData.setFillStatus("未填报"); studentData.setIsRegistered(2); studentData.setIsPay(0); //studentData.setPicture("https://chtech.ncjti.edu.cn/welcome/homeimage/newStudentHeadImage.jpg"); studentData.setPicture("https://chtech.ncjti.edu.cn/welcome/homeimage/studentImage/" + studentData.getCardId() + ".jpg"); 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/welcome/homeimage/学生信息管理.xlsx"); } @Override public void welcomeStudentExport(String userId, HttpServletResponse response, Integer collegeId, Integer majorId, Integer classstrId, String trafficMethod, String name, String fillStatus, Integer isRegistered, Integer isPay, Integer isCheck, String school, String batchValue, Integer carNumber, Integer yearId) throws ParseException { String nstartTime = null; String nendTime = null; boolean lastYear = TimeExchange.CompareDate(TimeExchange.getDate(), TimeExchange.getYear() + "-07-01", "yyyy-MM-dd"); if (yearId == null) { Integer yearInt = Integer.valueOf(TimeExchange.getYear()); //当前时间小于本年度的7月1日 说明要查去年的数据 if (lastYear) { nstartTime = (yearInt - 1) + "-06-01"; nendTime = yearInt + "-06-01"; } else { nstartTime = yearInt + "-06-01"; nendTime = (yearInt + 1) + "-06-01"; } } else { nstartTime = yearId + "-06-01"; nendTime = (yearId + 1) + "-06-01"; } Workbook workbook = new XSSFWorkbook(); Sheet sheet = workbook.createSheet("学生信息"); WelcomeAccount wa = welcomeAccountService.getManageById(userId); if (wa == null) { System.out.println("当前账户已失效,无权限查看"); ExcelUtils.excelDownload(workbook, "学生信息.xlsx", response); } List collegeIds = Arrays.asList(wa.getCollegeId().split(",")); if (collegeId != null && collegeId.intValue() > 0) { if (!collegeIds.contains(String.valueOf(collegeId))) { ExcelUtils.excelDownload(workbook, "学生信息.xlsx", response); } else { collegeIds = new ArrayList<>(); collegeIds.add(String.valueOf(collegeId)); } } List result = welcomeStudentService.queryStudentList(collegeIds, majorId, classstrId, trafficMethod, name, fillStatus, isRegistered, isPay, isCheck, school, batchValue, carNumber, nstartTime, nendTime); //导出 DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); DateTimeFormatter dateTimeFormatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd"); 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("应缴金额"); headerRow.createCell(14).setCellValue("实付金额"); headerRow.createCell(15).setCellValue("宿舍信息"); headerRow.createCell(16).setCellValue("学生手机号"); headerRow.createCell(17).setCellValue("家长名称"); headerRow.createCell(18).setCellValue("家长手机号"); headerRow.createCell(19).setCellValue("到站日期"); headerRow.createCell(20).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.getSex()); dataRow.createCell(3).setCellValue(studentData.getName()); dataRow.createCell(4).setCellValue(studentData.getCardId()); dataRow.createCell(5).setCellValue(studentData.getCollege()); dataRow.createCell(6).setCellValue(studentData.getMajor()); dataRow.createCell(7).setCellValue(studentData.getClassstr()); dataRow.createCell(8).setCellValue(studentData.getTrafficMethod()); dataRow.createCell(9).setCellValue(studentData.getArrive()); dataRow.createCell(10).setCellValue(studentData.getCarNumber()); dataRow.createCell(11).setCellValue(studentData.getAccompanyNum()); dataRow.createCell(12).setCellValue(studentData.getFillStatus()); dataRow.createCell(13).setCellValue(String.valueOf(studentData.getAmountPayable())); dataRow.createCell(14).setCellValue(String.valueOf(studentData.getPayAmount())); dataRow.createCell(15).setCellValue(studentData.getDormitory()); dataRow.createCell(16).setCellValue(studentData.getPhone()); dataRow.createCell(17).setCellValue(studentData.getFamilyName()); dataRow.createCell(18).setCellValue(studentData.getFamilyPhone()); if (ObjectUtils.isNotEmpty(studentData.getArrvieDate())) { String arrvieDate = LocalDateTime.parse(studentData.getArrvieDate(), dateTimeFormatter1).toLocalDate().format(dateTimeFormatter2); dataRow.createCell(19).setCellValue(arrvieDate); } String registered = "未报到"; if (ObjectUtils.isNotEmpty(studentData.getIsRegistered())) { Integer isRegistered1 = studentData.getIsRegistered(); if (isRegistered1 == 1) { registered = "已报到"; } else if (isRegistered1 == 2) { registered = "未报到"; } } dataRow.createCell(20).setCellValue(registered); } // 将工作簿写入文件 ExcelUtils.excelDownload(workbook, "学生信息.xlsx", response); } @Override public CommonResult studentOverview(Integer collegeId, Integer yearId) throws ParseException { String nstartTime = null; String nendTime = null; boolean lastYear = TimeExchange.CompareDate(TimeExchange.getDate(), TimeExchange.getYear() + "-07-01", "yyyy-MM-dd"); // 获取年份 String yearStr=""; if (yearId == null) { Integer yearInt = Integer.valueOf(TimeExchange.getYear()); //当前时间小于本年度的7月1日 说明要查去年的数据 if (lastYear) { yearStr=(yearInt - 1) +"级新生"; nstartTime = (yearInt - 1) + "-06-01"; nendTime = yearInt + "-06-01"; } else { yearStr=yearInt +"级新生"; nstartTime = yearInt + "-06-01"; nendTime = (yearInt + 1) + "-06-01"; } } else { yearStr=yearId +"级新生"; nstartTime = yearId + "-06-01"; nendTime = (yearId + 1) + "-06-01"; } //获取学生总数 int enrollmentTotal = welcomeStudentService.studentTotalCount(collegeId, nstartTime, nendTime); //录取总数 //LambdaQueryWrapper queryWrapper=new LambdaQueryWrapper<>(); //queryWrapper.eq(WelcomeStudent::getIdenType,1); //int enrollmentTotal = 8085;//welcomeStudentService.count(queryWrapper); //全部缴费人数 int payCount = welcomeStudentService.payCount(collegeId, nstartTime, nendTime); //全部缴费率 Double rate = enrollmentTotal <= 0 ? 0 : ((double) payCount / enrollmentTotal) * 100; String payRate = String.format("%.2f", rate); // 部分缴费人数,支付状态未缴费,并且实付金额大于0 int portionPayCount = welcomeStudentService.payPortionCount(collegeId, nstartTime, nendTime); // 部分缴费率 Double portionRate = enrollmentTotal <= 0 ? 0 : ((double) portionPayCount / enrollmentTotal) * 100; String portionPayRate = String.format("%.2f", portionRate); // 总缴费人数(包括部分缴费人数) int totalPayCount =payCount+portionPayCount; // 总缴费率(包括部分缴费) Double totalRate=enrollmentTotal <= 0 ? 0 : ((double) totalPayCount / enrollmentTotal) * 100; String totalPayRate = String.format("%.2f", totalRate); // 现场报到总人数 int registrationCount = welcomeStudentService.registrationCount(collegeId, nstartTime, nendTime); Double result = enrollmentTotal <= 0 ? 0 : ((double) registrationCount / enrollmentTotal) * 100; String registrationRate = String.format("%.2f", result); // 未报道人数 int notRegistrationCount=enrollmentTotal-registrationCount; // 已缴费但未现场报到人数 int payNotRegistrationCount=welcomeStudentService.payNotRegistrationCount(collegeId, nstartTime, nendTime); // 已缴费但未现场报到比率 Double payNotReportCountRate = enrollmentTotal <= 0 ? 0 : ((double) payNotRegistrationCount / enrollmentTotal) * 100; String payNotRegistrationRate = String.format("%.2f", payNotReportCountRate); //已入住寝室数 // LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); // wrapper.eq(WelcomeBed::getIsCheck, 1) // .eq(WelcomeBed::getRetentionState, 1) // .eq(ObjectUtils.isNotEmpty(collegeId), WelcomeBed::getCollegeId, collegeId); // wrapper.between(WelcomeBed::getCreateTime, nstartTime, nendTime); // int checkInBedTotal = welcomeBedService.count(wrapper); // Double result = enrollmentTotal <= 0 ? 0 : ((double) checkInBedTotal / enrollmentTotal) * 100; // String registrationRate = String.format("%.2f", result); 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"); String startTime = start.format(dateTimeFormatter1); String endTime = end.format(dateTimeFormatter1); Integer mVisitorTotal = welcomeVisitorService.countTotal(startTime, endTime, 1, nstartTime, nendTime); Integer hVisitorTotal = welcomeVisitorService.countTotal(startTime, endTime, 2, nstartTime, nendTime); List wss = welcomeSettingService.list(null); //墨轩湖总车辆数 Integer mCarTotal = wss != null && wss.size() > 0 ? (wss.get(0).getMxhCarNum() == null ? 0 : wss.get(0).getMxhCarNum()) : 0; //黄家湖总车辆数 Integer hCarTotal = wss != null && wss.size() > 0 ? (wss.get(0).getHjhCarNum() == null ? 0 : wss.get(0).getHjhCarNum()) : 0; StudentOverviewVo vo = new StudentOverviewVo(); // 总人数 vo.setEnrollmentTotal(enrollmentTotal); // 年份字段 vo.setYearStr(yearStr); // 现场报到人数 vo.setRegistrationCount(registrationCount); // 现场报到率 vo.setRegistrationRate(registrationRate); // 未报到人数 vo.setNotRegistrationCount(notRegistrationCount); // 总缴费人数(包括部分缴费) vo.setTotalPayCount(totalPayCount); // 总缴费率(包括部分缴费) vo.setTotalPayRate(totalPayRate); // 全部缴费人数 vo.setPayCount(payCount); // 全部缴费率 vo.setPayRate(payRate); // 部分缴费人数 vo.setPortionPayCount(portionPayCount); // 部分缴费率 vo.setPortionPayRate(portionPayRate); // 已缴费未报到人数 vo.setPayNotRegistrationCount(payNotRegistrationCount); // 已缴费未报到率 vo.setPayNotRegistrationRate(payNotRegistrationRate); // 黄家湖当日剩余总数 vo.setHCarTotal(hCarTotal - hVisitorTotal); // 黄家湖当日预定数 vo.setHVisitorTotal(hVisitorTotal); // 墨轩湖当日剩余数 vo.setMCarTotal(mCarTotal - mVisitorTotal); // 墨轩湖当日预定数 vo.setMVisitorTotal(mVisitorTotal); return CommonResult.ok(vo); } @Override public CommonResult studentRegister(Integer collegeId, Integer yearId) throws ParseException { String nstartTime = null; String nendTime = null; boolean lastYear = TimeExchange.CompareDate(TimeExchange.getDate(), TimeExchange.getYear() + "-07-01", "yyyy-MM-dd"); if (yearId == null) { Integer yearInt = Integer.valueOf(TimeExchange.getYear()); //当前时间小于本年度的7月1日 说明要查去年的数据 if (lastYear) { nstartTime = (yearInt - 1) + "-06-01"; nendTime = yearInt + "-06-01"; } else { nstartTime = yearInt + "-06-01"; nendTime = (yearInt + 1) + "-06-01"; } } else { nstartTime = yearId + "-06-01"; nendTime = (yearId + 1) + "-06-01"; } // 学生总数 int enrollmentTotal = welcomeStudentService.studentTotalCount(collegeId, nstartTime, nendTime); // 获取总数 Integer count = welcomeStudentService.totalCount(collegeId, nstartTime, nendTime); // 获取比例 Double result = enrollmentTotal <= 0 ? 0 : ((double) count / enrollmentTotal) * 100; String rate = String.format("%.2f", result); StudentRegisterVo vo = new StudentRegisterVo(); vo.setName("报到总数"); vo.setCount(count); vo.setRate(rate); vo.setTotalCount(enrollmentTotal); if (ObjectUtils.isNotEmpty(collegeId)) { List vos = welcomeStudentService.studentMajorRegister(collegeId, nstartTime, nendTime); vos.add(vo); return CommonResult.ok(vos); } else { List vos = welcomeStudentService.studentRegister(nstartTime, nendTime); vos.add(vo); return CommonResult.ok(vos); } } @Override public CommonResult studentTraffic(Integer collegeId, Integer yearId) throws ParseException { String nstartTime = null; String nendTime = null; boolean lastYear = TimeExchange.CompareDate(TimeExchange.getDate(), TimeExchange.getYear() + "-07-01", "yyyy-MM-dd"); if (yearId == null) { Integer yearInt = Integer.valueOf(TimeExchange.getYear()); //当前时间小于本年度的7月1日 说明要查去年的数据 if (lastYear) { nstartTime = (yearInt - 1) + "-06-01"; nendTime = yearInt + "-06-01"; } else { nstartTime = yearInt + "-06-01"; nendTime = (yearInt + 1) + "-06-01"; } } else { nstartTime = yearId + "-06-01"; nendTime = (yearId + 1) + "-06-01"; } List vos = welcomeStudentService.studentTraffic(collegeId, nstartTime, nendTime); return CommonResult.ok(vos); } @Override public CommonResult studentSexRatio(Integer yearId) throws ParseException { String nstartTime = null; String nendTime = null; boolean lastYear = TimeExchange.CompareDate(TimeExchange.getDate(), TimeExchange.getYear() + "-07-01", "yyyy-MM-dd"); if (yearId == null) { Integer yearInt = Integer.valueOf(TimeExchange.getYear()); //当前时间小于本年度的7月1日 说明要查去年的数据 if (lastYear) { nstartTime = (yearInt - 1) + "-06-01"; nendTime = yearInt + "-06-01"; } else { nstartTime = yearInt + "-06-01"; nendTime = (yearInt + 1) + "-06-01"; } } else { nstartTime = yearId + "-06-01"; nendTime = (yearId + 1) + "-06-01"; } Integer manCount = welcomeStudentService.genderCount("男"); Integer girlCount = welcomeStudentService.genderCount("女"); StudentSexRatioVo vo = new StudentSexRatioVo(); vo.setCollegeName("全部"); vo.setManCount(manCount); vo.setGirlCount(girlCount); List vos = welcomeStudentService.studentSexRatio(nstartTime, nendTime); vos.add(vo); return CommonResult.ok(vos); } @Override public CommonResult studentStay(Integer yearId) throws ParseException { String nstartTime = null; String nendTime = null; boolean lastYear = TimeExchange.CompareDate(TimeExchange.getDate(), TimeExchange.getYear() + "-07-01", "yyyy-MM-dd"); if (yearId == null) { Integer yearInt = Integer.valueOf(TimeExchange.getYear()); //当前时间小于本年度的7月1日 说明要查去年的数据 if (lastYear) { nstartTime = (yearInt - 1) + "-06-01"; nendTime = yearInt + "-06-01"; } else { nstartTime = yearInt + "-06-01"; nendTime = (yearInt + 1) + "-06-01"; } } else { nstartTime = yearId + "-06-01"; nendTime = (yearId + 1) + "-06-01"; } ArrayList vos = new ArrayList<>(); List list = welcomeSchoolService.list(new QueryWrapper<>()); for (WelcomeSchool welcomeSchool : list) { Integer schoolId = welcomeSchool.getId(); List 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) throws ParseException { WelcomeStudent student = welcomeStudentService.getManageById(Integer.valueOf(userId)); if (student == null) { return CommonResult.fail("558", "学生信息已失效,查询失败"); } //家庭成员 List fvs = new ArrayList<>(); List familys = welcomeFamilyService.getManageByCardId(student.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); } } student.setFvs(fvs); //陪同人员 List avs = new ArrayList<>(); List accompanys = welcomeAccompanyService.getManageByCardId(student.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); } } student.setAvs(avs); //时间段 List atvs = new ArrayList<>(); List 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((student.getArriveTimeId() != null && was.getId().equals(student.getArriveTimeId())) ? 1 : 0); atvs.add(atv); } } student.setAtvs(atvs); if (!(student.getIsPay() != null && student.getIsPay().intValue() == 1)) { List payInfos = WelcomePayController.queryStudentPayInfo(student.getAdmissNum(), TimeExchange.getYear()); BigDecimal payAmount = new BigDecimal(BigInteger.ZERO);//实缴金额 BigDecimal yjPayAmount = new BigDecimal(BigInteger.ZERO);//应缴金额 BigDecimal dkAmount = new BigDecimal(BigInteger.ZERO);//贷款金额 for (JsonPayVo pi : payInfos) { dkAmount = dkAmount.add(pi.getDKJE()); payAmount = payAmount.add(pi.getSJJE()); yjPayAmount = yjPayAmount.add(pi.getYJJE()); } BigDecimal studentPay = payAmount.add(dkAmount); student.setPayAmount(studentPay); student.setAmountPayable(yjPayAmount); System.out.println("进支付比较1" + JSON.toJSON(payInfos)); if (payInfos != null && payInfos.size() > 0) { System.out.println("进支付比较2"); String nstartTime = null; String nendTime = null; boolean lastYear = TimeExchange.CompareDate(TimeExchange.getDate(), TimeExchange.getYear() + "-07-01", "yyyy-MM-dd"); Integer yearInt = Integer.valueOf(TimeExchange.getYear()); //当前时间小于本年度的7月1日 说明要查去年的数据 if (lastYear) { nstartTime = (yearInt - 1) + "-06-01"; nendTime = yearInt + "-06-01"; } else { nstartTime = yearInt + "-06-01"; nendTime = (yearInt + 1) + "-06-01"; } WelcomePaySetting paySettings = welcomePaySettingService.queryPaySettingById(student.getCollegeId(), student.getMajorId(), student.getBatchValue(), nstartTime, nendTime); System.out.println("进支付比较3" + JSON.toJSON(paySettings)); if (paySettings != null) { System.out.println("进支付比较4"); if (studentPay.compareTo(paySettings.getPayAmount()) >= 0) { student.setIsPay(1); } else { student.setIsPay(0); } } else { student.setIsPay(0); } } else { student.setIsPay(0); } if (payInfos != null && payInfos.size() > 0) { int update = welcomeStudentService.updateWelcomeStudent(student); if (update < 0) { logger.error("获取支付信息导致学校信息查询失败"); return CommonResult.fail("查询失败"); } } } if (student.getIsPay() == null) { student.setIsPay(0); } long expired = 1000 * 60 * 60 * 24 * 365; TokenDateVo token = JWTUtil.getToken(student.getCardId(), student.getId(), expired); student.setToken(token.getToken()); return CommonResult.ok(student); } @Override public CommonResult queryStudentInfo(String admissNum) throws ParseException { WelcomeStudent ws = welcomeStudentService.getDataByNum(admissNum); if (ws == null) { return CommonResult.fail("558", "当前学生信息已失效,查询失败"); } //家庭成员 List fvs = new ArrayList<>(); List 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); } } ws.setFvs(fvs); //陪同人员 List avs = new ArrayList<>(); List 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); } } ws.setAvs(avs); //时间段 List atvs = new ArrayList<>(); List 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); } } ws.setAtvs(atvs); List pdvs = new ArrayList<>(); System.out.println("进支付比较"); List payInfos = WelcomePayController.queryStudentPayInfo(ws.getAdmissNum(), TimeExchange.getYear()); BigDecimal payAmount = new BigDecimal(BigInteger.ZERO);//实缴金额 BigDecimal yjPayAmount = new BigDecimal(BigInteger.ZERO);//应缴金额 BigDecimal dkAmount = new BigDecimal(BigInteger.ZERO);//贷款金额 for (JsonPayVo pi : payInfos) { dkAmount = dkAmount.add(pi.getDKJE()); payAmount = payAmount.add(pi.getSJJE()); yjPayAmount = yjPayAmount.add(pi.getYJJE()); PayDetailVO pdv = new PayDetailVO(); pdv.setPayName(pi.getSFXMMC()); pdv.setYJJE(pi.getYJJE()); pdv.setSJJE(pi.getSJJE()); pdvs.add(pdv); } BigDecimal studentPay = payAmount.add(dkAmount); ws.setPayAmount(studentPay); ws.setAmountPayable(yjPayAmount); System.out.println("进支付比较1" + JSON.toJSON(payInfos)); if (payInfos != null && payInfos.size() > 0) { System.out.println("进支付比较2"); String nstartTime = null; String nendTime = null; boolean lastYear = TimeExchange.CompareDate(TimeExchange.getDate(), TimeExchange.getYear() + "-07-01", "yyyy-MM-dd"); Integer yearInt = Integer.valueOf(TimeExchange.getYear()); //当前时间小于本年度的7月1日 说明要查去年的数据 if (lastYear) { nstartTime = (yearInt - 1) + "-06-01"; nendTime = yearInt + "-06-01"; } else { nstartTime = yearInt + "-06-01"; nendTime = (yearInt + 1) + "-06-01"; } WelcomePaySetting paySettings = welcomePaySettingService.queryPaySettingById(ws.getCollegeId(), ws.getMajorId(), ws.getBatchValue(), nstartTime, nendTime); System.out.println("进支付比较3" + JSON.toJSON(paySettings)); if (paySettings != null) { System.out.println("进支付比较4"); if (studentPay.compareTo(paySettings.getPayAmount()) >= 0) { ws.setIsPay(1); } else { ws.setIsPay(0); } } else { ws.setIsPay(0); } } else { ws.setIsPay(0); } if (ws.getIsPay() == null) { ws.setIsPay(0); } if (!(ws.getIsPay() != null && ws.getIsPay().intValue() == 1)) { int updateResult = welcomeStudentService.updateWelcomeStudent(ws); if (updateResult < 0) { return CommonResult.fail("查询支付信息失败"); } } PayInfoVO result = new PayInfoVO(); result.setId(ws.getId()); result.setName(ws.getName()); result.setAdmissNum(ws.getAdmissNum()); result.setIsPay(ws.getIsPay()); result.setPays(pdvs); return CommonResult.ok(result); } @Override @AWelcomeLog("学生报到") @AWelcomeTypeLog("编辑") @AWelcomeLogMode("学生信息管理") @AWelcomeLevelLog("信息") public CommonResult isRegistered(WelcomeStudent welcomeStudent) { boolean update = welcomeStudentService.updateById(welcomeStudent); return update ? CommonResult.ok() : CommonResult.fail(); } @Override public CommonResult levelRegister(Integer collegeId, Integer yearId) throws ParseException { String nstartTime = null; String nendTime = null; boolean lastYear = TimeExchange.CompareDate(TimeExchange.getDate(), TimeExchange.getYear() + "-07-01", "yyyy-MM-dd"); if (yearId == null) { Integer yearInt = Integer.valueOf(TimeExchange.getYear()); //当前时间小于本年度的7月1日 说明要查去年的数据 if (lastYear) { nstartTime = (yearInt - 1) + "-06-01"; nendTime = yearInt + "-06-01"; } else { nstartTime = yearInt + "-06-01"; nendTime = (yearInt + 1) + "-06-01"; } } else { nstartTime = yearId + "-06-01"; nendTime = (yearId + 1) + "-06-01"; } // 获取学生总数 int enrollmentTotal = welcomeStudentService.studentTotalCount(collegeId, nstartTime, nendTime); // 获取报到总数 Integer count = welcomeStudentService.totalCount(collegeId, nstartTime, nendTime); // 获取比例 Double result = ((double) count / enrollmentTotal) * 100; String rate = String.format("%.2f", result); StudentRegisterVo vo = new StudentRegisterVo(); vo.setName("报到总数"); vo.setCount(count); vo.setRate(rate); vo.setTotalCount(enrollmentTotal); String bk = "本科"; String zsb = "专升本"; String zk = "专科"; // 获取总本科人数 Integer bkCount = welcomeStudentService.getLevelTotalCount(bk, collegeId, nstartTime, nendTime); // 获取总专升本人数 Integer zsbCount = welcomeStudentService.getLevelTotalCount(zsb, collegeId, nstartTime, nendTime); // 获取总专科人数 Integer zkCount = welcomeStudentService.getLevelTotalCount(zk, collegeId, nstartTime, nendTime); List vos = welcomeStudentService.levelRegister(collegeId, nstartTime, nendTime); HashMap map = new HashMap<>(); for (StudentRegisterVo studentRegisterVo : vos) { Integer count1 = studentRegisterVo.getCount(); if (studentRegisterVo.getName().equals(bk)) { Double result1 = ((double) count1 / bkCount) * 100; String rate1 = String.format("%.2f", result1); studentRegisterVo.setRate(rate1); studentRegisterVo.setTotalCount(bkCount); } else if (studentRegisterVo.getName().equals(zsb)) { Double result1 = ((double) count1 / zsbCount) * 100; String rate1 = String.format("%.2f", result1); studentRegisterVo.setRate(rate1); studentRegisterVo.setTotalCount(zsbCount); } else if (studentRegisterVo.getName().equals(zk)) { Double result1 = ((double) count1 / zkCount) * 100; String rate1 = String.format("%.2f", result1); studentRegisterVo.setRate(rate1); studentRegisterVo.setTotalCount(zkCount); } map.put(studentRegisterVo.getName(), studentRegisterVo); } if (!map.containsKey("本科")) { StudentRegisterVo vo1 = new StudentRegisterVo(); vo1.setName("本科"); vo1.setCount(0); vo1.setRate("0.00"); vo1.setTotalCount(bkCount); vos.add(vo1); } if (!map.containsKey("专升本")) { StudentRegisterVo vo2 = new StudentRegisterVo(); vo2.setName("专升本"); vo2.setCount(0); vo2.setRate("0.00"); vo2.setTotalCount(zsbCount); vos.add(vo2); } if (!map.containsKey("专科")) { StudentRegisterVo vo3 = new StudentRegisterVo(); vo3.setName("专科"); vo3.setCount(0); vo3.setRate("0.00"); vo3.setTotalCount(zkCount); vos.add(vo3); } vos.add(vo); return CommonResult.ok(vos); } }