Quellcode durchsuchen

重构代码,修复log4j2的问题

宋悦 vor 8 Jahren
Ursprung
Commit
b50808a4b1
41 geänderte Dateien mit 501 neuen und 846 gelöschten Zeilen
  1. 31 19
      cqb-comm-utils/pom.xml
  2. 28 4
      cqb-comm-utils/src/main/java/com/qmth/cqb/utils/CommonUtils.java
  3. 0 147
      cqb-comm-utils/src/main/java/com/qmth/cqb/utils/ConvertOutHtml.java
  4. 0 73
      cqb-comm-utils/src/main/java/com/qmth/cqb/utils/ParserDocxUtils.java
  5. 23 16
      cqb-comm-utils/src/main/java/com/qmth/cqb/utils/word/DocxProcessUtil.java
  6. 1 6
      cqb-comm-utils/src/main/resources/log4j.properties
  7. 0 9
      cqb-paper/src/main/java/com/qmth/cqb/paper/dao/PaperStructDetailRepo.java
  8. 22 21
      cqb-paper/src/main/java/com/qmth/cqb/paper/dto/PaperDetailExp.java
  9. 22 10
      cqb-paper/src/main/java/com/qmth/cqb/paper/dto/PaperDetailUnitExp.java
  10. 8 7
      cqb-paper/src/main/java/com/qmth/cqb/paper/dto/PaperExp.java
  11. 6 9
      cqb-paper/src/main/java/com/qmth/cqb/paper/model/ExamPaper.java
  12. 1 1
      cqb-paper/src/main/java/com/qmth/cqb/paper/model/ExtractConfig.java
  13. 0 14
      cqb-paper/src/main/java/com/qmth/cqb/paper/model/PaperDetail.java
  14. 8 32
      cqb-paper/src/main/java/com/qmth/cqb/paper/model/PaperDetailStruct.java
  15. 4 7
      cqb-paper/src/main/java/com/qmth/cqb/paper/model/PaperDetailUnit.java
  16. 47 0
      cqb-paper/src/main/java/com/qmth/cqb/paper/model/PaperDetailUnitStruct.java
  17. 5 5
      cqb-paper/src/main/java/com/qmth/cqb/paper/model/PaperStruct.java
  18. 20 20
      cqb-paper/src/main/java/com/qmth/cqb/paper/service/ExportPaperService.java
  19. 7 16
      cqb-paper/src/main/java/com/qmth/cqb/paper/service/ExtractService.java
  20. 36 29
      cqb-paper/src/main/java/com/qmth/cqb/paper/service/ImportPaperService.java
  21. 18 12
      cqb-paper/src/main/java/com/qmth/cqb/paper/service/PaperDetailService.java
  22. 7 10
      cqb-paper/src/main/java/com/qmth/cqb/paper/service/PaperDetailUnitService.java
  23. 34 21
      cqb-paper/src/main/java/com/qmth/cqb/paper/service/PaperService.java
  24. 0 63
      cqb-paper/src/main/java/com/qmth/cqb/paper/service/PaperStructDetailService.java
  25. 1 3
      cqb-paper/src/main/java/com/qmth/cqb/paper/service/PaperStructService.java
  26. 0 6
      cqb-paper/src/main/java/com/qmth/cqb/paper/web/ExtractController.java
  27. 4 4
      cqb-paper/src/main/java/com/qmth/cqb/paper/web/ImportPaperController.java
  28. 29 31
      cqb-paper/src/main/java/com/qmth/cqb/paper/web/PaperController.java
  29. 58 57
      cqb-paper/src/main/java/com/qmth/cqb/paper/web/PaperDetailController.java
  30. 51 54
      cqb-paper/src/main/java/com/qmth/cqb/paper/web/PaperDetailUnitController.java
  31. 16 36
      cqb-paper/src/main/java/com/qmth/cqb/paper/web/PaperStructController.java
  32. 0 81
      cqb-paper/src/main/java/com/qmth/cqb/paper/web/PaperStructDetailController.java
  33. 4 3
      cqb-question-resource/src/main/java/com/qmth/cqb/question/model/Question.java
  34. 2 5
      cqb-question-resource/src/main/java/com/qmth/cqb/question/service/QuesService.java
  35. BIN
      cqb-question-resource/target/classes/com/qmth/cqb/question/model/Question.class
  36. BIN
      cqb-question-resource/target/classes/com/qmth/cqb/question/service/QuesService.class
  37. 1 1
      cqb-question-resource/target/maven-archiver/pom.properties
  38. 2 1
      cqb-starter/pom.xml
  39. 1 1
      cqb-starter/src/main/resources/application.properties
  40. 1 8
      cqb-starter/src/main/resources/log4j2.xml
  41. 3 4
      cqb-starter/src/test/java/com/qmth/cqb/AppTest.java

+ 31 - 19
cqb-comm-utils/pom.xml

@@ -24,11 +24,6 @@
             <version>2.7</version>
         </dependency>
 
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-log4j2</artifactId>
-        </dependency>
-
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-web</artifactId>
@@ -58,12 +53,6 @@
             <scope>test</scope>
         </dependency>
 
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-test</artifactId>
-            <scope>test</scope>
-        </dependency>
-
         <dependency>
             <groupId>org.apache.commons</groupId>
             <artifactId>commons-lang3</artifactId>
@@ -77,15 +66,43 @@
         </dependency>
 
         <dependency>
-            <groupId>org.apache.logging.log4j</groupId>
-            <artifactId>log4j-core</artifactId>
-            <version>2.7</version>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-collections4</artifactId>
+            <version>4.1</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-math3</artifactId>
+            <version>3.6.1</version>
+        </dependency>
+
+        <dependency>
+            <groupId>commons-codec</groupId>
+            <artifactId>commons-codec</artifactId>
+            <version>1.10</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-text</artifactId>
+            <version>1.0</version>
         </dependency>
 
         <dependency>
             <groupId>org.docx4j</groupId>
             <artifactId>docx4j</artifactId>
             <version>3.3.3</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.slf4j</groupId>
+                    <artifactId>slf4j-api</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>org.slf4j</groupId>
+                    <artifactId>slf4j-log4j12</artifactId>
+                </exclusion>
+            </exclusions>
         </dependency>
 
         <dependency>
@@ -148,10 +165,5 @@
             <version>1.11.3</version>
         </dependency>
 
-         <dependency>
-             <groupId>org.docx4j</groupId>
- 	         <artifactId>docx4j</artifactId>
-	          <version>3.3.3</version>
-         </dependency>
     </dependencies>
 </project>

+ 28 - 4
cqb-comm-utils/src/main/java/com/qmth/cqb/utils/CommonUtils.java

@@ -6,8 +6,7 @@ import java.io.BufferedReader;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Properties;
+import java.util.*;
 import java.util.stream.Stream;
 
 /**
@@ -73,6 +72,14 @@ public final class CommonUtils {
         return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
     }
 
+    /**
+     * 根据当前日期获取数字字符串
+     * @return
+     */
+    public static String getCurNum(){
+        return new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date());
+    }
+
     /**
      * 根据枚举名称获取枚举
      * @param clazz
@@ -83,7 +90,7 @@ public final class CommonUtils {
     public static <T> T getEnum(Class<T> clazz, String name){
         T[] enumConstants = clazz.getEnumConstants();
         for(T _enum : enumConstants){
-            if(_enum.toString().equals(name)){
+                if(_enum.toString().equals(name)){
                 return _enum;
             }
         }
@@ -121,9 +128,26 @@ public final class CommonUtils {
 
     }
 
+    /**
+     * iterator转List
+     * @param <T>
+     * @param iterator
+     * @return
+     */
+    public static <T> List<T> toList(Iterable<T> iterator) {
+        if (iterator == null) {
+            throw new NullPointerException("Iterator must not be null");
+        }
+        final List<T> list = new ArrayList<T>();
+        final Iterator<T> iter = iterator.iterator();
+        while (iter.hasNext())
+            list.add(iter.next());
+        return list;
+    }
+
     public static void main(String[] args) {
 //        QuesStructType quesStructType = getEnum(QuesStructType.class,"单选");
 //        System.out.println(quesStructType.getName());
-        System.out.println(toCHNum(1));
+        System.out.println(getCurNum());
     }
 }

+ 0 - 147
cqb-comm-utils/src/main/java/com/qmth/cqb/utils/ConvertOutHtml.java

