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
ac97711f
Commit
ac97711f
authored
Jun 15, 2020
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
压缩视频
parent
cbc824d5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
14 deletions
+31
-14
SqlData.java
...il-db/src/main/java/com/yanzuoguang/dao/impl/SqlData.java
+12
-1
TableStruct.java
...b/src/main/java/com/yanzuoguang/dao/impl/TableStruct.java
+19
-13
No files found.
yzg-util-db/src/main/java/com/yanzuoguang/dao/impl/SqlData.java
View file @
ac97711f
...
...
@@ -168,9 +168,20 @@ public class SqlData {
* @return
*/
public
SqlData
add
(
Class
<?>
clsModel
,
String
tag
)
{
return
this
.
add
(
clsModel
,
tag
,
false
);
}
/**
* 按照一种类型添加SQL语句
*
* @param clsModel 实体
* @param tag 标签
* @return
*/
public
SqlData
add
(
Class
<?>
clsModel
,
String
tag
,
boolean
removeFlag
)
{
// 生成表结构
TableStruct
table
=
new
TableStruct
(
StringHelper
.
EMPTY
,
clsModel
);
table
.
addWhereExtend
(
this
,
tag
);
table
.
addWhereExtend
(
this
,
tag
,
removeFlag
);
return
this
;
}
...
...
yzg-util-db/src/main/java/com/yanzuoguang/dao/impl/TableStruct.java
View file @
ac97711f
...
...
@@ -557,7 +557,7 @@ public class TableStruct {
* @return 生成的语句
*/
private
void
addWhereField
(
SqlData
sql
,
String
tag
,
boolean
isRemove
)
{
addWhereBase
(
sql
,
tag
,
isRemove
);
addWhereBase
(
sql
,
tag
,
isRemove
,
false
);
// 查询时,不能查询到非删除的字段
addWhereRemove
(
sql
);
}
...
...
@@ -568,12 +568,12 @@ public class TableStruct {
* @param sql 需要扩展的SQL语句
* @param tag 扩展标签
*/
public
void
addWhereExtend
(
SqlData
sql
,
String
tag
)
{
addWhereBase
(
sql
,
tag
,
false
);
public
void
addWhereExtend
(
SqlData
sql
,
String
tag
,
boolean
removeHistory
)
{
addWhereBase
(
sql
,
tag
,
false
,
removeHistory
);
}
private
void
addWhereBase
(
SqlData
sql
,
String
tag
,
boolean
isRemove
)
{
addWhereFieldCommon
(
sql
,
this
.
getKey
(),
tag
);
private
void
addWhereBase
(
SqlData
sql
,
String
tag
,
boolean
isRemove
,
boolean
removeHistory
)
{
addWhereFieldCommon
(
sql
,
this
.
getKey
(),
tag
,
removeHistory
);
// Where条件包含的字段
List
<
TableFieldVo
>
fields
;
...
...
@@ -586,24 +586,30 @@ public class TableStruct {
}
// 添加普通的Where条件
for
(
TableFieldVo
field
:
fields
)
{
addWhereFieldCommon
(
sql
,
field
,
tag
);
addWhereFieldCommon
(
sql
,
field
,
tag
,
removeHistory
);
}
}
private
void
addWhereFieldCommon
(
SqlData
sql
,
TableFieldVo
field
,
String
tag
)
{
addWhereFieldNotExtend
(
sql
,
field
.
inputName
,
String
.
format
(
DaoConst
.
CODE_WHERE_EQUALS
,
tag
,
field
.
name
,
DaoConst
.
CODE_PARA
));
private
void
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
);
// 添加in条件
String
sqlIn
=
String
.
format
(
DaoConst
.
CODE_WHERE_IN
,
tag
,
field
.
name
,
DaoConst
.
CODE_PARA
);
if
(
field
.
inputLName
.
endsWith
(
DaoConst
.
CODE_WHERE_IN_END
))
{
addWhereFieldNotExtend
(
sql
,
field
.
inputName
+
DaoConst
.
CODE_WHERE_IN_END_ES
,
sqlIn
);
addWhereFieldNotExtend
(
sql
,
field
.
inputName
+
DaoConst
.
CODE_WHERE_IN_END_ES
,
sqlIn
,
removeHistory
);
}
else
{
addWhereFieldNotExtend
(
sql
,
field
.
inputName
+
DaoConst
.
CODE_WHERE_IN_END
,
sqlIn
);
addWhereFieldNotExtend
(
sql
,
field
.
inputName
+
DaoConst
.
CODE_WHERE_IN_END
,
sqlIn
,
removeHistory
);
}
}
private
void
addWhereFieldNotExtend
(
SqlData
sql
,
String
inputName
,
String
sqlWhere
)
{
if
(
sql
.
getField
(
inputName
)
==
null
)
{
// 添加等于条件
private
void
addWhereFieldNotExtend
(
SqlData
sql
,
String
inputName
,
String
sqlWhere
,
boolean
removeHistory
)
{
SqlDataField
field
=
sql
.
getField
(
inputName
);
if
(
field
==
null
)
{
// 添加新的条件
sql
.
add
(
inputName
,
sqlWhere
);
}
else
if
(
removeHistory
)
{
// 删除历史条件
sql
.
removeField
(
inputName
);
// 添加新的条件
sql
.
add
(
inputName
,
sqlWhere
);
}
}
...
...
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