|
|
|
@@ -1,18 +1,24 @@
|
|
|
|
|
package com.accompany.business.service.medal.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.accompany.business.constant.MedalConstant;
|
|
|
|
|
import com.accompany.business.model.UserMedal;
|
|
|
|
|
import com.accompany.business.model.medal.Medal;
|
|
|
|
|
import com.accompany.business.mybatismapper.medal.UserMedalMapper;
|
|
|
|
|
import com.accompany.business.service.BaseSendService;
|
|
|
|
|
import com.accompany.business.service.medal.MedalRecordService;
|
|
|
|
|
import com.accompany.business.service.medal.MedalService;
|
|
|
|
|
import com.accompany.business.service.medal.UserMedalService;
|
|
|
|
|
import com.accompany.business.util.VipUtil;
|
|
|
|
|
import com.accompany.business.vo.medal.UserDetailMedalVo;
|
|
|
|
|
import com.accompany.business.vo.medal.UserMedalVo;
|
|
|
|
|
import com.accompany.common.constant.Constant;
|
|
|
|
|
import com.accompany.common.status.BusiStatus;
|
|
|
|
|
import com.accompany.common.utils.DateTimeUtil;
|
|
|
|
|
import com.accompany.common.utils.StringUtils;
|
|
|
|
|
import com.accompany.core.enumeration.I18nAlertEnum;
|
|
|
|
|
import com.accompany.core.exception.ServiceException;
|
|
|
|
|
import com.accompany.core.util.I18NMessageSourceUtil;
|
|
|
|
|
import com.accompany.core.vo.BaseMedalVo;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
@@ -21,7 +27,6 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
|
|
import org.redisson.api.RBucket;
|
|
|
|
|
import org.redisson.api.RList;
|
|
|
|
|
import org.redisson.api.RedissonClient;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
@@ -32,7 +37,6 @@ import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import static com.accompany.business.constant.MedalConstant.RedisKey.user_use_medal;
|
|
|
|
|
import static java.util.Collections.EMPTY_LIST;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author: liaozetao
|
|
|
|
@@ -49,6 +53,8 @@ public class UserMedalServiceImpl extends ServiceImpl<UserMedalMapper, UserMedal
|
|
|
|
|
private MedalRecordService medalRecordService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private RedissonClient redissonClient;
|
|
|
|
|
@Autowired
|
|
|
|
|
private BaseSendService baseSendService;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Long countValidMedal(Long uid) {
|
|
|
|
@@ -79,17 +85,18 @@ public class UserMedalServiceImpl extends ServiceImpl<UserMedalMapper, UserMedal
|
|
|
|
|
.eq(UserMedal::getUseStatus, Constant.StatusV2.valid)
|
|
|
|
|
.le(UserMedal::getCreateTime, now)
|
|
|
|
|
.ge(UserMedal::getExpireTime, now)
|
|
|
|
|
.orderByDesc(UserMedal::getUseTime));
|
|
|
|
|
.orderByAsc(UserMedal::getUseTime));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<BaseMedalVo> loadAndCacheMedals(Long uid, Integer medalSeatNum) {
|
|
|
|
|
List<BaseMedalVo> baseMedalVos = new ArrayList<>();
|
|
|
|
|
try {
|
|
|
|
|
RBucket<String> cacheUseMedal = this.cacheUseMedal(uid);
|
|
|
|
|
String s = cacheUseMedal.get();
|
|
|
|
|
List<BaseMedalVo> baseMedalVos;
|
|
|
|
|
if (StringUtils.isNotEmpty(s)) {
|
|
|
|
|
if ("[]".equals(s)) {
|
|
|
|
|
return EMPTY_LIST;
|
|
|
|
|
return baseMedalVos;
|
|
|
|
|
}
|
|
|
|
|
baseMedalVos = JSONObject.parseObject(s, List.class);
|
|
|
|
|
} else {
|
|
|
|
@@ -97,7 +104,7 @@ public class UserMedalServiceImpl extends ServiceImpl<UserMedalMapper, UserMedal
|
|
|
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(userMedals)) {
|
|
|
|
|
cacheUseMedal.set("[]", Duration.ofDays(7));
|
|
|
|
|
return EMPTY_LIST;
|
|
|
|
|
return baseMedalVos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<Integer> medalIds = userMedals.stream().map(UserMedal::getMedalId).collect(Collectors.toList());
|
|
|
|
@@ -118,6 +125,9 @@ public class UserMedalServiceImpl extends ServiceImpl<UserMedalMapper, UserMedal
|
|
|
|
|
if (baseMedalVos.size() > medalSeatNum) {
|
|
|
|
|
return baseMedalVos.subList(0, medalSeatNum);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("UserMedalServiceImpl.loadAndCacheMedals,uid:{},e:{}", uid, e.getMessage(), e);
|
|
|
|
|
}
|
|
|
|
|
return baseMedalVos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -209,6 +219,61 @@ public class UserMedalServiceImpl extends ServiceImpl<UserMedalMapper, UserMedal
|
|
|
|
|
return redissonClient.getBucket(user_use_medal.getKey(uid));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void doExpireCheck() {
|
|
|
|
|
Date now = new Date();
|
|
|
|
|
List<UserMedal> expireList = list(Wrappers.<UserMedal>lambdaQuery()
|
|
|
|
|
.eq(UserMedal::getMedalStatus, Constant.StatusV2.valid)
|
|
|
|
|
.lt(UserMedal::getExpireTime, now));
|
|
|
|
|
if (CollectionUtils.isEmpty(expireList)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
for (UserMedal userMedal : expireList) {
|
|
|
|
|
userMedal.setMedalStatus(Constant.StatusV2.invalid);
|
|
|
|
|
userMedal.setUseStatus(Constant.StatusV2.invalid);
|
|
|
|
|
userMedal.setUpdateTime(new Date());
|
|
|
|
|
}
|
|
|
|
|
updateBatchById(expireList);
|
|
|
|
|
for (UserMedal userMedal : expireList) {
|
|
|
|
|
Long uid = userMedal.getUid();
|
|
|
|
|
this.cacheUseMedal(uid).delete();
|
|
|
|
|
Medal medal = medalService.getById(userMedal.getMedalId());
|
|
|
|
|
String name = I18NMessageSourceUtil.getMessage(Medal.class.getSimpleName() + StrUtil.DOT + medal.getName(), medal.getName(), uid);
|
|
|
|
|
String message = I18NMessageSourceUtil.getMessage(I18nAlertEnum.MEDAL_EXPIRE_MSG, new Object[]{name}, uid);
|
|
|
|
|
baseSendService.sendsecretaryMsg(userMedal.getUid(), message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void vipExpireCheck(Long uid) {
|
|
|
|
|
List<UserMedal> userMedals = this.listUseMedal(uid);
|
|
|
|
|
if (CollectionUtils.isEmpty(userMedals)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Integer vipLevel = VipUtil.getVipLevel(uid);
|
|
|
|
|
String vipAuthItemValue = VipUtil.getVipAuthItemValue(vipLevel, Constant.VipAuthType.MEDAL_SEAT);
|
|
|
|
|
Integer medalSeatNum = Optional.ofNullable(vipAuthItemValue)
|
|
|
|
|
.map(Integer::valueOf)
|
|
|
|
|
.orElse(MedalConstant.MEDAL_SEAT_LIMIT);
|
|
|
|
|
|
|
|
|
|
int size = userMedals.size();
|
|
|
|
|
if (size <= medalSeatNum) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
List<UserMedal> updateList = new ArrayList<>();
|
|
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
|
|
if (i < medalSeatNum) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
UserMedal userMedal = userMedals.get(i);
|
|
|
|
|
userMedal.setUseStatus(Constant.StatusV2.invalid);
|
|
|
|
|
userMedal.setUpdateTime(new Date());
|
|
|
|
|
updateList.add(userMedal);
|
|
|
|
|
}
|
|
|
|
|
updateBatchById(updateList);
|
|
|
|
|
this.loadAndCacheMedals(uid, medalSeatNum);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private UserDetailMedalVo transUserMedal2Vo(List<UserMedal> userMedalList, Long uid) {
|
|
|
|
|
List<Integer> medalIdList = userMedalList.stream().map(UserMedal::getMedalId)
|
|
|
|
|