Commit d1e8dd30 authored by yanzg's avatar yanzg

常规BUG的修改

parent 6653c4b2
......@@ -159,4 +159,32 @@ public class DaoConst {
* 删除时记录操作状态的字段
*/
public static final int FIELD_REMOVE_UPDATE = 5;
/**
* SQL语句类型-普通语句
*/
public static final int SQL_TYPE_COMMON = 0;
/**
* SQL语句类型-创建语句
*/
public static final int SQL_TYPE_CREATE = 1;
/**
* SQL语句类型-更新语句
*/
public static final int SQL_TYPE_UPDATE = 2;
/**
* SQL语句类型-删除语句
*/
public static final int SQL_TYPE_REMOVE = 3;
/**
* SQL语句类型-加载语句
*/
public static final int SQL_TYPE_LOAD = 4;
/**
* SQL语句类型-是否存在
*/
public static final int SQL_TYPE_EXINTS = 5;
}
......@@ -163,6 +163,12 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
InitDao to = (InitDao) model;
to.init();
}
List<SqlData> sqlArray = this.table.getSqlType(DaoConst.SQL_TYPE_EXINTS);
if (sqlArray != null) {
for (SqlData sql : sqlArray) {
this.checkExist(sql.getName(), model, String.format("%s已经存在", sql.getName()));
}
}
}
/**
......
......@@ -11,6 +11,11 @@ import java.util.List;
*/
public class SqlData {
/**
* SQL语句类型
*/
private int sqlType = DaoConst.SQL_TYPE_COMMON;
/**
* 对应的参数顺序
*/
......@@ -33,6 +38,22 @@ public class SqlData {
this("", "");
}
/**
* Sql语句类型
* @return Sql语句类型
*/
public int getSqlType() {
return sqlType;
}
/**
* Sql语句类型
* @param sqlType Sql语句类型
*/
public void setSqlType(int sqlType) {
this.sqlType = sqlType;
}
public List<SqlDataField> getSqlDataFields() {
return sqlDataFields;
}
......
......@@ -34,6 +34,11 @@ public class TableSqlCache {
*/
private MemoryCache<SqlData> sqls = new MemoryCache<SqlData>();
/**
* 根据Sql语句类型进行缓存
*/
private MemoryCache<List<SqlData>> sqlTypes = new MemoryCache<>();
/**
* 构造函数
*/
......@@ -60,10 +65,24 @@ public class TableSqlCache {
public SqlData add(SqlData sql) {
if (sql != null) {
this.sqls.put(sql.getName(), sql);
String keyType = String.valueOf(sql.getSqlType());
this.sqlTypes.get(keyType, new ArrayList<>()).add(sql);
}
return sql;
}
/**
* 获取所有的Sql语句执行类型
*
* @param sqlType Sql语句执行类型
* @return Sql语句列表
*/
public List<SqlData> getSqlType(int sqlType) {
String keyType = String.valueOf(sqlType);
return sqlTypes.get(keyType);
}
/**
* 添加SQL
*
......
......@@ -310,6 +310,7 @@ public class TableStruct {
// 生成添加的SQL语句
String text = DaoConst.INSERT_MODEL.replace(DaoConst.TABLE_CODE, this.name);
SqlData sql = new SqlData(DaoConst.CREATE, text);
sql.setSqlType(DaoConst.SQL_TYPE_CREATE);
String flag = "";
if (this.getKeyType() == String.class) {
sql.addParaConst(this.getKey().inputName, DaoConst.FIELD_CODE, this.getKey().name, DaoConst.VALUES_CODE, "?");
......@@ -331,6 +332,7 @@ public class TableStruct {
// 生成添加的SQL语句
String text = DaoConst.UPDATE_MODEL.replace(DaoConst.TABLE_CODE, this.name);
SqlData sql = new SqlData(DaoConst.UPDATE, text);
sql.setSqlType(DaoConst.SQL_TYPE_UPDATE);
TableFieldVo removeField = this.getRemove();
TableFieldVo versionField = this.getVersion();
sql.addParaConst(this.getKey().inputName,
......@@ -365,6 +367,7 @@ public class TableStruct {
// 生成添加的SQL语句
String text = DaoConst.UPDATE_MODEL.replace(DaoConst.TABLE_CODE, this.name);
SqlData sql = new SqlData(DaoConst.REMOVE, text);
sql.setSqlType(DaoConst.SQL_TYPE_REMOVE);
sql.addCode(DaoConst.FIELD_CODE, "a." + removeField.name + "=1");
for (TableFieldVo field : this.getFieldActionList(DaoConst.FIELD_REMOVE_UPDATE)) {
sql.addParaConst(field.inputName, DaoConst.FIELD_CODE, ",a." + field.name + "=?");
......@@ -391,6 +394,7 @@ public class TableStruct {
// 生成添加的SQL语句
String text = DaoConst.LOAD_MODEL.replace(DaoConst.TABLE_CODE, this.name);
SqlData sql = new SqlData(DaoConst.LOAD, text);
sql.setSqlType(DaoConst.SQL_TYPE_LOAD);
addWhereField(sql, "a.", false);
return sql;
}
......@@ -510,6 +514,7 @@ public class TableStruct {
public void addExist(TableSqlCache sqlTableData, String sqlName, String[] fields) {
String text = DaoConst.LOAD_MODEL.replace(DaoConst.TABLE_CODE, this.name);
SqlData sql = new SqlData(sqlName, text);
sql.setSqlType(DaoConst.SQL_TYPE_EXINTS);
sql.addPara(this.getKey().inputName, DaoConst.WHERE_CODE, " AND a." + this.getKey().name + "<>?");
for (String field : fields) {
sql.addParaConst(field, DaoConst.WHERE_CODE, " AND a." + field + "=?");
......
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