he2802 3 éve
szülő
commit
766bd94fb9

+ 10 - 0
zhongzheng-admin/src/main/java/com/zhongzheng/controller/bank/QuestionController.java

@@ -174,4 +174,14 @@ public class QuestionController extends BaseController {
             return AjaxResult.success();
         }
     }
+
+    @Log(title = "导入题目Word模板", businessType = BusinessType.IMPORT)
+    @ApiOperation("导入题目Word模板")
+    @PreAuthorize("@ss.hasPermi('system:question:import')")
+    @PostMapping("/importWordData")
+    public AjaxResult importWordData(MultipartFile file, boolean updateSupport) throws Exception
+    {
+        iQuestionService.importWordQuestion(file);
+        return AjaxResult.success();
+    }
 }

+ 22 - 6
zhongzheng-common/pom.xml

@@ -91,17 +91,33 @@
             <artifactId>fastjson</artifactId>
         </dependency>
 
-        <!-- excel工具 -->
-        <!--    <dependency>
-                <groupId>org.apache.poi</groupId>
-                <artifactId>poi-ooxml</artifactId>
-            </dependency>-->
         <dependency>
             <groupId>cn.afterturn</groupId>
             <artifactId>easypoi-spring-boot-starter</artifactId>
-            <version>4.0.0</version>
+            <version>4.1.0</version>
         </dependency>
+        <!-- excel工具 -->
+           <dependency>
+                <groupId>org.apache.poi</groupId>
+                <artifactId>poi-ooxml</artifactId>
+               <version>4.1.0</version>
+            </dependency>
 
+        <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>poi</artifactId>
+            <version>4.1.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>poi-scratchpad</artifactId>
+            <version>4.1.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>ooxml-schemas</artifactId>
+            <version>1.1</version>
+        </dependency>
 
             <!-- yml解析器 -->
         <dependency>

+ 24 - 2
zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/service/impl/QuestionServiceImpl.java

@@ -34,6 +34,11 @@ import com.zhongzheng.modules.exam.service.IExamKnowledgeService;
 import com.zhongzheng.modules.goods.bo.GoodsQueryBo;
 import com.zhongzheng.modules.goods.vo.GoodsUserQuestionVo;
 import io.micrometer.core.lang.NonNull;
+import org.apache.poi.hwpf.extractor.WordExtractor;
+import org.apache.poi.ooxml.POIXMLDocument;
+import org.apache.poi.ooxml.extractor.POIXMLTextExtractor;
+import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
 import org.apache.poi.xwpf.usermodel.XWPFDocument;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -329,9 +334,26 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
 
     @Override
     public void importWordQuestion(MultipartFile file) {
+        String buffer = "";
         try{
-           /* InputStream inputStream = baseInfoFile.getInputStream();
-            XWPFDocument doc = new XWPFDocument(inputStream);*/
+            String path = file.getOriginalFilename();
+            if (path.endsWith(".doc")) {
+                InputStream is = file.getInputStream();
+
+                WordExtractor wordExtractor = new WordExtractor(is);
+                buffer = wordExtractor.getText();
+                wordExtractor.close();
+                System.out.println("CC");
+                System.out.println(buffer);
+            } else if (path.endsWith("docx")) {
+                OPCPackage opcPackage = POIXMLDocument.openPackage(path);
+                POIXMLTextExtractor extractor = new XWPFWordExtractor(opcPackage);
+                buffer = extractor.getText();
+                extractor.close();
+                System.out.println(buffer);
+            } else {
+                System.out.println("此文件不是word文件!");
+            }
         }catch (Exception e){
 
         }