Commit e6edc2de authored by licc's avatar licc

月度肥料接口自测优化2

parent 5628e33e
......@@ -94,11 +94,22 @@ public class AccountManager {
}
@Transactional(rollbackFor = Exception.class)
public void updateAccountPerformanceMonth(List<TeamPerformance> list) {
for (TeamPerformance teamPerformance : list) {
public void updateAccountPerformanceMonth(List<TeamPerformance> addList, List<TeamPerformance> updateList) {
//1、新增
if (!CollectionUtils.isEmpty(addList)) {
for (TeamPerformance teamPerformance : addList) {
teamPerformanceMapper.add(teamPerformance);
}
}
//2、更新
if (!CollectionUtils.isEmpty(updateList)) {
for (TeamPerformance teamPerformance : updateList) {
teamPerformanceMapper.edit(teamPerformance);
}
}
}
/**
* 修改 或新增 删除 最大进步奖实体类
......
......@@ -151,51 +151,62 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
totalMoney = totalMoney.add(orderInfo.getPayment());
}
//累计用户和上级用户-团队业绩
Map<String, Double> tempMap = new HashMap<>();
//遍历订单
for (Map.Entry<String, Double> entity : map.entrySet()) {
List<TeamPerformance> teamPerformances = new ArrayList<>();
//获取用户信息
User user = usersMapper.getByUserId(entity.getKey());
if (null == user) {
continue;
}
String userId = entity.getKey();
//1)、统计当前用户月度业绩
double userCount = entity.getValue();
tempMap.put(userId, userCount);
//获取团队业绩信息
TeamPerformance teamPerformance = teamPerformanceMapper.getByUserIdAndTime(user.getUserId(), yearMonth);
if (null == teamPerformance) {
continue;
}
//1、统计当前用户月度业绩
BigDecimal userCount = BigDecimal.valueOf(entity.getValue());
teamPerformance.setMonthTeamPerformance(userCount);
teamPerformances.add(teamPerformance);
//2、获取当前用户的上级用户列表 todo 邀请码等于一个固定值,停止 等于两个值 七位XXXXXXX 和 7777777
List<User> userList = getByList(user.getUserId());
//2)、获取当前用户的上级用户列表
List<User> userList = getByList(userId);
if (CollectionUtils.isEmpty(userList)) {
//更新当前用户月度业绩
accountManager.updateAccountPerformanceMonth(teamPerformances);
continue;
}
for (User userInfo : userList) {
//3、统计当前用户上级月度绩效
TeamPerformance team = teamPerformanceMapper.getByUserIdAndTime(userInfo.getUserId(), yearMonth);
if (null == team) {
continue;
//3)、统计当前用户的上级用户团队绩效
//key 存在 当前用户团队绩效 + 上级用户团队绩效
if (tempMap.containsKey(userInfo.getUserId())) {
double teamMoney = userCount + map.get(userInfo.getUserId());
map.put(userInfo.getUserId(), teamMoney);
} else {
//key 不存在,加入集合 当前用户团队绩效
map.put(userInfo.getUserId(), userCount);
}
}
//1、统计当前用户月度绩效
BigDecimal monthCount = team.getMonthTeamPerformance().add(userCount);
log.info("当前用户月度绩效:" + monthCount);
team.setMonthTeamPerformance(monthCount);
teamPerformances.add(team);
}
//4、更新账户月度绩效
accountManager.updateAccountPerformanceMonth(teamPerformances);
//3、获取用户当月绩效信息 新增 or 更新
List<TeamPerformance> addList = new ArrayList<>();
List<TeamPerformance> updateList = new ArrayList<>();
for (Map.Entry<String, Double> entity : tempMap.entrySet()) {
//获取团队业绩信息
TeamPerformance teamPerformance = teamPerformanceMapper.getByUserIdAndTime(entity.getKey(), yearMonth);
if (null == teamPerformance) {
//获取用户信息
User user = usersMapper.getByUserId(entity.getKey());
//添加用户团队业绩信息
TeamPerformance performance = new TeamPerformance();
performance.setUserId(user.getUserId());
performance.setMonthTeamPerformance(BigDecimal.valueOf(entity.getValue()));
performance.setUserLevel(user.getUserLevel());
performance.setYearMonth(yearMonth);
teamPerformanceMapper.add(performance);
addList.add(performance);
} else {
teamPerformance.setMonthTeamPerformance(BigDecimal.valueOf(entity.getValue()));
updateList.add(teamPerformance);
}
}
//4、更新账户月度绩效
accountManager.updateAccountPerformanceMonth(addList, updateList);
//5、获取所有用户,如果会员等级是黄金以上,计算月度收益
List<User> userList = usersMapper.getAllGoldUser();
if (CollectionUtils.isEmpty(userList)) {
......
......@@ -84,61 +84,84 @@ public class MonthTaskServiceImpl implements MonthTaskService {
Date date = new Date();
String yearMonth = DateUtil.convertDateToStr(date, PATTERN);
//计算月所有订单成交额
//计算月所有订单成交额
BigDecimal totalMoney = new BigDecimal(0);
for (OrderInfo orderInfo : list) {
//判断是否是本月
boolean bool = publicManager.isThisMonth(orderInfo.getCreateTime(), PATTERN);
if (bool && orderInfo.getMonthlyTaskStatus() == 0) {
totalMoney = totalMoney.add(orderInfo.getPayment());
}
}
//遍历订单 订单状态创建时间,当月时间小于当前时间
//统计出出每个用户上月订单成交额 key:userId value:用户上月订单成交额
Map<String, Double> map = new HashMap<>();
for (OrderInfo orderInfo : list) {
long createTime = orderInfo.getCreated().getTime();
long time = System.currentTimeMillis();
String userId = orderInfo.getBuyerId();
double payMoney = orderInfo.getPayment().doubleValue();
//获取用户信息
User user = usersMapper.selectById(orderInfo.getBuyerId());
if (null == user) {
continue;
//key 存在 累加订单金额 到 value
if (map.containsKey(userId)) {
double money = payMoney + map.get(orderInfo.getBuyerId());
map.put(orderInfo.getBuyerId(), money);
} else {
//key 不存在,加入集合
map.put(userId, payMoney);
}
List<TeamPerformance> teamPerformances = new ArrayList<>();
//获取团队业绩信息
TeamPerformance teamPerformance = teamPerformanceMapper.getByUserIdAndTime(user.getUserId(), yearMonth);
if (null == teamPerformance) {
continue;
//累加所以订单成交额
totalMoney = totalMoney.add(orderInfo.getPayment());
}
//1、统计当前用户月度业绩
BigDecimal userCount = teamPerformance.getMonthTeamPerformance().add(orderInfo.getPayment());
teamPerformance.setMonthTeamPerformance(userCount);
teamPerformances.add(teamPerformance);
//累计用户和上级用户-团队业绩
Map<String, Double> tempMap = new HashMap<>();
//2、获取当前用户的上级用户列表 todo 邀请码等于一个固定值,停止 等于两个值 七位XXXXXXX 和 7777777
List<User> userList = accountService.getByList(user.getUserId());
//遍历订单
for (Map.Entry<String, Double> entity : map.entrySet()) {
String userId = entity.getKey();
//1)、统计当前用户月度业绩
double userCount = entity.getValue();
tempMap.put(userId, userCount);
//2)、获取当前用户的上级用户列表
List<User> userList = accountService.getByList(userId);
if (CollectionUtils.isEmpty(userList)) {
continue;
}
//3、统计当前用户上级月度绩效
for (User userInfo : userList) {
TeamPerformance team = teamPerformanceMapper.getByUserIdAndTime(userInfo.getUserId(), yearMonth);
if (null == team) {
continue;
//3)、统计当前用户的上级用户团队绩效
//key 存在 当前用户团队绩效 + 上级用户团队绩效
if (tempMap.containsKey(userInfo.getUserId())) {
double teamMoney = userCount + map.get(userInfo.getUserId());
map.put(userInfo.getUserId(), teamMoney);
} else {
//key 不存在,加入集合 当前用户团队绩效
map.put(userInfo.getUserId(), userCount);
}
}
//1)、统计当前用户月度绩效
BigDecimal monthCount = team.getMonthTeamPerformance().add(orderInfo.getPayment());
team.setMonthTeamPerformance(monthCount);
teamPerformances.add(team);
}
//4、更新账户月度绩效
accountManager.updateAccountPerformanceMonth(teamPerformances);
//3、获取用户上月绩效信息 新增 or 更新
List<TeamPerformance> addList = new ArrayList<>();
List<TeamPerformance> updateList = new ArrayList<>();
for (Map.Entry<String, Double> entity : tempMap.entrySet()) {
//获取团队业绩信息
TeamPerformance teamPerformance = teamPerformanceMapper.getByUserIdAndTime(entity.getKey(), yearMonth);
if (null == teamPerformance) {
//获取用户信息
User user = usersMapper.getByUserId(entity.getKey());
//添加用户团队业绩信息
TeamPerformance performance = new TeamPerformance();
performance.setUserId(user.getUserId());
performance.setMonthTeamPerformance(BigDecimal.valueOf(entity.getValue()));
performance.setUserLevel(user.getUserLevel());
performance.setYearMonth(yearMonth);
teamPerformanceMapper.add(performance);
addList.add(performance);
} else {
teamPerformance.setMonthTeamPerformance(BigDecimal.valueOf(entity.getValue()));
updateList.add(teamPerformance);
}
}
//4、更新账户月度绩效
accountManager.updateAccountPerformanceMonth(addList, updateList);
//5、获取所有用户,如果会员等级是黄金以上,计算月度收益
List<User> userList = usersMapper.getAllGoldUser();
if (CollectionUtils.isEmpty(userList)) {
......@@ -153,7 +176,7 @@ public class MonthTaskServiceImpl implements MonthTaskService {
return R.ok(0, true);
}
//7、计算收益
//6、计算收益
boolean bool = monthlyIncome(totalMoney, userList);
if (!bool) {
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