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
2a52374d
Commit
2a52374d
authored
Jul 01, 2020
by
xuxin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加注释与日志
parent
d149c51e
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
298 additions
and
403 deletions
+298
-403
AccountController.java
.../browserbackend/account/controller/AccountController.java
+24
-48
Account.java
...java/com/edgec/browserbackend/account/domain/Account.java
+1
-1
Otp.java
...ain/java/com/edgec/browserbackend/account/domain/Otp.java
+14
-23
Promotion.java
...va/com/edgec/browserbackend/account/domain/Promotion.java
+38
-79
User.java
...in/java/com/edgec/browserbackend/account/domain/User.java
+6
-100
UserPrePaidBilling.java
...gec/browserbackend/account/domain/UserPrePaidBilling.java
+10
-2
AccountServiceImpl.java
...owserbackend/account/service/impl/AccountServiceImpl.java
+117
-111
UserServiceImpl.java
...gec/browserbackend/auth/service/Impl/UserServiceImpl.java
+4
-6
ShopController.java
...gec/browserbackend/browser/controller/ShopController.java
+3
-0
IpResourceRequestDto.java
...dgec/browserbackend/browser/dto/IpResourceRequestDto.java
+33
-2
IpResourceRepositoryCustomImpl.java
...nd/browser/repository/IpResourceRepositoryCustomImpl.java
+1
-4
IpResourceServiceImpl.java
...erbackend/browser/service/Impl/IpResourceServiceImpl.java
+2
-2
BrowserTask.java
...va/com/edgec/browserbackend/browser/task/BrowserTask.java
+9
-7
PromotionTask.java
.../com/edgec/browserbackend/browser/task/PromotionTask.java
+36
-18
No files found.
src/main/java/com/edgec/browserbackend/account/controller/AccountController.java
View file @
2a52374d
...
...
@@ -30,7 +30,9 @@ import java.security.Principal;
import
java.time.ZoneOffset
;
import
java.time.ZonedDateTime
;
import
java.time.format.DateTimeFormatter
;
import
java.util.*
;
import
java.util.Date
;
import
java.util.Enumeration
;
import
java.util.List
;
@RestController
@RequestMapping
(
"/user"
)
...
...
@@ -80,11 +82,7 @@ public class AccountController {
resultDto
.
setStatus
(
0
);
resultDto
.
setData
(
userDtos
);
}
catch
(
ClientRequestException
e
)
{
resultDto
.
setStatus
(-
1
);
Map
<
String
,
Object
>
statusInfo
=
new
HashMap
<>();
statusInfo
.
put
(
"code"
,
e
.
getErrorCode
());
statusInfo
.
put
(
"message"
,
e
.
getMessage
());
resultDto
.
setStatusInfo
(
statusInfo
);
dealClientRequestException
(
resultDto
,
e
);
}
return
resultDto
;
}
...
...
@@ -102,11 +100,7 @@ public class AccountController {
resultDto
.
setStatus
(
0
);
resultDto
.
setData
(
account1
);
}
catch
(
ClientRequestException
e
)
{
resultDto
.
setStatus
(-
1
);
Map
<
String
,
Object
>
statusInfo
=
new
HashMap
<>();
statusInfo
.
put
(
"code"
,
e
.
getErrorCode
());
statusInfo
.
put
(
"message"
,
e
.
getMessage
());
resultDto
.
setStatusInfo
(
statusInfo
);
dealClientRequestException
(
resultDto
,
e
);
}
return
resultDto
;
}
...
...
@@ -119,32 +113,29 @@ public class AccountController {
resultDto
.
setStatus
(
0
);
}
catch
(
ClientRequestException
e
)
{
logger
.
error
(
"fail to send sms"
,
e
);
resultDto
.
setStatus
(-
1
);
Map
<
String
,
Object
>
statusInfo
=
new
HashMap
<>();
statusInfo
.
put
(
"code"
,
e
.
getErrorCode
());
statusInfo
.
put
(
"message"
,
e
.
getMessage
());
resultDto
.
setStatusInfo
(
statusInfo
);
dealClientRequestException
(
resultDto
,
e
);
}
return
resultDto
;
}
/**
* 用户注册
*/
@RequestMapping
(
path
=
"/signUp"
,
method
=
RequestMethod
.
POST
)
public
ResultDto
createNewAccount
(
@Valid
@RequestBody
User
user
)
{
ResultDto
resultDto
=
new
ResultDto
();
try
{
Account
account
=
new
Account
();
if
(!
StringUtils
.
isEmpty
(
user
.
getEmail
()))
if
(!
StringUtils
.
isEmpty
(
user
.
getEmail
()))
{
account
=
accountService
.
create
(
user
);
else
}
else
{
account
=
accountService
.
createWithSms
(
user
);
}
resultDto
.
setStatus
(
0
);
resultDto
.
setData
(
account
);
}
catch
(
ClientRequestException
e
)
{
resultDto
.
setStatus
(-
1
);
Map
<
String
,
Object
>
statusInfo
=
new
HashMap
<>();
statusInfo
.
put
(
"code"
,
e
.
getErrorCode
());
statusInfo
.
put
(
"message"
,
e
.
getMessage
());
resultDto
.
setStatusInfo
(
statusInfo
);
dealClientRequestException
(
resultDto
,
e
);
}
return
resultDto
;
}
...
...
@@ -173,11 +164,7 @@ public class AccountController {
resultDto
.
setData
(
accountService
.
getUserPrePaidBills
(
principal
.
getName
(),
userPrePaidBillingRequestDto
));
resultDto
.
setStatus
(
0
);
}
catch
(
ClientRequestException
e
)
{
resultDto
.
setStatus
(-
1
);
Map
<
String
,
Object
>
statusInfo
=
new
HashMap
<>();
statusInfo
.
put
(
"code"
,
e
.
getErrorCode
());
statusInfo
.
put
(
"message"
,
e
.
getMessage
());
resultDto
.
setStatusInfo
(
statusInfo
);
dealClientRequestException
(
resultDto
,
e
);
}
return
resultDto
;
}
...
...
@@ -217,11 +204,7 @@ public class AccountController {
accountService
.
resetPassword
(
principal
.
getName
(),
user
);
resultDto
.
setStatus
(
0
);
}
catch
(
ClientRequestException
e
)
{
resultDto
.
setStatus
(-
1
);
Map
<
String
,
Object
>
statusInfo
=
new
HashMap
<>();
statusInfo
.
put
(
"code"
,
e
.
getErrorCode
());
statusInfo
.
put
(
"message"
,
e
.
getMessage
());
resultDto
.
setStatusInfo
(
statusInfo
);
dealClientRequestException
(
resultDto
,
e
);
}
return
resultDto
;
}
...
...
@@ -238,11 +221,7 @@ public class AccountController {
accountService
.
resetPasswordWithOtp
(
user
);
resultDto
.
setStatus
(
0
);
}
catch
(
ClientRequestException
e
)
{
resultDto
.
setStatus
(-
1
);
Map
<
String
,
Object
>
statusInfo
=
new
HashMap
<>();
statusInfo
.
put
(
"code"
,
e
.
getErrorCode
());
statusInfo
.
put
(
"message"
,
e
.
getMessage
());
resultDto
.
setStatusInfo
(
statusInfo
);
dealClientRequestException
(
resultDto
,
e
);
}
return
resultDto
;
}
...
...
@@ -449,11 +428,7 @@ public class AccountController {
accountService
.
authorizeCompany
(
principal
.
getName
(),
companyAuthorizeDto
);
resultDto
.
setStatus
(
0
);
}
catch
(
ClientRequestException
e
)
{
resultDto
.
setStatus
(-
1
);
Map
<
String
,
Object
>
statusInfo
=
new
HashMap
<>();
statusInfo
.
put
(
"code"
,
e
.
getErrorCode
());
statusInfo
.
put
(
"message"
,
e
.
getMessage
());
resultDto
.
setStatusInfo
(
statusInfo
);
dealClientRequestException
(
resultDto
,
e
);
}
return
resultDto
;
}
...
...
@@ -498,12 +473,13 @@ public class AccountController {
else
resultDto
.
setStatus
(-
1
);
}
catch
(
ClientRequestException
e
)
{
resultDto
.
setStatus
(-
1
);
Map
<
String
,
Object
>
statusInfo
=
new
HashMap
<>();
statusInfo
.
put
(
"code"
,
e
.
getErrorCode
());
statusInfo
.
put
(
"message"
,
e
.
getMessage
());
resultDto
.
setStatusInfo
(
statusInfo
);
dealClientRequestException
(
resultDto
,
e
);
}
return
resultDto
;
}
private
void
dealClientRequestException
(
ResultDto
resultDto
,
ClientRequestException
e
)
{
dealClientRequestException
(
resultDto
,
e
);
}
}
src/main/java/com/edgec/browserbackend/account/domain/Account.java
View file @
2a52374d
...
...
@@ -68,7 +68,7 @@ public class Account {
private
int
permission
=
-
1
;
/**
* 注册成功后,当前用户的邀请码,用于邀请别人获取佣金
* 注册成功后,当前用户的邀请码
相关信息
,用于邀请别人获取佣金
*/
private
Promotion
promotion
;
...
...
src/main/java/com/edgec/browserbackend/account/domain/Otp.java
View file @
2a52374d
package
com
.
edgec
.
browserbackend
.
account
.
domain
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
lombok.Data
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.mongodb.core.mapping.Document
;
@Data
@Document
(
collection
=
"phoneotp"
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
Otp
{
/**
* 手机号
*/
@Id
private
String
phone
;
private
String
otp
;
private
long
createdAt
;
public
String
getPhone
()
{
return
phone
;
}
public
void
setPhone
(
String
phone
)
{
this
.
phone
=
phone
;
}
public
String
getOtp
()
{
return
otp
;
}
public
void
setOtp
(
String
otp
)
{
this
.
otp
=
otp
;
}
/**
* 发送给用户的短信验证码
*/
private
String
otp
;
public
long
getCreatedAt
()
{
return
createdAt
;
}
/**
* 短信验证码的发送时间
*/
private
long
createdAt
;
public
void
setCreatedAt
(
long
createdAt
)
{
this
.
createdAt
=
createdAt
;
}
}
src/main/java/com/edgec/browserbackend/account/domain/Promotion.java
View file @
2a52374d
package
com
.
edgec
.
browserbackend
.
account
.
domain
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
lombok.Getter
;
import
lombok.Setter
;
/**
* @Desc
* @Author jason
* @CreateTime 2020/3/12 3:14 下午
**/
@Getter
@Setter
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
Promotion
{
/**
* 邀请码(用户邀请好友使用本产品)
*/
private
String
code
;
//邀请人数
/**
* 邀请人数
*/
private
int
invitedUsers
;
//好友本月以前总消费
private
int
totalCommission
;
//好友当月消费
private
int
commission
;
//好友上月总消费
private
int
commissionLastMonth
;
//是否是本公司的销售
private
boolean
isSale
;
//当月礼金
private
double
gift
;
//所有未提现金额
private
double
allGift
;
//已提现金额
private
double
withdrawn
;
public
int
getCommission
()
{
return
commission
;
}
public
void
setCommission
(
int
commission
)
{
this
.
commission
=
commission
;
}
public
int
getInvitedUsers
()
{
return
invitedUsers
;
}
public
void
setInvitedUsers
(
int
invitedUsers
)
{
this
.
invitedUsers
=
invitedUsers
;
}
public
String
getCode
()
{
return
code
;
}
public
void
setCode
(
String
code
)
{
this
.
code
=
code
;
}
public
boolean
isSale
()
{
return
isSale
;
}
public
void
setSale
(
boolean
sale
)
{
isSale
=
sale
;
}
public
double
getGift
()
{
return
gift
;
}
public
void
setGift
(
double
gift
)
{
this
.
gift
=
gift
;
}
public
int
getCommissionLastMonth
()
{
return
commissionLastMonth
;
}
/**
* 好友本月以前总消费
*/
private
int
totalCommission
;
public
void
setCommissionLastMonth
(
int
commissionLastMonth
)
{
this
.
commissionLastMonth
=
commissionLastMonth
;
}
/**
* 好友当月消费
*/
private
int
commission
;
public
double
getAllGift
()
{
return
allGift
;
}
/**
* 好友上月总消费
*/
private
int
commissionLastMonth
;
public
void
setAllGift
(
double
allGift
)
{
this
.
allGift
=
allGift
;
}
/**
* 是否是本公司的销售
*/
private
boolean
isSale
;
public
double
getWithdrawn
()
{
return
withdrawn
;
}
/**
* 当月礼金
*/
private
double
gift
;
public
void
setWithdrawn
(
double
withdrawn
)
{
this
.
withdrawn
=
withdrawn
;
}
/**
* 所有未提现金额
*/
private
double
allGift
;
public
int
getTotalCommission
()
{
return
totalCommission
;
}
/**
* 已提现金额
*/
private
double
withdrawn
;
public
void
setTotalCommission
(
int
totalCommission
)
{
this
.
totalCommission
=
totalCommission
;
}
}
src/main/java/com/edgec/browserbackend/account/domain/User.java
View file @
2a52374d
package
com
.
edgec
.
browserbackend
.
account
.
domain
;
import
lombok.Data
;
import
org.hibernate.validator.constraints.Length
;
import
javax.validation.constraints.Email
;
...
...
@@ -7,15 +8,16 @@ import java.util.ArrayList;
import
java.util.List
;
import
java.util.UUID
;
@Data
public
class
User
{
@Length
(
min
=
3
,
max
=
20
,
message
=
"Name length should be between 3 - 20"
)
@Length
(
min
=
3
,
max
=
20
,
message
=
"Name length should be between 3 - 20"
)
private
String
username
;
@Length
(
min
=
6
,
max
=
40
,
message
=
"Password length should be between 6 - 40"
)
@Length
(
min
=
6
,
max
=
40
,
message
=
"Password length should be between 6 - 40"
)
private
String
password
;
@Email
(
message
=
"Invalid email address"
)
@Email
(
message
=
"Invalid email address"
)
private
String
email
;
private
String
phone
;
...
...
@@ -28,108 +30,12 @@ public class User {
private
String
lockReason
;
public
String
getAuthCode
()
{
return
authCode
;
}
public
void
setAuthCode
(
String
authCode
)
{
this
.
authCode
=
authCode
;
}
public
String
getPhone
()
{
return
phone
;
}
public
void
setPhone
(
String
phone
)
{
this
.
phone
=
phone
;
}
private
boolean
allowedToCreateSubUser
=
true
;
private
int
permission
;
private
List
<
String
>
whiteList
=
new
ArrayList
<>();
private
String
verificationCode
=
UUID
.
randomUUID
().
toString
();
public
boolean
isEnabled
()
{
return
enabled
;
}
public
void
setEnabled
(
boolean
enabled
)
{
this
.
enabled
=
enabled
;
}
public
String
getVerificationCode
()
{
return
verificationCode
;
}
public
void
setVerificationCode
(
String
verificationCode
)
{
this
.
verificationCode
=
verificationCode
;
}
public
String
getEmail
()
{
return
email
;
}
public
void
setEmail
(
String
email
)
{
this
.
email
=
email
;
}
public
String
getUsername
()
{
return
username
;
}
public
void
setUsername
(
String
username
)
{
this
.
username
=
username
;
}
public
String
getPassword
()
{
return
password
;
}
public
void
setPassword
(
String
password
)
{
this
.
password
=
password
;
}
public
boolean
isAllowedToCreateSubUser
()
{
return
allowedToCreateSubUser
;
}
public
void
setAllowedToCreateSubUser
(
boolean
allowedToCreateSubUser
)
{
allowedToCreateSubUser
=
allowedToCreateSubUser
;
}
public
int
getPermission
()
{
return
permission
;
}
public
void
setPermission
(
int
permission
)
{
this
.
permission
=
permission
;
}
public
String
getLockReason
()
{
return
lockReason
;
}
public
void
setLockReason
(
String
lockReason
)
{
this
.
lockReason
=
lockReason
;
}
public
List
<
String
>
getWhiteList
()
{
return
whiteList
;
}
public
void
setWhiteList
(
List
<
String
>
whiteList
)
{
this
.
whiteList
=
whiteList
;
}
public
String
getPromotionCode
()
{
return
promotionCode
;
}
private
String
verificationCode
=
UUID
.
randomUUID
().
toString
();
public
void
setPromotionCode
(
String
promotionCode
)
{
this
.
promotionCode
=
promotionCode
;
}
}
src/main/java/com/edgec/browserbackend/account/domain/UserPrePaidBilling.java
View file @
2a52374d
...
...
@@ -40,13 +40,21 @@ public class UserPrePaidBilling {
private
BillStatus
status
;
//0 -- 余额, 1 -- 支付宝, 2 -- 微信, 3 -- 银行转账
/**
* 0 -- 余额, 1 -- 支付宝, 2 -- 微信, 3 -- 银行转账
*/
private
int
payMethod
;
private
boolean
isPrepaid
;
/**
* 本次消费金额
*/
private
float
total
;
//0 -- 充值, 1 -- newip, 2 -- renew, 3 -- return, 4 -- 礼金提现
/**
* 0 -- 充值, 1 -- newip, 2 -- renew, 3 -- return, 4 -- 礼金提现
*/
private
int
chargeType
;
private
String
unit
=
"month"
;
...
...
src/main/java/com/edgec/browserbackend/account/service/impl/AccountServiceImpl.java
View file @
2a52374d
...
...
@@ -224,40 +224,6 @@ public class AccountServiceImpl implements AccountService {
return
charge
;
}
@NotNull
private
UserPrePaidBilling
getUserPrePaidBilling
(
String
name
,
float
money
,
IpChargeRequestDto
requestDto
,
Account
account
,
UserBalance
userBalance
)
{
UserPrePaidBilling
bill
=
new
UserPrePaidBilling
();
if
(
account
.
getParent
()
!=
null
)
{
bill
.
setAdministrator
(
account
.
getParent
());
}
else
{
bill
.
setAdministrator
(
account
.
getName
());
}
bill
.
setTradeNo
(
new
SimpleDateFormat
(
"yyyyMMddHHmmss"
).
format
(
new
Date
())
+
SmsUtils
.
createRandom
(
true
,
4
));
bill
.
setChargeType
(
requestDto
.
getChargeType
());
if
(
requestDto
.
getChargeIp
()
!=
null
)
{
bill
.
setChargeIp
(
requestDto
.
getChargeIp
());
}
bill
.
setAmount
(
requestDto
.
getAmount
());
bill
.
setUnit
(
requestDto
.
getUnit
());
bill
.
setPeriod
(
requestDto
.
getPeriod
());
bill
.
setPayMethod
(
requestDto
.
getPayMethod
());
bill
.
setUsername
(
name
);
bill
.
setTotal
(
money
);
bill
.
setStatus
(
BillStatus
.
PAID
);
bill
.
setPrepaid
(
true
);
bill
.
setTimestamp
(
Instant
.
now
().
toEpochMilli
());
final
YearMonth
lastmonth
=
YearMonth
.
now
();
int
monthValue
=
lastmonth
.
getMonthValue
();
int
year
=
lastmonth
.
getYear
();
bill
.
setYear
(
year
);
bill
.
setMonth
(
monthValue
);
bill
.
setBalanced
(
userBalance
.
getBalanced
());
return
bill
;
}
private
static
final
String
DEFAULT_REGION_KEY
=
"--default"
;
@Override
...
...
@@ -454,25 +420,17 @@ public class AccountServiceImpl implements AccountService {
@Override
public
Account
createWithSms
(
User
user
)
{
Account
existing
=
accountRepository
.
findByName
(
user
.
getUsername
()).
orElse
(
null
);
if
(
existing
!=
null
)
// 1. 校验注册用户是否已存在
Account
existing1
=
accountRepository
.
findByName
(
user
.
getUsername
()).
orElse
(
null
);
Account
existing2
=
accountRepository
.
findByPhoneNumber
(
user
.
getUsername
());
Account
existing3
=
accountRepository
.
findByPhoneNumber
(
user
.
getPhone
());
Account
existing4
=
accountRepository
.
findByName
(
user
.
getPhone
()).
orElse
(
null
);
if
(
existing1
!=
null
||
existing2
!=
null
||
existing3
!=
null
||
existing4
!=
null
)
{
throw
new
ClientRequestException
(
AccountErrorCode
.
NAMEEXIST
,
"account already exists: "
+
user
.
getUsername
());
}
existing
=
accountRepository
.
findByPhoneNumber
(
user
.
getUsername
());
if
(
existing
!=
null
)
throw
new
ClientRequestException
(
AccountErrorCode
.
NAMEEXIST
,
"account already exists: "
+
user
.
getUsername
());
existing
=
accountRepository
.
findByPhoneNumber
(
user
.
getPhone
());
if
(
existing
!=
null
)
throw
new
ClientRequestException
(
AccountErrorCode
.
PHONEEXIST
,
"phone number already exists: "
+
user
.
getPhone
());
existing
=
accountRepository
.
findByName
(
user
.
getPhone
()).
orElse
(
null
);
if
(
existing
!=
null
)
throw
new
ClientRequestException
(
AccountErrorCode
.
PHONEEXIST
,
"phone number already exists: "
+
user
.
getPhone
());
// 2. 校验用户输入的短信验证码是否正确
Otp
otp
=
otpRepository
.
findByPhoneAndCreatedAtGreaterThanEqual
(
user
.
getUsername
(),
Instant
.
now
().
minusSeconds
(
600
).
toEpochMilli
());
if
(
otp
==
null
)
{
throw
new
ClientRequestException
(
AccountErrorCode
.
OTPWRONG
,
AccountErrorCode
.
OTPWRONG
.
getReason
());
}
...
...
@@ -482,85 +440,69 @@ public class AccountServiceImpl implements AccountService {
// otpRepository.delete(otp);
}
Account
account
=
new
Account
();
account
.
setName
(
user
.
getUsername
());
account
.
setLastSeen
(
new
Date
());
account
.
setEmail
(
user
.
getEmail
());
account
.
setPhoneNumber
(
user
.
getUsername
());
account
.
setPermission
(
15
);
if
(
user
.
getPromotionCode
()
!=
null
)
{
account
.
setPromotionCode
(
user
.
getPromotionCode
());
}
// 3. 若用户注册时输入了邀请码,则更新邀请人的 account 信息
Account
inviter
=
accountRepository
.
findByPromotion
(
user
.
getPromotionCode
());
if
(
inviter
!=
null
)
{
inviter
.
getPromotion
().
setInvitedUsers
(
inviter
.
getPromotion
().
getInvitedUsers
()
+
1
);
accountRepository
.
save
(
inviter
);
}
Account
pExisting
=
null
;
String
random
=
null
;
do
{
random
=
String
.
valueOf
((
int
)
((
Math
.
random
()
*
9
+
1
)
*
100000
));
pExisting
=
accountRepository
.
findByPromotion
(
random
);
}
while
(
pExisting
!=
null
);
Promotion
promotion
=
new
Promotion
();
promotion
.
setCode
(
random
);
promotion
.
setInvitedUsers
(
0
);
promotion
.
setCommission
(
0
);
account
.
setPromotion
(
promotion
);
account
.
setAllowedToCreateSubUser
(
true
);
List
<
String
>
whiteList
=
new
ArrayList
<>();
if
(
user
.
getWhiteList
()
!=
null
&&
user
.
getWhiteList
().
size
()
>
0
)
whiteList
.
addAll
(
user
.
getWhiteList
());
account
.
setWhiteList
(
whiteList
);
// 4. 创建 User
user
.
setEnabled
(
true
);
userService
.
create
(
new
com
.
edgec
.
browserbackend
.
auth
.
domain
.
User
(
user
));
// 5. 封装用户账户 并 创建
Account
account
=
buildAccount
(
user
);
accountRepository
.
save
(
account
);
JSONObject
param
=
new
JSONObject
();
param
.
put
(
"newuser"
,
account
.
getName
());
if
(
inviter
!=
null
)
if
(
inviter
!=
null
)
{
param
.
put
(
"referral"
,
inviter
.
getName
()
+
"("
+
user
.
getPromotionCode
()
+
")"
);
else
}
else
{
param
.
put
(
"referral"
,
"123456"
);
}
com
.
edgec
.
browserbackend
.
common
.
commons
.
utils
.
SmsUtils
.
sendNewAccountSms
(
"15919921106"
,
com
.
edgec
.
browserbackend
.
common
.
commons
.
utils
.
SmsUtils
.
SmsTemplateCode
.
NEWACCOUNT
,
param
);
com
.
edgec
.
browserbackend
.
common
.
commons
.
utils
.
SmsUtils
.
sendNewAccountSms
(
"13570690305"
,
com
.
edgec
.
browserbackend
.
common
.
commons
.
utils
.
SmsUtils
.
SmsTemplateCode
.
NEWACCOUNT
,
param
);
com
.
edgec
.
browserbackend
.
common
.
commons
.
utils
.
SmsUtils
.
sendNewAccountSms
(
"13802945832"
,
com
.
edgec
.
browserbackend
.
common
.
commons
.
utils
.
SmsUtils
.
SmsTemplateCode
.
NEWACCOUNT
,
param
);
// 6. 使用手机注册就送 12 元体验金
paymentService
.
bankTransferInsertion
(
account
.
getName
(),
12
);
log
.
info
(
"new account has been created: "
+
account
.
getName
());
// 7. 发送注册成功的邮件
notifyCustomerRegister
(
account
);
return
account
;
}
public
Account
create
(
User
user
,
String
parentName
)
{
// 1. 校验用户是否已注册
Account
existing
=
accountRepository
.
findByName
(
user
.
getUsername
()).
orElse
(
null
);
if
(
existing
!=
null
)
if
(
existing
!=
null
)
{
throw
new
ClientRequestException
(
AccountErrorCode
.
NAMEEXIST
,
"account already exists: "
+
user
.
getUsername
());
}
existing
=
accountRepository
.
findByPhoneNumber
(
user
.
getUsername
());
if
(
existing
!=
null
)
if
(
existing
!=
null
)
{
throw
new
ClientRequestException
(
AccountErrorCode
.
NAMEEXIST
,
"account already exists: "
+
user
.
getUsername
());
}
existing
=
accountRepository
.
findByEmail
(
user
.
getEmail
());
if
(
existing
!=
null
)
if
(
existing
!=
null
)
{
throw
new
ClientRequestException
(
AccountErrorCode
.
EMAILEXIST
,
"email already exists: "
+
user
.
getEmail
());
}
// 2. 发送校验邮件
emailService
.
sendEmailVerification
(
user
.
getUsername
(),
user
.
getEmail
(),
user
.
getVerificationCode
());
// 3. 创建 User
user
.
setEnabled
(
false
);
userService
.
create
(
new
com
.
edgec
.
browserbackend
.
auth
.
domain
.
User
(
user
));
// 4. 创建用户账户
Account
account
=
new
Account
();
account
.
setName
(
user
.
getUsername
());
account
.
setLastSeen
(
new
Date
());
account
.
setEmail
(
user
.
getEmail
());
if
(
StringUtils
.
isEmpty
(
parentName
))
{
account
.
setAllowedToCreateSubUser
(
true
);
account
.
setPermission
(
Integer
.
valueOf
(
"1111"
,
2
));
...
...
@@ -568,36 +510,17 @@ public class AccountServiceImpl implements AccountService {
account
.
setAllowedToCreateSubUser
(
user
.
isAllowedToCreateSubUser
());
account
.
setPermission
(
user
.
getPermission
());
}
account
.
setParent
(
parentName
);
emailService
.
sendEmailVerification
(
user
.
getUsername
(),
user
.
getEmail
(),
user
.
getVerificationCode
());
userService
.
create
(
new
com
.
edgec
.
browserbackend
.
auth
.
domain
.
User
(
user
));
accountRepository
.
save
(
account
);
log
.
info
(
"new account has been created: "
+
account
.
getName
());
// SmsUtils.notifyNewUserRegistered();
// 5. 发送注册成功的邮件
notifyCustomerRegister
(
account
);
return
account
;
}
private
void
notifyCustomerRegister
(
Account
contactUs
)
{
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"Name: "
+
contactUs
.
getName
()
+
"<br/>"
);
sb
.
append
(
"Email: "
+
contactUs
.
getEmail
()
+
"<br/>"
);
sb
.
append
(
"Phone: "
+
contactUs
.
getPhoneNumber
()
+
"<br/>"
);
sb
.
append
(
"Company: "
+
contactUs
.
getCompanyName
()
+
"<br/>"
);
sb
.
append
(
"Title: "
+
contactUs
.
getJobTitle
()
+
"<br/>"
);
try
{
emailService
.
sendHtmlMail
(
"sales@cloudam.io"
,
"新客户注册:"
+
contactUs
.
getName
(),
sb
.
toString
());
}
catch
(
Exception
e
)
{
log
.
error
(
"sending email fails on customer regisration"
,
e
);
}
}
@Override
public
List
<
UserDto
>
getAllDesendentUsers
(
String
name
,
int
level
)
{
...
...
@@ -1226,4 +1149,87 @@ public class AccountServiceImpl implements AccountService {
return
false
;
}
}
private
void
notifyCustomerRegister
(
Account
contactUs
)
{
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"Name: "
+
contactUs
.
getName
()
+
"<br/>"
);
sb
.
append
(
"Email: "
+
contactUs
.
getEmail
()
+
"<br/>"
);
sb
.
append
(
"Phone: "
+
contactUs
.
getPhoneNumber
()
+
"<br/>"
);
sb
.
append
(
"Company: "
+
contactUs
.
getCompanyName
()
+
"<br/>"
);
sb
.
append
(
"Title: "
+
contactUs
.
getJobTitle
()
+
"<br/>"
);
try
{
emailService
.
sendHtmlMail
(
"sales@cloudam.io"
,
"新客户注册:"
+
contactUs
.
getName
(),
sb
.
toString
());
}
catch
(
Exception
e
)
{
log
.
error
(
"sending email fails on customer regisration"
,
e
);
}
}
@NotNull
private
UserPrePaidBilling
getUserPrePaidBilling
(
String
name
,
float
money
,
IpChargeRequestDto
requestDto
,
Account
account
,
UserBalance
userBalance
)
{
UserPrePaidBilling
bill
=
new
UserPrePaidBilling
();
if
(
account
.
getParent
()
!=
null
)
{
bill
.
setAdministrator
(
account
.
getParent
());
}
else
{
bill
.
setAdministrator
(
account
.
getName
());
}
bill
.
setTradeNo
(
new
SimpleDateFormat
(
"yyyyMMddHHmmss"
).
format
(
new
Date
())
+
SmsUtils
.
createRandom
(
true
,
4
));
bill
.
setChargeType
(
requestDto
.
getChargeType
());
if
(
requestDto
.
getChargeIp
()
!=
null
)
{
bill
.
setChargeIp
(
requestDto
.
getChargeIp
());
}
bill
.
setAmount
(
requestDto
.
getAmount
());
bill
.
setUnit
(
requestDto
.
getUnit
());
bill
.
setPeriod
(
requestDto
.
getPeriod
());
bill
.
setPayMethod
(
requestDto
.
getPayMethod
());
bill
.
setUsername
(
name
);
bill
.
setTotal
(
money
);
bill
.
setStatus
(
BillStatus
.
PAID
);
bill
.
setPrepaid
(
true
);
bill
.
setTimestamp
(
Instant
.
now
().
toEpochMilli
());
final
YearMonth
lastmonth
=
YearMonth
.
now
();
int
monthValue
=
lastmonth
.
getMonthValue
();
int
year
=
lastmonth
.
getYear
();
bill
.
setYear
(
year
);
bill
.
setMonth
(
monthValue
);
bill
.
setBalanced
(
userBalance
.
getBalanced
());
return
bill
;
}
@NotNull
private
Account
buildAccount
(
User
user
)
{
Account
account
=
new
Account
();
account
.
setName
(
user
.
getUsername
());
account
.
setLastSeen
(
new
Date
());
account
.
setEmail
(
user
.
getEmail
());
account
.
setPhoneNumber
(
user
.
getUsername
());
account
.
setPermission
(
15
);
if
(
user
.
getPromotionCode
()
!=
null
)
{
account
.
setPromotionCode
(
user
.
getPromotionCode
());
}
Account
pExisting
=
null
;
String
random
=
null
;
do
{
random
=
String
.
valueOf
((
int
)
((
Math
.
random
()
*
9
+
1
)
*
100000
));
pExisting
=
accountRepository
.
findByPromotion
(
random
);
}
while
(
pExisting
!=
null
);
Promotion
promotion
=
new
Promotion
();
promotion
.
setCode
(
random
);
promotion
.
setInvitedUsers
(
0
);
promotion
.
setCommission
(
0
);
account
.
setPromotion
(
promotion
);
account
.
setAllowedToCreateSubUser
(
true
);
List
<
String
>
whiteList
=
new
ArrayList
<>();
if
(
user
.
getWhiteList
()
!=
null
&&
user
.
getWhiteList
().
size
()
>
0
)
{
whiteList
.
addAll
(
user
.
getWhiteList
());
}
account
.
setWhiteList
(
whiteList
);
return
account
;
}
}
src/main/java/com/edgec/browserbackend/auth/service/Impl/UserServiceImpl.java
View file @
2a52374d
...
...
@@ -15,8 +15,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
;
import
org.springframework.stereotype.Service
;
import
java.util.Optional
;
@Service
public
class
UserServiceImpl
implements
UserService
{
...
...
@@ -96,11 +94,11 @@ public class UserServiceImpl implements UserService {
@Override
public
void
create
(
User
user
)
{
Optional
<
User
>
existing
=
repository
.
findById
(
user
.
getUsername
());
existing
.
ifPresent
(
it
->
{
repository
.
findById
(
user
.
getUsername
()).
ifPresent
(
it
->
{
throw
new
ClientRequestException
(
AuthErrorCode
.
NAMEEXIST
,
"user already exists: "
+
it
.
getUsername
());
});
}
);
String
hash
=
encoder
.
encode
(
user
.
getPassword
());
user
.
setPassword
(
hash
);
...
...
src/main/java/com/edgec/browserbackend/browser/controller/ShopController.java
View file @
2a52374d
...
...
@@ -216,6 +216,9 @@ public class ShopController {
return
resultDto
;
}
/**
* 恢复部分缺失数据,仅仅调用一次就好了
*/
@GetMapping
(
value
=
"/deal_dirtydata"
)
public
ResultDto
dealDirtydata
()
{
...
...
src/main/java/com/edgec/browserbackend/browser/dto/IpResourceRequestDto.java
View file @
2a52374d
...
...
@@ -10,27 +10,58 @@ import java.util.List;
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
IpResourceRequestDto
{
private
String
name
;
/**
* ip 所在地域(英文)
*/
private
String
region
;
/**
* ip 所在地域(中文)
*/
private
String
regionCn
;
/**
* ip 厂商
*/
private
String
vendor
=
"aliyun"
;
private
String
logintype
=
"password"
;
private
String
shopId
;
//0 -- 余额, 1 -- 支付宝, 2 -- 微信
/**
* 0:余额, 1:支付宝, 2:微信
*/
private
int
payMethod
=
0
;
@Max
(
12
)
@Min
(
1
)
private
int
period
=
1
;
/**
* 例如 period :2,unit = month
* 代表:购买 ip 2 个 月
*/
private
String
unit
=
"month"
;
/**
* 购买的ip数量(用户可以一次购买多个ip)
*/
private
int
amount
=
1
;
private
boolean
autorenew
=
false
;
private
int
ipkeptperiod
=
7
;
private
String
startscript
=
""
;
/**
* ip 是否需要使用专线
*/
private
boolean
specialLine
;
//自有IP需要传proxy的账号
/**
* 自有IP需要传proxy的账号
*/
private
String
username
;
private
String
password
;
private
String
instanceSpecKey
;
...
...
src/main/java/com/edgec/browserbackend/browser/repository/IpResourceRepositoryCustomImpl.java
View file @
2a52374d
...
...
@@ -35,10 +35,7 @@ public class IpResourceRepositoryCustomImpl implements IpResourceRepositoryCusto
update
.
set
(
"isLocked"
,
true
).
set
(
"lockTimestamp"
,
Instant
.
now
().
toEpochMilli
());
UpdateResult
result
=
mongoTemplate
.
updateFirst
(
basicQuery
,
update
,
IpResource
.
class
);
if
(
result
.
getModifiedCount
()
<
1
)
return
false
;
else
return
true
;
return
result
.
getModifiedCount
()
>=
1
;
}
@Override
...
...
src/main/java/com/edgec/browserbackend/browser/service/Impl/IpResourceServiceImpl.java
View file @
2a52374d
...
...
@@ -272,7 +272,7 @@ public class IpResourceServiceImpl implements IpResourceService {
}
ipResource
.
setRegion
(
ipResourceRequestDto
.
getRegion
());
// 只要 申请的 ip 地域不是在 大陆,则一定会执行下面 if 中的代码块
boolean
condition1
=
StringUtils
.
isNotBlank
(
ipResource
.
getRegion
())
&&
region
.
contains
(
ipResource
.
getRegion
());
boolean
condition2
=
ipResourceRequestDto
.
getVendor
().
equals
(
"own"
)
&&
ipResource
.
isSpecialLine
();
if
(
condition1
||
condition2
)
{
...
...
@@ -306,7 +306,7 @@ public class IpResourceServiceImpl implements IpResourceService {
accountService
.
chargeByMoney
(
username
,
newprice
*
ipChargeRequestDto
.
getAmount
()
*
ipChargeRequestDto
.
getPeriod
(),
ipChargeRequestDto
);
}
// 如果ip需要绑定店铺,则将店铺与ip绑定
// 如果ip需要绑定店铺,则将店铺与ip绑定
todo 感觉这个地方代码用不到,
if
(
ipResourceRequestDto
.
getShopId
()
!=
null
)
{
ShopRequestDto
shopRequestDto
=
new
ShopRequestDto
();
shopRequestDto
.
setIpId
(
ipResourceDtos
.
get
(
0
).
getId
());
...
...
src/main/java/com/edgec/browserbackend/browser/task/BrowserTask.java
View file @
2a52374d
...
...
@@ -101,12 +101,15 @@ public class BrowserTask {
}
/**
* 购买ip的定时任务,每分钟一次
*/
@Scheduled
(
cron
=
"0 0/1 * * * ?"
)
public
void
buyIpTasks
()
{
String
URL
=
(
profiles
.
equals
(
"dev"
)
||
profiles
.
equals
(
"staging"
))
?
TESTURL
:
CLOUDAMURL
;
long
time
=
Instant
.
now
().
minusSeconds
(
300
).
toEpochMilli
();
List
<
IpResource
>
ipResources
=
ipResourceRepository
.
sampleTasks
(
6
,
time
);
log
.
error
(
"buyIpTasks sample {} tasks"
,
ipResources
.
size
());
log
.
info
(
"buyIpTasks sample {} tasks"
,
ipResources
.
size
());
List
<
CompletableFuture
>
futureList
=
new
ArrayList
<>();
for
(
IpResource
ipResource
:
ipResources
)
{
long
start
=
System
.
currentTimeMillis
();
...
...
@@ -139,8 +142,8 @@ public class BrowserTask {
}
if
(
ipBuyResultDto
!=
null
&&
ipBuyResultDto
.
getIplist
()
!=
null
&&
ipBuyResultDto
.
getIplist
().
size
()
>=
1
)
{
AtomicInteger
index
=
new
AtomicInteger
();
ipBuyResultDto
.
getIplist
().
forEach
(
x
->
{
if
(
ipResource
!=
null
)
{
ipBuyResultDto
.
getIplist
().
forEach
(
x
->
{
ipResource
.
setAddr
(
x
.
getIp
());
ipResource
.
setStatus
(
3
);
ipResource
.
setValidTime
(
Instant
.
parse
(
x
.
getValidTill
()).
toEpochMilli
());
...
...
@@ -150,11 +153,10 @@ public class BrowserTask {
ipResource
.
setSpecialLine
(
true
);
}
ipResourceRepository
.
save
(
ipResource
);
}
else
{
log
.
error
(
"no ipResource"
);
}
index
.
getAndIncrement
();
});
}
);
result
=
true
;
}
}
catch
(
Exception
e
)
{
...
...
src/main/java/com/edgec/browserbackend/browser/task/PromotionTask.java
View file @
2a52374d
...
...
@@ -12,9 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
java.time.Instant
;
import
java.time.YearMonth
;
import
java.time.ZoneOffset
;
import
java.util.Arrays
;
import
java.util.List
;
...
...
@@ -32,32 +30,43 @@ public class PromotionTask {
@SchedulerLock
(
name
=
"countGift"
,
lockAtLeastForString
=
"PT1H"
,
lockAtMostForString
=
"PT2H"
)
@Scheduled
(
cron
=
"0 0 1 1 * ?"
)
public
void
countGift
()
{
log
.
info
(
"Start scheduled task:Scheduled.countGift..."
);
List
<
Account
>
accounts
=
accountRepository
.
findByParentIsNull
();
for
(
Account
account
:
accounts
)
{
// 1. 获取当前账户的邀请码信息
String
code
=
account
.
getPromotion
().
getCode
();
// 2. 获取被当前账户邀请的所有账户
List
<
Account
>
promotes
=
accountRepository
.
findByPromotionCodeAndParentIsNull
(
code
);
double
totalCommission
=
0
;
double
secondCommission
=
0
;
// 3. 计算所有被当前账户邀请的账户上个月的消费信息,以及如果当前账户是销售账户则还需要计算销售账户的下下级账户的上个月消费信息
for
(
Account
promote
:
promotes
)
{
List
<
UserPrePaidBilling
>
userPrePaidBillings
=
userPrePaidBillingRepository
.
findByAdministratorAndYearAndMonthAndPayMethodIn
(
promote
.
getName
(),
YearMonth
.
now
().
minusMonths
(
1
).
getYear
(),
YearMonth
.
now
().
minusMonths
(
1
).
getMonthValue
(),
Arrays
.
asList
(
1
,
2
,
3
));
// 3.1 获取被邀请的用户上个月的消费信息,todo 感觉这个地方最好加上支付状态
List
<
UserPrePaidBilling
>
userPrePaidBillings
=
userPrePaidBillingRepository
.
findByAdministratorAndYearAndMonthAndPayMethodIn
(
promote
.
getName
(),
YearMonth
.
now
().
minusMonths
(
1
).
getYear
(),
YearMonth
.
now
().
minusMonths
(
1
).
getMonthValue
(),
Arrays
.
asList
(
1
,
2
,
3
)
);
// 3.2. 计算被邀请的用户上个月的总消费金额
totalCommission
+=
userPrePaidBillings
.
stream
().
mapToDouble
(
UserPrePaidBilling:
:
getTotal
).
sum
();
// 3.3. 如果当前账户是本公司销售,则计算下下级用户(例如:销售人员A 邀请了 用户B,用户B 邀请了 其他用户,其他用户就是A的下下级用户)上个月总消费金额
if
(
account
.
getPromotion
().
isSale
()
&&
promote
.
getParent
()
==
null
)
{
// 获取下下级账户
List
<
Account
>
secondPromotes
=
accountRepository
.
findByPromotionCodeAndParentIsNull
(
promote
.
getPromotion
().
getCode
());
if
(
secondPromotes
!=
null
&&
secondPromotes
.
size
()
>
0
)
{
if
(
secondPromotes
!=
null
&&
!
secondPromotes
.
isEmpty
()
)
{
for
(
Account
secondPromote
:
secondPromotes
)
{
List
<
UserPrePaidBilling
>
userPrePaidBillings1
=
userPrePaidBillingRepository
.
findByAdministratorAndYearAndMonthAndPayMethodIn
(
secondPromote
.
getName
(),
YearMonth
.
now
().
minusMonths
(
1
).
getYear
(),
YearMonth
.
now
().
minusMonths
(
1
).
getMonthValue
(),
Arrays
.
asList
(
1
,
2
,
3
)
);
List
<
UserPrePaidBilling
>
userPrePaidBillings1
=
userPrePaidBillingRepository
.
findByAdministratorAndYearAndMonthAndPayMethodIn
(
secondPromote
.
getName
(),
YearMonth
.
now
().
minusMonths
(
1
).
getYear
(),
YearMonth
.
now
().
minusMonths
(
1
).
getMonthValue
(),
Arrays
.
asList
(
1
,
2
,
3
)
);
secondCommission
+=
userPrePaidBillings1
.
stream
().
mapToDouble
(
UserPrePaidBilling:
:
getTotal
).
sum
();
}
}
}
}
// 4. 封装当前账户的返佣相关信息(总消费、上月消费、当月礼金、总共未体现礼金)并保存
Promotion
promotion
=
account
.
getPromotion
();
promotion
.
setTotalCommission
((
int
)(
promotion
.
getTotalCommission
()
+
totalCommission
));
promotion
.
setCommissionLastMonth
((
int
)
totalCommission
);
promotion
.
setTotalCommission
((
int
)
(
promotion
.
getTotalCommission
()
+
totalCommission
));
promotion
.
setCommissionLastMonth
((
int
)
totalCommission
);
promotion
.
setGift
(
totalCommission
*
0.08
);
if
(
account
.
getPromotion
().
isSale
())
{
promotion
.
setGift
(
totalCommission
*
0.1
+
secondCommission
*
0.02
);
...
...
@@ -65,41 +74,50 @@ public class PromotionTask {
promotion
.
setAllGift
(
promotion
.
getAllGift
()
+
promotion
.
getGift
());
accountRepository
.
save
(
account
);
}
log
.
info
(
"End scheduled task:Scheduled.countGift..."
);
}
@SchedulerLock
(
name
=
"countCommission"
,
lockAtLeastForString
=
"PT1H"
,
lockAtMostForString
=
"PT2H"
)
@Scheduled
(
cron
=
"0 0 1 * * ?"
)
public
void
countCommission
()
{
log
.
info
(
"Start scheduled task:Scheduled.countCommission..."
);
List
<
Account
>
accounts
=
accountRepository
.
findByParentIsNull
();
for
(
Account
account
:
accounts
)
{
// 1. 获取被当前账户邀请的所有账户
String
code
=
account
.
getPromotion
().
getCode
();
List
<
Account
>
promotes
=
accountRepository
.
findByPromotionCodeAndParentIsNull
(
code
);
double
totalCommission
=
0
;
double
secondCommission
=
0
;
// 2. 计算所有被当前账户邀请的账户当月当前的消费信息,以及如果当前账户是销售账户则还需要计算销售账户的下下级账户的当月当前消费信息
for
(
Account
promote
:
promotes
)
{
List
<
UserPrePaidBilling
>
userPrePaidBillings
=
userPrePaidBillingRepository
.
findByAdministratorAndYearAndMonthAndPayMethodIn
(
promote
.
getName
(),
YearMonth
.
now
().
getYear
(),
YearMonth
.
now
().
getMonthValue
(),
Arrays
.
asList
(
1
,
2
,
3
)
);
List
<
UserPrePaidBilling
>
userPrePaidBillings
=
userPrePaidBillingRepository
.
findByAdministratorAndYearAndMonthAndPayMethodIn
(
promote
.
getName
(),
YearMonth
.
now
().
getYear
(),
YearMonth
.
now
().
getMonthValue
(),
Arrays
.
asList
(
1
,
2
,
3
)
);
totalCommission
+=
userPrePaidBillings
.
stream
().
mapToDouble
(
UserPrePaidBilling:
:
getTotal
).
sum
();
if
(
account
.
getPromotion
().
isSale
()
&&
promote
.
getParent
()
==
null
)
{
List
<
Account
>
secondPromotes
=
accountRepository
.
findByPromotionCodeAndParentIsNull
(
promote
.
getPromotion
().
getCode
());
if
(
secondPromotes
!=
null
&&
secondPromotes
.
size
()
>
0
)
{
for
(
Account
secondPromote
:
secondPromotes
)
{
List
<
UserPrePaidBilling
>
userPrePaidBillings1
=
userPrePaidBillingRepository
.
findByAdministratorAndYearAndMonthAndPayMethodIn
(
secondPromote
.
getName
(),
YearMonth
.
now
().
getYear
(),
YearMonth
.
now
().
getMonthValue
(),
Arrays
.
asList
(
1
,
2
,
3
)
);
List
<
UserPrePaidBilling
>
userPrePaidBillings1
=
userPrePaidBillingRepository
.
findByAdministratorAndYearAndMonthAndPayMethodIn
(
secondPromote
.
getName
(),
YearMonth
.
now
().
getYear
(),
YearMonth
.
now
().
getMonthValue
(),
Arrays
.
asList
(
1
,
2
,
3
)
);
secondCommission
+=
userPrePaidBillings1
.
stream
().
mapToDouble
(
UserPrePaidBilling:
:
getTotal
).
sum
();
}
}
}
}
// 3. 封装当前账户的返佣相关信息(当月当前的消费、当月当前的返佣)并保存
Promotion
promotion
=
account
.
getPromotion
();
promotion
.
setCommission
((
int
)
totalCommission
);
promotion
.
setCommission
((
int
)
totalCommission
);
promotion
.
setGift
(
totalCommission
*
0.08
);
if
(
account
.
getPromotion
().
isSale
())
{
promotion
.
setGift
(
totalCommission
*
0.1
+
secondCommission
*
0.02
);
}
accountRepository
.
save
(
account
);
}
log
.
info
(
"End scheduled task:Scheduled.countCommission..."
);
}
}
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