Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
customer-service
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
QG
customer-service
Commits
dfe565b1
Commit
dfe565b1
authored
Feb 12, 2022
by
王业雄
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vcc线下还款
parent
069840a7
Changes
14
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
929 additions
and
0 deletions
+929
-0
pom.xml
pom.xml
+28
-0
OfflineRepayOperateRecord.java
...quantgroup/customer/entity/OfflineRepayOperateRecord.java
+39
-0
OfflineRepaySubmitRecord.java
.../quantgroup/customer/entity/OfflineRepaySubmitRecord.java
+67
-0
OfflineRepayOperateRecordRepo.java
...antgroup/customer/repo/OfflineRepayOperateRecordRepo.java
+10
-0
OfflineRepaySubmitRecordRepo.java
...uantgroup/customer/repo/OfflineRepaySubmitRecordRepo.java
+17
-0
VccRest.java
src/main/java/cn/quantgroup/customer/rest/VccRest.java
+177
-0
ApplyBill.java
...java/cn/quantgroup/customer/rest/param/vcc/ApplyBill.java
+11
-0
OfflineRepaySubmitParam.java
...roup/customer/rest/param/vcc/OfflineRepaySubmitParam.java
+28
-0
UserPreRepayInfoQuery.java
...tgroup/customer/rest/param/vcc/UserPreRepayInfoQuery.java
+31
-0
QueryPreOfflineRepayVo.java
...antgroup/customer/rest/vo/vcc/QueryPreOfflineRepayVo.java
+25
-0
IVccService.java
...main/java/cn/quantgroup/customer/service/IVccService.java
+26
-0
VccServiceImpl.java
...a/cn/quantgroup/customer/service/impl/VccServiceImpl.java
+318
-0
IdUtil.java
src/main/java/cn/quantgroup/customer/util/IdUtil.java
+68
-0
IpAddrUtils.java
src/main/java/cn/quantgroup/customer/util/IpAddrUtils.java
+84
-0
No files found.
pom.xml
View file @
dfe565b1
...
...
@@ -52,6 +52,22 @@
<encoding>
${project.build.sourceEncoding}
</encoding>
</configuration>
</plugin>
<plugin>
<groupId>
com.mysema.maven
</groupId>
<artifactId>
apt-maven-plugin
</artifactId>
<version>
1.1.3
</version>
<executions>
<execution>
<goals>
<goal>
process
</goal>
</goals>
<configuration>
<outputDirectory>
target/generated-sources/java
</outputDirectory>
<processor>
com.querydsl.apt.jpa.JPAAnnotationProcessor
</processor>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
...
@@ -254,6 +270,18 @@
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
com.querydsl
</groupId>
<artifactId>
querydsl-jpa
</artifactId>
<version>
4.2.1
</version>
</dependency>
<dependency>
<groupId>
com.querydsl
</groupId>
<artifactId>
querydsl-apt
</artifactId>
<version>
4.2.1
</version>
<scope>
provided
</scope>
</dependency>
</dependencies>
</project>
src/main/java/cn/quantgroup/customer/entity/OfflineRepayOperateRecord.java
0 → 100644
View file @
dfe565b1
package
cn
.
quantgroup
.
customer
.
entity
;
import
lombok.*
;
import
javax.persistence.*
;
import
java.time.LocalDateTime
;
@Entity
@Table
(
name
=
"offline_repay_operate_record"
)
@ToString
@Builder
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public
class
OfflineRepayOperateRecord
{
@Id
@Column
(
name
=
"id"
)
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
private
Long
id
;
@Column
(
name
=
"serial_no"
)
private
String
serialNo
;
@Column
(
name
=
"operate_account"
)
private
String
operateAccount
;
@Column
(
name
=
"operate_name"
)
private
String
operateName
;
@Column
(
name
=
"operate_content"
)
private
String
operateContent
;
@Column
(
name
=
"operate_time"
)
private
LocalDateTime
operateTime
;
@Column
(
name
=
"remark"
)
private
String
remark
;
@Column
(
name
=
"create_time"
)
private
LocalDateTime
createTime
;
@Column
(
name
=
"update_time"
)
private
LocalDateTime
updateTime
;
}
src/main/java/cn/quantgroup/customer/entity/OfflineRepaySubmitRecord.java
0 → 100644
View file @
dfe565b1
package
cn
.
quantgroup
.
customer
.
entity
;
import
lombok.*
;
import
javax.persistence.*
;
import
java.math.BigDecimal
;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
@Entity
@Table
(
name
=
"offline_repay_submit_record"
)
@ToString
@Builder
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public
class
OfflineRepaySubmitRecord
{
@Id
@Column
(
name
=
"id"
)
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
private
Long
id
;
@Column
(
name
=
"serial_no"
)
private
String
serialNo
;
@Column
(
name
=
"unique_id"
)
private
String
uniqueId
;
@Column
(
name
=
"bills"
)
private
String
bills
;
@Column
(
name
=
"curr_term"
)
private
Integer
currTerm
;
@Column
(
name
=
"amount"
)
private
BigDecimal
amount
;
@Column
(
name
=
"actual_amount"
)
private
BigDecimal
actualAmount
;
@Column
(
name
=
"actual_date"
)
private
LocalDate
actualDate
;
@Column
(
name
=
"trans_no"
)
private
String
transNo
;
@Column
(
name
=
"receive_account"
)
private
String
receiveAccount
;
@Column
(
name
=
"receive_account_name"
)
private
String
receiveAccountName
;
@Column
(
name
=
"credentials_address"
)
private
String
credentialsAddress
;
@Column
(
name
=
"mark"
)
private
String
mark
;
@Column
(
name
=
"repay_type"
)
private
Integer
repayType
;
@Column
(
name
=
"user_id"
)
private
Integer
userId
;
@Column
(
name
=
"name"
)
private
String
name
;
@Column
(
name
=
"phone"
)
private
String
phone
;
@Column
(
name
=
"id_no"
)
private
String
idNo
;
@Column
(
name
=
"repay_status"
)
private
String
repayStatus
;
@Column
(
name
=
"approval_status"
)
private
Integer
approvalStatus
;
@Column
(
name
=
"create_time"
)
private
LocalDateTime
createTime
;
@Column
(
name
=
"update_time"
)
private
LocalDateTime
updateTime
;
}
src/main/java/cn/quantgroup/customer/repo/OfflineRepayOperateRecordRepo.java
0 → 100644
View file @
dfe565b1
package
cn
.
quantgroup
.
customer
.
repo
;
import
cn.quantgroup.customer.entity.OfflineRepayOperateRecord
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
java.util.List
;
public
interface
OfflineRepayOperateRecordRepo
extends
JpaRepository
<
OfflineRepayOperateRecord
,
Long
>
{
List
<
OfflineRepayOperateRecord
>
findBySerialNoEquals
(
String
serailNo
);
}
src/main/java/cn/quantgroup/customer/repo/OfflineRepaySubmitRecordRepo.java
0 → 100644
View file @
dfe565b1
package
cn
.
quantgroup
.
customer
.
repo
;
import
cn.quantgroup.customer.entity.OfflineRepaySubmitRecord
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.querydsl.QueryDslPredicateExecutor
;
import
java.util.List
;
public
interface
OfflineRepaySubmitRecordRepo
extends
JpaRepository
<
OfflineRepaySubmitRecord
,
Long
>,
QueryDslPredicateExecutor
<
OfflineRepaySubmitRecord
>
{
OfflineRepaySubmitRecord
findFirstByBillIdsContains
(
String
bill
);
OfflineRepaySubmitRecord
findBySerialNoEquals
(
String
serialNo
);
OfflineRepaySubmitRecord
findFirstByUniqueIdEquals
(
String
uniqueId
);
List
<
OfflineRepaySubmitRecord
>
findByUserIdEqualsAndRepayTypeEquals
(
Integer
userId
,
Integer
repayType
);
}
src/main/java/cn/quantgroup/customer/rest/VccRest.java
0 → 100644
View file @
dfe565b1
package
cn
.
quantgroup
.
customer
.
rest
;
import
cn.quantgroup.customer.rest.param.vcc.OfflineRepaySubmitParam
;
import
cn.quantgroup.customer.rest.param.vcc.UserPreRepayInfoQuery
;
import
cn.quantgroup.customer.rest.vo.JsonResult
;
import
cn.quantgroup.customer.service.IVccService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.validation.Valid
;
import
javax.validation.constraints.NotNull
;
@Slf4j
@RestController
@RequestMapping
(
"/vcc"
)
public
class
VccRest
{
@Autowired
private
IVccService
vccService
;
/**
* 查询用户的待还款信息
* @param query
* @return
*/
@PostMapping
(
"/offline_pre_repay/query_page"
)
public
JsonResult
queryPage
(
@RequestBody
@Valid
UserPreRepayInfoQuery
query
){
log
.
info
(
"queryPage | 开始用户待还款查询,param={}"
,
query
);
if
(
StringUtils
.
isBlank
(
query
.
getBillId
())
&&
StringUtils
.
isBlank
(
query
.
getPhone
())
&&
StringUtils
.
isBlank
(
query
.
getUserId
())
&&
StringUtils
.
isBlank
(
query
.
getOrderNo
())){
log
.
error
(
"queryPage | 请求参数userId,phone,billId,orderNo不能同时为空"
);
return
JsonResult
.
buildErrorStateResult
(
"请求参数userId,phone,billId,orderNo不能同时为空"
);
}
try
{
JsonResult
jsonResult
=
vccService
.
queryPage
(
query
);
log
.
info
(
"queryPage | 结束用户待还款查询,param={}"
,
query
);
return
jsonResult
;
}
catch
(
Exception
e
){
log
.
error
(
"queryPage | 用户待还款查询发生异常"
,
e
);
return
JsonResult
.
buildErrorStateResult
(
"用户待还款查询发生异常"
);
}
}
/**
* 查询分期账单的详情
* @param uniqueId
* @param repayType
* @return
*/
@GetMapping
(
"/pre_repay_cal/detail"
)
public
JsonResult
repayPlanDetail
(
@NotNull
String
uniqueId
,
@NotNull
Integer
repayType
){
log
.
info
(
"repayPlanDetail | 查询用户分期的详情及试算详情,uniqueId={},repayType={}"
,
uniqueId
,
repayType
);
try
{
JsonResult
jsonResult
=
vccService
.
queryRepayCalDetail
(
uniqueId
,
repayType
);
log
.
info
(
"repayPlanDetail | 结束查询用户分期的详情及试算详情,uniqueId={},repayType={}"
,
uniqueId
,
repayType
);
return
jsonResult
;
}
catch
(
Exception
e
){
log
.
error
(
"repayPlanDetail | 查询用户分期的详情及试算详情发生异常"
,
e
);
return
JsonResult
.
buildErrorStateResult
(
"查询用户分期的详情及试算详情发生异常"
);
}
}
/**
* 保存线下还款的申请记录
* @param request
* @param param
* @return
*/
@PostMapping
(
"/offline_repay/save_submit"
)
public
JsonResult
saveSubmit
(
HttpServletRequest
request
,
@RequestBody
OfflineRepaySubmitParam
param
){
log
.
info
(
"saveSubmit | 开始保存线下还款的申请记录,param={}"
,
param
);
try
{
String
token
=
request
.
getHeader
(
"x-auth-token"
);
vccService
.
saveSubmitRecord
(
param
,
token
);
log
.
info
(
"saveSubmit | 保存线下还款的申请记录成功,param={}"
,
param
);
return
JsonResult
.
buildSuccessResult
(
"请求成功"
,
null
);
}
catch
(
Exception
e
){
log
.
error
(
"saveSubmit | 保存线下还款提交申请时发生异常"
,
e
);
return
JsonResult
.
buildErrorStateResult
(
"保存线下还款提交申请时发生异常"
);
}
}
/**
* 审批回显提交的线下还款申请记录
* @param serialNo
* @return
*/
@GetMapping
(
"/offline_repay/approval"
)
public
JsonResult
approval
(
@NotNull
String
serialNo
){
log
.
info
(
"approval | 开始点击审批按钮查询信息,serialNo={}"
,
serialNo
);
try
{
OfflineRepaySubmitParam
param
=
vccService
.
approvalQuery
(
serialNo
);
log
.
info
(
"approval | 点击审批按钮查询信息成功,serialNo={}"
,
serialNo
);
return
JsonResult
.
buildSuccessResult
(
"请求成功"
,
param
);
}
catch
(
Exception
e
){
log
.
error
(
"approval | 点击审批按钮查询信息时发生异常"
,
e
);
return
JsonResult
.
buildErrorStateResult
(
"点击审批按钮查询信息时发生异常"
);
}
}
/**
* 查看审批流水记录
* @param serialNo
* @return
*/
@GetMapping
(
"/approval/detail"
)
public
JsonResult
queryApprovalRecord
(
@NotNull
String
serialNo
){
log
.
info
(
"queryApprovalRecord | 开始查看审批流水记录,serialNo={}"
,
serialNo
);
try
{
JsonResult
jsonResult
=
vccService
.
queryApprovalRecord
(
serialNo
);
log
.
info
(
"queryApprovalRecord | 查看审批流水记录成功,serialNo={}"
,
serialNo
);
return
jsonResult
;
}
catch
(
Exception
e
){
log
.
error
(
"queryApprovalRecord | 查询审批流水时发生异常"
,
e
);
return
JsonResult
.
buildErrorStateResult
(
"查询审批流水时发生异常"
);
}
}
/**
* 审批结果:通过/拒绝
* @param request
* @param serialNo
* @param remark
* @param status
* @return
*/
@GetMapping
(
"/approval/result"
)
public
JsonResult
approvalResult
(
HttpServletRequest
request
,
@NotNull
String
serialNo
,
String
remark
,
@NotNull
Integer
status
){
log
.
info
(
"approvalResult | 开始提交审批结果,serialNo={},remark={},status={}"
,
serialNo
,
remark
,
status
);
try
{
String
token
=
request
.
getHeader
(
"x-auth-token"
);
vccService
.
approvalResult
(
serialNo
,
remark
,
status
,
token
);
log
.
info
(
"approvalResult | 提交审批结果成功,serialNo={},remark={},status={}"
,
serialNo
,
remark
,
status
);
return
JsonResult
.
buildSuccessResult
(
"请求成功"
,
null
);
}
catch
(
Exception
e
){
log
.
error
(
"approvalResult | 通过/拒绝审批时发生异常"
,
e
);
return
JsonResult
.
buildErrorStateResult
(
"通过/拒绝审批时发生异常"
);
}
}
/**
* 上传打款凭证
* @param file
* @return
*/
@PostMapping
(
"/offline_repay_file/upload"
)
public
JsonResult
fileUpload
(
MultipartFile
file
){
try
{
return
null
;
}
catch
(
Exception
e
){
log
.
error
(
"fileUpload | 文件上传时发生异常"
,
e
);
return
JsonResult
.
buildErrorStateResult
(
"文件上传时发生异常"
);
}
}
/**
* 查询线下还款的申请记录
* @param query
* @return
*/
@PostMapping
(
"/approval/query_applly_record"
)
public
JsonResult
queryApplyRecord
(
@RequestBody
UserPreRepayInfoQuery
query
){
log
.
info
(
"queryApplyRecord | 开始查看线下还款的申请记录,param={}"
,
query
);
try
{
JsonResult
jsonResult
=
vccService
.
queryApplyRecord
(
query
);
log
.
info
(
"queryApplyRecord | 查看线下还款的申请记录成功,param={}"
,
query
);
return
jsonResult
;
}
catch
(
Exception
e
){
log
.
error
(
"queryApplyRecord | 查询线下还款申请记录时发生异常"
,
e
);
return
JsonResult
.
buildErrorStateResult
(
"查询线下还款申请记录时发生异常"
);
}
}
}
src/main/java/cn/quantgroup/customer/rest/param/vcc/ApplyBill.java
0 → 100644
View file @
dfe565b1
package
cn
.
quantgroup
.
customer
.
rest
.
param
.
vcc
;
import
lombok.Data
;
import
java.math.BigDecimal
;
@Data
public
class
ApplyBill
{
private
Long
billId
;
private
BigDecimal
amount
;
}
src/main/java/cn/quantgroup/customer/rest/param/vcc/OfflineRepaySubmitParam.java
0 → 100644
View file @
dfe565b1
package
cn
.
quantgroup
.
customer
.
rest
.
param
.
vcc
;
import
lombok.Data
;
import
java.math.BigDecimal
;
import
java.time.LocalDate
;
import
java.util.List
;
@Data
public
class
OfflineRepaySubmitParam
{
private
String
uniqueId
;
private
List
<
ApplyBill
>
list
;
private
Integer
currTerm
;
private
BigDecimal
amount
;
private
BigDecimal
actualAmount
;
private
LocalDate
actualDate
;
private
String
transNo
;
private
String
receiveAccount
;
private
String
receiveAccountName
;
private
List
<
String
>
credentialsAddress
;
private
String
mark
;
private
Integer
repayType
;
private
String
name
;
private
String
phone
;
private
String
idNo
;
private
String
repayStatus
;
private
Integer
userId
;
}
src/main/java/cn/quantgroup/customer/rest/param/vcc/UserPreRepayInfoQuery.java
0 → 100644
View file @
dfe565b1
package
cn
.
quantgroup
.
customer
.
rest
.
param
.
vcc
;
import
lombok.Data
;
import
javax.validation.constraints.NotNull
;
@Data
public
class
UserPreRepayInfoQuery
{
private
String
userId
;
private
String
phone
;
private
String
billId
;
private
String
orderNo
;
private
Integer
approvalStatus
;
/**
* 1.月还账单 2.账单分期 3.订单分期
*/
@NotNull
private
Integer
repayType
;
//当前页数
@NotNull
private
Integer
pageIndex
;
//默认每页条数
@NotNull
private
Integer
pageSize
;
}
src/main/java/cn/quantgroup/customer/rest/vo/vcc/QueryPreOfflineRepayVo.java
0 → 100644
View file @
dfe565b1
package
cn
.
quantgroup
.
customer
.
rest
.
vo
.
vcc
;
import
lombok.Data
;
import
java.math.BigDecimal
;
@Data
public
class
QueryPreOfflineRepayVo
{
private
String
uniqueId
;
private
String
name
;
private
String
phone
;
private
String
idNo
;
private
String
installTime
;
private
Integer
installTerm
;
private
Integer
currTerm
;
private
BigDecimal
currBall
;
private
BigDecimal
settleAmount
;
private
String
repayStatus
;
private
String
billTime
;
private
String
repayTime
;
private
String
serialNo
;
private
Integer
approvalStatus
;
private
Integer
userId
;
}
src/main/java/cn/quantgroup/customer/service/IVccService.java
0 → 100644
View file @
dfe565b1
package
cn
.
quantgroup
.
customer
.
service
;
import
cn.quantgroup.customer.rest.param.vcc.OfflineRepaySubmitParam
;
import
cn.quantgroup.customer.rest.param.vcc.UserPreRepayInfoQuery
;
import
cn.quantgroup.customer.rest.vo.JsonResult
;
import
org.springframework.web.multipart.MultipartFile
;
public
interface
IVccService
{
JsonResult
queryPage
(
UserPreRepayInfoQuery
query
)
throws
Exception
;
JsonResult
queryRepayCalDetail
(
String
uniqueId
,
Integer
repayType
)
throws
Exception
;
void
saveSubmitRecord
(
OfflineRepaySubmitParam
param
,
String
token
)
throws
Exception
;
OfflineRepaySubmitParam
approvalQuery
(
String
serialNo
)
throws
Exception
;
JsonResult
queryApprovalRecord
(
String
serialNo
)
throws
Exception
;
void
approvalResult
(
String
serialNo
,
String
remark
,
Integer
status
,
String
token
)
throws
Exception
;
String
fileUpload
(
MultipartFile
file
)
throws
Exception
;
JsonResult
queryApplyRecord
(
UserPreRepayInfoQuery
query
)
throws
Exception
;
void
saveApprovalRecord
(
String
serialNo
,
String
remark
,
Integer
status
,
String
token
)
throws
Exception
;
}
src/main/java/cn/quantgroup/customer/service/impl/VccServiceImpl.java
0 → 100644
View file @
dfe565b1
This diff is collapsed.
Click to expand it.
src/main/java/cn/quantgroup/customer/util/IdUtil.java
0 → 100644
View file @
dfe565b1
package
cn
.
quantgroup
.
customer
.
util
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.text.*
;
import
java.util.Calendar
;
public
class
IdUtil
{
/** .log */
private
final
static
Logger
logger
=
LoggerFactory
.
getLogger
(
IdUtil
.
class
);
/** The FieldPosition. */
private
static
final
FieldPosition
HELPER_POSITION
=
new
FieldPosition
(
0
);
/** This Format for format the data to special format. */
private
final
static
Format
dateFormat
=
new
SimpleDateFormat
(
"yyyyMMddHHmmss"
);
/** This Format for format the number to special format. */
private
final
static
NumberFormat
numberFormat
=
new
DecimalFormat
(
"000"
);
/** This int is the sequence number ,the default value is 0. */
private
static
int
seq
=
0
;
private
static
final
int
MAX
=
999
;
/**
* 时间格式生成序列
*
* @return String
*/
public
static
String
generateSequenceNo
()
{
return
generateSequenceNo
(
"Q"
);
}
/**
* 时间格式生成序列
*
* @return String
*/
public
static
synchronized
String
generateSequenceNo
(
String
prefix
)
{
Calendar
rightNow
=
Calendar
.
getInstance
();
StringBuffer
sb
=
new
StringBuffer
();
dateFormat
.
format
(
rightNow
.
getTime
(),
sb
,
HELPER_POSITION
);
numberFormat
.
format
(
seq
,
sb
,
HELPER_POSITION
);
if
(
seq
==
MAX
)
{
seq
=
0
;
}
else
{
seq
++;
}
if
(
StringUtils
.
isEmpty
(
prefix
)){
prefix
=
"C"
;
}
String
ip
=
IpAddrUtils
.
getHostIp
();
Integer
ipValue
=
Integer
.
parseInt
(
ip
.
split
(
"\\."
)[
ip
.
split
(
"\\."
).
length
-
1
]);
StringBuffer
ipStr
=
new
StringBuffer
();
numberFormat
.
format
(
ipValue
,
ipStr
,
HELPER_POSITION
);
String
idNo
=
prefix
+
sb
.
toString
()
+
ipStr
.
toString
();
logger
.
debug
(
"THE SQUENCE IS :"
+
idNo
);
return
idNo
;
}
public
static
void
main
(
String
[]
args
)
{
// for (int i = 0; i < 1000; i++) {
// System.out.println(generateSequenceNo());
// }
System
.
out
.
println
(
System
.
currentTimeMillis
());
//System.out.println(dateFormat.format(Calendar.getInstance().getTime().getTime(), new StringBuffer(), HELPER_POSITION));
}
}
src/main/java/cn/quantgroup/customer/util/IpAddrUtils.java
0 → 100644
View file @
dfe565b1
package
cn
.
quantgroup
.
customer
.
util
;
import
lombok.extern.slf4j.Slf4j
;
import
javax.servlet.http.HttpServletRequest
;
import
java.net.InetAddress
;
import
java.net.NetworkInterface
;
import
java.util.Enumeration
;
@Slf4j
public
class
IpAddrUtils
{
private
final
static
String
UNKNOWN
=
"unknown"
;
public
static
String
getIpAddr
(
HttpServletRequest
request
)
{
try
{
StringBuffer
sb
=
new
StringBuffer
();
Enumeration
<
String
>
er
=
request
.
getHeaderNames
();
while
(
er
.
hasMoreElements
())
{
String
name
=
er
.
nextElement
();
String
value
=
request
.
getHeader
(
name
);
sb
.
append
(
name
).
append
(
"="
).
append
(
value
).
append
(
";"
);
}
log
.
info
(
"获取请求Header: "
+
sb
.
toString
());
}
catch
(
Exception
e
)
{
log
.
error
(
"获取请求Header: "
+
e
.
getMessage
());
}
String
ip
=
request
.
getHeader
(
"X-Forwarded-For"
);
if
(
ip
!=
null
&&
ip
.
length
()
!=
0
&&
!
UNKNOWN
.
equalsIgnoreCase
(
ip
))
{
// 多次反向代理后会有多个ip值,第一个ip才是真实ip
if
(
ip
.
contains
(
","
))
{
ip
=
ip
.
split
(
","
)[
0
];
}
}
if
(
ip
==
null
||
ip
.
length
()
==
0
||
UNKNOWN
.
equalsIgnoreCase
(
ip
))
{
ip
=
request
.
getHeader
(
"Proxy-Client-IP"
);
}
if
(
ip
==
null
||
ip
.
length
()
==
0
||
UNKNOWN
.
equalsIgnoreCase
(
ip
))
{
ip
=
request
.
getHeader
(
"WL-Proxy-Client-IP"
);
}
if
(
ip
==
null
||
ip
.
length
()
==
0
||
UNKNOWN
.
equalsIgnoreCase
(
ip
))
{
ip
=
request
.
getHeader
(
"HTTP_CLIENT_IP"
);
}
if
(
ip
==
null
||
ip
.
length
()
==
0
||
UNKNOWN
.
equalsIgnoreCase
(
ip
))
{
ip
=
request
.
getHeader
(
"HTTP_X_FORWARDED_FOR"
);
}
if
(
ip
==
null
||
ip
.
length
()
==
0
||
UNKNOWN
.
equalsIgnoreCase
(
ip
))
{
ip
=
request
.
getHeader
(
"X-Real-IP"
);
}
if
(
ip
==
null
||
ip
.
length
()
==
0
||
UNKNOWN
.
equalsIgnoreCase
(
ip
))
{
ip
=
request
.
getRemoteAddr
();
}
return
ip
;
}
public
static
String
getHostIp
()
{
String
sIP
=
""
;
InetAddress
ip
=
null
;
try
{
boolean
bFindIP
=
false
;
Enumeration
<
NetworkInterface
>
netInterfaces
=
NetworkInterface
.
getNetworkInterfaces
();
while
(
netInterfaces
.
hasMoreElements
())
{
if
(
bFindIP
)
{
break
;
}
NetworkInterface
ni
=
netInterfaces
.
nextElement
();
Enumeration
<
InetAddress
>
ips
=
ni
.
getInetAddresses
();
while
(
ips
.
hasMoreElements
())
{
ip
=
ips
.
nextElement
();
if
(!
ip
.
isLoopbackAddress
()
&&
ip
.
getHostAddress
().
matches
(
"(\\d{1,3}\\.){3}\\d{1,3}"
))
{
bFindIP
=
true
;
break
;
}
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
if
(
null
!=
ip
)
{
sIP
=
ip
.
getHostAddress
();
}
return
sIP
;
}
}
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