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
d0b3994d
Commit
d0b3994d
authored
Aug 04, 2020
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
默认日期格式的支持
parent
2ce6dbaa
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
138 additions
and
25 deletions
+138
-25
SqlCondUtil.java
...b/src/main/java/com/yanzuoguang/dao/impl/SqlCondUtil.java
+100
-0
SqlData.java
...il-db/src/main/java/com/yanzuoguang/dao/impl/SqlData.java
+11
-0
TableSqlCache.java
...src/main/java/com/yanzuoguang/dao/impl/TableSqlCache.java
+27
-25
No files found.
yzg-util-db/src/main/java/com/yanzuoguang/dao/impl/SqlCondUtil.java
0 → 100644
View file @
d0b3994d
package
com
.
yanzuoguang
.
dao
.
impl
;
import
com.yanzuoguang.dao.cond.SqlCond
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* 将条件排序,符合索引
*
* @author 颜佐光
*/
class
SqlCondUtil
{
/**
* 时间等级
*/
public
static
final
int
COND_DATE
=
0
;
/**
* ID等级
*/
public
static
final
int
COND_ID
=
1
;
/**
* 普通相等
*/
public
static
final
int
COND_COMMON
=
2
;
/**
* 普通IN,NOT IN
*/
public
static
final
int
COND_IN
=
3
;
/**
* Like条件
*/
public
static
final
int
COND_LIKE
=
4
;
/**
* 全文索引
*/
public
static
final
int
COND_MATCH
=
5
;
/**
* 将SQL语句条件排序,符合索引
*
* @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
);
List
<
SqlDataField
>
levelCond
=
mapLevel
.
get
(
level
);
if
(
levelCond
==
null
)
{
levelCond
=
new
ArrayList
<>();
mapLevel
.
put
(
level
,
levelCond
);
}
levelCond
.
add
(
field
);
}
// 添加到排序好的条件
List
<
SqlDataField
>
tos
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<=
COND_MATCH
;
i
++)
{
List
<
SqlDataField
>
levelCond
=
mapLevel
.
get
(
i
);
if
(
levelCond
==
null
)
{
continue
;
}
tos
.
addAll
(
levelCond
);
}
return
tos
;
}
private
static
int
getCondLevel
(
SqlDataField
field
)
{
if
(
field
==
null
)
{
return
COND_COMMON
;
}
SqlCond
<?>
cond
=
field
.
getCond
();
for
(
String
fieldName
:
cond
.
getFields
())
{
fieldName
=
fieldName
.
toLowerCase
();
if
(
fieldName
.
indexOf
(
"date"
)
>
-
1
||
fieldName
.
indexOf
(
"time"
)
>
-
1
)
{
return
COND_DATE
;
}
else
if
(
fieldName
.
indexOf
(
"id"
)
>
-
1
)
{
return
COND_ID
;
}
}
int
len
=
field
.
getCodes
().
size
()
/
2
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
String
codeName
=
field
.
getCodes
().
get
(
i
*
2
);
String
codeValue
=
field
.
getCodes
().
get
(
i
*
2
+
1
).
toLowerCase
();
if
(
codeValue
.
indexOf
(
"in"
)
>
-
1
)
{
return
COND_IN
;
}
else
if
(
codeValue
.
indexOf
(
"like"
)
>
-
1
)
{
return
COND_LIKE
;
}
else
if
(
codeValue
.
indexOf
(
"match"
)
>
-
1
)
{
return
COND_MATCH
;
}
}
return
COND_COMMON
;
}
}
yzg-util-db/src/main/java/com/yanzuoguang/dao/impl/SqlData.java
View file @
d0b3994d
...
...
@@ -6,7 +6,9 @@ import com.yanzuoguang.dao.cond.SqlCondDefault;
import
com.yanzuoguang.util.helper.StringHelper
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* SQL语句基本信息
...
...
@@ -400,6 +402,15 @@ public class SqlData {
return
to
;
}
/**
* 条件排序
*/
public
SqlData
sortCond
()
{
SqlCondUtil
.
sortCond
(
this
.
sqlDataFields
);
return
this
;
}
/**
* 获取默认条件
*
...
...
yzg-util-db/src/main/java/com/yanzuoguang/dao/impl/TableSqlCache.java
View file @
d0b3994d
...
...
@@ -45,31 +45,6 @@ public class TableSqlCache {
this
.
table
=
new
TableStruct
();
}
/**
* 添加SQL语句组
*
* @param sqls
*/
public
void
add
(
SqlData
...
sqls
)
{
for
(
SqlData
sql
:
sqls
)
{
this
.
add
(
sql
);
}
}
/**
* 添加可执行的SQL语句
*
* @param sql SQL语句
*/
public
SqlData
add
(
SqlData
sql
)
{
if
(
sql
!=
null
)
{
this
.
nameCache
.
put
(
sql
.
getName
(),
sql
);
String
keyType
=
String
.
valueOf
(
sql
.
getSqlType
());
this
.
typeCache
.
get
(
keyType
,
new
ArrayList
<>()).
add
(
sql
);
}
return
sql
;
}
/**
* 获取所有的Sql语句执行类型
...
...
@@ -82,6 +57,17 @@ public class TableSqlCache {
return
typeCache
.
get
(
keyType
);
}
/**
* 添加SQL语句组
*
* @param sqls
*/
public
void
add
(
SqlData
...
sqls
)
{
for
(
SqlData
sql
:
sqls
)
{
this
.
add
(
sql
);
}
}
/**
* 添加SQL
*
...
...
@@ -108,6 +94,22 @@ public class TableSqlCache {
return
this
.
add
(
to
);
}
/**
* 添加可执行的SQL语句
*
* @param sql SQL语句
*/
public
SqlData
add
(
SqlData
sql
)
{
if
(
sql
!=
null
)
{
// 排序查询条件,用于排序优先级
sql
.
sortCond
();
this
.
nameCache
.
put
(
sql
.
getName
(),
sql
);
String
keyType
=
String
.
valueOf
(
sql
.
getSqlType
());
this
.
typeCache
.
get
(
keyType
,
new
ArrayList
<>()).
add
(
sql
);
}
return
sql
;
}
/**
* 生成GroupSQL语句
*
...
...
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