diff --git a/src/main/java/com/zhgd/xmgl/modules/basicdata/controller/DownloadController.java b/src/main/java/com/zhgd/xmgl/modules/basicdata/controller/DownloadController.java index e4f4e13bd..378fd3290 100644 --- a/src/main/java/com/zhgd/xmgl/modules/basicdata/controller/DownloadController.java +++ b/src/main/java/com/zhgd/xmgl/modules/basicdata/controller/DownloadController.java @@ -5,6 +5,7 @@ import com.zhgd.xmgl.modules.bigdevice.service.ITowerAlarmService; import com.zhgd.xmgl.modules.bigdevice.service.ITowerCurrentDataService; import com.zhgd.xmgl.modules.bigdevice.service.ITowerWorkCycleService; import com.zhgd.xmgl.modules.dangerous.service.IHiddenDangerInspectRecordService; +import com.zhgd.xmgl.modules.exam.service.IExamQuestionBankService; import com.zhgd.xmgl.modules.massrebound.service.IMassReboundSurveyAreaService; import com.zhgd.xmgl.modules.quality.service.IQualityInspectionRecordService; import com.zhgd.xmgl.modules.standard.service.IStandardAlarmService; @@ -44,6 +45,8 @@ public class DownloadController { @Autowired private IWorkerInfoService workerInfoService; @Autowired + private IExamQuestionBankService examQuestionBankService; + @Autowired private IWorkerMonthAttendanceStatisticsService workerMonthAttendanceStatisticsService; @Autowired private IMassReboundSurveyAreaService massReboundSurveyAreaService; @@ -311,6 +314,15 @@ public class DownloadController { workerInfoService.exporExcelWorkerTemplate(response, projectSn); } + @ApiOperation(value = "题库导入模板下载", notes = "题库导入模板下载", httpMethod = "GET") + @ApiImplicitParams({ + @ApiImplicitParam(name = "projectSn", value = "项目SN", paramType = "query", required = true, dataType = "String"), + }) + @GetMapping(value = "/exporExcelExamQuestionTemplate") + public void exporExcelExamQuestionTemplate(HttpServletResponse response, String projectSn) { + examQuestionBankService.exporExcelTemplate(response, projectSn); + } + @ApiOperation(value = "列表查询隐患检查记录信息下载", notes = "列表查询隐患检查记录信息下载", httpMethod = "GET") @ApiImplicitParams({ @ApiImplicitParam(name = "projectSn", value = "项目SN", paramType = "query", required = true, dataType = "String"), diff --git a/src/main/java/com/zhgd/xmgl/modules/exam/controller/ExamQuestionBankController.java b/src/main/java/com/zhgd/xmgl/modules/exam/controller/ExamQuestionBankController.java index c554f3446..d63bbe6ae 100644 --- a/src/main/java/com/zhgd/xmgl/modules/exam/controller/ExamQuestionBankController.java +++ b/src/main/java/com/zhgd/xmgl/modules/exam/controller/ExamQuestionBankController.java @@ -17,6 +17,7 @@ import com.zhgd.xmgl.modules.exam.vo.ExamQuestionBankVo; import com.zhgd.xmgl.modules.exam.vo.RandomQuery; import com.zhgd.xmgl.security.entity.UserInfo; import com.zhgd.xmgl.security.util.SecurityUtils; +import com.zhgd.xmgl.util.ExcelUtils; import com.zhgd.xmgl.util.PageUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -323,28 +324,25 @@ public class ExamQuestionBankController { List pageList = examQuestionBankService.list(queryWrapper); List subList = examSubjectService.list(); List resultList = new ArrayList<>(); - int index = 1; for (ExamQuestionBank examQuestionBank : pageList) { ExamSubject examSubject = subList.stream().filter(s -> s.getId().toString().equals(examQuestionBank.getSubjectId().toString())) .collect(Collectors.toList()).get(0); ExamQuestionBankImport examQuestionBankImport = new ExamQuestionBankImport(); - examQuestionBankImport.setIndex(index + "、"); examQuestionBankImport.setSubjectName(examSubject.getName()); examQuestionBankImport.setQuestionName(examQuestionBank.getQuestionName()); examQuestionBankImport.setTypeName(getType(examQuestionBank.getType())); examQuestionBankImport.setDifficulty(getDifficulty(examQuestionBank.getDifficulty())); examQuestionBankImport.setOptions(examQuestionBank.getOptions()); examQuestionBankImport.setIsEnable(examQuestionBank.getIsEnable() == 1 ? "是" : "否"); - examQuestionBankImport.setScore(examQuestionBank.getScore()); + examQuestionBankImport.setScore(examQuestionBank.getScore().toString()); resultList.add(examQuestionBankImport); List questionOptions = examQuestionOptionService.list(Wrappers.lambdaQuery().eq(ExamQuestionOption::getQuestionId, examQuestionBank.getId())); for (ExamQuestionOption questionOption : questionOptions) { ExamQuestionBankImport examQuestionBankImport1 = new ExamQuestionBankImport(); - examQuestionBankImport1.setSubjectName(questionOption.getOptionCode()); - examQuestionBankImport1.setQuestionName(questionOption.getOptionDesc()); + examQuestionBankImport1.setOptionCode(questionOption.getOptionCode()); + examQuestionBankImport1.setOptionDesc(questionOption.getOptionDesc()); resultList.add(examQuestionBankImport1); } - index++; } //导出文件名称 mv.addObject(NormalExcelConstants.FILE_NAME, "题目管理列表"); @@ -376,40 +374,42 @@ public class ExamQuestionBankController { params.setHeadRows(1); params.setNeedSave(true); try { - List examQuestionBankImports = ExcelImportUtil.importExcel(file.getInputStream(), ExamQuestionBankImport.class, params); + List> examQuestionBankImports = ExcelUtils.jxlExlToList(file.getInputStream(), 0); List examQuestionBankList = new ArrayList<>(); List examQuestionOptionList = new ArrayList<>(); int index = 0; - for (ExamQuestionBankImport examQuestionBankImport : examQuestionBankImports) { - if (StringUtils.isNotBlank(examQuestionBankImport.getQuestionName())) { - if (StringUtils.isNotBlank(examQuestionBankImport.getIndex())) { - index++; - List subjects = subList.stream().filter(s -> s.getName().equals(examQuestionBankImport.getSubjectName())).collect(Collectors.toList()); - if (subjects == null || subjects.size() == 0) { - throw new CustomException("没有对应的科目名称,请检查", HttpStatus.INTERNAL_SERVER_ERROR); - } - ExamQuestionBank examQuestionBank = new ExamQuestionBank(); - examQuestionBank.setId((long) index); - examQuestionBank.setSubjectId(subjects.get(0).getId()); - examQuestionBank.setQuestionName(examQuestionBankImport.getQuestionName()); - examQuestionBank.setType(getType(examQuestionBankImport.getTypeName())); - examQuestionBank.setDifficulty(getDifficulty(examQuestionBankImport.getDifficulty())); - examQuestionBank.setOptions(examQuestionBankImport.getOptions()); - examQuestionBank.setIsEnable(examQuestionBankImport.getIsEnable().equals("是") ? 1 : 0); - examQuestionBank.setScore(examQuestionBankImport.getScore()); - examQuestionBank.setProjectSn(systemUser.getSn()); - examQuestionBank.setCreateBy(systemUser.getUserId().toString()); - examQuestionBank.setCreateTime(new Date()); - examQuestionBank.setUpdateBy(systemUser.getUserId().toString()); - examQuestionBank.setUpdateTime(examQuestionBank.getCreateTime()); - examQuestionBankList.add(examQuestionBank); - } else { - ExamQuestionOption examQuestionOption = new ExamQuestionOption(); - examQuestionOption.setQuestionId((long) index); - examQuestionOption.setOptionCode(examQuestionBankImport.getSubjectName()); - examQuestionOption.setOptionDesc(examQuestionBankImport.getQuestionName()); - examQuestionOptionList.add(examQuestionOption); + for (Map examQuestionBankImport : examQuestionBankImports) { + if (StringUtils.isNotBlank(examQuestionBankImport.get("*科目名称").trim())) { + index++; + List subjects = subList.stream().filter(s -> s.getName().equals(examQuestionBankImport.get("*科目名称").trim())).collect(Collectors.toList()); + if (subjects == null || subjects.size() == 0) { + throw new CustomException("没有对应的科目名称,请检查", HttpStatus.INTERNAL_SERVER_ERROR); } + ExamQuestionBank examQuestionBank = new ExamQuestionBank(); + examQuestionBank.setId((long) index); + examQuestionBank.setSubjectId(subjects.get(0).getId()); + examQuestionBank.setQuestionName(examQuestionBankImport.get("*试题名称").trim()); + examQuestionBank.setType(getType(examQuestionBankImport.get("*试题类型").trim())); + examQuestionBank.setDifficulty(getDifficulty(examQuestionBankImport.get("*难易程度").trim())); + examQuestionBank.setOptions(examQuestionBankImport.get("*试题答案").trim()); + examQuestionBank.setIsEnable(examQuestionBankImport.get("*是否应用").trim().equals("是") ? 1 : 0); + try { + examQuestionBank.setScore(Integer.parseInt(examQuestionBankImport.get("*作答正确得分").trim())); + } catch (Exception e) { + throw new CustomException("分数格式错误,请填写正确的分数", HttpStatus.INTERNAL_SERVER_ERROR); + } + examQuestionBank.setProjectSn(systemUser.getSn()); + examQuestionBank.setCreateBy(systemUser.getUserId().toString()); + examQuestionBank.setCreateTime(new Date()); + examQuestionBank.setUpdateBy(systemUser.getUserId().toString()); + examQuestionBank.setUpdateTime(examQuestionBank.getCreateTime()); + examQuestionBankList.add(examQuestionBank); + } else if(StringUtils.isNotBlank(examQuestionBankImport.get("*选项代码").trim())) { + ExamQuestionOption examQuestionOption = new ExamQuestionOption(); + examQuestionOption.setQuestionId((long) index); + examQuestionOption.setOptionCode(examQuestionBankImport.get("*选项代码").trim()); + examQuestionOption.setOptionDesc(examQuestionBankImport.get("*选项描述").trim()); + examQuestionOptionList.add(examQuestionOption); } } for (ExamQuestionBank examQuestionBank : examQuestionBankList) { @@ -438,13 +438,6 @@ public class ExamQuestionBankController { return Result.ok("文件导入失败!"); } - @ApiOperation(value = "导入模板下载", notes = "导入模板下载", httpMethod = "GET") - @ApiImplicitParam(name = "projectSn", value = "项目SN", paramType = "query", required = true, dataType = "String") - @GetMapping(value = "/exporExcelTemplate") - public void exporExcelTemplate(HttpServletResponse response, String projectSn) { - examQuestionBankService.exporExcelTemplate(response, projectSn); - } - private String getType(int type) { String typeName = null; switch (type) { diff --git a/src/main/java/com/zhgd/xmgl/modules/exam/vo/ExamQuestionBankImport.java b/src/main/java/com/zhgd/xmgl/modules/exam/vo/ExamQuestionBankImport.java index f528cb67c..252128a11 100644 --- a/src/main/java/com/zhgd/xmgl/modules/exam/vo/ExamQuestionBankImport.java +++ b/src/main/java/com/zhgd/xmgl/modules/exam/vo/ExamQuestionBankImport.java @@ -9,35 +9,41 @@ import org.jeecgframework.poi.excel.annotation.Excel; @ApiModel(value = "试题导入(VO)", description = "ExamQuestionBankImport") public class ExamQuestionBankImport { - @Excel(name = "试题序号", width = 15) - @ApiModelProperty(value = "试题序号") private String index; - @Excel(name = "科目名称/选项代码", width = 15) - @ApiModelProperty(value = "科目名称/选项代码") + @Excel(name = "*科目名称", width = 15) + @ApiModelProperty(value = "科目名称") private String subjectName; - @Excel(name = "试题名称/选项描述", width = 15) - @ApiModelProperty(value = "试题名称/选项描述") + @Excel(name = "*试题名称", width = 15) + @ApiModelProperty(value = "试题名称") private String questionName; - @Excel(name = "试题类型(单选题;多选题;)", width = 15) - @ApiModelProperty(value = "试题类型(单选题;多选题;)") + @Excel(name = "*试题类型", width = 15) + @ApiModelProperty(value = "试题类型") private String typeName; - @Excel(name = "难易程度", width = 15) + @Excel(name = "*难易程度", width = 15) @ApiModelProperty(value = "难易程度") private String difficulty; - @Excel(name = "试题答案", width = 15) + @Excel(name = "*试题答案", width = 15) @ApiModelProperty(value = "试题答案") private String options; - @Excel(name = "是否应用(否;是)", width = 15) + @Excel(name = "*是否应用(否;是)", width = 15) @ApiModelProperty(value = "是否应用(否;是)") private String isEnable; - @Excel(name = "作答正确得分", width = 15) + @Excel(name = "*作答正确得分", width = 15) @ApiModelProperty(value = "作答正确得分") - private Integer score; + private String score; + + @Excel(name = "*选项代码", width = 15) + @ApiModelProperty(value = "选项代码") + private String optionCode; + + @Excel(name = "*选项描述", width = 15) + @ApiModelProperty(value = "选项描述") + private String optionDesc; } diff --git a/src/main/java/com/zhgd/xmgl/util/ExcelUtils.java b/src/main/java/com/zhgd/xmgl/util/ExcelUtils.java index deba14ce3..9637eda7d 100644 --- a/src/main/java/com/zhgd/xmgl/util/ExcelUtils.java +++ b/src/main/java/com/zhgd/xmgl/util/ExcelUtils.java @@ -253,7 +253,7 @@ public class ExcelUtils { public static void exporExcelExamQuestionBankTemplate(HttpServletResponse response, List subjectList) { try { - ClassPathResource classPathResource = new ClassPathResource("excel/题库导入模板.xlsx"); + ClassPathResource classPathResource = new ClassPathResource("excel/题库导入模版.xlsx"); InputStream inputStream = classPathResource.getInputStream(); XSSFWorkbook workbook = new XSSFWorkbook(inputStream); //部门/班组下拉列 @@ -266,7 +266,7 @@ public class ExcelUtils { cell1.setCellValue(subjectList.get(i).getName()); } } - downLoadExcel("题库导入模板.xlsx", response, workbook); + downLoadExcel("题库导入模版.xlsx", response, workbook); } catch (IOException e) { log.error("error:", e); } diff --git a/src/main/resources/excel/题库导入模版.xlsx b/src/main/resources/excel/题库导入模版.xlsx index 888b992f9..7fe478788 100644 Binary files a/src/main/resources/excel/题库导入模版.xlsx and b/src/main/resources/excel/题库导入模版.xlsx differ