Browse Source

fix 导入

he2802 3 years ago
parent
commit
d84866dc3d

+ 1 - 1
zhongzheng-admin/src/main/java/com/zhongzheng/controller/bank/QuestionChapterController.java

@@ -81,7 +81,7 @@ public class QuestionChapterController extends BaseController {
     @PreAuthorize("@ss.hasPermi('system:chapter:query')")
     @GetMapping("/{chapterExamId}")
     public AjaxResult<QuestionChapterVo> getInfo(@PathVariable("chapterExamId" ) Long chapterExamId) {
-        return AjaxResult.success(iQuestionChapterService.queryById(chapterExamId));
+        return AjaxResult.success(iQuestionChapterService.getById(chapterExamId));
     }
 
     /**

+ 1 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/mapper/ExamQuestionMapper.java

@@ -18,4 +18,5 @@ import java.util.List;
 public interface ExamQuestionMapper extends BaseMapper<ExamQuestion> {
     List<ExamQuestionVo> getList(ExamQuestionQueryBo bo);
     List<ExamQuestionVo> getAppList(ExamQuestionQueryBo bo);
+
 }

+ 1 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/mapper/QuestionChapterMapper.java

@@ -16,4 +16,5 @@ import java.util.List;
  */
 public interface QuestionChapterMapper extends BaseMapper<QuestionChapter> {
     List<QuestionChapterVo> getList(QuestionChapterQueryBo bo);
+    QuestionChapterVo getById(Long chapterExamId);
 }

+ 4 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/service/IQuestionChapterService.java

@@ -22,6 +22,10 @@ public interface IQuestionChapterService extends IService<QuestionChapter> {
 	 * @return
 	 */
 	QuestionChapterVo queryById(Long chapterExamId);
+
+	QuestionChapterVo getById(Long chapterExamId);
+
+
 	List<QuestionChapterVo> getList(QuestionChapterQueryBo bo);
 
 	/**

+ 5 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/service/impl/QuestionChapterServiceImpl.java

@@ -59,6 +59,11 @@ public class QuestionChapterServiceImpl extends ServiceImpl<QuestionChapterMappe
         return BeanUtil.toBean(db, QuestionChapterVo.class);
     }
 
+    @Override
+    public QuestionChapterVo getById(Long chapterExamId) {
+        return this.baseMapper.getById(chapterExamId);
+    }
+
     @Override
     public List<QuestionChapterVo> getList(QuestionChapterQueryBo bo) {
         return questionChapterMapper.getList(bo);

+ 65 - 10
zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/service/impl/QuestionServiceImpl.java

@@ -450,6 +450,26 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
         return false;
     }
 
+    private boolean isOptionStart(String content) {
+        if (Validator.isNotEmpty(content)) {
+            if(content.startsWith("A.")||content.startsWith("B.")||content.startsWith("C.")||content.startsWith("D.")||content.startsWith("E.")
+                    ||content.startsWith("F.")){
+                return true;
+            }
+        }
+        return false;
+    }
+
+    private boolean isNotOptionStart(String content) {
+        if (Validator.isNotEmpty(content)) {
+            if(isQuestionStart(content)||content.startsWith("正确答案")||content.startsWith("解题思路")||content.startsWith("考查考点")||content.startsWith("老师解答")
+                    ||content.startsWith("单选题模板")||content.startsWith("判读题模板")||content.startsWith("问答题模板")||content.startsWith("多选题题模板")){
+                return true;
+            }
+        }
+        return false;
+    }
+
     private List<QuestionChildAddBo> copyList(List<QuestionChildAddBo> list){
         List<QuestionChildAddBo> nList = new ArrayList<>();
         for(QuestionChildAddBo addBo : list){
@@ -496,16 +516,19 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
 
                 Integer nowPart = -1;//0正文 1选项A 2选项B 3选项C 4选项D 5选项E 6选项F
                 String strContent = "";
+                String imgUrl  = null;
                 for (XWPFParagraph paragraph : paragraphList) {
                     content = paragraph.getText();
                     content = dealTxt(content);
                     List<XWPFRun> runs = paragraph.getRuns();
+                    imgUrl = null;
                     for (XWPFRun run : runs) {
                         Node node = run.getCTR().getDomNode();
 
                         // drawing 一个绘画的图片
                         Node drawingNode = getChildNode(node, "w:drawing");
                         if (drawingNode == null && content == null) {
+                            imgUrl = null;
                             continue;
                         }
                         //上传图片
@@ -536,12 +559,15 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                             } catch (Exception e) {
                                 e.printStackTrace();
                             }
-                            String imgUrl = ossHost + "/" + ossPath + "?x-oss-process=image/resize,w_" + wPx + ",h_" + HPx;
-                            if(Validator.isNotEmpty(content)&&content!=""){
-                                content =  content +"<br />" +"<p><img src=\"" + imgUrl + "\"></p>";
+                            imgUrl =  ossPath + "?x-oss-process=image/resize,w_" + wPx + ",h_" + HPx;
+                            if(isOptionStart(content)||(nowPart>0&&nowPart<7&&!isNotOptionStart(content))){
+                                //选项图片路径不用处理
+
                             }else{
-                                content = "<p><img src=\"" + imgUrl + "\"></p>";
+                                //正文图片
+                                content =  content +"<br />" +"<p><img src=\"" + ossHost + "/" + imgUrl + "\"></p>";
                             }
+
                         }
                     }
                     if (content.startsWith("#")||isQuestionStart(content)) {
@@ -624,9 +650,11 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                             bo1 = new QuestionChildAddBo();
                             bo1.setOptionsId(1L);
                             bo1.setContent(strContent.replace("A.", ""));
+                            bo1.setImgUrl(imgUrl);
                             optionsList.add(bo1);
                         }else{
                             bo1 = optionsList.get(0);
+                            bo1.setImgUrl(imgUrl);
                             bo1.setContent(strContent.replace("A.", ""));
                         }
                     }
@@ -642,10 +670,12 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                             bo1 = new QuestionChildAddBo();
                             bo1.setOptionsId(2L);
                             bo1.setContent(strContent.replace("B.", ""));
+                            bo1.setImgUrl(imgUrl);
                             optionsList.add(bo1);
                         }else{
                             bo1 = optionsList.get(1);
                             bo1.setContent(strContent.replace("B.", ""));
+                            bo1.setImgUrl(imgUrl);
                         }
                     }
                     //第三个选项
@@ -659,10 +689,12 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                         if(optionsList.size()<3){
                             bo1 = new QuestionChildAddBo();
                             bo1.setOptionsId(3L);
+                            bo1.setImgUrl(imgUrl);
                             bo1.setContent(strContent.replace("C.", ""));
                             optionsList.add(bo1);
                         }else{
                             bo1 = optionsList.get(2);
+                            bo1.setImgUrl(imgUrl);
                             bo1.setContent(strContent.replace("C.", ""));
                         }
                     }
@@ -678,10 +710,12 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                             bo1 = new QuestionChildAddBo();
                             bo1.setOptionsId(4L);
                             bo1.setContent(strContent.replace("D.", ""));
+                            bo1.setImgUrl(imgUrl);
                             optionsList.add(bo1);
                         }else{
                             bo1 = optionsList.get(3);
                             bo1.setContent(strContent.replace("D.", ""));
+                            bo1.setImgUrl(imgUrl);
                         }
                     }
                     //第五个选项
@@ -696,10 +730,12 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                             bo1 = new QuestionChildAddBo();
                             bo1.setOptionsId(5L);
                             bo1.setContent(strContent.replace("E.", ""));
+                            bo1.setImgUrl(imgUrl);
                             optionsList.add(bo1);
                         }else{
                             bo1 = optionsList.get(4);
                             bo1.setContent(strContent.replace("E.", ""));
+                            bo1.setImgUrl(imgUrl);
                         }
                     }
                     //第六个选项
@@ -714,10 +750,12 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                             bo1 = new QuestionChildAddBo();
                             bo1.setOptionsId(6L);
                             bo1.setContent(strContent.replace("F.", ""));
+                            bo1.setImgUrl(imgUrl);
                             optionsList.add(bo1);
                         }else{
                             bo1 = optionsList.get(5);
                             bo1.setContent(strContent.replace("F.", ""));
+                            bo1.setImgUrl(imgUrl);
                         }
                     }
                     //答案和题型
@@ -840,15 +878,18 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
 
                 Integer nowPart = -1;//0正文 1选项A 2选项B 3选项C 4选项D 5选项E 6选项F
                 String strContent = "";
+                String imgUrl = "";
                 for (XWPFParagraph paragraph : paragraphList) {
                     content = paragraph.getText();
                     List<XWPFRun> runs = paragraph.getRuns();
+                    imgUrl = null;
                     for (XWPFRun run : runs) {
                         Node node = run.getCTR().getDomNode();
 
                         // drawing 一个绘画的图片
                         Node drawingNode = getChildNode(node, "w:drawing");
                         if (drawingNode == null && content == null) {
+                            imgUrl = null;
                             continue;
                         }
                         //上传图片
@@ -869,18 +910,20 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
 
                             // 获取图片信息
                             PackagePart part = doc.getPartById(rid);
-                          /*  System.out.println(part.getContentType());
-                            System.out.println(part.getPartName().getName());
-                            System.out.println(part.getInputStream());
-                            System.out.println("------ run ------");*/
                             String ossPath = null;
                             try {
                                 ossPath = ossService.uploadInputStream(part.getInputStream(), 8);
                             } catch (Exception e) {
                                 e.printStackTrace();
                             }
-                            String imgUrl = ossHost + "/" + ossPath + "?x-oss-process=image/resize,w_" + wPx + ",h_" + HPx;
-                            content = "<p><img src=\"" + imgUrl + "\"></p>";
+                            imgUrl =  ossPath + "?x-oss-process=image/resize,w_" + wPx + ",h_" + HPx;
+                            if(isOptionStart(content)||(nowPart>0&&nowPart<7&&!isNotOptionStart(content))){
+                                //选项图片路径不用处理
+
+                            }else{
+                                //正文图片
+                                content =  content +"<br />" +"<p><img src=\"" + ossHost + "/" + imgUrl + "\"></p>";
+                            }
                         }
                     }
                     content = dealTxt(content);
