// 根据编号获得团购
 @Action(
     value = "searchGroupon",
     interceptorRefs = {@InterceptorRef(value = "userActionStack")},
     results = {@Result(name = SUCCESS, type = "json")})
 public String searchGroupon() {
   User sessionUser = (User) ServletActionContext.getRequest().getSession().getAttribute("user");
   // 获得这个学校所有的团购项目
   if (groupon.getName() != null) {
     //            name = CommonUtil.getSortString(name.trim());
     name = "%" + groupon.getName() + "%";
   }
   List<Groupon> groupons =
       grouponService.effectiveGroupons(sessionUser.getSchool().getId(), page, name);
   List<GrouponBean> grouponBeanList = new ArrayList<>();
   for (int i = 0; i < groupons.size(); i++) {
     GrouponBean bean = new GrouponBean();
     bean.setId(groupons.get(i).getId());
     bean.setName(groupons.get(i).getName());
     bean.setClassNo(groupons.get(i).getClassNo());
     bean.setTel(groupons.get(i).getTel());
     bean.setEndTime(CommonUtil.dateToString(groupons.get(i).getEndTime()));
     grouponBeanList.add(bean);
   }
   String json = JSONArray.fromObject(grouponBeanList).toString();
   PrintWriter writer = CommonUtil.getJsonPrintWriter(ServletActionContext.getResponse());
   writer.write(json);
   writer.flush();
   writer.close();
   return SUCCESS;
 }
Пример #2
0
  private static void parseCondition(
      String action, String desc, final List<Object> params, final StringBuilder sb) {
    if (!CommonUtil.isBlank(action)) {
      if (sb.length() > 0) sb.append(" and ");

      sb.append("action like ?");
      params.add(new StringBuilder("%").append(action.trim()).append("%").toString());
    }

    if (!CommonUtil.isBlank(desc)) {
      if (sb.length() > 0) sb.append(" and ");

      sb.append("description like ?");
      params.add(new StringBuilder("%").append(desc.trim()).append("%").toString());
    }
  }
Пример #3
0
  public static String createByJson(String models) {
    List<PermVO> vos = JSON.parseArray(models, PermVO.class);
    if (vos == null) return models;

    for (PermVO vo : vos) {
      Permission.createByVO(vo);
    }

    final String _models = CommonUtil.toJson(vos);
    return _models;
  }
 // 4 删除一个团购项
 @Action(
     value = "delGrouponItem",
     interceptorRefs = {@InterceptorRef(value = "userActionStack")},
     results = {@Result(name = SUCCESS, type = "json")})
 public String delGrouponItem() {
   Grouponitem grouponitem = grouponService.getGrouponitem(groupon.getId());
   if (grouponitem != null) {
     grouponService.delGrouponitem(grouponitem);
   }
   PrintWriter writer = CommonUtil.getHtmlPrintWriter(ServletActionContext.getResponse());
   writer.write("success");
   writer.flush();
   writer.close();
   return SUCCESS;
 }
 /** 用户自己创建的班级购 */
 @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;
 }
 @Action(
     value = "grouponBook",
     interceptorRefs = {@InterceptorRef(value = "userActionStack")},
     results = {@Result(name = SUCCESS, type = "json")})
 public String grouponBook() {
   PrintWriter writer = CommonUtil.getJsonPrintWriter(ServletActionContext.getResponse());
   Book book = bookService.getBookByIsbn(isbn);
   BookBase base = null;
   if (book != null) {
     base = new BookBase();
     base.setIsbn(book.getIsbn());
     base.setAuthor(book.getAuthor());
     base.setPrice(book.getPrice());
     base.setTitle(book.getTitle());
     base.setPublisher(book.getPublisher());
   }
   String json = JSONObject.fromObject(base).toString();
   writer.write(json);
   writer.flush();
   writer.close();
   return SUCCESS;
 }
Пример #7
0
  private static Permission findByAction(String action) {
    if (CommonUtil.isBlank(action)) return null;

    return Permission.find("byAction", action.trim()).first();
  }
  // 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;
  }