# 功能描述

common包为平台基础包,提供基础功能供后续组件调用。 主要完成功能:
(1) 提供国际化翻译
(2) 跨域配置
(3) swagger
(4) FastJson转换
(5) url拦截并添加跟踪标记用户的操作序列号
(6) 针对没有被业务捕获的异常进行全局异常处理器
(7) 提供基础工具包(在sei.cloud.common.util包中)
(5) 其它初始化环境设置

# 重要支撑类

# 系统参数类Constants

系统参数类Constants主要存放本系统后续可能会使用到的环境参数,具体内容如下:

属性或方法名 返回类型 功能说明
DEBUG boolean 是否调试模式
isRuning boolean 系统是否在运行
THREAD_POOL ExecutorService 线程池
LocalProcessIP String 当前运行的 进程号@机器名称:IP
IP String 机器IP
PORT String 端口
JarPathName String 启动的jar文件绝对路径及文件名
ROOT_PATH String 当前运行程序根的绝对路径,带斜杠结尾
LOG_PATH String 使用文件记录操作日志时的文件存放目录
ATT_TEMP_PATH String 系统临时文件存放目录的绝对路径,带斜杠结尾
ATT_FILE_PATH String 系统附件文件存放目录的绝对路径,带斜杠结尾
WEB_PATH String 系统Web绝对路径(用于前后端分离时存放web直接浏览的文件),带斜杠结尾
isUpdateDataBase boolean 是否更新数据库表结构
isRedis boolean 是否开启了redis
isLocalCache boolean 是否开启了本地缓存(即一级缓存)
isMongo boolean 是否开启了Mongo
isQuartz boolean 是否开启了Quartz定时任务
isMybatis boolean 是否开启了Mybatis
isWorkflow boolean 是否开启了工作流
isLinux() boolean 当前运行环境是否是Linux
isWindows() boolean 当前运行环境是否是Windows
isMac() boolean 当前运行环境是否是Mac

# 返回前端类ResMsg

只要返回前台的数据都采用ResMsg格式。

点击查看ResMsg类
package sei.cloud.common.support;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.lang.NonNull;
import java.io.Serializable;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/** 过滤空值 */
@JsonInclude(JsonInclude.Include.NON_NULL)

/**
 * 执行结果
 * @param <T>:附加数据
 * @author xiong
 */
public class ResMsg<T> implements Serializable {
    private static final long serialVersionUID = -2946579545083632979L;
    @ApiModelProperty(value = "成功标识;0:失败;1:成功;2:部分成功;-2:未登录;-3:未权限",required = true)
    private int code = Flag.common.FAIL;
    @ApiModelProperty(value = "描述信息",required = true)
    private String message;
    @ApiModelProperty(value = "附加数据")
    private Map data = null;
    private T extData = null;

    public ResMsg(){}
    public ResMsg(String errMessage){
        this.message = errMessage;
    }
    public ResMsg(int code){
        this.code = code;
    }
    public ResMsg(int code, @NonNull String message){
        this.code = code;
        this.message = message;
    }

    public ResMsg(int code, Map map){
        this.code = code;
        this.data = map;
    }

    public ResMsg(int code, List list){
        this.code = code;
        addData("rows", list == null ? Collections.EMPTY_LIST : list);
    }

    public ResMsg(int code, List list, long total){
        this.code = code;
        addData("rows", list == null ? Collections.EMPTY_LIST : list);
        addData("total", total);
    }

    public ResMsg(int code, @NonNull String message, Map map){
        this.code = code;
        this.message  = message;
        this.data = map;
    }

    public void addMessage(@NonNull String message) {
        if(this.message != null){
            this.message += "\n";
        }
        this.message += message;
    }
    public void setCodeMessage(int code, @NonNull String message){
        this.code = code;
        this.message = message;
    }

