| | |
| | | import com.iplatform.recvideo.util.PythonInvokeUtils; |
| | | import com.iplatform.recvideo.util.TestUtils; |
| | | import com.iplatform.recvideo.util.VideoFileUtils; |
| | | import com.walker.infrastructure.utils.FileUtils; |
| | | import com.walker.infrastructure.utils.StringUtils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | import java.io.File; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | |
| | | public int execute() throws Exception{ |
| | | if(!this.pythonLoadVideoDone){ |
| | | logger.debug("当前 pythonLoadVideoDone = false, 需要查询数据库是否已加载视频"); |
| | | this.pythonLoadVideoDone = this.pythonLoadVideoDone(this.batchId, VideoFileUtils.combineBatchPath(videoDataFolder, batchId)); |
| | | String batchPath = VideoFileUtils.combineBatchPath(videoDataFolder, batchId); |
| | | if(!FileUtils.isExist(batchPath)){ |
| | | // 文件夹不存在,或略该状态记录,2022-10-11 |
| | | this.ignoreTaskStatus(batchId); |
| | | logger.warn("文件夹不存在,忽略该批次记录,自动更新为'已完成', batchPath = " + batchPath); |
| | | return 1; |
| | | } |
| | | this.pythonLoadVideoDone = this.pythonLoadVideoDone(this.batchId, batchPath); |
| | | } |
| | | |
| | | // 1: 如果视频还未加载,则先加载视频 |
| | |
| | | } |
| | | } |
| | | if(StringUtils.isEmptyList(this.videoFolderInfoList)){ |
| | | logger.warn("视频分析文件夹内容为空,无法继续查询相似度结果! videoFolderInfoList = null"); |
| | | return -1; |
| | | logger.warn("视频分析文件夹内容为空,无法继续查询相似度结果!忽略该批次。 videoFolderInfoList = null"); |
| | | // return -1; |
| | | // 文件夹不没有任何视频文件,或略该状态记录,2022-10-11 |
| | | this.ignoreTaskStatus(batchId); |
| | | return 1; |
| | | } |
| | | |
| | | for(VideoFolderInfo v : this.videoFolderInfoList){ |
| | | this.videoIdList.add(v.getVideoId()); |
| | | } |
| | |
| | | } |
| | | |
| | | try { |
| | | this.processOneSearchAndWrite(); |
| | | this.processOneSearchAndWrite(this.batchId); |
| | | return 0; |
| | | } catch (Exception e) { |
| | | throw new Exception("processOneSearchAndWrite(): " + e.getMessage(), e); |
| | | } |
| | | } |
| | | |
| | | private void processOneSearchAndWrite() throws Exception{ |
| | | private void processOneSearchAndWrite(String batchId) throws Exception{ |
| | | if(this.currentVideoFolderIndex >= this.videoFolderInfoList.size()){ |
| | | throw new IllegalArgumentException("currentVideoFolderIndex 越界: " + this.currentVideoFolderIndex); |
| | | } |
| | |
| | | // 每个视频的最后一张图片 |
| | | if((this.currentImageIndex + 1) >= currentVideoFolderInfo.getImageInfoSize()){ |
| | | try { |
| | | this.writeRcVideoT2(currentVideoFolderInfo); |
| | | this.writeRcVideoT2(currentVideoFolderInfo, batchId); |
| | | } catch (Exception ex){ |
| | | throw new Exception("writeRcVideoT2()执行错误:" + ex.getMessage(), ex); |
| | | } |
| | |
| | | * 分析表'rc_video_t1',并把给定视频相似记录写入第二个临时表'rc_video_t2' |
| | | * @param videoFolderInfo |
| | | */ |
| | | protected abstract void writeRcVideoT2(VideoFolderInfo videoFolderInfo); |
| | | protected abstract void writeRcVideoT2(VideoFolderInfo videoFolderInfo, String batchId); |
| | | |
| | | /** |
| | | * 分析给定批次所有视频用户推荐的视频信息,并写入表:'rc_video_user' |
| | | * @param batchId |
| | | * @param recVideoIdList 推荐视频id集合 |
| | | * @param recVideoIdList 本批次处理原始视频id集合 |
| | | */ |
| | | protected abstract void writeRcVideoUser(String batchId, List<String> recVideoIdList); |
| | | |
| | | /** |
| | | * 忽略该状态批次,由于文件夹不存在等原因,不带处理,不要在这里打伴。 |
| | | * @param batchId |
| | | * @date 2022-10-11 |
| | | */ |
| | | protected abstract void ignoreTaskStatus(String batchId); |
| | | } |