From e75364c0d66fff66432bce505c136d51034ba408 Mon Sep 17 00:00:00 2001 From: shikeying <shikeying@163.com> Date: 星期五, 28 十月 2022 18:09:28 +0800 Subject: [PATCH] 添加视频推荐api --- recommend-video/src/main/java/com/iplatform/recvideo/service/VideoShowServiceImpl.java | 14 +++ deploy-jar-template/src/main/resources/application-dev.yml | 5 recommend-video/src/main/java/com/iplatform/recvideo/ResponseValue.java | 150 +++++++++++++++++++++++++++++++++++++ deploy-jar-template/src/main/resources/sftp.properties | 2 recommend-video/src/main/java/com/iplatform/recvideo/api/ShowResultApi.java | 61 +++++++++++++++ 5 files changed, 229 insertions(+), 3 deletions(-) diff --git a/deploy-jar-template/src/main/resources/application-dev.yml b/deploy-jar-template/src/main/resources/application-dev.yml index cca4d14..50db6ae 100644 --- a/deploy-jar-template/src/main/resources/application-dev.yml +++ b/deploy-jar-template/src/main/resources/application-dev.yml @@ -75,7 +75,7 @@ # 璋冨害鍣ㄦā鍧楋紝鏄惁鍚敤 scheduler: - enabled: true + enabled: false # 鏁版嵁閲囬泦妯″潡 gather: @@ -102,7 +102,8 @@ test-mode: false #涓氬姟瑙嗛鎵�鍦ㄦ暟鎹簱淇℃伅 - business-datasource-url: 116.198.40.76 +# business-datasource-url: 116.198.40.76 + business-datasource-url: 127.0.0.1 business-datasource-port: 3306 business-datasource-service: train_zs business-datasource-authentication: root diff --git a/deploy-jar-template/src/main/resources/sftp.properties b/deploy-jar-template/src/main/resources/sftp.properties index 073cd90..f5b1af2 100644 --- a/deploy-jar-template/src/main/resources/sftp.properties +++ b/deploy-jar-template/src/main/resources/sftp.properties @@ -1,4 +1,4 @@ -sftp.host=124.70.39.177 +sftp.host=116.198.40.76 sftp.port=22 sftp.user=mysftp sftp.pass=Bjjmy_2020 diff --git a/recommend-video/src/main/java/com/iplatform/recvideo/ResponseValue.java b/recommend-video/src/main/java/com/iplatform/recvideo/ResponseValue.java new file mode 100644 index 0000000..e46d3ed --- /dev/null +++ b/recommend-video/src/main/java/com/iplatform/recvideo/ResponseValue.java @@ -0,0 +1,150 @@ +package com.iplatform.recvideo; + +import java.io.Serializable; +import java.util.List; + +/** + * 鎻忚堪锛氬搷搴攚eb璇锋眰瀵硅薄瀹氫箟銆� + * @author 鏃跺厠鑻� + * @date 2020骞�6鏈�30鏃� 涓婂崍10:42:18 + */ + +public class ResponseValue<T> implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -3530568444640938940L; + + public static final int CODE_SUCCESS = 1; + public static final int CODE_ERROR = 0; + public static final int CODE_RELOGIN = 10; + public static final String TEXT_SUCCESS = "success"; + public static final String TEXT_ERROR = "failed"; + public static final String TEXT_RELOGIN = "瓒呮椂锛岃閲嶆柊鐧诲綍"; + + private boolean state = false; + private int code = CODE_ERROR; + private String msg; + private T data = null; + + // 涓洪�傞厤鑻ヤ緷鍓嶇澧炲姞灞炴�э紝2022-10-10 + private long total = 0; + +// private List<T> datas = null; +// public List<T> getDatas() { +// return datas; +// } +// public void setDatas(List<T> datas) { +// this.datas = datas; +// } + + private ResponseValue(){} + + public boolean isState() { + if(code == CODE_SUCCESS){ + return true; + } + return state; + } + public void setState(boolean state) { + this.state = state; + } + public int getCode() { + return code; + } + public void setCode(int code) { + this.code = code; + } + public String getMsg() { + return this.msg; + } + public void setMsg(String text) { + this.msg = text; + } + public T getData() { + return data; + } + public void setData(T data) { + if(data == null){ + return; + } + if(data instanceof List){ + List<?> list = (List<?>)data; + this.total = list.size(); + } + this.data = data; + } + + public long getTotal() { + return total; + } + public void setTotal(long total) { + this.total = total; + } + + public static <T> ResponseValue<T> success(T data){ + return success(TEXT_SUCCESS, data); + } + + public static <T> ResponseValue<T> success(String text, T data){ + ResponseValue<T> rv = new ResponseValue<T>(); + rv.setState(true); + rv.setCode(CODE_SUCCESS); + rv.setMsg(text); + rv.setData(data); + return rv; + } + + public static ResponseValue<List<?>> success(String text, List<?> data){ + ResponseValue<List<?>> rv = new ResponseValue<List<?>>(); + rv.setState(true); + rv.setCode(CODE_SUCCESS); + rv.setMsg(text); + rv.setData(data); + return rv; + } + + public static ResponseValue<String> success(String text){ + ResponseValue<String> rv = new ResponseValue<String>(); + rv.setState(true); + rv.setCode(CODE_SUCCESS); + rv.setMsg(text); + return rv; + } + + public static ResponseValue<String> success(){ + return success(TEXT_SUCCESS); + } + + public static ResponseValue<String> error(String text){ + ResponseValue<String> rv = new ResponseValue<String>(); + rv.setState(false); + rv.setCode(CODE_ERROR); + rv.setMsg(text); + return rv; + } + + public static ResponseValue<String> error(){ + return error(TEXT_ERROR); + } + + public static ResponseValue<String> error(int code, String text){ + if(code == CODE_SUCCESS){ + throw new IllegalArgumentException("閿欒浠g爜涓嶈兘鏄� '鎴愬姛浠g爜'"); + } + ResponseValue<String> rv = new ResponseValue<String>(); + rv.setState(false); + rv.setCode(code); + rv.setMsg(text); + return rv; + } + + public static ResponseValue<String> relogin(){ + ResponseValue<String> rv = new ResponseValue<String>(); + rv.setState(true); + rv.setCode(CODE_RELOGIN); + rv.setMsg(TEXT_RELOGIN); + return rv; + } +} diff --git a/recommend-video/src/main/java/com/iplatform/recvideo/api/ShowResultApi.java b/recommend-video/src/main/java/com/iplatform/recvideo/api/ShowResultApi.java new file mode 100644 index 0000000..4554988 --- /dev/null +++ b/recommend-video/src/main/java/com/iplatform/recvideo/api/ShowResultApi.java @@ -0,0 +1,61 @@ +package com.iplatform.recvideo.api; + +import com.iplatform.model.po.Rc_video_user; +import com.iplatform.recvideo.ResponseValue; +import com.iplatform.recvideo.service.VideoShowServiceImpl; +import com.walker.infrastructure.utils.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +import java.util.ArrayList; +import java.util.List; + +@RestController +@RequestMapping("/api/video") +public class ShowResultApi { + + private VideoShowServiceImpl videoShowService; + + @Autowired + public ShowResultApi(VideoShowServiceImpl videoShowService){ + this.videoShowService = videoShowService; + } + + @RequestMapping("/rec_list") + @ResponseBody + public ResponseValue showUserRecommendList(String userId){ + if(StringUtils.isEmpty(userId)){ + return ResponseValue.error("鍙傛暟閿欒"); + } + long userIdValue = Long.parseLong(userId); + List<Rc_video_user> data = this.videoShowService.queryRecommendList(userIdValue, 128); + ResponseValue<List<Rc_video_user>> responseValue = ResponseValue.success(data); + return responseValue; + } + + @RequestMapping("/rec_list_test") + @ResponseBody + public ResponseValue testUserRecommendList(String userId){ + if(StringUtils.isEmpty(userId)){ + return ResponseValue.error("鍙傛暟閿欒"); + } + long userIdValue = Long.parseLong(userId); +// List<Rc_video_user> data = this.videoShowService.queryRecommendList(userIdValue, 128); + List<Rc_video_user> data = new ArrayList<>(); + data.add(this.testAcquireVideoUser(userIdValue, "test")); + ResponseValue<List<Rc_video_user>> responseValue = ResponseValue.success(data); + return responseValue; + } + + private Rc_video_user testAcquireVideoUser(long userId, String videoId){ + Rc_video_user user = new Rc_video_user(); + user.setUser_id(userId); + user.setVideo_id(videoId); + user.setCreate_time(20221011164126L); + user.setScore(0.8); + user.setId(System.nanoTime()); + return user; + } +} 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 index 00d84da..c97b140 100644 --- a/recommend-video/src/main/java/com/iplatform/recvideo/service/VideoShowServiceImpl.java +++ b/recommend-video/src/main/java/com/iplatform/recvideo/service/VideoShowServiceImpl.java @@ -2,6 +2,7 @@ import com.iplatform.model.po.Rc_video_batch; import com.iplatform.model.po.Rc_video_t2; +import com.iplatform.model.po.Rc_video_user; import com.walker.db.page.GenericPager; import com.walker.jdbc.service.BaseServiceImpl; import org.springframework.stereotype.Service; @@ -12,6 +13,19 @@ public class VideoShowServiceImpl extends BaseServiceImpl { /** + * 鏌ヨ缁欏畾鐢ㄦ埛鎺ㄨ崘鐨勮棰戦泦鍚� + * @param userId + * @param limit 闄愬埗杩斿洖鍑犳潯 + * @return + */ + public List<Rc_video_user> queryRecommendList(long userId, int limit){ + if(limit <= 0){ + limit = 128; + } + return this.select("select video_id, score from rc_video_user where user_id=? order by score desc limit ?", new Object[]{userId, limit}, new Rc_video_user()); + } + + /** * 杩斿洖閮ㄥ垎鍘熷瑙嗛闆嗗悎锛岀敤浜庨�夋嫨鐩镐技瑙嗛浣跨敤銆� * @return */ -- Gitblit v1.9.1