|
|
@ -15,18 +15,14 @@ import com.tz.platform.pc.dto.ListQuestionImportDTO;
|
|
|
|
import com.tz.platform.pc.dto.QuestionImportDTO;
|
|
|
|
import com.tz.platform.pc.dto.QuestionImportDTO;
|
|
|
|
import com.tz.platform.repository.CourseDao;
|
|
|
|
import com.tz.platform.repository.CourseDao;
|
|
|
|
import com.tz.platform.repository.QuestionDao;
|
|
|
|
import com.tz.platform.repository.QuestionDao;
|
|
|
|
import org.apache.catalina.User;
|
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
|
import org.apache.poi.ss.usermodel.Cell;
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Component
|
|
|
|
@Component
|
|
|
|
public class QuestionImportBiz {
|
|
|
|
public class QuestionImportBiz {
|
|
|
@ -42,12 +38,12 @@ public class QuestionImportBiz {
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private IFeignStudentLevel feignStudentLevel;
|
|
|
|
private IFeignStudentLevel feignStudentLevel;
|
|
|
|
|
|
|
|
|
|
|
|
public Result<ListQuestionImportDTO> importExcel(MultipartFile file,Long userNo){
|
|
|
|
public Result<ListQuestionImportDTO> importExcel(MultipartFile file, Long userNo) {
|
|
|
|
if(userNo == null ||userNo<=0){
|
|
|
|
if (userNo == null || userNo <= 0) {
|
|
|
|
return Result.error("无权操作");
|
|
|
|
return Result.error("无权操作");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UserVo user = feignUser.getByUserNo(userNo);
|
|
|
|
UserVo user = feignUser.getByUserNo(userNo);
|
|
|
|
if(user==null||user.getUserType()< UserTypeEnum.TEACHER.getCode()){
|
|
|
|
if (user == null || user.getUserType() < UserTypeEnum.TEACHER.getCode()) {
|
|
|
|
return Result.error("无权操作");
|
|
|
|
return Result.error("无权操作");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ListQuestionImportDTO dto = new ListQuestionImportDTO();
|
|
|
|
ListQuestionImportDTO dto = new ListQuestionImportDTO();
|
|
|
@ -57,18 +53,22 @@ public class QuestionImportBiz {
|
|
|
|
ExcelUtil util = new ExcelUtil(file.getInputStream());
|
|
|
|
ExcelUtil util = new ExcelUtil(file.getInputStream());
|
|
|
|
int lastRowNum = util.getLastRowNum();
|
|
|
|
int lastRowNum = util.getLastRowNum();
|
|
|
|
List<QuestionImportDTO> list = new ArrayList<>();
|
|
|
|
List<QuestionImportDTO> list = new ArrayList<>();
|
|
|
|
for(int rowNo = 1;rowNo<=lastRowNum;){
|
|
|
|
|
|
|
|
int lineCount = util.getMergedRegionLineCount(rowNo,1);
|
|
|
|
Workbook workbook = new XSSFWorkbook(file.getInputStream());
|
|
|
|
if(lineCount <=0){
|
|
|
|
ExcelUtil.initSheet(workbook);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int rowNo = 1; rowNo <= lastRowNum; ) {
|
|
|
|
|
|
|
|
int lineCount = util.getMergedRegionLineCount(rowNo, 1);
|
|
|
|
|
|
|
|
if (lineCount <= 0) {
|
|
|
|
return Result.error("格式错误");
|
|
|
|
return Result.error("格式错误");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QuestionImportDTO subDto = new QuestionImportDTO();
|
|
|
|
QuestionImportDTO subDto = new QuestionImportDTO();
|
|
|
|
String stem = util.getMergedRegionValue(rowNo,0);
|
|
|
|
String stem = util.getMergedRegionValue(rowNo, 0);
|
|
|
|
String questType = util.getMergedRegionValue(rowNo,1);
|
|
|
|
String questType = util.getMergedRegionValue(rowNo, 1);
|
|
|
|
String levelNamme = util.getMergedRegionValue(rowNo,2);
|
|
|
|
String levelNamme = util.getMergedRegionValue(rowNo, 2);
|
|
|
|
String courseName = util.getMergedRegionValue(rowNo,3);
|
|
|
|
String courseName = util.getMergedRegionValue(rowNo, 3);
|
|
|
|
String score = util.getMergedRegionValue(rowNo,4);
|
|
|
|
String score = util.getMergedRegionValue(rowNo, 4);
|
|
|
|
String analysis = util.getMergedRegionValue(rowNo,5);
|
|
|
|
String analysis = util.getMergedRegionValue(rowNo, 5);
|
|
|
|
|
|
|
|
|
|
|
|
subDto.setStem(stem);
|
|
|
|
subDto.setStem(stem);
|
|
|
|
subDto.setQuestionType(questType);
|
|
|
|
subDto.setQuestionType(questType);
|
|
|
@ -82,7 +82,7 @@ public class QuestionImportBiz {
|
|
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(stem)) {
|
|
|
|
if (StringUtils.isEmpty(stem)) {
|
|
|
|
subDto.setStatus("题干为空");
|
|
|
|
subDto.setStatus("题干为空");
|
|
|
|
}else{
|
|
|
|
} else {
|
|
|
|
Question temp = questionDao.getByStem(stem);
|
|
|
|
Question temp = questionDao.getByStem(stem);
|
|
|
|
if (temp != null) {
|
|
|
|
if (temp != null) {
|
|
|
|
subDto.setStatus("题干已存在");
|
|
|
|
subDto.setStatus("题干已存在");
|
|
|
@ -98,7 +98,7 @@ public class QuestionImportBiz {
|
|
|
|
question.setLevelId(levelVo.getId());
|
|
|
|
question.setLevelId(levelVo.getId());
|
|
|
|
question.setLevelName(levelNamme);
|
|
|
|
question.setLevelName(levelNamme);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//todo 兼容填空题
|
|
|
|
question.setStem(stem);
|
|
|
|
question.setStem(stem);
|
|
|
|
question.setUserNo(userNo);
|
|
|
|
question.setUserNo(userNo);
|
|
|
|
question.setCreateTime(new Date());
|
|
|
|
question.setCreateTime(new Date());
|
|
|
@ -111,41 +111,43 @@ public class QuestionImportBiz {
|
|
|
|
question.setAnalysis(analysis);
|
|
|
|
question.setAnalysis(analysis);
|
|
|
|
question.setCourseId(course.getId());
|
|
|
|
question.setCourseId(course.getId());
|
|
|
|
QuestionTypeEnum qt = null;
|
|
|
|
QuestionTypeEnum qt = null;
|
|
|
|
if(questType.equals(QuestionTypeEnum.SINGLE.getDesc())){
|
|
|
|
if (questType.equals(QuestionTypeEnum.SINGLE.getDesc())) {
|
|
|
|
qt = QuestionTypeEnum.SINGLE;
|
|
|
|
qt = QuestionTypeEnum.SINGLE;
|
|
|
|
}else if(questType.equals(QuestionTypeEnum.MULTY.getDesc())){
|
|
|
|
} else if (questType.equals(QuestionTypeEnum.MULTY.getDesc())) {
|
|
|
|
qt = QuestionTypeEnum.MULTY;
|
|
|
|
qt = QuestionTypeEnum.MULTY;
|
|
|
|
}else if(questType.equals(QuestionTypeEnum.JUDGE.getDesc())) {
|
|
|
|
} else if (questType.equals(QuestionTypeEnum.JUDGE.getDesc())) {
|
|
|
|
qt= QuestionTypeEnum.JUDGE;
|
|
|
|
qt = QuestionTypeEnum.JUDGE;
|
|
|
|
|
|
|
|
} else if (questType.equals(QuestionTypeEnum.GAPFILLING.getDesc())) {
|
|
|
|
|
|
|
|
qt = QuestionTypeEnum.GAPFILLING;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(qt == null){
|
|
|
|
if (qt == null) {
|
|
|
|
subDto.setStatus("题型未匹配");
|
|
|
|
subDto.setStatus("题型未匹配");
|
|
|
|
}else{
|
|
|
|
} else {
|
|
|
|
List<Answer> answerList = new ArrayList<>();
|
|
|
|
List<Answer> answerList = new ArrayList<>();
|
|
|
|
List<Integer> answerIds = new ArrayList<>();
|
|
|
|
List<Integer> answerIds = new ArrayList<>();
|
|
|
|
for(int i = 0 ;i<lineCount;i++){
|
|
|
|
for (int i = 0; i < lineCount; i++) {
|
|
|
|
Row row = util.getRow(rowNo +i);
|
|
|
|
Row row = util.getRow(rowNo + i);
|
|
|
|
String itemStem = util.getCellValue(row.getCell(6));
|
|
|
|
String itemStem = util.getCellValue(row.getCell(6));
|
|
|
|
String isAnwser = util.getCellValue(row.getCell(7));
|
|
|
|
String isAnwser = util.getCellValue(row.getCell(7));
|
|
|
|
if(StringUtils.isEmpty(itemStem)){
|
|
|
|
if (StringUtils.isEmpty(itemStem)) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Answer answer = new Answer();
|
|
|
|
Answer answer = new Answer();
|
|
|
|
answer.setId(i+1);
|
|
|
|
answer.setId(i + 1);
|
|
|
|
answer.setTitle(itemStem);
|
|
|
|
answer.setTitle(itemStem);
|
|
|
|
if(isAnwser.contains("是")){
|
|
|
|
if (isAnwser.contains("是")) {
|
|
|
|
answerIds.add(i+1);
|
|
|
|
answerIds.add(i + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
answerList.add(answer);
|
|
|
|
answerList.add(answer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(answerIds.size() == 0){
|
|
|
|
if (answerIds.size() == 0) {
|
|
|
|
subDto.setStatus("无答案");
|
|
|
|
subDto.setStatus("无答案");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(answerList.size()==0){
|
|
|
|
if (answerList.size() == 0) {
|
|
|
|
subDto.setStatus("无选项");
|
|
|
|
subDto.setStatus("无选项");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//todo 兼容填空题
|
|
|
|
if(answerIds.size()>0&&answerList.size()>0&&qt!=null){
|
|
|
|
if (answerIds.size() > 0 && answerList.size() > 0) {
|
|
|
|
question.setQuestionType(qt.getCode());
|
|
|
|
question.setQuestionType(qt.getCode());
|
|
|
|
question.setAnswerList(answerList);
|
|
|
|
question.setAnswerList(answerList);
|
|
|
|
question.setAnswerId(answerIds);
|
|
|
|
question.setAnswerId(answerIds);
|
|
|
@ -156,11 +158,11 @@ public class QuestionImportBiz {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}catch (Exception ex){
|
|
|
|
} catch (Exception ex) {
|
|
|
|
subDto.setStatus("数据异常");
|
|
|
|
subDto.setStatus("数据异常");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
list.add(subDto);
|
|
|
|
list.add(subDto);
|
|
|
|
rowNo+=lineCount;
|
|
|
|
rowNo += lineCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dto.setList(list);
|
|
|
|
dto.setList(list);
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
@ -169,4 +171,159 @@ public class QuestionImportBiz {
|
|
|
|
|
|
|
|
|
|
|
|
return Result.success(dto);
|
|
|
|
return Result.success(dto);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Result<String> importExcel11(MultipartFile file, Long userNo, Long courseId) throws Exception {
|
|
|
|
|
|
|
|
//身份校验
|
|
|
|
|
|
|
|
if (userNo == null || userNo <= 0) {
|
|
|
|
|
|
|
|
return Result.error("无权操作");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UserVo user = feignUser.getByUserNo(userNo);
|
|
|
|
|
|
|
|
if (user == null || user.getUserType() < UserTypeEnum.TEACHER.getCode()) {
|
|
|
|
|
|
|
|
return Result.error("无权操作");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
List<Question> questionList = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Workbook workbook = WorkbookFactory.create(file.getInputStream());
|
|
|
|
|
|
|
|
Sheet sheet = workbook.getSheetAt(0);
|
|
|
|
|
|
|
|
// 迭代每一行
|
|
|
|
|
|
|
|
Iterator<Row> iterator = sheet.iterator();
|
|
|
|
|
|
|
|
iterator.next();
|
|
|
|
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
|
|
|
|
Row row = iterator.next();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*解析列,下标从0开始*/
|
|
|
|
|
|
|
|
Cell cell0 = row.getCell(0); //题型
|
|
|
|
|
|
|
|
Cell cell1 = row.getCell(1);//题干
|
|
|
|
|
|
|
|
Cell cell2 = row.getCell(2);//A
|
|
|
|
|
|
|
|
Cell cell3 = row.getCell(3);//B
|
|
|
|
|
|
|
|
Cell cell4 = row.getCell(4);//C
|
|
|
|
|
|
|
|
Cell cell5 = row.getCell(5);//D
|
|
|
|
|
|
|
|
Cell cell6 = row.getCell(6);//E
|
|
|
|
|
|
|
|
Cell cell7 = row.getCell(7);//答案
|
|
|
|
|
|
|
|
Cell cell8 = row.getCell(8);//分数
|
|
|
|
|
|
|
|
Cell cell9 = row.getCell(9);//解析
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//判断题的BCDE选项和解析可能为空
|
|
|
|
|
|
|
|
if (cell0 == null || cell1 == null || cell2 == null || cell3 == null || cell7 == null || cell8 == null) {
|
|
|
|
|
|
|
|
return Result.error("必填项不能为空!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String questType = this.getCellValue(cell0);//题型
|
|
|
|
|
|
|
|
String a = null;
|
|
|
|
|
|
|
|
String b = null;
|
|
|
|
|
|
|
|
if (!questType.equals("填空题")) {
|
|
|
|
|
|
|
|
a = this.getCellValue(cell2); //选项A
|
|
|
|
|
|
|
|
b = this.getCellValue(cell3);//选项B
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String stem = this.getCellValue(cell1);//题干
|
|
|
|
|
|
|
|
String answer = this.getCellValue(cell7);//答案
|
|
|
|
|
|
|
|
String score = this.getCellValue(cell8);//分值
|
|
|
|
|
|
|
|
String c = cell4 != null ? this.getCellValue(cell4) : null;
|
|
|
|
|
|
|
|
String d = cell5 != null ? this.getCellValue(cell5) : null;
|
|
|
|
|
|
|
|
String e = cell6 != null ? this.getCellValue(cell6) : null;
|
|
|
|
|
|
|
|
String analysis = cell9 != null ? this.getCellValue(cell9) : null; //答案解析
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Course course = courseDao.getById(courseId);
|
|
|
|
|
|
|
|
if (course == null) {
|
|
|
|
|
|
|
|
return Result.error("课程不存在");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Question temp = questionDao.getByStem(stem);
|
|
|
|
|
|
|
|
if (temp != null) {
|
|
|
|
|
|
|
|
return Result.error("题干已存在");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QuestionTypeEnum qt = null;
|
|
|
|
|
|
|
|
if (questType.equals(QuestionTypeEnum.SINGLE.getDesc())) {
|
|
|
|
|
|
|
|
qt = QuestionTypeEnum.SINGLE;
|
|
|
|
|
|
|
|
} else if (questType.equals(QuestionTypeEnum.MULTY.getDesc())) {
|
|
|
|
|
|
|
|
qt = QuestionTypeEnum.MULTY;
|
|
|
|
|
|
|
|
} else if (questType.equals(QuestionTypeEnum.JUDGE.getDesc())) {
|
|
|
|
|
|
|
|
qt = QuestionTypeEnum.JUDGE;
|
|
|
|
|
|
|
|
} else if (questType.equals(QuestionTypeEnum.GAPFILLING.getDesc())) {
|
|
|
|
|
|
|
|
qt = QuestionTypeEnum.GAPFILLING;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (qt == null) {
|
|
|
|
|
|
|
|
return Result.error("题型未匹配");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Question question = new Question();
|
|
|
|
|
|
|
|
question.setStem(stem);
|
|
|
|
|
|
|
|
question.setUserNo(userNo);
|
|
|
|
|
|
|
|
question.setCreateTime(new Date());
|
|
|
|
|
|
|
|
question.setStatus(0);
|
|
|
|
|
|
|
|
question.setScore(Long.parseLong(score));
|
|
|
|
|
|
|
|
question.setCreatorId(userNo);
|
|
|
|
|
|
|
|
question.setCreator(user.getName());
|
|
|
|
|
|
|
|
question.setType(0);
|
|
|
|
|
|
|
|
question.setAnalysis(analysis);
|
|
|
|
|
|
|
|
question.setCourseId(course.getId());
|
|
|
|
|
|
|
|
question.setLevelId(0);
|
|
|
|
|
|
|
|
question.setLevelName("通用");
|
|
|
|
|
|
|
|
question.setQuestionType(qt.getCode());
|
|
|
|
|
|
|
|
question.setCourseName(course.getName());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Answer> answerList = new ArrayList<>();
|
|
|
|
|
|
|
|
List<Integer> answerIds = new ArrayList<>();
|
|
|
|
|
|
|
|
String[] split = answer.split(",");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int id = 1; // 选项的ID
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (questType.equals("填空题")) {
|
|
|
|
|
|
|
|
Answer answerData = new Answer();
|
|
|
|
|
|
|
|
answerData.setId(id);
|
|
|
|
|
|
|
|
answerData.setTitle(answer);
|
|
|
|
|
|
|
|
answerList.add(answerData);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
String[] options = {a, b, c, d, e}; // 选项文本
|
|
|
|
|
|
|
|
for (String option : options) {
|
|
|
|
|
|
|
|
if (com.alibaba.cloud.commons.lang.StringUtils.isNotBlank(option)) {
|
|
|
|
|
|
|
|
Answer answerData = new Answer();
|
|
|
|
|
|
|
|
answerData.setId(id);
|
|
|
|
|
|
|
|
answerData.setTitle(option);
|
|
|
|
|
|
|
|
answerList.add(answerData);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
id++; // 每次循环递增ID
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (String s : split) {
|
|
|
|
|
|
|
|
int answerId = 1; // 默认A选项对应ID为1
|
|
|
|
|
|
|
|
if (s.equals("A")) {
|
|
|
|
|
|
|
|
answerId = 1;
|
|
|
|
|
|
|
|
} else if (s.equals("B")) {
|
|
|
|
|
|
|
|
answerId = 2;
|
|
|
|
|
|
|
|
} else if (s.equals("C")) {
|
|
|
|
|
|
|
|
answerId = 3;
|
|
|
|
|
|
|
|
} else if (s.equals("D")) {
|
|
|
|
|
|
|
|
answerId = 4;
|
|
|
|
|
|
|
|
} else if (s.equals("E")) {
|
|
|
|
|
|
|
|
answerId = 5;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
answerIds.add(answerId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
question.setAnswerList(answerList);
|
|
|
|
|
|
|
|
question.setAnswerId(answerIds);
|
|
|
|
|
|
|
|
questionList.add(question);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
questionDao.saveAll(questionList);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
return Result.error("系统异常,请联系管理员");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return Result.success("导入成功!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String getCellValue(Cell cell) {
|
|
|
|
|
|
|
|
if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
|
|
|
|
|
|
|
|
return String.valueOf(cell.getBooleanCellValue());
|
|
|
|
|
|
|
|
} else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
|
|
|
|
|
|
|
|
Double d = cell.getNumericCellValue();
|
|
|
|
|
|
|
|
return String.valueOf(d.intValue());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return String.valueOf(cell.getStringCellValue());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|