【新增】监控管理结束工具类,学生文件新增字段文件名
This commit is contained in:
@@ -7,7 +7,7 @@ import lombok.Data;
|
||||
@Data
|
||||
public class StuMonitorPaperEndVo {
|
||||
private String stuId;
|
||||
|
||||
private String paperId;
|
||||
private String score;
|
||||
private String taskId;
|
||||
|
||||
|
@@ -48,6 +48,8 @@ public class SysFileUpload extends BaseDO {
|
||||
// @Excel(name = "文件类型(0:素材,1:原始,2:结果)")
|
||||
private String fileType;
|
||||
|
||||
private String fileName;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@@ -12,6 +12,7 @@ import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
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.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.monitor.MonitorDO;
|
||||
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.question.ExamQuestionMapper;
|
||||
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.module.system.enums.ErrorCodeConstants.MONITOR_NOT_EXISTS;
|
||||
@@ -63,6 +66,9 @@ public class MonitorServiceImpl implements MonitorService {
|
||||
private EducationPaperParamMapper educationPaperParamMapper;
|
||||
@Resource
|
||||
private EducationPaperSessionMapper educationPaperSessionMapper;
|
||||
|
||||
// @Resource
|
||||
// private FileService fileService;
|
||||
@Override
|
||||
public String createMonitor(MonitorSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
@@ -107,10 +113,9 @@ public class MonitorServiceImpl implements MonitorService {
|
||||
@Override
|
||||
public Boolean getStuMonitor(StuMonitorPaperVo stuMonitorPaperVo) {
|
||||
String key = "userCache:"+stuMonitorPaperVo.getTaskId()+":" + stuMonitorPaperVo.getStuId();
|
||||
// MonitorDO info = JsonUtils.parseObject(stringRedisTemplate.opsForValue().get(key),MonitorDO.class);
|
||||
MonitorDO info=new MonitorDO();
|
||||
String uuid = IdUtils.simpleUUID();
|
||||
info.setMonitorId(uuid);
|
||||
MonitorDO info = JsonUtils.parseObject(stringRedisTemplate.opsForValue().get(key),MonitorDO.class);
|
||||
// MonitorDO info=new MonitorDO();
|
||||
|
||||
if (StringUtils.isNotBlank(stuMonitorPaperVo.getPaperId())){
|
||||
EducationPaper educationPaper = educationPaperMapper.selectEducationPaperByPaperId(stuMonitorPaperVo.getPaperId());
|
||||
String counts = educationPaper.getCounts();
|
||||
@@ -134,7 +139,7 @@ public class MonitorServiceImpl implements MonitorService {
|
||||
|
||||
if (info.getRemainingTime()==null){
|
||||
stringRedisTemplate.opsForValue().set("userCache:"+stuMonitorPaperVo.getTaskId()+":"+stuMonitorPaperVo.getStuId(), JsonUtils.toJsonString(info));
|
||||
monitorMapper.insert(info);
|
||||
monitorMapper.updateById(info);
|
||||
return true;
|
||||
}else {
|
||||
EducationPaperPerson educationPaperPerson = educationPaperPersonMapper.selectByTaskIdAndPersonId(stuMonitorPaperVo.getTaskId(), stuMonitorPaperVo.getStuId());
|
||||
@@ -173,7 +178,9 @@ public class MonitorServiceImpl implements MonitorService {
|
||||
|
||||
|
||||
//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);
|
||||
return true;
|
||||
}else {
|
||||
@@ -206,49 +213,57 @@ public class MonitorServiceImpl implements MonitorService {
|
||||
|
||||
@Override
|
||||
public void endStuMonitor(StuMonitorPaperEndVo stuMonitorPaperEndVo) {
|
||||
String key = "userCache:" + stuMonitorPaperEndVo.getTaskId()+":" +stuMonitorPaperEndVo.getStuId();
|
||||
String keychoice = "keychoice:"+stuMonitorPaperEndVo.getTaskId()+":" + stuMonitorPaperEndVo.getStuId();
|
||||
StuMonitorQuVo stuMonitorQuVo = JsonUtils.parseObject(stringRedisTemplate.opsForValue().get(keychoice),StuMonitorQuVo.class);
|
||||
|
||||
try {
|
||||
String fileName = "StuMonitorQu.txt";
|
||||
FileWriter writer = new FileWriter(fileName);
|
||||
writer.write(JsonUtils.toJsonString(stuMonitorQuVo));
|
||||
writer.close();
|
||||
//上传至
|
||||
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
|
||||
MonitorDO info = JsonUtils.parseObject(stringRedisTemplate.opsForValue().get(key),MonitorDO.class);
|
||||
EducationPaperParam educationPaperParam = educationPaperParamMapper.selectEducationPaperParamByTaskId(stuMonitorPaperEndVo.getTaskId());
|
||||
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 (Integer.parseInt(monitorDO.getScore()) <Integer.parseInt(stuMonitorPaperEndVo.getScore())){
|
||||
info.setScore(stuMonitorPaperEndVo.getScore());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
//练习下的任务 结束改为 代考
|
||||
if ("0".equals(educationPaperTask.getStatus())){
|
||||
info.setExamStatus("0");
|
||||
}else {
|
||||
info.setExamStatus("2");
|
||||
}
|
||||
//todo 这些都写成方法
|
||||
redisTemplate.delete(key);
|
||||
redisTemplate.delete(keychoice);
|
||||
monitorMapper.updateById(info);
|
||||
// String key = "userCache:" + stuMonitorPaperEndVo.getTaskId()+":" +stuMonitorPaperEndVo.getStuId();
|
||||
// String keychoice = "keychoice:"+stuMonitorPaperEndVo.getTaskId()+":" + stuMonitorPaperEndVo.getStuId();
|
||||
// StuMonitorQuVo stuMonitorQuVo = JsonUtils.parseObject(stringRedisTemplate.opsForValue().get(keychoice),StuMonitorQuVo.class);
|
||||
//
|
||||
// try {
|
||||
// String fileName = "StuMonitorQu.txt";
|
||||
// FileWriter writer = new FileWriter(fileName);
|
||||
// writer.write(JsonUtils.toJsonString(stuMonitorQuVo));
|
||||
// writer.close();
|
||||
// //上传至
|
||||
// String stuId = stuMonitorPaperEndVo.getStuId(); // 学生ID
|
||||
// String paperId = stuMonitorPaperEndVo.getPaperId(); // 试卷ID
|
||||
// String path = ""; // 存储路径(可选)
|
||||
// // 1. 生成 JSON 内容
|
||||
// String content = JsonUtils.toJsonString(stuMonitorQuVo);
|
||||
//
|
||||
// // 2. 转换为 UTF-8 字节数组(关键修复!)
|
||||
// byte[] bytes = content.getBytes(StandardCharsets.UTF_8);
|
||||
//// String fileurl= fileService.createFile(fileName,path, bytes);
|
||||
//// System.out.println(fileurl);
|
||||
//
|
||||
// } catch (IOException e) {
|
||||
// System.out.println(e);
|
||||
// }
|
||||
//
|
||||
// MonitorDO info = JsonUtils.parseObject(stringRedisTemplate.opsForValue().get(key),MonitorDO.class);
|
||||
// EducationPaperParam educationPaperParam = educationPaperParamMapper.selectEducationPaperParamByTaskId(stuMonitorPaperEndVo.getTaskId());
|
||||
// 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 (Integer.parseInt(monitorDO.getScore()) <Integer.parseInt(stuMonitorPaperEndVo.getScore())){
|
||||
// info.setScore(stuMonitorPaperEndVo.getScore());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// }
|
||||
// //练习下的任务 结束改为 代考 其他为结束
|
||||
// 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);
|
||||
MonitorDO info = JsonUtils.parseObject(stringRedisTemplate.opsForValue().get(key),MonitorDO.class);
|
||||
|
||||
info.setExamStatus(status);
|
||||
|
||||
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.setPaperNum("");
|
||||
info.setStuId(stuId);
|
||||
info.setUsername(personRepDto.getUsername());
|
||||
info.setNickname(personRepDto.getNickname());
|
||||
}else {
|
||||
info.setExamStatus(status);
|
||||
}
|
||||
|
||||
|
||||
stringRedisTemplate.opsForValue().set(key, JsonUtils.toJsonString(info));
|
||||
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package pc.exam.pp.module.exam.service.question;
|
||||
|
||||
import com.alibaba.excel.util.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import pc.exam.pp.framework.common.pojo.PageResult;
|
||||
@@ -110,8 +111,31 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
|
||||
|
||||
if (fileUploads!=null&&fileUploads.size()>0){
|
||||
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.setQuId(uuid);
|
||||
|
||||
return fileUpload;
|
||||
});
|
||||
sysFileMapper.insertSysFileList(fileUploads);
|
||||
|
@@ -9,10 +9,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="quId" column="qu_id" />
|
||||
<result property="url" column="url" />
|
||||
<result property="fileType" column="file_type" />
|
||||
<result property="fileName" column="file_name" />
|
||||
|
||||
</resultMap>
|
||||
|
||||
<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>
|
||||
|
||||
<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="url != null">url,</if>
|
||||
<if test="fileType != null">file_type,</if>
|
||||
<if test="fileName != null">file_name,</if>
|
||||
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="fileId != null">#{fileId},</if>
|
||||
<if test="quId != null">#{quId},</if>
|
||||
<if test="url != null">#{url},</if>
|
||||
<if test="fileType != null">#{fileType},</if>
|
||||
<if test="fileName != null">#{fileName},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
<insert id="insertSysFileList">
|
||||
insert into sys_file
|
||||
(file_id, qu_id,url,file_type)
|
||||
(file_id, qu_id,url,file_type,file_name)
|
||||
values
|
||||
<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>
|
||||
</insert>
|
||||
|
||||
|
@@ -30,4 +30,5 @@ public class MysqlController {
|
||||
// return CommonResult.success(mysqlServerice.Judgement( ));
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
@@ -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());
|
||||
}
|
||||
|
||||
}
|
@@ -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;
|
||||
|
||||
|
@@ -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));
|
||||
// }
|
||||
|
||||
}
|
||||
|
@@ -14,6 +14,4 @@ public interface IMysqlServerice {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@@ -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 {
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 将指定内容追加写入到指定文件中。
|
||||
*
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
package pc.exam.pp.module.judgement.controller.service.mysql;
|
||||
|
||||
public interface testservice {
|
||||
boolean test();
|
||||
|
||||
|
||||
}
|
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user