Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
S
shop-Mall
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
licc
shop-Mall
Commits
582ff44c
Commit
582ff44c
authored
Mar 08, 2021
by
licc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
月度任务接口优化
parent
e9904ab8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
119 additions
and
68 deletions
+119
-68
AccountManager.java
...ain/java/cn/wisenergy/service/Manager/AccountManager.java
+59
-14
AccountServiceImpl.java
...ava/cn/wisenergy/service/app/impl/AccountServiceImpl.java
+60
-54
No files found.
wisenergy-service/src/main/java/cn/wisenergy/service/Manager/AccountManager.java
View file @
582ff44c
...
@@ -8,17 +8,13 @@ import cn.wisenergy.model.enums.TradeRecordEnum;
...
@@ -8,17 +8,13 @@ import cn.wisenergy.model.enums.TradeRecordEnum;
import
cn.wisenergy.model.enums.TradeStatusEnum
;
import
cn.wisenergy.model.enums.TradeStatusEnum
;
import
cn.wisenergy.model.vo.TeamPerformanceSortVo
;
import
cn.wisenergy.model.vo.TeamPerformanceSortVo
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections.map.HashedMap
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.CollectionUtils
;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
java.util.ArrayList
;
import
java.util.*
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
/**
/**
...
@@ -46,6 +42,9 @@ public class AccountManager {
...
@@ -46,6 +42,9 @@ public class AccountManager {
@Autowired
@Autowired
private
ProgressPrizeMapper
progressPrizeMapper
;
private
ProgressPrizeMapper
progressPrizeMapper
;
@Autowired
private
TradeRecordMapper
tradeRecordMapper
;
private
static
final
String
PATTERN
=
"yyyy-MM"
;
private
static
final
String
PATTERN
=
"yyyy-MM"
;
...
@@ -102,12 +101,12 @@ public class AccountManager {
...
@@ -102,12 +101,12 @@ public class AccountManager {
* @param prizes 上一次统计的进步奖 对象
* @param prizes 上一次统计的进步奖 对象
*/
*/
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
updateOrSavePrize
(
List
<
TeamPerformanceSortVo
>
listVo
,
List
<
AccountInfo
>
accountInfoList
,
List
<
ProgressPrize
>
prizes
)
{
public
Boolean
updateOrSavePrize
(
List
<
TeamPerformanceSortVo
>
listVo
,
List
<
AccountInfo
>
accountInfoList
,
List
<
ProgressPrize
>
prizes
)
{
Date
date
=
new
Date
();
Date
date
=
new
Date
();
String
yearMonth
=
DateUtil
.
convertDateToStr
(
date
,
PATTERN
);
String
yearMonth
=
DateUtil
.
convertDateToStr
(
date
,
PATTERN
);
//构造一个map key:userId value progressPrize
//构造一个map key:userId value progressPrize
Map
<
String
,
ProgressPrize
>
map
=
new
Hash
edMap
(
32
);
Map
<
String
,
ProgressPrize
>
map
=
new
Hash
Map
<>
(
32
);
for
(
ProgressPrize
progressPrize
:
prizes
)
{
for
(
ProgressPrize
progressPrize
:
prizes
)
{
map
.
put
(
progressPrize
.
getUserId
(),
progressPrize
);
map
.
put
(
progressPrize
.
getUserId
(),
progressPrize
);
}
}
...
@@ -122,13 +121,15 @@ public class AccountManager {
...
@@ -122,13 +121,15 @@ public class AccountManager {
progressPrize
.
setGrowthRate
(
sortVo
.
getGrowthRate
());
progressPrize
.
setGrowthRate
(
sortVo
.
getGrowthRate
());
progressPrize
.
setAwardMoney
(
sortVo
.
getMonthPerformance
());
progressPrize
.
setAwardMoney
(
sortVo
.
getMonthPerformance
());
progressPrize
.
setYearMonth
(
yearMonth
);
progressPrize
.
setYearMonth
(
yearMonth
);
progressPrizeMapper
.
add
(
progressPrize
);
int
count
=
progressPrizeMapper
.
add
(
progressPrize
);
if
(
count
==
0
)
{
return
false
;
}
}
}
}
else
{
}
else
{
//2、不为空。存在的修改,不存在的新增,多余的,删除
//2、不为空。存在的修改,不存在的新增,多余的,删除
List
<
ProgressPrize
>
updateList
=
new
ArrayList
<>();
List
<
ProgressPrize
>
updateList
=
new
ArrayList
<>();
List
<
ProgressPrize
>
addList
=
new
ArrayList
<>();
List
<
ProgressPrize
>
addList
=
new
ArrayList
<>();
List
<
ProgressPrize
>
deleteList
=
new
ArrayList
<>();
List
<
String
>
userIds
=
prizes
.
stream
().
map
(
ProgressPrize:
:
getUserId
).
collect
(
Collectors
.
toList
());
List
<
String
>
userIds
=
prizes
.
stream
().
map
(
ProgressPrize:
:
getUserId
).
collect
(
Collectors
.
toList
());
//遍历 筛选出要修改、新增、删除 对象
//遍历 筛选出要修改、新增、删除 对象
...
@@ -152,18 +153,27 @@ public class AccountManager {
...
@@ -152,18 +153,27 @@ public class AccountManager {
addList
.
add
(
progress
);
addList
.
add
(
progress
);
}
}
}
}
deleteList
.
addAll
(
prizes
);
List
<
ProgressPrize
>
deleteList
=
new
ArrayList
<>
(
prizes
);
for
(
ProgressPrize
updatePrize
:
updateList
)
{
for
(
ProgressPrize
updatePrize
:
updateList
)
{
progressPrizeMapper
.
edit
(
updatePrize
);
int
count
=
progressPrizeMapper
.
edit
(
updatePrize
);
if
(
count
==
0
)
{
return
false
;
}
}
}
for
(
ProgressPrize
addPrize
:
addList
)
{
for
(
ProgressPrize
addPrize
:
addList
)
{
progressPrizeMapper
.
add
(
addPrize
);
int
count
=
progressPrizeMapper
.
add
(
addPrize
);
if
(
count
==
0
)
{
return
false
;
}
}
}
for
(
ProgressPrize
deletePrize
:
deleteList
)
{
for
(
ProgressPrize
deletePrize
:
deleteList
)
{
progressPrizeMapper
.
delById
(
deletePrize
.
getId
());
int
count
=
progressPrizeMapper
.
delById
(
deletePrize
.
getId
());
if
(
count
==
0
)
{
return
false
;
}
}
}
}
}
...
@@ -177,7 +187,42 @@ public class AccountManager {
...
@@ -177,7 +187,42 @@ public class AccountManager {
tradeRecord
.
setTradeType
(
TradeRecordEnum
.
PROGRESS_PRIZE
.
getCode
());
tradeRecord
.
setTradeType
(
TradeRecordEnum
.
PROGRESS_PRIZE
.
getCode
());
tradeRecord
.
setTradeNo
(
null
);
tradeRecord
.
setTradeNo
(
null
);
tradeRecord
.
setStatus
(
TradeStatusEnum
.
ALREADY_SETTLE_ACCOUNTS
.
getCode
());
tradeRecord
.
setStatus
(
TradeStatusEnum
.
ALREADY_SETTLE_ACCOUNTS
.
getCode
());
recordMapper
.
add
(
tradeRecord
);
int
count
=
recordMapper
.
add
(
tradeRecord
);
if
(
count
==
0
)
{
return
false
;
}
}
return
true
;
}
/**
* 更新账户信息和保存交易流水记录
*
* @param accountInfoList 账户列表
* @param recordList 交易流水信息
*/
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
Boolean
updateAccountAddRecord
(
List
<
AccountInfo
>
accountInfoList
,
List
<
TradeRecord
>
recordList
)
{
//更新月收益
if
(!
CollectionUtils
.
isEmpty
(
accountInfoList
))
{
for
(
AccountInfo
accountInfo
:
accountInfoList
)
{
int
count
=
accountMapper
.
updateById
(
accountInfo
);
if
(
count
==
0
)
{
return
false
;
}
}
}
//新增交易流水记录
if
(!
CollectionUtils
.
isEmpty
(
recordList
))
{
for
(
TradeRecord
tradeRecord
:
recordList
)
{
int
count
=
tradeRecordMapper
.
add
(
tradeRecord
);
if
(
count
==
0
)
{
return
false
;
}
}
}
}
return
true
;
}
}
}
}
wisenergy-service/src/main/java/cn/wisenergy/service/app/impl/AccountServiceImpl.java
View file @
582ff44c
...
@@ -57,6 +57,8 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
...
@@ -57,6 +57,8 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
private
static
final
String
PATTERN
=
"yyyy-MM"
;
private
static
final
String
PATTERN
=
"yyyy-MM"
;
private
static
final
Integer
TWENTY
=
20
;
@Override
@Override
public
R
<
Boolean
>
orderRebate
(
List
<
OrderInfo
>
list
)
{
public
R
<
Boolean
>
orderRebate
(
List
<
OrderInfo
>
list
)
{
log
.
info
(
"shop-mall[]AccountServiceImpl[]orderRebate[]input.param.list:{}"
,
list
.
size
());
log
.
info
(
"shop-mall[]AccountServiceImpl[]orderRebate[]input.param.list:{}"
,
list
.
size
());
...
@@ -171,8 +173,10 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
...
@@ -171,8 +173,10 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
if
(
CollectionUtils
.
isEmpty
(
userList
))
{
if
(
CollectionUtils
.
isEmpty
(
userList
))
{
return
R
.
ok
(
0
,
true
);
return
R
.
ok
(
0
,
true
);
}
}
for
(
User
user
:
userList
)
{
monthlyIncome
(
totalMoney
,
user
);
boolean
bool
=
monthlyIncome
(
totalMoney
,
userList
);
if
(!
bool
)
{
return
R
.
ok
(
1
,
false
);
}
}
return
R
.
ok
(
0
,
true
);
return
R
.
ok
(
0
,
true
);
...
@@ -216,6 +220,8 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
...
@@ -216,6 +220,8 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
//获取20名进步最大的月业绩和
//获取20名进步最大的月业绩和
Double
twentyTotal
=
teamPerformanceMapper
.
countTwenty
(
yearMonth
);
Double
twentyTotal
=
teamPerformanceMapper
.
countTwenty
(
yearMonth
);
List
<
AccountInfo
>
accountInfoList
=
new
ArrayList
<>();
List
<
TradeRecord
>
tradeRecordList
=
new
ArrayList
<>();
for
(
TeamPerformance
user
:
list
)
{
for
(
TeamPerformance
user
:
list
)
{
//获取最大进步奖 百分比
//获取最大进步奖 百分比
MemberPercent
memberPercent
=
memberPercentMapper
.
getByLevelAndType
(
user
.
getUserLevel
(),
3
);
MemberPercent
memberPercent
=
memberPercentMapper
.
getByLevelAndType
(
user
.
getUserLevel
(),
3
);
...
@@ -229,9 +235,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
...
@@ -229,9 +235,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
//获取账户信息
//获取账户信息
AccountInfo
accountInfo
=
accountMapper
.
getByUserId
(
user
.
getUserId
());
AccountInfo
accountInfo
=
accountMapper
.
getByUserId
(
user
.
getUserId
());
accountInfo
.
setEarningsMonth
(
new
BigDecimal
(
income
));
accountInfo
.
setEarningsMonth
(
new
BigDecimal
(
income
));
accountInfoList
.
add
(
accountInfo
);
//更新用户账户表
accountMapper
.
updateById
(
accountInfo
);
//添加交易流水记录
//添加交易流水记录
TradeRecord
tradeRecord
=
new
TradeRecord
();
TradeRecord
tradeRecord
=
new
TradeRecord
();
...
@@ -239,7 +243,13 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
...
@@ -239,7 +243,13 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
tradeRecord
.
setTradeType
(
TradeRecordEnum
.
PROGRESS_PRIZE
.
getCode
());
tradeRecord
.
setTradeType
(
TradeRecordEnum
.
PROGRESS_PRIZE
.
getCode
());
tradeRecord
.
setTradeNo
(
null
);
tradeRecord
.
setTradeNo
(
null
);
tradeRecord
.
setStatus
(
TradeStatusEnum
.
ALREADY_SETTLE_ACCOUNTS
.
getCode
());
tradeRecord
.
setStatus
(
TradeStatusEnum
.
ALREADY_SETTLE_ACCOUNTS
.
getCode
());
tradeRecordMapper
.
add
(
tradeRecord
);
tradeRecordList
.
add
(
tradeRecord
);
}
//更新账户信息,添加交易流水记录
boolean
bool
=
accountManager
.
updateAccountAddRecord
(
accountInfoList
,
tradeRecordList
);
if
(!
bool
)
{
return
R
.
ok
(
1
,
false
);
}
}
}
}
return
R
.
ok
(
0
,
true
);
return
R
.
ok
(
0
,
true
);
...
@@ -256,9 +266,9 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
...
@@ -256,9 +266,9 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
List
<
TeamPerformanceSortVo
>
listVo
=
progressPrizeStatistics
(
userList
);
List
<
TeamPerformanceSortVo
>
listVo
=
progressPrizeStatistics
(
userList
);
//5、如果集合大于20 ,取前二十名,小于,取全部
//5、如果集合大于20 ,取前二十名,小于,取全部
if
(
listVo
.
size
()
>=
20
)
{
if
(
listVo
.
size
()
>=
TWENTY
)
{
//取排名前20的
//取排名前20的
listVo
.
subList
(
0
,
20
);
listVo
.
subList
(
0
,
TWENTY
);
//计算前20的总业绩
//计算前20的总业绩
double
total
=
listVo
.
stream
().
mapToDouble
(
TeamPerformanceSortVo:
:
getMonthPerformance
).
sum
();
double
total
=
listVo
.
stream
().
mapToDouble
(
TeamPerformanceSortVo:
:
getMonthPerformance
).
sum
();
...
@@ -284,64 +294,59 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
...
@@ -284,64 +294,59 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
/**
/**
* 如果会员等级是黄金以上,计算月度收益
* 如果会员等级是黄金以上,计算月度收益
*
*
* @param totalMoney
* @param totalMoney
月金额总额
* @param user
* @param user
List 用户列表
* @return
* @return
*/
*/
private
boolean
monthlyIncome
(
BigDecimal
totalMoney
,
User
user
)
{
private
boolean
monthlyIncome
(
BigDecimal
totalMoney
,
List
<
User
>
userList
)
{
double
total
=
totalMoney
.
doubleValue
();
double
total
=
totalMoney
.
doubleValue
();
BigDecimal
money
;
Date
date
=
new
Date
();
Date
date
=
new
Date
();
String
yearMonth
=
DateUtil
.
convertDateToStr
(
date
,
PATTERN
);
String
yearMonth
=
DateUtil
.
convertDateToStr
(
date
,
PATTERN
);
//当月所有人订单成交总金额/3980/12 向下整
//当月所有人订单成交总金额/3980/12 向下整
double
moneyMonth
=
Math
.
floor
(
total
/
3980
/
12
);
double
moneyMonth
=
Math
.
floor
(
total
/
3980
/
12
);
List
<
AccountInfo
>
accountInfoList
=
new
ArrayList
<>();
if
(
moneyMonth
!=
0
)
{
List
<
TradeRecord
>
tradeRecordList
=
new
ArrayList
<>();
//获取等级优惠百分比
for
(
User
user
:
userList
)
{
MemberPercent
memberPercent
=
memberPercentMapper
.
getByLevelAndType
(
user
.
getUserLevel
(),
2
);
if
(
moneyMonth
!=
0
)
{
if
(
null
!=
memberPercent
)
{
//获取等级优惠百分比
//获取本月团队总金额
MemberPercent
memberPercent
=
memberPercentMapper
.
getByLevelAndType
(
user
.
getUserLevel
(),
2
);
TeamPerformance
teamPerformance
=
teamPerformanceMapper
.
getByUserIdAndTime
(
user
.
getUserId
(),
yearMonth
);
if
(
null
!=
memberPercent
)
{
//获取本月团队总金额
//获取该等级团队总金额
TeamPerformance
teamPerformance
=
teamPerformanceMapper
.
getByUserIdAndTime
(
user
.
getUserId
(),
yearMonth
);
Double
teamTotal
=
teamPerformanceMapper
.
countTeamMoney
(
user
.
getUserLevel
(),
yearMonth
);
if
(
null
!=
teamPerformance
&&
null
!=
teamTotal
)
{
//获取该等级团队总金额
double
month
=
teamPerformance
.
getMonthTeamPerformance
().
doubleValue
();
Double
teamTotal
=
teamPerformanceMapper
.
countTeamMoney
(
user
.
getUserLevel
(),
yearMonth
);
double
percent
=
memberPercent
.
getPercent
().
doubleValue
();
if
(
null
!=
teamPerformance
&&
null
!=
teamTotal
)
{
//计算收益
double
month
=
teamPerformance
.
getMonthTeamPerformance
().
doubleValue
();
double
income
=
moneyMonth
*
3980
*
percent
*
month
/
teamTotal
;
double
percent
=
memberPercent
.
getPercent
().
doubleValue
();
//计算收益
//获取账户信息
double
income
=
moneyMonth
*
3980
*
percent
*
month
/
teamTotal
;
AccountInfo
accountInfo
=
accountMapper
.
getByUserId
(
user
.
getUserId
());
BigDecimal
bigDecimal
=
new
BigDecimal
(
income
);
//获取账户信息
BigDecimal
performanceMonth
=
accountInfo
.
getEarningsMonth
().
add
(
bigDecimal
);
AccountInfo
accountInfo
=
accountMapper
.
getByUserId
(
user
.
getUserId
());
accountInfo
.
setEarningsMonth
(
performanceMonth
);
BigDecimal
bigDecimal
=
new
BigDecimal
(
income
);
BigDecimal
performanceMonth
=
accountInfo
.
getEarningsMonth
().
add
(
bigDecimal
);
BigDecimal
performanceTotal
=
accountInfo
.
getEarningsMonth
().
add
(
bigDecimal
);
accountInfo
.
setEarningsMonth
(
performanceMonth
);
accountInfo
.
setEarningsMonth
(
performanceTotal
);
BigDecimal
performanceTotal
=
accountInfo
.
getEarningsMonth
().
add
(
bigDecimal
);
//更新月收益
accountInfo
.
setEarningsMonth
(
performanceTotal
);
int
count
=
accountMapper
.
updateById
(
accountInfo
);
accountInfoList
.
add
(
accountInfo
);
if
(
count
!=
0
)
{
return
true
;
}
//5、添加交易流水记录
TradeRecord
tradeRecord
=
new
TradeRecord
();
//5、添加交易流水记录
tradeRecord
.
setUserId
(
user
.
getUserId
());
TradeRecord
tradeRecord
=
new
TradeRecord
();
tradeRecord
.
setTradeType
(
TradeRecordEnum
.
ORDER_REBATE
.
getCode
());
tradeRecord
.
setUserId
(
user
.
getUserId
());
tradeRecord
.
setTradeNo
(
null
);
tradeRecord
.
setTradeType
(
TradeRecordEnum
.
ORDER_REBATE
.
getCode
());
tradeRecord
.
setStatus
(
TradeStatusEnum
.
NO_SETTLE_ACCOUNTS
.
getCode
());
tradeRecord
.
setTradeNo
(
null
);
tradeRecordList
.
add
(
tradeRecord
);
tradeRecord
.
setStatus
(
TradeStatusEnum
.
NO_SETTLE_ACCOUNTS
.
getCode
());
int
number
=
tradeRecordMapper
.
add
(
tradeRecord
);
if
(
number
==
0
)
{
return
false
;
}
}
}
}
}
}
}
}
return
false
;
//更新账户信息,新增交易流水记录
return
accountManager
.
updateAccountAddRecord
(
accountInfoList
,
tradeRecordList
);
}
}
/**
/**
...
@@ -382,6 +387,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
...
@@ -382,6 +387,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
}
}
teamVo
.
setGrowthRate
(
growthRate
);
teamVo
.
setGrowthRate
(
growthRate
);
double
monthPerformance
;
double
monthPerformance
;
assert
teamPerformance
!=
null
;
if
(
null
==
teamPerformance
.
getMonthTeamPerformance
())
{
if
(
null
==
teamPerformance
.
getMonthTeamPerformance
())
{
monthPerformance
=
0.00
;
monthPerformance
=
0.00
;
}
else
{
}
else
{
...
...
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