2026-04-27 10:27:57 +08:00
|
|
|
package com.labelsys.backend.controller;
|
|
|
|
|
|
|
|
|
|
import com.labelsys.backend.common.Result;
|
|
|
|
|
import com.labelsys.backend.context.UserContext;
|
|
|
|
|
import com.labelsys.backend.dto.common.PageResult;
|
2026-05-05 18:40:44 +08:00
|
|
|
import com.labelsys.backend.dto.request.SaveImageBboxRequest;
|
2026-04-27 10:27:57 +08:00
|
|
|
import com.labelsys.backend.dto.request.SourceResourcePageQuery;
|
|
|
|
|
import com.labelsys.backend.dto.request.SourceUploadRequest;
|
2026-05-05 18:40:44 +08:00
|
|
|
import com.labelsys.backend.dto.response.ImageBboxResponse;
|
2026-04-27 10:27:57 +08:00
|
|
|
import com.labelsys.backend.dto.response.SourceResourceResponse;
|
|
|
|
|
import com.labelsys.backend.dto.response.SourceUploadResponse;
|
2026-05-05 18:40:44 +08:00
|
|
|
import com.labelsys.backend.entity.SourceResource;
|
2026-04-27 10:27:57 +08:00
|
|
|
import com.labelsys.backend.service.SourceResourceService;
|
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
2026-04-27 16:25:39 +08:00
|
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
2026-04-27 10:27:57 +08:00
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
2026-05-05 18:40:44 +08:00
|
|
|
import jakarta.validation.Valid;
|
2026-04-27 10:27:57 +08:00
|
|
|
import lombok.RequiredArgsConstructor;
|
2026-04-27 16:25:39 +08:00
|
|
|
import org.springdoc.core.annotations.ParameterObject;
|
2026-05-05 18:40:44 +08:00
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
|
|
import org.springframework.http.ResponseEntity;
|
2026-04-27 10:27:57 +08:00
|
|
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
2026-05-05 18:40:44 +08:00
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
2026-04-27 10:27:57 +08:00
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
@Tag(name = "资源管理")
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/api/source-resources")
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
public class SourceResourceController {
|
|
|
|
|
|
|
|
|
|
private final SourceResourceService sourceResourceService;
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "上传资源")
|
|
|
|
|
@PostMapping("/upload")
|
2026-04-27 16:25:39 +08:00
|
|
|
public Result<SourceUploadResponse> upload(@ParameterObject @ModelAttribute SourceUploadRequest request) {
|
2026-04-27 10:27:57 +08:00
|
|
|
return Result.success(sourceResourceService.upload(UserContext.requireUser(), request));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "分页查询资源")
|
|
|
|
|
@GetMapping
|
2026-05-05 18:40:44 +08:00
|
|
|
public Result<PageResult<SourceResourceResponse>> page(
|
|
|
|
|
@ParameterObject @ModelAttribute SourceResourcePageQuery query) {
|
2026-04-27 10:27:57 +08:00
|
|
|
return Result.success(sourceResourceService.pageResources(UserContext.requireUser(), query));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "查询资源详情")
|
|
|
|
|
@GetMapping("/{id}")
|
2026-04-27 16:25:39 +08:00
|
|
|
public Result<SourceResourceResponse> detail(
|
2026-05-05 18:40:44 +08:00
|
|
|
@Parameter(description = "资源ID", example = "191000000000000101")
|
|
|
|
|
@PathVariable Long id
|
2026-04-27 16:25:39 +08:00
|
|
|
) {
|
2026-04-27 10:27:57 +08:00
|
|
|
return Result.success(sourceResourceService.getResource(UserContext.requireUser(), id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "删除资源")
|
|
|
|
|
@DeleteMapping("/{id}")
|
2026-04-27 16:25:39 +08:00
|
|
|
public Result<Void> delete(
|
2026-05-05 18:40:44 +08:00
|
|
|
@Parameter(description = "资源ID", example = "191000000000000101")
|
|
|
|
|
@PathVariable Long id
|
2026-04-27 16:25:39 +08:00
|
|
|
) {
|
2026-04-27 10:27:57 +08:00
|
|
|
sourceResourceService.deleteResource(UserContext.requireUser(), id);
|
|
|
|
|
return Result.success();
|
|
|
|
|
}
|
2026-05-05 18:40:44 +08:00
|
|
|
|
|
|
|
|
@Operation(summary = "下载图片资源")
|
|
|
|
|
@GetMapping("/{id}/download")
|
|
|
|
|
public ResponseEntity<byte[]> downloadImage(
|
|
|
|
|
@Parameter(description = "资源ID", example = "191000000000000101")
|
|
|
|
|
@PathVariable Long id
|
|
|
|
|
) {
|
|
|
|
|
var currentUser = UserContext.requireUser();
|
|
|
|
|
byte[] imageData = sourceResourceService.downloadImage(currentUser, id);
|
|
|
|
|
|
|
|
|
|
// 获取资源信息以确定Content-Type
|
|
|
|
|
SourceResource resource = sourceResourceService.getResourceEntity(id);
|
|
|
|
|
String contentType = sourceResourceService.getImageContentType(resource);
|
|
|
|
|
|
|
|
|
|
return ResponseEntity.ok()
|
|
|
|
|
.header(HttpHeaders.CONTENT_TYPE, contentType)
|
|
|
|
|
.header(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=\"" + resource.getResourceName() + "\"")
|
|
|
|
|
.body(imageData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 添加新接口
|
|
|
|
|
@Operation(summary = "查询图片资源BBOX标注")
|
|
|
|
|
@GetMapping("/{id}/bbox")
|
|
|
|
|
public Result<ImageBboxResponse> getImageBbox(
|
|
|
|
|
@Parameter(description = "资源ID", example = "191000000000000101")
|
|
|
|
|
@PathVariable Long id
|
|
|
|
|
) {
|
|
|
|
|
return Result.success(sourceResourceService.getImageBbox(UserContext.requireUser(), id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "保存图片资源BBOX标注")
|
|
|
|
|
@PostMapping("/{id}/bbox")
|
|
|
|
|
public Result<ImageBboxResponse> saveImageBbox(
|
|
|
|
|
@Parameter(description = "资源ID", example = "191000000000000101")
|
|
|
|
|
@PathVariable Long id,
|
|
|
|
|
@Valid @RequestBody SaveImageBboxRequest request
|
|
|
|
|
) {
|
|
|
|
|
return Result.success(sourceResourceService.saveImageBbox(UserContext.requireUser(), id, request));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "删除图片资源BBOX标注")
|
|
|
|
|
@DeleteMapping("/{id}/bbox")
|
|
|
|
|
public Result<Void> deleteImageBbox(
|
|
|
|
|
@Parameter(description = "资源ID", example = "191000000000000101")
|
|
|
|
|
@PathVariable Long id
|
|
|
|
|
) {
|
|
|
|
|
sourceResourceService.deleteImageBbox(UserContext.requireUser(), id);
|
|
|
|
|
return Result.success();
|
|
|
|
|
}
|
|
|
|
|
}
|