【新增】监控管理结束工具类,学生文件新增字段文件名
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>
|
||||
|
||||
|
Reference in New Issue
Block a user