Commit e26204ed authored by licc's avatar licc

优化最大进步奖

parent 6a860a91
...@@ -120,8 +120,9 @@ ...@@ -120,8 +120,9 @@
from from
<include refid="table"/> <include refid="table"/>
<where> <where>
user_level>0
<if test="yearMonth != null"> <if test="yearMonth != null">
`year_month` = #{yearMonth} and `year_month` = #{yearMonth}
</if> </if>
</where> </where>
</select> </select>
......
...@@ -123,67 +123,34 @@ public class AccountManager { ...@@ -123,67 +123,34 @@ public class AccountManager {
/** /**
* 修改 或新增 删除 最大进步奖实体类 * 修改 或新增 删除 最大进步奖实体类
* *
* @param listVo 最新的进步奖 对象 * @param addList 最新的进步奖 对象
* @param accountInfoList 要更新的最大进步奖账户收益 * @param accountInfoList 要更新的最大进步奖账户收益
* @param prizes 上一次统计的进步奖 对象 * @param prizes 上一次统计的进步奖 对象
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Boolean updateOrSavePrize(List<TeamPerformanceSortVo> listVo, List<AccountInfo> accountInfoList, public Boolean updateOrSavePrize(List<AccountInfo> accountInfoList,
List<ProgressPrize> prizes, int flag) { List<ProgressPrize> prizes, List<ProgressPrize> addList,
Date date = new Date(); List<ProgressPrize> updateList, int flag) {
String yearMonth = DateUtil.convertDateToStr(date, PATTERN);
//构造一个map key:userId value progressPrize //1、存在的修改,不存在的新增,多余的,删除
Map<String, ProgressPrize> map = new HashMap<>(32); List<String> userIds = prizes.stream().map(ProgressPrize::getUserId).collect(Collectors.toList());
List<ProgressPrize> deleteList = new ArrayList<>();
//遍历:要删除的数据
for (ProgressPrize progressPrize : prizes) { for (ProgressPrize progressPrize : prizes) {
map.put(progressPrize.getUserId(), progressPrize); if (!userIds.contains(progressPrize.getUserId())) {
deleteList.add(progressPrize);
}
} }
//1、判断 prizes 是否为空集合,是新增 for (ProgressPrize deletePrize : deleteList) {
//新增 int count = progressPrizeMapper.delById(deletePrize.getId());
if (CollectionUtils.isEmpty(prizes)) {
for (TeamPerformanceSortVo sortVo : listVo) {
String userId = sortVo.getTeamPerformance().getUserId();
ProgressPrize progressPrize = new ProgressPrize();
progressPrize.setUserId(userId);
progressPrize.setGrowthRate(sortVo.getGrowthRate());
progressPrize.setAwardMoney(sortVo.getMonthPerformance());
progressPrize.setYearMonth(yearMonth);
int count = progressPrizeMapper.add(progressPrize);
if (count == 0) { if (count == 0) {
return false; return false;
} }
} }
} else {
//2、不为空。存在的修改,不存在的新增,多余的,删除
List<ProgressPrize> updateList = new ArrayList<>();
List<ProgressPrize> addList = new ArrayList<>();
List<String> userIds = prizes.stream().map(ProgressPrize::getUserId).collect(Collectors.toList());
//遍历 筛选出要修改、新增、删除 对象
for (TeamPerformanceSortVo sortVo : listVo) {
if (userIds.contains(sortVo.getUserId())) {
//修改
ProgressPrize prize = map.get(sortVo.getUserId());
prize.setGrowthRate(sortVo.getGrowthRate());
prize.setAwardMoney(sortVo.getMonthPerformance());
updateList.add(prize);
//移除要修改的
prizes.remove(prize);
} else {
//新增
String userId = sortVo.getTeamPerformance().getUserId();
ProgressPrize progress = new ProgressPrize();
progress.setUserId(userId);
progress.setGrowthRate(sortVo.getGrowthRate());
progress.setAwardMoney(sortVo.getMonthPerformance());
progress.setYearMonth(yearMonth);
addList.add(progress);
}
}
//剩余的是要删除的 //更新
List<ProgressPrize> deleteList = new ArrayList<>(prizes);
for (ProgressPrize updatePrize : updateList) { for (ProgressPrize updatePrize : updateList) {
int count = progressPrizeMapper.edit(updatePrize); int count = progressPrizeMapper.edit(updatePrize);
log.info("更新最大进步奖用户" + updatePrize.getUserId() + "奖金为:" + updatePrize.getAwardMoney()); log.info("更新最大进步奖用户" + updatePrize.getUserId() + "奖金为:" + updatePrize.getAwardMoney());
...@@ -192,6 +159,7 @@ public class AccountManager { ...@@ -192,6 +159,7 @@ public class AccountManager {
} }
} }
//新增
for (ProgressPrize addPrize : addList) { for (ProgressPrize addPrize : addList) {
int count = progressPrizeMapper.add(addPrize); int count = progressPrizeMapper.add(addPrize);
log.info("新增最大进步奖用户" + addPrize.getUserId() + "奖金:" + addPrize.getAwardMoney()); log.info("新增最大进步奖用户" + addPrize.getUserId() + "奖金:" + addPrize.getAwardMoney());
...@@ -200,13 +168,6 @@ public class AccountManager { ...@@ -200,13 +168,6 @@ public class AccountManager {
} }
} }
for (ProgressPrize deletePrize : deleteList) {
int count = progressPrizeMapper.delById(deletePrize.getId());
if (count == 0) {
return false;
}
}
}
//3、添加账户获得的收益 //3、添加账户获得的收益
for (AccountInfo accountInfo : accountInfoList) { for (AccountInfo accountInfo : accountInfoList) {
......
...@@ -315,6 +315,9 @@ public class DayTaskServiceImpl implements DayTaskService { ...@@ -315,6 +315,9 @@ public class DayTaskServiceImpl implements DayTaskService {
return R.ok(0, true); return R.ok(0, true);
} }
//如果用户的团队业绩不存在的,新增本月团队业绩
addTeamPerformance(userList);
//4计算每个用户本月的业绩增长率 如果集合大于20 ,取前二十名,小于,取全部 //4计算每个用户本月的业绩增长率 如果集合大于20 ,取前二十名,小于,取全部
List<TeamPerformanceSortVo> listVo = progressPrizeStatistics(userList); List<TeamPerformanceSortVo> listVo = progressPrizeStatistics(userList);
if (listVo.size() >= TWENTY) { if (listVo.size() >= TWENTY) {
...@@ -399,7 +402,6 @@ public class DayTaskServiceImpl implements DayTaskService { ...@@ -399,7 +402,6 @@ public class DayTaskServiceImpl implements DayTaskService {
} }
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 {
...@@ -516,42 +518,75 @@ public class DayTaskServiceImpl implements DayTaskService { ...@@ -516,42 +518,75 @@ public class DayTaskServiceImpl implements DayTaskService {
private boolean totalPerformanceIncome(List<TeamPerformanceSortVo> listVo, double number, double total) { private boolean totalPerformanceIncome(List<TeamPerformanceSortVo> listVo, double number, double total) {
//要更新的账户列表 //要更新的账户列表
List<AccountInfo> updateAccountList = new ArrayList<>(); List<AccountInfo> updateAccountList = new ArrayList<>();
String yearMonth = DateUtil.convertDateToStr(new Date(), "yyyy-MM");
BigDecimal sum = new BigDecimal(0); List<ProgressPrize> addList = new ArrayList<>();
for (int i = 0; i < listVo.size(); i++) { List<ProgressPrize> updateList = new ArrayList<>();
String userId = listVo.get(i).getTeamPerformance().getUserId(); for (TeamPerformanceSortVo teamVo : listVo) {
Integer userLevel = listVo.get(i).getTeamPerformance().getUserLevel(); String userId = teamVo.getTeamPerformance().getUserId();
Integer userLevel = teamVo.getTeamPerformance().getUserLevel();
//获取最大进步奖 百分比 //获取最大进步奖 百分比
MemberPercent memberPercent = memberPercentMapper.getByLevelAndType(userLevel, 3); MemberPercent memberPercent = memberPercentMapper.getByLevelAndType(userLevel, 3);
//计算收益 //计算收益
double userTeamPerformance = listVo.get(i).getTeamPerformance().getMonthTeamPerformance().doubleValue(); double userTeamPerformance = teamVo.getTeamPerformance().getMonthTeamPerformance().doubleValue();
double percent = memberPercent.getPercent().doubleValue(); double percent = memberPercent.getPercent().doubleValue();
double income = number * 3980 * percent * userTeamPerformance / total; double income = number * 3980 * percent * userTeamPerformance / total;
//获取账户信息 //获取账户信息
AccountInfo accountInfo = accountMapper.getByUserId(userId); AccountInfo accountInfo = accountMapper.getByUserId(userId);
BigDecimal bigDecimal; //用户月收益 =其他收益+最大进步奖收益
if (i == listVo.size() - 1) { BigDecimal earningsMonth = accountInfo.getEarningsMonth().add(BigDecimal.valueOf(income));
bigDecimal = new BigDecimal(total).subtract(sum); accountInfo.setEarningsMonth(earningsMonth);
//用户总收益 =其他总收益 + 最大进步奖收益
BigDecimal earningsTotal = accountInfo.getEarningsTotal().add(BigDecimal.valueOf(income));
accountInfo.setEarningsTotal(earningsTotal);
updateAccountList.add(accountInfo);
//最大进步奖信息
ProgressPrize progressPrize = progressPrizeMapper.getByUserIdYearMonth(userId, yearMonth);
if (null == progressPrize) {
//新增
ProgressPrize addPrize = new ProgressPrize();
addPrize.setAwardMoney(income);
addPrize.setYearMonth(yearMonth);
addPrize.setGrowthRate(0.0);
addPrize.setUserId(userId);
addList.add(addPrize);
} else { } else {
bigDecimal = accountInfo.getEarningsMonth().add(new BigDecimal(income)); progressPrize.setGrowthRate(teamVo.getGrowthRate());
sum = sum.add(new BigDecimal(income)); progressPrize.setAwardMoney(income);
progressPrize.setGrowthRate(teamVo.getGrowthRate());
updateList.add(progressPrize);
} }
accountInfo.setEarningsMonth(bigDecimal);
updateAccountList.add(accountInfo);
} }
//判断本月是否有最大进步奖数据 无,新增 有,修改或删除 //获取本月已经存在的最大进步奖列表
Date date = new Date();
String yearMonth = DateUtil.convertDateToStr(date, PATTERN);
List<ProgressPrize> prizes = progressPrizeMapper.getByYearMonth(yearMonth); List<ProgressPrize> prizes = progressPrizeMapper.getByYearMonth(yearMonth);
//修改或保存最大进步奖信息 //修改或保存最大进步奖信息
// flag 1: 日定时任务 2:月定时任务 // flag 1: 日定时任务 2:月定时任务
int flag = 1; int flag = 1;
return accountManager.updateOrSavePrize(listVo, updateAccountList, prizes, flag); return accountManager.updateOrSavePrize(updateAccountList, prizes,addList,updateList, flag);
} }
private void addTeamPerformance(List<User> userList) {
String yearMonth = DateUtil.convertDateToStr(new Date(), "yyyy-MM");
if (!CollectionUtils.isEmpty(userList)) {
for (User user : userList) {
//获取团队业绩信息
TeamPerformance teamPerformance = teamPerformanceMapper.getByUserIdAndTime(user.getUserId(), yearMonth);
if (null == teamPerformance) {
TeamPerformance addTeam = new TeamPerformance();
addTeam.setMonthTeamPerformance(new BigDecimal(0));
addTeam.setYearMonth(yearMonth);
addTeam.setUserLevel(user.getUserLevel());
addTeam.setUserId(user.getUserId());
teamPerformanceMapper.add(addTeam);
}
}
}
}
} }
...@@ -735,41 +735,56 @@ public class MonthTaskServiceImpl implements MonthTaskService { ...@@ -735,41 +735,56 @@ public class MonthTaskServiceImpl implements MonthTaskService {
private boolean totalPerformanceIncome(List<TeamPerformanceSortVo> listVo, double number, double total) { private boolean totalPerformanceIncome(List<TeamPerformanceSortVo> listVo, double number, double total) {
//要更新的账户列表 //要更新的账户列表
List<AccountInfo> updateAccountList = new ArrayList<>(); List<AccountInfo> updateAccountList = new ArrayList<>();
Date lastMonth = DateUtil.getLastMonth(new Date());
String yearMonth = DateUtil.convertDateToStr(lastMonth, PATTERN);
List<ProgressPrize> addList = new ArrayList<>();
List<ProgressPrize> updateList = new ArrayList<>();
BigDecimal sum = new BigDecimal(0); for (TeamPerformanceSortVo teamPerformanceSortVo : listVo) {
for (int i = 0; i < listVo.size(); i++) { String userId = teamPerformanceSortVo.getTeamPerformance().getUserId();
String userId = listVo.get(i).getTeamPerformance().getUserId(); Integer userLevel = teamPerformanceSortVo.getTeamPerformance().getUserLevel();
Integer userLevel = listVo.get(i).getTeamPerformance().getUserLevel();
//获取最大进步奖 百分比 //获取最大进步奖 百分比
MemberPercent memberPercent = memberPercentMapper.getByLevelAndType(userLevel, 3); MemberPercent memberPercent = memberPercentMapper.getByLevelAndType(userLevel, 3);
//计算收益 //计算收益
double userTeamPerformance = listVo.get(i).getTeamPerformance().getMonthTeamPerformance().doubleValue(); double userTeamPerformance = teamPerformanceSortVo.getTeamPerformance().getMonthTeamPerformance().doubleValue();
double percent = memberPercent.getPercent().doubleValue(); double percent = memberPercent.getPercent().doubleValue();
double income = number * 3980 * percent * userTeamPerformance / total; double income = number * 3980 * percent * userTeamPerformance / total;
//获取账户信息 //获取账户信息
AccountInfo accountInfo = accountMapper.getByUserId(userId); AccountInfo accountInfo = accountMapper.getByUserId(userId);
BigDecimal bigDecimal; //用户月收益 =其他收益+最大进步奖收益
if (i == listVo.size() - 1) { BigDecimal earningsMonth = accountInfo.getEarningsMonth().add(BigDecimal.valueOf(income));
bigDecimal = new BigDecimal(total).subtract(sum); accountInfo.setEarningsMonth(earningsMonth);
//用户总收益 =其他总收益 + 最大进步奖收益
BigDecimal earningsTotal = accountInfo.getEarningsTotal().add(BigDecimal.valueOf(income));
accountInfo.setEarningsTotal(earningsTotal);
updateAccountList.add(accountInfo);
//最大进步奖信息
ProgressPrize progressPrize = progressPrizeMapper.getByUserIdYearMonth(userId, yearMonth);
if (null == progressPrize) {
//新增
ProgressPrize addPrize = new ProgressPrize();
addPrize.setAwardMoney(income);
addPrize.setYearMonth(yearMonth);
addPrize.setGrowthRate(0.0);
addPrize.setUserId(userId);
addList.add(addPrize);
} else { } else {
bigDecimal = accountInfo.getEarningsMonth().add(new BigDecimal(income)); progressPrize.setGrowthRate(teamPerformanceSortVo.getGrowthRate());
sum = sum.add(new BigDecimal(income)); progressPrize.setAwardMoney(income);
updateList.add(progressPrize);
} }
accountInfo.setEarningsMonth(bigDecimal);
updateAccountList.add(accountInfo);
} }
//判断本月是否有最大进步奖数据 无,新增 有,修改或删除 //获取本月存在的最大进步奖列表
Date date = new Date();
String yearMonth = DateUtil.convertDateToStr(date, PATTERN);
List<ProgressPrize> prizes = progressPrizeMapper.getByYearMonth(yearMonth); List<ProgressPrize> prizes = progressPrizeMapper.getByYearMonth(yearMonth);
//修改或保存最大进步奖信息 //修改或保存最大进步奖信息
// flag 1: 日定时任务 2:月定时任务 // flag 1: 日定时任务 2:月定时任务
int flag = 2; int flag = 2;
return accountManager.updateOrSavePrize(listVo, updateAccountList, prizes, flag); return accountManager.updateOrSavePrize(updateAccountList, prizes, addList, updateList, flag);
} }
} }
\ No newline at end of file
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