public class DriverAmendUtil {
public static String findDifferent(String str,DataEntity oldClass,DataEntity newClass){
Map<String, String> valuesMap = updateValue();
Map<String, String> valueList = valueMap();
try {
Method[] omethods = oldClass.getClass().getDeclaredMethods();//获得类的方法集合
Method[] nmethods = newClass.getClass().getDeclaredMethods();//获得类的方法集合
//遍历方法集合
for(int i =0 ;i<omethods.length;i++){
//获取所有getXX()的返回值
//methods[i].getName()方法返回方法名
if(omethods[i].getName().startsWith("get")){
Object oldObject = omethods[i].invoke(oldClass, null);
Object newObject = nmethods[i].invoke(newClass, null);
if(oldObject == null||oldObject.toString().equals("")) oldObject = "无";
if(newObject == null||newObject.toString().equals("")) newObject = "无";
if(!(oldObject.toString().equals(newObject.toString()))){
for (Entry<String, String> entry : valuesMap.entrySet()) {
if(nmethods[i].getName().equals(entry.getKey())){
if (valueList.containsKey(entry.getValue())) {
if (oldObject.toString().contains(",")) {
String[] commStr = oldObject.toString().split(",");
String strRe = "";
for (String strC : commStr) {
strRe = strRe.concat(DictUtils.getDictLabel(strC, valueList.get(entry.getValue()), "")).concat(",");
}
oldObject = strRe.substring(0, strRe.length() - 1);
} else {
oldObject = DictUtils.getDictLabel(oldObject.toString(), valueList.get(entry.getValue()), "");
}
if (newObject.toString().contains(",")) {
String[] commStr = newObject.toString().split(",");
String strRe = "";
for (String strC : commStr) {
strRe = strRe.concat(DictUtils.getDictLabel(strC, valueList.get(entry.getValue()), "")).concat(",");
}
newObject = strRe.substring(0, strRe.length() - 1);
} else {
newObject = DictUtils.getDictLabel(newObject.toString(), valueList.get(entry.getValue()), "");
}
}
if(oldObject instanceof Date && newObject instanceof Date){
oldObject =DateUtils.formatDate((Date)oldObject, "yyyy-MM-dd");
newObject =DateUtils.formatDate((Date)newObject, "yyyy-MM-dd");
}
if ("getsArea".equals(entry.getKey())){
if (oldObject.toString().contains(",")) {
String[] commStr = oldObject.toString().split(",");
oldObject = commStr[1];
}
if (newObject.toString().contains(",")){
String[] commStr = newObject.toString().split(",");
newObject = commStr[1];
}
}
str = str + entry.getValue()+"由" + oldObject.toString() + "更改至" + newObject.toString()+ ",";
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return str;
}
private static Map<String, String> valueMap() {
Map<String, String> valueMap = new HashMap<String, String>();
valueMap.put("性别", "sk_sex_Flag");
valueMap.put("身份证明名称", "sk_identity_certify");
valueMap.put("准驾机型", "sk_driving_mark");
return valueMap;
}
private static Map<String, String> updateValue() {
Map<String,String> KV = new HashMap<String, String>();
// 驾驶员初次申请表
KV.put("getsRecordCode","档案编号");
KV.put("getsArea","所属地区");
KV.put("getDCheckDate","办理日期");
KV.put("getsPhotoName","照片名称");
KV.put("getsPhotoPath","照片路径");
KV.put("getsDriveno","准驾机型");
// 人员参数基础表
KV.put("getSName", "姓名");
KV.put("getSTel", "联系电话");
KV.put("getSAddress", "住所地址");
KV.put("getIZipcode", "住所邮政编码");
KV.put("getCIdentnameCode", "身份证明名称");
KV.put("getSDocumentsNo", "证件号码");
KV.put("getSResidProveName", "居住/暂住证明名称");
KV.put("getSResidProveNo", "居住/暂住证号码");
KV.put("getsNationality", "国籍");
KV.put("getCSexFlag", "性别");
KV.put("getDBirth", "出生日期");
// 驾驶证数据业务表
KV.put("getDCheckDate","数据办理日期");
KV.put("getSStartDate", "有效开始日期");
KV.put("getSEndDate", "有效截止日期");
KV.put("getSValidPeriod", "有效期限");
return KV;
}
}