diff --git a/src/main/java/com/msdw/tms/api/QuestionsControllerApi.java b/src/main/java/com/msdw/tms/api/QuestionsControllerApi.java index eef6de3..670c8cc 100644 --- a/src/main/java/com/msdw/tms/api/QuestionsControllerApi.java +++ b/src/main/java/com/msdw/tms/api/QuestionsControllerApi.java @@ -87,6 +87,6 @@ public interface QuestionsControllerApi { * 通过excel批量导出 */ @ApiOperation(value = "通过excel批量导出", notes = "通过excel批量导出") - R exportQuestion() throws IOException; + R exportQuestion(HttpServletResponse response) throws Exception; } diff --git a/src/main/java/com/msdw/tms/common/utils/Constant.java b/src/main/java/com/msdw/tms/common/utils/Constant.java index 9562d95..14962fa 100644 --- a/src/main/java/com/msdw/tms/common/utils/Constant.java +++ b/src/main/java/com/msdw/tms/common/utils/Constant.java @@ -205,17 +205,17 @@ public class Constant { } /** - * 是否删除 + * 是否删除:0使用,1删除,默认0使用 */ public enum IsDel { /** * 删除 */ - DEL(0, "删除"), + DEL(1, "删除"), /** * 不删除 */ - NOT_DEL(1, "不删除"); + NOT_DEL(0, "不删除"); private Integer type; //类型 private String desc; //描述 diff --git a/src/main/java/com/msdw/tms/common/utils/poi/ExcelExportUtil.java b/src/main/java/com/msdw/tms/common/utils/poi/ExcelExportUtil.java index 6da79eb..7c011a5 100644 --- a/src/main/java/com/msdw/tms/common/utils/poi/ExcelExportUtil.java +++ b/src/main/java/com/msdw/tms/common/utils/poi/ExcelExportUtil.java @@ -77,7 +77,7 @@ public class ExcelExportUtil { workbook.write(response.getOutputStream()); } - public CellStyle[] getTemplateStyles(Row row) { + CellStyle[] getTemplateStyles(Row row) { CellStyle[] styles = new CellStyle[row.getLastCellNum()]; for (int i = 0; i < row.getLastCellNum(); i++) { styles[i] = row.getCell(i).getCellStyle(); diff --git a/src/main/java/com/msdw/tms/config/CorsConfig.java b/src/main/java/com/msdw/tms/config/CorsConfig.java new file mode 100644 index 0000000..5250d87 --- /dev/null +++ b/src/main/java/com/msdw/tms/config/CorsConfig.java @@ -0,0 +1,19 @@ +package com.msdw.tms.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +public class CorsConfig implements WebMvcConfigurer { + + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**") + .allowedOrigins("*") + .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS") + .allowCredentials(true) + .maxAge(3600) + .allowedHeaders("*"); + } +} diff --git a/src/main/java/com/msdw/tms/controller/QuestionsController.java b/src/main/java/com/msdw/tms/controller/QuestionsController.java index d8c056c..5d823c9 100644 --- a/src/main/java/com/msdw/tms/controller/QuestionsController.java +++ b/src/main/java/com/msdw/tms/controller/QuestionsController.java @@ -151,9 +151,9 @@ public class QuestionsController implements QuestionsControllerApi { @Override @GetMapping("/export") - public R exportQuestion() throws IOException { - // List<> list = questionsService.exportQuestion(); - return null; + public R exportQuestion(HttpServletResponse response) throws Exception { + questionsService.exportQuestion(response); + return R.ok(); } } diff --git a/src/main/java/com/msdw/tms/entity/QuestionsEntity.java b/src/main/java/com/msdw/tms/entity/QuestionsEntity.java index 03600ef..20cc204 100644 --- a/src/main/java/com/msdw/tms/entity/QuestionsEntity.java +++ b/src/main/java/com/msdw/tms/entity/QuestionsEntity.java @@ -71,7 +71,7 @@ public class QuestionsEntity implements Serializable { */ private Integer isEnable; /** - * 是否删除:1使用,0删除,默认1使用 + * 是否删除:0使用,1删除,默认0使用 */ private Integer isDel; /** diff --git a/src/main/java/com/msdw/tms/entity/vo/QuestionsDetailVO.java b/src/main/java/com/msdw/tms/entity/vo/QuestionsDetailVO.java index 9d32676..9851391 100644 --- a/src/main/java/com/msdw/tms/entity/vo/QuestionsDetailVO.java +++ b/src/main/java/com/msdw/tms/entity/vo/QuestionsDetailVO.java @@ -89,7 +89,7 @@ public class QuestionsDetailVO implements Serializable { */ private Integer isEnable; /** - * 是否删除:1使用,0删除,默认1使用 + * 是否删除:0使用,1删除,默认0使用 */ private Integer isDel; /** diff --git a/src/main/java/com/msdw/tms/entity/vo/QuestionsVO.java b/src/main/java/com/msdw/tms/entity/vo/QuestionsVO.java index 64a5c14..9c7cf9c 100644 --- a/src/main/java/com/msdw/tms/entity/vo/QuestionsVO.java +++ b/src/main/java/com/msdw/tms/entity/vo/QuestionsVO.java @@ -67,7 +67,7 @@ public class QuestionsVO implements Serializable { */ private Integer isEnable; /** - * 是否删除:1使用,0删除,默认1使用 + * 是否删除:0使用,1删除,默认0使用 */ private Integer isDel; /** diff --git a/src/main/java/com/msdw/tms/service/QuestionsService.java b/src/main/java/com/msdw/tms/service/QuestionsService.java index f3d4544..b1f5fec 100644 --- a/src/main/java/com/msdw/tms/service/QuestionsService.java +++ b/src/main/java/com/msdw/tms/service/QuestionsService.java @@ -9,6 +9,7 @@ import com.msdw.tms.entity.request.QuestionsQueryRequest; import com.msdw.tms.entity.request.QuestionsUpdateRequest; import com.msdw.tms.entity.vo.EvaluationVO; import com.msdw.tms.entity.vo.QuestionsDetailVO; +import com.msdw.tms.entity.vo.QuestionsVO; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; @@ -44,5 +45,7 @@ public interface QuestionsService extends IService { void downloadFiles(HttpServletResponse response) throws IOException; EvaluationVO evaluation(); + + void exportQuestion(HttpServletResponse response) throws Exception; } diff --git a/src/main/java/com/msdw/tms/service/impl/QuestionsServiceImpl.java b/src/main/java/com/msdw/tms/service/impl/QuestionsServiceImpl.java index 6ece057..feba884 100644 --- a/src/main/java/com/msdw/tms/service/impl/QuestionsServiceImpl.java +++ b/src/main/java/com/msdw/tms/service/impl/QuestionsServiceImpl.java @@ -8,6 +8,7 @@ import com.msdw.tms.common.utils.Constant; import com.msdw.tms.common.utils.FilesResult; import com.msdw.tms.common.utils.PageUtils; import com.msdw.tms.common.utils.Query; +import com.msdw.tms.common.utils.poi.ExcelExportUtil; import com.msdw.tms.common.utils.poi.ExcelImportUtil; import com.msdw.tms.dao.QuestionsDao; import com.msdw.tms.entity.QuestionsEntity; @@ -27,12 +28,14 @@ import com.msdw.tms.service.QuestionsService; import com.msdw.tms.service.XlsxTemplateService; import org.apache.commons.lang.StringUtils; import org.springframework.beans.BeanUtils; +import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; +import java.io.FileInputStream; import java.io.IOException; import java.time.Instant; import java.time.LocalDateTime; @@ -278,7 +281,8 @@ public class QuestionsServiceImpl extends ServiceImpl list = new ExcelImportUtil(QuestionsImportRequest.class).readExcel(file.getInputStream(), Constant.STARTING_ROW, Constant.STARTING_CELL); + List list = new ExcelImportUtil(QuestionsImportRequest.class) + .readExcel(file.getInputStream(), Constant.STARTING_ROW, Constant.STARTING_CELL); if (list == null || list.size() == 0) { ExceptionCast.cast(CommonCode.INVALID_PARAM); @@ -413,6 +417,22 @@ public class QuestionsServiceImpl extends ServiceImpl list = this.list().stream().map(item -> { + QuestionsImportRequest importRequest = new QuestionsImportRequest(); + BeanUtils.copyProperties(item, importRequest); + return importRequest; + }).collect(Collectors.toList()); + + //2.加载模板流数据 + org.springframework.core.io.Resource resource = new ClassPathResource("excel-template/试题导入模板.xlsx"); + FileInputStream fis = new FileInputStream(resource.getFile()); + new ExcelExportUtil(QuestionsImportRequest.class, Constant.STARTING_ROW, Constant.STARTING_CELL). + export(response, fis, list, "试题表.xlsx"); + } + private Set getRandomList(int len, List list) { Set set = new HashSet<>(); Random random = new Random(); diff --git a/src/main/resources/excel-template/试题导入模板.xlsx b/src/main/resources/excel-template/试题导入模板.xlsx index 30c5e14..7cc7230 100644 Binary files a/src/main/resources/excel-template/试题导入模板.xlsx and b/src/main/resources/excel-template/试题导入模板.xlsx differ