Selaa lähdekoodia

直播代码提交

yuhongqi 1 viikko sitten
vanhempi
commit
c4052487f2

+ 24 - 5
fs-admin/src/main/java/com/fs/live/controller/LiveDataController.java

@@ -1,27 +1,46 @@
 package com.fs.live.controller;
 
+import com.fs.common.core.controller.BaseController;
 import com.fs.common.core.domain.R;
+import com.fs.common.core.page.TableDataInfo;
 import com.fs.common.utils.SecurityUtils;
 import com.fs.live.domain.LiveData;
 import com.fs.live.service.ILiveDataService;
+import com.fs.live.vo.LiveUserFirstVo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletRequest;
 import java.util.List;
 import java.util.Map;
 
 
 @RestController
 @RequestMapping("/live/liveData")
-public class LiveDataController {
+public class LiveDataController extends BaseController {
 
     @Autowired
     private ILiveDataService liveDataService;
 
+    /**
+     * 直播数据页面卡片数据
+     */
+    @GetMapping("/dashboardData")
+    public R dashboardData(@RequestParam Long liveId, HttpServletRequest request) {
+        return liveDataService.dashboardData(liveId);
+    }
+
+    /**
+     * 直播数据页面 分页查询邀请榜单
+     */
+    @GetMapping("/dashboardInviteList")
+    public TableDataInfo inviteList(@RequestParam Long liveId, HttpServletRequest request) {
+        startPage();
+        List<LiveUserFirstVo> list = liveDataService.inviteList(liveId);
+        return getDataTable(list);
+    }
+
     /**
      * 查询直播数据列表
      * */

+ 8 - 0
fs-admin/src/main/java/com/fs/live/controller/LiveWatchUserController.java

@@ -59,6 +59,14 @@ public class LiveWatchUserController extends BaseController
         return getDataTable(onLineUserList);
     }
 
+    @GetMapping("/dashBoardWatchUserList")
+    public TableDataInfo dashBoardWatchUserList(@RequestParam Map<String,Object> param) {
+
+        startPage();
+        List<LiveWatchUserVO> onLineUserList = liveWatchUserService.dashBoardWatchUserList(param);
+        return getDataTable(onLineUserList);
+    }
+
     /**
      * 导出直播间观看用户列表
      */

+ 11 - 0
fs-company/src/main/java/com/fs/company/controller/live/LiveDataController.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;
@@ -35,6 +36,16 @@ public class LiveDataController extends BaseController
     @Autowired
     private TokenService tokenService;
 
+    /**
+     * 直播数据页面卡片数据
+     */
+    @GetMapping("/dashboardData")
+    public R dashboardData(@RequestParam Long liveId, HttpServletRequest request) {
+        LoginUser loginUser = tokenService.getLoginUser(request);
+        Long userId = loginUser.getUser().getUserId();
+        return liveDataService.dashboardData(liveId);
+    }
+
     /**
      * 查询直播数据列表
      */

+ 8 - 0
fs-company/src/main/java/com/fs/company/controller/live/LiveWatchUserController.java

@@ -59,6 +59,14 @@ public class LiveWatchUserController extends BaseController
         return getDataTable(onLineUserList);
     }
 
+    @GetMapping("/dashBoardWatchUserList")
+    public TableDataInfo dashBoardWatchUserList(@RequestParam Map<String,Object> param) {
+
+        startPage();
+        List<LiveWatchUserVO> onLineUserList = liveWatchUserService.dashBoardWatchUserList(param);
+        return getDataTable(onLineUserList);
+    }
+
     /**
      * 导出直播间观看用户列表
      */

+ 11 - 0
fs-service/src/main/java/com/fs/live/mapper/LiveDataMapper.java

@@ -2,11 +2,14 @@ package com.fs.live.mapper;
 
 
 import com.fs.live.domain.LiveData;
+import com.fs.live.vo.LiveDashBoardDataVo;
 import com.fs.live.vo.RecentLiveDataVo;
 import com.fs.live.vo.TrendDataVO;
 import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
 import org.springframework.stereotype.Repository;
 
+import java.math.BigDecimal;
 import java.util.List;
 import java.util.Map;
 
@@ -124,4 +127,12 @@ public interface LiveDataMapper {
     TrendDataVO getCompanyPreviousData(@Param("prevStartDate") String start,@Param("prevEndDate") String end,@Param("companyId") Long companyId);
 
     List<Map<String, Object>> getCompanyChartData(@Param("chartStartDate") String chartStartDate,@Param("chartEndDate") String chartEndDate, @Param("format") String format,@Param("category") String category,@Param("companyId") Long companyId);
+
+    @Select("SELECT " +
+            "    ld.total_views AS viewNum,                        " +
+            "    ld.likes AS likeNum                        " +
+            "FROM " +
+            "    live_data ld " +
+            "where ld.live_id=#{liveId}")
+    Map<String, Integer> selectDashboardCount(@Param("liveId") Long liveId);
 }

