|
@@ -0,0 +1,782 @@
|
|
|
|
+package cn.com.qmth.examcloud.core.questions.service.temp;
|
|
|
|
+
|
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.net.URLEncoder;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.LinkedHashMap;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.Set;
|
|
|
|
+import java.util.UUID;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+import java.util.regex.Matcher;
|
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
+
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+import cn.com.qmth.examcloud.common.dto.question.enums.QuesStructType;
|
|
|
|
+import cn.com.qmth.examcloud.commons.base.util.JsonUtil;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.base.CommonUtils;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.base.enums.PaperStatus;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.base.enums.PaperType;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.base.word.DocxProcessUtil;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.CourseRepo;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.PaperDetailRepo;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.PaperDetailUnitRepo;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.PaperRepo;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.QuesPkgPathRepo;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.QuesRepo;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.entity.Course;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.entity.Paper;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.entity.PaperDetail;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.entity.PaperDetailUnit;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.entity.QuesOption;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.entity.Question;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.entity.QuestionPkgPath;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.service.temp.vo.TestFillAnswer;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.service.temp.vo.TestFillContent;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.service.temp.vo.TestOption;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.service.temp.vo.TestOptionGroup;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.service.temp.vo.TestPaper;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.service.temp.vo.TestQuestion;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.service.temp.vo.TestQuestionInfo;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @author weiwenhai
|
|
|
|
+ * @date 2018.7.19
|
|
|
|
+ * @company qmth
|
|
|
|
+ * @describle 地大题库数据导入
|
|
|
|
+ */
|
|
|
|
+@Service("ddCollegeUtilService")
|
|
|
|
+public class DdCollegeUtilService {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private JdbcTemplate jdbcTemplate;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private CourseRepo courseRepo;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private QuesPkgPathRepo quesPkgPathRepo;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private QuesRepo quesRepo;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private PaperRepo paperRepo;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private PaperDetailRepo paperDetailRepo;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private PaperDetailUnitRepo paperDetailUnitRepo;
|
|
|
|
+
|
|
|
|
+ public void importPaper(String orgId,String courseCode) throws Exception{
|
|
|
|
+ //查询课程
|
|
|
|
+ Course course = courseRepo.findFirstByCodeAndOrgId(courseCode,orgId);
|
|
|
|
+ //查询试卷集合
|
|
|
|
+ //List<TestPaper> papers = queryByCourse(courseCode);
|
|
|
|
+ TestPaper testPaper1 = new TestPaper();
|
|
|
|
+ testPaper1.setId("21D9D5D5E5FE0A438282C9B490BF45DE");
|
|
|
|
+ testPaper1.setName("地大所有题型");
|
|
|
|
+ testPaper1.setScore(100.0);
|
|
|
|
+ testPaper1.setTestPaperContentId("F61A67F4898249767CB0A31A3BD2616B");//EBE6752BCE3A360D1F50BE9FBA4ADCE7,F61A67F4898249767CB0A31A3BD2616B
|
|
|
|
+ List<TestPaper> papers = new ArrayList<TestPaper>();
|
|
|
|
+ papers.add(testPaper1);
|
|
|
|
+ if(papers != null && papers.size()>0){
|
|
|
|
+ for(TestPaper testPaper:papers){
|
|
|
|
+ //查询试题详情
|
|
|
|
+ List<TestQuestion> questions = queryByTestPaper(testPaper.getTestPaperContentId());
|
|
|
|
+ if(questions != null && questions.size()>0){
|
|
|
|
+ //构建大题和小题对应关系
|
|
|
|
+ Map<Integer, List<TestQuestion>> map = sortPaperDetail(questions);
|
|
|
|
+ //初始化试卷
|
|
|
|
+ Paper paper = initPaper(testPaper,orgId,course,map);
|
|
|
|
+ //定义大题集合
|
|
|
|
+ List<PaperDetail> paperDetails = new ArrayList<PaperDetail>();
|
|
|
|
+ //定义小题集合
|
|
|
|
+ List<PaperDetailUnit> paperDetailUnits = new ArrayList<PaperDetailUnit>();
|
|
|
|
+ //试题---资源 对应关系
|
|
|
|
+ Map<Question, QuestionPkgPath> map2 = new HashMap<Question, QuestionPkgPath>();
|
|
|
|
+ //定义试卷难度
|
|
|
|
+ double difficulty = 0;
|
|
|
|
+ for(Integer key:map.keySet()){
|
|
|
|
+ List<TestQuestion> dQuestions = map.get(key);
|
|
|
|
+ //初始化大题对象
|
|
|
|
+ PaperDetail paperDetail = initPaperDetail(dQuestions,paper);
|
|
|
|
+ if(dQuestions != null && dQuestions.size()>0){
|
|
|
|
+ for(TestQuestion testQuestion:dQuestions){
|
|
|
|
+ TestQuestionInfo testQuestionInfo = JsonUtil.fromJson(testQuestion.getJson(),TestQuestionInfo.class);
|
|
|
|
+ //初始化试题对象
|
|
|
|
+ Question question= initQuestion(testQuestionInfo,testQuestion,course,map2,difficulty);
|
|
|
|
+ //初始化小题对象
|
|
|
|
+ PaperDetailUnit paperDetailUnit = initPaperDetailUnit(paper, paperDetail, question, testQuestion);
|
|
|
|
+ paperDetailUnits.add(paperDetailUnit);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ paperDetails.add(paperDetail);
|
|
|
|
+ }
|
|
|
|
+ //保存试题资源
|
|
|
|
+ quesPkgPathRepo.save(map2.values());
|
|
|
|
+ for(Map.Entry<Question, QuestionPkgPath> entry:map2.entrySet()){
|
|
|
|
+ entry.getKey().setQuesPkgPathId(entry.getValue().getId());
|
|
|
|
+ }
|
|
|
|
+ //计算试卷难度
|
|
|
|
+ BigDecimal b = new BigDecimal(difficulty / paper.getTotalScore());
|
|
|
|
+ Double difficultyDegree = b.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
|
+ paper.setDifficultyDegree(difficultyDegree);
|
|
|
|
+ //重新计算试题序号
|
|
|
|
+ Map<PaperDetail, List<PaperDetailUnit>> map3 = new LinkedHashMap<PaperDetail, List<PaperDetailUnit>>();
|
|
|
|
+ List<PaperDetailUnit> newList = null;
|
|
|
|
+ for(PaperDetail paperDetail:paperDetails){
|
|
|
|
+ for(PaperDetailUnit paperDetailUnit:paperDetailUnits){
|
|
|
|
+ if(paperDetail.getName().equals(paperDetailUnit.getPaperDetail().getName())){
|
|
|
|
+ if(map3.get(paperDetail) == null){
|
|
|
|
+ newList = new ArrayList<PaperDetailUnit>();
|
|
|
|
+ newList.add(paperDetailUnit);
|
|
|
|
+ }else {
|
|
|
|
+ newList = map3.get(paperDetail);
|
|
|
|
+ newList.add(paperDetailUnit);
|
|
|
|
+ }
|
|
|
|
+ map3.put(paperDetail, newList);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ int number =1;
|
|
|
|
+ for(Map.Entry<PaperDetail, List<PaperDetailUnit>> entry:map3.entrySet()){
|
|
|
|
+ for(PaperDetailUnit paperDetailUnit:entry.getValue()){
|
|
|
|
+ paperDetailUnit.setNumber(number);
|
|
|
|
+ number++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ quesRepo.save(map2.keySet());
|
|
|
|
+ paperRepo.save(paper);
|
|
|
|
+ paperDetailRepo.save(paperDetails);
|
|
|
|
+ paperDetailUnitRepo.save(paperDetailUnits);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据课程代码查询所有试卷
|
|
|
|
+ * @param codeName
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @SuppressWarnings({"unchecked","rawtypes"})
|
|
|
|
+ public List<TestPaper> queryByCourse(String courseCode){
|
|
|
|
+ String sql = "SELECT * from dd_test_paper_info_temp p WHERE p.COURSE_ID in "
|
|
|
|
+ + "(SELECT c.ID FROM dd_pe_tch_course_temp c WHERE c.code = '"+ courseCode +"')";
|
|
|
|
+ List<TestPaper> papers = this.jdbcTemplate.query(sql, new BeanPropertyRowMapper(TestPaper.class));
|
|
|
|
+ return papers;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据考试id查询所有试题
|
|
|
|
+ * @param testPaperContentId
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @SuppressWarnings({"unchecked","rawtypes"})
|
|
|
|
+ public List<TestQuestion> queryByTestPaper(String testPaperContentId){
|
|
|
|
+ String sql = "SELECT q.ID id,d.dNumber,d.`name` dName,d.number number,d.score score,q.PARENT_ID parent_id,q.QUESTION_TYPE_ENUM type,q.JSON "
|
|
|
|
+ + "FROM dd_question_content_temp q ,(SELECT b.QUESTION_CONTENT_ID question_id, b.SCORE score, b.SEQUENCE number, c.name name, c.dNumber dNumber "
|
|
|
|
+ + "FROM dd_test_paper_question_temp b ,(SELECT a.ID id, a.`NAME` name,a.SEQUENCE dNumber,a.TEST_PAPER_CONTENT_ID "
|
|
|
|
+ + "FROM dd_test_paper_question_group_temp a WHERE a.TEST_PAPER_CONTENT_ID = '"+ testPaperContentId + "' ORDER BY a.sequence) c "
|
|
|
|
+ + "WHERE b.TEST_PAPER_QUESTION_GROUP_ID = c.id ORDER BY c.dNumber,b.SEQUENCE) d WHERE q.ID = d.question_id ORDER BY d.dNumber,d.number;";
|
|
|
|
+ List<TestQuestion> questions = this.jdbcTemplate.query(sql, new BeanPropertyRowMapper(TestQuestion.class));
|
|
|
|
+ return questions;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据父ID查询子题
|
|
|
|
+ * @param parentId
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @SuppressWarnings({"unchecked","rawtypes"})
|
|
|
|
+ public List<TestQuestion> querySubQuestions(String parentId){
|
|
|
|
+ String sql = "SELECT q.question_type_enum type, q.json json from dd_question_content_temp q WHERE q.parent_id = '" + parentId +"'";
|
|
|
|
+ List<TestQuestion> questions = this.jdbcTemplate.query(sql, new BeanPropertyRowMapper(TestQuestion.class));
|
|
|
|
+ return questions;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 初始化试卷对象
|
|
|
|
+ * @param paper
|
|
|
|
+ * @param paperName
|
|
|
|
+ * @param user
|
|
|
|
+ */
|
|
|
|
+ public Paper initPaper(TestPaper testPaper, String orgId, Course course,Map<Integer, List<TestQuestion>> map) {
|
|
|
|
+ int unitCount = 0;
|
|
|
|
+ Set<Integer> paperDetails = map.keySet();
|
|
|
|
+ for(Map.Entry<Integer, List<TestQuestion>> entry:map.entrySet()){
|
|
|
|
+ unitCount = unitCount + entry.getValue().size();
|
|
|
|
+ }
|
|
|
|
+ Paper paper = new Paper();
|
|
|
|
+ paper.setName(testPaper.getName());
|
|
|
|
+ paper.setTitle(testPaper.getName());
|
|
|
|
+ paper.setPaperType(PaperType.IMPORT);
|
|
|
|
+ paper.setPaperStatus(PaperStatus.DRAFT);
|
|
|
|
+ paper.setOrgId(orgId);
|
|
|
|
+ paper.setCreator("wei");
|
|
|
|
+ paper.setTotalScore(testPaper.getScore());
|
|
|
|
+ paper.setCourse(course);
|
|
|
|
+ paper.setCourseName(course.getName());
|
|
|
|
+ paper.setCourseNo(course.getCode());
|
|
|
|
+ paper.setCreateTime(CommonUtils.getCurDateTime());
|
|
|
|
+ paper.setPaperDetailCount(paperDetails.size());
|
|
|
|
+ paper.setUnitCount(unitCount);
|
|
|
|
+ return paper;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 初始化大题对象
|
|
|
|
+ * @param testQuestion
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public PaperDetail initPaperDetail(List<TestQuestion> dQuestions,Paper paper){
|
|
|
|
+ //定义大题分数
|
|
|
|
+ double dTotal = 0;
|
|
|
|
+ PaperDetail paperDetail = new PaperDetail();
|
|
|
|
+ if(dQuestions != null && dQuestions.size()>0){
|
|
|
|
+ for(TestQuestion question:dQuestions){
|
|
|
|
+ dTotal = dTotal + question.getScore();
|
|
|
|
+ }
|
|
|
|
+ paperDetail.setPaper(paper);
|
|
|
|
+ paperDetail.setNumber(dQuestions.get(0).getdNumber());
|
|
|
|
+ paperDetail.setName(dQuestions.get(0).getdName());
|
|
|
|
+ paperDetail.setScore(dTotal);
|
|
|
|
+ paperDetail.setUnitCount(dQuestions.size());
|
|
|
|
+ paperDetail.setCreator("wei");
|
|
|
|
+ paperDetail.setCreateTime(CommonUtils.getCurDateTime());
|
|
|
|
+ }
|
|
|
|
+ return paperDetail;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 初始化试题对象
|
|
|
|
+ * @param testQuestionInfo
|
|
|
|
+ * @param testQuestion
|
|
|
|
+ * @param course
|
|
|
|
+ * @param map
|
|
|
|
+ * @return
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
|
|
+ public Question initQuestion(TestQuestionInfo testQuestionInfo,TestQuestion testQuestion,Course course,Map<Question, QuestionPkgPath> map,double difficulty) throws Exception{
|
|
|
|
+ Question question = new Question();
|
|
|
|
+ question.setCreateTime(CommonUtils.getCurDateTime());
|
|
|
|
+ question.setScore(testQuestion.getScore());
|
|
|
|
+ question.setCourse(course);
|
|
|
|
+ question.setOrgId(course.getOrgId());
|
|
|
|
+ question.setHasAudio(false);
|
|
|
|
+ question.setDifficulty("中");
|
|
|
|
+ question.setDifficultyDegree(0.5);
|
|
|
|
+ question.setPublicity(true);
|
|
|
|
+ //按试题分类初始化题干,答案,选项
|
|
|
|
+ initQuestionInfo(question,testQuestionInfo,map,testQuestion);
|
|
|
|
+ difficulty = question.getScore() * 0.5 + difficulty;
|
|
|
|
+ return question;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 初始化题干,答案,选项,资源
|
|
|
|
+ * @param question
|
|
|
|
+ * @param testQuestionInfo
|
|
|
|
+ * @param map
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
|
|
+ public void initQuestionInfo(Question question,TestQuestionInfo testQuestionInfo,Map<Question, QuestionPkgPath> map,TestQuestion testQuestion) throws Exception{
|
|
|
|
+ WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
|
|
|
|
+ //选词填空
|
|
|
|
+ if(testQuestionInfo.getQuestionType() == 14){
|
|
|
|
+ question.setQuestionType(QuesStructType.TEXT_ANSWER_QUESTION);
|
|
|
|
+ //定义答案集合
|
|
|
|
+ List<String> answers = new ArrayList<String>();
|
|
|
|
+ //定义答案ID集合
|
|
|
|
+ List<String> answerIds = new ArrayList<String>();
|
|
|
|
+ List<TestFillAnswer> blanks = testQuestionInfo.getBlanks();
|
|
|
|
+ if(blanks != null && blanks.size()>0){
|
|
|
|
+ for(TestFillAnswer answer : blanks){
|
|
|
|
+ answerIds.add(answer.getAnswerId());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ StringBuffer quesBody = new StringBuffer();
|
|
|
|
+ quesBody.append("<p>"+testQuestionInfo.getQuestionHTML()+"</p>");
|
|
|
|
+ //获取选项,添加到题干
|
|
|
|
+ TestOptionGroup optionGroup = testQuestionInfo.getOptionGroup();
|
|
|
|
+ if(optionGroup!=null){
|
|
|
|
+ List<TestOption> options = optionGroup.getOptions();
|
|
|
|
+ if(options != null && options.size()>0){
|
|
|
|
+ int number = 1;
|
|
|
|
+ for(TestOption option:options){
|
|
|
|
+ char c1=(char) (number+64);
|
|
|
|
+ quesBody.append("<p>"+"("+String.valueOf(c1)+")"+option.getOptionHTML()+"</p>");
|
|
|
|
+ if(answerIds.contains(option.getID())){
|
|
|
|
+ answers.add(String.valueOf(c1));
|
|
|
|
+ }
|
|
|
|
+ number++;
|
|
|
|
+ }
|
|
|
|
+ //去掉<span>标签中的lang
|
|
|
|
+ String quesBodys = replaceLang(quesBody.toString());
|
|
|
|
+ //获取img标签
|
|
|
|
+ LinkedHashMap<String, String> bodyImgList = imgList(quesBodys);
|
|
|
|
+ //替换、补全Img标签
|
|
|
|
+ quesBodys = replaceImg(bodyImgList, quesBodys);
|
|
|
|
+ question.setQuesBody(quesBodys);
|
|
|
|
+ question.setQuesBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(question.getQuesBody())));
|
|
|
|
+ question.setQuesAnswer(StringUtils.join(answers,","));
|
|
|
|
+ String answerWord = "<p>" +question.getQuesAnswer() +"</p>";
|
|
|
|
+ question.setQuesAnswerWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(answerWord)));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //阅读理解题
|
|
|
|
+ if(testQuestionInfo.getQuestionType() == 42){
|
|
|
|
+ String quesBody = testQuestionInfo.getQuestionHTML();
|
|
|
|
+ //去掉<span>标签中的lang
|
|
|
|
+ quesBody = replaceLang(quesBody);
|
|
|
|
+ //获取img标签
|
|
|
|
+ LinkedHashMap<String, String> bodyImgList = imgList(quesBody);
|
|
|
|
+ //替换、补全Img标签
|
|
|
|
+ quesBody = replaceImg(bodyImgList, quesBody);
|
|
|
|
+ question.setQuesBody("<p>"+quesBody+"</p>");
|
|
|
|
+ question.setQuesBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(question.getQuesBody())));
|
|
|
|
+ question.setQuestionType(QuesStructType.NESTED_ANSWER_QUESTION);
|
|
|
|
+ List<Question> subQues = new ArrayList<Question>();
|
|
|
|
+ //查询所有子题
|
|
|
|
+ List<TestQuestion> subQuestions = querySubQuestions(testQuestion.getId());
|
|
|
|
+ if(subQuestions!=null && subQuestions.size()>0){
|
|
|
|
+ for(TestQuestion testQuestion2:subQuestions){
|
|
|
|
+ TestQuestionInfo testQuestionInfo2 = JsonUtil.fromJson(testQuestion2.getJson(),TestQuestionInfo.class);
|
|
|
|
+ Question subQuestion = new Question();
|
|
|
|
+ subQuestion.setDifficulty("中");
|
|
|
|
+ subQuestion.setDifficultyDegree(0.5);
|
|
|
|
+ subQuestion.setPublicity(true);
|
|
|
|
+ //按试题分类初始化题干,答案,选项
|
|
|
|
+ initQuestionInfo(subQuestion,testQuestionInfo2,map,testQuestion2);
|
|
|
|
+ subQues.add(subQuestion);
|
|
|
|
+ }
|
|
|
|
+ question.setSubQuestions(subQues);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //完形填空题
|
|
|
|
+ if(testQuestionInfo.getQuestionType() == 15){
|
|
|
|
+ String quesBody = testQuestionInfo.getQuestionHTML();
|
|
|
|
+ //去掉<span>标签中的lang
|
|
|
|
+ quesBody = replaceLang(quesBody);
|
|
|
|
+ //获取img标签
|
|
|
|
+ LinkedHashMap<String, String> bodyImgList = imgList(quesBody);
|
|
|
|
+ if(bodyImgList != null && bodyImgList.size()>0){
|
|
|
|
+ int number = 1;
|
|
|
|
+ for(Map.Entry<String, String> entry:bodyImgList.entrySet()){
|
|
|
|
+ if(StringUtils.isBlank(entry.getValue())){
|
|
|
|
+ quesBody = quesBody.replace(entry.getKey(),"##"+number+"##");
|
|
|
|
+ number++;
|
|
|
|
+ }else {
|
|
|
|
+ quesBody = quesBody.replace(entry.getKey(),entry.getValue());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ question.setQuesBody("<p>"+quesBody+"</p>");
|
|
|
|
+ question.setQuesBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(question.getQuesBody())));
|
|
|
|
+ question.setQuestionType(QuesStructType.NESTED_ANSWER_QUESTION);
|
|
|
|
+ //获取所有选项
|
|
|
|
+ List<TestFillAnswer> blanks = testQuestionInfo.getBlanks();
|
|
|
|
+ List<Question> subQuestions = initSubQuestions(blanks, wordMLPackage);
|
|
|
|
+ question.setSubQuestions(subQuestions);
|
|
|
|
+ }
|
|
|
|
+ //问答题 、 名词解释
|
|
|
|
+ if(testQuestionInfo.getQuestionType() == 60 || testQuestionInfo.getQuestionType() == 69){
|
|
|
|
+ String quesBody = testQuestionInfo.getQuestionHTML();
|
|
|
|
+ //去掉<span>标签中的lang
|
|
|
|
+ quesBody = replaceLang(quesBody);
|
|
|
|
+ //获取img标签
|
|
|
|
+ LinkedHashMap<String, String> bodyImgList = imgList(quesBody);
|
|
|
|
+ //替换、补全Img标签
|
|
|
|
+ quesBody = replaceImg(bodyImgList, quesBody);
|
|
|
|
+ question.setQuesBody("<p>"+quesBody+"</p>");
|
|
|
|
+ question.setQuesBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(question.getQuesBody())));
|
|
|
|
+ question.setQuestionType(QuesStructType.TEXT_ANSWER_QUESTION);
|
|
|
|
+ String answer = testQuestionInfo.getAnswer();
|
|
|
|
+ //去掉<span>标签中的lang
|
|
|
|
+ answer = replaceLang(answer);
|
|
|
|
+ //获取img标签
|
|
|
|
+ LinkedHashMap<String, String> answerImgList = imgList(answer);
|
|
|
|
+ //替换、补全Img标签
|
|
|
|
+ answer = replaceImg(answerImgList, answer);
|
|
|
|
+ question.setQuesAnswer("<p>"+answer+"</p>");
|
|
|
|
+ question.setQuesAnswerWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(question.getQuesAnswer())));
|
|
|
|
+ }
|
|
|
|
+ //单选题
|
|
|
|
+ if(testQuestionInfo.getQuestionType() == 11){
|
|
|
|
+ String quesBody = testQuestionInfo.getQuestionHTML();
|
|
|
|
+ //去掉<span>标签中的lang
|
|
|
|
+ quesBody = replaceLang(quesBody);
|
|
|
|
+ //获取img标签
|
|
|
|
+ LinkedHashMap<String, String> bodyImgList = imgList(quesBody);
|
|
|
|
+ //替换、补全Img标签
|
|
|
|
+ quesBody = replaceImg(bodyImgList, quesBody);
|
|
|
|
+ question.setQuesBody("<p>"+quesBody+"</p>");
|
|
|
|
+ question.setQuesBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(question.getQuesBody())));
|
|
|
|
+ question.setQuestionType(QuesStructType.SINGLE_ANSWER_QUESTION);
|
|
|
|
+ List<QuesOption> quesOptions = new ArrayList<QuesOption>();
|
|
|
|
+ List<TestOption> options = testQuestionInfo.getOptions();
|
|
|
|
+ Integer answerNumber = null;
|
|
|
|
+ if(options != null && options.size()>0){
|
|
|
|
+ int number = 1;
|
|
|
|
+ short isCorrect = 0;
|
|
|
|
+ for(TestOption testOption:options){
|
|
|
|
+ if(testOption.getID().equals(testQuestionInfo.getAnswerId())){
|
|
|
|
+ isCorrect = 1;
|
|
|
|
+ answerNumber = number;
|
|
|
|
+ }else {
|
|
|
|
+ isCorrect = 0;
|
|
|
|
+ }
|
|
|
|
+ QuesOption quesOption = initQuesOption(testOption, number, isCorrect, wordMLPackage);
|
|
|
|
+ quesOptions.add(quesOption);
|
|
|
|
+ number++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ question.setQuesOptions(quesOptions);
|
|
|
|
+ if(answerNumber != null){
|
|
|
|
+ char c1=(char) (answerNumber+64);
|
|
|
|
+ question.setQuesAnswer(String.valueOf(c1));
|
|
|
|
+ question.setQuesAnswerWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml("<p>"+question.getQuesAnswer()+"</p>")));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //多选题
|
|
|
|
+ if(testQuestionInfo.getQuestionType() == 12){
|
|
|
|
+ String quesBody = testQuestionInfo.getQuestionHTML();
|
|
|
|
+ //去掉<span>标签中的lang
|
|
|
|
+ quesBody = replaceLang(quesBody);
|
|
|
|
+ //获取img标签
|
|
|
|
+ LinkedHashMap<String, String> bodyImgList = imgList(quesBody);
|
|
|
|
+ //替换、补全Img标签
|
|
|
|
+ quesBody = replaceImg(bodyImgList, quesBody);
|
|
|
|
+ question.setQuesBody("<p>"+quesBody+"</p>");
|
|
|
|
+ question.setQuesBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(question.getQuesBody())));
|
|
|
|
+ question.setQuestionType(QuesStructType.MULTIPLE_ANSWER_QUESTION);
|
|
|
|
+ List<QuesOption> quesOptions = new ArrayList<QuesOption>();
|
|
|
|
+ List<TestOption> options = testQuestionInfo.getOptions();
|
|
|
|
+ List<Integer> answerNumbers = new ArrayList<Integer>();
|
|
|
|
+ if(options != null && options.size()>0){
|
|
|
|
+ int number = 1;
|
|
|
|
+ short isCorrect = 0;
|
|
|
|
+ for(TestOption testOption:options){
|
|
|
|
+ if(testQuestionInfo.getAnswers().contains(testOption.getID())){
|
|
|
|
+ isCorrect = 1;
|
|
|
|
+ answerNumbers.add(number);
|
|
|
|
+ }else {
|
|
|
|
+ isCorrect = 0;
|
|
|
|
+ }
|
|
|
|
+ QuesOption quesOption = initQuesOption(testOption, number, isCorrect, wordMLPackage);
|
|
|
|
+ quesOptions.add(quesOption);
|
|
|
|
+ number++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ question.setQuesOptions(quesOptions);
|
|
|
|
+ if(answerNumbers!=null && answerNumbers.size()>0){
|
|
|
|
+ String answers = "";
|
|
|
|
+ for(Integer number:answerNumbers){
|
|
|
|
+ char c1=(char) (number+64);
|
|
|
|
+ if(StringUtils.isBlank(answers)){
|
|
|
|
+ answers = String.valueOf(c1);
|
|
|
|
+ }else {
|
|
|
|
+ answers = answers +","+ String.valueOf(c1);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ question.setQuesAnswer(answers);
|
|
|
|
+ question.setQuesAnswerWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml("<p>"+question.getQuesAnswer()+"</p>")));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //填空题 ###
|
|
|
|
+ if(testQuestionInfo.getQuestionType() == 13){
|
|
|
|
+ String quesBody = testQuestionInfo.getQuestionHTML();
|
|
|
|
+ //去掉<span>标签中的lang
|
|
|
|
+ quesBody = replaceLang(quesBody);
|
|
|
|
+ //获取img标签
|
|
|
|
+ LinkedHashMap<String, String> imgList = imgList(quesBody);
|
|
|
|
+ if(imgList != null && imgList.size()>0){
|
|
|
|
+ for(Map.Entry<String, String> entry:imgList.entrySet()){
|
|
|
|
+ if(StringUtils.isBlank(entry.getValue())){
|
|
|
|
+ quesBody = quesBody.replace(entry.getKey(),"(###)");
|
|
|
|
+ }else {
|
|
|
|
+ quesBody = quesBody.replace(entry.getKey(),entry.getValue());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ question.setQuesBody("<p>"+quesBody+"</p>");
|
|
|
|
+ question.setQuesBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(question.getQuesBody())));
|
|
|
|
+ question.setQuestionType(QuesStructType.FILL_BLANK_QUESTION);
|
|
|
|
+ String answer = "";
|
|
|
|
+ List<TestFillAnswer> blanks = testQuestionInfo.getBlanks();
|
|
|
|
+ if(blanks != null && blanks.size()>0){
|
|
|
|
+ for(TestFillAnswer testFillAnswer:blanks){
|
|
|
|
+ List<TestFillContent> answers = testFillAnswer.getAnswers();
|
|
|
|
+ if(answers != null && answers.size()>0){
|
|
|
|
+ for(TestFillContent testFillContent:answers){
|
|
|
|
+ if(StringUtils.isBlank(answer)){
|
|
|
|
+ answer = testFillContent.getContent();
|
|
|
|
+ }else {
|
|
|
|
+ answer = answer + "##" + testFillContent.getContent();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //去掉<span>标签中的lang
|
|
|
|
+ answer = replaceLang(answer);
|
|
|
|
+ //获取img标签
|
|
|
|
+ LinkedHashMap<String, String> answerImgList = imgList(answer);
|
|
|
|
+ //替换、补全Img标签
|
|
|
|
+ answer = replaceImg(answerImgList, answer);
|
|
|
|
+ question.setQuesAnswer("<p>"+answer+"</p>");
|
|
|
|
+ question.setQuesAnswerWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(question.getQuesAnswer())));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //判断题
|
|
|
|
+ if(testQuestionInfo.getQuestionType() == 20){
|
|
|
|
+ String quesBody = testQuestionInfo.getQuestionHTML();
|
|
|
|
+ //去掉<span>标签中的lang
|
|
|
|
+ quesBody = replaceLang(quesBody);
|
|
|
|
+ //获取img标签
|
|
|
|
+ LinkedHashMap<String, String> bodyImgList = imgList(quesBody);
|
|
|
|
+ //替换、补全Img标签
|
|
|
|
+ quesBody = replaceImg(bodyImgList, quesBody);
|
|
|
|
+ question.setQuesBody("<p>"+quesBody+"</p>");
|
|
|
|
+ question.setQuesBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(question.getQuesBody())));
|
|
|
|
+ question.setQuestionType(QuesStructType.BOOL_ANSWER_QUESTION);
|
|
|
|
+ String answer = testQuestionInfo.getAnswer();
|
|
|
|
+ if(answer.equals("false")){
|
|
|
|
+ answer = "错误";
|
|
|
|
+ }else {
|
|
|
|
+ answer = "正确";
|
|
|
|
+ }
|
|
|
|
+ question.setQuesAnswer(answer);
|
|
|
|
+ question.setQuesAnswerWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml("<p>"+question.getQuesAnswer()+"</p>")));
|
|
|
|
+ }
|
|
|
|
+ byte [] pkgByte = DocxProcessUtil.getPkgByte(wordMLPackage);
|
|
|
|
+ QuestionPkgPath quesPkgPath = new QuestionPkgPath(pkgByte);
|
|
|
|
+ map.put(question, quesPkgPath);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 初始化选项
|
|
|
|
+ * @param testOption
|
|
|
|
+ * @param number
|
|
|
|
+ * @param isCorrect
|
|
|
|
+ * @param wordMLPackage
|
|
|
|
+ * @return
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
|
|
+ public QuesOption initQuesOption(TestOption testOption,int number,short isCorrect,WordprocessingMLPackage wordMLPackage) throws Exception{
|
|
|
|
+ QuesOption quesOption = new QuesOption();
|
|
|
|
+ quesOption.setNumber(String.valueOf(number));
|
|
|
|
+ quesOption.setIsCorrect(isCorrect);
|
|
|
|
+ String optionBody = testOption.getOptionHTML();
|
|
|
|
+ //去掉<span>标签中的lang
|
|
|
|
+ optionBody = replaceLang(optionBody);
|
|
|
|
+ //获取img标签
|
|
|
|
+ LinkedHashMap<String, String> optionBodyImgList = imgList(optionBody);
|
|
|
|
+ //替换、补全Img标签
|
|
|
|
+ optionBody = replaceImg(optionBodyImgList, optionBody);
|
|
|
|
+ quesOption.setOptionBody("<p>"+optionBody+"</p>");
|
|
|
|
+ quesOption.setOptionBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(quesOption.getOptionBody())));
|
|
|
|
+ return quesOption;
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 完形填空初始化所有子题
|
|
|
|
+ * @param blanks
|
|
|
|
+ * @param wordMLPackage
|
|
|
|
+ * @return
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
|
|
+ public List<Question> initSubQuestions(List<TestFillAnswer> blanks,WordprocessingMLPackage wordMLPackage) throws Exception{
|
|
|
|
+ List<Question> subQuestions = new ArrayList<Question>();
|
|
|
|
+ if(blanks!=null && blanks.size()>0){
|
|
|
|
+ //int number = 1;
|
|
|
|
+ for(TestFillAnswer testFillAnswer:blanks){
|
|
|
|
+ Question question = new Question();
|
|
|
|
+ question.setId(UUID.randomUUID().toString());
|
|
|
|
+ question.setQuestionType(QuesStructType.SINGLE_ANSWER_QUESTION);
|
|
|
|
+ question.setDifficulty("中");
|
|
|
|
+ question.setDifficultyDegree(0.5);
|
|
|
|
+ question.setPublicity(true);
|
|
|
|
+ question.setQuesBody("______");
|
|
|
|
+ question.setQuesBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml("<p>"+question.getQuesBody()+"</p>")));
|
|
|
|
+ TestOptionGroup optionGroup = testFillAnswer.getOptionGroup();
|
|
|
|
+ List<QuesOption> quesOptions = new ArrayList<QuesOption>();
|
|
|
|
+ List<TestOption> subOptions = optionGroup.getOptions();
|
|
|
|
+ Integer answerNumber = null;
|
|
|
|
+ if(subOptions!=null && subOptions.size()>0){
|
|
|
|
+ int subNumber = 1;
|
|
|
|
+ short isCorrect = 0;
|
|
|
|
+ for(TestOption subOption:subOptions){
|
|
|
|
+ if (testFillAnswer.getAnswerId().equals(subOption.getID())) {
|
|
|
|
+ isCorrect = 1;
|
|
|
|
+ answerNumber = subNumber;
|
|
|
|
+ }else {
|
|
|
|
+ isCorrect = 0;
|
|
|
|
+ }
|
|
|
|
+ QuesOption quesOption = initQuesOption(subOption,subNumber,isCorrect,wordMLPackage);
|
|
|
|
+ quesOptions.add(quesOption);
|
|
|
|
+ subNumber++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ question.setQuesOptions(quesOptions);
|
|
|
|
+ if(answerNumber != null){
|
|
|
|
+ char c1=(char) (answerNumber+64);
|
|
|
|
+ question.setQuesAnswer(String.valueOf(c1));
|
|
|
|
+ question.setQuesAnswerWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml("<p>"+question.getQuesAnswer()+"</p>")));
|
|
|
|
+ }
|
|
|
|
+ subQuestions.add(question);
|
|
|
|
+ //number++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return subQuestions;
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 初始化小题对象
|
|
|
|
+ * @param question
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public PaperDetailUnit initPaperDetailUnit(Paper paper,PaperDetail paperDetail,Question question,TestQuestion testQuestion){
|
|
|
|
+ PaperDetailUnit paperDetailUnit = new PaperDetailUnit();
|
|
|
|
+ paperDetailUnit.setPaper(paper);
|
|
|
|
+ paperDetailUnit.setNumber(testQuestion.getNumber());
|
|
|
|
+ paperDetailUnit.setScore(testQuestion.getScore());
|
|
|
|
+ paperDetailUnit.setPaperDetail(paperDetail);
|
|
|
|
+ paperDetailUnit.setQuestionType(question.getQuestionType());
|
|
|
|
+ paperDetailUnit.setCreator("wei");
|
|
|
|
+ paperDetailUnit.setCreateTime(CommonUtils.getCurDateTime());
|
|
|
|
+ paperDetailUnit.setQuestion(question);
|
|
|
|
+ return paperDetailUnit;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 将大题和小题分类
|
|
|
|
+ * @param questions
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public Map<Integer, List<TestQuestion>> sortPaperDetail(List<TestQuestion> questions){
|
|
|
|
+ if(questions != null && questions.size()>0){
|
|
|
|
+ Map<Integer, List<TestQuestion>> map = new HashMap<Integer, List<TestQuestion>>();
|
|
|
|
+ List<TestQuestion> sortQuestions = null;
|
|
|
|
+ for(TestQuestion testQuestion:questions){
|
|
|
|
+ if(map.get(testQuestion.getdNumber()) == null){
|
|
|
|
+ sortQuestions = new ArrayList<TestQuestion>();
|
|
|
|
+ sortQuestions.add(testQuestion);
|
|
|
|
+ }else {
|
|
|
|
+ sortQuestions = map.get(testQuestion.getdNumber());
|
|
|
|
+ sortQuestions.add(testQuestion);
|
|
|
|
+ }
|
|
|
|
+ map.put(testQuestion.getdNumber(), sortQuestions);
|
|
|
|
+ }
|
|
|
|
+ return map;
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 去除图片中有下划线的图片,并补全图片下载地址
|
|
|
|
+ * @param str
|
|
|
|
+ * @return
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
|
|
+ public LinkedHashMap<String, String> imgList(String str) throws Exception{
|
|
|
|
+ LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
|
|
|
|
+ //获取img标签
|
|
|
|
+ List<String> srcList = ImgDataUtils.parseImages(str);
|
|
|
|
+ if(srcList!=null && srcList.size()>0){
|
|
|
|
+ for (String img : srcList) {
|
|
|
|
+ if(img.contains("/Shared/UnderLine")){
|
|
|
|
+ map.put(img, "");
|
|
|
|
+ }else {
|
|
|
|
+ List<String> parseImageSrc = ImgDataUtils.parseImageSrc(img);
|
|
|
|
+ if(parseImageSrc!=null && parseImageSrc.size()>0){
|
|
|
|
+ String src = parseImageSrc.get(0);
|
|
|
|
+ String url = regexCH(src);
|
|
|
|
+ String picture = "http://ncexam.cug.edu.cn"+url;
|
|
|
|
+ String base64 = ImgDataUtils.loadImageToBase64(picture);
|
|
|
|
+ if(base64 == null){
|
|
|
|
+ throw new Exception("图片下载失败" + picture);
|
|
|
|
+ }else {
|
|
|
|
+ if(src.contains("jpg")){
|
|
|
|
+ map.put(img, img.replace(src, "data:image/jpg;base64,"+base64));
|
|
|
|
+ }else {
|
|
|
|
+ map.put(img, img.replace(src, "data:image/png;base64,"+base64));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return map;
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 去除<span>标签中lang=EN-US
|
|
|
|
+ * @param str
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public String replaceLang(String str){
|
|
|
|
+ if(str.contains("lang=EN-US")){
|
|
|
|
+ str = str.replace("lang=EN-US", "");
|
|
|
|
+ }
|
|
|
|
+ return str;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 替换img标签,补全图片
|
|
|
|
+ * @param imgList
|
|
|
|
+ * @param str
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public String replaceImg(LinkedHashMap<String, String> imgList,String str){
|
|
|
|
+ if(imgList != null && imgList.size()>0){
|
|
|
|
+ for(Map.Entry<String, String> entry:imgList.entrySet()){
|
|
|
|
+ if(StringUtils.isBlank(entry.getValue())){
|
|
|
|
+ str = str.replace(entry.getKey(),"___");
|
|
|
|
+ }else {
|
|
|
|
+ str = str.replace(entry.getKey(),entry.getValue());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return str;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 將url路徑中的中文转码
|
|
|
|
+ * @param str
|
|
|
|
+ * @return
|
|
|
|
+ * @throws UnsupportedEncodingException
|
|
|
|
+ */
|
|
|
|
+ public String regexCH(String str) throws UnsupportedEncodingException{
|
|
|
|
+ StringBuffer s = new StringBuffer();
|
|
|
|
+ Pattern pat = Pattern.compile("[\u4E00-\u9FA5]");
|
|
|
|
+ Matcher mat = pat.matcher(str);
|
|
|
|
+ while(mat.find()) {
|
|
|
|
+ s.append(mat.group());
|
|
|
|
+ }
|
|
|
|
+ String url = java.net.URLEncoder.encode(s.toString(), "utf-8");
|
|
|
|
+ return str.replace(s.toString(), url);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static void main(String[] args) throws UnsupportedEncodingException{
|
|
|
|
+ String ssString = "/UploadFiles/刘昌辉/Images/OnlineExam20140923161629.jpg";
|
|
|
|
+ //String ss = regexCH(ssString);
|
|
|
|
+ //System.out.println(ss);
|
|
|
|
+ }
|
|
|
|
+}
|