WANG 6 лет назад
Родитель
Сommit
c0c31522ab

+ 130 - 54
pom.xml

@@ -8,42 +8,44 @@
 	</parent>
 	<artifactId>examcloud-commons</artifactId>
 	<version>2019-SNAPSHOT</version>
+	<packaging>jar</packaging>
 
 	<dependencies>
 		<dependency>
-			<groupId>junit</groupId>
-			<artifactId>junit</artifactId>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter-test</artifactId>
+			<exclusions>
+				<exclusion>
+					<groupId>org.springframework.boot</groupId>
+					<artifactId>spring-boot-starter-logging</artifactId>
+				</exclusion>
+			</exclusions>
 		</dependency>
 		<dependency>
-			<groupId>org.apache.commons</groupId>
-			<artifactId>commons-lang3</artifactId>
-			<version>${commons-lang3.version}</version>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter-log4j2</artifactId>
 		</dependency>
 		<dependency>
-			<groupId>redis.clients</groupId>
-			<artifactId>jedis</artifactId>
+			<groupId>org.slf4j</groupId>
+			<artifactId>jcl-over-slf4j</artifactId>
 		</dependency>
 		<dependency>
-			<groupId>org.springframework.data</groupId>
-			<artifactId>spring-data-redis</artifactId>
+			<groupId>org.apache.logging.log4j</groupId>
+			<artifactId>log4j-1.2-api</artifactId>
 		</dependency>
 		<dependency>
-			<groupId>org.slf4j</groupId>
-			<artifactId>slf4j-api</artifactId>
-		</dependency>
-		<dependency>
-			<groupId>com.google.code.gson</groupId>
-			<artifactId>gson</artifactId>
+			<groupId>com.fasterxml.jackson.dataformat</groupId>
+			<artifactId>jackson-dataformat-yaml</artifactId>
 		</dependency>
+
 		<dependency>
-			<groupId>com.alibaba</groupId>
-			<artifactId>fastjson</artifactId>
-			<version>${fastjson.version}</version>
+			<groupId>commons-lang</groupId>
+			<artifactId>commons-lang</artifactId>
+			<version>2.6</version>
 		</dependency>
 		<dependency>
-			<groupId>org.apache.poi</groupId>
-			<artifactId>poi-ooxml</artifactId>
-			<version>${poi.version}</version>
+			<groupId>org.apache.commons</groupId>
+			<artifactId>commons-lang3</artifactId>
 		</dependency>
 		<dependency>
 			<groupId>commons-io</groupId>
@@ -51,80 +53,154 @@
 			<version>2.5</version>
 		</dependency>
 		<dependency>
-			<groupId>org.springframework</groupId>
-			<artifactId>spring-aop</artifactId>
+			<groupId>com.thoughtworks.xstream</groupId>
+			<artifactId>xstream</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>commons-net</groupId>
+			<artifactId>commons-net</artifactId>
+			<version>3.4</version>
 		</dependency>
 		<dependency>
-			<groupId>org.springframework</groupId>
-			<artifactId>spring-aspects</artifactId>
+			<groupId>com.mchange</groupId>
+			<artifactId>c3p0</artifactId>
+			<version>0.9.5.2</version>
 		</dependency>
 		<dependency>
-			<groupId>org.springframework</groupId>
-			<artifactId>spring-web</artifactId>
+			<groupId>com.jcraft</groupId>
+			<artifactId>jsch</artifactId>
 		</dependency>
 		<dependency>
-			<groupId>org.springframework</groupId>
-			<artifactId>spring-core</artifactId>
+			<groupId>commons-codec</groupId>
+			<artifactId>commons-codec</artifactId>
 		</dependency>
 		<dependency>
-			<groupId>javax.servlet</groupId>
-			<artifactId>javax.servlet-api</artifactId>
+			<groupId>commons-collections</groupId>
+			<artifactId>commons-collections</artifactId>
+			<version>3.2.2</version>
 		</dependency>
 		<dependency>
-			<groupId>commons-fileupload</groupId>
-			<artifactId>commons-fileupload</artifactId>
-			<version>1.3.3</version>
+			<groupId>org.apache.zookeeper</groupId>
+			<artifactId>zookeeper</artifactId>
+			<version>3.4.11</version>
 			<exclusions>
 				<exclusion>
