@Result(success = "/WEB-INF/pages/user/filter.jsp", fail = "/WEB-INF/pages/user/viewSetRule.jsp") public String setRule(HttpServletRequest req, HttpServletResponse resp) { String[] usernames = params(req, "usernames"); StringBuilder usernameStr = new StringBuilder(); for (int i = 0; i < usernames.length; i++) { if (i == usernames.length - 1) usernameStr.append(usernames[i]); else usernameStr.append(usernames[i] + ","); } String pattern = param(req, "pattern"); // 操作不完整时返回到输入必须 String ids = param(req, "userIds"); setAttr(req, USER_IDS, ids); String[] userIds = ids.split(","); if (StringUtils.isBlank(pattern)) { setAttr(req, TIP_NAME_KEY, "请选择规则模式"); this.viewSetRule(req, resp); return FAIL; } // 用户规则的保存 int totalRequire = usernames.length; int realSave = 0; for (String u : userIds) { UserRule model = new UserRule(); Integer userid = Integer.valueOf(u); // 存在即加载数据 model.isExist(userid); model.setUserid(userid); model.setPattern(pattern); if (model.save() > 0) realSave += 1; } if (totalRequire == realSave) { setAttr(req, TIP_NAME_KEY, "为[" + usernameStr.toString() + "]设置规则[" + pattern + "]成功"); this.filter(req, resp); return SUCCESS; } else { setAttr(req, TIP_NAME_KEY, "设置规则部分失败"); this.viewSetRule(req, resp); return FAIL; } }
@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; }