+ 5 - 0
fs-service/src/main/java/com/fs/live/mapper/LiveMsgMapper.java

@@ -5,7 +5,9 @@ import com.fs.live.domain.LiveMsg;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 
+import java.math.BigDecimal;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 直播讨论Mapper接口
@@ -74,4 +76,7 @@ public interface LiveMsgMapper
 
     @Select("select * from live_msg where live_id = #{liveId} order by create_time desc limit 30")
     List<LiveMsg> listRecentMsg(@Param("liveId")Long liveId);
+
+    @Select("SELECT count(1) as commentNum from live_msg where live_id = #{liveId}")
+    Map<String, Long> selectDashboardCount(@Param("liveId") Long liveId);
 }

+ 39 - 0
fs-service/src/main/java/com/fs/live/mapper/LiveUserFirstEntryMapper.java

@@ -2,12 +2,17 @@ package com.fs.live.mapper;
 
 
 import com.fs.live.domain.LiveUserFirstEntry;
+import com.fs.live.vo.LiveDashBoardDataVo;
 import com.fs.live.vo.LiveUserFirstProfit;
+import com.fs.live.vo.LiveUserFirstVo;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
+import org.springframework.security.core.parameters.P;
 
+import java.math.BigDecimal;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 用户每日首次进入直播间记录Mapper接口
@@ -71,4 +76,38 @@ public interface LiveUserFirstEntryMapper {
 
     @Select("select * from live_user_first_entry where live_id=#{liveId} and user_id=#{userId}")
     LiveUserFirstEntry selectEntityByLiveIdUserId(@Param("liveId") long liveId,@Param("userId") long userId);
+
+    @Select("SELECT  " +
+            "  cu.user_name companyUserName,  " +
+            "  count( 1 ) AS invite_num   " +
+            "FROM  " +
+            "  live_user_first_entry lufe  " +
+            "  LEFT JOIN company_user cu ON lufe.company_user_id = cu.user_id   " +
+            "WHERE  " +
+            "  lufe.company_user_id > 0   " +
+            "GROUP BY  " +
+            "  lufe.company_user_id   " +
+            "ORDER BY  " +
+            "  invite_num DESC   " +
+            "  LIMIT 10")
+    List<LiveUserFirstVo> selectDashboardInviteCount(@Param("liveId") Long liveId);
+
+    @Select("SELECT  " +
+            "  cu.user_name companyUserName,  " +
+            "  count( 1 ) AS invite_num   " +
+            "FROM  " +
+            "  live_user_first_entry lufe  " +
+            "  LEFT JOIN company_user cu ON lufe.company_user_id = cu.user_id   " +
+            "WHERE  " +
+            "  lufe.company_user_id > 0   " +
+            "GROUP BY  " +
+            "  lufe.company_user_id   " +
+            "ORDER BY  " +
+            "  invite_num DESC   ")
+    List<LiveUserFirstVo> inviteList(@Param("liveId") Long liveId);
+
+    @Select("SELECT  sum(case when company_user_id > 0 then 1 else 0 end ) as shareUrlNum, " +
+            " sum(case when company_user_id < 0 then 1 else 0 end ) as directAccessNum  " +
+            " from live_user_first_entry where live_id=#{liveId}" )
+    Map<String, BigDecimal> selectDashboardCount(@Param("liveId") Long liveId);
 }

+ 15 - 1
fs-service/src/main/java/com/fs/live/mapper/LiveWatchUserMapper.java

@@ -2,11 +2,13 @@ package com.fs.live.mapper;
 
 
 import com.fs.live.domain.LiveWatchUser;
+import com.fs.live.vo.LiveDashBoardDataVo;
 import com.fs.live.vo.LiveWatchUserStatistics;
 import com.fs.live.vo.LiveWatchUserVO;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 
+import java.math.BigDecimal;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -107,8 +109,20 @@ public interface LiveWatchUserMapper {
     @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 " +
+            "    SUM(CASE WHEN msg_status = 1 THEN 1 ELSE 0 END) AS silenced, " +
+            "    SUM(CASE WHEN user_id > 0 THEN 1 ELSE 0 END) AS al " +
             "FROM " +
             "    live_watch_user where live_id=#{liveId}")
     LiveWatchUserStatistics liveUserTotals(LiveWatchUser liveWatchUser);
