From fb66d5ed24e716e536543364f746a9db5aeb20a9 Mon Sep 17 00:00:00 2001
From: shikeying <shikeying@163.com>
Date: 星期二, 27 九月 2022 18:47:56 +0800
Subject: [PATCH] 视频相似度分析4

---
 recommend-video/src/main/java/com/iplatform/recvideo/VideoLoader.java                    |   99 +++++++++++
 recommend-video/doc/table.SQL                                                            |  191 +++++++++++++++++++++
 recommend-video/src/main/java/com/iplatform/recvideo/scheduler/VideoLoadScheduler.java   |   17 +
 recommend-video/src/main/java/com/iplatform/recvideo/VideoLoadInfo.java                  |   61 ++++++
 recommend-video/src/main/java/com/iplatform/recvideo/service/VideoLoaderServiceImpl.java |   45 +++++
 recommend-video/src/main/java/com/iplatform/recvideo/support/DefaultVideoLoader.java     |   76 ++++++++
 6 files changed, 488 insertions(+), 1 deletions(-)

diff --git a/recommend-video/doc/table.SQL b/recommend-video/doc/table.SQL
index 4506ab4..8c5d46e 100644
--- a/recommend-video/doc/table.SQL
+++ b/recommend-video/doc/table.SQL
@@ -1,3 +1,6 @@
+-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+-- 浠ヤ笅涓虹储寮曡缃�
+-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 ALTER TABLE rc_video_t1
     ADD INDEX inx_src_img (src_img) USING BTREE ;
@@ -17,4 +20,190 @@
     ADD INDEX inx_vb_bid (batch_id) USING BTREE ;
 
 ALTER TABLE rc_video_user
