Accept Merge Request #112: (hyc -> master)

Merge Request: 【修改】判分时下载的文件带上文件的属性

Created By: @华允传
Accepted By: @华允传
URL: https://g-iswv8783.coding.net/p/education/d/pengchen-exam-java/git/merge/112?initial=true
This commit is contained in:
华允传
2025-06-11 15:30:48 +08:00
committed by Coding
8 changed files with 53 additions and 36 deletions

View File

@@ -65,18 +65,11 @@ public class ExamQuestionAnswer
// @Excel(name = "排序")
private Integer sort;
private String attribute;
@TableField(exist = false)
@JsonInclude(value = JsonInclude.Include.NON_EMPTY)
private List<ExamMysqlKeyword> examMysqlKeywordList;
public ExamQuestionAnswer(String answerId, String quId, String isRight, String image, String content, String contentIn, String scoreRate, Integer sort) {
this.answerId = answerId;
this.quId = quId;
this.isRight = isRight;
this.image = image;
this.content = content;
this.contentIn = contentIn;
this.scoreRate = scoreRate;
this.sort = sort;
}
}

View File

@@ -68,18 +68,19 @@ public class GetDifferencesBetweenFolders {
}
}
// 在 getFileAttributes 方法中,只返回文件的属性,如果是文件夹则返回特殊标识
// 返回文件和文件夹的属性
static String getFileAttributes(Path path) {
try {
if (Files.isDirectory(path)) {
return "文件夹"; // 特别标记为文件夹
} else {
BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class);
boolean isDirectory = Files.isDirectory(path);
boolean isHidden = Files.isHidden(path);
boolean isReadable = Files.isReadable(path);
if (isDirectory) {
return String.format("隐藏: %b, 可读: %b", isHidden, isReadable);
} else {
boolean isWritable = Files.isWritable(path);
return String.format("大小: %dB, 隐藏: %b, 可读: %b, 可写: %b",
attrs.size(), isHidden, isReadable, isWritable);
return String.format("隐藏: %b, 可读: %b, 可写: %b",
isHidden, isReadable, isWritable);
}
} catch (IOException e) {
return "无法获取属性";

View File

@@ -11,11 +11,12 @@
<result property="content" column="content" />
<result property="contentIn" column="contentIn" />
<result property="scoreRate" column="score_rate" />
<result property="attribute" column="attribute" />
<result property="sort" column="sort" />
</resultMap>
<sql id="selectExamQuestionAnswerVo">
select answer_id, qu_id, is_right, image, content,contentIn, score_rate,sort from exam_question_answer
select answer_id, qu_id, is_right, image, content,contentIn, score_rate,attribute,sort from exam_question_answer
</sql>
<select id="selectExamQuestionAnswerList" parameterType="ExamQuestionAnswer" resultMap="ExamQuestionAnswerResult">
@@ -105,10 +106,10 @@
</select>
<insert id="insertExamQuestionAnswerList">
insert into exam_question_answer
(answer_id, qu_id, is_right, image, content,contentIn,score_rate,sort)
(answer_id, qu_id, is_right, image, content,contentIn,score_rate,sort,attribute)
values
<foreach collection="collection" separator="," item="item">
(#{item.answerId},#{item.quId},#{item.isRight},#{item.image},#{item.content},#{item.contentIn},#{item.scoreRate},#{item.sort})
(#{item.answerId},#{item.quId},#{item.isRight},#{item.image},#{item.content},#{item.contentIn},#{item.scoreRate},#{item.sort},#{item.attribute})
</foreach>
</insert>

View File

@@ -66,10 +66,10 @@ public class GetPointsController {
return CommonResult.success(examGetPointsService.getPointById(quId));
}
/**
* 新增/修改浏览器操作考点
* 新增/修改浏览器/文件操作考点
* @return 得分
*/
@Operation(summary = "新增/修改浏览器操作考点")
@Operation(summary = "新增/修改浏览器/文件操作考点")
@PostMapping("/set_browser_point")
@TenantIgnore
//老师自己设置,不读文件

View File

@@ -11,4 +11,5 @@ public class FileNode {
private Long id;
private String name;
private Long parentId;
private String attribute;
}

View File

@@ -92,7 +92,7 @@ public class FileServericeImpl implements IFileServerice {
// 如果学生提交中存在该文件,且属性匹配,则得分
if (stuFiles.containsKey(filePath)) {
String studentAttrs = stuFiles.get(filePath); // 学生提交的属性
String expectedAttrs = answer.getScoreRate(); // 试题中期望的属性
String expectedAttrs = answer.getAttribute(); // 试题中期望的属性
isCorrect = studentAttrs.equals(expectedAttrs);
}
}

View File

@@ -89,6 +89,7 @@ public class ExamGetPointsServiceImpl implements ExamGetPointsService{
answer.setContentIn("考察名称");
} else if (value.startsWith("属性不同")) {
answer.setContentIn("考察属性");
answer.setAttribute(value.split(" vs ")[1]);
// answer.setContent(key + " -> " + value.split(" vs ")[1]); // 设置属性信息
}
return answer;
@@ -131,6 +132,7 @@ public class ExamGetPointsServiceImpl implements ExamGetPointsService{
node.setId(currentId);
node.setName(file.getName());
node.setParentId(parentId);
node.setAttribute(getFileAttributes(file)); // 设置属性
list.add(node);
if (file.isDirectory()) {
@@ -144,6 +146,24 @@ public class ExamGetPointsServiceImpl implements ExamGetPointsService{
}
private static String getFileAttributes(File file) {
try {
boolean isDirectory = file.isDirectory();
boolean isHidden = file.isHidden();
boolean isReadable = file.canRead();
if (isDirectory) {
return String.format("隐藏: %b, 可读: %b", isHidden, isReadable);
} else {
boolean isWritable = file.canWrite();
return String.format(" 隐藏: %b, 可读: %b, 可写: %b",
isHidden, isReadable, isWritable);
}
} catch (SecurityException e) {
return "无法获取属性";
}
}

View File

@@ -30,6 +30,7 @@ import pc.exam.pp.module.infra.service.file.FileService;
import pc.exam.pp.module.judgement.controller.service.browser.IBrowserServerice;
import pc.exam.pp.module.judgement.controller.service.file.IFileServerice;
import pc.exam.pp.module.judgement.controller.service.mysql.IMysqlServerice;
import pc.exam.pp.module.judgement.controller.utils.zip.ZipUtil;
import pc.exam.pp.module.judgement.service.c_programming.JudgementService;
import pc.exam.pp.module.judgement.service.choice.JudgementChoiceService;
import pc.exam.pp.module.judgement.service.wps_excel.JudgementWpsExcelService;
@@ -271,7 +272,7 @@ public class AutoToolsServiceImpl implements AutoToolsService{
String patn = downloadStudentFile(stuPaperFileDO.getUrl(), config.getValue());
File zip_file = new File(patn);
// 4、获取到得是zip文件需要解压
String stuFilePath = unzipToNamedFolder(patn);
String stuFilePath = ZipUtil.unzipToNamedFolder(patn);
// 5、解压之后得文件获取文件夹和文件
File folder = new File(stuFilePath);
File[] files = folder.listFiles();