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
08181534
Commit
08181534
authored
Jun 14, 2020
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
压缩视频
parent
b1256682
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
78 additions
and
11 deletions
+78
-11
StringHelper.java
...c/main/java/com/yanzuoguang/util/helper/StringHelper.java
+11
-0
SqlCondBase.java
...b/src/main/java/com/yanzuoguang/dao/cond/SqlCondBase.java
+29
-1
SqlCondEquals.java
...src/main/java/com/yanzuoguang/dao/cond/SqlCondEquals.java
+38
-10
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/StringHelper.java
View file @
08181534
...
@@ -340,6 +340,17 @@ public class StringHelper {
...
@@ -340,6 +340,17 @@ public class StringHelper {
}
}
}
}
/**
* 判断类型是否是整形
*
* @param cls
* @return
*/
public
static
boolean
isInt
(
Class
<?>
cls
)
{
String
vName
=
cls
.
getName
();
return
TYPE_INT
.
equals
(
vName
)
||
isType
(
cls
,
Integer
.
class
);
}
/**
/**
* 根据类型来获取值
* 根据类型来获取值
*
*
...
...
yzg-util-db/src/main/java/com/yanzuoguang/dao/cond/SqlCondBase.java
View file @
08181534
...
@@ -135,7 +135,35 @@ public abstract class SqlCondBase<T extends SqlCondBase> implements SqlCond<T> {
...
@@ -135,7 +135,35 @@ public abstract class SqlCondBase<T extends SqlCondBase> implements SqlCond<T> {
}
}
for
(
String
toField
:
toFields
)
{
for
(
String
toField
:
toFields
)
{
String
to
=
toField
.
toLowerCase
().
replaceAll
(
"_"
,
""
);
String
to
=
toField
.
toLowerCase
().
replaceAll
(
"_"
,
""
);
mapField
.
remove
(
to
);
if
(
mapField
.
containsKey
(
to
))
{
mapField
.
remove
(
to
);
}
else
{
return
false
;
}
}
return
mapField
.
isEmpty
();
}
/**
* 判断值是否相等
*
* @param fromFields 来源字段
* @param toFields 目标字段
* @return
*/
protected
static
boolean
eqaulsValues
(
List
fromFields
,
List
toFields
)
{
Map
<
Object
,
Boolean
>
mapField
=
new
HashMap
<>();
for
(
Object
fromField
:
fromFields
)
{
Object
from
=
fromField
!=
null
?
fromField
:
StringHelper
.
EMPTY
;
mapField
.
put
(
from
,
true
);
}
for
(
Object
toField
:
toFields
)
{
Object
to
=
toField
!=
null
?
toField
:
StringHelper
.
EMPTY
;
if
(
mapField
.
containsKey
(
to
))
{
mapField
.
remove
(
to
);
}
else
{
return
false
;
}
}
}
return
mapField
.
isEmpty
();
return
mapField
.
isEmpty
();
}
}
...
...
yzg-util-db/src/main/java/com/yanzuoguang/dao/cond/SqlCondEquals.java
View file @
08181534
...
@@ -6,7 +6,9 @@ import com.yanzuoguang.util.helper.ArrayHelper;
...
@@ -6,7 +6,9 @@ import com.yanzuoguang.util.helper.ArrayHelper;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
/**
/**
* 包含的值字段
* 包含的值字段
...
@@ -15,15 +17,32 @@ import java.util.List;
...
@@ -15,15 +17,32 @@ import java.util.List;
*/
*/
public
class
SqlCondEquals
extends
SqlCondBase
<
SqlCondEquals
>
{
public
class
SqlCondEquals
extends
SqlCondBase
<
SqlCondEquals
>
{
public
Object
val
;
public
Object
[]
vals
;
public
SqlCondEquals
(
String
field
,
Object
val
)
{
private
boolean
valIsInteger
=
false
;
this
(
Arrays
.
asList
(
field
),
val
);
private
Map
<
Object
,
Boolean
>
mapValue
=
new
HashMap
<>();
public
SqlCondEquals
(
String
field
,
Object
...
vals
)
{
this
(
Arrays
.
asList
(
field
),
vals
);
}
}
public
SqlCondEquals
(
List
<
String
>
fields
,
Object
val
)
{
public
SqlCondEquals
(
List
<
String
>
fields
,
Object
...
vals
)
{
super
(
fields
);
super
(
fields
);
this
.
val
=
val
;
this
.
vals
=
vals
;
// 判断值是否为整形
if
(
vals
!=
null
)
{
for
(
Object
val
:
this
.
vals
)
{
if
(
val
!=
null
)
{
valIsInteger
=
valIsInteger
||
StringHelper
.
isInt
(
val
.
getClass
());
mapValue
.
put
(
val
,
true
);
}
else
{
mapValue
.
put
(
StringHelper
.
EMPTY
,
true
);
}
}
}
}
}
/**
/**
...
@@ -41,12 +60,20 @@ public class SqlCondEquals extends SqlCondBase<SqlCondEquals> {
...
@@ -41,12 +60,20 @@ public class SqlCondEquals extends SqlCondBase<SqlCondEquals> {
for
(
String
field
:
this
.
fields
)
{
for
(
String
field
:
this
.
fields
)
{
// 获取值
// 获取值
Object
val
=
ObjectHelper
.
get
(
model
,
field
);
Object
val
=
ObjectHelper
.
get
(
model
,
field
);
if
(
StringHelper
.
isEmpty
(
val
)
||
StringHelper
.
isEmptyArray
(
val
))
{
// 转换为整形
continue
;
if
(
valIsInteger
)
{
val
=
StringHelper
.
toInt
(
val
);
}
}
// 判断值是否相等
List
list
=
ArrayHelper
.
getList
(
val
);
List
list
=
ArrayHelper
.
getList
(
val
);
for
(
Object
item
:
list
)
{
for
(
Object
item
:
list
)
{
if
(
StringHelper
.
compare
(
item
,
this
.
val
))
{
// 值处理
Object
itemTo
=
item
;
if
(
itemTo
==
null
)
{
itemTo
=
StringHelper
.
EMPTY
;
}
// 判断是否包含该值
if
(
this
.
mapValue
.
containsKey
(
itemTo
))
{
// 只要有值不为空,则条件满足
// 只要有值不为空,则条件满足
return
COND_TYPE_CODE_COND
;
return
COND_TYPE_CODE_COND
;
}
}
...
@@ -63,7 +90,7 @@ public class SqlCondEquals extends SqlCondBase<SqlCondEquals> {
...
@@ -63,7 +90,7 @@ public class SqlCondEquals extends SqlCondBase<SqlCondEquals> {
*/
*/
@Override
@Override
public
SqlCond
copy
()
{
public
SqlCond
copy
()
{
SqlCondEquals
cond
=
new
SqlCondEquals
(
this
.
fields
,
this
.
val
);
SqlCondEquals
cond
=
new
SqlCondEquals
(
this
.
fields
,
this
.
val
s
);
return
cond
;
return
cond
;
}
}
...
@@ -75,6 +102,7 @@ public class SqlCondEquals extends SqlCondBase<SqlCondEquals> {
...
@@ -75,6 +102,7 @@ public class SqlCondEquals extends SqlCondBase<SqlCondEquals> {
*/
*/
@Override
@Override
public
boolean
equals
(
SqlCondEquals
cond
)
{
public
boolean
equals
(
SqlCondEquals
cond
)
{
return
SqlCondBase
.
eqaulsField
(
this
.
fields
,
cond
.
fields
)
&&
StringHelper
.
compare
(
this
.
val
,
cond
.
val
);
return
SqlCondBase
.
eqaulsField
(
this
.
fields
,
cond
.
fields
)
&&
StringHelper
.
compare
(
Arrays
.
asList
(
this
.
vals
),
Arrays
.
asList
(
cond
.
vals
));
}
}
}
}
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