コード例 #1
0
 // 1 进入团购的页面
 @Action(
     value = "grouponDetailPage",
     interceptorRefs = {@InterceptorRef(value = "userActionStack")},
     results = {@Result(name = SUCCESS, location = "/userPages/groupondetail.jsp")})
 public String grouponDetailPage() {
   // 获得这个学校所有的团购项目
   groupon = grouponService.getGrouponDetail(groupon.getId());
   if (groupon != null) {
     String phone = groupon.getTel();
     String phone1 = phone.substring(0, 3);
     String phone2 = phone.substring(7, 11);
     phone = phone1 + "****" + phone2;
     groupon.setTel(phone);
   }
   return SUCCESS;
 }
コード例 #2
0
  // 2 发起一个团购
  @Action(
      value = "grouponInitiate",
      interceptorRefs = {@InterceptorRef(value = "userActionStack")},
      results = {@Result(name = SUCCESS, type = "json")})
  public String grouponInitiate() {
    User user = (User) ServletActionContext.getRequest().getSession().getAttribute("user");
    PrintWriter writer = CommonUtil.getHtmlPrintWriter(ServletActionContext.getResponse());
    isbns = isbns.replaceAll("\\]", "");
    isbns = isbns.replaceAll("\\[", "");
    isbns = isbns.replaceAll("\"", "");
    if (groupon.getId() == null) {
      groupon.setId(0);
    }
    Groupon grouponInit = grouponService.getGroupon(groupon.getId());
    if (grouponInit == null) {
      Date createTime = CommonUtil.getDayDate();
      Date endTime = CommonUtil.dateOperate(createTime, 60);
      grouponInit = new Groupon();
      grouponInit.setName(groupon.getName());
      grouponInit.setTel(groupon.getTel());
      grouponInit.setEndTime(endTime);
      grouponInit.setState(0);
      grouponInit.setCreateTime(createTime);
      grouponInit.setUser(user);
      grouponInit.setSchool(user.getSchool());
      grouponInit.setRemark(groupon.getRemark());
      grouponInit.setClassNo(groupon.getClassNo());
      String[] isbnArray = isbns.split(",");
      grouponService.save(grouponInit);
      for (int i = 0; i < isbnArray.length; i++) {
        Grouponitem grouponitem = new Grouponitem();
        Book findBook = bookService.getBookFromDB(isbnArray[i]);
        grouponitem.setGroupon(grouponInit);
        grouponitem.setBook(findBook);
        grouponService.save(grouponitem);
      }
    } else {
      grouponInit.setName(groupon.getName());
      grouponInit.setTel(groupon.getTel());
      grouponInit.setState(0);
      grouponInit.setRemark(groupon.getRemark());
      grouponInit.setClassNo(groupon.getClassNo());
      grouponInit.setEndTime(CommonUtil.dateOperate(new Date(), 60));
      String[] isbnArray = isbns.split(",");
      grouponService.update(grouponInit);
      for (int i = 0; i < isbnArray.length; i++) {
        Grouponitem grouponitem = grouponService.loadGrouponitem(isbnArray[i], grouponInit.getId());
        System.out.println(grouponitem == null);
        if (grouponitem == null) {
          grouponitem = new Grouponitem();
          Book findBook = bookService.getBookFromDB(isbnArray[i]);
          grouponitem.setGroupon(grouponInit);
          grouponitem.setBook(findBook);
          grouponService.save(grouponitem);
        }
      }
    }

    writer.write("success");
    writer.flush();
    writer.close();
    return SUCCESS;
  }