Forráskód Böngészése

直播流量统计 修改定时任务 强制直播间秒数为1

yuhongqi 1 hete
szülő
commit
206dccbc14
22 módosított fájl, 241 hozzáadás és 51 törlés
  1. 1 1
      fs-admin/src/main/java/com/fs/live/controller/LiveController.java
  2. 4 0
      fs-common/src/main/java/com/fs/common/vo/LiveVo.java
  3. 1 1
      fs-live-socket/src/main/java/com/fs/live/task/Task.java
  4. 13 6
      fs-live-socket/src/main/java/com/fs/live/websocket/service/WebSocketServer.java
  5. 6 0
      fs-service-system/src/main/java/com/fs/live/domain/Live.java
  6. 2 2
      fs-service-system/src/main/java/com/fs/live/domain/LiveTrafficLog.java
  7. 8 0
      fs-service-system/src/main/java/com/fs/live/mapper/LiveCouponIssueMapper.java
  8. 4 0
      fs-service-system/src/main/java/com/fs/live/mapper/LiveMapper.java
  9. 18 15
      fs-service-system/src/main/java/com/fs/live/mapper/LiveTrafficLogMapper.java
  10. 3 0
      fs-service-system/src/main/java/com/fs/live/mapper/LiveVideoMapper.java
  11. 2 1
      fs-service-system/src/main/java/com/fs/live/param/LiveFinishUParam.java
  12. 2 0
      fs-service-system/src/main/java/com/fs/live/service/ILiveService.java
  13. 2 0
      fs-service-system/src/main/java/com/fs/live/service/ILiveTrafficLogService.java
  14. 1 1
      fs-service-system/src/main/java/com/fs/live/service/impl/LiveDataServiceImpl.java
  15. 1 1
      fs-service-system/src/main/java/com/fs/live/service/impl/LiveOrderServiceImpl.java
  16. 38 1
      fs-service-system/src/main/java/com/fs/live/service/impl/LiveServiceImpl.java
  17. 27 4
      fs-service-system/src/main/java/com/fs/live/service/impl/LiveTrafficLogServiceImpl.java
  18. 8 1
      fs-service-system/src/main/java/com/fs/live/service/impl/LiveVideoServiceImpl.java
  19. 12 4
      fs-service-system/src/main/resources/mapper/live/LiveMapper.xml
  20. 47 13
      fs-service-system/src/main/resources/mapper/live/LiveTrafficLogMapper.xml
  21. 9 0
      fs-user-app/src/main/java/com/fs/app/controller/LiveTrafficLogController.java
  22. 32 0
      fs-user-app/src/main/java/com/fs/app/controller/LiveVideoController.java

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

