Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
24d4ff91
Commit
24d4ff91
authored
Aug 18, 2023
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
表结构修改表结构修改
parent
c5c9feb3
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
136 additions
and
157 deletions
+136
-157
DaoConst.java
yzg-util-db/src/main/java/com/yanzuoguang/dao/DaoConst.java
+3
-3
QueryPara.java
yzg-util-db/src/main/java/com/yanzuoguang/dao/QueryPara.java
+3
-26
BaseDaoImpl.java
...b/src/main/java/com/yanzuoguang/dao/impl/BaseDaoImpl.java
+2
-4
BaseDaoSql.java
...db/src/main/java/com/yanzuoguang/dao/impl/BaseDaoSql.java
+1
-10
TableStruct.java
...b/src/main/java/com/yanzuoguang/dao/impl/TableStruct.java
+127
-114
No files found.
yzg-util-db/src/main/java/com/yanzuoguang/dao/DaoConst.java
View file @
24d4ff91
...
...
@@ -141,7 +141,7 @@ public class DaoConst {
/**
* 更新字段模板参数
*/
public
static
final
String
CODE_UPDATE_FIELD_REMOVE
=
"a.%s=
1
"
;
public
static
final
String
CODE_UPDATE_FIELD_REMOVE
=
"a.%s=
IFNULL(?,1)
"
;
/**
* 等于条件
*/
...
...
@@ -173,7 +173,7 @@ public class DaoConst {
/**
* 未删除条件
*/
public
static
final
String
CODE_WHERE_EQUALS_NOT_REMOVE
=
"AND a.%s=
0
"
;
public
static
final
String
CODE_WHERE_EQUALS_NOT_REMOVE
=
"AND a.%s=
IFNULL(?,0)
"
;
/**
* 版本好字段
*/
...
...
@@ -225,7 +225,7 @@ public class DaoConst {
/**
* 删除字符串长度变量
*/
public
static
final
String
REMOVE_FLAG_INPUT
=
"remove_input
"
;
public
static
final
String
OLD_FLAG
=
"Old
"
;
/**
* ID字段
*/
...
...
yzg-util-db/src/main/java/com/yanzuoguang/dao/QueryPara.java
View file @
24d4ff91
...
...
@@ -6,37 +6,22 @@ import io.swagger.annotations.ApiModelProperty;
/**
* 查询参数
*
* @author
颜佐光
* @author
颜佐光
*/
@ApiModel
(
description
=
"查询参数"
)
public
class
QueryPara
{
/**
* 查询删除
*/
public
static
QueryPara
LOAD_REMOVE
=
new
QueryPara
(
false
,
true
);
/**
* 所有条件生效
*/
public
static
QueryPara
FULL_COND
=
new
QueryPara
(
true
,
false
);
public
static
QueryPara
FULL_COND
=
new
QueryPara
(
true
);
/**
* 所有条件生效
*/
@ApiModelProperty
(
notes
=
"所有条件生效,而不仅仅在主键存在时,通过主键加载"
)
private
boolean
fullCond
;
/**
* 查询删除标记的结果
*/
@ApiModelProperty
(
notes
=
"在数据通过删除标记删除时,可以通过该参数查询出来"
)
private
boolean
loadRemove
;
public
QueryPara
(
boolean
fullCond
,
boolean
loadRemove
)
{
public
QueryPara
(
boolean
fullCond
)
{
this
.
fullCond
=
fullCond
;
this
.
loadRemove
=
loadRemove
;
}
public
boolean
isFullCond
()
{
...
...
@@ -46,12 +31,4 @@ public class QueryPara {
public
void
setFullCond
(
boolean
fullCond
)
{
this
.
fullCond
=
fullCond
;
}
public
boolean
isLoadRemove
()
{
return
loadRemove
;
}
public
void
setLoadRemove
(
boolean
loadRemove
)
{
this
.
loadRemove
=
loadRemove
;
}
}
yzg-util-db/src/main/java/com/yanzuoguang/dao/impl/BaseDaoImpl.java
View file @
24d4ff91
...
...
@@ -61,8 +61,7 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
// 最终处理
this
.
created
(
model
);
// 返回执行结果
String
retVal
=
ret
>
0
?
keyString
:
""
;
return
retVal
;
return
ret
>
0
?
keyString
:
""
;
}
protected
List
<
String
>
createReplaceList
(
String
sqlName
,
Collection
collection
)
{
...
...
@@ -403,8 +402,7 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
return
model
;
}
// 获取来源主键
Object
from
=
this
.
table
.
getKeyObject
(
model
);
return
from
;
return
this
.
table
.
getKeyObject
(
model
);
}
private
<
T
>
void
checkLoadResult
(
T
toItem
,
List
<
T
>
tos
)
{
...
...
yzg-util-db/src/main/java/com/yanzuoguang/dao/impl/BaseDaoSql.java
View file @
24d4ff91
...
...
@@ -213,16 +213,7 @@ public abstract class BaseDaoSql {
* @param copy 是否复制
*/
protected
SqlData
getSqlQueryPara
(
SqlData
sqlData
,
QueryPara
queryPara
,
boolean
copy
)
{
SqlData
copyTo
=
sqlData
;
if
(
queryPara
!=
null
&&
queryPara
.
isLoadRemove
())
{
if
(
copyTo
.
getField
(
DaoConst
.
REMOVE_FLAG_INPUT
)
!=
null
)
{
if
(
copy
)
{
copyTo
=
sqlData
.
copy
();
}
copyTo
.
removeField
(
DaoConst
.
REMOVE_FLAG_INPUT
);
}
}
return
copyTo
;
return
sqlData
;
}
/**
...
...
yzg-util-db/src/main/java/com/yanzuoguang/dao/impl/TableStruct.java
View file @
24d4ff91
package
com
.
yanzuoguang
.
dao
.
impl
;
import
com.yanzuoguang.dao.DaoConst
;
import
com.yanzuoguang.dao.TableAnnotation
;
import
com.yanzuoguang.dao.cond.SqlCondDefault
;
import
com.yanzuoguang.util.base.MethodField
;
...
...
@@ -13,6 +12,8 @@ import java.util.HashMap;
import
java.util.List
;
import
java.util.Map
;
import
static
com
.
yanzuoguang
.
dao
.
DaoConst
.*;
/**
* 表结构的基本信息
*
...
...
@@ -75,7 +76,7 @@ public class TableStruct {
*/
private
void
addMethodField
(
MethodField
field
)
{
int
fieldAction
=
DaoConst
.
FIELD_NONE
;
int
fieldAction
=
FIELD_NONE
;
// 默认后台数据库字段和前台参数字段为字段名,字段类型为class
String
fieldName
=
field
.
getName
();
...
...
@@ -117,10 +118,10 @@ public class TableStruct {
int
resultActionType
=
getActionType
(
fieldAction
,
stringAction
);
// 获取普通类型字段列表
List
<
TableFieldVo
>
commonActionList
=
this
.
getFieldActionList
(
DaoConst
.
FIELD_COMMON
);
if
(
resultActionType
==
DaoConst
.
FIELD_PRIMARY
)
{
List
<
TableFieldVo
>
commonActionList
=
this
.
getFieldActionList
(
FIELD_COMMON
);
if
(
resultActionType
==
FIELD_PRIMARY
)
{
// 将历史主键添加到普通列,并且移除历史主键
List
<
TableFieldVo
>
primaryActionList
=
this
.
getFieldActionList
(
DaoConst
.
FIELD_PRIMARY
);
List
<
TableFieldVo
>
primaryActionList
=
this
.
getFieldActionList
(
FIELD_PRIMARY
);
commonActionList
.
addAll
(
primaryActionList
);
primaryActionList
.
clear
();
// 将现有列添加到主键
...
...
@@ -129,12 +130,12 @@ public class TableStruct {
// 将所有非主键列添加到普通列
commonActionList
.
add
(
vo
);
boolean
isTypeMany
=
resultActionType
!=
DaoConst
.
FIELD_MD5
&&
resultActionType
!=
DaoConst
.
FIELD_REMOVE
&&
resultActionType
!=
DaoConst
.
FIELD_VERSION
&&
resultActionType
!=
DaoConst
.
FIELD_COMMON
;
boolean
isTypeMany
=
resultActionType
!=
FIELD_MD5
&&
resultActionType
!=
FIELD_REMOVE
&&
resultActionType
!=
FIELD_VERSION
&&
resultActionType
!=
FIELD_COMMON
;
if
(
resultActionType
!=
DaoConst
.
FIELD_COMMON
)
{
if
(
resultActionType
!=
FIELD_COMMON
)
{
List
<
TableFieldVo
>
actionList
=
this
.
getFieldActionList
(
resultActionType
);
// 处理其他特殊列
if
(
isTypeMany
)
{
...
...
@@ -161,7 +162,7 @@ public class TableStruct {
* @return 最终类型
*/
private
int
getActionType
(
int
fieldAction
,
int
stringAction
)
{
if
(
fieldAction
!=
DaoConst
.
FIELD_NONE
)
{
if
(
fieldAction
!=
FIELD_NONE
)
{
return
fieldAction
;
}
else
{
return
stringAction
;
...
...
@@ -176,21 +177,21 @@ public class TableStruct {
*/
private
int
getStringAction
(
TableFieldVo
vo
)
{
if
(
getKey
()
==
null
)
{
return
DaoConst
.
FIELD_PRIMARY
;
}
else
if
(
DaoConst
.
REMOVE_FLAG
.
equals
(
vo
.
inputLName
))
{
return
DaoConst
.
FIELD_REMOVE
;
}
else
if
(
DaoConst
.
VERSION_FLAG
.
equals
(
vo
.
inputLName
))
{
return
DaoConst
.
FIELD_VERSION
;
return
FIELD_PRIMARY
;
}
else
if
(
REMOVE_FLAG
.
equals
(
vo
.
inputLName
))
{
return
FIELD_REMOVE
;
}
else
if
(
VERSION_FLAG
.
equals
(
vo
.
inputLName
))
{
return
FIELD_VERSION
;
}
// 判断是否属于统计字段
else
if
(
DaoConst
.
MD5_KEY_FLAG
.
equals
(
vo
.
inputLName
))
{
return
DaoConst
.
FIELD_MD5
;
}
else
if
(
vo
.
inputLName
.
startsWith
(
DaoConst
.
UPDATE_FLAG
))
{
return
DaoConst
.
FIELD_REMOVE_UPDATE
;
}
else
if
(
vo
.
inputLName
.
startsWith
(
DaoConst
.
CREATE_FLAG
))
{
return
DaoConst
.
FIELD_CREATE
;
else
if
(
MD5_KEY_FLAG
.
equals
(
vo
.
inputLName
))
{
return
FIELD_MD5
;
}
else
if
(
vo
.
inputLName
.
startsWith
(
UPDATE_FLAG
))
{
return
FIELD_REMOVE_UPDATE
;
}
else
if
(
vo
.
inputLName
.
startsWith
(
CREATE_FLAG
))
{
return
FIELD_CREATE
;
}
else
{
return
DaoConst
.
FIELD_COMMON
;
return
FIELD_COMMON
;
}
}
...
...
@@ -250,7 +251,7 @@ public class TableStruct {
* @return 所有的普通股字段
*/
public
List
<
TableFieldVo
>
getFields
()
{
return
getFieldActionList
(
DaoConst
.
FIELD_COMMON
);
return
getFieldActionList
(
FIELD_COMMON
);
}
/**
...
...
@@ -259,10 +260,10 @@ public class TableStruct {
* @return 获取统计纬度列
*/
public
List
<
TableFieldVo
>
getGroupLatitudeFields
()
{
return
getFieldActionList
(
DaoConst
.
FIELD_COMMON
,
DaoConst
.
FIELD_ADD_GROUP
,
DaoConst
.
FIELD_REPLACE_GROUP
,
DaoConst
.
FIELD_MD5
return
getFieldActionList
(
FIELD_COMMON
,
FIELD_ADD_GROUP
,
FIELD_REPLACE_GROUP
,
FIELD_MD5
);
}
...
...
@@ -290,7 +291,7 @@ public class TableStruct {
* @return 获取到的键值
*/
public
TableFieldVo
getKey
()
{
return
getFieldAction
(
DaoConst
.
FIELD_PRIMARY
);
return
getFieldAction
(
FIELD_PRIMARY
);
}
/**
...
...
@@ -317,7 +318,7 @@ public class TableStruct {
* @return md5字段
*/
public
TableFieldVo
getMd5Key
()
{
return
getFieldAction
(
DaoConst
.
FIELD_MD5
);
return
getFieldAction
(
FIELD_MD5
);
}
/**
...
...
@@ -336,7 +337,7 @@ public class TableStruct {
* @return 版本号字段
*/
public
TableFieldVo
getVersion
()
{
return
getFieldAction
(
DaoConst
.
FIELD_VERSION
);
return
getFieldAction
(
FIELD_VERSION
);
}
/**
...
...
@@ -345,17 +346,17 @@ public class TableStruct {
* @return 删除字段
*/
public
TableFieldVo
getRemove
()
{
return
getFieldAction
(
DaoConst
.
FIELD_REMOVE
);
return
getFieldAction
(
FIELD_REMOVE
);
}
/**
* 获取删除时更新
子弹
* 获取删除时更新
字段
*
* @return 删除时更新字段
*/
public
List
<
TableFieldVo
>
getRemoveUpdate
()
{
return
getFieldActionList
(
DaoConst
.
FIELD_REMOVE_UPDATE
);
return
getFieldActionList
(
FIELD_REMOVE_UPDATE
);
}
/**
...
...
@@ -413,11 +414,11 @@ public class TableStruct {
* @return 初始化的表SQL语句
*/
private
void
initSaveWith
(
TableSqlCache
table
)
{
List
<
TableFieldVo
>
saveWithField
=
getFieldActionList
(
DaoConst
.
FIELD_SAVE_WITH
);
List
<
TableFieldVo
>
saveWithField
=
getFieldActionList
(
FIELD_SAVE_WITH
);
if
(
saveWithField
==
null
||
saveWithField
.
isEmpty
())
{
return
;
}
this
.
addSaveWithSql
(
table
,
DaoConst
.
SAVE_WITH
,
saveWithField
);
this
.
addSaveWithSql
(
table
,
SAVE_WITH
,
saveWithField
);
}
/**
...
...
@@ -426,8 +427,8 @@ public class TableStruct {
* @return 初始化的表SQL语句
*/
private
void
initAddGroup
(
TableSqlCache
table
)
{
List
<
TableFieldVo
>
addGroupField
=
getFieldActionList
(
DaoConst
.
FIELD_ADD_GROUP
);
List
<
TableFieldVo
>
replaceGroupField
=
getFieldActionList
(
DaoConst
.
FIELD_REPLACE_GROUP
);
List
<
TableFieldVo
>
addGroupField
=
getFieldActionList
(
FIELD_ADD_GROUP
);
List
<
TableFieldVo
>
replaceGroupField
=
getFieldActionList
(
FIELD_REPLACE_GROUP
);
List
<
TableFieldVo
>
commonField
=
this
.
getGroupLatitudeFields
();
this
.
addGroupSql
(
table
,
commonField
,
replaceGroupField
,
addGroupField
);
}
...
...
@@ -438,7 +439,7 @@ public class TableStruct {
* @return 生成的语句
*/
private
SqlData
releaseSqlReplace
()
{
return
releaseSqlCreateReplace
(
DaoConst
.
SQL_REPLACE
,
DaoConst
.
REPLACE
,
DaoConst
.
SQL_TYPE_CREATE
);
return
releaseSqlCreateReplace
(
SQL_REPLACE
,
REPLACE
,
SQL_TYPE_CREATE
);
}
/**
...
...
@@ -447,27 +448,29 @@ public class TableStruct {
* @return 生成的语句
*/
private
SqlData
releaseSqlCreate
()
{
return
releaseSqlCreateReplace
(
DaoConst
.
SQL_INSERT
,
DaoConst
.
CREATE
,
DaoConst
.
SQL_TYPE_CREATE
);
return
releaseSqlCreateReplace
(
SQL_INSERT
,
CREATE
,
SQL_TYPE_CREATE
);
}
private
SqlData
releaseSqlCreateReplace
(
String
sqlModel
,
String
sqlName
,
int
sqlType
)
{
// 生成添加的SQL语句
String
text
=
sqlModel
.
replace
(
DaoConst
.
CODE_TABLE
,
this
.
name
);
String
text
=
sqlModel
.
replace
(
CODE_TABLE
,
this
.
name
);
SqlData
sql
=
new
SqlData
(
sqlName
,
text
);
sql
.
setSqlType
(
sqlType
);
TableFieldVo
key
=
this
.
getKey
();
// 第一个增加的字段,不需要增加 ","
String
flag
=
StringHelper
.
EMPTY
;
if
(
this
.
getKeyType
()
==
String
.
class
)
{
sql
.
addParaConst
(
this
.
getKey
().
inputName
,
DaoConst
.
CODE_FIELD
,
this
.
getKey
()
.
name
,
DaoConst
.
CODE_VALUES
,
DaoConst
.
CODE_PARA
sql
.
addParaConst
(
key
.
inputName
,
CODE_FIELD
,
key
.
name
,
CODE_VALUES
,
CODE_PARA
);
flag
=
DaoConst
.
CODE_SPLIT
;
flag
=
CODE_SPLIT
;
}
for
(
TableFieldVo
field
:
this
.
getFields
())
{
sql
.
addParaConst
(
field
.
inputName
,
DaoConst
.
CODE_FIELD
,
flag
+
field
.
name
,
DaoConst
.
CODE_VALUES
,
flag
+
DaoConst
.
CODE_PARA
sql
.
addParaConst
(
field
.
inputName
,
CODE_FIELD
,
flag
+
field
.
name
,
CODE_VALUES
,
flag
+
CODE_PARA
);
flag
=
DaoConst
.
CODE_SPLIT
;
flag
=
CODE_SPLIT
;
}
return
sql
;
}
...
...
@@ -478,36 +481,32 @@ public class TableStruct {
* @return 生成的语句
*/
private
SqlData
releaseSqlUpdate
()
{
TableFieldVo
remove
=
this
.
getRemove
();
// 生成添加的SQL语句
String
text
=
DaoConst
.
SQL_UPDATE
.
replace
(
DaoConst
.
CODE_TABLE
,
this
.
name
);
SqlData
sql
=
new
SqlData
(
DaoConst
.
UPDATE
,
text
);
sql
.
setSqlType
(
DaoConst
.
SQL_TYPE_UPDATE
);
String
text
=
SQL_UPDATE
.
replace
(
CODE_TABLE
,
this
.
name
);
SqlData
sql
=
new
SqlData
(
UPDATE
,
text
);
sql
.
setSqlType
(
SQL_TYPE_UPDATE
);
TableFieldVo
key
=
this
.
getKey
();
// 主键字段操作
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
));
sql
.
addCode
(
CODE_FIELD
,
String
.
format
(
CODE_UPDATE_PRIMARY
,
key
.
name
,
key
.
name
));
sql
.
addConst
(
key
.
inputName
,
String
.
format
(
CODE_WHERE_EQUALS_PARA
,
key
.
name
));
// 增加普通代码片段字段
List
<
TableFieldVo
>
updateList
=
getFieldActionList
(
DaoConst
.
FIELD_COMMON
,
DaoConst
.
FIELD_CREATE
,
DaoConst
.
FIELD_REMOVE
,
DaoConst
.
FIELD_VERSION
);
List
<
TableFieldVo
>
updateList
=
getFieldActionList
(
FIELD_COMMON
,
FIELD_CREATE
,
FIELD_REMOVE
,
FIELD_VERSION
);
for
(
TableFieldVo
field
:
updateList
)
{
sql
.
addParaConst
(
field
.
inputName
,
DaoConst
.
CODE_FIELD
,
String
.
format
(
DaoConst
.
CODE_UPDATE_FIELD_PARA
,
field
.
name
)
CODE_FIELD
,
String
.
format
(
CODE_UPDATE_FIELD_PARA
,
field
.
name
)
);
}
// 设置删除标记可以通过前台传入
if
(
remove
!=
null
)
{
sql
.
addParaConst
(
remove
.
inputName
,
DaoConst
.
CODE_FIELD
,
String
.
format
(
DaoConst
.
CODE_UPDATE_FIELD_PARA
,
remove
.
name
));
}
// 添加删除字段
// addWhereRemove(sql);
addUpdateVersion
(
sql
);
addUpdateRemoveField
(
sql
);
addUpdateVersionField
(
sql
);
// 添加版本号条件
if
(
getVersion
()
!=
null
)
{
sql
.
addConst
(
getVersion
().
inputName
,
String
.
format
(
DaoConst
.
CODE_WHERE_EQUALS_PARA
,
getVersion
().
name
));
sql
.
addConst
(
getVersion
().
inputName
,
String
.
format
(
CODE_WHERE_EQUALS_PARA
,
getVersion
().
name
));
}
return
sql
;
}
...
...
@@ -521,41 +520,39 @@ public class TableStruct {
TableFieldVo
remove
=
this
.
getRemove
();
if
(
remove
!=
null
)
{
// 生成添加的SQL语句
String
text
=
DaoConst
.
SQL_UPDATE
.
replace
(
DaoConst
.
CODE_TABLE
,
this
.
name
);
SqlData
sql
=
new
SqlData
(
DaoConst
.
REMOVE
,
text
);
sql
.
setSqlType
(
DaoConst
.
SQL_TYPE_REMOVE
);
String
text
=
SQL_UPDATE
.
replace
(
CODE_TABLE
,
this
.
name
);
SqlData
sql
=
new
SqlData
(
REMOVE
,
text
);
sql
.
setSqlType
(
SQL_TYPE_REMOVE
);
// 设置删除字段标记
sql
.
addCode
(
DaoConst
.
CODE_FIELD
,
String
.
format
(
DaoConst
.
CODE_UPDATE_FIELD_REMOVE
,
remove
.
name
));
addUpdateRemoveField
(
sql
);
// 增加版本号字段的值
addUpdateVersionField
(
sql
);
// 设置删除时需要修改的字段的值
for
(
TableFieldVo
field
:
this
.
getFieldActionList
(
DaoConst
.
FIELD_REMOVE_UPDATE
))
{
for
(
TableFieldVo
field
:
this
.
getFieldActionList
(
FIELD_REMOVE_UPDATE
))
{
sql
.
addParaConst
(
field
.
inputName
,
DaoConst
.
CODE_FIELD
,
String
.
format
(
DaoConst
.
CODE_UPDATE_FIELD_PARA
,
field
.
name
)
CODE_FIELD
,
String
.
format
(
CODE_UPDATE_FIELD_PARA
,
field
.
name
)
);
}
// 增加版本号字段的值
addUpdateVersion
(
sql
);
// 生成逻辑删除WHERE条件
addWhereField
(
sql
,
DaoConst
.
CODE_TAG
,
true
);
addWhereField
(
sql
,
CODE_TAG
,
true
);
return
sql
;
}
else
{
String
text
=
DaoConst
.
SQL_REMOVE
.
replace
(
DaoConst
.
CODE_TABLE
,
this
.
name
);
SqlData
sql
=
new
SqlData
(
DaoConst
.
REMOVE
,
text
);
String
text
=
SQL_REMOVE
.
replace
(
CODE_TABLE
,
this
.
name
);
SqlData
sql
=
new
SqlData
(
REMOVE
,
text
);
// 生成删除语句Where条件
addWhereField
(
sql
,
DaoConst
.
CODE_TAG
,
true
);
addWhereField
(
sql
,
CODE_TAG
,
true
);
return
sql
;
}
}
private
SqlData
releaseSqlQuery
(
String
sqlName
,
int
sqlType
)
{
// 生成添加的SQL语句
String
text
=
DaoConst
.
SQL_LOAD
.
replace
(
DaoConst
.
CODE_TABLE
,
this
.
name
);
String
text
=
SQL_LOAD
.
replace
(
CODE_TABLE
,
this
.
name
);
SqlData
sql
=
new
SqlData
(
sqlName
,
text
);
sql
.
addParaConst
(
DaoConst
.
CODE_FIELD_DEFAULT_NAME
,
DaoConst
.
CODE_FIELD
,
DaoConst
.
CODE_FIELD_DEFAULT
);
sql
.
addParaConst
(
CODE_FIELD_DEFAULT_NAME
,
CODE_FIELD
,
CODE_FIELD_DEFAULT
);
sql
.
setSqlType
(
sqlType
);
// 生成加载语句的WHERE条件
addWhereField
(
sql
,
DaoConst
.
CODE_TAG
,
false
);
addWhereField
(
sql
,
CODE_TAG
,
false
);
return
sql
;
}
...
...
@@ -566,7 +563,7 @@ public class TableStruct {
* @return 生成的语句
*/
private
SqlData
releaseSqlLoad
()
{
return
releaseSqlQuery
(
DaoConst
.
LOAD
,
DaoConst
.
SQL_TYPE_LOAD
);
return
releaseSqlQuery
(
LOAD
,
SQL_TYPE_LOAD
);
}
/**
...
...
@@ -575,7 +572,7 @@ public class TableStruct {
* @return
*/
private
SqlData
releaseSqlQuery
()
{
return
releaseSqlQuery
(
DaoConst
.
QUERY
,
DaoConst
.
SQL_TYPE_COMMON
);
return
releaseSqlQuery
(
QUERY
,
SQL_TYPE_COMMON
);
}
/**
...
...
@@ -587,7 +584,7 @@ public class TableStruct {
* @return 生成的语句
*/
private
void
addWhereField
(
SqlData
sql
,
String
tag
,
boolean
isRemove
)
{
addWhereBase
(
sql
,
DaoConst
.
CODE_WHERE
,
tag
,
isRemove
,
false
);
addWhereBase
(
sql
,
CODE_WHERE
,
tag
,
isRemove
,
false
);
// 查询时,不能查询到非删除的字段
addWhereRemove
(
sql
);
}
...
...
@@ -600,7 +597,7 @@ public class TableStruct {
* @param tag 扩展标签
*/
public
void
addWhereExtend
(
SqlData
sql
,
String
tag
,
boolean
removeHistory
,
String
...
codes
)
{
addWhereBase
(
sql
,
DaoConst
.
CODE_WHERE
,
tag
,
false
,
removeHistory
,
codes
);
addWhereBase
(
sql
,
CODE_WHERE
,
tag
,
false
,
removeHistory
,
codes
);
}
/**
...
...
@@ -623,7 +620,7 @@ public class TableStruct {
fields
=
this
.
getFields
();
}
else
{
// 非删除时需要更新的字段
fields
=
this
.
getFieldActionList
(
DaoConst
.
FIELD_COMMON
,
DaoConst
.
FIELD_REMOVE_UPDATE
);
fields
=
this
.
getFieldActionList
(
FIELD_COMMON
,
FIELD_REMOVE_UPDATE
);
}
List
<
String
>
codesField
=
new
ArrayList
<>();
...
...
@@ -641,11 +638,11 @@ public class TableStruct {
private
int
addWhereFieldCommon
(
SqlData
sql
,
String
codeName
,
TableFieldVo
field
,
String
tag
,
boolean
removeHistory
)
{
addWhereFieldNotExtend
(
sql
,
field
.
inputName
,
codeName
,
String
.
format
(
DaoConst
.
CODE_WHERE_EQUALS
,
tag
,
field
.
name
,
DaoConst
.
CODE_PARA
),
removeHistory
);
String
.
format
(
CODE_WHERE_EQUALS
,
tag
,
field
.
name
,
CODE_PARA
),
removeHistory
);
// 添加in条件
String
sqlIn
=
String
.
format
(
DaoConst
.
CODE_WHERE_IN
,
tag
,
field
.
name
,
DaoConst
.
CODE_PARA
);
String
sqlIn
=
String
.
format
(
CODE_WHERE_IN
,
tag
,
field
.
name
,
CODE_PARA
);
return
addWhereFieldNotExtend
(
sql
,
DaoConst
.
getArrayParameterName
(
field
.
inputName
),
codeName
,
return
addWhereFieldNotExtend
(
sql
,
getArrayParameterName
(
field
.
inputName
),
codeName
,
sqlIn
,
removeHistory
);
}
...
...
@@ -671,23 +668,39 @@ public class TableStruct {
* @param sql SQL语句实体
*/
private
void
addWhereRemove
(
SqlData
sql
)
{
if
(
getRemove
()
!=
null
)
{
sql
.
addParaConst
(
DaoConst
.
REMOVE_FLAG_INPUT
,
DaoConst
.
CODE_WHERE
,
String
.
format
(
DaoConst
.
CODE_WHERE_EQUALS_NOT_REMOVE
,
this
.
getRemove
().
name
)
TableFieldVo
remove
=
this
.
getRemove
();
if
(
remove
!=
null
)
{
sql
.
addParaConst
(
remove
.
inputName
+
OLD_FLAG
,
CODE_WHERE
,
String
.
format
(
CODE_WHERE_EQUALS_NOT_REMOVE
,
this
.
getRemove
().
name
)
);
}
}
/**
* 添加删除到更新SQL语句
*
* @param sql 删除语句
*/
private
void
addUpdateRemoveField
(
SqlData
sql
)
{
TableFieldVo
remove
=
this
.
getRemove
();
// 设置删除标记可以通过前台传入
if
(
remove
!=
null
)
{
sql
.
addParaConst
(
remove
.
inputName
,
CODE_FIELD
,
String
.
format
(
CODE_UPDATE_FIELD_PARA
,
remove
.
name
));
}
}
/**
* 版本号进行累加
*
* @param sql 需要处理的SQL语句
*/
private
void
addUpdateVersion
(
SqlData
sql
)
{
private
void
addUpdateVersion
Field
(
SqlData
sql
)
{
// 添加版本字段
if
(
getVersion
()
!=
null
)
{
sql
.
addCode
(
DaoConst
.
CODE_FIELD
,
String
.
format
(
DaoConst
.
CODE_UPDATE_VERSION_FIELD
,
getVersion
().
name
,
getVersion
().
name
));
TableFieldVo
version
=
getVersion
();
if
(
version
!=
null
)
{
sql
.
addCode
(
CODE_FIELD
,
String
.
format
(
CODE_UPDATE_VERSION_FIELD
,
version
.
name
,
version
.
name
));
}
}
...
...
@@ -704,17 +717,17 @@ public class TableStruct {
*/
private
SqlData
releaseSql
(
int
sqlType
,
String
name
,
String
model
,
String
valueModel
,
List
<
TableFieldVo
>
valueFields
,
List
<
TableFieldVo
>
whereFields
)
{
// 生成修改的SQL语句
SqlData
sql
=
new
SqlData
(
name
,
model
.
replace
(
DaoConst
.
CODE_TABLE
,
this
.
name
));
SqlData
sql
=
new
SqlData
(
name
,
model
.
replace
(
CODE_TABLE
,
this
.
name
));
sql
.
setSqlType
(
sqlType
);
// 生成添加的SQL语句
String
flag
=
StringHelper
.
EMPTY
;
for
(
TableFieldVo
field
:
valueFields
)
{
sql
.
addParaConst
(
field
.
inputName
,
DaoConst
.
CODE_FIELD
,
flag
+
valueModel
.
replace
(
DaoConst
.
CODE_FIELD
,
field
.
name
));
flag
=
DaoConst
.
CODE_SPLIT
;
sql
.
addParaConst
(
field
.
inputName
,
CODE_FIELD
,
flag
+
valueModel
.
replace
(
CODE_FIELD
,
field
.
name
));
flag
=
CODE_SPLIT
;
}
for
(
TableFieldVo
field
:
whereFields
)
{
sql
.
addConst
(
field
.
inputName
,
String
.
format
(
DaoConst
.
CODE_WHERE_EQUALS_PARA
,
field
.
name
));
sql
.
addConst
(
field
.
inputName
,
String
.
format
(
CODE_WHERE_EQUALS_PARA
,
field
.
name
));
}
return
sql
;
...
...
@@ -755,8 +768,8 @@ 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
.
SQL_LOAD
,
StringHelper
.
EMPTY
,
new
ArrayList
<>(),
whereFields
);
sqlData
.
addParaConst
(
DaoConst
.
CODE_FIELD_DEFAULT_NAME
,
DaoConst
.
CODE_FIELD
,
DaoConst
.
CODE_FIELD_DEFAULT
);
SqlData
sqlData
=
this
.
releaseSql
(
SQL_TYPE_SAVE_WITH
,
sqlName
,
SQL_LOAD
,
StringHelper
.
EMPTY
,
new
ArrayList
<>(),
whereFields
);
sqlData
.
addParaConst
(
CODE_FIELD_DEFAULT_NAME
,
CODE_FIELD
,
CODE_FIELD_DEFAULT
);
tableStruct
.
add
(
sqlData
);
}
...
...
@@ -790,23 +803,23 @@ public class TableStruct {
* @param addFields 需要增加的值的字段
*/
private
void
addGroupSql
(
TableSqlCache
sqlTableData
,
List
<
TableFieldVo
>
whereFields
,
List
<
TableFieldVo
>
replaceFields
,
List
<
TableFieldVo
>
addFields
)
{
List
<
TableFieldVo
>
prmaryKey
=
this
.
getFieldActionList
(
DaoConst
.
FIELD_PRIMARY
);
List
<
TableFieldVo
>
prmaryKey
=
this
.
getFieldActionList
(
FIELD_PRIMARY
);
// 生成统计加载SQL语句
SqlData
sqlLoad
=
this
.
releaseSql
(
DaoConst
.
SQL_TYPE_ADD_GROUP
,
DaoConst
.
GROUP_QUERY
,
DaoConst
.
SQL_LOAD
,
SqlData
sqlLoad
=
this
.
releaseSql
(
SQL_TYPE_ADD_GROUP
,
GROUP_QUERY
,
SQL_LOAD
,
StringHelper
.
EMPTY
,
new
ArrayList
<>(),
whereFields
);
sqlLoad
.
addParaConst
(
DaoConst
.
CODE_FIELD_DEFAULT_NAME
,
DaoConst
.
CODE_FIELD
,
DaoConst
.
CODE_FIELD_DEFAULT
);
sqlLoad
.
addParaConst
(
CODE_FIELD_DEFAULT_NAME
,
CODE_FIELD
,
CODE_FIELD_DEFAULT
);
// 生成统计累加SQL语句
SqlData
sqlGroupAdd
=
this
.
releaseSql
(
DaoConst
.
SQL_TYPE_ADD_GROUP
,
DaoConst
.
GROUP_ADD
,
DaoConst
.
SQL_UPDATE
,
DaoConst
.
CODE_GROUP_ADD
,
addFields
,
prmaryKey
);
SqlData
sqlGroupAdd
=
this
.
releaseSql
(
SQL_TYPE_ADD_GROUP
,
GROUP_ADD
,
SQL_UPDATE
,
CODE_GROUP_ADD
,
addFields
,
prmaryKey
);
// 当没有字段时,直接修改主键
if
(
addFields
.
isEmpty
())
{
sqlGroupAdd
.
addCode
(
DaoConst
.
CODE_FIELD
,
String
.
format
(
"%s=%s"
,
prmaryKey
.
get
(
0
).
inputName
,
prmaryKey
.
get
(
0
).
inputName
));
sqlGroupAdd
.
addCode
(
CODE_FIELD
,
String
.
format
(
"%s=%s"
,
prmaryKey
.
get
(
0
).
inputName
,
prmaryKey
.
get
(
0
).
inputName
));
}
// 生成覆盖值
if
(
replaceFields
!=
null
)
{
for
(
TableFieldVo
field
:
replaceFields
)
{
sqlGroupAdd
.
addPara
(
field
.
inputName
,
DaoConst
.
CODE_FIELD
,
String
.
format
(
",a.%s=?"
,
field
.
name
));
sqlGroupAdd
.
addPara
(
field
.
inputName
,
CODE_FIELD
,
String
.
format
(
",a.%s=?"
,
field
.
name
));
}
}
sqlTableData
.
add
(
sqlLoad
);
...
...
@@ -823,12 +836,12 @@ public class TableStruct {
*/
public
void
addExist
(
TableSqlCache
sqlTableData
,
String
sqlName
,
TableFieldString
mustField
,
TableFieldString
allowNullField
)
{
// String[] fields
SqlData
sql
=
new
SqlData
(
sqlName
,
DaoConst
.
SQL_LOAD
.
replace
(
DaoConst
.
CODE_TABLE
,
this
.
name
));
sql
.
addParaConst
(
DaoConst
.
CODE_FIELD_DEFAULT_NAME
,
DaoConst
.
CODE_FIELD
,
DaoConst
.
CODE_FIELD_DEFAULT
);
SqlData
sql
=
new
SqlData
(
sqlName
,
SQL_LOAD
.
replace
(
CODE_TABLE
,
this
.
name
));
sql
.
addParaConst
(
CODE_FIELD_DEFAULT_NAME
,
CODE_FIELD
,
CODE_FIELD_DEFAULT
);
sql
.
setSqlType
(
DaoConst
.
SQL_TYPE_EXISTS
);
sql
.
setSqlType
(
SQL_TYPE_EXISTS
);
sql
.
addConst
(
this
.
getKey
().
inputName
,
String
.
format
(
DaoConst
.
CODE_WHERE_NOT_EQUALS_PARA
,
this
.
getKey
().
name
)
String
.
format
(
CODE_WHERE_NOT_EQUALS_PARA
,
this
.
getKey
().
name
)
);
// 必须判断的字段
...
...
@@ -836,7 +849,7 @@ public class TableStruct {
for
(
String
fieldName
:
mustField
.
getFields
())
{
TableFieldVo
field
=
this
.
getField
(
fieldName
);
sql
.
addConst
(
field
.
inputName
,
String
.
format
(
DaoConst
.
CODE_WHERE_EQUALS_PARA
,
field
.
name
)
String
.
format
(
CODE_WHERE_EQUALS_PARA
,
field
.
name
)
);
}
}
...
...
@@ -846,7 +859,7 @@ public class TableStruct {
for
(
String
fieldName
:
allowNullField
.
getFields
())
{
TableFieldVo
field
=
this
.
getField
(
fieldName
);
sql
.
addConst
(
field
.
inputName
,
String
.
format
(
DaoConst
.
CODE_WHERE_EQUALS_NOT_EMPTY_PARA
,
field
.
name
)
String
.
format
(
CODE_WHERE_EQUALS_NOT_EMPTY_PARA
,
field
.
name
)
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment