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
ef1b2105
Commit
ef1b2105
authored
Mar 25, 2020
by
renjie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ip购买修改
parent
7605fbad
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
12 additions
and
121 deletions
+12
-121
UserPrePaidBilling.java
...gec/browserbackend/account/domain/UserPrePaidBilling.java
+2
-40
CvmChargeRegion.java
...com/edgec/browserbackend/account/dto/CvmChargeRegion.java
+0
-28
AccountServiceImpl.java
...owserbackend/account/service/impl/AccountServiceImpl.java
+0
-43
AdministratorServiceImpl.java
...ackend/account/service/impl/AdministratorServiceImpl.java
+0
-5
IpResourceServiceImpl.java
...erbackend/browser/service/Impl/IpResourceServiceImpl.java
+10
-5
No files found.
src/main/java/com/edgec/browserbackend/account/domain/UserPrePaidBilling.java
View file @
ef1b2105
...
...
@@ -19,6 +19,8 @@ public class UserPrePaidBilling {
private
String
username
;
private
String
tradeNo
;
private
int
year
;
private
int
month
;
...
...
@@ -42,18 +44,10 @@ public class UserPrePaidBilling {
private
String
user
;
private
float
ownPotentialCost
=
0
;
private
float
ownActualCost
=
0
;
private
float
ownBillingCost
=
0
;
private
float
total
;
//0 -- 充值, 1 -- newip, 2 --renew, 3 --ipkeptfee, 4 --deleteip,
private
int
chargeType
;
private
String
target
;
private
String
unit
=
"month"
;
private
List
<
DeductionRecord
>
deductionRecords
=
new
ArrayList
<>();
...
...
@@ -82,14 +76,6 @@ public class UserPrePaidBilling {
this
.
chargeType
=
chargeType
;
}
public
String
getTarget
()
{
return
target
;
}
public
void
setTarget
(
String
target
)
{
this
.
target
=
target
;
}
public
String
getUnit
()
{
return
unit
;
}
...
...
@@ -146,22 +132,6 @@ public class UserPrePaidBilling {
this
.
services
=
services
;
}
public
float
getOwnPotentialCost
()
{
return
ownPotentialCost
;
}
public
void
setOwnPotentialCost
(
float
ownPotentialCost
)
{
this
.
ownPotentialCost
=
ownPotentialCost
;
}
public
float
getOwnActualCost
()
{
return
ownActualCost
;
}
public
void
setOwnActualCost
(
float
ownActualCost
)
{
this
.
ownActualCost
=
ownActualCost
;
}
public
BillStatus
getStatus
()
{
return
status
;
}
...
...
@@ -206,14 +176,6 @@ public class UserPrePaidBilling {
this
.
period
=
period
;
}
public
float
getOwnBillingCost
()
{
return
ownBillingCost
;
}
public
void
setOwnBillingCost
(
float
ownBillingCost
)
{
this
.
ownBillingCost
=
ownBillingCost
;
}
public
String
getUser
()
{
if
(
StringUtils
.
isEmpty
(
user
))
return
username
;
...
...
src/main/java/com/edgec/browserbackend/account/dto/CvmChargeRegion.java
deleted
100644 → 0
View file @
7605fbad
package
com
.
edgec
.
browserbackend
.
account
.
dto
;
// 购买,续费云主机时参数
public
class
CvmChargeRegion
{
private
float
defaultRate
;
//默认金额
private
String
region
;
// cvm-实例类型-带宽-系统盘-数据盘 -> cvm-2_4-8-20-40
public
float
getDefaultRate
()
{
return
defaultRate
;
}
public
void
setDefaultRate
(
float
defaultRate
)
{
this
.
defaultRate
=
defaultRate
;
}
public
String
getRegion
()
{
return
region
;
}
public
void
setRegion
(
String
region
)
{
this
.
region
=
region
;
}
}
src/main/java/com/edgec/browserbackend/account/service/impl/AccountServiceImpl.java
View file @
ef1b2105
...
...
@@ -192,51 +192,8 @@ public class AccountServiceImpl implements AccountService {
return
charge
;
}
private
float
findCvmRate
(
String
name
,
String
region
,
int
usedChargeType
)
{
CvmChargeRegion
cvmChargeRegion
=
JSONObject
.
parseObject
(
region
,
CvmChargeRegion
.
class
);
float
defaulRate
=
cvmChargeRegion
.
getDefaultRate
();
String
chargeRegion
=
cvmChargeRegion
.
getRegion
();
List
<
UserRate
>
byUsername
=
rateRepository
.
findByUsernameAndChargeType
(
name
,
usedChargeType
);
float
defaultRatePerMonth
=
byUsername
.
stream
().
filter
(
x
->
x
.
getRegion
().
equalsIgnoreCase
(
DEFAULT_REGION_KEY
)).
findFirst
().
map
(
x
->
x
.
getRate
()).
orElse
(
40.0
F
);
if
(
StringUtils
.
isEmpty
(
region
))
return
defaultRatePerMonth
;
UserRate
userRate
=
byUsername
.
stream
().
filter
(
x
->
Pattern
.
matches
(
x
.
getRegion
(),
chargeRegion
)).
findFirst
().
orElse
(
null
);
if
(
userRate
==
null
)
{
return
defaulRate
;
}
return
userRate
.
getRate
();
}
private
static
final
String
DEFAULT_REGION_KEY
=
"--default"
;
private
float
tryToFindClosedRate
(
String
name
,
String
region
,
int
usedChargeType
)
{
if
(
region
!=
null
&&
region
.
startsWith
(
"vps:"
))
{
name
=
"vpsclient"
;
}
List
<
UserRate
>
byUsername
=
rateRepository
.
findByUsernameAndChargeType
(
name
,
usedChargeType
);
float
defaultRatePerMonth
=
byUsername
.
stream
().
filter
(
x
->
x
.
getRegion
().
equalsIgnoreCase
(
DEFAULT_REGION_KEY
)).
findFirst
().
map
(
x
->
x
.
getRate
()).
orElse
(
40.0
F
);
if
(
StringUtils
.
isEmpty
(
region
))
return
defaultRatePerMonth
;
else
{
float
ratePerMonth
=
byUsername
.
stream
().
sorted
((
x1
,
x2
)
->
{
int
match1
=
CommonStringUtils
.
getLongestCommonSubstring
(
region
,
x1
.
getRegion
());
int
match2
=
CommonStringUtils
.
getLongestCommonSubstring
(
region
,
x2
.
getRegion
());
return
match2
-
match1
;
}).
findFirst
().
map
(
x
->
{
int
match1
=
CommonStringUtils
.
getLongestCommonSubstring
(
region
,
x
.
getRegion
());
if
(
match1
<=
3
)
return
defaultRatePerMonth
;
else
return
x
.
getRate
();
}).
orElse
(
defaultRatePerMonth
);
return
ratePerMonth
;
}
}
@Override
public
String
deletePreOrder
(
String
username
)
{
List
<
PreOrder
>
preOrders
=
preOrderRepository
.
findPreOrderByUserName
(
username
);
...
...
src/main/java/com/edgec/browserbackend/account/service/impl/AdministratorServiceImpl.java
View file @
ef1b2105
...
...
@@ -205,7 +205,6 @@ public class AdministratorServiceImpl implements AdministratorService {
CompanyEarningsDto
companyEarningsDto
=
new
CompanyEarningsDto
();
companyEarningsDto
.
setUsername
(
userPrePaidBilling
.
getUsername
());
companyEarningsDto
.
setUserBillAmount
(
userPrePaidBilling
.
getOwnActualCost
());
companyEarningsDto
.
setTotalBillingCost
(
userPrePaidBilling
.
getTotal
());
companyEarningsDto
.
setPayStatus
(
userPrePaidBilling
.
getStatus
());
...
...
@@ -272,9 +271,6 @@ public class AdministratorServiceImpl implements AdministratorService {
userPrePaidBilling
.
setStatus
(
BillStatus
.
PAID
);
}
userPrePaidBilling
.
setDeductionRecords
(
userBilling
.
getDeductionRecords
());
userPrePaidBilling
.
setOwnPotentialCost
(
userBilling
.
getOwnPotentialCost
());
userPrePaidBilling
.
setOwnActualCost
(
userBilling
.
getOwnActualCost
());
userPrePaidBilling
.
setOwnBillingCost
(
userBilling
.
getOwnBillingCost
());
userPrePaidBilling
.
setTotal
(
userBilling
.
getTotalBillingCost
());
userPrePaidBilling
.
setTimestamp
(
ZonedDateTime
.
of
(
userBilling
.
getYear
(),
userBilling
.
getMonth
(),
1
,
0
,
0
,
0
,
0
,
ZoneOffset
.
systemDefault
()).
toEpochSecond
()
*
1000
);
userPrePaidBilling
.
setPrepaid
(
false
);
...
...
@@ -282,7 +278,6 @@ public class AdministratorServiceImpl implements AdministratorService {
userPrePaidBilling
.
setUnit
(
"month"
);
userPrePaidBilling
.
setUser
(
userBilling
.
getUsername
());
userPrePaidBilling
.
setUsername
(
userBilling
.
getUsername
());
userPrePaidBilling
.
setTarget
(
userBilling
.
getUsername
()
+
"创建的云端伸缩组"
);
userPrePaidBillingRepository
.
save
(
userPrePaidBilling
);
}
...
...
src/main/java/com/edgec/browserbackend/browser/service/Impl/IpResourceServiceImpl.java
View file @
ef1b2105
...
...
@@ -35,6 +35,7 @@ import java.time.Instant;
import
java.time.ZoneOffset
;
import
java.util.*
;
import
java.util.concurrent.CompletableFuture
;
import
java.util.concurrent.atomic.AtomicBoolean
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
java.util.concurrent.atomic.AtomicReference
;
import
java.util.stream.Collectors
;
...
...
@@ -235,6 +236,7 @@ public class IpResourceServiceImpl implements IpResourceService {
ipTransactionDto
.
setIpResourceDtos
(
ipResourceDtos
);
if
(!
ipResourceRequestDto
.
getVendor
().
equals
(
"local"
))
{
AtomicBoolean
result
=
new
AtomicBoolean
(
false
);
CompletableFuture
.
runAsync
(()
->
{
PollerUtils
.
poll
(
300
,
15
,
()
->
{
try
{
...
...
@@ -263,11 +265,6 @@ public class IpResourceServiceImpl implements IpResourceService {
try
{
ipBuyResultDto
=
restTemplate
.
postForObject
(
URL
+
"/intelligroup/ipresources?accountId=browser"
,
httpEntity
,
IpBuyResultDto
.
class
);
if
(
StringUtils
.
isNotBlank
(
ipBuyResultDto
.
getErrorCode
()))
{
IpChargeRequestDto
ipChargeRequestDto
=
buildIpChargeRequestDto
(
ipResourceRequestDto
,
3
,
0
);
accountService
.
chargeByMoney
(
username
,
-
newprice
*
ipChargeRequestDto
.
getAmount
(),
ipChargeRequestDto
);
for
(
IpResourceDto
ipResourceDto
:
ipResourceDtos
)
{
ipResourceRepository
.
deleteById
(
ipResourceDto
.
getId
());
}
logger
.
error
(
"fail to buy ip"
);
logger
.
error
(
ipBuyResultDto
.
getErrorCode
());
return
false
;
...
...
@@ -300,12 +297,20 @@ public class IpResourceServiceImpl implements IpResourceService {
}
ipTransaction
.
setStatus
(
1
);
ipTransactionRepository
.
save
(
ipTransaction
);
result
.
set
(
true
);
return
true
;
}
catch
(
Exception
e
)
{
logger
.
error
(
e
.
getMessage
());
return
false
;
}
});
if
(
result
.
get
()
==
false
)
{
IpChargeRequestDto
ipChargeRequestDto
=
buildIpChargeRequestDto
(
ipResourceRequestDto
,
3
,
0
);
accountService
.
chargeByMoney
(
username
,
-
newprice
*
ipChargeRequestDto
.
getAmount
(),
ipChargeRequestDto
);
for
(
IpResourceDto
ipResourceDto
:
ipResourceDtos
)
{
ipResourceRepository
.
deleteById
(
ipResourceDto
.
getId
());
}
}
},
ThreadPoolUtils
.
taskExecutorPool
);
}
else
{
ipTransaction
.
setStatus
(
1
);
...
...
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