Commit 08181534 authored by yanzg's avatar yanzg

压缩视频

parent b1256682
...@@ -340,6 +340,17 @@ public class StringHelper { ...@@ -340,6 +340,17 @@ public class StringHelper {
} }
} }
/**
* 判断类型是否是整形
*
* @param cls
* @return
*/
public static boolean isInt(Class<?> cls) {
String vName = cls.getName();
return TYPE_INT.equals(vName) || isType(cls, Integer.class);
}
/** /**
* 根据类型来获取值 * 根据类型来获取值
* *
......
...@@ -135,7 +135,35 @@ public abstract class SqlCondBase<T extends SqlCondBase> implements SqlCond<T> { ...@@ -135,7 +135,35 @@ public abstract class SqlCondBase<T extends SqlCondBase> implements SqlCond<T> {
} }
for (String toField : toFields) { for (String toField : toFields) {
String to = toField.toLowerCase().replaceAll("_", ""); String to = toField.toLowerCase().replaceAll("_", "");
if (mapField.containsKey(to)) {
mapField.remove(to); mapField.remove(to);
} else {
return false;
}
}
return mapField.isEmpty();
}
/**
* 判断值是否相等
*
* @param fromFields 来源字段
* @param toFields 目标字段
* @return
*/
protected static boolean eqaulsValues(List fromFields, List toFields) {
Map<Object, Boolean> mapField = new HashMap<>();
for (Object fromField : fromFields) {
Object from = fromField != null ? fromField : StringHelper.EMPTY;
mapField.put(from, true);
}
for (Object toField : toFields) {
Object to = toField != null ? toField : StringHelper.EMPTY;
if (mapField.containsKey(to)) {
mapField.remove(to);
} else {
return false;
}
} }
return mapField.isEmpty(); return mapField.isEmpty();
} }
......
...@@ -6,7 +6,9 @@ import com.yanzuoguang.util.helper.ArrayHelper; ...@@ -6,7 +6,9 @@ import com.yanzuoguang.util.helper.ArrayHelper;
import com.yanzuoguang.util.helper.StringHelper; import com.yanzuoguang.util.helper.StringHelper;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 包含的值字段 * 包含的值字段
...@@ -15,15 +17,32 @@ import java.util.List; ...@@ -15,15 +17,32 @@ import java.util.List;
*/ */
public class SqlCondEquals extends SqlCondBase<SqlCondEquals> { public class SqlCondEquals extends SqlCondBase<SqlCondEquals> {
public Object val; public Object[] vals;
public SqlCondEquals(String field, Object val) { private boolean valIsInteger = false;
this(Arrays.asList(field), val);
private Map<Object, Boolean> mapValue = new HashMap<>();
public SqlCondEquals(String field, Object... vals) {
this(Arrays.asList(field), vals);
} }
public SqlCondEquals(List<String> fields, Object val) { public SqlCondEquals(List<String> fields, Object... vals) {
super(fields); super(fields);
this.val = val; this.vals = vals;
// 判断值是否为整形
if (vals != null) {
for (Object val : this.vals) {
if (val != null) {
valIsInteger = valIsInteger || StringHelper.isInt(val.getClass());
mapValue.put(val, true);
} else {
mapValue.put(StringHelper.EMPTY, true);
}
}
}
} }
/** /**
...@@ -41,12 +60,20 @@ public class SqlCondEquals extends SqlCondBase<SqlCondEquals> { ...@@ -41,12 +60,20 @@ public class SqlCondEquals extends SqlCondBase<SqlCondEquals> {
for (String field : this.fields) { for (String field : this.fields) {
// 获取值 // 获取值
Object val = ObjectHelper.get(model, field); Object val = ObjectHelper.get(model, field);
if (StringHelper.isEmpty(val) || StringHelper.isEmptyArray(val)) { // 转换为整形
continue; if (valIsInteger) {
val = StringHelper.toInt(val);
} }
// 判断值是否相等
List list = ArrayHelper.getList(val); List list = ArrayHelper.getList(val);
for (Object item : list) { for (Object item : list) {
if (StringHelper.compare(item, this.val)) { // 值处理
Object itemTo = item;
if (itemTo == null) {
itemTo = StringHelper.EMPTY;
}
// 判断是否包含该值
if (this.mapValue.containsKey(itemTo)) {
// 只要有值不为空,则条件满足 // 只要有值不为空,则条件满足
return COND_TYPE_CODE_COND; return COND_TYPE_CODE_COND;
} }
...@@ -63,7 +90,7 @@ public class SqlCondEquals extends SqlCondBase<SqlCondEquals> { ...@@ -63,7 +90,7 @@ public class SqlCondEquals extends SqlCondBase<SqlCondEquals> {
*/ */
@Override @Override
public SqlCond copy() { public SqlCond copy() {
SqlCondEquals cond = new SqlCondEquals(this.fields, this.val); SqlCondEquals cond = new SqlCondEquals(this.fields, this.vals);
return cond; return cond;
} }
...@@ -75,6 +102,7 @@ public class SqlCondEquals extends SqlCondBase<SqlCondEquals> { ...@@ -75,6 +102,7 @@ public class SqlCondEquals extends SqlCondBase<SqlCondEquals> {
*/ */
@Override @Override
public boolean equals(SqlCondEquals cond) { public boolean equals(SqlCondEquals cond) {
return SqlCondBase.eqaulsField(this.fields, cond.fields) && StringHelper.compare(this.val, cond.val); return SqlCondBase.eqaulsField(this.fields, cond.fields)
&& StringHelper.compare(Arrays.asList(this.vals), Arrays.asList(cond.vals));
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment