@RequestMapping("/metric.do") public String metric( @RequestParam(value = "key", defaultValue = "") String key, @RequestParam(value = "theme", defaultValue = THEME_DEFAULT) String theme, @RequestParam("metricName") String metricName, @RequestParam(value = "refresh", defaultValue = "0") String refresh, @RequestParam(value = "p", defaultValue = "") String param, Model model, HttpServletRequest req, HttpServletResponse resp) { LOG.info("[metric] " + metricName + ",params:" + param); model.addAttribute("theme", getTheme(theme)); if (null == key || "".equals(key)) { model.addAttribute("error", "密钥不能为空!"); } else { key = getKey(key); User user = userService.getUserByKey(key); if (null != user) { if ("".equals(user.getKey())) { model.addAttribute("error", "密钥已失效!"); } else { Map<String, String> params = generateParams(param); WebMetricInfo metricInfo = webMetricService.getWebMetric(metricName, params, user); if (null != metricInfo) { model.addAttribute("metricInfo", metricInfo); model.addAttribute("metricInfoJson", JSON.toJSONString(metricInfo)); model.addAttribute("user", user); model.addAttribute("refresh", refresh); model.addAttribute("p", param); return "metric"; } else { // model.addAttribute("error", "没有找到对应的指标"); // return "error"; throw new RuntimeException("没有找到指标名称为\"" + metricName + "\"对应的指标数据"); } } } else { model.addAttribute("error", "没有找到密钥对应的用户。密钥:" + key); } } model.addAttribute("referer", req.getRequestURI() + "?" + req.getQueryString()); return "login"; }
@RequestMapping("/metricScript.do") public @ResponseBody String metricScript( @RequestParam(value = "key", defaultValue = "") String key, @RequestParam("metricName") String metricName, @RequestParam(value = "p", defaultValue = "") String param, HttpServletRequest req, HttpServletResponse resp) { resp.setContentType("application/javascript;charset=UTF-8"); key = getKey(key); User user = userService.getUserByKey(key); String error = userService.check(user); if (!"".equals(error)) { return "NEED_LOGIN:"******"m", m); WebMetricInfo metricInfo = webMetricService.getWebMetric(metricName, params, user); if (null != metricInfo) { return "function tmpFun(){" + metricInfo.getTemplateScript() + "}; tmpFun();"; } else { return ""; } }