【修改】 判分返回保留小数点两位
This commit is contained in:
@@ -22,6 +22,7 @@ import pc.exam.pp.module.judgement.service.wps_excel.JudgementWpsExcelService;
|
||||
import pc.exam.pp.module.judgement.service.wps_pptx.JudgementWpsPptxService;
|
||||
import pc.exam.pp.module.judgement.service.wps_word.JudgementWpsWordService;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -50,7 +51,7 @@ public class AutoToolsController {
|
||||
IExamQuestionService examQuestionService;
|
||||
|
||||
@GetMapping("/get")
|
||||
public CommonResult<Double> get(StuPaperReqVo stuPaperReqVo) throws Exception {
|
||||
public CommonResult<BigDecimal> get(StuPaperReqVo stuPaperReqVo) throws Exception {
|
||||
return autoToolsService.judgementScore(stuPaperReqVo.getStuId(),stuPaperReqVo.getPaperId());
|
||||
}
|
||||
@GetMapping("/getTest")
|
||||
|
@@ -2,6 +2,8 @@ package pc.exam.pp.module.judgement.service.auto_tools;
|
||||
|
||||
import pc.exam.pp.framework.common.pojo.CommonResult;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public interface AutoToolsService {
|
||||
|
||||
|
||||
@@ -32,5 +34,5 @@ public interface AutoToolsService {
|
||||
* @param paperId 试卷ID
|
||||
* @return 分数
|
||||
*/
|
||||
CommonResult<Double> judgementScore(Long stuId, String paperId) throws Exception;
|
||||
CommonResult<BigDecimal> judgementScore(Long stuId, String paperId) throws Exception;
|
||||
}
|
||||
|
@@ -36,6 +36,7 @@ import pc.exam.pp.module.judgement.utils.zipfile.FolderZipper;
|
||||
|
||||
import java.io.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.file.Files;
|
||||
@@ -165,9 +166,9 @@ public class AutoToolsServiceImpl implements AutoToolsService{
|
||||
* @throws Exception 异常
|
||||
*/
|
||||
@Override
|
||||
public CommonResult<Double> judgementScore(Long stuId, String paperId) throws Exception {
|
||||
public CommonResult<BigDecimal> judgementScore(Long stuId, String paperId) throws Exception {
|
||||
// 监控管理 生成选择题文件路径
|
||||
// endStuMonitorUtils.endStuMonitor(String.valueOf(stuId), paperId);
|
||||
endStuMonitorUtils.endStuMonitor(String.valueOf(stuId), paperId);
|
||||
// 获取平台文件参数
|
||||
ConfigDO config = configService.getConfigByKey("file_down_path");
|
||||
double score = 0;
|
||||
@@ -183,7 +184,6 @@ public class AutoToolsServiceImpl implements AutoToolsService{
|
||||
stuPaperFileDO = stuPaperFileDOs;
|
||||
}
|
||||
}
|
||||
|
||||
// 1-1、 穿插选择题判分
|
||||
// 1-1-1、下载选择题文件
|
||||
String select_qu = downloadStudentFile(noZipFileDO.getUrl(), config.getValue());
|
||||
@@ -213,131 +213,134 @@ public class AutoToolsServiceImpl implements AutoToolsService{
|
||||
|
||||
// 2、判断文件路径是否存在
|
||||
if (stuPaperFileDO == null) {
|
||||
return CommonResult.error(100031, "试题文件没有上传,无法判分!");
|
||||
}
|
||||
// 3、下载文件
|
||||
String patn = downloadStudentFile(stuPaperFileDO.getUrl(), config.getValue());
|
||||
File zip_file = new File(patn);
|
||||
// 4、获取到得是zip文件,需要解压
|
||||
String stuFilePath = unzipToNamedFolder(patn);
|
||||
// 5、解压之后得文件获取文件夹和文件
|
||||
File folder = new File(stuFilePath);
|
||||
File[] files = folder.listFiles();
|
||||
String stu_files = null;
|
||||
// 5.1、 只查询文件夹 (学号-试卷ID-试题ID-具体内容)
|
||||
if (files == null) return CommonResult.error(100032, "1、试题文件上传,目录不正确!");
|
||||
// if (files.length > 1) return CommonResult.error(100033, "2、试题文件上传,目录不正确!");
|
||||
if (!files[0].isDirectory()) return CommonResult.error(100034, "3、试题文件上传,目录不正确!");
|
||||
// 判断学号是否正确
|
||||
if (!files[0].getName().equals(stuId.toString())) return CommonResult.error(100035, "文件与学号匹配异常");
|
||||
// 5.2、查询试题ID
|
||||
File folders = new File(files[0].getPath());
|
||||
File[] filess = folders.listFiles();
|
||||
if (filess == null) return CommonResult.error(100036, "4、试卷文件上传,目录不正确!");
|
||||
if (filess.length > 1) return CommonResult.error(100037, "5、试卷文件上传,目录不正确!");
|
||||
if (!filess[0].isDirectory()) return CommonResult.error(100038, "6、试卷文件上传,目录不正确!");
|
||||
// 判断学号是否正确
|
||||
if (!filess[0].getName().equals(paperId)) return CommonResult.error(100039, "文件与试卷匹配异常");
|
||||
// 5.3、查询出来所有试题
|
||||
File qu_files = new File(filess[0].getPath());
|
||||
// 所有试题文件夹
|
||||
File[] filess_qu = qu_files.listFiles();
|
||||
if (filess_qu == null) return CommonResult.error(100040, "没有试题文件!");
|
||||
for (File file : filess_qu) {
|
||||
// ** 接下来已经到了,每个课程题型了 file 得名称
|
||||
// return CommonResult.error(100031, "试题文件没有上传,无法判分!");
|
||||
// 3、下载文件
|
||||
String patn = downloadStudentFile(stuPaperFileDO.getUrl(), config.getValue());
|
||||
File zip_file = new File(patn);
|
||||
// 4、获取到得是zip文件,需要解压
|
||||
String stuFilePath = unzipToNamedFolder(patn);
|
||||
// 5、解压之后得文件获取文件夹和文件
|
||||
File folder = new File(stuFilePath);
|
||||
File[] files = folder.listFiles();
|
||||
String stu_files = null;
|
||||
// 5.1、 只查询文件夹 (学号-试卷ID-试题ID-具体内容)
|
||||
if (files == null) return CommonResult.error(100032, "1、试题文件上传,目录不正确!");
|
||||
// if (files.length > 1) return CommonResult.error(100033, "2、试题文件上传,目录不正确!");
|
||||
if (!files[0].isDirectory()) return CommonResult.error(100034, "3、试题文件上传,目录不正确!");
|
||||
// 判断学号是否正确
|
||||
if (!files[0].getName().equals(stuId.toString())) return CommonResult.error(100035, "文件与学号匹配异常");
|
||||
// 5.2、查询试题ID
|
||||
File folders = new File(files[0].getPath());
|
||||
File[] filess = folders.listFiles();
|
||||
if (filess == null) return CommonResult.error(100036, "4、试卷文件上传,目录不正确!");
|
||||
if (filess.length > 1) return CommonResult.error(100037, "5、试卷文件上传,目录不正确!");
|
||||
if (!filess[0].isDirectory()) return CommonResult.error(100038, "6、试卷文件上传,目录不正确!");
|
||||
// 判断学号是否正确
|
||||
if (!filess[0].getName().equals(paperId)) return CommonResult.error(100039, "文件与试卷匹配异常");
|
||||
// 5.3、查询出来所有试题
|
||||
File cs_files = new File(file.getPath());
|
||||
File qu_files = new File(filess[0].getPath());
|
||||
// 所有试题文件夹
|
||||
File[] cs_file_list = cs_files.listFiles();
|
||||
if (cs_file_list!=null){
|
||||
for (File one_file : cs_file_list) {
|
||||
// 6、根据试题ID查询试题详情
|
||||
String qu_id = file.getName();
|
||||
ExamQuestion examQuestion = examQuestionService.selectExamQuestionByQuId(qu_id);
|
||||
if (examQuestion != null) {
|
||||
// 7、进行对应得判分
|
||||
// --- 7.1、查询试题文件
|
||||
File qu_file = new File(one_file.getPath());
|
||||
File[] qu_file_list = qu_file.listFiles();
|
||||
if (qu_file_list == null) continue;
|
||||
// --- 7.2、通过文件名称进行判分
|
||||
for (File file_one : qu_file_list) {
|
||||
// 判断名称 类似于 C语言程序设计。 课程+题型
|
||||
System.out.println(one_file.getName());
|
||||
if (one_file.getName().split("\\.")[0].equals("C语言编程题")) {
|
||||
double c_score = judgementService.ProgrammingC(15.0, one_file.getPath(), file_one.getName(), examQuestion);
|
||||
score += c_score;
|
||||
System.out.println(c_score+"C语言程序设计得分");
|
||||
break;
|
||||
}
|
||||
// wps 类型存在多级文文件夹,需要个性化设置
|
||||
if (one_file.getName().split("\\.")[0].equals("WPS文字")) {
|
||||
File[] filess_qu = qu_files.listFiles();
|
||||
if (filess_qu == null) return CommonResult.error(100040, "没有试题文件!");
|
||||
for (File file : filess_qu) {
|
||||
// ** 接下来已经到了,每个课程题型了 file 得名称
|
||||
// 5.3、查询出来所有试题
|
||||
File cs_files = new File(file.getPath());
|
||||
// 所有试题文件夹
|
||||
File[] cs_file_list = cs_files.listFiles();
|
||||
if (cs_file_list!=null){
|
||||
for (File one_file : cs_file_list) {
|
||||
// 6、根据试题ID查询试题详情
|
||||
String qu_id = file.getName();
|
||||
ExamQuestion examQuestion = examQuestionService.selectExamQuestionByQuId(qu_id);
|
||||
if (examQuestion != null) {
|
||||
// 7、进行对应得判分
|
||||
// --- 7.1、查询试题文件
|
||||
File qu_file = new File(one_file.getPath());
|
||||
File[] qu_file_list = qu_file.listFiles();
|
||||
if (qu_file_list == null) continue;
|
||||
// --- 7.2、通过文件名称进行判分
|
||||
for (File file_one : qu_file_list) {
|
||||
// 判断名称 类似于 C语言程序设计。 课程+题型
|
||||
System.out.println(one_file.getName());
|
||||
if (one_file.getName().split("\\.")[0].equals("C语言编程题")) {
|
||||
double c_score = judgementService.ProgrammingC(15.0, one_file.getPath(), file_one.getName(), examQuestion);
|
||||
score += c_score;
|
||||
System.out.println(c_score+"C语言程序设计得分");
|
||||
break;
|
||||
}
|
||||
// wps 类型存在多级文文件夹,需要个性化设置
|
||||
if (one_file.getName().split("\\.")[0].equals("WPS文字")) {
|
||||
double wps_word_score = judgementWpsWordService.judgementWpsWord(15.0, one_file.getPath(), file_one.getPath(), examQuestion);
|
||||
score += wps_word_score;
|
||||
System.out.println(wps_word_score+"wps_word得分");
|
||||
break;
|
||||
}
|
||||
if (one_file.getName().split("\\.")[0].equals("WPS演示")) {
|
||||
double wps_pptx_score = judgementWpsPptxService.judgementWpsPptx(15.0, one_file.getPath(), file_one.getPath(), examQuestion);
|
||||
score += wps_pptx_score;
|
||||
System.out.println(wps_pptx_score+"wps_ppt得分");
|
||||
break;
|
||||
}
|
||||
if (one_file.getName().split("\\.")[0].equals("WPS表格")) {
|
||||
double wps_excel_score = judgementWpsExcelService.judgementWpsXlsx(15.0, one_file.getPath(), file_one.getPath(), examQuestion);
|
||||
score += wps_excel_score;
|
||||
System.out.println(wps_excel_score+"wps_excel得分");
|
||||
break;
|
||||
}
|
||||
//windows文件处理
|
||||
if (one_file.getName().split("\\.")[0].equals("文件处理")) {
|
||||
File win_file = new File(one_file.getPath());
|
||||
double win_file_score = fileServerice.run_file_point(20.0,win_file, examQuestion);
|
||||
score += win_file_score;
|
||||
System.out.println(win_file_score+"windows文件处理得分");
|
||||
break;
|
||||
}
|
||||
//浏览器操作
|
||||
// if ("浏览器网络题".equals(examQuestion.getCourseName()+examQuestion.getSubjectName())){
|
||||
if (one_file.getName().split("\\.")[0].equals("网络题")) {
|
||||
System.out.println(one_file);
|
||||
File edge_file = new File(one_file.getPath());
|
||||
double browse_score= browserServerice.Judgement(20.0,edge_file,examQuestion);
|
||||
score += browse_score;
|
||||
System.out.println(browse_score+"浏览器操作得分");
|
||||
}
|
||||
if (one_file.getName().split("\\.")[0].equals("WPS演示")) {
|
||||
double wps_pptx_score = judgementWpsPptxService.judgementWpsPptx(15.0, one_file.getPath(), file_one.getPath(), examQuestion);
|
||||
score += wps_pptx_score;
|
||||
System.out.println(wps_pptx_score+"wps_ppt得分");
|
||||
break;
|
||||
}
|
||||
if (one_file.getName().split("\\.")[0].equals("WPS表格")) {
|
||||
double wps_excel_score = judgementWpsExcelService.judgementWpsXlsx(15.0, one_file.getPath(), file_one.getPath(), examQuestion);
|
||||
score += wps_excel_score;
|
||||
System.out.println(wps_excel_score+"wps_excel得分");
|
||||
break;
|
||||
}
|
||||
//windows文件处理
|
||||
if (one_file.getName().split("\\.")[0].equals("文件处理")) {
|
||||
File win_file = new File(one_file.getPath());
|
||||
double win_file_score = fileServerice.run_file_point(20.0,win_file, examQuestion);
|
||||
score += win_file_score;
|
||||
System.out.println(win_file_score+"windows文件处理得分");
|
||||
break;
|
||||
}
|
||||
//浏览器操作
|
||||
// if ("浏览器网络题".equals(examQuestion.getCourseName()+examQuestion.getSubjectName())){
|
||||
if (one_file.getName().split("\\.")[0].equals("网络题")) {
|
||||
System.out.println(one_file);
|
||||
File edge_file = new File(one_file.getPath());
|
||||
double browse_score= browserServerice.Judgement(20.0,edge_file,examQuestion);
|
||||
score += browse_score;
|
||||
System.out.println(browse_score+"浏览器操作得分");
|
||||
|
||||
break;
|
||||
break;
|
||||
}
|
||||
if (one_file.getName().split("\\.")[0].equals("程序设计")) {
|
||||
System.out.println(one_file);
|
||||
File mysql_file = new File(one_file.getPath());
|
||||
double judgement = mysqlServerice.Judgement(20.0,mysql_file, examQuestion);
|
||||
score+=judgement;
|
||||
System.out.println(judgement+"mysql得分");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (one_file.getName().split("\\.")[0].equals("程序设计")) {
|
||||
System.out.println(one_file);
|
||||
File mysql_file = new File(one_file.getPath());
|
||||
double judgement = mysqlServerice.Judgement(20.0,mysql_file, examQuestion);
|
||||
score+=judgement;
|
||||
System.out.println(judgement+"mysql得分");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
// 8、将解压之后得问及那继续重新压缩并上传到服务器,并删除文件和文件夹
|
||||
String zipPath = FolderZipper.zipFolder(files[0].getPath().replace("\\"+stuId, ""));
|
||||
File folderStuUpdateFile = new File(files[0].getPath());
|
||||
folderStuUpdateFile.delete();
|
||||
// 9、上传文件
|
||||
MultipartFile file = new CustomMultipartFile(zipPath);
|
||||
String path = null;
|
||||
fileService.createStuFile(stuId, paperId, file.getOriginalFilename(), path, IoUtil.readBytes(file.getInputStream()));
|
||||
// 更新学生分数
|
||||
// endStuMonitorUtils.endStuMonitor(String.valueOf(stuId),paperId,score);
|
||||
// end、删除文件
|
||||
System.out.println(stuFilePath);
|
||||
zip_file.delete();
|
||||
// 8、将解压之后得问及那继续重新压缩并上传到服务器,并删除文件和文件夹
|
||||
String zipPath = FolderZipper.zipFolder(files[0].getPath().replace("\\"+stuId, ""));
|
||||
File folderStuUpdateFile = new File(files[0].getPath());
|
||||
folderStuUpdateFile.delete();
|
||||
// 9、上传文件
|
||||
MultipartFile file = new CustomMultipartFile(zipPath);
|
||||
String path = null;
|
||||
fileService.createStuFile(stuId, paperId, file.getOriginalFilename(), path, IoUtil.readBytes(file.getInputStream()));
|
||||
// 更新学生分数
|
||||
endStuMonitorUtils.endStuMonitor(String.valueOf(stuId),paperId,score);
|
||||
// end、删除文件
|
||||
System.out.println(stuFilePath);
|
||||
zip_file.delete();
|
||||
// folder.delete();
|
||||
deleteFolder(folder);
|
||||
return CommonResult.success(score);
|
||||
deleteFolder(folder);
|
||||
}
|
||||
BigDecimal bd = new BigDecimal(Double.toString(score));
|
||||
// 保留两位小数并四舍五入
|
||||
bd = bd.setScale(2, RoundingMode.HALF_UP);
|
||||
return CommonResult.success(bd);
|
||||
}
|
||||
public static void deleteFolder(File folder) {
|
||||
if (folder.isDirectory()) {
|
||||
|
Reference in New Issue
Block a user