Quellcode durchsuchen

运营任务重新计算 订单价格计算 直播间复制 直播间定时任务

yuhongqi vor 1 Woche
Ursprung
Commit
cdb70dbf4c

+ 42 - 21
fs-live-socket/src/main/java/com/fs/live/task/Task.java

@@ -93,24 +93,32 @@ public class Task {
             return;
         List<Long> liveIdLists = list.stream().map(Live::getLiveId).collect(Collectors.toList());
         List<LiveAutoTask> liveAutoTasks = liveAutoTaskService.selectLiveAutoTaskByLiveIds(liveIdLists);
-        List<Live> activeLiveList = new ArrayList<>();
-        LocalDateTime now = LocalDateTime.now().minusSeconds(2L);
+        LocalDateTime now = LocalDateTime.now().plusSeconds(2L);
+        List<Live> startLiveList = new ArrayList<>();
+        List<Live> endLiveList = new ArrayList<>();
         list.forEach(live -> {
             if (live.getLiveType() != 3) {
                 if (live.getFinishTime() == null) {
                     if (now.isAfter(live.getStartTime().minusSeconds(2L))){
+                        if(live.getStatus() != 2){
+                            startLiveList.add(live);
+                        }
                         live.setStatus(2);
-                        activeLiveList.add( live);
                     } else if (now.isBefore(live.getStartTime())) {
                         live.setStatus(1);
                     }
                 } else {
                     if (now.isAfter(live.getStartTime().minusSeconds(2L)) && now.isBefore(live.getFinishTime())) {
+                        if(live.getStatus() != 2){
+                            startLiveList.add(live);
+                        }
                         live.setStatus(2);
-                        activeLiveList.add( live);
                     } else if (now.isBefore(live.getStartTime().minusSeconds(2L))) {
                         live.setStatus(1);
                     } else if (now.isAfter(live.getFinishTime().minusSeconds(2L))) {
+                        if(live.getStatus() != 3){
+                            endLiveList.add(live);
+                        }
                         live.setStatus(3);
                     }
                 }
@@ -120,6 +128,9 @@ public class Task {
                 if (liveReplayParam.getIsPlaybackOpen()) {
                     if (liveReplayParam.getFinishTime() != null) {
                         if (now.isAfter(live.getFinishTime().minusSeconds(2L))) {
+                            if(live.getStatus() != 3){
+                                endLiveList.add(live);
+                            }
                             live.setStatus(3);
                         }
                     }
@@ -128,8 +139,14 @@ public class Task {
 
         });
         String key = "live:auto_task:";
-        if(!activeLiveList.isEmpty()){
-            activeLiveList.forEach(live -> {
+
+        if(!list.isEmpty()){
+            for (Live live : list) {
+                liveService.updateLive(live);
+            }
+        }
+        if (!startLiveList.isEmpty()) {
+            for (Live live : startLiveList) {
                 List<LiveAutoTask> collect = liveAutoTasks.stream().filter(liveAutoTask -> liveAutoTask.getLiveId().equals(live.getLiveId())).collect(Collectors.toList());
                 if (!collect.isEmpty()) {
                     collect.forEach(liveAutoTask -> {
@@ -139,23 +156,27 @@ public class Task {
                         redisCache.redisTemplate.expire(key+live.getLiveId(), 30, java.util.concurrent.TimeUnit.MINUTES);
                     });
                 }
-            });
+                liveService.asyncToCacheLiveDetail(live.getLiveId());
+                SendMsgVo sendMsgVo = new SendMsgVo();
+                sendMsgVo.setMsg("开始直播");
+                sendMsgVo.setCmd("live_start");
+                webSocketServer.broadcastMessage(live.getLiveId(), JSONObject.toJSONString(R.ok().put("data",sendMsgVo)));
+            }
         }
-
-        if(!list.isEmpty()){
-            for (Live live : list) {
-                liveService.updateLive(live);
-                if (live.getStatus() == 2) {
-                    SendMsgVo sendMsgVo = new SendMsgVo();
-                    sendMsgVo.setMsg("开始直播");
-                    sendMsgVo.setCmd("live_start");
-                    webSocketServer.broadcastMessage(live.getLiveId(), JSONObject.toJSONString(R.ok().put("data",sendMsgVo)));
-                }else if (live.getStatus() == 3) {
-                    SendMsgVo sendMsgVo = new SendMsgVo();
-                    sendMsgVo.setMsg("结束直播");
-                    sendMsgVo.setCmd("live_end");
-                    webSocketServer.broadcastMessage(live.getLiveId(), JSONObject.toJSONString(R.ok().put("data",sendMsgVo)));
+        if (!endLiveList.isEmpty()) {
+            for (Live live : endLiveList) {
+                List<LiveAutoTask> collect = liveAutoTasks.stream().filter(liveAutoTask -> liveAutoTask.getLiveId().equals(live.getLiveId())).collect(Collectors.toList());
+                if (!collect.isEmpty()) {
+                    collect.forEach(liveAutoTask -> {
+                        liveAutoTask.setCreateTime(null);
+                        liveAutoTask.setUpdateTime(null);
+                        redisCache.redisTemplate.opsForZSet().remove(key + live.getLiveId(), JSON.toJSONString(liveAutoTask),liveAutoTask.getAbsValue().getTime());
+                    });
                 }
+                SendMsgVo sendMsgVo = new SendMsgVo();
+                sendMsgVo.setMsg("开始直播");
+                sendMsgVo.setCmd("live_start");
+                webSocketServer.broadcastMessage(live.getLiveId(), JSONObject.toJSONString(R.ok().put("data",sendMsgVo)));
             }
         }
     }

+ 1 - 1
fs-service-system/src/main/java/com/fs/live/mapper/LiveAutoTaskMapper.java

@@ -69,7 +69,7 @@ public interface LiveAutoTaskMapper {
     @Select("select * from live_auto_task where live_id= #{liveId}")
     List<LiveAutoTask> selectLiveAutoTaskByLiveId(@Param("liveId") Long liveId);
 
-    @Select("select * from live_auto_task where live_id= #{liveId} and task_type = 1")
+    @Select("select * from live_auto_task where live_id= #{liveId} and task_type in (1,3)")
     List<LiveAutoTask> recalcLiveAutoTaskQuery(@Param("liveId") Long liveId);
 
     @Select("select * from live_auto_task where live_id= #{liveId} and status=1 and finish_status = 0 and abs_value>#{now} order by abs_value")

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

@@ -2,6 +2,7 @@ package com.fs.live.service;
 
 
 import com.fs.common.core.domain.R;
+import com.fs.live.domain.Live;
 import com.fs.live.domain.LiveAutoTask;
 
 import java.util.Date;
@@ -44,7 +45,7 @@ public interface ILiveAutoTaskService {
      * @param liveAutoTask 直播间自动化任务配置
      * @return 结果
      */
-    R copyInsertLiveAutoTask(LiveAutoTask liveAutoTask);
+    R copyInsertLiveAutoTask(LiveAutoTask liveAutoTask, Live live);
 
     /**
      * 修改直播间自动化任务配置

+ 2 - 5
fs-service-system/src/main/java/com/fs/live/service/impl/LiveAutoTaskServiceImpl.java

@@ -154,12 +154,9 @@ public class LiveAutoTaskServiceImpl implements ILiveAutoTaskService {
      * @return 结果
      */
     @Override
-    public R copyInsertLiveAutoTask(LiveAutoTask liveAutoTask)
+    public R copyInsertLiveAutoTask(LiveAutoTask liveAutoTask , Live live)
     {
 
-        Live live = liveMapper.selectLiveByLiveId(liveAutoTask.getLiveId());
-        if(live == null) return R.error("直播间不存在");
-        //截取triggerValue 时分秒部分 ,然后根据查询出来的直播间开始时间计算出相对时间
         Date triggerValue = liveAutoTask.getTriggerValue();
         if (triggerValue == null) {
             return R.error("请设置触发时间");
@@ -259,7 +256,7 @@ public class LiveAutoTaskServiceImpl implements ILiveAutoTaskService {
     public void recalcLiveAutoTask(Long liveId) {
         Live live = liveMapper.selectLiveByLiveId(liveId);
         if(live == null) return;
-        // 目前只重算 推送商品
+        // 目前只重算 推送商品 弹幕脚本
         List<LiveAutoTask> liveAutoTasks = baseMapper.recalcLiveAutoTaskQuery(liveId);
         Date now = new Date();
         for (LiveAutoTask liveAutoTask : liveAutoTasks) {

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

@@ -1495,7 +1495,6 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
         BigDecimal payDelivery = BigDecimal.ZERO;
         if (param.getCityId() != null) {
             payDelivery = handleDeliveryMoney(param.getCityId(), fsStoreProduct, param.getTotalNum());
-            totalPrice = totalPrice.add(payDelivery);
             payPrice = payPrice.add(payDelivery);
         }
 

+ 4 - 4
fs-service-system/src/main/java/com/fs/live/service/impl/LiveServiceImpl.java

@@ -731,7 +731,7 @@ public class LiveServiceImpl implements ILiveService
                 liveAutoTaskEntity.setCreateTime(now);
                 liveAutoTaskEntity.setUpdateTime(now);
                 liveAutoTaskEntity.setFinishStatus(0L);
-                liveAutoTaskService.copyInsertLiveAutoTask(liveAutoTaskEntity);
+                liveAutoTaskService.copyInsertLiveAutoTask(liveAutoTaskEntity,liveEntity);
             }
         }
         if (!barrageTask.isEmpty()) {
@@ -743,7 +743,7 @@ public class LiveServiceImpl implements ILiveService
                 liveAutoTaskEntity.setCreateTime(now);
                 liveAutoTaskEntity.setUpdateTime(now);
                 liveAutoTaskEntity.setFinishStatus(0L);
-                liveAutoTaskService.copyInsertLiveAutoTask(liveAutoTaskEntity);
+                liveAutoTaskService.copyInsertLiveAutoTask(liveAutoTaskEntity,liveEntity);
             }
         }
         //直播间红包配置
@@ -768,7 +768,7 @@ public class LiveServiceImpl implements ILiveService
                     liveAutoTaskEntity.setUpdateTime(now);
                     liveAutoTaskEntity.setFinishStatus(0L);
                     liveAutoTaskEntity.setContent(JSON.toJSONString(liveRedConfEntity));
-                    liveAutoTaskService.copyInsertLiveAutoTask(liveAutoTaskEntity);
+                    liveAutoTaskService.copyInsertLiveAutoTask(liveAutoTaskEntity,liveEntity);
                 }
             }
         }
@@ -801,7 +801,7 @@ public class LiveServiceImpl implements ILiveService
                     liveAutoTaskEntity.setUpdateTime(now);
                     liveAutoTaskEntity.setFinishStatus(0L);
                     liveAutoTaskEntity.setContent(JSON.toJSONString(liveLotteryConfEntity));
-                    liveAutoTaskService.copyInsertLiveAutoTask(liveAutoTaskEntity);
+                    liveAutoTaskService.copyInsertLiveAutoTask(liveAutoTaskEntity,liveEntity);
                 }
             }
         }