【新增】监控管理结束工具类,学生文件新增字段文件名

This commit is contained in:
YOHO\20373
2025-05-07 14:07:45 +08:00
parent cdb75a5b44
commit acd0cf5cb4
14 changed files with 315 additions and 64 deletions

View File

@@ -30,4 +30,5 @@ public class MysqlController {
// return CommonResult.success(mysqlServerice.Judgement( ));
// }
}

View File

@@ -0,0 +1,27 @@
package pc.exam.pp.module.judgement.controller.admin.Mysql;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pc.exam.pp.framework.common.pojo.CommonResult;
import pc.exam.pp.module.judgement.controller.service.mysql.IMysqlServerice;
import pc.exam.pp.module.judgement.controller.service.mysql.testservice;
import java.io.IOException;
import java.sql.SQLException;
@RestController
@RequestMapping("/tool/Test")
public class TestControler {
@Autowired
private testservice testservice;
@PostMapping("/test")
public CommonResult run_C_code() {
return CommonResult.success(testservice.test());
}
}

View File

@@ -6,6 +6,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pc.exam.pp.framework.common.pojo.CommonResult;
import pc.exam.pp.module.judgement.controller.service.file.IFileServerice;
import pc.exam.pp.module.judgement.utils.EndStuMonitorUtils;
import java.io.IOException;

View File

@@ -9,7 +9,6 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pc.exam.pp.framework.common.pojo.CommonResult;
import pc.exam.pp.module.judgement.service.wps_excel.JudgementWpsExcelService;
import pc.exam.pp.module.judgement.service.wps_word.JudgementWpsWordService;
import pc.exam.pp.module.judgement.utils.wps_word.vo.WordVO;
@@ -29,8 +28,8 @@ public class WpsWordController {
@Autowired
private JudgementWpsWordService judgementWpsWordService;
@Resource
JudgementWpsExcelService judgementWpsExcelService;
// @Resource
// JudgementWpsExcelService judgementWpsExcelService;
/**
* wps word
* @return 判分
@@ -43,9 +42,9 @@ public class WpsWordController {
* wps word
* @return 判分
*/
@GetMapping("/run_wps_excel")
public CommonResult<String> run_wps_excel(String path) throws Exception {
return CommonResult.success(judgementWpsExcelService.ProgrammingWpsExcel(path));
}
// @GetMapping("/run_wps_excel")
// public CommonResult<String> run_wps_excel(String path) throws Exception {
// return CommonResult.success(judgementWpsExcelService.ProgrammingWpsExcel(path));
// }
}

View File