@@ -963,10 +1006,12 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                         if(optionsList.size()<1){
                             bo1 = new QuestionChildAddBo();
                             bo1.setOptionsId(1L);
+                            bo1.setImgUrl(imgUrl);
                             bo1.setContent(strContent.replace("A.", ""));
                             optionsList.add(bo1);
                         }else{
                             bo1 = optionsList.get(0);
+                            bo1.setImgUrl(imgUrl);
                             bo1.setContent(strContent.replace("A.", ""));
                         }
                     }
@@ -981,10 +1026,12 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                         if(optionsList.size()<2){
                             bo1 = new QuestionChildAddBo();
                             bo1.setOptionsId(2L);
+                            bo1.setImgUrl(imgUrl);
                             bo1.setContent(strContent.replace("B.", ""));
                             optionsList.add(bo1);
                         }else{
                             bo1 = optionsList.get(1);
+                            bo1.setImgUrl(imgUrl);
                             bo1.setContent(strContent.replace("B.", ""));
                         }
                     }
@@ -999,10 +1046,12 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                         if(optionsList.size()<3){
                             bo1 = new QuestionChildAddBo();
                             bo1.setOptionsId(3L);
+                            bo1.setImgUrl(imgUrl);
                             bo1.setContent(strContent.replace("C.", ""));
                             optionsList.add(bo1);
                         }else{
                             bo1 = optionsList.get(2);
+                            bo1.setImgUrl(imgUrl);
                             bo1.setContent(strContent.replace("C.", ""));
                         }
                     }
