Search in sources :

Example 1 with WatchMovieMapper

use of com.mapper.WatchMovieMapper in project Movie by batsqd.

the class MovieController method getRecommendedMoviesByOurAlgorithm.

/////////////////////////////////////////////////////
@RequestMapping("getRecommendedMoviesByOurAlgorithm.action")
public ModelAndView getRecommendedMoviesByOurAlgorithm(HttpSession session) throws Exception {
    User user = (User) session.getAttribute("user");
    int user_id = user.getUserid();
    int recommend_movie_num = Configs.recommend_movie_num;
    ApplicationContext ac = ApplicationContextUtil.getApplicationContext();
    WatchMovieMapper watchMovieMapper = (WatchMovieMapper) ac.getBean("watchMovieMapper");
    int numsOfRatedMoviesByUserId = watchMovieMapper.numsOfRatedMoviesByUserId(user_id);
    ModelAndView modelAndView = new ModelAndView();
    if (numsOfRatedMoviesByUserId < 5) {
        modelAndView.addObject("numsOfRatedMoviesByUserId", numsOfRatedMoviesByUserId);
        modelAndView.setViewName("/WEB-INF/jsp/guessYouLike.jsp");
        return modelAndView;
    } else {
        //超过5人评价,才做预测
        ImproveSlopeOne improveSlopeOne = new ImproveSlopeOne();
        List<RecommendedMovie> recommendedMovieslist = improveSlopeOne.getPredictMovies(user_id, recommend_movie_num);
        //System.out.println("=========================================");
        //System.out.println("推荐电影的数量:"+recommendedMovieslist.size());
        //System.out.println(recommendedMovieslist.toString());
        //System.out.println("==========================================");
        MovieMapper movieMapper = (MovieMapper) ac.getBean("movieMapper");
        RecommendMapper recommendMapper = (RecommendMapper) ac.getBean("recommendMapper");
        ArrayList<Movie> moviesList = new ArrayList<Movie>();
        for (int i = 0; i < recommendedMovieslist.size(); i++) {
            double movie_recommend_value = recommendedMovieslist.get(i).getRecommend_vale();
            int recommendedMovie_id = recommendedMovieslist.get(i).getMovie_id();
            HashMap<String, Object> parameter = new HashMap<String, Object>();
            parameter.put("movie_id", recommendedMovie_id);
            parameter.put("user_id", user_id);
            parameter.put("recommend_value", movie_recommend_value);
            //最好处理下异常
            //只是保存user_id movie_id recommend_value timestamp
            recommendMapper.saveRecommendedMovies(parameter);
            Movie movie = movieMapper.selectMovieById(recommendedMovie_id);
            if (movie != null) {
                moviesList.add(movie);
            }
        }
        modelAndView.addObject("moviesList", moviesList);
        modelAndView.setViewName("/WEB-INF/jsp/guessYouLike.jsp");
        return modelAndView;
    }
}
Also used : RecommendedMovie(com.po.RecommendedMovie) Movie(com.po.Movie) User(com.po.User) ImproveSlopeOne(com.recommender.ImproveSlopeOne) HashMap(java.util.HashMap) ModelAndView(org.springframework.web.servlet.ModelAndView) ArrayList(java.util.ArrayList) RecommendedMovie(com.po.RecommendedMovie) ApplicationContext(org.springframework.context.ApplicationContext) WatchMovieMapper(com.mapper.WatchMovieMapper) RecommendMapper(com.mapper.RecommendMapper) MovieMapper(com.mapper.MovieMapper) WatchMovieMapper(com.mapper.WatchMovieMapper) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with WatchMovieMapper

use of com.mapper.WatchMovieMapper in project Movie by batsqd.

the class MovieController method getHotMovies.

