//package com.qmth.jkserver.service;
//
//import com.alibaba.fastjson.JSON;
//import com.qmth.jkserver.dto.QueryResultDto;
//import com.qmth.jkserver.dto.examProgress.ExamProgressDto;
//import com.qmth.jkserver.enums.ExamConditionEnum;
//import com.qmth.jkserver.enums.ExamFinishStatusEnum;
//import com.qmth.jkserver.enums.RegistrationStatusEnum;
//import com.qmth.jkserver.model.*;
//import org.junit.Test;
//import org.junit.runner.RunWith;
//import org.springframework.boot.test.context.SpringBootTest;
//import org.springframework.data.domain.Page;
//import org.springframework.data.mongodb.core.MongoOperations;
//import org.springframework.data.mongodb.core.query.Criteria;
//import org.springframework.data.mongodb.core.query.Query;
//import org.springframework.test.context.junit4.SpringRunner;
//
//import javax.annotation.Resource;
//import java.util.List;
//import java.util.Set;
//import java.util.stream.Collectors;
//
///**
// * @Description: 数据中心接口获取数据测试类
// * @Author: CaoZixuan
// * @Date: 2021-05-12
// */
//@SpringBootTest
//@RunWith(SpringRunner.class)
//public class DateCenterApiTest {
//    @Resource
//    private ExamPlanService examPlanService;
//    @Resource
//    private ExamPaperTempService examPaperTempService;
//    @Resource
//    private ExamStudentAnswerService examStudentAnswerService;
//    @Resource
//    private MongoOperations mongoTemplate;
//    @Resource
//    private ExamProgressStatisticService examProgressStatisticService;
//
//    private static final String examCode = "qSsI";
//
//    // 清除学生作答记录同步记录
//    @Test
//    public void updateExamStudentAnswer() {
//        List<ExamStudentAnswer> examStudentAnswerList = examStudentAnswerService.findByExamCode(examCode);
//        for (ExamStudentAnswer examStudentAnswer : examStudentAnswerList) {
//            examStudentAnswer.setTaskSyncResult(false);
//            examStudentAnswer.setExamTask(null);
//            mongoTemplate.save(examStudentAnswer);
//        }
//    }
//
//    // 清除试卷同步记录
//    @Test
//    public void updateSubject() {
//        List<ExamPaperTemp> examPaperTempList = examPaperTempService.findExamCourseAllByTask(examCode);
//        for (ExamPaperTemp examPaperTemp : examPaperTempList) {
//            examPaperTemp.setTaskSyncResult(false);
//            examPaperTemp.setExamTask(null);
//            mongoTemplate.save(examPaperTemp);
//        }
//    }
//
//    // 清除考试计划同步记录
//    @Test
//    public void updateExamPlan() {
//        List<ExamPlan> examPlanList = examPlanService.findExamPlanAllByTask();
//        ExamPlan examPlan = examPlanList.stream().filter(e -> e.getExamCode().equals(examCode)).collect(Collectors.toList()).get(0);
//        examPlan.setExamTask(null);
//        mongoTemplate.save(examPlan);
//    }
//
//    // 清除任务记录
//    @Test
//    public void updateTask(){
//        Query query = new Query();
//        query.addCriteria(Criteria.where("examCode").is(examCode));
//
//        List<ExamTask> examTaskList = mongoTemplate.find(query,ExamTask.class);
//        mongoTemplate.remove(examTaskList);
//    }
//
//    @Test
//    public void searchTest(){
//        String examCode = "nY5R";
//        Query query = new Query();
//        query.addCriteria(Criteria.where("examCode").is(examCode));
//        List<ExamStudent> examStudentList = mongoTemplate.find(query, ExamStudent.class);
//
//
//        System.out.println(JSON.toJSONString(examStudentList));
//    }
//
//    @Test
//    public void changeExamStudent() {
//        String examCode = "KcrP";
//        Query query = new Query();
//        query.addCriteria(Criteria.where("examCode").is(examCode));
//        List<ExamStudent> examStudentList = mongoTemplate.find(query, ExamStudent.class);
//        for (ExamStudent examStudent : examStudentList) {
//            // 重置考生检录、完成考试状态
//            examStudent.setRegistrationStatus(null);
//            examStudent.setExamFinishStatus(null);
//            // 9/10 的概率检录
//            if (randomByTen(9)) {
//                // 9/10 的概率通过检录 1/10 的概率不通过
//                examStudent.setRegistrationStatus(randomByTen(9));
//            }
////            if (examStudent.getRegistrationStatus() != null && examStudent.getRegistrationStatus()) {
////                // 如果检录通过了 8/10的概率完成考试
////                if (randomByTen(8)) {
////                    examStudent.setExamFinishStatus(ExamFinishStatusEnum.FINISHED);
////                } else {
////                    examStudent.setExamFinishStatus(ExamFinishStatusEnum.UN_FINISHED);
////                }
////            }
//            mongoTemplate.save(examStudent);
//        }
//    }
//
//    private boolean randomByTen(int times){
//        int x = (int) (Math.random() * 10);
//        System.out.println(x);
//        return x < times;
//    }
//
//
//    @Test
//    public void testStatistic(){
//        String examPlanId = "618cfa9e3fe66d79486b3f88";
//        System.out.println(JSON.toJSONString(examProgressStatisticService.findExamProgressStatisticByExamCode(examPlanId)));
//    }
//
//    @Test
//    public void findExamProgressPage(){
//        String examCode = "nY5R";
//        String batchId = null;
//        String stageId = null;
//        String placeCode = null;
//        String roomCode = null;
//        String courseCode = "0002";
//        RegistrationStatusEnum registrationStatus = null;
//        String examStudentParams = null;
//        ExamFinishStatusEnum examFinishStatus = ExamFinishStatusEnum.UN_FINISHED;
//        int pageNumber = 1;
//        int pageSize = 10;
//        Page<ExamProgressDto> examProgressDtoPage = examProgressStatisticService.findExamProgressPage(examCode,batchId,stageId,placeCode,roomCode,courseCode,registrationStatus,examFinishStatus,examStudentParams,pageNumber,pageSize);
//        System.out.println(JSON.toJSONString(examProgressDtoPage));
//    }
//
//    @Test
//    public void findCourseCode(){
//        String examCode = "nY5R";
//        String batchId = null;
//        String stageId = null;
//        String placeCode = null;
//        String roomCode = null;
//        ExamConditionEnum examConditionEnum = ExamConditionEnum.EXAM_STAGE;
//        List<QueryResultDto> queryResultDtoSet = examProgressStatisticService.findExamConditionCascade(examCode,batchId,stageId,placeCode,roomCode,examConditionEnum);
//        System.out.println(JSON.toJSONString(queryResultDtoSet));
//    }
//
////    // 清除考试任务数据
////    @Test
////    public void createExamPlan(){
////        ExamPlan examPlan = new ExamPlan();
////        examPlan.setExamCode(examCode);
////        examPlan.setExamType(ExamType.NORMAL);
////        examPlan.setExamStatus(ExamStatus.PUBLISHED);
////        examPlan.setEnable(true);
////        examPlan.setCreateTime(new Date());
////        examPlan.setStartTime(new Date());
////        mongoTemplate.save(examPlan);
////    }
//
////    // 获取考生作答信息
////    @Test
////    public void getStudentAnswerJson() throws Exception {
////        FileDto fileDto = examPaperTempService.getExamStudentAnswerJsonFile(examCode);
////        List<File> fileList = fileDto.getFileList();
////        List<String> deletePaths = fileDto.getDeletePaths();
////        for (File file : fileList) {
////            System.out.println("---------------------------考生得到的文件路径-------------------------");
////            System.out.println(file.getPath());
////        }
////        for (String deletePath : deletePaths) {
////            System.out.println("-------------------------要删除的文件路径----------------------");
////            System.out.println(deletePath);
////            File dirFile = new File(deletePath);
////            if (dirFile.exists()){
////                SystemConstant.deleteFolder(dirFile);
////            }
////        }
////
////    }
////
////    @Test
////    public void getPaperJson() throws Exception {
////        FileDto fileDto = examPaperTempService.getPaperAnswerJsonFile(examCode);
////        List<File> fileList = fileDto.getFileList();
////        List<String> deletePaths = fileDto.getDeletePaths();
////        for (File file : fileList) {
////            System.out.println("---------------------------试卷得到的文件路径-------------------------");
////            System.out.println(file.getPath());
////        }
////        for (String deletePath : deletePaths) {
////            System.out.println("-------------------------要删除的试卷文件路径----------------------");
////            System.out.println(deletePath);
////            File dirFile = new File(deletePath);
////            if (dirFile.exists()){
////                SystemConstant.deleteFolder(dirFile);
////            }
////        }
////    }
////
////    @Test
////    public void createFiles() throws Exception {
////        FileDto fileDtoAnswer = examPaperTempService.getExamStudentAnswerJsonFile(examCode);
////
////        FileDto fileDtoPaper = examPaperTempService.getPaperAnswerJsonFile(examCode);
////        System.out.println("-------------------------------------");
////        System.out.println("student: " + fileDtoAnswer.getFileList().get(0).getPath());
////
////        for (File file : fileDtoPaper.getFileList()) {
////            System.out.println("paper: " + file.getPath());
////        }
////
////    }
//}
