类 CommonFunction

java.lang.Object
com.sh.common.util.CommonFunction

public final class CommonFunction extends Object

Description: 系统开发中的一些公共方法

Company:首亨软件(重庆)有限公司

  • 字段详细资料

    • log4j

      protected static org.apache.logging.log4j.Logger log4j
    • USER_KEY

      public static final String USER_KEY
    • CSRF_TOKEN

      public static final String CSRF_TOKEN
      另请参阅:
    • ssABCDEObj

      protected static Object ssABCDEObj
  • 构造器详细资料

    • CommonFunction

      public CommonFunction()
  • 方法详细资料

    • getResourceURI

      public static String getResourceURI()
      获取资源文件所在的URI
      返回:
      String
    • getUserInfo

      public static UserInfo getUserInfo(jakarta.servlet.http.HttpServletRequest request)
    • getUserInfo

      public static UserInfo getUserInfo(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
    • getUserInfo

      public static UserInfo getUserInfo(DataCenter dc, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
      获取登录系统时保存的UserInfo信息
      参数:
      dc - DataCenter
      request - HttpServletRequest http请求
      response - HttpServletResponse
      返回:
      UserInfo 用户信息的实例
    • setUserInfo

      public static void setUserInfo(jakarta.servlet.http.HttpServletRequest request, UserInfo userInfo)
    • setUserInfo

      public static void setUserInfo(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, UserInfo userInfo)
      设置用户信息的实例放入Session
      参数:
      request - HttpServletRequest对象
      response - HttpServletResponse对象
      userInfo - 用户信息对象 这里对集群的session共享做了一个处理,将值保存到cookie中,然后分配到每个tomcat的时候,检查当前cookie中的值是否正确,即包含该sessionId,然后再加载UserInfo 要求:每个tomcat中保存session的名称需要不一样
    • removeUserInfo

      public static void removeUserInfo(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
      Session中删除用户信息的实例
      参数:
      request - HttpServletRequest
      response - HttpServletResponse
    • getUserSubSysInfo

      public static Datastore getUserSubSysInfo(DataCenter dc, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws Exception
      获取用户具有权限的子系统信息
      参数:
      dc - DataCenter对象
      request - HttpServletRequest对象
      response - HttpServletResponse
      返回:
      Datastore 用户权限数据集,数据集的结构参照sys_sub_system表
      抛出:
      Exception - Exception
    • getDeptByUserId

      public static String[] getDeptByUserId(DataCenter dc, String userId) throws Exception
      获取座席所在的部门编号
      参数:
      dc - DataCenter
      userId - String
      返回:
      String[]
      抛出:
      Exception - Exception
    • getRequestURL

      public static String getRequestURL()
      重建URL,根据request对象值,重新构建URL,其中可以排除部分参数
      返回:
      String
    • getRequestURL

      public static String getRequestURL(jakarta.servlet.http.HttpServletRequest request)
      重建URL,根据request对象值,重新构建URL,其中可以排除部分参数
      参数:
      request - HttpServletRequest
      返回:
      String
    • getRequestURL

      public static String getRequestURL(jakarta.servlet.http.HttpServletRequest request, String[] eliminateParms, boolean delEndTag)
    • getRequestURL

      public static String getRequestURL(jakarta.servlet.http.HttpServletRequest request, String[] eliminateParms, boolean delEndTag, boolean addAutoParam)
      重建URL,根据request对象值,重新构建URL,其中可以排除部分参数 重新构建的URL的最后一个字符串要么是?(不带参数),要么是&(带参数),这个结束符可以去掉
      参数:
      request - 请求对象
      eliminateParms - request中排除的参数列表
      delEndTag - 删除结束符,结束符是?或者&
      addAutoParam - boolean
      返回:
      重新构建的URL
    • getRequestURL

      public static String getRequestURL(jakarta.servlet.http.HttpServletRequest request, String[] eliminateParms, boolean delEndTag, boolean addAutoParam, CheckUrlParam_I cp)
    • checkUrlParamValue

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

      public static boolean isOnlyNumberAndDot(String str)
      判断是否是数字或字母
      参数:
      str -
      返回:
    • isContainStr

      public static boolean isContainStr(String[] array, String str)
      重载public static boolean isContainStr(String array[],String str,boolean ignoreCase) 相当于isContainStr(array,str,false),不区分大小写进行比较
      参数:
      array - 字符数组
      str - 字符串
      返回:
      true存在、false不存在
    • isContainStr

      public static boolean isContainStr(String[] array, String str, boolean ignoreCase)
      判断某一个字符串是否存在于String数组之中
      参数:
      array - 字符数组
      str - 字符串
      ignoreCase - 是否忽略大小写
      返回:
      true存在、false不存在
    • systemTime

      public static String systemTime()
      取得系统时间 格式为yyyy-MM-dd HH:mm:ss
      返回:
      Tomcat所在主机的系统时间
    • getNextSequenceValue

      public static String getNextSequenceValue(String seqName)
      获取下一序列编号 ORACLE 时从序列中取值
      参数:
      seqName - 序列名称,不区分大小写
      返回:
      String
    • getNextSequenceValue

      public static String getNextSequenceValue(DataCenter dc, String seqName)
      获取下一序列编号 ORACLE 时从序列中取值
      参数:
      dc - DataCenter
      seqName - 序列名称,不区分大小写
      返回:
      String
    • getCurSequenceValue

      public static String getCurSequenceValue(DataCenter dc, String seqName)
      获取当前序列值 ORACLE有效
      参数:
      dc - DataCenter对象
      seqName - 序列名称,不区分大小写
      返回:
      String
    • getMyCompanyName

      public static String getMyCompanyName(DataCenter dc)
      获取公司名称
      参数:
      dc - DataCenter 对象
      返回:
      公司名称 对应sys_info_mycompany中记录的公司名称
    • getValueFromCookie

      public static String getValueFromCookie(jakarta.servlet.http.HttpServletRequest request, String name)
      获取本地COOKIE中保存的值
      参数:
      request - HttpServletRequest对象
      name - 保存在COOKIE中的名称
      返回:
      String
    • getValueFromCookie

      public static String getValueFromCookie(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String name)
    • getValueFromResponseCookie

      public static String getValueFromResponseCookie(jakarta.servlet.http.HttpServletResponse response, String name)
      从response中获取cookie值,即当前请求添加的cookie值
      参数:
      response - HttpServletResponse
      name - String
      返回:
      String
    • setCookie

      public static void setCookie(jakarta.servlet.http.HttpServletResponse response, String name, String value)
    • setCookie

      public static void setCookie(jakarta.servlet.http.HttpServletResponse response, String name, String value, int expiry)
      保存COOKIE值
      参数:
      response - HttpServletResponse对象
      name - 保存名称
      value - 保存值
      expiry - 设置 cookie 的最大生存时间,以秒为单位
    • removeCookie

      public static void removeCookie(jakarta.servlet.http.HttpServletResponse response, String name)
      删除cookie
      参数:
      response - HttpServletResponse
      name - String
    • dbGetRowNum

      public static String dbGetRowNum(DataCenter dc)
      返回行函数 为兼容不同数据库
      参数:
      dc - DataCenter
      返回:
      String
    • dbGetRowNum

      public static String dbGetRowNum(DataCenter dc, boolean isString)
      返回行函数 字符型 为兼容不同数据库
      参数:
      dc - DataCenter
      isString - boolean
      返回:
      String
    • dbGetRowNum

      public static String dbGetRowNum(String uniqueCol)
      通过ROW_NUMBER() OVER(ORDER BY uniqueCol)的方式来返回行号 为兼容不同数据库
      参数:
      uniqueCol - String
      返回:
      String
    • dbGetLimitRow

      public static String dbGetLimitRow(DataCenter dc, int allRow, int beginRow)
      返回带条件的行限制 ORACLE对第二个参数无效 为兼容不同数据库
      参数:
      dc - DataCenter
      allRow - int
      beginRow - int
      返回:
      String
    • isPostgres

      public static boolean isPostgres(DataCenter dc)
      是否POSTGRES数据库
      参数:
      dc - DataCenter
      返回:
      true|false
    • isOracle

      public static boolean isOracle(DataCenter dc)
      判断是否是ORACLE数据库
      参数:
      dc - DataCenter
      返回:
      true|false
    • isDM

      public static boolean isDM(DataCenter dc)
      判断是否是DM数据库
      参数:
      dc - DataCenter
      返回:
      true|false
    • isSqlserver

      public static boolean isSqlserver(DataCenter dc)
      判断是否是SQLSERVER数据库
      参数:
      dc - DataCenter
      返回:
      true|false
    • isAccess

      public static boolean isAccess(DataCenter dc)
      判断是否使用的是Acess数据库
      参数:
      dc - DataCenter
      返回:
      boolean
    • isPhoenix

      public static boolean isPhoenix(DataCenter dc)
      判断是否使用的是Phoenix
      参数:
      dc - DataCenter
      返回:
      boolean
    • isGreenplum

      public static boolean isGreenplum(DataCenter dc)
      判断是否使用的是Greenplum
      参数:
      dc - DataCenter
      返回:
      boolean
    • isXCloud

      public static boolean isXCloud(DataCenter dc)
      判断是否使用的是XCloud
      参数:
      dc - DataCenter
      返回:
      boolean
    • isES

      public static boolean isES(DataCenter dc)
      判断是否使用的是ES
      参数:
      dc - DataCenter
      返回:
      boolean
    • isMongoDB

      public static boolean isMongoDB(DataCenter dc)
      判断是否使用的是MongoDB
      参数:
      dc - DataCenter
      返回:
      boolean
    • isSQuery

      public static boolean isSQuery(DataCenter dc)
      判断是否使用的是SQuery
      参数:
      dc - DataCenter
      返回:
      boolean
    • getDBType

      public static String getDBType()
    • getDBType

      public static String getDBType(DataCenter dc)
    • isMySql

      public static boolean isMySql(DataCenter dc)
    • isKingbase

      public static boolean isKingbase(DataCenter dc)
    • isKingbase_MySql

      public static boolean isKingbase_MySql(DataCenter dc)
    • isKingbase_SqlServer

      public static boolean isKingbase_SqlServer(DataCenter dc)
    • isKingbase_Oracle

      public static boolean isKingbase_Oracle(DataCenter dc)
    • isStarRocks

      public static boolean isStarRocks(DataCenter dc)
    • isH2

      public static boolean isH2(DataCenter dc)
      判断数据库是否H2数据库
      参数:
      dc - DataCenter
      返回:
      boolean
    • isDB2

      public static boolean isDB2(DataCenter dc)
    • isSQLite

      public static boolean isSQLite()
    • isSQLite

      public static boolean isSQLite(DataCenter dc)
      判断数据库是否SQLite数据库
      参数:
      dc - DataCenter
      返回:
      boolean
    • dbDateDiff

      public static String dbDateDiff(DataCenter dc, String startTime, String endTime)
      startTime-endTime 返回两时间相差的秒数
      参数:
      dc - DataCenter
      startTime - 开始时间
      endTime - 结束时间
      返回:
      相差的秒数
    • dbTrim

      public static String dbTrim(DataCenter dc, String param)
      去空格 兼容数据库
      参数:
      dc - DataCenter
      param - String
      返回:
      String
    • sequenceEnable

      public static boolean sequenceEnable()
    • sequenceEnable

      public static boolean sequenceEnable(DataCenter dc)
      是否使用序列,如果返回false则表示自动生成序列
      参数:
      dc - DataCenter
      返回:
      boolean
    • getNewId

      public static String getNewId(String prefix)
      获取新ID
      参数:
      prefix - 新ID的前缀
      返回:
      String
    • getNewId2

      public static String getNewId2(String prefix)
    • getMidValue

      public static long getMidValue()
      获取后缀
      返回:
      long
    • getNewId

      public static String getNewId()
      获取新ID 默认前缘为SH
      返回:
      String
    • getNewId2

      public static String getNewId2()
    • toJson

      public static String toJson(Object obj)
      将对象转换为JSON字符串
      参数:
      obj - Object
      返回:
      String
    • writeToPage

      public static void writeToPage(jakarta.servlet.http.HttpServletResponse response, String html)
      输出到页面
      参数:
      response - HttpServletResponse对象
      html - 输出到页面的内容
    • writeToPage

      public static void writeToPage(jakarta.servlet.http.HttpServletResponse response, String html, String charset)
      输出到页面
      参数:
      response - HttpServletResponse对象
      html - 输出到页面的内容
      charset - 编码
    • write

      public static void write(InputStream is, OutputStream os) throws Exception
      将输入流转化为输出流
      参数:
      is - 输入流
      os - 输出流
      抛出:
      Exception - Exception
    • getSystemFilePath

      public static String getSystemFilePath(jakarta.servlet.http.HttpServletRequest request) throws Exception
      返回系统所在的路径,如:F:/workspace/shforce/shforce/
      参数:
      request - HttpServletRequest
      返回:
      String
      抛出:
      Exception - Exception
    • getSystemHTTPPath

      public static String getSystemHTTPPath(jakarta.servlet.http.HttpServletRequest request) throws Exception
      获取系统HTTP路径,类似127.0.0.1
      参数:
      request - HttpServletRequest
      返回:
      String
      抛出:
      Exception - Exception
    • getSystemPort

      public static String getSystemPort(jakarta.servlet.http.HttpServletRequest request) throws Exception
      获取端口号,如:8080
      参数:
      request - HttpServletRequest
      返回:
      String
      抛出:
      Exception - Exception
    • getSystemURI

      public static String getSystemURI(jakarta.servlet.http.HttpServletRequest request)
      获取系统访问的URI,如:http://127.0.0.1:8080/
      参数:
      request - HttpServletRequest
      返回:
      String
    • getSystemURL

      public static String getSystemURL(jakarta.servlet.http.HttpServletRequest request)
      获取系统访问URL,如:http://127.0.0.1:8080/shforce/
      参数:
      request - HttpServletRequest
      返回:
      String
    • getSystemAlias

      public static String getSystemAlias(jakarta.servlet.http.HttpServletRequest request)
      返回系统发布的简称,如:shforce
      参数:
      request - HttpServletRequest
      返回:
      String
    • getSystemBaseUrl

      public static String getSystemBaseUrl(jakarta.servlet.http.HttpServletRequest request)
      获取系统访问根路径 http://localhost:8080/shforce/
      参数:
      request - HttpServletRequest
      返回:
      String
    • getFileSeparator

      public static String getFileSeparator()
      返回与操作系统相关的文件分隔符,如:Windows系统返回\ Unix系统返回 /
      返回:
      String
    • isWindows

      public static boolean isWindows()
      判断是否在windows下运行
      返回:
      true|false
    • copyFile

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

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

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

      public static void copyForder(String sourceFilePath, String aimFilePath) throws Exception
      复制文件夹
      参数:
      sourceFilePath - String
      aimFilePath - String
      抛出:
      Exception - Exception
    • checkDir

      public static void checkDir(String filePath)
      检查文件对应的目录是否存在
      参数:
      filePath - String
    • checkDir

      public static void checkDir(File file)
      检查文件对应的文件夹是否存在
      参数:
      file - File
    • isWww

      public static boolean isWww(jakarta.servlet.http.HttpServletRequest request)
      判断当前请求是否在外网
      参数:
      request - HttpServletRequest对象
      返回:
      true 请求在外网 false 请求在内网 注意:需要在系统参数wwwIpValue中指定当前服务器所使用的外网IP
    • operateSvc

      public static boolean operateSvc(DataCenter dc, String buttonId)
      知识库模块树结点右键弹出菜单权限
      参数:
      dc - DataCenter
      buttonId - String
      返回:
      boolean
    • getPostgresLargeObject

      public static InputStream getPostgresLargeObject(int oid, DataCenter dc)
      通过OID获取POSTGRESQL中的大对象流
      参数:
      oid - int
      dc - DataCenter
      返回:
      InputStream
    • isMobileBrowser

      public static boolean isMobileBrowser(jakarta.servlet.http.HttpServletRequest request)
      判断是否手机浏览器
      参数:
      request - HttpServletRequest
      返回:
      boolean
    • setCsrfToken

      public static String setCsrfToken(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
      设置csrf验证token
      参数:
      request - HttpServletRequest
      返回:
      String
    • getCsrfToken

      public static String getCsrfToken(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, boolean autoCreate)
    • checkSystemValid

      protected static boolean checkSystemValid()
    • getUserSubSysInfo

      public static Datastore getUserSubSysInfo(DataCenter dc, jakarta.servlet.http.HttpServletRequest request, String subSystemId) throws Exception
      获取用户具有权限的子系统信息
      参数:
      dc - DataCenter对象
      request - HttpServletRequest对象
      subSystemId - String
      返回:
      Datastore 用户权限数据集,数据集的结构参照sys_sub_system表
      抛出:
      Exception - Exception
    • getSubSystemDefaultURL

      public static String getSubSystemDefaultURL(DataCenter dc, jakarta.servlet.http.HttpServletRequest request, String subSystemId)
      获取默认子系统URL
      参数:
      dc - DataCenter
      request - HttpServletRequest
      subSystemId - String
      返回:
      String
    • getSubSystemDefaultURL

      public static String getSubSystemDefaultURL(DataCenter dc, jakarta.servlet.http.HttpServletRequest request)