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
fe50a963
Commit
fe50a963
authored
Aug 04, 2020
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
默认日期格式的支持
parent
8e0dcf55
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
25 deletions
+21
-25
SqlCondUtil.java
...b/src/main/java/com/yanzuoguang/dao/impl/SqlCondUtil.java
+21
-25
No files found.
yzg-util-db/src/main/java/com/yanzuoguang/dao/impl/SqlCondUtil.java
View file @
fe50a963
...
...
@@ -16,31 +16,31 @@ class SqlCondUtil {
/**
* 代码片段等级
*/
public
static
final
int
CON
D_CODE
=
0
;
public
static
final
int
FIEL
D_CODE
=
0
;
/**
* 时间等级
*/
public
static
final
int
COND
_DATE
=
1
;
public
static
final
int
WHERE
_DATE
=
1
;
/**
* ID等级
*/
public
static
final
int
COND
_ID
=
2
;
public
static
final
int
WHERE
_ID
=
2
;
/**
* 普通相等
*/
public
static
final
int
COND
_COMMON
=
3
;
public
static
final
int
WHERE
_COMMON
=
3
;
/**
* 普通IN,NOT IN
*/
public
static
final
int
COND
_IN
=
4
;
public
static
final
int
WHERE
_IN
=
4
;
/**
* Like条件
*/
public
static
final
int
COND
_LIKE
=
5
;
public
static
final
int
WHERE
_LIKE
=
5
;
/**
* 全文索引
*/
public
static
final
int
COND
_MATCH
=
6
;
public
static
final
int
WHERE
_MATCH
=
6
;
/**
* 将SQL语句条件排序,符合索引
...
...
@@ -48,7 +48,7 @@ class SqlCondUtil {
* @param fields
*/
public
static
List
<
SqlDataField
>
sortCond
(
List
<
SqlDataField
>
fields
)
{
//
最大级别
//
获取代码片段的级别,并且放到对应级别的数组中
Map
<
Integer
,
List
<
SqlDataField
>>
mapLevel
=
new
HashMap
<>();
for
(
SqlDataField
field
:
fields
)
{
int
level
=
getCondLevel
(
field
);
...
...
@@ -59,9 +59,9 @@ class SqlCondUtil {
}
levelCond
.
add
(
field
);
}
//
添加到排序好的条件
//
按照级别返回代码片段
List
<
SqlDataField
>
tos
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<=
COND
_MATCH
;
i
++)
{
for
(
int
i
=
0
;
i
<=
WHERE
_MATCH
;
i
++)
{
List
<
SqlDataField
>
levelCond
=
mapLevel
.
get
(
i
);
if
(
levelCond
==
null
)
{
continue
;
...
...
@@ -73,42 +73,38 @@ class SqlCondUtil {
private
static
int
getCondLevel
(
SqlDataField
field
)
{
if
(
field
==
null
)
{
return
COND
_COMMON
;
return
WHERE
_COMMON
;
}
SqlCond
<?>
cond
=
field
.
getCond
();
boolean
isWhere
=
false
;
int
len
=
field
.
getCodes
().
size
()
/
2
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
// 判断是否包含where条件,当没有包含where条件时,则属于普通代码片段,优先级最高
String
codeName
=
field
.
getCodes
().
get
(
i
*
2
).
toLowerCase
();
String
codeValue
=
field
.
getCodes
().
get
(
i
*
2
+
1
).
toLowerCase
();
if
(
codeName
.
indexOf
(
"where"
)
<
0
)
{
continue
;
}
isWhere
=
true
;
// 当包含where条件时,则按照规则排序
for
(
String
fieldName
:
cond
.
getFields
())
{
fieldName
=
fieldName
.
toLowerCase
();
if
(
fieldName
.
indexOf
(
"date"
)
>
-
1
||
fieldName
.
indexOf
(
"time"
)
>
-
1
)
{
return
COND
_DATE
;
return
WHERE
_DATE
;
}
else
if
(
fieldName
.
indexOf
(
"id"
)
>
-
1
)
{
return
COND
_ID
;
return
WHERE
_ID
;
}
}
if
(
codeValue
.
indexOf
(
"in"
)
>
-
1
)
{
return
COND
_IN
;
return
WHERE
_IN
;
}
else
if
(
codeValue
.
indexOf
(
"like"
)
>
-
1
)
{
return
COND
_LIKE
;
return
WHERE
_LIKE
;
}
else
if
(
codeValue
.
indexOf
(
"match"
)
>
-
1
)
{
return
COND_MATCH
;
}
}
if
(
isWhere
)
{
return
COND_COMMON
;
return
WHERE_MATCH
;
}
else
{
return
COND_CODE
;
return
WHERE_COMMON
;
}
}
return
FIELD_CODE
;
}
}
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