Commit b56b10bd authored by licc's avatar licc

定时任务优化

parent 412a09fe
...@@ -200,7 +200,7 @@ public class DayTaskServiceImpl implements DayTaskService { ...@@ -200,7 +200,7 @@ public class DayTaskServiceImpl implements DayTaskService {
} }
} }
//4、更新账户月度绩效 //4、更新账户月度团队业绩
boolean updateBool = accountManager.updateAccountPerformanceMonth(addList, updateList); boolean updateBool = accountManager.updateAccountPerformanceMonth(addList, updateList);
if (!updateBool) { if (!updateBool) {
return R.ok(1, false); return R.ok(1, false);
...@@ -228,12 +228,20 @@ public class DayTaskServiceImpl implements DayTaskService { ...@@ -228,12 +228,20 @@ public class DayTaskServiceImpl implements DayTaskService {
Date date = new Date(); Date date = new Date();
String yearMonth = DateUtil.convertDateToStr(date, PATTERN); String yearMonth = DateUtil.convertDateToStr(date, PATTERN);
//获取当月所有人业绩总额
List<OrderInfo> orderList = orderMapper.getByCreateTime(new Date());
if (CollectionUtils.isEmpty(orderList)) {
return R.ok(0, true);
}
BigDecimal totalMoney = new BigDecimal(0);
for (OrderInfo orderInfo : orderList) {
totalMoney = totalMoney.add(orderInfo.getPayment());
}
double number = Math.floor(totalMoney.doubleValue() / 3980 / 12);
//1、判断当前月是否是业绩开始的第一个月 //1、判断当前月是否是业绩开始的第一个月
List<TeamPerformance> teamPerformances = teamPerformanceMapper.getByBeforeTime(yearMonth); List<TeamPerformance> teamPerformances = teamPerformanceMapper.getByBeforeTime(yearMonth);
//获取当月所有人业绩总额
Double totalMoney = teamPerformanceMapper.countByTime(yearMonth);
double number = Math.floor(totalMoney / 3980 / 12);
//2、集合为空 是业绩开始的第一个月 //2、集合为空 是业绩开始的第一个月
if (CollectionUtils.isEmpty(teamPerformances)) { if (CollectionUtils.isEmpty(teamPerformances)) {
if (number != 0) { if (number != 0) {
...@@ -356,6 +364,7 @@ public class DayTaskServiceImpl implements DayTaskService { ...@@ -356,6 +364,7 @@ public class DayTaskServiceImpl implements DayTaskService {
if (null != user && !StringUtils.isBlank(user.getBeInvitedCode())) { if (null != user && !StringUtils.isBlank(user.getBeInvitedCode())) {
user = usersMapper.getByBeInvitedCode(user.getBeInvitedCode()); user = usersMapper.getByBeInvitedCode(user.getBeInvitedCode());
if (null != user) { if (null != user) {
//todo 被邀请码=1 或 888888
if (user.getBeInvitedCode().equals(user.getInviteCode())) { if (user.getBeInvitedCode().equals(user.getInviteCode())) {
return; return;
} }
...@@ -396,8 +405,10 @@ public class DayTaskServiceImpl implements DayTaskService { ...@@ -396,8 +405,10 @@ public class DayTaskServiceImpl implements DayTaskService {
double last = lastMonth.getMonthTeamPerformance().doubleValue(); double last = lastMonth.getMonthTeamPerformance().doubleValue();
if (last >= month) { if (last >= month) {
growthRate = 0.00; growthRate = 0.00;
} else if (last == 0) {
growthRate = 0.00;
} else { } else {
growthRate = (month - last) / month; growthRate = (month - last) / last;
} }
} }
teamVo.setGrowthRate(growthRate); teamVo.setGrowthRate(growthRate);
...@@ -446,62 +457,64 @@ public class DayTaskServiceImpl implements DayTaskService { ...@@ -446,62 +457,64 @@ public class DayTaskServiceImpl implements DayTaskService {
} else { } else {
lastMonthAward = monthManure.getManureAward(); lastMonthAward = monthManure.getManureAward();
} }
if (moneyMonth == 0) {
return true;
}
for (User user : userList) { for (User user : userList) {
if (moneyMonth != 0) { //获取等级优惠百分比
//获取等级优惠百分比 MemberPercent memberPercent = memberPercentMapper.getByLevelAndType(user.getUserLevel(), 2);
MemberPercent memberPercent = memberPercentMapper.getByLevelAndType(user.getUserLevel(), 2); if (null != memberPercent) {
if (null != memberPercent) { //获取本月团队总金额
//获取本月团队总金额 TeamPerformance teamPerformance = teamPerformanceMapper.getByUserIdAndTime(user.getUserId(), yearMonth);
TeamPerformance teamPerformance = teamPerformanceMapper.getByUserIdAndTime(user.getUserId(), yearMonth);
//获取该等级团队总金额
//获取该等级团队总金额 Double teamTotal = teamPerformanceMapper.countTeamMoney(user.getUserLevel(), yearMonth);
Double teamTotal = teamPerformanceMapper.countTeamMoney(user.getUserLevel(), yearMonth); if (null != teamPerformance && null != teamTotal) {
if (null != teamPerformance && null != teamTotal) { double month = teamPerformance.getMonthTeamPerformance().doubleValue();
double month = teamPerformance.getMonthTeamPerformance().doubleValue(); double percent = memberPercent.getPercent().doubleValue();
double percent = memberPercent.getPercent().doubleValue(); //计算收益 todo
//计算收益 double teamMoney = ((moneyMonth * 3980) + lastMonthAward) * percent * month;
double teamMoney = (moneyMonth + lastMonthAward) * 3980 * percent * month; DecimalFormat df = new DecimalFormat("######0.00");
DecimalFormat df = new DecimalFormat("######0.00"); double income = Double.parseDouble(df.format(teamMoney / teamTotal));
double income = Double.parseDouble(df.format(teamMoney / teamTotal));
//获取账户信息
//获取账户信息 AccountInfo accountInfo = accountMapper.getByUserId(user.getUserId());
AccountInfo accountInfo = accountMapper.getByUserId(user.getUserId()); BigDecimal bigDecimal = new BigDecimal(income).setScale(2, RoundingMode.HALF_UP);
BigDecimal bigDecimal = new BigDecimal(income).setScale(2, RoundingMode.HALF_UP);
//获取本月培育奖信息
//获取本月培育奖信息 TradeRecord tradeRecordMonth = tradeRecordMapper.getByUserIdAndTypeAndStatus(user.getUserId(),
TradeRecord tradeRecordMonth = tradeRecordMapper.getByUserIdAndTypeAndStatus(user.getUserId(), TradeRecordEnum.CULTIVATING_PRIZE.getCode(), new Date(), TradeStatusEnum.NO_SETTLE_ACCOUNTS.getCode());
TradeRecordEnum.CULTIVATING_PRIZE.getCode(), new Date(), TradeStatusEnum.NO_SETTLE_ACCOUNTS.getCode()); BigDecimal tradeMoney = new BigDecimal(0);
BigDecimal tradeMoney = new BigDecimal(0); if (null != tradeRecordMonth) {
if (null != tradeRecordMonth) { tradeMoney = tradeRecordMonth.getMoney();
tradeMoney = tradeRecordMonth.getMoney();
}
//获取用户本月收益=可提现金额+ 本月肥料收益+培育奖收益
BigDecimal performanceMonth = accountInfo.getExtractMoney().add(bigDecimal).add(tradeMoney);
accountInfo.setEarningsMonth(performanceMonth);
//获取用户上月总收益
LastMonthAccount lastMonthAccount = lastAccountMapper.getByUserIdAndTime(user.getUserId(), yearMonthTime);
BigDecimal lastTotalMonth;
if (null == lastMonthAccount || null == lastMonthAccount.getEarningsTotal()) {
lastTotalMonth = new BigDecimal("0.00");
} else {
lastTotalMonth = lastMonthAccount.getEarningsTotal();
}
//用户总收益=上月总收益+本月收益
BigDecimal performanceTotal = lastTotalMonth.add(performanceMonth);
accountInfo.setEarningsTotal(performanceTotal);
accountInfoList.add(accountInfo);
//5、添加交易流水记录
TradeRecord tradeRecord = new TradeRecord();
tradeRecord.setUserId(user.getUserId());
tradeRecord.setTradeType(TradeRecordEnum.MONTHLY_FERTILIZER.getCode());
tradeRecord.setTradeNo(null);
tradeRecord.setStatus(TradeStatusEnum.NO_SETTLE_ACCOUNTS.getCode());
tradeRecordList.add(tradeRecord);
} }
//获取用户本月收益=可提现金额+ 本月肥料收益+培育奖收益
BigDecimal performanceMonth = accountInfo.getExtractMoney().add(bigDecimal).add(tradeMoney);
accountInfo.setEarningsMonth(performanceMonth);
//获取用户上月总收益
LastMonthAccount lastMonthAccount = lastAccountMapper.getByUserIdAndTime(user.getUserId(), yearMonthTime);
BigDecimal lastTotalMonth;
if (null == lastMonthAccount || null == lastMonthAccount.getEarningsTotal()) {
lastTotalMonth = new BigDecimal("0.00");
} else {
lastTotalMonth = lastMonthAccount.getEarningsTotal();
}
//用户总收益=上月总收益+本月收益
BigDecimal performanceTotal = lastTotalMonth.add(performanceMonth);
accountInfo.setEarningsTotal(performanceTotal);
accountInfoList.add(accountInfo);
//5、添加交易流水记录
TradeRecord tradeRecord = new TradeRecord();
tradeRecord.setUserId(user.getUserId());
tradeRecord.setTradeType(TradeRecordEnum.MONTHLY_FERTILIZER.getCode());
tradeRecord.setTradeNo(null);
tradeRecord.setStatus(TradeStatusEnum.NO_SETTLE_ACCOUNTS.getCode());
tradeRecordList.add(tradeRecord);
} }
} }
} }
......
...@@ -133,15 +133,15 @@ public class MonthTaskServiceImpl implements MonthTaskService { ...@@ -133,15 +133,15 @@ public class MonthTaskServiceImpl implements MonthTaskService {
continue; continue;
} }
for (User User : userList) { for (User user : userList) {
//3)、统计当前用户的上级用户团队绩效 //3)、统计当前用户的上级用户团队绩效
//key 存在 当前用户团队绩效 + 上级用户团队绩效 //key 存在 当前用户团队绩效 + 上级用户团队绩效
if (tempMap.containsKey(User.getUserId())) { if (tempMap.containsKey(user.getUserId())) {
double teamMoney = userCount + tempMap.get(User.getUserId()); double teamMoney = userCount + tempMap.get(user.getUserId());
tempMap.put(User.getUserId(), teamMoney); tempMap.put(user.getUserId(), teamMoney);
} else { } else {
//key 不存在,加入集合 当前用户团队绩效 //key 不存在,加入集合 当前用户团队绩效
tempMap.put(User.getUserId(), userCount); tempMap.put(user.getUserId(), userCount);
} }
} }
} }
...@@ -178,7 +178,7 @@ public class MonthTaskServiceImpl implements MonthTaskService { ...@@ -178,7 +178,7 @@ public class MonthTaskServiceImpl implements MonthTaskService {
//5、获取所有用户,如果会员等级是黄金以上,计算月度收益 //5、获取所有用户,如果会员等级是黄金以上,计算月度收益
List<User> userList = usersMapper.getAllGoldUser(); List<User> userList = usersMapper.getAllGoldUser();
if (CollectionUtils.isEmpty(userList)) { if (CollectionUtils.isEmpty(userList)) {
//添加月度肥料剩余奖金 //添加月度肥料剩余奖金 todo /3980/12*3980*(黄金以上比列相加)
MonthManure monthManure = new MonthManure(); MonthManure monthManure = new MonthManure();
monthManure.setManureAward(totalMoney.doubleValue()); monthManure.setManureAward(totalMoney.doubleValue());
monthManure.setYearMonth(yearMonth); monthManure.setYearMonth(yearMonth);
...@@ -203,13 +203,21 @@ public class MonthTaskServiceImpl implements MonthTaskService { ...@@ -203,13 +203,21 @@ public class MonthTaskServiceImpl implements MonthTaskService {
log.info("shop-mall[]MonthTaskServiceImpl[]performanceCount[]input.method"); log.info("shop-mall[]MonthTaskServiceImpl[]performanceCount[]input.method");
Date date = DateUtil.getLastMonth(new Date()); Date date = DateUtil.getLastMonth(new Date());
String lastMonth = DateUtil.convertDateToStr(date, PATTERN); String lastMonth = DateUtil.convertDateToStr(date, PATTERN);
//获取当月所有人业绩总额
List<OrderInfo> orderList = orderMapper.getByCreateTime(date);
if (CollectionUtils.isEmpty(orderList)) {
return R.ok(0, true);
}
//获取上月月所有人业绩总额
BigDecimal totalMoney = new BigDecimal(0);
for (OrderInfo orderInfo : orderList) {
totalMoney = totalMoney.add(orderInfo.getPayment());
}
double number = Math.floor(totalMoney.doubleValue() / 3980 / 12);
//1、判断上月是否是业绩开始的第一个月 //1、判断上月是否是业绩开始的第一个月
List<TeamPerformance> teamPerformances = teamPerformanceMapper.getByBeforeTime(lastMonth); List<TeamPerformance> teamPerformances = teamPerformanceMapper.getByBeforeTime(lastMonth);
//获取上月月所有人业绩总额
Double totalMoney = teamPerformanceMapper.countByTime(lastMonth);
double number = Math.floor(totalMoney / 3980 / 12);
//2、集合为空 是业绩开始的第一个月 //2、集合为空 是业绩开始的第一个月
if (CollectionUtils.isEmpty(teamPerformances)) { if (CollectionUtils.isEmpty(teamPerformances)) {
if (number != 0) { if (number != 0) {
...@@ -523,15 +531,18 @@ public class MonthTaskServiceImpl implements MonthTaskService { ...@@ -523,15 +531,18 @@ public class MonthTaskServiceImpl implements MonthTaskService {
} else { } else {
lastMonthAward = monthManure.getManureAward(); lastMonthAward = monthManure.getManureAward();
} }
moneyMonth = moneyMonth + lastMonthAward;
//1、判断每个等级是否都有用户,没有用户的,记录下剩余奖金 //1、判断每个等级是否都有用户,没有用户的,记录下剩余奖金
MonthManure manure = checkUserLevel(moneyMonth); MonthManure manure = checkUserLevel(moneyMonth, lastMonthAward);
//获取上月是否有月度剩余奖金信息 //获取上月是否有月度剩余奖金信息
MonthManure lastMonthManure = monthManureMapper.queryByTime(lastMonth); MonthManure lastMonthManure = monthManureMapper.queryByTime(lastMonth);
List<AccountInfo> accountInfoList = new ArrayList<>(); List<AccountInfo> accountInfoList = new ArrayList<>();
List<TradeRecord> tradeRecordList = new ArrayList<>(); List<TradeRecord> tradeRecordList = new ArrayList<>();
if (moneyMonth == 0) {
return true;
}
for (User user : userList) { for (User user : userList) {
if (moneyMonth != 0) { if (moneyMonth != 0) {
//获取等级优惠百分比 //获取等级优惠百分比
...@@ -547,7 +558,7 @@ public class MonthTaskServiceImpl implements MonthTaskService { ...@@ -547,7 +558,7 @@ public class MonthTaskServiceImpl implements MonthTaskService {
double month = teamPerformance.getMonthTeamPerformance().doubleValue(); double month = teamPerformance.getMonthTeamPerformance().doubleValue();
double percent = memberPercent.getPercent().doubleValue(); double percent = memberPercent.getPercent().doubleValue();
//计算收益 //计算收益
double income = moneyMonth * 3980 * percent * month / teamTotal; double income = ((moneyMonth * 3980) + lastMonthAward) * percent * month / teamTotal;
//获取账户信息 //获取账户信息
AccountInfo accountInfo = accountMapper.getByUserId(user.getUserId()); AccountInfo accountInfo = accountMapper.getByUserId(user.getUserId());
...@@ -595,7 +606,7 @@ public class MonthTaskServiceImpl implements MonthTaskService { ...@@ -595,7 +606,7 @@ public class MonthTaskServiceImpl implements MonthTaskService {
* @param moneyMonth 奖金总额 * @param moneyMonth 奖金总额
* @return 月度肥料奖金 * @return 月度肥料奖金
*/ */
private MonthManure checkUserLevel(double moneyMonth) { private MonthManure checkUserLevel(double moneyMonth, double lastMonthAward) {
MonthManure monthManure = new MonthManure(); MonthManure monthManure = new MonthManure();
double total = 0.00; double total = 0.00;
//1、判断是否有黄金等级的用户 //1、判断是否有黄金等级的用户
...@@ -609,7 +620,7 @@ public class MonthTaskServiceImpl implements MonthTaskService { ...@@ -609,7 +620,7 @@ public class MonthTaskServiceImpl implements MonthTaskService {
//计算该等级剩余奖金 //计算该等级剩余奖金
double goldAward; double goldAward;
if (moneyMonth != 0) { if (moneyMonth != 0) {
goldAward = moneyMonth * 3980 * percent; goldAward = ((moneyMonth * 3980) + lastMonthAward) * percent;
total = total + goldAward; total = total + goldAward;
} }
} }
...@@ -625,7 +636,7 @@ public class MonthTaskServiceImpl implements MonthTaskService { ...@@ -625,7 +636,7 @@ public class MonthTaskServiceImpl implements MonthTaskService {
//计算该等级剩余奖金 //计算该等级剩余奖金
double goldAward; double goldAward;
if (moneyMonth != 0) { if (moneyMonth != 0) {
goldAward = moneyMonth * 3980 * percent; goldAward = ((moneyMonth * 3980) + lastMonthAward) * percent;
total = total + goldAward; total = total + goldAward;
} }
} }
...@@ -641,7 +652,7 @@ public class MonthTaskServiceImpl implements MonthTaskService { ...@@ -641,7 +652,7 @@ public class MonthTaskServiceImpl implements MonthTaskService {
//计算该等级剩余奖金 //计算该等级剩余奖金
double goldAward; double goldAward;
if (moneyMonth != 0) { if (moneyMonth != 0) {
goldAward = moneyMonth * 3980 * percent; goldAward = ((moneyMonth * 3980) + lastMonthAward) * percent;
total = total + goldAward; total = total + goldAward;
} }
} }
...@@ -657,7 +668,7 @@ public class MonthTaskServiceImpl implements MonthTaskService { ...@@ -657,7 +668,7 @@ public class MonthTaskServiceImpl implements MonthTaskService {
//计算该等级剩余奖金 //计算该等级剩余奖金
double goldAward; double goldAward;
if (moneyMonth != 0) { if (moneyMonth != 0) {
goldAward = moneyMonth * 3980 * percent; goldAward = ((moneyMonth * 3980) + lastMonthAward) * percent;
total = total + goldAward; total = total + goldAward;
} }
} }
......
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