mirror of
https://gitee.com/freshday/radar.git
synced 2026-03-22 04:37:16 +08:00
opts:
code review feihu wang
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
package com.pgmmers.radar.test;
|
||||
import com.pgmmers.radar.util.CryptUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CryptUtilTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void testSHA() {
|
||||
String str = CryptUtils.sha("123456", "admin").toUpperCase();
|
||||
System.out.println(str);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -40,78 +40,6 @@ public class DateUtils {
|
||||
return dateTimeFormat.parse(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getStartCurrentDate.</p>
|
||||
*
|
||||
* @return a {@link Date} object.
|
||||
*/
|
||||
public static Date getStartCurrentDate() {
|
||||
// Calendar cal = Calendar.getInstance();
|
||||
// cal.set(Calendar.HOUR_OF_DAY, 0);
|
||||
// cal.set(Calendar.MINUTE, 0);
|
||||
// cal.set(Calendar.SECOND, 0);
|
||||
// try {
|
||||
// return dateTimeFormat.parse(dateTimeFormat.format(cal.getTime()));
|
||||
// } catch (ParseException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// return null;
|
||||
return getCurrentDate();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getEndCurrentDate.</p>
|
||||
*
|
||||
* @return a {@link Date} object.
|
||||
*/
|
||||
public static Date getEndCurrentDate() {
|
||||
// Calendar cal = Calendar.getInstance();
|
||||
// cal.set(Calendar.HOUR_OF_DAY, 23);
|
||||
// cal.set(Calendar.MINUTE, 59);
|
||||
// cal.set(Calendar.SECOND, 59);
|
||||
//
|
||||
// try {
|
||||
// return dateTimeFormat.parse(dateTimeFormat.format(cal.getTime()));
|
||||
// } catch (ParseException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// return null;
|
||||
return addDate(1,getCurrentDate());
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getDateTime.</p>
|
||||
*
|
||||
* @return a long.
|
||||
*/
|
||||
public static long getDateTime() {
|
||||
return new Date().getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getCurrentDate.</p>
|
||||
*
|
||||
* @return a {@link Date} object.
|
||||
*/
|
||||
public static Date getCurrentDate() {
|
||||
return new Date();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getCurrentGMTDate.</p>
|
||||
*
|
||||
* @return a {@link Date} object.
|
||||
*/
|
||||
public static Date getCurrentGMTDate() {
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
dateFormat.setTimeZone(new SimpleTimeZone(0, "GMT"));
|
||||
try {
|
||||
return dateTimeFormat.parse(dateFormat.format(new Date()));
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>formatDate.</p>
|
||||
@@ -148,8 +76,6 @@ public class DateUtils {
|
||||
startCal.setTime(startDate);
|
||||
Calendar endCal = Calendar.getInstance();
|
||||
endCal.setTime(endDate);
|
||||
//System.out.println(startCal.getTimeInMillis());
|
||||
//System.out.println(endCal.getTimeInMillis());
|
||||
return (startCal.getTimeInMillis() - endCal.getTimeInMillis()) / (1000);
|
||||
}
|
||||
|
||||
@@ -200,9 +126,6 @@ public class DateUtils {
|
||||
* @param args an array of {@link String} objects.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
System.out.println(getStartCurrentDate());
|
||||
System.out.println(getEndCurrentDate());
|
||||
|
||||
System.out.println(formatDate(new Date(), "yyyy-MM-ww-dd"));
|
||||
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import java.util.StringTokenizer;
|
||||
*/
|
||||
public class JsonParserUtil {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(JsonParserUtil.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(JsonParserUtil.class);
|
||||
|
||||
private static final String AQL_SEPARATOR = ".";
|
||||
|
||||
@@ -25,8 +25,8 @@ public class JsonParserUtil {
|
||||
StringTokenizer token = new StringTokenizer(aql, AQL_SEPARATOR);
|
||||
try {
|
||||
while (token.hasMoreElements()) {
|
||||
String args_string = token.nextToken();
|
||||
json = json.getJSONObject(args_string);
|
||||
String argsString = token.nextToken();
|
||||
json = json.getJSONObject(argsString);
|
||||
}
|
||||
return json;
|
||||
} catch (Exception e) {
|
||||
@@ -44,11 +44,11 @@ public class JsonParserUtil {
|
||||
StringTokenizer token = new StringTokenizer(aql, AQL_SEPARATOR);
|
||||
try {
|
||||
while (token.hasMoreElements()) {
|
||||
String args_string = token.nextToken();
|
||||
String argsString = token.nextToken();
|
||||
if (token.hasMoreElements()) {
|
||||
json = json.getJSONObject(args_string);
|
||||
json = json.getJSONObject(argsString);
|
||||
} else {
|
||||
json_array = json.getJSONArray(args_string);
|
||||
json_array = json.getJSONArray(argsString);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -64,26 +64,26 @@ public class JsonParserUtil {
|
||||
* 获取安全方法链的值,方法中出现错误返回传入的 value
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T value(String jsonStr, String aql, T default_result) {
|
||||
public static <T> T value(String jsonStr, String aql, T defaultResult) {
|
||||
logger.debug("#获取 json 节点 safety ".concat(aql));
|
||||
JSONObject json_object = JSONObject.parseObject(jsonStr);
|
||||
JSONObject jsonObject = JSONObject.parseObject(jsonStr);
|
||||
StringTokenizer token = new StringTokenizer(aql, AQL_SEPARATOR);
|
||||
T tmp_result = null;
|
||||
try {
|
||||
while (token.hasMoreElements()) {
|
||||
String args_string = token.nextToken();
|
||||
String argsString = token.nextToken();
|
||||
if (token.hasMoreElements()) {
|
||||
json_object = json_object.getJSONObject(args_string);
|
||||
jsonObject = jsonObject.getJSONObject(argsString);
|
||||
} else {
|
||||
tmp_result = (T) json_object.get(args_string);
|
||||
tmp_result = (T) jsonObject.get(argsString);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
String message = "解析 json 节点".concat(aql).concat("错误:");
|
||||
logger.warn(message, e);
|
||||
}
|
||||
default_result = (tmp_result == null) ? default_result : tmp_result;
|
||||
return default_result;
|
||||
defaultResult = (tmp_result == null) ? defaultResult : tmp_result;
|
||||
return defaultResult;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user