Commit 0ad53399 authored by yanzg's avatar yanzg

修改保存历史记录

parent e97194d8
......@@ -41,13 +41,25 @@ public class SqlCondDefault extends SqlCondBase<SqlCondDefault> {
*/
@Override
protected int getCondType(Object model, SqlDataField sqlField) {
return getCondType(fields, model, sqlField);
}
/**
* 获取sql类型该
*
* @param fields
* @param model
* @param sqlField
* @return
*/
public static int getCondType(List<String> fields, Object model, SqlDataField sqlField) {
// 判断是否包含输入参数
boolean isInputField = !this.fields.isEmpty();
boolean isInputField = !fields.isEmpty();
// 判断是否属于条件
boolean isCond = sqlField.getCodes().size() > 0 && sqlField.isAuto();
boolean isConst = sqlField.getCodes().size() > 0 && !sqlField.isAuto();
if (isInputField && isCond) {
for (String field : this.fields) {
for (String field : fields) {
// 获取值
Object val = ObjectHelper.get(model, field);
if (StringHelper.isEmpty(val) || StringHelper.isEmptyArray(val)) {
......
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.helper.ArrayHelper;
import com.yanzuoguang.util.helper.StringHelper;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
* 分别处理每一项,用于替换
*
* @author 颜佐光
*/
public class SqlCondItem extends SqlCondBase<SqlCondItem> {
public SqlCondItem(String... field) {
this(Arrays.asList(field));
}
public SqlCondItem(List<String> fields) {
this(null, fields);
}
public SqlCondItem(Runnable debugRunnable, String... field) {
this(debugRunnable, Arrays.asList(field));
}
public SqlCondItem(Runnable debugRunnable, List<String> fields) {
super(fields);
super.debugRunnable = debugRunnable;
}
/**
* 当前条件是否相等
*
* @param model 请求参数实体
* @param sqlField 请求字段
* @return
*/
@Override
protected int getCondType(Object model, SqlDataField sqlField) {
return SqlCondDefault.getCondType(this.fields, model, sqlField);
}
/**
* 获取新的SQL语句
*
* @param sql
* @param sqlData
* @param sqlDataField
* @param model
* @param codeMap
* @return
*/
@Override
public String getSql(String sql, SqlData sqlData, SqlDataField sqlDataField, Object model, Map<String, List<String>> codeMap) {
if (sqlDataField.getCond() != this) {
throw new RuntimeException("不能处理非本条件的字段");
}
if (debugRunnable != null) {
// 用于断点调试的支持
debugRunnable.run();
}
int condType = getCondType(model, sqlDataField);
switch (condType) {
case COND_TYPE_CONST_ONLY_PARA: {
throw new RuntimeException("SqlCondItem不支持输入参数,必须带代码片段");
}
case COND_TYPE_CODE_COND: {
String fieldName = this.fields.isEmpty() ? StringHelper.EMPTY : this.fields.get(0);
// 判断代码片段是否合法
if (sqlDataField.getCodes().size() % 2 == 1) {
throw new RuntimeException("代码片段" + this.getClass().getSimpleName() + ":" + sqlData.getName() + ":" + fieldName + "为单数");
}
Object value = ObjectHelper.get(model, fieldName);
List list = ArrayHelper.getList(value);
for (Object item : list) {
// 处理代码片段
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("\\?", item.toString()).replaceAll("\\{0\\}", item.toString());
codeValue = StringHelper.getCodeString(codeValue, item);
addCodeMap(codeMap, codeName, codeValue);
}
}
break;
}
case COND_TYPE_NONE:
default:
break;
}
return sql;
}
/**
* 将当前条件复制为新的对象
*
* @return
*/
@Override
public SqlCond copy() {
SqlCondItem cond = new SqlCondItem(this.debugRunnable, this.fields);
return cond;
}
}
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