|
|
@@ -1,31 +1,34 @@
|
|
|
package com.fs.app.facade.impl;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
-import cn.hutool.core.thread.ThreadUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
-import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
import com.fs.app.facade.LiveFacadeService;
|
|
|
+import com.fs.app.vo.LiveVo;
|
|
|
import com.fs.common.constant.LiveKeysConstant;
|
|
|
import com.fs.common.core.controller.BaseController;
|
|
|
import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.core.page.PageRequest;
|
|
|
import com.fs.common.core.page.TableDataInfo;
|
|
|
import com.fs.common.core.redis.RedisUtil;
|
|
|
+import com.fs.core.aspectj.lock.DistributeLock;
|
|
|
import com.fs.live.domain.Live;
|
|
|
+import com.fs.live.domain.LiveLotteryRegistration;
|
|
|
+import com.fs.live.domain.LiveRedConf;
|
|
|
import com.fs.live.domain.LiveWatchUser;
|
|
|
-import com.fs.live.service.ILiveService;
|
|
|
-import com.fs.live.service.ILiveWatchUserService;
|
|
|
+import com.fs.live.param.LotteryPO;
|
|
|
+import com.fs.live.param.RedPO;
|
|
|
+import com.fs.live.service.*;
|
|
|
+import com.fs.live.vo.LiveConfigVo;
|
|
|
+import com.fs.live.vo.LiveLotteryConfVo;
|
|
|
import com.fs.live.vo.LiveWatchUserVO;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
@@ -40,6 +43,15 @@ public class LiveFacadeServiceImpl extends BaseController implements LiveFacadeS
|
|
|
|
|
|
@Autowired
|
|
|
private ILiveWatchUserService liveWatchUserService;
|
|
|
+ @Autowired
|
|
|
+ private ILiveUserRedRecordService liveUserRedRecordService;
|
|
|
+ @Autowired
|
|
|
+ private ILiveUserLotteryRecordService liveUserLotteryRecordService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ILiveLotteryRegistrationService liveLotteryRegistrationService;
|
|
|
+ @Autowired
|
|
|
+ private ILiveRedConfService iLiveRedConfService;
|
|
|
|
|
|
@Override
|
|
|
public R liveList(PageRequest pageRequest) {
|
|
|
@@ -78,12 +90,12 @@ public class LiveFacadeServiceImpl extends BaseController implements LiveFacadeS
|
|
|
|
|
|
@Override
|
|
|
public TableDataInfo watchUserList(LiveWatchUser param) {
|
|
|
- List<LiveWatchUserVO> liveWatchUserVOS ;
|
|
|
- String setKey = String.format(LiveKeysConstant.LIVE_WATCH_USERS, param.getLiveId());
|
|
|
+ List<LiveWatchUserVO> liveWatchUserVOS;
|
|
|
+ String setKey = String.format(LiveKeysConstant.LIVE_WATCH_USERS, param.getLiveId());
|
|
|
Map<Object, Object> hashEntries = redisUtil.hashEntries(setKey);
|
|
|
- if (CollUtil.isEmpty(hashEntries)){
|
|
|
+ if (CollUtil.isEmpty(hashEntries)) {
|
|
|
liveWatchUserVOS = liveWatchUserService.asyncToCache(param.getLiveId());
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
liveWatchUserVOS = hashEntries.values().stream()
|
|
|
.map(value -> {
|
|
|
try {
|
|
|
@@ -98,4 +110,67 @@ public class LiveFacadeServiceImpl extends BaseController implements LiveFacadeS
|
|
|
}
|
|
|
return getDataTable(liveWatchUserVOS);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R liveDetail(Long id) {
|
|
|
+ Object o = redisUtil.hashGet(LiveKeysConstant.LIVE_HOME_PAGE_DETAIL, String.valueOf(id));
|
|
|
+ LiveVo liveVo;
|
|
|
+ if (ObjectUtil.isNotEmpty(o)) {
|
|
|
+ liveVo = JSON.parseObject(o.toString(), LiveVo.class);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ liveVo = liveService.asyncToCacheLiveDetail(id);
|
|
|
+ }
|
|
|
+ return R.ok().put("data", liveVo).put("storeId", liveVo.getStoreId());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R currentActivities(Long liveId, String userId) {
|
|
|
+ // 直播间配置信息
|
|
|
+ Object oLiveConfigVo = redisUtil.get(String.format(LiveKeysConstant.LIVE_HOME_PAGE_CONFIG, liveId, liveId));
|
|
|
+ LiveConfigVo liveConfigVo;
|
|
|
+ if (ObjectUtil.isNotEmpty(oLiveConfigVo)) {
|
|
|
+ liveConfigVo = JSON.parseObject(oLiveConfigVo.toString(), LiveConfigVo.class);
|
|
|
+ } else {
|
|
|
+ liveConfigVo = liveService.asyncToCacheLiveConfig(liveId);
|
|
|
+ }
|
|
|
+ List<LiveRedConf> redConfs = liveConfigVo.getLiveRedConfs()
|
|
|
+ .stream()
|
|
|
+ .filter(item -> ObjectUtil.isEmpty(redisUtil.hashGet(String.format(LiveKeysConstant.LIVE_HOME_PAGE_CONFIG_RED, liveId, item.getRedId()), userId)))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<LiveLotteryConfVo> lotteryConfs = liveConfigVo.getLiveLotteryConfs()
|
|
|
+ .stream()
|
|
|
+ .filter(item -> ObjectUtil.isEmpty(redisUtil.hashGet(String.format(LiveKeysConstant.LIVE_HOME_PAGE_CONFIG_RED, liveId, item.getLotteryId()), userId)))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ return R.ok()
|
|
|
+ .put("red", redConfs)
|
|
|
+ .put("lottery", lotteryConfs)
|
|
|
+ .put("goods", liveConfigVo.getLiveGoodsVo());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R redClaim(RedPO red) {
|
|
|
+ return iLiveRedConfService.claimRedPacket(red);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @DistributeLock(keyExpression = "#lottery.liveId + #lottery.userId", scene = "draw_claim")
|
|
|
+ public R drawClaim(LotteryPO lottery) {
|
|
|
+ Object o = redisUtil.hashGet(String.format(LiveKeysConstant.LIVE_HOME_PAGE_CONFIG_RED, lottery.getLiveId(), lottery.getLotteryId()), String.valueOf(lottery.getUserId()));
|
|
|
+ if (ObjectUtil.isNotEmpty(o)) {
|
|
|
+ return R.ok("您已参加抽奖活动,请等待开奖!");
|
|
|
+ }
|
|
|
+ LiveLotteryRegistration registration = new LiveLotteryRegistration();
|
|
|
+ Date now = new Date();
|
|
|
+ registration.setLiveId(lottery.getLiveId());
|
|
|
+ registration.setUserId(lottery.getUserId());
|
|
|
+ registration.setLotteryId(lottery.getLotteryId());
|
|
|
+ registration.setIsWin(0L);
|
|
|
+ registration.setRizeLevel(-1L);
|
|
|
+ registration.setCreateTime(now);
|
|
|
+ registration.setUpdateTime(now);
|
|
|
+ redisUtil.hashPut(String.format(LiveKeysConstant.LIVE_HOME_PAGE_CONFIG_DRAW, lottery.getLiveId(), lottery.getLotteryId()), String.valueOf(lottery.getUserId()), JSONUtil.toJsonStr(registration));
|
|
|
+ liveLotteryRegistrationService.insertLiveLotteryRegistration(registration);
|
|
|
+ return R.ok("参与抽奖成功!请在直播间等待开奖");
|
|
|
+ }
|
|
|
}
|