TASK:模块化;
This commit is contained in:
@@ -115,11 +115,4 @@ public class DesignController {
|
||||
public Response<CloudTaskResultVO> getDesignCloudResult(@Valid @RequestBody DesignCloudResultQuery designCloudResultQuery) {
|
||||
return Response.success(designService.getDesignCloudResult(designCloudResultQuery));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取生成结果")
|
||||
@PostMapping("/toProductImageBatchResult")
|
||||
public Response<List<MagicToolResultVO>> getToProductImageResult(@Valid @RequestBody List<String> taskIdList) {
|
||||
List<MagicToolResultVO> magicToolResultVOList = userLikeGroupService.getToProductImageResultList(taskIdList);
|
||||
return Response.success(magicToolResultVOList);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,4 +9,5 @@ import java.util.List;
|
||||
public class CloudTaskResultVO {
|
||||
private PageBaseResponse<DesignCollectionItemVO> design;
|
||||
private List<MagicToolResultVO> toProductImage;
|
||||
private List<MagicToolResultVO> relight;
|
||||
}
|
||||
|
||||
@@ -111,4 +111,6 @@ public interface UserLikeGroupService extends IService<UserLikeGroup> {
|
||||
Boolean brandDNADelete(BrandDNADTO brandDNADTO);
|
||||
|
||||
void toProductBatch(String taskId, String url, String progress);
|
||||
|
||||
void relightBatch(String taskId, String url, String progress);
|
||||
}
|
||||
|
||||
@@ -2483,6 +2483,11 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
return convert;
|
||||
}
|
||||
|
||||
@Value("${redis.key.toProductImageResultKey}")
|
||||
private String toProductImageResultKey;
|
||||
@Value("${redis.key.relightResultKey}")
|
||||
private String relightResultKey;
|
||||
|
||||
@Override
|
||||
public CloudTaskResultVO getDesignCloudResult(DesignCloudResultQuery query) {
|
||||
CloudTaskResultVO result = new CloudTaskResultVO();
|
||||
@@ -2519,21 +2524,66 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
toProductImageResultQueryWrapper.lambda().eq(ToProductImageResult::getTaskIdBatch, query.getTaskId());
|
||||
List<ToProductImageResult> toProductImageResultList = toProductImageResultMapper.selectList(toProductImageResultQueryWrapper);
|
||||
for (ToProductImageResult toProductImageResult : toProductImageResultList) {
|
||||
MagicToolResultVO magicToolResultVO = new MagicToolResultVO();
|
||||
magicToolResultVO.setUrl(minioUtil.getPreSignedUrl(toProductImageResult.getUrl(), CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
||||
magicToolResultVO.setResultType(toProductImageResult.getResultType());
|
||||
magicToolResultVO.setElementId(toProductImageResult.getElementId());
|
||||
magicToolResultVO.setElementType(toProductImageResult.getElementType());
|
||||
if (toProductImageResult.getElementType().equals("ProductElement")) {
|
||||
ToProductElement toProductElement = toProductElementMapper.selectById(toProductImageResult.getElementId());
|
||||
magicToolResultVO.setSourceUrl(minioUtil.getPreSignedUrl(toProductElement.getUrl(), 24 * 60));
|
||||
}else {
|
||||
TDesignPythonOutfit tDesignPythonOutfit = designPythonOutfitMapper.selectById(toProductImageResult.getElementId());
|
||||
magicToolResultVO.setSourceUrl(minioUtil.getPreSignedUrl(tDesignPythonOutfit.getDesignUrl(), 24 * 60));
|
||||
String key = toProductImageResultKey + ":" + toProductImageResult.getTaskId();
|
||||
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));
|
||||
magicToolResultVO.setResultType(toProductImageResult.getResultType());
|
||||
magicToolResultVO.setElementId(toProductImageResult.getElementId());
|
||||
magicToolResultVO.setElementType(toProductImageResult.getElementType());
|
||||
if (toProductImageResult.getElementType().equals("ProductElement")) {
|
||||
ToProductElement toProductElement = toProductElementMapper.selectById(toProductImageResult.getElementId());
|
||||
magicToolResultVO.setSourceUrl(minioUtil.getPreSignedUrl(toProductElement.getUrl(), 24 * 60));
|
||||
}else {
|
||||
TDesignPythonOutfit tDesignPythonOutfit = designPythonOutfitMapper.selectById(toProductImageResult.getElementId());
|
||||
magicToolResultVO.setSourceUrl(minioUtil.getPreSignedUrl(tDesignPythonOutfit.getDesignUrl(), 24 * 60));
|
||||
}
|
||||
}
|
||||
} else if (Objects.isNull(magicToolResultVO)) {
|
||||
magicToolResultVO = new MagicToolResultVO();
|
||||
}
|
||||
// if (!StringUtil.isNullOrEmpty(magicToolResultVO.getStatus())) collect.add(magicToolResultVO.getStatus());
|
||||
results.add(magicToolResultVO);
|
||||
}
|
||||
result.setToProductImage(results);
|
||||
return result;
|
||||
} else if (query.getBuildType().equals(BuildType.RELIGHT.getValue())) {
|
||||
List<MagicToolResultVO> results = new ArrayList<>();
|
||||
QueryWrapper<ToProductImageResult> toProductImageResultQueryWrapper = new QueryWrapper<>();
|
||||
toProductImageResultQueryWrapper.lambda().eq(ToProductImageResult::getTaskIdBatch, query.getTaskId());
|
||||
List<ToProductImageResult> toProductImageResultList = toProductImageResultMapper.selectList(toProductImageResultQueryWrapper);
|
||||
for (ToProductImageResult toProductImageResult : toProductImageResultList) {
|
||||
String key = relightResultKey + ":" + toProductImageResult.getTaskId();
|
||||
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));
|
||||
magicToolResultVO.setResultType(toProductImageResult.getResultType());
|
||||
magicToolResultVO.setElementId(toProductImageResult.getElementId());
|
||||
magicToolResultVO.setElementType(toProductImageResult.getElementType());
|
||||
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);
|
||||
}
|
||||
result.setRelight(results);
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -2230,7 +2230,73 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
||||
}
|
||||
cloudTaskMapper.updateById(cloudTask);
|
||||
}
|
||||
|
||||
String key = toProductImageResultKey + ":" + 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, null);
|
||||
redisUtil.addToString(key, new Gson().toJson(generateResultVO), CommonConstant.GENERATE_RESULT_EXPIRE_TIME);
|
||||
|
||||
Long accountId = Long.parseLong(taskId.substring(taskId.lastIndexOf("-") + 1));
|
||||
if (!status.equals("Invalid")) {
|
||||
// 4、扣除积分
|
||||
Boolean b = creditsService.taskCreditsDeduction(accountId, taskId);
|
||||
// 3、记录积分变更
|
||||
if (b) creditsService.insertToCreditsDetail(accountId,
|
||||
CreditsEventsEnum.TO_PRODUCT_IMAGE.getName(),
|
||||
CreditsEventsEnum.TO_PRODUCT_IMAGE.getValue(),
|
||||
"negative", null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void relightBatch(String taskId, String url, String progress) {
|
||||
QueryWrapper<ToProductImageResult> qw = new QueryWrapper<>();
|
||||
qw.lambda().eq(ToProductImageResult::getTaskId, taskId);
|
||||
ToProductImageResult toProductImageResult = toProductImageResultMapper.selectOne(qw);
|
||||
if (Objects.nonNull(toProductImageResult)) {
|
||||
if (toProductImageResult.getBrightenValue() != null && toProductImageResult.getBrightenValue() != 1.0) {
|
||||
pythonService.bright(url, toProductImageResult.getBrightenValue());
|
||||
}
|
||||
toProductImageResult.setUrl(url);
|
||||
toProductImageResult.setResultType("Relight");
|
||||
toProductImageResultMapper.updateById(toProductImageResult);
|
||||
|
||||
String taskIdBatch = toProductImageResult.getTaskIdBatch();
|
||||
QueryWrapper<CloudTask> cloudTaskQueryWrapper = new QueryWrapper<>();
|
||||
cloudTaskQueryWrapper.lambda().eq(CloudTask::getTaskId, taskIdBatch);
|
||||
CloudTask cloudTask = cloudTaskMapper.selectOne(cloudTaskQueryWrapper);
|
||||
if (Objects.nonNull(cloudTask)) {
|
||||
if (cloudTask.getCompletedNum() == null) {
|
||||
cloudTask.setCompletedNum(1);
|
||||
}else {
|
||||
cloudTask.setCompletedNum(cloudTask.getCompletedNum() + 1);
|
||||
}
|
||||
if (progress.equals("OK")) {
|
||||
cloudTask.setStatus(1);
|
||||
cloudTask.setCompletedNum(cloudTask.getNums());
|
||||
}
|
||||
cloudTaskMapper.updateById(cloudTask);
|
||||
}
|
||||
|
||||
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, null);
|
||||
redisUtil.addToString(key, new Gson().toJson(generateResultVO), CommonConstant.GENERATE_RESULT_EXPIRE_TIME);
|
||||
|
||||
Long accountId = Long.parseLong(taskId.substring(taskId.lastIndexOf("-") + 1));
|
||||
if (!status.equals("Invalid")) {
|
||||
// 4、扣除积分
|
||||
Boolean b = creditsService.taskCreditsDeduction(accountId, taskId);
|
||||
// 3、记录积分变更
|
||||
if (b) creditsService.insertToCreditsDetail(accountId,
|
||||
CreditsEventsEnum.RELIGHT.getName(),
|
||||
CreditsEventsEnum.RELIGHT.getValue(),
|
||||
"negative", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user