diff --git a/tamguo-common/.classpath b/tamguo-common/.classpath
new file mode 100644
index 0000000..16c89cc
--- /dev/null
+++ b/tamguo-common/.classpath
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tamguo-common/.gitignore b/tamguo-common/.gitignore
new file mode 100644
index 0000000..b83d222
--- /dev/null
+++ b/tamguo-common/.gitignore
@@ -0,0 +1 @@
+/target/
diff --git a/tamguo-common/.project b/tamguo-common/.project
new file mode 100644
index 0000000..787ce0b
--- /dev/null
+++ b/tamguo-common/.project
@@ -0,0 +1,23 @@
+
+
+ tamguo-common
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.m2e.core.maven2Builder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+ org.eclipse.m2e.core.maven2Nature
+
+
diff --git a/tamguo-common/.settings/org.eclipse.jdt.core.prefs b/tamguo-common/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..d59e09c
--- /dev/null
+++ b/tamguo-common/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,5 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/tamguo-common/.settings/org.eclipse.m2e.core.prefs b/tamguo-common/.settings/org.eclipse.m2e.core.prefs
new file mode 100644
index 0000000..14b697b
--- /dev/null
+++ b/tamguo-common/.settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,4 @@
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
diff --git a/tamguo-common/pom.xml b/tamguo-common/pom.xml
new file mode 100644
index 0000000..49cf8f5
--- /dev/null
+++ b/tamguo-common/pom.xml
@@ -0,0 +1,29 @@
+
+ 4.0.0
+ com.tamguo
+ tamguo-common
+ 1.0.0
+
+
+
+ org.slf4j
+ slf4j-api
+ 1.7.25
+
+
+
+
+ tamguo-modules-core
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.1
+
+ 1.8
+ 1.8
+
+
+
+
+
\ No newline at end of file
diff --git a/tamguo-common/src/main/java/com/tamguo/common/utils/AbstractRunningLogHandler.java b/tamguo-common/src/main/java/com/tamguo/common/utils/AbstractRunningLogHandler.java
new file mode 100644
index 0000000..f82fa18
--- /dev/null
+++ b/tamguo-common/src/main/java/com/tamguo/common/utils/AbstractRunningLogHandler.java
@@ -0,0 +1,114 @@
+package com.tamguo.common.utils;
+
+import java.io.InterruptedIOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+public abstract class AbstractRunningLogHandler implements LogHandler {
+
+ private static Method getStackTraceMethod;
+ private static Method getClassNameMethod;
+ private static Method getMethodNameMethod;
+ private static Method getFileNameMethod;
+ private static Method getLineNumberMethod;
+
+ static {
+ try {
+ Class>[] noArgs = null;
+ getStackTraceMethod = Throwable.class.getMethod("getStackTrace", noArgs);
+ Class> stackTraceElementClass = Class.forName("java.lang.StackTraceElement");
+ getClassNameMethod = stackTraceElementClass.getMethod("getClassName", noArgs);
+ getMethodNameMethod = stackTraceElementClass.getMethod("getMethodName", noArgs);
+ getFileNameMethod = stackTraceElementClass.getMethod("getFileName", noArgs);
+ getLineNumberMethod = stackTraceElementClass.getMethod("getLineNumber", noArgs);
+ } catch (ClassNotFoundException ex) {
+ LogDebug.debug("will use pre-JDK 1.4 methods to determine location.");
+ } catch (NoSuchMethodException ex) {
+ LogDebug.debug("will use pre-JDK 1.4 methods to determine location.");
+ }
+ }
+
+ /**
+ * 获得指定class的StackTraceElement
+ *
+ * @param t
+ * @param fqnOfCallingClass
+ *
+ * @return
+ */
+ protected StackTraceElement getRunningStackTrace(Throwable t, String fqnOfCallingClass) {
+ if (getLineNumberMethod != null) {
+ try {
+ Object[] noArgs = null;
+ Object[] elements = (Object[]) getStackTraceMethod.invoke(t, noArgs);
+ for (int i = elements.length - 1; i >= 0; i--) {
+ String thisClass = (String) getClassNameMethod.invoke(elements[i], noArgs);
+ if (fqnOfCallingClass.equals(thisClass)) {
+ // 执行class名称
+ String className = fqnOfCallingClass;
+ // 执行方法名称
+ String methodName = (String) getMethodNameMethod.invoke(elements[i], noArgs);
+ // 执行class文件名称
+ String fileName = (String) getFileNameMethod.invoke(elements[i], noArgs);
+ // 执行到行号
+ int lineNumber = ((Integer) getLineNumberMethod.invoke(elements[i], noArgs)).intValue();
+ return new StackTraceElement(className, methodName, fileName, lineNumber);
+ }
+ }
+ } catch (IllegalAccessException ex) {
+ LogDebug.debug("failed using JDK 1.4 methods", ex);
+ } catch (InvocationTargetException ex) {
+ if (ex.getTargetException() instanceof InterruptedException
+ || ex.getTargetException() instanceof InterruptedIOException) {
+ Thread.currentThread().interrupt();
+ }
+ LogDebug.debug("failed using JDK 1.4 methods", ex);
+ } catch (RuntimeException ex) {
+ LogDebug.debug("failed using JDK 1.4 methods", ex);
+ }
+ }
+ return this.createDefaultStackTrace();
+ }
+
+ /**
+ * 创建默认StackTraceElement
+ *
+ * @return
+ */
+ private StackTraceElement createDefaultStackTrace() {
+ return new StackTraceElement(this.getClass().getName(), "log", this.getClass().getName(), 0);
+ }
+
+ @Override
+ public void info(String msg, String fqnOfCallingClass) {
+ }
+
+ @Override
+ public void info(String msg, Throwable t, String fqnOfCallingClass) {
+ }
+
+ @Override
+ public void error(String msg, String fqnOfCallingClass) {
+ }
+
+ @Override
+ public void error(String msg, Throwable t, String fqnOfCallingClass) {
+ }
+
+ @Override
+ public void debug(String msg, String fqnOfCallingClass) {
+ }
+
+ @Override
+ public void debug(String msg, Throwable t, String fqnOfCallingClass) {
+ }
+
+ @Override
+ public void warning(String msg, String fqnOfCallingClass) {
+ }
+
+ @Override
+ public void warning(String msg, Throwable t, String fqnOfCallingClass) {
+ }
+
+}
diff --git a/tamguo-common/src/main/java/com/tamguo/common/utils/CException.java b/tamguo-common/src/main/java/com/tamguo/common/utils/CException.java
new file mode 100644
index 0000000..878d158
--- /dev/null
+++ b/tamguo-common/src/main/java/com/tamguo/common/utils/CException.java
@@ -0,0 +1,23 @@
+package com.tamguo.common.utils;
+
+public class CException extends RuntimeException {
+
+ private static final long serialVersionUID = 6401592364022805815L;
+
+ public CException() {
+ super();
+ }
+
+ public CException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public CException(String message) {
+ super(message);
+ }
+
+ public CException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/tamguo-common/src/main/java/com/tamguo/common/utils/DateUtil.java b/tamguo-common/src/main/java/com/tamguo/common/utils/DateUtil.java
new file mode 100644
index 0000000..b1c315b
--- /dev/null
+++ b/tamguo-common/src/main/java/com/tamguo/common/utils/DateUtil.java
@@ -0,0 +1,524 @@
+package com.tamguo.common.utils;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+
+public final class DateUtil {
+
+ /**
+ * 正常日期格式化模板.
+ */
+ private static final SimpleDateFormat NORMAL_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
+ private static final SimpleDateFormat NORMAL_DATE_FORMAT_YY_MM_DD = new SimpleDateFormat("yyyy-MM-dd");
+ private static final SimpleDateFormat NORMAL_DATE_FORMAT_YY_MM_DD_ = new SimpleDateFormat("yyyyMMdd");
+
+ private static final SimpleDateFormat NORMAL_DATE_FORMAT_YYMMDDHHMISS = new SimpleDateFormat("yyyyMMddHHmmss");
+
+ /**
+ * 正常日期格式化.
+ *
+ * @param date
+ * 日期距离1970年1月1日秒数
+ * @return 格式化后的日期(2011-11-24)
+ */
+ public static String dateFormatYYMMDD(long date) {
+ return NORMAL_DATE_FORMAT_YY_MM_DD.format(new Date(date * 1000));
+ }
+
+ /**
+ * 正常日期格式化.
+ *
+ * @param date
+ * 日期距离1970年1月1日秒数
+ * @return 格式化后的日期(20111124)
+ */
+
+ public static String getCurrentDateStr() {
+ return NORMAL_DATE_FORMAT_YY_MM_DD_.format(new Date());
+ }
+
+ public static String getCurrentDateYYYYMMDDStr() {
+ return NORMAL_DATE_FORMAT_YY_MM_DD.format(new Date());
+ }
+
+ public static String getNextDayYYYYMMDDStr() {
+ Calendar cal = Calendar.getInstance();
+ try {
+ cal.setTime(NORMAL_DATE_FORMAT_YY_MM_DD.parse(getCurrentTime()));
+ cal.add(Calendar.DATE, 1);
+ return NORMAL_DATE_FORMAT_YY_MM_DD.format(cal.getTime());
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public static long getNextDayYYYYMMDDLong() {
+ Calendar cal = Calendar.getInstance();
+ try {
+ cal.setTime(NORMAL_DATE_FORMAT_YY_MM_DD.parse(getCurrentTime()));
+ cal.add(Calendar.DATE, 1);
+ return cal.getTimeInMillis();
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ return 0l;
+ }
+
+ /**
+ * 正常日期格式化.
+ *
+ * @param date
+ * 日期距离1970年1月1日秒数
+ * @return 格式化后的日期(2011-11-24 16:46:38)
+ */
+ public static String dateFormat(long date) {
+ return NORMAL_DATE_FORMAT.format(new Date(date * 1000));
+ }
+
+ /**
+ * 正常日期格式化.
+ *
+ * @param date
+ * 日期距离1970年1月1日秒数
+ * @return 格式化后的日期(2011-11-24)
+ */
+ public static String dateFormatYYYYMMDD(long date) {
+ return NORMAL_DATE_FORMAT_YY_MM_DD.format(new Date(date * 1000));
+ }
+
+ /**
+ * 正常日期格式化.
+ *
+ * @param date
+ * 日期距离1970年1月1日秒数
+ * @return 格式化后的日期(2011-11-24 16:46:38)
+ */
+
+ public static String dateFormat(Date date) {
+ return NORMAL_DATE_FORMAT.format(date);
+ }
+
+ /**
+ * 正常日期格式化.
+ *
+ * @param date
+ * 日期距离1970年1月1日秒数
+ * @return 格式化后的日期(20111124164638)
+ */
+
+ public static String dateFormathhmmss(Date date) {
+ return NORMAL_DATE_FORMAT_YYMMDDHHMISS.format(date);
+ }
+
+ /**
+ * 正常日期格式化.
+ *
+ * @param date
+ * 日期距离1970年1月1日秒数
+ * @return 格式化后的日期(20111124164638)
+ */
+
+ public static String dateFormatYYYYMMDD(Date date) {
+ return NORMAL_DATE_FORMAT_YY_MM_DD_.format(date);
+ }
+
+ /**
+ * 正常日期格式化.
+ *
+ * @param date
+ * 日期距离1970年1月1日秒数
+ * @return 格式化后的日期(2011-11-24 16:46:38)
+ */
+
+ public static String getCurrentTime() {
+ return NORMAL_DATE_FORMAT_YY_MM_DD.format(new Date());
+ }
+
+ /**
+ * 获取当前距1970年1月1日秒数.
+ *
+ * @return 当前距1970年1月1日秒数.
+ */
+ public static Long getTime() {
+ return new Date().getTime() / 1000;
+ }
+
+ /**
+ * 获取当前距1970年1月1日秒数.
+ *
+ * @return 获取最近一周的秒数.
+ */
+ public static long getLastWeekTime() {
+ return new Date().getTime() / 1000 - 7 * 24 * 60 * 60;
+ }
+
+ /**
+ * 获取当前距1970年1月1日秒数.
+ *
+ * @return 获取最近一个月的秒数.
+ */
+ public static long getLastMonthTime() {
+ return new Date().getTime() / 1000 - 30 * 24 * 60 * 60;
+ }
+
+ /**
+ * 获取某年某月第一天.
+ *
+ * @return 日期格式如:2011-12-31 00:00:00 .
+ */
+ public static long getFirstDayOfMonth(String year, String month) {
+ Calendar cal = Calendar.getInstance();
+ cal.set(Calendar.YEAR, Integer.valueOf(year));
+ cal.set(Calendar.MONTH, Integer.valueOf(month) - 1);
+ cal.set(Calendar.DAY_OF_MONTH, cal.getMinimum(Calendar.DATE));
+ return parseDate(NORMAL_DATE_FORMAT_YY_MM_DD.format(cal.getTime()) + " 00:00:00").getTime() / 1000;
+ }
+
+ /**
+ * 获取某年某月最后一天.
+ *
+ * @return 日期格式如:2011-12-31 23:59:59 .
+ */
+ public static long getLastDayOfMonth(String year, String month) {
+ Calendar cal = Calendar.getInstance();
+ cal.set(Calendar.YEAR, Integer.valueOf(year));
+ cal.set(Calendar.MONTH, Integer.valueOf(month) - 1);
+ cal.set(Calendar.DAY_OF_MONTH, 1);
+ int value = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
+ cal.set(Calendar.DAY_OF_MONTH, value);
+ return parseDate(NORMAL_DATE_FORMAT_YY_MM_DD.format(cal.getTime()) + " 23:59:59").getTime() / 1000;
+ }
+
+ /**
+ * 解析字符串为Date.
+ *
+ * @param dateString
+ * 日期字符串 例如 2011-12-17 17:41:18.843 CST.
+ * @return 解析后的日期类型.若解析出错则返回null
+ */
+ public static Date parseDate(String dateStr) {
+ try {
+ return NORMAL_DATE_FORMAT.parse(dateStr);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ /**
+ * 正常日期格式化.
+ *
+ * @param date
+ * 日期距离1970年1月1日秒数
+ * @return 格式化后的日期()
+ */
+
+ public static long parseLong(String date) {
+ return parseDate(date).getTime() / 1000;
+ }
+
+ /**
+ * 日期格式转换为字符串格式
+ *
+ * @param date
+ * @return 格式化后的日期字符串
+ */
+ public static String parseString(Date date) {
+
+ return NORMAL_DATE_FORMAT_YY_MM_DD.format(date);
+ }
+
+ public static long getLastDayStartTime(long daytime) {
+ Calendar todayStart = Calendar.getInstance();
+ todayStart.setTimeInMillis(daytime * 1000);
+ todayStart.add(Calendar.DAY_OF_YEAR, -1);
+ todayStart.set(Calendar.HOUR_OF_DAY, 0);
+ todayStart.set(Calendar.MINUTE, 0);
+ todayStart.set(Calendar.SECOND, 0);
+ todayStart.set(Calendar.MILLISECOND, 0);
+ return todayStart.getTimeInMillis() / 1000;
+ }
+
+ public static long getLastDayEndTime(long daytime) {
+ Calendar todayEnd = Calendar.getInstance();
+ todayEnd.setTimeInMillis(daytime * 1000);
+ todayEnd.add(Calendar.DAY_OF_YEAR, -1);
+ todayEnd.set(Calendar.HOUR_OF_DAY, 23);
+ todayEnd.set(Calendar.MINUTE, 59);
+ todayEnd.set(Calendar.SECOND, 59);
+ todayEnd.set(Calendar.MILLISECOND, 999);
+ return todayEnd.getTimeInMillis() / 1000;
+ }
+
+ public static long getTime(long time) {
+ Calendar timeCalendar = Calendar.getInstance();
+ Calendar nowCalendar = Calendar.getInstance();
+ timeCalendar.setTimeInMillis(time * 1000);
+ timeCalendar.set(Calendar.HOUR_OF_DAY, nowCalendar.get(Calendar.HOUR_OF_DAY));
+ timeCalendar.set(Calendar.MINUTE, nowCalendar.get(Calendar.MINUTE));
+ timeCalendar.set(Calendar.SECOND, nowCalendar.get(Calendar.SECOND));
+ timeCalendar.set(Calendar.MILLISECOND, nowCalendar.get(Calendar.MILLISECOND));
+ return timeCalendar.getTimeInMillis() / 1000;
+ }
+
+ public static long getStartTime(long daytime) {
+ Calendar todayStart = Calendar.getInstance();
+ todayStart.setTimeInMillis(daytime * 1000);
+ // todayStart.add(Calendar.DAY_OF_YEAR, -1);
+ todayStart.set(Calendar.HOUR_OF_DAY, 0);
+ todayStart.set(Calendar.MINUTE, 0);
+ todayStart.set(Calendar.SECOND, 0);
+ todayStart.set(Calendar.MILLISECOND, 0);
+ return todayStart.getTime().getTime() / 1000;
+ }
+
+ public static long getEndTime(long daytime) {
+ Calendar todayEnd = Calendar.getInstance();
+ todayEnd.setTimeInMillis(daytime * 1000);
+ // todayEnd.add(Calendar.DAY_OF_YEAR, -1);
+ todayEnd.set(Calendar.HOUR_OF_DAY, 23);
+ todayEnd.set(Calendar.MINUTE, 59);
+ todayEnd.set(Calendar.SECOND, 59);
+ todayEnd.set(Calendar.MILLISECOND, 999);
+ return todayEnd.getTimeInMillis() / 1000;
+ }
+
+ /**
+ * 比较俩日期是否是同一天
+ *
+ * @param d1
+ * @param d2
+ * @return
+ */
+ public static boolean compareSameDate(Date d1, Date d2) {
+ Calendar c1 = Calendar.getInstance();
+ c1.setTime(d1);
+ Calendar c2 = Calendar.getInstance();
+ c2.setTime(d2);
+ boolean isSameYear = c1.get(Calendar.YEAR) == c2.get(Calendar.YEAR);
+ boolean isSameMonth = isSameYear && c1.get(Calendar.MONTH) == c2.get(Calendar.MONTH);
+ boolean isSameDate = isSameMonth && c1.get(Calendar.DAY_OF_MONTH) == c2.get(Calendar.DAY_OF_MONTH);
+ return isSameDate;
+ }
+
+ /**
+ * 当月的第一天距1970年1月1日秒数.
+ *
+ * @param date
+ * @return long
+ * @author mengxm
+ */
+ public static final long firstMonthDayTime() {
+ Calendar cal = Calendar.getInstance();
+ cal.set(Calendar.DAY_OF_MONTH, 1);
+ return cal.getTime().getTime() / 1000;
+ }
+
+ /**
+ * 根据指定格式解析时间
+ *
+ * @param dateString
+ * @param fmtString
+ * @return Date
+ * @author mengxm
+ */
+ public static final Date parse(String dateString, String fmtString) {
+ Date date = null;
+ try {
+ DateFormat format = new SimpleDateFormat(fmtString);
+ date = format.parse(dateString);
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ return date;
+ }
+
+ /** 比较提现前后时间间隔秒数 */
+ public static boolean getDatePoor(Date endDate, Date nowDate) {
+
+ // 获得两个时间的毫秒时间差异
+ System.out.println(endDate.getTime());
+ System.out.println(nowDate.getTime());
+ long diff = (endDate.getTime() - nowDate.getTime()) / 1000;
+ if (diff < 30) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * 当前时间加几天
+ *
+ * @param day
+ * 天数
+ * @return
+ */
+ public static long currentDateAddDay(int day) {
+ Calendar cal = Calendar.getInstance();
+ try {
+ cal.setTime(NORMAL_DATE_FORMAT_YY_MM_DD.parse(getCurrentTime()));
+ cal.add(Calendar.DATE, day); // add N days
+ return cal.getTimeInMillis() / 1000;
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ return 0l;
+ }
+
+ public static long dateAddDay(long dateLong, int day) {
+ Calendar cal = Calendar.getInstance();
+ Date d = new Date(dateLong * 1000);
+ cal.setTime(d);
+ cal.add(Calendar.DATE, day);
+ return cal.getTimeInMillis() / 1000;
+ }
+
+ /**
+ * 计算两个日期之间相差的天数
+ *
+ * @param smdate
+ * 较小的时间
+ * @param bdate
+ * 较大的时间
+ * @return 相差天数
+ * @throws ParseException
+ */
+ public static int daysBetween(Date smdate, Date bdate) {
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+ long between_days = 0L;
+ try {
+ smdate = sdf.parse(sdf.format(smdate));
+ bdate = sdf.parse(sdf.format(bdate));
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(smdate);
+ long time1 = cal.getTimeInMillis();
+ cal.setTime(bdate);
+ long time2 = cal.getTimeInMillis();
+ between_days = (time2 - time1) / (1000 * 3600 * 24);
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ return Integer.parseInt(String.valueOf(between_days));
+ }
+
+ /** 日期转换为自定义格式输出 */
+ public static String DateToString(Date date, String formatType) {
+ if (date == null) {
+ return null;
+ }
+ if (formatType == null || "".equals(formatType)) {
+ return null;
+ }
+ String dateStr = "";
+ try {
+ SimpleDateFormat sdf = new SimpleDateFormat(formatType);
+ dateStr = sdf.format(date);
+ return dateStr;
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ public static long getStartTimeCurrentDay() {
+ Calendar todayStart = Calendar.getInstance();
+ // todayStart.add(Calendar.DAY_OF_YEAR, -1);
+ todayStart.set(Calendar.HOUR_OF_DAY, 0);
+ todayStart.set(Calendar.MINUTE, 0);
+ todayStart.set(Calendar.SECOND, 0);
+ todayStart.set(Calendar.MILLISECOND, 0);
+ return todayStart.getTime().getTime() / 1000;
+ }
+
+ public static long getEndTimeCurrentDay() {
+ Calendar todayStart = Calendar.getInstance();
+ // todayStart.add(Calendar.DAY_OF_YEAR, -1);
+ todayStart.set(Calendar.HOUR_OF_DAY, 23);
+ todayStart.set(Calendar.MINUTE, 59);
+ todayStart.set(Calendar.SECOND, 59);
+ todayStart.set(Calendar.MILLISECOND, 59);
+ return todayStart.getTime().getTime() / 1000;
+ }
+
+ /** 日期转换为自定义格式输出 */
+ public static String fomatDate(Date date, String format) {
+ if (date == null) {
+ return "";
+ }
+ if (format == null || "".equals(format)) {
+ return "";
+ }
+ try {
+ SimpleDateFormat sdf = new SimpleDateFormat(format);
+ return sdf.format(date);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return "";
+
+ }
+ }
+
+ public static String getLastDayFmtYYYYMMDD() {
+ Calendar todayStart = Calendar.getInstance();
+ todayStart.add(Calendar.DAY_OF_YEAR, -1);
+ todayStart.set(Calendar.HOUR_OF_DAY, 0);
+ todayStart.set(Calendar.MINUTE, 0);
+ todayStart.set(Calendar.SECOND, 0);
+ todayStart.set(Calendar.MILLISECOND, 0);
+ return NORMAL_DATE_FORMAT_YY_MM_DD_.format(todayStart.getTime());
+ }
+
+ /**
+ * @Title: getDateFormat
+ * @Description: 日期格式化 yyyy-MM-dd
+ * @param str
+ * @return String
+ */
+ public static String getDateFormat(String str) {
+ return dateFormatYYMMDD(Long.parseLong(str));
+ }
+
+ /**
+ * @Title: getTimeFormat
+ * @Description: 时间格式化 yyyy-MM-dd HH:mm:ss
+ * @param str
+ * @return String
+ */
+ public static String getTimeFormat(String str) {
+ return dateFormat(Long.parseLong(str));
+ }
+
+ public static void main(String[] args) {
+
+ System.out.println(dateFormat(1441036802));
+ System.out.println(getFirstDayOfMonth("2015", "9"));
+ System.out.println(getLastDayOfMonth("2015", "8"));
+ System.out.println(dateFormat(getLastMonthTime()));
+ System.out.println(dateFormat(getLastWeekTime()));
+ System.out.println(parseLong("2017-01-01 00:00:00"));
+ System.out.println(getTime());
+ System.out.println(dateFormat(1451624155));
+ System.out.println(parse("20151222", "yyyyMMdd"));
+ Calendar c = Calendar.getInstance();
+ Date nowDate = c.getTime();
+ c.set(Calendar.MINUTE, -1);
+ Date endDate = c.getTime();
+ System.out.println("nowDate--" + nowDate + ";endDate--" + endDate);
+ System.out.println(getDatePoor(nowDate, endDate));
+ System.out.println(dateFormatYYYYMMDD(new Date()));
+
+ System.out.println("args = [" + DateUtil.currentDateAddDay(0) + "]");
+ System.out.println("args = [" + DateUtil.parse("2016-01-19", "yyyy-MM-dd").getTime() + "]");
+
+ System.out.println(getTime());
+ System.out.println(getEndTimeCurrentDay());
+
+ System.out.println(getEndTimeCurrentDay() - getTime());
+
+ }
+
+}
diff --git a/tamguo-common/src/main/java/com/tamguo/common/utils/DateUtils.java b/tamguo-common/src/main/java/com/tamguo/common/utils/DateUtils.java
new file mode 100644
index 0000000..e89ff34
--- /dev/null
+++ b/tamguo-common/src/main/java/com/tamguo/common/utils/DateUtils.java
@@ -0,0 +1,274 @@
+package com.tamguo.common.utils;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+
+public class DateUtils {
+ public static final String DEFAULT_PATTERN = "yyyy-MM-dd";
+
+ public static String getOneDayFromNow(int day, String pattern) {
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(new Date());
+ cal.add(Calendar.DAY_OF_MONTH, day);
+ SimpleDateFormat sdf = new SimpleDateFormat(pattern);
+ return sdf.format(cal.getTime());
+ }
+
+ public static String getOneDayFromNow(int day) {
+ return DateUtils.getOneDayFromNow(day, DEFAULT_PATTERN);
+ }
+
+ /**
+ * 计算两个日期之间相差的天数
+ *
+ * @param smdate
+ * 较小的时间
+ * @param bdate
+ * 较大的时间
+ * @return 相差天数
+ * @throws ParseException
+ * @throws java.text.ParseException
+ */
+ public static int daysBetween(Date smdate, Date bdate)
+ throws ParseException {
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+ smdate = sdf.parse(sdf.format(smdate));
+ bdate = sdf.parse(sdf.format(bdate));
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(smdate);
+ long time1 = cal.getTimeInMillis();
+ cal.setTime(bdate);
+ long time2 = cal.getTimeInMillis();
+ long between_days = (time2 - time1) / (1000 * 3600 * 24);
+
+ return Integer.parseInt(String.valueOf(between_days));
+ }
+
+ public static void main(String[] args) throws ParseException {
+ System.out.println(daysBetween(null, null));
+ }
+
+ /**
+ * 英文简写(默认)如:2010-12-01
+ */
+ public static String FORMAT_SHORT = "yyyy-MM-dd";
+ /**
+ * 英文全称 如:2010-12-01 23:15:06
+ */
+ public static String FORMAT_LONG = "yyyy-MM-dd HH:mm:ss";
+ /**
+ * 精确到毫秒的完整时间 如:yyyy-MM-dd HH:mm:ss.S
+ */
+ public static String FORMAT_FULL = "yyyy-MM-dd HH:mm:ss.S";
+ /**
+ * 中文简写 如:2010年12月01日
+ */
+ public static String FORMAT_SHORT_CN = "yyyy年MM月dd";
+ /**
+ * 中文全称 如:2010年12月01日 23时15分06秒
+ */
+ public static String FORMAT_LONG_CN = "yyyy年MM月dd日 HH时mm分ss秒";
+ /**
+ * 精确到毫秒的完整中文时间
+ */
+ public static String FORMAT_FULL_CN = "yyyy年MM月dd日 HH时mm分ss秒SSS毫秒";
+
+ /**
+ * 获得默认的 date pattern
+ */
+ public static String getDatePattern() {
+ return FORMAT_LONG;
+ }
+
+ /**
+ * 根据预设格式返回当前日期
+ *
+ * @return
+ */
+ public static String getNow() {
+ return format(new Date());
+ }
+
+ /**
+ * 根据用户格式返回当前日期
+ *
+ * @param format
+ * @return
+ */
+ public static String getNow(String format) {
+ return format(new Date(), format);
+ }
+
+ /**
+ * 使用预设格式格式化日期
+ *
+ * @param date
+ * @return
+ */
+ public static String format(Date date) {
+ return format(date, getDatePattern());
+ }
+
+ /**
+ * 使用用户格式格式化日期
+ *
+ * @param date
+ * 日期
+ * @param pattern
+ * 日期格式
+ * @return
+ */
+ public static String format(Date date, String pattern) {
+ String returnValue = "";
+ if (date != null) {
+ SimpleDateFormat df = new SimpleDateFormat(pattern);
+ returnValue = df.format(date);
+ }
+ return (returnValue);
+ }
+
+ /**
+ * 使用用户格式格式化时间戳
+ *
+ * @param timestamp
+ * 时间戳
+ * @param pattern
+ * 日期格式
+ * @return
+ */
+ public static String format(String timestamp, String pattern) {
+ SimpleDateFormat sdf = new SimpleDateFormat(pattern);
+ return sdf.format(new Date(Long.parseLong(timestamp)));
+ }
+
+ /**
+ * 使用预设格式提取字符串日期
+ *
+ * @param strDate
+ * 日期字符串
+ * @return
+ */
+ public static Date parse(String strDate) {
+ return parse(strDate, getDatePattern());
+ }
+
+ /**
+ * 使用用户格式提取字符串日期
+ *
+ * @param strDate
+ * 日期字符串
+ * @param pattern
+ * 日期格式
+ * @return
+ */
+ public static Date parse(String strDate, String pattern) {
+ SimpleDateFormat df = new SimpleDateFormat(pattern);
+ try {
+ return df.parse(strDate);
+ } catch (ParseException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ /**
+ * 在日期上增加数个整月
+ *
+ * @param date
+ * 日期
+ * @param n
+ * 要增加的月数
+ * @return
+ */
+ public static Date addMonth(Date date, int n) {
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(date);
+ cal.add(Calendar.MONTH, n);
+ return cal.getTime();
+ }
+
+ /**
+ * 在日期上增加天数
+ *
+ * @param date
+ * 日期
+ * @param n
+ * 要增加的天数
+ * @return
+ */
+ public static Date addDay(Date date, int n) {
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(date);
+ cal.add(Calendar.DATE, n);
+ return cal.getTime();
+ }
+
+ /**
+ * 获取时间戳
+ */
+ public static String getTimeString() {
+ SimpleDateFormat df = new SimpleDateFormat(FORMAT_FULL);
+ Calendar calendar = Calendar.getInstance();
+ return df.format(calendar.getTime());
+ }
+
+ /**
+ * 获取日期年份
+ *
+ * @param date
+ * 日期
+ * @return
+ */
+ public static String getYear(Date date) {
+ return format(date).substring(0, 4);
+ }
+
+ /**
+ * 按默认格式的字符串距离今天的天数
+ *
+ * @param date
+ * 日期字符串
+ * @return
+ */
+ public static int countDays(String date) {
+ long t = Calendar.getInstance().getTime().getTime();
+ Calendar c = Calendar.getInstance();
+ c.setTime(parse(date));
+ long t1 = c.getTime().getTime();
+ return (int) (t / 1000 - t1 / 1000) / 3600 / 24;
+ }
+
+ /**
+ * 按用户格式字符串距离今天的天数
+ *
+ * @param date
+ * 日期字符串
+ * @param format
+ * 日期格式
+ * @return
+ */
+ public static int countDays(String date, String format) {
+ long t = Calendar.getInstance().getTime().getTime();
+ Calendar c = Calendar.getInstance();
+ c.setTime(parse(date, format));
+ long t1 = c.getTime().getTime();
+ return (int) (t / 1000 - t1 / 1000) / 3600 / 24;
+ }
+
+ public static String timeFormat(Date date, String format, Boolean flag, int beforeDay, int nowDay) {
+ if(date == null) {
+ date = new Date();
+ }
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(date);
+ if(flag) {
+ cal.add(Calendar.DATE,-30);
+ } else {
+ cal.add(Calendar.DATE,0);
+ }
+ SimpleDateFormat sdf = new SimpleDateFormat(format);
+ return sdf.format(cal.getTime());
+ }
+}
diff --git a/tamguo-common/src/main/java/com/tamguo/common/utils/ExceptionSupport.java b/tamguo-common/src/main/java/com/tamguo/common/utils/ExceptionSupport.java
new file mode 100644
index 0000000..829281d
--- /dev/null
+++ b/tamguo-common/src/main/java/com/tamguo/common/utils/ExceptionSupport.java
@@ -0,0 +1,32 @@
+package com.tamguo.common.utils;
+
+/**
+ * 统一异常处理 日志处理
+ *
+ */
+public class ExceptionSupport {
+
+ private final static Result failResult = Result.failResult("500");
+ private static LogHandler handler = new Log4jHandler();
+
+ private final static String LOG_INFO_PREFIX = "--info>> ";
+ private final static String LOG_ERROR_PREFIX = "--error>> ";
+
+ public static Result resolverResult(String methodInfo, Class> clazz, Exception e) {
+ if(e instanceof CException) {
+ handler.info(formatInfoLevelMsg(methodInfo, e.getMessage()), clazz.getName());
+ return Result.failResult(e.getMessage());
+ }
+ handler.error(formatErrorLevelMsg(methodInfo), e, clazz.getName());
+ return failResult;
+ }
+
+ private static String formatInfoLevelMsg(String methodInfo, String infoMsg) {
+ return LOG_INFO_PREFIX + methodInfo + ": " + infoMsg;
+ }
+
+ private static String formatErrorLevelMsg(String methodInfo) {
+ return LOG_ERROR_PREFIX + methodInfo;
+ }
+
+}
diff --git a/tamguo-common/src/main/java/com/tamguo/common/utils/IdGen.java b/tamguo-common/src/main/java/com/tamguo/common/utils/IdGen.java
new file mode 100644
index 0000000..f44b5e1
--- /dev/null
+++ b/tamguo-common/src/main/java/com/tamguo/common/utils/IdGen.java
@@ -0,0 +1,99 @@
+package com.tamguo.common.utils;
+
+public class IdGen
+{
+ private long workerId;
+ private long datacenterId;
+ private long sequence = 0L;
+ private long twepoch = 1288834974657L;
+ private long workerIdBits = 5L;
+ private long datacenterIdBits = 5L;
+ private long maxWorkerId = -1L ^ (-1L << workerIdBits);
+ private long maxDatacenterId = -1L ^ (-1L << datacenterIdBits);
+ private long sequenceBits = 12L;
+ private long workerIdShift = sequenceBits;
+ private long datacenterIdShift = sequenceBits + workerIdBits;
+ private long timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits;
+ private long sequenceMask = -1L ^ (-1L << sequenceBits);
+ private long lastTimestamp = -1L;
+ private String suffix;
+ private boolean flag;
+
+ private static class IdGenHolder {
+ private static final IdGen instance = new IdGen();
+ }
+
+ public static IdGen get(){
+ return IdGenHolder.instance;
+ }
+
+ /**
+ * 获取字符串拼接id
+ * @param suffix 字符串
+ * @param flag true:前缀 false:后缀
+ * @return
+ */
+ public static IdGen get(String suffix,boolean flag){
+ if(suffix == null || suffix.trim().length() == 0)
+ return IdGenHolder.instance;
+ else{
+ return new IdGen(suffix,flag);
+ }
+ }
+
+
+ public IdGen() {
+ this(0L, 0L);
+ }
+
+ public IdGen(String suffix,boolean flag){
+ this.suffix = suffix;
+ this.flag = flag;
+ }
+
+ public IdGen(long workerId, long datacenterId) {
+ if (workerId > maxWorkerId || workerId < 0) {
+ throw new IllegalArgumentException(String.format("worker Id can't be greater than %d or less than 0", maxWorkerId));
+ }
+ if (datacenterId > maxDatacenterId || datacenterId < 0) {
+ throw new IllegalArgumentException(String.format("datacenter Id can't be greater than %d or less than 0", maxDatacenterId));
+ }
+ this.workerId = workerId;
+ this.datacenterId = datacenterId;
+ }
+
+ public synchronized String nextId() {
+ long timestamp = timeGen();
+ if (timestamp < lastTimestamp) {
+ throw new RuntimeException(String.format(
+ "Clock moved backwards. Refusing to generate id for %d milliseconds", lastTimestamp - timestamp));
+ }
+ if (lastTimestamp == timestamp) {
+ sequence = (sequence + 1) & sequenceMask;
+ if (sequence == 0) {
+ timestamp = tilNextMillis(lastTimestamp);
+ }
+ } else {
+ sequence = 0L;
+ }
+ lastTimestamp = timestamp;
+
+ long serialNumber = ((timestamp - twepoch) << timestampLeftShift) | (datacenterId << datacenterIdShift)
+ | (workerId << workerIdShift) | sequence;
+
+ return (suffix == null || suffix.trim().length() == 0) ? serialNumber+"" : (flag ? (new StringBuffer()).append(suffix).append(serialNumber).toString() : (new StringBuffer()).append(serialNumber).append(suffix).toString());
+ }
+
+ protected long tilNextMillis(long lastTimestamp) {
+ long timestamp = timeGen();
+ while (timestamp <= lastTimestamp) {
+ timestamp = timeGen();
+ }
+ return timestamp;
+ }
+
+ protected long timeGen() {
+ return System.currentTimeMillis();
+ }
+
+}
diff --git a/tamguo-common/src/main/java/com/tamguo/common/utils/Log4jHandler.java b/tamguo-common/src/main/java/com/tamguo/common/utils/Log4jHandler.java
new file mode 100644
index 0000000..a8cf9da
--- /dev/null
+++ b/tamguo-common/src/main/java/com/tamguo/common/utils/Log4jHandler.java
@@ -0,0 +1,27 @@
+package com.tamguo.common.utils;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.event.Level;
+
+public class Log4jHandler extends AbstractRunningLogHandler {
+
+ private static final Logger logger = LoggerFactory.getLogger(Log4jHandler.class);
+
+ public void info(String msg, String fqnOfCallingClass) {
+ logger.info(fqnOfCallingClass, Level.INFO, msg, null);
+ }
+
+ public void info(String msg, Throwable t, String fqnOfCallingClass) {
+ logger.info(fqnOfCallingClass, Level.INFO, msg, t);
+ }
+
+ public void error(String msg, String fqnOfCallingClass) {
+ logger.error(fqnOfCallingClass, Level.ERROR, msg, null);
+ }
+
+ public void error(String msg, Throwable t, String fqnOfCallingClass) {
+ logger.error(fqnOfCallingClass, Level.ERROR, msg, t);
+ }
+
+}
diff --git a/tamguo-common/src/main/java/com/tamguo/common/utils/LogDebug.java b/tamguo-common/src/main/java/com/tamguo/common/utils/LogDebug.java
new file mode 100644
index 0000000..e517e92
--- /dev/null
+++ b/tamguo-common/src/main/java/com/tamguo/common/utils/LogDebug.java
@@ -0,0 +1,17 @@
+package com.tamguo.common.utils;
+
+public class LogDebug {
+
+ private final static String DEBUG_LOG_KEY = "-- LogHandler: ";
+
+ public static void debug(String msg) {
+ System.err.println(DEBUG_LOG_KEY + msg);
+ }
+
+ public static void debug(String msg, Throwable t) {
+ System.err.println(DEBUG_LOG_KEY + msg);
+ if (t != null)
+ t.printStackTrace(System.err);
+ }
+
+}
diff --git a/tamguo-common/src/main/java/com/tamguo/common/utils/LogHandler.java b/tamguo-common/src/main/java/com/tamguo/common/utils/LogHandler.java
new file mode 100644
index 0000000..5fe8d8e
--- /dev/null
+++ b/tamguo-common/src/main/java/com/tamguo/common/utils/LogHandler.java
@@ -0,0 +1,21 @@
+package com.tamguo.common.utils;
+
+public interface LogHandler {
+
+ public void info(String msg, String fqnOfCallingClass);
+
+ public void info(String msg, Throwable t, String fqnOfCallingClass);
+
+ public void error(String msg, String fqnOfCallingClass);
+
+ public void error(String msg, Throwable t, String fqnOfCallingClass);
+
+ public void debug(String msg, String fqnOfCallingClass);
+
+ public void debug(String msg, Throwable t, String fqnOfCallingClass);
+
+ public void warning(String msg, String fqnOfCallingClass);
+
+ public void warning(String msg, Throwable t, String fqnOfCallingClass);
+
+}
diff --git a/tamguo-common/src/main/java/com/tamguo/common/utils/ObjectUtil.java b/tamguo-common/src/main/java/com/tamguo/common/utils/ObjectUtil.java
new file mode 100644
index 0000000..e81775c
--- /dev/null
+++ b/tamguo-common/src/main/java/com/tamguo/common/utils/ObjectUtil.java
@@ -0,0 +1,69 @@
+package com.tamguo.common.utils;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+public class ObjectUtil extends SerializeTranscoder {
+ @Override
+ public byte[] serialize(Object value) {
+ if (value == null) {
+ throw new NullPointerException("Can't serialize null");
+ }
+ byte[] result = null;
+ ByteArrayOutputStream bos = null;
+ ObjectOutputStream os = null;
+ try {
+ bos = new ByteArrayOutputStream();
+ os = new ObjectOutputStream(bos);
+ os.writeObject(value);
+ os.close();
+ bos.close();
+ result = bos.toByteArray();
+ } catch (IOException e) {
+ throw new IllegalArgumentException("Non-serializable object", e);
+ } finally {
+ close(os);
+ close(bos);
+ }
+ return result;
+ }
+
+ @Override
+ public Object deserialize(byte[] in) {
+ Object result = null;
+ ByteArrayInputStream bis = null;
+ ObjectInputStream is = null;
+ try {
+ if (in != null) {
+ bis = new ByteArrayInputStream(in);
+ is = new ObjectInputStream(bis);
+ result = is.readObject();
+ is.close();
+ bis.close();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ } finally {
+ close(is);
+ close(bis);
+ }
+ return result;
+ }
+
+ public static boolean equals(Object o1, Object o2) {
+
+ if (o1 == o2) {
+ return true;
+ } else if (o1 == null || o2 == null) {
+ return false;
+ } else {
+ return o1.equals(o2);
+ }
+ }
+
+}
diff --git a/tamguo-common/src/main/java/com/tamguo/common/utils/Result.java b/tamguo-common/src/main/java/com/tamguo/common/utils/Result.java
new file mode 100644
index 0000000..850b79d
--- /dev/null
+++ b/tamguo-common/src/main/java/com/tamguo/common/utils/Result.java
@@ -0,0 +1,108 @@
+package com.tamguo.common.utils;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class Result implements Serializable {
+
+ private static final long serialVersionUID = -1651614836984397356L;
+
+ private int code;
+
+ private Object result;
+
+ private String message;
+
+ public static final int SUCCESS_CODE = 0;
+
+ public static final int FAIL_CODE = 1;
+
+ private Result() {
+ }
+
+ private Result(int code, Object result, String message) {
+ this.code = code;
+ this.result = result;
+ this.message = message;
+ }
+
+ /**
+ * 成功响应
+ *
+ * @param result
+ * @return
+ */
+ public static Result successResult(Object result) {
+ return result(SUCCESS_CODE, result, "");
+ }
+
+ public static Result successResult(Object records, Long recordSum, Long rowsOfPage) {
+ return successResult(records, recordSum, rowsOfPage, null);
+ }
+
+ public static Result successResult(Object records, Long recordSum, Long rowsOfPage, Object userData) {
+ Map result = resultOfList(records, recordSum, rowsOfPage, userData);
+
+ return successResult(result);
+ }
+
+ public static Map resultOfList(Object records, Long recordSum, Long rowsOfPage) {
+ return resultOfList(records, recordSum, rowsOfPage, null);
+ }
+
+ public static Map resultOfList(Object Obj, Long records, Long rowsOfPage, Object userData) {
+ Map result = new HashMap();
+ result.put("rows", Obj);
+ result.put("records", records);
+ result.put("total", rowsOfPage);
+ if (null != userData) {
+ result.put("userdata", userData);
+ }
+ ;
+ return result;
+ }
+
+ public static Map jqGridResult(List> list, long totalCount, int pageSize, int currPage,
+ int totalPage) {
+ Map result = new HashMap();
+ result.put("list", list);
+ result.put("count", totalCount);
+ result.put("next", currPage == totalPage ? currPage : currPage + 1);
+ result.put("prev", currPage == 1 ? 1 : currPage - 1);
+ result.put("first", 1);
+ result.put("last", totalPage);
+ result.put("pageSize", pageSize);
+ result.put("pageNo", currPage);
+ return result;
+ }
+
+ /**
+ * 失败响应
+ *
+ * @param errorMsg
+ * @return
+ */
+ public static Result failResult(String errorMsg) {
+ return result(FAIL_CODE, "", errorMsg);
+ }
+
+ public static Result result(int code, Object result, String message) {
+ Result res = new Result(code, result, message);
+ return res;
+ }
+
+ public int getCode() {
+ return code;
+ }
+
+ public Object getResult() {
+ return result;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+}
diff --git a/tamguo-common/src/main/java/com/tamguo/common/utils/SerializeTranscoder.java b/tamguo-common/src/main/java/com/tamguo/common/utils/SerializeTranscoder.java
new file mode 100644
index 0000000..36b9f14
--- /dev/null
+++ b/tamguo-common/src/main/java/com/tamguo/common/utils/SerializeTranscoder.java
@@ -0,0 +1,20 @@
+package com.tamguo.common.utils;
+
+import java.io.Closeable;
+
+public abstract class SerializeTranscoder {
+
+ public abstract byte[] serialize(Object value);
+
+ public abstract Object deserialize(byte[] in);
+
+ public void close(Closeable closeable) {
+ if (closeable != null) {
+ try {
+ closeable.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+}
diff --git a/tamguo-common/src/main/java/com/tamguo/common/utils/ShaEncrypt.java b/tamguo-common/src/main/java/com/tamguo/common/utils/ShaEncrypt.java
new file mode 100644
index 0000000..171d979
--- /dev/null
+++ b/tamguo-common/src/main/java/com/tamguo/common/utils/ShaEncrypt.java
@@ -0,0 +1,68 @@
+package com.tamguo.common.utils;
+
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+public class ShaEncrypt {
+
+ /**
+ * 传入文本内容,返回 SHA-256 串
+ *
+ * @param strText
+ * @return
+ */
+ public static String SHA256(final String strText) {
+ return SHA(strText, "SHA-256");
+ }
+
+ /**
+ * 传入文本内容,返回 SHA-512 串
+ *
+ * @param strText
+ * @return
+ */
+ public static String SHA512(final String strText) {
+ return SHA(strText, "SHA-512");
+ }
+
+ /**
+ * 字符串 SHA 加密
+ *
+ * @param strSourceText
+ * @return
+ */
+ private static String SHA(final String strText, final String strType) {
+ // 返回值
+ String strResult = null;
+
+ // 是否是有效字符串
+ if (strText != null && strText.length() > 0) {
+ try {
+ // SHA 加密开始
+ // 创建加密对象 并傳入加密類型
+ MessageDigest messageDigest = MessageDigest.getInstance(strType);
+ // 传入要加密的字符串
+ messageDigest.update(strText.getBytes());
+ // 得到 byte 類型结果
+ byte byteBuffer[] = messageDigest.digest();
+
+ // 將 byte 轉換爲 string
+ StringBuffer strHexString = new StringBuffer();
+ // 遍歷 byte buffer
+ for (int i = 0; i < byteBuffer.length; i++) {
+ String hex = Integer.toHexString(0xff & byteBuffer[i]);
+ if (hex.length() == 1) {
+ strHexString.append('0');
+ }
+ strHexString.append(hex);
+ }
+ // 得到返回結果
+ strResult = strHexString.toString();
+ } catch (NoSuchAlgorithmException e) {
+ e.printStackTrace();
+ }
+ }
+
+ return strResult;
+ }
+}
\ No newline at end of file
diff --git a/tamguo-common/src/main/java/com/tamguo/common/utils/SystemConstant.java b/tamguo-common/src/main/java/com/tamguo/common/utils/SystemConstant.java
new file mode 100644
index 0000000..0a64316
--- /dev/null
+++ b/tamguo-common/src/main/java/com/tamguo/common/utils/SystemConstant.java
@@ -0,0 +1,13 @@
+package com.tamguo.common.utils;
+
+public class SystemConstant {
+
+ /** 初始密码*/
+ public static final String INIT_PASSWORD = "123456";
+
+ /** 验证码常数*/
+ public static final String KAPTCHA_SESSION_KEY = "KAPTCHA_SESSION_KEY";
+
+ /** 验证码常数*/
+ public static final String SYSTEM_USER_CODE = "system";
+}
diff --git a/tamguo-common/src/main/java/com/tamguo/common/utils/XMLConfiguration.java b/tamguo-common/src/main/java/com/tamguo/common/utils/XMLConfiguration.java
new file mode 100644
index 0000000..6737c2d
--- /dev/null
+++ b/tamguo-common/src/main/java/com/tamguo/common/utils/XMLConfiguration.java
@@ -0,0 +1,53 @@
+package com.tamguo.common.utils;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.w3c.dom.Document;
+
+public class XMLConfiguration {
+ private Document document = null;
+
+ public boolean readConfigFile(String configFilename) {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ try {
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ document = db.parse(configFilename);
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ if (document == null) {
+ return false;
+ }
+ return true;
+ }
+
+ public boolean readConfigFile(InputStream stream) {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ try {
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ document = db.parse(stream);
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ if (document == null) {
+ return false;
+ }
+ return true;
+ }
+
+ public Document getDocument() {
+ return document;
+ }
+
+ protected void setDocument(Document document) {
+ this.document = document;
+ }
+}