@SuppressWarnings("unchecked") @Result(success = "/WEB-INF/pages/user/viewSetRule.jsp", fail = "/WEB-INF/pages/user/filter.jsp") public String viewSetRule(HttpServletRequest req, HttpServletResponse resp) { String[] ids = StringUtils.isBlank((String) getAttr(req, USER_IDS)) ? params(req, "userIds") : (((String) getAttr(req, USER_IDS)).split(",")); StringBuilder userIds = new StringBuilder(); for (int i = 0; i < ids.length; i++) { System.out.println("id:" + ids[i]); if (i != ids.length - 1) userIds.append(ids[i] + ','); else userIds.append(ids[i]); } if (ids.length == 0) { setAttr(req, TIP_NAME_KEY, "请选择要设置规则的用户"); this.filter(req, resp); return FAIL; } // 规则列表 Rule rule = new Rule(); List<Rule> ruleList = (List<Rule>) rule.listAll(); // 根据id获取用户列表 List<User> userList = new ArrayList<User>(); for (String s : ids) { User user = new User(); Integer id = Integer.valueOf(s); user = (User) user.get(id); userList.add(user); } setAttr(req, RULE_LIST, ruleList); setAttr(req, USER_LIST, userList); setAttr(req, USER_IDS, userIds.toString()); return SUCCESS; }
@SuppressWarnings("unchecked") @Result(success = "/WEB-INF/pages/user/show.jsp") @Override public String show(HttpServletRequest req, HttpServletResponse resp) { long id = Long.parseLong(param(req, "id")); User model = new User(); model.setId(id); model = model.get(id); setAttr(req, MODEL, model); // 用户规则 StringBuilder filter = new StringBuilder(); filter.append(" where userid=" + id + ""); UserRule userrule = new UserRule(); List<UserRule> list = (List<UserRule>) userrule.filter(filter.toString()); UserRule newUserrule = list.size() > 0 ? list.get(0) : userrule; Rule rule = new Rule(); boolean ruleExist = rule.isExist(newUserrule.getPattern()); String pattern = list.size() > 0 ? list.get(0).getPattern() : NOT_CONFIG_USERRULE; setAttr(req, PATTERN, pattern); setAttr(req, NOT_CONFIG_USERRULE_KEY, NOT_CONFIG_USERRULE); setAttr(req, RULE_VERTIFY_VALUE, pattern.equals(NOT_CONFIG_USERRULE) ? true : ruleExist); return SUCCESS; }