/***
* 递归比较 两个list 两个list同时包含子list
*
* @param now
* @param before
* @return 如果两个list不同返回false
*/
@SuppressWarnings("unused")
public static boolean getAppItInfoUuidDiff(List<FieldInfo> before, List<FieldInfo> now,StringBuffer diff) {
long startTime = System.currentTimeMillis();
boolean flag = true;
if (before != null && now == null) { // 如果有一个为null 另一个不为空 肯定不相同
flag = false;
diff.append("参数列表的数量不同");
return flag;
} else if (before == null && now != null) {// 如果有一个为null 另一个不为空 肯定不相同
flag = false;
diff.append("参数列表的数量不同");
return flag;
} else if (before != null && before.isEmpty() && now != null && !now.isEmpty()) { // 如果有一个为null 另一个不为空 肯定不相同
flag = false;
diff.append("参数列表的数量不同");
return flag;
} else if (before != null && !before.isEmpty() && now != null && now.isEmpty()) {// 如果有一个为null 另一个不为空 肯定不相同
flag = false;
diff.append("参数列表的数量不同");
return flag;
} else if (before != null && !before.isEmpty() && now != null && !now.isEmpty()) {// 都不为空
if (before.size() != now.size()) { // 包含的元素数量不同 肯定不同
flag = false;
diff.append("参数列表的数量不同");
return flag;
} else { // 包含的元素数量相同
for (int i = 0; i < before.size(); i++) {
String before_fieldName = (before.get(i).getFieldName() == null) ? "": before.get(i).getFieldName();
String before_dataType = (before.get(i).getDataType() == null) ? "" : before.get(i).getDataType();
String before_fieldType = (before.get(i).getFieldType() == null) ? "" : before.get(i).getFieldType();
String before_fieldLength = (before.get(i).getFieldLength() == null) ? "" : before.get(i).getFieldLength();
String before_notNull = (before.get(i).getNotNull() == null) ? "" : before.get(i).getNotNull();
String now_fieldName = (now.get(i).getFieldName() == null) ? "" : now.get(i).getFieldName();
String now_dataType = (now.get(i).getDataType() == null) ? "" : now.get(i).getDataType();
String now_fieldType = (now.get(i).getFieldType() == null) ? "" : now.get(i).getFieldType();
String now_fieldLength = (now.get(i).getFieldLength() == null) ? "" : now.get(i).getFieldLength();
String now_notNull = (now.get(i).getNotNull() == null) ? "" : now.get(i).getNotNull();
if ((before_fieldName.equals(now_fieldName)) && (before_dataType.equals(now_dataType)) && (before_fieldType.equals(now_fieldType)) && (before_fieldLength.equals(now_fieldLength)) && (before_notNull.equals(now_notNull))) {// 因为需要比对的属性都相等所以递归调用比对其子list
List<FieldInfo> beforeChild = before.get(i).getFields();
List<FieldInfo> nowChild = now.get(i).getFields();
if(!getAppItInfoUuidDiff(beforeChild, nowChild,diff)){
return false;
}
} else {
diff.append(now.get(i).getFullName()).append(":");
if(!before_fieldName.equals(now_fieldName)){
diff.append("字段名称变更了;");
}
if(!before_dataType.equals(now_dataType)) {
diff.append("数据类型变更了;");
}
if(!before_fieldType.equals(now_fieldType)) {
diff.append("字段类型变更了;");
}
if(!before_fieldLength.equals(now_fieldLength)) {
diff.append("长度变更了;");
}
if(!before_notNull.equals(now_notNull)) {
diff.append("非空变更了;");
}
flag = false;
continue;
}
}
}
}
return flag;
}
@PojoNote(desc="字段信息", resource="app-it-info")
public class FieldInfo
{
@FieldNote(desc="字段名称", length=64, notNull=true)
private String fieldName;
@FieldNote(desc="变量名称", length=64, notNull=true)
private String varName;
@FieldNote(desc="JSON数据", length=12, notNull=false)
private String requestBody;
@FieldNote(desc="字段说明", length=128, notNull=false)
private String fieldDesc;
@FieldNote(desc="数据类型", length=128, notNull=false)
private String dataType;
@FieldNote(desc="真实的数据类型", length=128, notNull=false)
private String dataType2;
@FieldNote(desc="泛型", length=128, notNull=false)
private String generic;
@FieldNote(desc="字段类型", length=32, notNull=false)
private String fieldType;
@FieldNote(desc="长度", length=24, notNull=false)
private String fieldLength;
@FieldNote(desc="非空", length=24, notNull=false)
private String notNull;
@FieldNote(desc="字段路径", length=128, notNull=false)
private String fullName;
@FieldNote(desc="参数名称", length=128, notNull=false)
private String paramName;
@FieldNote(desc="参数类型:para=参数、sys=系统字段", length=24, notNull=false)
private String paramType;
@FieldNote(desc="子节点")
private List<FieldInfo> fields;
public String getFieldName() {
return fieldName;
}
public void setFieldName(String fieldName) {
this.fieldName = fieldName;
}
public String getVarName() {
return varName;
}
public void setVarName(String varName) {
this.varName = varName;
}
public String getRequestBody() {
return requestBody;
}
public void setRequestBody(String requestBody) {
this.requestBody = requestBody;
}
public String getFieldDesc() {
return fieldDesc;
}
public void setFieldDesc(String fieldDesc) {
this.fieldDesc = fieldDesc;
}
public String getDataType() {
return dataType;
}
public void setDataType(String dataType) {
this.dataType = dataType;
}
public String getDataType2() {
return dataType2;
}
public void setDataType2(String dataType2) {
this.dataType2 = dataType2;
}
public String getGeneric() {
return generic;
}
public void setGeneric(String generic) {
this.generic = generic;
}
public String getFieldType() {
return fieldType;
}
public void setFieldType(String fieldType) {
this.fieldType = fieldType;
}
public String getFieldLength() {
return fieldLength;
}
public void setFieldLength(String fieldLength) {
this.fieldLength = fieldLength;
}
public String getNotNull() {
return notNull;
}
public void setNotNull(String notNull) {
this.notNull = notNull;
}
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
public String getParamName() {
return paramName;
}
public void setParamName(String paramName) {
this.paramName = paramName;
}
public String getParamType() {
return paramType;
}
public void setParamType(String paramType) {
this.paramType = paramType;
}
public List<FieldInfo> getFields() {
return fields;
}
public void setFields(List<FieldInfo> fields) {
this.fields = fields;
}
}