Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
matrix
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
mall
arch
matrix
Commits
7b2b6f3e
Commit
7b2b6f3e
authored
Nov 11, 2019
by
李秋伟
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' into 'master'
Dev See merge request mall/arch/matrix!24
parents
18ea8cd1
2e307686
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
249 additions
and
22 deletions
+249
-22
DateUtil.java
common-util/src/main/java/com/secoo/mall/common/util/date/DateUtil.java
+164
-0
WebUtil.java
common-util/src/main/java/com/secoo/mall/common/util/web/WebUtil.java
+48
-1
pom.xml
mybatis-starter/pom.xml
+6
-0
pom.xml
pom.xml
+18
-15
ProtocolExceptionHandler.java
protocol-starter/src/main/java/com/secoo/mall/common/handler/ProtocolExceptionHandler.java
+4
-3
AbsExceptionProcessor.java
protocol-starter/src/main/java/com/secoo/mall/common/processor/AbsExceptionProcessor.java
+9
-3
No files found.
common-util/src/main/java/com/secoo/mall/common/util/date/DateUtil.java
0 → 100644
View file @
7b2b6f3e
package
com
.
secoo
.
mall
.
common
.
util
.
date
;
import
org.apache.commons.lang3.time.DateFormatUtils
;
import
org.apache.commons.lang3.time.DateUtils
;
import
org.joda.time.Days
;
import
java.text.ParseException
;
import
java.util.Date
;
public
class
DateUtil
extends
DateUtils
{
private
static
String
[]
parsePatterns
=
{
"yyyy-MM-dd"
,
"yyyy-MM-dd HH:mm:ss"
,
"yyyy-MM-dd HH:mm"
,
"yyyy-MM"
,
"yyyy/MM/dd"
,
"yyyy/MM/dd HH:mm:ss"
,
"yyyy/MM/dd HH:mm"
,
"yyyy/MM"
,
"yyyy.MM.dd"
,
"yyyy.MM.dd HH:mm:ss"
,
"yyyy.MM.dd HH:mm"
,
"yyyy.MM"
};
/*
* 得到当前日期字符串 格式(yyyy-MM-dd)
*/
public
static
String
getDate
()
{
return
getDate
(
"yyyy-MM-dd"
);
}
/*
* 得到当前日期字符串 格式(yyyy-MM-dd) pattern可以为:"yyyy-MM-dd" "HH:mm:ss" "E"
*/
public
static
String
getDate
(
String
pattern
)
{
return
DateFormatUtils
.
format
(
new
Date
(),
pattern
);
}
/*
* 得到日期字符串 默认格式(yyyy-MM-dd) pattern可以为:"yyyy-MM-dd" "HH:mm:ss" "E"
*/
public
static
String
formatDate
(
Date
date
,
Object
...
pattern
)
{
String
formatDate
=
null
;
if
(
pattern
!=
null
&&
pattern
.
length
>
0
)
{
formatDate
=
DateFormatUtils
.
format
(
date
,
pattern
[
0
].
toString
());
}
else
{
formatDate
=
DateFormatUtils
.
format
(
date
,
"yyyy-MM-dd"
);
}
return
formatDate
;
}
/*
* 得到日期时间字符串,转换格式(yyyy-MM-dd HH:mm:ss)
*/
public
static
String
formatDateTime
(
Date
date
)
{
return
formatDate
(
date
,
"yyyy-MM-dd HH:mm:ss"
);
}
/*
* 得到当前时间字符串 格式(HH:mm:ss)
*/
public
static
String
getTime
()
{
return
formatDate
(
new
Date
(),
"HH:mm:ss"
);
}
/*
* 得到当前日期和时间字符串 格式(yyyy-MM-dd HH:mm:ss)
*/
public
static
String
getDateTime
()
{
return
formatDate
(
new
Date
(),
"yyyy-MM-dd HH:mm:ss"
);
}
/*
* 得到当前年份字符串 格式(yyyy)
*/
public
static
String
getYear
()
{
return
formatDate
(
new
Date
(),
"yyyy"
);
}
/*
* 得到当前月份字符串 格式(MM)
*/
public
static
String
getMonth
()
{
return
formatDate
(
new
Date
(),
"MM"
);
}
/*
* 得到当天字符串 格式(dd)
*/
public
static
String
getDay
()
{
return
formatDate
(
new
Date
(),
"dd"
);
}
/*
* 得到当前星期字符串 格式(E)星期几
*/
public
static
String
getWeek
()
{
return
formatDate
(
new
Date
(),
"E"
);
}
/*
* 日期型字符串转化为日期 格式 { "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm",
* "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy.MM.dd",
* "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm" }
*/
public
static
Date
parseDate
(
Object
str
)
{
if
(
str
==
null
)
{
return
null
;
}
try
{
return
parseDate
(
str
.
toString
(),
parsePatterns
);
}
catch
(
ParseException
e
)
{
return
null
;
}
}
/*
* 获取过去的天数
* @param date
*/
public
static
long
pastDays
(
Date
date
)
{
long
t
=
new
Date
().
getTime
()
-
date
.
getTime
();
return
t
/
(
24
*
60
*
60
*
1000
);
}
/*
* 获取过去的小时
*
* @param date
*/
public
static
long
pastHour
(
Date
date
)
{
long
t
=
new
Date
().
getTime
()
-
date
.
getTime
();
return
t
/
(
60
*
60
*
1000
);
}
/*
* 获取过去的分钟
*
* @param date
*/
public
static
long
pastMinutes
(
Date
date
)
{
long
t
=
new
Date
().
getTime
()
-
date
.
getTime
();
return
t
/
(
60
*
1000
);
}
/*
* 转换为时间(天,时:分:秒.毫秒)
*
* @param timeMillis
*/
public
static
String
formatDateTime
(
long
timeMillis
)
{
long
day
=
timeMillis
/
(
24
*
60
*
60
*
1000
);
long
hour
=
(
timeMillis
/
(
60
*
60
*
1000
)
-
day
*
24
);
long
min
=
((
timeMillis
/
(
60
*
1000
))
-
day
*
24
*
60
-
hour
*
60
);
long
s
=
(
timeMillis
/
1000
-
day
*
24
*
60
*
60
-
hour
*
60
*
60
-
min
*
60
);
long
sss
=
(
timeMillis
-
day
*
24
*
60
*
60
*
1000
-
hour
*
60
*
60
*
1000
-
min
*
60
*
1000
-
s
*
1000
);
return
(
day
>
0
?
day
+
","
:
""
)
+
hour
+
":"
+
min
+
":"
+
s
+
"."
+
sss
;
}
/*
* 获取两个日期之间的天数
*
* @param before
* @param after
*/
public
static
double
getDistanceOfTwoDate
(
Date
before
,
Date
after
)
{
long
beforeTime
=
before
.
getTime
();
long
afterTime
=
after
.
getTime
();
return
(
afterTime
-
beforeTime
)
/
(
1000
*
60
*
60
*
24
);
}
}
common-util/src/main/java/com/secoo/mall/common/util/web/WebUtil.java
View file @
7b2b6f3e
package
com
.
secoo
.
mall
.
common
.
util
.
web
;
package
com
.
secoo
.
mall
.
common
.
util
.
web
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.context.request.RequestAttributes
;
import
org.springframework.web.context.request.RequestAttributes
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
org.springframework.web.util.WebUtils
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpSession
;
import
javax.servlet.http.HttpSession
;
public
class
WebUtil
{
public
class
WebUtil
extends
WebUtils
{
private
static
String
sessionUser
=
"sessionUser"
;
private
static
String
sessionUser
=
"sessionUser"
;
private
static
String
[]
headers
=
new
String
[]{
"Cdn-Src-Ip"
,
"X-Real-IP"
,
"X-Forwarded-For"
,
"Proxy-Client-IP"
,
"WL-Proxy-Client-IP"
,
"HTTP_CLIENT_IP"
,
"HTTP_X_FORWARDED_FOR"
};
private
static
String
localIP
=
"127.0.0.1"
;
public
static
String
getParameter
(
String
name
)
{
public
static
String
getParameter
(
String
name
)
{
return
getRequest
().
getParameter
(
name
);
return
getRequest
().
getParameter
(
name
);
...
@@ -52,4 +56,47 @@ public class WebUtil {
...
@@ -52,4 +56,47 @@ public class WebUtil {
return
getAttribute
(
sessionUser
);
return
getAttribute
(
sessionUser
);
}
}
/**
* 获取请求客户端IP地址,支持代理服务器
*
* @param request {@link HttpServletRequest} 对象
* @return IP地址
*/
public
static
String
getRemoteAddr
(
HttpServletRequest
request
)
{
// 1、获取客户端IP地址,支持代理服务器
String
remoteAddr
=
null
;
for
(
String
header
:
headers
)
{
remoteAddr
=
request
.
getHeader
(
header
);
if
(
StringUtils
.
hasText
(
remoteAddr
)
&&
!
remoteAddr
.
equals
(
"unknown"
))
{
break
;
}
}
// 2、没有取得特定标记的值
if
(!
StringUtils
.
hasText
(
remoteAddr
))
{
remoteAddr
=
request
.
getRemoteAddr
();
}
// 3、判断是否localhost访问
if
(
remoteAddr
.
equals
(
"localhost"
))
{
remoteAddr
=
localIP
;
}
return
remoteAddr
;
}
/**
* 获得请求的客户端信息【ip,port,name】
*
* @param request {@link HttpServletRequest} 对象
* @return 客户端信息[ip, port, name]
*/
public
static
String
[]
getRemoteInfo
(
HttpServletRequest
request
)
{
if
(
request
==
null
)
{
return
new
String
[]{
""
,
""
,
""
};
}
return
new
String
[]{
getRemoteAddr
(
request
),
request
.
getRemotePort
()
+
""
,
request
.
getRemoteHost
()};
}
}
}
mybatis-starter/pom.xml
View file @
7b2b6f3e
...
@@ -36,5 +36,10 @@
...
@@ -36,5 +36,10 @@
<groupId>
org.springframework
</groupId>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-tx
</artifactId>
<artifactId>
spring-tx
</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-configuration-processor
</artifactId>
<optional>
true
</optional>
</dependency>
</dependencies>
</dependencies>
</project>
</project>
\ No newline at end of file
pom.xml
View file @
7b2b6f3e
...
@@ -25,12 +25,7 @@
...
@@ -25,12 +25,7 @@
<module>
logger-starter
</module>
<module>
logger-starter
</module>
</modules>
</modules>
<parent>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-parent
</artifactId>
<version>
2.1.9.RELEASE
</version>
<relativePath/>
</parent>
<properties>
<properties>
<java.version>
1.8
</java.version>
<java.version>
1.8
</java.version>
...
@@ -42,6 +37,15 @@
...
@@ -42,6 +37,15 @@
<dependencyManagement>
<dependencyManagement>
<dependencies>
<dependencies>
<!-- Spring Boot -->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-dependencies
</artifactId>
<version>
2.1.9.RELEASE
</version>
<type>
pom
</type>
<scope>
import
</scope>
</dependency>
<!--matrix-->
<dependency>
<dependency>
<groupId>
com.secoo.mall
</groupId>
<groupId>
com.secoo.mall
</groupId>
<artifactId>
logger-starter
</artifactId>
<artifactId>
logger-starter
</artifactId>
...
@@ -154,7 +158,12 @@
...
@@ -154,7 +158,12 @@
<artifactId>
mybatis-plus-boot-starter
</artifactId>
<artifactId>
mybatis-plus-boot-starter
</artifactId>
<version>
3.1.0
</version>
<version>
3.1.0
</version>
</dependency>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
druid-spring-boot-starter
</artifactId>
<version>
1.1.20
</version>
<optional>
true
</optional>
</dependency>
<dependency>
<dependency>
<groupId>
mysql
</groupId>
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
<artifactId>
mysql-connector-java
</artifactId>
...
@@ -165,14 +174,7 @@
...
@@ -165,14 +174,7 @@
<artifactId>
guava
</artifactId>
<artifactId>
guava
</artifactId>
<version>
20.0
</version>
<version>
20.0
</version>
</dependency>
</dependency>
<!--spring boot-->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-dependencies
</artifactId>
<version>
2.1.6.RELEASE
</version>
<type>
pom
</type>
<scope>
import
</scope>
</dependency>
<!-- Aapche Dubbo -->
<!-- Aapche Dubbo -->
<dependency>
<dependency>
<groupId>
org.apache.dubbo
</groupId>
<groupId>
org.apache.dubbo
</groupId>
...
@@ -317,3 +319,4 @@
...
@@ -317,3 +319,4 @@
</project>
</project>
protocol-starter/src/main/java/com/secoo/mall/common/handler/ProtocolExceptionHandler.java
View file @
7b2b6f3e
...
@@ -7,6 +7,7 @@ import com.secoo.mall.common.core.exception.SystemInternalException;
...
@@ -7,6 +7,7 @@ import com.secoo.mall.common.core.exception.SystemInternalException;
import
com.secoo.mall.common.processor.ExceptionProcessor
;
import
com.secoo.mall.common.processor.ExceptionProcessor
;
import
com.secoo.mall.common.util.log.LoggerUtil
;
import
com.secoo.mall.common.util.log.LoggerUtil
;
import
com.secoo.mall.common.util.response.ResponseUtil
;
import
com.secoo.mall.common.util.response.ResponseUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.MessageSource
;
import
org.springframework.context.MessageSource
;
import
org.springframework.context.i18n.LocaleContextHolder
;
import
org.springframework.context.i18n.LocaleContextHolder
;
...
@@ -36,13 +37,13 @@ public class ProtocolExceptionHandler {
...
@@ -36,13 +37,13 @@ public class ProtocolExceptionHandler {
LoggerUtil
.
info
(
msg
);
LoggerUtil
.
info
(
msg
);
return
ResponseUtil
.
getFailResponse
(
ex
.
getCode
(),
msg
);
return
ResponseUtil
.
getFailResponse
(
ex
.
getCode
(),
msg
);
}
catch
(
SystemInternalException
ex
)
{
}
catch
(
SystemInternalException
ex
)
{
LoggerUtil
.
error
(
e
);
LoggerUtil
.
warn
(
"WarnError"
,
ex
);
return
ResponseUtil
.
getFailResponse
(
CommonErrorCode
.
SYSTEM_INTERNAL_EXCEPTION
.
getCode
(),
CommonErrorCode
.
SYSTEM_INTERNAL_EXCEPTION
.
getMsg
());
return
ResponseUtil
.
getFailResponse
(
CommonErrorCode
.
SYSTEM_INTERNAL_EXCEPTION
.
getCode
(),
CommonErrorCode
.
SYSTEM_INTERNAL_EXCEPTION
.
getMsg
());
}
catch
(
BusinessException
ex
)
{
}
catch
(
BusinessException
ex
)
{
LoggerUtil
.
warn
(
"
businessException info:"
,
ex
);
LoggerUtil
.
warn
(
"
BizError:"
+
getMsg
(
ex
),
ex
);
return
ResponseUtil
.
getFailResponse
(
ex
.
getCode
(),
getMsg
(
ex
));
return
ResponseUtil
.
getFailResponse
(
ex
.
getCode
(),
getMsg
(
ex
));
}
catch
(
Exception
ex
)
{
}
catch
(
Exception
ex
)
{
LoggerUtil
.
error
(
ex
);
LoggerUtil
.
error
(
"Error:"
,
ex
);
return
ResponseUtil
.
getFailResponse
(
CommonErrorCode
.
SYSTEM_INTERNAL_EXCEPTION
.
getCode
(),
CommonErrorCode
.
SYSTEM_INTERNAL_EXCEPTION
.
getMsg
());
return
ResponseUtil
.
getFailResponse
(
CommonErrorCode
.
SYSTEM_INTERNAL_EXCEPTION
.
getCode
(),
CommonErrorCode
.
SYSTEM_INTERNAL_EXCEPTION
.
getMsg
());
}
}
...
...
protocol-starter/src/main/java/com/secoo/mall/common/processor/AbsExceptionProcessor.java
View file @
7b2b6f3e
package
com
.
secoo
.
mall
.
common
.
processor
;
package
com
.
secoo
.
mall
.
common
.
processor
;
import
com.secoo.mall.common.core.exception.SystemInternalException
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
@Slf4j
@Slf4j
public
abstract
class
AbsExceptionProcessor
implements
ExceptionProcessor
{
public
abstract
class
AbsExceptionProcessor
implements
ExceptionProcessor
{
public
void
process
(
Exception
e
)
throws
Exception
{
public
void
process
(
Exception
e
)
throws
Exception
{
log
.
warn
(
"warn:"
,
e
);
convertException
(
e
);
convertException
(
e
);
//如果不进行运行时异常抛出,则转换为运行时异常
if
(!(
e
instanceof
RuntimeException
))
{
log
.
error
(
"error:"
,
e
);
throw
new
SystemInternalException
();
}
throw
e
;
throw
e
;
}
}
...
...
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