Commit e3d95941 by 吕明尚

会员进度日志表增加过期时间

parent f677c315
...@@ -24,6 +24,7 @@ import share.common.constant.MqttConstants; ...@@ -24,6 +24,7 @@ import share.common.constant.MqttConstants;
import share.common.core.redis.RedisUtil; import share.common.core.redis.RedisUtil;
import share.common.enums.*; import share.common.enums.*;
import share.common.exception.base.BaseException; import share.common.exception.base.BaseException;
import share.common.utils.DateUtils;
import share.system.domain.*; import share.system.domain.*;
import share.system.domain.vo.MqttxVo; import share.system.domain.vo.MqttxVo;
import share.system.service.*; import share.system.service.*;
...@@ -92,6 +93,15 @@ public class RedisTask { ...@@ -92,6 +93,15 @@ public class RedisTask {
@Autowired @Autowired
private SConsumerTokenService sConsumerTokenService; private SConsumerTokenService sConsumerTokenService;
@Autowired
private ConsumerMemberService consumerMemberService;
@Autowired
private ConsumerWalletService consumerWalletService;
@Autowired
private MemberProgressLogService memberProgressLogService;
//15分钟的常量 //15分钟的常量
final long FIFTEEN_MINUTES = 60 * 15; final long FIFTEEN_MINUTES = 60 * 15;
...@@ -103,8 +113,8 @@ public class RedisTask { ...@@ -103,8 +113,8 @@ public class RedisTask {
final long FOUR_MINUTES = 60 * 4; final long FOUR_MINUTES = 60 * 4;
//1分钟的常量 //1分钟的常量
final long ONE_MINUTES = 60; final long ONE_MINUTES = 60;
final long FOUR_DAY = 60 * 24 * 4;
final long THREE_DAY = 60 * 24 * 3; final long THREE_DAY = 60 * 24 * 3;
final long TWO_DAY = 60 * 24 * 2;
/** /**
...@@ -459,7 +469,7 @@ public class RedisTask { ...@@ -459,7 +469,7 @@ public class RedisTask {
}); });
} }
public void AutoEquityMembers() { public void AutoEquityMembersSms() {
Set<String> keys = redisTemplate.keys(ReceiptRdeisEnum.EQUITY_MEMBERS_TIME + "*"); Set<String> keys = redisTemplate.keys(ReceiptRdeisEnum.EQUITY_MEMBERS_TIME + "*");
if (keys.size() == 0) { if (keys.size() == 0) {
return; return;
...@@ -471,13 +481,71 @@ public class RedisTask { ...@@ -471,13 +481,71 @@ public class RedisTask {
Long consumerId = jsonObject.getLong("consumerId"); Long consumerId = jsonObject.getLong("consumerId");
//判断当前的日期是否在第3天和第2天中 //判断当前的日期是否在第3天和第2天中
long expire = (expirationTime.getTime() - new Date().getTime()) / 1000 / 60 / 60; long expire = (expirationTime.getTime() - new Date().getTime()) / 1000 / 60 / 60;
if (TWO_DAY < expire && expire < THREE_DAY) { if (THREE_DAY < expire && expire < FOUR_DAY) {
SConsumer sConsumer = sConsumerService.getById(consumerId); SConsumer sConsumer = sConsumerService.getById(consumerId);
logger.debug("手机号为:{}的用户年度权益会员将在3天后失效", sConsumer.getPhone());
smsService.sendOneSms(sConsumer.getPhone(), "年度权益会员将在3天后失效,请及时续约保障权益会员的权益"); smsService.sendOneSms(sConsumer.getPhone(), "年度权益会员将在3天后失效,请及时续约保障权益会员的权益");
} }
}); });
} }
//权益会员降级
public void AutoUpdateEquityMembers() {
Set<String> keys = redisTemplate.keys(ReceiptRdeisEnum.EQUITY_MEMBERS_TIME + "*");
if (keys.size() == 0) {
return;
}
keys.stream().forEach(key -> {
String value = redisUtil.get(String.valueOf(key));
JSONObject jsonObject = new JSONObject(value);
Date expirationTime = jsonObject.getDate("expirationTime");
Long consumerId = jsonObject.getLong("consumerId");
if (expirationTime.getTime() < new Date().getTime()) {
ConsumerWallet consumerWallet = consumerWalletService.getOne(new LambdaQueryWrapper<ConsumerWallet>().eq(ConsumerWallet::getConsumerId, consumerId));
ConsumerMember consumerMember = consumerMemberService.getOne(new LambdaQueryWrapper<ConsumerMember>().eq(ConsumerMember::getConsumerId, consumerId));
if (ObjectUtil.isNotEmpty(consumerWallet)) {
consumerMember.setMemberType(MemberTypeEnum.RECHARGE.getIndex());
} else {
consumerMember.setMemberType(MemberTypeEnum.NORMAL.getIndex());
}
consumerMemberService.updateConsumerMember(consumerMember);
}
});
}
public void AutoProgressLog() {
//查询1年之前的数据
List<MemberProgressLog> list = memberProgressLogService.list(new LambdaQueryWrapper<MemberProgressLog>()
.gt(MemberProgressLog::getCreateTime, DateUtils.addYears(new Date(), -1))
);
list.sort(Comparator.comparing(MemberProgressLog::getOperationType).reversed());
//获得list的consumerId
List<Long> consumerIds = list.stream().map(MemberProgressLog::getConsumerId).distinct().collect(Collectors.toList());
//按照consumerId进行分组
Map<Long, List<MemberProgressLog>> collect = list.stream().collect(Collectors.groupingBy(MemberProgressLog::getConsumerId));
consumerIds.stream().forEach(item -> {
List<MemberProgressLog> memberProgressLogs = collect.get(item);
if (memberProgressLogs.size() > 1) {
final BigDecimal[] sum = {new BigDecimal(100)};
memberProgressLogs.stream().forEach(log -> {
if (log.getOperationType().equals(YesNoEnum.yes.getIndex())) {
sum[0] = sum[0].subtract(log.getVariableProgress());
} else if (log.getOperationType().equals(YesNoEnum.no.getIndex())) {
sum[0] = sum[0].add(log.getVariableProgress());
}
});
sum[0].subtract(new BigDecimal(100));
ConsumerMember consumerMember = consumerMemberService.getOne(new LambdaQueryWrapper<ConsumerMember>().eq(ConsumerMember::getConsumerId, item));
if (consumerMember.getMembershipProgress().compareTo(sum[0]) >= 0) {
consumerMember.setMembershipProgress(consumerMember.getMembershipProgress().subtract(sum[0]));
consumerMemberService.updateConsumerMember(consumerMember);
}
}
});
}
public void AutoAddRoomLabel() { public void AutoAddRoomLabel() {
List<RoomLabel> roomLabelList = roomLabelService.list(); List<RoomLabel> roomLabelList = roomLabelService.list();
//获取roomLabelList中的roomId,去重 //获取roomLabelList中的roomId,去重
......
...@@ -3,8 +3,6 @@ package share.system.domain; ...@@ -3,8 +3,6 @@ package share.system.domain;
import com.baomidou.mybatisplus.annotation.*; import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data; import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import share.common.annotation.Excel; import share.common.annotation.Excel;
import share.common.core.domain.BaseEntity; import share.common.core.domain.BaseEntity;
...@@ -59,6 +57,11 @@ public class MemberProgressLog extends BaseEntity { ...@@ -59,6 +57,11 @@ public class MemberProgressLog extends BaseEntity {
@Excel(name = "操作时间", width = 30, dateFormat = "yyyy-MM-dd") @Excel(name = "操作时间", width = 30, dateFormat = "yyyy-MM-dd")
private Date operationTime; private Date operationTime;
//过期时间
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "过期时间", width = 30, dateFormat = "yyyy-MM-dd")
private Date expirationTime;
/** /**
* 是否删除 * 是否删除
*/ */
...@@ -67,22 +70,4 @@ public class MemberProgressLog extends BaseEntity { ...@@ -67,22 +70,4 @@ public class MemberProgressLog extends BaseEntity {
@TableField(select = false) @TableField(select = false)
private Long isDelete; private Long isDelete;
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("consumerId", getConsumerId())
.append("variableProgress", getVariableProgress())
.append("currentProgress", getCurrentProgress())
.append("operationType", getOperationType())
.append("operationTime", getOperationTime())
.append("isDelete", getIsDelete())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.append("remark", getRemark())
.toString();
}
} }
...@@ -129,6 +129,8 @@ public class ConsumerWalletServiceImpl extends ServiceImpl<ConsumerWalletMapper, ...@@ -129,6 +129,8 @@ public class ConsumerWalletServiceImpl extends ServiceImpl<ConsumerWalletMapper,
@Override @Override
public boolean addConsumerWallet(ConsumerWallet consumerWallet) { public boolean addConsumerWallet(ConsumerWallet consumerWallet) {
int i = consumerWalletMapper.insertConsumerWallet(consumerWallet); int i = consumerWalletMapper.insertConsumerWallet(consumerWallet);
ConsumerMember one = consumerMemberService.getOne(new LambdaQueryWrapper<ConsumerMember>().eq(ConsumerMember::getConsumerId, consumerWallet.getConsumerId()));
MemberConfig memberConfig = memberConfigService.getById(one.getMemberConfigId());
if (consumerWallet.getBalance().compareTo(new BigDecimal(0)) > 0) { if (consumerWallet.getBalance().compareTo(new BigDecimal(0)) > 0) {
BalanceLog balanceLog = new BalanceLog(); BalanceLog balanceLog = new BalanceLog();
balanceLog.setConsumerId(consumerWallet.getConsumerId()); balanceLog.setConsumerId(consumerWallet.getConsumerId());
...@@ -165,6 +167,7 @@ public class ConsumerWalletServiceImpl extends ServiceImpl<ConsumerWalletMapper, ...@@ -165,6 +167,7 @@ public class ConsumerWalletServiceImpl extends ServiceImpl<ConsumerWalletMapper,
memberProgressLog.setOperationTime(new Date()); memberProgressLog.setOperationTime(new Date());
memberProgressLog.setOperationType(YesNoEnum.yes.getIndex()); memberProgressLog.setOperationType(YesNoEnum.yes.getIndex());
memberProgressLog.setCreateTime(new Date()); memberProgressLog.setCreateTime(new Date());
memberProgressLog.setExpirationTime(DateUtils.addYears(new Date(), memberConfig.getValidityPeriod().intValue()));
memberProgressLogService.save(memberProgressLog); memberProgressLogService.save(memberProgressLog);
} }
return i == 1; return i == 1;
...@@ -194,7 +197,18 @@ public class ConsumerWalletServiceImpl extends ServiceImpl<ConsumerWalletMapper, ...@@ -194,7 +197,18 @@ public class ConsumerWalletServiceImpl extends ServiceImpl<ConsumerWalletMapper,
} }
int i = updateConsumerWallet(consumerWallet); int i = updateConsumerWallet(consumerWallet);
//查询当前会员类型和下一级的会员配置
MemberConfig memberConfigServiceOne = memberConfigService.getOne(new LambdaQueryWrapper<MemberConfig>()
.eq(MemberConfig::getMemberType, one.getMemberType())
.eq(MemberConfig::getMembershipLevel, one.getMembershipLevel() + 1L));
if (ObjectUtil.isNotEmpty(memberConfigServiceOne)) {
//判断是否升级
if (one.getMembershipProgress().compareTo(BigDecimal.valueOf(memberConfigServiceOne.getLimitRequirements())) >= 0) {
one.setMembershipLevel(one.getMembershipLevel() + 1L);
one.setMemberConfigId(one.getId());
}
}
if (consumerWallet.getBalance().compareTo(new BigDecimal(0)) > 0) { if (consumerWallet.getBalance().compareTo(new BigDecimal(0)) > 0) {
BalanceLog balanceLog = new BalanceLog(); BalanceLog balanceLog = new BalanceLog();
balanceLog.setConsumerId(consumerWallet.getConsumerId()); balanceLog.setConsumerId(consumerWallet.getConsumerId());
...@@ -234,21 +248,11 @@ public class ConsumerWalletServiceImpl extends ServiceImpl<ConsumerWalletMapper, ...@@ -234,21 +248,11 @@ public class ConsumerWalletServiceImpl extends ServiceImpl<ConsumerWalletMapper,
memberProgressLog.setOperationTime(new Date()); memberProgressLog.setOperationTime(new Date());
memberProgressLog.setOperationType(YesNoEnum.yes.getIndex()); memberProgressLog.setOperationType(YesNoEnum.yes.getIndex());
memberProgressLog.setCreateTime(new Date()); memberProgressLog.setCreateTime(new Date());
memberProgressLog.setExpirationTime(DateUtils.addYears(new Date(), memberConfigService.getById(one.getConsumerId()).getValidityPeriod().intValue()));
memberProgressLogService.save(memberProgressLog); memberProgressLogService.save(memberProgressLog);
one.setMembershipProgress(one.getMembershipProgress().add(divide)); one.setMembershipProgress(one.getMembershipProgress().add(divide));
} }
//查询当前会员类型和下一级的会员配置
MemberConfig memberConfigServiceOne = memberConfigService.getOne(new LambdaQueryWrapper<MemberConfig>()
.eq(MemberConfig::getMemberType, one.getMemberType())
.eq(MemberConfig::getMembershipLevel, one.getMembershipLevel() + 1L));
if (ObjectUtil.isNotEmpty(memberConfigServiceOne)) {
//判断是否升级
if (one.getMembershipProgress().compareTo(BigDecimal.valueOf(memberConfigServiceOne.getLimitRequirements())) >= 0) {
one.setMembershipLevel(one.getMembershipLevel() + 1L);
one.setMemberConfigId(one.getId());
}
}
consumerMemberService.updateConsumerMember(one); consumerMemberService.updateConsumerMember(one);
return i == 1; return i == 1;
} }
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
<result property="currentProgress" column="current_progress"/> <result property="currentProgress" column="current_progress"/>
<result property="operationType" column="operation_type"/> <result property="operationType" column="operation_type"/>
<result property="operationTime" column="operation_time"/> <result property="operationTime" column="operation_time"/>
<result property="expirationTime" column="expiration_time"/>
<result property="isDelete" column="is_delete"/> <result property="isDelete" column="is_delete"/>
<result property="createBy" column="create_by"/> <result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/> <result property="createTime" column="create_time"/>
...@@ -29,6 +30,7 @@ ...@@ -29,6 +30,7 @@
current_progress, current_progress,
operation_type, operation_type,
operation_time, operation_time,
expiration_time,
is_delete, is_delete,
create_by, create_by,
create_time, create_time,
...@@ -48,6 +50,7 @@ ...@@ -48,6 +50,7 @@
m.current_progress, m.current_progress,
m.operation_type, m.operation_type,
m.operation_time, m.operation_time,
m.expiration_time,
m.is_delete, m.is_delete,
m.create_by, m.create_by,
m.create_time, m.create_time,
...@@ -82,6 +85,7 @@ ...@@ -82,6 +85,7 @@
<if test="currentProgress != null">current_progress,</if> <if test="currentProgress != null">current_progress,</if>
<if test="operationType != null">operation_type,</if> <if test="operationType != null">operation_type,</if>
<if test="operationTime != null">operation_time,</if> <if test="operationTime != null">operation_time,</if>
<if test="expirationTime != null">expiration_time,</if>
<if test="isDelete != null">is_delete,</if> <if test="isDelete != null">is_delete,</if>
<if test="createBy != null">create_by,</if> <if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if> <if test="createTime != null">create_time,</if>
...@@ -95,6 +99,7 @@ ...@@ -95,6 +99,7 @@
<if test="currentProgress != null">#{currentProgress},</if> <if test="currentProgress != null">#{currentProgress},</if>
<if test="operationType != null">#{operationType},</if> <if test="operationType != null">#{operationType},</if>
<if test="operationTime != null">#{operationTime},</if> <if test="operationTime != null">#{operationTime},</if>
<if test="expirationTime != null">#{expirationTime},</if>
<if test="isDelete != null">#{isDelete},</if> <if test="isDelete != null">#{isDelete},</if>
<if test="createBy != null">#{createBy},</if> <if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if> <if test="createTime != null">#{createTime},</if>
...@@ -112,6 +117,7 @@ ...@@ -112,6 +117,7 @@
<if test="currentProgress != null">current_progress = #{currentProgress},</if> <if test="currentProgress != null">current_progress = #{currentProgress},</if>
<if test="operationType != null">operation_type = #{operationType},</if> <if test="operationType != null">operation_type = #{operationType},</if>
<if test="operationTime != null">operation_time = #{operationTime},</if> <if test="operationTime != null">operation_time = #{operationTime},</if>
<if test="expirationTime != null">expiration_time = #{expirationTime},</if>
<if test="isDelete != null">is_delete = #{isDelete},</if> <if test="isDelete != null">is_delete = #{isDelete},</if>
<if test="createBy != null">create_by = #{createBy},</if> <if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if> <if test="createTime != null">create_time = #{createTime},</if>
......
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