Compare commits
16 Commits
dev/dev
...
prod/relea
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5f2825af80 | ||
|
|
01d1e69e17 | ||
| 8bc8bc08da | |||
| 413e4cb7fb | |||
| c376acfb2c | |||
| d7d0fc53fd | |||
|
|
655f434cf0 | ||
| fd61c6b588 | |||
| 595c1eeaa8 | |||
| f74685c4d1 | |||
|
|
318309c770 | ||
|
|
4f149263a5 | ||
| fecf9bcb61 | |||
|
|
190a57c855 | ||
| 278510aa21 | |||
| 91eb21aa84 |
@@ -4,6 +4,9 @@ services:
|
|||||||
build: .
|
build: .
|
||||||
volumes:
|
volumes:
|
||||||
# 日志目录映射
|
# 日志目录映射
|
||||||
- ./log:/log
|
- ./log:/app/log
|
||||||
ports:
|
ports:
|
||||||
- '10095:8080'
|
- '10095:8080'
|
||||||
|
networks:
|
||||||
|
back_default:
|
||||||
|
driver: bridge
|
||||||
@@ -21,7 +21,13 @@ public enum StatusEnum {
|
|||||||
FAILED(2),
|
FAILED(2),
|
||||||
|
|
||||||
@Schema(description = "运行中")
|
@Schema(description = "运行中")
|
||||||
RUNNING(3);
|
RUNNING(3),
|
||||||
|
|
||||||
|
@Schema(description = "重试中")
|
||||||
|
RETRYING(4),
|
||||||
|
|
||||||
|
@Schema(description = "生成即将结束")
|
||||||
|
ALMOST_DONE(5);
|
||||||
|
|
||||||
private int code;
|
private int code;
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,11 @@ public enum StylistPathEnum {
|
|||||||
|
|
||||||
STYLIST_ONE("crystal", "lanecarford/stylist_guide/latest/crystal_en.md"),
|
STYLIST_ONE("crystal", "lanecarford/stylist_guide/latest/crystal_en.md"),
|
||||||
|
|
||||||
STYLIST_TWO("mini", "lanecarford/stylist_guide/latest/mini_en.md");
|
STYLIST_TWO("mini", "lanecarford/stylist_guide/latest/mini_en.md"),
|
||||||
|
|
||||||
|
STYLIST_THREE("vera", "lanecarford/stylist_guide/latest/mini_en.md"),
|
||||||
|
|
||||||
|
STYLIST_FOUR("edi", "lanecarford/stylist_guide/latest/mini_en.md");
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package com.aida.lanecarford.common.security;
|
|||||||
|
|
||||||
import com.aida.lanecarford.common.security.config.JwtProperties;
|
import com.aida.lanecarford.common.security.config.JwtProperties;
|
||||||
import com.aida.lanecarford.common.security.context.UserContext;
|
import com.aida.lanecarford.common.security.context.UserContext;
|
||||||
import com.aida.lanecarford.exception.BusinessException;
|
|
||||||
import com.aida.lanecarford.util.CacheUtil;
|
import com.aida.lanecarford.util.CacheUtil;
|
||||||
import com.aida.lanecarford.vo.AuthPrincipalVO;
|
import com.aida.lanecarford.vo.AuthPrincipalVO;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
@@ -25,7 +24,7 @@ public class JwtInterceptor implements HandlerInterceptor {
|
|||||||
private final JwtProperties jwtProperties;
|
private final JwtProperties jwtProperties;
|
||||||
|
|
||||||
@Override
|
@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())) {
|
if ("OPTIONS".equalsIgnoreCase(request.getMethod())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -41,7 +40,8 @@ public class JwtInterceptor implements HandlerInterceptor {
|
|||||||
String extracted = jwtUtil.extractUserinfo(jwtToken);
|
String extracted = jwtUtil.extractUserinfo(jwtToken);
|
||||||
if (StringUtil.isNullOrEmpty(extracted)) {
|
if (StringUtil.isNullOrEmpty(extracted)) {
|
||||||
log.warn("TOKEN已过期,请重新登录!(token without userInfo)");
|
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);
|
AuthPrincipalVO authPrincipalVO = JSONObject.parseObject(extracted, AuthPrincipalVO.class);
|
||||||
@@ -54,10 +54,12 @@ public class JwtInterceptor implements HandlerInterceptor {
|
|||||||
|
|
||||||
if (Objects.isNull(token)) {
|
if (Objects.isNull(token)) {
|
||||||
log.warn("TOKEN已过期,请重新登录!(local cache empty)");
|
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)) {
|
} else if (!token.toString().equals(jwtToken)) {
|
||||||
log.warn("TOKEN已过期,请重新登录!(token not match local cache)");
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.aida.lanecarford.common.ApiResponse;
|
|||||||
import com.aida.lanecarford.dto.CustomerPhotoDto;
|
import com.aida.lanecarford.dto.CustomerPhotoDto;
|
||||||
import com.aida.lanecarford.entity.CustomerPhoto;
|
import com.aida.lanecarford.entity.CustomerPhoto;
|
||||||
import com.aida.lanecarford.service.CustomerPhotoService;
|
import com.aida.lanecarford.service.CustomerPhotoService;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
@@ -24,7 +25,7 @@ public class CustomerPhotoController {
|
|||||||
private final CustomerPhotoService customerPhotoService;
|
private final CustomerPhotoService customerPhotoService;
|
||||||
|
|
||||||
@PostMapping("/upload")
|
@PostMapping("/upload")
|
||||||
public ApiResponse<CustomerPhoto> upload(@ModelAttribute CustomerPhotoDto customerPhotoDto) {
|
public ApiResponse<CustomerPhoto> upload(@Valid @ModelAttribute CustomerPhotoDto customerPhotoDto) {
|
||||||
CustomerPhoto customerPhoto = customerPhotoService.upload(customerPhotoDto);
|
CustomerPhoto customerPhoto = customerPhotoService.upload(customerPhotoDto);
|
||||||
return ApiResponse.success(customerPhoto);
|
return ApiResponse.success(customerPhoto);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -121,4 +121,12 @@ public class LoginController {
|
|||||||
return ApiResponse.success(loginService.parseGoogleAccessToken(accessToken));
|
return ApiResponse.success(loginService.parseGoogleAccessToken(accessToken));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//修改用户信息
|
||||||
|
@Operation(summary = "修改用户信息",
|
||||||
|
description = "传username,email,password三个值,password要加密")
|
||||||
|
@PostMapping("/updateUserInfo")
|
||||||
|
public ApiResponse<String> updateUserInfo(@RequestBody User user) {
|
||||||
|
return ApiResponse.success(loginService.updateUserInfo(user));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,8 +109,10 @@ public class StyleController {
|
|||||||
@GetMapping("/retrieveAndRegenerate")
|
@GetMapping("/retrieveAndRegenerate")
|
||||||
public ApiResponse<List<String>> retrieveAndRegenerate(
|
public ApiResponse<List<String>> retrieveAndRegenerate(
|
||||||
@Parameter(description = "tryOn后的图片id", required = true, example = "1369")
|
@Parameter(description = "tryOn后的图片id", required = true, example = "1369")
|
||||||
@RequestParam Long tryOnEffectsId) {
|
@RequestParam Long tryOnEffectsId,
|
||||||
return ApiResponse.success(styleService.retrieveAndRegenerate(tryOnEffectsId));
|
@Parameter(description = "用户进店记录", required = true, example = "3")
|
||||||
|
@RequestParam Long checkInId ) {
|
||||||
|
return ApiResponse.success(styleService.retrieveAndRegenerate(tryOnEffectsId, checkInId));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -92,28 +92,28 @@ public class TryOnEffectController {
|
|||||||
return ApiResponse.success();
|
return ApiResponse.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* 首页默认图换脸演示
|
// * 首页默认图换脸演示
|
||||||
*/
|
// */
|
||||||
@Operation(summary = "首页点击换脸", description = "传入上传顾客照片后得到的ID")
|
// @Operation(summary = "首页点击换脸", description = "传入上传顾客照片后得到的ID")
|
||||||
@PostMapping("/reFace")
|
// @PostMapping("/reFace")
|
||||||
public ApiResponse<String> reFace(@Nullable @RequestParam Long customerPhotoId,
|
// public ApiResponse<String> reFace(@Nullable @RequestParam Long customerPhotoId,
|
||||||
@Nullable @RequestParam String prompt,
|
// @Nullable @RequestParam String prompt,
|
||||||
@Nullable @RequestParam String tryonUrl) {
|
// @Nullable @RequestParam String tryonUrl) {
|
||||||
if (customerPhotoId == null&& StringUtil.isNullOrEmpty(prompt)&& StringUtil.isNullOrEmpty(tryonUrl)){
|
// if (customerPhotoId == null&& StringUtil.isNullOrEmpty(prompt)&& StringUtil.isNullOrEmpty(tryonUrl)){
|
||||||
return ApiResponse.error("system error:Parameter null");
|
// return ApiResponse.error("system error:Parameter null");
|
||||||
}
|
// }
|
||||||
String result = "";
|
// String result = "";
|
||||||
if (StringUtil.isNullOrEmpty(prompt)){
|
// if (StringUtil.isNullOrEmpty(prompt)){
|
||||||
//换脸
|
// //换脸
|
||||||
result = tryOnEffectService.reFace(customerPhotoId);
|
// result = tryOnEffectService.reFace(customerPhotoId);
|
||||||
}else {
|
// }else {
|
||||||
if (StringUtil.isNullOrEmpty(tryonUrl)){
|
// if (StringUtil.isNullOrEmpty(tryonUrl)){
|
||||||
return ApiResponse.error("system error:Parameter null");
|
// return ApiResponse.error("system error:Parameter null");
|
||||||
}
|
// }
|
||||||
//根据提示词修改图像
|
// //根据提示词修改图像
|
||||||
result = tryOnEffectService.generateUrl(prompt,tryonUrl);
|
// result = tryOnEffectService.generateUrl(prompt,tryonUrl);
|
||||||
}
|
// }
|
||||||
return ApiResponse.success("操作成功",result);
|
// return ApiResponse.success("操作成功",result);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,7 @@ public class OutfitCallbackDTO {
|
|||||||
|
|
||||||
private String outfit_id;
|
private String outfit_id;
|
||||||
|
|
||||||
// 取值范围:ok || failed || stop
|
// 取值范围:ok || failed || stop || retrying || retry_failed
|
||||||
private String status;
|
private String status;
|
||||||
|
|
||||||
private String path;
|
private String path;
|
||||||
|
|||||||
@@ -88,6 +88,12 @@ public class GlobalExceptionHandler {
|
|||||||
|
|
||||||
logger.error("MinIO异常: {}", e.getMessage(), e);
|
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");
|
return ApiResponse.error(ResultEnum.ERROR.getCode(), "File storage service error");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,4 +36,6 @@ public interface LoginService extends IService<User> {
|
|||||||
LoginVO parseGoogleCredential(String credential) throws ParseException, JOSEException, IOException;
|
LoginVO parseGoogleCredential(String credential) throws ParseException, JOSEException, IOException;
|
||||||
|
|
||||||
LoginVO parseGoogleAccessToken(String accessToken);
|
LoginVO parseGoogleAccessToken(String accessToken);
|
||||||
|
|
||||||
|
String updateUserInfo(User user);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,6 @@ public interface StyleService extends IService<Style> {
|
|||||||
*/
|
*/
|
||||||
void cancelFavoriteStyle(Long styleId);
|
void cancelFavoriteStyle(Long styleId);
|
||||||
|
|
||||||
List<String> retrieveAndRegenerate(Long tryOnEffectsId);
|
List<String> retrieveAndRegenerate(Long tryOnEffectsId, Long checkInId);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -44,8 +44,8 @@ public interface TryOnEffectService extends IService<TryOnEffect> {
|
|||||||
*/
|
*/
|
||||||
boolean addComment(Suggestion suggestion);
|
boolean addComment(Suggestion suggestion);
|
||||||
|
|
||||||
|
//已废弃
|
||||||
String reFace(Long customerPhotoId);
|
String reFace(Long customerPhotoId);
|
||||||
|
|
||||||
String generateUrl(String prompt, String tryonUrl);
|
String generateUrl(String prompt, String tryonUrl);
|
||||||
|
|
||||||
PageResult<TryOnResultVO> getTryOnHistoricals(HistoricalDTO historicalDTO);
|
PageResult<TryOnResultVO> getTryOnHistoricals(HistoricalDTO historicalDTO);
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
package com.aida.lanecarford.service.impl;
|
package com.aida.lanecarford.service.impl;
|
||||||
|
|
||||||
import com.aida.lanecarford.common.constant.MinioFileConstants;
|
import com.aida.lanecarford.common.constant.MinioFileConstants;
|
||||||
|
import com.aida.lanecarford.common.response.ResultEnum;
|
||||||
import com.aida.lanecarford.config.MinioConfig;
|
import com.aida.lanecarford.config.MinioConfig;
|
||||||
import com.aida.lanecarford.dto.CustomerPhotoDto;
|
import com.aida.lanecarford.dto.CustomerPhotoDto;
|
||||||
import com.aida.lanecarford.entity.CustomerPhoto;
|
import com.aida.lanecarford.entity.CustomerPhoto;
|
||||||
|
import com.aida.lanecarford.exception.BusinessException;
|
||||||
import com.aida.lanecarford.mapper.CustomerPhotoMapper;
|
import com.aida.lanecarford.mapper.CustomerPhotoMapper;
|
||||||
import com.aida.lanecarford.service.CustomerPhotoService;
|
import com.aida.lanecarford.service.CustomerPhotoService;
|
||||||
import com.aida.lanecarford.util.CopyUtil;
|
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 com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 顾客照片服务实现类
|
* 顾客照片服务实现类
|
||||||
@@ -26,9 +29,14 @@ public class CustomerPhotoServiceImpl extends ServiceImpl<CustomerPhotoMapper, C
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CustomerPhoto upload(CustomerPhotoDto customerPhotoDto) {
|
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(
|
String logicalUrl = minioUtil.uploadFile(
|
||||||
customerPhotoDto.getFile(),
|
file,
|
||||||
MinioFileConstants.FileType.CUSTOMER_PHOTO,
|
MinioFileConstants.FileType.CUSTOMER_PHOTO,
|
||||||
minioConfig.getBucketName()
|
minioConfig.getBucketName()
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -108,6 +108,8 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
|
|||||||
customer.setCreatedTime(LocalDateTime.now());
|
customer.setCreatedTime(LocalDateTime.now());
|
||||||
|
|
||||||
save(customer);
|
save(customer);
|
||||||
|
} else {
|
||||||
|
throw new BusinessException("VIP ID'" + vipId + "' already exists.Please proceed directly to check-in.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return customer;
|
return customer;
|
||||||
|
|||||||
@@ -353,6 +353,66 @@ public class LoginServiceImpl extends ServiceImpl<UserMapper, User> implements L
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String updateUserInfo(User user) {
|
||||||
|
// 1. 获取当前登录用户ID
|
||||||
|
AuthPrincipalVO userHolder = UserContext.getUserHolder();
|
||||||
|
if (Objects.isNull(userHolder)) {
|
||||||
|
throw new BusinessException("User not logged in", "用户未登录", ResultEnum.ERROR.getCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
Long userId = userHolder.getId();
|
||||||
|
|
||||||
|
// 2. 验证用户是否存在
|
||||||
|
User existingUser = getById(userId);
|
||||||
|
if (Objects.isNull(existingUser)) {
|
||||||
|
throw new BusinessException("User not found", "用户不存在", ResultEnum.ERROR.getCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 构建更新条件,只更新有值的字段
|
||||||
|
UpdateWrapper<User> updateWrapper = new UpdateWrapper<>();
|
||||||
|
updateWrapper.lambda().eq(User::getId, userId);
|
||||||
|
|
||||||
|
boolean hasUpdate = false;
|
||||||
|
|
||||||
|
// 如果username有值,则更新
|
||||||
|
if (!StringUtil.isNullOrEmpty(user.getUsername())) {
|
||||||
|
updateWrapper.lambda().set(User::getUsername, user.getUsername());
|
||||||
|
hasUpdate = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果email有值,则更新
|
||||||
|
if (!StringUtil.isNullOrEmpty(user.getEmail())) {
|
||||||
|
updateWrapper.lambda().set(User::getEmail, user.getEmail());
|
||||||
|
hasUpdate = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果password有值,则更新
|
||||||
|
if (!StringUtil.isNullOrEmpty(user.getPassword())) {
|
||||||
|
updateWrapper.lambda().set(User::getPassword, user.getPassword());
|
||||||
|
hasUpdate = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. 如果没有需要更新的字段,返回提示信息
|
||||||
|
if (!hasUpdate) {
|
||||||
|
return "No fields to update";
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. 执行更新
|
||||||
|
boolean updated = update(updateWrapper);
|
||||||
|
|
||||||
|
if (updated) {
|
||||||
|
log.info("用户信息更新成功 userId={}, updatedFields=username:{}, email:{}, password:{}",
|
||||||
|
userId,
|
||||||
|
!StringUtil.isNullOrEmpty(user.getUsername()),
|
||||||
|
!StringUtil.isNullOrEmpty(user.getEmail()),
|
||||||
|
!StringUtil.isNullOrEmpty(user.getPassword()));
|
||||||
|
return "User information updated successfully";
|
||||||
|
} else {
|
||||||
|
throw new BusinessException("Failed to update user information", "更新用户信息失败", ResultEnum.ERROR.getCode());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static final String TOKEN_URL = "https://oauth2.googleapis.com/token";
|
private static final String TOKEN_URL = "https://oauth2.googleapis.com/token";
|
||||||
|
|
||||||
public GoogleUser getGoogleUserFromCode(String code) {
|
public GoogleUser getGoogleUserFromCode(String code) {
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import com.alibaba.fastjson2.JSON;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import io.netty.util.internal.StringUtil;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@@ -62,6 +61,10 @@ public class StyleServiceImpl extends ServiceImpl<StyleMapper, Style> implements
|
|||||||
// 请求需要顾客id, 生成的数量,风格
|
// 请求需要顾客id, 生成的数量,风格
|
||||||
|
|
||||||
StylistPathEnum stylistPathEnum = StylistPathEnum.of(requestOutfitDTO.getStylist());
|
StylistPathEnum stylistPathEnum = StylistPathEnum.of(requestOutfitDTO.getStylist());
|
||||||
|
if (Objects.isNull(stylistPathEnum)) {
|
||||||
|
log.error("未知设计师: {}",requestOutfitDTO.getStylist() );
|
||||||
|
stylistPathEnum = StylistPathEnum.STYLIST_ONE;
|
||||||
|
}
|
||||||
Map<String, Object> params = setRequestOutfitParams(requestOutfitDTO, stylistPathEnum);
|
Map<String, Object> params = setRequestOutfitParams(requestOutfitDTO, stylistPathEnum);
|
||||||
|
|
||||||
SessionRecord sessionRecord = saveOrUpdateSession(requestOutfitDTO.getSessionId(), requestOutfitDTO.getCheckInId(), null, null);
|
SessionRecord sessionRecord = saveOrUpdateSession(requestOutfitDTO.getSessionId(), requestOutfitDTO.getCheckInId(), null, null);
|
||||||
@@ -101,6 +104,7 @@ public class StyleServiceImpl extends ServiceImpl<StyleMapper, Style> implements
|
|||||||
|
|
||||||
String key = RedisURIConstants.outfitResultCache + requestId;
|
String key = RedisURIConstants.outfitResultCache + requestId;
|
||||||
OutfitResultVO outfitResultVO = new OutfitResultVO(style.getId(), requestId, StatusEnum.PENDING.name());
|
OutfitResultVO outfitResultVO = new OutfitResultVO(style.getId(), requestId, StatusEnum.PENDING.name());
|
||||||
|
outfitResultVO.setCreateTimeStamp(System.currentTimeMillis());
|
||||||
cacheUtil.setCache(key, outfitResultVO, RedisURIConstants.verifyCodeTimeout);
|
cacheUtil.setCache(key, outfitResultVO, RedisURIConstants.verifyCodeTimeout);
|
||||||
}
|
}
|
||||||
return requestIds;
|
return requestIds;
|
||||||
@@ -129,44 +133,74 @@ public class StyleServiceImpl extends ServiceImpl<StyleMapper, Style> implements
|
|||||||
|
|
||||||
// 搭配完成后的回调通知处理
|
// 搭配完成后的回调通知处理
|
||||||
public void callback(OutfitCallbackDTO callbackDTO) {
|
public void callback(OutfitCallbackDTO callbackDTO) {
|
||||||
if (Objects.isNull(callbackDTO.getStatus())) {
|
if (Objects.isNull(callbackDTO.getStatus())
|
||||||
|
|| callbackDTO.getStatus().equals("failed")
|
||||||
|
|| callbackDTO.getStatus().equals("continue")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("ok".equals(callbackDTO.getStatus()) || "stop".equals(callbackDTO.getStatus())) {
|
// 1. 判断path是否为空,是 -> 不做任何处理
|
||||||
// 1. 判断path是否为空,是 -> 不做任何处理
|
if (("ok".equals(callbackDTO.getStatus())
|
||||||
if (StringUtil.isNullOrEmpty(callbackDTO.getPath())) {
|
|| "stop".equals(callbackDTO.getStatus()))
|
||||||
return;
|
&& StringUtils.isBlank(callbackDTO.getPath())) {
|
||||||
|
log.error("状态为ok || stop时,path为空");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isBlank(callbackDTO.getOutfit_id())) {
|
||||||
|
log.error("回调参数中,outfit_id为空");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String requestId = callbackDTO.getOutfit_id();
|
||||||
|
|
||||||
|
// 2. 获取outfit_id,查询数据库
|
||||||
|
String key = RedisURIConstants.outfitResultCache + requestId;
|
||||||
|
Object outfitResult = cacheUtil.getCache(key);
|
||||||
|
if (Objects.isNull(outfitResult)) {
|
||||||
|
log.error("未知搭配请求");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3.更新path, items, 状态
|
||||||
|
// 由于数据变化较频繁,考虑存到redis
|
||||||
|
if (outfitResult instanceof OutfitResultVO) {
|
||||||
|
String status;
|
||||||
|
switch(callbackDTO.getStatus()) {
|
||||||
|
case "ok":
|
||||||
|
status = StatusEnum.RUNNING.name();
|
||||||
|
((OutfitResultVO) outfitResult).setPath(minioUtil.getPresignedUrl(callbackDTO.getPath(), CommonConstants.MINIO_PATH_TIMEOUT));
|
||||||
|
break;
|
||||||
|
case "stop":
|
||||||
|
status = StatusEnum.SUCCEEDED.name();
|
||||||
|
((OutfitResultVO) outfitResult).setPath(minioUtil.getPresignedUrl(callbackDTO.getPath(), CommonConstants.MINIO_PATH_TIMEOUT));
|
||||||
|
break;
|
||||||
|
case "retrying":
|
||||||
|
status = StatusEnum.PENDING.name();
|
||||||
|
((OutfitResultVO) outfitResult).setCreateTimeStamp(System.currentTimeMillis());
|
||||||
|
((OutfitResultVO) outfitResult).setPath(null);
|
||||||
|
break;
|
||||||
|
case "almost_done":
|
||||||
|
// 此时是没有更新path的
|
||||||
|
status = StatusEnum.ALMOST_DONE.name();
|
||||||
|
break;
|
||||||
|
case /*"failed",*/ "retry_failed":
|
||||||
|
status = StatusEnum.FAILED.name();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
log.error("outfit_id为{},回调状态未知{}", requestId, callbackDTO.getStatus());
|
||||||
|
status = StatusEnum.FAILED.name();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StringUtil.isNullOrEmpty(callbackDTO.getOutfit_id())) {
|
((OutfitResultVO) outfitResult).setStatus(status);
|
||||||
log.error("回调参数中,outfit_id为空");
|
cacheUtil.setCache(key, outfitResult, RedisURIConstants.outfitResultTimeout);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String requestId = callbackDTO.getOutfit_id();
|
|
||||||
|
|
||||||
// 2. 获取outfit_id,查询数据库
|
|
||||||
String key = RedisURIConstants.outfitResultCache + requestId;
|
|
||||||
Object outfitResult = cacheUtil.getCache(key);
|
|
||||||
if (Objects.isNull(outfitResult)) {
|
|
||||||
log.error("未知搭配请求");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3.更新path, items, 状态
|
|
||||||
// 由于数据变化较频繁,考虑存到redis
|
|
||||||
if (outfitResult instanceof OutfitResultVO) {
|
|
||||||
((OutfitResultVO) outfitResult).setPath(minioUtil.getPresignedUrl(callbackDTO.getPath(), CommonConstants.MINIO_PATH_TIMEOUT));
|
|
||||||
String status = "ok".equals(callbackDTO.getStatus()) ? StatusEnum.RUNNING.name() : StatusEnum.SUCCEEDED.name();
|
|
||||||
((OutfitResultVO) outfitResult).setStatus(status);
|
|
||||||
cacheUtil.setCache(key, outfitResult, RedisURIConstants.outfitResultTimeout);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 生成结束或失败时更新数据库
|
// 生成结束或失败时更新数据库
|
||||||
if ("stop".equals(callbackDTO.getStatus()) || "failed".equals(callbackDTO.getStatus())) {
|
if ("stop".equals(callbackDTO.getStatus())
|
||||||
String requestId = callbackDTO.getOutfit_id();
|
/*|| "failed".equals(callbackDTO.getStatus())*/
|
||||||
|
|| "retry_failed".equals(callbackDTO.getStatus())) {
|
||||||
|
// String requestId = callbackDTO.getOutfit_id();
|
||||||
|
|
||||||
LambdaQueryWrapper<Style> queryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<Style> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
queryWrapper.eq(Style::getPythonRequestId, requestId);
|
queryWrapper.eq(Style::getPythonRequestId, requestId);
|
||||||
@@ -198,6 +232,7 @@ public class StyleServiceImpl extends ServiceImpl<StyleMapper, Style> implements
|
|||||||
public List<OutfitResultVO> getOutfitResult(List<String> requestIDs) {
|
public List<OutfitResultVO> getOutfitResult(List<String> requestIDs) {
|
||||||
ArrayList<OutfitResultVO> resultVOS = new ArrayList<>();
|
ArrayList<OutfitResultVO> resultVOS = new ArrayList<>();
|
||||||
ArrayList<String> reQueryIds = new ArrayList<>();
|
ArrayList<String> reQueryIds = new ArrayList<>();
|
||||||
|
List<String> expiredIds = new ArrayList<>();
|
||||||
// 优先从redis中获取结果,没有再从数据库中查询
|
// 优先从redis中获取结果,没有再从数据库中查询
|
||||||
for (String requestID : requestIDs) {
|
for (String requestID : requestIDs) {
|
||||||
String key = RedisURIConstants.outfitResultCache + requestID;
|
String key = RedisURIConstants.outfitResultCache + requestID;
|
||||||
@@ -207,7 +242,25 @@ public class StyleServiceImpl extends ServiceImpl<StyleMapper, Style> implements
|
|||||||
reQueryIds.add(requestID);
|
reQueryIds.add(requestID);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
resultVOS.add((OutfitResultVO) outfit);
|
|
||||||
|
// 判断这条记录的状态是否为成功或者失败,否,判断这条记录的创建时间是否超过3分钟,否,继续往后,是,设置为失败并更新数据库
|
||||||
|
if (outfit instanceof OutfitResultVO) {
|
||||||
|
if ((((OutfitResultVO) outfit).getStatus().equals(StatusEnum.PENDING.name())
|
||||||
|
|| ((OutfitResultVO) outfit).getStatus().equals(StatusEnum.RUNNING.name())
|
||||||
|
|| ((OutfitResultVO) outfit).getStatus().equals(StatusEnum.ALMOST_DONE.name()))
|
||||||
|
&& isExpired(((OutfitResultVO) outfit).getCreateTimeStamp())) {
|
||||||
|
// 设置状态为失败
|
||||||
|
((OutfitResultVO) outfit).setStatus(StatusEnum.FAILED.name());
|
||||||
|
// 更新redis和数据库状态
|
||||||
|
expiredIds.add(requestID);
|
||||||
|
cacheUtil.setCache(key, outfit, RedisURIConstants.outfitResultTimeout);
|
||||||
|
}
|
||||||
|
resultVOS.add((OutfitResultVO) outfit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!expiredIds.isEmpty()) {
|
||||||
|
batchUpdateExpiredRecords(expiredIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!reQueryIds.isEmpty()) {
|
if (!reQueryIds.isEmpty()) {
|
||||||
@@ -216,12 +269,13 @@ public class StyleServiceImpl extends ServiceImpl<StyleMapper, Style> implements
|
|||||||
|
|
||||||
List<Style> list = list(queryWrapper);
|
List<Style> list = list(queryWrapper);
|
||||||
if (!list.isEmpty()) {
|
if (!list.isEmpty()) {
|
||||||
|
// 在数据库中的数据,都是处于成功或失败的状态
|
||||||
for (Style style : list) {
|
for (Style style : list) {
|
||||||
OutfitResultVO outfitResultVO = new OutfitResultVO();
|
OutfitResultVO outfitResultVO = new OutfitResultVO();
|
||||||
outfitResultVO.setId(style.getId());
|
outfitResultVO.setId(style.getId());
|
||||||
outfitResultVO.setRequestId(style.getPythonRequestId());
|
outfitResultVO.setRequestId(style.getPythonRequestId());
|
||||||
outfitResultVO.setStatus(StatusEnum.of(style.getGenerationStatus()).name());
|
outfitResultVO.setStatus(StatusEnum.of(style.getGenerationStatus()).name());
|
||||||
if (!StringUtil.isNullOrEmpty(style.getStyleImageUrl())) {
|
if (!StringUtils.isBlank(style.getStyleImageUrl())) {
|
||||||
outfitResultVO.setPath(minioUtil.getPresignedUrl(style.getStyleImageUrl(), CommonConstants.MINIO_PATH_TIMEOUT));
|
outfitResultVO.setPath(minioUtil.getPresignedUrl(style.getStyleImageUrl(), CommonConstants.MINIO_PATH_TIMEOUT));
|
||||||
}
|
}
|
||||||
resultVOS.add(outfitResultVO);
|
resultVOS.add(outfitResultVO);
|
||||||
@@ -232,6 +286,34 @@ public class StyleServiceImpl extends ServiceImpl<StyleMapper, Style> implements
|
|||||||
return resultVOS;
|
return resultVOS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 3分钟的毫秒数
|
||||||
|
private static final long THREE_MINUTES_IN_MILLIS = 3 * 60 * 1000;
|
||||||
|
|
||||||
|
private boolean isExpired(long createTimeMillis) {
|
||||||
|
long currentTimeMillis = System.currentTimeMillis();
|
||||||
|
return (currentTimeMillis - createTimeMillis) >= THREE_MINUTES_IN_MILLIS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void batchUpdateExpiredRecords(List<String> expiredIds) {
|
||||||
|
try {
|
||||||
|
if (CollectionUtils.isEmpty(expiredIds)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 批量更新,减少数据库压力
|
||||||
|
lambdaUpdate()
|
||||||
|
.in(Style::getPythonRequestId, expiredIds)
|
||||||
|
.set(Style::getGenerationStatus, StatusEnum.FAILED.getCode())
|
||||||
|
.set(Style::getUpdatedTime, LocalDateTime.now())
|
||||||
|
.update();
|
||||||
|
|
||||||
|
log.info("批量更新过期记录为失败状态,数量:{}", expiredIds.size());
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("批量更新过期记录失败", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setFavoriteStyle(Long styleId) {
|
public void setFavoriteStyle(Long styleId) {
|
||||||
if (styleId == null) {
|
if (styleId == null) {
|
||||||
@@ -291,7 +373,7 @@ public class StyleServiceImpl extends ServiceImpl<StyleMapper, Style> implements
|
|||||||
return sessionRecord;
|
return sessionRecord;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> retrieveAndRegenerate(Long tryOnEffectsId) {
|
public List<String> retrieveAndRegenerate(Long tryOnEffectsId, Long checkInId) {
|
||||||
// 1. 判断id是否有效
|
// 1. 判断id是否有效
|
||||||
TryOnEffect tryOnEffect = tryOnEffectMapper.selectById(tryOnEffectsId);
|
TryOnEffect tryOnEffect = tryOnEffectMapper.selectById(tryOnEffectsId);
|
||||||
if (Objects.isNull(tryOnEffect)) {
|
if (Objects.isNull(tryOnEffect)) {
|
||||||
@@ -302,6 +384,10 @@ public class StyleServiceImpl extends ServiceImpl<StyleMapper, Style> implements
|
|||||||
log.error("Id 为:{} 的tryOnEffects记录,没有style_id", tryOnEffectsId);
|
log.error("Id 为:{} 的tryOnEffects记录,没有style_id", tryOnEffectsId);
|
||||||
throw new BusinessException("Cannot recreate outfit from past data.");
|
throw new BusinessException("Cannot recreate outfit from past data.");
|
||||||
}
|
}
|
||||||
|
if (Objects.isNull(checkInId)) {
|
||||||
|
log.error("checkInId 为空");
|
||||||
|
throw new BusinessException("'checkInId' cannot be empty");
|
||||||
|
}
|
||||||
|
|
||||||
// 2. 组装参数
|
// 2. 组装参数
|
||||||
Style style = baseMapper.selectById(tryOnEffect.getStyleId());
|
Style style = baseMapper.selectById(tryOnEffect.getStyleId());
|
||||||
@@ -316,7 +402,7 @@ public class StyleServiceImpl extends ServiceImpl<StyleMapper, Style> implements
|
|||||||
log.error("找不到Id 为:{} 的SessionRecord记录", outfitRequest.getSessionRecordId());
|
log.error("找不到Id 为:{} 的SessionRecord记录", outfitRequest.getSessionRecordId());
|
||||||
throw new BusinessException("Cannot recreate outfit from past data.");
|
throw new BusinessException("Cannot recreate outfit from past data.");
|
||||||
}
|
}
|
||||||
RequestOutfitDTO requestOutfitDTO = getRequestOutfitDTO(outfitRequest, sessionRecord);
|
RequestOutfitDTO requestOutfitDTO = getRequestOutfitDTO(outfitRequest, sessionRecord, checkInId);
|
||||||
|
|
||||||
return requestOutfit(requestOutfitDTO);
|
return requestOutfit(requestOutfitDTO);
|
||||||
} else {
|
} else {
|
||||||
@@ -326,10 +412,10 @@ public class StyleServiceImpl extends ServiceImpl<StyleMapper, Style> implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static RequestOutfitDTO getRequestOutfitDTO(OutfitRequest outfitRequest, SessionRecord sessionRecord) {
|
private static RequestOutfitDTO getRequestOutfitDTO(OutfitRequest outfitRequest, SessionRecord sessionRecord, Long checkInId) {
|
||||||
RequestOutfitDTO requestOutfitDTO = new RequestOutfitDTO();
|
RequestOutfitDTO requestOutfitDTO = new RequestOutfitDTO();
|
||||||
requestOutfitDTO.setCustomerId(outfitRequest.getCustomerId());
|
requestOutfitDTO.setCustomerId(outfitRequest.getCustomerId());
|
||||||
requestOutfitDTO.setCheckInId(outfitRequest.getVisitRecordId());
|
requestOutfitDTO.setCheckInId(checkInId);
|
||||||
requestOutfitDTO.setStylist(outfitRequest.getStylist());
|
requestOutfitDTO.setStylist(outfitRequest.getStylist());
|
||||||
requestOutfitDTO.setGender(outfitRequest.getGender());
|
requestOutfitDTO.setGender(outfitRequest.getGender());
|
||||||
requestOutfitDTO.setNum(1);
|
requestOutfitDTO.setNum(1);
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ public class TryOnEffectServiceImpl extends ServiceImpl<TryOnEffectMapper, TryOn
|
|||||||
"\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, All items must be worn on the person; they must not be displayed anywhere else except on the model.** **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) {
|
||||||
@@ -213,6 +213,7 @@ public class TryOnEffectServiceImpl extends ServiceImpl<TryOnEffectMapper, TryOn
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//已废弃
|
||||||
@Override
|
@Override
|
||||||
public String reFace(Long customerPhotoId) {
|
public String reFace(Long customerPhotoId) {
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ public class OutfitResultVO {
|
|||||||
)
|
)
|
||||||
private String status;
|
private String status;
|
||||||
|
|
||||||
|
private Long createTimeStamp;
|
||||||
|
|
||||||
public OutfitResultVO(Long id, String requestId, String status) {
|
public OutfitResultVO(Long id, String requestId, String status) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.requestId = requestId;
|
this.requestId = requestId;
|
||||||
|
|||||||
Reference in New Issue
Block a user