/** 用户自己创建的班级购 */
 @Action(
     value = "changeGrouponState",
     interceptorRefs = {@InterceptorRef(value = "userActionStack")},
     results = {@Result(name = SUCCESS, type = "json")})
 public String changeGrouponState() {
   PrintWriter writer = CommonUtil.getHtmlPrintWriter(ServletActionContext.getResponse());
   Groupon find = grouponService.getGroupon(groupon.getId());
   if (find != null) {
     if (find.getState() == 0) find.setState(1);
     else find.setState(0);
   }
   grouponService.update(find);
   writer.write("success");
   writer.flush();
   writer.close();
   return SUCCESS;
 }
  // 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;
  }