Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
browser-backend
Project
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
browser-backend
Commits
6f9b8daf
Commit
6f9b8daf
authored
Jul 24, 2020
by
xuxin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修復過期ip無法清除的bug
parent
bfa2888a
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
126 additions
and
9 deletions
+126
-9
IpResourceServiceImpl.java
...erbackend/browser/service/Impl/IpResourceServiceImpl.java
+119
-6
ShopServiceImpl.java
.../browserbackend/browser/service/Impl/ShopServiceImpl.java
+2
-2
IpResourceService.java
...gec/browserbackend/browser/service/IpResourceService.java
+5
-1
No files found.
src/main/java/com/edgec/browserbackend/browser/service/Impl/IpResourceServiceImpl.java
View file @
6f9b8daf
...
...
@@ -425,6 +425,102 @@ public class IpResourceServiceImpl implements IpResourceService {
return
ipOperationResultDto
;
}
@Override
public
IpOperationResultDto
deleteExpiredIp
(
String
username
,
IpResourceRequestDto
ipResourceRequestDto
)
{
Account
account
=
accountRepository
.
findByName
(
username
).
orElseThrow
(()
->
new
ClientRequestException
(
AccountErrorCode
.
NAMENOTEXIST
));
String
URL
=
(
profiles
.
equals
(
"dev"
)
||
profiles
.
equals
(
"staging"
))
?
TESTURL
:
CLOUDAMURL
;
RestTemplate
restTemplate
=
new
RestTemplate
();
HttpHeaders
headers
=
buildGetHeader
();
Map
<
String
,
String
>
params
=
new
HashMap
<
String
,
String
>();
HttpEntity
<
Map
<
String
,
String
>>
httpEntity
=
new
HttpEntity
<>(
params
,
headers
);
IpOperationResultDto
ipOperationResultDto
=
new
IpOperationResultDto
();
if
(
ipResourceRequestDto
.
getAddr
()
!=
null
&&
ipResourceRequestDto
.
getAddr
().
size
()
>
0
)
{
ipResourceRequestDto
.
getAddr
().
forEach
(
ipAddr
->
{
// 1. 查找需要删除的 ip 资源 是否被占用、 是否是当前用户的,若占用或不是当前用户的,则删除失败
IpResource
ipResource
=
ipResourceRepository
.
findByAddrAndIsDeletedAndIsLocked
(
ipAddr
,
false
,
false
);
if
(
ipResource
==
null
)
{
ipOperationResultDto
.
getFailList
().
add
(
ipAddr
);
// 在 foreach 中 return 的作用 相当于 普通 for循环中 continue 的作用
return
;
}
try
{
// 调用 uri删除远程的 IP资源
ResponseEntity
<
String
>
result
=
restTemplate
.
exchange
(
URL
+
"/intelligroup/ipresources?accountId=browser&ip={ip}"
,
HttpMethod
.
DELETE
,
httpEntity
,
String
.
class
,
ipAddr
);
DeleteIpResultDto
deleteIpResultDto
=
JSON
.
parseObject
(
result
.
getBody
(),
DeleteIpResultDto
.
class
);
if
(
deleteIpResultDto
.
getResult
().
equals
(
"failed"
)
||
StringUtils
.
isNotBlank
(
deleteIpResultDto
.
getErrorCode
()))
{
NotifyUtils
.
sendMessage
(
"防关联浏览器 ip "
+
ipResource
.
getAddr
()
+
" 删除失败"
,
NotifyUtils
.
MsgType
.
WEBHOOK
);
logger
.
error
(
"ip "
+
ipResource
.
getAddr
()
+
" 删除失败"
);
logger
.
error
(
"ErrorCode: "
+
deleteIpResultDto
.
getErrorCode
()
+
" "
+
deleteIpResultDto
.
getResult
());
}
}
catch
(
Exception
e
)
{
logger
.
error
(
"fail to delete ip"
,
e
);
ipOperationResultDto
.
getFailList
().
add
(
ipAddr
);
}
try
{
// ip资源为未绑定,则直接删除
if
(
ipResource
.
getStatus
()
==
6
)
{
ipResourceRepository
.
delete
(
ipResource
);
// 其他情况(主要是 ip资源还未创建成功的状态),则将 ip资源的状态改为删除
}
else
{
ipResource
.
setShopIds
(
null
);
ipResource
.
setDeleted
(
true
);
ipResourceRepository
.
save
(
ipResource
);
}
ipOperationResultDto
.
getSuccessList
().
add
(
ipAddr
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"fail to delete ip"
,
e
);
ipOperationResultDto
.
getFailList
().
add
(
ipAddr
);
return
;
}
}
);
}
if
(
ipResourceRequestDto
.
getIpId
()
!=
null
&&
ipResourceRequestDto
.
getIpId
().
size
()
>
0
)
{
ipResourceRequestDto
.
getIpId
().
forEach
(
ipId
->
{
IpResource
ipResource
=
ipResourceRepository
.
findByIdAndIsDeletedAndIsLocked
(
ipId
,
false
,
false
);
if
(
ipResource
==
null
)
{
ipOperationResultDto
.
getFailList
().
add
(
ipId
);
return
;
}
if
(
ipResource
.
getStatus
()
==
6
)
{
ipResourceRepository
.
delete
(
ipResource
);
}
else
if
(
StringUtils
.
isNotBlank
(
ipResource
.
getAddr
())
&&
ipResource
.
getIpType
()
==
IpType
.
VENDOR
)
{
try
{
ResponseEntity
<
String
>
result
=
restTemplate
.
exchange
(
URL
+
"/intelligroup/ipresources?accountId=browser&ip={ip}"
,
HttpMethod
.
DELETE
,
httpEntity
,
String
.
class
,
ipResource
.
getAddr
());
DeleteIpResultDto
deleteIpResultDto
=
JSON
.
parseObject
(
result
.
getBody
(),
DeleteIpResultDto
.
class
);
if
(
deleteIpResultDto
.
getResult
().
equals
(
"failed"
)
||
StringUtils
.
isNotBlank
(
deleteIpResultDto
.
getErrorCode
()))
{
NotifyUtils
.
sendMessage
(
"防关联浏览器 ip "
+
ipResource
.
getAddr
()
+
" 删除失败"
,
NotifyUtils
.
MsgType
.
WEBHOOK
);
logger
.
error
(
"ip "
+
ipResource
.
getAddr
()
+
" 删除失败"
);
}
}
catch
(
Exception
t
)
{
logger
.
error
(
"ip "
+
ipResource
.
getAddr
()
+
" 删除失败"
,
t
);
}
}
ipResource
.
setDeleted
(
true
);
ipResource
.
setShopIds
(
null
);
ipResourceRepository
.
save
(
ipResource
);
ipOperationResultDto
.
getSuccessList
().
add
(
ipId
);
}
);
}
return
ipOperationResultDto
;
}
@Override
public
IpOperationResultDto
deleteIp
(
String
username
,
IpResourceRequestDto
ipResourceRequestDto
)
{
...
...
@@ -471,6 +567,12 @@ public class IpResourceServiceImpl implements IpResourceService {
logger
.
error
(
"ErrorCode: "
+
deleteIpResultDto
.
getErrorCode
()
+
" "
+
deleteIpResultDto
.
getResult
());
}
}
catch
(
Exception
e
)
{
logger
.
error
(
"fail to delete ip"
,
e
);
ipOperationResultDto
.
getFailList
().
add
(
ipAddr
);
}
try
{
// ip资源为未绑定,则直接删除
if
(
ipResource
.
getStatus
()
==
6
)
{
ipResourceRepository
.
delete
(
ipResource
);
...
...
@@ -483,7 +585,7 @@ public class IpResourceServiceImpl implements IpResourceService {
}
ipOperationResultDto
.
getSuccessList
().
add
(
ipAddr
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"fail to delete ip"
,
e
.
getMessage
()
);
logger
.
error
(
"fail to delete ip"
,
e
);
ipOperationResultDto
.
getFailList
().
add
(
ipAddr
);
return
;
}
...
...
@@ -501,6 +603,7 @@ public class IpResourceServiceImpl implements IpResourceService {
if
(
ipResource
.
getStatus
()
==
6
)
{
ipResourceRepository
.
delete
(
ipResource
);
}
else
if
(
StringUtils
.
isNotBlank
(
ipResource
.
getAddr
())
&&
ipResource
.
getIpType
()
==
IpType
.
VENDOR
)
{
try
{
ResponseEntity
<
String
>
result
=
restTemplate
.
exchange
(
URL
+
"/intelligroup/ipresources?accountId=browser&ip={ip}"
,
HttpMethod
.
DELETE
,
httpEntity
,
String
.
class
,
ipResource
.
getAddr
());
DeleteIpResultDto
deleteIpResultDto
=
JSON
.
parseObject
(
result
.
getBody
(),
DeleteIpResultDto
.
class
);
...
...
@@ -508,6 +611,9 @@ public class IpResourceServiceImpl implements IpResourceService {
NotifyUtils
.
sendMessage
(
"防关联浏览器 ip "
+
ipResource
.
getAddr
()
+
" 删除失败"
,
NotifyUtils
.
MsgType
.
WEBHOOK
);
logger
.
error
(
"ip "
+
ipResource
.
getAddr
()
+
" 删除失败"
);
}
}
catch
(
Exception
t
)
{
logger
.
error
(
"ip "
+
ipResource
.
getAddr
()
+
" 删除失败"
,
t
);
}
}
if
(
ipResource
.
getShopIds
()
!=
null
)
{
...
...
@@ -578,11 +684,11 @@ public class IpResourceServiceImpl implements IpResourceService {
if
(
x
.
getIpType
()
==
IpType
.
VENDOR
)
{
IpResourceRequestDto
ipResourceRequestDto
=
new
IpResourceRequestDto
();
ipResourceRequestDto
.
setAddr
(
Arrays
.
asList
(
x
.
getAddr
()));
deleteIp
(
username
,
ipResourceRequestDto
);
delete
Expired
Ip
(
username
,
ipResourceRequestDto
);
}
else
{
IpResourceRequestDto
ipResourceRequestDto
=
new
IpResourceRequestDto
();
ipResourceRequestDto
.
setIpId
(
Arrays
.
asList
(
x
.
getId
()));
deleteIp
(
username
,
ipResourceRequestDto
);
delete
Expired
Ip
(
username
,
ipResourceRequestDto
);
}
return
;
...
...
@@ -621,9 +727,16 @@ public class IpResourceServiceImpl implements IpResourceService {
// 将当前页的数据封装到 ipPageResultDto 中
IpPageResultDto
ipPageResultDto
=
new
IpPageResultDto
();
Page
<
IpResourceDto
>
ipResourceDtoPage
=
new
PageImpl
<>(
ipResourceDtos
,
pageable
,
allIpIds
.
size
());
int
totalSize
=
allIpIds
.
size
();
if
(
ipResourceDtos
==
null
||
ipResourceDtos
.
isEmpty
())
{
totalSize
=
0
;
}
Page
<
IpResourceDto
>
ipResourceDtoPage
=
new
PageImpl
<>(
ipResourceDtos
,
pageable
,
totalSize
);
ipPageResultDto
.
setIpList
(
ipResourceDtoPage
.
getContent
());
PageInfo
pageInfo
=
new
PageInfo
(
ipResourceDtoPage
.
getPageable
().
getPageNumber
(),
ipResourceDtoPage
.
getTotalPages
(),
allIpIds
.
size
()
);
PageInfo
pageInfo
=
new
PageInfo
(
ipResourceDtoPage
.
getPageable
().
getPageNumber
(),
ipResourceDtoPage
.
getTotalPages
(),
totalSize
);
ipPageResultDto
.
setIpPage
(
pageInfo
);
return
ipPageResultDto
;
...
...
@@ -740,7 +853,7 @@ public class IpResourceServiceImpl implements IpResourceService {
if
(
ipResource
.
getValidTime
()
<=
Instant
.
now
().
plusSeconds
(
60
*
60
*
24
*
7
).
toEpochMilli
()
&&
ipResource
.
getValidTime
()
>
Instant
.
now
().
toEpochMilli
())
{
ipResourceRepository
.
updateStatus
(
ipResource
.
getId
(),
2
);
}
else
if
(
ipResource
.
getValidTime
()
<=
Instant
.
now
().
minusSeconds
(
60
*
60
*
24
*
7
).
toEpochMilli
())
{
deleteIp
(
username
,
ipResourceRequestDto
);
delete
Expired
Ip
(
username
,
ipResourceRequestDto
);
}
else
if
(
ipResource
.
getValidTime
()
<=
Instant
.
now
().
toEpochMilli
())
{
ipResourceRepository
.
updateStatus
(
ipResource
.
getId
(),
1
);
}
else
{
...
...
src/main/java/com/edgec/browserbackend/browser/service/Impl/ShopServiceImpl.java
View file @
6f9b8daf
...
...
@@ -460,7 +460,7 @@ public class ShopServiceImpl implements ShopService {
IpResourceRequestDto
ipResourceRequestDto1
=
new
IpResourceRequestDto
();
ipResourceRequestDto1
.
setAddr
(
Arrays
.
asList
(
ipResource
.
getAddr
()));
try
{
ipResourceService
.
deleteIp
(
username
,
ipResourceRequestDto1
);
ipResourceService
.
delete
Expired
Ip
(
username
,
ipResourceRequestDto1
);
}
catch
(
Exception
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
}
...
...
@@ -468,7 +468,7 @@ public class ShopServiceImpl implements ShopService {
IpResourceRequestDto
ipResourceRequestDto1
=
new
IpResourceRequestDto
();
ipResourceRequestDto1
.
setIpId
(
Arrays
.
asList
(
ipResource
.
getId
()));
try
{
ipResourceService
.
deleteIp
(
username
,
ipResourceRequestDto1
);
ipResourceService
.
delete
Expired
Ip
(
username
,
ipResourceRequestDto1
);
}
catch
(
Exception
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
}
...
...
src/main/java/com/edgec/browserbackend/browser/service/IpResourceService.java
View file @
6f9b8daf
package
com
.
edgec
.
browserbackend
.
browser
.
service
;
import
com.edgec.browserbackend.browser.domain.*
;
import
com.edgec.browserbackend.browser.domain.IpOptions
;
import
com.edgec.browserbackend.browser.domain.IpSummary
;
import
com.edgec.browserbackend.browser.domain.PlatformOptions
;
import
com.edgec.browserbackend.browser.dto.*
;
import
java.util.List
;
...
...
@@ -13,6 +15,8 @@ public interface IpResourceService {
IpOperationResultDto
deleteIp
(
String
username
,
IpResourceRequestDto
ipResourceRequestDto
)
throws
Exception
;
IpOperationResultDto
deleteExpiredIp
(
String
username
,
IpResourceRequestDto
ipResourceRequestDto
);
IpPageResultDto
getIpList
(
String
username
,
int
groupType
,
int
page
,
int
amount
,
IpFilterDto
ipFilterDto
);
void
setIpOptions
();
...
...
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