|
@@ -4,11 +4,13 @@ import cn.rankin.apiweb.assist.resolver.NeedUser;
|
|
|
import cn.rankin.apiweb.code.ApiWebCode;
|
|
|
import cn.rankin.apiweb.service.event.EventService;
|
|
|
import cn.rankin.apiweb.service.product.ProductService;
|
|
|
+import cn.rankin.apiweb.service.user.UserService;
|
|
|
import cn.rankin.common.utils.api.model.APIResult;
|
|
|
import cn.rankin.data.api.app.vo.DeviceUserVo;
|
|
|
import cn.rankin.data.api.app.vo.RecommendVo;
|
|
|
import cn.rankin.data.api.product.entity.Course;
|
|
|
import cn.rankin.data.api.product.entity.Poster;
|
|
|
+import cn.rankin.data.api.user.entity.UserRecommend;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
@@ -27,6 +29,9 @@ public class RecommendController {
|
|
|
private ProductService productService;
|
|
|
|
|
|
@Autowired
|
|
|
+ private UserService userService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
private EventService eventService;
|
|
|
|
|
|
public static final int RECOMMEND_NUM = 5;
|
|
@@ -40,58 +45,103 @@ public class RecommendController {
|
|
|
List<RecommendVo> result = new ArrayList<>();
|
|
|
|
|
|
//查询浏览历史课程ID,已去重
|
|
|
- List<String> courseIds = eventService.getCoursesFromLogs(user.getUid());
|
|
|
-// log.info("get course ids from logs, courseIds={}", courseIds);
|
|
|
- if(courseIds != null && courseIds.size() > 0){
|
|
|
+ List<String> pids = eventService.getCoursesFromLogs(user.getUid());
|
|
|
+ if(pids != null && pids.size() > 0){
|
|
|
+ log.info("get course ids from logs, courseIds={}", pids);
|
|
|
//如果有浏览历史,提取浏览历史前五展示 (目前推荐位为5)
|
|
|
- courseIds.forEach(courseId -> {
|
|
|
+ pids.forEach(pid -> {
|
|
|
if(result.size() <= RECOMMEND_NUM){
|
|
|
- Course course = productService.getCourse(courseId);
|
|
|
+ Course course = productService.getCourse(pid);
|
|
|
if(course != null){
|
|
|
- RecommendVo vo = new RecommendVo();
|
|
|
+ /*RecommendVo vo = new RecommendVo();
|
|
|
vo.setId(course.getId());
|
|
|
vo.setCode(course.getCode());
|
|
|
vo.setTitle(course.getTitle());
|
|
|
vo.setSubTitle(course.getSubTitle());
|
|
|
vo.setBreadCrumb(course.getBreadCrumb());
|
|
|
- vo.setCoverUrl(course.getCoverUrl());
|
|
|
+ vo.setCoverUrl(course.getCoverUrl());*/
|
|
|
+ RecommendVo vo = courseToRecommendVo(course);
|
|
|
result.add(vo);
|
|
|
+ }else{
|
|
|
+ log.info("not found course by pid, pid={}", pid);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
|
|
|
-
|
|
|
if(result.size() < RECOMMEND_NUM){
|
|
|
- //浏览历史少于五,追加推荐,补足五 (目前推荐位为5)
|
|
|
- String merchantId = user.getMerchantId();
|
|
|
- APIResult<List<RecommendVo>> apiResult = productService.getRecommendCourses(merchantId);
|
|
|
- if(!apiResult.getSuccess()){
|
|
|
- return apiResult;
|
|
|
- }
|
|
|
-
|
|
|
- List<RecommendVo> data = apiResult.getData();
|
|
|
+ //浏览历史少于五,追加用户推荐,补足五 (目前推荐位为5)
|
|
|
+ String uid = user.getUid();
|
|
|
+ List<UserRecommend> userData = userService.getUserRecommendCourses(uid);
|
|
|
+ if(null != userData && userData.size() > 0){
|
|
|
+ log.info("get user recommend course , size={}", userData.size());
|
|
|
+ userData.forEach(userRecommend -> {
|
|
|
+ if(result.size() < RECOMMEND_NUM){
|
|
|
+ Course course = productService.getCourse(userRecommend.getPid());
|
|
|
+ if(course != null){
|
|
|
+ RecommendVo vo = courseToRecommendVo(course);
|
|
|
+ //如果用户浏览课程不包含推荐课程,追加推荐课程 |(此处为避免推荐位课程重复)
|
|
|
+ if(!result.contains(vo)){
|
|
|
+ result.add(vo);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ log.info("not found course by pid, pid={}", userRecommend.getPid());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ //浏览历史少于五,没有用户推荐 追加 渠道推荐,补足五 (目前推荐位为5)
|
|
|
+ String merchantId = user.getMerchantId();
|
|
|
+ APIResult<List<RecommendVo>> apiResult = productService.getRecommendCourses(merchantId);
|
|
|
+ if(!apiResult.getSuccess()){
|
|
|
+ return apiResult;
|
|
|
+ }
|
|
|
|
|
|
- log.info("get recommend course , size={}", data.size());
|
|
|
+ List<RecommendVo> data = apiResult.getData();
|
|
|
+ if(data != null){
|
|
|
+ log.info("get merchant recommend course , size={}", data.size());
|
|
|
+ data.forEach(vo -> {
|
|
|
+ if(result.size() < RECOMMEND_NUM){
|
|
|
+ //如果用户浏览课程不包含推荐课程,追加推荐课程 |(此处为避免推荐位课程重复)
|
|
|
+ if(!result.contains(vo)){
|
|
|
+ result.add(vo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return APIResult.ok(result);
|
|
|
+ }else{
|
|
|
|
|
|
- data.forEach(vo -> {
|
|
|
+ //不存在浏览历史,使用用户推荐
|
|
|
+ String uid = user.getUid();
|
|
|
+ List<UserRecommend> userData = userService.getUserRecommendCourses(uid);
|
|
|
+ if(null != userData && userData.size() > 0){
|
|
|
+ log.info("get user recommend course , size={}", userData.size());
|
|
|
+ userData.forEach(userRecommend -> {
|
|
|
if(result.size() < RECOMMEND_NUM){
|
|
|
- //如果用户浏览课程不包含推荐课程,追加推荐课程 |(此处为避免推荐位课程重复)
|
|
|
- if(!result.contains(vo)){
|
|
|
- result.add(vo);
|
|
|
+ Course course = productService.getCourse(userRecommend.getPid());
|
|
|
+ if(course != null){
|
|
|
+ RecommendVo vo = courseToRecommendVo(course);
|
|
|
+ //如果用户浏览课程不包含推荐课程,追加推荐课程 |(此处为避免推荐位课程重复)
|
|
|
+ if(!result.contains(vo)){
|
|
|
+ result.add(vo);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ log.info("not found course by pid, pid={}", userRecommend.getPid());
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
+ return APIResult.ok(result);
|
|
|
+ }else{
|
|
|
+ //不存在浏览历史,不存在用户推荐;使用渠道推荐
|
|
|
+ String merchantId = user.getMerchantId();
|
|
|
+ return productService.getRecommendCourses(merchantId);
|
|
|
}
|
|
|
- return APIResult.ok(result);
|
|
|
- }else{
|
|
|
- //不存在浏览历史,直接使用推荐
|
|
|
- String merchantId = user.getMerchantId();
|
|
|
- return productService.getRecommendCourses(merchantId);
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* Get recommend posters
|
|
@@ -119,4 +169,17 @@ public class RecommendController {
|
|
|
|
|
|
return APIResult.ok(data);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private RecommendVo courseToRecommendVo(Course course) {
|
|
|
+ RecommendVo vo = new RecommendVo();
|
|
|
+ vo.setId(course.getId());
|
|
|
+ vo.setCode(course.getCode());
|
|
|
+ vo.setTitle(course.getTitle());
|
|
|
+ vo.setSubTitle(course.getSubTitle());
|
|
|
+ vo.setBreadCrumb(course.getBreadCrumb());
|
|
|
+ vo.setCoverUrl(course.getCoverUrl());
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
}
|