@@ -1017,10 +1066,12 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                         if(optionsList.size()<4){
                             bo1 = new QuestionChildAddBo();
                             bo1.setOptionsId(4L);
+                            bo1.setImgUrl(imgUrl);
                             bo1.setContent(strContent.replace("D.", ""));
                             optionsList.add(bo1);
                         }else{
                             bo1 = optionsList.get(3);
+                            bo1.setImgUrl(imgUrl);
                             bo1.setContent(strContent.replace("D.", ""));
                         }
                     }
@@ -1035,10 +1086,12 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                         if(optionsList.size()<5){
                             bo1 = new QuestionChildAddBo();
                             bo1.setOptionsId(5L);
+                            bo1.setImgUrl(imgUrl);
                             bo1.setContent(strContent.replace("E.", ""));
                             optionsList.add(bo1);
                         }else{
                             bo1 = optionsList.get(4);
+                            bo1.setImgUrl(imgUrl);
                             bo1.setContent(strContent.replace("E.", ""));
                         }
                     }
@@ -1053,10 +1106,12 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                         if(optionsList.size()<6){
                             bo1 = new QuestionChildAddBo();
                             bo1.setOptionsId(6L);
+                            bo1.setImgUrl(imgUrl);
                             bo1.setContent(strContent.replace("F.", ""));
                             optionsList.add(bo1);
                         }else{
                             bo1 = optionsList.get(5);
+                            bo1.setImgUrl(imgUrl);
                             bo1.setContent(strContent.replace("F.", ""));
                         }
                     }

