【修改】监控管理,【新增】学生端试卷接口

This commit is contained in:
YOHO\20373
2025-05-05 21:19:14 +08:00
47 changed files with 722 additions and 45 deletions

View File

@@ -73,4 +73,11 @@ public interface ErrorCodeConstants {
// ========== 试卷参数 1-001-401-000 ==========
ErrorCode DEMO03_PAPER_SESSION_EXISTS = new ErrorCode(1_001_401_001, "请开启考场设置");
// ========== 监控管理 1-001-606-000 ==========
ErrorCode DEMO03_MONITOR_TIME_EXISTS = new ErrorCode(1-001-606-001, "该考试不在考场时间范围内!");
ErrorCode DEMO03_MONITOR_SESSION_EXISTS = new ErrorCode(1-001-606-002, "考生状态未在考试中!请联系管理员");
}

View File

@@ -124,6 +124,12 @@
<groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId> <!-- 文件客户端:文件类型的识别 -->
</dependency>
<dependency>
<groupId>pc.exam.gg</groupId>
<artifactId>exam-module-exam-biz</artifactId>
<version>2.4.2-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>

View File

@@ -66,6 +66,14 @@ public class FileController {
return success(true);
}
@PostMapping("/upload_stu")
@Operation(summary = "上传学生考试文件", description = "模式三后端上传文件带有学生ID")
public CommonResult<String> uploadStuFile(StuFileUploadReqVO uploadReqVO) throws Exception {
MultipartFile file = uploadReqVO.getFile();
String path = uploadReqVO.getPath();
return success(fileService.createStuFile(uploadReqVO.getStuId(), uploadReqVO.getPaperId(), file.getOriginalFilename(), path, IoUtil.readBytes(file.getInputStream())));
}
@GetMapping("/{configId}/get/**")
@PermitAll
@Operation(summary = "下载文件")

View File

@@ -0,0 +1,25 @@
package pc.exam.pp.module.infra.controller.admin.file.vo.file;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import org.springframework.web.multipart.MultipartFile;
@Schema(description = "管理后台 - 上传文件 Request VO")
@Data
public class StuFileUploadReqVO {
@Schema(description = "文件附件", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "文件附件不能为空")
private MultipartFile file;
@Schema(description = "文件附件", example = "examyuanma.png")
private String path;
@Schema(description = "学生ID")
private Long stuId;
@Schema(description = "试卷ID")
private String paperId;
}

View File

@@ -31,6 +31,16 @@ public interface FileService {
*/
String createFile(String name, String path, byte[] content);
/**
* 保存文件,并返回文件的访问路径
*
* @param name 文件名称
* @param path 文件路径
* @param content 文件内容
* @return 文件路径
*/
String createStuFile(Long stuId, String paperId, String name, String path, byte[] content);
/**
* 创建文件
*

View File

@@ -5,6 +5,8 @@ import cn.hutool.core.util.StrUtil;
import pc.exam.pp.framework.common.pojo.PageResult;
import pc.exam.pp.framework.common.util.io.FileUtils;
import pc.exam.pp.framework.common.util.object.BeanUtils;
import pc.exam.pp.module.exam.dal.dataobject.student.StuPaperFileDO;
import pc.exam.pp.module.exam.service.stu_paper_file.StuPaperFileService;
import pc.exam.pp.module.infra.framework.file.core.client.FileClient;
import pc.exam.pp.module.infra.framework.file.core.client.s3.FilePresignedUrlRespDTO;
import pc.exam.pp.module.infra.framework.file.core.utils.FileTypeUtils;
@@ -34,6 +36,9 @@ public class FileServiceImpl implements FileService {
@Resource
private FileMapper fileMapper;
@Resource
private StuPaperFileService stuPaperFileService;
@Override
public PageResult<FileDO> getFilePage(FilePageReqVO pageReqVO) {
return fileMapper.selectPage(pageReqVO);
@@ -69,6 +74,53 @@ public class FileServiceImpl implements FileService {
return url;
}
@Override
@SneakyThrows
public String createStuFile(Long stuId, String paperId, String name, String path, byte[] content) {
// 计算默认的 path 名
String type = FileTypeUtils.getMineType(content, name);
if (StrUtil.isEmpty(path)) {
path = FileUtils.generatePath(content, name);
}
// 如果 name 为空,则使用 path 填充
if (StrUtil.isEmpty(name)) {
name = path;
}
// 上传到文件存储器
FileClient client = fileConfigService.getMasterFileClient();
Assert.notNull(client, "客户端(master) 不能为空");
String url = client.upload(content, path, type);
// 保存到数据库
FileDO file = new FileDO();
file.setConfigId(client.getId());
file.setName(name);
file.setPath(path);
file.setUrl(url);
file.setType(type);
file.setSize(content.length);
fileMapper.insert(file);
// 需要更新学生表
// 1、先查询学生试卷 是否已经存在数据
StuPaperFileDO stuPaperFileDO = stuPaperFileService.findByStuIDAndPaperId(stuId, paperId);
if (stuPaperFileDO == null) {
// 说明没有上传过,需要新增进去
StuPaperFileDO stuPaperFile = new StuPaperFileDO();
stuPaperFile.setPaperId(paperId);
stuPaperFile.setStuId(stuId);
stuPaperFile.setUrl(url);
stuPaperFileService.insertStuPaperFile(stuPaperFile);
} else {
// 说明已经上传过判断url是否一致不一致得需要进行更新操作
if (!url.equals(stuPaperFileDO.getUrl())) {
stuPaperFileDO.setUrl(url);
stuPaperFileService.updateStuPaperFile(stuPaperFileDO);
}
}
return url;
}
@Override
public Long createFile(FileCreateReqVO createReqVO) {
FileDO file = BeanUtils.toBean(createReqVO, FileDO.class);