|
@@ -15,6 +15,8 @@ import org.apache.poi.ss.usermodel.Row;
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
import org.springframework.data.mongodb.core.query.Criteria;
|
|
import org.springframework.data.mongodb.core.query.Criteria;
|
|
@@ -28,6 +30,7 @@ import java.util.*;
|
|
|
|
|
|
@Service("ddExcelService")
|
|
@Service("ddExcelService")
|
|
public class DdExcelService {
|
|
public class DdExcelService {
|
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(DdExcelService.class);
|
|
private final String exportExcelPath = "D:/exportExcel.xlsx";
|
|
private final String exportExcelPath = "D:/exportExcel.xlsx";
|
|
private final String xianExcelPath = "D:/xianExcelNew.xlsx";
|
|
private final String xianExcelPath = "D:/xianExcelNew.xlsx";
|
|
private final String paperExcelPath = "D:/paperExcel.xlsx";
|
|
private final String paperExcelPath = "D:/paperExcel.xlsx";
|
|
@@ -59,7 +62,7 @@ public class DdExcelService {
|
|
//List<Course> courses = courseRepo.findByOrgId(orgId);
|
|
//List<Course> courses = courseRepo.findByOrgId(orgId);
|
|
List<Course> courses = new ArrayList<Course>();
|
|
List<Course> courses = new ArrayList<Course>();
|
|
long endCourseTime = System.currentTimeMillis();
|
|
long endCourseTime = System.currentTimeMillis();
|
|
- System.out.println("查询课程耗时:" + (endCourseTime - startCourseTime) + "ms");
|
|
|
|
|
|
+ log.debug("查询课程耗时:" + (endCourseTime - startCourseTime) + "ms");
|
|
if (courses != null && courses.size() > 0) {
|
|
if (courses != null && courses.size() > 0) {
|
|
int i = 1;
|
|
int i = 1;
|
|
int j = 1;
|
|
int j = 1;
|
|
@@ -68,7 +71,7 @@ public class DdExcelService {
|
|
long startPaperTime = System.currentTimeMillis();
|
|
long startPaperTime = System.currentTimeMillis();
|
|
List<Paper> papers = paperRepo.findByCourseNoAndOrgId(course.getCode(), orgId);
|
|
List<Paper> papers = paperRepo.findByCourseNoAndOrgId(course.getCode(), orgId);
|
|
long endPaperTime = System.currentTimeMillis();
|
|
long endPaperTime = System.currentTimeMillis();
|
|
- System.out.println("查询第" + i + "个课程下所有试卷耗时耗时:" + (endPaperTime - startPaperTime) + "ms,课程代码为:" + course.getCode());
|
|
|
|
|
|
+ log.debug("查询第" + i + "个课程下所有试卷耗时耗时:" + (endPaperTime - startPaperTime) + "ms,课程代码为:" + course.getCode());
|
|
if (papers != null && papers.size() > 0) {
|
|
if (papers != null && papers.size() > 0) {
|
|
//生成所有试卷的试题集合
|
|
//生成所有试卷的试题集合
|
|
List<PaperDetailUnit> allUnits = new ArrayList<>();
|
|
List<PaperDetailUnit> allUnits = new ArrayList<>();
|
|
@@ -77,14 +80,14 @@ public class DdExcelService {
|
|
long startUnitTime = System.currentTimeMillis();
|
|
long startUnitTime = System.currentTimeMillis();
|
|
List<PaperDetailUnit> paperDetailUnits = paperDetailUnitRepo.findByPaper(paper);
|
|
List<PaperDetailUnit> paperDetailUnits = paperDetailUnitRepo.findByPaper(paper);
|
|
long endUnitTime = System.currentTimeMillis();
|
|
long endUnitTime = System.currentTimeMillis();
|
|
- System.out.println("查询" + paper.getName() + "个试卷下所有试题耗时耗时:" + (endUnitTime - startUnitTime) + "ms");
|
|
|
|
|
|
+ log.debug("查询" + paper.getName() + "个试卷下所有试题耗时耗时:" + (endUnitTime - startUnitTime) + "ms");
|
|
if (paperDetailUnits != null && paperDetailUnits.size() > 0) {
|
|
if (paperDetailUnits != null && paperDetailUnits.size() > 0) {
|
|
for (PaperDetailUnit unit : paperDetailUnits) {
|
|
for (PaperDetailUnit unit : paperDetailUnits) {
|
|
allUnits.add(unit);
|
|
allUnits.add(unit);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- System.out.println("开始生成对象...总题数量:" + allUnits.size());
|
|
|
|
|
|
+ log.debug("开始生成对象...总题数量:" + allUnits.size());
|
|
//生成需要保存的大题来源集合
|
|
//生成需要保存的大题来源集合
|
|
List<QuesTypeName> quesTypeNames = new ArrayList<>();
|
|
List<QuesTypeName> quesTypeNames = new ArrayList<>();
|
|
Map<QuesStructType, List<String>> map = buildQuesTypeName(allUnits);
|
|
Map<QuesStructType, List<String>> map = buildQuesTypeName(allUnits);
|
|
@@ -95,18 +98,18 @@ public class DdExcelService {
|
|
quesTypeName.setQuestionType(entry.getKey());
|
|
quesTypeName.setQuestionType(entry.getKey());
|
|
quesTypeName.setQuesNames(entry.getValue());
|
|
quesTypeName.setQuesNames(entry.getValue());
|
|
quesTypeNames.add(quesTypeName);
|
|
quesTypeNames.add(quesTypeName);
|
|
- System.out.println("生成完第" + j + "个对象");
|
|
|
|
|
|
+ log.debug("生成完第" + j + "个对象");
|
|
j++;
|
|
j++;
|
|
}
|
|
}
|
|
long endTime = System.currentTimeMillis();
|
|
long endTime = System.currentTimeMillis();
|
|
- System.out.println("所有试题耗时耗时:" + (endTime - endPaperTime) + "ms");
|
|
|
|
|
|
+ log.debug("所有试题耗时耗时:" + (endTime - endPaperTime) + "ms");
|
|
quesTypeRepo.saveAll(quesTypeNames);
|
|
quesTypeRepo.saveAll(quesTypeNames);
|
|
long ends = System.currentTimeMillis();
|
|
long ends = System.currentTimeMillis();
|
|
- System.out.println("第" + i + "个课程保存所有来源大题耗时:" + (ends - endTime) + "ms");
|
|
|
|
|
|
+ log.debug("第" + i + "个课程保存所有来源大题耗时:" + (ends - endTime) + "ms");
|
|
}
|
|
}
|
|
i++;
|
|
i++;
|
|
}
|
|
}
|
|
- System.out.println("对象生成完");
|
|
|
|
|
|
+ log.debug("对象生成完");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -145,7 +148,7 @@ public class DdExcelService {
|
|
//List<Course> courses = courseRepo.findByOrgId(orgId);
|
|
//List<Course> courses = courseRepo.findByOrgId(orgId);
|
|
List<Course> courses = new ArrayList<>();
|
|
List<Course> courses = new ArrayList<>();
|
|
long endCourseTime = System.currentTimeMillis();
|
|
long endCourseTime = System.currentTimeMillis();
|
|
- System.out.println("查询课程耗时:" + (endCourseTime - startCourseTime) + "ms");
|
|
|
|
|
|
+ log.debug("查询课程耗时:" + (endCourseTime - startCourseTime) + "ms");
|
|
if (courses != null && courses.size() > 0) {
|
|
if (courses != null && courses.size() > 0) {
|
|
int i = 0;
|
|
int i = 0;
|
|
for (Course course : courses) {
|
|
for (Course course : courses) {
|
|
@@ -153,7 +156,7 @@ public class DdExcelService {
|
|
long startQuestionTime = System.currentTimeMillis();
|
|
long startQuestionTime = System.currentTimeMillis();
|
|
List<Question> questions = quesRepo.findByCourseAndOrgId(course, orgId);
|
|
List<Question> questions = quesRepo.findByCourseAndOrgId(course, orgId);
|
|
long endQuestionTime = System.currentTimeMillis();
|
|
long endQuestionTime = System.currentTimeMillis();
|
|
- System.out.println("查询第" + i + "个课程试题耗时:" + (endQuestionTime - startQuestionTime) + "ms");
|
|
|
|
|
|
+ log.debug("查询第" + i + "个课程试题耗时:" + (endQuestionTime - startQuestionTime) + "ms");
|
|
List<String> oIds = new ArrayList<>();
|
|
List<String> oIds = new ArrayList<>();
|
|
for (Question question : questions) {
|
|
for (Question question : questions) {
|
|
oIds.add(question.getId());
|
|
oIds.add(question.getId());
|
|
@@ -162,7 +165,7 @@ public class DdExcelService {
|
|
long startUnitTime = System.currentTimeMillis();
|
|
long startUnitTime = System.currentTimeMillis();
|
|
List<PaperDetailUnit> oDetailUnits = paperDetailUnitService.findByDDQuestionsAndPaperType(oIds, PaperType.IMPORT, questions);
|
|
List<PaperDetailUnit> oDetailUnits = paperDetailUnitService.findByDDQuestionsAndPaperType(oIds, PaperType.IMPORT, questions);
|
|
long endUnitTime = System.currentTimeMillis();
|
|
long endUnitTime = System.currentTimeMillis();
|
|
- System.out.println("查询第" + i + "个课程试题耗时:" + (endUnitTime - startUnitTime) + "ms");
|
|
|
|
|
|
+ log.debug("查询第" + i + "个课程试题耗时:" + (endUnitTime - startUnitTime) + "ms");
|
|
Map<String, Long> map = new HashMap<>();
|
|
Map<String, Long> map = new HashMap<>();
|
|
if (oDetailUnits != null && oDetailUnits.size() > 0) {
|
|
if (oDetailUnits != null && oDetailUnits.size() > 0) {
|
|
for (PaperDetailUnit unit : oDetailUnits) {
|
|
for (PaperDetailUnit unit : oDetailUnits) {
|
|
@@ -179,7 +182,7 @@ public class DdExcelService {
|
|
}
|
|
}
|
|
DdExcelDto ddExcelDto = new DdExcelDto(course.getName(), course.getCode(), map);
|
|
DdExcelDto ddExcelDto = new DdExcelDto(course.getName(), course.getCode(), map);
|
|
ddExcelDtos.add(ddExcelDto);
|
|
ddExcelDtos.add(ddExcelDto);
|
|
- System.out.println("已经处理完:" + i + "个课程...");
|
|
|
|
|
|
+ log.debug("已经处理完:" + i + "个课程...");
|
|
i++;
|
|
i++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -189,7 +192,7 @@ public class DdExcelService {
|
|
Workbook workBook = new XSSFWorkbook(ddExcelFile);
|
|
Workbook workBook = new XSSFWorkbook(ddExcelFile);
|
|
//获取第一个工作页
|
|
//获取第一个工作页
|
|
Sheet sheet = workBook.getSheetAt(0);
|
|
Sheet sheet = workBook.getSheetAt(0);
|
|
- System.out.println(sheet.getSheetName());
|
|
|
|
|
|
+ log.debug(sheet.getSheetName());
|
|
//向Excle中写入数据,从第2行开始
|
|
//向Excle中写入数据,从第2行开始
|
|
for (int i = 0; i < ddExcelDtos.size(); i++) {
|
|
for (int i = 0; i < ddExcelDtos.size(); i++) {
|
|
//创建一行:从第1行开始,跳过表头
|
|
//创建一行:从第1行开始,跳过表头
|
|
@@ -369,15 +372,14 @@ public class DdExcelService {
|
|
}
|
|
}
|
|
|
|
|
|
} else {
|
|
} else {
|
|
- System.out.println("课程:" + ddExcelDto.getCourseName());
|
|
|
|
|
|
+ log.debug("课程:" + ddExcelDto.getCourseName());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
File file = new File(xianExcelPath);
|
|
File file = new File(xianExcelPath);
|
|
OutputStream out = new FileOutputStream(file);
|
|
OutputStream out = new FileOutputStream(file);
|
|
workBook.write(out);
|
|
workBook.write(out);
|
|
out.close();
|
|
out.close();
|
|
- System.out.println("结束...");
|
|
|
|
- System.out.println(otherMap);
|
|
|
|
|
|
+ log.debug("结束...");
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -385,7 +387,7 @@ public class DdExcelService {
|
|
*/
|
|
*/
|
|
@SuppressWarnings("resource")
|
|
@SuppressWarnings("resource")
|
|
public void exportPaperExcel(String orgId) throws Exception {
|
|
public void exportPaperExcel(String orgId) throws Exception {
|
|
- System.out.println("开始导出试卷具体信息。。。。");
|
|
|
|
|
|
+ log.debug("开始导出试卷具体信息。。。。");
|
|
//导出Excel对象集合
|
|
//导出Excel对象集合
|
|
List<DdPaperDto> excelDtoList = new ArrayList<DdPaperDto>();
|
|
List<DdPaperDto> excelDtoList = new ArrayList<DdPaperDto>();
|
|
//根据课程查询试卷
|
|
//根据课程查询试卷
|
|
@@ -409,14 +411,14 @@ public class DdExcelService {
|
|
excelDtoList.add(ddPaperDto);
|
|
excelDtoList.add(ddPaperDto);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- System.out.println("处理完第" + j + "套试卷。。。");
|
|
|
|
|
|
+ log.debug("处理完第" + j + "套试卷。。。");
|
|
j++;
|
|
j++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//查询所有课程
|
|
//查询所有课程
|
|
//List<Course> courses = courseRepo.findByOrgId(orgId);
|
|
//List<Course> courses = courseRepo.findByOrgId(orgId);
|
|
//List<Course> courses = new ArrayList<Course>();
|
|
//List<Course> courses = new ArrayList<Course>();
|
|
- //System.out.println("查询课程总数:"+ courses.size());
|
|
|
|
|
|
+ //log.debug("查询课程总数:"+ courses.size());
|
|
/*if(courses != null && courses.size()>0){
|
|
/*if(courses != null && courses.size()>0){
|
|
int i = 1;
|
|
int i = 1;
|
|
for(Course course : courses){
|
|
for(Course course : courses){
|
|
@@ -427,7 +429,7 @@ public class DdExcelService {
|
|
query.addCriteria(Criteria.where("course.enable").is("true"));
|
|
query.addCriteria(Criteria.where("course.enable").is("true"));
|
|
query.addCriteria(Criteria.where("course.code").is(course.getCode()));
|
|
query.addCriteria(Criteria.where("course.code").is(course.getCode()));
|
|
List<Paper> paperList = this.mongoTemplate.find(query, Paper.class);
|
|
List<Paper> paperList = this.mongoTemplate.find(query, Paper.class);
|
|
- System.out.println(course.getCode() + "课程下的组卷试卷数量:" + paperList.size());
|
|
|
|
|
|
+ log.debug(course.getCode() + "课程下的组卷试卷数量:" + paperList.size());
|
|
if(paperList != null && paperList.size()>0){
|
|
if(paperList != null && paperList.size()>0){
|
|
int j = 1;
|
|
int j = 1;
|
|
for(Paper paper : paperList){
|
|
for(Paper paper : paperList){
|
|
@@ -444,11 +446,11 @@ public class DdExcelService {
|
|
excelDtoList.add(ddPaperDto);
|
|
excelDtoList.add(ddPaperDto);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- System.out.println("处理完第"+ j + "套试卷。。。");
|
|
|
|
|
|
+ log.debug("处理完第"+ j + "套试卷。。。");
|
|
j++;
|
|
j++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- System.out.println("处理完第"+ i + "个课程。。。");
|
|
|
|
|
|
+ log.debug("处理完第"+ i + "个课程。。。");
|
|
i++;
|
|
i++;
|
|
}
|
|
}
|
|
}*/
|
|
}*/
|
|
@@ -473,7 +475,7 @@ public class DdExcelService {
|
|
OutputStream out = new FileOutputStream(file);
|
|
OutputStream out = new FileOutputStream(file);
|
|
workBook.write(out);
|
|
workBook.write(out);
|
|
out.close();
|
|
out.close();
|
|
- System.out.println("结束...");
|
|
|
|
|
|
+ log.debug("结束...");
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -481,13 +483,13 @@ public class DdExcelService {
|
|
*/
|
|
*/
|
|
@SuppressWarnings("resource")
|
|
@SuppressWarnings("resource")
|
|
public void exportPaperStructExcel(String orgId) throws Exception {
|
|
public void exportPaperStructExcel(String orgId) throws Exception {
|
|
- System.out.println("开始导出试卷结构");
|
|
|
|
|
|
+ log.debug("开始导出试卷结构");
|
|
//导出Excel对象集合
|
|
//导出Excel对象集合
|
|
List<DdPaperStructDto> excelDtoList = new ArrayList<>();
|
|
List<DdPaperStructDto> excelDtoList = new ArrayList<>();
|
|
//查询所有课程
|
|
//查询所有课程
|
|
List<Course> courses = courseRepo.findByOrgId(orgId);
|
|
List<Course> courses = courseRepo.findByOrgId(orgId);
|
|
//List<Course> courses = new ArrayList<Course>();
|
|
//List<Course> courses = new ArrayList<Course>();
|
|
- System.out.println("查询课程总数:" + courses.size());
|
|
|
|
|
|
+ log.debug("查询课程总数:" + courses.size());
|
|
|
|
|
|
if (courses != null && courses.size() > 0) {
|
|
if (courses != null && courses.size() > 0) {
|
|
int i = 1;
|
|
int i = 1;
|
|
@@ -497,7 +499,7 @@ public class DdExcelService {
|
|
query.addCriteria(Criteria.where("type").is("EXACT"));
|
|
query.addCriteria(Criteria.where("type").is("EXACT"));
|
|
query.addCriteria(Criteria.where("courseNo").is(course.getCode()));
|
|
query.addCriteria(Criteria.where("courseNo").is(course.getCode()));
|
|
List<PaperStruct> paperStructList = this.mongoTemplate.find(query, PaperStruct.class);
|
|
List<PaperStruct> paperStructList = this.mongoTemplate.find(query, PaperStruct.class);
|
|
- System.out.println(course.getCode() + "课程下的试卷结构数量:" + paperStructList.size());
|
|
|
|
|
|
+ log.debug(course.getCode() + "课程下的试卷结构数量:" + paperStructList.size());
|
|
if (paperStructList != null && paperStructList.size() > 0) {
|
|
if (paperStructList != null && paperStructList.size() > 0) {
|
|
for (PaperStruct paperStruct : paperStructList) {
|
|
for (PaperStruct paperStruct : paperStructList) {
|
|
//得到大题集合
|
|
//得到大题集合
|
|
@@ -522,8 +524,8 @@ public class DdExcelService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- System.out.println("处理完第:" + i + "个课程。");
|
|
|
|
- System.out.println("生成对象个数:" + excelDtoList.size());
|
|
|
|
|
|
+ log.debug("处理完第:" + i + "个课程。");
|
|
|
|
+ log.debug("生成对象个数:" + excelDtoList.size());
|
|
i++;
|
|
i++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -549,7 +551,7 @@ public class DdExcelService {
|
|
OutputStream out = new FileOutputStream(file);
|
|
OutputStream out = new FileOutputStream(file);
|
|
workBook.write(out);
|
|
workBook.write(out);
|
|
out.close();
|
|
out.close();
|
|
- System.out.println("结束...");
|
|
|
|
|
|
+ log.debug("结束...");
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -557,12 +559,12 @@ public class DdExcelService {
|
|
*/
|
|
*/
|
|
@SuppressWarnings("resource")
|
|
@SuppressWarnings("resource")
|
|
public void exportSubQues(String orgId, Long examId, List<String> codes) throws Exception {
|
|
public void exportSubQues(String orgId, Long examId, List<String> codes) throws Exception {
|
|
- System.out.println(String.format("共%s门课程的调卷规则", codes.size()));
|
|
|
|
|
|
+ log.debug(String.format("共%s门课程的调卷规则", codes.size()));
|
|
|
|
|
|
int index = 1;
|
|
int index = 1;
|
|
List<SubQuestionDto> subjectQuestions = new ArrayList<>();
|
|
List<SubQuestionDto> subjectQuestions = new ArrayList<>();
|
|
for (String code : codes) {
|
|
for (String code : codes) {
|
|
- System.out.println("开始处理第" + index + "门课程的调卷规则");
|
|
|
|
|
|
+ log.debug("开始处理第" + index + "门课程的调卷规则");
|
|
index++;
|
|
index++;
|
|
|
|
|
|
Query query = new Query();
|
|
Query query = new Query();
|
|
@@ -571,7 +573,7 @@ public class DdExcelService {
|
|
query.addCriteria(Criteria.where("courseCode").is(code));
|
|
query.addCriteria(Criteria.where("courseCode").is(code));
|
|
ExtractConfig tempConfig = this.mongoTemplate.findOne(query, ExtractConfig.class);
|
|
ExtractConfig tempConfig = this.mongoTemplate.findOne(query, ExtractConfig.class);
|
|
if (tempConfig == null) {
|
|
if (tempConfig == null) {
|
|
- System.out.println(String.format("课程-%s:没有调卷规则", code));
|
|
|
|
|
|
+ log.debug(String.format("课程-%s:没有调卷规则", code));
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -580,12 +582,12 @@ public class DdExcelService {
|
|
|
|
|
|
//获取试卷
|
|
//获取试卷
|
|
List<ExamPaper> examPaperList = tempConfig.getExamPaperList();
|
|
List<ExamPaper> examPaperList = tempConfig.getExamPaperList();
|
|
- System.out.println("原试卷数量:" + examPaperList.size());
|
|
|
|
|
|
+ log.debug("原试卷数量:" + examPaperList.size());
|
|
|
|
|
|
for (ExamPaper examPaper : examPaperList) {
|
|
for (ExamPaper examPaper : examPaperList) {
|
|
ids.add(examPaper.getPaper().getId());
|
|
ids.add(examPaper.getPaper().getId());
|
|
}
|
|
}
|
|
- System.out.println("去重后的试卷数量:" + ids.size());
|
|
|
|
|
|
+ log.debug("去重后的试卷数量:" + ids.size());
|
|
|
|
|
|
//循环去重后的试卷
|
|
//循环去重后的试卷
|
|
for (String id : ids) {
|
|
for (String id : ids) {
|
|
@@ -669,7 +671,7 @@ public class DdExcelService {
|
|
OutputStream out = new FileOutputStream(file);
|
|
OutputStream out = new FileOutputStream(file);
|
|
workBook.write(out);
|
|
workBook.write(out);
|
|
out.close();
|
|
out.close();
|
|
- System.out.println("结束...");
|
|
|
|
|
|
+ log.debug("结束...");
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|