فهرست منبع

重算所有的自动化任务,查询商品仅有商品码的数据

yuhongqi 4 هفته پیش
والد
کامیت
9a30913db4

+ 1 - 1
fs-live-socket/src/main/java/com/fs/live/controller/LiveController.java

@@ -77,7 +77,7 @@ public class LiveController {
 		live.setLiveId(Long.valueOf(params.get("stream_id")));
 		live.setStatus(3);
 		live.setFinishTime(LocalDateTime.now());
-		liveService.updateLive(live);
+		liveService.updateLiveEntity(live);
 		return R.ok();
 //		{app=200149.push.tlivecloud.com, appid=1319721001, appname=live, channel_id=673,
 //				errcode=1, errmsg=The push client actively stopped the push, event_time=1755571239,

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

@@ -175,7 +175,7 @@ public class Task {
                         liveAutoTask.setCreateTime(null);
                         liveAutoTask.setUpdateTime(null);
                         redisCache.redisTemplate.opsForZSet().add(key + live.getLiveId(), JSON.toJSONString(liveAutoTask),liveAutoTask.getAbsValue().getTime());
-                        redisCache.redisTemplate.expire(key+live.getLiveId(), 30, java.util.concurrent.TimeUnit.MINUTES);
+                        redisCache.redisTemplate.expire(key+live.getLiveId(), 1, TimeUnit.DAYS);
                     });
                 }
             }

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

@@ -84,4 +84,7 @@ public interface LiveAutoTaskMapper {
     List<LiveAutoTask> selectLiveAutoTaskBarrageList(LiveAutoTask liveAutoTask);
 
     void batchInsertLiveAutoTask(@Param("list") List<LiveAutoTask> addList);
+
+
+    void batchUpdateLiveAutoTask(@Param("list")  List<LiveAutoTask> updateList);
 }

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

@@ -3,6 +3,7 @@ package com.fs.live.service.impl;
 import java.time.LocalDateTime;
 import java.time.LocalTime;
 import java.time.ZoneId;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Date;
 import java.util.List;
@@ -283,14 +284,21 @@ public class LiveAutoTaskServiceImpl implements ILiveAutoTaskService {
     public void recalcLiveAutoTask(Live live) {
 
         if(live == null) return;
-        // 目前只重算 推送商品 弹幕脚本
         List<LiveAutoTask> liveAutoTasks = baseMapper.recalcLiveAutoTaskQuery(live.getLiveId());
         Date now = new Date();
+        List<LiveAutoTask> updateList = new ArrayList<>();
         for (LiveAutoTask liveAutoTask : liveAutoTasks) {
             liveAutoTask.setAbsValue(getTriggerValue(liveAutoTask.getTriggerValue(), live.getStartTime()));
             liveAutoTask.setUpdateTime(now);
             liveAutoTask.setFinishStatus(0L);
-            baseMapper.updateLiveAutoTask(liveAutoTask);
+            updateList.add(liveAutoTask);
+            if (updateList.size() >= 200) {
+                baseMapper.batchUpdateLiveAutoTask(updateList);
+                updateList.clear();
+            }
+        }
+        if (!updateList.isEmpty()) {
+            baseMapper.batchUpdateLiveAutoTask(updateList);
         }
     }
 

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

@@ -391,9 +391,8 @@ public class LiveServiceImpl implements ILiveService
 
         }
         int result = baseMapper.updateLive(live);
-        if (live.getStatus() == 2) {
-            liveAutoTaskService.recalcLiveAutoTask(live);
-        }
+        liveAutoTaskService.recalcLiveAutoTask(live);
+
         return result;
     }
 
@@ -634,6 +633,7 @@ public class LiveServiceImpl implements ILiveService
     }
 
     @Override
+    @Transactional
     public R startLive(Live live) {
         Live exist = baseMapper.selectLiveByLiveId(live.getLiveId());
         if (exist == null) {
@@ -659,7 +659,13 @@ public class LiveServiceImpl implements ILiveService
         exist.setFinishTime( null);
         exist.setStartTime(LocalDateTime.now());
         baseMapper.updateLive(exist);
-
+        List<LiveAutoTask> liveAutoTasks = liveAutoTaskService.selectNoActivedByLiveId(exist.getLiveId(), new Date());
+        liveAutoTasks.forEach(liveAutoTask -> {
+            liveAutoTask.setCreateTime(null);
+            liveAutoTask.setUpdateTime(null);
+            redisCache.redisTemplate.opsForZSet().add("live:auto_task:" + live.getLiveId(), JSON.toJSONString(liveAutoTask),liveAutoTask.getAbsValue().getTime());
+            redisCache.redisTemplate.expire("live:auto_task:"+live.getLiveId(), 1, TimeUnit.DAYS);
+        });
 
         return R.ok();
     }
@@ -735,8 +741,8 @@ public class LiveServiceImpl implements ILiveService
         List<LiveAutoTask> lotteryTaskList = liveAutoTasksList.stream().filter(liveAutoTask -> liveAutoTask.getTaskType() == 4L).collect(Collectors.toList());
         List<LiveAutoTask> addList = new ArrayList<>();
         if (!barrageTask.isEmpty()) {
-            LiveAutoTask liveAutoTaskEntity = new LiveAutoTask();
             for (LiveAutoTask liveAutoTask : barrageTask) {
+                LiveAutoTask liveAutoTaskEntity = new LiveAutoTask();
                 BeanUtils.copyBeanProp(liveAutoTaskEntity, liveAutoTask);
                 liveAutoTaskEntity.setId(null);
                 liveAutoTaskEntity.setLiveId(newLiveId);
@@ -757,8 +763,8 @@ public class LiveServiceImpl implements ILiveService
         //直播间红包配置
         List<LiveRedConf> liveRedConfs = liveRedConfService.selectByLiveId(existLiveId);
         if (!liveRedConfs.isEmpty()) {
-            LiveRedConf liveRedConfEntity = new LiveRedConf();
             for (LiveRedConf liveRedConf : liveRedConfs) {
+                LiveRedConf liveRedConfEntity = new LiveRedConf();
                 BeanUtils.copyBeanProp(liveRedConfEntity, liveRedConf);
                 liveRedConfEntity.setRedId(null);
                 liveRedConfEntity.setLiveId(newLiveId);
@@ -782,10 +788,11 @@ public class LiveServiceImpl implements ILiveService
         // 直播间礼物配置
         List<LiveLotteryConf> liveLotteryConfs = liveLotteryConfService.selectByLiveId(existLiveId);
         if (!liveLotteryConfs.isEmpty()) {
-            LiveLotteryConf liveLotteryConfEntity = new LiveLotteryConf();
+
             List<Long> lotteryIds = liveLotteryConfs.stream().map(LiveLotteryConf::getLotteryId).collect(Collectors.toList());
             List<LiveLotteryProductConf> products = liveLotteryProductConfMapper.selectEntityByIds(lotteryIds);
             for (LiveLotteryConf liveLotteryConf : liveLotteryConfs) {
+                LiveLotteryConf liveLotteryConfEntity = new LiveLotteryConf();
                 BeanUtils.copyBeanProp(liveLotteryConfEntity, liveLotteryConf);
                 liveLotteryConfEntity.setLotteryId(null);
                 liveLotteryConfEntity.setLiveId(newLiveId);
@@ -818,8 +825,8 @@ public class LiveServiceImpl implements ILiveService
         if (!goodsList.isEmpty()) {
             List<String> goodsProductIds = goodsList.stream().map(item -> String.valueOf(item.getProductId())).collect(Collectors.toList());
             Map<Long, FsStoreProduct> collect = fsStoreProductMapper.selectFsStoreProductByProductIds(goodsProductIds).stream().collect(Collectors.toMap(FsStoreProduct::getProductId, item -> item));
-            LiveGoods liveGoodsEntity = new LiveGoods();
             for (LiveGoodsVo liveGoods : goodsList) {
+                LiveGoods liveGoodsEntity = new LiveGoods();
                 BeanUtils.copyBeanProp(liveGoodsEntity, liveGoods);
                 liveGoodsEntity.setGoodsId(null);
                 liveGoodsEntity.setLiveId(newLiveId);

+ 1 - 1
fs-service-system/src/main/java/com/fs/store/mapper/FsStoreProductMapper.java

@@ -229,7 +229,7 @@ public interface FsStoreProductMapper
     @Select({"<script> " +
             "SELECT fsp.* FROM fs_store_product fsp " +
             " left join fs_store_product_attr_value fspav on fsp.product_id = fspav.product_id  " +
-            "WHERE fsp.is_show = 1 and (fspav.bar_code is not null or fspav.group_bar_code is not null)  and " +
+            "WHERE fsp.is_show = 1 and (fspav.bar_code is not null)  and " +
             " fsp.product_id NOT IN (" +
             "   SELECT product_id FROM live_goods " +
             "   WHERE live_id = #{maps.liveId} " +

+ 23 - 0
fs-service-system/src/main/resources/mapper/live/LiveAutoTaskMapper.xml

@@ -143,4 +143,27 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             )
         </foreach>
     </insert>
+
+    <!-- 批量更新直播间自动化任务 -->
+    <update id="batchUpdateLiveAutoTask">
+        <foreach collection="list" item="task" separator=";">
+            UPDATE live_auto_task
+            <set>
+                <!-- 1. 按需添加需更新的字段,非必更新字段用 if 判断(避免更新为 null) -->
+                <if test="task.liveId != null">live_id = #{task.liveId},</if>
+                <if test="task.taskName != null and task.taskName != ''">task_name = #{task.taskName},</if>
+                <if test="task.taskType != null">task_type = #{task.taskType},</if>
+                <if test="task.triggerType != null">trigger_type = #{task.triggerType},</if>
+                <if test="task.triggerValue != null">trigger_value = #{task.triggerValue},</if>
+                <if test="task.absValue != null">abs_value = #{task.absValue},</if>
+                <if test="task.content != null and task.content != ''">content = #{task.content},</if>
+                <if test="task.status != null">status = #{task.status},</if>
+                <if test="task.finishStatus != null">finish_status = #{task.finishStatus},</if>
+                <!-- 2. 若有更新时间字段,自动填充当前时间 -->
+                update_time = NOW()
+            </set>
+            <!-- 3. 必须通过主键 id 定位数据(批量更新的核心) -->
+            WHERE id = #{task.id}
+        </foreach>
+    </update>
 </mapper>