新增接口:图片分割
This commit is contained in:
@@ -18,7 +18,10 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@Api(tags = "collection模块")
|
||||
@@ -106,4 +109,25 @@ public class ElementController {
|
||||
return Response.success();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "图片分割")
|
||||
@PostMapping("/imageSegmentation")
|
||||
public Response<List<CollectionElementVO>> selectedImageSeg(
|
||||
@RequestPart(value = "files", required = false) MultipartFile[] files,
|
||||
@RequestParam(value = "type", required = false) @Pattern(regexp = "sketch|product", message = "类型必须是sketch或product") String type,
|
||||
@RequestParam(value = "id", required = false) Long id) {
|
||||
// 过滤空文件
|
||||
List<MultipartFile> nonEmptyFiles = Arrays.stream(files)
|
||||
.filter(file -> !file.isEmpty())
|
||||
.collect(Collectors.toList());
|
||||
// 参数校验
|
||||
if ((nonEmptyFiles.isEmpty()) && id == null) {
|
||||
throw new BusinessException("必须提供文件上传或ID");
|
||||
}
|
||||
if (!nonEmptyFiles.isEmpty() && id != null) {
|
||||
throw new BusinessException("不能同时提供文件上传和ID");
|
||||
}
|
||||
|
||||
return Response.success(collectionElementService.selectedImageSeg(nonEmptyFiles, id, type));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user