Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yd-backend
Overview
Overview
Details
Activity
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
AutogeneralShanghai
yd-backend
Commits
cd72645e
Commit
cd72645e
authored
Nov 03, 2021
by
hongzhong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
等保调整,获取经纪人登录ip
parent
b5cacf8e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
0 deletions
+56
-0
yd-api/src/main/java/com/yd/dal/service/customer/impl/AclCustomerLogDALServiceImpl.java
+4
-0
yd-api/src/main/java/com/yd/util/SpringContextUtil.java
+52
-0
No files found.
yd-api/src/main/java/com/yd/dal/service/customer/impl/AclCustomerLogDALServiceImpl.java
View file @
cd72645e
...
...
@@ -4,6 +4,8 @@ import com.yd.api.practitioner.vo.login.PractitionerLoginRequestVO;
import
com.yd.dal.entity.customer.AclCustomerLog
;
import
com.yd.dal.mapper.customer.AclCustomerLogMapper
;
import
com.yd.dal.service.customer.AclCustomerLogDALService
;
import
com.yd.util.CommonUtil
;
import
com.yd.util.SpringContextUtil
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
...
...
@@ -47,6 +49,8 @@ public class AclCustomerLogDALServiceImpl implements AclCustomerLogDALService {
}
else
{
customerLog
.
setIsSuccess
(
1
);
}
String
ip
=
SpringContextUtil
.
getCurrentIpAddress
();
customerLog
.
setFromIp
(
ip
);
customerLog
.
setLoginName
(
requestVO
.
getName
());
customerLog
.
setMessage
(
requestVO
.
getMessage
());
customerLog
.
setCreatedAt
(
new
Date
());
...
...
yd-api/src/main/java/com/yd/util/SpringContextUtil.java
View file @
cd72645e
package
com
.
yd
.
util
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.BeansException
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContextAware
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.Locale
;
/**
...
...
@@ -84,5 +88,53 @@ public class SpringContextUtil implements ApplicationContextAware {
public
static
String
getEnvironmentName
()
{
return
getActiveProfile
().
toUpperCase
();
}
/**
* 获取IP地址时获取当前请求
* @return
*/
public
static
HttpServletRequest
getRequest
()
{
ServletRequestAttributes
attributes
=
(
ServletRequestAttributes
)
RequestContextHolder
.
currentRequestAttributes
();
return
attributes
.
getRequest
();
}
/**
* 获取当前请求的IP地址
* @return
*/
public
static
String
getCurrentIpAddress
()
{
String
ip
=
"127.0.0.1"
;
try
{
HttpServletRequest
request
=
getRequest
();
ip
=
getIp
(
request
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
ip
;
}
/**
* 通过请求头获得IP地址
* @param request
* @return
* @throws Exception
*/
public
static
String
getIp
(
HttpServletRequest
request
)
throws
Exception
{
String
ip
=
request
.
getHeader
(
"X-Real-IP"
);
if
(!
StringUtils
.
isBlank
(
ip
)
&&
!
"unknown"
.
equalsIgnoreCase
(
ip
))
{
return
ip
;
}
ip
=
request
.
getHeader
(
"X-Forwarded-For"
);
if
(!
StringUtils
.
isBlank
(
ip
)
&&
!
"unknown"
.
equalsIgnoreCase
(
ip
))
{
// 多次反向代理后会有多个IP值,第一个为真实IP。
int
index
=
ip
.
indexOf
(
','
);
if
(
index
!=
-
1
)
{
return
ip
.
substring
(
0
,
index
);
}
else
{
return
ip
;
}
}
else
{
return
request
.
getRemoteAddr
();
}
}
}
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