+ 2 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/vo/QuestionChapterVo.java

@@ -87,5 +87,7 @@ public class QuestionChapterVo {
 	@ApiModelProperty("修改时间")
 	@Excel(name = "修改时间")
 	private Long updateTime;
+	@ApiModelProperty("题目数量")
+	private Integer questionNum;
 
 }

+ 29 - 1
zhongzheng-system/src/main/resources/mapper/modules/bank/QuestionChapterMapper.xml

@@ -35,6 +35,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="examNum" column="exam_num"/>
         <result property="createTime" column="create_time"/>
         <result property="updateTime" column="update_time"/>
+        <result property="questionNum" column="question_num"/>
         <collection property="goodsList" column="chapter_exam_id" select="findGoodsList"/>
     </resultMap>
 
@@ -65,7 +66,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         cpt.project_name,
         cb.business_name,
         cs.subject_name,
-        (SELECT COUNT(qce.exam_id) FROM question_chapter_exam qce where qce.chapter_exam_id = qc.chapter_exam_id ) as exam_num
+        (SELECT COUNT(qce.exam_id) FROM question_chapter_exam qce where qce.chapter_exam_id = qc.chapter_exam_id ) as exam_num,
+        (SELECT COUNT(eq.question_id) FROM question_chapter_exam qce LEFT JOIN exam_question eq on qce.exam_id = eq.exam_id where qce.chapter_exam_id = qc.chapter_exam_id) as question_num
         FROM
         question_chapter qc
         LEFT JOIN question_business qb ON qc.chapter_exam_id = qb.major_id
@@ -113,4 +115,30 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </if>
         ORDER BY qc.chapter_exam_id DESC
     </select>
+
+    <select id="getById" parameterType="Long" resultMap="QuestionChapterResultVo">
+        SELECT
+        qc.*,
+        qb.education_type_id,
+        qb.business_id,
+        qb.project_id,
+        qb.subject_id,
+        cet.education_name,
+        cpt.project_name,
+        cb.business_name,
+        cs.subject_name,
+        (SELECT COUNT(qce.exam_id) FROM question_chapter_exam qce where qce.chapter_exam_id = qc.chapter_exam_id ) as exam_num,
+        (SELECT COUNT(eq.question_id) FROM question_chapter_exam qce LEFT JOIN exam_question eq on qce.exam_id = eq.exam_id where qce.chapter_exam_id = qc.chapter_exam_id) as question_num
+        FROM
+        question_chapter qc
+        LEFT JOIN question_business qb ON qc.chapter_exam_id = qb.major_id
+        AND qb.type = 3
+        LEFT JOIN course_education_type cet ON qb.education_type_id = cet.id AND cet.status =1
+        LEFT JOIN course_project_type cpt ON qb.project_id = cpt.id AND cpt.status =1
+        LEFT JOIN course_business cb ON qb.business_id = cb.id AND cb.status =1
+        LEFT JOIN course_subject cs ON cs.id = qb.subject_id  AND cs.status =1
+        where qc.chapter_exam_id= #{chapterExamId}
+
+
+    </select>
 </mapper>