Browse Source

优化在线消息 在线人数统计

yuhongqi 1 month ago
parent
commit
08fa64c886

+ 11 - 4
fs-admin/src/main/java/com/fs/live/controller/LiveWatchUserController.java

@@ -3,6 +3,7 @@ package com.fs.live.controller;
 import com.fs.common.annotation.Log;
 import com.fs.common.core.controller.BaseController;
 import com.fs.common.core.domain.AjaxResult;
+import com.fs.common.core.domain.R;
 import com.fs.common.core.page.TableDataInfo;
 import com.fs.common.enums.BusinessType;
 import com.fs.common.utils.poi.ExcelUtil;
@@ -42,13 +43,19 @@ public class LiveWatchUserController extends BaseController
         return getDataTable(list);
     }
 
+    @GetMapping("/liveUserTotals")
+    public R liveUserTotals(LiveWatchUser liveWatchUser)
+    {
+
+        return liveWatchUserService.liveUserTotals(liveWatchUser);
+    }
+
 //    @PreAuthorize("@ss.hasPermi('live:liveWatchUser:list')")
     @GetMapping("/watchUserList")
-    public TableDataInfo watchUserList(@RequestParam Long liveId) {
-        Map<String, Object> params = new HashMap<>();
-        params.put("liveId", liveId);
+    public TableDataInfo watchUserList(@RequestParam Map<String,Object> param) {
+
         startPage();
-        List<LiveWatchUserVO> onLineUserList = liveWatchUserService.selectWatchUserList(params);
+        List<LiveWatchUserVO> onLineUserList = liveWatchUserService.selectWatchUserList(param);
         return getDataTable(onLineUserList);
     }
 

+ 10 - 4
fs-company/src/main/java/com/fs/company/controller/live/LiveWatchUserController.java

@@ -3,6 +3,7 @@ package com.fs.company.controller.live;
 import com.fs.common.annotation.Log;
 import com.fs.common.core.controller.BaseController;
 import com.fs.common.core.domain.AjaxResult;
+import com.fs.common.core.domain.R;
 import com.fs.common.core.page.TableDataInfo;
 import com.fs.common.enums.BusinessType;
 import com.fs.common.utils.poi.ExcelUtil;
@@ -42,14 +43,19 @@ public class LiveWatchUserController extends BaseController
         return getDataTable(list);
     }
 
+    @GetMapping("/liveUserTotals")
+    public R liveUserTotals(LiveWatchUser liveWatchUser)
+    {
+
+        return liveWatchUserService.liveUserTotals(liveWatchUser);
+    }
+
 //    @PreAuthorize("@ss.hasPermi('live:liveWatchUser:list')")
     @GetMapping("/watchUserList")
