|
@@ -1887,6 +1887,255 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> importJJWordQuestionList(MultipartFile file, Long eduId, Long projectId, Long businessId, Long subjectId) {
|
|
|
+ Map<String,Object> result = new HashMap<>();
|
|
|
+ List<QuestionAddBo> list = new ArrayList<>();
|
|
|
+ String errorLog = ""; //错误提示
|
|
|
+ String buffer = "";
|
|
|
+ String importNo = ServletUtils.getEncoded("IMPORT");
|
|
|
+ Long sort = 1L;
|
|
|
+ if(Validator.isEmpty(file)){
|
|
|
+ throw new CustomException("请选择文件");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ Long nowTime = DateUtils.getNowTime();
|
|
|
+ String path = file.getOriginalFilename();
|
|
|
+ if (path.endsWith(".doc")) {
|
|
|
+ throw new CustomException("不支持doc格式");
|
|
|
+ } else if (path.endsWith("docx")) {
|
|
|
+ InputStream is = file.getInputStream();
|
|
|
+ XWPFDocument doc = new XWPFDocument(is);
|
|
|
+ List<XWPFParagraph> paragraphList = doc.getParagraphs();
|
|
|
+ int type = -1; //题目类型
|
|
|
+ boolean isOption = false; //是否判断题
|
|
|
+ List<QuestionChildAddBo> optionsList = new ArrayList<>(); //题目选项
|
|
|
+ String content = ""; //每行正文
|
|
|
+ String qContent = ""; //题目正文
|
|
|
+ String answerQuestion = null; //答案
|
|
|
+ String analysisContent = ""; //解析文本
|
|
|
+ int index = 1; //题目序列号
|
|
|
+ List<QuestionBusinessAddBo> businessList = new ArrayList<>();
|
|
|
+ QuestionBusinessAddBo questionBusinessAddBo = new QuestionBusinessAddBo();
|
|
|
+ questionBusinessAddBo.setEducationTypeId(eduId);
|
|
|
+ questionBusinessAddBo.setProjectId(projectId);
|
|
|
+ questionBusinessAddBo.setBusinessId(businessId);
|
|
|
+ questionBusinessAddBo.setSubjectId(subjectId);
|
|
|
+ businessList.add(questionBusinessAddBo);
|
|
|
+
|
|
|
+ List<QuestionAddBo> list1 = new ArrayList<>(); //单选列表
|
|
|
+ List<QuestionAddBo> list2 = new ArrayList<>(); //多选列表
|
|
|
+ List<QuestionAddBo> list3 = new ArrayList<>(); //简答列表
|
|
|
+ List<QuestionAddBo> list4 = new ArrayList<>(); //判断列表
|
|
|
+ Map<String,QuestionAddBo> allQues = new HashMap<>();
|
|
|
+ Integer nowPart = -1;//0正文 1选项A 2选项B 3选项C 4选项D 5选项E 6选项F
|
|
|
+ String strContent = "";
|
|
|
+ String imgUrl = "";
|
|
|
+ boolean hasQuestion = false;
|
|
|
+ boolean hasRightTag = false;
|
|
|
+ boolean hasError = false;
|
|
|
+ boolean answerStatus = false;
|
|
|
+ int cIndex = 1;
|
|
|
+ int nIndex = 2;
|
|
|
+ List<String> alKeyList = new ArrayList<>();
|
|
|
+ alKeyList.add("案例(一)");
|
|
|
+ alKeyList.add("案例(二)");
|
|
|
+ alKeyList.add("案例(三)");
|
|
|
+ alKeyList.add("案例(四)");
|
|
|
+ alKeyList.add("案例(五)");
|
|
|
+ alKeyList.add("案例(六)");
|
|
|
+ alKeyList.add("案例(七)");
|
|
|
+ alKeyList.add("案例(八)");
|
|
|
+ alKeyList.add("案例(九)");
|
|
|
+ alKeyList.add("案例(十)");
|
|
|
+ String indexKey = null;
|
|
|
+ for (XWPFParagraph paragraph : paragraphList) {
|
|
|
+ content = paragraph.getText();
|
|
|
+ List<XWPFRun> runs = paragraph.getRuns();
|
|
|
+ imgUrl = null;
|
|
|
+ // System.out.println(content);
|
|
|
+ for (XWPFRun run : runs) {
|
|
|
+ Node node = run.getCTR().getDomNode();
|
|
|
+
|
|
|
+ // drawing 一个绘画的图片
|
|
|
+ Node drawingNode = getChildNode(node, "w:drawing");
|
|
|
+ if (drawingNode == null && content == null) {
|
|
|
+ imgUrl = null;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //上传图片
|
|
|
+ if (Validator.isNotEmpty(drawingNode)) {
|
|
|
+ System.out.println("有图片拉");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ content = dealTxt(content);
|
|
|
+ // System.out.println(content);
|
|
|
+ if (content.startsWith("#")) { //导入结束
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if(content.indexOf("单项选择题")>0&&!answerStatus){
|
|
|
+ System.out.println(content);
|
|
|
+ type = 1;
|
|
|
+ }
|
|
|
+ if(content.indexOf("多项选择题")>0&&!answerStatus){
|
|
|
+ type = 2;
|
|
|
+ }
|
|
|
+ if(content.indexOf("案例分析题")>0&&!answerStatus){
|
|
|
+ type = 5;
|
|
|
+ }
|
|
|
+ //单选,多选
|
|
|
+ if(type==1||type==2){
|
|
|
+ if(content.startsWith(cIndex+".")||content.startsWith(nIndex+".")){
|
|
|
+ if(content.startsWith(nIndex+".")){
|
|
|
+ indexKey =nIndex+".";
|
|
|
+ //上一道结束
|
|
|
+ cIndex++;
|
|
|
+ nIndex++;
|
|
|
+ }else{
|
|
|
+ indexKey =cIndex+".";
|
|
|
+ }
|
|
|
+ QuestionAddBo addBo = new QuestionAddBo();
|
|
|
+ qContent = content.replace(indexKey, "");
|
|
|
+ addBo.setContent(qContent);
|
|
|
+ addBo.setType(type);
|
|
|
+ addBo.setOptionsList(new ArrayList<>());
|
|
|
+ allQues.put(indexKey,addBo);
|
|
|
+ }
|
|
|
+ //第一个选项
|
|
|
+ if(content.startsWith("A.")) {
|
|
|
+ QuestionAddBo cAddBo = allQues.get(indexKey);
|
|
|
+ QuestionChildAddBo bo1;
|
|
|
+ bo1 = new QuestionChildAddBo();
|
|
|
+ bo1.setOptionsId(1L);
|
|
|
+ bo1.setImgUrl(imgUrl);
|
|
|
+ bo1.setContent(content.replace("A.", ""));
|
|
|
+ cAddBo.getOptionsList().add(bo1);
|
|
|
+
|
|
|
+ }
|
|
|
+ //第二个选项
|
|
|
+ if (content.startsWith("B.")) {
|
|
|
+ QuestionChildAddBo bo1;
|
|
|
+ bo1 = new QuestionChildAddBo();
|
|
|
+ bo1.setOptionsId(2L);
|
|
|
+ bo1.setImgUrl(imgUrl);
|
|
|
+ bo1.setContent(content.replace("B.", ""));
|
|
|
+ QuestionAddBo cAddBo = allQues.get(indexKey);
|
|
|
+ cAddBo.getOptionsList().add(bo1);
|
|
|
+ }
|
|
|
+ //第三个选项
|
|
|
+ if (content.startsWith("C.")) {
|
|
|
+ QuestionChildAddBo bo1;
|
|
|
+ bo1 = new QuestionChildAddBo();
|
|
|
+ bo1.setOptionsId(2L);
|
|
|
+ bo1.setImgUrl(imgUrl);
|
|
|
+ bo1.setContent(content.replace("C.", ""));
|
|
|
+ QuestionAddBo cAddBo = allQues.get(indexKey);
|
|
|
+ cAddBo.getOptionsList().add(bo1);
|
|
|
+ }
|
|
|
+ //第四个选项
|
|
|
+ if (content.startsWith("D.")) {
|
|
|
+ QuestionChildAddBo bo1;
|
|
|
+ bo1 = new QuestionChildAddBo();
|
|
|
+ bo1.setOptionsId(2L);
|
|
|
+ bo1.setImgUrl(imgUrl);
|
|
|
+ bo1.setContent(content.replace("D.", ""));
|
|
|
+ QuestionAddBo cAddBo = allQues.get(indexKey);
|
|
|
+ cAddBo.getOptionsList().add(bo1);
|
|
|
+ }
|
|
|
+ //第五个选项
|
|
|
+ if (content.startsWith("E.")) {
|
|
|
+ QuestionChildAddBo bo1;
|
|
|
+ bo1 = new QuestionChildAddBo();
|
|
|
+ bo1.setOptionsId(2L);
|
|
|
+ bo1.setImgUrl(imgUrl);
|
|
|
+ bo1.setContent(content.replace("E.", ""));
|
|
|
+ QuestionAddBo cAddBo = allQues.get(indexKey);
|
|
|
+ cAddBo.getOptionsList().add(bo1);
|
|
|
+ }
|
|
|
+ //第六个选项
|
|
|
+ if (content.startsWith("F.")) {
|
|
|
+ QuestionChildAddBo bo1;
|
|
|
+ bo1 = new QuestionChildAddBo();
|
|
|
+ bo1.setOptionsId(2L);
|
|
|
+ bo1.setImgUrl(imgUrl);
|
|
|
+ bo1.setContent(content.replace("F.", ""));
|
|
|
+ QuestionAddBo cAddBo = allQues.get(indexKey);
|
|
|
+ cAddBo.getOptionsList().add(bo1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //问答
|
|
|
+ if(type==5){
|
|
|
+ if(alKeyList.contains(content)){
|
|
|
+ indexKey = content;
|
|
|
+ QuestionAddBo addBo = new QuestionAddBo();
|
|
|
+ addBo.setType(type);
|
|
|
+ addBo.setContent("");
|
|
|
+ allQues.put(indexKey,addBo);
|
|
|
+ }else{
|
|
|
+ QuestionAddBo cAddBo = allQues.get(indexKey);
|
|
|
+ cAddBo.setContent(cAddBo.getContent()+ content+"<br />");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(content.startsWith("参考答案及解析")){
|
|
|
+ answerStatus = true;
|
|
|
+ }
|
|
|
+ if(content.indexOf("单项选择题")>0&&answerStatus){
|
|
|
+
|
|
|
+ }
|
|
|
+ if(content.indexOf("多项选择题")>0&&answerStatus){
|
|
|
+
|
|
|
+ }
|
|
|
+ if(content.indexOf("案例分析题")>0&&answerStatus){
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ System.out.println("结束");
|
|
|
+ System.out.println(allQues);
|
|
|
+ //遍历正文
|
|
|
+ int importSort = 1;
|
|
|
+ Collections.reverse(list4);
|
|
|
+ Collections.reverse(list3);
|
|
|
+ Collections.reverse(list2);
|
|
|
+ Collections.reverse(list1);
|
|
|
+ for(QuestionAddBo addBo : list3){
|
|
|
+ addBo.setImportSort(importSort + addBo.getCreateTime());
|
|
|
+ list.add(addBo);
|
|
|
+ importSort++;
|
|
|
+ }
|
|
|
+ for(QuestionAddBo addBo : list4){
|
|
|
+ addBo.setImportSort(importSort + addBo.getCreateTime());
|
|
|
+ list.add(addBo);
|
|
|
+ importSort++;
|
|
|
+ }
|
|
|
+ for(QuestionAddBo addBo : list2){
|
|
|
+ addBo.setImportSort(importSort + addBo.getCreateTime());
|
|
|
+ list.add(addBo);
|
|
|
+ importSort++;
|
|
|
+ }
|
|
|
+ for(QuestionAddBo addBo : list1){
|
|
|
+ addBo.setImportSort(importSort + addBo.getCreateTime());
|
|
|
+ list.add(addBo);
|
|
|
+ importSort++;
|
|
|
+ }
|
|
|
+ // buffer = extractor.getText();
|
|
|
+ //extractor.close();
|
|
|
+
|
|
|
+ } else {
|
|
|
+ throw new CustomException("请导入word文件!");
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ System.out.println("此文件不是word文件!" + e.getMessage() + e.toString() + e.getLocalizedMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ Collections.reverse(list);
|
|
|
+ result.put("list",list);
|
|
|
+ result.put("errorLog",errorLog);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public boolean batchDelQuestion(QuestionBatchDelBo bo) {
|