|
@@ -1,28 +1,46 @@
|
|
package com.qmth.cqb;
|
|
package com.qmth.cqb;
|
|
|
|
|
|
|
|
+import java.io.BufferedReader;
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.FileNotFoundException;
|
|
|
|
+import java.io.FileReader;
|
|
|
|
+import java.io.FileWriter;
|
|
|
|
+import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
import org.junit.runner.RunWith;
|
|
import org.junit.runner.RunWith;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
|
+import org.springframework.data.domain.Example;
|
|
|
|
+import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
|
+import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
|
+import org.springframework.data.mongodb.core.query.Query;
|
|
import org.springframework.mock.web.MockHttpServletRequest;
|
|
import org.springframework.mock.web.MockHttpServletRequest;
|
|
import org.springframework.mock.web.MockHttpServletResponse;
|
|
import org.springframework.mock.web.MockHttpServletResponse;
|
|
import org.springframework.test.context.junit4.SpringRunner;
|
|
import org.springframework.test.context.junit4.SpringRunner;
|
|
|
|
|
|
import cn.com.qmth.examcloud.common.dto.question.QuestionDto;
|
|
import cn.com.qmth.examcloud.common.dto.question.QuestionDto;
|
|
|
|
|
|
|
|
+import com.qmth.cqb.paper.dao.ExportServiceManageRepo;
|
|
import com.qmth.cqb.paper.dao.PaperRepo;
|
|
import com.qmth.cqb.paper.dao.PaperRepo;
|
|
import com.qmth.cqb.paper.model.ExamFile;
|
|
import com.qmth.cqb.paper.model.ExamFile;
|
|
import com.qmth.cqb.paper.model.ExamPaper;
|
|
import com.qmth.cqb.paper.model.ExamPaper;
|
|
|
|
+import com.qmth.cqb.paper.model.ExportServiceManage;
|
|
import com.qmth.cqb.paper.model.Paper;
|
|
import com.qmth.cqb.paper.model.Paper;
|
|
import com.qmth.cqb.paper.service.ExamFileService;
|
|
import com.qmth.cqb.paper.service.ExamFileService;
|
|
import com.qmth.cqb.paper.service.ExtractConfigService;
|
|
import com.qmth.cqb.paper.service.ExtractConfigService;
|
|
|
|
+import com.qmth.cqb.paper.service.PaperService;
|
|
|
|
+import com.qmth.cqb.paper.service.export.ExportPaperAbstractService;
|
|
|
|
+import com.qmth.cqb.paper.service.export.SddxExportPaperService;
|
|
import com.qmth.cqb.paper.service.export.SxsfExportPaperService;
|
|
import com.qmth.cqb.paper.service.export.SxsfExportPaperService;
|
|
|
|
+import com.qmth.cqb.utils.SpringContextUtils;
|
|
import com.qmth.cqb.utils.enums.ExamFileType;
|
|
import com.qmth.cqb.utils.enums.ExamFileType;
|
|
|
|
+import com.qmth.cqb.utils.enums.PaperType;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @author chenken
|
|
* @author chenken
|
|
@@ -43,10 +61,75 @@ public class ExtractConfigServiceTest {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private ExamFileService examFileService;
|
|
private ExamFileService examFileService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ExportServiceManageRepo exportServiceManageRepo;
|
|
|
|
+ @Autowired
|
|
|
|
+ private SddxExportPaperService sddxExportPaperService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private MongoTemplate mongoTemplate;
|
|
|
|
|
|
private MockHttpServletRequest request;
|
|
private MockHttpServletRequest request;
|
|
private MockHttpServletResponse response;
|
|
private MockHttpServletResponse response;
|
|
|
|
|
|
|
|
+ @Test
|
|
|
|
+ public void downloadPaper() throws Exception{
|
|
|
|
+ Query query = new Query();
|
|
|
|
+ query.addCriteria(Criteria.where("orgId").is(135+""));
|
|
|
|
+ query.addCriteria(Criteria.where("paperType").is(PaperType.GENERATE.name()));
|
|
|
|
+ List<Paper> paperList = this.mongoTemplate.find(query, Paper.class);
|
|
|
|
+ for(Paper paper:paperList){
|
|
|
|
+ try {
|
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
|
+ List<String> paperIds = readFromFile();
|
|
|
|
+ for(String paperId:paperIds){
|
|
|
|
+ sb.append(paperId);
|
|
|
|
+ sb.append("\r\n");
|
|
|
|
+ }
|
|
|
|
+ if(!paperIds.contains(paper.getId())){
|
|
|
|
+ System.out.println("当前正在导出ID:"+paper.getId());
|
|
|
|
+ sddxExportPaperService.downloadPaper(paper.getId(), "shandong");
|
|
|
|
+ writeToFile(sb.toString()+"\r\n"+paper.getId());
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * DOC 从文件里读内容.
|
|
|
|
+ *
|
|
|
|
+ * @throws IOException
|
|
|
|
+ */
|
|
|
|
+ private static List<String> readFromFile() throws IOException {
|
|
|
|
+ BufferedReader bReader = new BufferedReader(new FileReader("E:\\paperIds.txt"));
|
|
|
|
+ List<String> paperIds = new ArrayList<String>();
|
|
|
|
+ String temp = "";
|
|
|
|
+ while((temp=bReader.readLine())!=null) {
|
|
|
|
+ if(StringUtils.isNotBlank(temp)){
|
|
|
|
+ paperIds.add(temp);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ bReader.close();
|
|
|
|
+ return paperIds;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * DOC 往文件里写入数据.
|
|
|
|
+ *
|
|
|
|
+ * @throws IOException
|
|
|
|
+ */
|
|
|
|
+ private static void writeToFile(String writerContent) throws IOException {
|
|
|
|
+ File file = new File("E:\\paperIds.txt");// 要写入的文本文件
|
|
|
|
+ if (!file.exists()) {// 如果文件不存在,则创建该文件
|
|
|
|
+ file.createNewFile();
|
|
|
|
+ }
|
|
|
|
+ FileWriter writer = new FileWriter(file);// 获取该文件的输出流
|
|
|
|
+ writer.write(writerContent);// 写内容
|
|
|
|
+ writer.flush();// 清空缓冲区,立即将输出流里的内容写到文件里
|
|
|
|
+ writer.close();// 关闭输出流,施放资源
|
|
|
|
+ }
|
|
|
|
+
|
|
@Test
|
|
@Test
|
|
public void test1() throws Exception{
|
|
public void test1() throws Exception{
|
|
ExamFile examFile = new ExamFile();
|
|
ExamFile examFile = new ExamFile();
|