|
@@ -171,18 +171,44 @@ public class ExtractConfigFileServiceImpl implements ExtractConfigFileService {
|
|
|
FileDisposeUtil.createDirectory(downloadDirectory);
|
|
|
//创建压缩文件的文件夹
|
|
|
FileDisposeUtil.createDirectory(zipDirectory);
|
|
|
- //得到所有锁定的试卷ID
|
|
|
- List<String> paperIds = getFinishPaperIds(exportModel);
|
|
|
+ ExportStructure exportStructure = exportStructureService.findStructureByExamId(exportModel.getExamId()+"");
|
|
|
+ if(exportStructure==null){
|
|
|
+ exportStructure = new ExportStructure();
|
|
|
+ exportStructure.setExportType(ExportType.NORMAL);
|
|
|
+ }
|
|
|
+ //如果是普通类型的批量导出
|
|
|
+ if(exportModel.getExportWay()==ExportWay.BATCH){
|
|
|
+ List<String> paperIds = checkAllCourseByExamId(exportModel.getExamId(),exportStructure.getExportType());
|
|
|
+ if(exportStructure.getExportType()==ExportType.NORMAL){
|
|
|
+ if(paperIds.size()>0&&exportModel.getExportContentList().contains(ExamFileType.PAPER_STRUCTURE_OBJECTIVE.name())){
|
|
|
+ makePaperStructure(exportStructure.getExamName(),paperIds,exportStructure);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
//根据条件获取到文件下载路径,下载文件到服务器的downloadDirectory文件夹
|
|
|
List<ExamFile> examFiles = examFileService.findExamFileListByExportPaperInfoModel(exportModel);
|
|
|
if(examFiles!=null&&examFiles.size()>0){
|
|
|
- List<Paper> papers = paperRepo.findByIdIn(paperIds);
|
|
|
for(int i = 0;i<examFiles.size();i++){
|
|
|
ExamFile examFile = examFiles.get(i);
|
|
|
UpYun upyun = new UpYun(bucketName,userName,password);
|
|
|
File file = new File(downloadDirectory+File.separator+examFile.getFileName());
|
|
|
upyun.readFile(examFile.getFilePath(), file);
|
|
|
- downloadAudio(papers.get(i),examFile);
|
|
|
+
|
|
|
+ if(examFile.getExamFileType()==ExamFileType.PAPER){
|
|
|
+ Long examId = Long.parseLong(exportModel.getExamId());
|
|
|
+ ExtractConfig extractConfig = extractConfigService.findConfig(new ExtractConfig(examId,exportModel.getCourseId()));
|
|
|
+ Map<String,String> finishedPaperIdMap = extractConfig.getFinishedPaperIdMap();
|
|
|
+ Set<Entry<String,String>> entrySet = finishedPaperIdMap.entrySet();
|
|
|
+ Iterator<Entry<String,String>> iterator = entrySet.iterator();
|
|
|
+ while(iterator.hasNext()){
|
|
|
+ Entry<String,String> entry = iterator.next();
|
|
|
+ String groupCode = entry.getKey();
|
|
|
+ String paperId = entry.getValue();
|
|
|
+ if(groupCode.equals(examFile.getGroupCode())){
|
|
|
+ downloadAudio(paperId,examFile);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
//创建压缩文件名称
|
|
@@ -199,23 +225,21 @@ public class ExtractConfigFileServiceImpl implements ExtractConfigFileService {
|
|
|
/**
|
|
|
* 下载试卷音频文件
|
|
|
*/
|
|
|
- private void downloadAudio(Paper paper,ExamFile examFile){
|
|
|
- if(examFile.getExamFileType()==ExamFileType.PAPER){
|
|
|
- if(paper.getOrgId().equals(examFile.getOrgId())
|
|
|
- &&paper.getCourse().getCode().equals(examFile.getCourseId())){
|
|
|
- List<PaperDetailUnit> paperDetailUnits = paperDetailUnitRepo.findByPaperOrderByNumber(paper);
|
|
|
- for(PaperDetailUnit unit:paperDetailUnits){
|
|
|
- if(unit.getQuestion().getHasAudio()!=null&&unit.getQuestion().getHasAudio()){
|
|
|
- List<QuestionAudio> questionAudios = questionAudioService.findQuestionAudiosByQuestionId(unit.getQuestion().getId());
|
|
|
- for(QuestionAudio audio:questionAudios){
|
|
|
- String fileName = getAudioFileName(audio,unit);
|
|
|
- String audioFileName = examFile.getFileName().split("\\.")[0]+"_"+fileName;
|
|
|
- UpYun upyun = new UpYun(bucketName,userName,password);
|
|
|
- File file = new File(downloadDirectory+File.separator+audioFileName);
|
|
|
- upyun.readFile(audio.getFileUrl(), file);
|
|
|
- logger.info(audioFileName+"音频下载完成后返回");
|
|
|
- }
|
|
|
- }
|
|
|
+ private void downloadAudio(String paperId,ExamFile examFile){
|
|
|
+ Paper paper = paperRepo.findOne(paperId);
|
|
|
+ List<PaperDetailUnit> paperDetailUnits = paperDetailUnitRepo.findByPaperOrderByNumber(paper);
|
|
|
+ for(PaperDetailUnit unit:paperDetailUnits){
|
|
|
+ if(unit.getQuestion().getHasAudio()!=null&&unit.getQuestion().getHasAudio()){
|
|
|
+ List<QuestionAudio> questionAudios = questionAudioService.findQuestionAudiosByQuestionId(unit.getQuestion().getId());
|
|
|
+ for(QuestionAudio audio:questionAudios){
|
|
|
+ String audioFileName = examFile.getCourseName()
|
|
|
+ +"_"+examFile.getCourseId()
|
|
|
+ +"_试卷_"+examFile.getGroupCode()
|
|
|
+ +"_"+getAudioFileName(audio,unit);
|
|
|
+ UpYun upyun = new UpYun(bucketName,userName,password);
|
|
|
+ File file = new File(downloadDirectory+File.separator+audioFileName);
|
|
|
+ upyun.readFile(audio.getFileUrl(), file);
|
|
|
+ logger.info(audioFileName+"音频下载完成后返回");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -259,53 +283,6 @@ public class ExtractConfigFileServiceImpl implements ExtractConfigFileService {
|
|
|
return audioFileName.toString();
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 得到调卷规则中已完成的试卷的ID集合
|
|
|
- * @param exportModel
|
|
|
- * @return
|
|
|
- * @throws Exception
|
|
|
- */
|
|
|
- private List<String> getFinishPaperIds(ExportPaperInfoModel exportModel) throws Exception {
|
|
|
- List<String> paperIds = new ArrayList<String>();
|
|
|
- ExportStructure exportStructure = exportStructureService.findStructureByExamId(exportModel.getExamId()+"");
|
|
|
- if(exportStructure==null){
|
|
|
- exportStructure = new ExportStructure();
|
|
|
- exportStructure.setExportType(ExportType.NORMAL);
|
|
|
- }
|
|
|
- //如果是普通类型的批量导出
|
|
|
- if(exportModel.getExportWay()==ExportWay.BATCH){
|
|
|
- paperIds = checkAllCourseByExamId(exportModel.getExamId(),exportStructure.getExportType());
|
|
|
- if(exportStructure.getExportType()==ExportType.NORMAL){
|
|
|
- if(paperIds.size()>0&&exportModel.getExportContentList().contains(ExamFileType.PAPER_STRUCTURE_OBJECTIVE.name())){
|
|
|
- makePaperStructure(exportStructure.getExamName(),paperIds,exportStructure);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- //如果是普通类型的单个导出
|
|
|
- if(exportModel.getExportWay()==ExportWay.SINGLE){
|
|
|
- if(exportStructure.getExportType()==ExportType.NORMAL){
|
|
|
- paperIds = getSinglePaperFinishPaperIds(exportModel);
|
|
|
- }
|
|
|
- }
|
|
|
- return paperIds;
|
|
|
- }
|
|
|
-
|
|
|
- private List<String> getSinglePaperFinishPaperIds(ExportPaperInfoModel exportModel){
|
|
|
- List<String> paperIds = new ArrayList<String>();
|
|
|
- ExtractConfig condition = new ExtractConfig();
|
|
|
- condition.setExamId(Long.parseLong(exportModel.getExamId()));
|
|
|
- condition.setCourseCode(exportModel.getCourseId());
|
|
|
- ExtractConfig extractConfig = extractConfigService.findConfig(condition);
|
|
|
- Map<String,String> finishedPaperIdMap = extractConfig.getFinishedPaperIdMap();
|
|
|
- Set<Entry<String,String>> entry = finishedPaperIdMap.entrySet();
|
|
|
- Iterator<Entry<String,String>> iterator = entry.iterator();
|
|
|
- while(iterator.hasNext()){
|
|
|
- String paperId = iterator.next().getValue();
|
|
|
- paperIds.add(paperId);
|
|
|
- }
|
|
|
- return paperIds;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 查询该考试下是否所有课程都制定了调卷规则
|
|
|
* @param examId
|