Commit a7f87f32 by 吕明尚

Merge branch 'dev' into test

parents b060b896 f20c071f
......@@ -35,6 +35,7 @@ import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
......@@ -594,22 +595,19 @@ public class RedisTask {
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进行分组
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 -> {
List<MemberProgressLog> memberProgressLogs = collect.get(item);
if (memberProgressLogs.size() > 0) {
//查询会员
ConsumerMember consumerMember = consumerMemberMap.get(item);
;
if (consumerMember.getMembershipProgress().equals(BigDecimal.ZERO)) {
//结束此次循环
return;
}
//查询会员配置
MemberConfig memberConfig = memberConfigMap.get(consumerMember.getMembershipLevel());
final BigDecimal[] sum = {BigDecimal.ZERO};
//计算扣除进度
memberProgressLogs.stream().forEach(log -> {
......@@ -627,17 +625,31 @@ public class RedisTask {
//判断会员进度是否大于扣除进度
} else if (consumerMember.getMembershipProgress().compareTo(sum[0].abs()) >= 0) {
//会员进度减去扣除进度
BigDecimal subtract = BigDecimal.ZERO;
if (sum[0].compareTo(BigDecimal.ZERO) < 0) {
subtract = consumerMember.getMembershipProgress().add(sum[0]);
} else if (sum[0].compareTo(BigDecimal.ZERO) > 0) {
subtract = consumerMember.getMembershipProgress().subtract(sum[0]);
}
consumerMember.setMembershipProgress(subtract);
if (consumerMember.getMembershipProgress().compareTo(BigDecimal.valueOf(memberConfig.getLimitRequirements())) < 0) {
BigDecimal subtract = consumerMember.getMembershipProgress().subtract(sum[0]);
// consumerMember.setMembershipProgress(subtract);
// if (consumerMember.getMembershipProgress().compareTo(BigDecimal.valueOf(memberConfig.getLimitRequirements())) < 0) {
//等级降一级
if (consumerMember.getMembershipLevel() > 0L) {
consumerMember.setMembershipLevel(consumerMember.getMembershipLevel() - 1);
// if (consumerMember.getMembershipLevel() > 0L) {
// consumerMember.setMembershipLevel(consumerMember.getMembershipLevel() - 1);
// }
//转Map limitRequirements,MemberConfig
Map<Long, MemberConfig> configMap = memberConfigService.list(new LambdaQueryWrapper<MemberConfig>()
.orderByDesc(MemberConfig::getMembershipLevel)).stream().collect(Collectors.toMap(MemberConfig::getMembershipLevel, Function.identity()));
//Map根
//判断subtract小于当前等级的积分,并大于下一等级的积分
for (Map.Entry<Long, MemberConfig> entry : configMap.entrySet()) {
if (subtract.compareTo(BigDecimal.valueOf(entry.getValue().getLimitRequirements())) > 0 &&
subtract.compareTo(BigDecimal.valueOf(configMap.get(entry.getKey() + 1).getLimitRequirements())) <= 0
&& entry.getKey().compareTo(Collections.min(configMap.keySet())) > 0) {
consumerMember.setMembershipLevel(entry.getKey());
consumerMember.setMembershipProgress(subtract);
updateList.add(consumerMember);
return;
} else if (subtract.compareTo(BigDecimal.valueOf(configMap.get(Collections.min(configMap.keySet())).getLimitRequirements())) <= 0) {
consumerMember.setMembershipLevel(Collections.min(configMap.keySet()));
consumerMember.setMembershipProgress(subtract);
updateList.add(consumerMember);
return;
}
}
}
......
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