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
450b6128
Commit
450b6128
authored
Apr 30, 2021
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
分布式幂等性判断
parent
2ebffc67
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
99 additions
and
19 deletions
+99
-19
DaoConst.java
yzg-util-db/src/main/java/com/yanzuoguang/dao/DaoConst.java
+20
-0
SqlData.java
...il-db/src/main/java/com/yanzuoguang/dao/impl/SqlData.java
+54
-4
TableStruct.java
...b/src/main/java/com/yanzuoguang/dao/impl/TableStruct.java
+25
-15
No files found.
yzg-util-db/src/main/java/com/yanzuoguang/dao/DaoConst.java
View file @
450b6128
package
com
.
yanzuoguang
.
dao
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.helper.StringHelper
;
/**
* DAO层处理基本美剧
*
...
...
@@ -329,4 +332,21 @@ public class DaoConst {
*/
public
static
final
int
SQL_TYPE_ADD_GROUP
=
7
;
/**
* 获取数组参数名称
*
* @param name
* @return
*/
public
static
String
getArrayParameterName
(
String
name
)
{
if
(
StringHelper
.
isEmpty
(
name
))
{
throw
new
CodeException
(
"名称不对"
);
}
String
lName
=
name
.
toLowerCase
();
if
(
lName
.
endsWith
(
DaoConst
.
CODE_WHERE_IN_END
))
{
return
name
+
DaoConst
.
CODE_WHERE_IN_END_ES
;
}
else
{
return
name
+
DaoConst
.
CODE_WHERE_IN_END
;
}
}
}
yzg-util-db/src/main/java/com/yanzuoguang/dao/impl/SqlData.java
View file @
450b6128
...
...
@@ -224,8 +224,8 @@ public class SqlData {
/**
* 按照一种类型添加SQL语句
*
* @param
clsModel
实体
* @param tag
标签
* @param
table
实体
* @param tag 标签
* @return
*/
public
SqlData
add
(
TableStruct
table
,
String
tag
,
String
...
codes
)
{
...
...
@@ -235,8 +235,8 @@ public class SqlData {
/**
* 按照一种类型添加SQL语句
*
* @param
clsModel
实体
* @param tag
标签
* @param
table
实体
* @param tag 标签
* @return
*/
public
SqlData
add
(
TableStruct
table
,
String
tag
,
boolean
removeFlag
,
String
...
codes
)
{
...
...
@@ -245,6 +245,56 @@ public class SqlData {
return
this
;
}
/**
* 按照一种类型添加SQL语句
*
* @param clsModel 实体
* @param tag 标签
* @return
*/
public
SqlData
addPara
(
Class
<?>
clsModel
,
String
codeName
,
String
tag
,
String
...
codes
)
{
return
this
.
addPara
(
clsModel
,
codeName
,
tag
,
false
,
codes
);
}
/**
* 按照一种类型添加SQL语句
*
* @param clsModel 实体
* @param tag 标签
* @return
*/
public
SqlData
addPara
(
Class
<?>
clsModel
,
String
codeName
,
String
tag
,
boolean
removeFlag
,
String
...
codes
)
{
// 生成表结构
TableStruct
table
=
new
TableStruct
(
StringHelper
.
EMPTY
,
clsModel
);
this
.
addPara
(
table
,
codeName
,
tag
,
removeFlag
,
codes
);
return
this
;
}
/**
* 按照一种类型添加SQL语句
*
* @param table 实体
* @param tag 标签
* @return
*/
public
SqlData
addPara
(
TableStruct
table
,
String
codeName
,
String
tag
,
String
...
codes
)
{
return
this
.
addPara
(
table
,
codeName
,
tag
,
false
,
codes
);
}
/**
* 按照一种类型添加SQL语句
*
* @param table 实体
* @param tag 标签
* @return
*/
public
SqlData
addPara
(
TableStruct
table
,
String
codeName
,
String
tag
,
boolean
removeFlag
,
String
...
codes
)
{
// 生成表结构
table
.
addWhereExtend
(
this
,
codeName
,
tag
,
removeFlag
,
codes
);
return
this
;
}
/**
* 添加参数,当在SQL语句中存在参数时,用于处理。{@id} 代表前台输入参数字段为id
* 例子:
...
...
yzg-util-db/src/main/java/com/yanzuoguang/dao/impl/TableStruct.java
View file @
450b6128
...
...
@@ -573,11 +573,12 @@ public class TableStruct {
* @return 生成的语句
*/
private
void
addWhereField
(
SqlData
sql
,
String
tag
,
boolean
isRemove
)
{
addWhereBase
(
sql
,
tag
,
isRemove
,
false
);
addWhereBase
(
sql
,
DaoConst
.
CODE_WHERE
,
tag
,
isRemove
,
false
);
// 查询时,不能查询到非删除的字段
addWhereRemove
(
sql
);
}
/**
* 对当前Sql语句进行扩展
*
...
...
@@ -585,11 +586,21 @@ public class TableStruct {
* @param tag 扩展标签
*/
public
void
addWhereExtend
(
SqlData
sql
,
String
tag
,
boolean
removeHistory
,
String
...
codes
)
{
addWhereBase
(
sql
,
tag
,
false
,
removeHistory
,
codes
);
addWhereBase
(
sql
,
DaoConst
.
CODE_WHERE
,
tag
,
false
,
removeHistory
,
codes
);
}
/**
* 对当前Sql语句进行扩展
*
* @param sql 需要扩展的SQL语句
* @param tag 扩展标签
*/
public
void
addWhereExtend
(
SqlData
sql
,
String
codeName
,
String
tag
,
boolean
removeHistory
,
String
...
codes
)
{
addWhereBase
(
sql
,
codeName
,
tag
,
false
,
removeHistory
,
codes
);
}
private
void
addWhereBase
(
SqlData
sql
,
String
tag
,
boolean
isRemove
,
boolean
removeHistory
,
String
...
codes
)
{
addWhereFieldCommon
(
sql
,
this
.
getKey
(),
tag
,
removeHistory
);
private
void
addWhereBase
(
SqlData
sql
,
String
codeName
,
String
tag
,
boolean
isRemove
,
boolean
removeHistory
,
String
...
codes
)
{
addWhereFieldCommon
(
sql
,
codeName
,
this
.
getKey
(),
tag
,
removeHistory
);
// Where条件包含的字段
List
<
TableFieldVo
>
fields
;
...
...
@@ -604,7 +615,7 @@ public class TableStruct {
List
<
String
>
codesField
=
new
ArrayList
<>();
// 添加普通的Where条件
for
(
TableFieldVo
field
:
fields
)
{
int
isAdd
=
addWhereFieldCommon
(
sql
,
field
,
tag
,
removeHistory
);
int
isAdd
=
addWhereFieldCommon
(
sql
,
codeName
,
field
,
tag
,
removeHistory
);
if
(
isAdd
!=
WHERE_ADD_NOT
)
{
codesField
.
add
(
field
.
inputName
);
}
...
...
@@ -614,28 +625,27 @@ public class TableStruct {
}
}
private
int
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
);
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
);
// 添加in条件
String
sqlIn
=
String
.
format
(
DaoConst
.
CODE_WHERE_IN
,
tag
,
field
.
name
,
DaoConst
.
CODE_PARA
);
if
(
field
.
inputLName
.
endsWith
(
DaoConst
.
CODE_WHERE_IN_END
))
{
return
addWhereFieldNotExtend
(
sql
,
field
.
inputName
+
DaoConst
.
CODE_WHERE_IN_END_ES
,
sqlIn
,
removeHistory
);
}
else
{
return
addWhereFieldNotExtend
(
sql
,
field
.
inputName
+
DaoConst
.
CODE_WHERE_IN_END
,
sqlIn
,
removeHistory
);
}
return
addWhereFieldNotExtend
(
sql
,
DaoConst
.
getArrayParameterName
(
field
.
inputName
),
codeName
,
sqlIn
,
removeHistory
);
}
private
int
addWhereFieldNotExtend
(
SqlData
sql
,
String
inputName
,
String
sqlWhere
,
boolean
removeHistory
)
{
private
int
addWhereFieldNotExtend
(
SqlData
sql
,
String
inputName
,
String
codeName
,
String
sqlWhere
,
boolean
removeHistory
)
{
SqlDataField
field
=
sql
.
getField
(
inputName
);
if
(
field
==
null
)
{
// 添加新的条件
sql
.
add
(
input
Name
,
sqlWhere
);
sql
.
add
Para
(
inputName
,
code
Name
,
sqlWhere
);
return
WHERE_ADD
;
}
else
if
(
field
!=
null
&&
removeHistory
)
{
// 删除历史条件
sql
.
removeField
(
inputName
);
// 添加新的条件
sql
.
add
(
input
Name
,
sqlWhere
);
sql
.
add
Para
(
inputName
,
code
Name
,
sqlWhere
);
return
WHERE_REMOVE_ADD
;
}
return
WHERE_ADD_NOT
;
...
...
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