+
+    List<LiveWatchUserVO> selectWatchUserListAllByLiveId(@Param("params") Map<String, Object> param);
+
+    @Select("SELECT " +
+            "    SUM(CASE WHEN online = 0 and msg_status = 0 THEN 1 ELSE 0 END) AS onlineNum, " +
+            "    SUM(CASE WHEN user_id > 0 THEN 1 ELSE 0 END) AS newUserNum, " +
+            "    SUM(CASE WHEN user_id > 0 THEN 1 ELSE 0 END) AS oldUserNum " +
+            "FROM " +
+            "    live_watch_user where live_id=#{liveId}"
+    )
+    Map<String, BigDecimal> selectDashboardCount(Long liveId);
 }

+ 5 - 0
fs-service/src/main/java/com/fs/live/service/ILiveDataService.java

@@ -4,6 +4,7 @@ package com.fs.live.service;
 import com.fs.common.core.domain.R;
 import com.fs.live.domain.LiveData;
 import com.fs.live.vo.ColumnsConfigVo;
+import com.fs.live.vo.LiveUserFirstVo;
 import com.fs.live.vo.RecentLiveDataVo;
 import com.fs.live.vo.TrendDataVO;
 
@@ -127,4 +128,8 @@ public interface ILiveDataService {
     List<RecentLiveDataVo> getCompanyLiveTop(String rankType,Long companyId);
 
     TrendDataVO getCompanyTrendData(String type, String date, String category, Long companyId);
+
+    R dashboardData(Long liveId);
+
+    List<LiveUserFirstVo> inviteList(Long liveId);
 }

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

@@ -114,4 +114,6 @@ public interface ILiveWatchUserService {
     List<LiveWatchUserVO> asyncToCache(Long liveId);
 
     R liveUserTotals(LiveWatchUser liveWatchUser);
+
+    List<LiveWatchUserVO> dashBoardWatchUserList(Map<String, Object> param);
 }

+ 39 - 4
fs-service/src/main/java/com/fs/live/service/impl/LiveDataServiceImpl.java

@@ -10,14 +10,15 @@ import com.fs.live.domain.LiveUserFavorite;
 import com.fs.live.domain.LiveUserFollow;
 import com.fs.live.domain.LiveUserLike;
 import com.fs.live.mapper.LiveDataMapper;
+import com.fs.live.mapper.LiveMsgMapper;
+import com.fs.live.mapper.LiveUserFirstEntryMapper;
+import com.fs.live.mapper.LiveWatchUserMapper;
 import com.fs.live.service.ILiveDataService;
 import com.fs.live.service.ILiveUserFavoriteService;
 import com.fs.live.service.ILiveUserFollowService;
 import com.fs.live.service.ILiveUserLikeService;
