Commit b40bc8c2 authored by yanzg's avatar yanzg

压缩视频

parent 1153d9e1
...@@ -36,6 +36,15 @@ public interface SqlCond { ...@@ -36,6 +36,15 @@ public interface SqlCond {
*/ */
boolean isField(String... field); boolean isField(String... field);
/**
* 获取字段值
*
* @param model
* @return
*/
List<Object> getValues(Object model);
/** /**
* 获取新的SQL语句 * 获取新的SQL语句
* *
......
...@@ -3,6 +3,7 @@ package com.yanzuoguang.dao.cond; ...@@ -3,6 +3,7 @@ package com.yanzuoguang.dao.cond;
import com.yanzuoguang.dao.DaoConst; import com.yanzuoguang.dao.DaoConst;
import com.yanzuoguang.dao.impl.SqlData; import com.yanzuoguang.dao.impl.SqlData;
import com.yanzuoguang.dao.impl.SqlDataField; import com.yanzuoguang.dao.impl.SqlDataField;
import com.yanzuoguang.util.base.ObjectHelper;
import com.yanzuoguang.util.exception.CodeException; import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.StringHelper; import com.yanzuoguang.util.helper.StringHelper;
...@@ -54,11 +55,19 @@ public abstract class SqlCondBase implements SqlCond { ...@@ -54,11 +55,19 @@ public abstract class SqlCondBase implements SqlCond {
} }
/** /**
* 获取当前的字段 * 获取字段值
* *
* @param model
* @return * @return
*/ */
protected abstract String getFieldName(); @Override
public List<Object> getValues(Object model) {
List<Object> rets = new ArrayList<>();
for (String field : this.fields) {
rets.add(ObjectHelper.get(model, field));
}
return rets;
}
/** /**
* 当前条件是否相等 * 当前条件是否相等
...@@ -74,34 +83,35 @@ public abstract class SqlCondBase implements SqlCond { ...@@ -74,34 +83,35 @@ public abstract class SqlCondBase implements SqlCond {
* *
* @param sql * @param sql
* @param sqlData * @param sqlData
* @param field * @param sqlDataField
* @param model * @param model
* @param codeMap * @param codeMap
* @return * @return
*/ */
@Override @Override
public String getSql(String sql, SqlData sqlData, SqlDataField field, Object model, Map<String, List<String>> codeMap) { public String getSql(String sql, SqlData sqlData, SqlDataField sqlDataField, Object model, Map<String, List<String>> codeMap) {
if (field.getCond() != this) { if (sqlDataField.getCond() != this) {
throw new CodeException("不能处理非本条件的字段"); throw new CodeException("不能处理非本条件的字段");
} }
int condType = getCondType(model, field); int condType = getCondType(model, sqlDataField);
switch (condType) { switch (condType) {
case COND_TYPE_CONST_ONLY_PARA: { case COND_TYPE_CONST_ONLY_PARA: {
String fieldName = this.getFieldName(); for (String field : this.fields) {
// 进行SQL语句参数替换,后面增加一个空格,方便后续用正则表达式进行替换处理 // 进行SQL语句参数替换,后面增加一个空格,方便后续用正则表达式进行替换处理
sql = sql.replaceFirst("\\?", "@" + fieldName + " "); sql = sql.replaceFirst("\\?", "@" + field + " ");
}
break; break;
} }
case COND_TYPE_CODE_COND: { case COND_TYPE_CODE_COND: {
String fieldName = this.getFieldName(); String fieldName = this.fields.get(0);
// 判断代码片段是否合法 // 判断代码片段是否合法
if (field.getCodes().size() % 2 == 1) { if (sqlDataField.getCodes().size() % 2 == 1) {
throw new CodeException("代码片段" + this.getClass().getSimpleName() + ":" + sqlData.getName() + ":" + fieldName + "为单数"); throw new CodeException("代码片段" + this.getClass().getSimpleName() + ":" + sqlData.getName() + ":" + fieldName + "为单数");
} }
// 处理代码片段 // 处理代码片段
for (int i = 0; i < field.getCodes().size(); i = i + DaoConst.CODE_UNIT) { for (int i = 0; i < sqlDataField.getCodes().size(); i = i + DaoConst.CODE_UNIT) {
String codeName = field.getCodes().get(i); String codeName = sqlDataField.getCodes().get(i);
String codeValue = field.getCodes().get(i + 1); String codeValue = sqlDataField.getCodes().get(i + 1);
codeValue = codeValue.replaceAll("\\?", "@" + fieldName + " "); codeValue = codeValue.replaceAll("\\?", "@" + fieldName + " ");
addCodeMap(codeMap, codeName, codeValue); addCodeMap(codeMap, codeName, codeValue);
} }
......
...@@ -22,15 +22,6 @@ public class SqlCondDefault extends SqlCondBase { ...@@ -22,15 +22,6 @@ public class SqlCondDefault extends SqlCondBase {
super(fields); super(fields);
} }
/**
* 获取当前的字段
*
* @return
*/
@Override
protected String getFieldName() {
return fields.isEmpty() ? StringHelper.EMPTY : this.fields.get(0);
}
/** /**
* 当前条件是否相等 * 当前条件是否相等
......
...@@ -25,16 +25,6 @@ public class SqlCondEquals extends SqlCondBase { ...@@ -25,16 +25,6 @@ public class SqlCondEquals extends SqlCondBase {
this.val = val; this.val = val;
} }
/**
* 获取当前的字段
*
* @return
*/
@Override
protected String getFieldName() {
return fields.isEmpty() ? StringHelper.EMPTY : this.fields.get(0);
}
/** /**
* 当前条件是否相等 * 当前条件是否相等
* *
...@@ -58,7 +48,6 @@ public class SqlCondEquals extends SqlCondBase { ...@@ -58,7 +48,6 @@ public class SqlCondEquals extends SqlCondBase {
return COND_TYPE_CODE_COND; return COND_TYPE_CODE_COND;
} }
} }
return COND_TYPE_NONE;
} }
return COND_TYPE_NONE; return COND_TYPE_NONE;
} }
......
...@@ -736,12 +736,12 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao { ...@@ -736,12 +736,12 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
String date = StringHelper.EMPTY; String date = StringHelper.EMPTY;
for (SqlDataField field : sql.getSqlDataFields()) { for (SqlDataField field : sql.getSqlDataFields()) {
List<Object> values = field.getCond().getValues(model);
for (Object item : values) {
if (sb.length() > 0) { if (sb.length() > 0) {
sb.append(":"); sb.append(":");
} }
Object item = ObjectHelper.get(model, field.paraName);
sb.append(item); sb.append(item);
if (StringHelper.isEmpty(date)) { if (StringHelper.isEmpty(date)) {
String itemString = String.valueOf(item); String itemString = String.valueOf(item);
if (item instanceof Date) { if (item instanceof Date) {
...@@ -751,6 +751,7 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao { ...@@ -751,6 +751,7 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
} }
} }
} }
}
if (StringHelper.isEmpty(date)) { if (StringHelper.isEmpty(date)) {
return StringHelper.md5(sb.toString()); return StringHelper.md5(sb.toString());
} else { } else {
......
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