ly 1 anno fa
parent
commit
635cff00a5

+ 96 - 3
master/src/main/java/com/ruoyi/project/training/elearn/controller/TElQuController.java

@@ -3,9 +3,7 @@ package com.ruoyi.project.training.elearn.controller;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.time.LocalDate;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
+import java.util.*;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -647,8 +645,10 @@ public class TElQuController extends BaseController {
                             break;
                         }
                     } else if (j == 1) {
+                        cellValue = replaceSubSup(cellValue);
                         qu.setContent(cellValue);
                     } else if (j == 2) {
+                        cellValue = replaceSubSup(cellValue);
                         if (qu.getQuType() != 3) {
                             options = cellValue.split(";");
                         }
@@ -780,4 +780,97 @@ public class TElQuController extends BaseController {
         logger.info("failRow:" + String.valueOf(failRow));
         return AjaxResult.success(String.valueOf(successNumber), failRow);
     }
+
+    // 通用方法:替换 <sub> 和 <sup> 标签
+    public static String replaceSubSup(String input) {
+        // 映射用于将字符替换为对应的 Unicode 上标或下标
+         Map<Character, String> subMap = new HashMap<>();
+        Map<Character, String> supMap = new HashMap<>();
+        // 下标映射:支持 0-9 和小写字母a
+        subMap.put('0', "\u2080");
+        subMap.put('1', "\u2081");
+        subMap.put('2', "\u2082");
+        subMap.put('3', "\u2083");
+        subMap.put('4', "\u2084");
+        subMap.put('5', "\u2085");
+        subMap.put('6', "\u2086");
+        subMap.put('7', "\u2087");
+        subMap.put('8', "\u2088");
+        subMap.put('9', "\u2089");
+        subMap.put('a', "\u2090");
+        subMap.put('b', "\u2091");
+        subMap.put('c', "\u2092");
+        subMap.put('d', "\u2093");
+        subMap.put('e', "\u2094");
+        subMap.put('g', "\u2095");
+        subMap.put('h', "\u2096");
+        subMap.put('k', "\u2097");
+        subMap.put('l', "\u2098");
+        subMap.put('m', "\u2099");
+        subMap.put('n', "\u209A");
+        subMap.put('o', "\u209B");
+        subMap.put('p', "\u209C");
+
+
+        // 上标映射:支持 0-9
+        supMap.put('0', "\u2070");
+        supMap.put('1', "\u00B9");
+        supMap.put('2', "\u00B2");
+        supMap.put('3', "\u00B3");
+        supMap.put('4', "\u2074");
+        supMap.put('5', "\u2075");
+        supMap.put('6', "\u2076");
+        supMap.put('7', "\u2077");
+        supMap.put('8', "\u2078");
+        supMap.put('9', "\u2079");
+        supMap.put('+', "\u207A");
+        supMap.put('-', "\u207B");
+        // 替换 <sub> 标签
+        while (input.contains("<sub>")) {
+            int startIndex = input.indexOf("<sub>");
+            int endIndex = input.indexOf("</sub>");
+
+            if (startIndex != -1 && endIndex != -1) {
+                String subContent = input.substring(startIndex + 5, endIndex);  // 获取 <sub> 中的内容
+                StringBuilder replacedSubContent = new StringBuilder();
+
+                // 遍历 <sub> 中的字符,替换成下标字符
+                for (char c : subContent.toCharArray()) {
+                    if (subMap.containsKey(c)) {
+                        replacedSubContent.append(subMap.get(c));  // 替换为下标字符
+                    } else {
+                        replacedSubContent.append(c);  // 保留原字符
+                    }
+                }
+
+                // 替换原来的 <sub> 标签为处理后的字符
+                input = input.substring(0, startIndex) + replacedSubContent + input.substring(endIndex + 6);
+            }
+        }
+
+        // 替换 <sup> 或 <SUP> 标签
+        while (input.contains("<SUP>") || input.contains("<sup>")) {
+            int startIndex = input.indexOf("<sup>") != -1 ? input.indexOf("<sup>") : input.indexOf("<SUP>");
+            int endIndex = input.indexOf("</sup>") != -1 ? input.indexOf("</sup>") : input.indexOf("</SUP>");
+
+            if (startIndex != -1 && endIndex != -1) {
+                String supContent = input.substring(startIndex + 5, endIndex);  // 获取 <sup> 中的内容
+                StringBuilder replacedSupContent = new StringBuilder();
+
+                // 遍历 <sup> 中的字符,替换成上标字符
+                for (char c : supContent.toCharArray()) {
+                    if (supMap.containsKey(c)) {
+                        replacedSupContent.append(supMap.get(c));  // 替换为上标字符
+                    } else {
+                        replacedSupContent.append(c);  // 保留原字符
+                    }
+                }
+
+                // 替换原来的 <sup> 标签为处理后的字符
+                input = input.substring(0, startIndex) + replacedSupContent + input.substring(endIndex + 6);
+            }
+        }
+
+        return input;
+    }
 }

+ 1 - 1
master/src/main/resources/mybatis/training/elearn/TElQuMapper.xml

@@ -42,7 +42,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             </if>
             <if test="quType != null "> and d.qu_type = #{quType}</if>
             <if test="qlevel != null "> and d.qlevel = #{qlevel}</if>
-            <if test="content != null  and content != ''"> and cd.ontent = #{content}</if>
+            <if test="content != null  and content != ''"> and d.content like concat(concat('%', #{content}), '%')</if>
             <if test="image != null  and image != ''"> and d.image = #{image}</if>
             <if test="analysis != null  and analysis != ''"> and d.analysis = #{analysis}</if>
             <if test="createrCode != null  and createrCode != ''"> and d.creater_code = #{createrCode}</if>

+ 9 - 0
ui/src/views/training/elearn/qu/index.vue

@@ -14,10 +14,19 @@
       <el-form-item label="题库" prop="repoIds">
         <repo-select v-model="queryParams.repoIds" :multi="true" />
       </el-form-item>
+      <el-form-item label="题目内容" prop="content">
+        <el-input
+          v-model="queryParams.content"
+          placeholder="请输入题目内容"
+          clearable
+          size="small"
+        />
+      </el-form-item>
       <el-form-item>
         <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
         <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
       </el-form-item>
+
     </el-form>
 
     <el-row :gutter="10" class="mb8">