deason %!s(int64=6) %!d(string=hai) anos
pai
achega
3e78f78f47

+ 5 - 14
examcloud-core-print-common/pom.xml

@@ -29,6 +29,10 @@
                     <groupId>com.google.code.findbugs</groupId>
                     <artifactId>jsr305</artifactId>
                 </exclusion>
+                <exclusion>
+                    <groupId>org.apache.poi</groupId>
+                    <artifactId>poi-ooxml</artifactId>
+                </exclusion>
             </exclusions>
         </dependency>
         <dependency>
@@ -87,11 +91,9 @@
             <groupId>com.google.code.findbugs</groupId>
             <artifactId>jsr305</artifactId>
         </dependency>
-        <!-- easyPoi start -->
-        <!--<dependency>
+        <dependency>
             <groupId>cn.afterturn</groupId>
             <artifactId>easypoi-base</artifactId>
-            <version>3.3.0</version>
             <exclusions>
                 <exclusion>
                     <groupId>com.google.guava</groupId>
@@ -107,16 +109,5 @@
                 </exclusion>
             </exclusions>
         </dependency>
-        <dependency>
-            <groupId>cn.afterturn</groupId>
-            <artifactId>easypoi-web</artifactId>
-            <version>3.3.0</version>
-        </dependency>
-        <dependency>
-            <groupId>cn.afterturn</groupId>
-            <artifactId>easypoi-annotation</artifactId>
-            <version>3.3.0</version>
-        </dependency>-->
-        <!-- easyPoi end -->
     </dependencies>
 </project>

+ 6 - 4
examcloud-core-print-common/src/main/java/cn/com/qmth/examcloud/core/print/common/Constants.java

