|
|
@@ -8,7 +8,6 @@ import com.tzld.videoVector.common.enums.Modality;
|
|
|
import com.tzld.videoVector.dao.mapper.videoVector.VideoAiUnderstandingMapper;
|
|
|
import com.tzld.videoVector.dao.mapper.videoVector.deconstruct.DeconstructContentMapper;
|
|
|
import com.tzld.videoVector.model.entity.VideoDetail;
|
|
|
-import com.tzld.videoVector.model.param.GetDeconstructParam;
|
|
|
import com.tzld.videoVector.model.param.MatchTopNVideoParam;
|
|
|
import com.tzld.videoVector.model.param.recall.MatchByTextParam;
|
|
|
import com.tzld.videoVector.model.param.recall.MatchByVideoIdParam;
|
|
|
@@ -24,6 +23,7 @@ import com.tzld.videoVector.service.VideoSearchService;
|
|
|
import com.tzld.videoVector.service.recall.VectorRecallTestService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
@@ -59,8 +59,18 @@ public class VectorRecallTestServiceImpl implements VectorRecallTestService {
|
|
|
@Autowired(required = false)
|
|
|
private VideoAiUnderstandingMapper videoAiUnderstandingMapper;
|
|
|
|
|
|
+ @Autowired(required = false)
|
|
|
+ private StringRedisTemplate stringRedisTemplate;
|
|
|
+
|
|
|
private static final String PLACEHOLDER = "--";
|
|
|
|
|
|
+ /**
|
|
|
+ * Redis Key: recall:vid_decode:{vid}
|
|
|
+ * Value: 本地脚本(script/sync_decode_to_redis.py)解析后的瘦身 JSON,
|
|
|
+ * 含 vid/title/videoUrl/htmlUrl/topic/highValuePoints
|
|
|
+ */
|
|
|
+ private static final String REDIS_KEY_DECODE_PREFIX = "recall:vid_decode:";
|
|
|
+
|
|
|
@Override
|
|
|
public VideoBasicVO getVideoDetail(Long videoId) {
|
|
|
if (videoId == null || videoId <= 0L) {
|
|
|
@@ -129,76 +139,29 @@ public class VectorRecallTestServiceImpl implements VectorRecallTestService {
|
|
|
if (videoId == null || videoId <= 0L) {
|
|
|
return null;
|
|
|
}
|
|
|
- String channelContentId = String.valueOf(videoId);
|
|
|
-
|
|
|
- // 1. 按 channel_content_id 查 deconstruct_content (用 WithBLOBs 拿 result_json BLOB)
|
|
|
- DeconstructContent content;
|
|
|
+ if (stringRedisTemplate == null) {
|
|
|
+ log.warn("getDeconstructPoints: stringRedisTemplate 未注入");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ String vid = String.valueOf(videoId);
|
|
|
+ String key = REDIS_KEY_DECODE_PREFIX + vid;
|
|
|
+ String json;
|
|
|
try {
|
|
|
- DeconstructContentExample example = new DeconstructContentExample();
|
|
|
- example.createCriteria().andChannelContentIdEqualTo(channelContentId);
|
|
|
- example.setOrderByClause("id DESC");
|
|
|
- List<DeconstructContent> list = deconstructContentMapper.selectByExampleWithBLOBs(example);
|
|
|
- content = list.isEmpty() ? null : list.get(0);
|
|
|
+ json = stringRedisTemplate.opsForValue().get(key);
|
|
|
} catch (Exception e) {
|
|
|
- log.error("getDeconstructPoints: query db fail, videoId={}, err={}", videoId, e.getMessage(), e);
|
|
|
+ log.error("getDeconstructPoints: read redis fail, vid={}, err={}", vid, e.getMessage(), e);
|
|
|
return null;
|
|
|
}
|
|
|
-
|
|
|
- if (content == null) {
|
|
|
- log.info("getDeconstructPoints: deconstruct_content 表无 channel_content_id={} 的记录", channelContentId);
|
|
|
+ if (!StringUtils.hasText(json)) {
|
|
|
+ log.info("getDeconstructPoints: Redis 无 vid={} 的解构记录(脚本未同步或非视频内容)", vid);
|
|
|
return null;
|
|
|
}
|
|
|
-
|
|
|
- DeconstructPointsVO vo = new DeconstructPointsVO();
|
|
|
- vo.setId(videoId);
|
|
|
- vo.setChannelContentId(content.getChannelContentId());
|
|
|
- vo.setTaskId(content.getTaskId());
|
|
|
- // 用 Number → intValue 兼容 Byte (a909594) / Short (master) PO 字段类型
|
|
|
- vo.setContentType(content.getContentType() == null ? null : content.getContentType().intValue());
|
|
|
- vo.setBizType(content.getBizType() == null ? null : content.getBizType().intValue());
|
|
|
- vo.setStatus(content.getStatus() == null ? null : content.getStatus().intValue());
|
|
|
- vo.setStatusDesc(getStatusDesc(content.getStatus()));
|
|
|
- vo.setTitle(content.getTitle());
|
|
|
- vo.setFailureReason(content.getFailureReason());
|
|
|
-
|
|
|
- // 2. 优先用本地 result_json (已 WithBLOBs)
|
|
|
- if (StringUtils.hasText(content.getResultJson())) {
|
|
|
- try {
|
|
|
- vo.setRawResult(JSON.parseObject(content.getResultJson()));
|
|
|
- return vo;
|
|
|
- } catch (Exception e) {
|
|
|
- log.warn("getDeconstructPoints: parse local resultJson fail, videoId={}, err={}",
|
|
|
- videoId, e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 3. 本地 result_json 为空 → 用 taskId 调现有 getDeconstructResult,
|
|
|
- // 它内部会调外部 API 拉数据 + 回填本地表
|
|
|
- if (StringUtils.hasText(content.getTaskId())) {
|
|
|
- try {
|
|
|
- GetDeconstructParam p = new GetDeconstructParam();
|
|
|
- p.setTaskId(content.getTaskId());
|
|
|
- p.setBizType(content.getBizType() == null ? null : content.getBizType().intValue());
|
|
|
- p.setContentType(content.getContentType() == null ? null : content.getContentType().intValue());
|
|
|
- p.setChannelContentId(channelContentId);
|
|
|
- JSONObject apiResult = videoSearchService.getDeconstructResult(p);
|
|
|
- if (apiResult != null) {
|
|
|
- // 现有 getDeconstructResult 返回结构: { result: {...}, status, taskId, url }
|
|
|
- // 解构 JSON 在 result 字段里, 透传给前端
|
|
|
- Object inner = apiResult.get("result");
|
|
|
- if (inner instanceof JSONObject) {
|
|
|
- vo.setRawResult((JSONObject) inner);
|
|
|
- } else if (inner != null) {
|
|
|
- // 兜底: 整个 apiResult 透传
|
|
|
- vo.setRawResult(apiResult);
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.warn("getDeconstructPoints: fallback to videoSearchService.getDeconstructResult failed, videoId={}, taskId={}, err={}",
|
|
|
- videoId, content.getTaskId(), e.getMessage());
|
|
|
- }
|
|
|
+ try {
|
|
|
+ return JSON.parseObject(json, DeconstructPointsVO.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("getDeconstructPoints: parse redis value fail, vid={}, err={}", vid, e.getMessage(), e);
|
|
|
+ return null;
|
|
|
}
|
|
|
- return vo;
|
|
|
}
|
|
|
|
|
|
@Override
|