Commit 5d4d2f19 by 吕明尚

优化会员等级滚动降级定时任务

parent cdc82d20
...@@ -694,19 +694,24 @@ public class RedisTask { ...@@ -694,19 +694,24 @@ public class RedisTask {
list.sort(Comparator.comparing(MemberProgressLog::getOperationType).reversed()); list.sort(Comparator.comparing(MemberProgressLog::getOperationType).reversed());
//获得list的consumerId //获得list的consumerId
List<Long> consumerIds = list.stream().map(MemberProgressLog::getConsumerId).distinct().collect(Collectors.toList()); List<Long> consumerIds = list.stream().map(MemberProgressLog::getConsumerId).distinct().collect(Collectors.toList());
Map<Long, ConsumerMember> consumerMemberMap = consumerMemberService.list(new LambdaQueryWrapper<ConsumerMember>().in(ConsumerMember::getConsumerId, consumerIds))
.stream().collect(Collectors.toMap(ConsumerMember::getConsumerId, item -> item));
//按照consumerId进行分组 //按照consumerId进行分组
Map<Long, List<MemberProgressLog>> collect = list.stream().collect(Collectors.groupingBy(MemberProgressLog::getConsumerId)); Map<Long, List<MemberProgressLog>> collect = list.stream().collect(Collectors.groupingBy(MemberProgressLog::getConsumerId));
Map<Long, MemberConfig> memberConfigMap = memberConfigService.list().stream().collect(Collectors.toMap(MemberConfig::getMembershipLevel, item -> item));
List<ConsumerMember> updateList = new ArrayList<>();
consumerIds.stream().forEach(item -> { consumerIds.stream().forEach(item -> {
List<MemberProgressLog> memberProgressLogs = collect.get(item); List<MemberProgressLog> memberProgressLogs = collect.get(item);
if (memberProgressLogs.size() > 0) { if (memberProgressLogs.size() > 0) {
//查询会员 //查询会员
ConsumerMember consumerMember = consumerMemberService.getOne(new LambdaQueryWrapper<ConsumerMember>().eq(ConsumerMember::getConsumerId, item)); ConsumerMember consumerMember = consumerMemberMap.get(item);
;
if (consumerMember.getMembershipProgress().equals(BigDecimal.ZERO)) { if (consumerMember.getMembershipProgress().equals(BigDecimal.ZERO)) {
//结束此次循环 //结束此次循环
return; return;
} }
//查询会员配置 //查询会员配置
MemberConfig memberConfig = memberConfigService.getOne(new LambdaQueryWrapper<MemberConfig>().eq(MemberConfig::getMembershipLevel, consumerMember.getMembershipLevel())); MemberConfig memberConfig = memberConfigMap.get(consumerMember.getMembershipLevel());
final BigDecimal[] sum = {BigDecimal.ZERO}; final BigDecimal[] sum = {BigDecimal.ZERO};
//计算扣除进度 //计算扣除进度
memberProgressLogs.stream().forEach(log -> { memberProgressLogs.stream().forEach(log -> {
...@@ -738,9 +743,10 @@ public class RedisTask { ...@@ -738,9 +743,10 @@ public class RedisTask {
} }
} }
} }
consumerMemberService.updateConsumerMember(consumerMember); updateList.add(consumerMember);
} }
}); });
if (!CollectionUtils.isEmpty(updateList)) consumerMemberService.updateBatchById(updateList);
logger.debug("AutoProgressLog:会员等级滚动降级结束"); logger.debug("AutoProgressLog:会员等级滚动降级结束");
} }
......
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