-					<groupId>commons-io</groupId>
-					<artifactId>commons-io</artifactId>
+					<groupId>org.slf4j</groupId>
+					<artifactId>slf4j-log4j12</artifactId>
+				</exclusion>
+				<exclusion>
+					<groupId>log4j</groupId>
+					<artifactId>log4j</artifactId>
 				</exclusion>
 			</exclusions>
 		</dependency>
 		<dependency>
-			<groupId>com.google.guava</groupId>
-			<artifactId>guava</artifactId>
+			<groupId>com.google.code.gson</groupId>
+			<artifactId>gson</artifactId>
 		</dependency>
 		<dependency>
-			<groupId>commons-collections</groupId>
-			<artifactId>commons-collections</artifactId>
+			<groupId>org.apache.commons</groupId>
+			<artifactId>commons-compress</artifactId>
+			<version>1.12</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.httpcomponents</groupId>
+			<artifactId>httpclient</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.httpcomponents</groupId>
+			<artifactId>httpmime</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>dom4j</groupId>
+			<artifactId>dom4j</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>net.sf.json-lib</groupId>
+			<artifactId>json-lib</artifactId>
+			<version>2.4</version>
+			<classifier>jdk15</classifier>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.poi</groupId>
+			<artifactId>poi</artifactId>
+			<version>3.17</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.poi</groupId>
+			<artifactId>poi-ooxml</artifactId>
+			<version>3.17</version>
+		</dependency>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>redis.clients</groupId>
+			<artifactId>jedis</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.commons</groupId>
+			<artifactId>commons-pool2</artifactId>
 		</dependency>
 		<dependency>
 			<groupId>commons-fileupload</groupId>
 			<artifactId>commons-fileupload</artifactId>
-			<version>1.3.2</version>
+			<version>1.3.3</version>
 		</dependency>
 		<dependency>
-			<groupId>com.esotericsoftware</groupId>
-			<artifactId>reflectasm</artifactId>
-			<version>1.11.3</version>
+			<groupId>com.google.guava</groupId>
+			<artifactId>guava</artifactId>
 		</dependency>
 		<dependency>
-			<groupId>org.apache.httpcomponents</groupId>
-			<artifactId>httpclient</artifactId>
+			<groupId>com.fasterxml.jackson.core</groupId>
+			<artifactId>jackson-core</artifactId>
 		</dependency>
 		<dependency>
-			<groupId>org.apache.commons</groupId>
-			<artifactId>commons-compress</artifactId>
-			<version>1.12</version>
+			<groupId>com.fasterxml.jackson.core</groupId>
+			<artifactId>jackson-annotations</artifactId>
 		</dependency>
 		<dependency>
-			<groupId>com.mchange</groupId>
-			<artifactId>c3p0</artifactId>
-			<version>0.9.5.2</version>
+			<groupId>com.fasterxml.jackson.core</groupId>
+			<artifactId>jackson-databind</artifactId>
 		</dependency>
 		<dependency>
-			<groupId>com.thoughtworks.xstream</groupId>
-			<artifactId>xstream</artifactId>
+			<groupId>com.alibaba</groupId>
+			<artifactId>fastjson</artifactId>
+			<version>1.2.41</version>
 		</dependency>
 		<dependency>
 			<groupId>org.freemarker</groupId>
 			<artifactId>freemarker</artifactId>
 		</dependency>
+		<dependency>
+			<groupId>com.googlecode.aviator</groupId>
+			<artifactId>aviator</artifactId>
+			<version>2.3.3</version>
+		</dependency>
+		<dependency>
+			<groupId>org.quartz-scheduler</groupId>
+			<artifactId>quartz</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>mysql</groupId>
+			<artifactId>mysql-connector-java</artifactId>
+		</dependency>
 		<dependency>
 			<groupId>com.squareup.okhttp3</groupId>
 			<artifactId>okhttp</artifactId>
 		</dependency>
+		<dependency>
+			<groupId>jdk.tools</groupId>
+			<artifactId>jdk.tools</artifactId>
+			<version>${java.version}</version>
+			<scope>system</scope>
+			<systemPath>${JAVA_HOME}/lib/tools.jar</systemPath>
+		</dependency>
+		<dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter-mail</artifactId>
+		</dependency>
 	</dependencies>
 
 </project>

+ 63 - 0
src/main/java/cn/com/qmth/examcloud/commons/helpers/BlackHolePrintStreamBuilder.java

