Kaynağa Gözat

直播代码 回调和在线人数和消息记录

yuhongqi 2 hafta önce
ebeveyn
işleme
6964a9810a

+ 0 - 1
fs-live-app/src/main/java/com/fs/app/controller/LiveMsgController.java

@@ -30,7 +30,6 @@ public class LiveMsgController extends BaseController
     /**
      * 查询直播讨论列表
      */
-    @PreAuthorize("@ss.hasPermi('live:liveMsg:list')")
     @GetMapping("/list")
     public TableDataInfo list(LiveMsg liveMsg)
     {

+ 2 - 1
fs-live-app/src/main/java/com/fs/app/controller/LiveRedController.java

@@ -1,6 +1,7 @@
 package com.fs.app.controller;
 
 import com.fs.app.annotation.Login;
+import com.fs.common.core.domain.R;
 import com.fs.live.param.RedPO;
 import com.fs.live.service.ILiveRedConfService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -21,7 +22,7 @@ public class LiveRedController extends AppBaseController{
      * */
     @Login
     @PostMapping("/claim")
-    public boolean claim(@RequestBody RedPO red) {
+    public R claim(@RequestBody RedPO red) {
         red.setUserId(Long.parseLong(getUserId()));
         return liveRedConfService.claimRedPacket(red);
     }

+ 1 - 1
fs-live-app/src/main/java/com/fs/app/controller/LiveWatchUserController.java

@@ -33,7 +33,7 @@ public class LiveWatchUserController extends BaseController
 
 
 
-    @PreAuthorize("@ss.hasPermi('live:liveWatchUser:list')")
+
     @GetMapping("/watchUserList")
     public TableDataInfo watchUserList(@RequestParam Long liveId) {
         Map<String, Object> params = new HashMap<>();

+ 2 - 1
fs-service/src/main/java/com/fs/live/service/ILiveRedConfService.java

@@ -2,6 +2,7 @@ package com.fs.live.service;
 
 import java.util.List;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.fs.common.core.domain.R;
 import com.fs.live.domain.LiveRedConf;
 import com.fs.live.param.RedPO;
 
@@ -70,7 +71,7 @@ public interface ILiveRedConfService extends IService<LiveRedConf>{
 
     void delete(Long redId);
 
-    boolean claimRedPacket(RedPO red);
+    R claimRedPacket(RedPO red);
 
     String start(String redId, Long userId);
 }

+ 9 - 7
fs-service/src/main/java/com/fs/live/service/impl/LiveRedConfServiceImpl.java

@@ -4,6 +4,7 @@ import java.util.*;
 import java.util.concurrent.ThreadLocalRandom;
 import java.util.concurrent.TimeUnit;
 
+import com.fs.common.core.domain.R;
 import com.fs.common.core.redis.RedisCache;
 import com.fs.common.utils.DateUtils;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -143,7 +144,7 @@ public class LiveRedConfServiceImpl extends ServiceImpl<LiveRedConfMapper, LiveR
      */
     @Override
     @Transactional
-    public boolean claimRedPacket(RedPO red) {
+    public R claimRedPacket(RedPO red) {
         String lockKey = REDPACKET_REMAININGLOTS_KEY + red.getRedId();
         List<String> keyList =  new ArrayList<>();
         keyList.add(lockKey);
@@ -151,23 +152,23 @@ public class LiveRedConfServiceImpl extends ServiceImpl<LiveRedConfMapper, LiveR
         try {
             Integer remaining = getRemaining(red.getRedId());
             if (remaining <= 0) {
-                return false;
+                return R.error("手慢了,红包已被抢完~");
             }
             //获取红包锁
             if (!tryLock(lockKey, red.getUserId().toString(), 5)) {
-                return false;
+                return R.error("您已经领取过红包了!");
             }
 
             LiveRedConf conf = baseMapper.selectLiveRedConfByRedId(red.getRedId());
             if (conf == null || conf.getRedStatus() != 1) {
-                return false;
+                return R.error("手慢了,红包已被抢完~");
             }
             //redis剩余红包数
             // 平均分 暂时不适用redis 记录红包数
 
             Long integral = calculateIntegralAverage(conf);
             if (0L == integral) {
-                return false;
+                return R.error("手慢了,红包已被抢完~");
             }
             Date now = new Date();
             //剩余金额
@@ -178,12 +179,13 @@ public class LiveRedConfServiceImpl extends ServiceImpl<LiveRedConfMapper, LiveR
             conf.setRemaining(Math.toIntExact(conf.getTotalLots() - conf.getTotalSend()));
             conf.setUpdateTime(now);
 
+            // todo yhq 更新用户芳华币数量
 
 
             // 更新数据库和缓存
             baseMapper.updateLiveRedConf(conf);
             decreaseRemainingLotsIfPossible(red.getRedId());
-            //decreaseRemainingNumIfPossible(red.getRedId(),integral);
+            decreaseRemainingNumIfPossible(red.getRedId(),integral);
 
             // 记录用户红包
             LiveUserRedRecord record = new LiveUserRedRecord();
@@ -198,7 +200,7 @@ public class LiveRedConfServiceImpl extends ServiceImpl<LiveRedConfMapper, LiveR
             //String msg = String.format("用户 %d 抢到了红包 %d,获得 %d 芳华币", userId, redId, integral);
             //WebSocketServer.notifyUsers(msg);
 
-            return true;
+            return R.ok();
         } finally {
             releaseLock(keyList, red.getUserId().toString());
         }

+ 1 - 0
fs-service/src/main/java/com/fs/live/service/impl/LiveServiceImpl.java

@@ -410,6 +410,7 @@ public class LiveServiceImpl extends ServiceImpl<LiveMapper, Live> implements IL
 
         exist.setStatus(2);
         exist.setUpdateTime(new Date());
+        exist.setFinishTime( null);
         liveMapper.updateLive(exist);
 
         return R.ok();

+ 1 - 0
fs-service/src/main/resources/mapper/live/LiveMapper.xml

@@ -156,6 +156,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="liveType != null">live_type = #{liveType},</if>
             <if test="startTime != null">start_time = #{startTime},</if>
             <if test="finishTime != null">finish_time = #{finishTime},</if>
+            <if test="finishTime == null">finish_time = NULL,</if>
             <if test="liveImgUrl != null">live_img_url = #{liveImgUrl},</if>
             <if test="liveConfig != null">live_config = #{liveConfig},</if>
             <if test="isShow != null">is_show = #{isShow},</if>