-    public TableDataInfo watchUserList(@RequestParam Long liveId) {
-        Map<String, Object> params = new HashMap<>();
-        params.put("liveId", liveId);
+    public TableDataInfo watchUserList(@RequestParam Map<String,Object> param) {
 
         startPage();
-        List<LiveWatchUserVO> onLineUserList = liveWatchUserService.selectWatchUserList(params);
+        List<LiveWatchUserVO> onLineUserList = liveWatchUserService.selectWatchUserList(param);
         return getDataTable(onLineUserList);
     }
 

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

@@ -60,8 +60,9 @@ public class LiveGoods extends BaseEntity{
     private Long sort;
 
     /** 商品名称搜索关键字*/
-    
+
     private String keywords;
+    private String productName;
 
 
 }

+ 1 - 0
fs-service-system/src/main/java/com/fs/live/domain/LiveWatchUser.java

@@ -44,5 +44,6 @@ public class LiveWatchUser extends BaseEntity {
     /** 用户名字 */
 
     private String nickName;
+    private String tabName;
 
 }

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

@@ -82,4 +82,6 @@ public interface LiveAutoTaskMapper {
 
     @Select("select * from live_auto_task where live_id= #{liveId} and task_type = 3")
     List<LiveAutoTask> selectLiveAutoTaskBarrageList(LiveAutoTask liveAutoTask);
+
+    void batchInsertLiveAutoTask(@Param("list") List<LiveAutoTask> addList);
 }

+ 9 - 0
fs-service-system/src/main/java/com/fs/live/mapper/LiveWatchUserMapper.java

@@ -2,6 +2,7 @@ package com.fs.live.mapper;
 
 
 import com.fs.live.domain.LiveWatchUser;
+import com.fs.live.vo.LiveWatchUserStatistics;
 import com.fs.live.vo.LiveWatchUserVO;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
@@ -102,4 +103,12 @@ public interface LiveWatchUserMapper {
 
     @Select("select * from live_watch_user where live_id = #{liveId} and user_id = #{userId}")
     LiveWatchUser selectUserByLiveIdAndUserId(@Param("liveId") long liveId,@Param("userId")  long userId);
+
+    @Select("SELECT " +
+            "    SUM(CASE WHEN online = 0 and msg_status = 0 THEN 1 ELSE 0 END) AS online, " +
+            "    SUM(CASE WHEN online = 1 and msg_status = 0 THEN 1 ELSE 0 END) AS offline, " +
+            "    SUM(CASE WHEN msg_status = 1 THEN 1 ELSE 0 END) AS silenced " +
+            "FROM " +
+            "    live_watch_user where live_id=#{liveId}")
+    LiveWatchUserStatistics liveUserTotals(LiveWatchUser liveWatchUser);
 }

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

@@ -83,4 +83,6 @@ public interface ILiveAutoTaskService {
     List<LiveAutoTask> selectLiveAutoTaskBarrageList(LiveAutoTask liveAutoTask);
 
     void directInsertLiveAutoTask(LiveAutoTask liveAutoTask);
+
+    void batchInsertLiveAutoTask(List<LiveAutoTask> addList);
 }

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

@@ -1,6 +1,7 @@
 package com.fs.live.service;
 
 
+import com.fs.common.core.domain.R;
 import com.fs.live.domain.LiveWatchUser;
 import com.fs.live.vo.LiveWatchUserVO;
 
@@ -111,4 +112,6 @@ public interface ILiveWatchUserService {
 
 
     List<LiveWatchUserVO> asyncToCache(Long liveId);
+
+    R liveUserTotals(LiveWatchUser liveWatchUser);
 }

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

@@ -308,4 +308,9 @@ public class LiveAutoTaskServiceImpl implements ILiveAutoTaskService {
     public void directInsertLiveAutoTask(LiveAutoTask liveAutoTask) {
         baseMapper.insertLiveAutoTask(liveAutoTask);
     }
+
+    @Override
+    public void batchInsertLiveAutoTask(List<LiveAutoTask> addList) {
+        baseMapper.batchInsertLiveAutoTask(addList);
+    }
 }

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

@@ -728,6 +728,7 @@ public class LiveServiceImpl implements ILiveService
         List<LiveAutoTask> goodsTaskList = liveAutoTasksList.stream().filter(liveAutoTask -> liveAutoTask.getTaskType() == 1L).collect(Collectors.toList());
         List<LiveAutoTask> redTaskList = liveAutoTasksList.stream().filter(liveAutoTask -> liveAutoTask.getTaskType() == 2L).collect(Collectors.toList());
         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) {
@@ -737,9 +738,17 @@ public class LiveServiceImpl implements ILiveService
                 liveAutoTaskEntity.setCreateTime(now);
                 liveAutoTaskEntity.setUpdateTime(now);
                 liveAutoTaskEntity.setFinishStatus(0L);
-                liveAutoTaskService.directInsertLiveAutoTask(liveAutoTaskEntity);
+                addList.add(liveAutoTaskEntity);
+                if (addList.size() > 100) {
+                    liveAutoTaskService.batchInsertLiveAutoTask(addList);
+                    addList.clear();
+                }
             }
         }
+        if (!addList.isEmpty()) {
+            liveAutoTaskService.batchInsertLiveAutoTask(addList);
+            addList.clear();
+        }
         //直播间红包配置
         List<LiveRedConf> liveRedConfs = liveRedConfService.selectByLiveId(existLiveId);
         if (!liveRedConfs.isEmpty()) {
@@ -797,11 +806,13 @@ public class LiveServiceImpl implements ILiveService
                 liveAutoTaskService.directInsertLiveAutoTask(liveAutoTaskEntity);
             }
         }
+        LiveGoods queryParam = new LiveGoods();
+        queryParam.setLiveId(existLiveId);
         // 直播间商品
