跨域和是否删除类型修改

hehai
shijie 4 years ago
parent 0716b7f8d6
commit d9c26dcc37
  1. 2
      src/main/java/com/msdw/tms/api/QuestionsControllerApi.java
  2. 6
      src/main/java/com/msdw/tms/common/utils/Constant.java
  3. 2
      src/main/java/com/msdw/tms/common/utils/poi/ExcelExportUtil.java
  4. 19
      src/main/java/com/msdw/tms/config/CorsConfig.java
  5. 6
      src/main/java/com/msdw/tms/controller/QuestionsController.java
  6. 2
      src/main/java/com/msdw/tms/entity/QuestionsEntity.java
  7. 2
      src/main/java/com/msdw/tms/entity/vo/QuestionsDetailVO.java
  8. 2
      src/main/java/com/msdw/tms/entity/vo/QuestionsVO.java
  9. 3
      src/main/java/com/msdw/tms/service/QuestionsService.java
  10. 22
      src/main/java/com/msdw/tms/service/impl/QuestionsServiceImpl.java
  11. BIN
      src/main/resources/excel-template/试题导入模板.xlsx

@ -87,6 +87,6 @@ public interface QuestionsControllerApi {
* 通过excel批量导出
*/
@ApiOperation(value = "通过excel批量导出", notes = "通过excel批量导出")
R exportQuestion() throws IOException;
R exportQuestion(HttpServletResponse response) throws Exception;
}

@ -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; //描述

@ -77,7 +77,7 @@ public class ExcelExportUtil<T> {
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();

@ -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("*");
}
}

@ -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();
}
}

@ -71,7 +71,7 @@ public class QuestionsEntity implements Serializable {
*/
private Integer isEnable;
/**
* 是否删除1使用0删除默认1使用
* 是否删除0使用1删除默认0使用
*/
private Integer isDel;
/**

@ -89,7 +89,7 @@ public class QuestionsDetailVO implements Serializable {
*/
private Integer isEnable;
/**
* 是否删除1使用0删除默认1使用
* 是否删除0使用1删除默认0使用
*/
private Integer isDel;
/**

@ -67,7 +67,7 @@ public class QuestionsVO implements Serializable {
*/
private Integer isEnable;
/**
* 是否删除1使用0删除默认1使用
* 是否删除0使用1删除默认0使用
*/
private Integer isDel;
/**

@ -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<QuestionsEntity> {
void downloadFiles(HttpServletResponse response) throws IOException;
EvaluationVO evaluation();
void exportQuestion(HttpServletResponse response) throws Exception;
}

@ -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<QuestionsDao, QuestionsEnt
@Transactional
public boolean importQuestion(MultipartFile file) throws IOException {
// 使用excel导入工具类获取试题数据列表
List<QuestionsImportRequest> list = new ExcelImportUtil(QuestionsImportRequest.class).readExcel(file.getInputStream(), Constant.STARTING_ROW, Constant.STARTING_CELL);
List<QuestionsImportRequest> 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<QuestionsDao, QuestionsEnt
return evaluation;
}
@Override
public void exportQuestion(HttpServletResponse response) throws Exception {
//1.构造数据
List<QuestionsImportRequest> 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<QuestionsEntity> getRandomList(int len, List<QuestionsEntity> list) {
Set<QuestionsEntity> set = new HashSet<>();
Random random = new Random();

Loading…
Cancel
Save