    public boolean isSuccess() {
        return Flag.common.SUCCESS == code;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Map getData() {
        return data;
    }

    public <T> T getDataItem(String key) {
        if (data == null){
            return null;
        } else {
            return (T)data.get(key);
        }
    }

    public void setData(Map data) {
        this.data = data;
    }

    public void addData(@NonNull String key, Object data){
        if(this.data == null){
            this.data = new HashMap(2);
        }
        this.data.put(key, data);
    }

    public <T> T removeData(@NonNull String key){
        if(this.data != null){
            return (T)this.data.remove(key);
        }
        return null;
    }

    public void setRows(List list) {
        addData("rows", list == null ? Collections.EMPTY_LIST : list);
    }

    public void setExtData(T extData){
        this.extData = extData;
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133

# 返回前端的错误代码类Flag

系统错误代码类都存放在Flag类中,如果不够,开发者可继承并扩充此类。 下面只列出了部分错误代码。

点击查看ResMsg类
package sei.cloud.common.support;

public interface Flag {
	interface common {
		int SUCCESS = 1;	/* 成功标志 */
		int FAIL = 0;	/* 失败标志 */
		int SUCCESS_FAIL = -1;	/* 部分成功标志 */
		int NO_LOGIN = -2;	/* 未登录标志 */
		int NO_PRIVILEGE = -3;	/* 权限不够标志 */
		int NO_EDIT_PRIVILEGE = -4;	/* 无数据编辑权限 */
		int NO_ANALYSE = -5; /* 无法解析 */
		int NO_START = -6; /* 未启动 */
		int NO_ALLOW = -7; /* 不允许的操作 */
		int CONFIG_ERR = -8; /* 配置错误*/
		int LOST = -9; /* 不存在 */
		int CONVERT_ERR = -10; /* 转换错误 */
		int DEFINE_DOUBLE = -11; /* 重复定义 */
	}

	interface login {
		int LOGIN_USER_NULL = -100; /* 账号或密码为空,或账套不存在 */
		int LOGIN_CODE_ERR = -101; /* 验证码错误 */
		int LOGIN_USER_ERR = -102; /* 用户名密码错误 */
		int LOGIN_USER_DISABLE = -103; /* 用户被禁止登陆 */
		int LOGIN_USER_AUDIT = -104; /* 用户等待审核 */
		int LOGIN_IP_DISABLE = -105; /* 登录IP错误 */
	}

	interface data {
		int SQL_ERR = -200; /* SQL语句错误 */
		int NO_MODULE = -201; /* 无对应的模块 */
		int NO_MODULE_TABLE = -202; /* 模块中未设置表 */
		int NO_WEB_SQL = -203; /* 未开启前端编写SQL功能 */
		int MULTI_SQL = -204; /* 有多条SQL语句 */
		int NO_TABLE_PRIMARY = -205; /* 表无主键 */
		int NO_DATA = -206; /* 无操作数据 */
		int DEFINE_REAL = -207; /* 定义的{0}与实际{1}不符 */
		int DEFINE_VIEW_ERR = -208; /* 视图{0}设置的模块{1}与该视图挂载的模块不符 */
		int MULTI_MODULE = -209; /* {0}有多个模块 */
		int MULTI_TABLE = -210; /* {0}有多个表 */
		int MODULE_TABLE = -211; /* {0}表不属于模块{0} */
		int MODULE_TABLE_VIEW = -212; /* {0}模块中不存在表或视图 */
		int MODULE_TABLE_VIEW_DOUBLE = -213; /* {0}模块中定义了多个表或视图 */
		int DEFINE_ERR0 = -214; /* 权限注解Privilege未设置action类型,也不允许从SQL中提取操作类型!建议:(1)设置action;(2)设置注解中autoAction为true */
		int DEFINE_ERR1 = -215; /* 权限注解Privilege未设置module模块编号,也未设置从SQL中自动提取模块编号!建议:(1)设置module;(2)设置autoModuleBySQL为true */
		int NO_PRIMARY_FIELD = -216; /* {0}表缺少主键 */
		int JSON_ERR = -217; /* JSON格式错误 */
	}
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

# 数据库类型枚举类DatabaseType

枚举了系统可能会用到的数据库类型

点击查看DatabaseType类
package sei.cloud.common.support;

/**
 * 数据库类型
 * @author xiong
 */
public enum DatabaseType {
    mysql,oracle,sqlServer,db2,mongodb,elasticsearch,file,other
}
1
2
3
4
5
6
7
8
9

# 数据库切换类DataSourceSwitch

可以通过该类切换不同的数据库

属性或方法名 返回类型 功能说明
DEFAULT_DATASOURCE_KEY String 缺省数据库别名Key
getDataSourceKey() String 获得当前数据源的别名Key
setDataSourceByKey(@NonNull String dataSourceKey) void 通过数据源别名Key切换数据源
getDataBaseType() DatabaseType 获得当前使用的数据库类型
getDataBaseName() String 获得当前使用数据库的真实名称
containsDataSource(@NonNull String dataSourceKey) boolean 判断指定的dataSourceKey是否存在
getConfig() Map<String, Object> 获得当前运行中的数据源配置信息
getConfig(@NonNull String dataSourceKey) Map<String, Object> 获得指定的数据源配置信息
点击查看DataSourceSwitch类代码
package sei.cloud.common.support;

import org.springframework.lang.NonNull;
import sei.cloud.common.util.StringUtil;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 数据源上下文
 * @author xiong
 */
public class DataSourceSwitch {

    /**
     * 缺省数据库别名Key
     */
    public static String DEFAULT_DATASOURCE_KEY;

    /**
     * 存储注册的数据源key到list
     * list(0):数据库类型
     * list(1):配置文件中对数据库的别名Key
     * list(2):连接配置信息
     * list(3):数据库真实名称
     */
    public static Map<String, List> MULTI_DATASOURCE = new HashMap(4);

    /**
     * 线程级别的私有变量
     */
    private static final ThreadLocal<String> HOLDER = new ThreadLocal<>();

    /**
     * 获得当前数据源的别名Key
     * @return String
     */
    public static String getDataSourceKey () {
        return HOLDER.get() == null ? DEFAULT_DATASOURCE_KEY : HOLDER.get();
    }

    /**
     * 通过数据源别名Key切换数据源
     * @param dataSourceKey: 指定数据源别名Key
     */
    public static void setDataSourceByKey(@NonNull String dataSourceKey) {
        if(MULTI_DATASOURCE.size()==1 || StringUtil.isEmpty(dataSourceKey) || !containsDataSource(dataSourceKey) || getDataSourceKey().equalsIgnoreCase(dataSourceKey)){
            return;
        }
        HOLDER.remove();
        HOLDER.set(dataSourceKey);
    }
    /**
     * 获得当前使用的数据库类型
     * @return DatabaseType
     */
    public static DatabaseType getDataBaseType(){
        return (DatabaseType)MULTI_DATASOURCE.get(getDataSourceKey()).get(0);
    }

    /**
     * 获得当前使用数据库的真实名称
     * @return String
     */
    public static String getDataBaseName(){
        return (String)MULTI_DATASOURCE.get(getDataSourceKey()).get(3);
    }

    /**
     * 判断指定的dataSourceKey是否存在
     * @param dataSourceKey: 数据源编号
     * @return boolean
     */
    public static boolean containsDataSource(@NonNull String dataSourceKey){
        return MULTI_DATASOURCE.containsKey(dataSourceKey);
    }

    /**
     * 获得当前运行中的数据源配置信息
     * @return map
     */
    public static Map<String, Object> getConfig(){
        return (Map<String, Object>)MULTI_DATASOURCE.get(getDataSourceKey()).get(2);
    }

    /**
     * 获得指定的数据源配置信息
     * @param dataSourceKey: 数据源编号
     * @return map
     */
    public static Map<String, Object> getConfig(@NonNull String dataSourceKey){
        if (containsDataSource(dataSourceKey)) {
            return (Map<String, Object>)MULTI_DATASOURCE.get(dataSourceKey).get(2);
        }
        return null;
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97

# 系列工具类

系统提供了常用的工具类,路径在sei.cloud.common.util包中,具体类如下:

类名 主要说明
ByteBufferUtil 字节Buffer操作类
ByteUtil 字节操作类,实现字节对各种类型的转换
CaptchaUtil 验证码工具类,用于生产验证码图片
ClassUtil 包扫描工具,主要用于扫描接口、注解等
CommandUtil 用于执行操作系统命令
CookieUtil Cookie操作
DateTimeUtil 日期时间工具类
ExceptionUtil 用于Consumer异常处理
FileUtil 文件操作类,包括文件拷贝、上传文件、下载文件、删除文件、将文件发送到浏览器端图片浏览等
FontsUtil 字体工具类,用于安置字体、获得字体等
HardwareUtil 获取硬件信息,包括主板序列号、MAC地址、CPU序列号等
HttpUtils http请求工具,通过http请求或发送数据到指定url
ImageUtil 图片转换工具类,用于将图片与base64的转换等
MapUtil Map对象工具,用于map对象转换、比较等
Md5Util 用于将字符串生成MD5
MoneyUtil 金额工具类,用于字符串或数字转汉字金额等
NetUtil 网络工具包,用于获得当前机器的IP地址、运行的进程号、运行的端口等
NumberUtil 数字工具类,用于判断或转换以及数字精确化操作
ObjectUtil 对象工具类,用于对象判断、对象转换等
PropertiesUtil 属性工具类,用于对Properties文件的读写等操作
RandomUtil 随机数工具类
ReflectUtil 反射工具类
SerializeUtil 序列化工具
ServerInfoUtil 服务器信息工具类
SessionUtil Session操作类
SpringContextUtil Spring应用上下文环境操作类,用于获得bean对象等
StringUtil 字符串工具类
TypeUtil 对象转基本类型工具类
ZipUtil 文件压缩及解压工具类

# ByteBufferUtil字节Buffer工具类

/**
 * ByteBuffer操作工具类
 * @author xiongsoft
 */
public class ByteBufferUtil {
    /**
     * 获得指定大小的ByteBuff
     * @param size: ByteBuff大小
     * @return ByteBuff
     */
    public static ByteBuffer getByteBuffer(int size);
}
1
2
3
4
5
6
7
8
9
10
11
12

# ByteUtil字节工具类

/**
 * 字节操作类
 * @author xiongsoft
 */
public class ByteUtil {
    /**
     * long类型转换为字节数组,适合转高位在前低位在后的byte[]
     * @param n: 数字
     * @return byte[]
     */
    public static byte[] longToBytes(long n);

    /**
     * 字节转数子
     * @param array: 字节数组
     * @param position: 起始位置
     * @return long
     */
    public static long bytesToLong(byte[] array,int position);

    /**
     * intToBytes
     * @param n: 数字
     * @return byte[]
     */
    public static byte[] intToBytes(int n);

    /**
     * 字节数组换整形
     * @param b: 字节数组
     * @param position: 起始位置
     * @return int
     */
    public static int bytesToInt(byte b[],int position);

    public static byte[] uintToBytes(long n);

    public static long bytesToUint(byte[] array,int position);

    public static byte[] shortToBytes(short n);

    public static byte[] ShortToBytes(short number);

    public static short bytesToShort(byte[] b,int position);

    public static byte[] ushortToBytes(int n);

    public static int bytesToUshort(byte b[],int position);

    public static byte[] ubyteToBytes( int n );

    public static int bytesToUbyte( byte[] array,int position);

    public static String printHexString(byte[] b);

    public static byte[] hexStringToBytes(String hexString);

    private static byte charToByte(char c);

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

# CaptchaUtil验证码工具类

/**
 * 验证码工具类
 * @author xiongsoft
 */
public class CaptchaUtil {

	/**
	 * 验证码复杂程序 ComplexLevel.SIMPLE简单 ComplexLevel.MEDIUM中等 ComplexLevel.HARD复杂
	 */
	public enum ComplexLevel {SIMPLE,MEDIUM,HARD}

	/**
	 * 验证码生产类
	 * 简单的验证码由4位数字组成
	 * 中等复杂的验证码有5位,字母(包括大小写)和数字组成,有干扰点
	 * 最复杂的验证码由6位字母(包括大小写)和数字组成,有干扰点和干扰线
	 * 可自定义干扰点和干扰线的数量
	 * @param width 验证码图片宽度
	 * @param height 验证码图片高度
     * @param fontNumber 字数
	 * @param fontSize 字体大小
	 * @param lineCount 干扰线条数 仅对复杂验证码模式有效
	 * @param pointCount 干扰点 对复杂验证码和中等复杂度验证码有效
	 * @param colours 是否彩色字体
	 * @param border 是否绘制边框
	 * @param complexLevel 复杂度枚举类型,如传入ComplexLevel.SIMPLE
	 * @return Object 数组
	 * 		Object[0]是BufferImage图像信息,可以通过ImageIO.write((BufferImage)Object[0],"JPEG",HttpResponse.getOutputStream())写到客户端<br>
	 * 		Object[1]第二位是验证码字符串
	 */
	public static Object[] getCaptchaImage(int width,int height,int fontNumber,int fontSize,int lineCount,int pointCount,boolean border,boolean colours,ComplexLevel complexLevel);

	/**
	 * 验证码生产类
	 * @param width: 宽度
	 * @param height: 高度
	 * @param fontNumber: 字树
	 * @param fontSize: 字体大小
	 * @return Object[]
	 */
	public static Object[] getCaptchaImage(int width,int height,int fontNumber, int fontSize);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

# ClassUtil包扫描工具类

/**
 * 包扫描工具类
 * @author xiong
 */
public class ClassUtil {

    /**
     * 扫描某个包中某个接口实现、注解等的类
     * @param type: 接口,抽象类等
     * @param packageSuff: 包
     * @param <T>: 返回类型
     * @return Set
     */
    public static <T> Set<Class<? extends T>> getAllClass(Class<T> type, @Nullable String packageSuff);

    /**
     * 扫描SpringBean中某个接口Bean
     * @param type: 返回类型的Class
     * @param <T>: 返回类型
     * @return List
     */
    public static <T> List<T> getBeanClass(Class<T> type);

    /**
     * 扫描指定类型和路径下的class并转变为bean列表
     * @param type: class类型
     * @param packageSuff: 包路径
     * @param <T>: 类型
     * @return List
     */
    public static <T> List<T>  getScanClassToBeanList(Class<T> type, @Nullable String packageSuff);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

# CommandUtil命令执行工具类

/**
 * 命令执行工具
 * @author xiongsoft
 */
public class CommandUtil {

	/**
	 * 执行一条命令,等待执行结束并丢弃执行结果
	 * @param command: 操作系统命令
	 * @throws IOException 异常
	 * @throws InterruptedException 异常
	 */
	public static void execCommand(String command) throws IOException, InterruptedException;

	/**
	 * 执行一条命令,等待执行结束并获得执行结果
	 * @param command: 操作系统命令
	 * @return String
	 * @throws IOException 异常
	 * @throws InterruptedException 异常
	 */
	public static String execCommandResult(String command) throws IOException, InterruptedException;

	/**
	 * 执行多条命令,等待执行结束并丢弃执行结果
	 * @param command: 多条操作系统命令
	 * @throws IOException 异常
	 * @throws InterruptedException 异常
	 */
	public static void execCommand(List<String> command) throws IOException, InterruptedException;

	/**
	 * 执行多条命令,等待执行结束并获得执行结果
	 * @param command: 多条操作系统命令
	 * @return String
	 * @throws IOException 异常
	 * @throws InterruptedException 异常
	 */
	public static String execCommandResult(List<String> command) throws IOException, InterruptedException;

	/**
	 * 执行一条命令,丢弃执行结果
	 * @param command: 操作系统命令
	 * @param waitFor: 是否等待结束
	 * @throws IOException 异常
	 * @throws InterruptedException 异常
	 */
	public static void execCommand(String command, boolean waitFor) throws IOException, InterruptedException;

	/**
	 * 执行一条命令,获得执行结果
	 * @param command: 操作系统命令
	 * @param waitFor: 是否等待结束
	 * @return String
	 * @throws IOException 异常
	 * @throws InterruptedException 异常
	 */
	public static String execCommandResult(String command, boolean waitFor) throws IOException, InterruptedException;

	/**
	 * 执行多条命令,获得执行结果
	 * @param commands: 操作系统命令
	 * @param waitFor: 是否等待结束
	 * @throws IOException 异常
	 * @throws InterruptedException 异常
	 */
	public static void execCommand(List<String> commands, boolean waitFor) throws IOException, InterruptedException;

	/**
	 * 执行一条命令,获得执行结果
	 * @param commands: 操作系统命令
	 * @param waitFor: 是否等待结束
	 * @return String
	 * @throws IOException 异常
	 * @throws InterruptedException 异常
	 */
	public static String execCommandResult(List<String> commands, boolean waitFor) throws IOException, InterruptedException;

	/**
	 * 执行一条命令,丢弃执行结果
	 * @param command: 操作系统命令
	 * @param timeOut: 最长等待时间,单位秒
	 * @throws IOException 异常
	 * @throws InterruptedException 异常
	 */
	public static void execCommand(String command, int timeOut) throws IOException, InterruptedException;

	/**
	 * 执行一条命令,获得执行结果
	 * @param command: 操作系统命令
	 * @param timeOut: 最长等待时间,单位秒
	 * @return String
	 * @throws IOException 异常
	 * @throws InterruptedException 异常
	 */
	public static String execCommandResult(String command, int timeOut) throws IOException, InterruptedException;

	/**
	 * 执行多条命令,丢弃执行结果
	 * @param commands: 操作系统命令
	 * @param timeOut: 最长等待时间,单位秒
	 * @throws IOException 异常
	 * @throws InterruptedException 异常
	 */
	public static void execCommand(List<String> commands, int timeOut) throws IOException, InterruptedException;

	/**
	 * 执行多条命令,获得执行结果
	 * @param commands: 操作系统命令
	 * @param timeOut: 最长等待时间,单位秒
	 * @return String
	 * @throws IOException 异常
	 * @throws InterruptedException 异常
	 */
	public static String execCommandResult(List<String> commands, int timeOut) throws IOException, InterruptedException;

	/**
	 *  执行一条命令,对获得的每行结果行进行回调
	 * @param command: 操作系统命令
	 * @param waitFor: 是否等待,如果设置为tre,则timeOut时间无效
	 * @param action: 按执行结果每行回调函数
	 * @throws IOException 异常
	 * @throws InterruptedException 异常
	 */
	public static void execCommand(String command, boolean waitFor, Consumer<? super String> action) throws IOException, InterruptedException;

	/**
	 *  执行多条命令,对结果行进行回调
	 * @param commands: 操作系统命令
	 * @param waitFor: 是否等待,如果设置为tre,则timeOut时间无效
	 * @param action: 按执行结果每行回调函数
	 * @throws IOException 异常
	 * @throws InterruptedException 异常
	 */
	public static void execCommand(List<String> commands, boolean waitFor, Consumer<? super String> action) throws IOException, InterruptedException;

	/**
	 * 执行一条命令,对结果行进行回调
	 * @param command: 操作系统命令
	 * @param timeOut: 最长等待时间,单位秒
	 * @param action: 按执行结果每行回调函数
	 * @throws IOException 异常
	 * @throws InterruptedException 异常
	 */
	public static void execCommand(String command, int timeOut, Consumer<? super String> action) throws IOException, InterruptedException;

	/**
	 * 执行多条命令,对获得的每行结果行进行回调
	 * @param commands: 操作系统命令
	 * @param timeOut: 最长等待时间,单位秒
	 * @param action: 按执行结果每行回调函数
	 * @throws IOException 异常
	 * @throws InterruptedException 异常
	 */
	public static void execCommand(List<String> commands, int timeOut, Consumer<? super String> action) throws IOException, InterruptedException;

	/**
	 * 执行多条命令,对获得的每行结果行进行回调
	 * @param command: 操作系统命令
	 * @param waitFor: 是否等待,如果设置为tre,则timeOut时间无效
	 * @param timeOut: 最长等待时间,单位秒
	 * @param action: 按执行结果每行回调函数
	 * @throws IOException 异常
	 * @throws InterruptedException 异常
	 */
	public static void doCommand(List<String> command, boolean waitFor, int timeOut, Consumer<? super String> action) throws IOException, InterruptedException;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167

# CookieUtilCookie操作工具类

/**
 * Cookie操作工具类
 * @author xiong
 */
public class CookieUtil {
	/**
	 * 获得cookie中指定名称为name的值
	 * @param request: request
	 * @param name: 名称
	 * @return String
	 */
	public static String getCookieValue(HttpServletRequest request,String name);

	/**
	 * 设置Cookie中的某个值
	 * @param request: request
	 * @param response: response
	 * @param name: 名称
	 * @param value: 值
	 */
	public static void setValue(HttpServletRequest request,HttpServletResponse response,String name,String value);

	/**
	 * 判断Cookie中是否含有某个key
	 * @param request: request
	 * @param name: 名称
	 * @return boolean
	 */
	public static boolean hasCookie(HttpServletRequest request,String name);

	/**
	 * 写Cookie
	 * @param request: HttpServletRequest
	 * @param response: HttpServletResponse
	 * @param name: Cookie的名字
	 * @param value: Cookie的值
	 * @param secure: 是否安全
	 * @param expiry: 过期时间,-1表示关闭浏览器即过期,请给出一个合理有效的值
	 * @param path: 路径
	 */
	public static void addCookie(HttpServletRequest request,HttpServletResponse response,String name,String value,boolean secure,int expiry,String path);

	/**
	 * 移除Cookie中的指定名称的Cookie
	 * @param request: request
	 * @param response: response
	 * @param name: 名称
	 */
	public static void clearCookie(HttpServletRequest request,HttpServletResponse response,String name);

	/**
	 * 清除所有Cookie
	 * @param request: request
	 * @param response: response
	 */
	public static void clearAll(HttpServletRequest request,HttpServletResponse response);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

# DateTimeUtil日期时间工具类

/**
 * 日期工具类
 * @author xiongsoft
 */
public class DateTimeUtil {

	/**
	 * 将数字转换为时间
	 * @param time: 要转换的数字时间
	 * @param outFormat: 输出格式,例如: yyyy-MM-dd HH:mm:ss
	 * @return String
	 */
	public static String convertLongToTime(long time, String outFormat);

	/**
	 * 将字符串时间转换为数字
	 * @param time: 源字符串时间,例如: 2020-01-01 08:08:08
	 * @param inFormat: 源字符串时间格式,例如: yyyy-MM-dd HH:mm:ss
	 * @return Long
	 * @throws ParseException 异常
	 */
	public static Long convertTimeToLong(String time,String inFormat) throws ParseException;

	/**
	 * 获取制定日期的格式化字符串
	 * @param date: 日期
	 * @param outFormat: 目标输出格式,例如: yyyy-MM-dd HH:mm:ss
	 * @return String
	 */
	public static String convertDateToString(Date date, String outFormat);

	/**
	 * 将字符串转换成日期
	 * @param date: 源日期字符串,例如: 2020-01-01 08:08:08
	 * @param inFormat: 源日期字符串格式,例如: yyyy-MM-dd HH:mm:ss
	 * @return Date
	 * @throws ParseException 异常
	 */
	public static Date convertStringToDate(String date, String inFormat) throws ParseException;

	/**
	 * 获取两个日期之间相差的天数
	 * @param beginDate: 开始时间
	 * @param endDate: 结束时间
	 * @return Long
	 * @throws ParseException 异常
	 */
	public static Long getDatePoor(Date beginDate, Date endDate) throws ParseException;

    /**
     * 获取两个时间相差小时数
     * @param beginDate: 开始时间
     * @param endDate: 结束时间
     * @return Long
	 * @throws ParseException 异常
     */
    public static Long getDateDiffHour(Date beginDate, Date endDate) throws ParseException;

    /**
     * 返回当前时间,格式为:yyyy-MM-dd
     * @return String
     */
    public static String getCurrentDate();

	/**
	 * 获得指定格式的当前时间
	 * @param format: 格式
	 * @return String
	 */
	public static String getCurrentDate(String format);

    /**
     * 返回当前时间,格式为:yyyy-MM-dd HH:mm:ss
     * @return String
     */
    public static String getCurrentDateTime();

	/**
	 * 获得指定格式的当前时间
	 * @param format: 日期时间格式
	 * @return String
	 */
	public static String getCurrentDateTime(String format);

	/**
	 * 获取指定年月的第一天
	 * @param year: 年
	 * @param month: 月
	 * @return Date
	 */
	public static Date getFirstDayOfMonth(int year, int month);

	/**
	 * 获取指定年月的最后一天
	 * @param year: 年
	 * @param month: 月
	 * @return Date
	 */
	public static Date getLastDayOfMonth(int year, int month);

	/**
	 * 获取日期所在月天数
	 * @param date: 日期
	 * @return int
	 * @throws ParseException 异常
	 */
	public static int getDaysOfMonth(Date date) throws ParseException;

	/**
	 * 判断哪个日期在前,例如日期1在日期2之前,返回true,否则返回false
	 * @param date1: 日期1
	 * @param date2: 日期2
	 * @return boolean
	 */
	public static boolean isBefore(Date date1, Date date2);

	/**
	 * 是否是闰年
	 * @param year: 年份
	 * @return boolean
	 */
	public static boolean isLeapYear(int year);

    /**
     * 获取指定日期之前或者之后多少天的日期
     * @param day: 指定的时间
     * @param offset: 日期偏移量,正数表示延后,负数表示天前
     * @return Date
     */
    public static Date getDateByOffset(Date day, int offset);

    /**
     * 获取一天开始时间 如 2014-12-12 00:00:00
     * @return Date
     */
    public static Date getDayStart();

    /**
     * 获取一天结束时间,如:2014-12-12 23:59:59
     * @return Date
     */
    public static Date getDayEnd();

    /**
     * 时间分段
     * 比如:2014-12-12 10:00:00 ~ 2014-12-12 14:00:00
     * 分成两段就是 2014-12-12 10:00:00 ~ 2014-12-12 12:00:00 和2014-12-12 12:00:00 ~ 2014-12-12 14:00:00
     * @param start: 起始日期
     * @param end: 结束日期
     * @param pieces: 分成几段
	 * @return Date[]
     */
    public static Date[] getDatePieces(Date start,Date end,int pieces);

    /**
     * 获取从startDate时间开始前或后的时间
     * @param startDate: 开始时间
     * @param Type: 类型,Y或y代表年:,M或m代表月,D或d代表日,H或h代表小时,M或m代表分钟,S或s代表秒,W或w代表周
     * @param number: 具体数字,负数代表之前,正数代表之后
     * @param beginDate: 获得的最后时间开始日期,为0或者负数代表当前时间,例如:Type值为M,beginDate值为1代表第一天,Type值为W,beginDate值为1代表星期一,以此类推
     * @param outDataFormat: 输出的日期字符串格式,默认为yyyy-MM-dd HH:mm:ss格式
     * @return 从startDate时间开始前或后的时间字符串
     */
    public static String getBeforeOrAfterDate(Date startDate, String Type, int number, int beginDate, String outDataFormat);

	/**
	 * 获取从startDate时间开始前或后的时间
	 * @param startDate: 开始时间
	 * @param Type: 类型,Y或y代表年:,M或m代表月,D或d代表日,H或h代表小时,M或m代表分钟,S或s代表秒,W或w代表周
	 * @param number: 具体数字,负数代表之前,正数代表之后
	 * @return String
	 */
    public static String getBeforeOrAfterDate(Date startDate, String Type, int number);

	/**
	 * 获取从startDate时间开始前或后的时间
	 * @param startDate: 开始时间
	 * @param Type: 类型,Y或y代表年:,M或m代表月,D或d代表日,H或h代表小时,M或m代表分钟,S或s代表秒,W或w代表周
	 * @param number: 具体数字,负数代表之前,正数代表之后
	 * @param beginDate: 获得的最后时间开始日期,为0或者负数代表当前时间,例如:Type值为M,beginDate值为1代表第一天,Type值为W,beginDate值为1代表星期一,以此类推
	 * @return String
	 */
    public static String getBeforeOrAfterDate(Date startDate, String Type, int number, int beginDate);

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184

# ExceptionUtil异常包装工具类

/**
 * lamda异常包装工具类,用于包装lamda从而省略lamda内的异常处理
 */
public class ExceptionUtil {

    @FunctionalInterface
    public interface ThrowingConsumer<T, E extends Exception> {
        void accept(T t) throws E;
    }

    /**
     * 用于Consumer异常处理
     * @param throwingConsumer: Consumer类型
     * @param <T>: T
     * @return T
     */
    public static <T> Consumer<T> consumerWrapper(ThrowingConsumer<T, Exception> throwingConsumer);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

# FileUtil文件工具类

/**
 * 文件工具类
 */
public class FileUtil {
    /**
     * 创建Excel文件
     * @param pathName: 带绝对路径的文件名
     * @param sheet: 分别对多个sheet表的处理
     * @throws IOException 异常
     */
    public static void createExcelFile(@NonNull String pathName, Consumer<? super SXSSFSheet>... sheet) throws IOException;

    /**
     * 文件拷贝
     * @param srcFile: 源文件
     * @param targetFile: 目标文件
     * @throws IOException 异常
     */
    public static void copy(String srcFile, String targetFile) throws IOException;

    /**
     * 流拷贝
     * @param input: InputStream
     * @param output: OutputStream
     * @return size
     * @throws IOException 异常
     */
    public static long streamCopy(InputStream input, OutputStream output) throws IOException;

    /**
     * 设置文件的自定义属性(与操作系统有关,不支持mac)
     * @param path: 文件path
     * @param key: 关键字
     * @param val: 值
     * @throws IOException 异常
     */
    public static void setFileExtAttribute(Path path, String key, String val) throws IOException;

    /**
     * 获取文件的自定义属性(与操作系统有关,不支持mac)
     * @param path: 文件path
     * @param key: 关键字
     * @return String
     * @throws IOException 异常
     */
    public static String getFileExtAttribute(Path path, String key) throws IOException;

    /**
     * 根据目录文件名创建文件目录
     * @param pathFileName: 带路径的文件名
     * @throws IOException 异常
     */
    public static void mkdirFilePath(String pathFileName) throws IOException;

    /**
     * 将指定目录下的不在files中的文件删除
     * @param directories: 目录
     * @param files: 要保留的文件列表
     * @param isDelEmpty: 是否删除空目录
     * @throws IOException 异常
     */
    public static void syncDirectories(String directories, Collection<String> files, boolean isDelEmpty) throws IOException;

    /**
     * 上传文件
     * @param file: 文件
     * @param fileName: 存储的文件名,为空使用原始文件名
     * @param savePath: 存储路径
     * @return File
     */
    public static File upload(@RequestParam("file") MultipartFile file, @Nullable String fileName, @NonNull String savePath);

    /**
     * 下载文件
     * @param response: HttpServletResponse
     * @param pathFileName: 带绝对路径的文件名
     * @param toFileName: 要存为的文件名
     * @param isDelFile: 下载后是否删除
     * @param tempPath: 临时文件存储路径(下载目录时对目录压缩打包时使用)
     * @param pathReplace: 将zip文件中的去掉路径中包含的指定字符串(下载目录时对目录压缩打包时使用)
     * @return boolean
     * @throws IOException 异常
     */
    public static boolean downFile(HttpServletResponse response, String pathFileName, String toFileName, boolean isDelFile,String tempPath,String pathReplace) throws IOException;

    /**
     * 将文件发送到浏览器端,常用语图片浏览等
     * @param response: HttpServletResponse
     * @param pathFileName: 带绝对路径的文件
     * @return boolean
     */
    public static boolean seeFile(HttpServletResponse response, String pathFileName);

    /**
     * 删除一个文件
     * @param pathFileName: 带路径的文件名称
     * @throws IOException 异常
     */
    public static void deleteFile(String pathFileName) throws IOException;

    /**
     * 删除指定目录下的files集合中包含的文件
     * @param directoriee: 要检查的目录
     * @param files: 要删除的文件列表
     */
    public static void deleteInFiles(String directoriee, Collection<String> files);

    /**
     * 追加一行文本到文件,如果文件不存在,则自动创建
     * @param fileName: 文件名
     * @param content: 增加的内容
     */
    public static void appendLineToFile(String fileName, String content);

    /**
     * 将内容写入文件
     * @param dest:写入的文件
     * @param append:是否追加
     * @param newLine:是否换行
     * @param content:写入的内容
     * @throws IOException 异常
     */
    public static void writeToFile(String dest, boolean append, boolean newLine, String content) throws IOException;

    /**
     * 获取文件行数
     * @param src:源文件
     * @return int
     * @throws IOException 异常
     */
    public static int readLineNumber(String src) throws IOException;

    /**
     * 获取文件内容
     * @param src: 源文件
     * @param charset: 编码
     * @return List文件内容数组,每行占一个数组空间
     * @throws IOException 异常
     */
    public static List<String> getContentList(String src, Charset charset) throws IOException;

    /**
     * 获取文件内容
     * @param src: 源文件
     * @param charset: 字符集
     * @return String 文件内容
     * @throws IOException 异常
     */
    public static String getContentString(String src, Charset charset) throws IOException;

    /**
     * 获取文件后缀名
     * @param file: File文件
     * @return 如果没有后缀名则返回null
     */
    public static String getFileSuffix(File file);

    /**
     * 获取文件后缀名
     * @param fileName: 文件名
     * @return 如果没有后缀名则返回null
     */
    public static String getFileSuffix(String fileName);

    /**
     * 删除文件或目录
     * @param pathOrFileName: 文件或目录路径
     * @throws IOException 异常
     */
    public static void delete(String pathOrFileName) throws IOException;

    /**
     * 删除目录及目录下的所有文件
     * @param path: 要删除的目录路径
     * @throws IOException 异常
     */
    public static void deleteDirectories(String path) throws IOException;

    /**
     * 拷贝或移动目录及子目录下的所有文件到目标目录
     * @param srcPath: 源目录
     * @param targetPath: 目标目录
     * @param isMove: true移动文件,false:拷贝文件
     * @throws IOException 异常
     */
    public static void copyOrMoveDirectories(String srcPath, String targetPath, boolean isMove) throws IOException;

    /**
     * 拷贝或移动目录及子目录下的files中指定的文件到目标目录
     * @param srcPath: 源目录
     * @param targetPath: 目标目录
     * @param isMove: true移动文件,false:拷贝文件
     * @param files: 要拷贝或移动的文件列表
     * @throws IOException 异常
     */
    public static void copyOrMoveFiles(String srcPath, String targetPath, boolean isMove, Collection<String> files) throws IOException;

    /**
     * 移动文件
     * @param srcPathFileName: 带全路径的源文件
     * @param targetPathFileName: 带路径的目标文件
     * @param options: 选项
     * @throws IOException 异常
     */
    public static void move(String srcPathFileName, String targetPathFileName, CopyOption... options) throws IOException;

    /**
     * 获取文件MD5
     * @param filePath: 文件路径
     * @return String
     * @throws NoSuchAlgorithmException 异常
     * @throws IOException 异常
     */
    public static String getFileMD5(String filePath) throws NoSuchAlgorithmException, IOException;

    /**
     * 以进程锁的方式获取Property文件中的值
     * @param pathFileName: 文件绝对路径及文件名
     * @param key: 关键字
     *  @param delaultValue: 缺省值
     * @return String
     */
    public static String getFileKeyValue(String pathFileName,String key,String delaultValue);

    /**
     * 以进程锁的方式获取Property文件中的值
     * @param pathFileName: 文件绝对路径及文件名
     * @param key: 关键字
     * @return Map
     */
    public static Map<String,String> getFileKeyValue(String pathFileName, String... key);

    /**
     * 以进程锁的方式写入Property文件中
     * @param pathFileName:文件绝对路径及文件名
     * @param key: 关键字
     * @param value: 值
     * @return boolean
     */
    public static boolean setFileKeyValue(String pathFileName,String key, String value);

    /**
     * 以进程锁的方式写入Property文件中
     * @param pathFileName: 文件绝对路径及文件名
     * @param map: Map
     * @return boolean
     */
    public static boolean setFileKeyValue(String pathFileName,Map<String,String> map);

    /**
     * 以进程锁的方式写入Property文件中
     * @param pathFileName: 文件绝对路径及文件名
     * @param keyValues: 值
     * @return boolean
     */
    public static boolean setFileKeyValue(String pathFileName,String... keyValues);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257

# FontsUtil字体工具类

/**
 * 字体工具类
 */
public class FontsUtil {

    /**
     * 安装用户字体
     */
    public static void installFonts();

    /**
     * 获得指定字体
     * @param fontName: 字体名称
     * @param fontStyle: 字体样式
     * @param size: 字体大小
     * @return Font
     */
    public static Font getFont(String fontName, int fontStyle, float size);

    /**
     * 获得系统字体名称列表
     * @return list
     */
    public static List<String> systemFontNameList();

    /**
     * 获得用户定义的字体名称列表
     * @return list
     */
    public static List<String> getUserFontNameList();
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

# HardwareUtil硬件信息工具类

/**
 * 硬件信息工具类
 * @author xiongsoft
 */
public class HardwareUtil {

	/**
     * 获取主板序列号
     * @return String
     * @throws IOException 异常
     */
    public static String getMotherboardSN() throws IOException;

    /**
     * 获取硬盘序列号
     * @param drive: 盘符
     * @return String
     * @throws IOException 异常
     */
    public static String getHardDiskSN(String drive) throws IOException;

    /**
     * 获取CPU序列号
     * @return String
     * @throws IOException 异常
     */
    public static String getCPUSerial() throws IOException;

    /**
     * 获得服务器网卡MAC地址
     * @return Set
     * @throws SocketException 异常
     */
    public static Set<String> getMacList() throws SocketException;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

# HttpUtils网络请求工具类

/**
 * http网络请求工具类
 */
public class HttpUtils {

    /**
     * 通过http请求获得字符串数据
     * @param strUrl: url地址
     * @param map: 参数
     * @return String
     */
    public static String URLGet(String strUrl, Map map);

    /**
     * 以指定的方式发送数据
     * @param method: 方法, POST 或 GET
     * @param url: url地址
     * @param data: 要发送的数据
     * @param content: Content-Type类型
     * @return String
     * @throws IOException 异常
     */
    public static String PostOrGet(String method, String url, String data, String content) throws IOException;

    /**
     * 发送json个数数据
     * @param url: 目标地址
     * @param json: JSON数据
     * @return String
     * @throws IOException 异常
     */
    public static String URLPostJson(String url, JSONObject json) throws IOException;

    /**
     * 隐式post提交
     * @param url: 目标地址
     * @param map: 参数集合
     * @throws IOException 异常
     * @return String
     */
    public static String URLPost(String url, Map map) throws IOException;

    /**
     * 解析参数集合map,获取拼装字符串
     * @param map: Map对象
     * @return String
     */
    private static String getUrl(Map map);

    /**
     * 将目标url地址的执行结果静态化并压缩为html文件,并返回html代码
     * @param destUrl: 目标url地址
     * @param path: 静态化后的html文件存放目录
     * @param fileName: 静态化后的html文件名
     * @param purgeUrl: 清空指定URL地址的缓存
     * @throws IOException 异常
     * @return String
     */
    public static String saveUrlToHtml(String destUrl, String path,String fileName,String purgeUrl) throws IOException;

    /**
     * 将html代码静态化并压缩为html文件
     * @param htmlCode: html代码
     * @param path: 静态化后的html文件存放目录
     * @param fileName: 静态化后的html文件名
     * @param purgeUrl: 要清空的缓存页面URL
     * @throws IOException 异常
     * @return String
     */
    public static String saveHtmlToHtml(String htmlCode, String path,String fileName,String purgeUrl) throws IOException;

    /**
     * 获取指定HTML标签的指定属性的值,例如获取图片的src列表:getMatch(html,"img","src")
     * @param html 要匹配的源html
     * @param element 标签名称
     * @param attr 标签的属性名称
     * @return 属性值列表
     */
    public List<String> getMatch(String html, String element, String attr);

    /**
     * 清空nginx指定页面的缓存
     * @param url: url地址
     * @throws IOException 异常
     */
    public static void purgeHtml(String url) throws IOException;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87

# ImageUtil图片转码工具类

/**
 * 图片转码工具类
 */
public class ImageUtil {
    /**
     * 将base64字符串转换为图片
     * @param base64: base64格式的图片字符串
     * @return BufferedImage
     * @throws IOException 异常
     */
    public static BufferedImage base64StringToImage(String base64) throws IOException;

    /**
     * 将base64字符串转换为图片并写入指定的文件
     * @param base64: base64格式的图片字符串
     * @param pathFileName: 要存放的文件绝对路径及名称
     * @throws IOException 异常
     */
    public static void base64StringToImageFile(String base64, String pathFileName) throws IOException;

    /**
     * 将base64字符串转换为指定格式的图片并写入指定的文件
     * @param base64: base64格式的图片字符串
     * @param pathFileName: 要存放的文件绝对路径及名称
     * @param imageFormat: 图片格式
     * @throws IOException 异常
     */
    public static void base64StringToImageFile(String base64, String pathFileName, String imageFormat) throws IOException/**
     * 将图片文件转换为jpg格式的Base64字符串
     * @param file: 文件
     * @return String
     * @throws IOException 异常
     */
    public static String ImageToBase64String(File file) throws IOException/**
     * 将图片文件转换为指定格式的Base64字符串
     * @param file: 文件
     * @param imageFormat: 文件格式
     * @return String
     * @throws IOException 异常
     */
    public static String ImageToBase64String(File file, String imageFormat) throws IOException}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

# MapUtilMap对象工具类

/**
 * Map对象工具
 * @author xiong
 */
public class MapUtil {

    /**
     * 将map中字符串数组值转为以逗号分隔的字符串(常用于request参数转置)
     * @param srcMap: 要转置的map
     * @return Map
     */
    public static Map<String, String> conver(Map<String, String[]> srcMap);

    /**
     * 比较两个map对象及值是否相等
     * @param o1: JSONObject
     * @param o2: JSONObject
     * @return boolean
     */
    public static boolean isEquals(JSONObject o1, JSONObject o2);

    /**
     * map对象的格式转换
     * @param obj: Map对象
     * @return Map
     */
    public static Map<String, String> changeMap(Map<String, Object> obj);

    /**
     * map转换为对象
     * @param map: 数据map
     * @param beanClass: 业务类
     * @param <T> T
     * @return T
     * @throws InstantiationException 异常
     * @throws IllegalAccessException 异常
     * @throws IntrospectionException 异常
     * @throws IllegalArgumentException 异常
     */
    public static <T> T mapToObject(Map<String, Object> map, Class<T> beanClass) throws InstantiationException, IntrospectionException, IllegalAccessException, IllegalArgumentException;

    /**
     * 提取request参数。
     * @param request: request
     * @return HashMap
     */
    public static HashMap getRequestData(HttpServletRequest request);

    /**
     * 将json格式的字符串解析成Map对象
     * @param str: 字符串
     * @return HashMap
     */
    public static HashMap<String, String> jsonToMap(String str);

    /**
     * 业务对象转map
     * @param vo: 对象
     * @return HashMap
     * @throws IllegalArgumentException 异常
     * @throws IllegalAccessException 异常
     */
    public static HashMap<String, Object> objectToMap(Object vo) throws IllegalArgumentException, IllegalAccessException;

    /**
     * 业务对象转换为map,插入sql需要
     * @param vo: 对象
     * @return HashMap
     * @throws IllegalArgumentException 异常
     * @throws IllegalAccessException 异常
     */
    public static HashMap<String, Object> objectToMapForSql(Object vo) throws IllegalArgumentException, IllegalAccessException;

    /**
     * 检查map中是否存在name,注意:map中的key可能前后带%号匹配符
     * @param name: 要查找的字符串
     * @param map: 可能key带%号的map
     * @return String
     */
    public static String isExistsInMap(String name, Map<String,?> map);

    /**
     * 对新旧列表进行比较,获取新增加的元素列表map.get("add"),获取删除的元素列表map.get("del")
     * @param oldList: 原始List列表
     * @param newList: 新列List表
     * @return Map
     */
    public static Map<String, List> getDiff(List oldList, List newList);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89

# Md5UtilMd5工具类

/**
 * Md5工具类
 * @author xiong
 */
public class Md5Util {
    /**
     * 对字符串生成MD5
     * @param text: 字符串
     * @return String
     * @throws NoSuchAlgorithmException 异常
     * @throws UnsupportedEncodingException 异常
     */
    public static String encodeMD5(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# MoneyUtil金额转换工具类

/**
 * 金额转换工具类
 */
public class MoneyUtil {
    /**
     * 将字符串数字金额转换为中文金额
     * @param bigdMoneyNumber: 金额
     * @return String
     */
    public static String getChnMoney(String bigdMoneyNumber);

    /**
     * 将数字金额转换为中文金额
     * @param bigdMoneyNumber: 金额
     * @return String
     */
    public static String getChnMoney(double bigdMoneyNumber);

    /**
     * 将数字金额转换为中文金额
     * @param bigdMoneyNumber: 金额
     * @return String
     */
    public static String getChnMoney(BigDecimal bigdMoneyNumber);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

# NetUtil网络工具包类

/**
 * 网络工具包类
 * @author xiongsoft
 */
public class NetUtil {

	/**
	 * 获得当前运行的进程ID
	 * @return String
	 */
	public static String getProcessID();

    /**
     * 获得当前运行的 进程号@机器名称:IP
     * @return String
	 * @throws UnknownHostException 异常
     */
    public static String getLocalProcessIP() throws UnknownHostException;

	/**
	 * 获得当前机器的IP地址
	 * @return String
	 * @throws UnknownHostException 异常
	 */
	public static String getIP() throws UnknownHostException;

	/**
	 * 获得tomcat运行时监听的端口
	 * @return String
	 * @throws MalformedObjectNameException 异常
	 */
	public static String getPort() throws MalformedObjectNameException;

    /**
     * 获得用户访问的真实IP地址
     * @param request: request
     * @return String,真实的IP地址
     */
    public static String getIpAddr(HttpServletRequest request);

    /**
	 * IP地址是否可达
	 * @param ip: IP地址
	 * @return boolean
	 */
	public static boolean isReachable(String ip);

	/**
	 * 判断网址是否有效,注意:对于404页面,如果被电信或者联通劫持了,也会返回200的状态,这个是不准确的
	 * @param url URL对象
	 * @return boolean
	 */
	public static boolean isReachable(URL url);

	/**
	 * 实现Ping命令
	 * @param ip: IP地址
	 * @return String Ping的字符串换行使用java的换行符"\n",如果ping不通返回null
	 * @throws IOException 异常
	 * @throws InterruptedException 异常
	 */
	public static String ping(String ip) throws IOException, InterruptedException;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64

# NumberUtil数字处理工具类

/**
 * 数字处理工具类
 */
public class NumberUtil {

    /**
     * 判断字符串是否只有数字(包括0)
     * @param str:原始字符串
     * @return 只有数字为true,否则为false
     */
    public static boolean isNumeric(String str);

    /**
     * 判断是否正整数
     *
     * @param number
     *            数字
     * @return boolean true,通过,false,没通过
     */
    public static boolean isNumber(String number);

    /**
     * 判断几位小数(正数)
     *
     * @param decimal:数字
     * @param count:小数位数
     * @return boolean true,通过,false,没通过
     */
    public static boolean isDecimal(String decimal, int count);

	/**
     * 返回科学计算后的乘法结果
     * @param val1: 数1
     * @param val2: 数2
     * @param mc: 精度
     * @return double
     */
    public static double multiply(double val1,double val2,int mc);

    /**
     * 返回科学计算后的除法结果
     * @param fz: 分子
     * @param fm: 分母
     * @param mc: 精度,小数点后保留几位
     * @return double
     */
    public static double divide(double fz,double fm,int mc);

    /**
     * 返回科学计算后的减法结果
     * @param val1: 值1
     * @param val2: 值2
     * @param mc: 精度,小数点后保留几位
     * @return double
     */
    public static double subtract(double val1,double val2,int mc);

    /**
     * 返回科学计算后的加法结果
     * @param val1: 值1
     * @param val2: 值2
     * @param mc: 精度,小数点后保留几位
     * @return double
     */
    public static double add(double val1,double val2,int mc);

    /**
     * 小数格式化
     * @param value: 原值
     * @param precision: 精度,小数点后保留几位
     * @param round: 是否四舍五入
     * @return String
     */
    public static String numberFormat(String value,int precision,boolean round);

    /**
     * 小数格式化
     * 格式化表达式如:
     * 0:取一位整数
     * 0.00:取一位整数两位小数
     * 00.000:取两位整数和三位小数,整数不足部分以0填补
     * #:取所有整数部分
     * #.##%:以百分比方式计数,并取两位小数
     * #.#####E0:显示为科学计数法,并取五位小数
     * 00.####E0:显示为两位整数的科学计数法,并取四位小数
     * ,###:每三位以逗号进行分隔
     * 光速大小为每秒,###米: 将格式嵌入文本
     * @param expression: 格式化表达式
     * @param value: 值
     * @return String
     */
    public static String numberFormat(double value,String expression);

    /**
     * 根据地区格式化数字
     * @param expression: 格式化表达式
     * @param value: 值
     * @param locale: 地区Locale的地区静态常量
     * @return String
     */
    public static String numberFormat(double value,String expression, Locale locale);

    /**
     * 返回指定身份证的性别。
     * @param CardNumber: 身份证号
     * @return 返回性别,男或者女的字符串
     */
    public static String getSexFromCardNumber(String CardNumber);

    /**
     * 根据出生日期返回当前年龄。
     * @param birthday: 出生日期
     * @return 返回年龄
     */
    public static int getAge(String birthday);

    /**
     * 判断是否是手机号码
     * @param phoneNumber: 手机号码
     * @return true:通过, false:没通过
     */
    public static boolean isPhoneNumber(String phoneNumber);
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124

# ObjectUtil对象转换工具类

/**
 * Object对象转换工具类
 */
public class ObjectUtil {

    /**
     * 判定对象是否为空
     * @param obj: Object
     * @return boolean
     */
    public static boolean isEmpty(Object obj);

    /**
     * 判定对象是否不为空
     * @param obj: Object
     * @return boolean
     */
    public static boolean isNotEmpty(Object obj);

    /**
     * 返回对象的hashcode值
     * @param object: Object
     * @return String
     */
    public static String getHashCode(Object object);

    /**
     * 结构集转化,业务对象(列表)
     * @param resMsg: ResMsg
     * @param beanClass: 要转出的类型名称
     * @param <T> T类型
     * @return T
     * @throws InstantiationException 异常
     * @throws IntrospectionException 异常
     * @throws IllegalAccessException 异常
     * @throws IllegalArgumentException 异常
     */
    public static  <T> T dataToObjectList(ResMsg resMsg, Class<?> beanClass) throws InstantiationException, IntrospectionException, IllegalAccessException, IllegalArgumentException;

    /**
     * 结构集转化,业务对象  (单对象)
     * @param resMsg: ResMsg
     * @param beanClass: 要转出的类型名称
     * @param <T>: T类型
     * @return T
     * @throws InstantiationException 异常
     * @throws IntrospectionException 异常
     * @throws IllegalAccessException 异常
     * @throws IllegalArgumentException 异常
     */
    public static  <T> T dataToObject(ResMsg resMsg, Class<?> beanClass) throws InstantiationException, IntrospectionException, IllegalAccessException, IllegalArgumentException;

    /**
     * 转换
     * @param obj: Object
     * @param PropertyName: PropertyName
     * @return Object
     * @throws IllegalAccessException 异常
     * @throws InvocationTargetException 异常
     * @throws NoSuchMethodException 异常
     */
    public static Object getBeanOnePropertyVal(Object obj,String PropertyName) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException;

    /**
     * 对象转换为map
     * @param obj: Object
     * @return Map
     * @throws IntrospectionException 异常
     * @throws IllegalAccessException 异常
     * @throws IllegalArgumentException 异常
     * @throws InvocationTargetException 异常
     */
    public static Map<String, String> objectToMap(Object obj) throws IntrospectionException, IllegalAccessException, IllegalArgumentException, InvocationTargetException;

    /**
     * 常规类型转换
     * @param targetObj: Object
     * @param needClassName: String
     * @return Object
     */
    public static Object objToObj(Object targetObj,String needClassName);
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83

# PropertiesUtil属性文件读写工具类

/**
 * Properties属性文件读写工具类
 * @author xiongsoft
 */
public class PropertiesUtil {

	/**
	 * 读取Properties配置文件内容
	 * @param filePath: 文件路径及名称
	 * @return Properties
	 * @throws IOException 异常
	 */
	public static Properties readProperties(String filePath) throws IOException;

	/**
	 * 写key-value到properties文件 相同的key会被覆盖 追加不同的key-value
	 * @param key 键
	 * @param value 值
	 * @param filePath 文件路径
	 * @param comment key-value的注释
	 * @throws FileNotFoundException 异常
	 * @throws IOException 异常
	 */
	public static void writeProperties(String filePath,String key,String value,String comment) throws FileNotFoundException, IOException;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

# RandomUtil随机数工具类

/**
 * 随机数工具类
 * @author xiong
 */
public class RandomUtil {

	/**
	 * 获得时间数字作为UUID
	 * @return long
	 */
	public static long getShortUUID();

	/**
	 * 获取只有大写字母的16位uuid
	 * @return String
	 */
	public static String getUUID16();

	/**
	 * 获取大写的32位uuid
	 * @return String
	 */
	public static String getUUID32();

	/**
	 * 获取一个固定长度的随机整数
	 * @param size: 数字长度
	 * @return String
	 */
	public static String getRandomNumber(int size);

	/**
	 * 获取一个随机的字符串,包括数字,小写英文字母和大写英文字母
	 * @param size: 字符串长度
	 * @param withNumber: 是否包含数字
	 * @return String
	 */
	public static String getRandomString(int size, boolean withNumber);

	/**
	 * 获取指定长度的随机小写英文字母
	 * @param size: 长度
	 * @return String
	 */
	public static String getRandomLowercaseString(int size);

	/**
	 * 获取指定长度的随机大写英文字母
	 * @param size: 长度
	 * @return String
	 */
	public static String getRandomUppercaseString(int size);

	/**
	 * 获取一个双精度随机数
	 * @return Double
	 */
	public static Double getRandomDouble();

	/**
	 * 获取UUID
	 * @return String
	 */
	public static String getUUID();

	/**
	 * 获取某个区间的整形
	 * @param min: 最小值
	 * @param max: 最大值
	 * @return int
	 */
	public static int getRandomInt(int min, int max);

	/**
	 * 获取一个随机整形值
	 * @return int
	 */
	public static int getRandomInt();
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80

# ReflectUtil反射工具类

/**
 * 反射工具类
 */
public class ReflectUtil {

	/**
	 * 获取成员变量的修饰符
	 * @param clazz: 类型
	 * @param field: 字段
	 * @param <T>  T
	 * @return int
	 */
	public static <T> int getFieldModifier(Class<T> clazz, String field);

	/**
	 * 获取成员方法的修饰符
	 * @param clazz: 类型
	 * @param method: 方法
	 * @param <T>  T
	 * @return int
	 */
	public static <T> int getMethodModifier(Class<T> clazz, String method);

	/**
	 * [对象]根据成员变量名称获取其值
	 * @param clazzInstance: 类型
	 * @param field: 字段
	 * @param <T>  T
	 * @return Object
	 * @throws SecurityException 异常
	 * @throws IllegalArgumentException 异常
	 * @throws IllegalAccessException 异常
	 */
	public static <T> Object getFieldValue(Object clazzInstance, Object field) throws SecurityException, IllegalArgumentException, IllegalAccessException;

	/**
	 * [类]根据成员变量名称获取其值(默认值)
	 * @param clazz: 类型
	 * @param field: 字段
	 * @param <T>  T
	 * @return Object
	 * @throws SecurityException 异常
	 * @throws IllegalArgumentException 异常
	 * @throws IllegalAccessException 异常
	 * @throws InstantiationException 异常
	 */
	public static <T> Object getFieldValue(Class<T> clazz, String field) throws SecurityException, IllegalArgumentException, IllegalAccessException, InstantiationException;

	/**
	 * 获取所有的成员变量
	 * @param clazz: 类型
	 * @param <T>  T
	 * @return String[]
	 */
	public static <T> String[] getFields(Class<T> clazz);

	/**
	 * 获取所有的成员变量,包括父类
	 * @param clazz: 类型
	 * @param superClass: 是否包括父类
	 * @param <T>  T
	 * @return Field[]
	 */
	public static <T> Field[] getFields(Class<T> clazz, boolean superClass);

	/**
	 * 指定类,调用指定的无参方法
	 * @param clazz: 类型
	 * @param method: 方法
	 * @param <T>  T
	 * @return Object
	 * @throws NoSuchMethodException 异常
	 * @throws SecurityException 异常
	 * @throws IllegalAccessException 异常
	 * @throws IllegalArgumentException 异常
	 * @throws InvocationTargetException 异常
	 * @throws InstantiationException 异常
	 */
	public static <T> Object invoke(Class<T> clazz, String method) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException;

	/**
	 * 通过对象访问其方法
	 * @param clazzInstance: 类
	 * @param method: 方法
	 * @param <T>  T
	 * @return Object
	 * @throws NoSuchMethodException 异常
	 * @throws SecurityException 异常
	 * @throws IllegalAccessException 异常
	 * @throws IllegalArgumentException 异常
	 * @throws InvocationTargetException 异常
	 */
	public static <T> Object invoke(Object clazzInstance, String method) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException;

	/**
	 * 指定类,调用指定的方法
	 * @param clazz: 类型
	 * @param method: 方法
	 * @param paramClasses: 参数类数组
	 * @param params: 参数数组
	 * @param <T>  T
	 * @return Object
	 * @throws InstantiationException 异常
	 * @throws IllegalAccessException 异常
	 * @throws NoSuchMethodException 异常
	 * @throws SecurityException 异常
	 * @throws IllegalArgumentException 异常
	 * @throws InvocationTargetException 异常
	 */
	public static <T> Object invoke(Class<T> clazz, String method, Class<T>[] paramClasses, Object[] params) throws InstantiationException, IllegalAccessException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException;

	/**
	 * 通过类的实例,调用指定的方法
	 * @param clazzInstance: 类
	 * @param method: 方法
	 * @param paramClasses: 参数类数组
	 * @param params: 参数数组
	 * @param <T>  T
	 * @return Object
	 * @throws IllegalAccessException 异常
	 * @throws NoSuchMethodException 异常
	 * @throws SecurityException 异常
	 * @throws IllegalArgumentException 异常
	 * @throws InvocationTargetException 异常
	 */
	public static <T> Object invoke(Object clazzInstance, String method, Class<T>[] paramClasses, Object[] params) throws IllegalAccessException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException;

	/**
	 * 获得对象中指定字段值
	 * @param object: 任意对象
	 * @param field: 字段名称
	 * @return Object
	 * @throws InstantiationException 异常
	 * @throws IllegalAccessException 异常
	 */
	public static Object getFieldValue(Object object, String field) throws InstantiationException, IllegalAccessException;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138

# SerializeUtil序列化工具类

/**
 * 序列化工具类
 * @author xiong
 */
public class SerializeUtil {

    /**
     * 将对象序列化为字节数组
     * @param obj: 对象
     * @return byte[]
     * @throws IOException 异常
     */
    public static byte[] serializeToBytes(Object obj) throws IOException;

    /**
     * 将字节数组反序列化为对象
     * @param bytes: 字节数组
     * @return Object
     * @throws IOException 异常
     * @throws ClassNotFoundException 异常
     */
    public static Object deserialize(byte[] bytes) throws IOException, ClassNotFoundException;

    /**
     * 对象序列化为字符串
     * @param obj: 对象
     * @return String
     * @throws IOException 异常
     */
    public static String serializeToString(Object obj) throws IOException;

    /**
     * 字符串反序列化为对象
     * @param serStr: 字符串
     * @param <T> T
     * @return T
     * @throws IOException 异常
     * @throws ClassNotFoundException 异常
     */
    public static <T> T deserialize(String serStr) throws IOException, ClassNotFoundException;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

# ServerInfoUtil服务器信息工具类

/**
 * 服务器信息工具类
 */
public class ServerInfoUtil {

    /**
     * 获得服务器基本信息
     * @return List
     */
    public static List<Map<String, Object>> getServerInfo();

    /**
     * 获得Java信息
     * @return List
     */
    public static List<Map<String, Object>> getJavaInfo();

    /**
     * 获得内存信息
     * @return List
     */
    public static List<Map<String, Object>> getMemoInfo();

    /**
     * 获得jvm的内存信息
     * @return List
     */
    public static List<Map<String, Object>> getJvmInfo();

    /**
     * 获得磁盘信息
     * @return List
     */
    public static List<Map<String, Object>> getDiskInfo();

    /**
     * 获得服务器整体负载情况
     * @return List
     */
    public static List<Map<String, Object>> getSystemLoad();
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

# SessionUtil Session工具类

/**
 * Session工具类
 * @author xiong
 */
public class SessionUtil {
    /** jwt放到cookie中的token名称 */
    public final static String SESSION_TOKEN_KEY = "token";
    /** jwt放到request中缓存解析后的claims的名称 */
    public final static String SESSION_CLAIMS = "claims";
    /** SESSION 中项目编号的关键字key名称 */
    public final static String SESSION_PROJECTNAME = "projectName";
    /** SESSION 中数据库账套的关键字key名称 */
    public final static String SESSION_DBKEY = "dbKey";
    /** SESSION 判断用户登录的关键字key的名称 */
    public final static String SESSION_KEY = "user";
    /** SESSION 判断是否JWT方式登录的关键字key的名称 */
    public final static String SESSION_ISJWT = "isJWT";
    /** SESSION 中语言码key的名称 */
    public final static String SESSION_I18N = "i18n";

    /**
     * 获得是否是JWT登录方式
     * @return Boolean
     */
    public static Boolean getIsJWT() throws IllegalStateException;

    /**
     * 获得 Request
     * @return HttpServletRequest | null
     * @throws IllegalStateException 异常
     */
    public static HttpServletRequest getRequest() throws IllegalStateException;

    /**
     * 获得 Response
     * @return HttpServletResponse | null
     * @throws IllegalStateException 异常
     */
    public static HttpServletResponse getResponse() throws IllegalStateException;

    /**
     * 获得cookie中token值
     * @return String
     */
    public static String getToken();

    /**
     * 获得当前用户数据库账套编号
     * @return String
     */
    public static String getDbKey();

    /**
     * 获得当前用户的当前项目编号
     * @return String
     */
    public static String getProjectName();

    /**
     * 设置登录用户实体到request临时变量中
     * @param sessionUser: 用户类
     */
    public static void setSessionUser(SessionUser sessionUser);

    /**
     * 获得当前登录用户
     * @return SessionUser
     */
    public static SessionUser getSessionUser();

    /**
     * 获得指定类型的当前用户(该类型为SessionUser的子类)
     * @param tClass: SessionUser子类类型类
     * @param <T>: SessionUser子类类型
     * @return T
     * @throws NoSuchMethodException 异常
     * @throws SecurityException 异常
     * @throws InstantiationException 异常
     * @throws IllegalAccessException 异常
     * @throws IllegalArgumentException 异常
     * @throws InvocationTargetException 异常
     */
    public static <T> T  getSessionUser(Class<T> tClass) throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException;

    /**
     * 设置request临时变量值(注意没有保存到session中,当前会话结束就没有了)
     * @param key: 关键字名称
     * @param v: 对应的值
     */
    public static void setAttribute(String key, Object v) throws IllegalStateException;

    /**
     * 设置request临时变量值(注意没有保存到session中,当前会话结束就没有了)
     * @param key: 关键字名称
     * @param <T>: 返回类型
     * @return T
     */
    public static <T> T getAttribute(String key) throws IllegalStateException;

    /**
     * 当前request中是否存在指定key存在并且不为空
     * @param key: 关键字名称
     * @return boolean
     */
    public static boolean isExistsAttribute(String key) throws IllegalStateException;

    /**
     * 获得用户的语言设置
     * @return Locale
     */
    public static Locale getUserI18n();
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113

# SpringContextUtil Spring上下文类

/**
 * Spring上下文工具类
 * @author xiong
 */
@Service
public class SpringContextUtil implements ApplicationContextAware {

  /**
   * 实现ApplicationContextAware接口的回调方法,设置上下文环境
   * @param applicationContext: ApplicationContext
   * @throws BeansException 异常
   */
  @Override
  public void setApplicationContext(ApplicationContext applicationContext) throws BeansException;

  /**
   * @return ApplicationContext
   */
  public static ApplicationContext getApplicationContext();

  /**
   * 获取对象
   * @param name: 对象名称
   * @return Object 一个以所给名字注册的bean的实例
   * @throws BeansException 异常
   */
  public static Object getBean(String name) throws BeansException;

  /**
   * 获取类型为requiredType的对象
   * 如果bean不能被类型转换,相应的异常将会被抛出(BeanNotOfRequiredTypeException)
   * @param name: bean注册名
   * @param requiredType: 返回对象类型
   * @return Object 返回requiredType类型对象
   * @throws BeansException 异常
   */
  public static <T> T getBean(String name, Class<T> requiredType) throws BeansException;

  /**
   * 如果BeanFactory包含一个与所给名称匹配的bean定义,则返回true
   * @param name: bean注册名
   * @return boolean
   */
  public static boolean containsBean(String name);

  /**
   * 判断以给定名字注册的bean定义是一个singleton还是一个prototype。
   * 如果与给定名字相应的bean定义没有被找到,将会抛出一个异常(NoSuchBeanDefinitionException)
   * @param name: bean注册名
   * @return boolean
   * @throws NoSuchBeanDefinitionException 异常
   */
  public static boolean isSingleton(String name) throws NoSuchBeanDefinitionException;

  /**
   * @param name: bean注册名
   * @return Class 注册对象的类型
   * @throws NoSuchBeanDefinitionException 异常
   */
  public static Class getType(String name) throws NoSuchBeanDefinitionException;

  /**
   * 如果给定的bean名字在bean定义中有别名,则返回这些别名
   * @param name: bean注册名
   * @return String[]
   * @throws NoSuchBeanDefinitionException 异常
   */
  public static String[] getAliases(String name) throws NoSuchBeanDefinitionException;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

# StringUtil字符串工具类

/**
 * 字符串工具类
 * @author xiongsoft
 */
public class StringUtil {

    private static Pattern pattern = Pattern.compile("[\u4e00-\u9fa5]");

    /**
     * 去右空格
     * @param str: 要去掉右空格的字符串
     * @return string
     */
    public static String trimRight(String str);

    /**
     * 去左空格
     * @param str: 要去掉左空格的字符串
     * @return string
     */
    public static String trimLeft(String str);

    /**
     * 判断对象是否为null,如果为null返回null
     * @param obj: 要判断的对象
     * @return String
     */
    public static String valueOfNull(Object obj);

    /**
     * 判断对象是否为null,如果为null返回空字符串
     * @param obj: 要判断的对象
     * @return String
     */
    public static String valueOfString(Object obj);

    /**
     * 判断对象是否为null,如果为null返回缺省值
     * @param obj: 要判断的对象
     * @param detault: 为空时的缺省值
     * @return String
     */
    public static String valueOfDelault(Object obj, String detault);

    /**
     * 文件字节大小显示成M,G和K
     * @param size: 大小
     * @return String
     */
    public static String displayFileSize(long size);

	/**
	 * 判断一个逗号分隔的字符串中是否存在默认子串(不区分大小写)
	 * @param subStr: 子串
	 * @param allStr: 逗号分隔的字符串
	 * @return boolean
	 */
    public static boolean isIn(String subStr,String allStr);

    /**
     * 将15,56,876改为'15','56','876'
     * 以便于在sql where in 语句中使用
     * @param str 例如:15,56,876
     * @return 例如:'15','56','876'
     */
    public static String getInClause(String str);

	/**
	 * 将字符串有某种编码转变成另一种编码
	 * @param string 编码的字符串
	 * @param originCharset 原始编码格式
	 * @param targetCharset 目标编码格式
	 * @return String 编码后的字符串
	 */
	public static String encodeString(String string,Charset originCharset,Charset targetCharset);

	/**
	 * URL编码
	 * @param string 编码字符串
	 * @param charset 编码格式
	 * @return String
	 */
	@SuppressWarnings("deprecation")
	public static String encodeUrl(String string,String charset);

	/**
	 * URL编码
	 * @param string 解码字符串
	 * @param charset 解码格式
	 * @return String
     * @throws UnsupportedEncodingException 异常
     */
	public static String decodeUrl(String string,String charset) throws UnsupportedEncodingException;

	/**
	 * 判断字符串是否是空的
     * StringUtil.isEmpty(null)      = true
     * StringUtil.isEmpty("")        = true
     * StringUtil.isEmpty(" ")       = false
     * StringUtil.isEmpty("bob")     = false
     * StringUtil.isEmpty("  bob  ") = false
	 * @param str: 字符串
	 * @return boolean
	 */
	public static boolean isEmpty(String str);

    /**
     * 判断字符串是否不为空
     * @param str: 字符串
     * @return boolean
     */
    public static boolean isNotEmpty(String str);

    /**
     * 判断字符串是否是""," ",null,注意和isEmpty的区别
     * StringUtil.isBlank(null)      = true
     * StringUtil.isBlank("")        = true
     * StringUtil.isBlank(" ")       = true
     * StringUtil.isBlank("bob")     = false
     * StringUtil.isBlank("  bob  ") = false
     * @param str: 字符串
     * @return boolean
     */
    public static boolean isBlank(String str);

    /**
	 * 首字母转大写
	 * @param str: 字符串
	 * @return String
	 */
	public static String firstCharToUpperCase(String str);

	 /**
	 * 首字母转小写
	 * @param str: 字符串
	 * @return String
	 */
	public static String firstCharToLowerCase(String str);

	/**
	 * @param s: 要截取的原始字符串
	 * @param LimitStrlen: 截取的长度
	 * @return 截取后的字符串
	 */
	public static String getLimitLenStr(String s, int LimitStrlen);

	/**
	 * 字符串列表转换为字符串,以逗号分隔。
	 * @param data: 字符串列表
	 * @return String
	 */
	public static String convertListToString(List<String> data);

	/**
	 * 将字符串列表转换为字符串。
	 * @param data: 字符串列表
	 * @param splitStr: 间隔符号
	 * @return String
	 */
	public static String convertListToString(List<String> data,String splitStr);

    /**
     * 列表转字符串
     * @param stringList 字符串列表
     * @return String
     */
    public static String listToString(List<String> stringList);

    /**
     * 判断是否含有特殊字符
     * @param text: 要判断的字符串
     * @return boolean true:通过, false:没通过
     */
    public static boolean hasSpecialChar(String text);

    /**
     * 判断是否是正确的邮箱地址
     * @param email: 邮箱
     * @return boolean true:通过, false:没通过
     */
    public static boolean isEmail(String email);

    /**
     * 判断是否是正确的IP地址
     * @param ip: IP
     * @return boolean true:通过, false:没通过
     */
    public static boolean isIp(String ip);

    /**
     * 判断是否含有中文,仅适合中国汉字,不包括标点
     * @param text: 字符串
     * @return boolean true:通过, false:没通过
     */
    public static boolean isChinese(String text);

    /**
     * 适应CJK(中日韩)字符集,部分中日韩的字是一样的
     * @param strName: 字符串
     * @return boolean true:通过, false:没通过
     */
    public static boolean isChinese2(String strName);

    /**
     * 返回一行中去掉注释后的内容,用于读取配置文件
     * @param v: 字符串
     * @return String
     */
    public static String getValue(String v);

    /**
     * 判断2个字符串是否相等
     * @param str1: 字符串1
     * @param str2: 字符串2
     * @return boolean
     */
    public static boolean strEqual(String str1,String str2){
        if(str1 == null && str2 == null){
            return true;
        }else if (str1!=null && str1.equals(str2)){
            return true;
        }
        return false;
    }

    public static boolean isStrIn(String strList, String s) {
        return (("," + strList + ",").indexOf("," + s + ",") >= 0);
    }

    static public boolean isStrIn(String strList, String s, char c) {
        return ((c + strList + c).indexOf(c + s + c) >= 0);
    }
    public static String strcat(String s1,String link,String s2)
    {
        return s1!=null && s2!=null ? s1+link+s2 : (s1==null?s2:s1);
    }

    public static String strcat(String[] a,String link,String nullStr)
    {
        String s = null;
        if( a!=null ){
            for(int i=0;i<a.length;i++)
            {
                String s1 = a[i]==null ? nullStr : a[i];
                if( s1==null ){
                    continue;
                }
                s = s!=null ? s+link+s1 : s1;
            }
        }
        return s;
    }
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254

# TypeUtil对象转基本类型工具类

/**
 * 对象转基本类型工具类
 */
public class TypeUtil {

    /**
     * Object对象转字符串String
     * @param value: Object对象
     * @return String
     */
    public static String castToString(Object value);

    /**
     * Object对象转Byte
     * @param value: Object对象
     * @return Byte
     */
    public static Byte castToByte(Object value);

    /**
     * Object对象转Character
     * @param value: Object对象
     * @return Character
     */
    public static Character castToChar(Object value);

    /**
     * Object对象转Short
     * @param value: Object对象
     * @return Short
     */
    public static Short castToShort(Object value);

    /**
     * Object对象转BigDecimal
     * @param value: Object对象
     * @return BigDecimal
     */
    public static BigDecimal castToBigDecimal(Object value);

    /**
     * Object对象转BigInteger
     * @param value: Object对象
     * @return BigInteger
     */
    public static BigInteger castToBigInteger(Object value);

    /**
     * Object对象转Float
     * @param value: Object对象
     * @return Float
     */
    public static Float castToFloat(Object value);

    /**
     * Object对象转Double
     * @param value: Object对象
     * @return Double
     */
    public static Double castToDouble(Object value);

    /**
     * Object对象转Date
     * @param value: Object对象
     * @return Date
     */
    public static Date castToDate(Object value){
        return castToDate(value, null);
    }

    /**
     * Object对象转Date
     * @param value: Object对象
     * @param format: 日期格式
     * @return Date
     */
    public static Date castToDate(Object value, String format);

    /**
     * Object对象转Date
     * @param value: Object对象
     * @return Date
     */
    public static java.sql.Date castToSqlDate(Object value);

    /**
     * Number对象转long
     * @param number: Number对象
     * @return long
     */
    public static long longExtractValue(Number number);

    /**
     * Object对象转Time
     * @param value: Object对象
     * @return Time
     */
    public static java.sql.Time castToSqlTime(Object value);

    /**
     * Object对象转Timestamp
     * @param value: Object对象
     * @return Timestamp
     */
    public static java.sql.Timestamp castToTimestamp(Object value);

    /**
     * Stringt对象转boolean
     * @param str: String对象
     * @return boolean
     */
    public static boolean isNumber(String str);

    /**
     * Object对象转Long
     * @param value: Object对象
     * @return Long
     */
    public static Long castToLong(Object value);

    /**
     * BigDecimal对象转byte
     * @param decimal: BigDecimal对象
     * @return byte
     */
    public static byte byteValue(BigDecimal decimal);

    /**
     * BigDecimal对象转short
     * @param decimal: BigDecimal对象
     * @return short
     */
    public static short shortValue(BigDecimal decimal);

    /**
     * BigDecimal对象转int
     * @param decimal: BigDecimal对象
     * @return int
     */
    public static int intValue(BigDecimal decimal);

    /**
     * BigDecimal对象转long
     * @param decimal: BigDecimal对象
     * @return long
     */
    public static long longValue(BigDecimal decimal);

    /**
     * Object对象转Integer
     * @param value: Object对象
     * @return Integer
     */
    public static Integer castToInt(Object value);

    /**
     * Object对象转byte数字
     * @param value: Object对象
     * @return byte数字
     */
    public static byte[] castToBytes(Object value);

    /**
     * Object对象转Boolean
     * @param value: Object对象
     * @return Boolean
     */
    public static Boolean castToBoolean(Object value);
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170

# ZipUtil文件压缩及解压工具类

/**
 * 文件压缩及解压工具类
 * @author xiong
 */
public class ZipUtil {

	/**
	 * 增加或替换zip中文件
	 * @param destZipFile: 保存的zip文件路径及文件名
	 * @param in: 输入流
	 * @param writeFileName: 目录及文件名称
	 * @return boolean
	 * @throws IOException 异常
	 */
	public static boolean addFile(String destZipFile, InputStream in, String writeFileName) throws IOException;

	/**
	 * 删除zip中文件
	 * @param destZipFile: zip文件路径及文件名
	 * @param pathFileName: 要删除的文件路径及名称
	 * @throws IOException 异常
	 */
	public static void deleteFileFromZip(String destZipFile, String... pathFileName) throws IOException;

	/**
	 * 读取zip包中指定文件
	 * @param destZipFile: zip文件路径及文件名
	 * @param pathFileName: 要读取的文件路径及文件名
	 * @return Path
	 * @throws IOException 异常
	 */
	public static Path readFile(String destZipFile, String pathFileName) throws IOException;

	/**
	 * 压缩文件或者目录
	 * @param destZipFile: 保存的zip文件路径及文件名
	 * @param pathReplace: 去掉压缩文件中路径包含的字符串
	 * @param pathName: 要压缩的文件目录或文件名
	 * @return boolean
	 * @throws IOException 异常
	 */
	public static boolean zip(String destZipFile, String pathReplace, String... pathName) throws IOException;

	/**
	 * 文件解压缩 注意:不能有中文文件名
	 * @param zipSrc: zip文件路径
	 * @param dest: 解压的路径,无需以“\\”或者“/”结尾
	 * @throws IOException 异常
	 */
	public static void unzip(String zipSrc, String dest) throws IOException;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51