diff --git a/src/main/java/cn/com/tenlion/controller/api/applystudents/ApplyStudentsController.java b/src/main/java/cn/com/tenlion/controller/api/applystudents/ApplyStudentsController.java index 81f2a60..3e0a251 100644 --- a/src/main/java/cn/com/tenlion/controller/api/applystudents/ApplyStudentsController.java +++ b/src/main/java/cn/com/tenlion/controller/api/applystudents/ApplyStudentsController.java @@ -1,7 +1,14 @@ package cn.com.tenlion.controller.api.applystudents; +import cn.com.tenlion.listener.ImportExcelListener; +import cn.com.tenlion.pojo.dtos.excel.ImportFailDto; +import cn.com.tenlion.pojo.model.ApplyStudentsModel; +import cn.com.tenlion.service.handleimportexcel.IHandleImportExcelService; +import cn.com.tenlion.util.ExcelUtil; +import com.alibaba.excel.EasyExcel; import ink.wgink.annotation.CheckRequestBodyAnnotation; import ink.wgink.common.base.DefaultBaseController; +import ink.wgink.exceptions.SearchException; import ink.wgink.interfaces.consts.ISystemConstant; import ink.wgink.pojo.ListPage; import ink.wgink.pojo.result.ErrorResult; @@ -12,9 +19,15 @@ import cn.com.tenlion.pojo.dtos.applystudents.ApplyStudentsDTO; import cn.com.tenlion.pojo.vos.applystudents.ApplyStudentsVO; import cn.com.tenlion.service.applystudents.IApplyStudentsService; import io.swagger.annotations.*; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.net.URLEncoder; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -33,6 +46,9 @@ public class ApplyStudentsController extends DefaultBaseController { @Autowired private IApplyStudentsService applyStudentsService; + @Autowired + private IHandleImportExcelService handleImportExcelService; + private List failDtoList; @ApiOperation(value = "获取班级学生列表", notes = "获取班级学生列表接口") @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @@ -117,4 +133,87 @@ public class ApplyStudentsController extends DefaultBaseController { return new SuccessResultData<>(applyStudentsService.count(params)); } + @ApiOperation(value = "导入考试成绩", notes = "导入考试成绩接口") + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @PostMapping("importexcel") + public SuccessResultData importExcel(@RequestParam("file") MultipartFile file, HttpServletResponse response) throws Exception { + ImportExcelListener listener = new ImportExcelListener(handleImportExcelService, ApplyStudentsModel.class); + // 读取数据 + ExcelUtil.readExcel(file, 0, 1, listener, ApplyStudentsModel.class); + // 错误集 + List importFailDtoList = listener.getImportFailDtoList(); + if(!importFailDtoList.isEmpty()) { + failDtoList = importFailDtoList; + return new SuccessResultData(importFailDtoList.size()); + } + return new SuccessResultData("success"); + } + + @ApiOperation(value = "导出考试成绩失败信息", notes = "导入考试成绩失败接口") + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("exportexcel") + public void exportExcel(HttpServletResponse response) throws IOException { + String excelName = "学员成绩失败数据"; + String fileName = URLEncoder.encode(excelName, "UTF-8"); + response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); + + String [] headers = {"班号", "姓名", "考生身份证号码", "成绩", "失败原因"}; + List> listHeader = new ArrayList<>(); + for(String item : headers) { + List title = new ArrayList<>(); + title.add(item); + listHeader.add(title); + } + + List> listData = new ArrayList<>(); + for (ImportFailDto dto : failDtoList) { + List data = new ArrayList<>(); + ApplyStudentsModel applyStudentsModel = new ApplyStudentsModel(); + BeanUtils.copyProperties(dto.getObject(), applyStudentsModel); + data.add(applyStudentsModel.getPlanNumber()); + data.add(applyStudentsModel.getUserName()); + data.add(applyStudentsModel.getCardNumber()); + data.add(applyStudentsModel.getScore()); + data.add(dto.getErrMsg()); + listData.add(data); + } + EasyExcel.write(response.getOutputStream()).sheet("学员成绩导入失败数据").head(listHeader).doWrite(listData); + } + + @ApiOperation(value = "导出考试成绩失败信息", notes = "导入考试成绩失败接口") + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("export-excel-more") + public void exportExcelMore(HttpServletResponse response) throws IOException { + Map params = requestParams(); + String excelName = "学员成绩数据"; + String fileName = URLEncoder.encode(excelName, "UTF-8"); + response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); + + String [] headers = {"班号", "姓名", "考生身份证号码", "考试机构", "考试开始时间", "考试结束时间", "成绩", "失败原因"}; + List> listHeader = new ArrayList<>(); + for(String item : headers) { + List title = new ArrayList<>(); + title.add(item); + listHeader.add(title); + } + + List applyStudentsDTOS = applyStudentsService.list(params); + if(null == applyStudentsDTOS || applyStudentsDTOS.size() <= 0) { + throw new SearchException("暂无数据,导出失败"); + } + List> listData = new ArrayList<>(); + for (ApplyStudentsDTO dto : applyStudentsDTOS) { + List data = new ArrayList<>(); + data.add(dto.getClassPlanDTO().getPlanNumber()); + data.add(dto.getApplyName()); + data.add(dto.getApplyCardNumber()); + data.add(dto.getClassPlanDTO().getOrgName()); + data.add(dto.getExamStartTime()); + data.add(dto.getExamEndTime()); + data.add(dto.getApplyTestScores()); + listData.add(data); + } + EasyExcel.write(response.getOutputStream()).sheet("学员成绩数据").head(listHeader).doWrite(listData); + } + } \ No newline at end of file diff --git a/src/main/java/cn/com/tenlion/controller/route/indexweb/IndexWebController.java b/src/main/java/cn/com/tenlion/controller/route/indexweb/IndexWebController.java index fba2a0d..6925f5f 100644 --- a/src/main/java/cn/com/tenlion/controller/route/indexweb/IndexWebController.java +++ b/src/main/java/cn/com/tenlion/controller/route/indexweb/IndexWebController.java @@ -36,6 +36,8 @@ public class IndexWebController extends DefaultBaseController { private final static String ROLE_CODE_2 = "0002"; /*考试机构角色*/ private final static String ROLE_CODE_3 = "0003"; + /*考试中心角色*/ + private final static String ROLE_CODE_4 = "0004"; @ApiOperation(value = "角色统计页面", notes = "角色统计页面接口") @@ -60,6 +62,10 @@ public class IndexWebController extends DefaultBaseController { mv.setViewName("index3"); break; } + if (ROLE_CODE_4.equals(role.getRoleCode())){ + mv.setViewName("index4"); + break; + } } return mv; } diff --git a/src/main/java/cn/com/tenlion/dao/excel/IExcelDao.java b/src/main/java/cn/com/tenlion/dao/excel/IExcelDao.java new file mode 100644 index 0000000..7a31fcd --- /dev/null +++ b/src/main/java/cn/com/tenlion/dao/excel/IExcelDao.java @@ -0,0 +1,38 @@ +package cn.com.tenlion.dao.excel; + +import cn.com.tenlion.pojo.dtos.excel.ExcelDTO; +import ink.wgink.exceptions.SearchException; +import org.springframework.stereotype.Repository; + +import java.util.Map; + +/** + * @ClassName: IExcelDao + * @Description: 导入excel时相关操作 + * @Author: renpc + * @Date: 2021-02-28 15:38 + * @Version: 1.0 + **/ +@Repository +public interface IExcelDao { + + /** + * 字段比对数据库(字典) + * + * @param params + * @return + * @throws SearchException + */ + ExcelDTO checkDataFromDict(Map params) throws SearchException; + + /** + * 字段比对数据库(区域) + * + * @param params + * @return + * @throws SearchException + */ + ExcelDTO checkDataFromArea(Map params) throws SearchException; + + +} \ No newline at end of file diff --git a/src/main/java/cn/com/tenlion/listener/ImportExcelListener.java b/src/main/java/cn/com/tenlion/listener/ImportExcelListener.java new file mode 100644 index 0000000..7a8c5da --- /dev/null +++ b/src/main/java/cn/com/tenlion/listener/ImportExcelListener.java @@ -0,0 +1,216 @@ +package cn.com.tenlion.listener; + +import cn.com.tenlion.pojo.dtos.excel.ImportFailDto; +import cn.com.tenlion.pojo.dtos.excel.ImportSuccessDto; +import cn.com.tenlion.pojo.model.ApplyStudentsModel; +import cn.com.tenlion.service.handleimportexcel.IHandleImportExcelService; +import cn.com.tenlion.util.ImportExcelHelper; +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.context.AnalysisContext; +import com.alibaba.excel.event.AnalysisEventListener; +import com.alibaba.excel.exception.ExcelAnalysisException; + +import java.lang.reflect.Field; +import java.util.*; +import java.util.stream.Collectors; + +/** + * 导入excel的监听处理类 + * @author renpc + */ +public class ImportExcelListener extends AnalysisEventListener{ + + private static final int BATCH_COUNT = 1000; + + /** + * 导入成功的数据 + */ + private List importSuccessDtoList = new ArrayList<>(); + /** + * 导入失败的数据 + */ + private List importFailDtoList = new ArrayList<>(); + + /** + * 保存数据库专用list + */ + private List list = new ArrayList<>(); + + /** + * 去重专用list + */ + private List listForDistinct = new ArrayList<>(); + + /** + * 处理导入数据的逻辑 + */ + private IHandleImportExcelService handleImportExcelService; + + private Class tClass; + + public List getImportSuccessDtoList() { + return importSuccessDtoList; + } + + public void setImportSuccessDtoList(List importSuccessDtoList) { + this.importSuccessDtoList = importSuccessDtoList; + } + + public List getImportFailDtoList() { + return importFailDtoList; + } + + public void setImportFailDtoList(List importFailDtoList) { + this.importFailDtoList = importFailDtoList; + } + + public List getList() { + return list; + } + + public void setList(List list) { + this.list = list; + } + + public IHandleImportExcelService getHandleImportExcelService() { + return handleImportExcelService; + } + + public void setHandleImportExcelService(IHandleImportExcelService handleImportExcelService) { + this.handleImportExcelService = handleImportExcelService; + } + + public Class gettClass() { + return tClass; + } + + public void settClass(Class tClass) { + this.tClass = tClass; + } + + public ImportExcelListener(IHandleImportExcelService handleImportExcelService) { + this.handleImportExcelService = handleImportExcelService; + } + + public ImportExcelListener(IHandleImportExcelService handleImportExcelService, Class tClass) { + this.handleImportExcelService = handleImportExcelService; + this.tClass = tClass; + } + + /** + * 导入数据的处理逻辑 + * @param t + * @param analysisContext + */ + @Override + public void invoke(T t, AnalysisContext analysisContext) { + // 错误提示 + String msg = ""; + try { + msg = ImportExcelHelper.checkDataValid(t); + }catch (Exception e){ + msg = "存在空数据"; + e.printStackTrace(); + } + + // 如果校验失败 + if(msg.length() != 0){ + ImportFailDto importFailDto = new ImportFailDto(t, msg); + importFailDtoList.add(importFailDto); + }else{ + ImportExcelHelper.checkDataFromDatabase(t); + list.add(t); + listForDistinct.add(t); + } + + if(list.size() > BATCH_COUNT){ + try { + insertData(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + /** + * 所有数据处理完之后的处理方法 + * @param analysisContext + */ + @Override + public void doAfterAllAnalysed(AnalysisContext analysisContext) { + // PS:之所以最后这里还进行处理是防止最后一次的数据量没有达到批量值 + if(list.size() > 0) { + try { + insertData(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + /** + * 校验导入的表格的头是否匹配 + * @param headMap + * @param analysisContext + */ + @Override + public void invokeHeadMap(Map headMap, AnalysisContext analysisContext){ + super.invokeHeadMap(headMap, analysisContext); + if(tClass != null){ + try { + // 获取Excel导入实体的单元格内容 + Map indexNameMap = getIndexName(tClass); + Set keySet = indexNameMap.keySet(); + for (Integer key: keySet) { + // 头表是否存在空值 + if(headMap.get(key).length() == 0){ + throw new ExcelAnalysisException("Excel格式非法"); + } + // 对比导入Excel实体模板和当前上传Excel是否匹配 + /*if(!headMap.get(key).equals(indexNameMap.get(key))){ + throw new ExcelAnalysisException("Excel格式非法"); + }*/ + } + }catch (Exception e){ + e.printStackTrace(); + } + } + } + + private Map getIndexName(Class tClass) throws NoSuchFieldException { + Map result = new HashMap<>(); + Field[] declaredFields = tClass.getDeclaredFields(); + for (Field currentField: declaredFields) { + currentField.setAccessible(true); + ExcelProperty annotation = currentField.getAnnotation(ExcelProperty.class); + if(annotation != null){ + int index =annotation.index(); + String[] value = annotation.value(); + StringBuilder sb = new StringBuilder(); + for (String cur : value) { + sb.append(cur); + } + result.put(index, sb.toString()); + } + } + return result; + } + + /** + * 将数据插入数据库操作 + */ + private void insertData() throws Exception { + String value = ""; + // 出租房 + if(list.get(0) instanceof ApplyStudentsModel) { + List applyStudentsModelList = (List) list; + handleImportExcelService.updateApplyStudents(applyStudentsModelList, importFailDtoList); + } + listForDistinct.clear(); + list.clear(); + } + + +} \ No newline at end of file diff --git a/src/main/java/cn/com/tenlion/pojo/dtos/excel/ExcelDTO.java b/src/main/java/cn/com/tenlion/pojo/dtos/excel/ExcelDTO.java new file mode 100644 index 0000000..fb2d0f9 --- /dev/null +++ b/src/main/java/cn/com/tenlion/pojo/dtos/excel/ExcelDTO.java @@ -0,0 +1,57 @@ +package cn.com.tenlion.pojo.dtos.excel; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +/** + * + * @ClassName: ExcelDTO + * @Description: 导入excel相关DTO + * @Author: renpc + * @Date: 2021-02-28 15:38 + * @Version: 1.0 + **/ +@ApiModel +public class ExcelDTO { + + @ApiModelProperty(name = "dictId", value = "字典表ID") + private String dictId; + @ApiModelProperty(name = "dictName", value = "字典表名称") + private String dictName; + @ApiModelProperty(name = "areaId", value = "区域表ID") + private String areaId; + @ApiModelProperty(name = "areaName", value = "字典表名称") + private String areaName; + + public String getDictId() { + return dictId == null ? "" : dictId; + } + + public void setDictId(String dictId) { + this.dictId = dictId; + } + + public String getDictName() { + return dictName == null ? "" : dictName; + } + + public void setDictName(String dictName) { + this.dictName = dictName; + } + + public String getAreaId() { + return areaId == null ? "" : areaId; + } + + public void setAreaId(String areaId) { + this.areaId = areaId; + } + + public String getAreaName() { + return areaName == null ? "" : areaName; + } + + public void setAreaName(String areaName) { + this.areaName = areaName; + } +} diff --git a/src/main/java/cn/com/tenlion/pojo/dtos/excel/ImportFailDto.java b/src/main/java/cn/com/tenlion/pojo/dtos/excel/ImportFailDto.java new file mode 100644 index 0000000..eb2309b --- /dev/null +++ b/src/main/java/cn/com/tenlion/pojo/dtos/excel/ImportFailDto.java @@ -0,0 +1,40 @@ +package cn.com.tenlion.pojo.dtos.excel; + +import java.io.Serializable; + +/** + * 批量导入失败实体类 + * @author renpc + */ +public class ImportFailDto implements Serializable { + + /** + *导入实体信息 + */ + private Object object; + /** + * 导入错误提示 + */ + private String errMsg; + + public ImportFailDto(Object object, String errMsg) { + this.object = object; + this.errMsg = errMsg; + } + + public Object getObject() { + return object; + } + + public void setObject(Object object) { + this.object = object; + } + + public String getErrMsg() { + return errMsg == null ? "" : errMsg; + } + + public void setErrMsg(String errMsg) { + this.errMsg = errMsg; + } +} diff --git a/src/main/java/cn/com/tenlion/pojo/dtos/excel/ImportResultDto.java b/src/main/java/cn/com/tenlion/pojo/dtos/excel/ImportResultDto.java new file mode 100644 index 0000000..9adfac1 --- /dev/null +++ b/src/main/java/cn/com/tenlion/pojo/dtos/excel/ImportResultDto.java @@ -0,0 +1,53 @@ +package cn.com.tenlion.pojo.dtos.excel; + +import java.util.ArrayList; +import java.util.List; + +/** + * 批量导入结果实体类 + * @author renpc + */ +public class ImportResultDto { + + /** + * 导入成功的消息列表 + */ + private List successDtoList; + + /** + * 导入失败的消息列表 + */ + private List failDtoList; + + public ImportResultDto(List successDtoList, List failDtoList) { + this.successDtoList = successDtoList; + this.failDtoList = failDtoList; + } + + public ImportResultDto(List failDtoList) { + this.failDtoList = failDtoList; + this.successDtoList = new ArrayList<>(); + } + + public List getSuccessDtoList() { + if (successDtoList == null) { + return new ArrayList<>(); + } + return successDtoList; + } + + public void setSuccessDtoList(List successDtoList) { + this.successDtoList = successDtoList; + } + + public List getFailDtoList() { + if (failDtoList == null) { + return new ArrayList<>(); + } + return failDtoList; + } + + public void setFailDtoList(List failDtoList) { + this.failDtoList = failDtoList; + } +} diff --git a/src/main/java/cn/com/tenlion/pojo/dtos/excel/ImportSuccessDto.java b/src/main/java/cn/com/tenlion/pojo/dtos/excel/ImportSuccessDto.java new file mode 100644 index 0000000..4b6862d --- /dev/null +++ b/src/main/java/cn/com/tenlion/pojo/dtos/excel/ImportSuccessDto.java @@ -0,0 +1,17 @@ +package cn.com.tenlion.pojo.dtos.excel; + +import java.io.Serializable; + +/** + * 批量导入成功实体类 + * @author renpc + */ +public class ImportSuccessDto implements Serializable { + + private Object object; + + public ImportSuccessDto(Object object) { + this.object = object; + } + +} diff --git a/src/main/java/cn/com/tenlion/pojo/model/ApplyStudentsModel.java b/src/main/java/cn/com/tenlion/pojo/model/ApplyStudentsModel.java new file mode 100644 index 0000000..2db5c09 --- /dev/null +++ b/src/main/java/cn/com/tenlion/pojo/model/ApplyStudentsModel.java @@ -0,0 +1,53 @@ +package cn.com.tenlion.pojo.model; + +import com.alibaba.excel.annotation.ExcelProperty; +import io.swagger.annotations.ApiModel; + +/** + * @author 29492 + * 考生成绩 + */ +@ApiModel +public class ApplyStudentsModel { + + @ExcelProperty(index = 0) + private String planNumber; + @ExcelProperty(index = 1) + private String userName; + @ExcelProperty(index = 2) + private String cardNumber; + @ExcelProperty(index = 3) + private String score; + + public String getPlanNumber() { + return planNumber; + } + + public void setPlanNumber(String planNumber) { + this.planNumber = planNumber; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public String getCardNumber() { + return cardNumber; + } + + public void setCardNumber(String cardNumber) { + this.cardNumber = cardNumber; + } + + public String getScore() { + return score; + } + + public void setScore(String score) { + this.score = score; + } +} diff --git a/src/main/java/cn/com/tenlion/service/applystudents/impl/ApplyStudentsServiceImpl.java b/src/main/java/cn/com/tenlion/service/applystudents/impl/ApplyStudentsServiceImpl.java index 9c0828d..a7869f7 100644 --- a/src/main/java/cn/com/tenlion/service/applystudents/impl/ApplyStudentsServiceImpl.java +++ b/src/main/java/cn/com/tenlion/service/applystudents/impl/ApplyStudentsServiceImpl.java @@ -7,6 +7,7 @@ import cn.com.tenlion.pojo.bos.applystudents.ApplyStudentsBO; import cn.com.tenlion.pojo.dtos.applystudents.ApplyStudentsDTO; import cn.com.tenlion.pojo.dtos.classplan.ClassPlanDTO; import cn.com.tenlion.pojo.dtos.examapply.ExamApplyDTO; +import cn.com.tenlion.pojo.dtos.worktype.WorkTypeDTO; import cn.com.tenlion.pojo.pos.apply.ApplyPO; import cn.com.tenlion.pojo.pos.applystudents.ApplyStudentsPO; import cn.com.tenlion.pojo.vos.applystudents.ApplyStudentsVO; @@ -14,6 +15,7 @@ import cn.com.tenlion.service.apply.IApplyService; import cn.com.tenlion.service.applystudents.IApplyStudentsService; import cn.com.tenlion.service.classplan.IClassPlanService; import cn.com.tenlion.service.examapply.IExamApplyService; +import cn.com.tenlion.service.worktype.IWorkTypeService; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import ink.wgink.common.base.DefaultBaseService; @@ -27,10 +29,7 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * @ClassName: ApplyStudentsServiceImpl @@ -52,6 +51,8 @@ public class ApplyStudentsServiceImpl extends DefaultBaseService implements IApp private IInstitutionService iInstitutionService; @Autowired private IExamApplyService examApplyService; + @Autowired + private IWorkTypeService workTypeService; public String saveRelationReturnId(ApplyStudentsVO applyStudentsVO){ @@ -95,10 +96,6 @@ public class ApplyStudentsServiceImpl extends DefaultBaseService implements IApp return this.list(params); } - - - - @Override public void save(ApplyStudentsVO applyStudentsVO) { saveReturnId(applyStudentsVO); @@ -207,16 +204,35 @@ public class ApplyStudentsServiceImpl extends DefaultBaseService implements IApp @Override public List list(Map params) { + ClassPlanDTO searchClassPlanDto = null; + if(!com.alibaba.excel.util.StringUtils.isEmpty(params.get("planNumber"))) { + searchClassPlanDto = classPlanService.get(params); + } + if(null != searchClassPlanDto) { + params.remove("keywords"); + } List list = applyStudentsDao.list(params); if(null != list && list.size() > 0) { - for(ApplyStudentsDTO applyStudentsDTO: list) { + Iterator applyStudentsDTOIterator = list.iterator(); + while (applyStudentsDTOIterator.hasNext()) { + ApplyStudentsDTO applyStudentsDTO = applyStudentsDTOIterator.next(); + if(null != searchClassPlanDto) { + if(!searchClassPlanDto.getClassPlanId().equals(applyStudentsDTO.getApplyClassId())) { + applyStudentsDTOIterator.remove(); + continue; + } + } ClassPlanDTO classPlanDTO = classPlanService.get(applyStudentsDTO.getApplyClassId()); applyStudentsDTO.setClassPlanDTO(classPlanDTO); - if(null != classPlanDTO) { + /*if(null != classPlanDTO) { InstitutionDTO institutionDTO = iInstitutionService.get(classPlanDTO.getOrgId()); if(null != institutionDTO) { applyStudentsDTO.setApplyWorkTypeName(institutionDTO.getInstitutionName()); } + }*/ + WorkTypeDTO workTypeDTO = workTypeService.get(applyStudentsDTO.getApplyWorkTypeId()); + if(null != workTypeDTO) { + applyStudentsDTO.setApplyWorkTypeName(workTypeDTO.getWorkTypeName()); } params.put("examId", applyStudentsDTO.getApplyClassId()); ExamApplyDTO examApplyDTO = examApplyService.get(params); diff --git a/src/main/java/cn/com/tenlion/service/handleimportexcel/IHandleImportExcelService.java b/src/main/java/cn/com/tenlion/service/handleimportexcel/IHandleImportExcelService.java new file mode 100644 index 0000000..3b64429 --- /dev/null +++ b/src/main/java/cn/com/tenlion/service/handleimportexcel/IHandleImportExcelService.java @@ -0,0 +1,33 @@ +package cn.com.tenlion.service.handleimportexcel; + +import cn.com.tenlion.pojo.dtos.excel.ImportFailDto; +import cn.com.tenlion.pojo.dtos.excel.ImportResultDto; +import cn.com.tenlion.pojo.model.ApplyStudentsModel; + +import java.util.List; + +/** + * @ClassName: IHandleImportExcelService + * @Description: 导入excel service + * @Author: renpc + * @Date: 2021-02-27 14:40 + * @Version: 1.0 + **/ +public interface IHandleImportExcelService { + + /** + * 数据校验 + * + * @param list + * @return + * @throws Exception + */ + public ImportResultDto checkImportData(List list); + + /** + * 批量导入学员成绩 + * @param applyStudentsModelList + * @param importFailDtoList + */ + void updateApplyStudents(List applyStudentsModelList, List importFailDtoList); +} diff --git a/src/main/java/cn/com/tenlion/service/handleimportexcel/impl/HandleImportExcelServiceImpl.java b/src/main/java/cn/com/tenlion/service/handleimportexcel/impl/HandleImportExcelServiceImpl.java new file mode 100644 index 0000000..f7f5cc3 --- /dev/null +++ b/src/main/java/cn/com/tenlion/service/handleimportexcel/impl/HandleImportExcelServiceImpl.java @@ -0,0 +1,60 @@ +package cn.com.tenlion.service.handleimportexcel.impl; + +import cn.com.tenlion.dao.applystudents.IApplyStudentsDao; +import cn.com.tenlion.dao.classplan.IClassPlanDao; +import cn.com.tenlion.pojo.dtos.classplan.ClassPlanDTO; +import cn.com.tenlion.pojo.dtos.excel.ImportFailDto; +import cn.com.tenlion.pojo.dtos.excel.ImportResultDto; +import cn.com.tenlion.pojo.model.ApplyStudentsModel; +import cn.com.tenlion.service.handleimportexcel.IHandleImportExcelService; +import ink.wgink.common.base.DefaultBaseService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @ClassName: HandleImportExcelServiceImpl + * @Description: 导入excel service + * @Author: renpc + * @Date: 2021-02-27 14:40 + * @Version: 1.0 + **/ +@Service +public class HandleImportExcelServiceImpl extends DefaultBaseService implements IHandleImportExcelService { + + @Autowired + private IApplyStudentsDao applyStudentsDao; + @Autowired + private IClassPlanDao classPlanDao; + + @Override + public ImportResultDto checkImportData(List list) { + return new ImportResultDto(null); + } + + @Override + public void updateApplyStudents(List applyStudentsModelList, List importFailDtoList) { + Map params = new HashMap<>(1); + if(null != applyStudentsModelList) { + for(ApplyStudentsModel applyStudentsModel: applyStudentsModelList) { + // 通过班级编号获取班级ID + params.put("planNumber", applyStudentsModel.getPlanNumber()); + ClassPlanDTO classPlanDTO = classPlanDao.get(params); + if(null != classPlanDTO) { + params.put("classPlanId", classPlanDTO.getClassPlanId()); + setUpdateInfo(params); + }else { + String msg = "班级编号不存在"; + ImportFailDto importFailDto = new ImportFailDto(applyStudentsModel, msg); + importFailDtoList.add(importFailDto); + continue; + } + params.put("applyTestScores", applyStudentsModel.getScore()); + applyStudentsDao.update(params); + } + } + } +} diff --git a/src/main/java/cn/com/tenlion/util/ExcelUtil.java b/src/main/java/cn/com/tenlion/util/ExcelUtil.java new file mode 100644 index 0000000..cf49fee --- /dev/null +++ b/src/main/java/cn/com/tenlion/util/ExcelUtil.java @@ -0,0 +1,77 @@ +package cn.com.tenlion.util; + +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.event.AnalysisEventListener; +import com.alibaba.excel.support.ExcelTypeEnum; +import org.springframework.util.StringUtils; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.InputStream; +import java.net.URLEncoder; +import java.util.List; + +/** + * excel工具类 + * @author renpc + */ +public class ExcelUtil { + + /** + * 默认excel文件名和单元sheet名一样的 Excel文件导出 + * @param httpServletResponse + * @param data + * @param fileName + * @param clazz + * @throws IOException + */ + public static void writeExcel(HttpServletResponse httpServletResponse, List data, String fileName, Class clazz) throws IOException { + writeExcel(httpServletResponse, data, fileName, fileName, clazz); + } + + /** + * 导出数据为Excel文件 + * @param response 响应实体 + * @param data 导出数据 + * @param fileName 文件名 + * @param sheetName 单元格名 + * @param clazz 定义excel导出的实体 + * @throws IOException + */ + public static void writeExcel(HttpServletResponse response, List data, String fileName, String sheetName, Class clazz) throws IOException { + //防止中文乱码 + fileName = URLEncoder.encode(fileName, "UTF-8"); + response.setContentType("application/vnd.ms-excel"); + response.setCharacterEncoding("utf-8"); + //防止导入excel文件名中文不乱码 + response.setHeader("Content-disposition", "attachment;fileName=" + fileName + ".xlsx" + ";fileName*=utf-8''" + fileName + ".xlsx"); + EasyExcel.write(response.getOutputStream(), clazz).sheet(sheetName).doWrite(data); + } + + /** + * easyExcel处理上传的文件 + * @param sheetNo 单元格 + * @param rowNumber 行数 + * @param analysisEventListener 上传处理监听 + * @param clazz 上传处理excel类 + * @return + * @throws Exception + */ + public static List readExcel(MultipartFile file, Integer sheetNo, Integer rowNumber, AnalysisEventListener analysisEventListener, Class clazz) throws Exception { + if(null != file) { + String originalFilename = file.getOriginalFilename(); + if(StringUtils.isEmpty(originalFilename)){ + throw new Exception("上传的文件不能为空"); + } + if(!originalFilename.toLowerCase().endsWith(ExcelTypeEnum.XLS.getValue()) && + !originalFilename.toLowerCase().endsWith(ExcelTypeEnum.XLSX.getValue())){ + throw new Exception("上传的文件格式不匹配"); + } + InputStream inputStream = file.getInputStream(); + return EasyExcel.read(inputStream, clazz, analysisEventListener).sheet(sheetNo).headRowNumber(rowNumber).doReadSync(); + } + throw new Exception("上传的文件不能为空"); + } + +} diff --git a/src/main/java/cn/com/tenlion/util/ImportErrorData.java b/src/main/java/cn/com/tenlion/util/ImportErrorData.java new file mode 100644 index 0000000..ece8088 --- /dev/null +++ b/src/main/java/cn/com/tenlion/util/ImportErrorData.java @@ -0,0 +1,15 @@ +package cn.com.tenlion.util; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author xwangs + * @create 2021-03-23 17:52 + * @description + */ +public class ImportErrorData { + + public static Map errorData = new HashMap<>(36); + +} diff --git a/src/main/java/cn/com/tenlion/util/ImportExcelHelper.java b/src/main/java/cn/com/tenlion/util/ImportExcelHelper.java new file mode 100644 index 0000000..4db87a9 --- /dev/null +++ b/src/main/java/cn/com/tenlion/util/ImportExcelHelper.java @@ -0,0 +1,106 @@ +package cn.com.tenlion.util; + +import cn.com.tenlion.dao.excel.IExcelDao; +import cn.com.tenlion.pojo.model.ApplyStudentsModel; +import cn.com.tenlion.service.handleimportexcel.IHandleImportExcelService; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.Map; + + +/** + * 导入excel数据的校验类 + * @author renpc + */ +@Component +public class ImportExcelHelper { + + @Autowired + private IHandleImportExcelService handleImportExcelService; + + + /** + * excelDao + */ + private static IExcelDao excelDao; + + + @Autowired + public void init(IExcelDao excelDao) { + ImportExcelHelper.excelDao = excelDao; + } + + public static String checkDataValid(T obj) { + if(null == obj) { + return null; + } + String returnStr = isMustInput(obj); + return returnStr; + } + + /** + * 检查数据是否必填项缺失 + * @param obj + * @param + * @return + */ + private static String isMustInput(T obj) { + // 出租房 + if(obj instanceof ApplyStudentsModel) { + Object temp = obj; + ApplyStudentsModel rentalHousingModel = (ApplyStudentsModel) temp; + return checkApplyStudentsData(rentalHousingModel); + } + return ""; + } + + /** + * 从数据库比对数据,并转换为数据库数据 + * @param obj + * @param + */ + public static void checkDataFromDatabase(T obj) { + // 出租房 + if(obj instanceof ApplyStudentsModel) { + Object temp = obj; + ApplyStudentsModel applyStudentsModel = (ApplyStudentsModel) temp; + applyStudentsCheck(applyStudentsModel); + temp = applyStudentsModel; + obj = (T) temp; + } + } + + /** + * 检查数据是否必填项缺失(考生成绩) + * @param applyStudentsModel + * @return + */ + private static String checkApplyStudentsData(ApplyStudentsModel applyStudentsModel) { + if(StringUtils.isEmpty(applyStudentsModel.getPlanNumber())) { + return "班号必填"; + } + if(StringUtils.isEmpty(applyStudentsModel.getUserName())) { + return "考生姓名必填"; + } + if(StringUtils.isEmpty(applyStudentsModel.getCardNumber())) { + return "考生身份证号码必填"; + } + if(StringUtils.isEmpty(applyStudentsModel.getScore())) { + return "考生成绩必填"; + } + return ""; + } + + /** + * 从数据库比对数据,并转换为数据库数据(考生成绩) + * @param applyStudentsModel + */ + private static void applyStudentsCheck(ApplyStudentsModel applyStudentsModel) { + Map param = new HashMap<>(); + } + + +} diff --git a/src/main/resources/mybatis/mapper/applystudents/apply-students-mapper.xml b/src/main/resources/mybatis/mapper/applystudents/apply-students-mapper.xml index f46d6a2..9fae13e 100644 --- a/src/main/resources/mybatis/mapper/applystudents/apply-students-mapper.xml +++ b/src/main/resources/mybatis/mapper/applystudents/apply-students-mapper.xml @@ -269,7 +269,13 @@ gmt_modified = #{gmtModified}, modifier = #{modifier} WHERE - apply_id = #{applyId} + 1 = 1 + + AND apply_id = #{applyId} + + + AND apply_class_id = #{classPlanId} + @@ -419,8 +425,7 @@ t1.is_delete = 0 AND ( - - t1.id LIKE CONCAT('%', #{keywords}, '%') + t1.apply_card_number LIKE CONCAT('%', #{keywords}, '%') ) diff --git a/src/main/resources/static/route/examapply/list-check.html b/src/main/resources/static/route/examapply/list-check.html index 6f422f3..0d8e048 100644 --- a/src/main/resources/static/route/examapply/list-check.html +++ b/src/main/resources/static/route/examapply/list-check.html @@ -485,6 +485,7 @@ for(var i = 0, item; item = checkDatas[i++];) { if(item.checkStatus === 1 || item.checkStatus === 2) { top.dialog.msg('当前选择存在已经审核完成数据,请重新选择'); + reloadTable(); return false; } if (i > 1) { diff --git a/src/main/resources/static/route/examcheck/list.html b/src/main/resources/static/route/examcheck/list.html index 6341f97..b0521c2 100644 --- a/src/main/resources/static/route/examcheck/list.html +++ b/src/main/resources/static/route/examcheck/list.html @@ -433,7 +433,11 @@ } else { var ids = ''; for(var i = 0, item; item = checkDatas[i++];) { - debugger + if(item.checkStatus != 0) { + top.dialog.msg('当前选择存在已经审核完成数据,请重新选择'); + reloadTable(); + return false; + } if(item.checkStatus == 0) { if(i > 1) { ids += '_'; @@ -443,8 +447,8 @@ } if(ids.length <= 0) { top.dialog.msg('当前选择数据已经审核完成,请重新选择'); - reloadTable(); return false; + reloadTable(); } checkMore(ids); } diff --git a/src/main/resources/static/route/insertscore/score-handle.html b/src/main/resources/static/route/insertscore/score-handle.html new file mode 100644 index 0000000..7684293 --- /dev/null +++ b/src/main/resources/static/route/insertscore/score-handle.html @@ -0,0 +1,445 @@ + + + + + + + + + + + + + +
+
+
+
+
+
+
+ +
+
+ +
+
+ +
+ +
+
+ + +
+
+
+
+
+ + + + + \ No newline at end of file diff --git a/src/main/resources/static/route/insertscore/search-score.html b/src/main/resources/static/route/insertscore/search-score.html new file mode 100644 index 0000000..b006e8f --- /dev/null +++ b/src/main/resources/static/route/insertscore/search-score.html @@ -0,0 +1,455 @@ + + + + + + + + + + + + + +
+
+
+
+
+
+
+ +
+
+ +
+
+ +
+ +
+
+ + +
+
+
+
+
+ + + + + \ No newline at end of file diff --git a/src/main/resources/templates/index4.html b/src/main/resources/templates/index4.html new file mode 100644 index 0000000..8303787 --- /dev/null +++ b/src/main/resources/templates/index4.html @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + +
+
+
标题
+ +
请输入班级编号/考生身份证号码查询
+
+
+ + + + + + + \ No newline at end of file