Commit 8bcae95e authored by yanzg's avatar yanzg

默认日期格式的支持

parent 36fdb25b
...@@ -18,7 +18,7 @@ public class SqlCondDefault extends SqlCondBase<SqlCondDefault> { ...@@ -18,7 +18,7 @@ public class SqlCondDefault extends SqlCondBase<SqlCondDefault> {
this(Arrays.asList(field)); this(Arrays.asList(field));
} }
protected SqlCondDefault(List<String> fields) { public SqlCondDefault(List<String> fields) {
super(fields); super(fields);
} }
......
...@@ -169,8 +169,8 @@ public class SqlData { ...@@ -169,8 +169,8 @@ public class SqlData {
* @param tag 标签 * @param tag 标签
* @return * @return
*/ */
public SqlData add(Class<?> clsModel, String tag) { public SqlData add(Class<?> clsModel, String tag, String... codes) {
return this.add(clsModel, tag, false); return this.add(clsModel, tag, false, codes);
} }
/** /**
...@@ -180,10 +180,10 @@ public class SqlData { ...@@ -180,10 +180,10 @@ public class SqlData {
* @param tag 标签 * @param tag 标签
* @return * @return
*/ */
public SqlData add(Class<?> clsModel, String tag, boolean removeFlag) { public SqlData add(Class<?> clsModel, String tag, boolean removeFlag, String... codes) {
// 生成表结构 // 生成表结构
TableStruct table = new TableStruct(StringHelper.EMPTY, clsModel); TableStruct table = new TableStruct(StringHelper.EMPTY, clsModel);
table.addWhereExtend(this, tag, removeFlag); table.addWhereExtend(this, tag, removeFlag, codes);
return this; return this;
} }
......
...@@ -2,6 +2,7 @@ package com.yanzuoguang.dao.impl; ...@@ -2,6 +2,7 @@ package com.yanzuoguang.dao.impl;
import com.yanzuoguang.dao.DaoConst; import com.yanzuoguang.dao.DaoConst;
import com.yanzuoguang.dao.TableAnnotation; import com.yanzuoguang.dao.TableAnnotation;
import com.yanzuoguang.dao.cond.SqlCondDefault;
import com.yanzuoguang.util.base.MethodField; import com.yanzuoguang.util.base.MethodField;
import com.yanzuoguang.util.base.ObjectHelper; import com.yanzuoguang.util.base.ObjectHelper;
import com.yanzuoguang.util.helper.StringHelper; import com.yanzuoguang.util.helper.StringHelper;
...@@ -18,6 +19,9 @@ import java.util.Map; ...@@ -18,6 +19,9 @@ import java.util.Map;
*/ */
public class TableStruct { public class TableStruct {
private static final int WHERE_ADD = 1;
private static final int WHERE_REMOVE_ADD = 2;
private static final int WHERE_ADD_NOT = 0;
/** /**
* 数据库中的表名称 * 数据库中的表名称
*/ */
...@@ -568,11 +572,11 @@ public class TableStruct { ...@@ -568,11 +572,11 @@ public class TableStruct {
* @param sql 需要扩展的SQL语句 * @param sql 需要扩展的SQL语句
* @param tag 扩展标签 * @param tag 扩展标签
*/ */
public void addWhereExtend(SqlData sql, String tag, boolean removeHistory) { public void addWhereExtend(SqlData sql, String tag, boolean removeHistory, String... codes) {
addWhereBase(sql, tag, false, removeHistory); addWhereBase(sql, tag, false, removeHistory, codes);
} }
private void addWhereBase(SqlData sql, String tag, boolean isRemove, boolean removeHistory) { private void addWhereBase(SqlData sql, String tag, boolean isRemove, boolean removeHistory, String... codes) {
addWhereFieldCommon(sql, this.getKey(), tag, removeHistory); addWhereFieldCommon(sql, this.getKey(), tag, removeHistory);
// Where条件包含的字段 // Where条件包含的字段
...@@ -584,34 +588,45 @@ public class TableStruct { ...@@ -584,34 +588,45 @@ public class TableStruct {
// 非删除时需要更新的字段 // 非删除时需要更新的字段
fields = this.getFieldActionList(DaoConst.FIELD_COMMON, DaoConst.FIELD_REMOVE_UPDATE); fields = this.getFieldActionList(DaoConst.FIELD_COMMON, DaoConst.FIELD_REMOVE_UPDATE);
} }
List<String> codesField = new ArrayList<>();
// 添加普通的Where条件 // 添加普通的Where条件
for (TableFieldVo field : fields) { for (TableFieldVo field : fields) {
addWhereFieldCommon(sql, field, tag, removeHistory); int isAdd = addWhereFieldCommon(sql, field, tag, removeHistory);
if (isAdd != WHERE_ADD_NOT) {
codesField.add(field.inputName);
}
}
if (!codesField.isEmpty()) {
sql.addPara(new SqlCondDefault(codesField), codes);
} }
} }
private void addWhereFieldCommon(SqlData sql, TableFieldVo field, String tag, boolean removeHistory) { private int addWhereFieldCommon(SqlData sql, TableFieldVo field, String tag, boolean removeHistory) {
addWhereFieldNotExtend(sql, field.inputName, String.format(DaoConst.CODE_WHERE_EQUALS, tag, field.name, DaoConst.CODE_PARA), removeHistory); addWhereFieldNotExtend(sql, field.inputName, String.format(DaoConst.CODE_WHERE_EQUALS, tag, field.name, DaoConst.CODE_PARA), removeHistory);
// 添加in条件 // 添加in条件
String sqlIn = String.format(DaoConst.CODE_WHERE_IN, tag, field.name, DaoConst.CODE_PARA); String sqlIn = String.format(DaoConst.CODE_WHERE_IN, tag, field.name, DaoConst.CODE_PARA);
if (field.inputLName.endsWith(DaoConst.CODE_WHERE_IN_END)) { if (field.inputLName.endsWith(DaoConst.CODE_WHERE_IN_END)) {
addWhereFieldNotExtend(sql, field.inputName + DaoConst.CODE_WHERE_IN_END_ES, sqlIn, removeHistory); return addWhereFieldNotExtend(sql, field.inputName + DaoConst.CODE_WHERE_IN_END_ES, sqlIn, removeHistory);
} else { } else {
addWhereFieldNotExtend(sql, field.inputName + DaoConst.CODE_WHERE_IN_END, sqlIn, removeHistory); return addWhereFieldNotExtend(sql, field.inputName + DaoConst.CODE_WHERE_IN_END, sqlIn, removeHistory);
} }
} }
private void addWhereFieldNotExtend(SqlData sql, String inputName, String sqlWhere, boolean removeHistory) { private int addWhereFieldNotExtend(SqlData sql, String inputName, String sqlWhere, boolean removeHistory) {
SqlDataField field = sql.getField(inputName); SqlDataField field = sql.getField(inputName);
if (field == null) { if (field == null) {
// 添加新的条件 // 添加新的条件
sql.add(inputName, sqlWhere); sql.add(inputName, sqlWhere);
return WHERE_ADD;
} else if (field != null && removeHistory) { } else if (field != null && removeHistory) {
// 删除历史条件 // 删除历史条件
sql.removeField(inputName); sql.removeField(inputName);
// 添加新的条件 // 添加新的条件
sql.add(inputName, sqlWhere); sql.add(inputName, sqlWhere);
return WHERE_REMOVE_ADD;
} }
return WHERE_ADD_NOT;
} }
/** /**
......
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