From b652c9c86cd36bd3db2a34538f55b38240c21cac Mon Sep 17 00:00:00 2001 From: dlaren Date: Sat, 13 Sep 2025 01:48:11 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=96=B0=E5=A2=9E=E3=80=91=201?= =?UTF-8?q?=E3=80=81=E7=AD=94=E9=A2=98=E7=8A=B6=E6=80=81=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E4=B8=8E=E5=9B=9E=E6=98=BE=EF=BC=9B2=E3=80=81=E9=82=AE?= =?UTF-8?q?=E7=AE=B1=EF=BC=8Cedge=EF=BC=8C=E9=80=89=E6=8B=A9=E9=A2=98?= =?UTF-8?q?=E6=9B=B4=E6=8D=A2pc=E7=AD=94=E6=A1=88=E5=9B=9E=E6=98=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exam/controller/auto/AutoController.java | 16 +++ .../exam/controller/info/InfoController.java | 77 +++++++++++++++ .../exam/controller/info/vo/EdgeInfoVo.java | 14 +++ .../exam/controller/info/vo/EmailInfoVo.java | 14 +++ .../AutoForWinEmailSettingService.java | 4 + .../AutoForWinEmailSettingServiceImpl.java | 92 +++++++++++++++++ .../AutoForWinEdgeSettingService.java | 3 + .../AutoForWinEdgeSettingServiceImpl.java | 85 ++++++++++++++++ .../autoforbutton/AutoForButtonService.java | 16 +++ .../AutoForButtonServiceImpl.java | 99 +++++++++++++++++++ .../autoforchoice/AutoForChoiceService.java | 3 + .../AutoForChoiceServiceImpl.java | 30 ++++++ 12 files changed, 453 insertions(+) create mode 100644 src/main/java/com/example/exam/exam/controller/info/InfoController.java create mode 100644 src/main/java/com/example/exam/exam/controller/info/vo/EdgeInfoVo.java create mode 100644 src/main/java/com/example/exam/exam/controller/info/vo/EmailInfoVo.java create mode 100644 src/main/java/com/example/exam/exam/service/autoforbutton/AutoForButtonService.java create mode 100644 src/main/java/com/example/exam/exam/service/autoforbutton/AutoForButtonServiceImpl.java diff --git a/src/main/java/com/example/exam/exam/controller/auto/AutoController.java b/src/main/java/com/example/exam/exam/controller/auto/AutoController.java index 0c02dcd..e1727fc 100644 --- a/src/main/java/com/example/exam/exam/controller/auto/AutoController.java +++ b/src/main/java/com/example/exam/exam/controller/auto/AutoController.java @@ -5,6 +5,7 @@ import com.example.exam.exam.dal.StuPaperScoreDO; import com.example.exam.exam.service.autoForEmailSetting.AutoForWinEmailSettingService; import com.example.exam.exam.service.autoForWinEdgeSetting.AutoForWinEdgeSettingService; import com.example.exam.exam.service.autoforbrower.AutoForBrowerService; +import com.example.exam.exam.service.autoforbutton.AutoForButtonService; import com.example.exam.exam.service.autoforps.AutoForPsService; import com.example.exam.exam.service.brower.JudgementBrowerService; import com.example.exam.exam.service.autoforc.AutoForCService; @@ -38,6 +39,8 @@ public class AutoController { @Resource AutoForChoiceService autoForChoiceService; @Resource + AutoForButtonService autoForButtonService; + @Resource AutoForMysqlService autoForMysqlService; @Resource AutoForFileService autoForFileService; @@ -257,6 +260,7 @@ public class AutoController { return Result.success(autoForChoiceService.autoForChoiceToJson(stuInfoVo)); } + /** * 选择题判分 * @@ -267,4 +271,16 @@ public class AutoController { public Result judgementForChoice(@RequestBody StuInfoVo stuInfoVo) throws IOException { return Result.success(autoForChoiceService.autoForChoice(stuInfoVo)); } + + + /** + * 学生端答题后按钮状态记录 + * + * @param stuInfoVo 学生信息 + * @return 分数 + */ + @PostMapping("/judgementForButtonToJson") + public Result judgementForButtonToJson(@RequestBody StuInfoVo stuInfoVo) { + return Result.success(autoForButtonService.autoForButtonToJson(stuInfoVo)); + } } diff --git a/src/main/java/com/example/exam/exam/controller/info/InfoController.java b/src/main/java/com/example/exam/exam/controller/info/InfoController.java new file mode 100644 index 0000000..17ec3ad --- /dev/null +++ b/src/main/java/com/example/exam/exam/controller/info/InfoController.java @@ -0,0 +1,77 @@ +package com.example.exam.exam.controller.info; + +import com.example.exam.exam.controller.auto.vo.StuInfoVo; +import com.example.exam.exam.controller.info.vo.EmailInfoVo; +import com.example.exam.exam.controller.info.vo.EdgeInfoVo; +import com.example.exam.exam.service.autoForEmailSetting.AutoForWinEmailSettingService; +import com.example.exam.exam.service.autoForWinEdgeSetting.AutoForWinEdgeSettingService; +import com.example.exam.exam.service.autoforbutton.AutoForButtonService; +import com.example.exam.exam.service.autoforchoice.AutoForChoiceService; +import com.example.exam.exam.utils.Result; +import jakarta.annotation.Resource; +import org.springframework.web.bind.annotation.*; + +import java.io.IOException; +import java.util.List; +import java.util.Map; + +/** + * @author REN + */ +@RestController +@RequestMapping("/exam/info") +public class InfoController { + + @Resource + AutoForWinEdgeSettingService autoForWinEdgeSettingService; + @Resource + AutoForWinEmailSettingService autoForWinEmailSettingService; + @Resource + AutoForChoiceService autoForChoiceService; + @Resource + AutoForButtonService autoForButtonService; + + /** + * edge网络设置 获取文件内的答案进行回显设置 + * + * @param stuInfoVo 学生信息 + * @return String + */ + @PostMapping("/getEdgeDummyInfo") + public Result> getEdgeDummyInfo(@RequestBody StuInfoVo stuInfoVo) throws IOException { + return Result.success(autoForWinEdgeSettingService.getEdgeInfo(stuInfoVo)); + } + + /** + * 邮箱设置 获取文件内的答案进行回显设置 + * + * @param stuInfoVo 学生信息 + * @return String + */ + @PostMapping("/getEmailDummyInfo") + public Result> getEmailDummyInfo(@RequestBody StuInfoVo stuInfoVo) throws IOException { + return Result.success(autoForWinEmailSettingService.getEmailInfo(stuInfoVo)); + } + + /** + * 选择题 获取文件内的答案进行回显设置 + * + * @param stuInfoVo 学生信息 + * @return String + */ + @PostMapping("/getChoiceInfo") + public Result> getChoiceInfo(@RequestBody StuInfoVo stuInfoVo) throws IOException { + return Result.success(autoForChoiceService.getChoiceInfo(stuInfoVo)); + } + + /** + * 答题标识 获取文件内进行回显设置 + * + * @param stuInfoVo 学生信息 + * @return String + */ + @PostMapping("/getButtonInfo") + public Result> getButtonInfo(@RequestBody StuInfoVo stuInfoVo) throws IOException { + return Result.success(autoForButtonService.getButtonInfo(stuInfoVo)); + } +} diff --git a/src/main/java/com/example/exam/exam/controller/info/vo/EdgeInfoVo.java b/src/main/java/com/example/exam/exam/controller/info/vo/EdgeInfoVo.java new file mode 100644 index 0000000..8d4d4bf --- /dev/null +++ b/src/main/java/com/example/exam/exam/controller/info/vo/EdgeInfoVo.java @@ -0,0 +1,14 @@ +package com.example.exam.exam.controller.info.vo; + +import lombok.Data; + +import java.util.Map; + +@Data +public class EdgeInfoVo { + // 试题ID + private String quId; + + // 答案 + private Map map; +} diff --git a/src/main/java/com/example/exam/exam/controller/info/vo/EmailInfoVo.java b/src/main/java/com/example/exam/exam/controller/info/vo/EmailInfoVo.java new file mode 100644 index 0000000..d58a81d --- /dev/null +++ b/src/main/java/com/example/exam/exam/controller/info/vo/EmailInfoVo.java @@ -0,0 +1,14 @@ +package com.example.exam.exam.controller.info.vo; + +import lombok.Data; + +import java.util.Map; + +@Data +public class EmailInfoVo { + // 试题ID + private String quId; + + // 答案 + private Map map; +} diff --git a/src/main/java/com/example/exam/exam/service/autoForEmailSetting/AutoForWinEmailSettingService.java b/src/main/java/com/example/exam/exam/service/autoForEmailSetting/AutoForWinEmailSettingService.java index 09100b0..0edae82 100644 --- a/src/main/java/com/example/exam/exam/service/autoForEmailSetting/AutoForWinEmailSettingService.java +++ b/src/main/java/com/example/exam/exam/service/autoForEmailSetting/AutoForWinEmailSettingService.java @@ -1,9 +1,11 @@ package com.example.exam.exam.service.autoForEmailSetting; import com.example.exam.exam.controller.auto.vo.StuInfoVo; +import com.example.exam.exam.controller.info.vo.EmailInfoVo; import java.io.IOException; import java.math.BigDecimal; +import java.util.List; /** * @author REN @@ -13,4 +15,6 @@ public interface AutoForWinEmailSettingService { String autoForEmailToJson(StuInfoVo stuInfoVo); BigDecimal autoForEmail(StuInfoVo stuInfoVo) throws IOException; + + List getEmailInfo(StuInfoVo stuInfoVo); } diff --git a/src/main/java/com/example/exam/exam/service/autoForEmailSetting/AutoForWinEmailSettingServiceImpl.java b/src/main/java/com/example/exam/exam/service/autoForEmailSetting/AutoForWinEmailSettingServiceImpl.java index c32a052..90552c2 100644 --- a/src/main/java/com/example/exam/exam/service/autoForEmailSetting/AutoForWinEmailSettingServiceImpl.java +++ b/src/main/java/com/example/exam/exam/service/autoForEmailSetting/AutoForWinEmailSettingServiceImpl.java @@ -1,6 +1,7 @@ package com.example.exam.exam.service.autoForEmailSetting; import com.example.exam.exam.controller.auto.vo.StuInfoVo; +import com.example.exam.exam.controller.info.vo.EmailInfoVo; import com.example.exam.exam.dal.*; import com.example.exam.exam.mapper.EducationPaperMapper; import com.example.exam.exam.mapper.EducationPaperQuMapper; @@ -298,6 +299,97 @@ public class AutoForWinEmailSettingServiceImpl implements AutoForWinEmailSetting return score.setScale(1, BigDecimal.ROUND_HALF_UP); } + + @Override + public List getEmailInfo(StuInfoVo stuInfoVo) { + List emailInfoVos = new ArrayList<>(); + // 获取Paper下的所有windows网络设置ID + List examQuestions = educationPaperMapper.selectPaperQuByPaperId(stuInfoVo.getPaperId()); + List edgeList = new ArrayList<>(); + for (ExamQuestion examQuestion : examQuestions) { + if ("邮箱".equals(examQuestion.getSubjectName())) { + edgeList.add(examQuestion); + } + } + // 获取所有json文件,并取出试题ID + List resultFile = new ArrayList<>(); + File dir = new File(stuInfoVo.getFilePath()); + File[] files = dir.listFiles(); + if (files == null) return null; + // 获取到题型得文件夹 + for (File file : files) { + File[] fileQuNum = file.listFiles(); + if (fileQuNum != null) { + for (File fileNum : fileQuNum) { + if (Objects.requireNonNull(fileNum.listFiles()).length > 0) { + File fileJson = Objects.requireNonNull(fileNum.listFiles())[0]; + if (fileJson.isFile() + && fileJson.getName().contains("@EmailDummy") + && fileJson.getName().toLowerCase().endsWith(".json")) { + resultFile.add(fileJson); + } + } + } + } + } + List trueFileQuid = new ArrayList<>(); + List noFileQuid = new ArrayList<>(); + // 开始读取文件并进行拆分 + for (ExamQuestion examQuestion : edgeList) { + boolean fileIsTrue = false; + for (File file : resultFile) { + String quId = file.getName().split("@")[0]; + if (quId.equals(examQuestion.getQuId())) { + fileIsTrue = true; + trueFileQuid.add(quId); + break; + } + } + if (!fileIsTrue) { + noFileQuid.add(examQuestion.getQuId()); + } + } + // 查询哪些文件已经进行获取到学生作答文件了 + for (String str : trueFileQuid) { + // 创建 EmailInfoVo 对象 + EmailInfoVo emailInfoVo = new EmailInfoVo(); + // 查询到学生文件 + Optional fileResult = resultFile.stream().filter(resultFiles -> resultFiles.getName().contains(str)).findFirst(); + if (fileResult.isPresent()) { + File file = fileResult.get(); + // 创建 ObjectMapper 实例 + File jsonFile = new File(file.getPath()); + ObjectMapper objectMapper = new ObjectMapper(); + if (jsonFile.exists()) { + // 试题ID + String quId = file.getName().split("@")[0]; + emailInfoVo.setQuId(quId); + // 读取学生文件 + try (FileInputStream fileInputStream = new FileInputStream(jsonFile)) { + // 读取文件并转换为 JsonNode + JsonNode rootNode = objectMapper.readTree(fileInputStream); + String jsonText = objectMapper.writeValueAsString(rootNode); + // 从 JSON 文件读取并转换为 Person 对象 + Map map = objectMapper.readValue(jsonText, Map.class); + emailInfoVo.setMap(map); + emailInfoVos.add(emailInfoVo); + if (fileInputStream != null) { + try { + fileInputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + return emailInfoVos; + } + + // 将Map写入JSON文件 // 将Map追加到JSON文件 public static String writeMapToJson(Map map, String filePath) { diff --git a/src/main/java/com/example/exam/exam/service/autoForWinEdgeSetting/AutoForWinEdgeSettingService.java b/src/main/java/com/example/exam/exam/service/autoForWinEdgeSetting/AutoForWinEdgeSettingService.java index 9370f07..5017216 100644 --- a/src/main/java/com/example/exam/exam/service/autoForWinEdgeSetting/AutoForWinEdgeSettingService.java +++ b/src/main/java/com/example/exam/exam/service/autoForWinEdgeSetting/AutoForWinEdgeSettingService.java @@ -1,6 +1,7 @@ package com.example.exam.exam.service.autoForWinEdgeSetting; import com.example.exam.exam.controller.auto.vo.StuInfoVo; +import com.example.exam.exam.controller.info.vo.EdgeInfoVo; import java.io.IOException; import java.math.BigDecimal; @@ -14,4 +15,6 @@ public interface AutoForWinEdgeSettingService { String autoForEdgeToJson(StuInfoVo stuInfoVo); BigDecimal autoForEdge(StuInfoVo stuInfoVo) throws IOException; + + List getEdgeInfo(StuInfoVo stuInfoVo); } diff --git a/src/main/java/com/example/exam/exam/service/autoForWinEdgeSetting/AutoForWinEdgeSettingServiceImpl.java b/src/main/java/com/example/exam/exam/service/autoForWinEdgeSetting/AutoForWinEdgeSettingServiceImpl.java index 1a339b5..8c28200 100644 --- a/src/main/java/com/example/exam/exam/service/autoForWinEdgeSetting/AutoForWinEdgeSettingServiceImpl.java +++ b/src/main/java/com/example/exam/exam/service/autoForWinEdgeSetting/AutoForWinEdgeSettingServiceImpl.java @@ -1,6 +1,7 @@ package com.example.exam.exam.service.autoForWinEdgeSetting; import com.example.exam.exam.controller.auto.vo.StuInfoVo; +import com.example.exam.exam.controller.info.vo.EdgeInfoVo; import com.example.exam.exam.dal.*; import com.example.exam.exam.mapper.EducationPaperMapper; import com.example.exam.exam.mapper.EducationPaperQuMapper; @@ -293,6 +294,90 @@ public class AutoForWinEdgeSettingServiceImpl implements AutoForWinEdgeSettingSe return score.setScale(1, BigDecimal.ROUND_HALF_UP); } + @Override + public List getEdgeInfo(StuInfoVo stuInfoVo) { + List edgeInfoVos = new ArrayList<>(); + // 获取Paper下的所有windows网络设置ID + List examQuestions = educationPaperMapper.selectPaperQuByPaperId(stuInfoVo.getPaperId()); + List edgeList = new ArrayList<>(); + for (ExamQuestion examQuestion : examQuestions) { + if ("windows网络设置".equals(examQuestion.getSubjectName())) { + edgeList.add(examQuestion); + } + } + // 获取所有json文件,并取出试题ID + List resultFile = new ArrayList<>(); + File dir = new File(stuInfoVo.getFilePath()); + File[] files = dir.listFiles(); + if (files == null) return null; + // 获取到题型得文件夹 + for (File file : files) { + File[] fileQuNum = file.listFiles(); + if (fileQuNum != null) { + for (File fileNum : fileQuNum) { + if (Objects.requireNonNull(fileNum.listFiles()).length > 0) { + File fileJson = Objects.requireNonNull(fileNum.listFiles())[0]; + if (fileJson.isFile() + && fileJson.getName().contains("@EdgeDummy") + && fileJson.getName().toLowerCase().endsWith(".json")) { + resultFile.add(fileJson); + } + } + } + } + } + List trueFileQuid = new ArrayList<>(); + // 开始读取文件并进行拆分 + for (ExamQuestion examQuestion : edgeList) { + for (File file : resultFile) { + String quId = file.getName().split("@")[0]; + if (quId.equals(examQuestion.getQuId())) { + trueFileQuid.add(quId); + break; + } + } + } + // 查询哪些文件已经进行获取到学生作答文件了 + for (String str : trueFileQuid) { + // 创建windows试题返回结果 + EdgeInfoVo edgeInfoVo = new EdgeInfoVo(); + // 查询到学生文件 + Optional fileResult = resultFile.stream().filter(resultFiles -> resultFiles.getName().contains(str)).findFirst(); + if (fileResult.isPresent()) { + File file = fileResult.get(); + // 创建 ObjectMapper 实例 + File jsonFile = new File(file.getPath()); + ObjectMapper objectMapper = new ObjectMapper(); + if (jsonFile.exists()) { + // 获取试题ID + String quId = file.getName().split("@")[0]; + edgeInfoVo.setQuId(quId); + // 读取学生文件 + try (FileInputStream fileInputStream = new FileInputStream(jsonFile)) { + // 读取文件并转换为 JsonNode + JsonNode rootNode = objectMapper.readTree(fileInputStream); + String jsonText = objectMapper.writeValueAsString(rootNode); + // 从 JSON 文件读取并转换为 Person 对象 + Map map = objectMapper.readValue(jsonText, Map.class); + edgeInfoVo.setMap(map); + edgeInfoVos.add(edgeInfoVo); + // 关闭文件输入流 + if (fileInputStream != null) { + try { + fileInputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + return edgeInfoVos; + } + // 将Map写入JSON文件 // 将Map追加到JSON文件 public static String writeMapToJson(Map map, String filePath) { diff --git a/src/main/java/com/example/exam/exam/service/autoforbutton/AutoForButtonService.java b/src/main/java/com/example/exam/exam/service/autoforbutton/AutoForButtonService.java new file mode 100644 index 0000000..3c9d311 --- /dev/null +++ b/src/main/java/com/example/exam/exam/service/autoforbutton/AutoForButtonService.java @@ -0,0 +1,16 @@ +package com.example.exam.exam.service.autoforbutton; + +import com.example.exam.exam.controller.auto.vo.StuInfoVo; + +import java.io.IOException; +import java.util.Map; + +/** + * @author REN + */ +public interface AutoForButtonService { + + String autoForButtonToJson(StuInfoVo stuInfoVo); + + Map getButtonInfo(StuInfoVo stuInfoVo); +} diff --git a/src/main/java/com/example/exam/exam/service/autoforbutton/AutoForButtonServiceImpl.java b/src/main/java/com/example/exam/exam/service/autoforbutton/AutoForButtonServiceImpl.java new file mode 100644 index 0000000..7507b76 --- /dev/null +++ b/src/main/java/com/example/exam/exam/service/autoforbutton/AutoForButtonServiceImpl.java @@ -0,0 +1,99 @@ +package com.example.exam.exam.service.autoforbutton; + +import com.example.exam.exam.controller.auto.vo.StuInfoVo; +import com.example.exam.exam.utils.c.LogFileUtils; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.stereotype.Service; + +import java.io.*; +import java.util.*; + +@Service +public class AutoForButtonServiceImpl implements AutoForButtonService { + + /** + * 学生端答题后按钮状态记录 + * + * @param stuInfoVo 学生考试信息 + * @return 是否通过 + */ + @Override + public String autoForButtonToJson(StuInfoVo stuInfoVo) { + // 试题ID + String quId = stuInfoVo.getQuestionId(); + // 保存ID路径 + String filePath = stuInfoVo.getFilePath(); + File file = new File(filePath + "/Button.json"); + if (!file.exists()) { + LogFileUtils.createHiddenFile(filePath + "/Button.json"); + } + Map map = new HashMap<>(); + map.put(quId, quId); + return writeMapToJson(map, filePath + "/Button.json"); + } + + @Override + public Map getButtonInfo(StuInfoVo stuInfoVo) { + // 文件路径 + String filePath = stuInfoVo.getFilePath() + "/Button.json"; + // 读取JSON文件 + // 创建 ObjectMapper 实例 + File jsonFile = new File(filePath); + ObjectMapper objectMapper = new ObjectMapper(); + Map map = null; + if (jsonFile.exists()) { + try (FileInputStream fileInputStream = new FileInputStream(jsonFile)) { + // 读取文件并转换为 JsonNode + JsonNode rootNode = objectMapper.readTree(fileInputStream); + String jsonText = objectMapper.writeValueAsString(rootNode); + // 从 JSON 文件读取并转换为 Person 对象 + map = objectMapper.readValue(jsonText, Map.class); + if (fileInputStream != null) { + try { + fileInputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return map; + } + + // 将Map写入JSON文件 + // 将Map追加到JSON文件 + public static String writeMapToJson(Map map, String filePath) { + ObjectMapper objectMapper = new ObjectMapper(); + File file = new File(filePath); + + try { + Map existingMap = new HashMap<>(); + + if (file.exists() && file.length() > 0) { + try (InputStream fis = new FileInputStream(file)) { + existingMap = objectMapper.readValue(fis, Map.class); + } + } + + existingMap.putAll(map); + + try (OutputStream fos = new FileOutputStream(file, false); + BufferedOutputStream bos = new BufferedOutputStream(fos)) { + objectMapper.writeValue(bos, existingMap); + bos.flush(); // 强制刷新 + } + + // 可选占用测试 + boolean released = file.renameTo(file); + System.out.println("文件释放状态: " + released); + + } catch (IOException e) { + e.printStackTrace(); + } + + return "学生答案已经写入到 " + filePath; + } +} diff --git a/src/main/java/com/example/exam/exam/service/autoforchoice/AutoForChoiceService.java b/src/main/java/com/example/exam/exam/service/autoforchoice/AutoForChoiceService.java index 8936299..6ef902e 100644 --- a/src/main/java/com/example/exam/exam/service/autoforchoice/AutoForChoiceService.java +++ b/src/main/java/com/example/exam/exam/service/autoforchoice/AutoForChoiceService.java @@ -3,6 +3,7 @@ package com.example.exam.exam.service.autoforchoice; import com.example.exam.exam.controller.auto.vo.StuInfoVo; import java.io.IOException; +import java.util.Map; /** * @author REN @@ -12,4 +13,6 @@ public interface AutoForChoiceService { String autoForChoiceToJson(StuInfoVo stuInfoVo); Double autoForChoice(StuInfoVo stuInfoVo) throws IOException; + + Map getChoiceInfo(StuInfoVo stuInfoVo); } diff --git a/src/main/java/com/example/exam/exam/service/autoforchoice/AutoForChoiceServiceImpl.java b/src/main/java/com/example/exam/exam/service/autoforchoice/AutoForChoiceServiceImpl.java index d192d63..32802a4 100644 --- a/src/main/java/com/example/exam/exam/service/autoforchoice/AutoForChoiceServiceImpl.java +++ b/src/main/java/com/example/exam/exam/service/autoforchoice/AutoForChoiceServiceImpl.java @@ -297,6 +297,36 @@ public class AutoForChoiceServiceImpl implements AutoForChoiceService { return score; } + @Override + public Map getChoiceInfo(StuInfoVo stuInfoVo) { + // 文件路径 + String filePath = stuInfoVo.getFilePath() + "/Choice.json"; + // 读取JSON文件 + // 创建 ObjectMapper 实例 + File jsonFile = new File(filePath); + ObjectMapper objectMapper = new ObjectMapper(); + Map map = null; + if (jsonFile.exists()) { + try (FileInputStream fileInputStream = new FileInputStream(jsonFile)) { + // 读取文件并转换为 JsonNode + JsonNode rootNode = objectMapper.readTree(fileInputStream); + String jsonText = objectMapper.writeValueAsString(rootNode); + // 从 JSON 文件读取并转换为 Person 对象 + map = objectMapper.readValue(jsonText, Map.class); + if (fileInputStream != null) { + try { + fileInputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return map; + } + // 将Map写入JSON文件 // 将Map追加到JSON文件 public static String writeMapToJson(Map map, String filePath) {