类 CommonFunction
java.lang.Object
com.sh.common.util.CommonFunction
Description: 系统开发中的一些公共方法
Company:首亨软件(重庆)有限公司
-
字段概要
字段 -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static void检查文件对应的文件夹是否存在static void检查文件对应的目录是否存在protected static booleanstatic StringcheckUrlParamValue(String paramName, String str) 转换str到html的属性字符串,主要是防止xss漏洞static boolean拷贝文件,将文件从sourceFilePath 拷贝至aimFilePathstatic FilecopyFile(InputStream sourceInputStream, String aimFilePath) 拷贝文件,将文件从sourceFilePath 拷贝至aimFilePathstatic boolean拷贝文件,将文件从sourceFilePath 拷贝至aimFilePathstatic voidcopyForder(String sourceFilePath, String aimFilePath) 复制文件夹static StringdbDateDiff(DataCenter dc, String startTime, String endTime) startTime-endTime 返回两时间相差的秒数static StringdbGetLimitRow(DataCenter dc, int allRow, int beginRow) 返回带条件的行限制 ORACLE对第二个参数无效 为兼容不同数据库static String返回行函数 为兼容不同数据库static StringdbGetRowNum(DataCenter dc, boolean isString) 返回行函数 字符型 为兼容不同数据库static StringdbGetRowNum(String uniqueCol) 通过ROW_NUMBER() OVER(ORDER BY uniqueCol)的方式来返回行号 为兼容不同数据库static StringdbTrim(DataCenter dc, String param) 去空格 兼容数据库static StringgetCsrfToken(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, boolean autoCreate) static StringgetCurSequenceValue(DataCenter dc, String seqName) 获取当前序列值 ORACLE有效static Stringstatic StringgetDBType(DataCenter dc) static String[]getDeptByUserId(DataCenter dc, String userId) 获取座席所在的部门编号static String返回与操作系统相关的文件分隔符,如:Windows系统返回\ Unix系统返回 /static long获取后缀static String获取公司名称static StringgetNewId()获取新ID 默认前缘为SHstatic String获取新IDstatic Stringstatic Stringstatic StringgetNextSequenceValue(DataCenter dc, String seqName) 获取下一序列编号 ORACLE 时从序列中取值static StringgetNextSequenceValue(String seqName) 获取下一序列编号 ORACLE 时从序列中取值static InputStreamgetPostgresLargeObject(int oid, DataCenter dc) 通过OID获取POSTGRESQL中的大对象流static String重建URL,根据request对象值,重新构建URL,其中可以排除部分参数static StringgetRequestURL(jakarta.servlet.http.HttpServletRequest request) 重建URL,根据request对象值,重新构建URL,其中可以排除部分参数static StringgetRequestURL(jakarta.servlet.http.HttpServletRequest request, String[] eliminateParms, boolean delEndTag) static StringgetRequestURL(jakarta.servlet.http.HttpServletRequest request, String[] eliminateParms, boolean delEndTag, boolean addAutoParam) 重建URL,根据request对象值,重新构建URL,其中可以排除部分参数 重新构建的URL的最后一个字符串要么是?static StringgetRequestURL(jakarta.servlet.http.HttpServletRequest request, String[] eliminateParms, boolean delEndTag, boolean addAutoParam, CheckUrlParam_I cp) static String获取资源文件所在的URIstatic StringgetSubSystemDefaultURL(DataCenter dc, jakarta.servlet.http.HttpServletRequest request) static StringgetSubSystemDefaultURL(DataCenter dc, jakarta.servlet.http.HttpServletRequest request, String subSystemId) 获取默认子系统URLstatic StringgetSystemAlias(jakarta.servlet.http.HttpServletRequest request) 返回系统发布的简称,如:shforcestatic StringgetSystemBaseUrl(jakarta.servlet.http.HttpServletRequest request) 获取系统访问根路径 http://localhost:8080/shforce/static StringgetSystemFilePath(jakarta.servlet.http.HttpServletRequest request) 返回系统所在的路径,如:F:/workspace/shforce/shforce/static StringgetSystemHTTPPath(jakarta.servlet.http.HttpServletRequest request) 获取系统HTTP路径,类似127.0.0.1static StringgetSystemPort(jakarta.servlet.http.HttpServletRequest request) 获取端口号,如:8080static StringgetSystemURI(jakarta.servlet.http.HttpServletRequest request) 获取系统访问的URI,如:http://127.0.0.1:8080/static StringgetSystemURL(jakarta.servlet.http.HttpServletRequest request) 获取系统访问URL,如:http://127.0.0.1:8080/shforce/static UserInfogetUserInfo(DataCenter dc, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) 获取登录系统时保存的UserInfo信息static UserInfogetUserInfo(jakarta.servlet.http.HttpServletRequest request) static UserInfogetUserInfo(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) static DatastoregetUserSubSysInfo(DataCenter dc, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) 获取用户具有权限的子系统信息static DatastoregetUserSubSysInfo(DataCenter dc, jakarta.servlet.http.HttpServletRequest request, String subSystemId) 获取用户具有权限的子系统信息static StringgetValueFromCookie(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String name) static StringgetValueFromCookie(jakarta.servlet.http.HttpServletRequest request, String name) 获取本地COOKIE中保存的值static StringgetValueFromResponseCookie(jakarta.servlet.http.HttpServletResponse response, String name) 从response中获取cookie值,即当前请求添加的cookie值static booleanisAccess(DataCenter dc) 判断是否使用的是Acess数据库static booleanisContainStr(String[] array, String str) 重载public static boolean isContainStr(String array[],String str,boolean ignoreCase) 相当于isContainStr(array,str,false),不区分大小写进行比较static booleanisContainStr(String[] array, String str, boolean ignoreCase) 判断某一个字符串是否存在于String数组之中static booleanisDB2(DataCenter dc) static booleanisDM(DataCenter dc) 判断是否是DM数据库static booleanisES(DataCenter dc) 判断是否使用的是ESstatic boolean判断是否使用的是Greenplumstatic booleanisH2(DataCenter dc) 判断数据库是否H2数据库static booleanisKingbase(DataCenter dc) static booleanstatic booleanstatic booleanstatic booleanisMobileBrowser(jakarta.servlet.http.HttpServletRequest request) 判断是否手机浏览器static booleanisMongoDB(DataCenter dc) 判断是否使用的是MongoDBstatic booleanisMySql(DataCenter dc) static booleanisOnlyNumberAndDot(String str) 判断是否是数字或字母static booleanisOracle(DataCenter dc) 判断是否是ORACLE数据库static booleanisPhoenix(DataCenter dc) 判断是否使用的是Phoenixstatic booleanisPostgres(DataCenter dc) 是否POSTGRES数据库static booleanisSQLite()static booleanisSQLite(DataCenter dc) 判断数据库是否SQLite数据库static boolean判断是否是SQLSERVER数据库static booleanisSQuery(DataCenter dc) 判断是否使用的是SQuerystatic booleanstatic boolean判断是否在windows下运行static booleanisWww(jakarta.servlet.http.HttpServletRequest request) 判断当前请求是否在外网static booleanisXCloud(DataCenter dc) 判断是否使用的是XCloudstatic booleanoperateSvc(DataCenter dc, String buttonId) 知识库模块树结点右键弹出菜单权限static voidremoveCookie(jakarta.servlet.http.HttpServletResponse response, String name) 删除cookiestatic voidremoveUserInfo(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Session中删除用户信息的实例static booleanstatic boolean是否使用序列,如果返回false则表示自动生成序列static voidstatic void保存COOKIE值static StringsetCsrfToken(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) 设置csrf验证tokenstatic voidsetUserInfo(jakarta.servlet.http.HttpServletRequest request, UserInfo userInfo) static voidsetUserInfo(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, UserInfo userInfo) 设置用户信息的实例放入Sessionstatic String取得系统时间 格式为yyyy-MM-dd HH:mm:ssstatic String将对象转换为JSON字符串static voidwrite(InputStream is, OutputStream os) 将输入流转化为输出流static voidwriteToPage(jakarta.servlet.http.HttpServletResponse response, String html) 输出到页面static voidwriteToPage(jakarta.servlet.http.HttpServletResponse response, String html, String charset) 输出到页面
-
字段详细资料
-
log4j
protected static org.apache.logging.log4j.Logger log4j -
USER_KEY
-
CSRF_TOKEN
- 另请参阅:
-
ssABCDEObj
-
-
构造器详细资料
-
CommonFunction
public CommonFunction()
-
-
方法详细资料
-
getResourceURI
获取资源文件所在的URI- 返回:
- String
-
getUserInfo
-
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- DataCenterrequest- HttpServletRequest http请求response- HttpServletResponse- 返回:
- UserInfo 用户信息的实例
-
setUserInfo
-
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- HttpServletRequestresponse- 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
获取座席所在的部门编号- 参数:
dc- DataCenteruserId- String- 返回:
- String[]
- 抛出:
Exception- Exception
-
getRequestURL
重建URL,根据request对象值,重新构建URL,其中可以排除部分参数- 返回:
- String
-
getRequestURL
重建URL,根据request对象值,重新构建URL,其中可以排除部分参数- 参数:
request- HttpServletRequest- 返回:
- String
-
getRequestURL
-
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
转换str到html的属性字符串,主要是防止xss漏洞- 参数:
str- String- 返回:
- String
-
isOnlyNumberAndDot
判断是否是数字或字母- 参数:
str-- 返回:
-
isContainStr
重载public static boolean isContainStr(String array[],String str,boolean ignoreCase) 相当于isContainStr(array,str,false),不区分大小写进行比较- 参数:
array- 字符数组str- 字符串- 返回:
- true存在、false不存在
-
isContainStr
判断某一个字符串是否存在于String数组之中- 参数:
array- 字符数组str- 字符串ignoreCase- 是否忽略大小写- 返回:
- true存在、false不存在
-
systemTime
取得系统时间 格式为yyyy-MM-dd HH:mm:ss- 返回:
- Tomcat所在主机的系统时间
-
getNextSequenceValue
获取下一序列编号 ORACLE 时从序列中取值- 参数:
seqName- 序列名称,不区分大小写- 返回:
- String
-
getNextSequenceValue
获取下一序列编号 ORACLE 时从序列中取值- 参数:
dc- DataCenterseqName- 序列名称,不区分大小写- 返回:
- String
-
getCurSequenceValue
获取当前序列值 ORACLE有效- 参数:
dc- DataCenter对象seqName- 序列名称,不区分大小写- 返回:
- String
-
getMyCompanyName
获取公司名称- 参数:
dc- DataCenter 对象- 返回:
- 公司名称 对应sys_info_mycompany中记录的公司名称
-
getValueFromCookie
public static String getValueFromCookie(jakarta.servlet.http.HttpServletRequest request, String name) 获取本地COOKIE中保存的值- 参数:
request- HttpServletRequest对象name- 保存在COOKIE中的名称- 返回:
- String
-
getValueFromCookie
-
getValueFromResponseCookie
public static String getValueFromResponseCookie(jakarta.servlet.http.HttpServletResponse response, String name) 从response中获取cookie值,即当前请求添加的cookie值- 参数:
response- HttpServletResponsename- String- 返回:
- String
-
setCookie
-
setCookie
public static void setCookie(jakarta.servlet.http.HttpServletResponse response, String name, String value, int expiry) 保存COOKIE值- 参数:
response- HttpServletResponse对象name- 保存名称value- 保存值expiry- 设置 cookie 的最大生存时间,以秒为单位
-
removeCookie
删除cookie- 参数:
response- HttpServletResponsename- String
-
dbGetRowNum
返回行函数 为兼容不同数据库- 参数:
dc- DataCenter- 返回:
- String
-
dbGetRowNum
返回行函数 字符型 为兼容不同数据库- 参数:
dc- DataCenterisString- boolean- 返回:
- String
-
dbGetRowNum
通过ROW_NUMBER() OVER(ORDER BY uniqueCol)的方式来返回行号 为兼容不同数据库- 参数:
uniqueCol- String- 返回:
- String
-
dbGetLimitRow
返回带条件的行限制 ORACLE对第二个参数无效 为兼容不同数据库- 参数:
dc- DataCenterallRow- intbeginRow- int- 返回:
- String
-
isPostgres
是否POSTGRES数据库- 参数:
dc- DataCenter- 返回:
- true|false
-
isOracle
判断是否是ORACLE数据库- 参数:
dc- DataCenter- 返回:
- true|false
-
isDM
判断是否是DM数据库- 参数:
dc- DataCenter- 返回:
- true|false
-
isSqlserver
判断是否是SQLSERVER数据库- 参数:
dc- DataCenter- 返回:
- true|false
-
isAccess
判断是否使用的是Acess数据库- 参数:
dc- DataCenter- 返回:
- boolean
-
isPhoenix
判断是否使用的是Phoenix- 参数:
dc- DataCenter- 返回:
- boolean
-
isGreenplum
判断是否使用的是Greenplum- 参数:
dc- DataCenter- 返回:
- boolean
-
isXCloud
判断是否使用的是XCloud- 参数:
dc- DataCenter- 返回:
- boolean
-
isES
判断是否使用的是ES- 参数:
dc- DataCenter- 返回:
- boolean
-
isMongoDB
判断是否使用的是MongoDB- 参数:
dc- DataCenter- 返回:
- boolean
-
isSQuery
判断是否使用的是SQuery- 参数:
dc- DataCenter- 返回:
- boolean
-
getDBType
-
getDBType
-
isMySql
-
isKingbase
-
isKingbase_MySql
-
isKingbase_SqlServer
-
isKingbase_Oracle
-
isStarRocks
-
isH2
判断数据库是否H2数据库- 参数:
dc- DataCenter- 返回:
- boolean
-
isDB2
-
isSQLite
public static boolean isSQLite() -
isSQLite
判断数据库是否SQLite数据库- 参数:
dc- DataCenter- 返回:
- boolean
-
dbDateDiff
startTime-endTime 返回两时间相差的秒数- 参数:
dc- DataCenterstartTime- 开始时间endTime- 结束时间- 返回:
- 相差的秒数
-
dbTrim
去空格 兼容数据库- 参数:
dc- DataCenterparam- String- 返回:
- String
-
sequenceEnable
public static boolean sequenceEnable() -
sequenceEnable
是否使用序列,如果返回false则表示自动生成序列- 参数:
dc- DataCenter- 返回:
- boolean
-
getNewId
获取新ID- 参数:
prefix- 新ID的前缀- 返回:
- String
-
getNewId2
-
getMidValue
public static long getMidValue()获取后缀- 返回:
- long
-
getNewId
获取新ID 默认前缘为SH- 返回:
- String
-
getNewId2
-
toJson
将对象转换为JSON字符串- 参数:
obj- Object- 返回:
- String
-
writeToPage
输出到页面- 参数:
response- HttpServletResponse对象html- 输出到页面的内容
-
writeToPage
public static void writeToPage(jakarta.servlet.http.HttpServletResponse response, String html, String charset) 输出到页面- 参数:
response- HttpServletResponse对象html- 输出到页面的内容charset- 编码
-
write
将输入流转化为输出流- 参数:
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
获取系统访问的URI,如:http://127.0.0.1:8080/- 参数:
request- HttpServletRequest- 返回:
- String
-
getSystemURL
获取系统访问URL,如:http://127.0.0.1:8080/shforce/- 参数:
request- HttpServletRequest- 返回:
- String
-
getSystemAlias
返回系统发布的简称,如:shforce- 参数:
request- HttpServletRequest- 返回:
- String
-
getSystemBaseUrl
获取系统访问根路径 http://localhost:8080/shforce/- 参数:
request- HttpServletRequest- 返回:
- String
-
getFileSeparator
返回与操作系统相关的文件分隔符,如:Windows系统返回\ Unix系统返回 /- 返回:
- String
-
isWindows
public static boolean isWindows()判断是否在windows下运行- 返回:
- true|false
-
copyFile
拷贝文件,将文件从sourceFilePath 拷贝至aimFilePath- 参数:
sourceFilePath- 源文件地址 如:F:/SOURCE/test.txtaimFilePath- 目的文件地址 如:D:/AIM/test.txt- 返回:
- boolean
- 抛出:
Exception- Exception
-
copyFile
拷贝文件,将文件从sourceFilePath 拷贝至aimFilePath- 参数:
sourceFile- 源文件地址 如:F:/SOURCE/test.txtaimFilePath- 目的文件地址 如:D:/AIM/test.txt- 返回:
- boolean
- 抛出:
Exception- Exception
-
copyFile
拷贝文件,将文件从sourceFilePath 拷贝至aimFilePath- 参数:
sourceInputStream- 文件流aimFilePath- 目的文件地址 如:D:/AIM/test.txt- 返回:
- File
- 抛出:
Exception- Exception
-
copyForder
复制文件夹- 参数:
sourceFilePath- StringaimFilePath- String- 抛出:
Exception- Exception
-
checkDir
检查文件对应的目录是否存在- 参数:
filePath- String
-
checkDir
检查文件对应的文件夹是否存在- 参数:
file- File
-
isWww
public static boolean isWww(jakarta.servlet.http.HttpServletRequest request) 判断当前请求是否在外网- 参数:
request- HttpServletRequest对象- 返回:
- true 请求在外网 false 请求在内网 注意:需要在系统参数wwwIpValue中指定当前服务器所使用的外网IP
-
operateSvc
知识库模块树结点右键弹出菜单权限- 参数:
dc- DataCenterbuttonId- String- 返回:
- boolean
-
getPostgresLargeObject
通过OID获取POSTGRESQL中的大对象流- 参数:
oid- intdc- 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- DataCenterrequest- HttpServletRequestsubSystemId- String- 返回:
- String
-
getSubSystemDefaultURL
public static String getSubSystemDefaultURL(DataCenter dc, jakarta.servlet.http.HttpServletRequest request)
-