Пример #1
0
  @RequestMapping(value = "/room/info", method = RequestMethod.GET)
  public String pageAllRoom(Model model) {

    // 首先设置当前在线管理员或读者
    if ("".equals(getLibraryService().getTypeOnlien())) { // 当前没有读者或者管理员
      model.addAttribute("reader", null);
      model.addAttribute("admin", null);
    } else if ("reader".equals(getLibraryService().getTypeOnlien())) {
      ReaderEntity readerEntity = getLibraryService().getReaderEntity();
      model.addAttribute("reader", readerEntity);
      model.addAttribute("admin", null);
    } else if ("admin".equals(getLibraryService().getTypeOnlien())) {
      AdminEntity adminEntity = getLibraryService().getAdminEntity();
      model.addAttribute("reader", null);
      model.addAttribute("admin", adminEntity);
    }

    // 查询小组自习室的使用情况
    List<RoomEntity> roomEntityList =
        getLibraryService().getRoomRepository().findAllByLocationAsc();
    HashMap<String, List<String>> map = new HashMap<String, List<String>>();
    HashMap<String, List<BorrowRoomEntity>> map2 = new HashMap<String, List<BorrowRoomEntity>>();
    for (RoomEntity roomEntity : roomEntityList) {
      //            List<Integer> borrowRoomEntityList = getLibraryService()
      //                    .getBorrowRoomRepository()
      //                    .findBorrowRoomEntityByLocation(roomEntity.getRoomLocation());
      List<BorrowRoomEntity> borrowRoomEntityList =
          getLibraryService()
              .getBorrowRoomRepository()
              .findBorrowRoomEntityByLocation2(roomEntity.getRoomLocation());

      if (borrowRoomEntityList.size() != 0) {

        List<String> periodAndStatus = new ArrayList<String>();
        for (int i = 0; i < borrowRoomEntityList.size(); i++) {
          BorrowRoomEntity borrowRoomEntity = borrowRoomEntityList.get(i);
          String temp = borrowRoomEntity.getBorrowStatus() + borrowRoomEntity.getBorrowTimePeriod();
          periodAndStatus.add(i, temp);
        }

        for (String str : periodAndStatus) {
          System.out.println(str);
        }

        map.put(roomEntity.getRoomLocation(), periodAndStatus);
      } else map.put(roomEntity.getRoomLocation(), null);
    }

    model.addAttribute("roomEntityList", roomEntityList);
    model.addAttribute("map", map);

    return "allRoomsInfo";
  }
Пример #2
0
  @RequestMapping(value = "/room/borrow", method = RequestMethod.POST)
  public String borrowRoom(
      @RequestParam("roomLocation") String roomLocation,
      @RequestParam("timePeriod") String timePeriod,
      RedirectAttributes redirectAttributes) {

    Long res =
        getLibraryService()
            .getBorrowRoomRepository()
            .findBorrowEntityItem(roomLocation, Integer.valueOf(timePeriod));
    if (res != 0) {

      // 已经被借阅了
      redirectAttributes.addFlashAttribute("result", "occupied");
      return "redirect:/room/info";

    } else {

      // 可以借阅
      BorrowRoomEntity borrowRoomEntity = new BorrowRoomEntity();
      borrowRoomEntity.setBorrowRoomLocation(roomLocation);
      borrowRoomEntity.setBorrowRoomReaderNo(getLibraryService().getReaderEntity().getReaderNo());
      borrowRoomEntity.setBorrowTimePeriod(Integer.valueOf(timePeriod));
      borrowRoomEntity.setBorrowRoomAdminNo(null);
      borrowRoomEntity.setBorrowStatus("w");
      getLibraryService().getBorrowRoomRepository().saveAndFlush(borrowRoomEntity);

      redirectAttributes.addFlashAttribute("result", "booked");
      return "redirect:/room/info";
    }
  }