Commit fc72dcec by 吕明尚

修改滚动清除进度定时任务

parent 4c1f519d
......@@ -24,7 +24,6 @@ import share.common.constant.MqttConstants;
import share.common.core.redis.RedisUtil;
import share.common.enums.*;
import share.common.exception.base.BaseException;
import share.common.utils.DateUtils;
import share.system.domain.*;
import share.system.domain.vo.MqttxVo;
import share.system.service.*;
......@@ -102,6 +101,9 @@ public class RedisTask {
@Autowired
private MemberProgressLogService memberProgressLogService;
@Autowired
private MemberConfigService memberConfigService;
//15分钟的常量
final long FIFTEEN_MINUTES = 60 * 15;
......@@ -516,7 +518,7 @@ public class RedisTask {
public void AutoProgressLog() {
//查询1年之前的数据
List<MemberProgressLog> list = memberProgressLogService.list(new LambdaQueryWrapper<MemberProgressLog>()
.gt(MemberProgressLog::getCreateTime, DateUtils.addYears(new Date(), -1))
.gt(MemberProgressLog::getExpirationTime, new Date())
);
list.sort(Comparator.comparing(MemberProgressLog::getOperationType).reversed());
//获得list的consumerId
......@@ -526,7 +528,7 @@ public class RedisTask {
consumerIds.stream().forEach(item -> {
List<MemberProgressLog> memberProgressLogs = collect.get(item);
if (memberProgressLogs.size() > 1) {
final BigDecimal[] sum = {new BigDecimal(100)};
final BigDecimal[] sum = {BigDecimal.ZERO};
memberProgressLogs.stream().forEach(log -> {
if (log.getOperationType().equals(YesNoEnum.yes.getIndex())) {
sum[0] = sum[0].subtract(log.getVariableProgress());
......@@ -534,12 +536,25 @@ public class RedisTask {
sum[0] = sum[0].add(log.getVariableProgress());
}
});
sum[0].subtract(new BigDecimal(100));
ConsumerMember consumerMember = consumerMemberService.getOne(new LambdaQueryWrapper<ConsumerMember>().eq(ConsumerMember::getConsumerId, item));
MemberConfig memberConfig = memberConfigService.getById(consumerMember.getMemberConfigId());
if (consumerMember.getMembershipProgress().compareTo(sum[0]) >= 0) {
consumerMember.setMembershipProgress(consumerMember.getMembershipProgress().subtract(sum[0]));
consumerMemberService.updateConsumerMember(consumerMember);
BigDecimal subtract = consumerMember.getMembershipProgress().subtract(sum[0]);
consumerMember.setMembershipProgress(subtract);
if (subtract.compareTo(BigDecimal.valueOf(memberConfig.getLimitRequirements())) < 0) {
consumerMember.setMembershipLevel(memberConfig.getMembershipLevel() - 1);
MemberConfig memberConfigServiceOne = memberConfigService.getOne(new LambdaQueryWrapper<MemberConfig>()
.eq(MemberConfig::getMemberType, consumerMember.getMemberType())
.eq(MemberConfig::getMembershipLevel, consumerMember.getMembershipLevel())
);
consumerMember.setMemberConfigId(memberConfigServiceOne.getId());
}
} else {
consumerMember.setMembershipProgress(BigDecimal.ZERO);
consumerMember.setMembershipLevel(0L);
consumerMember.setMemberType(MemberTypeEnum.NORMAL.getIndex());
}
consumerMemberService.updateConsumerMember(consumerMember);
}
});
}
......
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