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
492a68f3
Commit
492a68f3
authored
May 07, 2019
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
消除成功接收处理
parent
37d70485
Changes
24
Hide whitespace changes
Inline
Side-by-side
Showing
24 changed files
with
212 additions
and
133 deletions
+212
-133
ObjectHelper.java
...src/main/java/com/yanzuoguang/util/base/ObjectHelper.java
+2
-1
CheckerHelper.java
.../main/java/com/yanzuoguang/util/helper/CheckerHelper.java
+4
-2
DateAutoHelper.java
...main/java/com/yanzuoguang/util/helper/DateAutoHelper.java
+9
-3
FileHelper.java
...src/main/java/com/yanzuoguang/util/helper/FileHelper.java
+6
-3
HttpHelper.java
...src/main/java/com/yanzuoguang/util/helper/HttpHelper.java
+6
-3
JsonHelper.java
...src/main/java/com/yanzuoguang/util/helper/JsonHelper.java
+7
-2
RunHelper.java
.../src/main/java/com/yanzuoguang/util/helper/RunHelper.java
+2
-1
StringHelper.java
...c/main/java/com/yanzuoguang/util/helper/StringHelper.java
+15
-9
RunPlanData.java
...rc/main/java/com/yanzuoguang/util/thread/RunPlanData.java
+2
-2
RunnableListAuto.java
...in/java/com/yanzuoguang/util/thread/RunnableListAuto.java
+1
-1
ThreadHelper.java
...c/main/java/com/yanzuoguang/util/thread/ThreadHelper.java
+3
-1
ThreadNext.java
...src/main/java/com/yanzuoguang/util/thread/ThreadNext.java
+28
-23
BaseVo.java
...il-base/src/main/java/com/yanzuoguang/util/vo/BaseVo.java
+2
-2
BaseRequestAspect.java
...ain/java/com/yanzuoguang/cloud/aop/BaseRequestAspect.java
+11
-5
WebAspect.java
...ud/src/main/java/com/yanzuoguang/cloud/aop/WebAspect.java
+7
-6
CodePwdImpl.java
...il-db/src/main/java/com/yanzuoguang/code/CodePwdImpl.java
+30
-24
DaoConst.java
yzg-util-db/src/main/java/com/yanzuoguang/dao/DaoConst.java
+4
-0
BaseDaoImpl.java
...b/src/main/java/com/yanzuoguang/dao/impl/BaseDaoImpl.java
+3
-3
BaseDaoSql.java
...db/src/main/java/com/yanzuoguang/dao/impl/BaseDaoSql.java
+50
-30
TableSqlCache.java
...src/main/java/com/yanzuoguang/dao/impl/TableSqlCache.java
+5
-4
AllBeanRowMapper.java
...c/main/java/com/yanzuoguang/db/impl/AllBeanRowMapper.java
+3
-3
BeanDao.java
...util-mq/src/main/java/com/yanzuoguang/mq/dao/BeanDao.java
+5
-2
MessageDaoImpl.java
...main/java/com/yanzuoguang/mq/dao/impl/MessageDaoImpl.java
+1
-1
QueueServiceImpl.java
...ava/com/yanzuoguang/mq/service/impl/QueueServiceImpl.java
+6
-2
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/base/ObjectHelper.java
View file @
492a68f3
...
...
@@ -292,7 +292,8 @@ public class ObjectHelper {
while
(
tempClass
!=
null
)
{
fields
.
addAll
(
Arrays
.
asList
(
tempClass
.
getDeclaredFields
()));
methods
.
addAll
(
Arrays
.
asList
(
tempClass
.
getDeclaredMethods
()));
tempClass
=
tempClass
.
getSuperclass
();
//得到父类,然后赋给自己
//得到父类,然后赋给自己
tempClass
=
tempClass
.
getSuperclass
();
}
// 忽略大小写、忽略下划线 _
...
...
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/CheckerHelper.java
View file @
492a68f3
...
...
@@ -28,6 +28,8 @@ public final class CheckerHelper {
public
static
final
String
PARAM_NOT_MIN
=
"param [%s] must be big %d"
;
public
static
final
String
PARAM_NOT_MAX
=
"param [%s] must be max %d"
;
public
static
final
String
PARAM_NOT_RANGE
=
"param [%s] must be range %d and %d"
;
public
static
final
String
DATE_CHECK_TYPE_DAY
=
"day"
;
public
static
final
String
DATE_CHECK_TYPE_MONTH
=
"month"
;
private
boolean
isValid
=
true
;
private
String
checkResult
;
...
...
@@ -178,10 +180,10 @@ public final class CheckerHelper {
this
.
setValid
(
false
);
return
this
;
}
if
(
"day"
.
equals
(
queryType
))
{
if
(
DATE_CHECK_TYPE_DAY
.
equals
(
queryType
))
{
eL
=
"[0-9]{4}[0-9]{2}[0-9]{2}"
;
msg
=
PARAM_NOT_DATE_DAY
;
}
else
if
(
"month"
.
equals
(
queryType
))
{
}
else
if
(
DATE_CHECK_TYPE_MONTH
.
equals
(
queryType
))
{
eL
=
"[0-9]{4}[0-9]{2}"
;
msg
=
PARAM_NOT_DATE_MONTH
;
}
...
...
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/DateAutoHelper.java
View file @
492a68f3
...
...
@@ -69,11 +69,17 @@ public class DateAutoHelper {
* 时间格式字符串
*/
private
static
class
DateReplace
{
// 正则表达式
/**
* 正则表达式
*/
public
String
regex
;
// 替换表达式
/**
* 替换表达式
*/
public
String
replace
;
// 终止标志位
/**
* 终止标志位
*/
public
boolean
end
;
}
...
...
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/FileHelper.java
View file @
492a68f3
...
...
@@ -116,13 +116,16 @@ public class FileHelper {
boolean
flag
=
false
;
File
file
=
new
File
(
sPath
);
// 判断目录或文件是否存在
if
(!
file
.
exists
())
{
// 不存在返回 false
if
(!
file
.
exists
())
{
// 不存在返回 false
return
flag
;
}
else
{
// 判断是否为文件
if
(
file
.
isFile
())
{
// 为文件时调用删除文件方法
if
(
file
.
isFile
())
{
// 为文件时调用删除文件方法
return
deleteFile
(
sPath
);
}
else
{
// 为目录时调用删除目录方法
}
else
{
// 为目录时调用删除目录方法
return
deleteDirectory
(
sPath
);
}
}
...
...
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/HttpHelper.java
View file @
492a68f3
...
...
@@ -83,10 +83,13 @@ public class HttpHelper {
* @return 远程响应结果
*/
public
static
String
post
(
HttpURLConnection
httpConn
,
String
url
,
String
jsonString
)
throws
IOException
{
String
result
=
""
;
// 返回的结果
BufferedReader
in
=
null
;
// 读取响应输入流
// 返回的结果
String
result
=
""
;
// 读取响应输入流
BufferedReader
in
=
null
;
PrintWriter
out
=
null
;
StringBuffer
sb
=
new
StringBuffer
();
// 处理请求参数
// 处理请求参数
StringBuffer
sb
=
new
StringBuffer
();
String
params
=
""
;
try
{
params
=
jsonString
;
...
...
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/J
SON
Helper.java
→
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/J
son
Helper.java
View file @
492a68f3
...
...
@@ -7,7 +7,12 @@ import com.alibaba.fastjson.TypeReference;
* JSON序列化的处理
* Created by yanzu on 2017/5/28.
*/
public
class
JSONHelper
{
public
class
JsonHelper
{
/**
* JSON对象开始标记
*/
public
static
final
String
OBJECT_START_FLAG
=
"{"
;
/**
* 将JSON字符串转化为JSON对象
...
...
@@ -48,7 +53,7 @@ public class JSONHelper {
return
null
;
}
json
=
json
.
trim
();
if
(
json
.
startsWith
(
"{"
))
{
if
(
json
.
startsWith
(
OBJECT_START_FLAG
))
{
json
=
String
.
format
(
"[%s]"
,
json
);
}
return
JSON
.
parseObject
(
json
,
type
);
...
...
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/RunHelper.java
View file @
492a68f3
...
...
@@ -42,7 +42,8 @@ public class RunHelper {
break
;
}
catch
(
Exception
e
)
{
if
(
i
<
size
)
{
ThreadHelper
.
sleep
(
sleep
);
// 间隔100ms,防止服务器重启时请求失败
// 间隔100ms,防止服务器重启时请求失败
ThreadHelper
.
sleep
(
sleep
);
}
ex
=
e
;
}
...
...
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/StringHelper.java
View file @
492a68f3
...
...
@@ -139,20 +139,23 @@ public class StringHelper {
boolean
foundDigit
=
false
;
// deal with any possible sign up front
final
int
start
=
(
chars
[
0
]
==
'-'
)
?
1
:
0
;
if
(
sz
>
start
+
1
&&
chars
[
start
]
==
'0'
)
{
// leading 0
// leading 0
if
(
sz
>
start
+
1
&&
chars
[
start
]
==
'0'
)
{
if
(
(
chars
[
start
+
1
]
==
'x'
)
||
(
chars
[
start
+
1
]
==
'X'
)
)
{
// leading 0x/0X
int
i
=
start
+
2
;
if
(
i
==
sz
)
{
return
false
;
// str == "0x"
// str == "0x"
return
false
;
}
// checking hex (it can't be anything else)
for
(;
i
<
chars
.
length
;
i
++)
{
if
(
(
chars
[
i
]
<
'0'
||
chars
[
i
]
>
'9'
)
boolean
inputHex
=
(
chars
[
i
]
<
'0'
||
chars
[
i
]
>
'9'
)
&&
(
chars
[
i
]
<
'a'
||
chars
[
i
]
>
'f'
)
&&
(
chars
[
i
]
<
'A'
||
chars
[
i
]
>
'F'
))
{
&&
(
chars
[
i
]
<
'A'
||
chars
[
i
]
>
'F'
);
if
(
inputHex
)
{
return
false
;
}
}
...
...
@@ -200,7 +203,8 @@ public class StringHelper {
return
false
;
}
allowSigns
=
false
;
foundDigit
=
false
;
// we need a digit after the E
// we need a digit after the E
foundDigit
=
false
;
}
else
{
return
false
;
}
...
...
@@ -223,11 +227,12 @@ public class StringHelper {
// single trailing decimal point after non-exponent is ok
return
foundDigit
;
}
if
(
!
allowSigns
boolean
allowD
=
!
allowSigns
&&
(
chars
[
i
]
==
'd'
||
chars
[
i
]
==
'D'
||
chars
[
i
]
==
'f'
||
chars
[
i
]
==
'F'
))
{
||
chars
[
i
]
==
'F'
);
if
(
allowD
)
{
return
foundDigit
;
}
if
(
chars
[
i
]
==
'l'
...
...
@@ -467,7 +472,7 @@ public class StringHelper {
* @return 转换成功后的值
*/
public
static
double
toDecimal
(
Object
from
)
{
Double
result
=
Double
.
valueOf
(
0
)
;
double
result
=
0
;
try
{
if
(!
isEmpty
(
from
))
{
result
=
Double
.
valueOf
(
from
.
toString
());
...
...
@@ -515,7 +520,8 @@ public class StringHelper {
byte
[]
buff
;
try
{
buff
=
from
.
getBytes
(
charset
);
from
=
new
String
(
buff
);
// 将字节流转换为字符串
// 将字节流转换为字符串
from
=
new
String
(
buff
);
from
=
from
.
replace
(
"\0"
,
""
).
replace
(
"\n"
,
""
);
}
catch
(
UnsupportedEncodingException
e
)
{
ExceptionHelper
.
handleException
(
StringHelper
.
class
,
e
,
from
);
...
...
yzg-util-base/src/main/java/com/yanzuoguang/util/thread/RunPlanData.java
View file @
492a68f3
...
...
@@ -19,9 +19,9 @@ public class RunPlanData {
*/
private
double
executeCount
;
/**
* 执行时错误次数
* 执行时错误次数
,调试变量
*/
private
double
executeError
;
// 调试变量
private
double
executeError
;
/**
* 执行时间
*/
...
...
yzg-util-base/src/main/java/com/yanzuoguang/util/thread/RunnableListAuto.java
View file @
492a68f3
...
...
@@ -64,7 +64,7 @@ public final class RunnableListAuto {
// 没有执行过的列表
List
<
RunnableListAutoItem
>
initList
=
new
ArrayList
<
RunnableListAutoItem
>();
// 已经执行过的数据缓存,待排序
Map
<
String
,
List
<
RunnableListAutoItem
>>
executeMap
=
new
HashMap
<
String
,
List
<
RunnableListAutoItem
>>(
);
Map
<
String
,
List
<
RunnableListAutoItem
>>
executeMap
=
new
HashMap
<
>(
20
);
// 已执行过的列表
List
<
RunnableListAutoItem
>
executedToList
=
new
ArrayList
<
RunnableListAutoItem
>();
...
...
yzg-util-base/src/main/java/com/yanzuoguang/util/thread/ThreadHelper.java
View file @
492a68f3
...
...
@@ -16,7 +16,9 @@ public class ThreadHelper {
private
static
Date
threadDate
=
null
;
private
static
RunPlan
timeout
;
private
static
RunPlan
interval
;
// 线程对象
/**
* 线程对象
*/
private
static
ExecutorService
executeService
=
Executors
.
newCachedThreadPool
();
/**
...
...
yzg-util-base/src/main/java/com/yanzuoguang/util/thread/ThreadNext.java
View file @
492a68f3
...
...
@@ -31,30 +31,35 @@ public class ThreadNext {
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
boolean
isExecute
=
true
;
Exception
frontEx
=
null
;
while
(
isExecute
)
{
try
{
isExecute
=
next
.
next
();
}
catch
(
Exception
ex
)
{
if
(
frontEx
==
null
||
!(
frontEx
.
getClass
()
==
ex
.
getClass
()
&&
StringHelper
.
compare
(
frontEx
.
getMessage
(),
ex
.
getMessage
())))
{
Log
.
error
(
ThreadNext
.
class
,
ex
);
}
frontEx
=
ex
;
}
if
(
isExecute
)
{
try
{
int
max
=
Math
.
max
(
next
.
getNextTime
(),
100
);
Thread
.
sleep
(
max
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
}
else
{
break
;
}
}
runNext
(
next
);
}
}).
start
();
}
private
static
void
runNext
(
Next
next
)
{
boolean
isExecute
=
true
;
Exception
frontEx
=
null
;
while
(
isExecute
)
{
try
{
isExecute
=
next
.
next
();
}
catch
(
Exception
ex
)
{
boolean
isHistoryEx
=
frontEx
==
null
||
!(
frontEx
.
getClass
()
==
ex
.
getClass
()
&&
StringHelper
.
compare
(
frontEx
.
getMessage
(),
ex
.
getMessage
()));
if
(
isHistoryEx
)
{
Log
.
error
(
ThreadNext
.
class
,
ex
);
}
frontEx
=
ex
;
}
if
(
isExecute
)
{
try
{
int
max
=
Math
.
max
(
next
.
getNextTime
(),
100
);
Thread
.
sleep
(
max
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
}
else
{
break
;
}
}
}
}
yzg-util-base/src/main/java/com/yanzuoguang/util/vo/BaseVo.java
View file @
492a68f3
package
com
.
yanzuoguang
.
util
.
vo
;
import
com.yanzuoguang.util.helper.J
SON
Helper
;
import
com.yanzuoguang.util.helper.J
son
Helper
;
import
java.io.Serializable
;
...
...
@@ -18,6 +18,6 @@ public class BaseVo implements Serializable {
*/
@Override
public
String
toString
()
{
return
J
SON
Helper
.
serialize
(
this
);
return
J
son
Helper
.
serialize
(
this
);
}
}
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/BaseRequestAspect.java
View file @
492a68f3
...
...
@@ -40,7 +40,9 @@ public class BaseRequestAspect implements ThreadNext.Next {
*/
protected
volatile
LinkedBlockingQueue
<
LogVo
>
cache
=
new
LinkedBlockingQueue
<
LogVo
>();
// 缓存的每次请求的结果
/**
* 缓存的每次请求的结果
*/
protected
MemoryCache
<
RequestCacheResult
>
cacheResult
=
new
MemoryCache
<>(
cacheTime
);
public
BaseRequestAspect
()
{
...
...
@@ -67,8 +69,10 @@ public class BaseRequestAspect implements ThreadNext.Next {
protected
LogVo
initLogInterVo
(
String
url
,
ProceedingJoinPoint
joinPoint
,
ResponseResult
responseResult
)
{
LogVo
logInterVo
=
new
LogVo
();
logInterVo
.
setLogId
(
StringHelper
.
getNewID
());
logInterVo
.
setLogSources
(
applicationName
);
//平台名
logInterVo
.
setInterUrl
(
url
);
//请求URL
//平台名
logInterVo
.
setLogSources
(
applicationName
);
//请求URL
logInterVo
.
setInterUrl
(
url
);
List
<
Object
>
para
=
new
ArrayList
<>();
for
(
Object
item
:
joinPoint
.
getArgs
())
{
if
(
item
instanceof
HttpServlet
||
item
instanceof
HttpServletResponse
||
item
instanceof
HttpServletRequest
)
{
...
...
@@ -80,8 +84,10 @@ public class BaseRequestAspect implements ThreadNext.Next {
if
(
para
.
size
()
==
1
)
{
paraTo
=
para
.
get
(
0
);
}
logInterVo
.
setContent
(
JSON
.
toJSONString
(
paraTo
));
//请求参数
logInterVo
.
setResult
(
JSON
.
toJSONString
(
responseResult
));
//返回参数
//请求参数
logInterVo
.
setContent
(
JSON
.
toJSONString
(
paraTo
));
//返回参数
logInterVo
.
setResult
(
JSON
.
toJSONString
(
responseResult
));
logInterVo
.
setStatus
(
responseResult
!=
null
&&
responseResult
.
getCode
()
==
ResultConstants
.
SUCCESS
?
1
:
0
);
return
logInterVo
;
}
...
...
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/WebAspect.java
View file @
492a68f3
...
...
@@ -3,7 +3,7 @@ package com.yanzuoguang.cloud.aop;
import
com.yanzuoguang.util.base.ObjectHelper
;
import
com.yanzuoguang.util.contants.ResultConstants
;
import
com.yanzuoguang.util.exception.ExceptionHelper
;
import
com.yanzuoguang.util.helper.J
SON
Helper
;
import
com.yanzuoguang.util.helper.J
son
Helper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.log.Log
;
import
com.yanzuoguang.util.vo.LogVo
;
...
...
@@ -51,7 +51,8 @@ public class WebAspect extends BaseRequestAspect {
@Around
(
value
=
"webAspect()"
)
public
Object
requestWebAround
(
ProceedingJoinPoint
joinPoint
)
throws
Throwable
{
Log
.
threadBegin
();
ResponseResult
responseResult
=
null
;
// 用户数据库记录
// 用户数据库记录
ResponseResult
responseResult
=
null
;
long
start
=
System
.
currentTimeMillis
();
String
name
=
joinPoint
.
getSignature
().
getName
();
try
{
...
...
@@ -100,17 +101,17 @@ public class WebAspect extends BaseRequestAspect {
}
private
Object
executeMethod
(
ProceedingJoinPoint
joinPoint
,
String
name
)
throws
Throwable
{
if
(
joinPoint
.
getArgs
().
length
!=
1
boolean
dataArgs
=
joinPoint
.
getArgs
().
length
!=
1
||
joinPoint
.
getArgs
().
length
==
1
&&
(
joinPoint
.
getArgs
()[
0
]
instanceof
ServletResponse
||
joinPoint
.
getArgs
()[
0
]
instanceof
ServletRequest
)
)
{
(
joinPoint
.
getArgs
()[
0
]
instanceof
ServletResponse
||
joinPoint
.
getArgs
()[
0
]
instanceof
ServletRequest
)
;
if
(
dataArgs
)
{
return
joinPoint
.
proceed
();
}
else
{
// 获取请求编号
Object
firstArgs
=
joinPoint
.
getArgs
().
length
>
0
?
joinPoint
.
getArgs
()[
0
]
:
null
;
String
reqId
=
ObjectHelper
.
getString
(
firstArgs
,
"reqId"
);
if
(
StringHelper
.
isEmpty
(
reqId
))
{
reqId
=
StringHelper
.
md5
(
J
SON
Helper
.
serialize
(
firstArgs
));
reqId
=
StringHelper
.
md5
(
J
son
Helper
.
serialize
(
firstArgs
));
}
else
{
// 请求编号和公司编号挂钩
reqId
=
StringHelper
.
getId
(
ObjectHelper
.
getString
(
firstArgs
,
"companyId"
),
reqId
);
...
...
yzg-util-db/src/main/java/com/yanzuoguang/code/CodePwdImpl.java
View file @
492a68f3
package
com
.
yanzuoguang
.
code
;
import
com.yanzuoguang.dao.DaoConst
;
import
com.yanzuoguang.util.helper.ByteHelper
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Random
;
/**
* 加密算法0版实现
*/
...
...
@@ -120,28 +126,28 @@ public class CodePwdImpl implements CodePwd {
return
ret
;
}
// public static void main
(String[] args) {
//
int[] pos2 = {3, 4, 5, 6, 8};
//
int startPos = 0;
//
int endPos = 1000000;
//
//
Date start = new Date();
// CodePwdReplaceImpl item = new CodePwdReplace
Impl();
// Map<String, Integer> map = new HashMap<>(
);
//
for (int i = startPos; i < endPos; i++) {
//
String index = String.format("%09d", i);
//
String code = item.getCode("", "", index, "18532354168");
//
if (map.containsKey(code)) {
//
map.put(code, map.get(code) + 1);
//
System.err.println("code: " + map.get(code));
//
} else {
//
map.put(code, 1);
//
}
//
int rand2 = pos2[new Random().nextInt(pos2.length)];
//
String mobile = "1" + rand2 + code;
//
System.out.println(mobile);
//
}
//
Date end = new Date();
//
System.out.println("长度: " + (endPos - startPos) + " time:" + (end.getTime() - start.getTime()));
//
}
public
static
void
test
(
String
[]
args
)
{
int
[]
pos2
=
{
3
,
4
,
5
,
6
,
8
};
int
startPos
=
0
;
int
endPos
=
1000000
;
Date
start
=
new
Date
();
CodePwdImpl
item
=
new
CodePwd
Impl
();
Map
<
String
,
Integer
>
map
=
new
HashMap
<>(
DaoConst
.
COLLECTION_INIT_SIZE
);
for
(
int
i
=
startPos
;
i
<
endPos
;
i
++)
{
String
index
=
String
.
format
(
"%09d"
,
i
);
String
code
=
item
.
getCode
(
""
,
""
,
index
,
"18532354168"
);
if
(
map
.
containsKey
(
code
))
{
map
.
put
(
code
,
map
.
get
(
code
)
+
1
);
System
.
err
.
println
(
"code: "
+
map
.
get
(
code
));
}
else
{
map
.
put
(
code
,
1
);
}
int
rand2
=
pos2
[
new
Random
().
nextInt
(
pos2
.
length
)];
String
mobile
=
"1"
+
rand2
+
code
;
System
.
out
.
println
(
mobile
);
}
Date
end
=
new
Date
();
System
.
out
.
println
(
"长度: "
+
(
endPos
-
startPos
)
+
" time:"
+
(
end
.
getTime
()
-
start
.
getTime
()));
}
}
yzg-util-db/src/main/java/com/yanzuoguang/dao/DaoConst.java
View file @
492a68f3
...
...
@@ -116,4 +116,8 @@ public class DaoConst {
* ID字段
*/
public
static
final
String
ID_FIELD
=
"id"
;
/**
* 集合初始化大小
*/
public
static
final
int
COLLECTION_INIT_SIZE
=
15
;
}
yzg-util-db/src/main/java/com/yanzuoguang/dao/impl/BaseDaoImpl.java
View file @
492a68f3
...
...
@@ -195,7 +195,7 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
// 当主键存在值时,直接通过主键删除
if
(!
StringHelper
.
isEmpty
(
keyString
))
{
// 去掉其他非主键的属性
from
=
new
HashMap
<
String
,
Object
>();
from
=
new
HashMap
<
String
,
Object
>(
DaoConst
.
COLLECTION_INIT_SIZE
);
this
.
setKeyString
(
from
,
keyString
);
// 调用删除日志
this
.
check
(
DaoConst
.
OPERATOR_TYPE_REMOVE
,
keyString
,
from
);
...
...
@@ -232,7 +232,7 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
// 当主键存在时,只通过主键加载
if
(!
StringHelper
.
isEmpty
(
key
))
{
from
=
new
HashMap
<
String
,
Object
>();
from
=
new
HashMap
<
String
,
Object
>(
DaoConst
.
COLLECTION_INIT_SIZE
);
this
.
setKeyString
(
from
,
key
);
}
...
...
@@ -278,7 +278,7 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
from
=
model
;
this
.
setKeyString
(
model
,
md5
);
}
else
if
(!
StringHelper
.
isEmpty
(
this
.
table
.
getTable
().
getMD5KeyName
()))
{
Map
<
String
,
Object
>
map
=
new
HashMap
<
String
,
Object
>(
);
Map
<
String
,
Object
>
map
=
new
HashMap
<
>(
DaoConst
.
COLLECTION_INIT_SIZE
);
map
.
put
(
this
.
table
.
getTable
().
getMD5KeyName
(),
md5
);
from
=
this
.
load
(
map
,
cls
);
}
else
{
...
...
yzg-util-db/src/main/java/com/yanzuoguang/dao/impl/BaseDaoSql.java
View file @
492a68f3
...
...
@@ -410,11 +410,7 @@ public abstract class BaseDaoSql {
* @return SQL条件
*/
protected
String
getQueryPara
(
List
<
Object
>
paras
,
SqlData
sqlData
,
Object
model
)
{
// 定义可替换片段
// String fromNext = "{FIELD_Front}";
// String fromPrev = "{FIELD}";
// String wherePrev = "{INNER}";
String
[]
lastCode
=
new
String
[]{
"{WHERE}"
,
"{GROUP}"
,
"{HAVING}"
,
"{ORDER}"
,
"{LIMIT}"
};
// 将SQL语句进行代码片段追加
...
...
@@ -425,9 +421,25 @@ public abstract class BaseDaoSql {
}
}
// 代码片段处理
sql
=
handleCodeMap
(
sql
,
sqlData
,
model
);
// 通过正则表达式处理参数 @name 并替换SQL语句成 ?
sql
=
handlePara
(
sql
,
paras
,
model
);
return
sql
;
}
/**
* 代码片段处理
*
* @return
*/
private
String
handleCodeMap
(
String
sql
,
SqlData
sqlData
,
Object
model
)
{
// 处理字段以及代码片段
// 代码片段缓存
Map
<
String
,
List
<
String
>>
codeMap
=
new
HashMap
<>();
Map
<
String
,
List
<
String
>>
codeMap
=
new
HashMap
<>(
DaoConst
.
COLLECTION_INIT_SIZE
);
// 循环处理字段
for
(
SqlDataField
field
:
sqlData
.
getSqlDataFields
())
{
// 获取值
...
...
@@ -470,38 +482,46 @@ public abstract class BaseDaoSql {
// 寻找到的代码片段 不包含分括号
while
(
m
.
find
())
{
String
name
=
m
.
group
();
// m.group(1);
List
<
String
>
codes
=
codeMap
.
containsKey
(
name
)
?
codeMap
.
get
(
name
)
:
new
ArrayList
<
String
>();
String
code
=
String
.
join
(
""
,
codes
);
sql
=
sql
.
replace
(
name
,
code
);
}
}
// 通过正则表达式处理参数 @name 并替换SQL语句成 ?
{
String
regex
=
"@([a-zA-Z0-9_]+)"
;
Pattern
p
=
Pattern
.
compile
(
regex
);
Matcher
m
=
p
.
matcher
(
sql
);
// 寻找到的代码片段 不包含分括号
while
(
m
.
find
())
{
// SQL参数名称 @name\s
String
name
=
m
.
group
();
// 对应的前台输入字段 name
String
field
=
m
.
group
(
1
);
// 根据输入字段从参数中取值
Object
val
=
ObjectHelper
.
get
(
model
,
field
);
// 判断是否为数组
if
(
val
!=
null
&&
(
val
instanceof
List
||
val
.
getClass
().
isArray
()))
{
sql
=
getListSql
(
paras
,
sql
,
name
,
val
);
}
else
{
// 当参数不为数组时,则直接增加
sql
=
sql
.
replaceFirst
(
name
,
"?"
);
val
=
this
.
getParaValue
(
val
);
paras
.
add
(
val
);
}
return
sql
;
}
/**
* 通过正则表达式处理参数 @name 并替换SQL语句成 ?
*
* @param sql 需要处理的SQL语句
* @param paras 需要添加的参数
* @param model 需要获取的参数实体
* @return 处理后的SQL语句
*/
private
String
handlePara
(
String
sql
,
List
<
Object
>
paras
,
Object
model
)
{
String
regex
=
"@([a-zA-Z0-9_]+)"
;
Pattern
p
=
Pattern
.
compile
(
regex
);
Matcher
m
=
p
.
matcher
(
sql
);
// 寻找到的代码片段 不包含分括号
while
(
m
.
find
())
{
// SQL参数名称 @name\s
String
name
=
m
.
group
();
// 对应的前台输入字段 name
String
field
=
m
.
group
(
1
);
// 根据输入字段从参数中取值
Object
val
=
ObjectHelper
.
get
(
model
,
field
);
// 判断是否为数组
boolean
isArray
=
val
!=
null
&&
(
val
instanceof
List
||
val
.
getClass
().
isArray
());
if
(
isArray
)
{
sql
=
getListSql
(
paras
,
sql
,
name
,
val
);
}
else
{
// 当参数不为数组时,则直接增加
sql
=
sql
.
replaceFirst
(
name
,
"?"
);
val
=
this
.
getParaValue
(
val
);
paras
.
add
(
val
);
}
}
return
sql
;
}
...
...
@@ -647,7 +667,7 @@ public abstract class BaseDaoSql {
}
// 将对象转换为 Map 对象
Map
to
=
new
HashMap
<
String
,
Object
>();
Map
to
=
new
HashMap
<
String
,
Object
>(
DaoConst
.
COLLECTION_INIT_SIZE
);
if
(
from
instanceof
Map
)
{
to
=
(
Map
)
from
;
}
else
{
...
...
yzg-util-db/src/main/java/com/yanzuoguang/dao/impl/TableSqlCache.java
View file @
492a68f3
package
com
.
yanzuoguang
.
dao
.
impl
;
import
com.yanzuoguang.dao.DaoConst
;
import
com.yanzuoguang.util.cache.MemoryCache
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.helper.StringHelper
;
...
...
@@ -120,9 +121,9 @@ public class TableSqlCache {
*/
public
List
<
SqlData
>
addGroupList
(
String
sqlName
,
TableFieldString
tableWhereField
,
TableFieldString
addField
,
String
sql
,
String
...
field
)
{
Map
<
String
,
Boolean
>
sqlFieldHas
=
new
HashMap
<
String
,
Boolean
>(
);
Map
<
String
,
Boolean
>
sqlFieldWhere
=
new
HashMap
<
String
,
Boolean
>(
);
Map
<
String
,
Boolean
>
sqlFieldAdd
=
new
HashMap
<
String
,
Boolean
>(
);
Map
<
String
,
Boolean
>
sqlFieldHas
=
new
HashMap
<
>(
DaoConst
.
COLLECTION_INIT_SIZE
);
Map
<
String
,
Boolean
>
sqlFieldWhere
=
new
HashMap
<
>(
DaoConst
.
COLLECTION_INIT_SIZE
);
Map
<
String
,
Boolean
>
sqlFieldAdd
=
new
HashMap
<
>(
DaoConst
.
COLLECTION_INIT_SIZE
);
SqlData
sqlInit
=
new
SqlData
(
sqlName
+
"_GroupInit"
,
""
,
field
);
SqlData
sqlAdd
=
new
SqlData
(
sqlName
+
"_GroupAdd"
,
""
,
field
);
...
...
@@ -166,7 +167,7 @@ public class TableSqlCache {
String
addModel
=
"UPDATE {table} AS a INNER JOIN ( {SelectSQL} ) AS b ON a.{Key} = b.{Key} SET {addConst} "
;
// 定义需要处理的SQL对象
Map
<
String
,
StringBuilder
>
map
=
new
HashMap
<
String
,
StringBuilder
>(
);
Map
<
String
,
StringBuilder
>
map
=
new
HashMap
<
>(
DaoConst
.
COLLECTION_INIT_SIZE
);
addString
(
map
,
"{SQL}"
,
sql
);
addString
(
map
,
"{table}"
,
this
.
table
.
getName
());
...
...
yzg-util-db/src/main/java/com/yanzuoguang/db/impl/AllBeanRowMapper.java
View file @
492a68f3
...
...
@@ -76,9 +76,9 @@ public class AllBeanRowMapper<T> implements RowMapper<T> {
*/
protected
void
initialize
(
Class
<
T
>
mappedClass
)
{
this
.
mappedClass
=
mappedClass
;
this
.
mappedFields
=
new
HashMap
<>();
this
.
mappedPropertys
=
new
HashMap
<>();
this
.
mappedIsFields
=
new
HashMap
<>();
this
.
mappedFields
=
new
HashMap
<>(
DaoConst
.
COLLECTION_INIT_SIZE
);
this
.
mappedPropertys
=
new
HashMap
<>(
DaoConst
.
COLLECTION_INIT_SIZE
);
this
.
mappedIsFields
=
new
HashMap
<>(
DaoConst
.
COLLECTION_INIT_SIZE
);
if
(
ObjectHelper
.
isSub
(
MapRow
.
class
,
mappedClass
)
||
ObjectHelper
.
isSub
(
Map
.
class
,
mappedClass
))
{
isMapping
=
true
;
...
...
yzg-util-mq/src/main/java/com/yanzuoguang/mq/dao/BeanDao.java
View file @
492a68f3
package
com
.
yanzuoguang
.
mq
.
dao
;
import
com.yanzuoguang.dao.DaoConst
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.log.Log
;
...
...
@@ -19,7 +20,9 @@ public class BeanDao {
private
static
final
String
QUEUE
=
"queue"
;
private
static
final
String
EXCHANGE
=
"exchange"
;
// 上下文
/**
* 上下文
*/
@Autowired
private
ApplicationContext
context
;
...
...
@@ -83,7 +86,7 @@ public class BeanDao {
bean
=
new
Queue
(
queueName
,
true
,
false
,
false
);
amqpAdmin
.
declareQueue
(
bean
);
}
else
{
Map
<
String
,
Object
>
params
=
new
HashMap
<>();
Map
<
String
,
Object
>
params
=
new
HashMap
<>(
DaoConst
.
COLLECTION_INIT_SIZE
);
if
(
deadTime
>
0
)
{
params
.
put
(
"x-message-ttl"
,
deadTime
);
}
...
...
yzg-util-mq/src/main/java/com/yanzuoguang/mq/dao/impl/MessageDaoImpl.java
View file @
492a68f3
...
...
@@ -39,7 +39,7 @@ public class MessageDaoImpl extends BaseDaoImpl implements MessageDao {
*/
@Override
public
int
updateBatch
(
String
batchId
,
int
size
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
Map
<
String
,
Object
>
map
=
new
HashMap
<>(
1
);
map
.
put
(
"batchId"
,
batchId
);
SqlData
sql
=
this
.
getSql
(
UPDATE_BATCH_SQL
).
copy
();
...
...
yzg-util-mq/src/main/java/com/yanzuoguang/mq/service/impl/QueueServiceImpl.java
View file @
492a68f3
...
...
@@ -19,12 +19,16 @@ import java.util.List;
@Component
public
class
QueueServiceImpl
implements
QueueService
{
// 队列名称
/**
* 队列名称
*/
@Autowired
private
QueueDao
queueDao
;
@Autowired
private
BeanDao
beanDao
;
// 是否已经初始化
/**
* 是否已经初始化
*/
private
boolean
init
;
/**
...
...
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