文件上传校验;部分演示代码废弃
This commit is contained in:
@@ -4,6 +4,7 @@ import com.aida.lanecarford.common.ApiResponse;
|
||||
import com.aida.lanecarford.dto.CustomerPhotoDto;
|
||||
import com.aida.lanecarford.entity.CustomerPhoto;
|
||||
import com.aida.lanecarford.service.CustomerPhotoService;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -24,7 +25,7 @@ public class CustomerPhotoController {
|
||||
private final CustomerPhotoService customerPhotoService;
|
||||
|
||||
@PostMapping("/upload")
|
||||
public ApiResponse<CustomerPhoto> upload(@ModelAttribute CustomerPhotoDto customerPhotoDto) {
|
||||
public ApiResponse<CustomerPhoto> upload(@Valid @ModelAttribute CustomerPhotoDto customerPhotoDto) {
|
||||
CustomerPhoto customerPhoto = customerPhotoService.upload(customerPhotoDto);
|
||||
return ApiResponse.success(customerPhoto);
|
||||
}
|
||||
|
||||
@@ -92,28 +92,28 @@ public class TryOnEffectController {
|
||||
return ApiResponse.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 首页默认图换脸演示
|
||||
*/
|
||||
@Operation(summary = "首页点击换脸", description = "传入上传顾客照片后得到的ID")
|
||||
@PostMapping("/reFace")
|
||||
public ApiResponse<String> reFace(@Nullable @RequestParam Long customerPhotoId,
|
||||
@Nullable @RequestParam String prompt,
|
||||
@Nullable @RequestParam String tryonUrl) {
|
||||
if (customerPhotoId == null&& StringUtil.isNullOrEmpty(prompt)&& StringUtil.isNullOrEmpty(tryonUrl)){
|
||||
return ApiResponse.error("system error:Parameter null");
|
||||
}
|
||||
String result = "";
|
||||
if (StringUtil.isNullOrEmpty(prompt)){
|
||||
//换脸
|
||||
result = tryOnEffectService.reFace(customerPhotoId);
|
||||
}else {
|
||||
if (StringUtil.isNullOrEmpty(tryonUrl)){
|
||||
return ApiResponse.error("system error:Parameter null");
|
||||
}
|
||||
//根据提示词修改图像
|
||||
result = tryOnEffectService.generateUrl(prompt,tryonUrl);
|
||||
}
|
||||
return ApiResponse.success("操作成功",result);
|
||||
}
|
||||
// /**
|
||||
// * 首页默认图换脸演示
|
||||
// */
|
||||
// @Operation(summary = "首页点击换脸", description = "传入上传顾客照片后得到的ID")
|
||||
// @PostMapping("/reFace")
|
||||
// public ApiResponse<String> reFace(@Nullable @RequestParam Long customerPhotoId,
|
||||
// @Nullable @RequestParam String prompt,
|
||||
// @Nullable @RequestParam String tryonUrl) {
|
||||
// if (customerPhotoId == null&& StringUtil.isNullOrEmpty(prompt)&& StringUtil.isNullOrEmpty(tryonUrl)){
|
||||
// return ApiResponse.error("system error:Parameter null");
|
||||
// }
|
||||
// String result = "";
|
||||
// if (StringUtil.isNullOrEmpty(prompt)){
|
||||
// //换脸
|
||||
// result = tryOnEffectService.reFace(customerPhotoId);
|
||||
// }else {
|
||||
// if (StringUtil.isNullOrEmpty(tryonUrl)){
|
||||
// return ApiResponse.error("system error:Parameter null");
|
||||
// }
|
||||
// //根据提示词修改图像
|
||||
// result = tryOnEffectService.generateUrl(prompt,tryonUrl);
|
||||
// }
|
||||
// return ApiResponse.success("操作成功",result);
|
||||
// }
|
||||
}
|
||||
@@ -88,6 +88,12 @@ public class GlobalExceptionHandler {
|
||||
|
||||
logger.error("MinIO异常: {}", e.getMessage(), e);
|
||||
|
||||
// 如果是文件为空等参数错误,返回参数错误码
|
||||
String message = e.getMessage();
|
||||
if (message != null && (message.contains("文件不能为空") || message.contains("不能为空"))) {
|
||||
return ApiResponse.error(ResultEnum.PARAMETER_ERROR.getCode(), "File cannot be empty");
|
||||
}
|
||||
|
||||
return ApiResponse.error(ResultEnum.ERROR.getCode(), "File storage service error");
|
||||
}
|
||||
|
||||
|
||||
@@ -44,8 +44,8 @@ public interface TryOnEffectService extends IService<TryOnEffect> {
|
||||
*/
|
||||
boolean addComment(Suggestion suggestion);
|
||||
|
||||
//已废弃
|
||||
String reFace(Long customerPhotoId);
|
||||
|
||||
String generateUrl(String prompt, String tryonUrl);
|
||||
|
||||
PageResult<TryOnResultVO> getTryOnHistoricals(HistoricalDTO historicalDTO);
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.aida.lanecarford.service.impl;
|
||||
|
||||
import com.aida.lanecarford.common.constant.MinioFileConstants;
|
||||
import com.aida.lanecarford.common.response.ResultEnum;
|
||||
import com.aida.lanecarford.config.MinioConfig;
|
||||
import com.aida.lanecarford.dto.CustomerPhotoDto;
|
||||
import com.aida.lanecarford.entity.CustomerPhoto;
|
||||
import com.aida.lanecarford.exception.BusinessException;
|
||||
import com.aida.lanecarford.mapper.CustomerPhotoMapper;
|
||||
import com.aida.lanecarford.service.CustomerPhotoService;
|
||||
import com.aida.lanecarford.util.CopyUtil;
|
||||
@@ -11,6 +13,7 @@ import com.aida.lanecarford.util.MinioUtil;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* 顾客照片服务实现类
|
||||
@@ -26,9 +29,14 @@ public class CustomerPhotoServiceImpl extends ServiceImpl<CustomerPhotoMapper, C
|
||||
|
||||
@Override
|
||||
public CustomerPhoto upload(CustomerPhotoDto customerPhotoDto) {
|
||||
// 验证文件是否为空
|
||||
MultipartFile file = customerPhotoDto.getFile();
|
||||
if (file == null || file.isEmpty()) {
|
||||
throw new BusinessException(ResultEnum.PARAMETER_ERROR, "File cannot be empty", "文件不能为空");
|
||||
}
|
||||
|
||||
String logicalUrl = minioUtil.uploadFile(
|
||||
customerPhotoDto.getFile(),
|
||||
file,
|
||||
MinioFileConstants.FileType.CUSTOMER_PHOTO,
|
||||
minioConfig.getBucketName()
|
||||
);
|
||||
|
||||
@@ -213,6 +213,7 @@ public class TryOnEffectServiceImpl extends ServiceImpl<TryOnEffectMapper, TryOn
|
||||
}
|
||||
}
|
||||
|
||||
//已废弃
|
||||
@Override
|
||||
public String reFace(Long customerPhotoId) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user