@RequestMapping("getHotMovies.action")
public ModelAndView getHotMovies() {
    long l = System.currentTimeMillis();
    Date date = new Date(l);
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    String rating_time = dateFormat.format(date);
    ApplicationContext ac = ApplicationContextUtil.getApplicationContext();
    WatchMovieMapper watchMovieMapper = (WatchMovieMapper) ac.getBean("watchMovieMapper");
    HashMap<String, Object> parameter = new HashMap<String, Object>();
    parameter.put("rating_time", rating_time);
    parameter.put("hot_movie_nums", Configs.hot_movie_nums);
    ArrayList<Integer> movie_id_List = (ArrayList<Integer>) watchMovieMapper.selectHotMovies(parameter);
    MovieMapper movieMapper = (MovieMapper) ac.getBean("movieMapper");
    List<Movie> moviesList = new ArrayList<Movie>();
    for (int i = 0; i < movie_id_List.size(); i++) {
        //此处拿到movie ID 去movie表查询List<movie>
        Movie movie = movieMapper.selectMovieById(movie_id_List.get(i));
        moviesList.add(movie);
    }
    ModelAndView modelAndView = new ModelAndView();
    modelAndView.addObject("moviesList", moviesList);
    modelAndView.setViewName("/WEB-INF/jsp/hotMovies.jsp");
    return modelAndView;
}
Also used : RecommendedMovie(com.po.RecommendedMovie) Movie(com.po.Movie) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) Date(java.sql.Date) ApplicationContext(org.springframework.context.ApplicationContext) WatchMovieMapper(com.mapper.WatchMovieMapper) SimpleDateFormat(java.text.SimpleDateFormat) MovieMapper(com.mapper.MovieMapper) WatchMovieMapper(com.mapper.WatchMovieMapper) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with WatchMovieMapper

use of com.mapper.WatchMovieMapper in project Movie by batsqd.

the class StarRating method saveRating.

@RequestMapping("/saveRating.action")
@ResponseBody
public Message saveRating(int userid, int movie_id, int rating) {
    //日志处理
    logger_rating.info(userid + "	" + movie_id + "	" + rating);
    ApplicationContext ac = ApplicationContextUtil.getApplicationContext();
    WatchMovieMapper watchMovieMapper = (WatchMovieMapper) ac.getBean("watchMovieMapper");
    HashMap<String, Object> parameter = new HashMap<String, Object>();
    parameter.put("userid", userid);
    parameter.put("movie_id", movie_id);
    parameter.put("rating", rating);
    //得到long类型当前时间
    long l = System.currentTimeMillis();
    //new日期对象
    Date date = new Date(l);
    //转换提日期输出格式
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    System.out.println(dateFormat.format(date));
    parameter.put("rating_time", date);
    parameter.put("comment", "");
    watchMovieMapper.saveRating(parameter);
    /*
		  ModelAndView modelAndView=new ModelAndView();
		  
		  try{
		     watchMovieMapper.saveRating(parameter);
		     modelAndView.addObject("insertException","感谢您的评分:"+rating+"分!");
		  }catch(Exception e){
			 modelAndView.addObject("insertException","保存数据异常!");
		  }finally{
			  modelAndView.setViewName("/WEB-INF/jsp/movieDetail.jsp");
			  return modelAndView;
		  }*/
    Message message = new Message();
    message.setRegister_prompt_info("1111111111");
    return message;
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) Message(com.po.Message) HashMap(java.util.HashMap) WatchMovieMapper(com.mapper.WatchMovieMapper) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.sql.Date) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

WatchMovieMapper (com.mapper.WatchMovieMapper)3 HashMap (java.util.HashMap)3 ApplicationContext (org.springframework.context.ApplicationContext)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 MovieMapper (com.mapper.MovieMapper)2 Movie (com.po.Movie)2 RecommendedMovie (com.po.RecommendedMovie)2 Date (java.sql.Date)2 SimpleDateFormat (java.text.SimpleDateFormat)2 ArrayList (java.util.ArrayList)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 RecommendMapper (com.mapper.RecommendMapper)1 Message (com.po.Message)1 User (com.po.User)1 ImproveSlopeOne (com.recommender.ImproveSlopeOne)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1