Commit 1d48b26e by yuanlin

提交签名类

git-svn-id: svn://192.168.3.233/frms/code/car-service/trunk/car-service@26512 aeb6102e-e053-11e5-9fec-f9ebc45caf4b
1 parent 2da2e615
package com.glsx.ordercenter.utils;
import com.glsx.common.utils.StringUtils;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.*;
import java.util.concurrent.TimeUnit;
public class HandlerUtils {
public static Map<String, String> doGetSign(Object base ,Object obj) {
Map<String, String> map = new TreeMap<>();
Class<?> clazzb = base.getClass();
Class<?> clazz = obj.getClass();
Class<?> clazzs = clazz.getSuperclass();
type2Map(base,clazzb,map);
type2Map(obj,clazz,map);
if(clazzs != null){
type2Map(obj,clazzs,map);
}
System.out.println("======签名map========="+map);
return map;
}
public static Map<String,String> type2Map(Object obj,Class<?> clazz,Map<String, String> map){
for (Field field : clazz.getDeclaredFields()) {
field.setAccessible(true);
//匹配是否为静态常量
if( Modifier.isStatic(field.getModifiers())) {
continue;
}
String fieldName = field.getName();
if("sign".equalsIgnoreCase(fieldName)){
continue;
}
Object value = null;
try {
value = field.get(obj);
} catch (IllegalAccessException e) {
e.printStackTrace();
System.out.println("转换map异常");
}
if (value == null) {
map.put(fieldName, "");
} else {
map.put(fieldName, String.valueOf(value));
}
}
return map;
}
public static long getDifferenceBetweenTwoTime(Date startDate, Date endDate, TimeUnitType timeUnitType) {
long duration = endDate.getTime() - startDate.getTime();
if (timeUnitType != null) {
if (TimeUnitType.SECOND.value() == timeUnitType.value()) {
return TimeUnit.MILLISECONDS.toSeconds(duration);
} else if (TimeUnitType.MINUTE.value() == timeUnitType.value()) {
return TimeUnit.MILLISECONDS.toMinutes(duration);
} else if (TimeUnitType.HOUR.value() == timeUnitType.value()) {
return TimeUnit.MILLISECONDS.toHours(duration);
} else if (TimeUnitType.DAY.value() == timeUnitType.value()) {
return TimeUnit.MILLISECONDS.toDays(duration);
}
}
return duration;
}
public enum TimeUnitType {
DAY(1), HOUR(2), MINUTE(3), SECOND(4);
private int value = 0;
TimeUnitType(int value) {
this.value = value;
}
public int value() {
return value;
}
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!