Эх сурвалжийг харах

题干分数去掉小数点

weiwenhai 7 жил өмнө
parent
commit
335d95ad7c

+ 17 - 4
cqb-paper/src/main/java/com/qmth/cqb/paper/service/export/DzkdExportPaperService.java

@@ -126,6 +126,9 @@ public class DzkdExportPaperService extends ExportPaperAbstractService {
 			String totalScore = BigDecimal.valueOf(paperDetailExp.getScore()).stripTrailingZeros().toPlainString();
 			QuesStructType type = paperDetailExp.getPaperDetailUnits().get(0).getQuestionType();
 			String questionScore = checkPaperDetailUnitScore(paperDetailExp);
+			if(questionScore!=null){
+   				questionScore = deletePoint(questionScore);
+   			}
 			String scoreString = questionScore==null?"":"每小题"+questionScore+"分,";
 			if (type == QuesStructType.SINGLE_ANSWER_QUESTION) {
 				paperDetailExp.setName("单项选择题");
@@ -162,6 +165,14 @@ public class DzkdExportPaperService extends ExportPaperAbstractService {
 		}
 	}
 	
+	//去掉分数后面的小数点
+  	private String deletePoint(String str) {
+  		if(str.indexOf(".0")>-1){
+  			return str.replace(".0", "");
+  		}
+  		return str;
+  	}
+	
 	/**
 	 * 计算每个大题所有填空题空格数量
 	 * @param paperDetailExp
@@ -259,12 +270,13 @@ public class DzkdExportPaperService extends ExportPaperAbstractService {
 			for(PaperDetailExp objectiveDetail:objectiveDetails){
 				score += objectiveDetail.getScore();
 			}
+			String scores = BigDecimal.valueOf(score).stripTrailingZeros().toPlainString();
 			//判断是否有主观题
 			if(subjectiveDetails == null || subjectiveDetails.size() < 1){
-				title = "客观题(总分" + score + "分)";
+				title = "客观题(总分" + scores + "分)";
 				paperExp.setObjectiveTitle(title);
 			}else {
-				title = "第一部分"+ "    " +"客观题(总分" + score + "分)";
+				title = "第一部分"+ "    " +"客观题(总分" + scores + "分)";
 			}
 			paperExp.setObjectiveTitle(title);
 		}
@@ -273,12 +285,13 @@ public class DzkdExportPaperService extends ExportPaperAbstractService {
 			for(PaperDetailExp objectiveDetail:subjectiveDetails){
 				score += objectiveDetail.getScore();
 			}
+			String scores = BigDecimal.valueOf(score).stripTrailingZeros().toPlainString();
 			//判断是否有客观题
 			if(objectiveDetails == null || objectiveDetails.size() < 1){
-				title = "主观题(总分" + score + "分)";
+				title = "主观题(总分" + scores + "分)";
 				paperExp.setSubjectiveTitle(title);
 			}else {
-				title = "第二部分"+ "    " +"主观题(总分" + score + "分)";
+				title = "第二部分"+ "    " +"主观题(总分" + scores + "分)";
 			}
 			paperExp.setSubjectiveTitle(title);
 		}

+ 90 - 70
cqb-paper/src/main/java/com/qmth/cqb/paper/service/export/ExportPaperAbstractService.java

@@ -303,75 +303,82 @@ public abstract class ExportPaperAbstractService {
            return String.valueOf(optionNum);
        }
     
-    /**
-     * 替换填空
-     * 将###替换为下划线_______
-     * @param wordMl
-     * @param num
-     * @return
-     * @throws Exception
-     */
-	public String replaceQuesBlank(String wordMl,int num) throws Exception {
-        String tmpStr = DocxProcessUtil.BODY_HEADER + wordMl + DocxProcessUtil.BODY_TAIL;
-        Body body = (Body)XmlUtils.unmarshalString(tmpStr,Context.jc,Body.class);
-        List<Object> pList = body.getContent();
-        int index = 0;
-        int cur = 0;
-        Map<Integer,String> curMap = new HashMap<Integer,String>();
-        for(Object pObj:pList){
-            if(pObj.getClass().equals(P.class)){
-                List<Object> pContent = ((P)pObj).getContent();
-                for(Object rObj:pContent){
-                    if(rObj.getClass().equals(R.class)){
-                        List<Object> rContent = ((R)rObj).getContent();
-                        for(Object tObj:rContent){
-                            if (tObj instanceof JAXBElement)
-                                tObj = ((JAXBElement<?>) tObj).getValue();
-                            if(tObj.getClass().equals(Text.class)){
-                                Text text = (Text)tObj;
-                                String str = text.getValue();
-                                //1
-                                str = str.replaceAll("###","______");
-                                text.setValue(str);
-                                //2
-                                Pattern pattern = Pattern.compile("##\\d{1,}##");
-                        		Matcher m = pattern.matcher(str);
-                            	while(m.find()){
-                            		int curNum = num + index;
-                                    String a = m.group();
-                                    str = str.replaceAll(a, "___"+(curNum)+"___");
-                                    text.setValue(str);
-                                    index++;
-                            	}
-                            	//3
-                                if(str.startsWith("#") || str.equals("___")){
-                                    curMap.put(cur,str);
-                                    text.setValue("");
-                                }
-                                //4
-                                if(str.matches("^\\d{1,}$")){
-                                    String preStr = curMap.get(cur - 1);
-                                    if(!StringUtils.isEmpty(preStr) && preStr.startsWith("#")){
-                                        int curNum = num + index;
-                                        text.setValue("___"+(curNum)+"___");
-                                        index++;
-                                    }
-                                }
-                                cur++;
-                            }
-                        }
-                    }
-                }
-            }
-        }
-        StringBuffer pWordMl = new StringBuffer();
-        for(Object pObj:pList){
-            if(pObj instanceof P){
-                pWordMl.append(DocxProcessUtil.formatPWordMl(XmlUtils.marshaltoString(pObj)));
-            }
-        }
-        return pWordMl.toString();
-    }
+       /**
+        * 替换填空
+        * 将###替换为下划线_______
+        * @param wordMl
+        * @param num
+        * @return
+        * @throws Exception
+        */
+   	public String replaceQuesBlank(String wordMl,int num) throws Exception {
+           String tmpStr = DocxProcessUtil.BODY_HEADER + wordMl + DocxProcessUtil.BODY_TAIL;
+           Body body = (Body)XmlUtils.unmarshalString(tmpStr,Context.jc,Body.class);
+           List<Object> pList = body.getContent();
+           int index = 0;
+           int cur = 0;
+           Map<Integer,String> curMap = new HashMap<Integer,String>();
+           for(Object pObj:pList){
+               if(pObj.getClass().equals(P.class)){
+                   List<Object> pContent = ((P)pObj).getContent();
+                   for(Object rObj:pContent){
+                       if(rObj.getClass().equals(R.class)){
+                           List<Object> rContent = ((R)rObj).getContent();
+                           for(Object tObj:rContent){
+                               if (tObj instanceof JAXBElement)
+                                   tObj = ((JAXBElement<?>) tObj).getValue();
+                               if(tObj.getClass().equals(Text.class)){
+                                   Text text = (Text)tObj;
+                                   String str = text.getValue();
+                                   //1
+                                   if("##".equals(str.trim())){
+                                   	str = "___";
+                                       text.setValue(str);
+                                   }
+                                   //2
+                                   str = str.replaceAll("###","______");
+                                   text.setValue(str);
+                                   //3
+                                   Pattern pattern = Pattern.compile("##\\d{1,}##");
+                           		Matcher m = pattern.matcher(str);
+                               	while(m.find()){
+                               		int curNum = num + index;
+                                       String a = m.group();
+                                       str = str.replaceAll(a, "___"+(curNum)+"___");
+                                       text.setValue(str);
+                                       index++;
+                               	}
+                               	//4
+                                   /*if(str.startsWith("#") || str.equals("___")){
+                                       curMap.put(cur,str);
+                                       text.setValue("");
+                                   }*/
+                                   //5
+                                   if(str.matches("^\\d{1,}$")){
+                                       String preStr = curMap.get(cur - 1);
+                                       int curNum = num + index;
+                                       if(!StringUtils.isEmpty(preStr) && preStr.startsWith("#")){
+                                           text.setValue("___"+(curNum)+"___");
+                                       }else{
+                                       	text.setValue(curNum+"");
+                                       }
+                                       index++;
+                                   }
+                                   cur++;
+                               }
+                           }
+                       }
+                   }
+               }
+           }
+           StringBuffer pWordMl = new StringBuffer();
+           for(Object pObj:pList){
+               if(pObj instanceof P){
+                   pWordMl.append(DocxProcessUtil.formatPWordMl(XmlUtils.marshaltoString(pObj)));
+               }
+           }
+           return pWordMl.toString();
+       }
 	
 	/**
      * 设置题号
@@ -457,6 +464,8 @@ public abstract class ExportPaperAbstractService {
      * @throws Exception 
      */
     public String appendScoreToQuestionBody(String quesBodyWordMl,double score) throws Exception{
+    	String totalScore = BigDecimal.valueOf(score).stripTrailingZeros().toPlainString();
+    	String scores = deletePoint(totalScore);
     	String tmpStr = DocxProcessUtil.BODY_HEADER + quesBodyWordMl + DocxProcessUtil.BODY_TAIL;
         Body body = (Body)XmlUtils.unmarshalString(tmpStr,Context.jc,Body.class);
         List<Object> pList = body.getContent();
@@ -469,7 +478,7 @@ public abstract class ExportPaperAbstractService {
             List<Object> pContent = p.getContent();
             R run = new R();
             Text text = new Text();
-            text.setValue("("+score+"分)");
+            text.setValue("("+scores+"分)");
             run.getContent().add(text);
             pContent.add(run);
             index++;
@@ -483,6 +492,14 @@ public abstract class ExportPaperAbstractService {
         return pWordMl.toString();
     }
     
+    //去掉分数后面的小数点
+  	private String deletePoint(String str) {
+  		if(str.indexOf(".0")>-1){
+  			return str.replace(".0", "");
+  		}
+  		return str;
+  	}
+  	
     /**
      * 当大题下小题分数不是全部一样时,在小题题干后面加上小题的分数
      * @param details
@@ -571,6 +588,9 @@ public abstract class ExportPaperAbstractService {
    			String totalScore = BigDecimal.valueOf(paperDetailExp.getScore()).stripTrailingZeros().toPlainString();
    			QuesStructType type = paperDetailExp.getPaperDetailUnits().get(0).getQuestionType();
    			String questionScore = checkPaperDetailUnitScore(paperDetailExp);
+   			if(questionScore!=null){
+   				questionScore = deletePoint(questionScore);
+   			}
    			String scoreString = questionScore==null?"":"每小题"+questionScore+"分,";
    			if (type == QuesStructType.SINGLE_ANSWER_QUESTION) {
    				paperDetailExp.setName("单项选择题");