@@ -8,6 +8,7 @@ import pc.exam.pp.module.judgement.controller.utils.Mysql.MySQLExporterUtil;
import pc.exam.pp.module.judgement.controller.utils.Mysql.SQLComparatorUtil;
import pc.exam.pp.module.judgement.controller.utils.Mysql.SqlFileProcessor;
import pc.exam.pp.module.judgement.domain.SqlExecutionResult;
import pc.exam.pp.module.judgement.utils.EndStuMonitorUtils;
import java.awt.*;
import java.io.*;
@@ -810,7 +811,6 @@ public class MysqlServericeImpl implements IMysqlServerice {
/**
* 将指定内容追加写入到指定文件中。
*

View File

@@ -0,0 +1,23 @@
package pc.exam.pp.module.judgement.controller.service.mysql;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pc.exam.pp.module.judgement.utils.EndStuMonitorUtils;
@Service
public class testServiceImpl implements testservice {
@Autowired
private EndStuMonitorUtils endStuMonitorUtils;
@Override
public boolean test() {
String s = endStuMonitorUtils.endStuMonitor("160", "78f7496a68ae48e0bfb0c288549485d8");
endStuMonitorUtils.endStuMonitor("160","78f7496a68ae48e0bfb0c288549485d8",20.0);
return true;
}
}

View File

@@ -0,0 +1,7 @@
package pc.exam.pp.module.judgement.controller.service.mysql;
public interface testservice {
boolean test();
}

View File

@@ -0,0 +1,133 @@
package pc.exam.pp.module.judgement.utils;
import com.alibaba.excel.util.StringUtils;
import jakarta.annotation.Resource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import pc.exam.pp.framework.common.util.json.JsonUtils;
import pc.exam.pp.module.exam.controller.admin.monitor.vo.StuMonitorQuVo;
import pc.exam.pp.module.exam.dal.dataobject.EducationPaper;
import pc.exam.pp.module.exam.dal.dataobject.EducationPaperParam;
import pc.exam.pp.module.exam.dal.dataobject.EducationPaperTask;
import pc.exam.pp.module.exam.dal.dataobject.monitor.MonitorDO;
import pc.exam.pp.module.exam.dal.dataobject.student.StuPaperFileDO;
import pc.exam.pp.module.exam.dal.mysql.monitor.MonitorMapper;
import pc.exam.pp.module.exam.dal.mysql.paper.EducationPaperMapper;
import pc.exam.pp.module.exam.dal.mysql.paper.EducationPaperParamMapper;
import pc.exam.pp.module.exam.dal.mysql.paper.EducationPaperTaskMapper;
import pc.exam.pp.module.exam.dal.mysql.student.StuPaperFileMapper;
import pc.exam.pp.module.infra.service.file.FileService;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@Component
public class EndStuMonitorUtils {
@Resource
private RedisTemplate redisTemplate;
@Resource
private MonitorMapper monitorMapper;
@Resource
private StringRedisTemplate stringRedisTemplate;
@Resource
private FileService fileService;
@Resource
private EducationPaperMapper educationPaperMapper;
@Resource
private StuPaperFileMapper stuPaperFileMapper;
@Resource
private EducationPaperParamMapper educationPaperParamMapper;
@Resource
private EducationPaperTaskMapper educationPaperTaskMapper;
public String endStuMonitor(String stuId,String paperId) {
System.out.println(paperId);
EducationPaper educationPaper = educationPaperMapper.selectEducationPaperByPaperId(paperId);
String taskId = educationPaper.getTaskId();
String key = "userCache:" + taskId + ":" + stuId;
String keychoice = "keychoice:" + taskId + ":" + stuId;
StuMonitorQuVo stuMonitorQuVo = JsonUtils.parseObject(stringRedisTemplate.opsForValue().get(keychoice), StuMonitorQuVo.class);
String fileurl = null;
try {
String fileName = "StuMonitorQu.txt";
FileWriter writer = new FileWriter(fileName);
writer.write(JsonUtils.toJsonString(stuMonitorQuVo));
writer.close();
String path = "";
// 存储路径(可选)
// 1. 生成 JSON 内容
String content = JsonUtils.toJsonString(stuMonitorQuVo);
// 2. 转换为 UTF-8 字节数组(关键修复!)
byte[] bytes = content.getBytes(StandardCharsets.UTF_8);
fileurl = fileService.createFile(fileName, path, bytes);
System.out.println(fileurl);
redisTemplate.delete(keychoice);
StuPaperFileDO stuPaperFileDO = new StuPaperFileDO();
stuPaperFileDO.setStuId(Long.valueOf(stuId));
stuPaperFileDO.setPaperId(paperId);
stuPaperFileDO.setType(1);
stuPaperFileDO.setUrl(fileurl);
stuPaperFileMapper.insert(stuPaperFileDO);
} catch (IOException e) {
System.out.println(e);
}
return fileurl;
}
public void endStuMonitor(String stuId,String paperId,double score) {
EducationPaper educationPaper = educationPaperMapper.selectEducationPaperByPaperId(paperId);
String taskId = educationPaper.getTaskId();
String key = "userCache:" + taskId + ":" + stuId;
MonitorDO info = JsonUtils.parseObject(stringRedisTemplate.opsForValue().get(key),MonitorDO.class);
EducationPaperParam educationPaperParam = educationPaperParamMapper.selectEducationPaperParamByTaskId(taskId);
EducationPaperTask educationPaperTask = educationPaperTaskMapper.selectEducationPaperTaskByTaskId(taskId);
if ("1".equals(educationPaperParam.getSaveGrades())){
info.setScore(String.valueOf(score));
}else {
MonitorDO monitorDO = monitorMapper.selectById(info.getMonitorId());
info.setScore(String.valueOf(score));
if (StringUtils.isNotBlank(monitorDO.getScore())) {
try {
double oldScore = Double.parseDouble(monitorDO.getScore());
if (score > oldScore) {
info.setScore(String.valueOf(score));
} else {
info.setScore(monitorDO.getScore()); // 保留旧成绩
}
} catch (NumberFormatException e) {
// 如果旧分数格式错误,则直接设置新分数
info.setScore(String.valueOf(score));
}
} else {
// 如果没有旧成绩,则直接设置
info.setScore(String.valueOf(score));
}
}
//练习下的任务 结束改为 代考 其他为结束
if ("0".equals(educationPaperTask.getTaskType())){
info.setExamStatus("0");
stringRedisTemplate.opsForValue().set(key, JsonUtils.toJsonString(info));
}else {
info.setExamStatus("2");
redisTemplate.delete(key);
}
monitorMapper.updateById(info);
}
}