Commit b40bc8c2 authored by yanzg's avatar yanzg

压缩视频

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