Merge branch 'dev/dev' into dev/dev_xp
# Conflicts: # src/main/java/com/ai/da/service/GenerateService.java
This commit is contained in:
@@ -36,4 +36,6 @@ public interface GenerateService extends IService<Generate> {
|
||||
Long getRankPosition(String uniqueId);
|
||||
|
||||
void cancelGenerate(Long userId, List<String> uniqueId, String timeZone, String type);
|
||||
|
||||
void processRelightResult(String taskId, String url, String category);
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public interface UserLikeGroupService extends IService<UserLikeGroup> {
|
||||
|
||||
Boolean productImageLike(ProductImageLikeDTO productImageLikeDTO);
|
||||
|
||||
List<GenerateResultVO> getToProductImageResultList(List<String> taskIdList);
|
||||
List<MagicToolResultVO> getToProductImageResultList(List<String> taskIdList);
|
||||
|
||||
JSONObject exportSearch(Long userLikeGroupId);
|
||||
|
||||
@@ -56,4 +56,8 @@ public interface UserLikeGroupService extends IService<UserLikeGroup> {
|
||||
List<ToProductImageResult> productImageLikeList(ToProductImageDTO toProductImageDTO);
|
||||
|
||||
Boolean productImageUnLike(ProductImageLikeDTO productImageLikeDTO);
|
||||
|
||||
List<ToProductImageResult> relight(ToProductImageDTO toProductImageDTO);
|
||||
|
||||
List<MagicToolResultVO> getRelightResult(List<String> taskIdList);
|
||||
}
|
||||
|
||||
@@ -77,6 +77,9 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
||||
@Value("${minio.bucketName.slogan}")
|
||||
private String sloganBucket;
|
||||
|
||||
@Value("${redis.key.relightResultKey}")
|
||||
private String relightResultKey;
|
||||
|
||||
@Value("${redis.key.toProductImageResultKey}")
|
||||
private String toProductImageResultKey;
|
||||
|
||||
@@ -255,6 +258,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
||||
}
|
||||
ToProductImageResult toProductImageResult = toProductImageResults.get(0);
|
||||
toProductImageResult.setUrl(url);
|
||||
toProductImageResult.setResultType("ToProductImage");
|
||||
toProductImageResultMapper.updateById(toProductImageResult);
|
||||
|
||||
String key = toProductImageResultKey + ":" + taskId;
|
||||
@@ -705,6 +709,27 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processRelightResult(String taskId, String url, String category) {
|
||||
QueryWrapper<ToProductImageResult> qw = new QueryWrapper<>();
|
||||
qw.lambda().eq(ToProductImageResult::getTaskId, taskId);
|
||||
List<ToProductImageResult> toProductImageResults = toProductImageResultMapper.selectList(qw);
|
||||
if (CollectionUtils.isEmpty(toProductImageResults)) {
|
||||
return;
|
||||
// throw new BusinessException("");
|
||||
}
|
||||
ToProductImageResult toProductImageResult = toProductImageResults.get(0);
|
||||
toProductImageResult.setUrl(url);
|
||||
toProductImageResult.setResultType("Relight");
|
||||
toProductImageResultMapper.updateById(toProductImageResult);
|
||||
|
||||
String key = relightResultKey + ":" + taskId;
|
||||
String imageName = url.substring(url.lastIndexOf("/") + 1);
|
||||
String status = imageName.equals("white_image.jpg") ? "Invalid" : "Success";
|
||||
GenerateResultVO generateResultVO = new GenerateResultVO(taskId, toProductImageResult.getId(), url, status, category);
|
||||
redisUtil.addToString(key, new Gson().toJson(generateResultVO), CommonConstant.GENERATE_RESULT_EXPIRE_TIME);
|
||||
}
|
||||
|
||||
// 判断试用用户试用generate机会是否使用完毕 每个board 3次机会
|
||||
private int getTrialsCount(Long userId, String level1Type) {
|
||||
List<Generate> getGenerateList = getGenerateByAccountId(userId, level1Type);
|
||||
|
||||
@@ -321,25 +321,40 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
||||
private RedisUtil redisUtil;
|
||||
@Value("${redis.key.toProductImageResultKey}")
|
||||
private String toProductImageResultKey;
|
||||
@Value("${redis.key.relightResultKey}")
|
||||
private String relightResultKey;
|
||||
@Override
|
||||
public List<GenerateResultVO> getToProductImageResultList(List<String> taskIdList) {
|
||||
List<GenerateResultVO> results = new ArrayList<>();
|
||||
public List<MagicToolResultVO> getToProductImageResultList(List<String> taskIdList) {
|
||||
List<MagicToolResultVO> results = new ArrayList<>();
|
||||
Set<String> collect = new HashSet<>();
|
||||
taskIdList.forEach(taskId -> {
|
||||
String key = toProductImageResultKey + ":" + taskId;
|
||||
GenerateResultVO generateResultVO = new Gson().fromJson(redisUtil.getFromString(key), GenerateResultVO.class);
|
||||
if (!Objects.isNull(generateResultVO) && !StringUtil.isNullOrEmpty(generateResultVO.getUrl())) {
|
||||
String url = generateResultVO.getUrl();
|
||||
MagicToolResultVO magicToolResultVO = new Gson().fromJson(redisUtil.getFromString(key), MagicToolResultVO.class);
|
||||
if (!Objects.isNull(magicToolResultVO) && !StringUtil.isNullOrEmpty(magicToolResultVO.getUrl())) {
|
||||
String url = magicToolResultVO.getUrl();
|
||||
if (url.substring(url.lastIndexOf("/") + 1).equals("white_image.jpg")) {
|
||||
generateResultVO.setStatus("Invalid");
|
||||
magicToolResultVO.setStatus("Invalid");
|
||||
} else {
|
||||
generateResultVO.setUrl(minioUtil.getPresignedUrl(url, CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
||||
magicToolResultVO.setUrl(minioUtil.getPresignedUrl(url, CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
||||
QueryWrapper<ToProductImageResult> qw = new QueryWrapper<>();
|
||||
qw.lambda().eq(ToProductImageResult::getTaskId, taskId);
|
||||
ToProductImageResult toProductImageResult = toProductImageResultMapper.selectOne(qw);
|
||||
if (Objects.isNull(toProductImageResult)) {
|
||||
throw new BusinessException("The source image does not exist.");
|
||||
}
|
||||
if (toProductImageResult.getElementType().equals("ProductElement")) {
|
||||
ToProductElement toProductElement = toProductElementMapper.selectById(toProductImageResult.getElementId());
|
||||
magicToolResultVO.setSourceUrl(minioUtil.getPresignedUrl(toProductElement.getUrl(), 24 * 60));
|
||||
}else {
|
||||
UserLike userLike = userLikeMapper.selectById(toProductImageResult.getElementId());
|
||||
magicToolResultVO.setSourceUrl(minioUtil.getPresignedUrl(userLike.getUrl(), 24 * 60));
|
||||
}
|
||||
}
|
||||
} else if (Objects.isNull(generateResultVO)) {
|
||||
generateResultVO = new GenerateResultVO();
|
||||
} else if (Objects.isNull(magicToolResultVO)) {
|
||||
magicToolResultVO = new MagicToolResultVO();
|
||||
}
|
||||
if (!StringUtil.isNullOrEmpty(generateResultVO.getStatus())) collect.add(generateResultVO.getStatus());
|
||||
results.add(generateResultVO);
|
||||
if (!StringUtil.isNullOrEmpty(magicToolResultVO.getStatus())) collect.add(magicToolResultVO.getStatus());
|
||||
results.add(magicToolResultVO);
|
||||
});
|
||||
return results;
|
||||
}
|
||||
@@ -408,6 +423,102 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public List<ToProductImageResult> relight(ToProductImageDTO toProductImageDTO) {
|
||||
AuthPrincipalVo userHolder = UserContext.getUserHolder();
|
||||
Long userLikeGroupId = toProductImageDTO.getUserLikeGroupId();
|
||||
ToProductImageRecord toProductImageRecord = new ToProductImageRecord();
|
||||
toProductImageRecord.setUserLikeGroupId(userLikeGroupId);
|
||||
toProductImageRecord.setCreateTime(LocalDateTime.now());
|
||||
if (!StringUtils.isEmpty(toProductImageDTO.getPrompt())) {
|
||||
toProductImageRecord.setPrompt(toProductImageDTO.getPrompt());
|
||||
}
|
||||
toProductImageRecordMapper.insert(toProductImageRecord);
|
||||
|
||||
List<ToProductImageResult> result = new ArrayList<>();
|
||||
|
||||
int i = 0;
|
||||
// 翻译
|
||||
String prompt = toProductImageDTO.getPrompt();
|
||||
String s = pythonService.promptTranslate(prompt);
|
||||
for (ToProductImageVO toProductImageVO : toProductImageDTO.getToProductImageVOList()) {
|
||||
if (toProductImageVO.getElementType().equals("ProductImage")) {
|
||||
String taskId = UUID.randomUUID() + "-" + i + "-" + userHolder.getId();
|
||||
i ++;
|
||||
ToProductImageResult toProductImageResult1 = toProductImageResultMapper.selectById(toProductImageVO.getElementId());
|
||||
// 走模型
|
||||
pythonService.toProductImage(toProductImageResult1.getUrl(), taskId, s);
|
||||
ToProductImageResult toProductImageResult = new ToProductImageResult();
|
||||
toProductImageResult.setElementId(toProductImageResult1.getId());
|
||||
toProductImageResult.setElementType("ProductImage");
|
||||
toProductImageResult.setCreateTime(LocalDateTime.now());
|
||||
toProductImageResult.setToProductImageRecordId(toProductImageRecord.getId());
|
||||
// toProductImageResult.setUrl(productImageUrl);
|
||||
toProductImageResult.setIsLike(0);
|
||||
toProductImageResult.setTaskId(taskId);
|
||||
toProductImageResult.setUserLikeGroupId(userLikeGroupId);
|
||||
toProductImageResultMapper.insert(toProductImageResult);
|
||||
// toProductImageResult.setUrl(minioUtil.getPresignedUrl(toProductImageResult.getUrl(), 24 * 60));
|
||||
result.add(toProductImageResult);
|
||||
}else {
|
||||
String taskId = UUID.randomUUID() + "-" + i + "-" + userHolder.getId();
|
||||
ToProductElement toProductElement = toProductElementMapper.selectById(toProductImageVO.getElementId());
|
||||
// 走模型
|
||||
pythonService.toProductImage(toProductElement.getUrl(), taskId, s);
|
||||
ToProductImageResult toProductImageResult = new ToProductImageResult();
|
||||
toProductImageResult.setElementId(toProductElement.getId());
|
||||
toProductImageResult.setElementType("ProductElement");
|
||||
toProductImageResult.setCreateTime(LocalDateTime.now());
|
||||
toProductImageResult.setToProductImageRecordId(toProductImageRecord.getId());
|
||||
// toProductImageResult.setUrl(productImageUrl);
|
||||
toProductImageResult.setIsLike(0);
|
||||
toProductImageResult.setTaskId(taskId);
|
||||
toProductImageResultMapper.insert(toProductImageResult);
|
||||
// toProductImageResult.setUrl(minioUtil.getPresignedUrl(toProductImageResult.getUrl(), 24 * 60));
|
||||
result.add(toProductImageResult);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MagicToolResultVO> getRelightResult(List<String> taskIdList) {
|
||||
List<MagicToolResultVO> results = new ArrayList<>();
|
||||
Set<String> collect = new HashSet<>();
|
||||
taskIdList.forEach(taskId -> {
|
||||
String key = toProductImageResultKey + ":" + taskId;
|
||||
MagicToolResultVO magicToolResultVO = new Gson().fromJson(redisUtil.getFromString(key), MagicToolResultVO.class);
|
||||
if (!Objects.isNull(magicToolResultVO) && !StringUtil.isNullOrEmpty(magicToolResultVO.getUrl())) {
|
||||
String url = magicToolResultVO.getUrl();
|
||||
if (url.substring(url.lastIndexOf("/") + 1).equals("white_image.jpg")) {
|
||||
magicToolResultVO.setStatus("Invalid");
|
||||
} else {
|
||||
magicToolResultVO.setUrl(minioUtil.getPresignedUrl(url, CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
||||
QueryWrapper<ToProductImageResult> qw = new QueryWrapper<>();
|
||||
qw.lambda().eq(ToProductImageResult::getTaskId, taskId);
|
||||
ToProductImageResult toProductImageResult = toProductImageResultMapper.selectOne(qw);
|
||||
if (Objects.isNull(toProductImageResult)) {
|
||||
throw new BusinessException("The source image does not exist.");
|
||||
}
|
||||
if (toProductImageResult.getElementType().equals("ProductElement")) {
|
||||
ToProductElement toProductElement = toProductElementMapper.selectById(toProductImageResult.getElementId());
|
||||
magicToolResultVO.setSourceUrl(minioUtil.getPresignedUrl(toProductElement.getUrl(), 24 * 60));
|
||||
}else {
|
||||
ToProductImageResult toProductImageResult1 = toProductImageResultMapper.selectById(toProductImageResult.getElementId());
|
||||
magicToolResultVO.setSourceUrl(minioUtil.getPresignedUrl(toProductImageResult1.getUrl(), 24 * 60));
|
||||
}
|
||||
}
|
||||
} else if (Objects.isNull(magicToolResultVO)) {
|
||||
magicToolResultVO = new MagicToolResultVO();
|
||||
}
|
||||
if (!StringUtil.isNullOrEmpty(magicToolResultVO.getStatus())) collect.add(magicToolResultVO.getStatus());
|
||||
results.add(magicToolResultVO);
|
||||
});
|
||||
return results;
|
||||
}
|
||||
|
||||
public static String convert(InputStream inputStream) {
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
|
||||
return reader.lines().collect(Collectors.joining("\n"));
|
||||
|
||||
@@ -141,6 +141,14 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
|
||||
workspaceRelStyleMapper.updateById(workspaceRelStyle);
|
||||
}
|
||||
}
|
||||
}else {
|
||||
QueryWrapper<WorkspaceRelStyle> qw = new QueryWrapper<>();
|
||||
qw.lambda().eq(WorkspaceRelStyle::getWorkspaceId, workspace.getId());
|
||||
List<WorkspaceRelStyle> workspaceRelStyles = workspaceRelStyleMapper.selectList(qw);
|
||||
if (!CollectionUtils.isEmpty(workspaceRelStyles)) {
|
||||
WorkspaceRelStyle workspaceRelStyle = workspaceRelStyles.get(0);
|
||||
workspaceRelStyleMapper.deleteById(workspaceRelStyle);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -308,6 +316,7 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
|
||||
List<WorkspaceRelStyle> workspaceRelStyles = workspaceRelStyleMapper.selectList(qw);
|
||||
if (!CollectionUtils.isEmpty(workspaceRelStyles)) {
|
||||
Long styleId = workspaceRelStyles.get(0).getStyleId();
|
||||
vo.setStyleId(styleId);
|
||||
Style style = styleMapper.selectById(styleId);
|
||||
StyleEnum styleEnum = StyleEnum.fromName(style.getName());
|
||||
vo.setStyle(styleEnum.name());
|
||||
|
||||
Reference in New Issue
Block a user