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
b40bc8c2
Commit
b40bc8c2
authored
Jun 10, 2020
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
压缩视频
parent
1153d9e1
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
46 additions
and
46 deletions
+46
-46
SqlCond.java
...il-db/src/main/java/com/yanzuoguang/dao/cond/SqlCond.java
+9
-0
SqlCondBase.java
...b/src/main/java/com/yanzuoguang/dao/cond/SqlCondBase.java
+24
-14
SqlCondDefault.java
...rc/main/java/com/yanzuoguang/dao/cond/SqlCondDefault.java
+0
-9
SqlCondEquals.java
...src/main/java/com/yanzuoguang/dao/cond/SqlCondEquals.java
+0
-11
BaseDaoImpl.java
...b/src/main/java/com/yanzuoguang/dao/impl/BaseDaoImpl.java
+13
-12
No files found.
yzg-util-db/src/main/java/com/yanzuoguang/dao/cond/SqlCond.java
View file @
b40bc8c2
...
...
@@ -36,6 +36,15 @@ public interface SqlCond {
*/
boolean
isField
(
String
...
field
);
/**
* 获取字段值
*
* @param model
* @return
*/
List
<
Object
>
getValues
(
Object
model
);
/**
* 获取新的SQL语句
*
...
...
yzg-util-db/src/main/java/com/yanzuoguang/dao/cond/SqlCondBase.java
View file @
b40bc8c2
...
...
@@ -3,6 +3,7 @@ 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.exception.CodeException
;
import
com.yanzuoguang.util.helper.StringHelper
;
...
...
@@ -54,11 +55,19 @@ public abstract class SqlCondBase implements SqlCond {
}
/**
* 获取
当前的字段
* 获取
字段值
*
* @param model
* @return
*/
protected
abstract
String
getFieldName
();
@Override
public
List
<
Object
>
getValues
(
Object
model
)
{
List
<
Object
>
rets
=
new
ArrayList
<>();
for
(
String
field
:
this
.
fields
)
{
rets
.
add
(
ObjectHelper
.
get
(
model
,
field
));
}
return
rets
;
}
/**
* 当前条件是否相等
...
...
@@ -74,34 +83,35 @@ public abstract class SqlCondBase implements SqlCond {
*
* @param sql
* @param sqlData
* @param
f
ield
* @param
sqlDataF
ield
* @param model
* @param codeMap
* @return
*/
@Override
public
String
getSql
(
String
sql
,
SqlData
sqlData
,
SqlDataField
f
ield
,
Object
model
,
Map
<
String
,
List
<
String
>>
codeMap
)
{
if
(
f
ield
.
getCond
()
!=
this
)
{
public
String
getSql
(
String
sql
,
SqlData
sqlData
,
SqlDataField
sqlDataF
ield
,
Object
model
,
Map
<
String
,
List
<
String
>>
codeMap
)
{
if
(
sqlDataF
ield
.
getCond
()
!=
this
)
{
throw
new
CodeException
(
"不能处理非本条件的字段"
);
}
int
condType
=
getCondType
(
model
,
f
ield
);
int
condType
=
getCondType
(
model
,
sqlDataF
ield
);
switch
(
condType
)
{
case
COND_TYPE_CONST_ONLY_PARA:
{
String
fieldName
=
this
.
getFieldName
();
for
(
String
field
:
this
.
fields
)
{
// 进行SQL语句参数替换,后面增加一个空格,方便后续用正则表达式进行替换处理
sql
=
sql
.
replaceFirst
(
"\\?"
,
"@"
+
fieldName
+
" "
);
sql
=
sql
.
replaceFirst
(
"\\?"
,
"@"
+
field
+
" "
);
}
break
;
}
case
COND_TYPE_CODE_COND:
{
String
fieldName
=
this
.
getFieldName
(
);
String
fieldName
=
this
.
fields
.
get
(
0
);
// 判断代码片段是否合法
if
(
f
ield
.
getCodes
().
size
()
%
2
==
1
)
{
if
(
sqlDataF
ield
.
getCodes
().
size
()
%
2
==
1
)
{
throw
new
CodeException
(
"代码片段"
+
this
.
getClass
().
getSimpleName
()
+
":"
+
sqlData
.
getName
()
+
":"
+
fieldName
+
"为单数"
);
}
// 处理代码片段
for
(
int
i
=
0
;
i
<
f
ield
.
getCodes
().
size
();
i
=
i
+
DaoConst
.
CODE_UNIT
)
{
String
codeName
=
f
ield
.
getCodes
().
get
(
i
);
String
codeValue
=
f
ield
.
getCodes
().
get
(
i
+
1
);
for
(
int
i
=
0
;
i
<
sqlDataF
ield
.
getCodes
().
size
();
i
=
i
+
DaoConst
.
CODE_UNIT
)
{
String
codeName
=
sqlDataF
ield
.
getCodes
().
get
(
i
);
String
codeValue
=
sqlDataF
ield
.
getCodes
().
get
(
i
+
1
);
codeValue
=
codeValue
.
replaceAll
(
"\\?"
,
"@"
+
fieldName
+
" "
);
addCodeMap
(
codeMap
,
codeName
,
codeValue
);
}
...
...
yzg-util-db/src/main/java/com/yanzuoguang/dao/cond/SqlCondDefault.java
View file @
b40bc8c2
...
...
@@ -22,15 +22,6 @@ public class SqlCondDefault extends SqlCondBase {
super
(
fields
);
}
/**
* 获取当前的字段
*
* @return
*/
@Override
protected
String
getFieldName
()
{
return
fields
.
isEmpty
()
?
StringHelper
.
EMPTY
:
this
.
fields
.
get
(
0
);
}
/**
* 当前条件是否相等
...
...
yzg-util-db/src/main/java/com/yanzuoguang/dao/cond/SqlCondEquals.java
View file @
b40bc8c2
...
...
@@ -25,16 +25,6 @@ public class SqlCondEquals extends SqlCondBase {
this
.
val
=
val
;
}
/**
* 获取当前的字段
*
* @return
*/
@Override
protected
String
getFieldName
()
{
return
fields
.
isEmpty
()
?
StringHelper
.
EMPTY
:
this
.
fields
.
get
(
0
);
}
/**
* 当前条件是否相等
*
...
...
@@ -58,7 +48,6 @@ public class SqlCondEquals extends SqlCondBase {
return
COND_TYPE_CODE_COND
;
}
}
return
COND_TYPE_NONE
;
}
return
COND_TYPE_NONE
;
}
...
...
yzg-util-db/src/main/java/com/yanzuoguang/dao/impl/BaseDaoImpl.java
View file @
b40bc8c2
...
...
@@ -736,12 +736,12 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
StringBuilder
sb
=
new
StringBuilder
();
String
date
=
StringHelper
.
EMPTY
;
for
(
SqlDataField
field
:
sql
.
getSqlDataFields
())
{
List
<
Object
>
values
=
field
.
getCond
().
getValues
(
model
);
for
(
Object
item
:
values
)
{
if
(
sb
.
length
()
>
0
)
{
sb
.
append
(
":"
);
}
Object
item
=
ObjectHelper
.
get
(
model
,
field
.
paraName
);
sb
.
append
(
item
);
if
(
StringHelper
.
isEmpty
(
date
))
{
String
itemString
=
String
.
valueOf
(
item
);
if
(
item
instanceof
Date
)
{
...
...
@@ -751,6 +751,7 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
}
}
}
}
if
(
StringHelper
.
isEmpty
(
date
))
{
return
StringHelper
.
md5
(
sb
.
toString
());
}
else
{
...
...
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