Commit 05ea4456 authored by licc's avatar licc

优化月度肥料任务

parent 0b532595
......@@ -212,6 +212,9 @@ public class DayTaskServiceImpl implements DayTaskService {
return R.ok(0, true);
}
//如果用户的团队业绩不存在的,新增本月团队业绩
addTeamPerformance(userList);
boolean bool = monthlyIncome(totalMoney, userList);
if (!bool) {
return R.ok(1, false);
......@@ -238,81 +241,81 @@ public class DayTaskServiceImpl implements DayTaskService {
totalMoney = totalMoney.add(orderInfo.getPayment());
}
double number = Math.floor(totalMoney.doubleValue() / 3980 / 12);
if (number == 0) {
return R.ok(0, true);
}
//1、判断当前月是否是业绩开始的第一个月
List<TeamPerformance> teamPerformances = teamPerformanceMapper.getByBeforeTime(yearMonth);
//2、集合为空 是业绩开始的第一个月
if (CollectionUtils.isEmpty(teamPerformances)) {
if (number != 0) {
//获取月业绩前20用户
List<TeamPerformance> list = teamPerformanceMapper.userTwenty(yearMonth);
if (CollectionUtils.isEmpty(list)) {
return R.ok(0, true);
}
//获取月业绩前20用户
List<TeamPerformance> list = teamPerformanceMapper.userTwenty(yearMonth);
if (CollectionUtils.isEmpty(list)) {
return R.ok(0, true);
}
//获取20名进步最大的月业绩和
Double twentyTotal = teamPerformanceMapper.countTwenty(yearMonth);
List<AccountInfo> accountInfoList = new ArrayList<>();
List<TradeRecord> tradeRecordList = new ArrayList<>();
List<ProgressPrize> addPrizeList = new ArrayList<>();
List<ProgressPrize> updatePrizeList = new ArrayList<>();
for (TeamPerformance user : list) {
//获取最大进步奖 百分比
MemberPercent memberPercent = memberPercentMapper.getByLevelAndType(user.getUserLevel(),
MemberPercentEnum.MONTH_BEST_AWARD.getCode());
//计算收益
double userTeamPerformance = user.getMonthTeamPerformance().doubleValue();
double percent = memberPercent.getPercent().doubleValue();
double income = Math.floor(number * 3980 * percent * userTeamPerformance / twentyTotal);
//获取20名进步最大的月业绩和
Double twentyTotal = teamPerformanceMapper.countTwenty(yearMonth);
List<AccountInfo> accountInfoList = new ArrayList<>();
List<TradeRecord> tradeRecordList = new ArrayList<>();
List<ProgressPrize> addPrizeList = new ArrayList<>();
List<ProgressPrize> updatePrizeList = new ArrayList<>();
for (TeamPerformance user : list) {
//获取最大进步奖 百分比
MemberPercent memberPercent = memberPercentMapper.getByLevelAndType(user.getUserLevel(),
MemberPercentEnum.MONTH_BEST_AWARD.getCode());
//获取账户信息
AccountInfo accountInfo = accountMapper.getByUserId(user.getUserId());
//计算收益
double userTeamPerformance = user.getMonthTeamPerformance().doubleValue();
double percent = memberPercent.getPercent().doubleValue();
double income = Math.floor(number * 3980 * percent * userTeamPerformance / twentyTotal);
//用户月收益 =其他收益+最大进步奖收益
BigDecimal earningsMonth = accountInfo.getEarningsMonth().add(BigDecimal.valueOf(income));
accountInfo.setEarningsMonth(earningsMonth);
//获取账户信息
AccountInfo accountInfo = accountMapper.getByUserId(user.getUserId());
//用户总收益 =其他总收益 + 最大进步奖收益
BigDecimal earningsTotal = accountInfo.getEarningsTotal().add(BigDecimal.valueOf(income));
accountInfo.setEarningsTotal(earningsTotal);
accountInfoList.add(accountInfo);
//用户月收益 =其他收益+最大进步奖收益
BigDecimal earningsMonth = accountInfo.getEarningsMonth().add(BigDecimal.valueOf(income));
accountInfo.setEarningsMonth(earningsMonth);
//添加最大进步奖信息 不存在:新增 存在,修改
BigDecimal awardMoney = new BigDecimal(income).setScale(2, RoundingMode.HALF_UP);
ProgressPrize progressPrize = progressPrizeMapper.getByUserIdYearMonth(user.getUserId(), yearMonth);
if (null == progressPrize) {
ProgressPrize prize = new ProgressPrize();
prize.setAwardMoney(awardMoney.doubleValue());
prize.setUserId(user.getUserId());
prize.setGrowthRate(0.0);
prize.setYearMonth(yearMonth);
addPrizeList.add(prize);
} else {
progressPrize.setYearMonth(yearMonth);
progressPrize.setAwardMoney(awardMoney.doubleValue());
updatePrizeList.add(progressPrize);
}
//用户总收益 =其他总收益 + 最大进步奖收益
BigDecimal earningsTotal = accountInfo.getEarningsTotal().add(BigDecimal.valueOf(income));
accountInfo.setEarningsTotal(earningsTotal);
accountInfoList.add(accountInfo);
//添加交易流水记录
TradeRecord tradeRecord = new TradeRecord();
tradeRecord.setUserId(user.getUserId());
tradeRecord.setTradeType(TradeRecordEnum.PROGRESS_PRIZE.getCode());
tradeRecord.setTradeNo(null);
tradeRecord.setStatus(TradeStatusEnum.NO_SETTLE_ACCOUNTS.getCode());
tradeRecord.setMoney(BigDecimal.valueOf(income));
tradeRecordList.add(tradeRecord);
//添加最大进步奖信息 不存在:新增 存在,修改
BigDecimal awardMoney = new BigDecimal(income).setScale(2, RoundingMode.HALF_UP);
ProgressPrize progressPrize = progressPrizeMapper.getByUserIdYearMonth(user.getUserId(), yearMonth);
if (null == progressPrize) {
ProgressPrize prize = new ProgressPrize();
prize.setAwardMoney(awardMoney.doubleValue());
prize.setUserId(user.getUserId());
prize.setGrowthRate(0.0);
prize.setYearMonth(yearMonth);
addPrizeList.add(prize);
} else {
progressPrize.setYearMonth(yearMonth);
progressPrize.setAwardMoney(awardMoney.doubleValue());
updatePrizeList.add(progressPrize);
}
//更新账户信息,添加交易流水记录
boolean bool = accountManager.updateAccountAddRecordAddPrize(accountInfoList, tradeRecordList,
addPrizeList, updatePrizeList);
if (!bool) {
return R.ok(1, false);
}
//添加交易流水记录
TradeRecord tradeRecord = new TradeRecord();
tradeRecord.setUserId(user.getUserId());
tradeRecord.setTradeType(TradeRecordEnum.PROGRESS_PRIZE.getCode());
tradeRecord.setTradeNo(null);
tradeRecord.setStatus(TradeStatusEnum.NO_SETTLE_ACCOUNTS.getCode());
tradeRecord.setMoney(BigDecimal.valueOf(income));
tradeRecordList.add(tradeRecord);
}
//更新账户信息,添加交易流水记录
boolean bool = accountManager.updateAccountAddRecordAddPrize(accountInfoList, tradeRecordList,
addPrizeList, updatePrizeList);
if (!bool) {
return R.ok(1, false);
}
log.info("本月最大进步奖日定时任务执行成功");
return R.ok(0, true);
}
......@@ -463,7 +466,9 @@ public class DayTaskServiceImpl implements DayTaskService {
if (null != memberPercent) {
//获取本月团队总金额
TeamPerformance teamPerformance = teamPerformanceMapper.getByUserIdAndTime(user.getUserId(), yearMonth);
if(null ==teamPerformance){
}
//获取该等级团队总金额
Double teamTotal = teamPerformanceMapper.countTeamMoney(user.getUserLevel(), yearMonth);
if (null != teamPerformance && null != teamTotal) {
......
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