2026-01-16 16:37:03 +08:00
|
|
|
package com.ai.da.controller;
|
|
|
|
|
|
|
|
|
|
import com.ai.da.common.response.Response;
|
2026-01-20 15:58:27 +08:00
|
|
|
import com.ai.da.model.dto.*;
|
2026-01-16 16:37:03 +08:00
|
|
|
import com.ai.da.model.dto.ContestantDTO;
|
2026-01-20 13:14:50 +08:00
|
|
|
import com.ai.da.model.vo.CheckOTPVO;
|
2026-01-16 16:37:03 +08:00
|
|
|
import com.ai.da.service.GlobalAwardService;
|
2026-01-20 15:58:27 +08:00
|
|
|
import com.ai.da.service.upload.UploadService;
|
|
|
|
|
import com.ai.da.service.upload.UploadTask;
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import io.swagger.annotations.ApiParam;
|
2026-01-16 16:37:03 +08:00
|
|
|
import jakarta.annotation.Resource;
|
2026-02-04 14:45:11 +08:00
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
2026-01-16 16:37:03 +08:00
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/api/global-award")
|
2026-01-20 15:58:27 +08:00
|
|
|
@Api(tags = "全球奖项API", description = "全球奖项大赛管理和文件上传")
|
2026-01-16 16:37:03 +08:00
|
|
|
public class GlobalAwardController {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private GlobalAwardService globalAwardService;
|
|
|
|
|
|
2026-01-20 15:58:27 +08:00
|
|
|
@Resource
|
|
|
|
|
private UploadService uploadService;
|
|
|
|
|
|
|
|
|
|
// @PostMapping("/uploads/pdf")
|
|
|
|
|
// public Response<String> uploadPdf(@RequestParam("file") MultipartFile file,
|
|
|
|
|
// @RequestParam(value = "email", required = false) String email) throws Exception {
|
|
|
|
|
// return Response.success(globalAwardService.uploadPdf(file, email));
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// @PostMapping("/uploads/video")
|
|
|
|
|
// public Response<String> uploadVideo(@RequestParam("file") MultipartFile file,
|
|
|
|
|
// @RequestParam(value = "email", required = false) String email) throws Exception {
|
|
|
|
|
// return Response.success(globalAwardService.uploadVideo(file, email));
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// ===== 新增分片上传接口 =====
|
|
|
|
|
|
|
|
|
|
// ===== PDF分片上传接口 =====
|
|
|
|
|
|
|
|
|
|
/** 初始化PDF上传任务 */
|
|
|
|
|
@PostMapping("/uploads/pdf/init")
|
|
|
|
|
@ApiOperation(value = "初始化PDF上传", notes = "创建新的PDF上传任务并返回上传参数")
|
|
|
|
|
public Response<UploadInitResponse> initPdfUpload(@ApiParam(value = "PDF上传初始化请求", required = true) @RequestBody UploadInitRequest request) {
|
|
|
|
|
UploadTask uploadTask = uploadService.initPdfUpload(request);
|
|
|
|
|
return Response.success(UploadInitResponse.builder()
|
|
|
|
|
.uploadId(uploadTask.getUploadId())
|
|
|
|
|
.chunkSize(uploadTask.getChunkSize())
|
|
|
|
|
.totalChunks(uploadTask.getTotalChunks())
|
|
|
|
|
.expiresAt(uploadTask.getExpiresAt())
|
|
|
|
|
.build());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 上传PDF分片 */
|
|
|
|
|
@PostMapping("/uploads/pdf/chunk")
|
|
|
|
|
@ApiOperation(value = "上传PDF分片", notes = "上传PDF文件的单个分片")
|
|
|
|
|
public Response<UploadChunkResponse> uploadPdfChunk(
|
|
|
|
|
@ApiParam(value = "PDF文件分片", required = true) @RequestParam("chunk") MultipartFile chunk,
|
|
|
|
|
@ApiParam(value = "上传任务ID", required = true) @RequestParam("uploadId") String uploadId,
|
|
|
|
|
@ApiParam(value = "分片索引(从0开始)", required = true) @RequestParam("chunkIndex") int chunkIndex,
|
|
|
|
|
@ApiParam(value = "分片总数", required = true) @RequestParam("totalChunks") int totalChunks) {
|
|
|
|
|
|
|
|
|
|
UploadChunkResponse uploadChunkResponse = uploadService.uploadPdfChunk(uploadId, chunk, chunkIndex, totalChunks);
|
|
|
|
|
return Response.success(uploadChunkResponse);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 完成PDF上传 */
|
|
|
|
|
@PostMapping("/uploads/pdf/complete")
|
|
|
|
|
@ApiOperation(value = "完成PDF上传", notes = "完成PDF上传并合并所有分片")
|
|
|
|
|
public Response<UploadCompleteResponse> completePdfUpload(@ApiParam(value = "PDF上传完成请求", required = true) @RequestBody UploadCompleteRequest request) {
|
|
|
|
|
UploadCompleteResponse uploadCompleteResponse = uploadService.completePdfUpload(
|
|
|
|
|
request.getUploadId(),
|
|
|
|
|
request.getFileName(),
|
2026-01-21 14:34:43 +08:00
|
|
|
request.getTotalSize(),
|
|
|
|
|
request.getEmail(),
|
|
|
|
|
request.getSecureToken());
|
2026-01-20 15:58:27 +08:00
|
|
|
return Response.success(uploadCompleteResponse);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 查询PDF上传状态 */
|
|
|
|
|
@GetMapping("/uploads/pdf/status/{uploadId}")
|
|
|
|
|
@ApiOperation(value = "查询PDF上传状态", notes = "获取PDF上传任务的当前状态")
|
|
|
|
|
public Response<UploadStatusResponse> getPdfUploadStatus(@ApiParam(value = "上传任务ID", required = true) @PathVariable String uploadId) {
|
|
|
|
|
UploadStatusResponse pdfUploadStatus = uploadService.getPdfUploadStatus(uploadId);
|
|
|
|
|
return Response.success(pdfUploadStatus);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ===== 视频分片上传接口 =====
|
|
|
|
|
|
|
|
|
|
/** 初始化视频上传任务 */
|
|
|
|
|
@PostMapping("/uploads/video/init")
|
|
|
|
|
@ApiOperation(value = "初始化视频上传", notes = "创建新的视频上传任务并返回上传参数")
|
|
|
|
|
public Response<UploadInitResponse> initVideoUpload(@ApiParam(value = "视频上传初始化请求", required = true) @RequestBody UploadInitRequest request) {
|
|
|
|
|
UploadTask uploadTask = uploadService.initVideoUpload(request);
|
|
|
|
|
return Response.success(UploadInitResponse.builder()
|
|
|
|
|
.uploadId(uploadTask.getUploadId())
|
|
|
|
|
.chunkSize(uploadTask.getChunkSize())
|
|
|
|
|
.totalChunks(uploadTask.getTotalChunks())
|
|
|
|
|
.expiresAt(uploadTask.getExpiresAt())
|
|
|
|
|
.build());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 上传视频分片 */
|
|
|
|
|
@PostMapping("/uploads/video/chunk")
|
|
|
|
|
@ApiOperation(value = "上传视频分片", notes = "上传视频文件的单个分片")
|
|
|
|
|
public Response<UploadChunkResponse> uploadVideoChunk(
|
|
|
|
|
@ApiParam(value = "视频文件分片", required = true) @RequestParam("chunk") MultipartFile chunk,
|
|
|
|
|
@ApiParam(value = "上传任务ID", required = true) @RequestParam("uploadId") String uploadId,
|
|
|
|
|
@ApiParam(value = "分片索引(从0开始)", required = true) @RequestParam("chunkIndex") int chunkIndex,
|
|
|
|
|
@ApiParam(value = "分片总数", required = true) @RequestParam("totalChunks") int totalChunks) {
|
|
|
|
|
|
|
|
|
|
UploadChunkResponse uploadChunkResponse = uploadService.uploadVideoChunk(uploadId, chunk, chunkIndex, totalChunks);
|
|
|
|
|
return Response.success(uploadChunkResponse);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 完成视频上传 */
|
|
|
|
|
@PostMapping("/uploads/video/complete")
|
|
|
|
|
@ApiOperation(value = "完成视频上传", notes = "完成视频上传并合并所有分片")
|
|
|
|
|
public Response<UploadCompleteResponse> completeVideoUpload(@ApiParam(value = "视频上传完成请求", required = true) @RequestBody UploadCompleteRequest request) {
|
|
|
|
|
UploadCompleteResponse uploadCompleteResponse = uploadService.completeVideoUpload(
|
|
|
|
|
request.getUploadId(),
|
|
|
|
|
request.getFileName(),
|
2026-01-21 14:34:43 +08:00
|
|
|
request.getTotalSize(),
|
|
|
|
|
request.getEmail(),
|
|
|
|
|
request.getSecureToken());
|
2026-01-20 15:58:27 +08:00
|
|
|
return Response.success(uploadCompleteResponse);
|
2026-01-16 16:37:03 +08:00
|
|
|
}
|
|
|
|
|
|
2026-01-20 15:58:27 +08:00
|
|
|
/** 查询视频上传状态 */
|
|
|
|
|
@GetMapping("/uploads/video/status/{uploadId}")
|
|
|
|
|
@ApiOperation(value = "查询视频上传状态", notes = "获取视频上传任务的当前状态")
|
|
|
|
|
public Response<UploadStatusResponse> getVideoUploadStatus(@ApiParam(value = "上传任务ID", required = true) @PathVariable String uploadId) {
|
|
|
|
|
UploadStatusResponse videoUploadStatus = uploadService.getVideoUploadStatus(uploadId);
|
|
|
|
|
return Response.success(videoUploadStatus);
|
2026-01-16 16:37:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/contestants/save")
|
2026-01-20 15:58:27 +08:00
|
|
|
@ApiOperation(value = "保存参赛者信息", notes = "保存或更新参赛者信息及已上传的文件")
|
|
|
|
|
public Response<Map<String,Object>> submit(@ApiParam(value = "参赛者信息", required = true) @RequestBody ContestantDTO request) {
|
2026-01-16 16:37:03 +08:00
|
|
|
return Response.success(globalAwardService.saveContestant(request));
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-21 14:59:41 +08:00
|
|
|
@GetMapping("/contestants/{id}")
|
|
|
|
|
@ApiOperation(value = "根据id查询参赛者", notes = "根据id获取参赛者信息")
|
|
|
|
|
public Response<ContestantDTO> getContestantByID(@ApiParam(value = "参赛者id", required = true) @PathVariable("id") String id) {
|
|
|
|
|
ContestantDTO dto = globalAwardService.getContestantByID(id);
|
|
|
|
|
return Response.success(dto);
|
|
|
|
|
}
|
2026-01-20 13:14:50 +08:00
|
|
|
|
|
|
|
|
@GetMapping("/checkEmail")
|
|
|
|
|
public Response<String> checkEmail(@RequestParam("email") String email) {
|
|
|
|
|
globalAwardService.checkEmail(email);
|
|
|
|
|
return Response.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping("/checkCode")
|
2026-01-21 14:13:33 +08:00
|
|
|
public Response<CheckOTPVO> checkCode(@RequestParam("email") String email, @RequestParam("code") String code) {
|
|
|
|
|
return Response.success(globalAwardService.checkCode(email, code));
|
2026-01-20 13:14:50 +08:00
|
|
|
}
|
|
|
|
|
|
2026-02-04 13:41:09 +08:00
|
|
|
@GetMapping("/contestants/export")
|
|
|
|
|
@ApiOperation(value = "导出参赛者列表为Excel", notes = "导出所有参赛者信息为xlsx并触发下载")
|
2026-02-04 14:45:11 +08:00
|
|
|
public void exportContestants(HttpServletResponse response) throws Exception {
|
|
|
|
|
byte[] data = globalAwardService.exportContestants();
|
|
|
|
|
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
|
|
response.setHeader("Content-Disposition", "attachment; filename=\"contestants.xlsx\"");
|
|
|
|
|
response.setContentLength(data.length);
|
|
|
|
|
response.getOutputStream().write(data);
|
|
|
|
|
response.getOutputStream().flush();
|
2026-02-04 13:41:09 +08:00
|
|
|
}
|
|
|
|
|
|
2026-02-09 10:21:40 +08:00
|
|
|
@PostMapping("/contestants/export/files")
|
|
|
|
|
@ApiOperation(value = "导出参赛者文件到本地", notes = "根据参赛者编号范围导出PDF和视频文件到本地temp/uploads/contestants目录")
|
|
|
|
|
public Response<Integer> exportContestantFiles(@ApiParam(value = "参赛者文件导出请求", required = true) @RequestBody ContestantExportRequest request) throws Exception {
|
|
|
|
|
int exportedCount = globalAwardService.exportContestantFiles(request.getMinContestantNumber(), request.getMaxContestantNumber());
|
|
|
|
|
return Response.success(exportedCount);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 10:22:43 +08:00
|
|
|
@GetMapping("/contestants/count")
|
|
|
|
|
@ApiOperation(value = "查询参赛者总数", notes = "查询数据库中参赛者的总数量")
|
|
|
|
|
public Response<Long> getContestantCount() {
|
|
|
|
|
return Response.success(globalAwardService.getContestantCount());
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-16 16:37:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|