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

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

@@ -7,7 +7,7 @@ import lombok.Data;
@Data @Data
public class StuMonitorPaperEndVo { public class StuMonitorPaperEndVo {
private String stuId; private String stuId;
private String paperId;
private String score; private String score;
private String taskId; private String taskId;

View File

@@ -48,6 +48,8 @@ public class SysFileUpload extends BaseDO {
// @Excel(name = "文件类型0:素材,1:原始,2:结果)") // @Excel(name = "文件类型0:素材,1:原始,2:结果)")
private String fileType; private String fileType;
private String fileName;
} }

View File

@@ -12,6 +12,7 @@ import org.springframework.validation.annotation.Validated;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.time.Instant; import java.time.Instant;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
@@ -27,12 +28,14 @@ import pc.exam.pp.framework.common.util.json.JsonUtils;
import pc.exam.pp.framework.common.util.object.BeanUtils; import pc.exam.pp.framework.common.util.object.BeanUtils;
import pc.exam.pp.module.exam.controller.admin.monitor.vo.*; import pc.exam.pp.module.exam.controller.admin.monitor.vo.*;
import pc.exam.pp.module.exam.controller.admin.paper.dto.PersonRepDto;
import pc.exam.pp.module.exam.dal.dataobject.*; import pc.exam.pp.module.exam.dal.dataobject.*;
import pc.exam.pp.module.exam.dal.dataobject.monitor.MonitorDO; import pc.exam.pp.module.exam.dal.dataobject.monitor.MonitorDO;
import pc.exam.pp.module.exam.dal.mysql.monitor.MonitorMapper; import pc.exam.pp.module.exam.dal.mysql.monitor.MonitorMapper;
import pc.exam.pp.module.exam.dal.mysql.paper.*; import pc.exam.pp.module.exam.dal.mysql.paper.*;
import pc.exam.pp.module.exam.dal.mysql.question.ExamQuestionMapper; import pc.exam.pp.module.exam.dal.mysql.question.ExamQuestionMapper;
import pc.exam.pp.module.exam.utils.uuid.IdUtils; import pc.exam.pp.module.exam.utils.uuid.IdUtils;
//import pc.exam.pp.module.infra.service.file.FileService;
import static pc.exam.pp.framework.common.exception.util.ServiceExceptionUtil.exception; import static pc.exam.pp.framework.common.exception.util.ServiceExceptionUtil.exception;
import static pc.exam.pp.module.system.enums.ErrorCodeConstants.MONITOR_NOT_EXISTS; import static pc.exam.pp.module.system.enums.ErrorCodeConstants.MONITOR_NOT_EXISTS;
@@ -63,6 +66,9 @@ public class MonitorServiceImpl implements MonitorService {
private EducationPaperParamMapper educationPaperParamMapper; private EducationPaperParamMapper educationPaperParamMapper;
@Resource @Resource
private EducationPaperSessionMapper educationPaperSessionMapper; private EducationPaperSessionMapper educationPaperSessionMapper;
// @Resource
// private FileService fileService;
@Override @Override
public String createMonitor(MonitorSaveReqVO createReqVO) { public String createMonitor(MonitorSaveReqVO createReqVO) {
// 插入 // 插入
@@ -107,10 +113,9 @@ public class MonitorServiceImpl implements MonitorService {
@Override @Override
public Boolean getStuMonitor(StuMonitorPaperVo stuMonitorPaperVo) { public Boolean getStuMonitor(StuMonitorPaperVo stuMonitorPaperVo) {
String key = "userCache:"+stuMonitorPaperVo.getTaskId()+":" + stuMonitorPaperVo.getStuId(); String key = "userCache:"+stuMonitorPaperVo.getTaskId()+":" + stuMonitorPaperVo.getStuId();
// MonitorDO info = JsonUtils.parseObject(stringRedisTemplate.opsForValue().get(key),MonitorDO.class); MonitorDO info = JsonUtils.parseObject(stringRedisTemplate.opsForValue().get(key),MonitorDO.class);
MonitorDO info=new MonitorDO(); // MonitorDO info=new MonitorDO();
String uuid = IdUtils.simpleUUID();
info.setMonitorId(uuid);
if (StringUtils.isNotBlank(stuMonitorPaperVo.getPaperId())){ if (StringUtils.isNotBlank(stuMonitorPaperVo.getPaperId())){
EducationPaper educationPaper = educationPaperMapper.selectEducationPaperByPaperId(stuMonitorPaperVo.getPaperId()); EducationPaper educationPaper = educationPaperMapper.selectEducationPaperByPaperId(stuMonitorPaperVo.getPaperId());
String counts = educationPaper.getCounts(); String counts = educationPaper.getCounts();
@@ -134,7 +139,7 @@ public class MonitorServiceImpl implements MonitorService {
if (info.getRemainingTime()==null){ if (info.getRemainingTime()==null){
stringRedisTemplate.opsForValue().set("userCache:"+stuMonitorPaperVo.getTaskId()+":"+stuMonitorPaperVo.getStuId(), JsonUtils.toJsonString(info)); stringRedisTemplate.opsForValue().set("userCache:"+stuMonitorPaperVo.getTaskId()+":"+stuMonitorPaperVo.getStuId(), JsonUtils.toJsonString(info));
monitorMapper.insert(info); monitorMapper.updateById(info);
return true; return true;
}else { }else {
EducationPaperPerson educationPaperPerson = educationPaperPersonMapper.selectByTaskIdAndPersonId(stuMonitorPaperVo.getTaskId(), stuMonitorPaperVo.getStuId()); EducationPaperPerson educationPaperPerson = educationPaperPersonMapper.selectByTaskIdAndPersonId(stuMonitorPaperVo.getTaskId(), stuMonitorPaperVo.getStuId());
@@ -173,7 +178,9 @@ public class MonitorServiceImpl implements MonitorService {
//todo 考虑加点时间,或判分后删除 //todo 考虑加点时间,或判分后删除
stringRedisTemplate.opsForValue().set("userCache:"+stuMonitorPaperVo.getTaskId()+":"+stuMonitorPaperVo.getStuId(), JsonUtils.toJsonString(info), remainingSeconds, TimeUnit.SECONDS); // stringRedisTemplate.opsForValue().set("userCache:"+stuMonitorPaperVo.getTaskId()+":"+stuMonitorPaperVo.getStuId(), JsonUtils.toJsonString(info), remainingSeconds, TimeUnit.SECONDS);
stringRedisTemplate.opsForValue().set("userCache:"+stuMonitorPaperVo.getTaskId()+":"+stuMonitorPaperVo.getStuId(), JsonUtils.toJsonString(info));
monitorMapper.updateById(info); monitorMapper.updateById(info);
return true; return true;
}else { }else {
@@ -206,49 +213,57 @@ public class MonitorServiceImpl implements MonitorService {
@Override @Override
public void endStuMonitor(StuMonitorPaperEndVo stuMonitorPaperEndVo) { public void endStuMonitor(StuMonitorPaperEndVo stuMonitorPaperEndVo) {
String key = "userCache:" + stuMonitorPaperEndVo.getTaskId()+":" +stuMonitorPaperEndVo.getStuId(); // String key = "userCache:" + stuMonitorPaperEndVo.getTaskId()+":" +stuMonitorPaperEndVo.getStuId();
String keychoice = "keychoice:"+stuMonitorPaperEndVo.getTaskId()+":" + stuMonitorPaperEndVo.getStuId(); // String keychoice = "keychoice:"+stuMonitorPaperEndVo.getTaskId()+":" + stuMonitorPaperEndVo.getStuId();
StuMonitorQuVo stuMonitorQuVo = JsonUtils.parseObject(stringRedisTemplate.opsForValue().get(keychoice),StuMonitorQuVo.class); // StuMonitorQuVo stuMonitorQuVo = JsonUtils.parseObject(stringRedisTemplate.opsForValue().get(keychoice),StuMonitorQuVo.class);
//
try { // try {
String fileName = "StuMonitorQu.txt"; // String fileName = "StuMonitorQu.txt";
FileWriter writer = new FileWriter(fileName); // FileWriter writer = new FileWriter(fileName);
writer.write(JsonUtils.toJsonString(stuMonitorQuVo)); // writer.write(JsonUtils.toJsonString(stuMonitorQuVo));
writer.close(); // writer.close();
//上传至 // //上传至
// String stuId = stuMonitorPaperEndVo.getStuId(); // 学生ID
// String paperId = stuMonitorPaperEndVo.getPaperId(); // 试卷ID
// String path = ""; // 存储路径(可选)
} catch (IOException e) { // // 1. 生成 JSON 内容
System.out.println(e); // String content = JsonUtils.toJsonString(stuMonitorQuVo);
} //
// // 2. 转换为 UTF-8 字节数组(关键修复!)
MonitorDO info = JsonUtils.parseObject(stringRedisTemplate.opsForValue().get(key),MonitorDO.class); // byte[] bytes = content.getBytes(StandardCharsets.UTF_8);
EducationPaperParam educationPaperParam = educationPaperParamMapper.selectEducationPaperParamByTaskId(stuMonitorPaperEndVo.getTaskId()); //// String fileurl= fileService.createFile(fileName,path, bytes);
EducationPaperTask educationPaperTask = educationPaperTaskMapper.selectEducationPaperTaskByTaskId(stuMonitorPaperEndVo.getTaskId()); //// System.out.println(fileurl);
if ("1".equals(educationPaperParam.getSaveGrades())){ //
info.setScore(stuMonitorPaperEndVo.getScore()); // } catch (IOException e) {
}else { // System.out.println(e);
MonitorDO monitorDO = monitorMapper.selectById(info.getMonitorId()); // }
info.setScore(stuMonitorPaperEndVo.getScore()); //
if (StringUtils.isNotBlank(monitorDO.getScore())) { // MonitorDO info = JsonUtils.parseObject(stringRedisTemplate.opsForValue().get(key),MonitorDO.class);
if (Integer.parseInt(monitorDO.getScore()) <Integer.parseInt(stuMonitorPaperEndVo.getScore())){ // EducationPaperParam educationPaperParam = educationPaperParamMapper.selectEducationPaperParamByTaskId(stuMonitorPaperEndVo.getTaskId());
info.setScore(stuMonitorPaperEndVo.getScore()); // EducationPaperTask educationPaperTask = educationPaperTaskMapper.selectEducationPaperTaskByTaskId(stuMonitorPaperEndVo.getTaskId());
} // if ("1".equals(educationPaperParam.getSaveGrades())){
} // info.setScore(stuMonitorPaperEndVo.getScore());
// }else {
// MonitorDO monitorDO = monitorMapper.selectById(info.getMonitorId());
} // info.setScore(stuMonitorPaperEndVo.getScore());
//练习下的任务 结束改为 代考 // if (StringUtils.isNotBlank(monitorDO.getScore())) {
if ("0".equals(educationPaperTask.getStatus())){ // if (Integer.parseInt(monitorDO.getScore()) <Integer.parseInt(stuMonitorPaperEndVo.getScore())){
info.setExamStatus("0"); // info.setScore(stuMonitorPaperEndVo.getScore());
}else { // }
info.setExamStatus("2"); // }
} //
//todo 这些都写成方法 //
redisTemplate.delete(key); // }
redisTemplate.delete(keychoice); // //练习下的任务 结束改为 代考 其他为结束
monitorMapper.updateById(info); // if ("0".equals(educationPaperTask.getTaskType())){
// info.setExamStatus("0");
// }else {
// info.setExamStatus("2");
// }
// //todo 这些都写成方法
// redisTemplate.delete(key);
// redisTemplate.delete(keychoice);
// monitorMapper.updateById(info);
} }
@@ -272,7 +287,23 @@ public class MonitorServiceImpl implements MonitorService {
monitorMapper.updateById(monitorDO); monitorMapper.updateById(monitorDO);
MonitorDO info = JsonUtils.parseObject(stringRedisTemplate.opsForValue().get(key),MonitorDO.class); MonitorDO info = JsonUtils.parseObject(stringRedisTemplate.opsForValue().get(key),MonitorDO.class);
if (info==null){
PersonRepDto personRepDto = educationPaperPersonMapper.selectUserById(stuId);
String name= educationPaperTaskMapper.selectEducationPaperTaskNameByid(taskId);
EducationPaperTask educationPaperTask = educationPaperTaskMapper.selectEducationPaperTaskByTaskId(taskId);
info.setScore("0");
info.setTaskId(taskId);
info.setTaskType(educationPaperTask.getTaskType());
info.setExamStatus(status); info.setExamStatus(status);
info.setPaperNum("");
info.setStuId(stuId);
info.setUsername(personRepDto.getUsername());
info.setNickname(personRepDto.getNickname());
}else {
info.setExamStatus(status);
}
stringRedisTemplate.opsForValue().set(key, JsonUtils.toJsonString(info)); stringRedisTemplate.opsForValue().set(key, JsonUtils.toJsonString(info));

View File

@@ -1,5 +1,6 @@
package pc.exam.pp.module.exam.service.question; package pc.exam.pp.module.exam.service.question;
import com.alibaba.excel.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import pc.exam.pp.framework.common.pojo.PageResult; import pc.exam.pp.framework.common.pojo.PageResult;
@@ -110,8 +111,31 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
if (fileUploads!=null&&fileUploads.size()>0){ if (fileUploads!=null&&fileUploads.size()>0){
fileUploads.replaceAll(fileUpload -> { fileUploads.replaceAll(fileUpload -> {
// 设置文件名(如果文件名为空)
if (!StringUtils.isNotBlank(fileUpload.getFileName())) {
switch (fileUpload.getFileType()) {
case "0":
fileUpload.setFileName("素材");
break;
case "1":
fileUpload.setFileName("原始");
break;
case "2":
fileUpload.setFileName("结果");
break;
default:
fileUpload.setFileName(null);
// 可以设置一个默认文件名或者保持原样null 或空)
break;
}
}
if (StringUtils.isNotBlank(fileUpload.getFileName())) {
fileUpload.setFileName(null);
}
// 设置 fileId 和 quId
fileUpload.setFileId(IdUtils.simpleUUID()); fileUpload.setFileId(IdUtils.simpleUUID());
fileUpload.setQuId(uuid); fileUpload.setQuId(uuid);
return fileUpload; return fileUpload;
}); });
sysFileMapper.insertSysFileList(fileUploads); sysFileMapper.insertSysFileList(fileUploads);

View File

@@ -9,10 +9,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="quId" column="qu_id" /> <result property="quId" column="qu_id" />
<result property="url" column="url" /> <result property="url" column="url" />
<result property="fileType" column="file_type" /> <result property="fileType" column="file_type" />
<result property="fileName" column="file_name" />
</resultMap> </resultMap>
<sql id="selectSysFileVo"> <sql id="selectSysFileVo">
select file_id, qu_id, url, file_type from sys_file select file_id, qu_id, url, file_type ,file_name from sys_file
</sql> </sql>
<select id="selectSysFileList" parameterType="SysFileUpload" resultMap="SysFileResult"> <select id="selectSysFileList" parameterType="SysFileUpload" resultMap="SysFileResult">
@@ -47,20 +49,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="quId != null">qu_id,</if> <if test="quId != null">qu_id,</if>
<if test="url != null">url,</if> <if test="url != null">url,</if>
<if test="fileType != null">file_type,</if> <if test="fileType != null">file_type,</if>
<if test="fileName != null">file_name,</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="fileId != null">#{fileId},</if> <if test="fileId != null">#{fileId},</if>
<if test="quId != null">#{quId},</if> <if test="quId != null">#{quId},</if>
<if test="url != null">#{url},</if> <if test="url != null">#{url},</if>
<if test="fileType != null">#{fileType},</if> <if test="fileType != null">#{fileType},</if>
<if test="fileName != null">#{fileName},</if>
</trim> </trim>
</insert> </insert>
<insert id="insertSysFileList"> <insert id="insertSysFileList">
insert into sys_file insert into sys_file
(file_id, qu_id,url,file_type) (file_id, qu_id,url,file_type,file_name)
values values
<foreach collection="collection" separator="," item="item"> <foreach collection="collection" separator="," item="item">
(#{item.fileId},#{item.quId},#{item.url},#{item.fileType}) (#{item.fileId},#{item.quId},#{item.url},#{item.fileType},#{item.fileName})
</foreach> </foreach>
</insert> </insert>

View File

@@ -30,4 +30,5 @@ public class MysqlController {
// return CommonResult.success(mysqlServerice.Judgement( )); // 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 org.springframework.web.bind.annotation.RestController;
import pc.exam.pp.framework.common.pojo.CommonResult; import pc.exam.pp.framework.common.pojo.CommonResult;
import pc.exam.pp.module.judgement.controller.service.file.IFileServerice; import pc.exam.pp.module.judgement.controller.service.file.IFileServerice;
import pc.exam.pp.module.judgement.utils.EndStuMonitorUtils;
import java.io.IOException; 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.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import pc.exam.pp.framework.common.pojo.CommonResult; 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.service.wps_word.JudgementWpsWordService;
import pc.exam.pp.module.judgement.utils.wps_word.vo.WordVO; import pc.exam.pp.module.judgement.utils.wps_word.vo.WordVO;
@@ -29,8 +28,8 @@ public class WpsWordController {
@Autowired @Autowired
private JudgementWpsWordService judgementWpsWordService; private JudgementWpsWordService judgementWpsWordService;
@Resource // @Resource
JudgementWpsExcelService judgementWpsExcelService; // JudgementWpsExcelService judgementWpsExcelService;
/** /**
* wps word * wps word
* @return 判分 * @return 判分
@@ -43,9 +42,9 @@ public class WpsWordController {
* wps word * wps word
* @return 判分 * @return 判分
*/ */
@GetMapping("/run_wps_excel") // @GetMapping("/run_wps_excel")
public CommonResult<String> run_wps_excel(String path) throws Exception { // public CommonResult<String> run_wps_excel(String path) throws Exception {
return CommonResult.success(judgementWpsExcelService.ProgrammingWpsExcel(path)); // 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.SQLComparatorUtil;
import pc.exam.pp.module.judgement.controller.utils.Mysql.SqlFileProcessor; import pc.exam.pp.module.judgement.controller.utils.Mysql.SqlFileProcessor;
import pc.exam.pp.module.judgement.domain.SqlExecutionResult; import pc.exam.pp.module.judgement.domain.SqlExecutionResult;
import pc.exam.pp.module.judgement.utils.EndStuMonitorUtils;
import java.awt.*; import java.awt.*;
import java.io.*; 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);
}
}