@@ -36,17 +36,19 @@ public interface Constants {
     String PRT_CODE_403 = "PRT-000403";
 
     /* 导出文件默认名称 */
-    String PAPER_DOC_NAME = "试卷.docx";
-    String ANSWER_DOC_NAME = "答案.docx";
+    String PAPER_DOC_NAME = "试卷.doc";
+    String ANSWER_DOC_NAME = "答案.doc";
     String PAPER_PDF_NAME = "试卷.pdf";
     String ANSWER_PDF_NAME = "答案.pdf";
     String STRUCT_ZIP_NAME = "试卷结构.zip";
-    String OBJECTIVE_EXCEL_NAME = "客观题.xlsx";
-    String SUBJECTIVE_EXCEL_NAME = "主观题.xlsx";
+    String OBJECTIVE_EXCEL_NAME = "客观题.xls";
+    String SUBJECTIVE_EXCEL_NAME = "主观题.xls";
     String PAPER_DIR = "paper";
     String ANSWER_DIR = "answer";
 
     String SUFFIX_ZIP = ".zip";
+    String SUFFIX_WORD = ".doc";
+    String SUFFIX_EXCEL = ".xls";
 
     static String rootFileDir() {
         return Constants.class.getClassLoader().getResource("").getPath() + "/files";

+ 52 - 0
examcloud-core-print-common/src/main/java/cn/com/qmth/examcloud/core/print/common/utils/ExcelUtils.java

@@ -0,0 +1,52 @@
+/*
+ * *************************************************
+ * Copyright (c) 2018 QMTH. All Rights Reserved.
+ * Created by Deason on 2018-11-21 17:17:03.
+ * *************************************************
+ */
+
+package cn.com.qmth.examcloud.core.print.common.utils;
+
+import cn.afterturn.easypoi.excel.ExcelExportUtil;
+import cn.afterturn.easypoi.excel.entity.ExportParams;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * @author: fengdesheng
+ * @since: 2018/11/21
+ */
+public class ExcelUtils {
+    private static Logger log = LoggerFactory.getLogger(ExcelUtils.class);
+
+    public static <T> void toExcelFile(Class<T> clazz, List<T> list, File excelFile, String title) {
+        if (excelFile == null) {
+            log.warn("excelFile must be not null.");
+            return;
+        }
+
+        if (StringUtils.isBlank(title)) {
+            title = "";
+        }
+        ExportParams params = new ExportParams(title, title);
+
+        try (FileOutputStream fos = new FileOutputStream(excelFile);
+             Workbook workbook = ExcelExportUtil.exportExcel(params, clazz, list);) {
+
+            workbook.write(fos);
+        } catch (FileNotFoundException e) {
+            log.error(e.getMessage(), e);
+        } catch (IOException e) {
+            log.error(e.getMessage(), e);
+        }
+    }
+
+}

+ 10 - 9
examcloud-core-print-dao/src/main/java/cn/com/qmth/examcloud/core/print/entity/ObjectiveQuestionStructure.java

@@ -7,6 +7,7 @@
 
 package cn.com.qmth.examcloud.core.print.entity;
 
+import cn.afterturn.easypoi.excel.annotation.Excel;
 import cn.com.qmth.examcloud.core.print.common.IdEntity;
 
 import javax.persistence.Column;
@@ -34,13 +35,13 @@ public class ObjectiveQuestionStructure extends IdEntity {
     /**
      * 课程代码
      */
-    //@ExcelProperty(name = "课程代码", index = 0)
+    @Excel(name = "课程代码", orderNum = "0")
     @Column(length = 50)
     private String courseCode;
     /**
      * 课程名称
      */
-    //@ExcelProperty(name = "课程名称", index = 1)
+    @Excel(name = "课程名称", orderNum = "1")
     @Column(length = 50)
     private String courseName;
     /**
@@ -51,13 +52,13 @@ public class ObjectiveQuestionStructure extends IdEntity {
     /**
      * 试卷名称
      */
-    //@ExcelProperty(name = "试卷名称", index = 2)
+    @Excel(name = "试卷名称", orderNum = "2")
     @Column(length = 50)
     private String paperName;
     /**
      * 试卷类型(如:A、B)
      */
-    //@ExcelProperty(name = "试卷类型", index = 3)
+    @Excel(name = "试卷类型", orderNum = "3")
     @Column(length = 50)
     private String paperType;
     /**
@@ -65,29 +66,29 @@ public class ObjectiveQuestionStructure extends IdEntity {
      *
      * @See QuesStructType.java
      */
-    //@ExcelProperty(name = "题目类型", index = 6)
+    @Excel(name = "题目类型", orderNum = "6")
     @Column(length = 50)
     private String questionType;
     /**
      * 标准答案
      */
-    //@ExcelProperty(name = "标准答案", index = 7)
+    @Excel(name = "标准答案", orderNum = "7")
     @Column(length = 50)
     private String answer;
     /**
      * 大题号
      */
-    //@ExcelProperty(name = "大题号", index = 4)
+    @Excel(name = "大题号", orderNum = "4")
     private Integer sectionNum;
     /**
      * 小题号
      */
-    //@ExcelProperty(name = "小题号", index = 5)
+    @Excel(name = "小题号", orderNum = "5")
     private Integer unitNum;
     /**
      * 小题分数
      */
-    //@ExcelProperty(name = "小题分数", index = 8)
+    @Excel(name = "小题分数", orderNum = "8")
     private Double unitScore;
 
     public Long getExamId() {

+ 9 - 8
examcloud-core-print-dao/src/main/java/cn/com/qmth/examcloud/core/print/entity/SubjectiveQuestionStructure.java

@@ -7,6 +7,7 @@
 
 package cn.com.qmth.examcloud.core.print.entity;
 
+import cn.afterturn.easypoi.excel.annotation.Excel;
 import cn.com.qmth.examcloud.core.print.common.IdEntity;
 
 import javax.persistence.Column;
@@ -34,13 +35,13 @@ public class SubjectiveQuestionStructure extends IdEntity {
     /**
      * 课程代码
      */
-    //@ExcelProperty(name = "科目代码", index = 0)
+    @Excel(name = "科目代码", orderNum = "0")
     @Column(length = 50)
     private String courseCode;
     /**
      * 课程名称
      */
-    //@ExcelProperty(name = "科目名称", index = 1)
+    @Excel(name = "科目名称", orderNum = "1")
     @Column(length = 50)
     private String courseName;
     /**
@@ -51,35 +52,35 @@ public class SubjectiveQuestionStructure extends IdEntity {
     /**
      * 试卷名称
      */
-    //@ExcelProperty(name = "试卷名称", index = 2)
+    @Excel(name = "试卷名称", orderNum = "2")
     @Column(length = 50)
     private String paperName;
     /**
      * 试卷类型(如:A、B)
      */
-    //@ExcelProperty(name = "试卷类型", index = 3)
+    @Excel(name = "试卷类型", orderNum = "3")
     private String paperType;
     /**
      * 大题号
      */
-    //@ExcelProperty(name = "大题号", index = 4)
+    @Excel(name = "大题号", orderNum = "4")
     @Column(length = 50)
     private Integer sectionNum;
     /**
      * 大题名称
      */
-    //@ExcelProperty(name = "大题名称", index = 5)
+    @Excel(name = "大题名称", orderNum = "5")
     @Column(length = 100)
     private String sectionName;
     /**
      * 小题号
      */
-    //@ExcelProperty(name = "小题号", index = 6)
+    @Excel(name = "小题号", orderNum = "6")
     private Integer unitNum;
     /**
      * 小题分数
      */
-    //@ExcelProperty(name = "满分", index = 7)
+    @Excel(name = "满分", orderNum = "7")
     private Double unitScore;
 
     public Long getExamId() {

+ 21 - 0
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/QuestionStructureService.java

@@ -7,6 +7,11 @@
 
 package cn.com.qmth.examcloud.core.print.service;
 
+import cn.com.qmth.examcloud.core.print.entity.ObjectiveQuestionStructure;
+import cn.com.qmth.examcloud.core.print.entity.SubjectiveQuestionStructure;
+
+import java.util.List;
+
 /**
  * @author: fengdesheng
  * @since: 2018/10/22
@@ -21,4 +26,20 @@ public interface QuestionStructureService {
      */
     void savePaperQuestionStructure(Long examId, String paperId);
 
+    /**
+     * 获取客观题结构
+     *
+     * @param examId
+     * @param paperId
+     */
+    List<ObjectiveQuestionStructure> getObjectiveQuestionStructureList(Long examId, String paperId);
+
+    /**
+     * 获取主观题结构
+     *
+     * @param examId
+     * @param paperId
+     */
+    List<SubjectiveQuestionStructure> getSubjectiveQuestionStructureList(Long examId, String paperId);
+
 }

+ 21 - 7
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/impl/CoursePaperServiceImpl.java

@@ -12,6 +12,7 @@ import cn.com.qmth.examcloud.core.print.common.Constants;
 import cn.com.qmth.examcloud.core.print.common.jpa.SearchBuilder;
 import cn.com.qmth.examcloud.core.print.common.jpa.SpecUtils;
 import cn.com.qmth.examcloud.core.print.common.utils.Check;
+import cn.com.qmth.examcloud.core.print.common.utils.ExcelUtils;
 import cn.com.qmth.examcloud.core.print.common.utils.FileUtils;
 import cn.com.qmth.examcloud.core.print.entity.CoursePaper;
 import cn.com.qmth.examcloud.core.print.entity.CourseStatistic;
@@ -273,9 +274,9 @@ public class CoursePaperServiceImpl implements CoursePaperService {
         //封装待导出的试卷文件列表
         List<ExportFileInfo> exportFiles = new ArrayList<>();
         //封装试卷结构-客观题数据
-        List<ObjectiveQuestionStructure> objectiveStructures = new ArrayList<>();
+        List<ObjectiveQuestionStructure> allObjectives = new ArrayList<>();
         //封装试卷结构-主观题数据
-        List<SubjectiveQuestionStructure> subjectiveStructures = new ArrayList<>();
+        List<SubjectiveQuestionStructure> allSubjectives = new ArrayList<>();
 
         for (CourseStatistic statistic : statistics) {
             CoursePaper paper = statistic.getCoursePaper();
@@ -298,18 +299,22 @@ public class CoursePaperServiceImpl implements CoursePaperService {
             }
 
             if (req.getNeedStruct()) {
-                //todo
-                //objectiveStructures.add(...)
-                //subjectiveStructures.add(...)
+                //客观题结构
+                List<ObjectiveQuestionStructure> objectives = questionStructureService.getObjectiveQuestionStructureList(req.getExamId(), paper.getPaperId());
+                allObjectives.addAll(objectives);
+
+                //主观题结构
+                List<SubjectiveQuestionStructure> subjectives = questionStructureService.getSubjectiveQuestionStructureList(req.getExamId(), paper.getPaperId());
+                allSubjectives.addAll(subjectives);
             }
             exportFiles.add(info);
         }
 
         //打包所有文件
-        return packageFiles(exportFiles);
+        return packageFiles(exportFiles, allObjectives, allSubjectives, req.getNeedStruct());
     }
 
-    private File packageFiles(List<ExportFileInfo> exportFiles) {
+    private File packageFiles(List<ExportFileInfo> exportFiles, List<ObjectiveQuestionStructure> allObjectives, List<SubjectiveQuestionStructure> allSubjectives, Boolean needStruct) {
         //文件存放目录
         final String rootDir = Constants.rootFileDir();
         final String targetDir = rootDir + "/" + FileUtils.randomUUID();
@@ -326,6 +331,15 @@ public class CoursePaperServiceImpl implements CoursePaperService {
             this.loadFile(answerDir, info.getAnswerPdf());
         }
 
+        //生成试卷结构文件
+        if (needStruct) {
+            final String objectiveFile = targetDir + "/" + OBJECTIVE_EXCEL_NAME;
+            ExcelUtils.toExcelFile(ObjectiveQuestionStructure.class, allObjectives, new File(objectiveFile), "");
+
+            final String subjectiveFile = targetDir + "/" + SUBJECTIVE_EXCEL_NAME;
+            ExcelUtils.toExcelFile(SubjectiveQuestionStructure.class, allSubjectives, new File(subjectiveFile), "");
+        }
+
         //压缩打包所有文件
         File target = new File(targetDir);
         File zipFile = new File(targetDir + SUFFIX_ZIP);

+ 19 - 0
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/impl/QuestionStructureServiceImpl.java

@@ -15,6 +15,7 @@ import cn.com.qmth.examcloud.core.print.repository.SubjectiveQuestionStructureRe
 import cn.com.qmth.examcloud.core.print.service.CommonService;
 import cn.com.qmth.examcloud.core.print.service.QuestionStructureService;
 import cn.com.qmth.examcloud.core.print.service.bean.questionstructure.PaperQuestionStructureInfo;
+import com.google.common.collect.Lists;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -62,4 +63,22 @@ public class QuestionStructureServiceImpl implements QuestionStructureService {
         }
     }
 
+    @Override
+    public List<ObjectiveQuestionStructure> getObjectiveQuestionStructureList(Long examId, String paperId) {
+        //todo
+        ObjectiveQuestionStructure objective = new ObjectiveQuestionStructure();
+        objective.setCourseCode("123");
+        objective.setCourseName("测试课程");
+        return Lists.newArrayList(objective);
+    }
+
+    @Override
+    public List<SubjectiveQuestionStructure> getSubjectiveQuestionStructureList(Long examId, String paperId) {
+        //todo
+        SubjectiveQuestionStructure subjective = new SubjectiveQuestionStructure();
+        subjective.setCourseCode("123");
+        subjective.setCourseName("测试课程");
+        return Lists.newArrayList(subjective);
+    }
+
 }

+ 5 - 0
pom.xml

@@ -98,6 +98,11 @@
                 <artifactId>java-sdk</artifactId>
                 <version>3.20</version>
             </dependency>
+            <dependency>
+                <groupId>cn.afterturn</groupId>
+                <artifactId>easypoi-base</artifactId>
+                <version>3.3.0</version>
+            </dependency>
         </dependencies>
     </dependencyManagement>