Просмотр исходного кода

[游戏发券]抽奖时设置券缓存

release_toaliyun_real
Gitea 6 лет назад
committed by Stormeye Wu
Родитель
Сommit
0e17245a5d
1 измененных файлов: 18 добавлений и 0 удалений
  1. +18
    -0
      mallinkService/src/main/java/com/iformall/service/impl/WxGameServiceImpl.java

+ 18
- 0
mallinkService/src/main/java/com/iformall/service/impl/WxGameServiceImpl.java Просмотреть файл

@@ -10,6 +10,7 @@ import com.iformall.common.ErrorCode;
import com.iformall.common.IdWorker;
import com.iformall.common.ResultData;
import com.iformall.domain.po.*;
import com.iformall.domain.vo.WxCouponCVo;
import com.iformall.domain.vo.WxCouponChannelVo;
import com.iformall.enums.EnumCouponChannelStatus;
import com.iformall.enums.EnumCouponChannelType;
@@ -24,11 +25,15 @@ import com.iformall.service.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import java.util.concurrent.TimeUnit;

@Service
public class WxGameServiceImpl implements WxGameService {
@@ -58,6 +63,10 @@ public class WxGameServiceImpl implements WxGameService {
@Autowired
private QrCodeService qrCodeService;

@Autowired
@Qualifier("couponDetailRedisTemplate")
RedisTemplate<String, WxCouponCVo> cdRedisTemplate;

@Override
public PageInfo<WxGame> listAsPage(WxGame record, Integer pageIndex, Integer pageSize) {
PageInfo<WxGame> page = PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxGameMapper.findList(record));
@@ -176,6 +185,7 @@ public class WxGameServiceImpl implements WxGameService {
// get game's coupon
List couponIdsList = new ArrayList();
JSONArray couponChannelIds = JSON.parseArray(record.getCouponIds());
ValueOperations<String, WxCouponCVo> operations = cdRedisTemplate.opsForValue();
for(int i=0; i<couponChannelIds.size();i++) {
JSONObject couponChanObj = (JSONObject) couponChannelIds.get(i);
Long couponId = couponChanObj.getLong("couponId");
@@ -184,6 +194,14 @@ public class WxGameServiceImpl implements WxGameService {
if (couponChannelVo != null) {
couponChannelVo.setGameWeight(couponChanObj.getInteger("weight"));
couponIdsList.add(couponChannelVo);
String key = "cc:" + couponChannelVo.getId();
if (!cdRedisTemplate.hasKey(key)) {
WxCouponCVo couponCVo = wxCouponChannelService.findVoStatusDetail(couponChannelVo.getId());
if(Objects.nonNull(couponCVo)) {
// 插入缓存
operations.set(key, couponCVo, 3600, TimeUnit.SECONDS);
}
}
}
}



Загрузка…
Отмена
Сохранить