Commit 1dd16657 authored by yanzg's avatar yanzg

常规BUG的修改

parent 625b923d
......@@ -53,6 +53,11 @@ public class DaoConst {
*/
public static final String GROUP_QUERY = "GroupQuery";
/**
* 根据某个字段保存
*/
public static final String SAVE_WITH = "SaveWith";
/**
* 驼峰式命名
*/
......@@ -157,7 +162,7 @@ public class DaoConst {
/**
* 统计语句增加字段模板
*/
public static final String CODE_GROUP_ADD = "{FIELD}={FIELD}+?";
public static final String CODE_GROUP_ADD = "a.{FIELD}=a.{FIELD}+?";
/**
* 版本号字段名称
*/
......@@ -227,6 +232,14 @@ public class DaoConst {
* 删除时记录操作状态的字段
*/
public static final int FIELD_CREATE = 6;
/**
* 根据字段保存
*/
public static final int FIELD_SAVE_WITH = 7;
/**
* 根据字段添加统计
*/
public static final int FIELD_ADD_GROUP = 8;
/**
* SQL语句类型-普通语句
......@@ -253,6 +266,14 @@ public class DaoConst {
/**
* SQL语句类型-是否存在
*/
public static final int SQL_TYPE_EXINTS = 5;
public static final int SQL_TYPE_EXISTS = 5;
/**
* SQL语句类型-根据字段保存
*/
public static final int SQL_TYPE_SAVE_WITH = 6;
/**
* SQL语句类型-添加统计
*/
public static final int SQL_TYPE_ADD_GROUP = 7;
}
......@@ -2,7 +2,6 @@ package com.yanzuoguang.dao.impl;
import com.yanzuoguang.dao.BaseDao;
import com.yanzuoguang.dao.DaoConst;
import com.yanzuoguang.db.impl.AllBeanRowMapper;
import com.yanzuoguang.util.base.ObjectHelper;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.DateHelper;
......@@ -169,7 +168,7 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
to.init();
}
if (operatorType == DaoConst.OPERATOR_TYPE_CREATE || operatorType == DaoConst.OPERATOR_TYPE_UPDATE) {
List<SqlData> sqlArray = this.table.getSqlType(DaoConst.SQL_TYPE_EXINTS);
List<SqlData> sqlArray = this.table.getSqlType(DaoConst.SQL_TYPE_SAVE_WITH);
if (sqlArray != null) {
for (SqlData sql : sqlArray) {
this.checkExist(sql.getName(), model, String.format("%s已经存在", sql.getName()));
......
......@@ -2,11 +2,11 @@ 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;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
......@@ -353,6 +353,33 @@ public class TableStruct {
if (!StringHelper.isEmpty(this.name)) {
table.add(releaseSqlCreate(), releaseSqlUpdate(), releaseSqlRemove(), releaseSqlLoad());
}
initSaveWith(table);
initAddGroup(table);
}
/**
* 初始化SaveWith
*/
private void initSaveWith(TableSqlCache table) {
List<TableFieldVo> saveWithField = getFieldActionList(DaoConst.FIELD_SAVE_WITH);
if (saveWithField == null || saveWithField.isEmpty()) {
return;
}
this.addSaveWithSql(table, DaoConst.SAVE_WITH, saveWithField);
}
/**
* 初始化添加统计SQL语句
*/
private void initAddGroup(TableSqlCache table) {
List<TableFieldVo> addGroupField = getFieldActionList(DaoConst.FIELD_ADD_GROUP);
if (addGroupField == null || addGroupField.isEmpty()) {
return;
}
List<TableFieldVo> commonField = getFieldActionList(DaoConst.FIELD_COMMON,
DaoConst.FIELD_ADD_GROUP, DaoConst.FIELD_MD5,
DaoConst.FIELD_REMOVE, DaoConst.FIELD_REMOVE_UPDATE, DaoConst.FIELD_CREATE);
this.addGroupSql(table, commonField, addGroupField);
}
/**
......@@ -520,35 +547,10 @@ public class TableStruct {
}
}
/**
* 生成统计的SQL语句
*
* @param sqlTableData 需要生成的实体
* @param whereFields WHERE字段
* @param updateFields 需要增加的值的字段
*/
public void addGroupSql(TableSqlCache sqlTableData, TableFieldString whereFields, TableFieldString updateFields) {
sqlTableData.add(this.releaseSqlWhere(DaoConst.GROUP_QUERY, DaoConst.LOAD_MODEL, whereFields));
sqlTableData.add(this.releaseSql(DaoConst.GROUP_ADD, DaoConst.UPDATE_MODEL,
DaoConst.CODE_GROUP_ADD, updateFields,
new TableFieldString(this.getKey().name)));
}
/**
* 生成SQL语句
*
* @param name
* @param model
* @param whereFields
* @return
*/
public SqlData releaseSqlWhere(String name, String model, TableFieldString whereFields) {
return this.releaseSql(name, model, StringHelper.EMPTY, new TableFieldString(), whereFields);
}
/**
* 生成SQL语句
*
* @param sqlType SQL语句类型
* @param name SQL语句名称
* @param model SQL语句模板
* @param valueModel 值字段模板
......@@ -556,60 +558,99 @@ public class TableStruct {
* @param whereFields WHERE字段
* @return
*/
public SqlData releaseSql(String name, String model, String valueModel, TableFieldString valueFields, TableFieldString whereFields) {
private SqlData releaseSql(int sqlType, String name, String model, String valueModel, List<TableFieldVo> valueFields, List<TableFieldVo> whereFields) {
// 参数字段
List<String> paraFields = new ArrayList<String>();
// 生成修改的SQL语句
SqlData sql = new SqlData(name, model.replace(DaoConst.TABLE_CODE, this.name));
sql.setSqlType(sqlType);
// 生成添加的SQL语句
StringBuilder sbField = new StringBuilder();
for (String field : valueFields.getFields()) {
if (sbField.length() > 0) {
sbField.append(",");
String flag = StringHelper.EMPTY;
for (TableFieldVo field : valueFields) {
sql.addParaConst(field.inputName, DaoConst.FIELD_CODE, flag + valueModel.replace(DaoConst.FIELD_CODE, field.name));
flag = DaoConst.CODE_SPLIT;
}
sbField.append(valueModel.replace(DaoConst.FIELD_CODE, field));
paraFields.add(field);
for (TableFieldVo field : whereFields) {
sql.addParaConst(field.inputName, DaoConst.WHERE_CODE, String.format(DaoConst.CODE_WHERE_EQUALS_PARA, field.name));
}
StringBuilder sbWhere = new StringBuilder();
for (String field : whereFields.getFields()) {
sbWhere.append(" AND ");
sbWhere.append(field);
sbWhere.append("=?");
paraFields.add(field);
return sql;
}
String[] fields = new String[paraFields.size()];
fields = paraFields.toArray(fields);
// 生成修改的SQL语句
String sql = model.replace(DaoConst.TABLE_CODE, this.name)
.replace(DaoConst.FIELD_CODE, sbField.toString())
.replace(DaoConst.WHERE_CODE, sbWhere.toString());
SqlData ret = new SqlData(name, sql, fields);
return ret;
/**
* 根据来源字符串获取结束字符串
*
* @param fieldFrom 来源字符串
* @return 返回字符串
*/
private List<TableFieldVo> getFieldString(TableFieldString fieldFrom) {
List<TableFieldVo> list = new ArrayList<>();
for (String fieldName : fieldFrom.getFields()) {
list.add(this.getField(fieldName));
}
return list;
}
/**
* 生成根据某些字段不存在则保存的SQL语句
*
* @param tableStruct
* @param sqlName
* @param whereFields
* @param tableStruct 表结构
* @param sqlName SQL语句
* @param whereFields WHERE条件
*/
public void addSaveWithSql(TableSqlCache tableStruct, String sqlName, TableFieldString whereFields) {
tableStruct.add(this.releaseSqlWhere(sqlName, DaoConst.LOAD_MODEL, whereFields));
addSaveWithSql(tableStruct, sqlName, getFieldString(whereFields));
}
/**
* 生成根据某些字段不存在则保存的SQL语句
*
* @param tableStruct 表结构
* @param sqlName SQL语句
* @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);
tableStruct.add(sqlData);
}
/**
* 生成统计的SQL语句
*
* @param sqlTableData 需要生成的实体
* @param whereFields WHERE字段
* @param updateFields 需要增加的值的字段
*/
public void addGroupSql(TableSqlCache sqlTableData, TableFieldString whereFields, TableFieldString updateFields) {
addGroupSql(sqlTableData, getFieldString(whereFields), getFieldString(updateFields));
}
/**
* 生成统计的SQL语句
*
* @param sqlTableData 需要生成的实体
* @param whereFields WHERE字段
* @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,
StringHelper.EMPTY, new ArrayList<>(), whereFields));
sqlTableData.add(this.releaseSql(DaoConst.SQL_TYPE_ADD_GROUP, DaoConst.GROUP_ADD, DaoConst.UPDATE_MODEL,
DaoConst.CODE_GROUP_ADD, updateFields, this.getFieldActionList(DaoConst.FIELD_PRIMARY)));
}
/**
* 生成判断数据是否存在的SQL语句
*
* @param sqlTableData
* @param sqlName
* @param fields
* @param sqlTableData 表结构
* @param sqlName SQL语句的名称
* @param fields 需要判断的字段
*/
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.setSqlType(DaoConst.SQL_TYPE_SAVE_WITH);
sql.addConst(this.getKey().inputName,
String.format(DaoConst.CODE_WHERE_NOT_EQUALS_PARA, this.getKey().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