@@ -106,7 +106,7 @@ public class LiveController extends BaseController {
     @PreAuthorize("@ss.hasPermi('live:live:edit')")
     @PostMapping("/updateLiveIsAudit")
     public Integer updateLiveIsAudit(@RequestBody Live live) {
-        return liveService.updateLive(live);
+        return liveService.updateLiveIsAudit(live);
     }
 
 

+ 4 - 0
fs-common/src/main/java/com/fs/common/vo/LiveVo.java

@@ -34,6 +34,8 @@ public class LiveVo {
     private String liveConfig;
 
     private String videoUrl;
+    private Long videoId;
+    private Integer videoType;
 
     private String flvHlsUrl;
 
@@ -47,4 +49,6 @@ public class LiveVo {
     /** 上下架 */
     private Integer isShow;
     private String previewUrl;
+    private Integer previewVideoType;
+    private Long previewVideoId;
 }

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

@@ -94,7 +94,7 @@ public class Task {
         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();
+        LocalDateTime now = LocalDateTime.now().minusSeconds(2L);
         list.forEach(live -> {
             if (live.getLiveType() != 3) {
                 if (live.getFinishTime() == null) {

+ 13 - 6
fs-live-socket/src/main/java/com/fs/live/websocket/service/WebSocketServer.java

@@ -435,7 +435,7 @@ public class WebSocketServer {
             return;
         liveDatas.forEach(liveData ->{
             liveData.setLikes(
-                    Optional.ofNullable(redisCache.incrementCacheValue("live:like:" + liveData.getLiveId(),0 )).orElse(0L)
+                    liveData.getLikes() + Optional.ofNullable(redisCache.incrementCacheValue("live:like:" + liveData.getLiveId(),0 )).orElse(0L)
             );
 
        /* for (Long liveId : liveIds) {
@@ -447,27 +447,27 @@ public class WebSocketServer {
 
             // 从 redis 获取数据,并提供默认值,避免 NPE
             liveData.setPageViews(
-                    Optional.ofNullable(redisCache.incrementCacheValue(PAGE_VIEWS_KEY + liveData.getLiveId(),0)).orElse(0L)
+                    liveData.getPageViews() + Optional.ofNullable(redisCache.incrementCacheValue(PAGE_VIEWS_KEY + liveData.getLiveId(),0)).orElse(0L)
             );
             liveData.setTotalViews(
-                    Optional.ofNullable(redisCache.incrementCacheValue(TOTAL_VIEWS_KEY + liveData.getLiveId(),0)).orElse(0L)
+                    liveData.getTotalViews() + Optional.ofNullable(redisCache.incrementCacheValue(TOTAL_VIEWS_KEY + liveData.getLiveId(),0)).orElse(0L)
             );
             liveData.setUniqueVisitors(
                     /*Optional.ofNullable(redisCache.getCacheSet(UNIQUE_VISITORS_KEY + liveId))
                             .map(Set::size)  // 获取集合大小
                             .map(Long::valueOf)  // 转换为 Long 类型
                             .orElse(0L)*/
-                    Optional.ofNullable(redisCache.incrementCacheValue(UNIQUE_VISITORS_KEY + liveData.getLiveId(),0)).orElse(0L)
+                    liveData.getUniqueVisitors() + Optional.ofNullable(redisCache.incrementCacheValue(UNIQUE_VISITORS_KEY + liveData.getLiveId(),0)).orElse(0L)
             );
             liveData.setUniqueViewers(
                     /*Optional.ofNullable(redisCache.getCacheSet(UNIQUE_VIEWERS_KEY + liveId))
                             .map(Set::size)  // 获取集合大小
                             .map(Long::valueOf)  // 转换为 Long 类型
                             .orElse(0L)*/
-                    Optional.ofNullable(redisCache.incrementCacheValue(UNIQUE_VIEWERS_KEY + liveData.getLiveId(),0)).orElse(0L)
+                    liveData.getUniqueViewers() + Optional.ofNullable(redisCache.incrementCacheValue(UNIQUE_VIEWERS_KEY + liveData.getLiveId(),0)).orElse(0L)
             );
             liveData.setPeakConcurrentViewers(
-                    Optional.ofNullable(redisCache.incrementCacheValue(MAX_ONLINE_USERS_KEY + liveData.getLiveId(),0)).orElse(0L)
+                    liveData.getPeakConcurrentViewers() + Optional.ofNullable(redisCache.incrementCacheValue(MAX_ONLINE_USERS_KEY + liveData.getLiveId(),0)).orElse(0L)
             );
         });
         if(!liveDatas.isEmpty())
@@ -515,6 +515,13 @@ public class WebSocketServer {
                 msg.setMsg(task.getContent());
                 msg.setUserType(1L);
                 msg.setNickName(task.getTaskName());
+                LiveMsg liveMsg = new LiveMsg();
+                liveMsg.setLiveId(task.getLiveId());
+                liveMsg.setUserId(0L);
+                liveMsg.setNickName(task.getTaskName());
+                liveMsg.setMsg(task.getContent());
+                liveMsg.setCreateTime(new Date());
+                liveMsgService.insertLiveMsg(liveMsg);
             }
             msg.setStatus(1);
             broadcastMessage(task.getLiveId(), JSONObject.toJSONString(R.ok().put("data", msg)));

+ 6 - 0
fs-service-system/src/main/java/com/fs/live/domain/Live.java

@@ -69,6 +69,10 @@ public class   Live extends BaseEntity {
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     @Excel(name = "开始时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
     private LocalDateTime startTime;
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private String startTimeS;
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private String endTimeE;
 
     /** 结束时间 */
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@@ -103,6 +107,8 @@ public class   Live extends BaseEntity {
 
 
     private String videoUrl;
+    private Long videoId;
+    private Integer videoType;
 
     private Long duration;
 

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

@@ -49,8 +49,8 @@ public class LiveTrafficLog extends BaseEntity
     private Long companyId;
 
     /** 课程id */
-    @Excel(name = "课程id")
-    private Long courseId;
+    @Excel(name = "视频id")
+    private Long videoId;
 
     /** 唯一id */
     @Excel(name = "唯一id")

+ 8 - 0
fs-service-system/src/main/java/com/fs/live/mapper/LiveCouponIssueMapper.java

@@ -2,7 +2,9 @@ package com.fs.live.mapper;
 
 import java.util.List;
 import com.fs.live.domain.LiveCouponIssue;
+import com.fs.live.domain.LiveCouponIssueRelation;
 import com.fs.live.param.CouponPO;
+import org.apache.ibatis.annotations.Insert;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 
@@ -67,4 +69,10 @@ public interface LiveCouponIssueMapper
 
     @Select("select lci.* from live_coupon_issue_user lciu where lciu.user_id=#{coupon.userId} and lciu.goods_id=#{coupon.goodsId}")
     List<LiveCouponIssue> curCoupon(@Param("coupon") CouponPO coupon);
+
+    @Select("select * from live_coupon_issue_relation where live_id= #{liveId}")
+    List<LiveCouponIssueRelation> selectRelationByLiveId(Long existLiveId);
+
+    @Insert("insert into live_coupon_issue_relation(live_id,coupon_issue_id,is_show,goods_id) values(#{liveId},#{couponIssueId},#{isShow},#{goodsId})")
+    void insertLiveCouponIssueRelation(LiveCouponIssueRelation liveCouponIssueRelation);
 }

+ 4 - 0
fs-service-system/src/main/java/com/fs/live/mapper/LiveMapper.java

@@ -5,6 +5,7 @@ import com.fs.live.domain.Live;
 import com.fs.live.vo.LiveListVo;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.Update;
 
 import java.util.List;
 
@@ -123,4 +124,7 @@ public interface LiveMapper
 
     @Select("select * from live where live_id = #{liveId} and (company_id = #{companyId} or company_id is null)")
     Live selectLiveByLiveIdAndCompanyId(@Param("liveId") Long liveId,@Param("companyId") Long companyId);
+
+    @Update("update live set is_audit = #{isAudit} where live_id = #{liveId}")
+    Integer updateLiveIsAudit(Live live);
 }

+ 18 - 15
fs-service-system/src/main/java/com/fs/live/mapper/LiveTrafficLogMapper.java

@@ -64,20 +64,23 @@ public interface LiveTrafficLogMapper
     public int deleteLiveTrafficLogByIds(Long[] logIds);
 
     @Select({"<script> " +
-            "select c.company_name, SUM(l.internet_traffic) AS total_internet_traffic" +
-            ",DATE_FORMAT(l.create_time, '%Y-%m') AS `month`  from live_traffic_log l " +
-            "left join company c on c.company_id = l.company_id " +
-            "where 1 = 1 " +
-            "<if test= 'maps.year != null '>" +
-            "and YEAR(l.create_time) = #{maps.year} " +
-            "</if>" +
-            "<if test= 'maps.month != null '>"+
-            "and MONTH(l.create_time) = #{maps.month} " +
-            "</if>" +
-            "<if test = ' maps.companyId !=null '> " +
-            "and l.company_id = #{maps.companyId} " +
-            "</if>" +
-            "group by l.company_id,`month` "+
-            "</script>"})
+            " select c.company_name, SUM(l.internet_traffic) AS total_internet_traffic" +
+            " ,DATE_FORMAT(l.create_time, '%Y-%m') AS `month`  from live_traffic_log l " +
+            " left join live lv on lv.live_id = l.live_id " +
+            " left join company c on c.company_id = lv.company_id " +
+            " where 1 = 1 " +
+            " <if test= 'maps.time != null '>" +
+            " and YEAR(l.create_time) = #{maps.year} " +
+            " </if>" +
+            " <if test= 'maps.month != null '>"+
+            " and MONTH(l.create_time) = #{maps.month} " +
+            " </if>" +
+            " <if test = ' maps.companyId !=null '> " +
+            " and l.company_id = #{maps.companyId} " +
+            " </if>" +
+            " group by l.company_id,`month` "+
+            " </script>"})
     List<LiveTrafficLogListVO> selectTrafficByCompany(@Param("maps") LiveTrafficLogParam param);
+
+    void insertOrUpdateLiveTrafficLog(LiveTrafficLog trafficLog);
 }

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

@@ -86,4 +86,7 @@ public interface LiveVideoMapper
 
     @Select("select * from live_video where live_id = #{liveId}")
     List<LiveVideo> selectLiveVideosByLiveId(@Param("liveId") Long liveId);
+
+    @Select("select * from live_video")
+    List<LiveVideo> selectByAll();
 }

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

@@ -14,7 +14,8 @@ public class LiveFinishUParam implements Serializable {
     private String corpId;
     private Long companyUserId;
     private Long companyId;
-    private Long courseId;
+    private Long videoId;
+    private Long internetTraffic;
     private BigDecimal bufferRate; //缓冲百分比
     private String uuId;
     private Long qwExternalId;

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

@@ -181,4 +181,6 @@ public interface ILiveService
     List<Live> liveCompanyList(Long companyId);
 
     R subNotifyLive(HashMap<String, Object> param);
+
+    Integer updateLiveIsAudit(Live live);
 }

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

@@ -67,4 +67,6 @@ public interface ILiveTrafficLogService
     List<LiveTrafficLogListVO> selectTrafficByCompany(LiveTrafficLogParam param);
 
     R getInternetTraffic(LiveFinishUParam param);
+
+    R getLiveInternetTraffic(LiveFinishUParam param);
 }

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

@@ -533,7 +533,7 @@ public class LiveDataServiceImpl implements ILiveDataService {
         //在线人数
         liveViewData.put("online", redisCache.getCacheObject(ONLINE_USERS_KEY+liveId));
         //关注数
-        liveViewData.put("follow", baseMapper.selectLiveDataByLiveId(liveId).getFollowNum());
+        liveViewData.put("follow", 0);
         //点赞数
         liveViewData.put("like", redisCache.getCacheObject("live:like:"+liveId));
         return liveViewData;

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

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

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

@@ -47,6 +47,7 @@ import java.time.format.DateTimeFormatter;
 import java.time.temporal.ChronoUnit;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
 /**
@@ -91,6 +92,8 @@ public class LiveServiceImpl implements ILiveService
     @Autowired
     private FsMiniprogramSubNotifyTaskMapper fsMiniprogramSubNotifyTaskMapper;
     @Autowired
+    private LiveCouponIssueMapper liveCouponIssueMapper;
+    @Autowired
     private FsUserMapper fsUserMapper;
 
     @Autowired
@@ -109,6 +112,8 @@ public class LiveServiceImpl implements ILiveService
             LiveVideo liveVideo = videos.get(0);
             byId.setVideoUrl(liveVideo.getVideoUrl());
             byId.setDuration(liveVideo.getDuration());
+            byId.setVideoId(liveVideo.getVideoId());
+            byId.setVideoType(liveVideo.getVideoType());
         }
         return byId;
     }
@@ -175,6 +180,8 @@ public class LiveServiceImpl implements ILiveService
         LiveVideo liveVideo = liveVideoService.selectLiveVideoByLiveIdAndType(id, 3);
         if (liveVideo != null) {
             liveVo.setPreviewUrl(liveVideo.getVideoUrl());
+            liveVo.setPreviewVideoType(liveVideo.getVideoType());
+            liveVo.setPreviewVideoId(liveVideo.getVideoId());
         }
 		if(live.getStatus() == 2){
 			long seconds = live.getStartTime().until(now, ChronoUnit.SECONDS);
@@ -195,7 +202,7 @@ public class LiveServiceImpl implements ILiveService
         LiveConfigVo liveConfigVo = currentActivities(liveId);
         ThreadUtil.execute(()->{
             log.info("同步配置信息到缓存{}", liveConfigVo);
-            redisUtil.delete(String.format(LiveKeysConstant.LIVE_HOME_PAGE_CONFIG, liveId));
+            redisUtil.delete(String.format(LiveKeysConstant.LIVE_HOME_PAGE_CONFIG, liveId,liveId));
             redisUtil.set(String.format(LiveKeysConstant.LIVE_HOME_PAGE_DETAIL, liveId), liveConfigVo,LiveKeysConstant.LIVE_HOME_PAGE_CONFIG_EXPIRE, TimeUnit.SECONDS);
             log.info("直播间数据同步到缓存完成");
         });
@@ -241,6 +248,11 @@ public class LiveServiceImpl implements ILiveService
         return R.ok("success");
     }
 
+    @Override
+    public Integer updateLiveIsAudit(Live live) {
+        return baseMapper.updateLiveIsAudit(live);
+    }
+
     /**
      * 查询企业直播
      * @param liveId            直播ID
@@ -302,6 +314,7 @@ public class LiveServiceImpl implements ILiveService
         live.setCreateTime(DateUtils.getNowDate());
         live.setIsDel(0);
         live.setIsAudit(0);
+        live.setStartTime(live.getStartTime().withSecond(1));
         live.setStatus(1);
         int save = baseMapper.insertLive(live);
         // 录播 才有视频
@@ -677,6 +690,9 @@ public class LiveServiceImpl implements ILiveService
         liveData.setFavouriteNum(0L);
         liveData.setFollowNum(0L);
         liveDataService.insertLiveData(liveData);
+        // 优惠券
+        List<LiveCouponIssueRelation> liveCouponIssueRelations = liveCouponIssueMapper.selectRelationByLiveId(existLiveId);
+        Map<Long, LiveCouponIssueRelation> collect = liveCouponIssueRelations.stream().collect(Collectors.toMap(LiveCouponIssueRelation::getGoodsId, Function.identity(), (existing, replacement) -> existing));
         // 直播视频
         List<LiveVideo> liveVideos = liveVideoService.selectLiveVideosByLiveId(existLiveId);
         if (!liveVideos.isEmpty()) {
@@ -692,6 +708,7 @@ public class LiveServiceImpl implements ILiveService
 
         // 运营自动化
         List<LiveAutoTask> liveAutoTasksList = liveAutoTaskService.selectLiveAutoTaskByLiveId(existLiveId);
+        List<LiveAutoTask> barrageTask = liveAutoTasksList.stream().filter(liveAutoTask -> liveAutoTask.getTaskType() == 3L).collect(Collectors.toList());
         List<LiveAutoTask> goodsTask = liveAutoTasksList.stream().filter(liveAutoTask -> liveAutoTask.getTaskType() == 1L).collect(Collectors.toList());
         Map<Long, LiveAutoTask> redMap = liveAutoTasksList.stream()
                 .filter(liveAutoTask -> liveAutoTask.getTaskType() == 2L)
@@ -717,6 +734,18 @@ public class LiveServiceImpl implements ILiveService
                 liveAutoTaskService.copyInsertLiveAutoTask(liveAutoTaskEntity);
             }
         }
+        if (!barrageTask.isEmpty()) {
+            LiveAutoTask liveAutoTaskEntity = new LiveAutoTask();
+            for (LiveAutoTask liveAutoTask : barrageTask) {
+                BeanUtils.copyBeanProp(liveAutoTaskEntity, liveAutoTask);
+                liveAutoTaskEntity.setId(null);
+                liveAutoTaskEntity.setLiveId(newLiveId);
+                liveAutoTaskEntity.setCreateTime(now);
+                liveAutoTaskEntity.setUpdateTime(now);
+                liveAutoTaskEntity.setFinishStatus(0L);
+                liveAutoTaskService.copyInsertLiveAutoTask(liveAutoTaskEntity);
+            }
+        }
         //直播间红包配置
         List<LiveRedConf> liveRedConfs = liveRedConfService.selectByLiveId(existLiveId);
         if (!liveRedConfs.isEmpty()) {
@@ -788,8 +817,16 @@ public class LiveServiceImpl implements ILiveService
                 liveGoodsEntity.setCompanyId(live.getCompanyId());
                 liveGoodsEntity.setCompanyUserId(live.getCompanyUserId());
                 liveGoodsService.insertLiveGoods(liveGoodsEntity);
+                if (collect.containsKey(liveGoods.getGoodsId())) {
+                    liveCouponIssueRelations.stream().filter(relation -> relation.getGoodsId().equals(liveGoods.getGoodsId())).findFirst().ifPresent(liveCouponIssueRelation -> liveCouponIssueRelation.setGoodsId(liveGoodsEntity.getGoodsId()));
+                }
             }
         }
+        for (LiveCouponIssueRelation liveCouponIssueRelation : liveCouponIssueRelations) {
+            liveCouponIssueRelation.setLiveId(newLiveId);
+            liveCouponIssueRelation.setIsShow(0);
+            liveCouponIssueMapper.insertLiveCouponIssueRelation(liveCouponIssueRelation);
+        }
 
         return R.ok("复制成功");
     }

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

@@ -127,10 +127,8 @@ public class LiveTrafficLogServiceImpl implements ILiveTrafficLogService
 
             List<LiveVideo> liveVideos = liveVideoMapper.selectByLiveIdAndType(param.getLiveId(),param.getVideoType());
 
+            if(liveVideos == null || liveVideos.isEmpty()) return R.error("视频不存在");
             LiveVideo video = liveVideos.get(0);
-            if (video == null) {
-                return R.error("视频不存在");
-            }
 
             // 计算流量
             BigDecimal result = param.getBufferRate().divide(new BigDecimal("100"), 4, RoundingMode.HALF_UP);
@@ -142,7 +140,32 @@ public class LiveTrafficLogServiceImpl implements ILiveTrafficLogService
             if (StringUtils.isNotEmpty(trafficLog.getUuId())) {
                 // 直接插入或更新
 //                logger.error("zyp \n【插入或更新流量】:{}",trafficLog);
-                liveTrafficLogMapper.insertLiveTrafficLog(trafficLog);
+                liveTrafficLogMapper.insertOrUpdateLiveTrafficLog(trafficLog);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            // 打印参数param和异常信息
+            log.error("zyp \n【插入或更新流量失败】参数: {}, 错误信息:{}", param, e.getMessage(), e);
+            return R.error();
+        }
+        return R.ok();
+    }
+
+    @Override
+    public R getLiveInternetTraffic(LiveFinishUParam param) {
+        try {
+            LiveTrafficLog trafficLog = new LiveTrafficLog();
+            trafficLog.setQwExternalContactId(param.getQwExternalId());
+            trafficLog.setCreateTime(new Date());
+            BeanUtils.copyProperties(param, trafficLog);
+
+            trafficLog.setInternetTraffic(param.getInternetTraffic());
+
+            // 处理 UUID 为空的情况
+            if (StringUtils.isNotEmpty(trafficLog.getUuId())) {
+                // 直接插入或更新
+//                logger.error("zyp \n【插入或更新流量】:{}",trafficLog);
+                liveTrafficLogMapper.insertOrUpdateLiveTrafficLog(trafficLog);
             }
         } catch (Exception e) {
             e.printStackTrace();

+ 8 - 1
fs-service-system/src/main/java/com/fs/live/service/impl/LiveVideoServiceImpl.java

@@ -1,12 +1,19 @@
 package com.fs.live.service.impl;
 
 import com.fs.common.utils.DateUtils;
+import com.fs.common.utils.StringUtils;
 import com.fs.live.domain.LiveVideo;
 import com.fs.live.mapper.LiveVideoMapper;
 import com.fs.live.service.ILiveVideoService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.client.ClientHttpRequest;
+import org.springframework.http.client.ClientHttpResponse;
 import org.springframework.stereotype.Service;
+import org.springframework.web.client.RestTemplate;
 
+import java.io.IOException;
+import java.net.URI;
 import java.util.Collections;
 import java.util.Date;
 import java.util.List;
@@ -140,7 +147,7 @@ public class LiveVideoServiceImpl implements ILiveVideoService
      */
     @Override
     public LiveVideo selectLiveVideoByLiveId(Long liveId) {
-        ;
+
         return liveVideoMapper.selectOne(liveId);
     }
 

+ 12 - 4
fs-service-system/src/main/resources/mapper/live/LiveMapper.xml

@@ -53,11 +53,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         order by create_time desc
     </select>
 
-    <select id="selectLiveList" parameterType="Live" resultMap="LiveResult">
+    <select id="selectLiveList" parameterType="com.fs.live.domain.Live" resultMap="LiveResult">
         select a.live_id, a.company_id, a.company_user_id,talent_id, a.live_name, a.is_audit, a.live_desc, a.show_type, a.status, a.anchor_id,
                a.live_type, a.start_time, a.finish_time, a.live_img_url, a.live_config, a.id_card_url, a.is_show, a.is_del, a.qw_qr_code, a.rtmp_url,
                a.flv_hls_url, a.create_time, a.create_by, a.update_by, a.update_time, a.remark,config_json, b.video_url
-                ,c.live_code_url,d.company_name,b.file_size
+                ,c.live_code_url,IFNULL(d.company_name, '总台') AS company_name,b.file_size
 
         from live a
         left join live_video b on a.live_id = b.live_id
@@ -67,6 +67,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         left join company d on a.company_id = d.company_id
         where 1=1 and a.is_del = 0 and  b.video_type in (1,2)
         <if test="companyId != null "> and (a.company_id = #{companyId} or a.company_id is null )</if>
+        <if test="companyName != null and companyName != ''">
+            and (
+            (d.company_name like concat('%', #{companyName}, '%'))
+            or
+            (#{companyName} = '总台' and a.company_id is null)
+            )
+        </if>
         <if test="talentId != null "> and talent_id = #{talentId}</if>
         <if test="liveName != null  and liveName != ''"> and live_name like concat('%', #{liveName}, '%')</if>
         <if test="liveDesc != null  and liveDesc != ''"> and live_desc = #{liveDesc}</if>
@@ -74,7 +81,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <if test="status != null "> and a.status = #{status}</if>
         <if test="anchorId != null "> and anchor_id = #{anchorId}</if>
         <if test="liveType != null "> and live_type = #{liveType}</if>
-        <if test="startTime != null "> and start_time = #{startTime}</if>
+        <if test="startTimeS != null "> and a.start_time &gt; STR_TO_DATE(#{startTimeS}, '%Y-%m-%d %H:%i:%s')</if>
+        <if test="endTimeE != null "> and a.finish_time &lt; STR_TO_DATE(#{endTimeE}, '%Y-%m-%d %H:%i:%s')</if>
         <if test="finishTime != null "> and finish_time = #{finishTime}</if>
         <if test="liveImgUrl != null  and liveImgUrl != ''"> and live_img_url = #{liveImgUrl}</if>
         <if test="liveConfig != null  and liveConfig != ''"> and live_config = #{liveConfig}</if>
@@ -82,7 +90,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <if test="qwQrCode != null  and qwQrCode != ''"> and qw_qr_code = #{qwQrCode}</if>
         <if test="rtmpUrl != null  and rtmpUrl != ''"> and rtmp_url = #{rtmpUrl}</if>
         <if test="flvHlsUrl != null  and flvHlsUrl != ''"> and flv_hls_url = #{flvHlsUrl}</if>
-        <if test="isAudit != null  and isAudit != ''"> and is_audit = #{isAudit}</if>
+        <if test="isAudit != null "> and is_audit = #{isAudit}</if>
         order by create_time desc
     </select>
 

+ 47 - 13
fs-service-system/src/main/resources/mapper/live/LiveTrafficLogMapper.xml

@@ -3,7 +3,7 @@
 PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.fs.live.mapper.LiveTrafficLogMapper">
-    
+
     <resultMap type="LiveTrafficLog" id="LiveTrafficLogResult">
         <result property="logId"    column="log_id"    />
         <result property="userId"    column="user_id"    />
@@ -14,17 +14,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="qwUserId"    column="qw_user_id"    />
         <result property="companyUserId"    column="company_user_id"    />
         <result property="companyId"    column="company_id"    />
-        <result property="courseId"    column="course_id"    />
+        <result property="videoId"    column="video_id"    />
         <result property="uuId"    column="uu_id"    />
     </resultMap>
 
     <sql id="selectLiveTrafficLogVo">
-        select log_id, user_id, live_id, create_time, qw_external_contact_id, internet_traffic, qw_user_id, company_user_id, company_id, course_id, uu_id from live_traffic_log
+        select log_id, user_id, live_id, create_time, qw_external_contact_id, internet_traffic, qw_user_id, company_user_id, company_id, video_id, uu_id from live_traffic_log
     </sql>
 
     <select id="selectLiveTrafficLogList" parameterType="LiveTrafficLog" resultMap="LiveTrafficLogResult">
         <include refid="selectLiveTrafficLogVo"/>
-        <where>  
+        <where>
             <if test="userId != null "> and user_id = #{userId}</if>
             <if test="liveId != null "> and live_id = #{liveId}</if>
             <if test="qwExternalContactId != null "> and qw_external_contact_id = #{qwExternalContactId}</if>
@@ -32,16 +32,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="qwUserId != null  and qwUserId != ''"> and qw_user_id = #{qwUserId}</if>
             <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
             <if test="companyId != null "> and company_id = #{companyId}</if>
-            <if test="courseId != null "> and course_id = #{courseId}</if>
+            <if test="videoId != null "> and video_id = #{videoId}</if>
             <if test="uuId != null  and uuId != ''"> and uu_id = #{uuId}</if>
         </where>
     </select>
-    
+
     <select id="selectLiveTrafficLogById" parameterType="Long" resultMap="LiveTrafficLogResult">
         <include refid="selectLiveTrafficLogVo"/>
         where log_id = #{logId}
     </select>
-        
+
     <insert id="insertLiveTrafficLog" parameterType="LiveTrafficLog" useGeneratedKeys="true" keyProperty="logId">
         insert into live_traffic_log
         <trim prefix="(" suffix=")" suffixOverrides=",">
@@ -53,7 +53,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="qwUserId != null">qw_user_id,</if>
             <if test="companyUserId != null">company_user_id,</if>
             <if test="companyId != null">company_id,</if>
-            <if test="courseId != null">course_id,</if>
+            <if test="videoId != null">video_id,</if>
             <if test="uuId != null">uu_id,</if>
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
@@ -65,7 +65,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="qwUserId != null">#{qwUserId},</if>
             <if test="companyUserId != null">#{companyUserId},</if>
             <if test="companyId != null">#{companyId},</if>
-            <if test="courseId != null">#{courseId},</if>
+            <if test="videoId != null">#{videoId},</if>
             <if test="uuId != null">#{uuId},</if>
          </trim>
     </insert>
@@ -81,7 +81,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="qwUserId != null">qw_user_id = #{qwUserId},</if>
             <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
             <if test="companyId != null">company_id = #{companyId},</if>
-            <if test="courseId != null">course_id = #{courseId},</if>
+            <if test="videoId != null">video_id = #{videoId},</if>
             <if test="uuId != null">uu_id = #{uuId},</if>
         </trim>
         where log_id = #{logId}
@@ -92,10 +92,44 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </delete>
 
     <delete id="deleteLiveTrafficLogByIds" parameterType="String">
-        delete from live_traffic_log where log_id in 
+        delete from live_traffic_log where log_id in
         <foreach item="logId" collection="array" open="(" separator="," close=")">
             #{logId}
         </foreach>
     </delete>
-    
-</mapper>
+    <insert id="insertOrUpdateLiveTrafficLog" parameterType="com.fs.live.domain.LiveTrafficLog">
+        INSERT INTO live_traffic_log (
+                                   user_id,
+            live_id,
+            create_time,
+            qw_external_contact_id,
+            internet_traffic,
+            qw_user_id,
+            company_user_id,
+            company_id,
+            video_id,
+            uu_id
+        ) VALUES (
+                  #{userId},
+                     #{liveId},
+                     #{createTime},
+                     #{qwExternalContactId},
+                     #{internetTraffic},
+                     #{qwUserId},
+                     #{companyUserId},
+                     #{companyId},
+                     #{videoId},
+                     #{uuId}
+                 ) ON DUPLICATE KEY UPDATE
+                     user_id = VALUES(user_id),
+            live_id = VALUES(live_id),
+            create_time = VALUES(createTime),
+            qw_external_contact_id = VALUES(qw_external_contact_id),
+            internet_traffic = VALUES(internet_traffic),
+            qw_user_id = VALUES(qw_user_id),
+            company_user_id = VALUES(company_user_id),
+            company_id = VALUES(company_id),
+            video_id = VALUES(video_id)
+    </insert>
+
+</mapper>

+ 9 - 0
fs-user-app/src/main/java/com/fs/app/controller/LiveTrafficLogController.java

@@ -26,4 +26,13 @@ public class LiveTrafficLogController extends AppBaseController {
         return liveTrafficLogService.getInternetTraffic(param);
     }
 
+    @Login
+    @ApiOperation("获取缓冲流量 ps:前端定时调")
+    @PostMapping("/getLiveInternetTraffic")
+    public R getLiveInternetTraffic(@RequestBody LiveFinishUParam param) {
+        Long userId = Long.parseLong(getUserId());
+        param.setUserId(userId);
+        return liveTrafficLogService.getLiveInternetTraffic(param);
+    }
+
 }

+ 32 - 0
fs-user-app/src/main/java/com/fs/app/controller/LiveVideoController.java

@@ -0,0 +1,32 @@
+package com.fs.app.controller;
+
+import com.fs.common.core.domain.R;
+import com.fs.live.domain.LiveVideo;
+import com.fs.live.mapper.LiveVideoMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+/**
+ * 用户直播赞Controller
+ *
+ * @author fs
+ * @date 2025-07-11
+ */
+@RestController
+@RequestMapping("/app/live/liveVideo")
+public class LiveVideoController {
+
+    @Autowired
+    private LiveVideoMapper liveVideoMapper;
+
+
+    @GetMapping("/{liveId}")
+    public R getVideo(@PathVariable("liveId") Long liveId,@RequestParam("videoType") Integer videoType) {
+        List<LiveVideo> liveVideos = liveVideoMapper.selectByLiveIdAndType(liveId, videoType);
+        if(liveVideos==null || liveVideos.isEmpty()) return R.error("没有该视频");
+
+        return R.ok().put("liveVideos", liveVideos.get(0));
+    }
+}