-import com.fs.live.vo.ColumnsConfigVo;
-import com.fs.live.vo.DateRange;
-import com.fs.live.vo.RecentLiveDataVo;
-import com.fs.live.vo.TrendDataVO;
+import com.fs.live.vo.*;
+import io.swagger.models.auth.In;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -62,6 +63,40 @@ public class LiveDataServiceImpl implements ILiveDataService {
     private ILiveUserFavoriteService liveUserFavoriteService;
     @Autowired
     private LiveDataMapper baseMapper;
+    @Autowired
+    private LiveUserFirstEntryMapper liveUserFirstEntryMapper;
+    @Autowired
+    private LiveWatchUserMapper liveWatchUserMapper;
+    @Autowired
+    private LiveMsgMapper liveMsgMapper;
+
+
+    /* 直播大屏展示 数据接口 */
+    @Override
+    public R dashboardData(Long liveId) {
+        Map<String,BigDecimal> map1 = liveWatchUserMapper.selectDashboardCount(liveId);
+        Map<String,Integer> map2 = baseMapper.selectDashboardCount(liveId);
+        Map<String, Long> map3 = liveMsgMapper.selectDashboardCount(liveId);
+        Map<String,BigDecimal> map4 = liveUserFirstEntryMapper.selectDashboardCount(liveId);
+        LiveDashBoardDataVo result = new LiveDashBoardDataVo();
+        result.setOnlineNum(map1.getOrDefault("onlineNum", BigDecimal.valueOf(0)));
+        result.setOldUserNum(map1.getOrDefault("oldUserNum", BigDecimal.valueOf(0)));
+        result.setNewUserNum(map1.getOrDefault("newUserNum", BigDecimal.valueOf(0)));
+        result.setViewNum(map2.getOrDefault("viewNum", 0));
+        result.setLikeNum(map2.getOrDefault("likeNum", 0));
+        result.setCommentNum(map3.getOrDefault("commentNum", 0L));
+        result.setShareUrlNum(map4.getOrDefault("shareUrlNum", BigDecimal.valueOf(0)));
+        result.setDirectAccessNum(map4.getOrDefault("directAccessNum", BigDecimal.valueOf(0)));
+        List<LiveUserFirstVo> liveUserFirstVos = liveUserFirstEntryMapper.selectDashboardInviteCount(liveId);
+        result.setInviteUserList(liveUserFirstVos);
+        return R.ok().put("data", result);
+    }
+
+    @Override
+    public List<LiveUserFirstVo> inviteList(Long liveId) {
+        return liveUserFirstEntryMapper.inviteList(liveId);
+    }
+
     /**
      * 查询直播数据
      *

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

@@ -281,6 +281,7 @@ public class LiveWatchUserServiceImpl implements ILiveWatchUserService {
             liveWatchUserStatistics.setOnline(0);
             liveWatchUserStatistics.setOffline(0);
             liveWatchUserStatistics.setSilenced(0);
+            liveWatchUserStatistics.setAl(0);
             return R.ok().put("data", liveWatchUserStatistics);
         }
         if(liveWatchUserStatistics.getOnline() == null)
@@ -293,7 +294,19 @@ public class LiveWatchUserServiceImpl implements ILiveWatchUserService {
         if (liveWatchUserStatistics.getSilenced() == null) {
             liveWatchUserStatistics.setSilenced(0);
         }
+        if (liveWatchUserStatistics.getAl() == null) {
+            liveWatchUserStatistics.setAl(0);
+        }
         return R.ok().put("data", liveWatchUserStatistics);
     }
 
+    @Override
+    public List<LiveWatchUserVO> dashBoardWatchUserList(Map<String, Object> param) {
+        if (param != null && param.containsKey("all") && "1".equals(param.get("all"))) {
+            return baseMapper.selectWatchUserListAllByLiveId(param);
+        } else {
+            return baseMapper.selectWatchUserListByLiveId(param);
+        }
+    }
+
 }

+ 37 - 0
fs-service/src/main/java/com/fs/live/vo/LiveDashBoardDataVo.java

@@ -0,0 +1,37 @@
+package com.fs.live.vo;
+
+import com.fs.live.domain.LiveUserFirstEntry;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+@Data
+public class LiveDashBoardDataVo {
+    // 在线人数 liveWatchUser
+    private BigDecimal onlineNum;
+
+    // 观看人数 liveData
+    private Integer viewNum;
+
+    // 点赞数量 liveData
+    private Integer likeNum;
+
+    // 评论数量 liveMsg
+    private Long commentNum;
+
+    // 新用户数量 liveWatchUser
+    private BigDecimal newUserNum;
+
+    // 老用户数量 liveWatchUser
+    private BigDecimal oldUserNum;
+
+    // 分享链接来源数量 liveUserFirstEntry
+    private BigDecimal shareUrlNum;
+
+    // 直接访问数量 liveUserFirstEntry
+    private BigDecimal directAccessNum;
+
+    private List<LiveUserFirstVo> inviteUserList;
+
+}

+ 28 - 0
fs-service/src/main/java/com/fs/live/vo/LiveUserFirstVo.java

@@ -0,0 +1,28 @@
+package com.fs.live.vo;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fs.common.annotation.Excel;
+import com.fs.common.core.domain.BaseEntity;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.util.Date;
+
+/**
+ * 用户每日首次进入直播间记录对象 live_user_first_entry
+ *
+ * @author fs
+ * @date 2025-09-04
+ */
+@Data
+public class LiveUserFirstVo{
+
+    /** 销售名称 */
+    private String userName;
+
+    /** 邀请数量 */
+    private Integer inviteNum;
+
+
+
+}

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

@@ -8,4 +8,5 @@ public class LiveWatchUserStatistics {
     private Integer online;
     private Integer offline;
     private Integer silenced;
+    private Integer al;
 }

+ 17 - 1
fs-service/src/main/resources/mapper/live/LiveWatchUserMapper.xml

@@ -44,13 +44,29 @@
         lwu.user_id     userId,
         lwu.msg_status  msgStatus,
         lwu.online      online,
-        fu.nickname    nickName,
+        fu.nick_name    nickName,
         fu.avatar       avatar
         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>
+        <if test="params.userName != null and params.userName != ''"> and fs.nickname like concat('%',#{params.userName},'%')</if>
+        order by lwu.create_time desc
+
+    </select>
+    <select id="selectWatchUserListAllByLiveId" resultType="com.fs.live.vo.LiveWatchUserVO">
+        select
+        lwu.live_id     liveId,
+        lwu.user_id     userId,
+        lwu.msg_status  msgStatus,
+        lwu.online      online,
+        fu.nick_name    nickName,
+        fu.avatar       avatar
+        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.userName != null and params.userName != ''"> and fs.nickname like concat('%',#{params.userName},'%')</if>
         order by lwu.create_time desc
 
     </select>