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
d367dd7b
Commit
d367dd7b
authored
May 07, 2019
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
消除成功接收处理
parent
4d5ca41b
Changes
43
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
43 changed files
with
621 additions
and
389 deletions
+621
-389
ObjectHelper.java
...src/main/java/com/yanzuoguang/util/base/ObjectHelper.java
+1
-1
MemoryCache.java
...src/main/java/com/yanzuoguang/util/cache/MemoryCache.java
+1
-1
MemoryCacheCenter.java
...in/java/com/yanzuoguang/util/cache/MemoryCacheCenter.java
+3
-3
ConfigBase.java
...src/main/java/com/yanzuoguang/util/extend/ConfigBase.java
+2
-2
DateHelper.java
...src/main/java/com/yanzuoguang/util/helper/DateHelper.java
+10
-8
EnumHelper.java
...src/main/java/com/yanzuoguang/util/helper/EnumHelper.java
+1
-1
Event.java
...base/src/main/java/com/yanzuoguang/util/helper/Event.java
+12
-10
EventRun.java
...e/src/main/java/com/yanzuoguang/util/helper/EventRun.java
+1
-1
StringHelper.java
...c/main/java/com/yanzuoguang/util/helper/StringHelper.java
+5
-5
UrlHelper.java
.../src/main/java/com/yanzuoguang/util/helper/UrlHelper.java
+3
-2
TableHead.java
...e/src/main/java/com/yanzuoguang/util/table/TableHead.java
+18
-16
TableHeadItem.java
...c/main/java/com/yanzuoguang/util/table/TableHeadItem.java
+24
-24
AbstractThreadList.java
.../java/com/yanzuoguang/util/thread/AbstractThreadList.java
+19
-25
RunExecute.java
...src/main/java/com/yanzuoguang/util/thread/RunExecute.java
+1
-2
RunInterval.java
...rc/main/java/com/yanzuoguang/util/thread/RunInterval.java
+14
-14
RunPlan.java
...se/src/main/java/com/yanzuoguang/util/thread/RunPlan.java
+36
-24
RunnableList.java
...c/main/java/com/yanzuoguang/util/thread/RunnableList.java
+1
-1
RunnableListAuto.java
...in/java/com/yanzuoguang/util/thread/RunnableListAuto.java
+11
-11
RunnableListAutoItem.java
...ava/com/yanzuoguang/util/thread/RunnableListAutoItem.java
+32
-32
ThreadHelper.java
...c/main/java/com/yanzuoguang/util/thread/ThreadHelper.java
+13
-13
ThreadWait.java
...src/main/java/com/yanzuoguang/util/thread/ThreadWait.java
+2
-2
BaseRequestAspect.java
...ain/java/com/yanzuoguang/cloud/aop/BaseRequestAspect.java
+1
-1
WebAspect.java
...ud/src/main/java/com/yanzuoguang/cloud/aop/WebAspect.java
+1
-1
DaoConst.java
yzg-util-db/src/main/java/com/yanzuoguang/dao/DaoConst.java
+25
-14
BaseDaoImpl.java
...b/src/main/java/com/yanzuoguang/dao/impl/BaseDaoImpl.java
+24
-24
BaseDaoSql.java
...db/src/main/java/com/yanzuoguang/dao/impl/BaseDaoSql.java
+26
-26
CaseSqlModel.java
.../src/main/java/com/yanzuoguang/dao/impl/CaseSqlModel.java
+145
-0
SqlData.java
...il-db/src/main/java/com/yanzuoguang/dao/impl/SqlData.java
+28
-8
SqlDataField.java
.../src/main/java/com/yanzuoguang/dao/impl/SqlDataField.java
+1
-1
TableFieldString.java
.../main/java/com/yanzuoguang/dao/impl/TableFieldString.java
+14
-4
TableFieldVo.java
.../src/main/java/com/yanzuoguang/dao/impl/TableFieldVo.java
+1
-1
TableSqlCache.java
...src/main/java/com/yanzuoguang/dao/impl/TableSqlCache.java
+45
-29
TableStruct.java
...b/src/main/java/com/yanzuoguang/dao/impl/TableStruct.java
+79
-58
DbExecute.java
yzg-util-db/src/main/java/com/yanzuoguang/db/DbExecute.java
+1
-1
AllBeanRowMapper.java
...c/main/java/com/yanzuoguang/db/impl/AllBeanRowMapper.java
+3
-5
DbExecuteImpl.java
.../src/main/java/com/yanzuoguang/db/impl/DbExecuteImpl.java
+1
-2
DbPrintSql.java
...-db/src/main/java/com/yanzuoguang/db/impl/DbPrintSql.java
+1
-1
DbRow.java
yzg-util-db/src/main/java/com/yanzuoguang/db/impl/DbRow.java
+1
-1
BaseServiceImpl.java
...in/java/com/yanzuoguang/service/impl/BaseServiceImpl.java
+1
-1
MessageDaoImpl.java
...main/java/com/yanzuoguang/mq/dao/impl/MessageDaoImpl.java
+5
-5
QueueDaoImpl.java
...c/main/java/com/yanzuoguang/mq/dao/impl/QueueDaoImpl.java
+6
-6
MqService.java
...q/src/main/java/com/yanzuoguang/mq/service/MqService.java
+1
-1
MqServiceImpl.java
...n/java/com/yanzuoguang/mq/service/impl/MqServiceImpl.java
+1
-1
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/base/ObjectHelper.java
View file @
d367dd7b
...
@@ -311,7 +311,7 @@ public class ObjectHelper {
...
@@ -311,7 +311,7 @@ public class ObjectHelper {
}
}
String
methodNameSource
=
method
.
getName
();
String
methodNameSource
=
method
.
getName
();
String
methodNameSimple
=
methodNameSource
.
toLowerCase
();
String
methodNameSimple
=
methodNameSource
.
toLowerCase
();
if
(
methodNameSource
.
equals
(
"getClass"
))
{
if
(
"getClass"
.
equals
(
methodNameSource
))
{
continue
;
continue
;
}
else
if
(
methodNameSimple
.
startsWith
(
"set"
))
{
}
else
if
(
methodNameSimple
.
startsWith
(
"set"
))
{
if
(
method
.
getParameterTypes
().
length
!=
1
)
{
if
(
method
.
getParameterTypes
().
length
!=
1
)
{
...
...
yzg-util-base/src/main/java/com/yanzuoguang/util/cache/MemoryCache.java
View file @
d367dd7b
...
@@ -230,7 +230,7 @@ public class MemoryCache<T> {
...
@@ -230,7 +230,7 @@ public class MemoryCache<T> {
* @throws Throwable
* @throws Throwable
*/
*/
@Override
@Override
protected
void
finalize
()
throws
Throwable
{
protected
void
finalize
(){
this
.
close
();
this
.
close
();
}
}
}
}
yzg-util-base/src/main/java/com/yanzuoguang/util/cache/MemoryCacheCenter.java
View file @
d367dd7b
...
@@ -2,7 +2,7 @@ package com.yanzuoguang.util.cache;
...
@@ -2,7 +2,7 @@ package com.yanzuoguang.util.cache;
import
com.yanzuoguang.util.extend.ConfigBase
;
import
com.yanzuoguang.util.extend.ConfigBase
;
import
com.yanzuoguang.util.thread.ThreadHelper
;
import
com.yanzuoguang.util.thread.ThreadHelper
;
import
com.yanzuoguang.util.thread.ThreadList
;
import
com.yanzuoguang.util.thread.
Abstract
ThreadList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Vector
;
import
java.util.Vector
;
...
@@ -32,7 +32,7 @@ public class MemoryCacheCenter {
...
@@ -32,7 +32,7 @@ public class MemoryCacheCenter {
do
{
do
{
clear
();
clear
();
// 等待1秒
// 等待1秒
ThreadHelper
.
sleep
(
ConfigBase
.
M
emoryClearTimeout
);
ThreadHelper
.
sleep
(
ConfigBase
.
M
EMORY_CLEAR_TIMEOUT
);
}
while
(
true
);
}
while
(
true
);
}
}
});
});
...
@@ -44,7 +44,7 @@ public class MemoryCacheCenter {
...
@@ -44,7 +44,7 @@ public class MemoryCacheCenter {
private
static
void
clear
()
{
private
static
void
clear
()
{
// todo: 需要修改
// todo: 需要修改
// 死循环处理
// 死循环处理
ThreadList
<
MemoryCache
>
threadList
=
new
ThreadList
<
MemoryCache
>(
1
)
{
AbstractThreadList
<
MemoryCache
>
threadList
=
new
Abstract
ThreadList
<
MemoryCache
>(
1
)
{
@Override
@Override
public
void
run
(
MemoryCache
item
)
{
public
void
run
(
MemoryCache
item
)
{
item
.
clearTimeout
();
item
.
clearTimeout
();
...
...
yzg-util-base/src/main/java/com/yanzuoguang/util/extend/ConfigBase.java
View file @
d367dd7b
...
@@ -10,12 +10,12 @@ public class ConfigBase {
...
@@ -10,12 +10,12 @@ public class ConfigBase {
/**
/**
* 打印线程相关参数
* 打印线程相关参数
*/
*/
public
static
final
boolean
P
rintThread
=
false
;
public
static
final
boolean
P
RINT_THREAD
=
false
;
/**
/**
* 内存缓存自动清除时间
* 内存缓存自动清除时间
*/
*/
public
static
final
int
M
emoryClearTimeout
=
5
*
1000
;
public
static
final
int
M
EMORY_CLEAR_TIMEOUT
=
5
*
1000
;
/**
/**
* 写入日志对象
* 写入日志对象
...
...
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/DateHelper.java
View file @
d367dd7b
...
@@ -17,7 +17,6 @@ public class DateHelper {
...
@@ -17,7 +17,6 @@ public class DateHelper {
private
static
final
String
FORMAT_DAY_STRING
=
"yyyy-MM-dd"
;
private
static
final
String
FORMAT_DAY_STRING
=
"yyyy-MM-dd"
;
private
static
final
String
FORMAT_SECOND_STRING
=
"yyyy-MM-dd HH:mm:ss"
;
private
static
final
String
FORMAT_SECOND_STRING
=
"yyyy-MM-dd HH:mm:ss"
;
private
static
SimpleDateFormat
FORMAT_DAY
=
new
SimpleDateFormat
(
FORMAT_DAY_STRING
);
/**
/**
* 获取时间
* 获取时间
...
@@ -423,12 +422,12 @@ public class DateHelper {
...
@@ -423,12 +422,12 @@ public class DateHelper {
public
static
String
getWeekName1
(
Date
date
)
{
public
static
String
getWeekName1
(
Date
date
)
{
Calendar
cal
=
Calendar
.
getInstance
();
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
setTime
(
date
);
cal
.
setTime
(
date
);
int
week
_i
ndex
=
cal
.
get
(
Calendar
.
DAY_OF_WEEK
)
-
1
;
int
week
I
ndex
=
cal
.
get
(
Calendar
.
DAY_OF_WEEK
)
-
1
;
if
(
week
_i
ndex
<
0
)
{
if
(
week
I
ndex
<
0
)
{
week
_i
ndex
=
0
;
week
I
ndex
=
0
;
}
}
String
[]
weeks
=
{
"星期日"
,
"星期一"
,
"星期二"
,
"星期三"
,
"星期四"
,
"星期五"
,
"星期六"
};
String
[]
weeks
=
{
"星期日"
,
"星期一"
,
"星期二"
,
"星期三"
,
"星期四"
,
"星期五"
,
"星期六"
};
return
weeks
[
week
_i
ndex
];
return
weeks
[
week
I
ndex
];
}
}
/**
/**
...
@@ -574,7 +573,8 @@ public class DateHelper {
...
@@ -574,7 +573,8 @@ public class DateHelper {
return
from
;
return
from
;
}
}
try
{
try
{
return
FORMAT_DAY
.
format
(
FORMAT_DAY
.
parse
(
from
));
SimpleDateFormat
format
=
new
SimpleDateFormat
(
FORMAT_DAY_STRING
);
return
format
.
format
(
format
.
parse
(
from
));
}
catch
(
ParseException
e
)
{
}
catch
(
ParseException
e
)
{
ExceptionHelper
.
handleException
(
DateHelper
.
class
,
e
,
from
);
ExceptionHelper
.
handleException
(
DateHelper
.
class
,
e
,
from
);
}
}
...
@@ -588,7 +588,8 @@ public class DateHelper {
...
@@ -588,7 +588,8 @@ public class DateHelper {
* @return 获取到的日期字符串
* @return 获取到的日期字符串
*/
*/
public
static
String
toDay
(
Date
date
)
{
public
static
String
toDay
(
Date
date
)
{
return
FORMAT_DAY
.
format
(
date
);
SimpleDateFormat
format
=
new
SimpleDateFormat
(
FORMAT_DAY_STRING
);
return
format
.
format
(
date
);
}
}
/**
/**
...
@@ -598,7 +599,8 @@ public class DateHelper {
...
@@ -598,7 +599,8 @@ public class DateHelper {
* @return 获取到的日期字符串
* @return 获取到的日期字符串
*/
*/
public
static
String
toDay
(
long
date
)
{
public
static
String
toDay
(
long
date
)
{
return
FORMAT_DAY
.
format
(
new
Date
(
date
));
SimpleDateFormat
format
=
new
SimpleDateFormat
(
FORMAT_DAY_STRING
);
return
format
.
format
(
new
Date
(
date
));
}
}
/**
/**
...
...
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/EnumHelper.java
View file @
d367dd7b
...
@@ -57,7 +57,7 @@ public class EnumHelper {
...
@@ -57,7 +57,7 @@ public class EnumHelper {
Method
[]
vMets
=
vType
.
getMethods
();
Method
[]
vMets
=
vType
.
getMethods
();
for
(
Method
vMet
:
vMets
)
{
for
(
Method
vMet
:
vMets
)
{
String
vName
=
vMet
.
getName
();
String
vName
=
vMet
.
getName
();
if
(
vName
.
equals
(
"forValue"
)
if
(
"forValue"
.
equals
(
vName
)
&&
vMet
.
getParameterTypes
().
length
==
1
)
{
&&
vMet
.
getParameterTypes
().
length
==
1
)
{
Class
vTempType
=
vMet
.
getParameterTypes
()[
0
];
Class
vTempType
=
vMet
.
getParameterTypes
()[
0
];
Object
obj
=
vMet
.
invoke
(
null
,
i
);
Object
obj
=
vMet
.
invoke
(
null
,
i
);
...
...
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/Event.java
View file @
d367dd7b
...
@@ -9,8 +9,10 @@ import java.util.List;
...
@@ -9,8 +9,10 @@ import java.util.List;
* @param <T>
* @param <T>
*/
*/
public
class
Event
<
T
>
{
public
class
Event
<
T
>
{
// 事件列表
/**
private
List
<
T
>
m_List
=
new
ArrayList
<>();
* 事件列表
*/
private
List
<
T
>
list
=
new
ArrayList
<>();
/**
/**
* 添加处理对象
* 添加处理对象
...
@@ -19,7 +21,7 @@ public class Event<T> {
...
@@ -19,7 +21,7 @@ public class Event<T> {
*/
*/
public
void
add
(
T
t
)
{
public
void
add
(
T
t
)
{
if
(
t
!=
null
)
{
if
(
t
!=
null
)
{
m_L
ist
.
add
(
t
);
l
ist
.
add
(
t
);
}
}
}
}
...
@@ -31,8 +33,8 @@ public class Event<T> {
...
@@ -31,8 +33,8 @@ public class Event<T> {
* @throws Exception
* @throws Exception
*/
*/
public
<
M
extends
EventRun
<
T
>>
void
exeucte
(
M
m
)
throws
Exception
{
public
<
M
extends
EventRun
<
T
>>
void
exeucte
(
M
m
)
throws
Exception
{
for
(
T
item
:
m_L
ist
)
{
for
(
T
item
:
l
ist
)
{
m
.
Execute
(
item
);
m
.
run
(
item
);
}
}
}
}
...
@@ -44,7 +46,7 @@ public class Event<T> {
...
@@ -44,7 +46,7 @@ public class Event<T> {
*/
*/
public
boolean
remove
(
T
t
)
{
public
boolean
remove
(
T
t
)
{
if
(
t
!=
null
)
{
if
(
t
!=
null
)
{
return
m_L
ist
.
remove
(
t
);
return
l
ist
.
remove
(
t
);
}
}
return
false
;
return
false
;
}
}
...
@@ -53,7 +55,7 @@ public class Event<T> {
...
@@ -53,7 +55,7 @@ public class Event<T> {
* 清除所有事件
* 清除所有事件
*/
*/
public
void
clear
()
{
public
void
clear
()
{
m_L
ist
.
clear
();
l
ist
.
clear
();
}
}
/**
/**
...
@@ -64,7 +66,7 @@ public class Event<T> {
...
@@ -64,7 +66,7 @@ public class Event<T> {
*/
*/
public
boolean
contants
(
T
t
)
{
public
boolean
contants
(
T
t
)
{
if
(
t
!=
null
)
{
if
(
t
!=
null
)
{
return
m_L
ist
.
contains
(
t
);
return
l
ist
.
contains
(
t
);
}
}
return
false
;
return
false
;
}
}
...
@@ -75,7 +77,7 @@ public class Event<T> {
...
@@ -75,7 +77,7 @@ public class Event<T> {
* @return 事件列表集合
* @return 事件列表集合
*/
*/
public
List
<
T
>
getList
()
{
public
List
<
T
>
getList
()
{
return
m_L
ist
;
return
l
ist
;
}
}
/**
/**
...
@@ -84,6 +86,6 @@ public class Event<T> {
...
@@ -84,6 +86,6 @@ public class Event<T> {
* @return 长度
* @return 长度
*/
*/
public
int
size
()
{
public
int
size
()
{
return
m_L
ist
.
size
();
return
l
ist
.
size
();
}
}
}
}
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/EventRun.java
View file @
d367dd7b
...
@@ -13,5 +13,5 @@ public interface EventRun<T> {
...
@@ -13,5 +13,5 @@ public interface EventRun<T> {
* @param t 接口
* @param t 接口
* @throws Exception 异常错误
* @throws Exception 异常错误
*/
*/
void
Execute
(
T
t
)
throws
Exception
;
void
run
(
T
t
)
throws
Exception
;
}
}
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/StringHelper.java
View file @
d367dd7b
...
@@ -258,7 +258,7 @@ public class StringHelper {
...
@@ -258,7 +258,7 @@ public class StringHelper {
}
else
if
(
type
.
equals
(
vBase
))
{
}
else
if
(
type
.
equals
(
vBase
))
{
return
true
;
return
true
;
}
}
if
(
type
.
toString
().
equals
(
"System.Object"
))
{
if
(
"System.Object"
.
equals
(
type
.
toString
()
))
{
return
false
;
return
false
;
}
else
{
}
else
{
return
isType
(
type
.
getSuperclass
(),
vBase
);
return
isType
(
type
.
getSuperclass
(),
vBase
);
...
@@ -467,10 +467,10 @@ public class StringHelper {
...
@@ -467,10 +467,10 @@ public class StringHelper {
* @return 转换成功后的值
* @return 转换成功后的值
*/
*/
public
static
double
toDecimal
(
Object
from
)
{
public
static
double
toDecimal
(
Object
from
)
{
Double
result
=
new
Double
(
0
);
Double
result
=
Double
.
valueOf
(
0
);
try
{
try
{
if
(!
isEmpty
(
from
))
{
if
(!
isEmpty
(
from
))
{
result
=
new
Double
(
from
.
toString
());
result
=
Double
.
valueOf
(
from
.
toString
());
}
}
}
catch
(
Exception
ex
)
{
}
catch
(
Exception
ex
)
{
ExceptionHelper
.
handleException
(
StringHelper
.
class
,
ex
,
from
);
ExceptionHelper
.
handleException
(
StringHelper
.
class
,
ex
,
from
);
...
@@ -768,7 +768,7 @@ public class StringHelper {
...
@@ -768,7 +768,7 @@ public class StringHelper {
// 使用指定的字节数组更新摘要。
// 使用指定的字节数组更新摘要。
md
.
update
(
from
.
getBytes
());
md
.
update
(
from
.
getBytes
());
// 通过执行诸如填充之类的最终操作完成哈希计算。
// 通过执行诸如填充之类的最终操作完成哈希计算。
byte
b
[]
=
md
.
digest
();
byte
[]
b
=
md
.
digest
();
// 生成具体的md5密码到buf数组
// 生成具体的md5密码到buf数组
int
i
;
int
i
;
StringBuilder
buf
=
new
StringBuilder
();
StringBuilder
buf
=
new
StringBuilder
();
...
@@ -882,7 +882,7 @@ public class StringHelper {
...
@@ -882,7 +882,7 @@ public class StringHelper {
*/
*/
public
static
String
getCamelCase
(
String
from
)
{
public
static
String
getCamelCase
(
String
from
)
{
StringBuilder
result
=
new
StringBuilder
();
StringBuilder
result
=
new
StringBuilder
();
String
a
[]
=
from
.
split
(
"_"
);
String
[]
a
=
from
.
split
(
"_"
);
for
(
String
s
:
a
)
{
for
(
String
s
:
a
)
{
if
(
result
.
length
()
==
0
)
{
if
(
result
.
length
()
==
0
)
{
result
.
append
(
s
.
substring
(
0
,
1
).
toLowerCase
());
result
.
append
(
s
.
substring
(
0
,
1
).
toLowerCase
());
...
...
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/UrlHelper.java
View file @
d367dd7b
...
@@ -62,7 +62,7 @@ public class UrlHelper {
...
@@ -62,7 +62,7 @@ public class UrlHelper {
return
ips
.
get
(
0
);
return
ips
.
get
(
0
);
}
}
for
(
String
ip
:
ips
)
{
for
(
String
ip
:
ips
)
{
if
(
ip
.
equals
(
"127.0.0.1"
)
||
ip
.
equals
(
"0.0.0.0"
))
{
if
(
"127.0.0.1"
.
equals
(
ip
)
||
"0.0.0.0"
.
equals
(
ip
))
{
continue
;
continue
;
}
}
return
ip
;
return
ip
;
...
@@ -84,7 +84,8 @@ public class UrlHelper {
...
@@ -84,7 +84,8 @@ public class UrlHelper {
Enumeration
<
InetAddress
>
inetAddresses
=
networkInterface
.
getInetAddresses
();
Enumeration
<
InetAddress
>
inetAddresses
=
networkInterface
.
getInetAddresses
();
while
(
inetAddresses
.
hasMoreElements
())
{
while
(
inetAddresses
.
hasMoreElements
())
{
InetAddress
inetAddress
=
inetAddresses
.
nextElement
();
InetAddress
inetAddress
=
inetAddresses
.
nextElement
();
if
(
inetAddress
!=
null
&&
inetAddress
instanceof
Inet4Address
)
{
// IPV4
// IPV4
if
(
inetAddress
!=
null
&&
inetAddress
instanceof
Inet4Address
)
{
String
ip
=
inetAddress
.
getHostAddress
();
String
ip
=
inetAddress
.
getHostAddress
();
ipList
.
add
(
ip
);
ipList
.
add
(
ip
);
}
}
...
...
yzg-util-base/src/main/java/com/yanzuoguang/util/table/TableHead.java
View file @
d367dd7b
...
@@ -5,6 +5,8 @@ import java.util.List;
...
@@ -5,6 +5,8 @@ import java.util.List;
/**
/**
* 表格头
* 表格头
*
* @author 颜佐光
*/
*/
public
class
TableHead
{
public
class
TableHead
{
...
@@ -12,61 +14,61 @@ public class TableHead {
...
@@ -12,61 +14,61 @@ public class TableHead {
* 构造函数
* 构造函数
*/
*/
public
TableHead
()
{
public
TableHead
()
{
this
.
T
otalColumn
=
0
;
this
.
t
otalColumn
=
0
;
this
.
T
otalRow
=
0
;
this
.
t
otalRow
=
0
;
this
.
D
ataColumn
=
0
;
this
.
d
ataColumn
=
0
;
this
.
C
olumns
=
new
ArrayList
<>();
this
.
c
olumns
=
new
ArrayList
<>();
}
}
/**
/**
* 总行数
* 总行数
*/
*/
private
int
T
otalRow
;
private
int
t
otalRow
;
/**
/**
* 总列数
* 总列数
*/
*/
private
int
T
otalColumn
;
private
int
t
otalColumn
;
/**
/**
* 已添加数据列
* 已添加数据列
*/
*/
private
int
D
ataColumn
;
private
int
d
ataColumn
;
/**
/**
* 列头数
* 列头数
*/
*/
private
List
<
TableHeadItem
>
C
olumns
;
private
List
<
TableHeadItem
>
c
olumns
;
public
int
getTotalRow
()
{
public
int
getTotalRow
()
{
return
T
otalRow
;
return
t
otalRow
;
}
}
public
void
setTotalRow
(
int
totalRow
)
{
public
void
setTotalRow
(
int
totalRow
)
{
T
otalRow
=
totalRow
;
this
.
t
otalRow
=
totalRow
;
}
}
public
int
getTotalColumn
()
{
public
int
getTotalColumn
()
{
return
T
otalColumn
;
return
t
otalColumn
;
}
}
public
void
setTotalColumn
(
int
totalColumn
)
{
public
void
setTotalColumn
(
int
totalColumn
)
{
T
otalColumn
=
totalColumn
;
this
.
t
otalColumn
=
totalColumn
;
}
}
public
int
getDataColumn
()
{
public
int
getDataColumn
()
{
return
D
ataColumn
;
return
d
ataColumn
;
}
}
public
void
setDataColumn
(
int
dataColumn
)
{
public
void
setDataColumn
(
int
dataColumn
)
{
D
ataColumn
=
dataColumn
;
this
.
d
ataColumn
=
dataColumn
;
}
}
public
List
<
TableHeadItem
>
getColumns
()
{
public
List
<
TableHeadItem
>
getColumns
()
{
return
C
olumns
;
return
c
olumns
;
}
}
public
void
setColumns
(
List
<
TableHeadItem
>
columns
)
{
public
void
setColumns
(
List
<
TableHeadItem
>
columns
)
{
C
olumns
=
columns
;
this
.
c
olumns
=
columns
;
}
}
}
}
yzg-util-base/src/main/java/com/yanzuoguang/util/table/TableHeadItem.java
View file @
d367dd7b
...
@@ -8,42 +8,42 @@ public class TableHeadItem {
...
@@ -8,42 +8,42 @@ public class TableHeadItem {
/**
/**
* 最高级别
* 最高级别
*/
*/
private
String
N
ame
;
private
String
n
ame
;
/**
/**
* 路径
* 路径
*/
*/
private
String
P
ath
;
private
String
p
ath
;
/**
/**
* 级别
* 级别
*/
*/
private
int
L
evel
;
private
int
l
evel
;
/**
/**
* 当前列的最大级别
* 当前列的最大级别
*/
*/
private
int
L
evelMax
;
private
int
l
evelMax
;
/**
/**
* 第几行
* 第几行
*/
*/
private
int
R
ow
;
private
int
r
ow
;
/**
/**
* 合并多少行
* 合并多少行
*/
*/
private
int
R
owCell
;
private
int
r
owCell
;
/**
/**
* 第几列
* 第几列
*/
*/
private
int
C
olumn
;
private
int
c
olumn
;
/**
/**
* 合并多少列
* 合并多少列
*/
*/
private
int
C
olumnCell
;
private
int
c
olumnCell
;
/**
/**
* 是否属于数据列
* 是否属于数据列
...
@@ -51,67 +51,67 @@ public class TableHeadItem {
...
@@ -51,67 +51,67 @@ public class TableHeadItem {
private
boolean
dataColumn
;
private
boolean
dataColumn
;
public
String
getName
()
{
public
String
getName
()
{
return
N
ame
;
return
n
ame
;
}
}
public
void
setName
(
String
name
)
{
public
void
setName
(
String
name
)
{
N
ame
=
name
;
this
.
n
ame
=
name
;
}
}
public
String
getPath
()
{
public
String
getPath
()
{
return
P
ath
;
return
p
ath
;
}
}
public
void
setPath
(
String
path
)
{
public
void
setPath
(
String
path
)
{
P
ath
=
path
;
this
.
p
ath
=
path
;
}
}
public
int
getLevel
()
{
public
int
getLevel
()
{
return
L
evel
;
return
l
evel
;
}
}
public
void
setLevel
(
int
level
)
{
public
void
setLevel
(
int
level
)
{
L
evel
=
level
;
this
.
l
evel
=
level
;
}
}
public
int
getLevelMax
()
{
public
int
getLevelMax
()
{
return
L
evelMax
;
return
l
evelMax
;
}
}
public
void
setLevelMax
(
int
levelMax
)
{
public
void
setLevelMax
(
int
levelMax
)
{
L
evelMax
=
levelMax
;
this
.
l
evelMax
=
levelMax
;
}
}
public
int
getRow
()
{
public
int
getRow
()
{
return
R
ow
;
return
r
ow
;
}
}
public
void
setRow
(
int
row
)
{
public
void
setRow
(
int
row
)
{
R
ow
=
row
;
this
.
r
ow
=
row
;
}
}
public
int
getRowCell
()
{
public
int
getRowCell
()
{
return
R
owCell
;
return
r
owCell
;
}
}
public
void
setRowCell
(
int
rowCell
)
{
public
void
setRowCell
(
int
rowCell
)
{
R
owCell
=
rowCell
;
this
.
r
owCell
=
rowCell
;
}
}
public
int
getColumn
()
{
public
int
getColumn
()
{
return
C
olumn
;
return
c
olumn
;
}
}
public
void
setColumn
(
int
column
)
{
public
void
setColumn
(
int
column
)
{
C
olumn
=
column
;
this
.
c
olumn
=
column
;
}
}
public
int
getColumnCell
()
{
public
int
getColumnCell
()
{
return
C
olumnCell
;
return
c
olumnCell
;
}
}
public
void
setColumnCell
(
int
columnCell
)
{
public
void
setColumnCell
(
int
columnCell
)
{
C
olumnCell
=
columnCell
;
this
.
c
olumnCell
=
columnCell
;
}
}
public
boolean
isDataColumn
()
{
public
boolean
isDataColumn
()
{
...
...
yzg-util-base/src/main/java/com/yanzuoguang/util/thread/ThreadList.java
→
yzg-util-base/src/main/java/com/yanzuoguang/util/thread/
Abstract
ThreadList.java
View file @
d367dd7b
...
@@ -3,17 +3,14 @@ package com.yanzuoguang.util.thread;
...
@@ -3,17 +3,14 @@ package com.yanzuoguang.util.thread;
import
com.yanzuoguang.util.helper.DateHelper
;
import
com.yanzuoguang.util.helper.DateHelper
;
import
com.yanzuoguang.util.log.Log
;
import
com.yanzuoguang.util.log.Log
;
import
java.util.Date
;
import
java.util.*
;
import
java.util.Hashtable
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.LinkedBlockingQueue
;
import
java.util.concurrent.LinkedBlockingQueue
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
/**
/**
* 多线程处理队列
* 多线程处理队列
*/
*/
public
abstract
class
ThreadList
<
T
extends
Object
>
implements
ThreadWaitExecute
{
public
abstract
class
Abstract
ThreadList
<
T
extends
Object
>
implements
ThreadWaitExecute
{
private
long
threadID
;
private
long
threadID
;
/**
/**
* 线程等待间隔
* 线程等待间隔
...
@@ -60,7 +57,7 @@ public abstract class ThreadList<T extends Object> implements ThreadWaitExecute
...
@@ -60,7 +57,7 @@ public abstract class ThreadList<T extends Object> implements ThreadWaitExecute
*
*
* @param threadCount
* @param threadCount
*/
*/
public
ThreadList
(
int
threadCount
)
{
public
Abstract
ThreadList
(
int
threadCount
)
{
this
.
threadID
=
Thread
.
currentThread
().
getId
();
this
.
threadID
=
Thread
.
currentThread
().
getId
();
threadCount
=
Math
.
max
(
threadCount
,
0
);
threadCount
=
Math
.
max
(
threadCount
,
0
);
this
.
threadCount
=
threadCount
;
this
.
threadCount
=
threadCount
;
...
@@ -118,17 +115,8 @@ public abstract class ThreadList<T extends Object> implements ThreadWaitExecute
...
@@ -118,17 +115,8 @@ public abstract class ThreadList<T extends Object> implements ThreadWaitExecute
* @param list
* @param list
*/
*/
public
void
add
(
T
...
list
)
{
public
void
add
(
T
...
list
)
{
if
(
list
==
null
||
list
.
length
==
0
)
{
if
(
list
!=
null
)
{
return
;
this
.
add
(
Arrays
.
asList
(
list
));
}
int
size
=
list
.
length
;
this
.
initRowTotal
(
size
);
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
T
item
=
list
[
i
];
if
(
item
==
null
)
{
continue
;
}
this
.
add
(
item
);
}
}
}
}
...
@@ -141,8 +129,14 @@ public abstract class ThreadList<T extends Object> implements ThreadWaitExecute
...
@@ -141,8 +129,14 @@ public abstract class ThreadList<T extends Object> implements ThreadWaitExecute
if
(
list
==
null
||
list
.
size
()
==
0
)
{
if
(
list
==
null
||
list
.
size
()
==
0
)
{
return
;
return
;
}
}
T
[]
to
=
(
T
[])
list
.
toArray
();
int
size
=
list
.
size
();
this
.
add
(
to
);
this
.
initRowTotal
(
size
);
for
(
T
item
:
list
)
{
if
(
item
==
null
)
{
continue
;
}
this
.
add
(
item
);
}
}
}
/**
/**
...
@@ -181,12 +175,12 @@ public abstract class ThreadList<T extends Object> implements ThreadWaitExecute
...
@@ -181,12 +175,12 @@ public abstract class ThreadList<T extends Object> implements ThreadWaitExecute
public
void
run
()
{
public
void
run
()
{
long
threadID
=
Thread
.
currentThread
().
getId
();
long
threadID
=
Thread
.
currentThread
().
getId
();
try
{
try
{
if
(
threadID
!=
ThreadList
.
this
.
threadID
)
{
if
(
threadID
!=
Abstract
ThreadList
.
this
.
threadID
)
{
Log
.
threadBegin
();
Log
.
threadBegin
();
}
}
threadExecute
();
threadExecute
();
}
finally
{
}
finally
{
if
(
threadID
!=
ThreadList
.
this
.
threadID
)
{
if
(
threadID
!=
Abstract
ThreadList
.
this
.
threadID
)
{
Log
.
threadCommit
();
Log
.
threadCommit
();
}
}
}
}
...
@@ -295,7 +289,7 @@ public abstract class ThreadList<T extends Object> implements ThreadWaitExecute
...
@@ -295,7 +289,7 @@ public abstract class ThreadList<T extends Object> implements ThreadWaitExecute
threadListNum
.
addSuccess
();
threadListNum
.
addSuccess
();
}
catch
(
RuntimeException
ex
)
{
}
catch
(
RuntimeException
ex
)
{
threadListNum
.
addError
();
threadListNum
.
addError
();
L
ogError
(
ex
);
l
ogError
(
ex
);
}
}
}
}
...
@@ -321,7 +315,7 @@ public abstract class ThreadList<T extends Object> implements ThreadWaitExecute
...
@@ -321,7 +315,7 @@ public abstract class ThreadList<T extends Object> implements ThreadWaitExecute
* @param log
* @param log
*/
*/
private
void
log
(
String
log
)
{
private
void
log
(
String
log
)
{
Log
.
info
(
ThreadList
.
class
,
log
);
Log
.
info
(
Abstract
ThreadList
.
class
,
log
);
}
}
/**
/**
...
@@ -329,14 +323,14 @@ public abstract class ThreadList<T extends Object> implements ThreadWaitExecute
...
@@ -329,14 +323,14 @@ public abstract class ThreadList<T extends Object> implements ThreadWaitExecute
*
*
* @param ex
* @param ex
*/
*/
private
void
L
ogError
(
RuntimeException
ex
)
{
private
void
l
ogError
(
RuntimeException
ex
)
{
this
.
exception
=
ex
;
this
.
exception
=
ex
;
}
}
/**
/**
* 抛出线程中的异常数据
* 抛出线程中的异常数据
*/
*/
public
ThreadList
<
T
>
throwThreadError
()
{
public
Abstract
ThreadList
<
T
>
throwThreadError
()
{
if
(
this
.
exception
!=
null
)
{
if
(
this
.
exception
!=
null
)
{
throw
this
.
exception
;
throw
this
.
exception
;
}
}
...
...
yzg-util-base/src/main/java/com/yanzuoguang/util/thread/RunExecute.java
View file @
d367dd7b
...
@@ -12,10 +12,9 @@ public class RunExecute implements EventRun<Runnable> {
...
@@ -12,10 +12,9 @@ public class RunExecute implements EventRun<Runnable> {
* 执行时间
* 执行时间
*
*
* @param t 接口 需要执行的对象
* @param t 接口 需要执行的对象
* @throws Exception 跑出异常
*/
*/
@Override
@Override
public
void
Execute
(
Runnable
t
)
{
public
void
run
(
Runnable
t
)
{
t
.
run
();
t
.
run
();
}
}
}
}
yzg-util-base/src/main/java/com/yanzuoguang/util/thread/RunInterval.java
View file @
d367dd7b
...
@@ -7,49 +7,49 @@ public class RunInterval {
...
@@ -7,49 +7,49 @@ public class RunInterval {
/**
/**
* 当前线程
* 当前线程
*/
*/
private
Thread
T
hread
;
private
Thread
t
hread
;
/**
/**
* 间隔时间,毫秒
* 间隔时间,毫秒
*/
*/
private
int
T
ime
;
private
int
t
ime
;
/**
/**
* 执行的代码
* 执行的代码
*/
*/
private
Runnable
C
ode
;
private
Runnable
c
ode
;
/**
/**
* 是否终端
* 是否终端
*/
*/
private
boolean
Break
;
private
boolean
breakFlag
;
public
java
.
lang
.
Thread
getThread
()
{
public
java
.
lang
.
Thread
getThread
()
{
return
T
hread
;
return
t
hread
;
}
}
public
void
setThread
(
java
.
lang
.
Thread
thread
)
{
public
void
setThread
(
java
.
lang
.
Thread
thread
)
{
T
hread
=
thread
;
this
.
t
hread
=
thread
;
}
}
public
int
getTime
()
{
public
int
getTime
()
{
return
T
ime
;
return
t
ime
;
}
}
public
void
setTime
(
int
time
)
{
public
void
setTime
(
int
time
)
{
T
ime
=
time
;
this
.
t
ime
=
time
;
}
}
public
Runnable
getCode
()
{
public
Runnable
getCode
()
{
return
C
ode
;
return
c
ode
;
}
}
public
void
setCode
(
Runnable
code
)
{
public
void
setCode
(
Runnable
code
)
{
C
ode
=
code
;
this
.
c
ode
=
code
;
}
}
public
boolean
isBreak
()
{
public
boolean
isBreak
Flag
()
{
return
Break
;
return
breakFlag
;
}
}
public
void
setBreak
(
boolean
aBreak
)
{
public
void
setBreak
Flag
(
boolean
breakFlag
)
{
Break
=
aBreak
;
this
.
breakFlag
=
breakFlag
;
}
}
}
}
\ No newline at end of file
yzg-util-base/src/main/java/com/yanzuoguang/util/thread/RunPlan.java
View file @
d367dd7b
...
@@ -12,17 +12,29 @@ import java.util.List;
...
@@ -12,17 +12,29 @@ import java.util.List;
* 自动执行任务
* 自动执行任务
*/
*/
public
class
RunPlan
{
public
class
RunPlan
{
// 任务锁
/**
private
Object
m_Lock
=
new
Object
();
* 任务锁
// 任务队列
*/
private
List
<
RunPlanData
>
m_List
=
new
ArrayList
<>();
private
Object
lock
=
new
Object
();
// 增加时触发的事件队列
/**
* 任务队列
*/
private
List
<
RunPlanData
>
list
=
new
ArrayList
<>();
/**
* 增加时触发的事件队列
*/
private
Event
<
Runnable
>
onAdd
=
new
Event
<>();
private
Event
<
Runnable
>
onAdd
=
new
Event
<>();
// 增加时触发的事件队列
/**
* 增加时触发的事件队列
*/
private
Event
<
Runnable
>
onRemove
=
new
Event
<>();
private
Event
<
Runnable
>
onRemove
=
new
Event
<>();
// 单项成功执行时的事件队列
/**
* 单项成功执行时的事件队列
*/
private
Event
<
Runnable
>
onItemExecuted
=
new
Event
<>();
private
Event
<
Runnable
>
onItemExecuted
=
new
Event
<>();
// 全部执行完时触发的事件队列
/**
* 全部执行完时触发的事件队列
*/
private
Event
<
Runnable
>
onExecuted
=
new
Event
<>();
private
Event
<
Runnable
>
onExecuted
=
new
Event
<>();
/**
/**
...
@@ -67,12 +79,12 @@ public class RunPlan {
...
@@ -67,12 +79,12 @@ public class RunPlan {
* @param isRemove 执行完成是否删除
* @param isRemove 执行完成是否删除
* @param maxError 最大错误次数
* @param maxError 最大错误次数
*/
*/
public
final
void
Execute
(
boolean
isRemove
,
int
maxError
)
{
public
final
void
run
(
boolean
isRemove
,
int
maxError
)
{
for
(
int
i
=
m_L
ist
.
size
()
-
1
;
i
>=
0
;
i
--)
{
for
(
int
i
=
l
ist
.
size
()
-
1
;
i
>=
0
;
i
--)
{
Date
now
=
new
Date
();
Date
now
=
new
Date
();
RunPlanData
item
;
RunPlanData
item
;
synchronized
(
this
.
m_L
ock
)
{
synchronized
(
this
.
l
ock
)
{
item
=
m_List
.
size
()
>
i
?
m_L
ist
.
get
(
i
)
:
null
;
item
=
list
.
size
()
>
i
?
l
ist
.
get
(
i
)
:
null
;
}
}
if
(
item
==
null
)
{
if
(
item
==
null
)
{
...
@@ -110,8 +122,8 @@ public class RunPlan {
...
@@ -110,8 +122,8 @@ public class RunPlan {
try
{
try
{
if
(
isRemove
)
{
if
(
isRemove
)
{
synchronized
(
this
.
m_L
ock
)
{
synchronized
(
this
.
l
ock
)
{
this
.
m_L
ist
.
remove
(
i
);
this
.
l
ist
.
remove
(
i
);
this
.
triggerEvent
(
this
.
onRemove
);
this
.
triggerEvent
(
this
.
onRemove
);
}
}
}
}
...
@@ -130,15 +142,15 @@ public class RunPlan {
...
@@ -130,15 +142,15 @@ public class RunPlan {
* @param vTime 间隔时间
* @param vTime 间隔时间
* @return 执行标志
* @return 执行标志
*/
*/
public
final
String
S
et
(
Runnable
run
,
int
vTime
)
{
public
final
String
s
et
(
Runnable
run
,
int
vTime
)
{
// 创建临时任务数据
// 创建临时任务数据
RunPlanData
temp
=
new
RunPlanData
();
RunPlanData
temp
=
new
RunPlanData
();
temp
.
setFlag
(
StringHelper
.
getNewID
());
temp
.
setFlag
(
StringHelper
.
getNewID
());
temp
.
setExecute
(
run
);
temp
.
setExecute
(
run
);
temp
.
setTime
(
vTime
);
temp
.
setTime
(
vTime
);
synchronized
(
m_L
ock
)
{
synchronized
(
l
ock
)
{
m_L
ist
.
add
(
temp
);
l
ist
.
add
(
temp
);
}
}
this
.
triggerEvent
(
this
.
onAdd
);
this
.
triggerEvent
(
this
.
onAdd
);
...
@@ -151,10 +163,10 @@ public class RunPlan {
...
@@ -151,10 +163,10 @@ public class RunPlan {
* @param flag 执行标志
* @param flag 执行标志
*/
*/
public
final
void
remove
(
String
flag
)
{
public
final
void
remove
(
String
flag
)
{
synchronized
(
m_L
ock
)
{
synchronized
(
l
ock
)
{
for
(
RunPlanData
item
:
this
.
m_L
ist
)
{
for
(
RunPlanData
item
:
this
.
l
ist
)
{
if
(
item
.
getFlag
().
equals
(
flag
))
{
if
(
item
.
getFlag
().
equals
(
flag
))
{
this
.
m_L
ist
.
remove
(
item
);
this
.
l
ist
.
remove
(
item
);
this
.
triggerEvent
(
this
.
onRemove
);
this
.
triggerEvent
(
this
.
onRemove
);
break
;
break
;
}
}
...
@@ -168,10 +180,10 @@ public class RunPlan {
...
@@ -168,10 +180,10 @@ public class RunPlan {
* @param run 执行的方法,注意有多个同样的方法时,只会清除第一个
* @param run 执行的方法,注意有多个同样的方法时,只会清除第一个
*/
*/
public
final
void
remove
(
Runnable
run
)
{
public
final
void
remove
(
Runnable
run
)
{
synchronized
(
m_L
ock
)
{
synchronized
(
l
ock
)
{
for
(
RunPlanData
item
:
this
.
m_L
ist
)
{
for
(
RunPlanData
item
:
this
.
l
ist
)
{
if
(
item
.
getExecute
().
equals
(
run
))
{
if
(
item
.
getExecute
().
equals
(
run
))
{
this
.
m_L
ist
.
remove
(
item
);
this
.
l
ist
.
remove
(
item
);
this
.
triggerEvent
(
this
.
onRemove
);
this
.
triggerEvent
(
this
.
onRemove
);
break
;
break
;
}
}
...
@@ -200,6 +212,6 @@ public class RunPlan {
...
@@ -200,6 +212,6 @@ public class RunPlan {
* @return 长度信息
* @return 长度信息
*/
*/
public
final
int
getCount
()
{
public
final
int
getCount
()
{
return
this
.
m_L
ist
.
size
();
return
this
.
l
ist
.
size
();
}
}
}
}
yzg-util-base/src/main/java/com/yanzuoguang/util/thread/RunnableList.java
View file @
d367dd7b
...
@@ -5,7 +5,7 @@ import com.yanzuoguang.util.exception.CodeException;
...
@@ -5,7 +5,7 @@ import com.yanzuoguang.util.exception.CodeException;
/**
/**
* 根据指定的线程数量, 执行多个Runnable对象
* 根据指定的线程数量, 执行多个Runnable对象
*/
*/
public
class
RunnableList
extends
ThreadList
<
Runnable
>
{
public
class
RunnableList
extends
Abstract
ThreadList
<
Runnable
>
{
/**
/**
* 线程数量
* 线程数量
*
*
...
...
yzg-util-base/src/main/java/com/yanzuoguang/util/thread/RunnableListAuto.java
View file @
d367dd7b
...
@@ -24,8 +24,8 @@ public final class RunnableListAuto {
...
@@ -24,8 +24,8 @@ public final class RunnableListAuto {
*
*
* @param codes
* @param codes
*/
*/
public
static
ThreadList
<
RunnableListAutoItem
>
Execute
(
Runnable
...
codes
)
{
public
static
AbstractThreadList
<
RunnableListAutoItem
>
run
(
Runnable
...
codes
)
{
return
Execute
(
Arrays
.
asList
(
codes
));
return
run
(
Arrays
.
asList
(
codes
));
}
}
/**
/**
...
@@ -33,12 +33,12 @@ public final class RunnableListAuto {
...
@@ -33,12 +33,12 @@ public final class RunnableListAuto {
*
*
* @param codes
* @param codes
*/
*/
public
static
ThreadList
<
RunnableListAutoItem
>
Execute
(
List
<
Runnable
>
codes
)
{
public
static
AbstractThreadList
<
RunnableListAutoItem
>
run
(
List
<
Runnable
>
codes
)
{
List
<
RunnableListAutoItem
>
autos
=
new
ArrayList
<
RunnableListAutoItem
>();
List
<
RunnableListAutoItem
>
autos
=
new
ArrayList
<
RunnableListAutoItem
>();
for
(
Runnable
code
:
codes
)
{
for
(
Runnable
code
:
codes
)
{
autos
.
add
(
new
RunnableListAutoItem
(
code
));
autos
.
add
(
new
RunnableListAutoItem
(
code
));
}
}
return
Execute
Auto
(
autos
);
return
run
Auto
(
autos
);
}
}
/**
/**
...
@@ -46,8 +46,8 @@ public final class RunnableListAuto {
...
@@ -46,8 +46,8 @@ public final class RunnableListAuto {
*
*
* @param methods
* @param methods
*/
*/
public
static
ThreadList
<
RunnableListAutoItem
>
Execute
Auto
(
RunnableListAutoItem
...
methods
)
{
public
static
AbstractThreadList
<
RunnableListAutoItem
>
run
Auto
(
RunnableListAutoItem
...
methods
)
{
return
Execute
Auto
(
Arrays
.
asList
(
methods
));
return
run
Auto
(
Arrays
.
asList
(
methods
));
}
}
/**
/**
...
@@ -55,7 +55,7 @@ public final class RunnableListAuto {
...
@@ -55,7 +55,7 @@ public final class RunnableListAuto {
*
*
* @param methods
* @param methods
*/
*/
public
static
ThreadList
<
RunnableListAutoItem
>
Execute
Auto
(
List
<
RunnableListAutoItem
>
methods
)
{
public
static
AbstractThreadList
<
RunnableListAutoItem
>
run
Auto
(
List
<
RunnableListAutoItem
>
methods
)
{
// 获取历史执行时间
// 获取历史执行时间
int
zeroCount
=
0
;
int
zeroCount
=
0
;
long
totalAvg
=
0
;
long
totalAvg
=
0
;
...
@@ -119,18 +119,18 @@ public final class RunnableListAuto {
...
@@ -119,18 +119,18 @@ public final class RunnableListAuto {
continue
;
continue
;
}
}
RunnableListAutoItem
toItem
=
cache
.
get
(
item
.
getKey
());
RunnableListAutoItem
toItem
=
cache
.
get
(
item
.
getKey
());
W
riteLog
(
"上次执行时间"
,
toItem
,
finalThreadCount
);
w
riteLog
(
"上次执行时间"
,
toItem
,
finalThreadCount
);
}
}
}
}
// 开始线程列表
// 开始线程列表
ThreadList
<
RunnableListAutoItem
>
threadList
=
new
ThreadList
<
RunnableListAutoItem
>(
finalThreadCount
)
{
AbstractThreadList
<
RunnableListAutoItem
>
threadList
=
new
Abstract
ThreadList
<
RunnableListAutoItem
>(
finalThreadCount
)
{
@Override
@Override
public
void
run
(
RunnableListAutoItem
item
)
{
public
void
run
(
RunnableListAutoItem
item
)
{
try
{
try
{
item
.
execute
();
item
.
execute
();
if
(
IsLog
)
{
if
(
IsLog
)
{
W
riteLog
(
"执行时间"
,
item
,
finalThreadCount
);
w
riteLog
(
"执行时间"
,
item
,
finalThreadCount
);
}
}
}
finally
{
}
finally
{
RunnableListAutoItem
to
=
cache
.
get
(
item
.
getKey
());
RunnableListAutoItem
to
=
cache
.
get
(
item
.
getKey
());
...
@@ -147,7 +147,7 @@ public final class RunnableListAuto {
...
@@ -147,7 +147,7 @@ public final class RunnableListAuto {
return
threadList
;
return
threadList
;
}
}
private
static
void
W
riteLog
(
String
tag
,
RunnableListAutoItem
item
,
int
threadCount
)
{
private
static
void
w
riteLog
(
String
tag
,
RunnableListAutoItem
item
,
int
threadCount
)
{
if
(!
IsLog
)
{
if
(!
IsLog
)
{
return
;
return
;
}
}
...
...
yzg-util-base/src/main/java/com/yanzuoguang/util/thread/RunnableListAutoItem.java
View file @
d367dd7b
...
@@ -40,26 +40,26 @@ public class RunnableListAutoItem implements Comparable<RunnableListAutoItem> {
...
@@ -40,26 +40,26 @@ public class RunnableListAutoItem implements Comparable<RunnableListAutoItem> {
if
(
name
==
null
)
{
if
(
name
==
null
)
{
name
=
""
;
name
=
""
;
}
}
this
.
C
lassType
=
code
.
getClass
();
this
.
c
lassType
=
code
.
getClass
();
this
.
N
ame
=
name
;
this
.
n
ame
=
name
;
this
.
code
=
code
;
this
.
code
=
code
;
this
.
Key
=
StringHelper
.
getMD5Id
(
this
.
C
lassType
.
getName
()
+
":"
+
name
);
this
.
key
=
StringHelper
.
getMD5Id
(
this
.
c
lassType
.
getName
()
+
":"
+
name
);
}
}
/**
/**
* 关键字
* 关键字
*/
*/
private
volatile
String
K
ey
;
private
volatile
String
k
ey
;
/**
/**
* 类型
* 类型
*/
*/
private
volatile
Class
<?>
C
lassType
;
private
volatile
Class
<?>
c
lassType
;
/**
/**
* 名称
* 名称
*/
*/
private
volatile
String
N
ame
;
private
volatile
String
n
ame
;
/**
/**
* 执行代码
* 执行代码
...
@@ -69,21 +69,21 @@ public class RunnableListAutoItem implements Comparable<RunnableListAutoItem> {
...
@@ -69,21 +69,21 @@ public class RunnableListAutoItem implements Comparable<RunnableListAutoItem> {
/**
/**
* 总执行时间
* 总执行时间
*/
*/
private
volatile
long
T
ime
;
private
volatile
long
t
ime
;
/**
/**
* 执行次数
* 执行次数
*/
*/
private
volatile
int
C
ount
;
private
volatile
int
c
ount
;
/**
/**
* 需要注意当达到
T
ime > Long.MaxValue / 2 或者 count > Integer.MaxValue /2 时
* 需要注意当达到
t
ime > Long.MaxValue / 2 或者 count > Integer.MaxValue /2 时
* 则Time =
T
ime/2, count = count/2;
* 则Time =
t
ime/2, count = count/2;
*/
*/
private
synchronized
void
init
()
{
private
synchronized
void
init
()
{
if
(
this
.
Time
>
Long
.
MAX_VALUE
/
2
||
this
.
C
ount
>
Integer
.
MAX_VALUE
/
2
)
{
if
(
this
.
time
>
Long
.
MAX_VALUE
/
2
||
this
.
c
ount
>
Integer
.
MAX_VALUE
/
2
)
{
this
.
Time
=
this
.
T
ime
/
2
;
this
.
time
=
this
.
t
ime
/
2
;
this
.
Count
=
this
.
C
ount
/
2
;
this
.
count
=
this
.
c
ount
/
2
;
}
}
}
}
...
@@ -93,11 +93,11 @@ public class RunnableListAutoItem implements Comparable<RunnableListAutoItem> {
...
@@ -93,11 +93,11 @@ public class RunnableListAutoItem implements Comparable<RunnableListAutoItem> {
* @param to
* @param to
*/
*/
public
synchronized
void
add
(
RunnableListAutoItem
to
)
{
public
synchronized
void
add
(
RunnableListAutoItem
to
)
{
if
(
this
.
ClassType
!=
to
.
ClassType
||
!
this
.
Name
.
equals
(
to
.
N
ame
))
{
if
(
this
.
classType
!=
to
.
classType
||
!
this
.
name
.
equals
(
to
.
n
ame
))
{
return
;
return
;
}
}
this
.
Time
+=
to
.
T
ime
;
this
.
time
+=
to
.
t
ime
;
this
.
Count
+=
to
.
C
ount
;
this
.
count
+=
to
.
c
ount
;
this
.
init
();
this
.
init
();
}
}
...
@@ -107,10 +107,10 @@ public class RunnableListAutoItem implements Comparable<RunnableListAutoItem> {
...
@@ -107,10 +107,10 @@ public class RunnableListAutoItem implements Comparable<RunnableListAutoItem> {
* @return
* @return
*/
*/
public
synchronized
long
getAvgTime
()
{
public
synchronized
long
getAvgTime
()
{
if
(
this
.
C
ount
==
0
)
{
if
(
this
.
c
ount
==
0
)
{
return
0
;
return
0
;
}
}
return
this
.
Time
/
this
.
C
ount
;
return
this
.
time
/
this
.
c
ount
;
}
}
/**
/**
...
@@ -120,11 +120,11 @@ public class RunnableListAutoItem implements Comparable<RunnableListAutoItem> {
...
@@ -120,11 +120,11 @@ public class RunnableListAutoItem implements Comparable<RunnableListAutoItem> {
*/
*/
public
synchronized
RunnableListAutoItem
newBase
()
{
public
synchronized
RunnableListAutoItem
newBase
()
{
RunnableListAutoItem
to
=
new
RunnableListAutoItem
();
RunnableListAutoItem
to
=
new
RunnableListAutoItem
();
to
.
Key
=
this
.
K
ey
;
to
.
key
=
this
.
k
ey
;
to
.
ClassType
=
this
.
C
lassType
;
to
.
classType
=
this
.
c
lassType
;
to
.
Name
=
this
.
N
ame
;
to
.
name
=
this
.
n
ame
;
to
.
Count
=
this
.
C
ount
;
to
.
count
=
this
.
c
ount
;
to
.
Time
=
this
.
T
ime
;
to
.
time
=
this
.
t
ime
;
return
to
;
return
to
;
}
}
...
@@ -139,10 +139,10 @@ public class RunnableListAutoItem implements Comparable<RunnableListAutoItem> {
...
@@ -139,10 +139,10 @@ public class RunnableListAutoItem implements Comparable<RunnableListAutoItem> {
}
}
this
.
code
.
run
();
this
.
code
.
run
();
}
catch
(
Exception
ex
)
{
}
catch
(
Exception
ex
)
{
this
.
H
andleException
(
ex
);
this
.
h
andleException
(
ex
);
}
finally
{
}
finally
{
this
.
C
ount
++;
this
.
c
ount
++;
this
.
T
ime
+=
System
.
currentTimeMillis
()
-
start
.
getTime
();
this
.
t
ime
+=
System
.
currentTimeMillis
()
-
start
.
getTime
();
}
}
}
}
...
@@ -151,7 +151,7 @@ public class RunnableListAutoItem implements Comparable<RunnableListAutoItem> {
...
@@ -151,7 +151,7 @@ public class RunnableListAutoItem implements Comparable<RunnableListAutoItem> {
*
*
* @param ex
* @param ex
*/
*/
private
void
H
andleException
(
Throwable
ex
)
{
private
void
h
andleException
(
Throwable
ex
)
{
if
(
ex
instanceof
RuntimeException
)
{
if
(
ex
instanceof
RuntimeException
)
{
throw
(
RuntimeException
)
ex
;
throw
(
RuntimeException
)
ex
;
}
else
{
}
else
{
...
@@ -165,15 +165,15 @@ public class RunnableListAutoItem implements Comparable<RunnableListAutoItem> {
...
@@ -165,15 +165,15 @@ public class RunnableListAutoItem implements Comparable<RunnableListAutoItem> {
}
}
public
String
getKey
()
{
public
String
getKey
()
{
return
K
ey
;
return
k
ey
;
}
}
public
Class
<?>
getClassType
()
{
public
Class
<?>
getClassType
()
{
return
C
lassType
;
return
c
lassType
;
}
}
public
String
getName
()
{
public
String
getName
()
{
return
N
ame
;
return
n
ame
;
}
}
public
Runnable
getCode
()
{
public
Runnable
getCode
()
{
...
@@ -181,10 +181,10 @@ public class RunnableListAutoItem implements Comparable<RunnableListAutoItem> {
...
@@ -181,10 +181,10 @@ public class RunnableListAutoItem implements Comparable<RunnableListAutoItem> {
}
}
public
long
getTime
()
{
public
long
getTime
()
{
return
T
ime
;
return
t
ime
;
}
}
public
int
getCount
()
{
public
int
getCount
()
{
return
C
ount
;
return
c
ount
;
}
}
}
}
yzg-util-base/src/main/java/com/yanzuoguang/util/thread/ThreadHelper.java
View file @
d367dd7b
...
@@ -17,7 +17,7 @@ public class ThreadHelper {
...
@@ -17,7 +17,7 @@ public class ThreadHelper {
private
static
RunPlan
timeout
;
private
static
RunPlan
timeout
;
private
static
RunPlan
interval
;
private
static
RunPlan
interval
;
// 线程对象
// 线程对象
private
static
ExecutorService
_E
xecuteService
=
Executors
.
newCachedThreadPool
();
private
static
ExecutorService
e
xecuteService
=
Executors
.
newCachedThreadPool
();
/**
/**
* 初始化线程对象,需要调用该函数之后才能使用
* 初始化线程对象,需要调用该函数之后才能使用
...
@@ -32,27 +32,27 @@ public class ThreadHelper {
...
@@ -32,27 +32,27 @@ public class ThreadHelper {
Runnable
addExecute
=
new
Runnable
()
{
Runnable
addExecute
=
new
Runnable
()
{
@Override
@Override
public
void
run
()
{
public
void
run
()
{
O
nExecuteAdd
();
o
nExecuteAdd
();
}
}
};
};
Runnable
itemExecuted
=
new
Runnable
()
{
Runnable
itemExecuted
=
new
Runnable
()
{
@Override
@Override
public
void
run
()
{
public
void
run
()
{
O
nItemExecuted
();
o
nItemExecuted
();
}
}
};
};
timeout
.
getOnAdd
().
add
(
addExecute
);
timeout
.
getOnAdd
().
add
(
addExecute
);
timeout
.
getOnItemExecuted
().
add
(
itemExecuted
);
timeout
.
getOnItemExecuted
().
add
(
itemExecuted
);
interval
.
getOnAdd
().
add
(
addExecute
);
interval
.
getOnAdd
().
add
(
addExecute
);
interval
.
getOnItemExecuted
().
add
(
itemExecuted
);
interval
.
getOnItemExecuted
().
add
(
itemExecuted
);
S
tartMonitor
();
s
tartMonitor
();
}
}
private
static
void
O
nItemExecuted
()
{
private
static
void
o
nItemExecuted
()
{
threadDate
=
new
Date
();
threadDate
=
new
Date
();
}
}
private
static
void
O
nExecuteAdd
()
{
private
static
void
o
nExecuteAdd
()
{
startThread
();
startThread
();
}
}
...
@@ -67,12 +67,12 @@ public class ThreadHelper {
...
@@ -67,12 +67,12 @@ public class ThreadHelper {
threadIsRun
=
true
;
threadIsRun
=
true
;
while
(
threadIsRun
)
{
while
(
threadIsRun
)
{
try
{
try
{
timeout
.
Execute
(
true
,
-
1
);
timeout
.
run
(
true
,
-
1
);
}
catch
(
Exception
ex
)
{
}
catch
(
Exception
ex
)
{
ExceptionHelper
.
handleException
(
ThreadHelper
.
class
,
ex
);
ExceptionHelper
.
handleException
(
ThreadHelper
.
class
,
ex
);
}
}
try
{
try
{
interval
.
Execute
(
false
,
-
1
);
interval
.
run
(
false
,
-
1
);
}
catch
(
Exception
ex
)
{
}
catch
(
Exception
ex
)
{
ExceptionHelper
.
handleException
(
ThreadHelper
.
class
,
ex
);
ExceptionHelper
.
handleException
(
ThreadHelper
.
class
,
ex
);
}
}
...
@@ -90,7 +90,7 @@ public class ThreadHelper {
...
@@ -90,7 +90,7 @@ public class ThreadHelper {
/**
/**
* 监控线程的方法,防止线程执行死机
* 监控线程的方法,防止线程执行死机
*/
*/
private
static
void
S
tartMonitor
()
{
private
static
void
s
tartMonitor
()
{
runThread
(
new
Runnable
()
{
runThread
(
new
Runnable
()
{
@Override
@Override
public
void
run
()
{
public
void
run
()
{
...
@@ -120,7 +120,7 @@ public class ThreadHelper {
...
@@ -120,7 +120,7 @@ public class ThreadHelper {
* @return 执行标志
* @return 执行标志
*/
*/
public
static
String
setTimeout
(
Runnable
run
,
int
vTime
)
{
public
static
String
setTimeout
(
Runnable
run
,
int
vTime
)
{
return
timeout
.
S
et
(
run
,
vTime
);
return
timeout
.
s
et
(
run
,
vTime
);
}
}
/**
/**
...
@@ -149,7 +149,7 @@ public class ThreadHelper {
...
@@ -149,7 +149,7 @@ public class ThreadHelper {
* @return 执行标志
* @return 执行标志
*/
*/
public
static
String
setInterval
(
Runnable
run
,
int
vTime
)
{
public
static
String
setInterval
(
Runnable
run
,
int
vTime
)
{
return
interval
.
S
et
(
run
,
vTime
);
return
interval
.
s
et
(
run
,
vTime
);
}
}
/**
/**
...
@@ -202,7 +202,7 @@ public class ThreadHelper {
...
@@ -202,7 +202,7 @@ public class ThreadHelper {
* @param run
* @param run
*/
*/
public
static
void
runThread
(
final
Runnable
run
)
{
public
static
void
runThread
(
final
Runnable
run
)
{
_E
xecuteService
.
execute
(
new
Runnable
()
{
e
xecuteService
.
execute
(
new
Runnable
()
{
@Override
@Override
public
void
run
()
{
public
void
run
()
{
executeCatch
(
run
);
executeCatch
(
run
);
...
@@ -219,7 +219,7 @@ public class ThreadHelper {
...
@@ -219,7 +219,7 @@ public class ThreadHelper {
runThread
(
new
Runnable
()
{
runThread
(
new
Runnable
()
{
@Override
@Override
public
void
run
()
{
public
void
run
()
{
while
(!
run
.
isBreak
())
{
while
(!
run
.
isBreak
Flag
())
{
try
{
try
{
run
.
getCode
().
run
();
run
.
getCode
().
run
();
}
catch
(
Exception
ex
)
{
}
catch
(
Exception
ex
)
{
...
...
yzg-util-base/src/main/java/com/yanzuoguang/util/thread/ThreadWait.java
View file @
d367dd7b
...
@@ -57,7 +57,7 @@ public class ThreadWait {
...
@@ -57,7 +57,7 @@ public class ThreadWait {
}
}
this
.
stopPrint
();
this
.
stopPrint
();
}
}
if
(
ConfigBase
.
P
rintThread
)
{
if
(
ConfigBase
.
P
RINT_THREAD
)
{
Log
.
info
(
ThreadWait
.
class
,
"客户端结束时间"
);
Log
.
info
(
ThreadWait
.
class
,
"客户端结束时间"
);
}
}
}
}
...
@@ -78,7 +78,7 @@ public class ThreadWait {
...
@@ -78,7 +78,7 @@ public class ThreadWait {
public
synchronized
void
finish
()
{
public
synchronized
void
finish
()
{
if
(
this
.
execute
.
isFinally
())
{
if
(
this
.
execute
.
isFinally
())
{
this
.
notify
();
this
.
notify
();
if
(
ConfigBase
.
P
rintThread
)
{
if
(
ConfigBase
.
P
RINT_THREAD
)
{
Log
.
info
(
ThreadWait
.
class
,
"客户端结束时间"
);
Log
.
info
(
ThreadWait
.
class
,
"客户端结束时间"
);
}
}
}
}
...
...
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/BaseRequestAspect.java
View file @
d367dd7b
...
@@ -41,7 +41,7 @@ public class BaseRequestAspect implements ThreadNext.Next {
...
@@ -41,7 +41,7 @@ public class BaseRequestAspect implements ThreadNext.Next {
protected
volatile
LinkedBlockingQueue
<
LogVo
>
cache
=
new
LinkedBlockingQueue
<
LogVo
>();
protected
volatile
LinkedBlockingQueue
<
LogVo
>
cache
=
new
LinkedBlockingQueue
<
LogVo
>();
// 缓存的每次请求的结果
// 缓存的每次请求的结果
protected
MemoryCache
<
RequestCacheResult
>
_
cacheResult
=
new
MemoryCache
<>(
cacheTime
);
protected
MemoryCache
<
RequestCacheResult
>
cacheResult
=
new
MemoryCache
<>(
cacheTime
);
public
BaseRequestAspect
()
{
public
BaseRequestAspect
()
{
ThreadNext
.
start
(
this
,
"save log error"
);
ThreadNext
.
start
(
this
,
"save log error"
);
...
...
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/WebAspect.java
View file @
d367dd7b
...
@@ -116,7 +116,7 @@ public class WebAspect extends BaseRequestAspect {
...
@@ -116,7 +116,7 @@ public class WebAspect extends BaseRequestAspect {
reqId
=
StringHelper
.
getId
(
ObjectHelper
.
getString
(
firstArgs
,
"companyId"
),
reqId
);
reqId
=
StringHelper
.
getId
(
ObjectHelper
.
getString
(
firstArgs
,
"companyId"
),
reqId
);
}
}
String
reqFull
=
StringHelper
.
getId
(
reqId
,
HttpAspectUtil
.
getHttpRequestUrl
());
String
reqFull
=
StringHelper
.
getId
(
reqId
,
HttpAspectUtil
.
getHttpRequestUrl
());
RequestCacheResult
req
=
_
cacheResult
.
get
(
reqFull
,
new
RequestCacheResult
(
reqFull
));
RequestCacheResult
req
=
cacheResult
.
get
(
reqFull
,
new
RequestCacheResult
(
reqFull
));
// 缓存的键值对
// 缓存的键值对
if
(
req
.
getResult
()
==
null
)
{
if
(
req
.
getResult
()
==
null
)
{
synchronized
(
req
)
{
synchronized
(
req
)
{
...
...
yzg-util-db/src/main/java/com/yanzuoguang/dao/DaoConst.java
View file @
d367dd7b
...
@@ -4,48 +4,59 @@ package com.yanzuoguang.dao;
...
@@ -4,48 +4,59 @@ package com.yanzuoguang.dao;
* created by yanzu on 2017/5/30.
* created by yanzu on 2017/5/30.
*/
*/
public
class
DaoConst
{
public
class
DaoConst
{
public
static
final
int
OperatorTypeCreate
=
0
;
/**
public
static
final
int
OperatorTypeUpdate
=
1
;
* 创建操作
public
static
final
int
OperatorTypeRemove
=
2
;
*/
public
static
final
int
OperatorTypeLoad
=
3
;
public
static
final
int
OPERATOR_TYPE_CREATE
=
0
;
/**
* 更新操作
*/
public
static
final
int
OPERATOR_TYPE_UPDATE
=
1
;
/**
* 删除操作
*/
public
static
final
int
OPERATOR_TYPE_REMOVE
=
2
;
/**
* 加载操作
*/
public
static
final
int
OPERATOR_TYPE_LOAD
=
3
;
/**
/**
* 创建
* 创建
*/
*/
public
static
final
String
C
reate
=
"create"
;
public
static
final
String
C
REATE
=
"create"
;
/**
/**
* 修改
* 修改
*/
*/
public
static
final
String
U
pdate
=
"update"
;
public
static
final
String
U
PDATE
=
"update"
;
/**
/**
* 删除
* 删除
*/
*/
public
static
final
String
R
emove
=
"remove"
;
public
static
final
String
R
EMOVE
=
"remove"
;
/**
/**
* 加载
* 加载
*/
*/
public
static
final
String
L
oad
=
"load"
;
public
static
final
String
L
OAD
=
"load"
;
/**
/**
* 查询
* 查询
*/
*/
public
static
final
String
Q
uery
=
"query"
;
public
static
final
String
Q
UERY
=
"query"
;
/**
/**
* GROUP增加数据的SQL语句
* GROUP增加数据的SQL语句
*/
*/
public
static
final
String
G
roupAdd
=
"GroupAdd"
;
public
static
final
String
G
ROUP_ADD
=
"GroupAdd"
;
/**
/**
* GROUP查询数据的SQL语句
* GROUP查询数据的SQL语句
*/
*/
public
static
final
String
G
roupQuery
=
"GroupQuery"
;
public
static
final
String
G
ROUP_QUERY
=
"GroupQuery"
;
/**
/**
* 驼峰式命名
* 驼峰式命名
*/
*/
public
static
final
int
R
owNameTypeCamelCase
=
0
;
public
static
final
int
R
OW_NAME_TYPE_CAMEL_CASE
=
0
;
/**
/**
* 原字段
* 原字段
*/
*/
public
static
final
int
R
owNameTypeNoChange
=
1
;
public
static
final
int
R
OW_NAME_TYPE_NO_CHANGE
=
1
;
}
}
yzg-util-db/src/main/java/com/yanzuoguang/dao/
I
mpl/BaseDaoImpl.java
→
yzg-util-db/src/main/java/com/yanzuoguang/dao/
i
mpl/BaseDaoImpl.java
View file @
d367dd7b
package
com
.
yanzuoguang
.
dao
.
I
mpl
;
package
com
.
yanzuoguang
.
dao
.
i
mpl
;
import
com.yanzuoguang.dao.BaseDao
;
import
com.yanzuoguang.dao.BaseDao
;
import
com.yanzuoguang.dao.DaoConst
;
import
com.yanzuoguang.dao.DaoConst
;
import
com.yanzuoguang.db.
I
mpl.AllBeanRowMapper
;
import
com.yanzuoguang.db.
i
mpl.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
;
...
@@ -36,10 +36,10 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
...
@@ -36,10 +36,10 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
* @return 获取主键名称
* @return 获取主键名称
*/
*/
protected
String
getKey
()
{
protected
String
getKey
()
{
if
(
this
.
T
able
==
null
)
{
if
(
this
.
t
able
==
null
)
{
throw
new
CodeException
(
"类"
+
this
.
getClass
().
getName
()
+
"未发现表结构"
);
throw
new
CodeException
(
"类"
+
this
.
getClass
().
getName
()
+
"未发现表结构"
);
}
}
return
this
.
Table
.
T
able
.
getKeyName
();
return
this
.
table
.
t
able
.
getKeyName
();
}
}
/**
/**
...
@@ -103,7 +103,7 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
...
@@ -103,7 +103,7 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
@Override
@Override
public
String
create
(
Object
model
)
{
public
String
create
(
Object
model
)
{
// 判断主键是字符串和需要生成主键
// 判断主键是字符串和需要生成主键
boolean
isKeyString
=
this
.
Table
.
T
able
.
getKeyType
()
==
String
.
class
;
boolean
isKeyString
=
this
.
table
.
t
able
.
getKeyType
()
==
String
.
class
;
String
keyString
=
this
.
getKeyString
(
model
);
String
keyString
=
this
.
getKeyString
(
model
);
// 生成主键
// 生成主键
...
@@ -113,10 +113,10 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
...
@@ -113,10 +113,10 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
}
}
// 检测数据合法性
// 检测数据合法性
this
.
check
(
DaoConst
.
O
peratorTypeCreate
,
keyString
,
model
);
this
.
check
(
DaoConst
.
O
PERATOR_TYPE_CREATE
,
keyString
,
model
);
// 执行创建的SQL语句
// 执行创建的SQL语句
int
ret
=
updateSql
(
DaoConst
.
C
reate
,
model
);
int
ret
=
updateSql
(
DaoConst
.
C
REATE
,
model
);
// 判断是否需要获取自增编号(主键为整形)
// 判断是否需要获取自增编号(主键为整形)
if
(
StringHelper
.
isEmpty
(
keyString
)
&&
!
isKeyString
)
{
if
(
StringHelper
.
isEmpty
(
keyString
)
&&
!
isKeyString
)
{
keyString
=
this
.
getIdentity
();
keyString
=
this
.
getIdentity
();
...
@@ -142,10 +142,10 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
...
@@ -142,10 +142,10 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
public
String
update
(
Object
model
)
{
public
String
update
(
Object
model
)
{
String
keyString
=
this
.
getKeyString
(
model
);
String
keyString
=
this
.
getKeyString
(
model
);
if
(
StringHelper
.
isEmpty
(
keyString
))
{
if
(
StringHelper
.
isEmpty
(
keyString
))
{
throw
new
CodeException
(
"表"
+
this
.
Table
.
T
able
.
getName
()
+
"主键值为空时不能更新"
);
throw
new
CodeException
(
"表"
+
this
.
table
.
t
able
.
getName
()
+
"主键值为空时不能更新"
);
}
}
this
.
check
(
DaoConst
.
O
peratorTypeUpdate
,
keyString
,
model
);
this
.
check
(
DaoConst
.
O
PERATOR_TYPE_UPDATE
,
keyString
,
model
);
SqlData
sqlData
=
this
.
getSql
(
DaoConst
.
U
pdate
);
SqlData
sqlData
=
this
.
getSql
(
DaoConst
.
U
PDATE
);
int
ret
=
updateSql
(
sqlData
,
model
);
int
ret
=
updateSql
(
sqlData
,
model
);
String
retVal
=
ret
>
0
?
keyString
:
""
;
String
retVal
=
ret
>
0
?
keyString
:
""
;
return
retVal
;
return
retVal
;
...
@@ -198,21 +198,21 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
...
@@ -198,21 +198,21 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
from
=
new
HashMap
<
String
,
Object
>();
from
=
new
HashMap
<
String
,
Object
>();
this
.
setKeyString
(
from
,
keyString
);
this
.
setKeyString
(
from
,
keyString
);
// 调用删除日志
// 调用删除日志
this
.
check
(
DaoConst
.
O
peratorTypeRemove
,
keyString
,
from
);
this
.
check
(
DaoConst
.
O
PERATOR_TYPE_REMOVE
,
keyString
,
from
);
}
else
{
}
else
{
List
<
MapRow
>
rows
=
this
.
query
(
MapRow
.
class
,
DaoConst
.
L
oad
,
from
);
List
<
MapRow
>
rows
=
this
.
query
(
MapRow
.
class
,
DaoConst
.
L
OAD
,
from
);
for
(
MapRow
row
:
rows
)
{
for
(
MapRow
row
:
rows
)
{
keyString
=
this
.
getKeyString
(
from
);
keyString
=
this
.
getKeyString
(
from
);
if
(
StringHelper
.
isEmpty
(
keyString
))
{
if
(
StringHelper
.
isEmpty
(
keyString
))
{
keyString
=
StringHelper
.
toString
(
AllBeanRowMapper
.
getLoweRowField
(
row
,
this
.
getKey
()));
keyString
=
StringHelper
.
toString
(
AllBeanRowMapper
.
getLoweRowField
(
row
,
this
.
getKey
()));
}
}
// 调用删除日志
// 调用删除日志
this
.
check
(
DaoConst
.
O
peratorTypeRemove
,
keyString
,
row
);
this
.
check
(
DaoConst
.
O
PERATOR_TYPE_REMOVE
,
keyString
,
row
);
}
}
}
}
// 调用删除语句
// 调用删除语句
SqlData
sqlData
=
this
.
getSql
(
DaoConst
.
R
emove
);
SqlData
sqlData
=
this
.
getSql
(
DaoConst
.
R
EMOVE
);
return
updateSql
(
sqlData
,
from
);
return
updateSql
(
sqlData
,
from
);
}
}
...
@@ -237,7 +237,7 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
...
@@ -237,7 +237,7 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
}
}
// 通过传入数据进行加载
// 通过传入数据进行加载
T
to
=
this
.
queryFirst
(
cls
,
DaoConst
.
L
oad
,
from
);
T
to
=
this
.
queryFirst
(
cls
,
DaoConst
.
L
OAD
,
from
);
if
(
to
==
null
)
{
if
(
to
==
null
)
{
return
to
;
return
to
;
}
}
...
@@ -247,7 +247,7 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
...
@@ -247,7 +247,7 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
key
=
this
.
getKeyString
(
to
);
key
=
this
.
getKeyString
(
to
);
}
}
check
(
DaoConst
.
O
peratorTypeLoad
,
key
,
to
);
check
(
DaoConst
.
O
PERATOR_TYPE_LOAD
,
key
,
to
);
return
to
;
return
to
;
}
}
...
@@ -267,22 +267,22 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
...
@@ -267,22 +267,22 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
}
}
// 获取前台分组的MD5标识
// 获取前台分组的MD5标识
String
md5
=
this
.
getMd5
(
DaoConst
.
G
roupQuery
,
model
);
String
md5
=
this
.
getMd5
(
DaoConst
.
G
ROUP_QUERY
,
model
);
if
(!
StringHelper
.
isEmpty
(
this
.
Table
.
T
able
.
getMD5KeyName
()))
{
if
(!
StringHelper
.
isEmpty
(
this
.
table
.
t
able
.
getMD5KeyName
()))
{
ObjectHelper
.
set
(
model
,
this
.
Table
.
T
able
.
getMD5KeyName
(),
md5
);
ObjectHelper
.
set
(
model
,
this
.
table
.
t
able
.
getMD5KeyName
(),
md5
);
}
}
// 获取标识的实体
// 获取标识的实体
T
from
;
T
from
;
if
(
this
.
Table
.
T
able
.
getKeyType
()
==
String
.
class
)
{
if
(
this
.
table
.
t
able
.
getKeyType
()
==
String
.
class
)
{
from
=
model
;
from
=
model
;
this
.
setKeyString
(
model
,
md5
);
this
.
setKeyString
(
model
,
md5
);
}
else
if
(!
StringHelper
.
isEmpty
(
this
.
Table
.
T
able
.
getMD5KeyName
()))
{
}
else
if
(!
StringHelper
.
isEmpty
(
this
.
table
.
t
able
.
getMD5KeyName
()))
{
Map
<
String
,
Object
>
map
=
new
HashMap
<
String
,
Object
>();
Map
<
String
,
Object
>
map
=
new
HashMap
<
String
,
Object
>();
map
.
put
(
this
.
Table
.
T
able
.
getMD5KeyName
(),
md5
);
map
.
put
(
this
.
table
.
t
able
.
getMD5KeyName
(),
md5
);
from
=
this
.
load
(
map
,
cls
);
from
=
this
.
load
(
map
,
cls
);
}
else
{
}
else
{
from
=
this
.
queryFirst
(
cls
,
DaoConst
.
G
roupQuery
,
model
);
from
=
this
.
queryFirst
(
cls
,
DaoConst
.
G
ROUP_QUERY
,
model
);
}
}
// 当没有存在,则创建,否则 UpdateAdd
// 当没有存在,则创建,否则 UpdateAdd
...
@@ -295,7 +295,7 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
...
@@ -295,7 +295,7 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
ObjectHelper
.
set
(
model
,
keyField
,
key
);
ObjectHelper
.
set
(
model
,
keyField
,
key
);
// 执行更新SQL语句
// 执行更新SQL语句
SqlData
sqlData
=
this
.
getSql
(
DaoConst
.
G
roupAdd
);
SqlData
sqlData
=
this
.
getSql
(
DaoConst
.
G
ROUP_ADD
);
int
ret
=
this
.
updateSql
(
sqlData
,
model
);
int
ret
=
this
.
updateSql
(
sqlData
,
model
);
if
(
ret
<
1
)
{
if
(
ret
<
1
)
{
return
this
.
create
(
model
);
return
this
.
create
(
model
);
...
...
yzg-util-db/src/main/java/com/yanzuoguang/dao/
I
mpl/BaseDaoSql.java
→
yzg-util-db/src/main/java/com/yanzuoguang/dao/
i
mpl/BaseDaoSql.java
View file @
d367dd7b
package
com
.
yanzuoguang
.
dao
.
I
mpl
;
package
com
.
yanzuoguang
.
dao
.
i
mpl
;
import
com.yanzuoguang.dao.TableAnnotation
;
import
com.yanzuoguang.dao.TableAnnotation
;
import
com.yanzuoguang.db.DbExecute
;
import
com.yanzuoguang.db.DbExecute
;
import
com.yanzuoguang.db.
I
mpl.DbRow
;
import
com.yanzuoguang.db.
i
mpl.DbRow
;
import
com.yanzuoguang.util.base.ObjectHelper
;
import
com.yanzuoguang.util.base.ObjectHelper
;
import
com.yanzuoguang.util.cache.MemoryCache
;
import
com.yanzuoguang.util.cache.MemoryCache
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.exception.CodeException
;
...
@@ -36,7 +36,7 @@ public abstract class BaseDaoSql {
...
@@ -36,7 +36,7 @@ public abstract class BaseDaoSql {
/**
/**
* 当前Dao的表结构SQL语句信息
* 当前Dao的表结构SQL语句信息
*/
*/
protected
TableSqlCache
T
able
=
null
;
protected
TableSqlCache
t
able
=
null
;
/**
/**
* 缓存的表结构和SQL语句
* 缓存的表结构和SQL语句
...
@@ -65,11 +65,11 @@ public abstract class BaseDaoSql {
...
@@ -65,11 +65,11 @@ public abstract class BaseDaoSql {
private
void
initTable
()
{
private
void
initTable
()
{
String
cls
=
this
.
getClass
().
getName
();
String
cls
=
this
.
getClass
().
getName
();
// 外检测,防止锁影响性能
// 外检测,防止锁影响性能
this
.
T
able
=
Cache
.
get
(
cls
);
this
.
t
able
=
Cache
.
get
(
cls
);
// 判断是否已经取到对象
// 判断是否已经取到对象
if
(
this
.
T
able
==
null
)
{
if
(
this
.
t
able
==
null
)
{
this
.
T
able
=
new
TableSqlCache
();
this
.
t
able
=
new
TableSqlCache
();
Cache
.
put
(
cls
,
this
.
T
able
);
Cache
.
put
(
cls
,
this
.
t
able
);
this
.
init
();
this
.
init
();
}
}
}
}
...
@@ -104,8 +104,8 @@ public abstract class BaseDaoSql {
...
@@ -104,8 +104,8 @@ public abstract class BaseDaoSql {
// 生成表结构
// 生成表结构
TableStruct
table
=
new
TableStruct
(
tableName
,
clsModel
);
TableStruct
table
=
new
TableStruct
(
tableName
,
clsModel
);
// 根据表结构生成基本的SQL语句
// 根据表结构生成基本的SQL语句
table
.
init
(
this
.
T
able
);
table
.
init
(
this
.
t
able
);
return
this
.
T
able
;
return
this
.
t
able
;
}
}
/**
/**
...
@@ -125,10 +125,10 @@ public abstract class BaseDaoSql {
...
@@ -125,10 +125,10 @@ public abstract class BaseDaoSql {
* @return 对应名称的SQL语句
* @return 对应名称的SQL语句
*/
*/
protected
SqlData
getSql
(
String
name
,
boolean
isThrow
)
{
protected
SqlData
getSql
(
String
name
,
boolean
isThrow
)
{
if
(
this
.
T
able
==
null
)
{
if
(
this
.
t
able
==
null
)
{
throw
new
CodeException
(
"类"
+
this
.
getClass
().
getName
()
+
"未发现表结构"
);
throw
new
CodeException
(
"类"
+
this
.
getClass
().
getName
()
+
"未发现表结构"
);
}
}
SqlData
sql
=
this
.
T
able
.
Sqls
.
get
(
name
);
SqlData
sql
=
this
.
t
able
.
Sqls
.
get
(
name
);
if
(
isThrow
&&
sql
==
null
)
{
if
(
isThrow
&&
sql
==
null
)
{
throw
new
CodeException
(
"类"
+
this
.
getClass
().
getName
()
+
"未发现SQL语句"
+
name
);
throw
new
CodeException
(
"类"
+
this
.
getClass
().
getName
()
+
"未发现SQL语句"
+
name
);
}
}
...
@@ -155,7 +155,7 @@ public abstract class BaseDaoSql {
...
@@ -155,7 +155,7 @@ public abstract class BaseDaoSql {
protected
int
updateSql
(
SqlData
sqlData
,
Object
model
)
{
protected
int
updateSql
(
SqlData
sqlData
,
Object
model
)
{
List
<
Object
>
paras
=
new
ArrayList
<
Object
>();
List
<
Object
>
paras
=
new
ArrayList
<
Object
>();
String
sql
=
this
.
getQueryPara
(
paras
,
sqlData
,
model
);
String
sql
=
this
.
getQueryPara
(
paras
,
sqlData
,
model
);
int
ret
=
db
.
update
(
this
.
getClass
(),
sqlData
.
N
ame
,
sql
,
paras
.
toArray
());
int
ret
=
db
.
update
(
this
.
getClass
(),
sqlData
.
n
ame
,
sql
,
paras
.
toArray
());
this
.
onUpdateSql
(
model
);
this
.
onUpdateSql
(
model
);
return
ret
;
return
ret
;
}
}
...
@@ -183,7 +183,7 @@ public abstract class BaseDaoSql {
...
@@ -183,7 +183,7 @@ public abstract class BaseDaoSql {
protected
Object
queryCell
(
SqlData
sqlData
,
Object
model
)
{
protected
Object
queryCell
(
SqlData
sqlData
,
Object
model
)
{
List
<
Object
>
paras
=
new
ArrayList
<
Object
>();
List
<
Object
>
paras
=
new
ArrayList
<
Object
>();
String
sql
=
this
.
getQueryPara
(
paras
,
sqlData
,
model
);
String
sql
=
this
.
getQueryPara
(
paras
,
sqlData
,
model
);
Object
cell
=
this
.
queryCellWithCache
(
sql
,
sqlData
.
N
ame
,
paras
.
toArray
());
Object
cell
=
this
.
queryCellWithCache
(
sql
,
sqlData
.
n
ame
,
paras
.
toArray
());
return
cell
;
return
cell
;
}
}
...
@@ -211,7 +211,7 @@ public abstract class BaseDaoSql {
...
@@ -211,7 +211,7 @@ public abstract class BaseDaoSql {
protected
<
T
extends
Object
>
List
<
T
>
queryData
(
Class
<
T
>
cls
,
SqlData
sqlData
,
Object
model
)
{
protected
<
T
extends
Object
>
List
<
T
>
queryData
(
Class
<
T
>
cls
,
SqlData
sqlData
,
Object
model
)
{
List
<
Object
>
paras
=
new
ArrayList
<
Object
>();
List
<
Object
>
paras
=
new
ArrayList
<
Object
>();
String
sql
=
this
.
getQueryPara
(
paras
,
sqlData
,
model
);
String
sql
=
this
.
getQueryPara
(
paras
,
sqlData
,
model
);
List
<
T
>
list
=
this
.
queryWithCache
(
cls
,
sqlData
.
N
ame
,
sql
,
paras
.
toArray
());
List
<
T
>
list
=
this
.
queryWithCache
(
cls
,
sqlData
.
n
ame
,
sql
,
paras
.
toArray
());
return
list
;
return
list
;
}
}
...
@@ -227,7 +227,7 @@ public abstract class BaseDaoSql {
...
@@ -227,7 +227,7 @@ public abstract class BaseDaoSql {
List
<
Object
>
paras
=
new
ArrayList
<
Object
>();
List
<
Object
>
paras
=
new
ArrayList
<
Object
>();
String
sql
=
this
.
getQueryPara
(
paras
,
sqlData
,
model
);
String
sql
=
this
.
getQueryPara
(
paras
,
sqlData
,
model
);
// 查询数据
// 查询数据
db
.
query
(
this
.
getClass
(),
cls
,
handle
,
sqlData
.
N
ame
,
sql
,
paras
);
db
.
query
(
this
.
getClass
(),
cls
,
handle
,
sqlData
.
n
ame
,
sql
,
paras
);
}
}
/**
/**
...
@@ -290,7 +290,7 @@ public abstract class BaseDaoSql {
...
@@ -290,7 +290,7 @@ public abstract class BaseDaoSql {
SqlData
from
=
this
.
getSql
(
sqlName
);
SqlData
from
=
this
.
getSql
(
sqlName
);
// 对SQL语句进行分页处理
// 对SQL语句进行分页处理
SqlData
to
=
from
.
copy
();
SqlData
to
=
from
.
copy
();
to
.
Sql
=
from
.
S
ql
;
to
.
sql
=
from
.
s
ql
;
to
.
addCode
(
"{LIMIT}"
,
" LIMIT "
+
pageSize
.
getPageStart
()
+
","
+
pageSize
.
getPageSize
());
to
.
addCode
(
"{LIMIT}"
,
" LIMIT "
+
pageSize
.
getPageStart
()
+
","
+
pageSize
.
getPageSize
());
return
queryData
(
cls
,
to
,
model
);
return
queryData
(
cls
,
to
,
model
);
}
}
...
@@ -417,7 +417,7 @@ public abstract class BaseDaoSql {
...
@@ -417,7 +417,7 @@ public abstract class BaseDaoSql {
String
[]
lastCode
=
new
String
[]{
"{WHERE}"
,
"{GROUP}"
,
"{HAVING}"
,
"{ORDER}"
,
"{LIMIT}"
};
String
[]
lastCode
=
new
String
[]{
"{WHERE}"
,
"{GROUP}"
,
"{HAVING}"
,
"{ORDER}"
,
"{LIMIT}"
};
// 将SQL语句进行代码片段追加
// 将SQL语句进行代码片段追加
String
sql
=
sqlData
.
S
ql
;
String
sql
=
sqlData
.
s
ql
;
for
(
String
code
:
lastCode
)
{
for
(
String
code
:
lastCode
)
{
if
(
sql
.
indexOf
(
code
)
==
-
1
)
{
if
(
sql
.
indexOf
(
code
)
==
-
1
)
{
sql
+=
code
;
sql
+=
code
;
...
@@ -449,7 +449,7 @@ public abstract class BaseDaoSql {
...
@@ -449,7 +449,7 @@ public abstract class BaseDaoSql {
// 判断代码片段是否合法
// 判断代码片段是否合法
if
(
field
.
codes
.
size
()
%
2
==
1
)
{
if
(
field
.
codes
.
size
()
%
2
==
1
)
{
throw
new
CodeException
(
"代码片段"
+
this
.
getClass
().
getSimpleName
()
+
":"
+
sqlData
.
N
ame
+
":"
+
field
.
paraName
+
"为单数"
);
throw
new
CodeException
(
"代码片段"
+
this
.
getClass
().
getSimpleName
()
+
":"
+
sqlData
.
n
ame
+
":"
+
field
.
paraName
+
"为单数"
);
}
}
// 处理代码片段
// 处理代码片段
for
(
int
i
=
0
;
i
<
field
.
codes
.
size
();
i
=
i
+
2
)
{
for
(
int
i
=
0
;
i
<
field
.
codes
.
size
();
i
=
i
+
2
)
{
...
@@ -475,16 +475,16 @@ public abstract class BaseDaoSql {
...
@@ -475,16 +475,16 @@ public abstract class BaseDaoSql {
}
}
}
}
// 通过正则表达式处理参数 @
N
ame 并替换SQL语句成 ?
// 通过正则表达式处理参数 @
n
ame 并替换SQL语句成 ?
{
{
String
regex
=
"@([a-zA-Z0-9_]+)"
;
String
regex
=
"@([a-zA-Z0-9_]+)"
;
Pattern
p
=
Pattern
.
compile
(
regex
);
Pattern
p
=
Pattern
.
compile
(
regex
);
Matcher
m
=
p
.
matcher
(
sql
);
Matcher
m
=
p
.
matcher
(
sql
);
// 寻找到的代码片段 不包含分括号
// 寻找到的代码片段 不包含分括号
while
(
m
.
find
())
{
while
(
m
.
find
())
{
// SQL参数名称 @
N
ame\s
// SQL参数名称 @
n
ame\s
String
name
=
m
.
group
();
String
name
=
m
.
group
();
// 对应的前台输入字段
N
ame
// 对应的前台输入字段
n
ame
String
field
=
m
.
group
(
1
);
String
field
=
m
.
group
(
1
);
// 根据输入字段从参数中取值
// 根据输入字段从参数中取值
Object
val
=
ObjectHelper
.
get
(
model
,
field
);
Object
val
=
ObjectHelper
.
get
(
model
,
field
);
...
@@ -593,19 +593,19 @@ public abstract class BaseDaoSql {
...
@@ -593,19 +593,19 @@ public abstract class BaseDaoSql {
sb
.
append
(
","
);
sb
.
append
(
","
);
}
}
switch
(
from
.
getGroupType
())
{
switch
(
from
.
getGroupType
())
{
case
CaseSqlModel
.
G
roupType
SUM
:
case
CaseSqlModel
.
G
ROUP_TYPE_
SUM
:
sb
.
append
(
"SUM"
);
sb
.
append
(
"SUM"
);
break
;
break
;
case
CaseSqlModel
.
G
roupType
COUNT
:
case
CaseSqlModel
.
G
ROUP_TYPE_
COUNT
:
sb
.
append
(
"COUNT"
);
sb
.
append
(
"COUNT"
);
break
;
break
;
case
CaseSqlModel
.
G
roupType
MAX
:
case
CaseSqlModel
.
G
ROUP_TYPE_
MAX
:
sb
.
append
(
"MAX"
);
sb
.
append
(
"MAX"
);
break
;
break
;
case
CaseSqlModel
.
G
roupType
MIN
:
case
CaseSqlModel
.
G
ROUP_TYPE_
MIN
:
sb
.
append
(
"MIN"
);
sb
.
append
(
"MIN"
);
break
;
break
;
case
CaseSqlModel
.
G
roupType
AVG
:
case
CaseSqlModel
.
G
ROUP_TYPE_
AVG
:
sb
.
append
(
"AVG"
);
sb
.
append
(
"AVG"
);
break
;
break
;
default
:
default
:
...
...
yzg-util-db/src/main/java/com/yanzuoguang/dao/
I
mpl/CaseSqlModel.java
→
yzg-util-db/src/main/java/com/yanzuoguang/dao/
i
mpl/CaseSqlModel.java
View file @
d367dd7b
package
com
.
yanzuoguang
.
dao
.
I
mpl
;
package
com
.
yanzuoguang
.
dao
.
i
mpl
;
/**
/**
* 行转列实体
* 行转列实体
*
* @author 颜佐光
*/
*/
public
class
CaseSqlModel
{
public
class
CaseSqlModel
{
public
final
static
int
G
roupType
SUM
=
0
;
public
final
static
int
G
ROUP_TYPE_
SUM
=
0
;
public
final
static
int
G
roupType
COUNT
=
1
;
public
final
static
int
G
ROUP_TYPE_
COUNT
=
1
;
public
final
static
int
G
roupType
AVG
=
2
;
public
final
static
int
G
ROUP_TYPE_
AVG
=
2
;
public
final
static
int
G
roupType
MIN
=
3
;
public
final
static
int
G
ROUP_TYPE_
MIN
=
3
;
public
final
static
int
G
roupType
MAX
=
4
;
public
final
static
int
G
ROUP_TYPE_
MAX
=
4
;
public
CaseSqlModel
(
String
caseField
,
String
caseValue
,
String
valueField
,
String
toName
)
{
public
CaseSqlModel
(
String
caseField
,
String
caseValue
,
String
valueField
,
String
toName
)
{
this
(
G
roupType
SUM
,
caseField
,
caseValue
,
valueField
,
toName
);
this
(
G
ROUP_TYPE_
SUM
,
caseField
,
caseValue
,
valueField
,
toName
);
}
}
public
CaseSqlModel
(
int
groupType
,
String
caseField
,
String
caseValue
,
String
valueField
,
String
toName
)
{
public
CaseSqlModel
(
int
groupType
,
String
caseField
,
String
caseValue
,
String
valueField
,
String
toName
)
{
this
.
G
roupType
=
groupType
;
this
.
g
roupType
=
groupType
;
this
.
C
aseField
=
caseField
;
this
.
c
aseField
=
caseField
;
this
.
C
aseValue
=
caseValue
;
this
.
c
aseValue
=
caseValue
;
this
.
V
alueField
=
valueField
;
this
.
v
alueField
=
valueField
;
this
.
T
oName
=
toName
;
this
.
t
oName
=
toName
;
this
.
A
ndWhere
=
""
;
this
.
a
ndWhere
=
""
;
}
}
public
CaseSqlModel
(
String
caseField
,
String
caseValue
,
Object
value
,
String
toName
,
String
andWhere
)
{
public
CaseSqlModel
(
String
caseField
,
String
caseValue
,
Object
value
,
String
toName
,
String
andWhere
)
{
this
(
G
roupType
SUM
,
caseField
,
caseValue
,
value
,
toName
,
andWhere
);
this
(
G
ROUP_TYPE_
SUM
,
caseField
,
caseValue
,
value
,
toName
,
andWhere
);
}
}
public
CaseSqlModel
(
int
groupType
,
String
caseField
,
String
caseValue
,
Object
value
,
String
toName
,
String
andWhere
)
{
public
CaseSqlModel
(
int
groupType
,
String
caseField
,
String
caseValue
,
Object
value
,
String
toName
,
String
andWhere
)
{
this
.
G
roupType
=
groupType
;
this
.
g
roupType
=
groupType
;
this
.
C
aseField
=
caseField
;
this
.
c
aseField
=
caseField
;
this
.
C
aseValue
=
caseValue
;
this
.
c
aseValue
=
caseValue
;
this
.
V
alue
=
value
;
this
.
v
alue
=
value
;
this
.
T
oName
=
toName
;
this
.
t
oName
=
toName
;
this
.
A
ndWhere
=
andWhere
;
this
.
a
ndWhere
=
andWhere
;
}
}
public
CaseSqlModel
(
String
caseField
,
String
caseValue
,
String
valueField
,
String
toName
,
String
andWhere
)
{
public
CaseSqlModel
(
String
caseField
,
String
caseValue
,
String
valueField
,
String
toName
,
String
andWhere
)
{
this
(
G
roupType
SUM
,
caseField
,
caseValue
,
valueField
,
toName
,
andWhere
);
this
(
G
ROUP_TYPE_
SUM
,
caseField
,
caseValue
,
valueField
,
toName
,
andWhere
);
}
}
public
CaseSqlModel
(
int
groupType
,
String
caseField
,
String
caseValue
,
String
valueField
,
String
toName
,
String
andWhere
)
{
public
CaseSqlModel
(
int
groupType
,
String
caseField
,
String
caseValue
,
String
valueField
,
String
toName
,
String
andWhere
)
{
this
.
G
roupType
=
groupType
;
this
.
g
roupType
=
groupType
;
this
.
C
aseField
=
caseField
;
this
.
c
aseField
=
caseField
;
this
.
C
aseValue
=
caseValue
;
this
.
c
aseValue
=
caseValue
;
this
.
V
alueField
=
valueField
;
this
.
v
alueField
=
valueField
;
this
.
T
oName
=
toName
;
this
.
t
oName
=
toName
;
this
.
A
ndWhere
=
andWhere
;
this
.
a
ndWhere
=
andWhere
;
}
}
/**
/**
* 统计纬度
* 统计纬度
*/
*/
private
int
G
roupType
;
private
int
g
roupType
;
/**
/**
* 需要判断的字段
* 需要判断的字段
*/
*/
private
String
C
aseField
;
private
String
c
aseField
;
/**
/**
* 需要判断的值
* 需要判断的值
*/
*/
private
String
C
aseValue
;
private
String
c
aseValue
;
/**
/**
* 需要统计的字段,和
V
alue 只能存在一个,ValueField优先级更高
* 需要统计的字段,和
v
alue 只能存在一个,ValueField优先级更高
*/
*/
private
String
V
alueField
;
private
String
v
alueField
;
/**
/**
* 需要统计的值,和 ValueField只能存在一个,ValueField优先级更高
* 需要统计的值,和 ValueField只能存在一个,ValueField优先级更高
*/
*/
private
Object
V
alue
;
private
Object
v
alue
;
/**
/**
* 目标字段名称
* 目标字段名称
*/
*/
private
String
T
oName
;
private
String
t
oName
;
/**
/**
* 需要判断的CASE字段的附加条件
* 需要判断的CASE字段的附加条件
*/
*/
private
String
A
ndWhere
;
private
String
a
ndWhere
;
public
int
getGroupType
()
{
public
int
getGroupType
()
{
return
G
roupType
;
return
g
roupType
;
}
}
public
void
setGroupType
(
int
groupType
)
{
public
void
setGroupType
(
int
groupType
)
{
G
roupType
=
groupType
;
this
.
g
roupType
=
groupType
;
}
}
public
String
getCaseField
()
{
public
String
getCaseField
()
{
return
C
aseField
;
return
c
aseField
;
}
}
public
void
setCaseField
(
String
caseField
)
{
public
void
setCaseField
(
String
caseField
)
{
C
aseField
=
caseField
;
this
.
c
aseField
=
caseField
;
}
}
public
String
getCaseValue
()
{
public
String
getCaseValue
()
{
return
C
aseValue
;
return
c
aseValue
;
}
}
public
void
setCaseValue
(
String
caseValue
)
{
public
void
setCaseValue
(
String
caseValue
)
{
C
aseValue
=
caseValue
;
this
.
c
aseValue
=
caseValue
;
}
}
public
String
getValueField
()
{
public
String
getValueField
()
{
return
V
alueField
;
return
v
alueField
;
}
}
public
void
setValueField
(
String
valueField
)
{
public
void
setValueField
(
String
valueField
)
{
V
alueField
=
valueField
;
this
.
v
alueField
=
valueField
;
}
}
public
Object
getValue
()
{
public
Object
getValue
()
{
return
V
alue
;
return
v
alue
;
}
}
public
void
setValue
(
Object
value
)
{
public
void
setValue
(
Object
value
)
{
V
alue
=
value
;
this
.
v
alue
=
value
;
}
}
public
String
getToName
()
{
public
String
getToName
()
{
return
T
oName
;
return
t
oName
;
}
}
public
void
setToName
(
String
toName
)
{
public
void
setToName
(
String
toName
)
{
T
oName
=
toName
;
this
.
t
oName
=
toName
;
}
}
public
String
getAndWhere
()
{
public
String
getAndWhere
()
{
return
A
ndWhere
;
return
a
ndWhere
;
}
}
public
void
setAndWhere
(
String
andWhere
)
{
public
void
setAndWhere
(
String
andWhere
)
{
A
ndWhere
=
andWhere
;
this
.
a
ndWhere
=
andWhere
;
}
}
}
}
yzg-util-db/src/main/java/com/yanzuoguang/dao/
I
mpl/SqlData.java
→
yzg-util-db/src/main/java/com/yanzuoguang/dao/
i
mpl/SqlData.java
View file @
d367dd7b
package
com
.
yanzuoguang
.
dao
.
I
mpl
;
package
com
.
yanzuoguang
.
dao
.
i
mpl
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
...
@@ -12,17 +12,17 @@ public class SqlData {
...
@@ -12,17 +12,17 @@ public class SqlData {
/**
/**
* 对应的参数顺序
* 对应的参数顺序
*/
*/
p
ublic
List
<
SqlDataField
>
sqlDataFields
=
new
ArrayList
<
SqlDataField
>();
p
rivate
List
<
SqlDataField
>
sqlDataFields
=
new
ArrayList
<
SqlDataField
>();
/**
/**
* SQL语句的名称
* SQL语句的名称
*/
*/
p
ublic
String
N
ame
;
p
rivate
String
n
ame
;
/**
/**
* SQL语句
* SQL语句
*/
*/
p
ublic
String
S
ql
;
p
rivate
String
s
ql
;
/**
/**
* 构造函数
* 构造函数
...
@@ -31,6 +31,26 @@ public class SqlData {
...
@@ -31,6 +31,26 @@ public class SqlData {
this
(
""
,
""
);
this
(
""
,
""
);
}
}
public
List
<
SqlDataField
>
getSqlDataFields
()
{
return
sqlDataFields
;
}
public
void
setSqlDataFields
(
List
<
SqlDataField
>
sqlDataFields
)
{
this
.
sqlDataFields
=
sqlDataFields
;
}
public
String
getName
()
{
return
name
;
}
public
String
getSql
()
{
return
sql
;
}
public
void
setSql
(
String
sql
)
{
this
.
sql
=
sql
;
}
/**
/**
* SQL语句的基本信息
* SQL语句的基本信息
*
*
...
@@ -39,8 +59,8 @@ public class SqlData {
...
@@ -39,8 +59,8 @@ public class SqlData {
* @param paras SQL语句参数名称数组
* @param paras SQL语句参数名称数组
*/
*/
public
SqlData
(
String
name
,
String
sql
,
String
...
paras
)
{
public
SqlData
(
String
name
,
String
sql
,
String
...
paras
)
{
this
.
N
ame
=
name
;
this
.
n
ame
=
name
;
this
.
S
ql
=
sql
;
this
.
s
ql
=
sql
;
for
(
String
input
:
paras
)
{
for
(
String
input
:
paras
)
{
this
.
add
(
input
);
this
.
add
(
input
);
}
}
...
@@ -220,7 +240,7 @@ public class SqlData {
...
@@ -220,7 +240,7 @@ public class SqlData {
* @return 复制的结果
* @return 复制的结果
*/
*/
public
SqlData
copy
()
{
public
SqlData
copy
()
{
SqlData
to
=
new
SqlData
(
this
.
Name
,
this
.
S
ql
);
SqlData
to
=
new
SqlData
(
this
.
name
,
this
.
s
ql
);
for
(
SqlDataField
sqlDataField
:
this
.
sqlDataFields
)
{
for
(
SqlDataField
sqlDataField
:
this
.
sqlDataFields
)
{
to
.
sqlDataFields
.
add
(
sqlDataField
.
copy
());
to
.
sqlDataFields
.
add
(
sqlDataField
.
copy
());
}
}
...
@@ -234,7 +254,7 @@ public class SqlData {
...
@@ -234,7 +254,7 @@ public class SqlData {
* @return
* @return
*/
*/
public
SqlData
setName
(
String
name
)
{
public
SqlData
setName
(
String
name
)
{
this
.
N
ame
=
name
;
this
.
n
ame
=
name
;
return
this
;
return
this
;
}
}
}
}
yzg-util-db/src/main/java/com/yanzuoguang/dao/
I
mpl/SqlDataField.java
→
yzg-util-db/src/main/java/com/yanzuoguang/dao/
i
mpl/SqlDataField.java
View file @
d367dd7b
package
com
.
yanzuoguang
.
dao
.
I
mpl
;
package
com
.
yanzuoguang
.
dao
.
i
mpl
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
...
...
yzg-util-db/src/main/java/com/yanzuoguang/dao/
I
mpl/TableFieldString.java
→
yzg-util-db/src/main/java/com/yanzuoguang/dao/
i
mpl/TableFieldString.java
View file @
d367dd7b
package
com
.
yanzuoguang
.
dao
.
I
mpl
;
package
com
.
yanzuoguang
.
dao
.
i
mpl
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
/**
/**
* Created by yanzu on 2017/6/6.
* Created by yanzu on 2017/6/6.
*
* @author 颜佐光
*/
*/
public
class
TableFieldString
{
public
class
TableFieldString
{
/**
/**
* 其他字段
* 其他字段
*/
*/
p
ublic
List
<
String
>
Fields
=
new
ArrayList
<
String
>();
p
rivate
List
<
String
>
fields
=
new
ArrayList
<
>();
/**
/**
* 构造函数
* 构造函数
...
@@ -20,7 +22,7 @@ public class TableFieldString {
...
@@ -20,7 +22,7 @@ public class TableFieldString {
*/
*/
public
TableFieldString
(
String
...
fields
)
{
public
TableFieldString
(
String
...
fields
)
{
for
(
String
field
:
fields
)
{
for
(
String
field
:
fields
)
{
this
.
F
ields
.
add
(
field
);
this
.
f
ields
.
add
(
field
);
}
}
}
}
...
@@ -31,7 +33,15 @@ public class TableFieldString {
...
@@ -31,7 +33,15 @@ public class TableFieldString {
*/
*/
public
TableFieldString
(
List
<
String
>
fields
)
{
public
TableFieldString
(
List
<
String
>
fields
)
{
for
(
String
field
:
fields
)
{
for
(
String
field
:
fields
)
{
this
.
F
ields
.
add
(
field
);
this
.
f
ields
.
add
(
field
);
}
}
}
}
public
List
<
String
>
getFields
()
{
return
fields
;
}
public
void
setFields
(
List
<
String
>
fields
)
{
this
.
fields
=
fields
;
}
}
}
yzg-util-db/src/main/java/com/yanzuoguang/dao/
I
mpl/TableFieldVo.java
→
yzg-util-db/src/main/java/com/yanzuoguang/dao/
i
mpl/TableFieldVo.java
View file @
d367dd7b
package
com
.
yanzuoguang
.
dao
.
I
mpl
;
package
com
.
yanzuoguang
.
dao
.
i
mpl
;
/**
/**
* 表结构的基本信息
* 表结构的基本信息
...
...
yzg-util-db/src/main/java/com/yanzuoguang/dao/
I
mpl/TableSqlCache.java
→
yzg-util-db/src/main/java/com/yanzuoguang/dao/
i
mpl/TableSqlCache.java
View file @
d367dd7b
package
com
.
yanzuoguang
.
dao
.
I
mpl
;
package
com
.
yanzuoguang
.
dao
.
i
mpl
;
import
com.yanzuoguang.util.cache.MemoryCache
;
import
com.yanzuoguang.util.cache.MemoryCache
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.exception.CodeException
;
...
@@ -25,18 +25,18 @@ public class TableSqlCache {
...
@@ -25,18 +25,18 @@ public class TableSqlCache {
/**
/**
* 表信息
* 表信息
*/
*/
p
ublic
TableStruct
T
able
;
p
rivate
TableStruct
t
able
;
/**
/**
* 缓存的SQL信息
* 缓存的SQL信息
*/
*/
p
ublic
MemoryCache
<
SqlData
>
S
qls
=
new
MemoryCache
<
SqlData
>();
p
rivate
MemoryCache
<
SqlData
>
s
qls
=
new
MemoryCache
<
SqlData
>();
/**
/**
* 构造函数
* 构造函数
*/
*/
public
TableSqlCache
()
{
public
TableSqlCache
()
{
this
.
T
able
=
new
TableStruct
();
this
.
t
able
=
new
TableStruct
();
}
}
/**
/**
...
@@ -57,7 +57,7 @@ public class TableSqlCache {
...
@@ -57,7 +57,7 @@ public class TableSqlCache {
*/
*/
public
SqlData
add
(
SqlData
sql
)
{
public
SqlData
add
(
SqlData
sql
)
{
if
(
sql
!=
null
)
{
if
(
sql
!=
null
)
{
this
.
Sqls
.
put
(
sql
.
Name
,
sql
);
this
.
sqls
.
put
(
sql
.
getName
()
,
sql
);
}
}
return
sql
;
return
sql
;
}
}
...
@@ -83,8 +83,8 @@ public class TableSqlCache {
...
@@ -83,8 +83,8 @@ public class TableSqlCache {
*/
*/
public
SqlData
addPageSize
(
SqlData
from
,
String
sql
)
{
public
SqlData
addPageSize
(
SqlData
from
,
String
sql
)
{
SqlData
to
=
from
.
copy
();
SqlData
to
=
from
.
copy
();
to
.
S
ql
=
sql
;
to
.
s
ql
=
sql
;
to
.
N
ame
+=
TableSqlCache
.
PAGE_SIZE_TAG
;
to
.
n
ame
+=
TableSqlCache
.
PAGE_SIZE_TAG
;
return
this
.
add
(
to
);
return
this
.
add
(
to
);
}
}
...
@@ -95,7 +95,7 @@ public class TableSqlCache {
...
@@ -95,7 +95,7 @@ public class TableSqlCache {
* @param addField
* @param addField
*/
*/
public
void
addGroup
(
TableFieldString
tableWhereField
,
TableFieldString
addField
)
{
public
void
addGroup
(
TableFieldString
tableWhereField
,
TableFieldString
addField
)
{
this
.
T
able
.
addGroupSql
(
this
,
tableWhereField
,
addField
);
this
.
t
able
.
addGroupSql
(
this
,
tableWhereField
,
addField
);
}
}
...
@@ -106,7 +106,7 @@ public class TableSqlCache {
...
@@ -106,7 +106,7 @@ public class TableSqlCache {
* @param whereFields
* @param whereFields
*/
*/
public
void
addSaveWith
(
String
sqlName
,
TableFieldString
whereFields
)
{
public
void
addSaveWith
(
String
sqlName
,
TableFieldString
whereFields
)
{
this
.
T
able
.
addSaveWithSql
(
this
,
sqlName
,
whereFields
);
this
.
t
able
.
addSaveWithSql
(
this
,
sqlName
,
whereFields
);
}
}
/**
/**
...
@@ -146,48 +146,48 @@ public class TableSqlCache {
...
@@ -146,48 +146,48 @@ public class TableSqlCache {
}
}
// 2. 判断所有纬度字段是否已经存在
// 2. 判断所有纬度字段是否已经存在
for
(
String
item
:
tableWhereField
.
F
ields
)
{
for
(
String
item
:
tableWhereField
.
f
ields
)
{
String
name
=
item
.
toLowerCase
();
String
name
=
item
.
toLowerCase
();
if
(!
sqlFieldHas
.
containsKey
(
name
))
{
if
(!
sqlFieldHas
.
containsKey
(
name
))
{
throw
new
CodeException
(
"SQL语句"
+
item
+
"不存在纬度"
+
item
);
throw
new
CodeException
(
"SQL语句"
+
item
+
"不存在纬度"
+
item
);
}
}
sqlFieldWhere
.
put
(
name
,
true
);
sqlFieldWhere
.
put
(
name
,
true
);
}
}
for
(
String
item
:
addField
.
F
ields
)
{
for
(
String
item
:
addField
.
f
ields
)
{
String
name
=
item
.
toLowerCase
();
String
name
=
item
.
toLowerCase
();
sqlFieldAdd
.
put
(
name
,
true
);
sqlFieldAdd
.
put
(
name
,
true
);
}
}
// 3. 生成SQL语句
// 3. 生成SQL语句
String
selectModel
=
"SELECT {FromField} FROM ( {SQL} )t"
;
String
selectModel
=
"SELECT {FromField} FROM ( {SQL} )t"
;
String
initModel
=
"INSERT INTO {
T
able}( {CreateField} ) "
+
String
initModel
=
"INSERT INTO {
t
able}( {CreateField} ) "
+
"SELECT {FromInitField} FROM( {SelectSQL} )a "
+
"SELECT {FromInitField} FROM( {SelectSQL} )a "
+
"LEFT JOIN {
T
able} AS b ON a.{Key} = b.{Key} WHERE b.{Key} IS NULL"
;
"LEFT JOIN {
t
able} AS b ON a.{Key} = b.{Key} WHERE b.{Key} IS NULL"
;
String
addModel
=
"UPDATE {
T
able} AS a INNER JOIN ( {SelectSQL} ) AS b ON a.{Key} = b.{Key} SET {addConst} "
;
String
addModel
=
"UPDATE {
t
able} AS a INNER JOIN ( {SelectSQL} ) AS b ON a.{Key} = b.{Key} SET {addConst} "
;
// 定义需要处理的SQL对象
// 定义需要处理的SQL对象
Map
<
String
,
StringBuilder
>
map
=
new
HashMap
<
String
,
StringBuilder
>();
Map
<
String
,
StringBuilder
>
map
=
new
HashMap
<
String
,
StringBuilder
>();
addString
(
map
,
"{SQL}"
,
sql
);
addString
(
map
,
"{SQL}"
,
sql
);
addString
(
map
,
"{
Table}"
,
this
.
T
able
.
getName
());
addString
(
map
,
"{
table}"
,
this
.
t
able
.
getName
());
if
(
this
.
T
able
.
getKeyType
()
==
String
.
class
)
{
if
(
this
.
t
able
.
getKeyType
()
==
String
.
class
)
{
addString
(
map
,
"{Key}"
,
this
.
T
able
.
getKeyName
());
addString
(
map
,
"{Key}"
,
this
.
t
able
.
getKeyName
());
}
else
if
(!
StringHelper
.
isEmpty
(
this
.
T
able
.
getMD5KeyName
()))
{
}
else
if
(!
StringHelper
.
isEmpty
(
this
.
t
able
.
getMD5KeyName
()))
{
addString
(
map
,
"{Key}"
,
this
.
T
able
.
getMD5KeyName
());
addString
(
map
,
"{Key}"
,
this
.
t
able
.
getMD5KeyName
());
}
else
{
}
else
{
throw
new
CodeException
(
"表中未包含MD5字段"
);
throw
new
CodeException
(
"表中未包含MD5字段"
);
}
}
String
lowerKey
=
this
.
T
able
.
getKeyName
().
toLowerCase
();
String
lowerKey
=
this
.
t
able
.
getKeyName
().
toLowerCase
();
String
lowerMD5Key
=
this
.
T
able
.
getMD5KeyName
().
toLowerCase
();
String
lowerMD5Key
=
this
.
t
able
.
getMD5KeyName
().
toLowerCase
();
List
<
TableFieldVo
>
allField
=
new
ArrayList
<
TableFieldVo
>();
List
<
TableFieldVo
>
allField
=
new
ArrayList
<
TableFieldVo
>();
allField
.
add
(
this
.
T
able
.
getKey
());
allField
.
add
(
this
.
t
able
.
getKey
());
allField
.
addAll
(
this
.
T
able
.
getFields
());
allField
.
addAll
(
this
.
t
able
.
getFields
());
for
(
TableFieldVo
fieldVo
:
allField
)
{
for
(
TableFieldVo
fieldVo
:
allField
)
{
String
fieldName
=
fieldVo
.
name
;
String
fieldName
=
fieldVo
.
name
;
String
fieldLName
=
fieldVo
.
lName
;
String
fieldLName
=
fieldVo
.
lName
;
if
(
fieldLName
.
equals
(
lowerKey
)
&&
this
.
T
able
.
getKeyType
()
!=
String
.
class
)
{
if
(
fieldLName
.
equals
(
lowerKey
)
&&
this
.
t
able
.
getKeyType
()
!=
String
.
class
)
{
continue
;
continue
;
}
}
...
@@ -202,7 +202,7 @@ public class TableSqlCache {
...
@@ -202,7 +202,7 @@ public class TableSqlCache {
// 处理需要MD5的字段
// 处理需要MD5的字段
addString
(
map
,
"{FromField}"
,
"MD5(CONCAT("
);
addString
(
map
,
"{FromField}"
,
"MD5(CONCAT("
);
int
i
=
0
;
int
i
=
0
;
for
(
String
whereField
:
tableWhereField
.
F
ields
)
{
for
(
String
whereField
:
tableWhereField
.
f
ields
)
{
if
(
i
>
0
)
{
if
(
i
>
0
)
{
addString
(
map
,
"{FromField}"
,
",':',"
);
addString
(
map
,
"{FromField}"
,
",':',"
);
}
}
...
@@ -231,7 +231,7 @@ public class TableSqlCache {
...
@@ -231,7 +231,7 @@ public class TableSqlCache {
addString
(
map
,
"{FromInitField}"
,
"0 AS "
+
fieldName
);
addString
(
map
,
"{FromInitField}"
,
"0 AS "
+
fieldName
);
}
else
{
}
else
{
addString
(
map
,
"{FromInitField}"
,
"a."
+
fieldName
);
addString
(
map
,
"{FromInitField}"
,
"a."
+
fieldName
);
System
.
err
.
println
(
"纬度"
+
this
.
T
able
.
getName
()
+
"->"
+
sqlName
+
"->"
+
fieldName
+
"存在,但是没有统计"
);
System
.
err
.
println
(
"纬度"
+
this
.
t
able
.
getName
()
+
"->"
+
sqlName
+
"->"
+
fieldName
+
"存在,但是没有统计"
);
}
}
}
}
}
}
...
@@ -239,8 +239,8 @@ public class TableSqlCache {
...
@@ -239,8 +239,8 @@ public class TableSqlCache {
// 最终SQL语句处理
// 最终SQL语句处理
selectModel
=
replaceString
(
map
,
selectModel
);
selectModel
=
replaceString
(
map
,
selectModel
);
addString
(
map
,
"{SelectSQL}"
,
selectModel
);
addString
(
map
,
"{SelectSQL}"
,
selectModel
);
sqlInit
.
S
ql
=
replaceString
(
map
,
initModel
);
sqlInit
.
s
ql
=
replaceString
(
map
,
initModel
);
sqlAdd
.
S
ql
=
replaceString
(
map
,
addModel
);
sqlAdd
.
s
ql
=
replaceString
(
map
,
addModel
);
this
.
add
(
sqlInit
);
this
.
add
(
sqlInit
);
this
.
add
(
sqlAdd
);
this
.
add
(
sqlAdd
);
...
@@ -258,7 +258,7 @@ public class TableSqlCache {
...
@@ -258,7 +258,7 @@ public class TableSqlCache {
* @param fields 字段
* @param fields 字段
*/
*/
public
void
addExist
(
String
sqlName
,
String
...
fields
)
{
public
void
addExist
(
String
sqlName
,
String
...
fields
)
{
this
.
T
able
.
addExist
(
this
,
sqlName
,
fields
);
this
.
t
able
.
addExist
(
this
,
sqlName
,
fields
);
}
}
private
void
addString
(
Map
<
String
,
StringBuilder
>
map
,
String
name
,
String
value
)
{
private
void
addString
(
Map
<
String
,
StringBuilder
>
map
,
String
name
,
String
value
)
{
...
@@ -282,4 +282,20 @@ public class TableSqlCache {
...
@@ -282,4 +282,20 @@ public class TableSqlCache {
}
}
return
sql
;
return
sql
;
}
}
public
TableStruct
getTable
()
{
return
table
;
}
public
void
setTable
(
TableStruct
table
)
{
this
.
table
=
table
;
}
public
MemoryCache
<
SqlData
>
getSqls
()
{
return
sqls
;
}
public
void
setSqls
(
MemoryCache
<
SqlData
>
sqls
)
{
this
.
sqls
=
sqls
;
}
}
}
yzg-util-db/src/main/java/com/yanzuoguang/dao/
I
mpl/TableStruct.java
→
yzg-util-db/src/main/java/com/yanzuoguang/dao/
i
mpl/TableStruct.java
View file @
d367dd7b
This diff is collapsed.
Click to expand it.
yzg-util-db/src/main/java/com/yanzuoguang/db/DbExecute.java
View file @
d367dd7b
package
com
.
yanzuoguang
.
db
;
package
com
.
yanzuoguang
.
db
;
import
com.yanzuoguang.db.
I
mpl.DbRow
;
import
com.yanzuoguang.db.
i
mpl.DbRow
;
import
com.yanzuoguang.util.vo.MapRow
;
import
com.yanzuoguang.util.vo.MapRow
;
import
java.util.List
;
import
java.util.List
;
...
...
yzg-util-db/src/main/java/com/yanzuoguang/db/
I
mpl/AllBeanRowMapper.java
→
yzg-util-db/src/main/java/com/yanzuoguang/db/
i
mpl/AllBeanRowMapper.java
View file @
d367dd7b
package
com
.
yanzuoguang
.
db
.
I
mpl
;
package
com
.
yanzuoguang
.
db
.
i
mpl
;
import
com.yanzuoguang.dao.DaoConst
;
import
com.yanzuoguang.dao.DaoConst
;
import
com.yanzuoguang.extend.ConfigDb
;
import
com.yanzuoguang.extend.ConfigDb
;
import
com.yanzuoguang.util.base.ObjectHelper
;
import
com.yanzuoguang.util.base.ObjectHelper
;
import
com.yanzuoguang.util.helper.DateHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.log.Log
;
import
com.yanzuoguang.util.log.Log
;
import
com.yanzuoguang.util.vo.MapRow
;
import
com.yanzuoguang.util.vo.MapRow
;
...
@@ -20,7 +19,6 @@ import java.lang.reflect.Modifier;
...
@@ -20,7 +19,6 @@ import java.lang.reflect.Modifier;
import
java.sql.ResultSet
;
import
java.sql.ResultSet
;
import
java.sql.ResultSetMetaData
;
import
java.sql.ResultSetMetaData
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
java.sql.Timestamp
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -251,9 +249,9 @@ public class AllBeanRowMapper<T> implements RowMapper<T> {
...
@@ -251,9 +249,9 @@ public class AllBeanRowMapper<T> implements RowMapper<T> {
*/
*/
private
String
getCamelCase
(
String
column
)
{
private
String
getCamelCase
(
String
column
)
{
switch
(
configDb
.
getRowNameType
())
{
switch
(
configDb
.
getRowNameType
())
{
case
DaoConst
.
R
owNameTypeNoChange
:
case
DaoConst
.
R
OW_NAME_TYPE_NO_CHANGE
:
break
;
break
;
case
DaoConst
.
R
owNameTypeCamelCase
:
case
DaoConst
.
R
OW_NAME_TYPE_CAMEL_CASE
:
default
:
default
:
column
=
StringHelper
.
getCamelCase
(
column
);
column
=
StringHelper
.
getCamelCase
(
column
);
break
;
break
;
...
...
yzg-util-db/src/main/java/com/yanzuoguang/db/
I
mpl/DbExecuteImpl.java
→
yzg-util-db/src/main/java/com/yanzuoguang/db/
i
mpl/DbExecuteImpl.java
View file @
d367dd7b
package
com
.
yanzuoguang
.
db
.
I
mpl
;
package
com
.
yanzuoguang
.
db
.
i
mpl
;
import
com.yanzuoguang.db.DbExecute
;
import
com.yanzuoguang.db.DbExecute
;
import
com.yanzuoguang.extend.ConfigDb
;
import
com.yanzuoguang.extend.ConfigDb
;
...
@@ -14,7 +14,6 @@ import javax.annotation.Resource;
...
@@ -14,7 +14,6 @@ import javax.annotation.Resource;
import
java.sql.ResultSet
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
...
yzg-util-db/src/main/java/com/yanzuoguang/db/
I
mpl/DbPrintSql.java
→
yzg-util-db/src/main/java/com/yanzuoguang/db/
i
mpl/DbPrintSql.java
View file @
d367dd7b
package
com
.
yanzuoguang
.
db
.
I
mpl
;
package
com
.
yanzuoguang
.
db
.
i
mpl
;
import
com.yanzuoguang.extend.ConfigDb
;
import
com.yanzuoguang.extend.ConfigDb
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
...
...
yzg-util-db/src/main/java/com/yanzuoguang/db/
I
mpl/DbRow.java
→
yzg-util-db/src/main/java/com/yanzuoguang/db/
i
mpl/DbRow.java
View file @
d367dd7b
package
com
.
yanzuoguang
.
db
.
I
mpl
;
package
com
.
yanzuoguang
.
db
.
i
mpl
;
/**
/**
* 处理行数据
* 处理行数据
...
...
yzg-util-db/src/main/java/com/yanzuoguang/service/
I
mpl/BaseServiceImpl.java
→
yzg-util-db/src/main/java/com/yanzuoguang/service/
i
mpl/BaseServiceImpl.java
View file @
d367dd7b
package
com
.
yanzuoguang
.
service
.
I
mpl
;
package
com
.
yanzuoguang
.
service
.
i
mpl
;
import
com.yanzuoguang.dao.BaseDao
;
import
com.yanzuoguang.dao.BaseDao
;
import
com.yanzuoguang.service.BaseService
;
import
com.yanzuoguang.service.BaseService
;
...
...
yzg-util-mq/src/main/java/com/yanzuoguang/mq/dao/impl/MessageDaoImpl.java
View file @
d367dd7b
package
com
.
yanzuoguang
.
mq
.
dao
.
impl
;
package
com
.
yanzuoguang
.
mq
.
dao
.
impl
;
import
com.yanzuoguang.dao.DaoConst
;
import
com.yanzuoguang.dao.DaoConst
;
import
com.yanzuoguang.dao.
I
mpl.BaseDaoImpl
;
import
com.yanzuoguang.dao.
i
mpl.BaseDaoImpl
;
import
com.yanzuoguang.dao.
I
mpl.SqlData
;
import
com.yanzuoguang.dao.
i
mpl.SqlData
;
import
com.yanzuoguang.mq.dao.MessageDao
;
import
com.yanzuoguang.mq.dao.MessageDao
;
import
com.yanzuoguang.mq.vo.MessageVo
;
import
com.yanzuoguang.mq.vo.MessageVo
;
import
com.yanzuoguang.util.vo.MapRow
;
import
com.yanzuoguang.util.vo.MapRow
;
...
@@ -20,11 +20,11 @@ public class MessageDaoImpl extends BaseDaoImpl implements MessageDao {
...
@@ -20,11 +20,11 @@ public class MessageDaoImpl extends BaseDaoImpl implements MessageDao {
protected
void
init
()
{
protected
void
init
()
{
register
(
MessageVo
.
class
);
register
(
MessageVo
.
class
);
Table
.
add
(
DaoConst
.
Query
,
"SELECT a.* FROM Queue_Message AS a WHERE 1=1 "
)
table
.
add
(
DaoConst
.
QUERY
,
"SELECT a.* FROM Queue_Message AS a WHERE 1=1 "
)
.
add
(
"batchId"
,
"AND a.batchId=?"
)
.
add
(
"batchId"
,
"AND a.batchId=?"
)
;
;
T
able
.
add
(
UPDATE_BATCH_SQL
,
"UPDATE Queue_Message AS a "
+
t
able
.
add
(
UPDATE_BATCH_SQL
,
"UPDATE Queue_Message AS a "
+
"INNER JOIN ( SELECT * FROM Queue_Message WHERE (HandleTime IS NULL OR HandleTime < NOW()) "
+
"INNER JOIN ( SELECT * FROM Queue_Message WHERE (HandleTime IS NULL OR HandleTime < NOW()) "
+
"ORDER BY HandleTime ASC,MessageId ASC {LIMIT} ) AS b ON a.MessageId = b.MessageId "
+
"ORDER BY HandleTime ASC,MessageId ASC {LIMIT} ) AS b ON a.MessageId = b.MessageId "
+
"SET a.BatchId = ?,a.HandleTime=DATE_ADD(NOW(),INTERVAL 5 MINUTE) "
,
"batchId"
);
"SET a.BatchId = ?,a.HandleTime=DATE_ADD(NOW(),INTERVAL 5 MINUTE) "
,
"batchId"
);
...
@@ -57,6 +57,6 @@ public class MessageDaoImpl extends BaseDaoImpl implements MessageDao {
...
@@ -57,6 +57,6 @@ public class MessageDaoImpl extends BaseDaoImpl implements MessageDao {
public
List
<
MessageVo
>
getListByBatch
(
String
batchId
)
{
public
List
<
MessageVo
>
getListByBatch
(
String
batchId
)
{
MapRow
row
=
new
MapRow
();
MapRow
row
=
new
MapRow
();
row
.
put
(
"batchId"
,
batchId
);
row
.
put
(
"batchId"
,
batchId
);
return
this
.
query
(
MessageVo
.
class
,
DaoConst
.
Q
uery
,
row
);
return
this
.
query
(
MessageVo
.
class
,
DaoConst
.
Q
UERY
,
row
);
}
}
}
}
yzg-util-mq/src/main/java/com/yanzuoguang/mq/dao/impl/QueueDaoImpl.java
View file @
d367dd7b
package
com
.
yanzuoguang
.
mq
.
dao
.
impl
;
package
com
.
yanzuoguang
.
mq
.
dao
.
impl
;
import
com.yanzuoguang.dao.DaoConst
;
import
com.yanzuoguang.dao.DaoConst
;
import
com.yanzuoguang.dao.
I
mpl.BaseDaoImpl
;
import
com.yanzuoguang.dao.
i
mpl.BaseDaoImpl
;
import
com.yanzuoguang.dao.
I
mpl.TableFieldString
;
import
com.yanzuoguang.dao.
i
mpl.TableFieldString
;
import
com.yanzuoguang.mq.dao.QueueDao
;
import
com.yanzuoguang.mq.dao.QueueDao
;
import
com.yanzuoguang.mq.vo.QueueVo
;
import
com.yanzuoguang.mq.vo.QueueVo
;
import
com.yanzuoguang.mq.vo.req.QueueQueryReqVo
;
import
com.yanzuoguang.mq.vo.req.QueueQueryReqVo
;
...
@@ -24,9 +24,9 @@ public class QueueDaoImpl extends BaseDaoImpl implements QueueDao {
...
@@ -24,9 +24,9 @@ public class QueueDaoImpl extends BaseDaoImpl implements QueueDao {
// 根据实体生成增删改查语句
// 根据实体生成增删改查语句
register
(
QueueVo
.
class
);
register
(
QueueVo
.
class
);
T
able
.
addSaveWith
(
SAVE_WITH_SQL
,
new
TableFieldString
(
"queueName"
,
"exchangeName"
,
"routeKey"
));
t
able
.
addSaveWith
(
SAVE_WITH_SQL
,
new
TableFieldString
(
"queueName"
,
"exchangeName"
,
"routeKey"
));
Table
.
add
(
DaoConst
.
Query
,
"SELECT * FROM Queue_Queue WHERE 1=1 "
)
table
.
add
(
DaoConst
.
QUERY
,
"SELECT * FROM Queue_Queue WHERE 1=1 "
)
.
add
(
"queueName"
,
"AND ( QueueName LIKE CONCAT('%',?,'%') OR DelayQueueName LIKE CONCAT('%',?,'%') )"
)
.
add
(
"queueName"
,
"AND ( QueueName LIKE CONCAT('%',?,'%') OR DelayQueueName LIKE CONCAT('%',?,'%') )"
)
.
add
(
"exchangeName"
,
"AND ( ExchangeName LIKE CONCAT('%',?,'%') OR DelayExchangeName LIKE CONCAT('%',?,'%') )"
)
.
add
(
"exchangeName"
,
"AND ( ExchangeName LIKE CONCAT('%',?,'%') OR DelayExchangeName LIKE CONCAT('%',?,'%') )"
)
.
add
(
"routeKey"
,
"AND ( RouteKey LIKE CONCAT('%',?,'%') OR DelayRouteKey LIKE CONCAT('%',?,'%') )"
)
.
add
(
"routeKey"
,
"AND ( RouteKey LIKE CONCAT('%',?,'%') OR DelayRouteKey LIKE CONCAT('%',?,'%') )"
)
...
@@ -53,7 +53,7 @@ public class QueueDaoImpl extends BaseDaoImpl implements QueueDao {
...
@@ -53,7 +53,7 @@ public class QueueDaoImpl extends BaseDaoImpl implements QueueDao {
*/
*/
@Override
@Override
public
PageSizeData
<
QueueVo
>
query
(
QueueQueryReqVo
req
)
{
public
PageSizeData
<
QueueVo
>
query
(
QueueQueryReqVo
req
)
{
return
this
.
queryPage
(
QueueVo
.
class
,
req
,
DaoConst
.
Q
uery
,
req
);
return
this
.
queryPage
(
QueueVo
.
class
,
req
,
DaoConst
.
Q
UERY
,
req
);
}
}
/**
/**
...
@@ -63,6 +63,6 @@ public class QueueDaoImpl extends BaseDaoImpl implements QueueDao {
...
@@ -63,6 +63,6 @@ public class QueueDaoImpl extends BaseDaoImpl implements QueueDao {
*/
*/
@Override
@Override
public
List
<
QueueVo
>
list
()
{
public
List
<
QueueVo
>
list
()
{
return
this
.
query
(
QueueVo
.
class
,
DaoConst
.
Q
uery
,
null
);
return
this
.
query
(
QueueVo
.
class
,
DaoConst
.
Q
UERY
,
null
);
}
}
}
}
yzg-util-mq/src/main/java/com/yanzuoguang/mq/service/MqService.java
View file @
d367dd7b
...
@@ -48,7 +48,7 @@ public interface MqService {
...
@@ -48,7 +48,7 @@ public interface MqService {
* @param req
* @param req
* @return
* @return
*/
*/
String
message
_e
rror
(
MessageVo
req
);
String
message
E
rror
(
MessageVo
req
);
/**
/**
* 消息收到确认
* 消息收到确认
...
...
yzg-util-mq/src/main/java/com/yanzuoguang/mq/service/impl/MqServiceImpl.java
View file @
d367dd7b
...
@@ -77,7 +77,7 @@ public class MqServiceImpl implements MqService {
...
@@ -77,7 +77,7 @@ public class MqServiceImpl implements MqService {
* @return
* @return
*/
*/
@Override
@Override
public
String
message
_e
rror
(
MessageVo
req
)
{
public
String
message
E
rror
(
MessageVo
req
)
{
req
.
check
();
req
.
check
();
return
messageService
.
onError
(
req
);
return
messageService
.
onError
(
req
);
}
}
...
...
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