Ejemplo n.º 1
0
  @Result("/WEB-INF/pages/freeze/team/filter.jsp")
  public String delete(HttpServletRequest req, HttpServletResponse resp) {
    int id = param(req, "id", 0);

    Team model = new Team();
    if (id != 0) {
      model.setId(id);
      model = model.get(id);
    }

    if (id == 0) {
      setAttr(req, TIP_NAME_KEY, "非法ID值");
    } else {
      model.setId(id);
      model = model.get(id);
      User user = new User();
      user = user.get(model.getUserID());
      // TODO more relative
      if (model.delete()) {
        setAttr(req, TIP_NAME_KEY, "成功删除[" + user.getUsername() + "]");
      } else {
        setAttr(req, TIP_NAME_KEY, "删除管理团队成员[" + user.getUsername() + "]失败");
      }
    }
    return this.filter(req, resp);
  }
Ejemplo n.º 2
0
  @SuppressWarnings("unchecked")
  @Result("/WEB-INF/pages/freeze/team/filter.jsp")
  public String filter(HttpServletRequest req, HttpServletResponse resp) {
    int userID = param(req, "userID", -1);
    int start = param(req, "start", 0);
    int end = param(req, "end", 0);

    String by = param(req, "by");
    String order = param(req, "order");

    Team model = new Team();
    model.setUserID(userID);
    model.setStart(start);
    model.setEnd(end);

    User user = new User();
    setAttr(req, PAGE_TEAM_USER_LIST_KEY, user.listAll(" order by username desc"));

    setAttr(req, MODEL, model);

    StringBuilder filter = new StringBuilder();

    if (userID != -1) {
      filter.append(" where userID=" + userID);
    }
    if (userID == -1 && start != 0) {
      filter.append(" where start >= " + start);
    } else if (userID != -1 && start != 0) {
      filter.append(" and start >= " + start);
    }
    if (userID == -1 && start == 0 && end != 0) {
      filter.append(" where end <= " + end);
    } else if ((userID != -1 || start != 0) && end != 0) {
      filter.append(" and end <= " + end);
    }

    if (StringUtils.isNotBlank(by)
        && (by.equals("id") || by.equals("stext") || by.equals("addtime"))) {
      if (StringUtils.isNotBlank(order) && (order.equals("asc") || order.equals("desc"))) {
        filter.append(" order by " + by + " " + order);
      } else {
        filter.append(" order by " + by + " asc");
      }
    } else {
      filter.append(" order by id asc");
    }

    // 前台分页
    int p = Constant.DEFAULT_CURRENT_PAGE;
    int countPerPage = Constant.DEFAULT_COUNT_PER_PAGE;
    try {
      p = param(req, "page", Constant.DEFAULT_CURRENT_PAGE);
      if (p < 1) p = Constant.DEFAULT_CURRENT_PAGE;
    } catch (NumberFormatException e) {
      p = Constant.DEFAULT_CURRENT_PAGE;
    }
    try {
      countPerPage = param(req, "countPerPage", Constant.DEFAULT_COUNT_PER_PAGE);
    } catch (NumberFormatException e) {
      countPerPage = Constant.DEFAULT_COUNT_PER_PAGE;
    }
    int currentPage = p;
    int totalCount = model.totalCount(filter.toString());
    Pager pager = new Pager(currentPage, countPerPage, totalCount);
    // 针对可能的原访问页数大于实际总页数,此处重置下
    if (currentPage > pager.getTotalPage()) currentPage = p = pager.getTotalPage();
    // 读取部分数据
    List<Team> dataList =
        (List<Team>) model.filterByPage(filter.toString(), p, pager.getCountPerPage());

    List<TeamTogether> ttList = new ArrayList<TeamTogether>();
    for (Team team : dataList) {
      TeamTogether tt = new TeamTogether();

      User u = new User();
      u = u.get(team.getUserID());

      tt.setId(team.getId());
      tt.setUser(u);
      tt.setHeadimage(team.getHeadimage());
      tt.setStart(team.getStart());
      tt.setEnd(team.getEnd());

      ttList.add(tt);
    }

    setAttr(req, CURRENT_PAGE_KEY, currentPage);
    setAttr(req, CURRENT_COUNT_PER_PAGE_KEY, countPerPage);
    setAttr(req, PAGER_KEY, pager);
    setAttr(req, MAX_PAGERSHOW_LENGTH_KEY, DEFAULT_MAX_PAGERSHOW_LENGTH);

    setAttr(req, DATA_LIST, ttList);

    return INPUT;
  }