コード例 #1
0
 @RequestMapping("/get_book_info")
 public ModelMap getBookInfo() throws Exception {
   ModelMap model = new ModelMap();
   User user = WebContextThreadLocal.getCurrentUser();
   List<Invite> inviteList = this.inviteService.getInviteByUserId();
   // Set<Course> courseSet = user.getCourses();
   HashMap<String, List<DoubanJson>> recommendBooks = new HashMap<String, List<DoubanJson>>();
   for (Invite invite : inviteList) {
     // Set<DoubanJson> bookInfos = course.getDoubanJsons();
     Course course = invite.getCourse();
     List<DoubanJson> bookInfos = this.bookJsonService.getBookByCourse(course.getId());
     recommendBooks.put(course.getName(), bookInfos);
     // model.put(course.getName(),bookInfos)  ;
   }
   model.put("bookList", recommendBooks);
   return model;
 }
コード例 #2
0
  @RequestMapping("/my_configure")
  public ModelAndView my_configure() throws Exception {
    ModelAndView mav = new ModelAndView();
    User user = WebContextThreadLocal.getCurrentUser();
    if (user != null) {
      int role = user.getRole();
      HashMapReduce<Major, Course> hashMapReduce = new HashMapReduce<Major, Course>();
      String id = user.getId();
      user = this.userService.getUserByUserId(id);
      WebContextThreadLocal.setCurrentUser(user);
      Set<Course> courseSet = user.getCourses();
      HashMapReduce<String, Set<DoubanJson>> recommendBooks =
          new HashMapReduce<String, Set<DoubanJson>>();
      for (Course course : courseSet) {
        hashMapReduce.put(course.getMajor(), course);
        Set<DoubanJson> recommendBook = new HashSet<DoubanJson>();
        if (course.getDoubanJsons().size() == 0) {
          String str = null;
          if (course.getSearchKeyword() == null)
            str = this.academyService.wordAnalyzer(course.getName(), course);
          else {
            str = course.getSearchKeyword();
            String[] strs = str.split(" ");
            boolean first = true;
            for (int i = 0; i < strs.length; i++) {
              if (first) {
                String para = java.net.URLEncoder.encode(strs[i], "UTF-8");
                str = para;
                first = false;
              } else {
                String para = java.net.URLEncoder.encode(strs[i], "UTF-8");
                str = str + ',' + para;
              }
            }
          }
          // String str =
          // "https://api.douban.com/v2/book/search?apikey=00e256c12217228802a7044366456798&q="+course.getName();
          recommendBook = this.bookJsonService.getJsonString(str, course.getId());
        } else {
          recommendBook = course.getDoubanJsons();
        }
        recommendBooks.put(course.getName(), recommendBook);
      }
      // String str = this.academyService.wordAnalyzer("Java课程设计");

      List<Invite> inviteList = this.inviteService.getInviteByUserId();
      HashMap<String, List<DoubanJson>> bookList = new HashMap<String, List<DoubanJson>>();
      for (Invite invite : inviteList) {
        Course course = invite.getCourse();
        List<DoubanJson> bookInfos = this.bookJsonService.getBookByCourse(course.getId());
        bookList.put(course.getName(), bookInfos);
      }
      mav.getModel().put("bookList", bookList);

      mav.getModel().put("majorMap", hashMapReduce.getMap());

      // ArrayList<DoubanJson> recommendBooks = this.bookJsonService.getJsonString(str);
      mav.getModel().put("recommendBooks", recommendBooks.getMap());
      // unactiveCommunities对于老师指的是没有创建的社区,对于学生指的是没有加入,但已经存在的社区
      Set<Community> unactiveCommunities = new HashSet<Community>();
      if (role == 1) {
        unactiveCommunities = this.communityService.getAllCommunitiesByCurrentUserRole();
      } else if (role == 0) {
        for (Course course : courseSet) {
          Set<Community> communities = course.getCommunities();
          for (Community community : communities) {
            if (community.getState() == 1 && !user.getCommunities().contains(community)) {
              unactiveCommunities.add(community);
            }
          }
        }
      }
      mav.getModel().put("unactiveCommunities", unactiveCommunities);
      mav.getModel().put("invitedCommunities", this.inviteService.getInviteCommunities());
      if (role == 2) {
        Pager<Resource> pager = this.resourceOperationService.getReviewResource(1);
        mav.getModel().put("pager", pager);
        mav.getModel().put("htmlTag", 1);
        mav.setViewName("admin/reviewResource");
        return mav;
      }
    }

    mav.setViewName("user/myConfigure");
    return mav;
  }