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
820d4d73
Commit
820d4d73
authored
Nov 04, 2021
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改实例化关系
parent
3ef1b5b3
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
123 additions
and
16 deletions
+123
-16
DaoConst.java
yzg-util-db/src/main/java/com/yanzuoguang/dao/DaoConst.java
+4
-0
GroupAdd.java
...l-db/src/main/java/com/yanzuoguang/dao/impl/GroupAdd.java
+1
-0
TableSqlCache.java
...src/main/java/com/yanzuoguang/dao/impl/TableSqlCache.java
+9
-0
TableStruct.java
...b/src/main/java/com/yanzuoguang/dao/impl/TableStruct.java
+41
-15
TestDbPrintSql.java
yzg-util-db/src/test/java/TestDbPrintSql.java
+17
-1
TestTableGroupVo.java
yzg-util-db/src/test/java/TestTableGroupVo.java
+51
-0
No files found.
yzg-util-db/src/main/java/com/yanzuoguang/dao/DaoConst.java
View file @
820d4d73
...
...
@@ -296,6 +296,10 @@ public class DaoConst {
* 根据字段添加统计
*/
public
static
final
int
FIELD_ADD_GROUP
=
8
;
/**
* 根据字段替换统计
*/
public
static
final
int
FIELD_REPLACE_GROUP
=
9
;
/**
* SQL语句类型-普通语句
...
...
yzg-util-db/src/main/java/com/yanzuoguang/dao/impl/GroupAdd.java
View file @
820d4d73
...
...
@@ -4,6 +4,7 @@ package com.yanzuoguang.dao.impl;
* 累加接口
*
* @param <T>
* @author 颜佐光
*/
public
interface
GroupAdd
<
T
extends
GroupAdd
>
{
/***
...
...
yzg-util-db/src/main/java/com/yanzuoguang/dao/impl/TableSqlCache.java
View file @
820d4d73
...
...
@@ -119,6 +119,15 @@ public class TableSqlCache {
this
.
table
.
addGroupSql
(
this
,
tableWhereField
,
addField
);
}
/**
* 生成GroupSQL语句
*
* @param tableWhereField
* @param addField
*/
public
void
addGroup
(
TableFieldString
tableWhereField
,
TableFieldString
replaceField
,
TableFieldString
addField
)
{
this
.
table
.
addGroupSql
(
this
,
tableWhereField
,
replaceField
,
addField
);
}
/**
* 生成GroupSQL语句
...
...
yzg-util-db/src/main/java/com/yanzuoguang/dao/impl/TableStruct.java
View file @
820d4d73
...
...
@@ -258,9 +258,11 @@ public class TableStruct {
* @return 获取统计纬度列
*/
public
List
<
TableFieldVo
>
getGroupLatitudeFields
()
{
List
<
TableFieldVo
>
commonField
=
getFieldActionList
(
DaoConst
.
FIELD_COMMON
,
DaoConst
.
FIELD_ADD_GROUP
,
DaoConst
.
FIELD_MD5
);
return
commonField
;
return
getFieldActionList
(
DaoConst
.
FIELD_COMMON
,
DaoConst
.
FIELD_ADD_GROUP
,
DaoConst
.
FIELD_REPLACE_GROUP
,
DaoConst
.
FIELD_MD5
);
}
/**
...
...
@@ -424,8 +426,9 @@ public class TableStruct {
*/
private
void
initAddGroup
(
TableSqlCache
table
)
{
List
<
TableFieldVo
>
addGroupField
=
getFieldActionList
(
DaoConst
.
FIELD_ADD_GROUP
);
List
<
TableFieldVo
>
replaceGroupField
=
getFieldActionList
(
DaoConst
.
FIELD_REPLACE_GROUP
);
List
<
TableFieldVo
>
commonField
=
this
.
getGroupLatitudeFields
();
this
.
addGroupSql
(
table
,
commonField
,
addGroupField
);
this
.
addGroupSql
(
table
,
commonField
,
replaceGroupField
,
addGroupField
);
}
/**
...
...
@@ -724,8 +727,10 @@ public class TableStruct {
*/
private
List
<
TableFieldVo
>
getFieldString
(
TableFieldString
fieldFrom
)
{
List
<
TableFieldVo
>
list
=
new
ArrayList
<>();
for
(
String
fieldName
:
fieldFrom
.
getFields
())
{
list
.
add
(
this
.
getField
(
fieldName
));
if
(
fieldFrom
!=
null
)
{
for
(
String
fieldName
:
fieldFrom
.
getFields
())
{
list
.
add
(
this
.
getField
(
fieldName
));
}
}
return
list
;
}
...
...
@@ -759,10 +764,10 @@ public class TableStruct {
*
* @param sqlTableData 需要生成的实体
* @param whereFields WHERE字段
* @param
updateFields
需要增加的值的字段
* @param
addFields
需要增加的值的字段
*/
public
void
addGroupSql
(
TableSqlCache
sqlTableData
,
TableFieldString
whereFields
,
TableFieldString
update
Fields
)
{
addGroupSql
(
sqlTableData
,
getFieldString
(
whereFields
),
getFieldString
(
updateFields
)
);
public
void
addGroupSql
(
TableSqlCache
sqlTableData
,
TableFieldString
whereFields
,
TableFieldString
add
Fields
)
{
addGroupSql
(
sqlTableData
,
whereFields
,
null
,
addFields
);
}
/**
...
...
@@ -770,16 +775,37 @@ public class TableStruct {
*
* @param sqlTableData 需要生成的实体
* @param whereFields WHERE字段
* @param
updateFields
需要增加的值的字段
* @param
addFields
需要增加的值的字段
*/
private
void
addGroupSql
(
TableSqlCache
sqlTableData
,
List
<
TableFieldVo
>
whereFields
,
List
<
TableFieldVo
>
updateFields
)
{
public
void
addGroupSql
(
TableSqlCache
sqlTableData
,
TableFieldString
whereFields
,
TableFieldString
replaceFields
,
TableFieldString
addFields
)
{
addGroupSql
(
sqlTableData
,
getFieldString
(
whereFields
),
getFieldString
(
replaceFields
),
getFieldString
(
addFields
));
}
/**
* 生成统计的SQL语句
*
* @param sqlTableData 需要生成的实体
* @param replaceFields WHERE字段
* @param addFields 需要增加的值的字段
*/
private
void
addGroupSql
(
TableSqlCache
sqlTableData
,
List
<
TableFieldVo
>
whereFields
,
List
<
TableFieldVo
>
replaceFields
,
List
<
TableFieldVo
>
addFields
)
{
List
<
TableFieldVo
>
prmaryKey
=
this
.
getFieldActionList
(
DaoConst
.
FIELD_PRIMARY
);
// 生成统计加载SQL语句
SqlData
sqlLoad
=
this
.
releaseSql
(
DaoConst
.
SQL_TYPE_ADD_GROUP
,
DaoConst
.
GROUP_QUERY
,
DaoConst
.
SQL_LOAD
,
StringHelper
.
EMPTY
,
new
ArrayList
<>(),
whereFields
);
sqlLoad
.
addParaConst
(
DaoConst
.
CODE_FIELD_DEFAULT_NAME
,
DaoConst
.
CODE_FIELD
,
DaoConst
.
CODE_FIELD_DEFAULT
);
// 生成统计累加SQL语句
SqlData
sqlGroupAdd
=
this
.
releaseSql
(
DaoConst
.
SQL_TYPE_ADD_GROUP
,
DaoConst
.
GROUP_ADD
,
DaoConst
.
SQL_UPDATE
,
DaoConst
.
CODE_GROUP_ADD
,
updateFields
,
prmaryKey
);
if
(
updateFields
.
isEmpty
())
{
DaoConst
.
CODE_GROUP_ADD
,
addFields
,
prmaryKey
);
// 生成覆盖值
if
(
replaceFields
!=
null
)
{
for
(
TableFieldVo
field
:
replaceFields
)
{
sqlGroupAdd
.
addPara
(
field
.
inputName
,
DaoConst
.
CODE_FIELD
,
String
.
format
(
"a.%s=?"
,
field
.
name
));
}
}
// 当没有字段时,直接修改主键
if
(
addFields
.
isEmpty
())
{
sqlGroupAdd
.
addCode
(
DaoConst
.
CODE_FIELD
,
String
.
format
(
"%s=%s"
,
prmaryKey
.
get
(
0
).
inputName
,
prmaryKey
.
get
(
0
).
inputName
));
}
sqlTableData
.
add
(
sqlLoad
);
...
...
@@ -856,8 +882,8 @@ public class TableStruct {
tos
.
add
(
from
);
mapFrom
.
put
(
key
,
from
);
}
else
{
T
histor
=
mapFrom
.
get
(
key
);
histor
.
add
(
from
);
T
histor
y
=
mapFrom
.
get
(
key
);
histor
y
.
add
(
from
);
}
}
...
...
yzg-util-db/src/test/java/TestDbPrintSql.java
View file @
820d4d73
import
com.yanzuoguang.dao.DaoConst
;
import
com.yanzuoguang.dao.impl.SqlData
;
import
com.yanzuoguang.dao.impl.TableSqlCache
;
import
com.yanzuoguang.dao.impl.TableStruct
;
import
com.yanzuoguang.db.impl.DbPrintSql
;
import
com.yanzuoguang.util.helper.JsonHelper
;
import
org.junit.Test
;
public
class
TestDbPrintSql
{
@Test
public
void
test
(){
public
void
test
()
{
DbPrintSql
printSql
=
new
DbPrintSql
();
String
stringSql
=
printSql
.
getStringSql
(
"select * from where id = ? AND name = ? and removeFlag = 0 "
,
"1"
);
System
.
out
.
println
(
stringSql
);
}
@Test
public
void
testTableStruct
()
{
TableSqlCache
cache
=
new
TableSqlCache
();
TableStruct
table
=
new
TableStruct
(
"test"
,
TestTableGroupVo
.
class
);
table
.
init
(
cache
);
SqlData
sqlData
=
cache
.
getNameCache
().
get
(
DaoConst
.
GROUP_ADD
);
System
.
out
.
println
(
JsonHelper
.
serialize
(
sqlData
,
true
));
}
}
yzg-util-db/src/test/java/TestTableGroupVo.java
0 → 100644
View file @
820d4d73
import
com.yanzuoguang.dao.DaoConst
;
import
com.yanzuoguang.dao.TableAnnotation
;
@TableAnnotation
(
"db_time"
)
public
class
TestTableGroupVo
{
@TableAnnotation
(
"id"
)
private
String
id
;
@TableAnnotation
(
"createDate"
)
private
String
createDate
;
@TableAnnotation
(
value
=
"total"
,
type
=
DaoConst
.
FIELD_REPLACE_GROUP
)
private
int
total
;
@TableAnnotation
(
value
=
"has"
,
type
=
DaoConst
.
FIELD_ADD_GROUP
)
private
int
has
;
public
String
getId
()
{
return
id
;
}
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
public
String
getCreateDate
()
{
return
createDate
;
}
public
void
setCreateDate
(
String
createDate
)
{
this
.
createDate
=
createDate
;
}
public
int
getTotal
()
{
return
total
;
}
public
void
setTotal
(
int
total
)
{
this
.
total
=
total
;
}
public
int
getHas
()
{
return
has
;
}
public
void
setHas
(
int
has
)
{
this
.
has
=
has
;
}
}
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