1 Commits

Author SHA1 Message Date
91eb21aa84 BUGFIX:token过期都返回401 2025-12-23 14:30:24 +08:00
15 changed files with 75 additions and 303 deletions

View File

@@ -10,9 +10,5 @@ public class CommonConstants {
public static final int CONN_TIMEOUT = 30000; // milliseconds
public static final String OUTFIT = "Outfit";
public static final String TRYON = "Try-on";
public static final String GENAI = "Gen-AI";
}

View File

@@ -2,7 +2,6 @@ package com.aida.lanecarford.common.security;
import com.aida.lanecarford.common.security.config.JwtProperties;
import com.aida.lanecarford.common.security.context.UserContext;
import com.aida.lanecarford.exception.BusinessException;
import com.aida.lanecarford.util.CacheUtil;
import com.aida.lanecarford.vo.AuthPrincipalVO;
import com.alibaba.fastjson.JSONObject;
@@ -25,7 +24,7 @@ public class JwtInterceptor implements HandlerInterceptor {
private final JwtProperties jwtProperties;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
if ("OPTIONS".equalsIgnoreCase(request.getMethod())) {
return true;
}
@@ -41,7 +40,8 @@ public class JwtInterceptor implements HandlerInterceptor {
String extracted = jwtUtil.extractUserinfo(jwtToken);
if (StringUtil.isNullOrEmpty(extracted)) {
log.warn("TOKEN已过期请重新登录(token without userInfo)");
throw new BusinessException("Token has expired, please log in again.");
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
// throw new BusinessException("Token has expired, please log in again.");
}
AuthPrincipalVO authPrincipalVO = JSONObject.parseObject(extracted, AuthPrincipalVO.class);
@@ -54,10 +54,12 @@ public class JwtInterceptor implements HandlerInterceptor {
if (Objects.isNull(token)) {
log.warn("TOKEN已过期请重新登录(local cache empty)");
throw new BusinessException("Token has expired, please log in again.");
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
// throw new BusinessException("Token has expired, please log in again.");
} else if (!token.toString().equals(jwtToken)) {
log.warn("TOKEN已过期请重新登录(token not match local cache)");
throw new BusinessException("Token has expired, please log in again.");
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
// throw new BusinessException("Token has expired, please log in again.");
}
return true;
}

View File

@@ -78,30 +78,6 @@ public class StyleController {
return ApiResponse.success(styleService.getOutfitResult(requestIDs));
}
/**
* 设置喜欢的风格
*/
@Operation(summary = "设置喜欢的outfit", description = "将指定风格设置为收藏")
@PostMapping("/set-favorite/{styleId}")
public ApiResponse<Void> setFavoriteStyle(
@Parameter(description = "风格ID", required = true)
@PathVariable Long styleId) {
styleService.setFavoriteStyle(styleId);
return ApiResponse.success();
}
/**
* 取消喜欢的风格
*/
@Operation(summary = "取消喜欢的outfit", description = "取消指定风格的收藏")
@PostMapping("/cancel-favorite/{styleId}")
public ApiResponse<Void> cancelFavoriteStyle(
@Parameter(description = "风格ID", required = true)
@PathVariable Long styleId) {
styleService.cancelFavoriteStyle(styleId);
return ApiResponse.success();
}
@Operation(
summary = "回溯历史对话,重新生成搭配图",
description = "根据当前的穿搭结果,回溯历史穿搭请求数据及历史对话,重新生成搭配"

View File

@@ -1,15 +1,10 @@
package com.aida.lanecarford.controller;
import com.aida.lanecarford.common.ApiResponse;
import com.aida.lanecarford.common.PageResult;
import com.aida.lanecarford.common.constant.CommonConstants;
import com.aida.lanecarford.dto.HistoricalDTO;
import com.aida.lanecarford.entity.Suggestion;
import com.aida.lanecarford.entity.TryOnEffect;
import com.aida.lanecarford.service.TryOnEffectService;
import com.aida.lanecarford.vo.BaseVO;
import com.aida.lanecarford.vo.OutfitHisVO;
import com.aida.lanecarford.vo.TryOnResultVO;
import com.aida.lanecarford.vo.TryOnResultVo;
import io.netty.util.internal.StringUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
@@ -37,25 +32,29 @@ public class TryOnEffectController {
@Operation(summary = "生成试穿效果", description = "根据服装模特照片生成试穿效果其中styleId是必选当二次生成时要带上相关参数比如顾客照片")
@PostMapping("/generate")
public ApiResponse<TryOnResultVO> generateTryOnEffect(
public ApiResponse<TryOnResultVo> generateTryOnEffect(
@Parameter(description = "试穿效果请求参数", required = true)
@Valid @RequestBody TryOnEffect tryOnEffectDto) {
TryOnResultVO tryOnResultVo = tryOnEffectService.generateTryOnEffect(tryOnEffectDto);
TryOnResultVo tryOnResultVo = tryOnEffectService.generateTryOnEffect(tryOnEffectDto);
return ApiResponse.success(tryOnResultVo);
}
@Operation(summary = "获取历史生成记录", description = "根据type进店记录id是否收藏来决定返回的数据支持分页")
@GetMapping("/getHistoricals")
public ApiResponse<PageResult<? extends BaseVO>> getHistoricals(
@Parameter(description = "历史记录查询参数", required = true)
@ModelAttribute HistoricalDTO historicalDTO) {
if (CommonConstants.OUTFIT.equals(historicalDTO.getType())) {
PageResult<OutfitHisVO> outfitHisVOS = tryOnEffectService.getOutfitHistoricals(historicalDTO);
return ApiResponse.success(outfitHisVOS);
} else {
PageResult<TryOnResultVO> tryOnResultVos = tryOnEffectService.getTryOnHistoricals(historicalDTO);
return ApiResponse.success(tryOnResultVos);
}
@Operation(summary = "获取收藏的试穿效果", description = "对应library页面点击details后的显示参数为进店记录id")
@GetMapping("/favorites/{visitRecordId}")
public ApiResponse<List<TryOnResultVo>> getFavoriteTryOnEffects(
@Parameter(description = "进店记录ID", required = true)
@PathVariable Long visitRecordId) {
List<TryOnResultVo> tryOnResultVos = tryOnEffectService.getFavoriteTryOnEffects(visitRecordId);
return ApiResponse.success(tryOnResultVos);
}
@GetMapping("/style/{styleId}")
@Operation(summary = "获取某套服装的所有生成结果", description = "对应customize your look页面点击finish后的显示")
public ApiResponse<List<TryOnResultVo>> getTryOnEffectsByStyleId(
@Parameter(description = "服装ID", required = true)
@PathVariable Long styleId) {
List<TryOnResultVo> tryOnResultVos = tryOnEffectService.getTryOnEffectsByStyleId(styleId);
return ApiResponse.success(tryOnResultVos);
}
/**

View File

@@ -1,27 +0,0 @@
package com.aida.lanecarford.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
public class HistoricalDTO {
@Schema(description = "顾客ID", example = "1")
private Long customerId;
@Schema(description = "进店记录ID", example = "1")
private Long visitRecordId;
@Schema(description = "类型", example = "Outfit , Try-on , Gen-AI")
private String type;
@Schema(description = "是否是收藏", example = "true")
private Boolean isLibrary;
@Schema(description = "当前页码从1开始", example = "1")
private Integer pageNum;
@Schema(description = "每页大小", example = "10")
private Integer pageSize;
}

View File

@@ -1,7 +1,6 @@
package com.aida.lanecarford.entity;
import com.baomidou.mybatisplus.annotation.*;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
@@ -77,11 +76,4 @@ public class Style extends BaseEntity {
private String errorMessage;
// 注意createdTime、updatedTime 字段已在 BaseEntity 中定义
/**
* 是否喜欢(0-否,1-是)
*/
@Schema(description = "是否喜欢(0-否,1-是)", example = "1", required = false)
@TableField("is_favorite")
private Integer isFavorite;
}

View File

@@ -19,18 +19,6 @@ public interface StyleService extends IService<Style> {
List<OutfitResultVO> getOutfitResult(List<String> requestIDs);
/**
* 设置风格为收藏
* @param styleId 风格ID
*/
void setFavoriteStyle(Long styleId);
/**
* 取消风格的收藏
* @param styleId 风格ID
*/
void cancelFavoriteStyle(Long styleId);
List<String> retrieveAndRegenerate(Long tryOnEffectsId);
}

View File

@@ -1,11 +1,8 @@
package com.aida.lanecarford.service;
import com.aida.lanecarford.common.PageResult;
import com.aida.lanecarford.dto.HistoricalDTO;
import com.aida.lanecarford.entity.Suggestion;
import com.aida.lanecarford.entity.TryOnEffect;
import com.aida.lanecarford.vo.OutfitHisVO;
import com.aida.lanecarford.vo.TryOnResultVO;
import com.aida.lanecarford.vo.TryOnResultVo;
import com.baomidou.mybatisplus.extension.service.IService;
import jakarta.validation.Valid;
@@ -19,9 +16,9 @@ import java.util.List;
*/
public interface TryOnEffectService extends IService<TryOnEffect> {
TryOnResultVO generateTryOnEffect(@Valid TryOnEffect tryOnEffectDto);
TryOnResultVo generateTryOnEffect(@Valid TryOnEffect tryOnEffectDto);
List<TryOnResultVO> getFavoriteTryOnEffects(Long visitRecordId);
List<TryOnResultVo> getFavoriteTryOnEffects(Long visitRecordId);
/**
* 设置试穿效果为收藏
@@ -35,7 +32,7 @@ public interface TryOnEffectService extends IService<TryOnEffect> {
*/
void cancelFavoriteTryOnEffect(Long tryOnId);
List<TryOnResultVO> getTryOnEffectsByStyleId(Long styleId);
List<TryOnResultVo> getTryOnEffectsByStyleId(Long styleId);
/**
* 添加意见建议
@@ -47,8 +44,4 @@ public interface TryOnEffectService extends IService<TryOnEffect> {
String reFace(Long customerPhotoId);
String generateUrl(String prompt, String tryonUrl);
PageResult<TryOnResultVO> getTryOnHistoricals(HistoricalDTO historicalDTO);
PageResult<OutfitHisVO> getOutfitHistoricals(HistoricalDTO historicalDTO);
}

View File

@@ -108,6 +108,8 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
customer.setCreatedTime(LocalDateTime.now());
save(customer);
} else {
throw new BusinessException("VIP ID'" + vipId + "' already exists.Please proceed directly to check-in.");
}
return customer;

View File

@@ -4,7 +4,6 @@ import com.aida.lanecarford.common.constant.CommonConstants;
import com.aida.lanecarford.common.constant.RedisURIConstants;
import com.aida.lanecarford.common.enums.StatusEnum;
import com.aida.lanecarford.common.enums.StylistPathEnum;
import com.aida.lanecarford.common.response.ResultEnum;
import com.aida.lanecarford.dto.OutfitCallbackDTO;
import com.aida.lanecarford.dto.RequestOutfitDTO;
import com.aida.lanecarford.entity.OutfitRequest;
@@ -232,40 +231,6 @@ public class StyleServiceImpl extends ServiceImpl<StyleMapper, Style> implements
return resultVOS;
}
@Override
public void setFavoriteStyle(Long styleId) {
if (styleId == null) {
throw new BusinessException("Style ID is required", "风格ID不能为空", ResultEnum.PARAMETER_ERROR.getCode());
}
Style style = this.getById(styleId);
if (style == null) {
throw new BusinessException("Style not found", "风格不存在", ResultEnum.FAIL.getCode());
}
// 设置为收藏
style.setIsFavorite(1);
this.updateById(style);
log.info("风格ID: {} 已设置为收藏", styleId);
}
@Override
public void cancelFavoriteStyle(Long styleId) {
if (styleId == null) {
throw new BusinessException("Style ID is required", "风格ID不能为空", ResultEnum.PARAMETER_ERROR.getCode());
}
Style style = this.getById(styleId);
if (style == null) {
throw new BusinessException("Style not found", "风格不存在", ResultEnum.FAIL.getCode());
}
// 取消收藏
style.setIsFavorite(0);
this.updateById(style);
log.info("风格ID: {} 已取消收藏", styleId);
}
public SessionRecord saveOrUpdateSession(String sessionId, Long visitsId, String summary, List<String> occasion) {
// 判断同一次进店记录中当前会话id是否已存在
QueryWrapper<SessionRecord> queryWrapper = new QueryWrapper<>();

View File

@@ -1,13 +1,11 @@
package com.aida.lanecarford.service.impl;
import cn.hutool.json.JSONObject;
import com.aida.lanecarford.common.PageResult;
import com.aida.lanecarford.common.constant.CommonConstants;
import com.aida.lanecarford.config.MinioConfig;
import com.aida.lanecarford.config.FaceSwapConfig;
import com.aida.lanecarford.common.response.ResultEnum;
import com.aida.lanecarford.common.constant.MinioFileConstants;
import com.aida.lanecarford.dto.HistoricalDTO;
import com.aida.lanecarford.entity.*;
import com.aida.lanecarford.exception.BusinessException;
import com.aida.lanecarford.mapper.CustomerMapper;
@@ -18,13 +16,10 @@ import com.aida.lanecarford.service.*;
import com.aida.lanecarford.entity.Suggestion;
import com.aida.lanecarford.util.MinioUtil;
import com.aida.lanecarford.util.StringListConverter;
import com.aida.lanecarford.vo.OutfitHisVO;
import com.aida.lanecarford.vo.TryOnResultVO;
import com.aida.lanecarford.vo.TryOnResultVo;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.auth.oauth2.GoogleCredentials;
import lombok.RequiredArgsConstructor;
@@ -43,7 +38,7 @@ import java.util.concurrent.TimeUnit;
*
* @author AI Assistant
* @since 2024-01-01
* /**
/**
* 试穿效果服务实现类
*/
@Service
@@ -51,7 +46,12 @@ import java.util.concurrent.TimeUnit;
public class TryOnEffectServiceImpl extends ServiceImpl<TryOnEffectMapper, TryOnEffect> implements TryOnEffectService {
private static final Logger log = LoggerFactory.getLogger(TryOnEffectServiceImpl.class);
private final StyleService styleService;
private final ModelPhotoService modelPhotoService;
private final CustomerPhotoService customerPhotoService;
private final ImageCompositionService imageCompositionService;
private final CustomerMapper customerMapper;
private final MinioUtil minioUtil;
private final MinioConfig minioConfig;
private final FaceSwapConfig faceSwapConfig;
@@ -59,7 +59,7 @@ public class TryOnEffectServiceImpl extends ServiceImpl<TryOnEffectMapper, TryOn
private final OutfitRequestMapper outfitRequestMapper;
@Override
public TryOnResultVO generateTryOnEffect(TryOnEffect tryOnEffectDto) {
public TryOnResultVo generateTryOnEffect(TryOnEffect tryOnEffectDto) {
Integer isRegenerated = tryOnEffectDto.getIsRegenerated();
String toAIlogicalUrl = null;
String prompt = null;
@@ -74,13 +74,7 @@ public class TryOnEffectServiceImpl extends ServiceImpl<TryOnEffectMapper, TryOn
throw BusinessException.parameterRequired("originalTryOnId");
}
TryOnEffect originalTryOn = this.getById(originalTryOnId);
if (tryOnEffectDto.getStyleId()==null){
tryOnEffectDto.setStyleId(originalTryOn.getStyleId());
}
String resultImageUrl = originalTryOn.getResultImageUrl();
if (tryOnEffectDto.getStyleId()==null){
tryOnEffectDto.setStyleId(originalTryOn.getStyleId());
}
imageUrls.add(resultImageUrl);
Long customerPhotoId = tryOnEffectDto.getCustomerPhotoId();
@@ -89,7 +83,7 @@ public class TryOnEffectServiceImpl extends ServiceImpl<TryOnEffectMapper, TryOn
CustomerPhoto customerPhoto = customerPhotoService.getById(customerPhotoId);
String customerPhotoUrl = customerPhoto.getPhotoUrl();
if (customerPhotoUrl != null && !customerPhotoUrl.trim().isEmpty()) {
if (imageUrls.isEmpty()) {
if (imageUrls.isEmpty()){
throw BusinessException.parameterRequired("TryOn result");
}
//先放tryon图片后放脸
@@ -120,24 +114,24 @@ public class TryOnEffectServiceImpl extends ServiceImpl<TryOnEffectMapper, TryOn
for (Map<String, String> map : maps) {
String category = map.get("category");
sb.append("a ");
sb.append(category);
sb.append( category);
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" +
"\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" +
"**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" +
"**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);
} else if (tryOnEffectDto.getIsRegenerated() == 1 && imageUrls.size() > 1) {
}else if (tryOnEffectDto.getIsRegenerated() == 1 && imageUrls.size() > 1){
//换脸
aiRreultlogicalUrl = callFaceSwapAPI(imageUrls);
}
@@ -146,8 +140,8 @@ public class TryOnEffectServiceImpl extends ServiceImpl<TryOnEffectMapper, TryOn
tryOnEffectDto.setGenerationStatus("completed");
this.saveOrUpdate(tryOnEffectDto);
TryOnResultVO tryOnResultVo = new TryOnResultVO();
tryOnResultVo.setId(tryOnEffectDto.getId());
TryOnResultVo tryOnResultVo = new TryOnResultVo();
tryOnResultVo.setTryOnId(tryOnEffectDto.getId());
tryOnResultVo.setTryOnUrl(minioUtil.convertToPresignedUrl(aiRreultlogicalUrl, CommonConstants.MINIO_PATH_TIMEOUT));
@@ -156,15 +150,15 @@ public class TryOnEffectServiceImpl extends ServiceImpl<TryOnEffectMapper, TryOn
//library页面点击details后的显示
@Override
public List<TryOnResultVO> getFavoriteTryOnEffects(Long visitRecordId) {
public List<TryOnResultVo> getFavoriteTryOnEffects(Long visitRecordId) {
List<TryOnEffect> tryOnEffects = this.list(new LambdaQueryWrapper<TryOnEffect>()
.eq(TryOnEffect::getVisitRecordId, visitRecordId)
.eq(TryOnEffect::getIsFavorite, 1)
.orderByDesc(TryOnEffect::getCreatedTime));
List<TryOnResultVO> tryOnResultVos = new ArrayList<>();
.orderByAsc(TryOnEffect::getCreatedTime));
List<TryOnResultVo> tryOnResultVos = new ArrayList<>();
for (TryOnEffect tryOnEffect : tryOnEffects) {
TryOnResultVO tryOnResultVo = new TryOnResultVO();
tryOnResultVo.setId(tryOnEffect.getId());
TryOnResultVo tryOnResultVo = new TryOnResultVo();
tryOnResultVo.setTryOnId(tryOnEffect.getId());
// 使用新的API获取预签名URL数据库存储的是逻辑URL
tryOnResultVo.setTryOnUrl(minioUtil.convertToPresignedUrl(
tryOnEffect.getResultImageUrl(),
@@ -190,7 +184,6 @@ public class TryOnEffectServiceImpl extends ServiceImpl<TryOnEffectMapper, TryOn
/**
* 添加意见建议
*
* @param suggestion 意见建议实体
* @return 是否添加成功
*/
@@ -199,7 +192,7 @@ public class TryOnEffectServiceImpl extends ServiceImpl<TryOnEffectMapper, TryOn
try {
// 保存意见建议
int result = suggestionMapper.insert(suggestion);
if (result > 0) {
log.info("意见建议添加成功 - id: {}", suggestion.getId());
return true;
@@ -241,7 +234,7 @@ public class TryOnEffectServiceImpl extends ServiceImpl<TryOnEffectMapper, TryOn
// 支持jpg和png格式的图片识别
int jpgEndIndex = tryonUrl.indexOf(".jpg");
int pngEndIndex = tryonUrl.indexOf(".png");
int endIndex = -1;
if (jpgEndIndex != -1 && (pngEndIndex == -1 || jpgEndIndex < pngEndIndex)) {
@@ -251,7 +244,7 @@ public class TryOnEffectServiceImpl extends ServiceImpl<TryOnEffectMapper, TryOn
// 找到png格式
endIndex = pngEndIndex + ".png".length();
}
if (endIndex != -1) {
String resultString = tryonUrl.substring(startIndex, endIndex);
aiRreultlogicalUrl = AITryOnEffect(prompt, Arrays.asList(resultString));
@@ -262,96 +255,16 @@ public class TryOnEffectServiceImpl extends ServiceImpl<TryOnEffectMapper, TryOn
return minioUtil.convertToPresignedUrl(aiRreultlogicalUrl, CommonConstants.MINIO_PATH_TIMEOUT);
}
@Override
public PageResult<TryOnResultVO> getTryOnHistoricals(HistoricalDTO historicalDTO) {
LambdaQueryWrapper<TryOnEffect> tryOnEffectLambdaQueryWrapper = new LambdaQueryWrapper<TryOnEffect>()
.eq(TryOnEffect::getCustomerId, historicalDTO.getCustomerId())
.orderByDesc(TryOnEffect::getCreatedTime);
if (historicalDTO.getVisitRecordId() != null) {
tryOnEffectLambdaQueryWrapper.eq(TryOnEffect::getVisitRecordId, historicalDTO.getVisitRecordId());
}
if (historicalDTO.getIsLibrary() != null && historicalDTO.getIsLibrary()) {
tryOnEffectLambdaQueryWrapper.eq(TryOnEffect::getIsFavorite, 1);
}
if (CommonConstants.TRYON.equals(historicalDTO.getType())) {
tryOnEffectLambdaQueryWrapper.eq(TryOnEffect::getIsRegenerated, 0);
} else if (CommonConstants.GENAI.equals(historicalDTO.getType())) {
tryOnEffectLambdaQueryWrapper.eq(TryOnEffect::getIsRegenerated, 1);
}
long current = historicalDTO.getPageNum() == null || historicalDTO.getPageNum() <= 0 ? 1L : historicalDTO.getPageNum();
long size = historicalDTO.getPageSize() == null || historicalDTO.getPageSize() <= 0 ? 10L : historicalDTO.getPageSize();
IPage<TryOnEffect> page = this.page(new Page<>(current, size), tryOnEffectLambdaQueryWrapper);
List<TryOnResultVO> tryOnResultVos = new ArrayList<>();
for (TryOnEffect tryOnEffect : page.getRecords()) {
TryOnResultVO tryOnResultVo = new TryOnResultVO();
tryOnResultVo.setId(tryOnEffect.getId());
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
));
}
tryOnResultVo.setIsRegenerated(tryOnEffect.getIsRegenerated());
tryOnResultVo.setIsFavorite(tryOnEffect.getIsFavorite());
tryOnResultVos.add(tryOnResultVo);
}
return new PageResult<>(tryOnResultVos, page.getTotal(), page.getCurrent(), page.getSize());
}
@Override
public PageResult<OutfitHisVO> getOutfitHistoricals(HistoricalDTO historicalDTO) {
LambdaQueryWrapper<Style> styleLambdaQueryWrapper = new LambdaQueryWrapper<Style>()
.eq(Style::getCustomerId, historicalDTO.getCustomerId())
.eq(Style::getGenerationStatus, 1)
.orderByDesc(Style::getCreatedTime);
if (historicalDTO.getVisitRecordId() != null) {
styleLambdaQueryWrapper.eq(Style::getVisitRecordId, historicalDTO.getVisitRecordId());
}
if (historicalDTO.getIsLibrary() != null && historicalDTO.getIsLibrary()) {
styleLambdaQueryWrapper.eq(Style::getIsFavorite, 1);
}
long current = historicalDTO.getPageNum() == null || historicalDTO.getPageNum() <= 0 ? 1L : historicalDTO.getPageNum();
long size = historicalDTO.getPageSize() == null || historicalDTO.getPageSize() <= 0 ? 10L : historicalDTO.getPageSize();
IPage<Style> page = styleService.page(new Page<>(current, size), styleLambdaQueryWrapper);
List<OutfitHisVO> outfitHisVos = new ArrayList<>();
for (Style style : page.getRecords()) {
OutfitHisVO outfitHisVo = new OutfitHisVO();
outfitHisVo.setId(style.getId());
outfitHisVo.setUrl(minioUtil.convertToPresignedUrl(
style.getStyleImageUrl(),
CommonConstants.MINIO_PATH_TIMEOUT
));
outfitHisVo.setIsFavorite(style.getIsFavorite());
outfitHisVos.add(outfitHisVo);
}
return new PageResult<>(outfitHisVos, page.getTotal(), page.getCurrent(), page.getSize());
}
//目前用于customize your look页面点击finish后的显示
@Override
public List<TryOnResultVO> getTryOnEffectsByStyleId(Long styleId) {
public List<TryOnResultVo> getTryOnEffectsByStyleId(Long styleId) {
List<TryOnEffect> tryOnEffects = this.list(new LambdaQueryWrapper<TryOnEffect>()
.eq(TryOnEffect::getStyleId, styleId)
.orderByDesc(TryOnEffect::getCreatedTime));
List<TryOnResultVO> tryOnResultVos = new ArrayList<>();
.orderByAsc(TryOnEffect::getCreatedTime));
List<TryOnResultVo> tryOnResultVos = new ArrayList<>();
for (TryOnEffect tryOnEffect : tryOnEffects) {
TryOnResultVO tryOnResultVo = new TryOnResultVO();
tryOnResultVo.setId(tryOnEffect.getId());
TryOnResultVo tryOnResultVo = new TryOnResultVo();
tryOnResultVo.setTryOnId(tryOnEffect.getId());
// 使用新的API获取预签名URL数据库存储的是逻辑URL
tryOnResultVo.setTryOnUrl(minioUtil.convertToPresignedUrl(
tryOnEffect.getResultImageUrl(),
@@ -489,7 +402,7 @@ public class TryOnEffectServiceImpl extends ServiceImpl<TryOnEffectMapper, TryOn
return processGoogleAPIResponse(response);
} catch (Exception e) {
log.error("调用Google API失败: {}", e.getMessage(), e);
throw new BusinessException("Generation timed out. Please try again later.", "生成超时,请稍后再试", ResultEnum.ERROR.getCode());
throw new BusinessException("Google API call failed", "Google API调用失败", ResultEnum.ERROR.getCode());
}
}
@@ -656,7 +569,7 @@ public class TryOnEffectServiceImpl extends ServiceImpl<TryOnEffectMapper, TryOn
String finishReason = candidate.getString("finishReason");
if (!"STOP".equals(finishReason)) {
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")) {
finishMessage = "Try rephrasing the prompt.If you think this was an error, send feedback.";
throw new BusinessException(finishMessage, "请尝试重新表述提示词。若您认为这是误判,可提交反馈。", ResultEnum.ERROR.getCode());
@@ -703,22 +616,21 @@ public class TryOnEffectServiceImpl extends ServiceImpl<TryOnEffectMapper, TryOn
/**
* 调用换脸API
*
* @param imageUrls 图片URL列表第一个为源图片第二个为目标图片
* @return 换脸后的图片URL
*/
private String callFaceSwapAPI(List<String> imageUrls) {
try {
log.info("开始调用换脸API - 源图片: {}, 目标图片: {}", imageUrls.get(0), imageUrls.get(1));
String inputFaceUrl = imageUrls.get(1);
// 构建输入图片列表(从第二张图片开始作为目标图片列表)
JSONArray inputImageList = new JSONArray();
inputImageList.add(imageUrls.get(0));
inputImageList.add(imageUrls.get(0));
// 构建请求体
JSONObject requestBody = new JSONObject();
@@ -726,11 +638,9 @@ public class TryOnEffectServiceImpl extends ServiceImpl<TryOnEffectMapper, TryOn
requestBody.put("input_face", inputFaceUrl);
requestBody.put("threshold", 0.2);
log.info("换脸API请求体: {}", requestBody.toString());
// 调用换脸API
String response = sendFaceSwapRequest(faceSwapConfig.getRefaceUrl(), requestBody.toString());
// 处理响应
return processFaceSwapResponse(response);
@@ -811,18 +721,19 @@ public class TryOnEffectServiceImpl extends ServiceImpl<TryOnEffectMapper, TryOn
log.info("开始处理换脸API响应: {}", response);
com.alibaba.fastjson.JSONObject jsonResponse = com.alibaba.fastjson.JSON.parseObject(response);
// 处理新的响应格式: {"output":["lanecarford/refaced_image/refaced1761809361.530157.png"]}
if (jsonResponse.containsKey("output")) {
Object outputObj = jsonResponse.get("output");
if (outputObj instanceof JSONArray) {
JSONArray outputArray = (JSONArray) outputObj;
if (outputArray.size() > 0) {
String imagePath = outputArray.getString(0);
log.info("换脸成功,图片路径: {}", imagePath);
// 下载图片并上传到MinIO
return imagePath;
} else {
@@ -833,7 +744,7 @@ public class TryOnEffectServiceImpl extends ServiceImpl<TryOnEffectMapper, TryOn
log.error("output字段不是数组格式: {}", outputObj);
throw new BusinessException("Invalid output format", "output字段格式不正确", ResultEnum.ERROR.getCode());
}
} else {
}else {
log.error("换脸API响应失败: {}", response);
throw new BusinessException("reface error", "换脸失败", ResultEnum.ERROR.getCode());
}
@@ -863,7 +774,7 @@ public class TryOnEffectServiceImpl extends ServiceImpl<TryOnEffectMapper, TryOn
if (!response.isSuccessful()) {
throw new IOException("Failed to download image: HTTP " + response.code());
}
return response.body().bytes();
}
}

View File

@@ -1,15 +0,0 @@
package com.aida.lanecarford.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serializable;
@Data
public class BaseVO implements Serializable {
private static final long serialVersionUID = 10007L;
@Schema(description = "ID")
private Long id;
}

View File

@@ -1,11 +0,0 @@
package com.aida.lanecarford.vo;
import lombok.Data;
@Data
public class OutfitHisVO extends BaseVO {
private String url;
private Integer isFavorite;
}

View File

@@ -3,7 +3,9 @@ package com.aida.lanecarford.vo;
import lombok.Data;
@Data
public class TryOnResultVO extends BaseVO {
public class TryOnResultVo {
private Long tryOnId;
private String tryOnUrl;

View File

@@ -71,7 +71,6 @@ CREATE TABLE `styles` (
`style_image_url` varchar(500) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '风格图片URL',
`python_request_id` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Python请求ID',
`generation_status` tinyint DEFAULT '0' COMMENT '生成状态(0-处理中,1-已完成,2-失败)',
`is_favorite` tinyint NOT NULL DEFAULT '0' COMMENT '是否喜欢(0-否,1-是)',
`items` json DEFAULT NULL COMMENT '单品唯一标识',
`error_message` text COLLATE utf8mb4_unicode_ci COMMENT '错误信息',
`created_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',