-    ADD INDEX inx_vu_uid (user_id) USING BTREE ;
\ No newline at end of file
+    ADD INDEX inx_vu_uid (user_id) USING BTREE ;
+
+-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+-- 浠ヤ笅涓鸿〃缁撴瀯
+-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+create table milvus_video_batch (
+                                    batch_id bigint(20) not null comment '鎵规id锛屽嵆锛氭棩鏈熸椂闂�',
+                                    video_id varchar(255) not null,
+                                    video_path varchar(255) default null,
+                                    vector_size int(11) not null default '0',
+                                    create_time bigint(20) not null,
+                                    status int(11) not null default '1' comment '鐘舵�侊細0 鏈畬鎴愶紝1瀹屾垚'
+) engine=innodb default charset=utf8;
+
+create table milvus_video_search (
+                                     milvus_id text,
+                                     image_path text,
+                                     video_id text
+) engine=innodb default charset=utf8;
+
+create table milvus_video_status (
+                                     id varchar(255) not null comment '瑙嗛璺緞',
+                                     create_time bigint(20) not null,
+                                     status int(11) not null default '0' comment '瀹屾垚鐘舵��: 0 鏈畬鎴�, 1 瀹屾垚',
+                                     records bigint(20) not null default '0',
+                                     primary key (id)
+) engine=innodb default charset=utf8;
+
+create table rc_task_status (
+                                id bigint(20) not null comment '涓婚敭',
+                                create_time bigint(20) not null comment '鍒涘缓鏃堕棿锛屽: 20220922180501',
+                                name varchar(180) not null comment '浠诲姟鍚嶇О',
+                                last_value bigint(20) not null comment '鑾峰彇鏁版嵁鐨勬渶澶у��',
+                                status varchar(32) not null comment '褰撳墠鐘舵�侊紝瑙佹灇涓�: taskstatus',
+                                start_time bigint(20) default null,
+                                end_time bigint(20) default null,
+                                msg varchar(180) default null comment '鎵ц鎻忚堪',
+                                task_type varchar(32) not null comment '浠诲姟绫诲瀷锛岃鏋氫妇: tasktype',
+                                primary key (id)
+) engine=innodb default charset=utf8;
+
+create table rc_video_batch (
+                                id bigint(20) not null,
+                                batch_id varchar(32) not null comment '鎵规id',
+                                user_id bigint(20) not null,
+                                src_video_id varchar(32) not null,
+                                src_video_path varchar(255) default null,
+                                primary key (id),
+                                key inx_vb_bid (batch_id) using btree
+) engine=innodb default charset=utf8;
+
+create table rc_video_t1 (
+                             src_img varchar(36) not null comment '鍥惧儚id',
+                             src_video_id varchar(32) not null,
+                             sim_video_id varchar(32) not null,
+                             distance double not null default '0',
+                             id varchar(32) not null,
+                             primary key (id),
+                             key inx_src_img (src_img) using btree,
+                             key inx_src_vid (src_video_id) using btree
+) engine=innodb default charset=utf8;
+
+create table rc_video_t2 (
+                             src_video_id varchar(32) not null,
+                             sim_video_id varchar(32) not null,
+                             score double not null default '0' comment '鐩镐技瑙嗛缁煎悎寰楀垎',
+                             id varchar(32) not null,
+                             batch_id varchar(32) not null default '0',
+                             primary key (id),
+                             key inx_t2_src_vid (src_video_id) using btree,
+                             key inx_t2_src_bid (batch_id) using btree
+) engine=innodb default charset=utf8;
+
+create table rc_video_user (
+                               user_id bigint(20) not null,
+                               video_id varchar(32) not null,
+                               score double not null default '0',
+                               create_time bigint(20) not null default '0',
+                               id bigint(20) not null,
+                               primary key (id),
+                               key inx_vu_uid (user_id) using btree
+) engine=innodb default charset=utf8;
+
+create table s_host (
+                        id bigint(20) not null auto_increment,
+                        create_time bigint(20) not null,
+                        create_user varchar(36) not null,
+                        url varchar(200) not null comment '搴撳湴鍧�',
+                        port int(11) not null default '1306' comment '绔彛',
+                        service_name varchar(100) default null comment '鏈嶅姟鍚嶇О',
+                        authentication varchar(30) default null comment '璁よ瘉鐢ㄦ埛',
+                        certification varchar(30) default null comment '鎺堟潈瀵嗙爜',
+                        max_active int(11) not null default '5' comment '鏈�澶ц繛鎺ユ暟',
+                        primary key (id)
+) engine=innodb auto_increment=105 default charset=utf8 comment='瀛樺偍璧勬簮鍙敤涓绘満';
+
+create table s_scheduler (
+                             id int(11) not null comment '璋冨害鍣╥d',
+                             create_time bigint(20) not null,
+                             name varchar(180) not null,
+                             status int(11) not null default '0' comment '鐘舵�侊細0_鍒濆鍖栵紝1_杩愯锛�2_鏆傚仠锛�9_缁撴潫锛�-1_浜哄伐缁堟',
+                             start_time bigint(20) not null default '0' comment '璋冨害寮�濮嬭繍琛屾椂闂�',
+                             end_time bigint(20) not null default '0' comment '璋冨害缁撴潫杩愯鏃堕棿',
+                             interval_time int(11) not null default '5000' comment '鍐呴儴绾跨▼鎵ц闂撮殧鏃堕棿锛岄粯璁わ細5绉�',
+                             sleep_time int(11) not null default '600000' comment '绾跨▼鎵ц涓紝鐫$湢鏃堕棿锛岄粯璁わ細10鍒嗛挓',
+                             sleep_option int(11) not null default '1' comment '閲囬泦绾跨▼鍦ㄦ病鏈夎幏鍙栨暟鎹椂锛屾槸鍚﹁繘鍏ヤ紤鐪狅細0_鍚︼紝1_鏄�',
+                             period_type varchar(36) not null comment '鍛ㄦ湡绫诲瀷锛歯one,day,week,month,year',
+                             time_type varchar(36) not null comment '瀹氭椂绫诲瀷锛氱簿纭椂闂確exactly锛屾椂闂存_range',
+                             year int(11) not null default '0',
+                             month int(11) not null default '0',
+                             day int(11) not null default '0',
+                             hour int(11) not null default '0',
+                             ranges varchar(50) default null comment '鏃堕棿鑼冨洿锛屽涓锛�5,6锛�12,15;...',
+                             dept int(11) not null default '0',
+                             class_name varchar(200) not null,
+                             pause_time bigint(20) not null default '0',
+                             summary varchar(255) default null,
+                             primary key (id)
+) engine=innodb default charset=utf8 comment='骞冲彴璋冨害鍣ㄨ褰曡〃';
+
+create table sdc_gather (
+                            id bigint(20) not null,
+                            create_time bigint(20) not null,
+                            create_user varchar(36) not null,
+                            name varchar(120) not null comment '閲囬泦鍚嶇О',
+                            description varchar(255) default null,
+                            src_type tinyint(4) not null default '0' comment '閲囬泦婧愶細0_http,1_db',
+                            src_url varchar(120) not null,
+                            src_port int(11) default '80',
+                            src_service varchar(120) default null,
+                            src_user varchar(120) default null,
+                            src_pass varchar(120) default null,
+                            store_id varchar(36) not null comment '澶栭敭锛氬瓨鍌╥d',
+                            status tinyint(4) not null default '0' comment '鐘舵�侊細0_鍒濆鍖栵紝1_杩愯锛�2_鏆傚仠锛�9_缁撴潫',
+                            schedule_id int(11) not null comment '璋冨害鍣╥d',
+                            primary key (id)
+) engine=innodb default charset=utf8 comment='閲囬泦浠诲姟璁板綍';
+
+create table sdc_meta_db (
+                             id bigint(20) not null,
+                             create_time bigint(20) not null,
+                             store_id varchar(36) not null comment '澶栭敭锛氬瓨鍌╥d',
+                             database_name varchar(60) default null,
+                             used tinyint(4) not null default '0' comment '鏄惁琚娇鐢ㄨ繃锛�0_鍚︼紝1_鏄�',
+                             is_using tinyint(4) not null default '0' comment '姝e湪琚娇鐢細0_鍚︼紝1_鏄�',
+                             host_info varchar(100) not null comment '瀛樺偍浣跨敤搴撶殑淇℃伅锛歩p:port',
+                             table_count int(11) not null default '0' comment '瀛樺湪鐨勮〃鏁伴噺',
+                             summary varchar(255) default null,
+                             password varchar(255) default null,
+                             username varchar(255) default null,
+                             primary key (id),
+                             key store_id (store_id),
+                             constraint sdc_meta_db_ibfk_1 foreign key (store_id) references sdc_store (id) on delete cascade
+) engine=innodb default charset=utf8 comment='鍏冩暟鎹暟鎹簱淇℃伅';
+
+create table sdc_meta_table (
+                                id bigint(20) not null auto_increment,
+                                create_time bigint(20) not null,
+                                store_id varchar(36) not null comment '澶栭敭锛氬瓨鍌╥d',
+                                db_id bigint(20) not null comment '澶栭敭锛歞bid',
+                                table_name varchar(60) not null comment '琛ㄥ悕',
+                                row_count bigint(20) not null default '0' comment '璁板綍鏁伴噺',
+                                summary varchar(255) default null,
+                                primary key (id),
+                                key db_id (db_id),
+                                key store_id (store_id),
+                                constraint sdc_meta_table_ibfk_1 foreign key (db_id) references sdc_meta_db (id) on delete cascade,
+                                constraint sdc_meta_table_ibfk_2 foreign key (store_id) references sdc_store (id) on delete cascade
+) engine=innodb default charset=utf8 comment='鍏冩暟鎹紝琛ㄤ俊鎭�';
+
+create table sdc_store (
+                           id varchar(36) not null comment '瀛樺偍id锛屼富閿�',
+                           create_time bigint(20) default null comment '鍒涘缓鏃堕棿姣鍊�',
+                           create_user varchar(36) not null,
+                           description varchar(255) not null comment '鎻忚堪',
+                           inner_use tinyint(4) not null default '0' comment '鍐呴儴浣跨敤锛�0_琛ㄧず绯荤粺鎺у埗鐨勫唴閮ㄦ暟鎹紝鍏朵粬琛ㄧず澶栭儴瀛樺偍锛屽锛氳嚜宸辨墜鍔ㄥ姞涓婄殑鍙綔涓鸿褰�',
+                           type varchar(30) not null comment '瀛樺偍绫诲瀷锛氭暟鎹簱銆佸垎甯冨紡鏂囦欢绯荤粺绛�',
+                           database_type tinyint(4) not null default '0' comment '鏁版嵁搴撶被鍨嬶細0_derby,1_oracle,2_mysql,3_sqlserver',
+                           strategy varchar(90) not null comment '瀛樺偍绛栫暐鐨勭被鍚�',
+                           deleted tinyint(4) not null default '0' comment '鏄惁搴熷純锛�1_鏄紝0_鍚�',
+                           update_time bigint(20) default null comment '鏇存柊鏃堕棿',
+                           update_user varchar(36) default null comment '鏇存柊鐢ㄦ埛',
+                           define_name varchar(60) not null comment '瀛樺偍搴撳畾涔夊悕瀛楋紝濡傦細鏁版嵁搴撳悕',
+                           select_hosts varchar(100) not null comment '閫夋嫨涓绘満淇℃伅锛屽涓敤鑻辨枃鍒嗗彿闅斿紑',
+                           primary key (id)
+) engine=innodb default charset=utf8;
diff --git a/recommend-video/src/main/java/com/iplatform/recvideo/VideoLoadInfo.java b/recommend-video/src/main/java/com/iplatform/recvideo/VideoLoadInfo.java
new file mode 100644
index 0000000..2af125a
--- /dev/null
+++ b/recommend-video/src/main/java/com/iplatform/recvideo/VideoLoadInfo.java
@@ -0,0 +1,61 @@
+package com.iplatform.recvideo;
+
+/**
+ * 瑕佽幏鍙栫殑瑙嗛璁板綍銆�
+ * @author 鏃跺厠鑻�
+ * @date 2022-09-26
+ */
+public class VideoLoadInfo {
+
+    private String srcVideoId;      // 瑙嗛鍘熷ID
+
+    private String videoSrcPath;    // 鍦ㄥ師鏈嶅姟鍣ㄨ矾寰�
+
+    private String videoDestPath;   // 瑕佹嫹璐濆埌鐩殑鏈嶅姟鍣ㄨ矾寰�
+
+    private String batchId;         // 鎵规ID锛屼竴鑸槸鏃堕棿
+
+    private long userId;            // 鐢ㄦ埛ID
+
+    public long getUserId() {
+        return userId;
+    }
+
+    public void setUserId(long userId) {
+        this.userId = userId;
+    }
+
+
+    public String getSrcVideoId() {
+        return srcVideoId;
+    }
+
+    public void setSrcVideoId(String srcVideoId) {
+        this.srcVideoId = srcVideoId;
+    }
+
+    public String getVideoSrcPath() {
+        return videoSrcPath;
+    }
+
+    public void setVideoSrcPath(String videoSrcPath) {
+        this.videoSrcPath = videoSrcPath;
+    }
+
+    public String getVideoDestPath() {
+        return videoDestPath;
+    }
+
+    public void setVideoDestPath(String videoDestPath) {
+        this.videoDestPath = videoDestPath;
+    }
+
+    public String getBatchId() {
+        return batchId;
+    }
+
+    public void setBatchId(String batchId) {
+        this.batchId = batchId;
+    }
+
+}
diff --git a/recommend-video/src/main/java/com/iplatform/recvideo/VideoLoader.java b/recommend-video/src/main/java/com/iplatform/recvideo/VideoLoader.java
new file mode 100644
index 0000000..62289d1
--- /dev/null
+++ b/recommend-video/src/main/java/com/iplatform/recvideo/VideoLoader.java
@@ -0,0 +1,99 @@
+package com.iplatform.recvideo;
+
+import com.walker.infrastructure.utils.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+
+public abstract class VideoLoader {
+
+    protected final transient Logger logger = LoggerFactory.getLogger(this.getClass());
+
+    public void startup(String videoDataFolder, String batchId, boolean testMode){
+
+    }
+
+    public void destroy(){
+
+    }
+
+    public int execute() throws Exception{
+
+        long nextBatchId = this.acquireNextBatchId();
+
+        if(nextBatchId == 0){
+            logger.debug("鏈壘鍒颁笅涓�涓�(宸叉湁)鏈�澶ф壒娆★紝璇存槑杩樻病鏈夋搷浣滆繃锛岄粯璁よ缃竴涓悎鐞嗗�煎仛鍒濆鏌ヨ");
+            nextBatchId = this.acquireInitBatchId();
+        }
+
+        List<VideoLoadInfo> readyLoadList = null;
+
+        try{
+            readyLoadList = this.acquireLoadVideoFromDatabase(nextBatchId);
+
+        } catch (Exception ex){
+            logger.error("acquireLoadVideoFromDatabase(): " + ex.getMessage(), ex);
+            return -1;
+        }
+
+        if(StringUtils.isEmptyList(readyLoadList)){
+            logger.debug("鏈煡鎵惧埌浠讳綍瑕佽繙绋嬭幏鍙栫殑瑙嗛锛宺eadyLoadList = null");
+            return -1;
+        }
+
+        long savedBatchId = this.copyRemoteVideoFiles(readyLoadList, nextBatchId);
+        logger.info("鎷疯礉涓�鎵硅棰戞枃浠讹紝鍏�:" + readyLoadList.size() + "涓�, 杩斿洖鏈�鏂� savedBatchId = " + savedBatchId);
+        if(savedBatchId <= 0){
+            throw new IllegalArgumentException("鐢熸垚鐨� savedBatchId 鏃犳晥锛屾棤娉曠户缁悗缁噰闆�: " + savedBatchId);
+        }
+
+        try{
+            this.saveDataAndStatus(readyLoadList, savedBatchId);
+            return 1;
+        } catch (Exception ex){
+            logger.error("saveDataAndStatus(),淇濆瓨閲囬泦瑙嗛鏁版嵁鍜岀姸鎬佸け璐�:" + ex.getMessage(), ex);
+            return -1;
+        }
+    }
+
+    /**
+     * 鑾峰彇鏈�澶ф壒娆¢噰闆嗗�硷紝閫氬父涓烘椂闂存埑锛岀郴缁熶細浣跨敤璇ュ�煎幓鏌ユ壘涓氬姟涓秴杩囪鍊肩殑瑙嗛淇℃伅銆�
+     * @return
+     */
+    protected abstract long acquireNextBatchId();
+
+    /**
+     * 濡傛灉绯荤粺涓嶅瓨鍦ㄥ凡閲囬泦璁板綍锛屽垯浼氳嚜鍔ㄥ垵濮嬪寲涓�涓壒娆℃潵閲囬泦锛岃鍊奸�氬父浼氳緝鏃�
+     * @return
+     */
+    protected abstract long acquireInitBatchId();
+
+    /**
+     * 浠庝笟鍔″簱涓紝妫�绱㈡瘮鎵规鍊兼洿澶�(姣旇鏃堕棿鏇存櫄)鐨勮棰戣褰曘��
+     * @param nextBatchId
+     * @return
+     */
+    protected abstract List<VideoLoadInfo> acquireLoadVideoFromDatabase(long nextBatchId);
+
+    /**
+     * 浠庤繙绋嬫湇鍔″櫒鎷疯礉瑙嗛鏂囦欢鍒版湰鏈鸿矾寰勪腑銆�
+     * <pre>
+     *     1) 瑙嗛瑕佹嫹璐濆埌鎸囧畾鏂囦欢鏍圭洰褰曪紝绯荤粺鏈夐厤缃�: data-folder
+     *     2) 鎷疯礉鍚庤棰戞枃浠跺繀椤荤敤鏁版嵁搴揑D閲嶅懡鍚嶄负鏂囦欢鍚嶏紝濡�: 202209123.mp4
+     * </pre>
+     * @param readyLoadList
+     * @param nextBatchId
+     * @return 杩斿洖涓�涓渶鏂版壒娆″彿锛屼篃灏辨槸褰撳墠杩欐壒鏁版嵁鐨勬渶澶ф椂闂存埑銆�
+     */
+    protected abstract long copyRemoteVideoFiles(List<VideoLoadInfo> readyLoadList, long nextBatchId) throws Exception;
+
+    /**
+     * 淇濆瓨瑙嗛鎵规鏁版嵁锛屽苟鍒涘缓鏂扮姸鎬佽褰曪紝璁� <code>VideoSearchScheduler</code> 鑳界户缁畬鎴愯绠楃浉浼煎害鍐欏叆銆�<p></p>
+     * 鍙傝��: {@linkplain com.iplatform.recvideo.scheduler.VideoSearchScheduler}
+     * @param readyLoadList
+     * @param savedBatchId
+     * @return
+     */
+    protected abstract int saveDataAndStatus(List<VideoLoadInfo> readyLoadList, long savedBatchId);
+}
diff --git a/recommend-video/src/main/java/com/iplatform/recvideo/scheduler/VideoLoadScheduler.java b/recommend-video/src/main/java/com/iplatform/recvideo/scheduler/VideoLoadScheduler.java
new file mode 100644
index 0000000..15886e7
--- /dev/null
+++ b/recommend-video/src/main/java/com/iplatform/recvideo/scheduler/VideoLoadScheduler.java
@@ -0,0 +1,17 @@
+package com.iplatform.recvideo.scheduler;
+
+import com.iplatform.recvideo.VideoScheduler;
+import com.walker.store.AbstractStore;
+import com.walker.store.task.GatherTask;
+
+public class VideoLoadScheduler extends VideoScheduler {
+
+    public VideoLoadScheduler(int id, String name){
+        super(id, name);
+    }
+
+    @Override
+    protected GatherTask providerTask(AbstractStore store) {
+        return null;
+    }
+}
diff --git a/recommend-video/src/main/java/com/iplatform/recvideo/service/VideoLoaderServiceImpl.java b/recommend-video/src/main/java/com/iplatform/recvideo/service/VideoLoaderServiceImpl.java
new file mode 100644
index 0000000..88023d5
--- /dev/null
+++ b/recommend-video/src/main/java/com/iplatform/recvideo/service/VideoLoaderServiceImpl.java
@@ -0,0 +1,45 @@
+package com.iplatform.recvideo.service;
+
+import com.iplatform.model.po.Rc_task_status;
+import com.iplatform.model.po.Rc_video_batch;
+import com.iplatform.reccommon.TaskType;
+import com.walker.jdbc.service.BaseServiceImpl;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+import java.util.Map;
+
+@Service
+public class VideoLoaderServiceImpl extends BaseServiceImpl {
+
+    private static final String SQL_NEXT_BATCH = "select max(last_value) next_batch_id from rc_task_status where task_type=? and (status='0' or status='1')";
+
+    /**
+     * 鏌ユ壘褰撳墠璁板綍涓凡鏈夌殑鏈�澶ф壒娆″�笺��
+     * @return
+     * @date 2022-09-26
+     */
+    public long queryNextBatchValue(){
+        Map<String, Object> nextBatchMap = this.get(SQL_NEXT_BATCH, new Object[]{TaskType.INDEX_VIDEO_LOAD});
+        if(nextBatchMap == null){
+            return 0;
+        }
+        if(nextBatchMap.get("next_batch_id") == null){
+            return 0;
+        }
+        return Long.parseLong(nextBatchMap.get("next_batch_id").toString());
+    }
+
+    /**
+     * 淇濆瓨鎵规瑙嗛璁板綍锛屽苟娣诲姞鏂扮殑(鐩镐技搴︽绱�)鐘舵�併��
+     * @param videoBatchList
+     * @param status
+     * @return
+     * @date 2022-09-26
+     */
+    public int execSaveBatchAndStatus(List<Rc_video_batch> videoBatchList, Rc_task_status status){
+        this.save(videoBatchList);
+        this.save(status);
+        return videoBatchList.size();
+    }
+}
diff --git a/recommend-video/src/main/java/com/iplatform/recvideo/support/DefaultVideoLoader.java b/recommend-video/src/main/java/com/iplatform/recvideo/support/DefaultVideoLoader.java
new file mode 100644
index 0000000..ad69420
--- /dev/null
+++ b/recommend-video/src/main/java/com/iplatform/recvideo/support/DefaultVideoLoader.java
@@ -0,0 +1,76 @@
+package com.iplatform.recvideo.support;
+
+import com.iplatform.model.po.Rc_task_status;
+import com.iplatform.model.po.Rc_video_batch;
+import com.iplatform.reccommon.TaskType;
+import com.iplatform.recvideo.VideoLoadInfo;
+import com.iplatform.recvideo.VideoLoader;
+import com.iplatform.recvideo.service.VideoLoaderServiceImpl;
+import com.walker.infrastructure.utils.DateUtils;
+import com.walker.infrastructure.utils.NumberGenerator;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class DefaultVideoLoader extends VideoLoader {
+
+    private VideoLoaderServiceImpl videoLoaderService;
+
+    public void setVideoLoaderService(VideoLoaderServiceImpl videoLoaderService) {
+        this.videoLoaderService = videoLoaderService;
+    }
+
+    @Override
+    protected long acquireNextBatchId() {
+        return this.videoLoaderService.queryNextBatchValue();
+    }
+
+    @Override
+    protected long acquireInitBatchId() {
+        return 0;
+    }
+
+    @Override
+    protected List<VideoLoadInfo> acquireLoadVideoFromDatabase(long nextBatchId) {
+        return null;
+    }
+
+    @Override
+    protected long copyRemoteVideoFiles(List<VideoLoadInfo> readyLoadList, long nextBatchId) throws Exception {
+        return 0;
+    }
+
+    @Override
+    protected int saveDataAndStatus(List<VideoLoadInfo> readyLoadList, long savedBatchId) {
+        List<Rc_video_batch> videoBatchList = this.toVideoBatchList(readyLoadList, savedBatchId);
+        Rc_task_status taskStatus = this.createNewTaskStatus(savedBatchId);
+        return this.videoLoaderService.execSaveBatchAndStatus(videoBatchList, taskStatus);
+    }
+
+    private Rc_task_status createNewTaskStatus(long savedBatchId){
+        Rc_task_status status = new Rc_task_status();
+        status.setCreate_time(Long.parseLong(DateUtils.getDateTimeSecondForShow()));
+        status.setStatus("0");
+        status.setId(NumberGenerator.getLongSequenceNumber());
+        status.setTask_type(TaskType.INDEX_VIDEO_LOAD);
+        status.setLast_value(savedBatchId);
+        status.setName("鏁寸悊鑾峰彇鐭棰戜换鍔�");
+        return status;
+    }
+
+    private List<Rc_video_batch> toVideoBatchList(List<VideoLoadInfo> readyLoadList, long savedBatchId){
+        List<Rc_video_batch> resultList = new ArrayList<>(readyLoadList.size());
+        Rc_video_batch e = null;
+        String batchId = String.valueOf(savedBatchId);
+        for(VideoLoadInfo v : readyLoadList){
+            e = new Rc_video_batch();
+            e.setBatch_id(batchId);
+            e.setSrc_video_id(v.getSrcVideoId());
+            e.setUser_id(v.getUserId());
+            e.setSrc_video_path(v.getVideoDestPath());
+            e.setId(NumberGenerator.getLongSequenceNumber());
+            resultList.add(e);
+        }
+        return resultList;
+    }
+}

--
Gitblit v1.9.1