public Event perform(HttpServletRequest request) throws HTMLActionException {

    HttpSession session = request.getSession();
    // look up the adventure transportation
    AdventureComponentManager acm =
        (AdventureComponentManager) session.getAttribute(AdventureKeys.COMPONENT_MANAGER);
    Cart cart = acm.getCart(session);
    String origin = request.getParameter("origin");
    // if we are doing a search for a different flight from the cart page
    if (origin == null) {
      origin = cart.getOrigin();
    } else {
      cart.setOrigin(origin);
    }

    String noTransport = request.getParameter("no_transport");
    String showTransport = request.getParameter("show_flights");
    Locale locale = new Locale("en", "us");
    String destination = cart.getDestination();
    // access catalog component and retrieve data from the database
    List transpDepartureBeans = searchTransportation(origin, destination, locale);
    List transpReturnBeans = searchTransportation(destination, origin, locale);

    // places result bean data in the request
    request.setAttribute("departure_result", transpDepartureBeans);
    request.setAttribute("return_result", transpReturnBeans);
    request.setAttribute("search_target", "transportation");
    return null;
  }
Ejemplo n.º 2
0
 /**
  * Goes trough the table auction and checks which auctions are over. If the auction is over, finds
  * all bids for that auction, selects the highest bid and sends winning message, also sends to all
  * other users message that auction is over.
  */
 public static void checkAuctionOutcome() {
   // Declaring list of all auctions.
   List<Auction> auctions = finder.all();
   // Declaring variable that represents current date.
   Date currentDate = new Date();
   // Going trough all auctions.
   for (int i = 0; i < auctions.size(); i++) {
     // Declaring variable that represents auction ending date.
     Date auctionEndingDate = auctions.get(i).endingDate;
     // Checking if the auction is active and if the auction ending date is before current date.
     if (auctions.get(i).isActive && auctionEndingDate.before(currentDate)) {
       // Finding all auction bids.
       List<Bid> bids = Bid.getAuctionBids(auctions.get(i));
       // Declaring variable that represents highest bid.
       Bid highestBid = bids.get(0);
       // Declaring string variable that represents winning message.
       String winningMessage =
           "Congratulations!!! You won bitBay auction for item #"
               + auctions.get(i).product.id
               + " - "
               + auctions.get(i).product.name
               + ".\n\r \n\r To proceed with transaction please contact: "
               + auctions.get(i).product.user.email;
       // Declaring and saving winning message.
       Message message =
           new Message(
               CommonHelpers.serviceUser(), highestBid.user, "Auction Winning", winningMessage);
       message.save();
       // Sending SMS notification to auction winner.
       String sms =
           "Congratulations!!! You won bitBay auction for item #"
               + auctions.get(i).product.id
               + " - "
               + auctions.get(i).product.name
               + ". "
               + "This product has been sent to your cart";
       if (highestBid.user.phoneNumber != null) {
         SmsHelper.sendSms(sms, highestBid.user.phoneNumber);
       }
       // After user won on auction create new cart if user don't have one, and put auction item to
       // his cart
       Cart cart = Cart.findCartByUser(highestBid.user);
       if (cart == null) {
         Cart newCart = new Cart();
         newCart.user = highestBid.user;
         newCart.save();
         CartItem cartItem = new CartItem(auctions.get(i).product, highestBid.user, newCart);
         cartItem.save();
       } else {
         CartItem cartItem = new CartItem(auctions.get(i).product, highestBid.user, cart);
         cartItem.save();
       }
       // Declaring string set that will contain emails of all users that have not had highest bid.
       Set<String> bidUsers = new HashSet<>();
       // Adding all user emails to the set.
       for (int j = 0; j < bids.size(); j++) {
         bidUsers.add(bids.get(j).user.email);
       }
       // Removing email of highest bit user from the set.
       bidUsers.remove(highestBid.user.email);
       // Declaring string variable that represents losing message.
       String losingMessage =
           "Biding for item #"
               + auctions.get(i).product.id
               + " - "
               + auctions.get(i).product.name
               + " is over.\n\r \n\r We are sorry to inform you that your bid was not enough.";
       // Declaring iterator list of all user emails.
       Iterator<String> iter = bidUsers.iterator();
       // Going trough all emails and sending message.
       while (iter.hasNext()) {
         User receiver = User.getUserByEmail(iter.next());
         Message msg =
             new Message(CommonHelpers.serviceUser(), receiver, "Auction results", losingMessage);
         msg.save();
       }
       // Setting auction status to inactive.
       auctions.get(i).isActive = false;
       auctions.get(i).update();
     }
   }
 }
  // 1 进入团购的页面
  @Action(
      value = "nextGrouponitemPage",
      interceptorRefs = {@InterceptorRef(value = "userActionStack")},
      results = {
        @Result(name = SUCCESS, location = "/userPages/grouponitem.jsp"),
        @Result(name = "over", location = "/userPages/cart.jsp")
      })
  public String nextGrouponitemPage() {
    User findUser = (User) ServletActionContext.getRequest().getSession().getAttribute("user");
    // if()
    Groupon find = grouponService.getGroupon(groupon.getId());
    Grouponitem grouponitem = new Grouponitem();
    grouponitem.setId(page);
    grouponitem.setGroupon(find);
    Grouponitem findItem = grouponService.next(grouponitem);
    // 如果没有找到,那么意味着查询已经结束
    if (findItem == null) {
      double fee = 0.0;
      int num = 0;
      List<Cart> result = new ArrayList<Cart>();
      List<Cartitem> items = cartService.getGrouponitemsByUser(findUser.getId(), find.getId());
      for (int i = 0; i < items.size(); i++) {
        Cartitem cartitem = items.get(i);
        num += cartitem.getNum();
        if (cartitem.getSalesBook() == null) {
          if (cartitem.getBook().getDiscount() == 0.0) {
            cartitem.getBook().setDiscount(ConstantUtil.NEWBOOKDISCOUNT);
          }
          SalesBook newbookSalesBook =
              salesBookService.getSalesBookByIsbnSeller(
                  cartitem.getBook().getIsbn(), ConstantUtil.NEWBOOKPRODUCT);
          float discount = ConstantUtil.NEWBOOKDISCOUNT;
          if (newbookSalesBook != null && newbookSalesBook.getDiscount() != null) {
            discount = newbookSalesBook.getDiscount();
          }
          fee +=
              cartitem.getNum() * Math.round(cartitem.getBook().getPrice() * discount * 10) / 10d;
        } else {
          fee += cartitem.getNum() * cartitem.getSalesBook().getPrice();
        }
        Cart cart = cartitem.getCart();
        Cart findCart = getCartByList(cart.getId(), result);
        if (findCart == null) {
          Cart cartResult = new Cart();
          cartResult.setId(cart.getId());
          cartResult.setSeller(cart.getSeller());
          cartResult.setCartitems(new HashSet());
          cartResult.setTotalFee(cart.getTotalFee());
          cartResult.setUser(cart.getUser());
          cartResult.getCartitems().add(cartitem);
          cartitem.setCart(cartResult);
          result.add(cartResult);
        } else {
          findCart.getCartitems().add(cartitem);
          cartitem.setCart(findCart);
        }
      }
      System.out.println(result.size());
      ActionContext.getContext().getValueStack().set("carts", result);
      ActionContext.getContext().getValueStack().set("num", num);
      ActionContext.getContext().getValueStack().set("fee", Math.round(fee * 10) / 10d);
      return "over";
    }

    Book book = bookService.getBookByIsbn(findItem.getBook().getIsbn());
    // 如果没有拿到数据,则返回空
    ServiceArea serviceArea = findUser.getSchool().getServiceArea();
    // 如果找到了,查看新书供应商有没有此数据,如果没有,那么就给新书供应商加进去
    SalesBook newbookSalesBook =
        salesBookService.getSalesBookByIsbnSeller(
            findItem.getBook().getIsbn(), ConstantUtil.NEWBOOKPRODUCT);
    Seller seller = sellerService.getSellerById(ConstantUtil.NEWBOOKPRODUCT);
    SalesBook model =
        salesBookService.getSalesBookByIsbnSeller(findItem.getBook().getIsbn(), seller.getId());
    float bookDiscount;
    if (newbookSalesBook == null) {
      newbookSalesBook = new SalesBook();
      newbookSalesBook.setSeller(seller);
      newbookSalesBook.setBook(book);
      newbookSalesBook.setTitle(book.getTitle());
      newbookSalesBook.setAuthor(book.getAuthor());
      newbookSalesBook.setStandardPrice(book.getPrice());
      newbookSalesBook.setPublisher(book.getPublisher());
      newbookSalesBook.setImage(book.getImage());
      newbookSalesBook.setBigImage(book.getBigImage());
      salesBookService.save(newbookSalesBook);
    }
    if (model == null) {
      model = newbookSalesBook;
    }
    if (newbookSalesBook.getDiscount() == null) {
      bookDiscount = ConstantUtil.NEWBOOKDISCOUNT;
    } else {
      bookDiscount = newbookSalesBook.getDiscount();
    }
    ActionContext.getContext().getValueStack().set("bookDiscount", bookDiscount);
    newbookSalesBook.setDiscount(bookDiscount);
    newbookSalesBook.setPrice(
        Math.round(newbookSalesBook.getBook().getPrice() * bookDiscount * 10) / 10d);
    newbookSalesBook.setNum(999);
    SalesBook salesBook = newbookSalesBook;
    School findSchool = findUser.getSchool();
    List<SellerBean> sellerBeans =
        salesBookService.getSellerBeans(
            newbookSalesBook.getBook().getIsbn(), findSchool.getServiceArea().getId());
    int totalNum = cartService.getGrouponitemsByUser(findUser.getId(), find.getId()).size();
    ActionContext.getContext().getValueStack().set("sellerBeans", sellerBeans);
    ActionContext.getContext().getValueStack().set("item", findItem);
    Seller newBookSeller = sellerService.getSellerById(ConstantUtil.NEWBOOKPRODUCT);
    ActionContext.getContext().getValueStack().set("totalNum", totalNum);
    ActionContext.getContext().getValueStack().set("model", model);
    ActionContext.getContext().getValueStack().set("newBookSeller", newBookSeller);
    ActionContext.getContext()
        .getValueStack()
        .set("price", Math.round(newbookSalesBook.getBook().getPrice() * bookDiscount * 10) / 10d);
    // 获得这个学校所有的团购项目
    return SUCCESS;
  }
Ejemplo n.º 4
0
 public static boolean isCustomerAddressSet(Cart cart) {
   return cart.getShippingAddress() != null;
 }