-        List<LiveGoods> goodsList = liveGoodsService.selectByLiveId(existLiveId);
+        List<LiveGoodsVo> goodsList = liveGoodsService.selectProductListByLiveId(queryParam);
         if (!goodsList.isEmpty()) {
             LiveGoods liveGoodsEntity = new LiveGoods();
-            for (LiveGoods liveGoods : goodsList) {
+            for (LiveGoodsVo liveGoods : goodsList) {
                 BeanUtils.copyBeanProp(liveGoodsEntity, liveGoods);
                 liveGoodsEntity.setGoodsId(null);
                 liveGoodsEntity.setLiveId(newLiveId);

+ 15 - 0
fs-service-system/src/main/java/com/fs/live/service/impl/LiveWatchUserServiceImpl.java

@@ -6,6 +6,7 @@ import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.thread.ThreadUtil;
 import com.alibaba.fastjson.JSON;
 import com.fs.common.constant.LiveKeysConstant;
+import com.fs.common.core.domain.R;
 import com.fs.common.core.redis.RedisCache;
 import com.fs.common.core.redis.RedisUtil;
 import com.fs.common.utils.DateUtils;
@@ -13,6 +14,7 @@ import com.fs.live.domain.Live;
 import com.fs.live.domain.LiveWatchUser;
 import com.fs.live.mapper.LiveWatchUserMapper;
 import com.fs.live.service.ILiveWatchUserService;
+import com.fs.live.vo.LiveWatchUserStatistics;
 import com.fs.live.vo.LiveWatchUserVO;
 import com.fs.store.domain.FsUser;
 import com.fs.store.service.IFsUserService;
@@ -79,6 +81,13 @@ public class LiveWatchUserServiceImpl implements ILiveWatchUserService {
     @Override
     public List<LiveWatchUser> selectLiveWatchUserList(LiveWatchUser liveWatchUser)
     {
+        if ("online".equals(liveWatchUser.getTabName())) {
+            liveWatchUser.setOnline(0);
+        } else if ("offline".equals(liveWatchUser.getTabName())) {
+            liveWatchUser.setOnline(1);
+        } else if ("silenced".equals(liveWatchUser.getTabName())) {
+            liveWatchUser.setMsgStatus(1);
+        }
         return baseMapper.selectLiveWatchUserList(liveWatchUser);
     }
 
@@ -266,4 +275,10 @@ public class LiveWatchUserServiceImpl implements ILiveWatchUserService {
         return liveWatchUserVOS;
     }
 
+    @Override
+    public R liveUserTotals(LiveWatchUser liveWatchUser) {
+        LiveWatchUserStatistics liveWatchUserStatistics = baseMapper.liveUserTotals(liveWatchUser);
+        return R.ok().put("data", liveWatchUserStatistics);
+    }
+
 }

+ 11 - 0
fs-service-system/src/main/java/com/fs/live/vo/LiveWatchUserStatistics.java

@@ -0,0 +1,11 @@
+package com.fs.live.vo;
+
+import lombok.Data;
+
+@Data
+public class LiveWatchUserStatistics {
+
+    private Integer online;
+    private Integer offline;
+    private Integer silenced;
+}

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

@@ -112,4 +112,35 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </foreach>
         and status=1 and finish_status = 0 and abs_value>#{now} order by abs_value
     </select>
+    <insert id="batchInsertLiveAutoTask" parameterType="java.util.List">
+        INSERT INTO live_auto_task (
+        live_id,
+        task_name,
+        task_type,
+        trigger_type,
+        trigger_value,
+        abs_value,
+        content,
+        status,
+        finish_status,
+        create_time,
+        update_time
+        )
+        VALUES
+        <foreach collection="list" item="task" separator=",">
+            (
+            #{task.liveId},
+            #{task.taskName},
+            #{task.taskType},
+            #{task.triggerType},
+            #{task.triggerValue},
+            #{task.absValue},
+            #{task.content},
+            #{task.status},
+            #{task.finishStatus},
+            #{task.createTime},
+            #{task.updateTime}
+            )
+        </foreach>
+    </insert>
 </mapper>

+ 3 - 0
fs-service-system/src/main/resources/mapper/live/LiveWatchUserMapper.xml

@@ -49,7 +49,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         from live_watch_user lwu
         left join fs_user fu on lwu.user_id = fu.user_id
         where lwu.live_id = #{params.liveId}
+        <if test="params.msgStatus != null "> and msg_status = #{params.msgStatus}</if>
+        <if test="params.online != null "> and online = #{params.online}</if>
         order by lwu.create_time desc
+
     </select>
 
     <select id="selectLiveWatchUserByIdAndCompanyIdAndCompanyUserId" resultMap="LiveWatchUserResult">