Merge branch 'dev/dev' into dev/dev_xp
# Conflicts: # src/main/java/com/ai/da/service/GenerateService.java
This commit is contained in:
@@ -46,6 +46,8 @@ public class GenerateConsumer {
|
|||||||
private String generateResultKey;
|
private String generateResultKey;
|
||||||
@Value("${redis.key.toProductImageResultKey}")
|
@Value("${redis.key.toProductImageResultKey}")
|
||||||
private String toProductImageResultKey;
|
private String toProductImageResultKey;
|
||||||
|
@Value("${redis.key.relightResultKey}")
|
||||||
|
private String relightResultKey;
|
||||||
|
|
||||||
public void generate(Message msg, Channel channel, String consumerName) {
|
public void generate(Message msg, Channel channel, String consumerName) {
|
||||||
log.info("============start listening==========");
|
log.info("============start listening==========");
|
||||||
@@ -204,73 +206,125 @@ public class GenerateConsumer {
|
|||||||
|
|
||||||
long end = System.currentTimeMillis();
|
long end = System.currentTimeMillis();
|
||||||
log.info("tasks_id : {}, end , message : {}, 执行时长: {} 毫秒", generateResult.get("tasks_id"), generateResult.get("message"), (end - start));
|
log.info("tasks_id : {}, end , message : {}, 执行时长: {} 毫秒", generateResult.get("tasks_id"), generateResult.get("message"), (end - start));
|
||||||
log.info("============ProcessGenerateResult End listening==========");
|
log.info("============ProcessToProductImageResult End listening==========");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@RabbitListener(queues = MQConfig.GENERATE_QUEUE)
|
private void processRelightResult(Message msg, Channel channel) {
|
||||||
@RabbitHandler
|
log.info("============processRelightResult listening==========");
|
||||||
public void generateConsumer1(Message msg, Channel channel) {
|
long start = System.currentTimeMillis();
|
||||||
generate(msg, channel, "consumer 1");
|
|
||||||
|
Map<String, String> generateResult = JSONObject.parseObject(msg.getBody(), Map.class);
|
||||||
|
log.info("toProductImage response : {}", generateResult);
|
||||||
|
|
||||||
|
try {
|
||||||
|
log.info("tasks_id : {} start ", generateResult.get("tasks_id"));
|
||||||
|
if (generateResult.get("status").equals("SUCCESS")) {
|
||||||
|
String url = generateResult.get("image_url");
|
||||||
|
String taskId = generateResult.get("tasks_id");
|
||||||
|
String category = generateResult.get("category");
|
||||||
|
generateService.processRelightResult(taskId, url, category);
|
||||||
|
} else {
|
||||||
|
// 修改redis中的数据状态为exception
|
||||||
|
String key = relightResultKey + ":" + generateResult.get("tasks_id");
|
||||||
|
redisUtil.addToString(key, new Gson().toJson(new GenerateResultVO(generateResult.get("tasks_id"), null, null, "Fail")), CommonConstant.GENERATE_RESULT_EXPIRE_TIME);
|
||||||
|
// 将异常信息存到exception中
|
||||||
|
HashMap<String, String> exceptionInfo = new HashMap<>();
|
||||||
|
exceptionInfo.put(generateResult.get("tasks_id"), generateResult.get("data"));
|
||||||
|
// 存redis
|
||||||
|
redisUtil.addToMap(exceptionMapKey, exceptionInfo);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage());
|
||||||
|
try {
|
||||||
|
channel.basicAck(msg.getMessageProperties().getDeliveryTag(), false);
|
||||||
|
// 将消息从redis排队队列中删除,需保证被消费的消息存储到db之后再从redis删除
|
||||||
|
redisUtil.removeFromZSet(consumptionOrderKey, generateResult.get("tasks_id"));
|
||||||
|
} catch (IOException exception) {
|
||||||
|
log.error("手动确认,取消返回队列,不再重新消费");
|
||||||
|
}
|
||||||
|
// 将入参和错误信息存入数据库
|
||||||
|
String exceptionMessage = JSONObject.toJSONString(generateResult) +
|
||||||
|
" Exception message : " + e.getMessage();
|
||||||
|
HashMap<String, String> exceptionInfo = new HashMap<>();
|
||||||
|
exceptionInfo.put(String.valueOf(generateResult.get("tasks_id")), exceptionMessage);
|
||||||
|
// 存redis
|
||||||
|
redisUtil.addToMap(exceptionMapKey, exceptionInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
long end = System.currentTimeMillis();
|
||||||
|
log.info("tasks_id : {}, end , message : {}, 执行时长: {} 毫秒", generateResult.get("tasks_id"), generateResult.get("message"), (end - start));
|
||||||
|
log.info("============ProcessRelightResult End listening==========");
|
||||||
}
|
}
|
||||||
|
|
||||||
@RabbitListener(queues = MQConfig.GENERATE_QUEUE)
|
// @RabbitListener(queues = MQConfig.GENERATE_QUEUE)
|
||||||
@RabbitHandler
|
// @RabbitHandler
|
||||||
public void generateConsumer2(Message msg, Channel channel) {
|
// public void generateConsumer1(Message msg, Channel channel) {
|
||||||
generate(msg, channel, "consumer 2");
|
// generate(msg, channel, "consumer 1");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
// @RabbitListener(queues = MQConfig.GENERATE_QUEUE)
|
||||||
|
// @RabbitHandler
|
||||||
|
// public void generateConsumer2(Message msg, Channel channel) {
|
||||||
|
// generate(msg, channel, "consumer 2");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @RabbitListener(queues = MQConfig.GENERATE_QUEUE)
|
||||||
|
// @RabbitHandler
|
||||||
|
// public void generateConsumer3(Message msg, Channel channel) {
|
||||||
|
// generate(msg, channel, "consumer 3");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @RabbitListener(queues = MQConfig.GENERATE_QUEUE)
|
||||||
|
// @RabbitHandler
|
||||||
|
// public void generateConsumer4(Message msg, Channel channel) {
|
||||||
|
// generate(msg, channel, "consumer 4");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @RabbitListener(queues = MQConfig.GENERATE_QUEUE)
|
||||||
|
// @RabbitHandler
|
||||||
|
// public void generateConsumer5(Message msg, Channel channel) {
|
||||||
|
// generate(msg, channel, "consumer 5");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @RabbitListener(queues = MQConfig.GENERATE_QUEUE)
|
||||||
|
// @RabbitHandler
|
||||||
|
// public void generateConsumer6(Message msg, Channel channel) {
|
||||||
|
// generate(msg, channel, "consumer 6");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @RabbitListener(queues = MQConfig.GENERATE_QUEUE)
|
||||||
|
// @RabbitHandler
|
||||||
|
// public void generateConsumer7(Message msg, Channel channel) {
|
||||||
|
// generate(msg, channel, "consumer 7");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @RabbitListener(queues = MQConfig.GENERATE_QUEUE)
|
||||||
|
// @RabbitHandler
|
||||||
|
// public void generateConsumer8(Message msg, Channel channel) {
|
||||||
|
// generate(msg, channel, "consumer 8");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @RabbitListener(queues = MQConfig.GENERATE_QUEUE)
|
||||||
|
// @RabbitHandler
|
||||||
|
// public void generateConsumer9(Message msg, Channel channel) {
|
||||||
|
// generate(msg, channel, "consumer 9");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @RabbitListener(queues = MQConfig.GENERATE_RESULT_QUEUE)
|
||||||
|
// @RabbitHandler
|
||||||
|
// public void getGenerateResult(Message msg, Channel channel) {
|
||||||
|
// processGenerateResult(msg, channel);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @RabbitListener(queues = MQConfig.TO_PRODUCT_IMAGE_RESULT_QUEUE)
|
||||||
|
// @RabbitHandler
|
||||||
|
// public void getToProductImageResult(Message msg, Channel channel) {
|
||||||
|
// processToProductImageResult(msg, channel);
|
||||||
|
// }
|
||||||
|
|
||||||
@RabbitListener(queues = MQConfig.GENERATE_QUEUE)
|
@RabbitListener(queues = MQConfig.RELIGHT_RESULT_QUEUE)
|
||||||
@RabbitHandler
|
@RabbitHandler
|
||||||
public void generateConsumer3(Message msg, Channel channel) {
|
public void getRelightResult(Message msg, Channel channel) {
|
||||||
generate(msg, channel, "consumer 3");
|
processRelightResult(msg, channel);
|
||||||
}
|
|
||||||
|
|
||||||
@RabbitListener(queues = MQConfig.GENERATE_QUEUE)
|
|
||||||
@RabbitHandler
|
|
||||||
public void generateConsumer4(Message msg, Channel channel) {
|
|
||||||
generate(msg, channel, "consumer 4");
|
|
||||||
}
|
|
||||||
|
|
||||||
@RabbitListener(queues = MQConfig.GENERATE_QUEUE)
|
|
||||||
@RabbitHandler
|
|
||||||
public void generateConsumer5(Message msg, Channel channel) {
|
|
||||||
generate(msg, channel, "consumer 5");
|
|
||||||
}
|
|
||||||
|
|
||||||
@RabbitListener(queues = MQConfig.GENERATE_QUEUE)
|
|
||||||
@RabbitHandler
|
|
||||||
public void generateConsumer6(Message msg, Channel channel) {
|
|
||||||
generate(msg, channel, "consumer 6");
|
|
||||||
}
|
|
||||||
|
|
||||||
@RabbitListener(queues = MQConfig.GENERATE_QUEUE)
|
|
||||||
@RabbitHandler
|
|
||||||
public void generateConsumer7(Message msg, Channel channel) {
|
|
||||||
generate(msg, channel, "consumer 7");
|
|
||||||
}
|
|
||||||
|
|
||||||
@RabbitListener(queues = MQConfig.GENERATE_QUEUE)
|
|
||||||
@RabbitHandler
|
|
||||||
public void generateConsumer8(Message msg, Channel channel) {
|
|
||||||
generate(msg, channel, "consumer 8");
|
|
||||||
}
|
|
||||||
|
|
||||||
@RabbitListener(queues = MQConfig.GENERATE_QUEUE)
|
|
||||||
@RabbitHandler
|
|
||||||
public void generateConsumer9(Message msg, Channel channel) {
|
|
||||||
generate(msg, channel, "consumer 9");
|
|
||||||
}
|
|
||||||
|
|
||||||
@RabbitListener(queues = MQConfig.GENERATE_RESULT_QUEUE)
|
|
||||||
@RabbitHandler
|
|
||||||
public void getGenerateResult(Message msg, Channel channel) {
|
|
||||||
processGenerateResult(msg, channel);
|
|
||||||
}
|
|
||||||
|
|
||||||
@RabbitListener(queues = MQConfig.TO_PRODUCT_IMAGE_RESULT_QUEUE)
|
|
||||||
@RabbitHandler
|
|
||||||
public void getToProductImageResult(Message msg, Channel channel) {
|
|
||||||
processToProductImageResult(msg, channel);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ public class MQConfig {
|
|||||||
public static final String GENERATE_RESULT_QUEUE = "GenerateImage-dev";
|
public static final String GENERATE_RESULT_QUEUE = "GenerateImage-dev";
|
||||||
|
|
||||||
public static final String TO_PRODUCT_IMAGE_RESULT_QUEUE = "ToProductImage-local";
|
public static final String TO_PRODUCT_IMAGE_RESULT_QUEUE = "ToProductImage-local";
|
||||||
|
|
||||||
|
public static final String RELIGHT_RESULT_QUEUE = "Relight-local";
|
||||||
public MQConfig() {
|
public MQConfig() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -218,17 +218,17 @@ public class SRConsumer {
|
|||||||
taskListService.updateTaskStatusOrOutputRedis(uniqueId, "fail", null);
|
taskListService.updateTaskStatusOrOutputRedis(uniqueId, "fail", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RabbitListener(queues = MQConfig.SR_QUEUE)
|
// @RabbitListener(queues = MQConfig.SR_QUEUE)
|
||||||
@RabbitHandler
|
// @RabbitHandler
|
||||||
public void SRConsumer1(Message msg, Channel channel) {
|
// public void SRConsumer1(Message msg, Channel channel) {
|
||||||
superResolution(msg, channel, "consumer 1");
|
// superResolution(msg, channel, "consumer 1");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
@RabbitListener(queues = MQConfig.SR_RESULT_QUEUE)
|
// @RabbitListener(queues = MQConfig.SR_RESULT_QUEUE)
|
||||||
@RabbitHandler
|
// @RabbitHandler
|
||||||
public void SRResultConsumer1(Message msg, Channel channel) {
|
// public void SRResultConsumer1(Message msg, Channel channel) {
|
||||||
getSRResult(msg, channel, "consumer 1");
|
// getSRResult(msg, channel, "consumer 1");
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -196,9 +196,9 @@ public class SavedCollectionController {
|
|||||||
|
|
||||||
@ApiOperation(value = "获取生成结果")
|
@ApiOperation(value = "获取生成结果")
|
||||||
@PostMapping("/toProductImageResult")
|
@PostMapping("/toProductImageResult")
|
||||||
public Response<List<GenerateResultVO>> getToProductImageResult(@Valid @RequestBody List<String> taskIdList) {
|
public Response<List<MagicToolResultVO>> getToProductImageResult(@Valid @RequestBody List<String> taskIdList) {
|
||||||
List<GenerateResultVO> generateResult = userLikeGroupService.getToProductImageResultList(taskIdList);
|
List<MagicToolResultVO> magicToolResultVOList = userLikeGroupService.getToProductImageResultList(taskIdList);
|
||||||
return Response.success(generateResult);
|
return Response.success(magicToolResultVOList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "画布用户上传元素")
|
@ApiOperation(value = "画布用户上传元素")
|
||||||
@@ -212,4 +212,17 @@ public class SavedCollectionController {
|
|||||||
public Response<List<ToProductImageResult>> productImageLikeList(@Valid @RequestBody ToProductImageDTO toProductImageDTO) {
|
public Response<List<ToProductImageResult>> productImageLikeList(@Valid @RequestBody ToProductImageDTO toProductImageDTO) {
|
||||||
return Response.success(userLikeGroupService.productImageLikeList(toProductImageDTO));
|
return Response.success(userLikeGroupService.productImageLikeList(toProductImageDTO));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "relight")
|
||||||
|
@PostMapping("/relight")
|
||||||
|
public Response<List<ToProductImageResult>> relight(@Valid @RequestBody ToProductImageDTO toProductImageDTO) {
|
||||||
|
return Response.success(userLikeGroupService.relight(toProductImageDTO));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "获取relight结果")
|
||||||
|
@PostMapping("/relightResult")
|
||||||
|
public Response<List<MagicToolResultVO>> getRelightResult(@Valid @RequestBody List<String> taskIdList) {
|
||||||
|
List<MagicToolResultVO> magicToolResultVOList = userLikeGroupService.getRelightResult(taskIdList);
|
||||||
|
return Response.success(magicToolResultVOList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,4 +39,7 @@ public class ToProductImageResult implements Serializable {
|
|||||||
|
|
||||||
@ApiModelProperty(value = "userLikeGroupId")
|
@ApiModelProperty(value = "userLikeGroupId")
|
||||||
private Long userLikeGroupId;
|
private Long userLikeGroupId;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "generate 结果类型")
|
||||||
|
private String resultType;
|
||||||
}
|
}
|
||||||
|
|||||||
25
src/main/java/com/ai/da/model/vo/MagicToolResultVO.java
Normal file
25
src/main/java/com/ai/da/model/vo/MagicToolResultVO.java
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package com.ai.da.model.vo;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@ApiModel("generate result 响应")
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class MagicToolResultVO {
|
||||||
|
|
||||||
|
private String taskId;
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
private String category;
|
||||||
|
|
||||||
|
private String sourceUrl;
|
||||||
|
}
|
||||||
@@ -24,7 +24,7 @@ public class WorkspaceVO extends Workspace {
|
|||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private Long currentId;
|
private Long styleId;
|
||||||
|
|
||||||
private PageBaseResponse<WorkspaceVO> page;
|
private PageBaseResponse<WorkspaceVO> page;
|
||||||
|
|
||||||
|
|||||||
@@ -36,4 +36,6 @@ public interface GenerateService extends IService<Generate> {
|
|||||||
Long getRankPosition(String uniqueId);
|
Long getRankPosition(String uniqueId);
|
||||||
|
|
||||||
void cancelGenerate(Long userId, List<String> uniqueId, String timeZone, String type);
|
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);
|
Boolean productImageLike(ProductImageLikeDTO productImageLikeDTO);
|
||||||
|
|
||||||
List<GenerateResultVO> getToProductImageResultList(List<String> taskIdList);
|
List<MagicToolResultVO> getToProductImageResultList(List<String> taskIdList);
|
||||||
|
|
||||||
JSONObject exportSearch(Long userLikeGroupId);
|
JSONObject exportSearch(Long userLikeGroupId);
|
||||||
|
|
||||||
@@ -56,4 +56,8 @@ public interface UserLikeGroupService extends IService<UserLikeGroup> {
|
|||||||
List<ToProductImageResult> productImageLikeList(ToProductImageDTO toProductImageDTO);
|
List<ToProductImageResult> productImageLikeList(ToProductImageDTO toProductImageDTO);
|
||||||
|
|
||||||
Boolean productImageUnLike(ProductImageLikeDTO productImageLikeDTO);
|
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}")
|
@Value("${minio.bucketName.slogan}")
|
||||||
private String sloganBucket;
|
private String sloganBucket;
|
||||||
|
|
||||||
|
@Value("${redis.key.relightResultKey}")
|
||||||
|
private String relightResultKey;
|
||||||
|
|
||||||
@Value("${redis.key.toProductImageResultKey}")
|
@Value("${redis.key.toProductImageResultKey}")
|
||||||
private String toProductImageResultKey;
|
private String toProductImageResultKey;
|
||||||
|
|
||||||
@@ -255,6 +258,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
|||||||
}
|
}
|
||||||
ToProductImageResult toProductImageResult = toProductImageResults.get(0);
|
ToProductImageResult toProductImageResult = toProductImageResults.get(0);
|
||||||
toProductImageResult.setUrl(url);
|
toProductImageResult.setUrl(url);
|
||||||
|
toProductImageResult.setResultType("ToProductImage");
|
||||||
toProductImageResultMapper.updateById(toProductImageResult);
|
toProductImageResultMapper.updateById(toProductImageResult);
|
||||||
|
|
||||||
String key = toProductImageResultKey + ":" + taskId;
|
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次机会
|
// 判断试用用户试用generate机会是否使用完毕 每个board 3次机会
|
||||||
private int getTrialsCount(Long userId, String level1Type) {
|
private int getTrialsCount(Long userId, String level1Type) {
|
||||||
List<Generate> getGenerateList = getGenerateByAccountId(userId, level1Type);
|
List<Generate> getGenerateList = getGenerateByAccountId(userId, level1Type);
|
||||||
|
|||||||
@@ -321,25 +321,40 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
|||||||
private RedisUtil redisUtil;
|
private RedisUtil redisUtil;
|
||||||
@Value("${redis.key.toProductImageResultKey}")
|
@Value("${redis.key.toProductImageResultKey}")
|
||||||
private String toProductImageResultKey;
|
private String toProductImageResultKey;
|
||||||
|
@Value("${redis.key.relightResultKey}")
|
||||||
|
private String relightResultKey;
|
||||||
@Override
|
@Override
|
||||||
public List<GenerateResultVO> getToProductImageResultList(List<String> taskIdList) {
|
public List<MagicToolResultVO> getToProductImageResultList(List<String> taskIdList) {
|
||||||
List<GenerateResultVO> results = new ArrayList<>();
|
List<MagicToolResultVO> results = new ArrayList<>();
|
||||||
Set<String> collect = new HashSet<>();
|
Set<String> collect = new HashSet<>();
|
||||||
taskIdList.forEach(taskId -> {
|
taskIdList.forEach(taskId -> {
|
||||||
String key = toProductImageResultKey + ":" + taskId;
|
String key = toProductImageResultKey + ":" + taskId;
|
||||||
GenerateResultVO generateResultVO = new Gson().fromJson(redisUtil.getFromString(key), GenerateResultVO.class);
|
MagicToolResultVO magicToolResultVO = new Gson().fromJson(redisUtil.getFromString(key), MagicToolResultVO.class);
|
||||||
if (!Objects.isNull(generateResultVO) && !StringUtil.isNullOrEmpty(generateResultVO.getUrl())) {
|
if (!Objects.isNull(magicToolResultVO) && !StringUtil.isNullOrEmpty(magicToolResultVO.getUrl())) {
|
||||||
String url = generateResultVO.getUrl();
|
String url = magicToolResultVO.getUrl();
|
||||||
if (url.substring(url.lastIndexOf("/") + 1).equals("white_image.jpg")) {
|
if (url.substring(url.lastIndexOf("/") + 1).equals("white_image.jpg")) {
|
||||||
generateResultVO.setStatus("Invalid");
|
magicToolResultVO.setStatus("Invalid");
|
||||||
} else {
|
} 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)) {
|
} else if (Objects.isNull(magicToolResultVO)) {
|
||||||
generateResultVO = new GenerateResultVO();
|
magicToolResultVO = new MagicToolResultVO();
|
||||||
}
|
}
|
||||||
if (!StringUtil.isNullOrEmpty(generateResultVO.getStatus())) collect.add(generateResultVO.getStatus());
|
if (!StringUtil.isNullOrEmpty(magicToolResultVO.getStatus())) collect.add(magicToolResultVO.getStatus());
|
||||||
results.add(generateResultVO);
|
results.add(magicToolResultVO);
|
||||||
});
|
});
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
@@ -408,6 +423,102 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
|||||||
return Boolean.TRUE;
|
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) {
|
public static String convert(InputStream inputStream) {
|
||||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
|
||||||
return reader.lines().collect(Collectors.joining("\n"));
|
return reader.lines().collect(Collectors.joining("\n"));
|
||||||
|
|||||||
@@ -141,6 +141,14 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
|
|||||||
workspaceRelStyleMapper.updateById(workspaceRelStyle);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -308,6 +316,7 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
|
|||||||
List<WorkspaceRelStyle> workspaceRelStyles = workspaceRelStyleMapper.selectList(qw);
|
List<WorkspaceRelStyle> workspaceRelStyles = workspaceRelStyleMapper.selectList(qw);
|
||||||
if (!CollectionUtils.isEmpty(workspaceRelStyles)) {
|
if (!CollectionUtils.isEmpty(workspaceRelStyles)) {
|
||||||
Long styleId = workspaceRelStyles.get(0).getStyleId();
|
Long styleId = workspaceRelStyles.get(0).getStyleId();
|
||||||
|
vo.setStyleId(styleId);
|
||||||
Style style = styleMapper.selectById(styleId);
|
Style style = styleMapper.selectById(styleId);
|
||||||
StyleEnum styleEnum = StyleEnum.fromName(style.getName());
|
StyleEnum styleEnum = StyleEnum.fromName(style.getName());
|
||||||
vo.setStyle(styleEnum.name());
|
vo.setStyle(styleEnum.name());
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ redis.key.taskList=TaskList
|
|||||||
redis.key.credits.pre-deduction=Credits:PreDeduction
|
redis.key.credits.pre-deduction=Credits:PreDeduction
|
||||||
redis.key.generateResult=Generate:Result
|
redis.key.generateResult=Generate:Result
|
||||||
redis.key.toProductImageResultKey=ToProductImage:Result
|
redis.key.toProductImageResultKey=ToProductImage:Result
|
||||||
|
redis.key.relightResultKey=Relight:Result
|
||||||
|
|
||||||
aws.s3.accessKeyId=AKIAVD3OJIMF6UJFLSHZ
|
aws.s3.accessKeyId=AKIAVD3OJIMF6UJFLSHZ
|
||||||
aws.s3.secretKey=LNIwFFB27/QedtZ+Q/viVUoX9F5x1DbuM8N0DkD8
|
aws.s3.secretKey=LNIwFFB27/QedtZ+Q/viVUoX9F5x1DbuM8N0DkD8
|
||||||
|
|||||||
Reference in New Issue
Block a user