|
@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.ynfy.buss.exam.paper.enmus.LevelType;
|
|
|
import com.ynfy.buss.exam.question.dto.QuestionConditionDTO;
|
|
|
import com.ynfy.buss.exam.question.dto.QuestionDTO;
|
|
|
import com.ynfy.buss.exam.question.entity.Question;
|
|
@@ -29,6 +30,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import javax.servlet.http.Cookie;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.BufferedInputStream;
|
|
|
import java.io.IOException;
|
|
@@ -613,4 +615,46 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void castExcel(MultipartFile file) throws Exception {
|
|
|
+ ExcelReader reader = ExcelUtil.getReader(file.getInputStream());
|
|
|
+ List<List<Object>> dataList = reader.read();
|
|
|
+ if (!CollectionUtils.isEmpty(dataList)) {
|
|
|
+ Iterator<List<Object>> iterator = dataList.iterator();
|
|
|
+ List<Question> questionList = new ArrayList<>();
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ List<Object> objectList = iterator.next();
|
|
|
+ String content = String.valueOf(objectList.get(0));
|
|
|
+ char c = content.charAt(0);
|
|
|
+ if (Character.isDigit(c)) {//字符串以数字开头
|
|
|
+ Question question = new Question();
|
|
|
+ String str = content.substring(content.indexOf(":") + 1, content.lastIndexOf(":")).replace("答案", "").trim();
|
|
|
+ question.setContent(str.startsWith(".") ? str.replace(".", "") : str);
|
|
|
+ question.setRemark(content.substring(content.lastIndexOf(":") + 1).trim());//正确答案
|
|
|
+ question.setType(QuestionType.RADIO.getCode());
|
|
|
+ question.setLevel(LevelType.YB.getCode());
|
|
|
+ question.setId(IdUtil.getSnowflake(1, 1).nextIdStr());
|
|
|
+ question.setAnswerList(new ArrayList<>());
|
|
|
+ questionList.add(question);
|
|
|
+ } else if (Character.isLetter(c)) {//字符串以字母开头
|
|
|
+ QuestionAnswer answer = new QuestionAnswer();
|
|
|
+ Question relateQuestion = questionList.get(questionList.size() - 1);
|
|
|
+ List<QuestionAnswer> answerList = relateQuestion.getAnswerList();
|
|
|
+ answer.setQuestionId(relateQuestion.getId());
|
|
|
+ answer.setTag(String.valueOf(c));
|
|
|
+ answer.setContent(content.substring(content.indexOf(".") + 1).trim());
|
|
|
+ answer.setIsRight(relateQuestion.getRemark().equals(answer.getTag()));
|
|
|
+ answer.setSort(answerList.size() + 1);
|
|
|
+ answerList.add(answer);
|
|
|
+ }
|
|
|
+ iterator.remove();
|
|
|
+ }
|
|
|
+ saveBatch(questionList);
|
|
|
+ List<QuestionAnswer> questionAnswerList = new ArrayList<>();
|
|
|
+ questionList.forEach(question -> questionAnswerList.addAll(question.getAnswerList()));
|
|
|
+ questionAnswerService.saveBatch(questionAnswerList);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|