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
1dd16657
Commit
1dd16657
authored
Jun 19, 2019
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
常规BUG的修改
parent
625b923d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
123 additions
and
62 deletions
+123
-62
DaoConst.java
yzg-util-db/src/main/java/com/yanzuoguang/dao/DaoConst.java
+23
-2
BaseDaoImpl.java
...b/src/main/java/com/yanzuoguang/dao/impl/BaseDaoImpl.java
+1
-2
TableStruct.java
...b/src/main/java/com/yanzuoguang/dao/impl/TableStruct.java
+99
-58
No files found.
yzg-util-db/src/main/java/com/yanzuoguang/dao/DaoConst.java
View file @
1dd16657
...
@@ -53,6 +53,11 @@ public class DaoConst {
...
@@ -53,6 +53,11 @@ public class DaoConst {
*/
*/
public
static
final
String
GROUP_QUERY
=
"GroupQuery"
;
public
static
final
String
GROUP_QUERY
=
"GroupQuery"
;
/**
* 根据某个字段保存
*/
public
static
final
String
SAVE_WITH
=
"SaveWith"
;
/**
/**
* 驼峰式命名
* 驼峰式命名
*/
*/
...
@@ -157,7 +162,7 @@ public class DaoConst {
...
@@ -157,7 +162,7 @@ public class DaoConst {
/**
/**
* 统计语句增加字段模板
* 统计语句增加字段模板
*/
*/
public
static
final
String
CODE_GROUP_ADD
=
"
{FIELD}=
{FIELD}+?"
;
public
static
final
String
CODE_GROUP_ADD
=
"
a.{FIELD}=a.
{FIELD}+?"
;
/**
/**
* 版本号字段名称
* 版本号字段名称
*/
*/
...
@@ -227,6 +232,14 @@ public class DaoConst {
...
@@ -227,6 +232,14 @@ public class DaoConst {
* 删除时记录操作状态的字段
* 删除时记录操作状态的字段
*/
*/
public
static
final
int
FIELD_CREATE
=
6
;
public
static
final
int
FIELD_CREATE
=
6
;
/**
* 根据字段保存
*/
public
static
final
int
FIELD_SAVE_WITH
=
7
;
/**
* 根据字段添加统计
*/
public
static
final
int
FIELD_ADD_GROUP
=
8
;
/**
/**
* SQL语句类型-普通语句
* SQL语句类型-普通语句
...
@@ -253,6 +266,14 @@ public class DaoConst {
...
@@ -253,6 +266,14 @@ public class DaoConst {
/**
/**
* SQL语句类型-是否存在
* SQL语句类型-是否存在
*/
*/
public
static
final
int
SQL_TYPE_EXINTS
=
5
;
public
static
final
int
SQL_TYPE_EXISTS
=
5
;
/**
* SQL语句类型-根据字段保存
*/
public
static
final
int
SQL_TYPE_SAVE_WITH
=
6
;
/**
* SQL语句类型-添加统计
*/
public
static
final
int
SQL_TYPE_ADD_GROUP
=
7
;
}
}
yzg-util-db/src/main/java/com/yanzuoguang/dao/impl/BaseDaoImpl.java
View file @
1dd16657
...
@@ -2,7 +2,6 @@ package com.yanzuoguang.dao.impl;
...
@@ -2,7 +2,6 @@ package com.yanzuoguang.dao.impl;
import
com.yanzuoguang.dao.BaseDao
;
import
com.yanzuoguang.dao.BaseDao
;
import
com.yanzuoguang.dao.DaoConst
;
import
com.yanzuoguang.dao.DaoConst
;
import
com.yanzuoguang.db.impl.AllBeanRowMapper
;
import
com.yanzuoguang.util.base.ObjectHelper
;
import
com.yanzuoguang.util.base.ObjectHelper
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.helper.DateHelper
;
import
com.yanzuoguang.util.helper.DateHelper
;
...
@@ -169,7 +168,7 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
...
@@ -169,7 +168,7 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
to
.
init
();
to
.
init
();
}
}
if
(
operatorType
==
DaoConst
.
OPERATOR_TYPE_CREATE
||
operatorType
==
DaoConst
.
OPERATOR_TYPE_UPDATE
)
{
if
(
operatorType
==
DaoConst
.
OPERATOR_TYPE_CREATE
||
operatorType
==
DaoConst
.
OPERATOR_TYPE_UPDATE
)
{
List
<
SqlData
>
sqlArray
=
this
.
table
.
getSqlType
(
DaoConst
.
SQL_TYPE_
EXINTS
);
List
<
SqlData
>
sqlArray
=
this
.
table
.
getSqlType
(
DaoConst
.
SQL_TYPE_
SAVE_WITH
);
if
(
sqlArray
!=
null
)
{
if
(
sqlArray
!=
null
)
{
for
(
SqlData
sql
:
sqlArray
)
{
for
(
SqlData
sql
:
sqlArray
)
{
this
.
checkExist
(
sql
.
getName
(),
model
,
String
.
format
(
"%s已经存在"
,
sql
.
getName
()));
this
.
checkExist
(
sql
.
getName
(),
model
,
String
.
format
(
"%s已经存在"
,
sql
.
getName
()));
...
...
yzg-util-db/src/main/java/com/yanzuoguang/dao/impl/TableStruct.java
View file @
1dd16657
...
@@ -2,11 +2,11 @@ package com.yanzuoguang.dao.impl;
...
@@ -2,11 +2,11 @@ package com.yanzuoguang.dao.impl;
import
com.yanzuoguang.dao.DaoConst
;
import
com.yanzuoguang.dao.DaoConst
;
import
com.yanzuoguang.dao.TableAnnotation
;
import
com.yanzuoguang.dao.TableAnnotation
;
import
com.yanzuoguang.util.helper.DateHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.base.MethodField
;
import
com.yanzuoguang.util.base.MethodField
;
import
com.yanzuoguang.util.base.ObjectHelper
;
import
com.yanzuoguang.util.base.ObjectHelper
;
import
java.lang.reflect.Field
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
...
@@ -353,6 +353,33 @@ public class TableStruct {
...
@@ -353,6 +353,33 @@ public class TableStruct {
if
(!
StringHelper
.
isEmpty
(
this
.
name
))
{
if
(!
StringHelper
.
isEmpty
(
this
.
name
))
{
table
.
add
(
releaseSqlCreate
(),
releaseSqlUpdate
(),
releaseSqlRemove
(),
releaseSqlLoad
());
table
.
add
(
releaseSqlCreate
(),
releaseSqlUpdate
(),
releaseSqlRemove
(),
releaseSqlLoad
());
}
}
initSaveWith
(
table
);
initAddGroup
(
table
);
}
/**
* 初始化SaveWith
*/
private
void
initSaveWith
(
TableSqlCache
table
)
{
List
<
TableFieldVo
>
saveWithField
=
getFieldActionList
(
DaoConst
.
FIELD_SAVE_WITH
);
if
(
saveWithField
==
null
||
saveWithField
.
isEmpty
())
{
return
;
}
this
.
addSaveWithSql
(
table
,
DaoConst
.
SAVE_WITH
,
saveWithField
);
}
/**
* 初始化添加统计SQL语句
*/
private
void
initAddGroup
(
TableSqlCache
table
)
{
List
<
TableFieldVo
>
addGroupField
=
getFieldActionList
(
DaoConst
.
FIELD_ADD_GROUP
);
if
(
addGroupField
==
null
||
addGroupField
.
isEmpty
())
{
return
;
}
List
<
TableFieldVo
>
commonField
=
getFieldActionList
(
DaoConst
.
FIELD_COMMON
,
DaoConst
.
FIELD_ADD_GROUP
,
DaoConst
.
FIELD_MD5
,
DaoConst
.
FIELD_REMOVE
,
DaoConst
.
FIELD_REMOVE_UPDATE
,
DaoConst
.
FIELD_CREATE
);
this
.
addGroupSql
(
table
,
commonField
,
addGroupField
);
}
}
/**
/**
...
@@ -520,35 +547,10 @@ public class TableStruct {
...
@@ -520,35 +547,10 @@ public class TableStruct {
}
}
}
}
/**
* 生成统计的SQL语句
*
* @param sqlTableData 需要生成的实体
* @param whereFields WHERE字段
* @param updateFields 需要增加的值的字段
*/
public
void
addGroupSql
(
TableSqlCache
sqlTableData
,
TableFieldString
whereFields
,
TableFieldString
updateFields
)
{
sqlTableData
.
add
(
this
.
releaseSqlWhere
(
DaoConst
.
GROUP_QUERY
,
DaoConst
.
LOAD_MODEL
,
whereFields
));
sqlTableData
.
add
(
this
.
releaseSql
(
DaoConst
.
GROUP_ADD
,
DaoConst
.
UPDATE_MODEL
,
DaoConst
.
CODE_GROUP_ADD
,
updateFields
,
new
TableFieldString
(
this
.
getKey
().
name
)));
}
/**
* 生成SQL语句
*
* @param name
* @param model
* @param whereFields
* @return
*/
public
SqlData
releaseSqlWhere
(
String
name
,
String
model
,
TableFieldString
whereFields
)
{
return
this
.
releaseSql
(
name
,
model
,
StringHelper
.
EMPTY
,
new
TableFieldString
(),
whereFields
);
}
/**
/**
* 生成SQL语句
* 生成SQL语句
*
*
* @param sqlType SQL语句类型
* @param name SQL语句名称
* @param name SQL语句名称
* @param model SQL语句模板
* @param model SQL语句模板
* @param valueModel 值字段模板
* @param valueModel 值字段模板
...
@@ -556,60 +558,99 @@ public class TableStruct {
...
@@ -556,60 +558,99 @@ public class TableStruct {
* @param whereFields WHERE字段
* @param whereFields WHERE字段
* @return
* @return
*/
*/
p
ublic
SqlData
releaseSql
(
String
name
,
String
model
,
String
valueModel
,
TableFieldString
valueFields
,
TableFieldString
whereFields
)
{
p
rivate
SqlData
releaseSql
(
int
sqlType
,
String
name
,
String
model
,
String
valueModel
,
List
<
TableFieldVo
>
valueFields
,
List
<
TableFieldVo
>
whereFields
)
{
// 参数字段
// 参数字段
List
<
String
>
paraFields
=
new
ArrayList
<
String
>();
List
<
String
>
paraFields
=
new
ArrayList
<
String
>();
// 生成修改的SQL语句
SqlData
sql
=
new
SqlData
(
name
,
model
.
replace
(
DaoConst
.
TABLE_CODE
,
this
.
name
));
sql
.
setSqlType
(
sqlType
);
// 生成添加的SQL语句
// 生成添加的SQL语句
String
Builder
sbField
=
new
StringBuilder
()
;
String
flag
=
StringHelper
.
EMPTY
;
for
(
String
field
:
valueFields
.
getFields
()
)
{
for
(
TableFieldVo
field
:
valueFields
)
{
if
(
sbField
.
length
()
>
0
)
{
sql
.
addParaConst
(
field
.
inputName
,
DaoConst
.
FIELD_CODE
,
flag
+
valueModel
.
replace
(
DaoConst
.
FIELD_CODE
,
field
.
name
));
sbField
.
append
(
","
)
;
flag
=
DaoConst
.
CODE_SPLIT
;
}
}
sbField
.
append
(
valueModel
.
replace
(
DaoConst
.
FIELD_CODE
,
field
));
paraFields
.
add
(
field
);
for
(
TableFieldVo
field
:
whereFields
)
{
sql
.
addParaConst
(
field
.
inputName
,
DaoConst
.
WHERE_CODE
,
String
.
format
(
DaoConst
.
CODE_WHERE_EQUALS_PARA
,
field
.
name
));
}
}
StringBuilder
sbWhere
=
new
StringBuilder
();
return
sql
;
for
(
String
field
:
whereFields
.
getFields
())
{
sbWhere
.
append
(
" AND "
);
sbWhere
.
append
(
field
);
sbWhere
.
append
(
"=?"
);
paraFields
.
add
(
field
);
}
}
String
[]
fields
=
new
String
[
paraFields
.
size
()];
/**
fields
=
paraFields
.
toArray
(
fields
);
* 根据来源字符串获取结束字符串
// 生成修改的SQL语句
*
String
sql
=
model
.
replace
(
DaoConst
.
TABLE_CODE
,
this
.
name
)
* @param fieldFrom 来源字符串
.
replace
(
DaoConst
.
FIELD_CODE
,
sbField
.
toString
())
* @return 返回字符串
.
replace
(
DaoConst
.
WHERE_CODE
,
sbWhere
.
toString
());
*/
SqlData
ret
=
new
SqlData
(
name
,
sql
,
fields
);
private
List
<
TableFieldVo
>
getFieldString
(
TableFieldString
fieldFrom
)
{
return
ret
;
List
<
TableFieldVo
>
list
=
new
ArrayList
<>();
for
(
String
fieldName
:
fieldFrom
.
getFields
())
{
list
.
add
(
this
.
getField
(
fieldName
));
}
return
list
;
}
}
/**
/**
* 生成根据某些字段不存在则保存的SQL语句
* 生成根据某些字段不存在则保存的SQL语句
*
*
* @param tableStruct
* @param tableStruct
表结构
* @param sqlName
* @param sqlName
SQL语句
* @param whereFields
* @param whereFields
WHERE条件
*/
*/
public
void
addSaveWithSql
(
TableSqlCache
tableStruct
,
String
sqlName
,
TableFieldString
whereFields
)
{
public
void
addSaveWithSql
(
TableSqlCache
tableStruct
,
String
sqlName
,
TableFieldString
whereFields
)
{
tableStruct
.
add
(
this
.
releaseSqlWhere
(
sqlName
,
DaoConst
.
LOAD_MODEL
,
whereFields
));
addSaveWithSql
(
tableStruct
,
sqlName
,
getFieldString
(
whereFields
));
}
/**
* 生成根据某些字段不存在则保存的SQL语句
*
* @param tableStruct 表结构
* @param sqlName SQL语句
* @param whereFields WHERE条件
*/
private
void
addSaveWithSql
(
TableSqlCache
tableStruct
,
String
sqlName
,
List
<
TableFieldVo
>
whereFields
)
{
SqlData
sqlData
=
this
.
releaseSql
(
DaoConst
.
SQL_TYPE_SAVE_WITH
,
sqlName
,
DaoConst
.
LOAD_MODEL
,
StringHelper
.
EMPTY
,
new
ArrayList
<>(),
whereFields
);
tableStruct
.
add
(
sqlData
);
}
/**
* 生成统计的SQL语句
*
* @param sqlTableData 需要生成的实体
* @param whereFields WHERE字段
* @param updateFields 需要增加的值的字段
*/
public
void
addGroupSql
(
TableSqlCache
sqlTableData
,
TableFieldString
whereFields
,
TableFieldString
updateFields
)
{
addGroupSql
(
sqlTableData
,
getFieldString
(
whereFields
),
getFieldString
(
updateFields
));
}
/**
* 生成统计的SQL语句
*
* @param sqlTableData 需要生成的实体
* @param whereFields WHERE字段
* @param updateFields 需要增加的值的字段
*/
private
void
addGroupSql
(
TableSqlCache
sqlTableData
,
List
<
TableFieldVo
>
whereFields
,
List
<
TableFieldVo
>
updateFields
)
{
sqlTableData
.
add
(
this
.
releaseSql
(
DaoConst
.
SQL_TYPE_ADD_GROUP
,
DaoConst
.
GROUP_QUERY
,
DaoConst
.
LOAD_MODEL
,
StringHelper
.
EMPTY
,
new
ArrayList
<>(),
whereFields
));
sqlTableData
.
add
(
this
.
releaseSql
(
DaoConst
.
SQL_TYPE_ADD_GROUP
,
DaoConst
.
GROUP_ADD
,
DaoConst
.
UPDATE_MODEL
,
DaoConst
.
CODE_GROUP_ADD
,
updateFields
,
this
.
getFieldActionList
(
DaoConst
.
FIELD_PRIMARY
)));
}
}
/**
/**
* 生成判断数据是否存在的SQL语句
* 生成判断数据是否存在的SQL语句
*
*
* @param sqlTableData
* @param sqlTableData
表结构
* @param sqlName
* @param sqlName
SQL语句的名称
* @param fields
* @param fields
需要判断的字段
*/
*/
public
void
addExist
(
TableSqlCache
sqlTableData
,
String
sqlName
,
String
[]
fields
)
{
public
void
addExist
(
TableSqlCache
sqlTableData
,
String
sqlName
,
String
[]
fields
)
{
String
text
=
DaoConst
.
LOAD_MODEL
.
replace
(
DaoConst
.
TABLE_CODE
,
this
.
name
);
String
text
=
DaoConst
.
LOAD_MODEL
.
replace
(
DaoConst
.
TABLE_CODE
,
this
.
name
);
SqlData
sql
=
new
SqlData
(
sqlName
,
text
);
SqlData
sql
=
new
SqlData
(
sqlName
,
text
);
sql
.
setSqlType
(
DaoConst
.
SQL_TYPE_
EXINTS
);
sql
.
setSqlType
(
DaoConst
.
SQL_TYPE_
SAVE_WITH
);
sql
.
addConst
(
this
.
getKey
().
inputName
,
sql
.
addConst
(
this
.
getKey
().
inputName
,
String
.
format
(
DaoConst
.
CODE_WHERE_NOT_EQUALS_PARA
,
this
.
getKey
().
name
)
String
.
format
(
DaoConst
.
CODE_WHERE_NOT_EQUALS_PARA
,
this
.
getKey
().
name
)
);
);
...
...
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