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
0ad53399
Commit
0ad53399
authored
Aug 03, 2021
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改保存历史记录
parent
e97194d8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
127 additions
and
2 deletions
+127
-2
SqlCondDefault.java
...rc/main/java/com/yanzuoguang/dao/cond/SqlCondDefault.java
+14
-2
SqlCondItem.java
...b/src/main/java/com/yanzuoguang/dao/cond/SqlCondItem.java
+113
-0
No files found.
yzg-util-db/src/main/java/com/yanzuoguang/dao/cond/SqlCondDefault.java
View file @
0ad53399
...
...
@@ -41,13 +41,25 @@ public class SqlCondDefault extends SqlCondBase<SqlCondDefault> {
*/
@Override
protected
int
getCondType
(
Object
model
,
SqlDataField
sqlField
)
{
return
getCondType
(
fields
,
model
,
sqlField
);
}
/**
* 获取sql类型该
*
* @param fields
* @param model
* @param sqlField
* @return
*/
public
static
int
getCondType
(
List
<
String
>
fields
,
Object
model
,
SqlDataField
sqlField
)
{
// 判断是否包含输入参数
boolean
isInputField
=
!
this
.
fields
.
isEmpty
();
boolean
isInputField
=
!
fields
.
isEmpty
();
// 判断是否属于条件
boolean
isCond
=
sqlField
.
getCodes
().
size
()
>
0
&&
sqlField
.
isAuto
();
boolean
isConst
=
sqlField
.
getCodes
().
size
()
>
0
&&
!
sqlField
.
isAuto
();
if
(
isInputField
&&
isCond
)
{
for
(
String
field
:
this
.
fields
)
{
for
(
String
field
:
fields
)
{
// 获取值
Object
val
=
ObjectHelper
.
get
(
model
,
field
);
if
(
StringHelper
.
isEmpty
(
val
)
||
StringHelper
.
isEmptyArray
(
val
))
{
...
...
yzg-util-db/src/main/java/com/yanzuoguang/dao/cond/SqlCondItem.java
0 → 100644
View file @
0ad53399
package
com
.
yanzuoguang
.
dao
.
cond
;
import
com.yanzuoguang.dao.DaoConst
;
import
com.yanzuoguang.dao.impl.SqlData
;
import
com.yanzuoguang.dao.impl.SqlDataField
;
import
com.yanzuoguang.util.base.ObjectHelper
;
import
com.yanzuoguang.util.helper.ArrayHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Map
;
/**
* 分别处理每一项,用于替换
*
* @author 颜佐光
*/
public
class
SqlCondItem
extends
SqlCondBase
<
SqlCondItem
>
{
public
SqlCondItem
(
String
...
field
)
{
this
(
Arrays
.
asList
(
field
));
}
public
SqlCondItem
(
List
<
String
>
fields
)
{
this
(
null
,
fields
);
}
public
SqlCondItem
(
Runnable
debugRunnable
,
String
...
field
)
{
this
(
debugRunnable
,
Arrays
.
asList
(
field
));
}
public
SqlCondItem
(
Runnable
debugRunnable
,
List
<
String
>
fields
)
{
super
(
fields
);
super
.
debugRunnable
=
debugRunnable
;
}
/**
* 当前条件是否相等
*
* @param model 请求参数实体
* @param sqlField 请求字段
* @return
*/
@Override
protected
int
getCondType
(
Object
model
,
SqlDataField
sqlField
)
{
return
SqlCondDefault
.
getCondType
(
this
.
fields
,
model
,
sqlField
);
}
/**
* 获取新的SQL语句
*
* @param sql
* @param sqlData
* @param sqlDataField
* @param model
* @param codeMap
* @return
*/
@Override
public
String
getSql
(
String
sql
,
SqlData
sqlData
,
SqlDataField
sqlDataField
,
Object
model
,
Map
<
String
,
List
<
String
>>
codeMap
)
{
if
(
sqlDataField
.
getCond
()
!=
this
)
{
throw
new
RuntimeException
(
"不能处理非本条件的字段"
);
}
if
(
debugRunnable
!=
null
)
{
// 用于断点调试的支持
debugRunnable
.
run
();
}
int
condType
=
getCondType
(
model
,
sqlDataField
);
switch
(
condType
)
{
case
COND_TYPE_CONST_ONLY_PARA:
{
throw
new
RuntimeException
(
"SqlCondItem不支持输入参数,必须带代码片段"
);
}
case
COND_TYPE_CODE_COND:
{
String
fieldName
=
this
.
fields
.
isEmpty
()
?
StringHelper
.
EMPTY
:
this
.
fields
.
get
(
0
);
// 判断代码片段是否合法
if
(
sqlDataField
.
getCodes
().
size
()
%
2
==
1
)
{
throw
new
RuntimeException
(
"代码片段"
+
this
.
getClass
().
getSimpleName
()
+
":"
+
sqlData
.
getName
()
+
":"
+
fieldName
+
"为单数"
);
}
Object
value
=
ObjectHelper
.
get
(
model
,
fieldName
);
List
list
=
ArrayHelper
.
getList
(
value
);
for
(
Object
item
:
list
)
{
// 处理代码片段
for
(
int
i
=
0
;
i
<
sqlDataField
.
getCodes
().
size
();
i
=
i
+
DaoConst
.
CODE_UNIT
)
{
String
codeName
=
sqlDataField
.
getCodes
().
get
(
i
);
String
codeValue
=
sqlDataField
.
getCodes
().
get
(
i
+
1
);
codeValue
=
codeValue
.
replaceAll
(
"\\?"
,
item
.
toString
()).
replaceAll
(
"\\{0\\}"
,
item
.
toString
());
codeValue
=
StringHelper
.
getCodeString
(
codeValue
,
item
);
addCodeMap
(
codeMap
,
codeName
,
codeValue
);
}
}
break
;
}
case
COND_TYPE_NONE:
default
:
break
;
}
return
sql
;
}
/**
* 将当前条件复制为新的对象
*
* @return
*/
@Override
public
SqlCond
copy
()
{
SqlCondItem
cond
=
new
SqlCondItem
(
this
.
debugRunnable
,
this
.
fields
);
return
cond
;
}
}
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