Commit 75e74d54 authored by yanzg's avatar yanzg

常规BUG的修改

parent 1dd16657
......@@ -74,39 +74,39 @@ public class DaoConst {
* 单位地址
*/
public static final int CODE_UNIT = 2;
/**
* 表名代码片段
* 插入SQL语句模板
*/
public static final String TABLE_CODE = "{TABLE}";
public static final String SQL_INSERT = "INSERT INTO {TABLE}({FIELD}) VALUES({VALUES})";
/**
* 字段代码片段
* 更新SQL语句模板
*/
public static final String FIELD_CODE = "{FIELD}";
public static final String SQL_UPDATE = "UPDATE {TABLE} AS a {INNER} SET {FIELD} WHERE 1=1 {WHERE}";
/**
* 值代码片段
* 删除SQL语句模板
*/
public static final String VALUES_CODE = "{VALUES}";
public static final String SQL_REMOVE = "DELETE a FROM {TABLE} AS a {INNER} WHERE 1=1 {WHERE}";
/**
* WHERE条件代码片段
* 加载SQL语句模板
*/
public static final String WHERE_CODE = "{WHERE}";
public static final String SQL_LOAD = "SELECT a.*{FIELD} FROM {TABLE} AS a {INNER} WHERE 1=1 {WHERE}";
/**
* 插入SQL语句模板
* 表名代码片段
*/
public static final String INSERT_MODEL = "INSERT INTO {TABLE}({FIELD}) VALUES({VALUES})";
public static final String CODE_TABLE = "{TABLE}";
/**
* 更新SQL语句模板
* 字段代码片段
*/
public static final String UPDATE_MODEL = "UPDATE {TABLE} AS a {INNER} SET {FIELD} WHERE 1=1 {WHERE}";
public static final String CODE_FIELD = "{FIELD}";
/**
* 删除SQL语句模板
* 值代码片段
*/
public static final String REMOVE_MODEL = "DELETE a FROM {TABLE} AS a {INNER} WHERE 1=1 {WHERE}";
public static final String CODE_VALUES = "{VALUES}";
/**
* 加载SQL语句模板
* WHERE条件代码片段
*/
public static final String LOAD_MODEL = "SELECT a.*{FIELD} FROM {TABLE} AS a {INNER} WHERE 1=1 {WHERE}";
public static final String CODE_WHERE = "{WHERE}";
/**
* 更新字段模板
*/
......
package com.yanzuoguang.dao;
import com.yanzuoguang.util.helper.StringHelper;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
......@@ -18,7 +20,7 @@ public @interface TableAnnotation {
*
* @return
*/
String value();
String value() default StringHelper.EMPTY;
/**
* 字段类型
......
......@@ -2,7 +2,6 @@ package com.yanzuoguang.dao.impl;
import com.yanzuoguang.dao.DaoConst;
import com.yanzuoguang.dao.TableAnnotation;
import com.yanzuoguang.util.helper.DateHelper;
import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.base.MethodField;
import com.yanzuoguang.util.base.ObjectHelper;
......@@ -85,7 +84,9 @@ public class TableStruct {
// 注解不为空,则修改后台数据库映射字段、字段类型
if (annotation != null) {
fieldName = annotation.value();
if (!StringHelper.isEmpty(annotation.value())) {
fieldName = annotation.value();
}
fieldAction = annotation.type();
}
......@@ -110,7 +111,9 @@ public class TableStruct {
// 将所有非主键列添加到普通列
commonActionList.add(vo);
boolean isTypeMany = resultActionType == DaoConst.FIELD_REMOVE_UPDATE || resultActionType == DaoConst.FIELD_CREATE;
boolean isTypeMany = resultActionType != DaoConst.FIELD_MD5
&& resultActionType != DaoConst.FIELD_REMOVE
&& resultActionType != DaoConst.FIELD_VERSION;
if (isTypeMany) {
List<TableFieldVo> actionList = this.getFieldActionList(resultActionType);
actionList.add(vo);
......@@ -389,20 +392,20 @@ public class TableStruct {
*/
private SqlData releaseSqlCreate() {
// 生成添加的SQL语句
String text = DaoConst.INSERT_MODEL.replace(DaoConst.TABLE_CODE, this.name);
String text = DaoConst.SQL_INSERT.replace(DaoConst.CODE_TABLE, this.name);
SqlData sql = new SqlData(DaoConst.CREATE, text);
sql.setSqlType(DaoConst.SQL_TYPE_CREATE);
// 第一个增加的字段,不需要增加 ","
String flag = StringHelper.EMPTY;
if (this.getKeyType() == String.class) {
sql.addParaConst(this.getKey().inputName, DaoConst.FIELD_CODE, this.getKey().name,
DaoConst.VALUES_CODE, DaoConst.CODE_PARA
sql.addParaConst(this.getKey().inputName, DaoConst.CODE_FIELD, this.getKey().name,
DaoConst.CODE_VALUES, DaoConst.CODE_PARA
);
flag = DaoConst.CODE_SPLIT;
}
for (TableFieldVo field : this.getFields()) {
sql.addParaConst(field.inputName, DaoConst.FIELD_CODE, flag + field.name,
DaoConst.VALUES_CODE, flag + DaoConst.CODE_PARA
sql.addParaConst(field.inputName, DaoConst.CODE_FIELD, flag + field.name,
DaoConst.CODE_VALUES, flag + DaoConst.CODE_PARA
);
flag = DaoConst.CODE_SPLIT;
}
......@@ -416,12 +419,12 @@ public class TableStruct {
*/
private SqlData releaseSqlUpdate() {
// 生成添加的SQL语句
String text = DaoConst.UPDATE_MODEL.replace(DaoConst.TABLE_CODE, this.name);
String text = DaoConst.SQL_UPDATE.replace(DaoConst.CODE_TABLE, this.name);
SqlData sql = new SqlData(DaoConst.UPDATE, text);
sql.setSqlType(DaoConst.SQL_TYPE_UPDATE);
// 主键字段操作
sql.addCode(DaoConst.FIELD_CODE, String.format(DaoConst.CODE_UPDATE_PRIMARY, this.getKey().name, this.getKey().name));
sql.addCode(DaoConst.CODE_FIELD, String.format(DaoConst.CODE_UPDATE_PRIMARY, this.getKey().name, this.getKey().name));
sql.addConst(this.getKey().inputName, String.format(DaoConst.CODE_WHERE_EQUALS_PARA, this.getKey().name));
// 增加普通代码片段字段
......@@ -429,7 +432,7 @@ public class TableStruct {
DaoConst.FIELD_CREATE, DaoConst.FIELD_REMOVE, DaoConst.FIELD_VERSION);
for (TableFieldVo field : updateList) {
sql.addParaConst(field.inputName,
DaoConst.FIELD_CODE, String.format(DaoConst.CODE_UPDATE_FIELD_PARA, field.name)
DaoConst.CODE_FIELD, String.format(DaoConst.CODE_UPDATE_FIELD_PARA, field.name)
);
}
// 添加删除字段
......@@ -450,17 +453,17 @@ public class TableStruct {
private SqlData releaseSqlRemove() {
if (this.getRemove() != null) {
// 生成添加的SQL语句
String text = DaoConst.UPDATE_MODEL.replace(DaoConst.TABLE_CODE, this.name);
String text = DaoConst.SQL_UPDATE.replace(DaoConst.CODE_TABLE, this.name);
SqlData sql = new SqlData(DaoConst.REMOVE, text);
sql.setSqlType(DaoConst.SQL_TYPE_REMOVE);
// 设置删除字段标记
sql.addCode(DaoConst.FIELD_CODE, String.format(DaoConst.CODE_UPDATE_FIELD_REMOVE, this.getRemove().name));
sql.addCode(DaoConst.CODE_FIELD, String.format(DaoConst.CODE_UPDATE_FIELD_REMOVE, this.getRemove().name));
// 设置删除时需要修改的字段的值
for (TableFieldVo field : this.getFieldActionList(DaoConst.FIELD_REMOVE_UPDATE)) {
sql.addParaConst(field.inputName,
DaoConst.FIELD_CODE, String.format(DaoConst.CODE_UPDATE_FIELD_PARA, field.name)
DaoConst.CODE_FIELD, String.format(DaoConst.CODE_UPDATE_FIELD_PARA, field.name)
);
}
// 增加版本号字段的值
......@@ -469,7 +472,7 @@ public class TableStruct {
addWhereField(sql, DaoConst.CODE_TAG, true);
return sql;
} else {
String text = DaoConst.REMOVE_MODEL.replace(DaoConst.TABLE_CODE, this.name);
String text = DaoConst.SQL_REMOVE.replace(DaoConst.CODE_TABLE, this.name);
SqlData sql = new SqlData(DaoConst.REMOVE, text);
// 生成删除语句Where条件
addWhereField(sql, DaoConst.CODE_TAG, true);
......@@ -484,7 +487,7 @@ public class TableStruct {
*/
private SqlData releaseSqlLoad() {
// 生成添加的SQL语句
String text = DaoConst.LOAD_MODEL.replace(DaoConst.TABLE_CODE, this.name);
String text = DaoConst.SQL_LOAD.replace(DaoConst.CODE_TABLE, this.name);
SqlData sql = new SqlData(DaoConst.LOAD, text);
sql.setSqlType(DaoConst.SQL_TYPE_LOAD);
// 生成加载语句的WHERE条件
......@@ -529,7 +532,7 @@ public class TableStruct {
private void addWhereRemove(SqlData sql) {
if (getRemove() != null) {
sql.addParaConst(DaoConst.REMOVE_FLAG_INPUT,
DaoConst.WHERE_CODE,
DaoConst.CODE_WHERE,
String.format(DaoConst.CODE_WHERE_EQUALS_NOT_REMOVE, this.getRemove().name)
);
}
......@@ -543,7 +546,7 @@ public class TableStruct {
private void addUpdateVersion(SqlData sql) {
// 添加版本字段
if (getVersion() != null) {
sql.addCode(DaoConst.FIELD_CODE, String.format(DaoConst.CODE_UPDATE_VERSION_FIELD, getVersion().name, getVersion().name));
sql.addCode(DaoConst.CODE_FIELD, String.format(DaoConst.CODE_UPDATE_VERSION_FIELD, getVersion().name, getVersion().name));
}
}
......@@ -562,17 +565,17 @@ public class TableStruct {
// 参数字段
List<String> paraFields = new ArrayList<String>();
// 生成修改的SQL语句
SqlData sql = new SqlData(name, model.replace(DaoConst.TABLE_CODE, this.name));
SqlData sql = new SqlData(name, model.replace(DaoConst.CODE_TABLE, this.name));
sql.setSqlType(sqlType);
// 生成添加的SQL语句
String flag = StringHelper.EMPTY;
for (TableFieldVo field : valueFields) {
sql.addParaConst(field.inputName, DaoConst.FIELD_CODE, flag + valueModel.replace(DaoConst.FIELD_CODE, field.name));
sql.addParaConst(field.inputName, DaoConst.CODE_FIELD, flag + valueModel.replace(DaoConst.CODE_FIELD, field.name));
flag = DaoConst.CODE_SPLIT;
}
for (TableFieldVo field : whereFields) {
sql.addParaConst(field.inputName, DaoConst.WHERE_CODE, String.format(DaoConst.CODE_WHERE_EQUALS_PARA, field.name));
sql.addParaConst(field.inputName, DaoConst.CODE_WHERE, String.format(DaoConst.CODE_WHERE_EQUALS_PARA, field.name));
}
return sql;
......@@ -611,7 +614,7 @@ public class TableStruct {
* @param whereFields WHERE条件
*/
private void addSaveWithSql(TableSqlCache tableStruct, String sqlName, List<TableFieldVo> whereFields) {
SqlData sqlData = this.releaseSql(DaoConst.SQL_TYPE_SAVE_WITH, sqlName, DaoConst.LOAD_MODEL, StringHelper.EMPTY, new ArrayList<>(), whereFields);
SqlData sqlData = this.releaseSql(DaoConst.SQL_TYPE_SAVE_WITH, sqlName, DaoConst.SQL_LOAD, StringHelper.EMPTY, new ArrayList<>(), whereFields);
tableStruct.add(sqlData);
}
......@@ -634,9 +637,9 @@ public class TableStruct {
* @param updateFields 需要增加的值的字段
*/
private void addGroupSql(TableSqlCache sqlTableData, List<TableFieldVo> whereFields, List<TableFieldVo> updateFields) {
sqlTableData.add(this.releaseSql(DaoConst.SQL_TYPE_ADD_GROUP, DaoConst.GROUP_QUERY, DaoConst.LOAD_MODEL,
sqlTableData.add(this.releaseSql(DaoConst.SQL_TYPE_ADD_GROUP, DaoConst.GROUP_QUERY, DaoConst.SQL_LOAD,
StringHelper.EMPTY, new ArrayList<>(), whereFields));
sqlTableData.add(this.releaseSql(DaoConst.SQL_TYPE_ADD_GROUP, DaoConst.GROUP_ADD, DaoConst.UPDATE_MODEL,
sqlTableData.add(this.releaseSql(DaoConst.SQL_TYPE_ADD_GROUP, DaoConst.GROUP_ADD, DaoConst.SQL_UPDATE,
DaoConst.CODE_GROUP_ADD, updateFields, this.getFieldActionList(DaoConst.FIELD_PRIMARY)));
}
......@@ -648,7 +651,7 @@ public class TableStruct {
* @param fields 需要判断的字段
*/
public void addExist(TableSqlCache sqlTableData, String sqlName, String[] fields) {
String text = DaoConst.LOAD_MODEL.replace(DaoConst.TABLE_CODE, this.name);
String text = DaoConst.SQL_LOAD.replace(DaoConst.CODE_TABLE, this.name);
SqlData sql = new SqlData(sqlName, text);
sql.setSqlType(DaoConst.SQL_TYPE_SAVE_WITH);
sql.addConst(this.getKey().inputName,
......
......@@ -84,7 +84,7 @@ public class AllBeanRowMapper<T> implements RowMapper<T> {
} else if (field.getGetMethod() != null) {
annotation = field.getGetMethod().getAnnotation(TableAnnotation.class);
}
if (annotation != null) {
if (annotation != null && !StringHelper.isEmpty(annotation.value())) {
name = annotation.value();
}
String underscoredName = underscoreName(name);
......
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