| | |
| | | package com.iplatform.recvideo.service; |
| | | |
| | | import com.iplatform.model.po.Rc_video_t1; |
| | | import com.iplatform.model.po.Rc_video_t2; |
| | | import com.iplatform.model.po.Rc_video_user; |
| | | import com.walker.infrastructure.utils.DateUtils; |
| | | import com.walker.infrastructure.utils.StringUtils; |
| | | import com.walker.jdbc.service.BaseServiceImpl; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Service |
| | | public class VideoExecutorServiceImpl extends BaseServiceImpl { |
| | | |
| | | private static final String SQL_CHECK_VIDEO_STATUS = "select * from milvus_video_status where id=?"; |
| | | private static final String SQL_CLEAR_VIDEO_T1 = "delete from rc_video_t1 where src_img=?"; |
| | | private static final String SQL_CLEAR_VIDEO_T2 = "delete from rc_video_t2 where src_video_id=?"; |
| | | |
| | | private static final String SQL_GET_BATCH_VIDEO = "select user_id, src_video_id from rc_video_batch where batch_id=?"; |
| | | |
| | | private static final String SQL_UPDATE_TASK_STATUS_LOAD = "update rc_task_status set status='1', end_time=? where last_value=? and status='0'"; |
| | | private static final String SQL_IGNORE_TASK_STATUS_LOAD = "update rc_task_status set status='1', msg='ignore' where last_value=? and status='0' and task_type='video_load'"; |
| | | |
| | | /** |
| | | * 写入视频相似度第一级临时数据,每个图像包含多个相似视频记录。 |
| | | * @param list |
| | | * @param srcImageId 原始图像ID |
| | | */ |
| | | public void execBatchInsertVideoT1(List<Rc_video_t1> list, String srcImageId){ |
| | | // 写入新数据之前,先清除老视频数据,后续分析避免数据重复(每个视频) |
| | | this.execute(SQL_CLEAR_VIDEO_T1, new Object[]{srcImageId}); |
| | | this.insert(list); |
| | | } |
| | | |
| | | /** |
| | | * 写入视频相似度第二临时数据,每个原始视频对应多个相似视频,已排序存储。 |
| | | * @param list |
| | | * @param srcVideoId |
| | | */ |
| | | public void execBatchInsertVideoT2(List<Rc_video_t2> list, String srcVideoId){ |
| | | this.execute(SQL_CLEAR_VIDEO_T2, new Object[]{srcVideoId}); |
| | | this.insert(list); |
| | | } |
| | | |
| | | /** |
| | | * 写入用户推荐视频记录集合,并更新批次任务状态为(已完成) |
| | | * @param videoUserList |
| | | * @param batchId |
| | | */ |
| | | public void execBatchInsertVideoUser(List<Rc_video_user> videoUserList, String batchId){ |
| | | this.insert(videoUserList); |
| | | Object[] param = new Object[2]; |
| | | param[0] = Long.parseLong(DateUtils.getDateTimeSecondForShow()); |
| | | param[1] = Long.parseLong(batchId); |
| | | this.execute(SQL_UPDATE_TASK_STATUS_LOAD, param); |
| | | } |
| | | |
| | | public void execIgnoreTaskStatus(String batchId){ |
| | | this.execute(SQL_IGNORE_TASK_STATUS_LOAD, new Object[]{Long.parseLong(batchId)}); |
| | | } |
| | | |
| | | /** |
| | | * 返回一个批次用户对应视频记录集合,用于最后更新用户推荐视频数据。 |
| | | * @param batchId |
| | | * @return |
| | | * @date 2022-09-26 |
| | | */ |
| | | public List<Map<String, Object>> queryBatchUserVideoList(String batchId){ |
| | | return this.select(SQL_GET_BATCH_VIDEO, new Object[]{batchId}); |
| | | } |
| | | |
| | | public List<Rc_video_t2> queryVideoT_2List(String batchId){ |
| | | return this.select(new Rc_video_t2(), "where batch_id=?", new Object[]{batchId}); |
| | | } |
| | | |
| | | /** |
| | | * 根据原始视频ID返回相似记录集合。 |
| | | * @param srcVideoId |
| | | * @return |
| | | */ |
| | | public List<Rc_video_t1> queryVideoT_1List(String srcVideoId){ |
| | | return this.select(new Rc_video_t1(), "where src_video_id=?", new Object[]{srcVideoId}); |
| | | } |
| | | |
| | | /** |
| | | * 查询视频加载状态表,是否已经完成加载(第一步),如果记录不存在说明还没有开始加载。 |
| | | * @param videoStatusId |
| | | * @return |
| | | */ |
| | | public boolean queryLoadVideoDone(String videoStatusId){ |
| | | Map<String, Object> map = this.get(SQL_CHECK_VIDEO_STATUS, new Object[]{videoStatusId}); |
| | | if(map == null){ |
| | | return false; |
| | | } |
| | | int status = Integer.parseInt(map.get("status").toString()); |
| | | if(status == 1){ |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | } |