2026-04-14 13:47:38 +08:00
|
|
|
|
package com.label.controller;
|
2026-04-09 15:21:32 +08:00
|
|
|
|
|
|
|
|
|
|
import com.label.common.result.PageResult;
|
|
|
|
|
|
import com.label.common.result.Result;
|
|
|
|
|
|
import com.label.common.shiro.TokenPrincipal;
|
2026-04-14 13:39:24 +08:00
|
|
|
|
import com.label.dto.SourceResponse;
|
2026-04-14 13:45:15 +08:00
|
|
|
|
import com.label.service.SourceService;
|
2026-04-12 00:15:59 +08:00
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
2026-04-09 15:21:32 +08:00
|
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
|
import org.apache.shiro.authz.annotation.RequiresRoles;
|
|
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2026-04-14 13:31:50 +08:00
|
|
|
|
* 原始资料管理接口。
|
|
|
|
|
|
*
|
|
|
|
|
|
* 权限设计:
|
|
|
|
|
|
* - 上传 / 列表 / 详情:UPLOADER 及以上角色(含 ANNOTATOR、REVIEWER、ADMIN)
|
|
|
|
|
|
* - 删除:仅 ADMIN
|
2026-04-09 15:21:32 +08:00
|
|
|
|
*/
|
2026-04-14 13:31:50 +08:00
|
|
|
|
@Tag(name = "资料管理", description = "原始资料上传、查询和删除")
|
2026-04-09 15:21:32 +08:00
|
|
|
|
@RestController
|
|
|
|
|
|
@RequestMapping("/api/source")
|
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
|
public class SourceController {
|
|
|
|
|
|
|
|
|
|
|
|
private final SourceService sourceService;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2026-04-14 13:31:50 +08:00
|
|
|
|
* 上传文件(multipart/form-data)。
|
|
|
|
|
|
* 返回 201 Created + 资料摘要。
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Operation(summary = "上传原始资料", description = "dataType: text,image, video")
|
2026-04-09 15:21:32 +08:00
|
|
|
|
@PostMapping("/upload")
|
|
|
|
|
|
@RequiresRoles("UPLOADER")
|
2026-04-09 16:18:39 +08:00
|
|
|
|
@ResponseStatus(HttpStatus.CREATED)
|
|
|
|
|
|
public Result<SourceResponse> upload(
|
2026-04-09 15:21:32 +08:00
|
|
|
|
@RequestParam("file") MultipartFile file,
|
|
|
|
|
|
@RequestParam("dataType") String dataType,
|
|
|
|
|
|
HttpServletRequest request) {
|
|
|
|
|
|
TokenPrincipal principal = (TokenPrincipal) request.getAttribute("__token_principal__");
|
2026-04-09 16:18:39 +08:00
|
|
|
|
return Result.success(sourceService.upload(file, dataType, principal));
|
2026-04-09 15:21:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2026-04-14 13:31:50 +08:00
|
|
|
|
* 分页查询资料列表。
|
|
|
|
|
|
* UPLOADER 只见自己的资料;ADMIN 见全公司资料。
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Operation(summary = "分页查询资料列表")
|
2026-04-09 15:21:32 +08:00
|
|
|
|
@GetMapping("/list")
|
|
|
|
|
|
@RequiresRoles("UPLOADER")
|
|
|
|
|
|
public Result<PageResult<SourceResponse>> list(
|
|
|
|
|
|
@RequestParam(defaultValue = "1") int page,
|
|
|
|
|
|
@RequestParam(defaultValue = "20") int pageSize,
|
|
|
|
|
|
@RequestParam(required = false) String dataType,
|
|
|
|
|
|
@RequestParam(required = false) String status,
|
|
|
|
|
|
HttpServletRequest request) {
|
|
|
|
|
|
TokenPrincipal principal = (TokenPrincipal) request.getAttribute("__token_principal__");
|
|
|
|
|
|
return Result.success(sourceService.list(page, pageSize, dataType, status, principal));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2026-04-14 13:31:50 +08:00
|
|
|
|
* 查询资料详情(含 15 分钟预签名下载链接)。
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Operation(summary = "查询资料详情")
|
2026-04-09 15:21:32 +08:00
|
|
|
|
@GetMapping("/{id}")
|
|
|
|
|
|
@RequiresRoles("UPLOADER")
|
|
|
|
|
|
public Result<SourceResponse> findById(@PathVariable Long id) {
|
|
|
|
|
|
return Result.success(sourceService.findById(id));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2026-04-14 13:31:50 +08:00
|
|
|
|
* 删除资料(仅 PENDING 状态可删)。
|
|
|
|
|
|
* 同步删除 RustFS 文件及 DB 记录。
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Operation(summary = "删除资料")
|
2026-04-09 15:21:32 +08:00
|
|
|
|
@DeleteMapping("/{id}")
|
|
|
|
|
|
@RequiresRoles("ADMIN")
|
|
|
|
|
|
public Result<Void> delete(@PathVariable Long id, HttpServletRequest request) {
|
|
|
|
|
|
TokenPrincipal principal = (TokenPrincipal) request.getAttribute("__token_principal__");
|
|
|
|
|
|
sourceService.delete(id, principal.getCompanyId());
|
|
|
|
|
|
return Result.success(null);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|