|
@@ -17,6 +17,7 @@ import com.qmth.cqb.utils.BeanCopierUtil;
|
|
|
import com.qmth.cqb.utils.CommonUtils;
|
|
|
import com.qmth.cqb.utils.exception.PaperException;
|
|
|
import com.qmth.cqb.utils.word.DocxProcessUtil;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.docx4j.XmlUtils;
|
|
|
import org.docx4j.jaxb.Context;
|
|
|
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
|
|
@@ -26,6 +27,7 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+import javax.xml.bind.JAXBElement;
|
|
|
import java.util.Collections;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
@@ -172,10 +174,16 @@ public class ExportPaperService {
|
|
|
}
|
|
|
}
|
|
|
List<Question> subQuesList = paperDetailUnit.getQuestion().getSubQuestions();
|
|
|
+ Question question = paperDetailUnit.getQuestion();
|
|
|
//套题序号
|
|
|
if(subQuesList != null && subQuesList.size() > 0){
|
|
|
+
|
|
|
+ question.setQuesBodyWord(replaceQuesBlank(question.getQuesBodyWord(),subNum + 1));
|
|
|
+
|
|
|
for(Question subQues:subQuesList){
|
|
|
- subQues.setQuesBodyWord(setSubQuesNum(subQues.getQuesBodyWord(),++subNum));
|
|
|
+ int curSubNum = ++subNum;
|
|
|
+ subQues.setQuesBodyWord(setSubQuesNum(subQues.getQuesBodyWord(),curSubNum));
|
|
|
+ subQues.setQuesBodyWord(replaceQuesBlank(subQues.getQuesBodyWord(),curSubNum));
|
|
|
List<QuesOption> subOptionList = subQues.getQuesOptions();
|
|
|
if(subOptionList != null && subOptionList.size() > 0){
|
|
|
int sub_index = 0;
|
|
@@ -186,8 +194,9 @@ public class ExportPaperService {
|
|
|
}
|
|
|
}
|
|
|
}else{
|
|
|
- Question question = paperDetailUnit.getQuestion();
|
|
|
- question.setQuesBodyWord(setSubQuesNum(question.getQuesBodyWord(),++subNum));
|
|
|
+ int curSubNum = ++subNum;
|
|
|
+ question.setQuesBodyWord(setSubQuesNum(question.getQuesBodyWord(),curSubNum));
|
|
|
+ question.setQuesBodyWord(replaceQuesBlank(question.getQuesBodyWord(),curSubNum));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -253,4 +262,60 @@ public class ExportPaperService {
|
|
|
return DocxProcessUtil.formatPWordMl(XmlUtils.marshaltoString(p));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 替换填空
|
|
|
+ * @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();
|
|
|
+ if(str.equals("###")){
|
|
|
+ text.setValue("______");
|
|
|
+ }else if(str.startsWith("#") || str.equals("___")){
|
|
|
+ curMap.put(cur,str);
|
|
|
+ text.setValue("");
|
|
|
+ }else 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();
|
|
|
+ }
|
|
|
+
|
|
|
}
|