@@ -1,147 +0,0 @@
-package com.qmth.cqb.utils;
-
-import java.io.ByteArrayOutputStream;
-import java.io.FileOutputStream;
-import java.io.OutputStream;
-import org.docx4j.Docx4J;
-import org.docx4j.Docx4jProperties;
-import org.docx4j.convert.out.ConversionFeatures;
-import org.docx4j.convert.out.HTMLSettings;
-import org.docx4j.convert.out.html.SdtToListSdtTagHandler;
-import org.docx4j.convert.out.html.SdtWriter;
-import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
-import org.docx4j.samples.AbstractSample;
-
-
-public class ConvertOutHtml extends AbstractSample  {
-	
-	
-
-		// Config for non-command line version
-		static {
-		
-	    	inputfilepath = System.getProperty("user.dir") + "/test/test.docx";
-
-			save = false;
-			nestLists = false;
-		}
-
-		static boolean save;
-		static boolean nestLists;
-
-	    public static void main(String[] args)
-	            throws Exception {
-	    	
-			try {
-				getInputFilePath(args);
-			} catch (IllegalArgumentException e) {
-			}
-			
-			// Document loading (required)
-			WordprocessingMLPackage wordMLPackage;
-			if (inputfilepath==null) {
-				// Create a docx
-				System.out.println("No imput path passed, creating dummy document");
-				 wordMLPackage = WordprocessingMLPackage.createPackage();
-				//SampleDocument.createContent(wordMLPackage.getMainDocumentPart());	
-			} else {
-				System.out.println("Loading file from " + inputfilepath);
-				wordMLPackage = Docx4J.load(new java.io.File(inputfilepath));
-			}
-
-			// HTML exporter setup (required)
-			// .. the HTMLSettings object
-	    	HTMLSettings htmlSettings = Docx4J.createHTMLSettings();
-
-	    	htmlSettings.setImageDirPath(inputfilepath + "_files");
-	    	htmlSettings.setImageTargetUri(inputfilepath.substring(inputfilepath.lastIndexOf("/")+1)
-	    			+ "_files");
-	    	htmlSettings.setWmlPackage(wordMLPackage);
-	    	
-	    	
-	    	/* CSS reset, see http://itumbcom.blogspot.com.au/2013/06/css-reset-how-complex-it-should-be.html 
-	    	 * 
-	    	 * motivated by vertical space in tables in Firefox and Google Chrome.
-	        
-		        If you have unwanted vertical space, in Chrome this may be coming from -webkit-margin-before and -webkit-margin-after
-		        (in Firefox, margin-top is set to 1em in html.css)
-		        
-		        Setting margin: 0 on p is enough to fix it.
-		        
-		        See further http://www.css-101.org/articles/base-styles-sheet-for-webkit-based-browsers/    	
-	    	*/
-	    	String userCSS = null;
-	    	if (nestLists) {
-	    		// use browser defaults for ol, ul, li
-	    		userCSS = "html, body, div, span, h1, h2, h3, h4, h5, h6, p, a, img,  table, caption, tbody, tfoot, thead, tr, th, td " +
-	    			"{ margin: 0; padding: 0; border: 0;}" +
-	    			"body {line-height: 1;} ";
-	    	} else {
-	    		userCSS = "html, body, div, span, h1, h2, h3, h4, h5, h6, p, a, img,  ol, ul, li, table, caption, tbody, tfoot, thead, tr, th, td " +
-	        			"{ margin: 0; padding: 0; border: 0;}" +
-	        			"body {line-height: 1;} ";
-	    		
-	    	}
-	    	htmlSettings.setUserCSS(userCSS);
-	    	
-	    	
-	    	//Other settings (optional)
-//	    	htmlSettings.setUserBodyTop("<H1>TOP!</H1>");
-//	    	htmlSettings.setUserBodyTail("<H1>TAIL!</H1>");
-			
-			// Sample sdt tag handler (tag handlers insert specific
-			// html depending on the contents of an sdt's tag).
-			// This will only have an effect if the sdt tag contains
-			// the string @class=XXX
-//				SdtWriter.registerTagHandler("@class", new TagClass() );
-			
-//			SdtWriter.registerTagHandler(Containerization.TAG_BORDERS, new TagSingleBox() );
-//			SdtWriter.registerTagHandler(Containerization.TAG_SHADING, new TagSingleBox() );
-	    	
-	    	
-	    	// list numbering:  depending on whether you want list numbering hardcoded, or done using <li>.
-	    	if (nestLists) {
-	    		SdtWriter.registerTagHandler("HTML_ELEMENT", new SdtToListSdtTagHandler());
-	    	} else {
-	    		htmlSettings.getFeatures().remove(ConversionFeatures.PP_HTML_COLLECT_LISTS);
-	    	}
-			
-			// output to an OutputStream.		
-			OutputStream os; 
-			if (save) {
-				os = new FileOutputStream(inputfilepath + ".html");
-			} else {
-				os = new ByteArrayOutputStream();
-				
-			}
-
-			// If you want XHTML output
-	    	Docx4jProperties.setProperty("docx4j.Convert.Out.HTML.OutputMethodXML", true);
-
-			//Don't care what type of exporter you use
-			Docx4J.toHTML(htmlSettings, os, Docx4J.FLAG_NONE);
-			//Prefer the exporter, that uses a xsl transformation
-			//Docx4J.toHTML(htmlSettings, os, Docx4J.FLAG_EXPORT_PREFER_XSL);
-			//Prefer the exporter, that doesn't use a xsl transformation (= uses a visitor)
-//			Docx4J.toHTML(htmlSettings, os, Docx4J.FLAG_EXPORT_PREFER_NONXSL);
-			//String originalHtml = new String(os.toString(), "UTF-8");
-			if (save) {
-				System.out.println("Saved: " + inputfilepath + ".html ");
-			} else {
-				//System.out.println( ((ByteArrayOutputStream)os).toString() );
-				String originalHtml = ((ByteArrayOutputStream)os).toString();
-				//System.out.println(CommonUtils.extractText(html));
-				originalHtml = originalHtml.substring(originalHtml.indexOf("<body>") + "<body>".length(),originalHtml.indexOf("</body"));
-				originalHtml = originalHtml.substring(originalHtml.indexOf("<p"),originalHtml.lastIndexOf("</span>"))+"</span></p>";
-				String[] trr = originalHtml.split("\\[.*试题分类.*\\]:");
-			}
-
-			// Clean up, so any ObfuscatedFontPart temp files can be deleted 
-			if (wordMLPackage.getMainDocumentPart().getFontTablePart()!=null) {
-				wordMLPackage.getMainDocumentPart().getFontTablePart().deleteEmbeddedFontTempFiles();
-			}		
-			// This would also do it, via finalize() methods
-			htmlSettings = null;
-			wordMLPackage = null;
-	    }
-}

+ 0 - 73
cqb-comm-utils/src/main/java/com/qmth/cqb/utils/ParserDocxUtils.java

@@ -1,73 +0,0 @@
-package com.qmth.cqb.utils;
-
-import java.io.File;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.xml.bind.JAXBElement;
-
-import org.apache.commons.lang3.StringUtils;
-import org.docx4j.Docx4J;
-import org.docx4j.TraversalUtil;
-import org.docx4j.XmlUtils;
-import org.docx4j.convert.out.html.AbstractHtmlExporter.HtmlSettings;
-import org.docx4j.finders.ClassFinder;
-import org.docx4j.openpackaging.exceptions.Docx4JException;
-import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
-import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart;
-import org.docx4j.wml.ArrayListWml;
-import org.docx4j.wml.Document;
-import org.docx4j.wml.FldChar;
-import org.docx4j.wml.P;
-import org.docx4j.wml.R;
-import org.docx4j.wml.RPr;
-import org.docx4j.wml.Text;
-
-public class ParserDocxUtils {
-	
-	public static void main(String[] args) throws Docx4JException{
-	     parserDocx("/test/test.docx");
-	}
-
-	private static void parserDocx(String docxFilePath) throws Docx4JException {
-		WordprocessingMLPackage  wordMLPackage = WordprocessingMLPackage.load(new File(System.getProperty("user.dir")+docxFilePath));
-		MainDocumentPart mdp = wordMLPackage.getMainDocumentPart();
-		ClassFinder finder = new ClassFinder(P.class); // <----- change this to suit
-		new TraversalUtil(mdp.getContent(), finder);
-		List<Object> objs = finder.results;
-		List<String> pStrs = new ArrayList<String>();
-		List<P> wps = new ArrayList<P>();
-		//int index = 0;
-		for (Object object :objs) {
-				  if (object instanceof P) {
-		                P p = (P) object;
-		            	//wps.add(p);
-		                System.out.println(XmlUtils.marshaltoString(p));
-		                ClassFinder tFinder = new ClassFinder(Text.class); 
-		                new TraversalUtil(p.getContent(), tFinder);
-		                List<Object> tList = tFinder.results;
-		                for (Object t :tList) {//排除空段落
-		                	if(t instanceof Text && StringUtils.isNotEmpty(((Text) t).getValue())){
-		                		wps.add(p);
-		                		pStrs.add(XmlUtils.marshaltoString(p));
-		                	    break;
-		                	}
-		                }
-//		                System.out.println(t.getValue());
-//		                if (t.getValue().equals("1")) {
-//		                    if (objs.size() > index + 1) {
-//		                        Text tnext = (Text) (objs.get(index + 1));
-//		                        R r = (R) (tnext.getParent());
-//		                        P p = (P) r.getParent();
-//		                        System.out.println(XmlUtils.marshaltoString(p));
-//		                    }
-//		                }
-		            }
-		        }
-		for(int i=0;i<pStrs.size();i++){
-			
-		}
-		    
-    }
-}

+ 23 - 16
cqb-comm-utils/src/main/java/com/qmth/cqb/utils/word/DocxProcessUtil.java

@@ -12,6 +12,7 @@ import net.sourceforge.jeuclid.converter.Converter;
 import org.apache.commons.codec.binary.Base64;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.RandomUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.docx4j.Docx4J;
 import org.docx4j.TraversalUtil;