@@ -0,0 +1,63 @@
+package cn.com.qmth.examcloud.commons.helpers;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+
+/**
+ * 黑洞(PrintStream)构建器
+ *
+ * @author WANGWEI
+ * @date 2019年3月28日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+public class BlackHolePrintStreamBuilder {
+
+	/**
+	 * 创建BlackHolePrintStream
+	 *
+	 * @author WANGWEI
+	 * @return
+	 */
+	public static PrintStream build() {
+		return new BlackHolePrintStream(new ByteArrayOutputStream());
+	}
+
+	/**
+	 * 黑洞(PrintStream)
+	 *
+	 * @author WANGWEI
+	 * @date 2019年3月28日
+	 * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+	 */
+	private static class BlackHolePrintStream extends PrintStream {
+
+		@Override
+		public void close() {
+			super.close();
+		}
+
+		ByteArrayOutputStream outputStream;
+
+		/**
+		 * 私有构造函数
+		 *
+		 * @param out
+		 */
+		private BlackHolePrintStream(ByteArrayOutputStream outputStream) {
+			super(outputStream);
+			this.outputStream = outputStream;
+		}
+
+		@Override
+		public void println(String x) {
+			outputStream.reset();
+		}
+
+		@Override
+		public void print(String x) {
+			outputStream.reset();
+		}
+
+	}
+
+}

+ 1 - 1
src/main/java/cn/com/qmth/examcloud/commons/helpers/poi/ExcelReader.java

@@ -162,4 +162,4 @@ public class ExcelReader {
 		return list;
 	}
 
-}
+}

+ 3 - 3
src/main/java/cn/com/qmth/examcloud/commons/helpers/poi/ExcelWriter.java

