fix: bug修改 result 写成 URL
This commit is contained in:
parent
8436c3515c
commit
45cff6ab27
|
|
@ -2,6 +2,7 @@ package com.ruoyi.api;
|
|||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.ruoyi.ai.domain.AiOrder;
|
||||
|
|
@ -153,6 +154,31 @@ public class PortalVideoController extends BaseController {
|
|||
}
|
||||
}
|
||||
|
||||
/** 写入 video_params.volcTaskId,任务成功后 result 会改为成品 URL,仍应用此 id 校验归属与轮询 */
|
||||
private void mergeVolcTaskIdIntoVideoParams(AiOrder aiOrder, String volcTaskId) {
|
||||
if (StringUtils.isEmpty(volcTaskId)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
ObjectNode node;
|
||||
if (StringUtils.isNotEmpty(aiOrder.getVideoParams())) {
|
||||
JsonNode existing = OM.readTree(aiOrder.getVideoParams());
|
||||
if (existing instanceof ObjectNode) {
|
||||
node = (ObjectNode) existing;
|
||||
} else {
|
||||
node = OM.createObjectNode();
|
||||
node.set("snapshotBeforeVolcId", existing);
|
||||
}
|
||||
} else {
|
||||
node = OM.createObjectNode();
|
||||
}
|
||||
node.put("volcTaskId", volcTaskId);
|
||||
aiOrder.setVideoParams(OM.writeValueAsString(node));
|
||||
} catch (Exception e) {
|
||||
aiOrder.setVideoParams("{\"volcTaskId\":\"" + volcTaskId.replace("\"", "") + "\"}");
|
||||
}
|
||||
}
|
||||
|
||||
private AjaxResult submitOrderAndCreate(PortalVideoGenRequest req, String mode, ByteBodyReq byteBodyReq) {
|
||||
String functionType = resolveFunctionType(req);
|
||||
AiOrder aiOrder = aiOrderService.getAiOrder(functionType);
|
||||
|
|
@ -170,6 +196,7 @@ public class PortalVideoController extends BaseController {
|
|||
aiOrderService.orderFailure(aiOrder);
|
||||
return AjaxResult.error(-2, "generation failed, balance has been refunded");
|
||||
}
|
||||
mergeVolcTaskIdIntoVideoParams(aiOrder, id);
|
||||
aiOrder.setResult(id);
|
||||
aiOrderService.orderSuccess(aiOrder);
|
||||
return AjaxResult.success(byteBodyRes);
|
||||
|
|
@ -357,7 +384,7 @@ public class PortalVideoController extends BaseController {
|
|||
@ApiOperation("查询单个视频生成任务(火山)")
|
||||
public AjaxResult getVolcTask(@PathVariable String taskId) throws Exception {
|
||||
Long uid = SecurityUtils.getAiUserId();
|
||||
AiOrder owned = aiOrderService.getAiOrderByResult(taskId);
|
||||
AiOrder owned = aiOrderService.getAiOrderByPortalVideoTask(taskId);
|
||||
if (owned == null || !uid.equals(owned.getUserId())) {
|
||||
return AjaxResult.error("无权查看该任务");
|
||||
}
|
||||
|
|
@ -383,7 +410,7 @@ public class PortalVideoController extends BaseController {
|
|||
@ApiOperation("删除或取消视频生成任务")
|
||||
public AjaxResult deleteOrCancelTask(@PathVariable String taskId) throws Exception {
|
||||
Long uid = SecurityUtils.getAiUserId();
|
||||
AiOrder owned = aiOrderService.getAiOrderByResult(taskId);
|
||||
AiOrder owned = aiOrderService.getAiOrderByPortalVideoTask(taskId);
|
||||
if (owned == null || !uid.equals(owned.getUserId())) {
|
||||
return AjaxResult.error("无权操作该任务");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,5 +22,8 @@ public interface AiOrderMapper extends BaseMapper<AiOrder> {
|
|||
|
||||
AiOrder getAiOrderByResult(@Param("result") String result);
|
||||
|
||||
/** 门户视频:按火山任务 id 查单(result 可能已被替换为成品 URL,故兼查 video_params.volcTaskId) */
|
||||
AiOrder getAiOrderByPortalVideoTask(@Param("taskId") String taskId);
|
||||
|
||||
BigDecimal getSumAmountByUserId(@Param("userId") String userId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,5 +79,7 @@ public interface IAiOrderService {
|
|||
|
||||
AiOrder getAiOrderByResult(String result);
|
||||
|
||||
AiOrder getAiOrderByPortalVideoTask(String taskId);
|
||||
|
||||
BigDecimal getSumAmountByUserId(String userId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -203,6 +203,11 @@ public class AiOrderServiceImpl implements IAiOrderService {
|
|||
return aiOrderMapper.selectOne(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AiOrder getAiOrderByPortalVideoTask(String taskId) {
|
||||
return aiOrderMapper.getAiOrderByPortalVideoTask(taskId);
|
||||
}
|
||||
|
||||
public int getChangerType(String aiType) {
|
||||
switch (aiType) {
|
||||
case "11":
|
||||
|
|
|
|||
|
|
@ -69,6 +69,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
where result = #{result}
|
||||
</select>
|
||||
|
||||
<select id="getAiOrderByPortalVideoTask" resultMap="AiOrderResult">
|
||||
<include refid="selectAiOrderVo"/>
|
||||
where ao.del_flag = '0'
|
||||
and ao.type = '21'
|
||||
and (
|
||||
ao.result = #{taskId}
|
||||
or (
|
||||
ao.video_params is not null and ao.video_params != ''
|
||||
and JSON_VALID(ao.video_params)
|
||||
and JSON_UNQUOTE(JSON_EXTRACT(ao.video_params, '$.volcTaskId')) = #{taskId}
|
||||
)
|
||||
)
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
<select id="getSumAmountByUserId" resultType="java.math.BigDecimal">
|
||||
SELECT COALESCE(sum(amount), 0) from ai_order where user_id = #{userId}
|
||||
</select>
|
||||
|
|
|
|||
Loading…
Reference in New Issue