fix:获取历史记录加入顾客id
All checks were successful
git commit 控制 连卡佛 back-java prod 分支构建部署 / build_and_deploy (push) Has been skipped

This commit is contained in:
litianxiang
2025-12-22 15:17:12 +08:00
parent 658149639f
commit 8eb42c9364
4 changed files with 67 additions and 59 deletions

View File

@@ -40,7 +40,7 @@ public class WebConfig implements WebMvcConfigurer {
registry.addInterceptor(jwtInterceptor) registry.addInterceptor(jwtInterceptor)
.addPathPatterns("/api/**/**") // 保护这些路径 .addPathPatterns("/api/**/**") // 保护这些路径
.excludePathPatterns(Arrays.asList("/api/auth/precheckEmail", "/api/auth/registerOrLogin", .excludePathPatterns(Arrays.asList("/api/auth/precheckEmail", "/api/auth/registerOrLogin",
"/api/auth/forgotPwd", "/api/style/callback", "/api/auth/parseGoogleAccessToken")); // 排除登录接口 "/api/auth/forgotPwd", "/api/style/callback", "/api/auth/parseGoogleAccessToken","/api/try-on-effects/getHistoricals")); // 排除登录接口
} }
/** /**

View File

@@ -47,7 +47,7 @@ public class TryOnEffectController {
@GetMapping("/getHistoricals") @GetMapping("/getHistoricals")
public ApiResponse<List<? extends BaseVO>> getHistoricals( public ApiResponse<List<? extends BaseVO>> getHistoricals(
@Parameter(description = "服装ID", required = true) @Parameter(description = "服装ID", required = true)
@RequestBody HistoricalDTO historicalDTO) { @ModelAttribute HistoricalDTO historicalDTO) {
if (CommonConstants.OUTFIT.equals(historicalDTO.getType())){ if (CommonConstants.OUTFIT.equals(historicalDTO.getType())){
List<OutfitHisVO> outfitHisVOS = tryOnEffectService.getOutfitHistoricals(historicalDTO); List<OutfitHisVO> outfitHisVOS = tryOnEffectService.getOutfitHistoricals(historicalDTO);
return ApiResponse.success(outfitHisVOS); return ApiResponse.success(outfitHisVOS);

View File

@@ -5,6 +5,10 @@ import lombok.Data;
@Data @Data
public class HistoricalDTO { public class HistoricalDTO {
@Schema(description = "顾客ID",example = "1")
private Long customerId;
@Schema(description = "进店记录ID",example = "1") @Schema(description = "进店记录ID",example = "1")
private Long visitRecordId; private Long visitRecordId;

View File

@@ -40,7 +40,7 @@ import java.util.concurrent.TimeUnit;
* *
* @author AI Assistant * @author AI Assistant
* @since 2024-01-01 * @since 2024-01-01
/** * /**
* 试穿效果服务实现类 * 试穿效果服务实现类
*/ */
@Service @Service
@@ -85,7 +85,7 @@ public class TryOnEffectServiceImpl extends ServiceImpl<TryOnEffectMapper, TryOn
CustomerPhoto customerPhoto = customerPhotoService.getById(customerPhotoId); CustomerPhoto customerPhoto = customerPhotoService.getById(customerPhotoId);
String customerPhotoUrl = customerPhoto.getPhotoUrl(); String customerPhotoUrl = customerPhoto.getPhotoUrl();
if (customerPhotoUrl != null && !customerPhotoUrl.trim().isEmpty()) { if (customerPhotoUrl != null && !customerPhotoUrl.trim().isEmpty()) {
if (imageUrls.isEmpty()){ if (imageUrls.isEmpty()) {
throw BusinessException.parameterRequired("TryOn result"); throw BusinessException.parameterRequired("TryOn result");
} }
//先放tryon图片后放脸 //先放tryon图片后放脸
@@ -116,24 +116,24 @@ public class TryOnEffectServiceImpl extends ServiceImpl<TryOnEffectMapper, TryOn
for (Map<String, String> map : maps) { for (Map<String, String> map : maps) {
String category = map.get("category"); String category = map.get("category");
sb.append("a "); sb.append("a ");
sb.append( category); sb.append(category);
sb.append(","); sb.append(",");
} }
prompt = "A full-body, photorealistic professional studio shot of a **young " + outfitRequest.getGender() + "**, mid-20s, with **clear facial features and a confident expression**. The model is centered in the frame.They are **standing in a direct, static, full-view pose** on a **clean, pure white background** **The entire figure, from head to toe, should be in frame and occupy approximately 80% of the vertical space.**.\n" + prompt = "A full-body, photorealistic professional studio shot of a **young " + outfitRequest.getGender() + "**, mid-20s, with **clear facial features and a confident expression**. The model is centered in the frame.They are **standing in a direct, static, full-view pose** on a **clean, pure white background** **The entire figure, from head to toe, should be in frame and occupy approximately 80% of the vertical space.**.\n" +
"\n" + "\n" +
"**CRITICAL COMPOSITION INSTRUCTION:**\n" + "**CRITICAL COMPOSITION INSTRUCTION:**\n" +
"Generate a single, seamless image of the model with a complete and fully visible head,**wearing ALL distinct items("+sb.toString()+")** from the uploaded image. **ALL items MUST be visible and correctly worn in the final outfit.**" + "Generate a single, seamless image of the model with a complete and fully visible head,**wearing ALL distinct items(" + sb.toString() + ")** from the uploaded image. **ALL items MUST be visible and correctly worn in the final outfit.**" +
"\n" + "\n" +
"**Placement Detail:** Outerwear must be worn on the outside, and if a bag is present, it must be visible.\n" + "**Placement Detail:** Outerwear must be worn on the outside, and if a bag is present, it must be visible.\n" +
"**Quality:** Ultra-high resolution, The figure should fill the frame as much as possible,studio photography quality. Emphasize **realistic fabric textures and sharp print fidelity**.\n" + "**Quality:** Ultra-high resolution, The figure should fill the frame as much as possible,studio photography quality. Emphasize **realistic fabric textures and sharp print fidelity**.\n" +
"**Negative Constraints (Exclude):** **NO text, NO borders, NO tables, NO multiple models, NO extra items.** **CRITICAL: NO cropping of the head or face.**"; "**Negative Constraints (Exclude):** **NO text, NO borders, NO tables, NO multiple models, NO extra items.** **CRITICAL: NO cropping of the head or face.**";
aiRreultlogicalUrl = AITryOnEffect(prompt, imageUrls); aiRreultlogicalUrl = AITryOnEffect(prompt, imageUrls);
}else if (tryOnEffectDto.getIsRegenerated() == 1 && imageUrls.size() == 1){ } else if (tryOnEffectDto.getIsRegenerated() == 1 && imageUrls.size() == 1) {
//根据提示词修改图像 //根据提示词修改图像
aiRreultlogicalUrl = AITryOnEffect(prompt, imageUrls); aiRreultlogicalUrl = AITryOnEffect(prompt, imageUrls);
}else if (tryOnEffectDto.getIsRegenerated() == 1 && imageUrls.size() > 1){ } else if (tryOnEffectDto.getIsRegenerated() == 1 && imageUrls.size() > 1) {
//换脸 //换脸
aiRreultlogicalUrl = callFaceSwapAPI(imageUrls); aiRreultlogicalUrl = callFaceSwapAPI(imageUrls);
} }
@@ -186,6 +186,7 @@ public class TryOnEffectServiceImpl extends ServiceImpl<TryOnEffectMapper, TryOn
/** /**
* 添加意见建议 * 添加意见建议
*
* @param suggestion 意见建议实体 * @param suggestion 意见建议实体
* @return 是否添加成功 * @return 是否添加成功
*/ */
@@ -194,7 +195,7 @@ public class TryOnEffectServiceImpl extends ServiceImpl<TryOnEffectMapper, TryOn
try { try {
// 保存意见建议 // 保存意见建议
int result = suggestionMapper.insert(suggestion); int result = suggestionMapper.insert(suggestion);
if (result > 0) { if (result > 0) {
log.info("意见建议添加成功 - id: {}", suggestion.getId()); log.info("意见建议添加成功 - id: {}", suggestion.getId());
return true; return true;
@@ -236,7 +237,7 @@ public class TryOnEffectServiceImpl extends ServiceImpl<TryOnEffectMapper, TryOn
// 支持jpg和png格式的图片识别 // 支持jpg和png格式的图片识别
int jpgEndIndex = tryonUrl.indexOf(".jpg"); int jpgEndIndex = tryonUrl.indexOf(".jpg");
int pngEndIndex = tryonUrl.indexOf(".png"); int pngEndIndex = tryonUrl.indexOf(".png");
int endIndex = -1; int endIndex = -1;
if (jpgEndIndex != -1 && (pngEndIndex == -1 || jpgEndIndex < pngEndIndex)) { if (jpgEndIndex != -1 && (pngEndIndex == -1 || jpgEndIndex < pngEndIndex)) {
@@ -246,7 +247,7 @@ public class TryOnEffectServiceImpl extends ServiceImpl<TryOnEffectMapper, TryOn
// 找到png格式 // 找到png格式
endIndex = pngEndIndex + ".png".length(); endIndex = pngEndIndex + ".png".length();
} }
if (endIndex != -1) { if (endIndex != -1) {
String resultString = tryonUrl.substring(startIndex, endIndex); String resultString = tryonUrl.substring(startIndex, endIndex);
aiRreultlogicalUrl = AITryOnEffect(prompt, Arrays.asList(resultString)); aiRreultlogicalUrl = AITryOnEffect(prompt, Arrays.asList(resultString));
@@ -259,53 +260,56 @@ public class TryOnEffectServiceImpl extends ServiceImpl<TryOnEffectMapper, TryOn
@Override @Override
public List<TryOnResultVO> getTryOnHistoricals(HistoricalDTO historicalDTO) { public List<TryOnResultVO> getTryOnHistoricals(HistoricalDTO historicalDTO) {
LambdaQueryWrapper<TryOnEffect> tryOnEffectLambdaQueryWrapper = new LambdaQueryWrapper<TryOnEffect>() LambdaQueryWrapper<TryOnEffect> tryOnEffectLambdaQueryWrapper = new LambdaQueryWrapper<TryOnEffect>()
.orderByDesc(TryOnEffect::getCreatedTime); .eq(TryOnEffect::getCustomerId, historicalDTO.getCustomerId())
if (historicalDTO.getVisitRecordId() != null){ .orderByDesc(TryOnEffect::getCreatedTime);
tryOnEffectLambdaQueryWrapper.eq(TryOnEffect::getVisitRecordId, historicalDTO.getVisitRecordId()); if (historicalDTO.getVisitRecordId() != null) {
} tryOnEffectLambdaQueryWrapper.eq(TryOnEffect::getVisitRecordId, historicalDTO.getVisitRecordId());
if (historicalDTO.getIsLibrary() != null||historicalDTO.getIsLibrary()){ }
tryOnEffectLambdaQueryWrapper.eq(TryOnEffect::getIsFavorite,1); if (historicalDTO.getIsLibrary() != null && historicalDTO.getIsLibrary()) {
} tryOnEffectLambdaQueryWrapper.eq(TryOnEffect::getIsFavorite, 1);
if (CommonConstants.TRYON.equals(historicalDTO.getType())){ }
tryOnEffectLambdaQueryWrapper.eq(TryOnEffect::getIsRegenerated, 0); if (CommonConstants.TRYON.equals(historicalDTO.getType())) {
}else if (CommonConstants.GENAI.equals(historicalDTO.getType())){ tryOnEffectLambdaQueryWrapper.eq(TryOnEffect::getIsRegenerated, 0);
tryOnEffectLambdaQueryWrapper.eq(TryOnEffect::getIsRegenerated, 1); } else if (CommonConstants.GENAI.equals(historicalDTO.getType())) {
} tryOnEffectLambdaQueryWrapper.eq(TryOnEffect::getIsRegenerated, 1);
List<TryOnEffect> tryOnEffects = this.list(tryOnEffectLambdaQueryWrapper); }
List<TryOnResultVO> tryOnResultVos = new ArrayList<>(); List<TryOnEffect> tryOnEffects = this.list(tryOnEffectLambdaQueryWrapper);
for (TryOnEffect tryOnEffect : tryOnEffects) { List<TryOnResultVO> tryOnResultVos = new ArrayList<>();
TryOnResultVO tryOnResultVo = new TryOnResultVO(); for (TryOnEffect tryOnEffect : tryOnEffects) {
tryOnResultVo.setId(tryOnEffect.getId()); TryOnResultVO tryOnResultVo = new TryOnResultVO();
tryOnResultVo.setTryOnUrl(minioUtil.convertToPresignedUrl( tryOnResultVo.setId(tryOnEffect.getId());
tryOnEffect.getResultImageUrl(), tryOnResultVo.setTryOnUrl(minioUtil.convertToPresignedUrl(
tryOnEffect.getResultImageUrl(),
CommonConstants.MINIO_PATH_TIMEOUT
));
// 如果是原始效果则获取对应的style图片
if (tryOnEffect.getIsRegenerated() == 0) {
LambdaQueryWrapper<Style> styleLambdaQueryWrapper = new LambdaQueryWrapper<>();
styleLambdaQueryWrapper.eq(Style::getId, tryOnEffect.getStyleId()).select(Style::getStyleImageUrl);
Style style = styleService.getOne(styleLambdaQueryWrapper);
tryOnResultVo.setStyleUrl(minioUtil.convertToPresignedUrl(
style.getStyleImageUrl(),
CommonConstants.MINIO_PATH_TIMEOUT CommonConstants.MINIO_PATH_TIMEOUT
)); ));
// 如果是原始效果则获取对应的style图片
if (tryOnEffect.getIsRegenerated() == 0) {
LambdaQueryWrapper<Style> styleLambdaQueryWrapper = new LambdaQueryWrapper<>();
styleLambdaQueryWrapper.eq(Style::getId, tryOnEffect.getStyleId()).select(Style::getStyleImageUrl);
Style style = styleService.getOne(styleLambdaQueryWrapper);
tryOnResultVo.setStyleUrl(minioUtil.convertToPresignedUrl(
style.getStyleImageUrl(),
CommonConstants.MINIO_PATH_TIMEOUT
));
}
tryOnResultVo.setIsRegenerated(tryOnEffect.getIsRegenerated());
tryOnResultVo.setIsFavorite(tryOnEffect.getIsFavorite());
tryOnResultVos.add(tryOnResultVo);
} }
tryOnResultVo.setIsRegenerated(tryOnEffect.getIsRegenerated());
tryOnResultVo.setIsFavorite(tryOnEffect.getIsFavorite());
tryOnResultVos.add(tryOnResultVo);
}
return tryOnResultVos; return tryOnResultVos;
} }
@Override @Override
public List<OutfitHisVO> getOutfitHistoricals(HistoricalDTO historicalDTO) { public List<OutfitHisVO> getOutfitHistoricals(HistoricalDTO historicalDTO) {
LambdaQueryWrapper<Style> styleLambdaQueryWrapper = new LambdaQueryWrapper<Style>().orderByDesc(Style::getCreatedTime); LambdaQueryWrapper<Style> styleLambdaQueryWrapper = new LambdaQueryWrapper<Style>()
if (historicalDTO.getVisitRecordId() != null){ .eq(Style::getCustomerId, historicalDTO.getCustomerId())
.orderByDesc(Style::getCreatedTime);
if (historicalDTO.getVisitRecordId() != null) {
styleLambdaQueryWrapper.eq(Style::getVisitRecordId, historicalDTO.getVisitRecordId()); styleLambdaQueryWrapper.eq(Style::getVisitRecordId, historicalDTO.getVisitRecordId());
} }
if (historicalDTO.getIsLibrary() != null||historicalDTO.getIsLibrary()){ if (historicalDTO.getIsLibrary() != null && historicalDTO.getIsLibrary()) {
styleLambdaQueryWrapper.eq(Style::getIsFavorite, 1); styleLambdaQueryWrapper.eq(Style::getIsFavorite, 1);
} }
List<Style> styles = styleService.list(styleLambdaQueryWrapper); List<Style> styles = styleService.list(styleLambdaQueryWrapper);
@@ -637,7 +641,7 @@ public class TryOnEffectServiceImpl extends ServiceImpl<TryOnEffectMapper, TryOn
String finishReason = candidate.getString("finishReason"); String finishReason = candidate.getString("finishReason");
if (!"STOP".equals(finishReason)) { if (!"STOP".equals(finishReason)) {
String finishMessage = candidate.getString("finishMessage"); String finishMessage = candidate.getString("finishMessage");
if (finishReason != null && finishReason.equals("IMAGE_SAFETY")){ if (finishReason != null && finishReason.equals("IMAGE_SAFETY")) {
if (finishMessage != null && finishMessage.contains("Try rephrasing the prompt")) { if (finishMessage != null && finishMessage.contains("Try rephrasing the prompt")) {
finishMessage = "Try rephrasing the prompt.If you think this was an error, send feedback."; finishMessage = "Try rephrasing the prompt.If you think this was an error, send feedback.";
throw new BusinessException(finishMessage, "请尝试重新表述提示词。若您认为这是误判,可提交反馈。", ResultEnum.ERROR.getCode()); throw new BusinessException(finishMessage, "请尝试重新表述提示词。若您认为这是误判,可提交反馈。", ResultEnum.ERROR.getCode());
@@ -684,21 +688,22 @@ public class TryOnEffectServiceImpl extends ServiceImpl<TryOnEffectMapper, TryOn
/** /**
* 调用换脸API * 调用换脸API
*
* @param imageUrls 图片URL列表第一个为源图片第二个为目标图片 * @param imageUrls 图片URL列表第一个为源图片第二个为目标图片
* @return 换脸后的图片URL * @return 换脸后的图片URL
*/ */
private String callFaceSwapAPI(List<String> imageUrls) { private String callFaceSwapAPI(List<String> imageUrls) {
try { try {
log.info("开始调用换脸API - 源图片: {}, 目标图片: {}", imageUrls.get(0), imageUrls.get(1)); log.info("开始调用换脸API - 源图片: {}, 目标图片: {}", imageUrls.get(0), imageUrls.get(1));
String inputFaceUrl = imageUrls.get(1); String inputFaceUrl = imageUrls.get(1);
// 构建输入图片列表(从第二张图片开始作为目标图片列表) // 构建输入图片列表(从第二张图片开始作为目标图片列表)
JSONArray inputImageList = new JSONArray(); JSONArray inputImageList = new JSONArray();
inputImageList.add(imageUrls.get(0)); inputImageList.add(imageUrls.get(0));
// 构建请求体 // 构建请求体
JSONObject requestBody = new JSONObject(); JSONObject requestBody = new JSONObject();
@@ -789,19 +794,18 @@ public class TryOnEffectServiceImpl extends ServiceImpl<TryOnEffectMapper, TryOn
log.info("开始处理换脸API响应: {}", response); log.info("开始处理换脸API响应: {}", response);
com.alibaba.fastjson.JSONObject jsonResponse = com.alibaba.fastjson.JSON.parseObject(response); com.alibaba.fastjson.JSONObject jsonResponse = com.alibaba.fastjson.JSON.parseObject(response);
// 处理新的响应格式: {"output":["lanecarford/refaced_image/refaced1761809361.530157.png"]} // 处理新的响应格式: {"output":["lanecarford/refaced_image/refaced1761809361.530157.png"]}
if (jsonResponse.containsKey("output")) { if (jsonResponse.containsKey("output")) {
Object outputObj = jsonResponse.get("output"); Object outputObj = jsonResponse.get("output");
if (outputObj instanceof JSONArray) { if (outputObj instanceof JSONArray) {
JSONArray outputArray = (JSONArray) outputObj; JSONArray outputArray = (JSONArray) outputObj;
if (outputArray.size() > 0) { if (outputArray.size() > 0) {
String imagePath = outputArray.getString(0); String imagePath = outputArray.getString(0);
log.info("换脸成功,图片路径: {}", imagePath); log.info("换脸成功,图片路径: {}", imagePath);
// 下载图片并上传到MinIO // 下载图片并上传到MinIO
return imagePath; return imagePath;
} else { } else {
@@ -812,7 +816,7 @@ public class TryOnEffectServiceImpl extends ServiceImpl<TryOnEffectMapper, TryOn
log.error("output字段不是数组格式: {}", outputObj); log.error("output字段不是数组格式: {}", outputObj);
throw new BusinessException("Invalid output format", "output字段格式不正确", ResultEnum.ERROR.getCode()); throw new BusinessException("Invalid output format", "output字段格式不正确", ResultEnum.ERROR.getCode());
} }
}else { } else {
log.error("换脸API响应失败: {}", response); log.error("换脸API响应失败: {}", response);
throw new BusinessException("reface error", "换脸失败", ResultEnum.ERROR.getCode()); throw new BusinessException("reface error", "换脸失败", ResultEnum.ERROR.getCode());
} }
@@ -842,7 +846,7 @@ public class TryOnEffectServiceImpl extends ServiceImpl<TryOnEffectMapper, TryOn
if (!response.isSuccessful()) { if (!response.isSuccessful()) {
throw new IOException("Failed to download image: HTTP " + response.code()); throw new IOException("Failed to download image: HTTP " + response.code());
} }
return response.body().bytes(); return response.body().bytes();
} }
} }