@@ -69,10 +70,9 @@ public final class DocxProcessUtil {
     public static final String PAPER_TEMPLATE="paper_template.ftl";
     public static final String ANSWER_TEMPLATE="answer_template.ftl";
     public static final String DOCX_SUFFIX = ".docx";
-    public static final String XML_SUFFIX = ".xml";
     public static final String BODY_HEADER ="<w:body xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\">";
     public static final String BODY_TAIL ="</w:body>";
-    public static final String REL_ID_HEADER="rld999999";
+    public static final String REL_ID_HEADER="rld";
 
     static{
         init();
@@ -211,7 +211,8 @@ public final class DocxProcessUtil {
      * @param wordMLPackage
      * @throws Exception
      */
-    public static void replaceAllMath2Image(WordprocessingMLPackage wordMLPackage) throws Exception{
+    public static void replaceAllMath2Image(WordprocessingMLPackage wordMLPackage)
+            throws Exception{
         List<Object> pList = getAllElementFromObject(wordMLPackage.getMainDocumentPart(), P.class);
         for (Object pObject : pList) {
             P p=(P) pObject;
@@ -242,7 +243,8 @@ public final class DocxProcessUtil {
      * @param p
      * @throws Exception
      */
-    public static void replaceMath2Image(WordprocessingMLPackage wordMLPackage,P p) throws Exception{
+    public static void replaceMath2Image(WordprocessingMLPackage wordMLPackage,P p)
+            throws Exception{
         List<Object> pContent = p.getContent();
         int index = 0;
         for(Object child:pContent){
@@ -397,7 +399,8 @@ public final class DocxProcessUtil {
             for(org.jsoup.nodes.Element img:imgs){
                 String imgSrc = img.attr("src");
                 if(!StringUtils.isEmpty(imgSrc)){
-                    String imgBase64 = new String(getBase64ByPath(htmlFile.getParent()+"/"+imgSrc));
+                    String imgBase64 = new String(getBase64ByPath(htmlFile.getParent()
+                            +"/"+imgSrc));
                     img.attr("src",BASE64_HEADER+imgBase64);
                 }
             }
@@ -450,14 +453,16 @@ public final class DocxProcessUtil {
         InputStream is = null;
         byte[] base64Byte = new byte[0];
         byte[] imgByte;
+        File imgFile = new File(imgFilePath);
         try {
-            is = new FileInputStream(new File(imgFilePath));
+            is = new FileInputStream(imgFile);
             imgByte = IOUtils.toByteArray(is);
             base64Byte = Base64.encodeBase64(imgByte);
         }catch(Exception e) {
             e.printStackTrace();
         }finally {
             IOUtils.closeQuietly(is);
+            FileUtils.deleteQuietly(imgFile);
         }
         return base64Byte;
     }
@@ -668,19 +673,12 @@ public final class DocxProcessUtil {
 
         DocxProcessUtil.initTmpPackage(wordMLPackage);
 
-        File tmpFile = new File(DocxProcessUtil.TEMP_FILE_IMP
-                + UUID.randomUUID().toString());
-        OutputStream outputStream = new FileOutputStream(tmpFile);
+        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
         Docx4J.save(wordMLPackage,outputStream);
-
-        InputStream inputStream = new FileInputStream(tmpFile);
-        byte[] bytes = IOUtils.toByteArray(inputStream);
+        byte[] bytes = outputStream.toByteArray();
 
         outputStream.flush();
         IOUtils.closeQuietly(outputStream);
-        IOUtils.closeQuietly(inputStream);
-        FileUtils.deleteQuietly(tmpFile);
-
         return bytes;
     }
 
@@ -715,6 +713,7 @@ public final class DocxProcessUtil {
                         .getRelationshipsPart().getRelationshipsByType(Namespaces.IMAGE);
         //同步替换资源ID
         int index = 0;
+        String rldHeader = getRldNum();
         for(Relationship relationship:relationships){
             String tmpId = relationship.getId();
             for(Object obj:blips){
@@ -722,7 +721,7 @@ public final class DocxProcessUtil {
                     CTBlip ctBlip = (CTBlip)obj;
                     String tmpEmbed = ctBlip.getEmbed();
                     if(tmpId.equals(tmpEmbed)){
-                        String tmp = REL_ID_HEADER+(++index);
+                        String tmp = rldHeader +(++index);
                         relationship.setId(tmp);
                         ctBlip.setEmbed(tmp);
                     }
@@ -731,4 +730,12 @@ public final class DocxProcessUtil {
         }
     }
 
+    /**
+     * 获取RldNum
+     * @return
+     */
+    public static String getRldNum(){
+        return REL_ID_HEADER + CommonUtils.getCurNum();
+    }
+
 }

+ 1 - 6
cqb-comm-utils/src/main/resources/log4j.properties

@@ -1,6 +1 @@
-log4j.rootCategory=OFF
-#log4j.rootLogger=DEBUG, stdout
-#
-#log4j.appender.stdout=org.apache.log4j.ConsoleAppender
-#log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
-#log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n
+log4j.rootCategory=OFF

+ 0 - 9
cqb-paper/src/main/java/com/qmth/cqb/paper/dao/PaperStructDetailRepo.java

@@ -1,9 +0,0 @@
-package com.qmth.cqb.paper.dao;
-
-import com.qmth.cqb.paper.model.PaperStructDetail;
-import org.springframework.data.mongodb.repository.MongoRepository;
-import org.springframework.data.repository.query.QueryByExampleExecutor;
-
-
-public interface PaperStructDetailRepo extends MongoRepository<PaperStructDetail, String>,QueryByExampleExecutor<PaperStructDetail> {
-}

+ 22 - 21
cqb-paper/src/main/java/com/qmth/cqb/paper/dto/PaperDetailDto.java → cqb-paper/src/main/java/com/qmth/cqb/paper/dto/PaperDetailExp.java

@@ -5,24 +5,25 @@ import java.io.Serializable;
 import java.util.*;
 
 /**
+ * 试卷大题导出dto
  * Created by songyue on 17/3/15.
  */
-public class PaperDetailDto implements Serializable {
+public class PaperDetailExp implements Serializable {
     private static final long serialVersionUID = -3520871668728091404L;
 
     private String id;
 
-    private int number;//大题序号
+    private Integer number;//大题序号
 
     private String cnNum;//中文序号
 
     private String name;//大题名称
 
-    private double score;//大题分数
+    private Double score;//大题分数
 
-    private int unitCount;//大题下的小题数量
+    private Integer unitCount;//大题下的小题数量
 
-    private List<PaperDetailUnitDto> paperDetailUnits;
+    private List<PaperDetailUnitExp> paperDetailUnits;
 
     public static long getSerialVersionUID() {
         return serialVersionUID;
@@ -36,14 +37,22 @@ public class PaperDetailDto implements Serializable {
         this.id = id;
     }
 
-    public int getNumber() {
+    public Integer getNumber() {
         return number;
     }
 
-    public void setNumber(int number) {
+    public void setNumber(Integer number) {
         this.number = number;
     }
 
+    public String getCnNum() {
+        return cnNum;
+    }
+
+    public void setCnNum(String cnNum) {
+        this.cnNum = cnNum;
+    }
+
     public String getName() {
         return name;
     }
@@ -52,35 +61,27 @@ public class PaperDetailDto implements Serializable {
         this.name = name;
     }
 
-    public double getScore() {
+    public Double getScore() {
         return score;
     }
 
-    public void setScore(double score) {
+    public void setScore(Double score) {
         this.score = score;
     }
 
-    public int getUnitCount() {
+    public Integer getUnitCount() {
         return unitCount;
     }
 
-    public void setUnitCount(int unitCount) {
+    public void setUnitCount(Integer unitCount) {
         this.unitCount = unitCount;
     }
 
-    public List<PaperDetailUnitDto> getPaperDetailUnits() {
+    public List<PaperDetailUnitExp> getPaperDetailUnits() {
         return paperDetailUnits;
     }
 
-    public String getCnNum() {
-        return cnNum;
-    }
-
-    public void setCnNum(String cnNum) {
-        this.cnNum = cnNum;
-    }
-
-    public void setPaperDetailUnits(List<PaperDetailUnitDto> paperDetailUnits) {
+    public void setPaperDetailUnits(List<PaperDetailUnitExp> paperDetailUnits) {
         this.paperDetailUnits = paperDetailUnits;
     }
 }

+ 22 - 10
cqb-paper/src/main/java/com/qmth/cqb/paper/dto/PaperDetailUnitDto.java → cqb-paper/src/main/java/com/qmth/cqb/paper/dto/PaperDetailUnitExp.java

@@ -2,25 +2,29 @@ package com.qmth.cqb.paper.dto;
 
 import com.qmth.cqb.question.model.Question;
 import com.qmth.cqb.question.model.QuestionType;
+import com.qmth.cqb.utils.enums.QuesStructType;
 
 import java.io.Serializable;
 
 /**
+ * 试卷小题导出dto
  * Created by songyue on 17/3/15.
  */
-public class PaperDetailUnitDto implements Serializable {
+public class PaperDetailUnitExp implements Serializable {
     private static final long serialVersionUID = 6507445685386413261L;
 
     private String id;
 
-    private int number;//小题序号
+    private Integer number;//小题序号
 
-    private double score;//小题分数
+    private Double score;//小题分数
 
-    private QuestionType questionType;//小题类型
+    private QuesStructType questionType;//小题类型
 
     private Question question;//关联试题
 
+    private String quesId;//关联试题Id
+
     public static long getSerialVersionUID() {
         return serialVersionUID;
     }
@@ -33,27 +37,27 @@ public class PaperDetailUnitDto implements Serializable {
         this.id = id;
     }
 
-    public int getNumber() {
+    public Integer getNumber() {
         return number;
     }
 
-    public void setNumber(int number) {
+    public void setNumber(Integer number) {
         this.number = number;
     }
 
-    public double getScore() {
+    public Double getScore() {
         return score;
     }
 
-    public void setScore(double score) {
+    public void setScore(Double score) {
         this.score = score;
     }
 
-    public QuestionType getQuestionType() {
+    public QuesStructType getQuestionType() {
         return questionType;
     }
 
-    public void setQuestionType(QuestionType questionType) {
+    public void setQuestionType(QuesStructType questionType) {
         this.questionType = questionType;
     }
 
@@ -64,4 +68,12 @@ public class PaperDetailUnitDto implements Serializable {
     public void setQuestion(Question question) {
         this.question = question;
     }
+
+    public String getQuesId() {
+        return quesId;
+    }
+
+    public void setQuesId(String quesId) {
+        this.quesId = quesId;
+    }
 }

+ 8 - 7
cqb-paper/src/main/java/com/qmth/cqb/paper/dto/PaperDto.java → cqb-paper/src/main/java/com/qmth/cqb/paper/dto/PaperExp.java

@@ -5,9 +5,10 @@ import java.util.Map;
 import java.util.*;
 
 /**
+ * 试卷导出dto
  * Created by songyue on 17/3/15.
  */
-public class PaperDto implements Serializable{
+public class PaperExp implements Serializable{
     private static final long serialVersionUID = -4673013279766466337L;
 
     private String id;
@@ -16,9 +17,9 @@ public class PaperDto implements Serializable{
 
     private String title;//试卷标题
 
-    private double totalScore;//试卷总分
+    private Double totalScore;//试卷总分
 
-    private List<PaperDetailDto> paperDetails;
+    private List<PaperDetailExp> paperDetails;
 
     private Map<String,String> params;//导入试卷属性
 
@@ -50,19 +51,19 @@ public class PaperDto implements Serializable{
         this.title = title;
     }
 
-    public double getTotalScore() {
+    public Double getTotalScore() {
         return totalScore;
     }
 
-    public void setTotalScore(double totalScore) {
+    public void setTotalScore(Double totalScore) {
         this.totalScore = totalScore;
     }
 
-    public List<PaperDetailDto> getPaperDetails() {
+    public List<PaperDetailExp> getPaperDetails() {
         return paperDetails;
     }
 
-    public void setPaperDetails(List<PaperDetailDto> paperDetails) {
+    public void setPaperDetails(List<PaperDetailExp> paperDetails) {
         this.paperDetails = paperDetails;
     }
 

+ 6 - 9
cqb-paper/src/main/java/com/qmth/cqb/paper/model/ExamPaper.java

@@ -18,9 +18,9 @@ public class ExamPaper implements Serializable {
 	
 	private String paperId;
 	
-	private int extractCount;//抽取试卷次数
+	private Integer extractCount;//抽取试卷次数
 	
-	private double weight;//抽取权重比例
+	private Double weight;//抽取权重比例
 
 	public static long getSerialVersionUID() {
 		return serialVersionUID;
@@ -58,22 +58,19 @@ public class ExamPaper implements Serializable {
 		this.paperId = paperId;
 	}
 
-	public int getExtractCount() {
+	public Integer getExtractCount() {
 		return extractCount;
 	}
 
-	public void setExtractCount(int extractCount) {
+	public void setExtractCount(Integer extractCount) {
 		this.extractCount = extractCount;
 	}
 
-	public double getWeight() {
+	public Double getWeight() {
 		return weight;
 	}
 
-	public void setWeight(double weight) {
+	public void setWeight(Double weight) {
 		this.weight = weight;
 	}
-	
-	
-	
 }

+ 1 - 1
cqb-paper/src/main/java/com/qmth/cqb/paper/model/ExtractConfig.java

@@ -17,7 +17,7 @@ public class ExtractConfig implements Serializable{
 	
 	private ExtractPolicy policy;//抽卷规则
 	
-	 private Map params;//类型参数
+	private Map params;//类型参数
 
 	public Long getExamId() {
 		return examId;

+ 0 - 14
cqb-paper/src/main/java/com/qmth/cqb/paper/model/PaperDetail.java

@@ -22,8 +22,6 @@ public class PaperDetail implements Serializable {
 	
 	private String name;//大题名称
 
-	private QuestionType questionType;//大题类型
-	
 	private Double score;//大题分数
 	
 	private Integer unitCount;//大题下的小题数量
@@ -32,10 +30,6 @@ public class PaperDetail implements Serializable {
 
 	private String createTime;//创建时间
 
-	public static long getSerialVersionUID() {
-		return serialVersionUID;
-	}
-
 	public String getId() {
 		return id;
 	}
@@ -68,14 +62,6 @@ public class PaperDetail implements Serializable {
 		this.name = name;
 	}
 
-	public QuestionType getQuestionType() {
-		return questionType;
-	}
-
-	public void setQuestionType(QuestionType questionType) {
-		this.questionType = questionType;
-	}
-
 	public Double getScore() {
 		return score;
 	}

+ 8 - 32
cqb-paper/src/main/java/com/qmth/cqb/paper/model/PaperStructDetail.java → cqb-paper/src/main/java/com/qmth/cqb/paper/model/PaperDetailStruct.java

@@ -11,7 +11,7 @@ import com.qmth.cqb.base.model.QuesType;
  * Created by songyue on 16/12/28.
  */
 
-public class PaperStructDetail implements Serializable{
+public class PaperDetailStruct implements Serializable{
 	
 	private static final long serialVersionUID = -1102384643351847702L;
 
@@ -21,20 +21,12 @@ public class PaperStructDetail implements Serializable{
 	
 	private String name;//大题名称
 	
-	private List<QuesType> quesTypes;//大题类型
+	private List<PaperDetailUnitStruct> paperDetailUnitStructs;//细分类型
 	
-	private Double totalScore;//大题分
+	private Double totalScore;//大题
 	
-	private Integer questionCount;//大题下的小题数量
-	
-	private Double[] questionScores;//大题下面小题分数
-
 	private Map params;//大题参数
 
-	public static long getSerialVersionUID() {
-		return serialVersionUID;
-	}
-
 	public String getId() {
 		return id;
 	}
@@ -59,12 +51,12 @@ public class PaperStructDetail implements Serializable{
 		this.name = name;
 	}
 
-	public List<QuesType> getQuesTypes() {
-		return quesTypes;
+	public List<PaperDetailUnitStruct> getPaperDetailUnitStructs() {
+		return paperDetailUnitStructs;
 	}
 
-	public void setQuesTypes(List<QuesType> quesTypes) {
-		this.quesTypes = quesTypes;
+	public void setPaperDetailUnitStructs(List<PaperDetailUnitStruct> paperDetailUnitStructs) {
+		this.paperDetailUnitStructs = paperDetailUnitStructs;
 	}
 
 	public Double getTotalScore() {
@@ -75,22 +67,6 @@ public class PaperStructDetail implements Serializable{
 		this.totalScore = totalScore;
 	}
 
-	public Integer getQuestionCount() {
-		return questionCount;
-	}
-
-	public void setQuestionCount(Integer questionCount) {
-		this.questionCount = questionCount;
-	}
-
-	public Double[] getQuestionScores() {
-		return questionScores;
-	}
-
-	public void setQuestionScores(Double[] questionScores) {
-		this.questionScores = questionScores;
-	}
-
 	public Map getParams() {
 		return params;
 	}
@@ -99,6 +75,6 @@ public class PaperStructDetail implements Serializable{
 		this.params = params;
 	}
 
-	public PaperStructDetail() {
+	public PaperDetailStruct() {
 	}
 }

+ 4 - 7
cqb-paper/src/main/java/com/qmth/cqb/paper/model/PaperDetailUnit.java

@@ -4,6 +4,7 @@ import java.io.Serializable;
 
 import com.qmth.cqb.question.model.Question;
 import com.qmth.cqb.question.model.QuestionType;
+import com.qmth.cqb.utils.enums.QuesStructType;
 import org.springframework.data.annotation.Id;
 import org.springframework.data.mongodb.core.mapping.DBRef;
 
@@ -24,7 +25,7 @@ public class PaperDetailUnit implements Serializable{
 	@DBRef
 	private PaperDetail paperDetail;//关联的大题
 	
-	private QuestionType questionType;//小题类型
+	private QuesStructType questionType;//小题类型
 	
 	@DBRef
 	private Question question;//关联试题
@@ -33,10 +34,6 @@ public class PaperDetailUnit implements Serializable{
 
 	private String createTime;//创建时间
 
-	public static long getSerialVersionUID() {
-		return serialVersionUID;
-	}
-
 	public String getId() {
 		return id;
 	}
@@ -77,11 +74,11 @@ public class PaperDetailUnit implements Serializable{
 		this.paperDetail = paperDetail;
 	}
 
-	public QuestionType getQuestionType() {
+	public QuesStructType getQuestionType() {
 		return questionType;
 	}
 
-	public void setQuestionType(QuestionType questionType) {
+	public void setQuestionType(QuesStructType questionType) {
 		this.questionType = questionType;
 	}
 

+ 47 - 0
cqb-paper/src/main/java/com/qmth/cqb/paper/model/PaperDetailUnitStruct.java

@@ -0,0 +1,47 @@
+package com.qmth.cqb.paper.model;
+
+import com.qmth.cqb.utils.enums.QuesStructType;
+import java.io.Serializable;
+
+/**
+ * Created by songyue on 17/3/21.
+ */
+public class PaperDetailUnitStruct implements Serializable{
+
+    private static final long serialVersionUID = -3766822545462183904L;
+
+    private String id;
+
+    private Double score;//小题分数
+
+    private QuesStructType questionType;//小题类型
+
+    public static long getSerialVersionUID() {
+        return serialVersionUID;
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public Double getScore() {
+        return score;
+    }
+
+    public void setScore(Double score) {
+        this.score = score;
+    }
+
+    public QuesStructType getQuestionType() {
+        return questionType;
+    }
+
+    public void setQuestionType(QuesStructType questionType) {
+        this.questionType = questionType;
+    }
+
+}

+ 5 - 5
cqb-paper/src/main/java/com/qmth/cqb/paper/model/PaperStruct.java

@@ -29,7 +29,7 @@ public class PaperStruct implements Serializable{
     
     private Map params;
 
-	private List<PaperStructDetail> paperStructDetails;//大题
+	private List<PaperDetailStruct> paperDetailStructs;//大题
 
 	private String creator;//创建人id
 
@@ -79,12 +79,12 @@ public class PaperStruct implements Serializable{
 		this.params = params;
 	}
 
-	public List<PaperStructDetail> getPaperStructDetails() {
-		return paperStructDetails;
+	public List<PaperDetailStruct> getPaperDetailStructs() {
+		return paperDetailStructs;
 	}
 
-	public void setPaperStructDetails(List<PaperStructDetail> paperStructDetails) {
-		this.paperStructDetails = paperStructDetails;
+	public void setPaperDetailStructs(List<PaperDetailStruct> paperDetailStructs) {
+		this.paperDetailStructs = paperDetailStructs;
 	}
 
 	public String getCreator() {

+ 20 - 20
cqb-paper/src/main/java/com/qmth/cqb/paper/service/ExportPaperService.java

@@ -4,9 +4,9 @@ import com.google.gson.Gson;
 import com.qmth.cqb.paper.dao.PaperDetailRepo;
 import com.qmth.cqb.paper.dao.PaperDetailUnitRepo;
 import com.qmth.cqb.paper.dao.PaperRepo;
-import com.qmth.cqb.paper.dto.PaperDetailDto;
-import com.qmth.cqb.paper.dto.PaperDetailUnitDto;
-import com.qmth.cqb.paper.dto.PaperDto;
+import com.qmth.cqb.paper.dto.PaperDetailExp;
+import com.qmth.cqb.paper.dto.PaperDetailUnitExp;
+import com.qmth.cqb.paper.dto.PaperExp;
 import com.qmth.cqb.paper.model.Paper;
 import com.qmth.cqb.paper.model.PaperDetail;
 import com.qmth.cqb.paper.model.PaperDetailUnit;
@@ -66,26 +66,26 @@ public class ExportPaperService {
             return returnMap;
         }
         //创建paperDto
-        PaperDto paperDto = BeanCopierUtil.copyProperties(paper,PaperDto.class);
+        PaperExp paperExp = BeanCopierUtil.copyProperties(paper,PaperExp.class);
         //获取大题
         List<PaperDetail> paperDetails = paperDetailRepo.findByPaper(paper);
-        List<PaperDetailDto> paperDetailDtos =
-                BeanCopierUtil.copyPropertiesOfList(paperDetails,PaperDetailDto.class);
-        paperDto.setPaperDetails(paperDetailDtos);
+        List<PaperDetailExp> paperDetailExps =
+                BeanCopierUtil.copyPropertiesOfList(paperDetails,PaperDetailExp.class);
+        paperExp.setPaperDetails(paperDetailExps);
 
         //封装小题
-        for(int i = 0;i < paperDetailDtos.size();i++){
+        for(int i = 0; i < paperDetailExps.size(); i++){
             List<PaperDetailUnit> paperDetailUnits =
                     paperDetailUnitRepo.findByPaperDetail(paperDetails.get(i));
-            List<PaperDetailUnitDto> paperDetailUnitDtos =
-                    BeanCopierUtil.copyPropertiesOfList(paperDetailUnits,PaperDetailUnitDto.class);
-            paperDetailDtos.get(i).setPaperDetailUnits(paperDetailUnitDtos);
+            List<PaperDetailUnitExp> paperDetailUnitExps =
+                    BeanCopierUtil.copyPropertiesOfList(paperDetailUnits,PaperDetailUnitExp.class);
+            paperDetailExps.get(i).setPaperDetailUnits(paperDetailUnitExps);
         }
         //初始化试卷序号
-        initPaperNum(paperDto);
+        initPaperNum(paperExp);
 
-        returnMap.put("paper",paperDto);
-        returnMap.put("fileName",paperDto.getName());
+        returnMap.put("paper", paperExp);
+        returnMap.put("fileName", paperExp.getName());
 
         return returnMap;
     }
@@ -107,15 +107,15 @@ public class ExportPaperService {
 
     /**
      * 初始化序号
-     * @param paperDto
+     * @param paperExp
      */
-    public void initPaperNum(PaperDto paperDto)throws Exception{
-        if(paperDto.getPaperDetails() == null || paperDto.getPaperDetails().size() == 0){
+    public void initPaperNum(PaperExp paperExp)throws Exception{
+        if(paperExp.getPaperDetails() == null || paperExp.getPaperDetails().size() == 0){
             return;
         }
         int mainNum = 0;
         int subNum = 0;
-        for(PaperDetailDto paperDetail:paperDto.getPaperDetails()){
+        for(PaperDetailExp paperDetail: paperExp.getPaperDetails()){
             //大题序号
             paperDetail.setCnNum(CommonUtils.toCHNum(paperDetail.getNumber()));
             paperDetail.setNumber(++mainNum);
@@ -124,7 +124,7 @@ public class ExportPaperService {
                 return;
             }
             //小题序号
-            for(PaperDetailUnitDto paperDetailUnit:paperDetail.getPaperDetailUnits()){
+            for(PaperDetailUnitExp paperDetailUnit:paperDetail.getPaperDetailUnits()){
                 List<Question> subQuesList = paperDetailUnit.getQuestion().getSubQuestions();
                 //套题序号
                 if(subQuesList != null && subQuesList.size() > 0){
@@ -160,7 +160,7 @@ public class ExportPaperService {
      * @throws Exception
      */
     public String setSubQuesNum(String quesBodyWordMl,int num) throws Exception {
-        String tmpStr = DocxProcessUtil.BODY_HEADER +quesBodyWordMl+DocxProcessUtil.BODY_TAIL;
+        String tmpStr = DocxProcessUtil.BODY_HEADER + quesBodyWordMl + DocxProcessUtil.BODY_TAIL;
         Body body = (Body)XmlUtils.unmarshalString(tmpStr,
                 Context.jc,Body.class);
         P p = (P)body.getContent().get(0);

+ 7 - 16
cqb-paper/src/main/java/com/qmth/cqb/paper/service/ExtractService.java

@@ -1,6 +1,5 @@
 package com.qmth.cqb.paper.service;
 
-import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 
@@ -11,7 +10,6 @@ import org.springframework.stereotype.Service;
 import com.qmth.cqb.paper.dao.ExamPaperRepo;
 import com.qmth.cqb.paper.dao.ExtractConfigRepo;
 import com.qmth.cqb.paper.dao.PaperRepo;
-import com.qmth.cqb.paper.model.ExamPaper;
 import com.qmth.cqb.paper.model.ExtractConfig;
 import com.qmth.cqb.paper.model.Paper;
 
@@ -27,24 +25,18 @@ public class ExtractService {
 	@Autowired 
 	ExtractConfigRepo extractConfigRepo;
 	
-//	public Paper extrcatExamPaper(long examId,String courseCode,String groupCode){
-//     	ExamPaper examPaper = new ExamPaper();
-//    	examPaper.setExamId(examId);
-//    	examPaper.setCourseCode(courseCode);
-//    	examPaper.setGroupCode(groupCode);
-//        ExamPaper examPaper2 = examPaperRepo.findOne(Example.of(examPaper));
-//        Paper paper = paperRepo.findOne(examPaper2.getPaperId());
-//		return paper;		
-//	}
 	/**
 	 * 随机抽一张试卷
 	 * @param papers
 	 * @return
 	 */
 	public Paper randomPaper(List<Paper> papers){
-	    Collections.shuffle(papers);
-		Paper paper = papers.get(0);
-		return paper;
+		if(papers.size() > 0){
+			Collections.shuffle(papers);
+		}else{
+			return null;
+		}
+		return papers.get(0);
 	}
 	
 	
@@ -52,8 +44,7 @@ public class ExtractService {
 		ExtractConfig tempConfig = new ExtractConfig();
 		tempConfig.setExamId(examId);
 		tempConfig.setCourseCode(courseCode);
-		ExtractConfig config =  extractConfigRepo.findOne(Example.of(tempConfig));
-		return config;
+		return extractConfigRepo.findOne(Example.of(tempConfig));
 	}
 	
 }

+ 36 - 29
cqb-paper/src/main/java/com/qmth/cqb/paper/service/ImportPaperService.java

@@ -5,10 +5,8 @@ import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatc
 import com.google.gson.Gson;
 import com.qmth.cqb.paper.dao.PaperDetailRepo;
 import com.qmth.cqb.paper.dao.PaperDetailUnitRepo;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+
+import java.util.*;
 
 import com.qmth.cqb.paper.dao.PaperRepo;
 import com.qmth.cqb.paper.model.*;
@@ -19,7 +17,6 @@ import com.qmth.cqb.question.model.QuestionType;
 import com.qmth.cqb.utils.CommonUtils;
 import com.qmth.cqb.utils.enums.QuesStructType;
 import com.qmth.cqb.utils.enums.QuesUnit;
-import com.qmth.cqb.utils.modal.PagingAndSortingResponse;
 import com.qmth.cqb.utils.word.DocxProcessUtil;
 import org.apache.commons.lang3.StringUtils;
 import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
@@ -55,6 +52,9 @@ public class ImportPaperService {
     @Autowired
     PaperDetailService paperDetailService;
 
+    @Autowired
+    PaperService paperService;
+
 
     /**
      * 查询所有已导入试卷
@@ -73,6 +73,14 @@ public class ImportPaperService {
                 new PageRequest(curPage - 1,pageSize));
     }
 
+    /**
+     * 批量删除导入试卷
+     * @param paperIds
+     */
+    public void deleteImportPaper(String[] paperIds) {
+        paperService.deletePapers(paperIds);
+    }
+
     /**
      * 查询所有已导入试卷
      * @param courseId
@@ -87,8 +95,7 @@ public class ImportPaperService {
         	param.put("courseId", courseId);
         	importPaper.setParams(param);
     	}
-        Page<Paper> importPaperList = paperRepo.findAll(Example.of(importPaper),new PageRequest(curPage-1,pageSize));
-        return importPaperList;
+        return paperRepo.findAll(Example.of(importPaper),new PageRequest(curPage - 1,pageSize));
     }
 
 
@@ -154,7 +161,7 @@ public class ImportPaperService {
             wordMLPackage = WordprocessingMLPackage.load(inputStream);
             //初始化图片路径
             DocxProcessUtil.initPkgImage(wordMLPackage);
-            //深拷贝临时pkg与最终写入pkg
+            //深拷贝临时pkg与最终写入数据库pkg
             tmpWordMlPackage = DocxProcessUtil.getTmpPackage(wordMLPackage);
             writePkg = DocxProcessUtil.getTmpPackage(wordMLPackage);
 
@@ -233,8 +240,7 @@ public class ImportPaperService {
                                         importPaperCheck.index,
                                         question,
                                         importPaperCheck,
-                                        tmpWordMlPackage
-                        );
+                                        tmpWordMlPackage);
 
                         //处理选项
                         processQuesOption(pList,
@@ -267,8 +273,7 @@ public class ImportPaperService {
                                         importPaperCheck.index,
                                         question,
                                         importPaperCheck,
-                                        tmpWordMlPackage
-                        );
+                                        tmpWordMlPackage);
 
                         processQuesTail(pList,
                                         importPaperCheck.index,
@@ -307,6 +312,7 @@ public class ImportPaperService {
         }
         wordMLPackage = null;
         tmpWordMlPackage = null;
+        writePkg = null;
         return importPaperCheck.errorInfo;
     }
 
@@ -358,11 +364,11 @@ public class ImportPaperService {
                                 int subQuesNum,
                                 ImportPaperCheck importPaperCheck){
 
-        question.setQuestionType(getQuesType(importPaperCheck.quesType));
+        question.setQuestionType(getQuesStructType(importPaperCheck.quesType));
         paperDetailUnit.setNumber(++subQuesNum);
         paperDetailUnit.setQuestion(question);
         paperDetailUnit.setPaperDetail(paperDetail);
-        paperDetailUnit.setQuestionType(getQuesType(importPaperCheck.quesType));
+        paperDetailUnit.setQuestionType(getQuesStructType(importPaperCheck.quesType));
         paperDetailUnit.setScore(Double.parseDouble(importPaperCheck.quesScore));
         paperDetailUnit.setPaper(paper);
     }
@@ -497,26 +503,19 @@ public class ImportPaperService {
         question.setQuesBodyWord(quesBodyWordMl);
     }
 
+
+
     /**
      * 处理题目选项
-     * @param paperIds
+     * @param pList
+     * @param index
+     * @param subQuesNum
+     * @param question
+     * @param importPaperCheck
+     * @param wordMLPackage
      * @return
      * @throws Exception
      */
-    public void deleteImportPaper(String[] paperIds) {
-        //需要同时删除paperDetail,paperdetailUnit
-        Iterable<Paper> papers = new ArrayList<Paper>();
-        List<String> ids = new ArrayList<String>();
-        for (int i = 0; i < paperIds.length; i++) {
-            ids.add(paperIds[i]);
-        }
-        papers = paperRepo.findAll(ids);
-        for (Paper paper : papers) {
-            paperDetailService.deletePaperDetailsByPaper(paper);
-        }
-        paperRepo.delete(papers);
-    }
-
     public String processQuesOption(List pList,
                                     int index,
                                     int subQuesNum,
@@ -756,6 +755,14 @@ public class ImportPaperService {
         return new QuestionType(quesStructType,quesName);
     }
 
+    /**
+     * 获取试题结构类型
+     * @param quesType
+     * @return
+     */
+    public static QuesStructType getQuesStructType(String quesType){
+        return CommonUtils.getEnum(QuesStructType.class,quesType);
+    }
 
 
     /**

+ 18 - 12
cqb-paper/src/main/java/com/qmth/cqb/paper/service/PaperDetailService.java

@@ -30,9 +30,7 @@ public class PaperDetailService {
 	public List<PaperDetailUnit> getUnitsByPaperDetailId(String id){	
 		return unitService.getUnitsByPaperDetail(paperDetailRepo.findOne(id));
 	}
-	
-	
-	
+
     /**
      * 按ID查询大题
      * @param id
@@ -44,12 +42,11 @@ public class PaperDetailService {
 
     /**
      * 保存大题
-     * @param PaperDetail
+     * @param pd
      * @return
      */
     public PaperDetail savePaperDetail(PaperDetail pd){
-        PaperDetail paperDetail = paperDetailRepo.save(pd);
-        return paperDetail;
+        return paperDetailRepo.save(pd);
     }
 
     /**
@@ -67,20 +64,29 @@ public class PaperDetailService {
      * @return
      */
     public List<PaperDetail> getPaperDetailsByPaper(Paper paper){
-    	PaperDetail pd = new PaperDetail();
-    	pd.setPaper(paper);  	
-    	List<PaperDetail> paperDetails = paperDetailRepo.findAll(Example.of(pd));
-    	return paperDetails;
+    	return paperDetailRepo.findByPaper(paper);
     }
     
     /**
-     * 先删掉大题下面的小题,然后再删掉大题
+     * 删除试卷大题
      * @param paper
      */
      public void deletePaperDetailsByPaper(Paper paper){
-    	List<PaperDetail> details = this.getPaperDetailsByPaper(paper);
+    	List<PaperDetail> details = getPaperDetailsByPaper(paper);
     	unitService.deleteUnitsByPaperDetails(details);
     	paperDetailRepo.delete(details);
     }
+
+	/**
+	 * 批量删除试卷大题
+	 * @param papers
+	 */
+	public void deletePaperDetailsByPapers(List<Paper> papers){
+		for(Paper paper:papers){
+			List<PaperDetail> details = getPaperDetailsByPaper(paper);
+			unitService.deleteUnitsByPaperDetails(details);
+			paperDetailRepo.delete(details);
+		}
+	}
 }
 

+ 7 - 10
cqb-paper/src/main/java/com/qmth/cqb/paper/service/PaperDetailUnitService.java

@@ -17,6 +17,7 @@ import com.qmth.cqb.paper.model.PaperDetailUnit;
 
 @Service
 public class PaperDetailUnitService {
+
 	@Autowired
 	PaperDetailUnitRepo paperDetailUnitRepo;
 
@@ -50,8 +51,7 @@ public class PaperDetailUnitService {
      * @return
      */
     public PaperDetailUnit savePaperDetailUnit(PaperDetailUnit pdu){
-        PaperDetailUnit tempPdu = paperDetailUnitRepo.save(pdu);
-        return tempPdu;
+        return paperDetailUnitRepo.save(pdu);
     }
 
     /**
@@ -69,20 +69,17 @@ public class PaperDetailUnitService {
      * @return
      */
     public List<PaperDetailUnit> getUnitsByPaperDetail(PaperDetail paperDetail){
-    	PaperDetailUnit pdu = new PaperDetailUnit();
-    	pdu.setPaperDetail(paperDetail);
-    	List<PaperDetailUnit> units = paperDetailUnitRepo.findAll(Example.of(pdu));
-    	return units;
+    	return paperDetailUnitRepo.findByPaperDetail(paperDetail);
     }
     
     /**
      * 根据大题集合删除小题
-     * @param paperDetail
+     * @param paperDetails
      */
-    public void deleteUnitsByPaperDetails (List<PaperDetail> paperDetail){
+    public void deleteUnitsByPaperDetails (List<PaperDetail> paperDetails){
     	List<PaperDetailUnit> units = new ArrayList<PaperDetailUnit>();
-    	for(PaperDetail pd:paperDetail){
-    		units.addAll(this.getUnitsByPaperDetail(pd));
+    	for(PaperDetail pd:paperDetails){
+    		units.addAll(getUnitsByPaperDetail(pd));
     	}
     	paperDetailUnitRepo.delete(units);
     }

+ 34 - 21
cqb-paper/src/main/java/com/qmth/cqb/paper/service/PaperService.java

@@ -1,10 +1,11 @@
 package com.qmth.cqb.paper.service;
 
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
+import com.qmth.cqb.utils.CommonUtils;
+import org.apache.commons.collections4.IteratorUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Example;
 import org.springframework.stereotype.Service;
@@ -51,7 +52,6 @@ public class PaperService {
     		Paper paper = paperRepo.findOne(ePaper.getPaperId());
     		papers.add(paper);
     	}
-    	
 		return papers;
     }
     
@@ -64,28 +64,28 @@ public class PaperService {
      * @param paperId
      * @return
      */
-    public boolean joinToExamPaper(long examId,String courseCode,String groupCode,String paperId){ 	
-    	boolean flag = false;
+    public void joinToExamPaper(long examId,
+								String courseCode,
+								String groupCode,
+								String paperId){
 		ExamPaper examPaper = new ExamPaper();
 		examPaper.setExamId(examId);
 		examPaper.setGroupCode(groupCode);
 		examPaper.setCourseCode(courseCode);
 		examPaper.setPaperId(paperId);
 		examPaperRepo.save(examPaper);
-		flag = true;
-    	return flag;   	
     }
     
-    public boolean releaseExamPaper(long examId,String courseCode,String groupCode,String paperId){ 	
-    	boolean flag = false;
+    public void releaseExamPaper(long examId,
+									String courseCode,
+									String groupCode,
+									String paperId){
 		ExamPaper examPaper = new ExamPaper();
 		examPaper.setExamId(examId);
 		examPaper.setGroupCode(groupCode);
 		examPaper.setCourseCode(courseCode);
 		examPaper.setPaperId(paperId);
 		examPaperRepo.delete(examPaper);
-		flag = true;
-    	return flag;   	
     }
     
     
@@ -102,15 +102,12 @@ public class PaperService {
     }
     
     
-    public boolean deletGroupCode(long examId,String courseCode,String groupCode){
-    	boolean flag = false;
+    public void deletGroupCode(long examId,String courseCode,String groupCode){
     	ExamPaper examPaper = new ExamPaper();
     	examPaper.setExamId(examId);
 		examPaper.setCourseCode(courseCode);
 		examPaper.setCourseCode(courseCode);
 		examPaperRepo.delete(examPaper);
-		flag = true;
-		return flag;
     }
     
     
@@ -123,8 +120,6 @@ public class PaperService {
         return paperDetailService.getPaperDetailsByPaper(paperRepo.findOne(id));
     }
 
-	
-	
     /**
      * 按ID查询试卷
      * @param id
@@ -140,8 +135,26 @@ public class PaperService {
      * @return
      */
     public Paper savePaper(Paper pd){
-        Paper paper = paperRepo.save(pd);
-        return paper;
+        return paperRepo.save(pd);
     }
 
+	/**
+	 * 删除试卷
+	 * @param paper
+     */
+    public void deletePaper(Paper paper){
+    	paperDetailService.deletePaperDetailsByPaper(paper);
+		paperRepo.delete(paper);
+	}
+
+	/**
+	 * 批量删除试卷
+	 * @param paperId
+     */
+	public void deletePapers(String [] paperId){
+		List<Paper> papers = CommonUtils.toList(paperRepo.findAll(Arrays.asList(paperId)));
+		paperDetailService.deletePaperDetailsByPapers(papers);
+		paperRepo.delete(papers);
+	}
+
 }

+ 0 - 63
cqb-paper/src/main/java/com/qmth/cqb/paper/service/PaperStructDetailService.java

@@ -1,63 +0,0 @@
-package com.qmth.cqb.paper.service;
-
-import java.util.List;
-
-import com.qmth.cqb.paper.dao.PaperStructRepo;
-import com.qmth.cqb.paper.model.PaperStructDetail;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import com.qmth.cqb.paper.dao.PaperStructDetailRepo;
-import com.qmth.cqb.paper.model.PaperStruct;
-/**
- * Created by songyue on 16/12/28.
- */
-@Service
-public class PaperStructDetailService {
-	
-	@Autowired
-    PaperStructDetailRepo detailStructureRepo;
-
-    @Autowired
-    PaperStructRepo paperStructRepo;
-	
-	
-
-    /**
-     * 按ID查询试卷结构明细
-     * @param detailId
-     * @return
-     */
-    public PaperStructDetail findById(String detailId){
-        return detailStructureRepo.findOne(detailId);
-    }
-    
-    
-
-    /**
-     * 保存试卷结构明细
-     * @param pds
-     * @return
-     */
-    public PaperStructDetail savePaperStructureDetail(PaperStructDetail pds){
-    	PaperStructDetail temp = detailStructureRepo.save(pds);
-        return temp;
-    }
-
-    /**
-     * 删除试卷结构明细
-     * @param detailId
-     * @return
-     */
-    public void deletePaperDetailStructure(String detailId){
-    	detailStructureRepo.delete(detailId);
-    }
-
-    /**
-     * 查询同一个试卷对象对应试卷结构明细
-     * @param paperStruct
-     * @return
-     */
-    public List<PaperStructDetail> getDetailsByPaperStructure(PaperStruct paperStruct){
-    	return paperStructRepo.findOne(paperStruct.getId()).getPaperStructDetails();
-    }
-}

+ 1 - 3
cqb-paper/src/main/java/com/qmth/cqb/paper/service/PaperStructService.java

@@ -28,7 +28,7 @@ public class PaperStructService {
 
     /**
      * 保存试卷
-     * @param importPaper
+     * @param ps
      * @return
      */
     public PaperStruct savePaperStructure(PaperStruct ps){
@@ -44,7 +44,5 @@ public class PaperStructService {
     public void deletePaperStructure(String paperId){
     	paperStructRepo.delete(paperId);
     }
-	
-
 
 }

+ 0 - 6
cqb-paper/src/main/java/com/qmth/cqb/paper/web/ExtractController.java

@@ -39,10 +39,4 @@ public class ExtractController {
 		return paper;
     }
     
-//    @GetMapping(value = "/extract/{exam_id}/{course_code}")
-//    public ExtractConfig findConfig (@PathVariable String exam_id,@PathVariable String course_code){
-//    	ExtractConfig config = extractService.findConfig(Long.parseLong(exam_id), course_code);
-//		return config;
-//    }
-
 }

+ 4 - 4
cqb-paper/src/main/java/com/qmth/cqb/paper/web/ImportPaperController.java

@@ -49,8 +49,8 @@ public class ImportPaperController {
     public ResponseEntity getAllPaper(@ModelAttribute ImportPaperSearchCondition searchCondition,                                            @PathVariable int curPage,
                                       @PathVariable int pageSize){
 
-      return new ResponseEntity(importPaperService.findAll(searchCondition,curPage,pageSize),
-              HttpStatus.OK);
+      return new ResponseEntity(importPaperService.findAll(searchCondition,
+              curPage,pageSize), HttpStatus.OK);
     }
 
     /**
@@ -63,8 +63,8 @@ public class ImportPaperController {
     		                              @PathVariable int curPage,
     		                              @PathVariable int pageSize
     		                              ){
-      ResponseEntity rse = new ResponseEntity(importPaperService.getImportPapersByCourseId(courseId,curPage, pageSize),HttpStatus.OK);
-      return rse;
+      return new ResponseEntity(importPaperService.getImportPapersByCourseId(courseId,
+              curPage, pageSize),HttpStatus.OK);
     }
 
 

+ 29 - 31
cqb-paper/src/main/java/com/qmth/cqb/paper/web/PaperController.java

@@ -27,7 +27,6 @@ public class PaperController {
     @Autowired
     PaperService paperService;
     
-    
     /**
      * 新增试卷
      * @param paper
@@ -35,14 +34,12 @@ public class PaperController {
      */
     @PostMapping(value = "/paper")
     public ResponseEntity CreatePaper(@ModelAttribute Paper paper){
-      Paper tempPaper  = paperService.savePaper(paper);
-      ResponseEntity rse = new ResponseEntity(tempPaper,HttpStatus.OK);
-      return rse;
+      return new ResponseEntity(paperService.savePaper(paper),HttpStatus.OK);
     }
-    
+
     /**
      * 根据Id获取试卷
-     * @param id
+     * @param paper_id
      * @return
      */
     @ApiOperation(value="获取单张试卷",notes="获取单张试卷")
@@ -50,18 +47,19 @@ public class PaperController {
     public Paper getPaperById(@PathVariable String paper_id){
         return paperService.findById(paper_id);
     }
-    
-    
+
+
     /**
      * 获取卷库考试试卷
-     * @param paper_id
+     * @param exam_id
+     * @param course_code
+     * @param group_code
      * @return
      */
     @GetMapping(value = "/paper/list/{exam_id}/{course_code}/{group_code}")
-    public List<Paper> listPaperById(
-    		@PathVariable String exam_id,
-    		@PathVariable String course_code,
-    		@PathVariable String group_code){
+    public List<Paper> listPaperById(@PathVariable String exam_id,
+                                     @PathVariable String course_code,
+                                     @PathVariable String group_code){
         return paperService.listExamPapers(Long.parseLong(exam_id), course_code, group_code);
     }
     
@@ -75,12 +73,12 @@ public class PaperController {
      */
     @PostMapping(value = "/paper/join/{exam_id}/{course_code}/{group_code}/{paper_id}")
     public ResponseEntity joinExamPaper(@PathVariable String exam_id,
-    		@PathVariable String course_code,
-    		@PathVariable String group_code,
-    		@PathVariable String paper_id){
-      boolean falg = paperService.joinToExamPaper(Long.parseLong(exam_id), course_code, group_code, paper_id);
-      ResponseEntity rse = new ResponseEntity(falg,HttpStatus.OK);
-      return rse;
+    		                            @PathVariable String course_code,
+    		                            @PathVariable String group_code,
+    		                            @PathVariable String paper_id){
+      paperService.joinToExamPaper(Long.parseLong(exam_id),
+              course_code, group_code, paper_id);
+          return new ResponseEntity(HttpStatus.OK);
     }
     
     /**
@@ -93,12 +91,13 @@ public class PaperController {
      */
     @DeleteMapping(value = "/paper/release/{exam_id}/{course_code}/{group_code}/{paper_id}")
     public ResponseEntity releaseExamPaper(@PathVariable String exam_id,
-    		@PathVariable String course_code,
-    		@PathVariable String group_code,
-    		@PathVariable String paper_id){
-      boolean falg = paperService.releaseExamPaper(Long.parseLong(exam_id), course_code, group_code, paper_id);
-      ResponseEntity rse = new ResponseEntity(falg,HttpStatus.OK);
-      return rse;
+                                           @PathVariable String course_code,
+                                           @PathVariable String group_code,
+                                           @PathVariable String paper_id){
+
+      paperService.releaseExamPaper(Long.parseLong(exam_id),
+              course_code, group_code, paper_id);
+        return new ResponseEntity(HttpStatus.OK);
     }
     
     /**
@@ -121,11 +120,10 @@ public class PaperController {
      * @return
      */
     @DeleteMapping(value = "/paper/deleteCode/{exam_id}/{course_code}/{group_code}")
-    public ResponseEntity deleteGropu(@PathVariable String exam_id,
-    		@PathVariable String course_code,
-    		@PathVariable String group_code){
-      boolean falg = paperService.deletGroupCode(Long.parseLong(exam_id), course_code, group_code);
-      ResponseEntity rse = new ResponseEntity(falg,HttpStatus.OK);
-      return rse;
+    public ResponseEntity deleteGroup(@PathVariable String exam_id,
+                                      @PathVariable String course_code,
+                                      @PathVariable String group_code){
+      paperService.deletGroupCode(Long.parseLong(exam_id), course_code, group_code);
+        return new ResponseEntity(HttpStatus.OK);
     }
 }

+ 58 - 57
cqb-paper/src/main/java/com/qmth/cqb/paper/web/PaperDetailController.java

@@ -30,63 +30,64 @@ public class PaperDetailController {
 	PaperDetailService paperDetailService;
 	
 		
-		 /**
-		  * 获取单个大题获得对应的小题
-		  * @param paperDetail
-		  * @return
-		  */
-		 @GetMapping(value = "/paperDetail/units/{detail_id}")
-		 public List<PaperDetailUnit> getUnitsByPaperDetailId(String detail_id){
-			 return paperDetailService.getUnitsByPaperDetailId(detail_id);
-		 }
+	/**
+	 * 获取大题对应的小题
+	 * @param detail_id
+	 * @return
+	 */
+	@ApiOperation(value="获取大题对应的小题",notes="获取大题对应的小题")
+	@GetMapping(value = "/paperDetail/units/{detail_id}")
+	public List<PaperDetailUnit> getUnitsByPaperDetailId(String detail_id){
+		return paperDetailService.getUnitsByPaperDetailId(detail_id);
+	}
 		 
-	   /**
-	    * 获取大题
-	    * @param id
-	    * @return
-	    */
-	   @ApiOperation(value="获取单个大题",notes="获取单个大题")
-	   @GetMapping(value = "/paperDetail/{detail_id}")
-	   public PaperDetail getPaperDetailId(@PathVariable String detail_id){
-	       return paperDetailService.findById(detail_id);
-	   }
-	
-	
-	   /**
-	    * 更新大题信息
-	    * @param PaperDetail
-	    * @return
-	    */
-	   @PutMapping(value = "/paperDetail")
-	   public ResponseEntity updatePaperDetail(@ModelAttribute PaperDetail pd){
-	       PaperDetail paperDetail = paperDetailService.savePaperDetail(pd);
-	       ResponseEntity rse = new ResponseEntity(paperDetail,HttpStatus.OK);
-	       return rse;
-	   	
-	   }
-	
-	   /**
-	    * 新增大题
-	    * @param PaperDetail
-	    * @return
-	    */
-	   @PostMapping(value = "/paperDetail")
-	   public ResponseEntity addPaperDetail(@ModelAttribute PaperDetail pd){
-	     PaperDetail paperDetail = paperDetailService.savePaperDetail(pd);
-	     ResponseEntity rse2 = new ResponseEntity(paperDetail,HttpStatus.OK);
-	     return rse2;
-	   }
-	
-	   /**
-	    * 删除大题
-	    * @param id
-	    * @return
-	    */
-	   @DeleteMapping(value = "/paperDetail/{detail_id}")
-	   public ResponseEntity removePaperDetail(@PathVariable String detail_id){
-	   	paperDetailService.deletePaperDetail(detail_id);
-	   	ResponseEntity rse2 = new ResponseEntity(detail_id,HttpStatus.OK);
-	   	return rse2;
-	   }
+	/**
+	 * 获取大题
+	 * @param detail_id
+	 * @return
+	 */
+	@ApiOperation(value="获取大题",notes="获取大题")
+	@GetMapping(value = "/paperDetail/{detail_id}")
+	public PaperDetail getPaperDetailId(@PathVariable String detail_id){
+		return paperDetailService.findById(detail_id);
+	}
+
+
+	/**
+	 * 更新大题信息
+	 * @param pd
+	 * @return
+	 */
+	@ApiOperation(value="更新大题",notes="更新大题")
+	@PutMapping(value = "/paperDetail")
+	public ResponseEntity updatePaperDetail(@ModelAttribute PaperDetail pd){
+		PaperDetail paperDetail = paperDetailService.savePaperDetail(pd);
+		return new ResponseEntity(paperDetail,HttpStatus.OK);
+
+	}
+
+	/**
+	 * 新增大题
+	 * @param pd
+	 * @return
+	 */
+	@ApiOperation(value="新增大题",notes="新增大题")
+	@PostMapping(value = "/paperDetail")
+	public ResponseEntity addPaperDetail(@ModelAttribute PaperDetail pd){
+		PaperDetail paperDetail = paperDetailService.savePaperDetail(pd);
+		return new ResponseEntity(paperDetail,HttpStatus.OK);
+	}
+
+	/**
+	 * 删除大题
+	 * @param detail_id
+	 * @return
+	 */
+	@ApiOperation(value="删除大题",notes="删除大题")
+	@DeleteMapping(value = "/paperDetail/{detail_id}")
+	public ResponseEntity removePaperDetail(@PathVariable String detail_id){
+		paperDetailService.deletePaperDetail(detail_id);
+		return new ResponseEntity(detail_id,HttpStatus.OK);
+	}
 	
 }

+ 51 - 54
cqb-paper/src/main/java/com/qmth/cqb/paper/web/PaperDetailUnitController.java

@@ -25,66 +25,63 @@ import io.swagger.annotations.ApiOperation;
 @RestController
 @RequestMapping("${api_cqb}/")
 public class PaperDetailUnitController {
-		 @Autowired
-		 PaperDetailUnitService  unitService;
+	@Autowired
+	PaperDetailUnitService  unitService;
 
-		 /**
-		  * 获取单个小题对应的试题
-		  * @param unit_id
-		  * @return
-		  */
-		 @GetMapping(value = "/paperDetailUnit/question/{unit_id}")
-		 public Question getQuestionByUnitId(String unit_id){
-			 return unitService.getQuestionByPaperDetailUnitId(unit_id);
-		 }
+	/**
+	 * 获取单个小题对应的试题
+	 * @param unit_id
+	 * @return
+	 */
+	@GetMapping(value = "/paperDetailUnit/question/{unit_id}")
+	public Question getQuestionByUnitId(String unit_id){
+		return unitService.getQuestionByPaperDetailUnitId(unit_id);
+	}
 
-	    /**
-	     * 获取小题
-	     * @param unit_id
-	     * @return
-	     */
-	    @ApiOperation(value="获取单个小题",notes="获取单个小题")
-	    @GetMapping(value = "/paperDetailUnit/{unit_id}")
-	    public PaperDetailUnit getPaperDetailUnitId(@PathVariable String unit_id){
-	        return unitService.findById(unit_id);
-	    }
+	/**
+	 * 获取小题
+	 * @param unit_id
+	 * @return
+	 */
+	@ApiOperation(value="获取单个小题",notes="获取单个小题")
+	@GetMapping(value = "/paperDetailUnit/{unit_id}")
+	public PaperDetailUnit getPaperDetailUnitId(@PathVariable String unit_id){
+		return unitService.findById(unit_id);
+	}
 
 
-	    /**
-	     * 更新小题信息
-	     * @param pdu
-	     * @return
-	     */
-	    @PutMapping(value = "/paperDetailUnit")
-	    public ResponseEntity updatePaperDetailUnit(@ModelAttribute PaperDetailUnit pdu){
-	        PaperDetailUnit pdUnit = unitService.savePaperDetailUnit(pdu);
-	        ResponseEntity rse = new ResponseEntity(pdUnit,HttpStatus.OK);
-	        return rse;
+	/**
+	 * 更新小题信息
+	 * @param pdu
+	 * @return
+	 */
+	@PutMapping(value = "/paperDetailUnit")
+	public ResponseEntity updatePaperDetailUnit(@ModelAttribute PaperDetailUnit pdu){
+		PaperDetailUnit pdUnit = unitService.savePaperDetailUnit(pdu);
+		return new ResponseEntity(pdUnit,HttpStatus.OK);
 
-	    }
+	}
 
-	    /**
-	     * 新增小题
-	     * @param pdu
-	     * @return
-	     */
-	    @PostMapping(value = "/paperDetailUnit")
-	    public ResponseEntity addPaperDetailUnit(@ModelAttribute PaperDetailUnit pdu){
-	      PaperDetailUnit pdUnit = unitService.savePaperDetailUnit(pdu);
-	      ResponseEntity rse2 = new ResponseEntity(pdUnit,HttpStatus.OK);
-	      return rse2;
-	    }
+	/**
+	 * 新增小题
+	 * @param pdu
+	 * @return
+	 */
+	@PostMapping(value = "/paperDetailUnit")
+	public ResponseEntity addPaperDetailUnit(@ModelAttribute PaperDetailUnit pdu){
+		PaperDetailUnit pdUnit = unitService.savePaperDetailUnit(pdu);
+		return new ResponseEntity(pdUnit,HttpStatus.OK);
+	}
 
-	    /**
-	     * 删除小题
-	     * @param unit_id
-	     * @return
-	     */
-	    @DeleteMapping(value = "/paperDetailUnit/{unit_id}")
-	    public ResponseEntity removePaperDetailUnit(@PathVariable String unit_id){
-	    	unitService.deletePaperDetailUnit(unit_id);
-	    	ResponseEntity rse2 = new ResponseEntity(unit_id,HttpStatus.OK);
-	    	return rse2;
-	    }
+	/**
+	 * 删除小题
+	 * @param unit_id
+	 * @return
+	 */
+	@DeleteMapping(value = "/paperDetailUnit/{unit_id}")
+	public ResponseEntity removePaperDetailUnit(@PathVariable String unit_id){
+		unitService.deletePaperDetailUnit(unit_id);
+		return new ResponseEntity(HttpStatus.OK);
+	}
 
 }

+ 16 - 36
cqb-paper/src/main/java/com/qmth/cqb/paper/web/PaperStructController.java

@@ -1,8 +1,5 @@
 package com.qmth.cqb.paper.web;
 
-import java.util.List;
-
-import com.qmth.cqb.paper.model.PaperStructDetail;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
@@ -16,7 +13,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import com.qmth.cqb.paper.model.PaperStruct;
-import com.qmth.cqb.paper.service.PaperStructDetailService;
 import com.qmth.cqb.paper.service.PaperStructService;
 
 /**
@@ -29,64 +25,48 @@ public class PaperStructController {
 	@Autowired
     PaperStructService paperStructService;
 	
-	@Autowired
-    PaperStructDetailService detailService;
-	
     /**
      * 根据id获取试卷结构
      * @param 
      * @return
      */
-    @GetMapping(value = "/paperStructure/{paper_id}")
-    public PaperStruct getPaperStructureById(@PathVariable String paper_id){
-        return paperStructService.findById(paper_id);
+    @GetMapping(value = "/paperStructure/{id}")
+    public PaperStruct getPaperStructureById(@PathVariable String id){
+        return paperStructService.findById(id);
     }
     
-    /**
-     * 获取试卷结构下面的详情信息
-     * @param paper_id
-     * @return
-     */
-    @GetMapping(value = "/paperStructure/detail/{paper_id}")
-    public List<PaperStructDetail> getQuesPaperById(@PathVariable String paper_id){
-    	return detailService.getDetailsByPaperStructure(paperStructService.findById(paper_id));
-    }
-
 
     /**
-     * 更新导入试卷信息
+     * 更新试卷结构
      * @param 
      * @return
      */
     @PutMapping(value = "/paperStructure")
     public ResponseEntity updatePaperStructure(@ModelAttribute PaperStruct ps){
-    	PaperStruct temp = paperStructService.savePaperStructure(ps);
-    	ResponseEntity rse = new ResponseEntity(temp,HttpStatus.OK);
-    	return rse;
+    	PaperStruct paperStruct = paperStructService.savePaperStructure(ps);
+    	return new ResponseEntity(paperStruct,HttpStatus.OK);
     	
     }
 
     /**
-     * 新增导入试卷
-     * @param paper
+     * 新增试卷结构
+     * @param ps
      * @return
      */
     @PostMapping(value = "/paperStructure")
     public ResponseEntity addPaperStructure(@ModelAttribute PaperStruct ps){
-    	PaperStruct temp = paperStructService.savePaperStructure(ps);
-    	ResponseEntity rse = new ResponseEntity(temp,HttpStatus.OK);
-    	return rse;
+    	PaperStruct paperStruct = paperStructService.savePaperStructure(ps);
+    	return new ResponseEntity(paperStruct,HttpStatus.OK);
     }
 
     /**
-     * 删除导入试卷
-     * @param paper_id
+     * 删除试卷结构
+     * @param id
      * @return
      */
-    @DeleteMapping(value = "/paperStructure/{paper_id}")
-    public ResponseEntity removePaperStructure(@PathVariable String paper_id){
-    	paperStructService.deletePaperStructure(paper_id);
-    	ResponseEntity res = new ResponseEntity(paper_id,HttpStatus.OK);
-		return res;
+    @DeleteMapping(value = "/paperStructure/{id}")
+    public ResponseEntity removePaperStructure(@PathVariable String id){
+    	paperStructService.deletePaperStructure(id);
+		return new ResponseEntity(HttpStatus.OK);
     }
 }

+ 0 - 81
cqb-paper/src/main/java/com/qmth/cqb/paper/web/PaperStructDetailController.java

@@ -1,81 +0,0 @@
-package com.qmth.cqb.paper.web;
-
-import com.qmth.cqb.paper.model.PaperStructDetail;
-import com.qmth.cqb.paper.service.PaperStructDetailService;
-
-import io.swagger.annotations.ApiOperation;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.ModelAttribute;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-/**
- * Created by songyue on 16/12/28.
- */
-@RestController
-@RequestMapping("${api_cqb}/")
-public class PaperStructDetailController {
-	@Autowired
-    PaperStructDetailService detailService;
-	
-	
-	
-	
-   /**
-    * 获取大题
-    * @param id
-    * @return
-    */
-   @ApiOperation(value="获取单个大题",notes="获取单个大题")
-   @GetMapping(value = "/PaperStructDetail/{detail_id}")
-   public PaperStructDetail getPaperDetailStructureById(@PathVariable String detail_id){
-       return detailService.findById(detail_id);
-   }
-
-
-   /**
-    * 更新大题信息
-    * @param PaperDetailStructure
-    * @return
-    */
-   @PutMapping(value = "/paperDetailStructure")
-   public ResponseEntity updatePaperDetailStructure(@ModelAttribute PaperStructDetail pd){
-       PaperStructDetail paperDetail = detailService.savePaperStructureDetail(pd);
-       ResponseEntity rse = new ResponseEntity(paperDetail,HttpStatus.OK);
-       return rse;
-   	
-   }
-
-   /**
-    * 新增大题
-    * @param PaperDetailStructure
-    * @return
-    */
-   @PostMapping(value = "/paperDetailStructure")
-   public ResponseEntity addPaperDetailStructure(@ModelAttribute PaperStructDetail pd){
-     PaperStructDetail paperDetail = detailService.savePaperStructureDetail(pd);
-     ResponseEntity rse2 = new ResponseEntity(paperDetail,HttpStatus.OK);
-     return rse2;
-   }
-
-   /**
-    * 删除大题
-    * @param id
-    * @return
-    */
-   @DeleteMapping(value = "/paperDetailStructure/{detail_id}")
-   public ResponseEntity removePaperDetailStructure(@PathVariable String detail_id){
-   	detailService.deletePaperDetailStructure(detail_id);
-   	ResponseEntity rse2 = new ResponseEntity(detail_id,HttpStatus.OK);
-   	return rse2;
-   }
-	
-}

+ 4 - 3
cqb-question-resource/src/main/java/com/qmth/cqb/question/model/Question.java

@@ -1,6 +1,7 @@
 package com.qmth.cqb.question.model;
 
 import com.qmth.cqb.utils.CommonUtils;
+import com.qmth.cqb.utils.enums.QuesStructType;
 import com.qmth.cqb.utils.word.DocxProcessUtil;
 import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
 import org.springframework.data.annotation.Id;
@@ -35,7 +36,7 @@ public class Question implements Serializable{
 
     private List<QuesResource> quesResource;//试题resource(试题资源库集合,适用于多媒体介质试题)
 
-    private QuestionType questionType;//试题结构类型
+    private QuesStructType questionType;//试题结构类型
 
     private String createTime;//创建时间
 
@@ -121,11 +122,11 @@ public class Question implements Serializable{
         this.quesResource = quesResource;
     }
 
-    public QuestionType getQuestionType() {
+    public QuesStructType getQuestionType() {
         return questionType;
     }
 
-    public void setQuestionType(QuestionType questionType) {
+    public void setQuestionType(QuesStructType questionType) {
         this.questionType = questionType;
     }
 

+ 2 - 5
cqb-question-resource/src/main/java/com/qmth/cqb/question/service/QuesService.java

@@ -5,6 +5,7 @@ import com.qmth.cqb.question.model.QuestionType;
 import com.qmth.cqb.question.model.Question;
 import com.qmth.cqb.question.model.QuestionSearchCondition;
 
+import com.qmth.cqb.utils.BeanCopierUtil;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Example;
@@ -31,11 +32,7 @@ public class QuesService {
     public Page<Question> findAll(QuestionSearchCondition searchCondition,
                                   int curPage,
                                   int pageSize){
-    	Question ques = new Question();
-    	QuestionType quesType = new QuestionType();
-        quesType.setName(searchCondition.getQuesTypeName());
-    	ques.setQuestionType(quesType);
-    	BeanUtils.copyProperties(searchCondition,ques);
+        Question ques = BeanCopierUtil.copyProperties(searchCondition,Question.class);
         return quesRepo.findAll(Example.of(ques),new PageRequest(curPage - 1,pageSize));
     }
 }

BIN
cqb-question-resource/target/classes/com/qmth/cqb/question/model/Question.class


BIN
cqb-question-resource/target/classes/com/qmth/cqb/question/service/QuesService.class


+ 1 - 1
cqb-question-resource/target/maven-archiver/pom.properties

@@ -1,5 +1,5 @@
 #Generated by Apache Maven
-#Mon Mar 20 18:27:20 CST 2017
+#Tue Mar 21 18:50:48 CST 2017
 version=0.1.0
 groupId=com.qmth.cqb
 artifactId=cqb-question-resource

+ 2 - 1
cqb-starter/pom.xml

@@ -78,6 +78,7 @@
             <artifactId>spring-boot-starter-test</artifactId>
             <scope>test</scope>
         </dependency>
+
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-devtools</artifactId>
@@ -94,9 +95,9 @@
             <artifactId>springfox-swagger-ui</artifactId>
             <version>${swagger-version}</version>
         </dependency>
-        
 
     </dependencies>
+
     <build>
         <plugins>
             <plugin>

+ 1 - 1
cqb-starter/src/main/resources/application.properties

@@ -1,4 +1,4 @@
-spring.data.mongodb.uri=mongodb://192.168.1.99:27017/comm-ques-bank
+spring.data.mongodb.uri=mongodb://localhost:27017/comm-ques-bank
 spring.data.mongodb.grid-fs-database=comm-ques-bank
 server.port=8888
 logging.config=classpath:log4j2.xml

+ 1 - 8
cqb-starter/src/main/resources/log4j2.xml

@@ -12,14 +12,7 @@
         <Root level="info">
             <AppenderRef ref="Console" />
         </Root>
-
-        <Root level="error">
-            <AppenderRef ref="Console" />
-        </Root>
-
-        <Root level="debug">
-            <AppenderRef ref="Console" />
-        </Root>
+        <Logger name="org.docx4j" level="off" />
 
     </Loggers>
 </Configuration>

+ 3 - 4
cqb-starter/src/test/java/com/qmth/cqb/AppTest.java

@@ -143,7 +143,7 @@ public class AppTest {
         QuestionType questionType = new QuestionType();
         questionType.setName("阅读理解");
         questionType.setQuesType(QuesStructType.NESTED_ANSWER_QUESTION);
-        question.setQuestionType(questionType);
+        question.setQuestionType(QuesStructType.NESTED_ANSWER_QUESTION);
         List<Question> subquestionList = new ArrayList<Question>();
 
 
@@ -165,7 +165,7 @@ public class AppTest {
             subquestion.setQuesOptions(quesOptionList);
             QuestionType questionType1 = new QuestionType();
             questionType1.setQuesType(QuesStructType.SINGLE_ANSWER_QUESTION);
-            subquestion.setQuestionType(questionType1);
+            subquestion.setQuestionType(QuesStructType.SINGLE_ANSWER_QUESTION);
             subquestionList.add(subquestion);
         }
         question.setSubQuestions(subquestionList);
@@ -190,7 +190,6 @@ public class AppTest {
         QuestionType questionType1 = new QuestionType();
         questionType1.setName("单项选择题");
         questionType1.setQuesType(QuesStructType.SINGLE_ANSWER_QUESTION);
-        paperDetail.setQuestionType(questionType1);
         paperDetail.setUnitCount(3);
 
         paperRepo.save(paper);
@@ -263,7 +262,7 @@ public class AppTest {
         @Test
         public void testExport()throws Exception{
             long startTime = System.currentTimeMillis();    //获取开始时间
-            exportPaperService.exportPaper("58cb82a8f6c5faef9b2a9f01");
+            exportPaperService.exportPaper("58d0ef46aaa9a760080e2136");
             long endTime = System.currentTimeMillis();    //获取结束时间
             System.out.println("程序运行时间:" + (endTime - startTime)/1000 + "s");    //输出程序运行时间
         }