Commit 6e6dddcb authored by licc's avatar licc

优化月度最大进步奖

parent ba26390e
...@@ -126,7 +126,8 @@ public class AccountManager { ...@@ -126,7 +126,8 @@ public class AccountManager {
* @param prizes 上一次统计的进步奖 对象 * @param prizes 上一次统计的进步奖 对象
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Boolean 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);
...@@ -251,6 +252,48 @@ public class AccountManager { ...@@ -251,6 +252,48 @@ public class AccountManager {
return true; return true;
} }
/**
* 更新账户信息和保存交易流水记录保存最大进步奖信息
*
* @param accountInfoList 账户列表
* @param recordList 交易流水信息
*/
@Transactional(rollbackFor = Exception.class)
public Boolean updateAccountAddRecordAddPrize(List<AccountInfo> accountInfoList, List<TradeRecord> recordList,
List<ProgressPrize> prizeList) {
//更新月收益
if (!CollectionUtils.isEmpty(accountInfoList)) {
for (AccountInfo accountInfo : accountInfoList) {
int count = accountMapper.edit(accountInfo);
if (count == 0) {
return false;
}
}
}
//新增交易流水记录
if (!CollectionUtils.isEmpty(recordList)) {
for (TradeRecord tradeRecord : recordList) {
int count = tradeRecordMapper.add(tradeRecord);
if (count == 0) {
return false;
}
}
}
//新增最大进步奖信息
if (!CollectionUtils.isEmpty(prizeList)) {
for (ProgressPrize progressPrize : prizeList) {
int count = progressPrizeMapper.add(progressPrize);
if (count == 0) {
return false;
}
}
}
return true;
}
/** /**
* 更新账户信息和保存交易流水记录、保存上月剩余月度肥料奖金 * 更新账户信息和保存交易流水记录、保存上月剩余月度肥料奖金
* *
......
...@@ -20,8 +20,8 @@ import org.springframework.stereotype.Service; ...@@ -20,8 +20,8 @@ import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
/** /**
...@@ -268,6 +268,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo> ...@@ -268,6 +268,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
Double twentyTotal = teamPerformanceMapper.countTwenty(yearMonth); Double twentyTotal = teamPerformanceMapper.countTwenty(yearMonth);
List<AccountInfo> accountInfoList = new ArrayList<>(); List<AccountInfo> accountInfoList = new ArrayList<>();
List<TradeRecord> tradeRecordList = new ArrayList<>(); List<TradeRecord> tradeRecordList = new ArrayList<>();
List<ProgressPrize> prizeList=new ArrayList<>();
for (TeamPerformance user : list) { for (TeamPerformance user : list) {
//用户是普通用户的,不计算最大进步奖 //用户是普通用户的,不计算最大进步奖
if (user.getUserLevel().equals(UserLevelEnum.NORMAL_USER.getCode())) { if (user.getUserLevel().equals(UserLevelEnum.NORMAL_USER.getCode())) {
...@@ -295,6 +296,15 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo> ...@@ -295,6 +296,15 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
accountInfo.setEarningsTotal(earningsTotal); accountInfo.setEarningsTotal(earningsTotal);
accountInfoList.add(accountInfo); accountInfoList.add(accountInfo);
//添加最大进步奖信息
ProgressPrize prize = new ProgressPrize();
BigDecimal awardMoney = new BigDecimal(income).setScale(2, RoundingMode.HALF_UP);
prize.setAwardMoney(awardMoney.doubleValue());
prize.setUserId(user.getUserId());
prize.setGrowthRate(0.0);
prize.setYearMonth(yearMonth);
prizeList.add(prize);
//添加交易流水记录 //添加交易流水记录
TradeRecord tradeRecord = new TradeRecord(); TradeRecord tradeRecord = new TradeRecord();
tradeRecord.setUserId(user.getUserId()); tradeRecord.setUserId(user.getUserId());
...@@ -306,7 +316,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo> ...@@ -306,7 +316,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
} }
//更新账户信息,添加交易流水记录 //更新账户信息,添加交易流水记录
boolean bool = accountManager.updateAccountAddRecord(accountInfoList, tradeRecordList); boolean bool = accountManager.updateAccountAddRecordAddPrize(accountInfoList, tradeRecordList,prizeList);
if (!bool) { if (!bool) {
return R.ok(1, false); return R.ok(1, false);
} }
......
...@@ -219,6 +219,7 @@ public class MonthTaskServiceImpl implements MonthTaskService { ...@@ -219,6 +219,7 @@ public class MonthTaskServiceImpl implements MonthTaskService {
Double twentyTotal = teamPerformanceMapper.countTwenty(lastMonth); Double twentyTotal = teamPerformanceMapper.countTwenty(lastMonth);
List<AccountInfo> accountInfoList = new ArrayList<>(); List<AccountInfo> accountInfoList = new ArrayList<>();
List<TradeRecord> tradeRecordList = new ArrayList<>(); List<TradeRecord> tradeRecordList = new ArrayList<>();
List<ProgressPrize> prizeList = new ArrayList<>();
for (TeamPerformance user : list) { for (TeamPerformance user : list) {
//用户是普通用户的,不计算最大进步奖 //用户是普通用户的,不计算最大进步奖
if (user.getUserLevel().equals(UserLevelEnum.NORMAL_USER.getCode())) { if (user.getUserLevel().equals(UserLevelEnum.NORMAL_USER.getCode())) {
...@@ -231,7 +232,6 @@ public class MonthTaskServiceImpl implements MonthTaskService { ...@@ -231,7 +232,6 @@ public class MonthTaskServiceImpl implements MonthTaskService {
//计算收益 //计算收益
double userTeamPerformance = user.getMonthTeamPerformance().doubleValue(); double userTeamPerformance = user.getMonthTeamPerformance().doubleValue();
double percent = memberPercent.getPercent().doubleValue(); double percent = memberPercent.getPercent().doubleValue();
double income = Math.floor(number * 3980 * percent * userTeamPerformance / twentyTotal); double income = Math.floor(number * 3980 * percent * userTeamPerformance / twentyTotal);
//获取账户信息 //获取账户信息
...@@ -239,25 +239,34 @@ public class MonthTaskServiceImpl implements MonthTaskService { ...@@ -239,25 +239,34 @@ public class MonthTaskServiceImpl implements MonthTaskService {
//用户月收益 =其他收益+最大进步奖收益 //用户月收益 =其他收益+最大进步奖收益
BigDecimal earningsMonth = accountInfo.getEarningsMonth().add(BigDecimal.valueOf(income)); BigDecimal earningsMonth = accountInfo.getEarningsMonth().add(BigDecimal.valueOf(income));
accountInfo.setEarningsMonth(earningsMonth); accountInfo.setEarningsMonth(earningsMonth.setScale(2, RoundingMode.HALF_UP));
//用户总收益 =其他总收益 + earningsMonth //用户总收益 =其他总收益 + earningsMonth
BigDecimal earningsTotal = accountInfo.getEarningsTotal().add(BigDecimal.valueOf(income)); BigDecimal earningsTotal = accountInfo.getEarningsTotal().add(BigDecimal.valueOf(income));
accountInfo.setEarningsTotal(earningsTotal); accountInfo.setEarningsTotal(earningsTotal.setScale(2, RoundingMode.HALF_UP));
accountInfoList.add(accountInfo); accountInfoList.add(accountInfo);
//添加最大进步奖信息
ProgressPrize prize = new ProgressPrize();
BigDecimal awardMoney = new BigDecimal(income).setScale(2, RoundingMode.HALF_UP);
prize.setAwardMoney(awardMoney.doubleValue());
prize.setUserId(user.getUserId());
prize.setGrowthRate(0.0);
prize.setYearMonth(lastMonth);
prizeList.add(prize);
//添加交易流水记录 //添加交易流水记录
TradeRecord tradeRecord = new TradeRecord(); TradeRecord tradeRecord = new TradeRecord();
tradeRecord.setUserId(user.getUserId()); tradeRecord.setUserId(user.getUserId());
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());
tradeRecord.setMoney(BigDecimal.valueOf(income)); tradeRecord.setMoney(BigDecimal.valueOf(income).setScale(2, RoundingMode.HALF_UP));
tradeRecordList.add(tradeRecord); tradeRecordList.add(tradeRecord);
} }
//更新账户信息,添加交易流水记录 //更新账户信息,添加交易流水记录
boolean bool = accountManager.updateAccountAddRecord(accountInfoList, tradeRecordList); boolean bool = accountManager.updateAccountAddRecordAddPrize(accountInfoList, tradeRecordList,prizeList);
if (!bool) { if (!bool) {
return R.ok(1, false); return R.ok(1, false);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment