/**
  * 处理取值表达式
  *
  * @param result
  * @param beans
  */
 @SuppressWarnings("unchecked")
 private void dealReplace(List<Map<String, Object>> result, List<Map<String, Object>> beans) {
   for (Map<String, Object> bean : beans) {
     try {
       // 获取取值表达式
       String replace = (String) bean.get(CgReportConstant.ITEM_REPLACE);
       if (StringUtil.isEmpty(replace)) {
         continue;
       }
       String[] groups = replace.split(",");
       for (String g : groups) {
         String[] items = g.split("_");
         String v = items[0]; // 逻辑判断值
         String txt = items[1]; // 要转换的文本
         for (Map r : result) {
           String value = String.valueOf(r.get(bean.get(CgReportConstant.ITEM_FIELDNAME)));
           if (value.equalsIgnoreCase(v)) {
             r.put(bean.get(CgReportConstant.ITEM_FIELDNAME), txt);
           }
         }
       }
     } catch (Exception e) {
       // 这里出现异常原因是因为取值表达式不正确
       e.printStackTrace();
       throw new BusinessException("取值表达式不正确");
     }
   }
 }
 /**
  * 装载数据字典
  *
  * @param m 要放入freemarker的数据
  * @param bean 读取出来的动态配置数据
  */
 @SuppressWarnings("unchecked")
 private void loadDic(Map m, Map<String, Object> cgReportMap) {
   String dict_code = (String) cgReportMap.get("dict_code");
   if (StringUtil.isEmpty(dict_code)) {
     m.put(CgReportConstant.FIELD_DICTLIST, new ArrayList(0));
     return;
   }
   List<Map<String, Object>> dicDatas = queryDicBySQL(dict_code);
   m.put(CgReportConstant.FIELD_DICTLIST, dicDatas);
 }
Exemple #3
0
 public static SysThemesEnum toEnum(String style) {
   if (StringUtil.isEmpty(style)) {
     return SHORTCUT_STYLE;
   }
   for (SysThemesEnum item : SysThemesEnum.values()) {
     if (item.getStyle().equals(style)) {
       return item;
     }
   }
   return SHORTCUT_STYLE;
 }
  /**
   * 保存DEMO维护
   *
   * @param demo
   * @param request
   * @return
   * @throws Exception
   */
  @RequestMapping(params = "saveDemo")
  @ResponseBody
  public AjaxJson saveDemo(TSDemo demo, HttpServletRequest request) throws Exception {
    AjaxJson j = new AjaxJson();
    if (!StringUtil.isEmpty(demo.getId())) {
      message = "Demo维护例子: " + demo.getDemotitle() + "被更新成功";
      TSDemo entity = this.systemService.get(TSDemo.class, demo.getId());
      MyBeanUtils.copyBeanNotNull2Bean(demo, entity);

      if (demo.getTSDemo() == null || StringUtil.isEmpty(demo.getTSDemo().getId())) {
        entity.setTSDemo(null);
      }
      this.systemService.saveOrUpdate(entity);
    } else {
      message = "Demo例子: " + demo.getDemotitle() + "被添加成功";
      if (demo.getTSDemo() == null || StringUtil.isEmpty(demo.getTSDemo().getId())) {
        demo.setTSDemo(null);
      }
      this.systemService.save(demo);
    }
    j.setMsg(message);
    return j;
  }
  public String getLang(String lanKey, String langArg) {
    String langContext = StringUtil.getEmptyString();
    if (StringUtil.isEmpty(langArg)) {
      langContext = getLang(lanKey);
    } else {
      String[] argArray = langArg.split(",");
      langContext = getLang(lanKey);

      for (int i = 0; i < argArray.length; i++) {
        String langKeyArg = argArray[i].trim();
        String langKeyContext = getLang(langKeyArg);
        langContext = StringUtil.replace(langContext, "{" + i + "}", langKeyContext);
      }
    }
    return langContext;
  }
  /** 取 o_muti_lang.lang_key 的值返回当前语言的值* */
  public String getLang(String langKey) {
    String language = BrowserUtils.getBrowserLanguage(request);

    if (request.getSession().getAttribute("lang") != null) {
      language = (String) request.getSession().getAttribute("lang");
    }

    String langContext = MutiLangEntity.mutiLangMap.get(langKey + "_" + language);

    if (StringUtil.isEmpty(langContext)) {
      langContext =
          MutiLangEntity.mutiLangMap.get(
              "common.notfind.langkey" + "_" + request.getSession().getAttribute("lang"));
      if ("null".equals(langContext) || langContext == null || langKey.startsWith("?")) {
        langContext = "";
      }
      langContext = langContext + langKey;
    }
    return langContext;
  }
  /**
   * 处理数据字典
   *
   * @param result 查询的结果集
   * @param beans 字段配置
   */
  @SuppressWarnings("unchecked")
  private void dealDic(List<Map<String, Object>> result, List<Map<String, Object>> beans) {
    for (Map<String, Object> bean : beans) {
      String dict_code = (String) bean.get(CgReportConstant.ITEM_DICCODE);
      if (StringUtil.isEmpty(dict_code)) {
        // 不需要处理字典
        continue;
      } else {
        List<Map<String, Object>> dicDatas = queryDicBySQL(dict_code);

        for (Map r : result) {
          String value = String.valueOf(r.get(bean.get(CgReportConstant.ITEM_FIELDNAME)));
          for (Map m : dicDatas) {
            String typecode = String.valueOf(m.get("typecode"));
            String typename = String.valueOf(m.get("typename"));
            if (value.equalsIgnoreCase(typecode)) {
              r.put(bean.get(CgReportConstant.ITEM_FIELDNAME), typename);
            }
          }
        }
      }
    }
  }
  /** 导出execel */
  private boolean exportExecel(
      HttpServletRequest request,
      HttpServletResponse response,
      String title,
      String tagName,
      String[] fields,
      List<Map<String, Object>> list,
      Map<String, Object> params) {
    if (!"1".equals(request.getParameter("export"))) {
      return false;
    }

    if (params == null) {
      params = new HashMap<String, Object>();
    }
    if (StringUtil.isEmpty(tagName)) {
      tagName = title;
    }

    response.setContentType("application/vnd.ms-excel");
    OutputStream fOut = null;
    try {
      // step.4 根据浏览器进行转码,使其支持中文文件名
      String browse = BrowserUtils.checkBrowse(request);
      if ("MSIE".equalsIgnoreCase(browse.substring(0, 4))) {
        response.setHeader(
            "content-disposition",
            "attachment;filename=" + java.net.URLEncoder.encode(title, "UTF-8") + ".xls");
      } else {
        String newtitle = new String(title.getBytes("UTF-8"), "ISO8859-1");
        response.setHeader("content-disposition", "attachment;filename=" + newtitle + ".xls");
      }
      // step.5 产生工作簿对象
      HSSFWorkbook workbook = null;

      List<Map<String, Object>> fieldList = new ArrayList<Map<String, Object>>();
      for (int i = 0; i < fields.length; i++, i++) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("field_txt", fields[i]);
        map.put("field_name", fields[i + 1]);
        fieldList.add(map);
      }

      workbook = cgReportExcelService.exportExcel(tagName, fieldList, list);
      fOut = response.getOutputStream();
      workbook.write(fOut);
      // TODO 增加操作日志
      // systemService.addLog(MsgUtil.getOperationLogMsg("导出成功", title, params),
      // Globals.Log_Type_EXPORT,
      //		Globals.Log_Leavel_INFO);
    } catch (UnsupportedEncodingException e1) {
      e1.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
        fOut.flush();
        fOut.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    return true;
  }