|
@@ -35,7 +35,6 @@ import javax.imageio.ImageIO;
|
|
|
import java.awt.image.BufferedImage;
|
|
|
import java.io.*;
|
|
|
import java.text.DecimalFormat;
|
|
|
-import java.text.NumberFormat;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.List;
|
|
@@ -137,12 +136,7 @@ public class PdfServiceImpl extends BaseService implements PdfService {
|
|
|
if (submitRecord == null) {
|
|
|
throw new HttpBadRequestException("score not exits");
|
|
|
}
|
|
|
- /*
|
|
|
- 成绩保留两位小数。
|
|
|
- */
|
|
|
- NumberFormat instance = NumberFormat.getInstance();
|
|
|
- instance.setMaximumFractionDigits(2);
|
|
|
- reportPDF.setScore(instance.format(submitRecord.getScore()));
|
|
|
+ reportPDF.setScore(submitRecord.getScore().toString());
|
|
|
List<SubmitRecord> submitRecords = submitRecordService.getAssignedTasks(examId);
|
|
|
List<Double> scores = calculateScoreService.calculateScores(submitRecords.stream().map(assignedTask1 -> assignedTask1.getScore()).collect(Collectors.toList()));
|
|
|
reportPDF.setMax(scores.get(0).toString());
|
|
@@ -165,14 +159,14 @@ public class PdfServiceImpl extends BaseService implements PdfService {
|
|
|
pdf.setDescription(caseExtends.getDescription());
|
|
|
for (AssignedCase assignedCase : cases) {
|
|
|
if (assignedCase.getCaseId() == caseId) {
|
|
|
- DecimalFormat decimalFormat = new DecimalFormat("######0.00");
|
|
|
+ DecimalFormat decimalFormat=new DecimalFormat("######0.00");
|
|
|
pdf.setCaseScore(String.valueOf(decimalFormat.format(assignedCase.getMaxScore())));
|
|
|
}
|
|
|
}
|
|
|
if (caseExtends.getAnswerWay() == AnswerWayConstants.REPORT)
|
|
|
pdf.setReport(this.getReport(examId, workerId, caseId));
|
|
|
if (caseExtends.getAnswerWay() == AnswerWayConstants.DEV_ECLIPSE) {
|
|
|
- String downloadUrl = pluginLogic.getAnalysisSignature(examId, workerId, caseExtends.getName());
|
|
|
+ String downloadUrl=pluginLogic.getAnalysisSignature(examId,workerId,caseExtends.getName());
|
|
|
pdf.setAnswerCode(this.getResultCode(downloadUrl));
|
|
|
}
|
|
|
pdfs.add(pdf);
|
|
@@ -248,9 +242,9 @@ public class PdfServiceImpl extends BaseService implements PdfService {
|
|
|
paragraph.setLeading(22f);
|
|
|
document.add(paragraph);
|
|
|
document.add(new Paragraph("案例名称:" + casePDF.getCaseName() + " 案例分数:" + casePDF.getCaseScore(), PdfUtils.getContent()));
|
|
|
- document.add(new Paragraph("案例描述:" + (casePDF.getDescription() != null ? casePDF.getDescription() : "无"), PdfUtils.getContent()));
|
|
|
+ document.add(new Paragraph("案例描述:" + (casePDF.getDescription()!=null?casePDF.getDescription():"无"), PdfUtils.getContent()));
|
|
|
//生成本题学生的提交内容
|
|
|
- generateCase(casePDF, document);
|
|
|
+ generateCase(casePDF,document);
|
|
|
}
|
|
|
}
|
|
|
document.close();
|
|
@@ -407,7 +401,7 @@ public class PdfServiceImpl extends BaseService implements PdfService {
|
|
|
|
|
|
private ReportForMongoDTO getReport(long examId, long participantId, long caseId) throws Exception {
|
|
|
CaseTake caseTake = CaseTakeService.getCaseTake(examId, caseId, participantId);
|
|
|
- if (caseTake == null) {
|
|
|
+ if(caseTake==null){
|
|
|
return null;
|
|
|
}
|
|
|
List<ReportForMongoDTO> reports = mongoAPIService.getReportFromMongo(caseTake.getId());
|
|
@@ -461,7 +455,7 @@ public class PdfServiceImpl extends BaseService implements PdfService {
|
|
|
CaseExtends caseExtends = caseService.getCaseExtendsById(caseId);
|
|
|
casePDF.setCaseName(caseExtends.getName());
|
|
|
casePDF.setDescription(caseExtends.getDescription());
|
|
|
- getCaseContent(caseExtends, casePDF);
|
|
|
+ getCaseContent(caseExtends,casePDF);
|
|
|
casePDFs.add(casePDF);
|
|
|
}
|
|
|
examPDF.setCasePDFs(casePDFs);
|
|
@@ -565,15 +559,15 @@ public class PdfServiceImpl extends BaseService implements PdfService {
|
|
|
paragraph.setLeading(22f);
|
|
|
document.add(paragraph);
|
|
|
document.add(new Paragraph("案例名称:" + casePDF.getCaseName(), PdfUtils.getContent()));
|
|
|
- document.add(new Paragraph("案例描述:" + (casePDF.getDescription() == null ? "无" : casePDF.getDescription()), PdfUtils.getContent()));
|
|
|
- if (casePDF.getContent() != null) {
|
|
|
+ document.add(new Paragraph("案例描述:" + (casePDF.getDescription()==null?"无":casePDF.getDescription()), PdfUtils.getContent()));
|
|
|
+ if(casePDF.getContent()!=null){
|
|
|
document.add(new Paragraph("案例内容:" + casePDF.getContent(), PdfUtils.getContent()));
|
|
|
- } else if (casePDF.getCodes() != null && casePDF.getCodes().size() > 0) {
|
|
|
+ }else if(casePDF.getCodes()!=null&&casePDF.getCodes().size()>0){
|
|
|
document.add(new Paragraph("案例内容:", PdfUtils.getContent()));
|
|
|
- List<String> codes = casePDF.getCodes();
|
|
|
- for (String str : codes) {
|
|
|
- document.add(new Paragraph("类" + (codes.indexOf(str) + 1), PdfUtils.getContent()));
|
|
|
- Paragraph paragraph1 = new Paragraph(str, PdfUtils.getCode());
|
|
|
+ List<String> codes=casePDF.getCodes();
|
|
|
+ for(String str:codes){
|
|
|
+ document.add(new Paragraph("类"+(codes.indexOf(str)+1), PdfUtils.getContent()));
|
|
|
+ Paragraph paragraph1=new Paragraph(str,PdfUtils.getCode());
|
|
|
paragraph.setIndentationLeft(25);
|
|
|
document.add(paragraph1);
|
|
|
}
|
|
@@ -587,15 +581,15 @@ public class PdfServiceImpl extends BaseService implements PdfService {
|
|
|
for (Long participantId : participantIds) {
|
|
|
ReportPDF reportPDF;
|
|
|
try {
|
|
|
- reportPDF = this.getReportPDF(examId, participantId);
|
|
|
- } catch (Exception e) {
|
|
|
+ reportPDF = this.getReportPDF(examId, participantId );
|
|
|
+ }catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
continue;
|
|
|
}
|
|
|
if (casePDFS != null) {
|
|
|
document.newPage();
|
|
|
Paragraph paragraph1 = new Paragraph("编号:" + participantIds.indexOf(participantId) + " 考生姓名:" + userDao.findOne(participantId).getName()
|
|
|
- + " 考试成绩:" + reportPDF.getScore() + " , " + getRank(examId, participantId), PdfUtils.getTitle());
|
|
|
+ + " 考试成绩:" + reportPDF.getScore() + " , " + getRank(examId, participantId),PdfUtils.getTitle());
|
|
|
document.add(paragraph1);
|
|
|
document.add(new Paragraph(18f, " "));
|
|
|
for (CasePDF casePDF : reportPDF.getCases()) {
|
|
@@ -604,9 +598,9 @@ public class PdfServiceImpl extends BaseService implements PdfService {
|
|
|
document.add(paragraph);
|
|
|
|
|
|
document.add(new Paragraph("案例名称:" + casePDF.getCaseName() + " 案例分数:" + casePDF.getCaseScore(), PdfUtils.getContent()));
|
|
|
- document.add(new Paragraph("案例描述:" + (casePDF.getDescription() == null ? "无" : casePDF.getDescription()), PdfUtils.getContent()));
|
|
|
+ document.add(new Paragraph("案例描述:" + (casePDF.getDescription()==null?"无":casePDF.getDescription()), PdfUtils.getContent()));
|
|
|
//生成本题学生的提交内容
|
|
|
- generateCase(casePDF, document);
|
|
|
+ generateCase(casePDF,document);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -616,29 +610,30 @@ public class PdfServiceImpl extends BaseService implements PdfService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ *
|
|
|
* @param pdfUrl pdf路径
|
|
|
- * @param type 图片保存格式 png/jpg ...
|
|
|
+ * @param type 图片保存格式 png/jpg ...
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
public String pdf2imageList(String pdfUrl, String type) {
|
|
|
// 将pdf装图片 并且自定义图片得格式大小
|
|
|
File file = new File(pdfUrl);
|
|
|
- return (String) this.pdf2imageList(file, type).get("url");
|
|
|
+ return (String)this.pdf2imageList(file,type).get("url");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Map<String, Object> pdf2imageList(File file, String type) {
|
|
|
- String tmpPath = System.getProperty("java.io.tmpdir") + File.separator;
|
|
|
+ String tmpPath = System.getProperty("java.io.tmpdir")+File.separator;
|
|
|
String result_path = tmpPath;
|
|
|
- String parentPath = "mooctest." + UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
+ String parentPath = "mooctest." + UUID.randomUUID().toString().replaceAll("-","");
|
|
|
String imagesParentPath = result_path + parentPath + File.separator;
|
|
|
File dir = new File(imagesParentPath);
|
|
|
- if (!dir.exists()) {
|
|
|
+ if(!dir.exists()) {
|
|
|
dir.mkdirs();
|
|
|
}
|
|
|
HashMap<String, Object> result = new HashMap<>();
|
|
|
- result.put("url", imagesParentPath);
|
|
|
+ result.put("url",imagesParentPath);
|
|
|
try {
|
|
|
PDDocument doc = PDDocument.load(file);
|
|
|
PDFRenderer renderer = new PDFRenderer(doc);
|
|
@@ -647,7 +642,7 @@ public class PdfServiceImpl extends BaseService implements PdfService {
|
|
|
for (int i = 0; i < pageCount; i++) {
|
|
|
BufferedImage image = renderer.renderImageWithDPI(i, 80); // Windows native DPI
|
|
|
// BufferedImage srcImage = resize(image, 240, 240);//产生缩略图
|
|
|
- ImageIO.write(image, type, new File(imagesParentPath + (i + 1) + "." + type));
|
|
|
+ ImageIO.write(image, type, new File(imagesParentPath + (i+1) +"."+type));
|
|
|
}
|
|
|
doc.close();
|
|
|
} catch (IOException e) {
|
|
@@ -656,7 +651,7 @@ public class PdfServiceImpl extends BaseService implements PdfService {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- private void generateCase(CasePDF casePDF, Document document) throws Exception {
|
|
|
+ private void generateCase(CasePDF casePDF, Document document) throws Exception{
|
|
|
ReportForMongoDTO report = casePDF.getReport();
|
|
|
//如果case的answerWay为report,则将测试用例和缺陷报告写入pdf中
|
|
|
if (report != null) {
|
|
@@ -679,11 +674,11 @@ public class PdfServiceImpl extends BaseService implements PdfService {
|
|
|
generateBug(dto, document);
|
|
|
}
|
|
|
}
|
|
|
- } else if (casePDF.getAnswerCode() != null && casePDF.getAnswerCode().size() > 0) {
|
|
|
+ }else if(casePDF.getAnswerCode()!=null&&casePDF.getAnswerCode().size()>0){
|
|
|
document.add(new Paragraph("考试结果:", PdfUtils.getContent()));
|
|
|
- for (String str : casePDF.getAnswerCode()) {
|
|
|
- document.add(new Paragraph("类" + (casePDF.getAnswerCode().indexOf(str) + 1) + ":", PdfUtils.getContent()));
|
|
|
- Paragraph paragraph = new Paragraph(str, PdfUtils.getCode());
|
|
|
+ for(String str:casePDF.getAnswerCode()){
|
|
|
+ document.add(new Paragraph("类"+(casePDF.getAnswerCode().indexOf(str)+1)+":",PdfUtils.getContent()));
|
|
|
+ Paragraph paragraph=new Paragraph(str,PdfUtils.getCode());
|
|
|
paragraph.setIndentationLeft(25);
|
|
|
document.add(paragraph);
|
|
|
}
|
|
@@ -704,7 +699,7 @@ public class PdfServiceImpl extends BaseService implements PdfService {
|
|
|
String path;
|
|
|
try {
|
|
|
path = downloadService.download(downloadUrl);
|
|
|
- } catch (Exception e) {
|
|
|
+ }catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
return null;
|
|
|
}
|
|
@@ -740,31 +735,31 @@ public class PdfServiceImpl extends BaseService implements PdfService {
|
|
|
, projectDirectory.getAbsolutePath()), e);
|
|
|
return null;
|
|
|
}
|
|
|
- List<String> codes = new ArrayList<>();
|
|
|
- getJavaCode(new File(projectDirectory.getPath()), codes);
|
|
|
+ List<String> codes=new ArrayList<>();
|
|
|
+ getJavaCode(new File(projectDirectory.getPath()),codes);
|
|
|
FileUtils.deleteQuietly(projectDirectory);
|
|
|
FileUtils.deleteQuietly(extractDirectory);
|
|
|
return codes;
|
|
|
}
|
|
|
|
|
|
- private void getJavaCode(File projectFile, List<String> codes) {
|
|
|
- File[] files = projectFile.listFiles();
|
|
|
- if (files == null || files.length == 0)
|
|
|
+ private void getJavaCode(File projectFile,List<String> codes){
|
|
|
+ File[] files=projectFile.listFiles();
|
|
|
+ if(files==null||files.length==0)
|
|
|
return;
|
|
|
- for (File file : files) {
|
|
|
- if (file.isDirectory()) {
|
|
|
- getJavaCode(file, codes);
|
|
|
+ for(File file:files){
|
|
|
+ if(file.isDirectory()){
|
|
|
+ getJavaCode(file,codes);
|
|
|
}
|
|
|
- if (FilenameUtils.getExtension(file.getName()).equals("java")) {
|
|
|
- StringBuilder stringBuilder = new StringBuilder();
|
|
|
- try {
|
|
|
+ if(FilenameUtils.getExtension(file.getName()).equals("java")){
|
|
|
+ StringBuilder stringBuilder=new StringBuilder();
|
|
|
+ try{
|
|
|
BufferedReader br = new BufferedReader(new FileReader(file));
|
|
|
String s;
|
|
|
- while ((s = br.readLine()) != null) {
|
|
|
- stringBuilder.append(System.lineSeparator() + s.replaceAll("\t", " "));
|
|
|
+ while((s = br.readLine())!=null){
|
|
|
+ stringBuilder.append(System.lineSeparator()+s.replaceAll("\t"," "));
|
|
|
}
|
|
|
br.close();
|
|
|
- } catch (Exception e) {
|
|
|
+ }catch(Exception e){
|
|
|
e.printStackTrace();
|
|
|
continue;
|
|
|
}
|
|
@@ -773,15 +768,15 @@ public class PdfServiceImpl extends BaseService implements PdfService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private List<String> getTargetCode(String downloadUrl) {
|
|
|
+ private List<String> getTargetCode(String downloadUrl){
|
|
|
String path;
|
|
|
try {
|
|
|
path = downloadService.download(downloadUrl);
|
|
|
- } catch (Exception e) {
|
|
|
+ }catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
return null;
|
|
|
}
|
|
|
- File file = new File(path);
|
|
|
+ File file=new File(path);
|
|
|
|
|
|
try {
|
|
|
ZipFile zipFile = new ZipFile(path);
|
|
@@ -791,19 +786,19 @@ public class PdfServiceImpl extends BaseService implements PdfService {
|
|
|
file.getAbsolutePath()), e);
|
|
|
return null;
|
|
|
}
|
|
|
- List<String> strs = new ArrayList<>();
|
|
|
- getJavaCode(new File(FileUtils.getUserDirectory() + "/" + FilenameUtils.removeExtension(file.getName()) + "/src"), strs);
|
|
|
+ List<String> strs=new ArrayList<>();
|
|
|
+ getJavaCode(new File(FileUtils.getUserDirectory()+"/"+FilenameUtils.removeExtension(file.getName())+"/src"),strs);
|
|
|
FileUtils.deleteQuietly(file);
|
|
|
- FileUtils.deleteQuietly(new File(FileUtils.getUserDirectory() + "/" + FilenameUtils.removeExtension(file.getName())));
|
|
|
+ FileUtils.deleteQuietly(new File(FileUtils.getUserDirectory()+"/"+FilenameUtils.removeExtension(file.getName())));
|
|
|
return strs;
|
|
|
}
|
|
|
|
|
|
- private void getCaseContent(CaseExtends caseExtends, CasePDF pdf) {
|
|
|
- JSONObject object = new JSONObject(caseExtends.getProperties());
|
|
|
- if (caseExtends.getAnswerWay() == AnswerWayConstants.DEV_ECLIPSE) {
|
|
|
- Target target = targetService.getAppById(caseExtends.getAppId());
|
|
|
+ private void getCaseContent(CaseExtends caseExtends,CasePDF pdf){
|
|
|
+ JSONObject object=new JSONObject(caseExtends.getProperties());
|
|
|
+ if(caseExtends.getAnswerWay()==AnswerWayConstants.DEV_ECLIPSE){
|
|
|
+ Target target =targetService.getAppById(caseExtends.getAppId());
|
|
|
pdf.setCodes(getTargetCode(target.getUrl()));
|
|
|
- } else {
|
|
|
+ }else {
|
|
|
if (object.has("require")) {
|
|
|
String path;
|
|
|
try {
|