类 DataUtil

java.lang.Object
com.sh.wf.module.util.DataUtil

public class DataUtil extends Object

Description:

Title:首亨软件 - TSS/CRM等

从以下版本开始:
2015年3月18日
  • 构造器详细资料

    • DataUtil

      public DataUtil()
  • 方法详细资料

    • refreshUser

      public static void refreshUser(DataCenter dc, String userId, boolean updatePwd)
      刷新用户信息,修改用户信息后操作
      参数:
      dc - DataCenter
      userId - String
      updatePwd - 是否修改了密码,修改了密码会触发修改密码的事件
    • convertMapProvider

      public static String[] convertMapProvider(String provider, String aimProvider, String lat, String lng)
      参数:
      provider - 坐标系 wgs84/gcj02/bd09
      provider - String
      aimProvider - String
      lat - String
      lng - String
      返回:
      [lat,lng]
    • getHtmlText

      public static String getHtmlText(String html)
      获取HTML代码中的文本值
      参数:
      html - String
      返回:
      String
    • getExportHtmlText

      public static String getExportHtmlText(String html)
      获取HTML代码中的文本值
      参数:
      html - String
      返回:
      String
    • getImageTag

      public static List<String> getImageTag(String html)
      获取图片标签的URL
      参数:
      html -
      返回:
    • checkResUrlAndReturnWWWUrl

      public static String checkResUrlAndReturnWWWUrl(String path)
      检查资源服务嚣路径,并转化为外网路径
      参数:
      path - String
      返回:
      String
    • checkResUrlAndReturnInnerUrl

      public static String checkResUrlAndReturnInnerUrl(String path)
      检查URL路径,并转化为内网路径
      参数:
      path - String
      返回:
      String
    • converInt2ColorStr

      public static String converInt2ColorStr(String s, String defaultColor)
      将10进制的颜色值转化为16进制的颜色值
      参数:
      s - String
      defaultColor - String
      返回:
      String
    • converInt2ColorStr

      public static String converInt2ColorStr(String s, String defaultColor, int color)
      将10进制的颜色值转化为16进制的颜色值
      参数:
      s - String
      defaultColor - String
      color - 忽略颜色
      返回:
      String
    • convertColorStr2Int

      public static int convertColorStr2Int(String colorStr, int defaultValue)
      将16进制颜色字符串转化为16进制整数值
      参数:
      colorStr - String
      defaultValue - int
      返回:
      int
    • convertColor2Hex

      public static String convertColor2Hex(Color color)
      将Color对象转化为16进制值
      参数:
      color -
      返回:
    • getPageColor

      public static String getPageColor(String colorValue)
      将16进制颜色值转为页面可识别#开头的颜色值
      参数:
      colorValue - 颜色值
      返回:
      String
    • convertString2Default

      public static String convertString2Default(String str, String defaultValue)
      如果将字符串为空或null时转化为默认值
      参数:
      str - String
      defaultValue - String
      返回:
      String
    • getJSONStringValue

      public static String getJSONStringValue(JSONObject obj, String key)
    • getJSONStringValue

      public static String getJSONStringValue(JSONObject obj, String key, String defaultValue)
    • getJSONIntValue

      public static int getJSONIntValue(JSONObject obj, String key, int defaultValue)
    • convertString2Boolean

      public static boolean convertString2Boolean(String str, boolean defaultValue)
    • convertString2Double

      public static double convertString2Double(String str, double defaultValue)
    • convert2Double

      public static double convert2Double(Object obj, double defaultValue)
    • convertString2Short

      public static short convertString2Short(String str, short defaultValue)
    • convertString2Number

      public static Number convertString2Number(String str, Number defaultValue)
    • convertString2Int

      public static int convertString2Int(String str, int defaultValue)
    • convert2Int

      public static int convert2Int(Object obj, int defaultValue)
    • convertString2Long

      public static long convertString2Long(String str, long defaultValue)
    • toContextRequestValue

      public static String toContextRequestValue(ModuleContext context, String objName)
    • parserContextRequestValue

      public static void parserContextRequestValue(ModuleContext context)
    • convert2HtmlKeyword

      public static String convert2HtmlKeyword(String str)
      将字符串转换为HTML的属性值,主要是去掉引号特殊字符
      参数:
      str - String
      返回:
      String
    • getLinkCellStyle

      public static org.apache.poi.ss.usermodel.CellStyle getLinkCellStyle(ModuleContext context, org.apache.poi.ss.usermodel.Workbook book, org.apache.poi.ss.usermodel.Cell cell, Td td)
      设置超链接样式
      参数:
      context - ModuleContext
      book - Workbook
      cell - Cell
      td - Td
      返回:
      CellStyle
    • getLinkCellStyle

      public static org.apache.poi.ss.usermodel.CellStyle getLinkCellStyle(ModuleContext context, org.apache.poi.ss.usermodel.Workbook book, org.apache.poi.ss.usermodel.Cell cell)
    • getHeaderCellStyle

      public static org.apache.poi.ss.usermodel.CellStyle getHeaderCellStyle(org.apache.poi.ss.usermodel.Workbook book, org.apache.poi.ss.usermodel.Cell cell)
      设置表头样式
      参数:
      book - Workbook
      cell - Cell
      返回:
      CellStyle
    • getHeaderCellStyle

      public static org.apache.poi.ss.usermodel.CellStyle getHeaderCellStyle(ModuleContext context, org.apache.poi.ss.usermodel.Workbook book, org.apache.poi.ss.usermodel.Cell cell)
      设置表头样式
      参数:
      context - ModuleContext
      book - Workbook
      cell - Cell
      返回:
      CellStyle
    • getCellStyle

      public static org.apache.poi.ss.usermodel.CellStyle getCellStyle(org.apache.poi.ss.usermodel.Workbook book, org.apache.poi.ss.usermodel.Cell cell, Td td)
      设置普通单元格样式
      参数:
      book - Workbook
      cell - Cell
      td - Td
      返回:
      CellStyle
    • getCellStyle

      public static org.apache.poi.ss.usermodel.CellStyle getCellStyle(ModuleContext context, org.apache.poi.ss.usermodel.Workbook book, org.apache.poi.ss.usermodel.Cell cell, Td td)
      设置普通单元格样式
      参数:
      context - ModuleContext
      book - Workbook
      cell - Cell
      td - Td
      返回:
      CellStyle
    • getCellStyle

      public static org.apache.poi.ss.usermodel.CellStyle getCellStyle(org.apache.poi.ss.usermodel.Workbook book, org.apache.poi.ss.usermodel.Cell cell)
    • processRequestParam

      public static String processRequestParam(ModuleContext context, String obj, String hasStr)
      将request中的参数进行传递
      参数:
      context - ModuleContext
      obj - String
      hasStr - String
      返回:
      String
    • isValidParamName

      public static boolean isValidParamName(String str)
      判断是否有效的变量名
      参数:
      str -
      返回:
    • decodeRequestParamValue

      public static String decodeRequestParamValue(String paramValue)
      对REQUEST中接收的参数进行解码
      参数:
      paramValue - String
      返回:
      String
    • encodeUrlParam

      public static String encodeUrlParam(String paramValue)
      转化URL变量值
      参数:
      paramValue - String
      返回:
      String
    • encodeUrlFull

      public static String encodeUrlFull(String url)
      将URL中的所有中文进行编码
      参数:
      url -
      返回:
    • encodeJsStr

      public static String encodeJsStr(String str)
      对参数变量进行加密,加密后在页面通过 module.decode(str)来进行解密
      参数:
      str -
      返回:
      简单加密
    • getRequestValue

      public static String getRequestValue(jakarta.servlet.http.HttpServletRequest request, String paramName)
    • getRequestValue

      public static String getRequestValue(jakarta.servlet.http.HttpServletRequest request, String paramName, boolean isEncode)
      获取HttpServletRequest中的值,已进行了转码
      参数:
      request - HttpServletRequest
      paramName - String
      isEncode - boolean
      返回:
      String
    • getRequestValues

      public static String[] getRequestValues(ModuleContext context, String paramName)
    • findParentComponent

      public static Component findParentComponent(Component component, String type)
      通过类型查找父级组件
      参数:
      component - Component
      type - String
      返回:
      Component
    • convertShowType

      public static String convertShowType(String showType, String value)
      转化显示方式
      参数:
      showType - String
      value - String
      返回:
      String
    • getLoadFuncName

      public static String getLoadFuncName(ModuleContext context, String paramName)
      获取异步调用的方法名参数,因为对于第一次加载的时候,需要从request.getAttribute中获取
      参数:
      context - ModuleContext
      paramName - String
      返回:
      String
    • removeSessionByKey

      public static void removeSessionByKey(jakarta.servlet.http.HttpSession session, String startKey)
      删除以指定字符串开头的session值
      参数:
      session - HttpSession
      startKey - String
    • getFileByte

      public static byte[] getFileByte(String src)
      获取图片二进制文件
      参数:
      src - String
      返回:
      byte[]
    • checkAttrSaveLine

      public static String checkAttrSaveLine(String attr)
    • checkAttrValue

      public static String checkAttrValue(String attr)
    • checkAttrValue

      public static String checkAttrValue(String attr, String defaultValue)
      表达式在进行解析前先调用的方法
      参数:
      attr - String
      defaultValue - String
      返回:
      String
    • checkAttrValue_reversal

      public static String checkAttrValue_reversal(String attr)
    • checkKeyword

      public static String checkKeyword(String str)
      特殊符号转义字符
      参数:
      str - String
      返回:
      String
    • isDsName

      public static boolean isDsName(ModuleContext context, String dsName)
      判断是否ds名称
      参数:
      context - ModuleContext
      dsName - String
      返回:
      boolean
    • getIconByMimeType

      public static String getIconByMimeType(ModuleContext context, String mimeType, String src, boolean mtShowPic, boolean inRes)
      根据文件类型获取显示的图标路径
      参数:
      context - 模块上下文
      mimeType - 文件类型
      src - 图片地址
      mtShowPic - 如果为图片时是否直接显示图片
      inRes - 图片是否保存在资源服务器上
      返回:
      String
    • isDouble

      public static boolean isDouble(String str)
      判断是否为double类型
      参数:
      str - String
      返回:
      boolean
    • checkScriptAttrStrYinghao

      public static String checkScriptAttrStrYinghao(String str)
      处理动态生成的脚本中的双引号属性,换行符转化为空格
      参数:
      str - String
      返回:
      String
    • removeEnterCharacter

      public static String removeEnterCharacter(String str)
      删除失败行符、水平制表符
      参数:
      str -
      返回:
    • convertLocalHttpImg

      public static String convertLocalHttpImg(jakarta.servlet.http.HttpServletRequest request, String path)
    • checkScriptAttrStrYinghaoHtml

      public static String checkScriptAttrStrYinghaoHtml(String str)
      处理动态生成的脚本中的双引号属性
      参数:
      str - String
      返回:
      String
    • checkScriptAttrStrDanYinghao

      public static String checkScriptAttrStrDanYinghao(String str)
      处理动态生成的脚本中的单引号属性,换行符会转化为空格
      参数:
      str - String
      返回:
      String
    • checkScriptAttrStrDanYinghaoHtml

      public static String checkScriptAttrStrDanYinghaoHtml(String str)
      处理动态生成的脚本中的单引号属性
      参数:
      str - String
      返回:
      String
    • checkHtml_attr_Yinghao

      public static String checkHtml_attr_Yinghao(String str)
    • checkHtml_attr_href_yinghao

      public static String checkHtml_attr_href_yinghao(String str)
      检查html 的a标签的href
      参数:
      str - String
      返回:
      String
    • checkHtmlAttr

      public static String checkHtmlAttr(String str)
      转换str到html的属性字符串,主要是防止xss漏洞
      参数:
      str - String
      返回:
      String
    • checkHtmlAttr_full

      public static String checkHtmlAttr_full(String str)
    • isMobileHttp

      public static boolean isMobileHttp(String userAgent)
      检测是否是移动设备访问
      参数:
      userAgent - 浏览器标识
      返回:
      true:移动设备接入,false:pc端接入
    • getResUrl

      public static String getResUrl(jakarta.servlet.http.HttpServletRequest request, String url)
      获取资源服务器转化为的URL
      参数:
      request - HttpServletRequest
      url - String
      返回:
      String
    • getResBaseUrl

      public static String getResBaseUrl(jakarta.servlet.http.HttpServletRequest request)
    • containValue

      public static boolean containValue(String[] array, String key)
    • isHttpImageTrue

      public static boolean isHttpImageTrue(String source)
      判断网络图片是否有效
      参数:
      source - String
      返回:
      boolean
    • convert2JsonStr

      public static String convert2JsonStr(String str)
      将字符串转化为json要求的字符串
      参数:
      str - String
      返回:
      String
    • cloneObj

      public static Object cloneObj(Object sourceObj)
      克隆对象
      参数:
      sourceObj - Object
      返回:
      Object
    • getDBDate

      public static String getDBDate(DataCenter dc, String format)
      获取数据库时间
      参数:
      dc - DataCenter
      format - String
      返回:
      String
    • getDBTimestamp

      public static Timestamp getDBTimestamp(DataCenter dc)
      获取数据库时间
      参数:
      dc - DataCenter
      返回:
      Timestamp
    • getDataCenter

      public static DataCenter getDataCenter(String dcType)
      根据数据类型获取连接 ,不会为Null
      参数:
      dcType - String
      返回:
      DataCenter
    • getDataCenterByDcType

      public static DataCenter getDataCenterByDcType(String dcType)
      通过dc获取数据,可能为null
      参数:
      dcType -
      返回:
    • closeDataCenter

      public static void closeDataCenter(ModuleContext context)
      关闭数据库连接
      参数:
      context - ModuleContext
    • convertBaiduMapGeoConv

      public static void convertBaiduMapGeoConv(Datastore ds, String provider, String lngCol, String latCol, String newLngCol, String newLatCol)
      将其他坐标系转换为百度坐标系
      参数:
      ds - Datastore
      provider - String
      lngCol - String
      latCol - String
      newLngCol - String
      newLatCol - String
    • generateNavigateSelectPageRows

      public static String generateNavigateSelectPageRows(int pageRows)
      生成页面分页标签可选择的每页记录数
      参数:
      pageRows - int
      返回:
      String
    • getMaxNavigateSelectPageRows

      public static int getMaxNavigateSelectPageRows()
      获取页面能获取到的最大页数
      返回:
      int
    • checkIsSQLInlineQuery

      public static String checkIsSQLInlineQuery(String sql)
    • checkAndSplitOrderby

      public static String[] checkAndSplitOrderby(String sql)
      判断并分离排序列
      参数:
      sql - String
      返回:
      String
    • isValidToken

      public static boolean isValidToken(ModuleContext context, String token)
    • isValidToken

      public static boolean isValidToken(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, UserInfo userInfo, String token)
    • convertFilseSizeStr

      public static String convertFilseSizeStr(double size)
      将文件大小进行转换
      参数:
      size - 文件大小 单位:字节
      返回:
      如:1024 转化为1kb
    • timeAgo

      public static String timeAgo(int sec)
      某个时间在当前时间的多久前
      参数:
      sec - 秒
      返回:
      多久前
    • checkJVMFont_simsun

      public static void checkJVMFont_simsun()
      检查是否包含宋体
    • copyClasspathFile

      public static void copyClasspathFile(String classpathFilePath, String dimPath)
      将资源路class路径下的文件复制到 指定目录
      参数:
      classpathFilePath - String
      dimPath - String
    • copyFile

      public static File copyFile(InputStream sourceInputStream, String aimFilePath) throws Exception
      拷贝文件,将文件从sourceFilePath 拷贝至aimFilePath
      参数:
      sourceInputStream - 文件流
      aimFilePath - 目的文件地址 如:D:/AIM/test.txt
      返回:
      File
      抛出:
      Exception - Exception
    • formatXml

      public static String formatXml(String xml)
      格式化xml
      参数:
      xml - String
      返回:
      String
    • getLayuiButtonIconColor

      public static String getLayuiButtonIconColor(String buttonStyle)
      根据样式获取图标的颜色
      参数:
      buttonStyle - String
      返回:
      String
    • getLayuiButtonIconColorOnly

      public static String getLayuiButtonIconColorOnly(String buttonStyle)
      根据样式获取图标的颜色
      参数:
      buttonStyle - String
      返回:
      String
    • getLayuiButtonSize

      public static String getLayuiButtonSize(String sizeClass)
      由于layui2.2.0后的版本对这个样式有调整,所以这里自动转化
      参数:
      sizeClass - String
      返回:
      String
    • checkXSSHtmlString

      public static String checkXSSHtmlString(String value)
      检查并转换XSS字符串,防止跨站脚本
      参数:
      value - String
      返回:
      String
    • restoreCheckXSSHtmlString

      public static String restoreCheckXSSHtmlString(String value)
    • checkXSSJavaScriptString

      public static String checkXSSJavaScriptString(String value)
    • checkXSSSqlString

      @Deprecated public static String checkXSSSqlString(String value)
      已过时。
    • atLeatOneNotEmpty

      public static boolean atLeatOneNotEmpty(String... args)
      判断至少有一个非空的参数
      参数:
      args -
      返回:
    • checkIsNormalVar

      public static boolean checkIsNormalVar(String str)
      判断是否是基本变量,只能包含:数字、字母、下划线、中划线
      参数:
      str - String
      返回:
      boolean
    • checkIsNormalVar

      public static boolean checkIsNormalVar(String str, boolean defaultValue)
    • checkIsValidTableCol

      public static boolean checkIsValidTableCol(String str)
      判断是否是有效的表列
      参数:
      str - String
      返回:
      boolean
    • getCharCount

      public static int getCharCount(String str, char c)
      获取字符串中的字符个数
      参数:
      str - String
      c - char
      返回:
      int
    • getSimHashSimilarity

      public static double getSimHashSimilarity(String text1, String text2)
      获取两字符串的匹配度,目前 使用HanLP分词实现
      参数:
      text1 - String
      text2 - String
      返回:
      double
    • getCosineSimilarity

      public static double getCosineSimilarity(String text1, String text2)
      获得两个句子的相似度 TF-IDF与余弦相似性 适合于短文本计算相似性 https://blog.csdn.net/egg1996911/article/details/81774456 http://www.ruanyifeng.com/blog/2013/03/cosine_similarity.html
      参数:
      text1 - String
      text2 - String
      返回:
      double
    • checkESColumn

      public static String checkESColumn(DsInfo dsInfo, String column)
      检查es列名合法性,因为有 _source_开头的前缀
      参数:
      dsInfo - DsInfo
      column - String
      返回:
      String
    • checkAndSetSortType

      public static String checkAndSetSortType(String sortType)
      检查sort的有效性
      参数:
      sortType - String
      返回:
      String
    • replaceWhereCondition

      public static String replaceWhereCondition(DataCenter dc, String sql, String where)
      替换掉SQL条件
      参数:
      dc - 数据连接
      sql - SQL语句
      where - 替换查询条件
      返回:
      String
    • storeContextDsKey

      public static String storeContextDsKey(String sql, String[] colsType, Object[] obj)
    • storeContextDs

      public static void storeContextDs(ModuleContext context, Datastore ds, String sql, String[] colsType, Object[] obj)
    • getStoreContextDs

      public static Datastore getStoreContextDs(ModuleContext context, String sql, String[] colsType, Object[] obj)
    • checkFormValueValid

      public static String[] checkFormValueValid(ModuleContext context, Map<String,String> attrMap, Component component, String paramName)
      检查表单是否合法
      参数:
      context - ModuleContext
      attrMap - Map
      component - Component
      paramName - String
      返回:
      String[]
    • isJSONValid

      public static boolean isJSONValid(String str)
      判断是否有效的JSON字符串
      参数:
      str - String
      返回:
      boolean
    • isJSONObjectValid

      public static boolean isJSONObjectValid(String str)
    • isJSONArrayValid

      public static boolean isJSONArrayValid(String str)
    • checkAndConvertNormalVariable

      public static String checkAndConvertNormalVariable(String str)
      过滤关键字,一般是变量名的问题
      参数:
      str -
      返回:
    • checkAndResetFuncNameVariable

      public static String checkAndResetFuncNameVariable(String funcName)
      判断函数变量名,只能是字母、数字、-、_
      参数:
      funcName -
      返回:
    • checkAndResetNormalVariable

      public static String checkAndResetNormalVariable(String funcName)
    • checkAndClearHtmlJavascript

      public static String checkAndClearHtmlJavascript(String html)
      清除html代码中的Javascript代码
      参数:
      html -
      返回:
    • toResUrl

      public static String toResUrl(String url)
    • toResUrl

      public static String toResUrl(jakarta.servlet.http.HttpServletRequest request, String url)
      将URL转换为资源服务器路径
      参数:
      request -
      url -
      返回:
    • toResInnerUrl

      public static String toResInnerUrl(String url)
    • getClientIP

      public static String getClientIP(jakarta.servlet.http.HttpServletRequest request)
      获取访问客户端的IP
      参数:
      request - HttpServletRequest
      返回:
      String
    • isJsContentContainAwait

      public static boolean isJsContentContainAwait(String content)
      判断JS内容中是否包含 await 关键字
      参数:
      content -
      返回:
    • checkComponetAttrMapLanguage

      public static void checkComponetAttrMapLanguage(ModuleContext context, Map<String,String> attrMap)
    • isFileNameValid

      public static boolean isFileNameValid(String name)
      判断文件是否有效
      参数:
      name -
      返回:
    • isFilePathValid

      public static boolean isFilePathValid(String path)
      判断文件路径是否合法
      参数:
      path -
      返回:
    • checkReferer

      public static boolean checkReferer(ModuleContext context)
      检查Referer的合法性
      参数:
      context -
      返回:
    • getDsColTypeByObjectValue

      public static String getDsColTypeByObjectValue(Object obj)
      根据传入的值自动获取Datastore数据类型
      参数:
      obj -
      返回:
    • calWidthByStr

      public static int calWidthByStr(ModuleContext context, String str)
      计算字符串占用的页面宽度
      参数:
      context -
      str -
      返回:
    • endsWithIgnoreCase

      public static boolean endsWithIgnoreCase(String str, String end)
      不区分大小写判断是否以指定字符串结尾
      参数:
      str -
      end -
      返回:
    • checkIsSqlInjection

      public static boolean checkIsSqlInjection(ModuleContext context, String str)
      判断该值是否为SQL注入的参数值
      参数:
      context -
      str -
      返回:
    • appendCssClass

      public static String appendCssClass(String str, String clazz)
      追加CSS的样式
      参数:
      str -
      clazz -
      返回:
    • autoParseTimePattern

      public static String autoParseTimePattern(String str)
      自动提示时间格式表达式
      参数:
      str -
      返回:
    • sendResponseAIAgentSSE

      public static void sendResponseAIAgentSSE(ModuleContext context, String text)
      响应SSE消息
      参数:
      context -
      data -
    • sendResponseAIAgentSSEError

      public static void sendResponseAIAgentSSEError(ModuleContext context, String text)
    • sendResponseAIAgentSSE

      public static boolean sendResponseAIAgentSSE(ModuleContext context, JSONObject data)
    • isObjectEqual

      public static boolean isObjectEqual(Object obj1, Object obj2)
      安全、通用的对象相等判断方法,支持 String / Number / Date / BigDecimal / Timestamp 等
    • checkPagePx

      public static String checkPagePx(String str)
      检查页面长度大位
      参数:
      str -
      返回: