params = new HashMap<>();
+ while (parameters.hasMoreElements()) {
+ String parameter = parameters.nextElement();
+ String value = request.getParameter(parameter);
+ if (StringUtils.isNotBlank(value)) {
+ params.put(parameter, value);
+ }
+ }
+
+ return params;
+ }
+
+ public static String getDomain(){
+ HttpServletRequest request = getHttpServletRequest();
+ StringBuffer url = request.getRequestURL();
+ return url.delete(url.length() - request.getRequestURI().length(), url.length()).toString();
+ }
+
+ public static String getOrigin(){
+ HttpServletRequest request = getHttpServletRequest();
+ return request.getHeader(HttpHeaders.ORIGIN);
+ }
+
+ public static String getLanguage() {
+ //默认语言
+ String defaultLanguage = "zh-CN";
+ //request
+ HttpServletRequest request = getHttpServletRequest();
+ if(request == null){
+ return defaultLanguage;
+ }
+
+ //请求语言
+ defaultLanguage = request.getHeader(HttpHeaders.ACCEPT_LANGUAGE);
+
+ return defaultLanguage;
+ }
+}
\ No newline at end of file
diff --git a/face-common/src/main/java/com/dkha/common/util/IdCardUtil.java b/face-common/src/main/java/com/dkha/common/util/IdCardUtil.java
new file mode 100644
index 0000000..2471940
--- /dev/null
+++ b/face-common/src/main/java/com/dkha/common/util/IdCardUtil.java
@@ -0,0 +1,427 @@
+package com.dkha.common.util;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+
+/**
+ *
+ * 身份证合法性校验
+ *
+ *
+ *
+ * --15位身份证号码:第7、8位为出生年份(两位数),第9、10位为出生月份,第11、12位代表出生日期,第15位代表性别,奇数为男,偶数为女。
+ * --18位身份证号码:第7、8、9、10位为出生年份(四位数),第11、第12位为出生月份,第13、14位代表出生日期,第17位代表性别,奇数为男,偶数为女。
+ * 最后一位为校验位
+ *
+ *
+ * @author 313921
+ */
+public class IdCardUtil {
+
+ private static Logger logger = LoggerFactory.getLogger(IdCardUtil.class);
+
+ /**
+ *
+ * 省、直辖市代码表:
+ * 11 : 北京 12 : 天津 13 : 河北 14 : 山西 15 : 内蒙古
+ * 21 : 辽宁 22 : 吉林 23 : 黑龙江 31 : 上海 32 : 江苏
+ * 33 : 浙江 34 : 安徽 35 : 福建 36 : 江西 37 : 山东
+ * 41 : 河南 42 : 湖北 43 : 湖南 44 : 广东 45 : 广西 46 : 海南
+ * 50 : 重庆 51 : 四川 52 : 贵州 53 : 云南 54 : 西藏
+ * 61 : 陕西 62 : 甘肃 63 : 青海 64 : 宁夏 65 : 新疆
+ * 71 : 台湾
+ * 81 : 香港 82 : 澳门
+ * 91 : 国外
+ *
+ */
+ private static String[] cityCode = { "11", "12", "13", "14", "15", "21",
+ "22", "23", "31", "32", "33", "34", "35", "36", "37", "41", "42",
+ "43", "44", "45", "46", "50", "51", "52", "53", "54", "61", "62",
+ "63", "64", "65", "71", "81", "82", "91" };
+
+ /**
+ * 每位加权因子
+ */
+ private static int power[] = { 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5,
+ 8, 4, 2 };
+
+ /**
+ * 验证所有的身份证的合法性
+ *
+ * @param idcard
+ * 身份证
+ * @return 合法返回true,否则返回false
+ */
+ public static boolean isValidatedAllIdcard(String idcard) {
+ if (idcard == null || "".equals(idcard)) {
+ return false;
+ }
+ int s=15;
+ if (idcard.length() == s) {
+ return validate15IDCard(idcard);
+ }
+ int s1=18;
+ if(idcard.length()==s1) {
+ return validate18Idcard(idcard);
+ }
+ return false;
+
+ }
+
+ /**
+ *
+ * 判断18位身份证的合法性
+ *
+ * 根据〖中华人民共和国国家标准GB11643-1999〗中有关公民身份号码的规定,公民身份号码是特征组合码,由十七位数字本体码和一位数字校验码组成。
+ * 排列顺序从左至右依次为:六位数字地址码,八位数字出生日期码,三位数字顺序码和一位数字校验码。
+ *
+ * 顺序码: 表示在同一地址码所标识的区域范围内,对同年、同月、同 日出生的人编定的顺序号,顺序码的奇数分配给男性,偶数分配 给女性。
+ *
+ *
+ * 1.前1、2位数字表示:所在省份的代码; 2.第3、4位数字表示:所在城市的代码; 3.第5、6位数字表示:所在区县的代码;
+ * 4.第7~14位数字表示:出生年、月、日; 5.第15、16位数字表示:所在地的派出所的代码;
+ * 6.第17位数字表示性别:奇数表示男性,偶数表示女性;
+ * 7.第18位数字是校检码:也有的说是个人信息码,一般是随计算机的随机产生,用来检验身份证的正确性。校检码可以是0~9的数字,有时也用x表示。
+ *
+ *
+ * 第十八位数字(校验码)的计算方法为: 1.将前面的身份证号码17位数分别乘以不同的系数。从第一位到第十七位的系数分别为:7 9 10 5 8 4
+ * 2 1 6 3 7 9 10 5 8 4 2
+ *
+ *
+ * 2.将这17位数字和系数相乘的结果相加。
+ *
+ *
+ * 3.用加出来和除以11,看余数是多少
+ *
+ * 4.余数只可能有0 1 2 3 4 5 6 7 8 9 10这11个数字。其分别对应的最后一位身份证的号码为1 0 X 9 8 7 6 5 4 3
+ * 2。
+ *
+ * 5.通过上面得知如果余数是2,就会在身份证的第18位数字上出现罗马数字的Ⅹ。如果余数是10,身份证的最后一位号码就是2。
+ *
+ *
+ * @param idcard
+ * @return
+ */
+ public static boolean validate18Idcard(String idcard) {
+ if (idcard == null) {
+ return false;
+ }
+
+ // 非18位为假
+ int s=18;
+ if (idcard.length() != s) {
+ logger.error("身份证位数不正确!");
+ return false;
+ }
+ // 获取前17位
+ String idcard17 = idcard.substring(0, 17);
+
+ // 前17位全部为数字
+ if (!isDigital(idcard17)) {
+ return false;
+ }
+
+ String provinceid = idcard.substring(0, 2);
+ // 校验省份
+ if (!checkProvinceid(provinceid)) {
+ return false;
+ }
+
+ // 校验出生日期
+ String birthday = idcard.substring(6, 14);
+
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
+
+ try {
+ Date birthDate = sdf.parse(birthday);
+ String tmpDate = sdf.format(birthDate);
+ // 出生年月日不正确
+ if (!tmpDate.equals(birthday)) {
+ return false;
+ }
+
+ } catch (ParseException e1) {
+
+ return false;
+ }
+
+ // 获取第18位
+ String idcard18Code = idcard.substring(17, 18);
+
+ char c[] = idcard17.toCharArray();
+
+ int bit[] = converCharToInt(c);
+
+ int sum17 = 0;
+
+ sum17 = getPowerSum(bit);
+
+ // 将和值与11取模得到余数进行校验码判断
+ String checkCode = getCheckCodeBySum(sum17);
+ if (null == checkCode) {
+ return false;
+ }
+ // 将身份证的第18位与算出来的校码进行匹配,不相等就为假
+ if (!idcard18Code.equalsIgnoreCase(checkCode)) {
+ return false;
+ }
+ //System.out.println("正确");
+ return true;
+ }
+
+ /**
+ * 校验15位身份证
+ *
+ *
+ * 只校验省份和出生年月日
+ *
+ *
+ * @param idcard
+ * @return
+ */
+ public static boolean validate15IDCard(String idcard) {
+ if (idcard == null) {
+ return false;
+ }
+ // 非15位为假
+ int s=15;
+ if (idcard.length() != s) {
+ return false;
+ }
+
+ // 15全部为数字
+ if (!isDigital(idcard)) {
+ return false;
+ }
+
+ String provinceid = idcard.substring(0, 2);
+ // 校验省份
+ if (!checkProvinceid(provinceid)) {
+ return false;
+ }
+
+ String birthday = idcard.substring(6, 12);
+
+ SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd");
+
+ try {
+ Date birthDate = sdf.parse(birthday);
+ String tmpDate = sdf.format(birthDate);
+ // 身份证日期错误
+ if (!tmpDate.equals(birthday)) {
+ return false;
+ }
+
+ } catch (ParseException e1) {
+
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * 将15位的身份证转成18位身份证
+ *
+ * @param idcard
+ * @return
+ */
+ public static String convertIdcarBy15bit(String idcard) {
+ if (idcard == null) {
+ return null;
+ }
+
+ // 非15位身份证
+ int s=15;
+ if (idcard.length() != s) {
+ return null;
+ }
+
+ // 15全部为数字
+ if (!isDigital(idcard)) {
+ return null;
+ }
+
+ String provinceid = idcard.substring(0, 2);
+ // 校验省份
+ if (!checkProvinceid(provinceid)) {
+ return null;
+ }
+
+ String birthday = idcard.substring(6, 12);
+
+ SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd");
+
+ Date birthdate = null;
+ try {
+ birthdate = sdf.parse(birthday);
+ String tmpDate = sdf.format(birthdate);
+ // 身份证日期错误
+ if (!tmpDate.equals(birthday)) {
+ return null;
+ }
+
+ } catch (ParseException e1) {
+ return null;
+ }
+
+ Calendar cday = Calendar.getInstance();
+ cday.setTime(birthdate);
+ String year = String.valueOf(cday.get(Calendar.YEAR));
+
+ String idcard17 = idcard.substring(0, 6) + year + idcard.substring(8);
+
+ char c[] = idcard17.toCharArray();
+ String checkCode = "";
+
+ // 将字符数组转为整型数组
+ int bit[] = converCharToInt(c);
+
+ int sum17 = 0;
+ sum17 = getPowerSum(bit);
+
+ // 获取和值与11取模得到余数进行校验码
+ checkCode = getCheckCodeBySum(sum17);
+
+ // 获取不到校验位
+ if (null == checkCode) {
+ return null;
+ }
+ // 将前17位与第18位校验码拼接
+ idcard17 += checkCode;
+ return idcard17;
+ }
+
+ /**
+ * 校验省份
+ *
+ * @param provinceid
+ * @return 合法返回TRUE,否则返回FALSE
+ */
+ private static boolean checkProvinceid(String provinceid) {
+ for (String id : cityCode) {
+ if (id.equals(provinceid)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * 数字验证
+ *
+ * @param str
+ * @return
+ */
+ private static boolean isDigital(String str) {
+ return str.matches("^[0-9]*$");
+ }
+
+ /**
+ * 将身份证的每位和对应位的加权因子相乘之后,再得到和值
+ *
+ * @param bit
+ * @return
+ */
+ private static int getPowerSum(int[] bit) {
+
+ int sum = 0;
+
+ if (power.length != bit.length) {
+ return sum;
+ }
+
+ for (int i = 0; i < bit.length; i++) {
+ for (int j = 0; j < power.length; j++) {
+ if (i == j) {
+ sum = sum + bit[i] * power[j];
+ }
+ }
+ }
+ return sum;
+ }
+
+ /**
+ * 将和值与11取模得到余数进行校验码判断
+ *
+ * @param sum17
+ * @return 校验位
+ */
+ private static String getCheckCodeBySum(int sum17) {
+ String checkCode = null;
+ switch (sum17 % 11) {
+ case 10:
+ checkCode = "2";
+ break;
+ case 9:
+ checkCode = "3";
+ break;
+ case 8:
+ checkCode = "4";
+ break;
+ case 7:
+ checkCode = "5";
+ break;
+ case 6:
+ checkCode = "6";
+ break;
+ case 5:
+ checkCode = "7";
+ break;
+ case 4:
+ checkCode = "8";
+ break;
+ case 3:
+ checkCode = "9";
+ break;
+ case 2:
+ checkCode = "x";
+ break;
+ case 1:
+ checkCode = "0";
+ break;
+ case 0:
+ checkCode = "1";
+ break;
+ default:
+ }
+ return checkCode;
+ }
+
+ /**
+ * 将字符数组转为整型数组
+ *
+ * @param c
+ * @return
+ * @throws NumberFormatException
+ */
+ private static int[] converCharToInt(char[] c) throws NumberFormatException {
+ int[] a = new int[c.length];
+ int k = 0;
+ for (char temp : c) {
+ a[k++] = Integer.parseInt(String.valueOf(temp));
+ }
+ return a;
+ }
+
+
+ /*public static void main(String[] args) throws Exception {
+ String idcard15 = "130321860311519";
+ String idcard18 = "210102198617083732";//
+ String idcard="610**************";
+ //自己身份证测试
+ System.out.println(isValidatedAllIdcard(idcard));
+ // 15位身份证
+ //System.out.println(isValidatedAllIdcard(idcard15));
+ // 18位身份证
+ //System.out.println(isValidatedAllIdcard(idcard18));
+ // 15位身份证转18位身份证
+ //System.out.println(convertIdcarBy15bit(idcard15));
+ }*/
+}
+
diff --git a/face-common/src/main/java/com/dkha/common/util/IntUUID.java b/face-common/src/main/java/com/dkha/common/util/IntUUID.java
new file mode 100644
index 0000000..a9c6801
--- /dev/null
+++ b/face-common/src/main/java/com/dkha/common/util/IntUUID.java
@@ -0,0 +1,40 @@
+package com.dkha.common.util;
+
+import java.util.UUID;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * @Description 生成32位int UUID
+ * 14位的当前系统时间(格式为:yyyyMMddHHmmss) + 当前电脑的IP地址的最后两位 + 当前线程的hashCode的前9位 + 7位的随机数
+ * @Author Spring
+ * @Since 2019/8/14 10:53
+ */
+
+public class IntUUID {
+
+ public static final AtomicInteger shortUUID = new AtomicInteger(0);
+
+ public static int getShortUUID(){
+ int current;
+ int next;
+ do {
+ current = shortUUID.get();
+ next = current >= 2147483647 ? 0 : current + 1;
+ } while(!shortUUID.compareAndSet(current, next));
+ return next;
+ }
+
+ /**
+ * 获取字符串类型UUID
+ * @return
+ */
+ public static synchronized String getStrUUID() {
+ return UUID.randomUUID().toString().replaceAll("-", "");
+ }
+
+ public static void main(String[] args) {
+ //System.out.println(IntUUID.getShortUUID());
+ String uuid = UUID.randomUUID().toString().replaceAll("-", "");
+ System.out.println(uuid);
+ }
+}
diff --git a/face-common/src/main/java/com/dkha/common/util/IpUtils.java b/face-common/src/main/java/com/dkha/common/util/IpUtils.java
new file mode 100644
index 0000000..3801fa7
--- /dev/null
+++ b/face-common/src/main/java/com/dkha/common/util/IpUtils.java
@@ -0,0 +1,61 @@
+/**
+ * Copyright (c) 2018 人人开源 All rights reserved.
+ *
+ * https://www.renren.io
+ *
+ * 版权所有,侵权必究!
+ */
+
+package com.dkha.common.util;
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * IP地址
+ * @author Spring
+ */
+public class IpUtils {
+ private static Logger logger = LoggerFactory.getLogger(IpUtils.class);
+
+ /**
+ * 获取IP地址
+ *
+ * 使用Nginx等反向代理软件, 则不能通过request.getRemoteAddr()获取IP地址
+ * 如果使用了多级反向代理的话,X-Forwarded-For的值并不止一个,而是一串IP地址,X-Forwarded-For中第一个非unknown的有效IP字符串,则为真实IP地址
+ */
+ public static String getIpAddr(HttpServletRequest request) {
+ String unknown = "unknown";
+ String ip = null;
+ try {
+ ip = request.getHeader("x-forwarded-for");
+ //nginx代理存在的情况下
+ if (UtilValidate.isNotEmpty(ip) && ip.contains(",")) {
+ ip = ip.split(",")[0];
+ }
+ if (StringUtils.isEmpty(ip) || unknown.equalsIgnoreCase(ip)) {
+ ip = request.getHeader("Proxy-Client-IP");
+ }
+ if (StringUtils.isEmpty(ip) || ip.length() == 0 || unknown.equalsIgnoreCase(ip)) {
+ ip = request.getHeader("WL-Proxy-Client-IP");
+ }
+ if (StringUtils.isEmpty(ip) || unknown.equalsIgnoreCase(ip)) {
+ ip = request.getHeader("HTTP_CLIENT_IP");
+ }
+ if (StringUtils.isEmpty(ip) || unknown.equalsIgnoreCase(ip)) {
+ ip = request.getHeader("HTTP_X_FORWARDED_FOR");
+ }
+ if (StringUtils.isEmpty(ip) || unknown.equalsIgnoreCase(ip)) {
+ ip = request.getRemoteAddr();
+ }
+ } catch (Exception e) {
+ logger.error("IPUtils ERROR ", e);
+ }
+
+ return ip;
+ }
+
+}
diff --git a/face-common/src/main/java/com/dkha/common/util/JsonUtil.java b/face-common/src/main/java/com/dkha/common/util/JsonUtil.java
new file mode 100644
index 0000000..3b555f4
--- /dev/null
+++ b/face-common/src/main/java/com/dkha/common/util/JsonUtil.java
@@ -0,0 +1,226 @@
+package com.dkha.common.util;
+
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.annotation.FieldFill;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.*;
+import lombok.Data;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @Author Spring
+ * @Since 2019/12/11 14:24
+ * @Description 基于jackson 对象序列化反序列化工具
+ */
+
+public class JsonUtil {
+
+ private static Logger logger = LoggerFactory.getLogger(JsonUtil.class);
+
+ private static ObjectMapper objectMapper = new ObjectMapper();
+
+ static {
+ //序列化的时候序列对象的所有属性
+ objectMapper.setSerializationInclusion(JsonInclude.Include.ALWAYS);
+
+ // 如果是空对象的时候,不抛异常
+ objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
+ //属性为null的转换--为空的值不参与反序列化
+ //objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
+ // 取消默认转换timestamps对象
+ objectMapper.configure(SerializationFeature.WRITE_DATE_KEYS_AS_TIMESTAMPS, false);
+ // 所有日期统一格式
+ objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
+ // 忽略 在json字符串中存在, 但是在java对象中不存在对应属性的情况, 防止出错
+ objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ }
+
+
+ public static String obj2String(T obj) {
+ if (obj == null) {
+ return null;
+ }
+ try {
+ return obj instanceof String ? (String)obj : objectMapper
+ .writeValueAsString
+ (obj);
+ } catch (Exception e) {
+ logger.error("Parse object to String error:" + e);
+ return null;
+ }
+ }
+
+ /**
+ * 返回一个格式化好的字符串, 用于调试
+ * @param obj
+ * @param
+ * @return
+ */
+ public static String obj2StringPretty(T obj) {
+ if (obj == null) {
+ return null;
+ }
+ try {
+ return obj instanceof String ? (String)obj : objectMapper.writerWithDefaultPrettyPrinter()
+ .writeValueAsString
+ (obj);
+ } catch (Exception e) {
+ logger.error("Parse object to String error:" + e);
+ return null;
+ }
+ }
+
+ /**
+ * 将字符串转成对象, 单个
+ * @param str
+ * @param clazz
+ * @param
+ * @return
+ */
+ public static T string2Obj(String str, Class clazz) {
+ if (UtilValidate.isEmpty(str) || clazz == null) {
+ return null;
+ }
+ try {
+ return clazz.equals(String.class) ? (T)str : objectMapper.readValue
+ (str, clazz);
+ } catch (IOException e) {
+ logger.error("Parse String to Object error :" + e);
+ return null;
+ }
+ }
+
+ /**
+ * 将字符串转换成对象, 集合
+ * List userEntityList1 = JsonUtil.string2Obj(str, new TypeReference>() {});
+ * @param str
+ * @param typeReference
+ * @param
+ * @return
+ */
+ public static T string2Obj(String str, TypeReference typeReference) {
+ if (UtilValidate.isEmpty(str) || typeReference == null) {
+ return null;
+ }
+ try {
+ return (T)(typeReference.getType().equals(String.class) ? (T)str :
+ objectMapper.readValue
+ (str, typeReference));
+ } catch (IOException e) {
+ logger.error("Parse String to typeReference Object error :" + e);
+ return null;
+ }
+ }
+ /**
+ * 将字符串转换成对象, 集合
+ * List sysUserEntityList2 = JsonUtil.string2Obj(str, List.class, SysUserEntity.class);
+ * @param str
+ * @param collectionClass
+ * @param
+ * @return
+ */
+ public static T string2Obj(String str, Class> collectionClass, Class>... elementClasses) {
+ JavaType javaType = objectMapper.getTypeFactory()
+ .constructParametricType(collectionClass, elementClasses);
+ try {
+ return objectMapper.readValue(str, javaType);
+ } catch (IOException e) {
+ logger.error("Parse String to Object2 error :" + e);
+ return null;
+ }
+ }
+
+ /**
+ * 测试代码
+ */
+ public static void main(String[] args) {
+ SysUserEntity userEntity = new SysUserEntity();
+ userEntity.setUsername("张三");
+ userEntity.setCreateTime(new Date());
+ System.out.println(JsonUtil.obj2String(userEntity));
+ List userEntityList = new ArrayList<>();
+ userEntityList.add(userEntity);
+ System.out.println(JsonUtil.obj2String(userEntityList));
+
+ String str = "[{\"username\":\"张三\",\"createTime\":\"2019-12-11 14:38:01\"}, {\"username\":\"李四\",\"createTime\":\"2019-10-11 14:38:01\"}]";
+ List userEntityList1 = JsonUtil.string2Obj(str, new TypeReference>() {
+ });
+ System.out.println(userEntityList1.toString());
+
+ List sysUserEntityList2 = JsonUtil.string2Obj(str, List.class, SysUserEntity.class);
+ System.out.println(sysUserEntityList2.toString());
+
+ SysUserEntity userEntity1 = JsonUtil.string2Obj("", SysUserEntity.class);
+ }
+
+ @Data
+ public static class SysUserEntity {
+ private static final long serialVersionUID = 1L;
+ /**
+ * 用户名
+ */
+ private String username;
+ /**
+ * 密码
+ */
+ private String password;
+ /**
+ * 姓名
+ */
+ private String realName;
+ /**
+ * 头像
+ */
+ private String headUrl;
+ /**
+ * 性别 0:男 1:女 2:保密
+ */
+ private Integer gender;
+ /**
+ * 邮箱
+ */
+ private String email;
+ /**
+ * 手机号
+ */
+ private String mobile;
+ /**
+ * 部门ID
+ */
+ private Long deptId;
+ /**
+ * 超级管理员 0:否 1:是
+ */
+ private Integer superAdmin;
+ /**
+ * 状态 0:停用 1:正常
+ */
+ private Integer status;
+ /**
+ * 更新者
+ */
+ @TableField(fill = FieldFill.INSERT_UPDATE)
+ private Long updater;
+ /**
+ * 更新时间
+ */
+ @TableField(fill = FieldFill.INSERT_UPDATE)
+ private Date updateDate;
+ /**
+ * 部门名称
+ */
+ @TableField(exist=false)
+ private String deptName;
+
+ private Date createTime;
+ }
+}
diff --git a/face-common/src/main/java/com/dkha/common/util/NameUtil.java b/face-common/src/main/java/com/dkha/common/util/NameUtil.java
new file mode 100644
index 0000000..5835399
--- /dev/null
+++ b/face-common/src/main/java/com/dkha/common/util/NameUtil.java
@@ -0,0 +1,98 @@
+package com.dkha.common.util;
+
+import com.dkha.common.exception.EmployeeException;
+
+/**
+ * @ClassName:
+ * @Description:(please write your description)
+ * @author: {开发人的姓名}
+ * @date:
+ * @Copyright: 成都电科惠安
+ */
+public class NameUtil {
+
+ public static String createAsterisk(int length) {
+ StringBuffer stringBuffer = new StringBuffer();
+ for (int i = 0; i < length; i++) {
+ stringBuffer.append("*");
+ }
+ return stringBuffer.toString();
+ }
+
+ public static String getNames(String name) {
+ if (UtilValidate.isEmpty(name)) {
+ throw new EmployeeException("不能输入空");
+ }
+ String[] show = name.split("·");
+ if (show.length == 2) {
+ name = show[0] + createAsterisk(show[1].length());
+ return name;
+ }
+
+ return name;
+ }
+
+ /**
+ * @param idCardNum 身份证号码
+ * @param front 需要显示前几位
+ * @param end 需要显示末几位
+ * @return
+ */
+ public static String idMask(String idCardNum, int front, int end) {
+ // 身份证不能为空
+ if (UtilValidate.isEmpty(idCardNum)) {
+ throw new EmployeeException("不能输入空");
+ }
+ // 需要截取的长度不能大于身份证号长度
+// if ((front + end) > idCardNum.length()) {
+// throw new EmployeeException("需要截取的长度不能大于身份证号长度");
+// }
+// // 需要截取的不能小于0
+//
+// if (front < 0 || end < 0) {
+// throw new EmployeeException("需要截取的不能小于0");
+// }
+ // 计算*的数量
+ int asteriskCount = idCardNum.length() - (front + end);
+ StringBuffer asteriskStr = new StringBuffer();
+// for (int i = 0; i < asteriskCount; i++) {
+ asteriskStr.append("********");
+// }
+ String regex = "(\\w{" + String.valueOf(front) + "})(\\w+)(\\w{" + String.valueOf(end) + "})";
+ return idCardNum.replaceAll(regex, "$1" + "********" + "$3");
+ }
+
+
+ /**
+ * 正则表达式判断是否是数字: 完美
+ * @param str
+ * @return
+ */
+ public static boolean isNumber(String str){
+ String reg = "^[0-9]+(.[0-9]+)?$";
+ return str.matches(reg);
+ }
+
+ /**
+ * ASCII码 ,不能判断小数点有几个 :1.1.1 也会返回true
+ * @param str
+ * @return
+ */
+ public static boolean isNumeric(String str){
+ for(int i=str.length();--i>=0;){
+ int chr=str.charAt(i);
+ System.out.println(chr);
+ if(chr<48 || chr>57) {
+ if(chr != 46){
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+// public static void main(String[] args) {
+// String id ="513902199202293979E.5";
+// System.out.println(NameUtil.isNumber(id));
+// }
+}
diff --git a/face-common/src/main/java/com/dkha/common/util/ShieldUtil.java b/face-common/src/main/java/com/dkha/common/util/ShieldUtil.java
new file mode 100644
index 0000000..f77fa0a
--- /dev/null
+++ b/face-common/src/main/java/com/dkha/common/util/ShieldUtil.java
@@ -0,0 +1,56 @@
+package com.dkha.common.util;
+
+/**
+ * 身份证号,姓名屏蔽
+ */
+public class ShieldUtil {
+
+ /**
+ * 少数名字屏蔽·后
+ * @param name
+ * @return
+ */
+ public static String getShieldName(String name) {
+
+ if (name != null && name.contains("·")) {
+ String[] strings = name.split("·");
+ char[] c = strings[1].toCharArray();
+ for (int i = 0; i < strings[1].toCharArray().length; i++) {
+ c[i] = '*';
+ }
+
+ strings[1] = new String(c);
+ name = strings[0] + "·" + strings[1];
+ }
+ return name;
+
+ }
+
+ /**
+ * 身份证号屏蔽出生日期
+ * @param idCardNo
+ * @return
+ */
+ public static String getShieldIdCardNo(String idCardNo) {
+ if (idCardNo != null && idCardNo.trim().length() != 0) {
+ char[] c = idCardNo.toCharArray();
+ for (int i = 0; i < c.length; i++) {
+ switch (i) {
+ case 6:
+ case 7:
+ case 8:
+ case 9:
+ case 10:
+ case 11:
+ case 12:
+ case 13:
+ c[i] = '*';
+ break;
+ }
+ }
+ idCardNo = new String(c);
+ }
+ return idCardNo;
+ }
+
+}
diff --git a/face-common/src/main/java/com/dkha/common/util/SpringBeanFactoryUtils.java b/face-common/src/main/java/com/dkha/common/util/SpringBeanFactoryUtils.java
new file mode 100644
index 0000000..f7036e8
--- /dev/null
+++ b/face-common/src/main/java/com/dkha/common/util/SpringBeanFactoryUtils.java
@@ -0,0 +1,28 @@
+package com.dkha.common.util;
+
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.stereotype.Component;
+
+/**
+ * @Author Spring
+ * @Since 2019/9/21 9:48
+ * @Description 用于在Spring框架无法注入的情况下获取对应的Bean
+ */
+@Component
+public class SpringBeanFactoryUtils implements ApplicationContextAware {
+
+ private static ApplicationContext context = null;
+
+ public static T getBean(Class type) {
+ return context.getBean(type);
+ }
+
+ @Override
+ public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+ if (SpringBeanFactoryUtils.context == null) {
+ SpringBeanFactoryUtils.context = applicationContext;
+ }
+ }
+}
diff --git a/face-common/src/main/java/com/dkha/common/util/SpringContextUtils.java b/face-common/src/main/java/com/dkha/common/util/SpringContextUtils.java
new file mode 100644
index 0000000..1efbbfb
--- /dev/null
+++ b/face-common/src/main/java/com/dkha/common/util/SpringContextUtils.java
@@ -0,0 +1,55 @@
+/**
+ * Copyright (c) 2018 人人开源 All rights reserved.
+ *
+ * https://www.renren.io
+ *
+ * 版权所有,侵权必究!
+ */
+
+package com.dkha.common.util;
+
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.stereotype.Component;
+
+/**
+ * Spring Context 工具类
+ *
+ * @author Mark sunlightcs@gmail.com
+ */
+@Component
+public class SpringContextUtils implements ApplicationContextAware {
+ public static ApplicationContext applicationContext;
+
+ @Override
+ public void setApplicationContext(ApplicationContext applicationContext)
+ throws BeansException {
+ SpringContextUtils.applicationContext = applicationContext;
+ }
+
+ public static Object getBean(String name) {
+ return applicationContext.getBean(name);
+ }
+
+ public static T getBean(Class requiredType) {
+ return applicationContext.getBean(requiredType);
+ }
+
+ public static T getBean(String name, Class requiredType) {
+ return applicationContext.getBean(name, requiredType);
+ }
+
+ public static boolean containsBean(String name) {
+ return applicationContext.containsBean(name);
+ }
+
+ public static boolean isSingleton(String name) {
+ return applicationContext.isSingleton(name);
+ }
+
+ public static Class extends Object> getType(String name) {
+ return applicationContext.getType(name);
+ }
+
+}
\ No newline at end of file
diff --git a/face-common/src/main/java/com/dkha/common/util/TimeUtil.java b/face-common/src/main/java/com/dkha/common/util/TimeUtil.java
new file mode 100644
index 0000000..1747843
--- /dev/null
+++ b/face-common/src/main/java/com/dkha/common/util/TimeUtil.java
@@ -0,0 +1,101 @@
+package com.dkha.common.util;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * @version V1.0
+ * @Description: TODO(please write your description)
+ * All rights 成都电科慧安
+ * @Title: TimeUtil
+ * @Package com.dkha.common.util
+ * @author: panhui
+ * @date: 2019/12/10 15:09
+ * @Copyright: 成都电科慧安
+ */
+public class TimeUtil {
+
+ /**
+ * 获取今天时间开始的时间
+ *
+ * @return
+ */
+ public static Long toDayStart() {
+ Date date=new Date();
+ date.setHours(0);
+ date.setMinutes(0);
+ date.setSeconds(0);
+ return date.getTime();
+ }
+ /**
+ * 获取今天时间结束的时间
+ *
+ * @return
+ */
+ public static Long toDayStop()
+ {
+ Date date=new Date();
+ date.setHours(23);
+ date.setMinutes(59);
+ date.setSeconds(59);
+ return date.getTime();
+ }
+
+ /**
+ * 获取传入时间的开始的时间
+ *
+ * @return
+ */
+ public static Long toDateByTimeStart(String time) {
+ Date date=exchangeDate(time);
+ date.setHours(0);
+ date.setMinutes(0);
+ date.setSeconds(0);
+ return date.getTime();
+ }
+ /**
+ * 获取传入时间结束的时间
+ *
+ * @return
+ */
+ public static Long toDateByTimeStop(String time)
+ {
+ Date date=exchangeDate(time);
+ date.setHours(23);
+ date.setMinutes(59);
+ date.setSeconds(59);
+ return date.getTime();
+ }
+
+ /**
+ * 将时间转换为时间戳
+ * @param time
+ * @return
+ */
+ public static Long exchangeTime(String time)
+ {
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ Date date = null;
+ try {
+ date = simpleDateFormat.parse(time);
+ } catch (ParseException e) {
+ }
+ return date.getTime();
+ }
+ /**
+ * 将时间转换为时间戳
+ * @param time
+ * @return
+ */
+ public static Date exchangeDate(String time)
+ {
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ Date date = null;
+ try {
+ date = simpleDateFormat.parse(time);
+ } catch (ParseException e) {
+ }
+ return date;
+ }
+}
diff --git a/face-common/src/main/java/com/dkha/common/util/UUIDBits.java b/face-common/src/main/java/com/dkha/common/util/UUIDBits.java
new file mode 100644
index 0000000..241ed87
--- /dev/null
+++ b/face-common/src/main/java/com/dkha/common/util/UUIDBits.java
@@ -0,0 +1,43 @@
+package com.dkha.common.util;
+
+import java.util.UUID;
+
+/**
+ * All rights 成都电科慧安
+ *
+ * @ClassName: UUIDBits
+ * @program: dkha-cloud
+ * @description:
+ * @author: maming
+ * @create: 2019/11/18 10:47
+ **/
+
+public class UUIDBits {
+
+ public static String[] chars = new String[] { "a", "b", "c", "d", "e", "f",
+ "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
+ "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5",
+ "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I",
+ "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V",
+ "W", "X", "Y", "Z" };
+
+ /**
+ * 生成6位UUID
+ * @return 6位UUID
+ */
+ public static String getUUIDBits(Integer num) {
+ StringBuffer shortBuffer = new StringBuffer();
+ String uuid = UUID.randomUUID().toString().replace("-", "");
+ for (int i = 0; i < num; i++) {
+ String str = uuid.substring(i * 4, i * 4 + 4);
+ int x = Integer.parseInt(str, 16);
+ shortBuffer.append(chars[x % 0x3E]);
+ }
+ return shortBuffer.toString();
+ }
+
+ public static void main(String[] args) {
+ System.out.println(getUUIDBits(6));
+ }
+}
+
diff --git a/face-common/src/main/java/com/dkha/common/util/UrlUtil.java b/face-common/src/main/java/com/dkha/common/util/UrlUtil.java
new file mode 100644
index 0000000..170cab0
--- /dev/null
+++ b/face-common/src/main/java/com/dkha/common/util/UrlUtil.java
@@ -0,0 +1,109 @@
+package com.dkha.common.util;
+
+import com.dkha.common.enums.ErrEnum;
+import com.dkha.common.http.HttpUtil;
+import com.dkha.common.modules.vo.ReturnVO;
+import com.dkha.common.result.CommonResult;
+import com.google.gson.Gson;
+
+/**
+ * @version V1.0
+ * @Description: TODO(please write your description)
+ * All rights 成都电科慧安
+ * @Title: UrlUtil
+ * @Package com.dkha.task.util
+ * @author: panhui
+ * @date: 2020/1/10 10:46
+ * @Copyright: 成都电科慧安
+ */
+public class UrlUtil {
+ /**
+ * 调用预警的信息 faceserver
+ *
+ * @param object
+ * @return
+ */
+ public static String postData(String warningUrl, Object object, HttpUtil httpUtil, Gson gson) {
+ try {
+ CommonResult commonResult = (CommonResult) httpUtil.post(warningUrl, object, CommonResult.class);
+ if (commonResult.getCode().intValue() != 0 || UtilValidate.isEmpty(commonResult.getData())) {
+ return null;
+ }
+ return gson.toJson(commonResult.getData());
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ /**
+ * 调用预警的信息 face-server
+ *
+ * @param warningUrl
+ * @return
+ */
+ public static String getData(String warningUrl, HttpUtil httpUtil, Gson gson) {
+// log.error("warningUrl={}",warningUrl);
+ try {
+
+ CommonResult commonResult = (CommonResult) httpUtil.get(warningUrl, CommonResult.class);
+ if (commonResult.getCode().intValue() != 0 || UtilValidate.isEmpty(commonResult.getData())) {
+ return null;
+ }
+ return gson.toJson(commonResult.getData());
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ /**
+ * 调用 api
+ *
+ * @param object
+ * @return
+ */
+ public static String postApiData(String warningUrl, Object object, HttpUtil httpUtil, Gson gson) {
+ try {
+ ReturnVO returnVO = (ReturnVO) httpUtil.post(warningUrl, object, ReturnVO.class);
+ if (returnVO.getCode().intValue() != 200 || UtilValidate.isEmpty(returnVO.getData())) {
+ return null;
+ }
+ return gson.toJson(returnVO.getData());
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+
+ /**
+ * 调用 api
+ *
+ * @param warningUrl
+ * @return
+ */
+ public static String getApiData(String warningUrl, HttpUtil httpUtil, Gson gson) {
+// log.error("warningUrl={}",warningUrl);
+ try {
+
+ ReturnVO returnVO = (ReturnVO) httpUtil.get(warningUrl, ReturnVO.class);
+ if (returnVO.getCode().intValue() != 200 || UtilValidate.isEmpty(returnVO.getData())) {
+ return null;
+ }
+ return gson.toJson(returnVO.getData());
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ public static String getData(String warningUrl, Object object, HttpUtil httpUtil, Gson gson)
+ {
+ CommonResult commonResult= (CommonResult) httpUtil.get(warningUrl,object,CommonResult.class);
+ //为授权
+ if (commonResult.getCode().intValue()==ErrEnum.UNAUTHORIZED.getCode()){
+ return gson.toJson(401);
+ }
+ if(commonResult.getCode().intValue()!=0 || UtilValidate.isEmpty(commonResult.getData())) {
+ return null;
+ }
+ return gson.toJson(commonResult.getData());
+ }
+}
diff --git a/face-common/src/main/java/com/dkha/common/util/UtilValidate.java b/face-common/src/main/java/com/dkha/common/util/UtilValidate.java
new file mode 100644
index 0000000..69531f4
--- /dev/null
+++ b/face-common/src/main/java/com/dkha/common/util/UtilValidate.java
@@ -0,0 +1,144 @@
+package com.dkha.common.util;
+
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * @author Spring
+ * @date 2017/5/18-11:30
+ * @Description: 通用验证工具类
+ */
+public class UtilValidate {
+
+ /**
+ * 验证一个对象是否非空,支持String,Map,Collection等。
+ * @param o
+ * @return
+ */
+ public static boolean isEmpty(Object o){
+ return isBaseEmpty(o);
+ }
+
+ /**
+ * 验证String是否为空
+ * @param s
+ * @return
+ */
+ public static boolean isEmpty(String s) {
+ return ((s == null) || (s.length() == 0));
+ }
+
+ /**
+ * 验证数组是否为空
+ * @param arrays
+ * @return
+ */
+ public static boolean isEmpty(Object [] arrays) {
+ return ((arrays == null) || (arrays.length == 0));
+ }
+
+ /**
+ * 验证一个集合是否为空
+ * @param c
+ * @param
+ * @return
+ */
+ public static boolean isEmpty(Collection c) {
+ return ((c == null) || (c.size() == 0));
+ }
+
+ /**
+ * 验证Map集合是否为空
+ * @param m
+ * @param
+ * @param
+ * @return
+ */
+ public static boolean isEmpty(Map m) {
+ return ((m == null) || (m.size() == 0));
+ }
+
+ /**
+ * 验证charsequence是否为空
+ * @param c
+ * @return
+ */
+ public static boolean isEmpty(CharSequence c) {
+ return ((c == null) || (c.length() == 0));
+ }
+
+ /**
+ * 验证一个对象是否非空,支持String,Map,Collection等。
+ * @param o
+ * @return
+ */
+ public static boolean isNotEmpty(Object o) {
+ return !isBaseEmpty(o);
+ }
+
+ /**
+ * 验证String是否不为空
+ * @param s
+ * @return
+ */
+ public static boolean isNotEmpty(String s) {
+ return ((s != null) && (s.length() > 0));
+ }
+
+ /**
+ * 验证数组是否为空
+ * @param arrays
+ * @return
+ */
+ public static boolean isNotEmpty(Object [] arrays) {
+ return ((arrays != null) && (arrays.length > 0));
+ }
+
+ /**
+ * 验证Collection是否不为空
+ * @param c
+ * @param
+ * @return
+ */
+ public static boolean isNotEmpty(Collection c) {
+ return ((c != null) && (c.size() > 0));
+ }
+
+ /**
+ * 验证CharSequence是否不能为空
+ * @param c
+ * @return
+ */
+ public static boolean isNotEmpty(CharSequence c) {
+ return ((c != null) && (c.length() > 0));
+ }
+
+ /**
+ * 基类
+ * @param value
+ * @return
+ */
+ @SuppressWarnings("unchecked")
+ private static boolean isBaseEmpty(Object value) {
+ if (value == null) return true;
+ if (value instanceof String) return UtilValidate.isEmpty((String) value);
+ if (value instanceof Collection) return UtilValidate.isEmpty((Collection extends Object>) value);
+ if (value instanceof Map) return UtilValidate.isEmpty((Map extends Object, ? extends Object>) value);
+ if (value instanceof CharSequence) return UtilValidate.isEmpty((CharSequence) value);
+ // These types would flood the log
+ // Number covers: BigDecimal, BigInteger, Byte, Double, Float, Integer, Long, Short
+ if (value instanceof Boolean) return false;
+ if (value instanceof Number) return false;
+ if (value instanceof Character) return false;
+ if (value instanceof java.sql.Timestamp) return false;
+ return false;
+ }
+
+ /**
+ * 系统测试方法
+ * @param args
+ */
+ public static void main(String[] args) {
+ System.out.println(UtilValidate.isEmpty(""));
+ }
+}
diff --git a/face-common/src/main/java/com/dkha/common/util/excel/ExcelField.java b/face-common/src/main/java/com/dkha/common/util/excel/ExcelField.java
new file mode 100644
index 0000000..2918801
--- /dev/null
+++ b/face-common/src/main/java/com/dkha/common/util/excel/ExcelField.java
@@ -0,0 +1,59 @@
+/**
+ * Copyright © 2012-2016 JeeSite All rights reserved.
+ */
+package com.dkha.common.util.excel;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Excel注解定义
+ * @author ThinkGem
+ * @version 2013-03-10
+ */
+@Target({ElementType.METHOD, ElementType.FIELD, ElementType.TYPE})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface ExcelField {
+
+ /**
+ * 导出字段名(默认调用当前字段的“get”方法,如指定导出字段为对象,请填写“对象名.对象属性”,例:“area.name”、“office.name”)
+ */
+ String value() default "";
+
+ /**
+ * 导出字段标题(需要添加批注请用“**”分隔,标题**批注,仅对导出模板有效)
+ */
+ String title();
+
+ /**
+ * 字段类型(0:导出导入;1:仅导出;2:仅导入)
+ */
+ int type() default 0;
+
+ /**
+ * 导出字段对齐方式(0:自动;1:靠左;2:居中;3:靠右)
+ */
+ int align() default 0;
+
+ /**
+ * 导出字段字段排序(升序)
+ */
+ int sort() default 0;
+
+ /**
+ * 如果是字典类型,请设置字典的type值
+ */
+ String dictType() default "";
+
+ /**
+ * 反射类型
+ */
+ Class> fieldType() default Class.class;
+
+ /**
+ * 字段归属组(根据分组导出导入)
+ */
+ int[] groups() default {};
+}
diff --git a/face-common/src/main/java/com/dkha/common/util/excel/ImportExcel.java b/face-common/src/main/java/com/dkha/common/util/excel/ImportExcel.java
new file mode 100644
index 0000000..ed9cb24
--- /dev/null
+++ b/face-common/src/main/java/com/dkha/common/util/excel/ImportExcel.java
@@ -0,0 +1,343 @@
+package com.dkha.common.util.excel;
+
+import com.google.common.collect.Lists;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.List;
+
+
+/**
+ * 导入Excel文件(支持“XLS”和“XLSX”格式)
+ * @author ThinkGem
+ * @version 2013-03-10
+ */
+public class ImportExcel {
+
+ private static Logger log = LoggerFactory.getLogger(ImportExcel.class);
+
+ /**
+ * 工作薄对象
+ */
+ private Workbook wb;
+
+ /**
+ * 工作表对象
+ */
+ private Sheet sheet;
+
+ /**
+ * 标题行号
+ */
+ private int headerNum;
+
+ /**
+ * 构造函数
+ * @param fileName 导入文件,读取第一个工作表
+ * @param headerNum 标题行号,数据行号=标题行号+1
+ * @throws InvalidFormatException
+ * @throws IOException
+ */
+ public ImportExcel(String fileName, int headerNum)
+ throws InvalidFormatException, IOException {
+ this(new File(fileName), headerNum);
+ }
+
+ /**
+ * 构造函数
+ * @param file 导入文件对象,读取第一个工作表
+ * @param headerNum 标题行号,数据行号=标题行号+1
+ * @throws InvalidFormatException
+ * @throws IOException
+ */
+ public ImportExcel(File file, int headerNum)
+ throws InvalidFormatException, IOException {
+ this(file, headerNum, 0);
+ }
+
+ /**
+ * 构造函数
+ * @param fileName 导入文件
+ * @param headerNum 标题行号,数据行号=标题行号+1
+ * @param sheetIndex 工作表编号
+ * @throws InvalidFormatException
+ * @throws IOException
+ */
+ public ImportExcel(String fileName, int headerNum, int sheetIndex)
+ throws InvalidFormatException, IOException {
+ this(new File(fileName), headerNum, sheetIndex);
+ }
+
+ /**
+ * 构造函数
+ * @param file 导入文件对象
+ * @param headerNum 标题行号,数据行号=标题行号+1
+ * @param sheetIndex 工作表编号
+ * @throws InvalidFormatException
+ * @throws IOException
+ */
+ public ImportExcel(File file, int headerNum, int sheetIndex)
+ throws InvalidFormatException, IOException {
+ this(file.getName(), new FileInputStream(file), headerNum, sheetIndex);
+ }
+
+ /**
+ * 构造函数
+ * @param multipartFile 导入文件对象
+ * @param headerNum 标题行号,数据行号=标题行号+1
+ * @param sheetIndex 工作表编号
+ * @throws InvalidFormatException
+ * @throws IOException
+ */
+ public ImportExcel(MultipartFile multipartFile, int headerNum, int sheetIndex)
+ throws InvalidFormatException, IOException {
+ this(multipartFile.getOriginalFilename(), multipartFile.getInputStream(), headerNum, sheetIndex);
+ }
+
+ /**
+ * @param fileName 导入文件对象
+ * @param is 文件流
+ * @param headerNum 标题行号,数据行号=标题行号+1
+ * @param sheetIndex 工作表编号
+ * @throws InvalidFormatException
+ * @throws IOException
+ */
+ public ImportExcel(String fileName, InputStream is, int headerNum, int sheetIndex)
+ throws InvalidFormatException, IOException {
+ if (StringUtils.isBlank(fileName)){
+ throw new RuntimeException("导入文档为空!");
+ }else if(fileName.toLowerCase().endsWith("xls")){
+ this.wb = new HSSFWorkbook(is);
+ }else if(fileName.toLowerCase().endsWith("xlsx")){
+ this.wb = new XSSFWorkbook(is);
+ }else{
+ throw new RuntimeException("文档格式不正确!");
+ }
+ if (this.wb.getNumberOfSheets() List getDataList(Class cls, int... groups) throws InstantiationException, IllegalAccessException{
+ List