/** * 动态报表数据查询 * * @param configId 配置id-code * @param page 分页页面 * @param rows 分页大小 * @param request * @param response */ @SuppressWarnings("unchecked") @RequestMapping(params = "datagrid") public void datagrid( String configId, String page, String field, String rows, HttpServletRequest request, HttpServletResponse response) { // step.1 根据id获取该动态报表的配置参数 Map<String, Object> cgReportMap = null; try { cgReportMap = graphReportService.queryCgReportConfig(configId); if (cgReportMap.size() <= 0) { throw new CgReportNotFoundException("动态报表配置不存在!"); } } catch (Exception e) { throw new CgReportNotFoundException("查找动态报表配置失败!" + e.getMessage()); } // step.2 获取该配置的查询SQL Map configM = (Map) cgReportMap.get(CgReportConstant.MAIN); String querySql = (String) configM.get(CgReportConstant.CONFIG_SQL); List<Map<String, Object>> items = (List<Map<String, Object>>) cgReportMap.get(CgReportConstant.ITEMS); Map queryparams = new LinkedHashMap<String, Object>(); for (Map<String, Object> item : items) { String isQuery = (String) item.get(CgReportConstant.ITEM_ISQUERY); if (CgReportConstant.BOOL_TRUE.equalsIgnoreCase(isQuery)) { // step.3 装载查询条件 CgReportQueryParamUtil.loadQueryParams(request, item, queryparams); } } // step.4 进行查询返回结果 int p = page == null ? 1 : Integer.parseInt(page); int r = rows == null ? 99999 : Integer.parseInt(rows); List<Map<String, Object>> result = graphReportService.queryByCgReportSql(querySql, queryparams, p, r); long size = graphReportService.countQueryByCgReportSql(querySql, queryparams); dealDic(result, items); dealReplace(result, items); response.setContentType("application/json"); response.setHeader("Cache-Control", "no-store"); PrintWriter writer; try { writer = response.getWriter(); writer.println(CgReportQueryParamUtil.getJson(result, size)); writer.flush(); } catch (IOException e) { e.printStackTrace(); } }
/** * 动态报表展现入口 * * @param id 动态配置ID-code * @param request * @param response */ @RequestMapping(params = "list") public void list(String id, HttpServletRequest request, HttpServletResponse response) { // step.1 根据id获取该动态报表的配置参数 Map<String, Object> cgReportMap = null; try { cgReportMap = graphReportService.queryCgReportConfig(id); } catch (Exception e) { throw new CgReportNotFoundException("动态报表配置不存在!"); } // step.2 获取列表ftl模板路径 FreemarkerHelper viewEngine = new FreemarkerHelper(); // step.3 组合模板+数据参数,进行页面展现 loadVars(cgReportMap); // step.4 页面css js引用 cgReportMap.put(CgAutoListConstant.CONFIG_IFRAME, getHtmlHead(request)); String html = viewEngine.parseTemplate( "/org/jeecgframework/web/graphreport/engine/core/graphreportlist.ftl", cgReportMap); try { response.setContentType("text/html"); response.setHeader("Cache-Control", "no-store"); PrintWriter writer = response.getWriter(); writer.println(html); writer.flush(); } catch (IOException e) { e.printStackTrace(); } }
/** * 查询数据字典 * * @param diccode 字典编码 * @return */ private List<Map<String, Object>> queryDic(String diccode) { StringBuilder dicSql = new StringBuilder(); dicSql.append(" SELECT TYPECODE,TYPENAME FROM"); dicSql.append(" " + CgReportConstant.SYS_DIC); dicSql.append(" " + "WHERE TYPEGROUPID = "); dicSql.append( " " + "(SELECT ID FROM " + CgReportConstant.SYS_DICGROUP + " WHERE TYPEGROUPCODE = '" + diccode + "' )"); List<Map<String, Object>> dicDatas = graphReportService.findForJdbc(dicSql.toString()); return dicDatas; }
/** * 解析SQL,返回字段集 * * @param sql * @return */ @SuppressWarnings("unchecked") @RequestMapping(params = "getFields", method = RequestMethod.POST) @ResponseBody public Object getSqlFields(String sql) { List<String> result = null; Map reJson = new HashMap<String, Object>(); try { result = graphReportService.getSqlFields(sql); } catch (Exception e) { e.printStackTrace(); String errorInfo = "解析失败!<br><br>失败原因:"; errorInfo += e.getMessage(); reJson.put("status", "error"); reJson.put("datas", errorInfo); return reJson; } reJson.put("status", "success"); reJson.put("datas", result); return reJson; }
/** * 动态报表数据查询(不分页) * * @param configId 配置id-code * @param request * @param response */ @SuppressWarnings("unchecked") @RequestMapping(params = "datagridGraph") public void datagridGraph( String configId, HttpServletRequest request, HttpServletResponse response) { // step.1 根据id获取该动态报表的配置参数 Map<String, Object> cgReportMap = null; try { cgReportMap = graphReportService.queryCgReportConfig(configId); if (cgReportMap.size() <= 0) { throw new CgReportNotFoundException("动态报表配置不存在!"); } } catch (Exception e) { throw new CgReportNotFoundException("查找动态报表配置失败!" + e.getMessage()); } try { // step.2 获取该配置的查询SQL Map configM = (Map) cgReportMap.get(CgReportConstant.MAIN); String querySql = (String) configM.get("CGR_SQL"); List<Map<String, Object>> items = (List<Map<String, Object>>) cgReportMap.get(CgReportConstant.ITEMS); Map queryparams = new LinkedHashMap<String, Object>(); for (Map<String, Object> item : items) { String isQuery = (String) item.get(CgReportConstant.ITEM_ISQUERY); if (CgReportConstant.BOOL_TRUE.equalsIgnoreCase(isQuery)) { // step.3 装载查询条件 CgReportQueryParamUtil.loadQueryParams(request, item, queryparams); } } // step.4 进行查询返回结果 List<Map<String, Object>> result = graphReportService.queryByCgReportSql(querySql, queryparams, -1, -1); dealDic(result, items); dealReplace(result, items); // 导出execel List<String> fields = new ArrayList<String>(); List<Map<String, Object>> configItems = (List<Map<String, Object>>) cgReportMap.get(CgReportConstant.ITEMS); for (Map<String, Object> map : configItems) { if ("Y".equals(map.get("is_show"))) { fields.add(map.get("field_txt").toString()); fields.add(map.get("field_name").toString()); } } if (exportExecel( request, response, configM.get("content").toString(), configM.get("content").toString(), fields.toArray(new String[fields.size()]), result, null)) { return; } response.setContentType("application/json"); response.setHeader("Cache-Control", "no-store"); PrintWriter writer; writer = response.getWriter(); writer.println(CgReportQueryParamUtil.getJson(result, -1L)); writer.flush(); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException(e); } }