73 lines
1.9 KiB
Java
73 lines
1.9 KiB
Java
package com.music.controller;
|
||
|
||
import com.music.common.Result;
|
||
import com.music.dto.DedupRequest;
|
||
import com.music.exception.BusinessException;
|
||
import com.music.service.DedupService;
|
||
import org.springframework.validation.annotation.Validated;
|
||
import org.springframework.web.bind.annotation.*;
|
||
|
||
import javax.validation.Valid;
|
||
import java.util.UUID;
|
||
|
||
/**
|
||
* 音乐去重任务控制器
|
||
*/
|
||
@RestController
|
||
@RequestMapping("/api/dedup")
|
||
@Validated
|
||
public class DedupController {
|
||
|
||
private final DedupService dedupService;
|
||
|
||
public DedupController(DedupService dedupService) {
|
||
this.dedupService = dedupService;
|
||
}
|
||
|
||
/**
|
||
* 启动音乐去重任务
|
||
*/
|
||
@PostMapping("/start")
|
||
public Result<StartResponse> start(@Valid @RequestBody DedupRequest request) {
|
||
// 模式校验
|
||
if (!"copy".equalsIgnoreCase(request.getMode()) &&
|
||
!"move".equalsIgnoreCase(request.getMode())) {
|
||
throw new BusinessException(400, "模式参数错误,必须是 copy 或 move");
|
||
}
|
||
|
||
// 至少启用一种策略
|
||
if (!request.isUseMd5() && !request.isUseMetadata()) {
|
||
throw new BusinessException(400, "至少需要启用一种去重策略(MD5 或元数据匹配)");
|
||
}
|
||
|
||
String taskId = UUID.randomUUID().toString();
|
||
dedupService.dedup(
|
||
taskId,
|
||
request.getLibraryDir(),
|
||
request.getTrashDir(),
|
||
request.isUseMd5(),
|
||
request.isUseMetadata(),
|
||
request.getMode()
|
||
);
|
||
|
||
return Result.success(new StartResponse(taskId));
|
||
}
|
||
|
||
public static class StartResponse {
|
||
private String taskId;
|
||
|
||
public StartResponse(String taskId) {
|
||
this.taskId = taskId;
|
||
}
|
||
|
||
public String getTaskId() {
|
||
return taskId;
|
||
}
|
||
|
||
public void setTaskId(String taskId) {
|
||
this.taskId = taskId;
|
||
}
|
||
}
|
||
}
|
||
|