@Override @Success(path = "/WEB-INF/pages/freeze/team/viewModify.jsp") @Fail(path = "/WEB-INF/pages/freeze/team/viewModify.jsp") public String modify(HttpServletRequest req, HttpServletResponse resp) { int id = param(req, "id", 0); String headimage = param(req, "headimage"); int start = param(req, "start", 0); int end = param(req, "end", 0); Team model = new Team(); model = model.get(id); User user = new User(); setAttr(req, PAGE_TEAM_USER_LIST_KEY, user.listAll(" order by username desc")); if (StringUtils.equals(headimage, model.getHeadimage()) && start == model.getStart() && end == model.getEnd()) { setAttr(req, TIP_NAME_KEY, "无任何变更"); setAttr(req, MODEL, model); return FAIL; } model.setHeadimage(headimage); model.setStart(start); model.setEnd(end); setAttr(req, MODEL, model); if (StringUtils.isBlank(headimage)) { setAttr(req, TIP_NAME_KEY, "请先上传用户头像"); return FAIL; } if (start == 0) { setAttr(req, TIP_NAME_KEY, "请选择任期开始时间"); return FAIL; } if (end == 0) { setAttr(req, TIP_NAME_KEY, "请选择任期结束时间"); return FAIL; } if (start > end) { setAttr(req, TIP_NAME_KEY, "任期开始时间必须小于结束时间"); model.setEnd(start); return FAIL; } if (model.save() > 0) { setAttr(req, TIP_NAME_KEY, "编辑管理团队成员成功"); return SUCCESS; } else { setAttr(req, TIP_NAME_KEY, "编辑管理团队成员失败"); return FAIL; } }
@Override @Result("/WEB-INF/pages/freeze/team/viewModify.jsp") public String viewModify(HttpServletRequest req, HttpServletResponse resp) { int id = param(req, "id", 0); Team model = new Team(); model = model.get(id); User user = new User(); setAttr(req, MODEL, model); setAttr(req, PAGE_TEAM_USER_LIST_KEY, user.listAll(" order by username desc")); return INPUT; }
@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); }
@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; }
@Override @Success(path = "/WEB-INF/pages/freeze/team/viewAdd.jsp") @Fail(path = "/WEB-INF/pages/freeze/team/viewAdd.jsp") public String add(HttpServletRequest req, HttpServletResponse resp) { int userID = param(req, "userID", -1); String headimage = param(req, "headimage"); int start = param(req, "start", 0); int end = param(req, "end", 0); Team model = new Team(); model.setUserID(userID); model.setHeadimage(headimage); 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); if (StringUtils.isBlank(headimage)) { setAttr(req, TIP_NAME_KEY, "请上传用户头像"); return FAIL; } if (userID == -1) { setAttr(req, TIP_NAME_KEY, "请选择用户"); return FAIL; } if (model.existProperty("userID", userID)) { setAttr(req, TIP_NAME_KEY, "此用户已在管理团队中,如需要更改请选择编辑功能"); return FAIL; } if (start == 0) { setAttr(req, TIP_NAME_KEY, "请选择任期开始时间"); return FAIL; } if (end == 0) { setAttr(req, TIP_NAME_KEY, "请选择任期结束时间"); return FAIL; } if (start > end) { setAttr(req, TIP_NAME_KEY, "任期开始时间必须小于结束时间"); model.setEnd(start); return FAIL; } if (model.save() > 0) { setAttr(req, TIP_NAME_KEY, "添加管理团队成员成功"); model.setUserID(-1); model.setHeadimage(""); model.setStart(0); model.setEnd(0); return SUCCESS; } else { setAttr(req, TIP_NAME_KEY, "添加管理团队成员失败"); return FAIL; } }