|
@@ -0,0 +1,228 @@
|
|
|
+import cn.com.qmth.stmms.ms.Application;
|
|
|
+import cn.com.qmth.stmms.ms.commons.config.SystemConfig;
|
|
|
+import cn.com.qmth.stmms.ms.commons.utils.RandomUtil;
|
|
|
+import cn.com.qmth.stmms.ms.core.domain.ExamQuestion;
|
|
|
+import cn.com.qmth.stmms.ms.core.domain.Paper;
|
|
|
+import cn.com.qmth.stmms.ms.core.domain.Student;
|
|
|
+import cn.com.qmth.stmms.ms.core.domain.Work;
|
|
|
+import cn.com.qmth.stmms.ms.core.domain.enums.TrialEnum;
|
|
|
+import cn.com.qmth.stmms.ms.core.repository.ExamQuestionRepo;
|
|
|
+import cn.com.qmth.stmms.ms.core.repository.PaperRepo;
|
|
|
+import cn.com.qmth.stmms.ms.core.repository.StudentRepo;
|
|
|
+import cn.com.qmth.stmms.ms.core.repository.WorkRepo;
|
|
|
+import cn.com.qmth.stmms.ms.core.vo.Subject;
|
|
|
+import net.coobird.thumbnailator.Thumbnails;
|
|
|
+import org.junit.Test;
|
|
|
+import org.junit.runner.RunWith;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
|
+import org.springframework.test.context.junit4.SpringRunner;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Random;
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
+import java.util.concurrent.Executors;
|
|
|
+
|
|
|
+@RunWith(SpringRunner.class)
|
|
|
+@SpringBootTest(classes = {Application.class})
|
|
|
+// 指定启动类
|
|
|
+public class SxTest {
|
|
|
+
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(SxTest.class);
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamQuestionRepo examQuestionRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private StudentRepo studentRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PaperRepo paperRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private WorkRepo workRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ RandomUtil randomUtil;
|
|
|
+
|
|
|
+ //考生数量
|
|
|
+ private int initNumber = 40000;
|
|
|
+ private static int COUNT = 20000;
|
|
|
+ private static Long WORK_ID = 1000l;
|
|
|
+ private String baseDir = "D:\\my_workspaces\\ide_workspace_qmth\\idea_workspace\\stmms-ms-server\\upload";
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void createSxTask() throws Exception {
|
|
|
+ //默认用id为1000的工作
|
|
|
+ Work work = workRepo.findOne(WORK_ID);
|
|
|
+ if (work == null) {
|
|
|
+ logger.info("指定id为1000的工作不存在");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //生成exam_question信息
|
|
|
+ List<ExamQuestion> questions = createQuestions();
|
|
|
+// examQuestionRepo.save(questions);
|
|
|
+ logger.info("questions新增:{}", questions.size());
|
|
|
+
|
|
|
+ //生成student信息
|
|
|
+ List<Student> students = createStudent();
|
|
|
+// studentRepo.save(students);
|
|
|
+ logger.info("students新增:{}", students.size());
|
|
|
+
|
|
|
+ //生成paper信息
|
|
|
+// List<Paper> papers = createPaper(students);
|
|
|
+// paperRepo.save(papers);
|
|
|
+// logger.info("papers新增:{}", papers.size());
|
|
|
+
|
|
|
+ //生成image
|
|
|
+// createImage(students);
|
|
|
+ logger.info("image成功");
|
|
|
+
|
|
|
+ //生成sheet
|
|
|
+// createSheet(students);
|
|
|
+ logger.info("sheet成功");
|
|
|
+
|
|
|
+ //生成thumb
|
|
|
+ createThumb(students);
|
|
|
+ logger.info("thumb成功");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<ExamQuestion> createQuestions() {
|
|
|
+ List<ExamQuestion> questions = new ArrayList<>();
|
|
|
+ ExamQuestion examQuestion1 = new ExamQuestion();
|
|
|
+ examQuestion1.setId(1l);
|
|
|
+ examQuestion1.setAreaCode("1");
|
|
|
+ examQuestion1.setAreaName("省艺术培训协会");
|
|
|
+ examQuestion1.setName("速写1");
|
|
|
+ examQuestion1.setSubject(Subject.SX);
|
|
|
+ examQuestion1.setWorkId(WORK_ID);
|
|
|
+ examQuestion1.setTest(0);
|
|
|
+ questions.add(examQuestion1);
|
|
|
+
|
|
|
+ ExamQuestion examQuestion2 = new ExamQuestion();
|
|
|
+ examQuestion2.setId(2l);
|
|
|
+ examQuestion2.setAreaCode("1");
|
|
|
+ examQuestion2.setAreaName("省艺术培训协会");
|
|
|
+ examQuestion2.setName("色彩1");
|
|
|
+ examQuestion2.setSubject(Subject.SC);
|
|
|
+ examQuestion2.setWorkId(WORK_ID);
|
|
|
+ examQuestion2.setTest(0);
|
|
|
+ questions.add(examQuestion2);
|
|
|
+
|
|
|
+ ExamQuestion examQuestion3 = new ExamQuestion();
|
|
|
+ examQuestion3.setId(3l);
|
|
|
+ examQuestion3.setAreaCode("1");
|
|
|
+ examQuestion3.setAreaName("省艺术培训协会");
|
|
|
+ examQuestion3.setName("素描1");
|
|
|
+ examQuestion3.setSubject(Subject.SM);
|
|
|
+ examQuestion3.setWorkId(WORK_ID);
|
|
|
+ examQuestion3.setTest(0);
|
|
|
+ questions.add(examQuestion3);
|
|
|
+
|
|
|
+ return questions;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Student> createStudent() {
|
|
|
+ List<Student> students = new ArrayList<>();
|
|
|
+ for (int i = 0; i < COUNT; i++) {
|
|
|
+ Student student = new Student();
|
|
|
+ student.setAreaCode("1");
|
|
|
+ student.setAreaName("省艺术培训协会");
|
|
|
+ student.setExamNumber(String.valueOf(initNumber + i));
|
|
|
+ student.setExamRoom("第一考场");
|
|
|
+ student.setSchool("湖北美术学院");
|
|
|
+ student.setAbsent(false);
|
|
|
+ student.setName("考生" + i);
|
|
|
+ student.setUploadStatus("SX:1,SC:0,SM:0");
|
|
|
+ student.setWorkId(WORK_ID);
|
|
|
+ student.setSourceName("湖北");
|
|
|
+ student.setTest("0");
|
|
|
+ student.setRelateExamNumber(student.getExamNumber());
|
|
|
+ students.add(student);
|
|
|
+ }
|
|
|
+ return students;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Paper> createPaper(List<Student> students) throws Exception {
|
|
|
+ List<Paper> papers = new ArrayList<>();
|
|
|
+ ExamQuestion examQuestion = examQuestionRepo.findByWorkIdAndSubjectAndAreaCodeAndTest(WORK_ID, Subject.SX, "1", TrialEnum.DEFAULT.getId());
|
|
|
+ for (Student student : students) {
|
|
|
+ Long random = getRandom(student.getWorkId(), student.getExamNumber());
|
|
|
+ Paper paper = new Paper(student.getWorkId(), null, Subject.SX, examQuestion, student, false, random);
|
|
|
+ papers.add(paper);
|
|
|
+ }
|
|
|
+ return papers;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void createImage(List<Student> students) throws IOException {
|
|
|
+ String imageDir = baseDir + File.separator + "images" + File.separator + WORK_ID + File.separator + Subject.SX.name() + File.separator + "1";
|
|
|
+ File out = new File(imageDir);
|
|
|
+ if (!out.exists()) {
|
|
|
+ out.mkdirs();
|
|
|
+ }
|
|
|
+ File in = new File(imageDir, "sx.jpg");
|
|
|
+ for (Student student : students) {
|
|
|
+ Thumbnails.of(in).scale(1f).toFile(new File(imageDir, student.getExamNumber() + ".jpg"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void createSheet(List<Student> students) throws IOException {
|
|
|
+ String sheetDir = baseDir + File.separator + "sheet" + File.separator + WORK_ID + File.separator + Subject.SX.name() + File.separator + "1";
|
|
|
+ File out = new File(sheetDir);
|
|
|
+ if (!out.exists()) {
|
|
|
+ out.mkdirs();
|
|
|
+ }
|
|
|
+ File in = new File(sheetDir, "sx.jpg");
|
|
|
+ for (Student student : students) {
|
|
|
+ Thumbnails.of(in).scale(1f).toFile(new File(sheetDir, student.getExamNumber() + ".jpg"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void createThumb(List<Student> students) throws IOException {
|
|
|
+ String thumbDir = baseDir + File.separator + "thumbs" + File.separator + WORK_ID + File.separator + Subject.SX.name() + File.separator + "1";
|
|
|
+ File out = new File(thumbDir);
|
|
|
+ if (!out.exists()) {
|
|
|
+ out.mkdirs();
|
|
|
+ }
|
|
|
+ File in = new File(thumbDir, "sx.jpg");
|
|
|
+ for (Student student : students) {
|
|
|
+ Thumbnails.of(in).scale(1f).toFile(new File(thumbDir, student.getExamNumber() + ".jpg"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取随机号
|
|
|
+ *
|
|
|
+ * @param workId
|
|
|
+ * @param examNumber
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public Long getRandom(Long workId, String examNumber) throws Exception {
|
|
|
+ int count = 0, result = 0;
|
|
|
+ Long random = 0L;
|
|
|
+ while (true) {
|
|
|
+ random = randomUtil.getRandomMap().get(workId).get(new Random().nextInt(randomUtil.getRandomMap().get(workId).size()));
|
|
|
+// random = RandomUtil.randomList.get(new Random().nextInt(RandomUtil.randomList.size()));
|
|
|
+ result = paperRepo.countByWorkIdAndExamNumberAndRandomSeq(workId, examNumber, random);
|
|
|
+ if (result == 0 && random != Long.parseLong(examNumber.substring(3, examNumber.length()))) {
|
|
|
+ break;
|
|
|
+ } else {
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ if (count > 1000) {
|
|
|
+// throw new Exception("重复几率较高,建议重新生成随机号");
|
|
|
+ randomUtil.getRandom(workId, true);
|
|
|
+ getRandom(workId, examNumber);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return random;
|
|
|
+ }
|
|
|
+}
|