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