Exemplo n.º 1
0
 /**
  * 动态报表数据查询
  *
  * @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();
   }
 }
Exemplo n.º 2
0
  /**
   * 组装模版参数
   *
   * @param cgReportMap
   */
  @SuppressWarnings("unchecked")
  private void loadVars(Map<String, Object> cgReportMap) {
    Map mainM = (Map) cgReportMap.get(CgReportConstant.MAIN);
    List<Map<String, Object>> fieldList =
        (List<Map<String, Object>>) cgReportMap.get(CgReportConstant.ITEMS);
    List<Map<String, Object>> queryList = new ArrayList<Map<String, Object>>(0);
    // 图表数据
    List<Map<String, Object>> graphList = new ArrayList<Map<String, Object>>(0);
    // tab数据
    Set<String> tabSet = new HashSet<String>();
    List<String> tabList = new ArrayList<String>();

    for (Map<String, Object> fl : fieldList) {
      fl.put(
          CgReportConstant.ITEM_FIELDNAME,
          ((String) fl.get(CgReportConstant.ITEM_FIELDNAME)).toLowerCase());
      String isQuery = (String) fl.get(CgReportConstant.ITEM_ISQUERY);
      if (CgReportConstant.BOOL_TRUE.equalsIgnoreCase(isQuery)) {
        loadDic(fl, fl);
        queryList.add(fl);
      }
      if ("y".equals(fl.get("is_graph")) || "Y".equals(fl.get("is_graph"))) {
        graphList.add(fl);
        String tabName = (fl.get("tab_name") == null ? "" : fl.get("tab_name").toString());
        if (!tabSet.contains(tabName)) {
          tabList.add(tabName);
          tabSet.add(tabName);
        }
      }
    }
    cgReportMap.put(CgReportConstant.CONFIG_ID, mainM.get("code"));
    cgReportMap.put(CgReportConstant.CONFIG_NAME, mainM.get("name"));
    cgReportMap.put(CgReportConstant.CONFIG_FIELDLIST, fieldList);
    cgReportMap.put(CgReportConstant.CONFIG_QUERYLIST, queryList);
    cgReportMap.put("graphList", graphList);
    cgReportMap.put("tabList", tabList);
  }
Exemplo n.º 3
0
  /**
   * 动态报表数据查询(不分页)
   *
   * @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);
    }
  }