From 26f5dd8ef80e5671cda8fc0e6c0d0298c4e678ff Mon Sep 17 00:00:00 2001 From: shikeying <shikeying@163.com> Date: 星期二, 27 九月 2022 16:31:33 +0800 Subject: [PATCH] 视频相似度分析3 --- recommend-model-pojo/src/main/java/com/iplatform/model/po/Rc_video_user_mapper.java | 34 + recommend-video/src/main/java/com/iplatform/recvideo/api/DemoDebug.java | 28 + recommend-video/src/main/java/com/iplatform/recvideo/service/VideoShowServiceImpl.java | 39 ++ recommend-model-pojo/src/main/java/com/iplatform/model/po/Rc_video_batch.java | 177 +++++++++++ deploy-jar-template/src/main/resources/application-dev.yml | 11 recommend-video/src/main/java/com/iplatform/recvideo/scheduler/VideoSearchScheduler.java | 12 recommend-video/src/main/resources/templates/video/index.ftl | 54 +++ deploy-jar-template/src/main/resources/application.yml | 21 + recommend-video/src/main/java/com/iplatform/recvideo/SimilarVideoInfo.java | 9 recommend-video/src/main/java/com/iplatform/recvideo/SimilarExecutor.java | 1 recommend-video/doc/table.SQL | 5 recommend-video/src/main/java/com/iplatform/recvideo/SimilarVideoUser.java | 4 deploy-jar-template/pom.xml | 4 recommend-model-pojo/src/main/java/com/iplatform/model/po/Rc_video_batch_mapper.java | 263 +++++++++++++++++ recommend-video/src/main/java/com/iplatform/recvideo/scheduler/VideoSearchTask.java | 2 recommend-video/pom.xml | 6 recommend-common/src/main/java/com/iplatform/reccommon/TaskStatus.java | 44 ++ recommend-video/src/main/java/com/iplatform/recvideo/config/VideoSimilarProperties.java | 11 recommend-model-pojo/src/main/java/com/iplatform/model/po/Rc_video_user.java | 14 recommend-video/src/main/java/com/iplatform/recvideo/controller/VideoResultController.java | 137 +++++++++ 20 files changed, 850 insertions(+), 26 deletions(-) diff --git a/deploy-jar-template/pom.xml b/deploy-jar-template/pom.xml index ce657ad..885289e 100644 --- a/deploy-jar-template/pom.xml +++ b/deploy-jar-template/pom.xml @@ -33,6 +33,10 @@ <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-freemarker</artifactId> + </dependency> </dependencies> diff --git a/deploy-jar-template/src/main/resources/application-dev.yml b/deploy-jar-template/src/main/resources/application-dev.yml index a25556c..4118ba0 100644 --- a/deploy-jar-template/src/main/resources/application-dev.yml +++ b/deploy-jar-template/src/main/resources/application-dev.yml @@ -12,7 +12,7 @@ type: com.walker.jdbc.ds.DefaultDataSource hikari: minimum-idle: 5 - idle-timeout: 5000 + idle-timeout: 600000 pool-name: databasePool_walker connection-timeout: 10000 connection-test-query: select 1 @@ -88,11 +88,14 @@ video: # 瑙嗛閲囬泦瀛樺偍鏍硅矾寰� -# data-folder: D:/dev_tools/ai/ - data-folder: /opt/ai/video/ + data-folder: D:/dev_tools/ai/ +# data-folder: /opt/ai/video/ # 瑙嗛鐩镐技搴I鏈嶅姟URL ai-service: http://121.36.40.27:12345 # 鎺ㄨ崘鐩镐技瑙嗛(绠楁硶)鍓嶅灏戜釜 - top-n: 40 \ No newline at end of file + top-n: 40 + + # 娴嬭瘯妯″紡锛屽鏋滄槸鍒欎粎鐢熸垚鍥哄畾娴嬭瘯鏁版嵁锛屾寮忛儴缃查渶瑕佹敼涓� false + test-mode: true diff --git a/deploy-jar-template/src/main/resources/application.yml b/deploy-jar-template/src/main/resources/application.yml index 3d7808a..82e0996 100644 --- a/deploy-jar-template/src/main/resources/application.yml +++ b/deploy-jar-template/src/main/resources/application.yml @@ -1,3 +1,24 @@ spring: profiles: active: dev + + # 瑙嗛娴嬭瘯鐣岄潰寮曞叆 2022-09-26 + freemarker: + # 妯℃澘鍚庣紑鍚� + suffix: .ftl + # 鏂囨。绫诲瀷 + content-type: text/html + # 椤甸潰缂栫爜 + charset: UTF-8 + # 椤甸潰缂撳瓨 + cache: false + # 妯℃澘璺緞 + template-loader-path: classpath:/templates/ + settings: + # 濡傛灉鍙橀噺涓簄ull,杞寲涓虹┖瀛楃涓� + classic_compatible: true + # 鏁板瓧鏍煎紡涓嶇敤閫楀彿闅斿紑 + number_format: 0.## + datetime_format: yyyy-MM-dd HH:mm:ss + # 鍘绘帀澶氫綑鐨勭┖鏍硷紝闈炲父鏈夌敤 + whitespace_stripping: true diff --git a/recommend-common/src/main/java/com/iplatform/reccommon/TaskStatus.java b/recommend-common/src/main/java/com/iplatform/reccommon/TaskStatus.java new file mode 100644 index 0000000..af31a35 --- /dev/null +++ b/recommend-common/src/main/java/com/iplatform/reccommon/TaskStatus.java @@ -0,0 +1,44 @@ +package com.iplatform.reccommon; + +/** + * 浠诲姟鐘舵�佺被鍨嬪畾涔夈�� + * @author 鏃跺厠鑻� + * @date 2022-09-27 + */ +public enum TaskStatus { + + /** + * 瑙嗛宸茶鍔犺浇(瑙f瀽) + */ + VideoLoad{ + public String getIndex(){ + return INDEX_VIDEO_LOAD; + } + }, + + /** + * 瑙嗛宸叉垚鍔熸绱㈠苟鐢熸垚鐩镐技瑙嗛(瀹屾瘯) + */ + VideoSearch{ + public String getIndex(){ + return INDEX_VIDEO_SEARCH; + } + }; + + public String getIndex(){ + throw new AbstractMethodError(); + } + + public static final TaskStatus getType(String index){ + if(index.equals(INDEX_VIDEO_LOAD)){ + return VideoLoad; + } else if(index.equals(INDEX_VIDEO_SEARCH)){ + return VideoSearch; + } else { + throw new UnsupportedOperationException("TaskStatus绫诲瀷涓嶆敮鎸�: " + index); + } + } + + public static final String INDEX_VIDEO_LOAD = "0"; + public static final String INDEX_VIDEO_SEARCH = "1"; +} diff --git a/recommend-model-pojo/src/main/java/com/iplatform/model/po/Rc_video_batch.java b/recommend-model-pojo/src/main/java/com/iplatform/model/po/Rc_video_batch.java new file mode 100644 index 0000000..2748b2b --- /dev/null +++ b/recommend-model-pojo/src/main/java/com/iplatform/model/po/Rc_video_batch.java @@ -0,0 +1,177 @@ +package com.iplatform.model.po; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.walker.jdbc.BasePo; + +/** + * 琛ㄥ悕:RC_VIDEO_BATCH * + * @author genrator + */ +@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY) +public class Rc_video_batch extends BasePo<Rc_video_batch> { + // 搴忓垪鍖栫増鏈彿 + private static final long serialVersionUID = 1L; + + /** + * 鐢ㄤ簬鍏煎鑰佸啓娉� + */ + @JsonIgnore + public static final Rc_video_batch ROW_MAPPER = new Rc_video_batch(); + + // 涓婚敭 + private Long id = null; + @JsonIgnore + protected boolean isset_id = false; + + // 灞炴�у垪琛� + private String batch_id = null; + @JsonIgnore + protected boolean isset_batch_id = false; + + private Long user_id = null; + @JsonIgnore + protected boolean isset_user_id = false; + + private String src_video_id = null; + @JsonIgnore + protected boolean isset_src_video_id = false; + + private String src_video_path = null; + @JsonIgnore + protected boolean isset_src_video_path = false; + + /** + * 榛樿鏋勯�犲嚱鏁� + */ + public Rc_video_batch() { + } + + /** + * 鏍规嵁涓婚敭鏋勯�犲璞� + */ + public Rc_video_batch(Long id) { + this.setId(id); + } + + /** + * 璁剧疆涓婚敭鍊� + */ + @Override + public void setPkValue(Object value) { + this.setId((Long) value); + } + + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + this.isset_id = true; + } + + @JsonIgnore + public boolean isEmptyId() { + return this.id == null; + } + + public String getBatch_id() { + return this.batch_id; + } + + public void setBatch_id(String batch_id) { + this.batch_id = batch_id; + this.isset_batch_id = true; + } + + @JsonIgnore + public boolean isEmptyBatch_id() { + return this.batch_id == null || this.batch_id.length() == 0; + } + + public Long getUser_id() { + return this.user_id; + } + + public void setUser_id(Long user_id) { + this.user_id = user_id; + this.isset_user_id = true; + } + + @JsonIgnore + public boolean isEmptyUser_id() { + return this.user_id == null; + } + + public String getSrc_video_id() { + return this.src_video_id; + } + + public void setSrc_video_id(String src_video_id) { + this.src_video_id = src_video_id; + this.isset_src_video_id = true; + } + + @JsonIgnore + public boolean isEmptySrc_video_id() { + return this.src_video_id == null || this.src_video_id.length() == 0; + } + + public String getSrc_video_path() { + return this.src_video_path; + } + + public void setSrc_video_path(String src_video_path) { + this.src_video_path = src_video_path; + this.isset_src_video_path = true; + } + + @JsonIgnore + public boolean isEmptySrc_video_path() { + return this.src_video_path == null || this.src_video_path.length() == 0; + } + + /** + * 閲嶅啓 toString() 鏂规硶 + */ + @Override + public String toString() { + return new StringBuilder() + .append("id=").append(this.id) + .append("batch_id=").append(this.batch_id) + .append("user_id=").append(this.user_id) + .append("src_video_id=").append(this.src_video_id) + .append("src_video_path=").append(this.src_video_path) + .toString(); + } + + /** + * 鍏嬮殕 + */ + public Rc_video_batch $clone() { + Rc_video_batch rc_video_batch = new Rc_video_batch(); + + // 鏁版嵁搴撳悕绉� + //rc_video_batch.setDatabaseName_(this.getDatabaseName_()); + + // 涓婚敭 + if (this.isset_id) { + rc_video_batch.setId(this.getId()); + } + // 鏅�氬睘鎬� + if (this.isset_batch_id) { + rc_video_batch.setBatch_id(this.getBatch_id()); + } + if (this.isset_user_id) { + rc_video_batch.setUser_id(this.getUser_id()); + } + if (this.isset_src_video_id) { + rc_video_batch.setSrc_video_id(this.getSrc_video_id()); + } + if (this.isset_src_video_path) { + rc_video_batch.setSrc_video_path(this.getSrc_video_path()); + } + return rc_video_batch; + } +} diff --git a/recommend-model-pojo/src/main/java/com/iplatform/model/po/Rc_video_batch_mapper.java b/recommend-model-pojo/src/main/java/com/iplatform/model/po/Rc_video_batch_mapper.java new file mode 100644 index 0000000..ad019d5 --- /dev/null +++ b/recommend-model-pojo/src/main/java/com/iplatform/model/po/Rc_video_batch_mapper.java @@ -0,0 +1,263 @@ +package com.iplatform.model.po; + +import com.walker.jdbc.BaseMapper; +import com.walker.jdbc.ResultSetUtils; +import com.walker.jdbc.SqlAndParameters; +import com.walker.jdbc.sqlgen.DeleteBuilder; +import com.walker.jdbc.sqlgen.InsertBuilder; +import com.walker.jdbc.sqlgen.SelectBuilder; +import com.walker.jdbc.sqlgen.UpdateBuilder; +import com.walker.jdbc.util.StringUtils; + +import org.springframework.jdbc.core.RowMapper; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Map; + +/** + * 琛ㄥ悕:RC_VIDEO_BATCH * + * @author genrator + */ +public class Rc_video_batch_mapper extends Rc_video_batch implements BaseMapper<Rc_video_batch> { + // 搴忓垪鍖栫増鏈彿 + private static final long serialVersionUID = 1L; + + public static final RowMapper<Rc_video_batch> ROW_MAPPER = new Rc_video_batchRowMapper(); + + // 涓婚敭 + public static final String ID = "id"; + // 鏅�氬睘鎬� + public static final String BATCH_ID = "batch_id"; + public static final String USER_ID = "user_id"; + public static final String SRC_VIDEO_ID = "src_video_id"; + public static final String SRC_VIDEO_PATH = "src_video_path"; + + /** + * 榛樿鏋勯�犲嚱鏁� + */ + public Rc_video_batch_mapper(Rc_video_batch rc_video_batch) { + if (rc_video_batch == null) { + throw new IllegalArgumentException("po鍙傛暟涓嶅厑璁镐负绌猴紒"); + } + //涓婚敭 + if (rc_video_batch.isset_id) { + this.setId(rc_video_batch.getId()); + } + //鏅�氬睘鎬� + if (rc_video_batch.isset_batch_id) { + this.setBatch_id(rc_video_batch.getBatch_id()); + } + if (rc_video_batch.isset_user_id) { + this.setUser_id(rc_video_batch.getUser_id()); + } + if (rc_video_batch.isset_src_video_id) { + this.setSrc_video_id(rc_video_batch.getSrc_video_id()); + } + if (rc_video_batch.isset_src_video_path) { + this.setSrc_video_path(rc_video_batch.getSrc_video_path()); + } + // 鍘绘帀锛�2022-09-07 + // this.setDatabaseName_(rc_video_batch.getDatabaseName_()); + } + + /** + * 鑾峰彇琛ㄥ悕 + */ + @Override + public String getTableName_() { + String tableName = "rc_video_batch"; + /** + if (StringUtils.isNotEmpty(this.getDatabaseName_())) { + return this.getDatabaseName_() + "." + tableName; + } else { + return tableName; + } + */ + return tableName; + } + + /** + * 鑾峰彇涓婚敭鍚嶇О + */ + @Override + public String getPkName_() { + return ID; + } + + /** + * 鑾峰彇涓婚敭鍊� + */ + @Override + public Object getPkValue_() { + return this.getId(); + } + + /** + * 鑾峰彇鎻掑叆璇彞鍜屽弬鏁� + */ + @Override + public SqlAndParameters<Map<String, Object>> getInsertSql_() { + InsertBuilder ib = new InsertBuilder(this.getTableName_()); + ib.set(ID, this.getId()); + ib.set(BATCH_ID, this.getBatch_id(), this.isset_batch_id); + ib.set(USER_ID, this.getUser_id(), this.isset_user_id); + ib.set(SRC_VIDEO_ID, this.getSrc_video_id(), this.isset_src_video_id); + ib.set(SRC_VIDEO_PATH, this.getSrc_video_path(), this.isset_src_video_path); + return ib.genMapSql(); + } + + /** + * 鑾峰彇鏇存柊璇彞鍜屽弬鏁� + */ + @Override + public SqlAndParameters<Map<String, Object>> getUpdateSql_() { + UpdateBuilder ub = new UpdateBuilder(this.getTableName_()); + ub.set(BATCH_ID, this.getBatch_id(), this.isset_batch_id); + ub.set(USER_ID, this.getUser_id(), this.isset_user_id); + ub.set(SRC_VIDEO_ID, this.getSrc_video_id(), this.isset_src_video_id); + ub.set(SRC_VIDEO_PATH, this.getSrc_video_path(), this.isset_src_video_path); + ub.where(this.getPkName_(), this.getPkValue_()); + return ub.genMapSql(); + } + + /** + * 鑾峰彇鏇存柊璇彞鍜屽弬鏁� + */ + @Override + public SqlAndParameters<Map<String, Object>> getUpdateSql_(String where, Map<String, Object> parameters) { + UpdateBuilder ub = new UpdateBuilder(this.getTableName_()); + ub.set(BATCH_ID, this.getBatch_id(), this.isset_batch_id); + ub.set(USER_ID, this.getUser_id(), this.isset_user_id); + ub.set(SRC_VIDEO_ID, this.getSrc_video_id(), this.isset_src_video_id); + ub.set(SRC_VIDEO_PATH, this.getSrc_video_path(), this.isset_src_video_path); + + return ub.genMapSql(where, parameters); + } + + /** + * 鑾峰彇鏇存柊璇彞鍜屽弬鏁� + */ + @Override + public SqlAndParameters<Object[]> getUpdateSql_(String where, Object[] parameters) { + UpdateBuilder ub = new UpdateBuilder(this.getTableName_()); + ub.set(BATCH_ID, this.getBatch_id(), this.isset_batch_id); + ub.set(USER_ID, this.getUser_id(), this.isset_user_id); + ub.set(SRC_VIDEO_ID, this.getSrc_video_id(), this.isset_src_video_id); + ub.set(SRC_VIDEO_PATH, this.getSrc_video_path(), this.isset_src_video_path); + + return ub.genArraySql(where, parameters); + } + + /** + * 鑾峰彇鍒犻櫎璇彞鍜屽弬鏁� + */ + @Override + public SqlAndParameters<Map<String, Object>> getDeleteSql_() { + DeleteBuilder db = new DeleteBuilder(this.getTableName_()); + db.where(this.getPkName_(), this.getPkValue_()); + return db.genMapSql(); + } + + /** + * 鑾峰彇鍒犻櫎璇彞鍜屽弬鏁� + */ + @Override + public SqlAndParameters<Map<String, Object>> getDeleteSql_(String where, Map<String, Object> parameters) { + DeleteBuilder db = new DeleteBuilder(this.getTableName_()); + return db.genMapSql(where, parameters); + } + + /** + * 鑾峰彇鍒犻櫎璇彞鍜屽弬鏁� + */ + @Override + public SqlAndParameters<Object[]> getDeleteSql_(String where, Object[] parameters) { + DeleteBuilder db = new DeleteBuilder(this.getTableName_()); + return db.genArraySql(where, parameters); + } + + /** + * 鑾峰彇鍗曡鏌ヨ璇彞鍜屽弬鏁� + */ + @Override + public SqlAndParameters<Map<String, Object>> getSingleSql_() { + SelectBuilder sb = new SelectBuilder(this.getTableName_()); + sb.where(this.getPkName_(), this.getPkValue_()); + return sb.genMapSql(); + } + + + /** + * 鑾峰彇鏌ヨ璇彞鍜屽弬鏁� + */ + @Override + public SqlAndParameters<Map<String, Object>> getSelectSql_(String where, Map<String, Object> parameters) { + return new SqlAndParameters<>("select id, batch_id, user_id, src_video_id, src_video_path from " + this.getTableName_() + " " + where, parameters); + } + + /** + * 鑾峰彇鏌ヨ璇彞鍜屽弬鏁� + */ + @Override + public SqlAndParameters<Object[]> getSelectSql_(String where, Object[] parameters) { + return new SqlAndParameters<>("select id, batch_id, user_id, src_video_id, src_video_path from " + this.getTableName_() + " " + where, parameters); + } + + /** + * 灏唕esultset鐨勪竴琛岃浆鍖栦负po + */ + @Override + public Rc_video_batch mapRow(ResultSet rs, int i) throws SQLException { + return ROW_MAPPER.mapRow(rs, i); + } + + /** + * 鍏嬮殕 + */ + public Rc_video_batch toRc_video_batch() { + return super.$clone(); + } +} + +/** + * rc_video_batch RowMapper + * + * @author genrator + */ +class Rc_video_batchRowMapper implements RowMapper<Rc_video_batch> { + + @Override + public Rc_video_batch mapRow(ResultSet rs, int i) throws SQLException { + ResultSetUtils resultSetUtils = new ResultSetUtils(); + Rc_video_batch rc_video_batch = new Rc_video_batch(); + Integer columnIndex; + //涓婚敭 + columnIndex = resultSetUtils.findColumn(rs, Rc_video_batch_mapper.ID); + if (columnIndex > 0) { + rc_video_batch.setId(rs.getLong(columnIndex)); + } + //鏅�氬睘鎬� + columnIndex = resultSetUtils.findColumn(rs, Rc_video_batch_mapper.BATCH_ID); + if (columnIndex > 0) { + rc_video_batch.setBatch_id(rs.getString(columnIndex)); + } + columnIndex = resultSetUtils.findColumn(rs, Rc_video_batch_mapper.USER_ID); + if (columnIndex > 0) { + if (rs.getBigDecimal(columnIndex) == null) { + rc_video_batch.setUser_id(null); + } else { + rc_video_batch.setUser_id(rs.getLong(columnIndex)); + } + } + columnIndex = resultSetUtils.findColumn(rs, Rc_video_batch_mapper.SRC_VIDEO_ID); + if (columnIndex > 0) { + rc_video_batch.setSrc_video_id(rs.getString(columnIndex)); + } + columnIndex = resultSetUtils.findColumn(rs, Rc_video_batch_mapper.SRC_VIDEO_PATH); + if (columnIndex > 0) { + rc_video_batch.setSrc_video_path(rs.getString(columnIndex)); + } + return rc_video_batch; + } +} diff --git a/recommend-model-pojo/src/main/java/com/iplatform/model/po/Rc_video_user.java b/recommend-model-pojo/src/main/java/com/iplatform/model/po/Rc_video_user.java index 1f37b0e..ecb778e 100644 --- a/recommend-model-pojo/src/main/java/com/iplatform/model/po/Rc_video_user.java +++ b/recommend-model-pojo/src/main/java/com/iplatform/model/po/Rc_video_user.java @@ -20,7 +20,7 @@ public static final Rc_video_user ROW_MAPPER = new Rc_video_user(); // 涓婚敭 - private Long id; + private Long id = null; @JsonIgnore protected boolean isset_id = false; @@ -62,9 +62,11 @@ this.setId((Long) value); } - public Long getId(){return this.id;} + public Long getId() { + return this.id; + } - public void setId(Long id){ + public void setId(Long id) { this.id = id; this.isset_id = true; } @@ -136,6 +138,7 @@ @Override public String toString() { return new StringBuilder() + .append("id=").append(this.id) .append("user_id=").append(this.user_id) .append("video_id=").append(this.video_id) .append("score=").append(this.score) @@ -153,10 +156,13 @@ //rc_video_user.setDatabaseName_(this.getDatabaseName_()); // 涓婚敭 + if (this.isset_id) { + rc_video_user.setId(this.getId()); + } + // 鏅�氬睘鎬� if (this.isset_user_id) { rc_video_user.setUser_id(this.getUser_id()); } - // 鏅�氬睘鎬� if (this.isset_video_id) { rc_video_user.setVideo_id(this.getVideo_id()); } diff --git a/recommend-model-pojo/src/main/java/com/iplatform/model/po/Rc_video_user_mapper.java b/recommend-model-pojo/src/main/java/com/iplatform/model/po/Rc_video_user_mapper.java index eb950b3..aa0112d 100644 --- a/recommend-model-pojo/src/main/java/com/iplatform/model/po/Rc_video_user_mapper.java +++ b/recommend-model-pojo/src/main/java/com/iplatform/model/po/Rc_video_user_mapper.java @@ -26,8 +26,9 @@ public static final RowMapper<Rc_video_user> ROW_MAPPER = new Rc_video_userRowMapper(); // 涓婚敭 - public static final String USER_ID = "user_id"; + public static final String ID = "id"; // 鏅�氬睘鎬� + public static final String USER_ID = "user_id"; public static final String VIDEO_ID = "video_id"; public static final String SCORE = "score"; public static final String CREATE_TIME = "create_time"; @@ -40,10 +41,13 @@ throw new IllegalArgumentException("po鍙傛暟涓嶅厑璁镐负绌猴紒"); } //涓婚敭 + if (rc_video_user.isset_id) { + this.setId(rc_video_user.getId()); + } + //鏅�氬睘鎬� if (rc_video_user.isset_user_id) { this.setUser_id(rc_video_user.getUser_id()); } - //鏅�氬睘鎬� if (rc_video_user.isset_video_id) { this.setVideo_id(rc_video_user.getVideo_id()); } @@ -78,7 +82,7 @@ */ @Override public String getPkName_() { - return USER_ID; + return ID; } /** @@ -86,7 +90,7 @@ */ @Override public Object getPkValue_() { - return this.getUser_id(); + return this.getId(); } /** @@ -95,7 +99,8 @@ @Override public SqlAndParameters<Map<String, Object>> getInsertSql_() { InsertBuilder ib = new InsertBuilder(this.getTableName_()); - ib.set(USER_ID, this.getUser_id()); + ib.set(ID, this.getId()); + ib.set(USER_ID, this.getUser_id(), this.isset_user_id); ib.set(VIDEO_ID, this.getVideo_id(), this.isset_video_id); ib.set(SCORE, this.getScore(), this.isset_score); ib.set(CREATE_TIME, this.getCreate_time(), this.isset_create_time); @@ -108,6 +113,7 @@ @Override public SqlAndParameters<Map<String, Object>> getUpdateSql_() { UpdateBuilder ub = new UpdateBuilder(this.getTableName_()); + ub.set(USER_ID, this.getUser_id(), this.isset_user_id); ub.set(VIDEO_ID, this.getVideo_id(), this.isset_video_id); ub.set(SCORE, this.getScore(), this.isset_score); ub.set(CREATE_TIME, this.getCreate_time(), this.isset_create_time); @@ -121,6 +127,7 @@ @Override public SqlAndParameters<Map<String, Object>> getUpdateSql_(String where, Map<String, Object> parameters) { UpdateBuilder ub = new UpdateBuilder(this.getTableName_()); + ub.set(USER_ID, this.getUser_id(), this.isset_user_id); ub.set(VIDEO_ID, this.getVideo_id(), this.isset_video_id); ub.set(SCORE, this.getScore(), this.isset_score); ub.set(CREATE_TIME, this.getCreate_time(), this.isset_create_time); @@ -134,6 +141,7 @@ @Override public SqlAndParameters<Object[]> getUpdateSql_(String where, Object[] parameters) { UpdateBuilder ub = new UpdateBuilder(this.getTableName_()); + ub.set(USER_ID, this.getUser_id(), this.isset_user_id); ub.set(VIDEO_ID, this.getVideo_id(), this.isset_video_id); ub.set(SCORE, this.getScore(), this.isset_score); ub.set(CREATE_TIME, this.getCreate_time(), this.isset_create_time); @@ -185,7 +193,7 @@ */ @Override public SqlAndParameters<Map<String, Object>> getSelectSql_(String where, Map<String, Object> parameters) { - return new SqlAndParameters<>("select user_id, video_id, score, create_time from " + this.getTableName_() + " " + where, parameters); + return new SqlAndParameters<>("select id, user_id, video_id, score, create_time from " + this.getTableName_() + " " + where, parameters); } /** @@ -193,7 +201,7 @@ */ @Override public SqlAndParameters<Object[]> getSelectSql_(String where, Object[] parameters) { - return new SqlAndParameters<>("select user_id, video_id, score, create_time from " + this.getTableName_() + " " + where, parameters); + return new SqlAndParameters<>("select id, user_id, video_id, score, create_time from " + this.getTableName_() + " " + where, parameters); } /** @@ -225,11 +233,19 @@ Rc_video_user rc_video_user = new Rc_video_user(); Integer columnIndex; //涓婚敭 - columnIndex = resultSetUtils.findColumn(rs, Rc_video_user_mapper.USER_ID); + columnIndex = resultSetUtils.findColumn(rs, Rc_video_user_mapper.ID); if (columnIndex > 0) { - rc_video_user.setUser_id(rs.getLong(columnIndex)); + rc_video_user.setId(rs.getLong(columnIndex)); } //鏅�氬睘鎬� + columnIndex = resultSetUtils.findColumn(rs, Rc_video_user_mapper.USER_ID); + if (columnIndex > 0) { + if (rs.getBigDecimal(columnIndex) == null) { + rc_video_user.setUser_id(null); + } else { + rc_video_user.setUser_id(rs.getLong(columnIndex)); + } + } columnIndex = resultSetUtils.findColumn(rs, Rc_video_user_mapper.VIDEO_ID); if (columnIndex > 0) { rc_video_user.setVideo_id(rs.getString(columnIndex)); diff --git a/recommend-video/doc/table.SQL b/recommend-video/doc/table.SQL index 5edc014..4506ab4 100644 --- a/recommend-video/doc/table.SQL +++ b/recommend-video/doc/table.SQL @@ -14,4 +14,7 @@ -- ADD INDEX inx_vb_vid (src_video_id) USING BTREE ; ALTER TABLE rc_video_batch - ADD INDEX inx_vb_bid (batch_id) USING BTREE ; \ No newline at end of file + 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 diff --git a/recommend-video/pom.xml b/recommend-video/pom.xml index 6360c92..330a1f3 100644 --- a/recommend-video/pom.xml +++ b/recommend-video/pom.xml @@ -40,6 +40,12 @@ <artifactId>spring-boot-starter-web</artifactId> <scope>provided</scope> </dependency> + <!-- FreeMarker鍋氭祴璇曢〉闈紝2022/09/23 --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-freemarker</artifactId> + <scope>provided</scope> + </dependency> </dependencies> diff --git a/recommend-video/src/main/java/com/iplatform/recvideo/SimilarExecutor.java b/recommend-video/src/main/java/com/iplatform/recvideo/SimilarExecutor.java index 51b6220..3e94ddd 100644 --- a/recommend-video/src/main/java/com/iplatform/recvideo/SimilarExecutor.java +++ b/recommend-video/src/main/java/com/iplatform/recvideo/SimilarExecutor.java @@ -8,7 +8,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; import java.util.ArrayList; import java.util.List; diff --git a/recommend-video/src/main/java/com/iplatform/recvideo/SimilarVideoInfo.java b/recommend-video/src/main/java/com/iplatform/recvideo/SimilarVideoInfo.java index f98a3c3..a532b3c 100644 --- a/recommend-video/src/main/java/com/iplatform/recvideo/SimilarVideoInfo.java +++ b/recommend-video/src/main/java/com/iplatform/recvideo/SimilarVideoInfo.java @@ -1,6 +1,6 @@ package com.iplatform.recvideo; -import java.text.DecimalFormat; +import com.walker.infrastructure.utils.NumberFormatUtils; /** * 鐩镐技瑙嗛瀵硅薄瀹氫箟銆� @@ -18,7 +18,7 @@ private double score = 0; - private DecimalFormat df = new DecimalFormat("#.00"); +// private DecimalFormat df = new DecimalFormat("#.00"); public String getId() { return id; @@ -45,8 +45,9 @@ return 0; } double s = (this.count)/100.0; - String score = df.format(s); - this.score = Double.parseDouble(score); +// String score = df.format(s); +// this.score = Double.parseDouble(score); + this.score = NumberFormatUtils.scaleAccuracy2(s); return this.score; } diff --git a/recommend-video/src/main/java/com/iplatform/recvideo/SimilarVideoUser.java b/recommend-video/src/main/java/com/iplatform/recvideo/SimilarVideoUser.java index 0d77dbd..aadbe0c 100644 --- a/recommend-video/src/main/java/com/iplatform/recvideo/SimilarVideoUser.java +++ b/recommend-video/src/main/java/com/iplatform/recvideo/SimilarVideoUser.java @@ -1,5 +1,7 @@ package com.iplatform.recvideo; +import com.walker.infrastructure.utils.NumberFormatUtils; + public class SimilarVideoUser implements Comparable<SimilarVideoUser>{ private long userId; @@ -32,7 +34,7 @@ } public double getScore() { - return score; + return NumberFormatUtils.scaleAccuracy2(this.score); } @Override diff --git a/recommend-video/src/main/java/com/iplatform/recvideo/api/DemoDebug.java b/recommend-video/src/main/java/com/iplatform/recvideo/api/DemoDebug.java index 4c36014..307f478 100644 --- a/recommend-video/src/main/java/com/iplatform/recvideo/api/DemoDebug.java +++ b/recommend-video/src/main/java/com/iplatform/recvideo/api/DemoDebug.java @@ -1,12 +1,19 @@ package com.iplatform.recvideo.api; +import com.iplatform.core.BeanContextAware; import com.iplatform.recvideo.config.VideoSimilarProperties; +import com.iplatform.recvideo.scheduler.VideoSearchScheduler; import com.iplatform.recvideo.service.VideoExecutorServiceImpl; import com.iplatform.recvideo.support.DefaultSimilarExecutor; +import com.walker.scheduler.ScheduleEngine; +import com.walker.scheduler.util.OptionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; + +import java.util.ArrayList; +import java.util.List; @RestController @RequestMapping("/debug/video") @@ -15,6 +22,8 @@ private RestTemplate restTemplate; private VideoSimilarProperties videoSimilarProperties; private VideoExecutorServiceImpl videoExecutorService; + + private VideoSearchScheduler videoSearchScheduler = null; private DefaultSimilarExecutor similarExecutor = null; @@ -27,6 +36,25 @@ this.videoExecutorService = videoExecutorService; } + @RequestMapping("/start_scheduler_1") + public String testStartVideoSearchScheduler(){ + if(this.videoSearchScheduler != null){ + this.videoSearchScheduler.stop(); + this.videoSearchScheduler = null; + } + + List<Integer[]> timeRanges = new ArrayList<Integer[]>(1); + timeRanges.add(new Integer[]{10,11}); + timeRanges.add(new Integer[]{12,12}); + + this.videoSearchScheduler = new VideoSearchScheduler(100, "瑙嗛鐩镐技搴﹀垎鏋愯皟搴︿换鍔�"); + this.videoSearchScheduler.setOption(OptionUtils.combineEveryDayHourRange(timeRanges)); + this.videoSearchScheduler.setScheduleEngine(BeanContextAware.getBeanByType(ScheduleEngine.class)); + this.videoSearchScheduler.setMaxFailedTimes(10); + this.videoSearchScheduler.start(); + return this.videoSearchScheduler.getName() + " 鍚姩"; + } + /** * 璇ユ祴璇曠敤浜庢ā鎷熻皟搴︿换鍔★紝姣忔璋冪敤涓�娆℃墽琛屽櫒鏂规硶锛屾壒閲忓鐞嗕竴寮犲浘鐗囨暟鎹��<p></p> * 鏈�缁堝畬鎴愪竴鎵瑰涓棰戠殑鐩镐技搴︽绱㈠苟鍐欏叆鏁版嵁搴撲腑銆� diff --git a/recommend-video/src/main/java/com/iplatform/recvideo/config/VideoSimilarProperties.java b/recommend-video/src/main/java/com/iplatform/recvideo/config/VideoSimilarProperties.java index 71c79db..2bb99e4 100644 --- a/recommend-video/src/main/java/com/iplatform/recvideo/config/VideoSimilarProperties.java +++ b/recommend-video/src/main/java/com/iplatform/recvideo/config/VideoSimilarProperties.java @@ -11,6 +11,17 @@ private String aiService; + private boolean testMode = false; + + public boolean isTestMode() { + return testMode; + } + + public void setTestMode(boolean testMode) { + this.testMode = testMode; + } + + public String getAiService() { return aiService; } diff --git a/recommend-video/src/main/java/com/iplatform/recvideo/controller/VideoResultController.java b/recommend-video/src/main/java/com/iplatform/recvideo/controller/VideoResultController.java new file mode 100644 index 0000000..c91a5c8 --- /dev/null +++ b/recommend-video/src/main/java/com/iplatform/recvideo/controller/VideoResultController.java @@ -0,0 +1,137 @@ +package com.iplatform.recvideo.controller; + +import com.iplatform.model.po.Rc_video_batch; +import com.iplatform.model.po.Rc_video_t2; +import com.iplatform.recvideo.config.VideoSimilarProperties; +import com.iplatform.recvideo.service.VideoShowServiceImpl; +import com.walker.db.page.GenericPager; +import com.walker.infrastructure.utils.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.servlet.http.HttpServletResponse; +import java.io.File; +import java.io.OutputStream; +import java.io.RandomAccessFile; +import java.nio.charset.StandardCharsets; +import java.util.List; + +@Controller +@RequestMapping("/video_ui") +public class VideoResultController { + + private VideoShowServiceImpl videoShowService; + private VideoSimilarProperties videoSimilarProperties; + + @Autowired + public VideoResultController(VideoShowServiceImpl videoShowService, VideoSimilarProperties videoSimilarProperties){ + this.videoShowService = videoShowService; + this.videoSimilarProperties = videoSimilarProperties; + } + + @GetMapping("/index") + public String index(Model model, String id) { + + GenericPager<Rc_video_batch> pager = this.videoShowService.queryPageVideoBatchList(); + List<Rc_video_batch> data = pager.getDatas(); + model.addAttribute("src_list", data); + model.addAttribute("video_folder", this.videoSimilarProperties.getDataFolder()); + + if(StringUtils.isNotEmpty(id)){ + List<Rc_video_t2> list = this.videoShowService.querySimilarVideoList(id); + model.addAttribute("similar_list", list); + model.addAttribute("select_id", id); + } else { + model.addAttribute("select_id", null); + } + return "video/index"; + } + + /** + * 鏈湴瑙嗛杞棰戞祦娴� + * @param response + * @return + */ + @RequestMapping("/get_video") + @ResponseBody + public void getVideo( +// HttpServletRequest request, + HttpServletResponse response, String id) { + if(StringUtils.isEmpty(id)){ + System.out.println("瑙嗛ID鏈彁渚�"); + return; + } + //瑙嗛璧勬簮瀛樺偍淇℃伅 + response.reset(); + //鑾峰彇浠庨偅涓瓧鑺傚紑濮嬭鍙栨枃浠� +// String rangeString = request.getHeader("Range"); + String rangeString = null; + + Rc_video_batch videoInfo = this.videoShowService.queryOneVideoInfo(id); + if(videoInfo == null){ + System.out.println("Rc_video_batch鏈煡鎵惧埌瀵硅薄: " + id); + return; + } + String videoPath = videoInfo.getSrc_video_path(); + if(this.videoSimilarProperties.isTestMode()){ + // 娴嬭瘯妯″紡锛岄渶瑕佹浛鎹㈡枃浠舵牴璺緞涓烘湰鏈簑indows璺緞 + StringBuilder windowPath = new StringBuilder(this.videoSimilarProperties.getDataFolder()); + windowPath.append(videoInfo.getBatch_id()); + windowPath.append("/").append(id).append(".mp4"); + videoPath = windowPath.toString(); + } + + try { + //鑾峰彇鍝嶅簲鐨勮緭鍑烘祦 + OutputStream outputStream = response.getOutputStream(); +// File file = new File("c:\\video.mp4"); + File file = new File(videoPath); + if(file.exists()){ + RandomAccessFile targetFile = new RandomAccessFile(file, "r"); + long fileLength = targetFile.length(); + //鎾斁 + if(rangeString != null){ + long range = Long.valueOf(rangeString.substring(rangeString.indexOf("=") + 1, rangeString.indexOf("-"))); + //璁剧疆鍐呭绫诲瀷 + response.setHeader("Content-Type", "video/mp4"); + //璁剧疆姝ゆ鐩稿簲杩斿洖鐨勬暟鎹暱搴� + response.setHeader("Content-Length", String.valueOf(fileLength - range)); + //璁剧疆姝ゆ鐩稿簲杩斿洖鐨勬暟鎹寖鍥� + response.setHeader("Content-Range", "bytes "+range+"-"+(fileLength-1)+"/"+fileLength); + //杩斿洖鐮侀渶瑕佷负206锛岃�屼笉鏄�200 + response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT); + //璁惧畾鏂囦欢璇诲彇寮�濮嬩綅缃紙浠ュ瓧鑺備负鍗曚綅锛� +// targetFile.seek(range); + }else {//涓嬭浇 + //璁剧疆鍝嶅簲澶达紝鎶婃枃浠跺悕瀛楄缃ソ + response.setHeader("Content-Disposition", "attachment; filename=video.mp4" ); + //璁剧疆鏂囦欢闀垮害 + response.setHeader("Content-Length", String.valueOf(fileLength)); + //瑙e喅缂栫爜闂 + response.setHeader("Content-Type","application/octet-stream"); + } + + byte[] cache = new byte[1024 * 300]; + int flag; + while ((flag = targetFile.read(cache))!=-1){ + outputStream.write(cache, 0, flag); + } + }else { + String message = "file: not exists"; + //瑙e喅缂栫爜闂 + response.setHeader("Content-Type","application/json"); + outputStream.write(message.getBytes(StandardCharsets.UTF_8)); + } + + outputStream.flush(); + outputStream.close(); + + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/recommend-video/src/main/java/com/iplatform/recvideo/scheduler/VideoSearchScheduler.java b/recommend-video/src/main/java/com/iplatform/recvideo/scheduler/VideoSearchScheduler.java index 27a5a78..9467a33 100644 --- a/recommend-video/src/main/java/com/iplatform/recvideo/scheduler/VideoSearchScheduler.java +++ b/recommend-video/src/main/java/com/iplatform/recvideo/scheduler/VideoSearchScheduler.java @@ -49,11 +49,21 @@ } logger.debug("寮�濮嬪惎鍔ㄦ壒娆℃煡璇�:" + this.currentVideoSearchMeta.getBatchId()); } + if(this.currentVideoSearchMeta == null){ + // 璇存槑涓婃宸茬粡鍒涘缓 videoSearchTask 浠诲姟锛屼絾娌℃湁杩斿洖鏈夋晥浠诲姟璁板綍 + return null; + } // this.videoSearchTask.checkExecutor(this.currentVideoSearchMeta); // - int result = this.videoSearchTask.executeOneSearch(); + int result = 0; + try{ + result = this.videoSearchTask.executeOneSearch(); + } catch (Exception ex){ + logger.error("executeOneSearch(): 鎵ц寮傚父:" + ex.getMessage(), ex); + result = -1; + } if(result == 0){ return SUCCESS; diff --git a/recommend-video/src/main/java/com/iplatform/recvideo/scheduler/VideoSearchTask.java b/recommend-video/src/main/java/com/iplatform/recvideo/scheduler/VideoSearchTask.java index 2e89235..b9c5cc8 100644 --- a/recommend-video/src/main/java/com/iplatform/recvideo/scheduler/VideoSearchTask.java +++ b/recommend-video/src/main/java/com/iplatform/recvideo/scheduler/VideoSearchTask.java @@ -76,7 +76,7 @@ defaultSimilarExecutor.setVideoExecutorService(BeanContextAware.getBeanByType(VideoExecutorServiceImpl.class)); defaultSimilarExecutor.setRestTemplate(BeanContextAware.getBeanByType(RestTemplate.class)); defaultSimilarExecutor.startup(this.videoSimilarProperties.getDataFolder() - , videoSearchMeta.getBatchId(), this.videoSimilarProperties.getTopN(), true); + , videoSearchMeta.getBatchId(), this.videoSimilarProperties.getTopN(), this.videoSimilarProperties.isTestMode()); this.similarExecutor = defaultSimilarExecutor; } diff --git a/recommend-video/src/main/java/com/iplatform/recvideo/service/VideoShowServiceImpl.java b/recommend-video/src/main/java/com/iplatform/recvideo/service/VideoShowServiceImpl.java new file mode 100644 index 0000000..00d84da --- /dev/null +++ b/recommend-video/src/main/java/com/iplatform/recvideo/service/VideoShowServiceImpl.java @@ -0,0 +1,39 @@ +package com.iplatform.recvideo.service; + +import com.iplatform.model.po.Rc_video_batch; +import com.iplatform.model.po.Rc_video_t2; +import com.walker.db.page.GenericPager; +import com.walker.jdbc.service.BaseServiceImpl; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class VideoShowServiceImpl extends BaseServiceImpl { + + /** + * 杩斿洖閮ㄥ垎鍘熷瑙嗛闆嗗悎锛岀敤浜庨�夋嫨鐩镐技瑙嗛浣跨敤銆� + * @return + */ + public GenericPager<Rc_video_batch> queryPageVideoBatchList(){ + return this.selectSplit("select * from rc_video_batch", new Object[]{}, 1, 128, new Rc_video_batch()); + } + + /** + * 杩斿洖缁欏畾鍘熷瑙嗛锛岀浉浼艰棰戦泦鍚堛�� + * @param srcVideoId + * @return + */ + public List<Rc_video_t2> querySimilarVideoList(String srcVideoId){ + return this.select(new Rc_video_t2(), "where src_video_id=?", new Object[]{srcVideoId}); + } + + /** + * 鏍规嵁鍘熷瑙嗛ID锛屾煡璇㈣瑙嗛淇℃伅銆� + * @param srcVideoId + * @return + */ + public Rc_video_batch queryOneVideoInfo(String srcVideoId){ + return this.get(new Rc_video_batch(), "where src_video_id=?", new Object[]{srcVideoId}); + } +} diff --git a/recommend-video/src/main/resources/templates/video/index.ftl b/recommend-video/src/main/resources/templates/video/index.ftl new file mode 100644 index 0000000..106b63c --- /dev/null +++ b/recommend-video/src/main/resources/templates/video/index.ftl @@ -0,0 +1,54 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="UTF-8"> + <title>Title</title> +</head> +<body> +<p> </p> + +<table style="width: 90%;"> + <tr> + <td style="width: 20%; vertical-align: top;"><h4>閫夋嫨婧愯棰戯細${select_id}<br></h4></td> + <td style="width:10%;"></td> + <td style="vertical-align: top;"><h4>鐩镐技瑙嗛闆嗗悎</h4></td> + </tr> +</table> + +<table style="width: 90%;"> + <tr> + <td style="width: 20%; vertical-align: top;"> + <table style="width: 90%;"> + <#list src_list as obj> + <tr> + <td> + <video id="my-video" class="video-js vjs-big-play-centered" controls="controls" poster="" width="320" height="180"> + <source src="/video_ui/get_video?id=${obj.src_video_id}" type='video/mp4'> + </video> + <br> ${obj.src_video_id} <a href="/video_ui/index?id=${obj.src_video_id}">妫�绱㈢浉浼�</a> + <p> </p> + </td> + </tr> + </#list> + </table> + </td> + <td style="width:10%;"></td> + <td style="vertical-align: top;"> + <table style="width: 90%;"> + <#list similar_list as sim> + <tr> + <td> + <video id="my-video" class="video-js vjs-big-play-centered" controls="controls" poster="" width="320" height="180"> + <source src="/video_ui/get_video?id=${sim.sim_video_id}" type='video/mp4'> + </video> + <br> ${sim.sim_video_id} 寰楀垎: ${sim.score} + <p> </p> + </td> + </tr> + </#list> + </table> + </td> + </tr> +</table> +</body> +</html> \ No newline at end of file -- Gitblit v1.9.1