@@ -22,7 +22,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import cn.com.qmth.examcloud.commons.util.DateUtil.DatePatterns;
 
 /**
- * Excel 生产者
+ * Excel 生成器
  *
  * @author WANGWEI
  * @date 2018年9月7日
@@ -104,7 +104,7 @@ public class ExcelWriter {
 					} else if (type.equals(Date.class)) {
 						CellStyle cs = workbook.createCellStyle();
 						XSSFDataFormat format = workbook.createDataFormat();
-						cs.setDataFormat(format.getFormat(DatePatterns.ISO));
+						cs.setDataFormat(format.getFormat(DatePatterns.CHINA_DEFAULT));
 						cell.setCellStyle(cs);
 						cell.setCellType(CellType.NUMERIC);
 						if (null != value) {
@@ -134,4 +134,4 @@ public class ExcelWriter {
 		}
 	}
 
-}
+}

+ 69 - 7
src/main/java/cn/com/qmth/examcloud/commons/util/DateUtil.java

@@ -2,8 +2,11 @@ package cn.com.qmth.examcloud.commons.util;
 
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.util.Calendar;
 import java.util.Date;
 
+import cn.com.qmth.examcloud.commons.exception.ExamCloudRuntimeException;
+
 /**
  * 日期工具
  * 
@@ -17,6 +20,7 @@ public class DateUtil {
 	 * @author WANGWEI
 	 */
 	public interface DatePatterns {
+
 		public static final String DEFAULT = "yyyyMMddHHmmss";
 
 		public static final String YYYY = "yyyy";
@@ -29,7 +33,7 @@ public class DateUtil {
 
 		public static final String YYYYMMDDHHMM = "yyyyMMddHHmm";
 
-		public static final String ISO = "yyyy-MM-dd HH:mm:ss";
+		public static final String CHINA_DEFAULT = "yyyy-MM-dd HH:mm:ss";
 
 		public static final String YYYY_MM = "yyyy-MM";
 
@@ -46,17 +50,17 @@ public class DateUtil {
 	 * @param pattern
 	 * @return
 	 */
-	public static String getNow(String pattern) {
+	public static String now(String pattern) {
 		return format(new Date(), pattern);
 	}
 
 	/**
-	 * get now ISO date.
+	 * get now china date.
 	 * 
 	 * @return
 	 */
-	public static String getNowISO() {
-		return format(new Date(), DatePatterns.ISO);
+	public static String chinaNow() {
+		return format(new Date(), DatePatterns.CHINA_DEFAULT);
 	}
 
 	/**
@@ -71,7 +75,23 @@ public class DateUtil {
 			SimpleDateFormat df = new SimpleDateFormat(pattern);
 			return df.format(date);
 		} catch (Exception e) {
-			throw new RuntimeException(e);
+			throw new ExamCloudRuntimeException(e);
+		}
+	}
+
+	/**
+	 * format now date.
+	 *
+	 * @author WANGWEI
+	 * @param pattern
+	 * @return
+	 */
+	public static String formatNow(String pattern) {
+		try {
+			SimpleDateFormat df = new SimpleDateFormat(pattern);
+			return df.format(new Date());
+		} catch (Exception e) {
+			throw new ExamCloudRuntimeException(e);
 		}
 	}
 
@@ -87,8 +107,50 @@ public class DateUtil {
 		try {
 			return df.parse(source);
 		} catch (ParseException e) {
-			throw new RuntimeException(e);
+			throw new ExamCloudRuntimeException(e);
+		}
+	}
+
+	/**
+	 * 是否同一天
+	 *
+	 * @author WANGWEI
+	 * @param date1
+	 * @param date2
+	 * @return
+	 */
+	public static boolean isSameDay(Date date1, Date date2) {
+		if (null == date1) {
+			throw new ExamCloudRuntimeException("first argument must not be null");
+		}
+		if (null == date2) {
+			throw new ExamCloudRuntimeException("second argument must not be null");
+		}
+
+		Calendar cal1 = Calendar.getInstance();
+		cal1.setTime(date1);
+		Calendar cal2 = Calendar.getInstance();
+		cal2.setTime(date2);
+		return isSameDay(cal1, cal2);
+	}
+
+	/**
+	 * 是否同一天
+	 *
+	 * @author WANGWEI
+	 * @param calendar1
+	 * @param calendar2
+	 * @return
+	 */
+	public static boolean isSameDay(Calendar calendar1, Calendar calendar2) {
+		if (null == calendar1) {
+			throw new ExamCloudRuntimeException("first argument must not be null");
+		}
+		if (null == calendar2) {
+			throw new ExamCloudRuntimeException("second argument must not be null");
 		}
+		return calendar1.get(0) == calendar2.get(0) && calendar1.get(1) == calendar2.get(1)
+				&& calendar1.get(6) == calendar2.get(6);
 	}
 
 }

+ 101 - 14
src/main/java/cn/com/qmth/examcloud/commons/util/JsonUtil.java

@@ -1,29 +1,44 @@
 package cn.com.qmth.examcloud.commons.util;
 
 import java.lang.reflect.Type;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
 
+import com.google.common.collect.Maps;
+import com.google.gson.ExclusionStrategy;
+import com.google.gson.FieldAttributes;
 import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
 
 import cn.com.qmth.examcloud.commons.util.DateUtil.DatePatterns;
 
 /**
- * 类注释
+ * json tool
  *
  * @author WANGWEI
+ * @param <T>
+ * @date 2019年1月16日
+ * @Copyright (c) 2018-2020 WANGWEI [QQ:522080330] All Rights Reserved.
  */
 public class JsonUtil {
+
 	/**
-	 * 方法注释
+	 * to json
 	 *
 	 * @author WANGWEI
 	 * @param obj
 	 * @return
 	 */
 	public static String toJson(Object obj) {
-		Gson gson = new GsonBuilder().disableHtmlEscaping().setDateFormat(DatePatterns.ISO)
-				.create();
-		return gson.toJson(obj);
+		GsonBuilder builder = new GsonBuilder().disableHtmlEscaping().serializeNulls()
+				.setDateFormat(DatePatterns.CHINA_DEFAULT);
+		return builder.create().toJson(obj);
 	}
 
 	/**
@@ -31,16 +46,49 @@ public class JsonUtil {
 	 *
 	 * @author WANGWEI
 	 * @param obj
+	 * @param excludeFields
+	 * @return
+	 */
+	public static String toJson(Object obj, String... excludeFields) {
+		GsonBuilder builder = new GsonBuilder().disableHtmlEscaping().serializeNulls()
+				.setDateFormat(DatePatterns.CHINA_DEFAULT);
+
+		builder.setExclusionStrategies(new ExclusionStrategy() {
+			@Override
+			public boolean shouldSkipField(FieldAttributes f) {
+				for (String field : excludeFields) {
+					if (f.getName().matches(field)) {
+						return true;
+					}
+				}
+
+				return false;
+			}
+
+			@Override
+			public boolean shouldSkipClass(Class<?> clazz) {
+				return false;
+			}
+		});
+
+		return builder.create().toJson(obj);
+	}
+
+	/**
+	 * to pretty json
+	 *
+	 * @author WANGWEI
+	 * @param obj
 	 * @return
 	 */
 	public static String toPrettyJson(Object obj) {
-		Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting()
-				.setDateFormat(DatePatterns.ISO).create();
-		return gson.toJson(obj);
+		GsonBuilder builder = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting()
+				.serializeNulls().setDateFormat(DatePatterns.CHINA_DEFAULT);
+		return builder.create().toJson(obj);
 	}
 
 	/**
-	 * 方法注释
+	 * json转对象
 	 *
 	 * @author WANGWEI
 	 * @param json
@@ -48,13 +96,52 @@ public class JsonUtil {
 	 * @return
 	 */
 	public static <T> T fromJson(String json, Class<T> c) {
-		Gson gson = new GsonBuilder().disableHtmlEscaping().setDateFormat(DatePatterns.ISO)
-				.create();
+		Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting()
+				.setDateFormat(DatePatterns.CHINA_DEFAULT).create();
 		return gson.fromJson(json, c);
 	}
 
 	/**
-	 * 方法注释
+	 * json数组转list
+	 *
+	 * @author WANGWEI
+	 * @param json
+	 * @param elementType
+	 * @return
+	 */
+	public static <T> List<T> fromJsonArray(String json, Class<T[]> elementType) {
+		Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting()
+				.setDateFormat(DatePatterns.CHINA_DEFAULT).create();
+		T[] array = gson.fromJson(json, elementType);
+		return Arrays.asList(array);
+	}
+
+	/**
+	 * simple json to map
+	 *
+	 * @author WANGWEI
+	 * @param s
+	 * @return
+	 */
+	public static Map<String, String> json2Map(String s) {
+		JsonParser parser = new JsonParser();
+		JsonElement jsonElement = parser.parse(s);
+		JsonObject jsonObject = jsonElement.getAsJsonObject();
+		Set<Entry<String, JsonElement>> entrySet = jsonObject.entrySet();
+
+		Map<String, String> map = Maps.newHashMap();
+		for (Entry<String, JsonElement> entry : entrySet) {
+			JsonElement e = entry.getValue();
+			if (!e.isJsonNull()) {
+				String v = e.getAsString();
+				map.put(entry.getKey(), v);
+			}
+		}
+		return map;
+	}
+
+	/**
+	 * json转对象
 	 *
 	 * @author WANGWEI
 	 * @param json
@@ -62,8 +149,8 @@ public class JsonUtil {
 	 * @return
 	 */
 	public static <T> T fromJson(String json, Type type) {
-		Gson gson = new GsonBuilder().disableHtmlEscaping().setDateFormat(DatePatterns.ISO)
-				.create();
+		Gson gson = new GsonBuilder().disableHtmlEscaping()
+				.setDateFormat(DatePatterns.CHINA_DEFAULT).create();
 		return gson.fromJson(json, type);
 	}
 

+ 4 - 20
src/main/java/cn/com/qmth/examcloud/commons/util/PropertiesUtil.java

@@ -10,7 +10,7 @@ import java.util.Properties;
 import java.util.Set;
 
 import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang.StringUtils;
 
 import com.google.common.collect.Sets;
 
@@ -19,9 +19,11 @@ import cn.com.qmth.examcloud.commons.logging.ExamCloudLog;
 import cn.com.qmth.examcloud.commons.logging.ExamCloudLogFactory;
 
 /**
- * Properties 工具
+ * 类注释
  *
  * @author WANGWEI
+ * @date 2018年10月8日
+ * @Copyright (c) 2018-2020 WANGWEI [QQ:522080330] All Rights Reserved.
  */
 public class PropertiesUtil {
 
@@ -31,8 +33,6 @@ public class PropertiesUtil {
 
 	private static final Set<String> PROP_FILES = Sets.newConcurrentHashSet();
 
-	private static boolean initialized = false;
-
 	static {
 		init();
 	}
@@ -50,10 +50,6 @@ public class PropertiesUtil {
 	 * @author WANGWEI
 	 */
 	public static void init() {
-		if (initialized) {
-			return;
-		}
-		initialized = true;
 		configure(PathUtil.getResoucePath("resource.properties"));
 	}
 
@@ -251,16 +247,4 @@ public class PropertiesUtil {
 			return defaultVale;
 		}
 	}
-
-	/**
-	 * 设置属性
-	 *
-	 * @author WANGWEI
-	 * @param key
-	 * @param value
-	 */
-	public static void setProperty(String key, String value) {
-		PROPS.setProperty(key, value);
-	}
-
 }

+ 38 - 13
src/main/java/cn/com/qmth/examcloud/commons/util/StringUtil.java

@@ -2,6 +2,10 @@ package cn.com.qmth.examcloud.commons.util;
 
 import java.util.List;
 
+import org.apache.commons.lang3.StringUtils;
+
+import cn.com.qmth.examcloud.commons.exception.ExamCloudRuntimeException;
+
 /**
  *
  * @author WANGWEI
@@ -108,7 +112,7 @@ public class StringUtil {
 		try {
 			return Integer.parseInt(in);
 		} catch (NumberFormatException e) {
-			throw new RuntimeException(e);
+			throw new ExamCloudRuntimeException(e);
 		}
 	}
 
@@ -303,35 +307,56 @@ public class StringUtil {
 	}
 
 	/**
-	 * 方法注释
+	 * 转换成Boolean
 	 *
 	 * @author WANGWEI
 	 * @param s
 	 * @return
 	 */
-	public static Boolean isInteger(String s) {
-		try {
-			Integer.parseInt(s);
+	public static Boolean toBoolean(String s) {
+		if (StringUtils.isBlank(s)) {
+			return null;
+		}
+		s = s.trim();
+		if (s.equals("true")) {
 			return true;
-		} catch (NumberFormatException e) {
+		} else if (s.equals("false")) {
 			return false;
+		} else {
+			throw new ExamCloudRuntimeException("[" + s + "] must be null, \"true\\\",\\\"false\\\"");
 		}
 	}
 
 	/**
-	 * 方法注释
+	 * 转换成Integer
 	 *
 	 * @author WANGWEI
 	 * @param s
 	 * @return
 	 */
-	public static Boolean isLong(String s) {
-		try {
-			Long.parseLong(s);
-			return true;
-		} catch (NumberFormatException e) {
-			return false;
+	public static Integer toInteger(String s) {
+		if (StringUtils.isBlank(s)) {
+			return null;
+		}
+		s = s.trim();
+		int i = Integer.parseInt(s);
+		return i;
+	}
+
+	/**
+	 * 转换成Long
+	 *
+	 * @author WANGWEI
+	 * @param s
+	 * @return
+	 */
+	public static Long toLong(String s) {
+		if (StringUtils.isBlank(s)) {
+			return null;
 		}
+		s = s.trim();
+		Long l = Long.parseLong(s);
+		return l;
 	}
 
 }

+ 8 - 8
src/main/java/cn/com/qmth/examcloud/commons/util/ThreadLocalUtil.java

@@ -3,7 +3,7 @@ package cn.com.qmth.examcloud.commons.util;
 import java.util.Map;
 import java.util.UUID;
 
-import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang.StringUtils;
 
 import com.google.common.collect.Maps;
 
@@ -42,7 +42,7 @@ public class ThreadLocalUtil {
 	public static String next() {
 		LOCAL_TRACE_MAP.set(null);
 		String traceID = UUID.randomUUID().toString().replace("-", "");
-		setTraceID(traceID);
+		setTraceId(traceID);
 		return traceID;
 	}
 
@@ -52,7 +52,7 @@ public class ThreadLocalUtil {
 	 * @author WANGWEI
 	 * @return
 	 */
-	public static String getTraceID() {
+	public static String getTraceId() {
 		String traceID = LOCAL_TRACE_ID.get();
 		if (traceID == null) {
 			traceID = next();
@@ -67,12 +67,12 @@ public class ThreadLocalUtil {
 	 * 方法注释
 	 *
 	 * @author WANGWEI
-	 * @param traceID
+	 * @param traceId
 	 */
-	public static void setTraceID(String traceID) {
-		if (!(StringUtils.isNotBlank(traceID)))
+	public static void setTraceId(String traceId) {
+		if (!(StringUtils.isNotBlank(traceId)))
 			return;
-		LOCAL_TRACE_ID.set(traceID);
+		LOCAL_TRACE_ID.set(traceId);
 	}
 
 	/**
@@ -106,4 +106,4 @@ public class ThreadLocalUtil {
 		}
 		return map.get(key);
 	}
-}
+}