1.修改了APP更多现场查询不到数据的BUG

2.修改了定时任务连接Redis方式
3.修改了getReportLiveCount接口字段名
4.getSceneDetail方法增加人数统计
5.修复了获取更多现场接口的sql语句错误
6.增加LiveSceneDTO 的一个字段
7.增加所有流结束后现场变为回顾状态。process方法遍历检查每个流的状态
8.增加现场状态和人数
This commit is contained in:
2210088963 2025-03-26 11:33:44 +08:00
parent 344e856953
commit 42b1936f33
10 changed files with 155 additions and 49 deletions

View File

@ -8,7 +8,7 @@ DROP COLUMN component_count,
DROP COLUMN title_setting;
ALTER TABLE aijinan.live_channel
ADD COLUMN component_type VARCHAR(20) DEFAULT '组件A' COMMENT '组件类型',
ADD COLUMN component_type VARCHAR(20) DEFAULT '组件A' COMMENT '组件类型',
ADD COLUMN component_layout VARCHAR(10) DEFAULT '2*N' COMMENT '组件排布',
ADD COLUMN component_count INT DEFAULT 6 COMMENT '组件数量',
ADD COLUMN title_setting VARCHAR(50) DEFAULT '政务前沿、直播快讯' COMMENT '标题设置';

View File

@ -376,12 +376,12 @@ public class LiveForeignController {
* @return 现场点赞数
*/
@GetMapping("/getReportLiveCount")
public R getReportLiveCount(@RequestParam Integer sceneId) {
LiveReportEntity report = liveReportService.selectById(sceneId);
public R getReportLiveCount(@RequestParam Integer reportId) {
LiveReportEntity report = liveReportService.selectById(reportId);
if(report==null){
return R.error("该报道不存在");
}
Long liveCount = liveForeignService.getReportLiveCount(sceneId);
Long liveCount = liveForeignService.getReportLiveCount(reportId);
return R.ok().put("liveCount", liveCount);
}

View File

@ -35,7 +35,27 @@ public class SceneForeignEntity {
// 评论总数
private String comments;
public SceneForeignEntity() {
private String liveState;
private String viewsShow;
public String getLiveState() {
return liveState;
}
public void setLiveState(String liveState) {
this.liveState = liveState;
}
public String getViewsShow() {
return viewsShow;
}
public void setViewsShow(String viewsShow) {
this.viewsShow = viewsShow;
}
public SceneForeignEntity() {
}
@ -65,6 +85,8 @@ public class SceneForeignEntity {
this.caster = entity.getCasterId().toString();
else
this.caster = "";
this.liveState = String.valueOf(entity.getLiveState());
this.viewsShow = String.valueOf(entity.getViewsShow());
}
public String getId() {

View File

@ -272,6 +272,8 @@ public class LiveForeignServiceImpl implements com.platform.modules.foreign.serv
entity.setTitleImage(compressImage(entity.getTitleImage()));
}
}
LiveSceneCountEntity countEntity = liveSceneCountService.selectById(id);
entity.setViewsShow(String.valueOf(countEntity.getViewsShow()));
return entity;
}
}
@ -301,6 +303,8 @@ public class LiveForeignServiceImpl implements com.platform.modules.foreign.serv
list.setCoverUrl(compressImage(list.getCoverUrl()));
});
}
LiveSceneCountEntity countEntity = liveSceneCountService.selectById(id);
entity.setViewsShow(String.valueOf(countEntity.getViewsShow()));
return entity;
}

View File

@ -65,7 +65,7 @@ public interface LiveSceneDao extends BaseMapper<LiveSceneEntity> {
@Select("select ls.id,ls.title,ls.title_image,ls.live_state from live_scene ls left join live_scene_count lsc on ls.id = lsc.scene_id where ls.scene_state = 2 and hot_spot = 1 order by lsc.views_show desc;")
List<LiveSceneDTO> getHotList();
@Select("select id,title,title_image,live_state from live_scene where scene_state = 2 by live_start desc limit 20;")
@Select("select id,title,title_image,live_state from live_scene where scene_state = 2 order by live_start desc limit 20;")
List<LiveSceneDTO> getMoreScenes();
@Update("<script>" +

View File

@ -9,5 +9,6 @@ public class LiveSceneDTO {
private String titleImage;
private Integer liveState;
private String liveImageShow;
private Integer views_show;
}

View File

@ -183,4 +183,6 @@ public interface LiveSceneService extends IService<LiveSceneEntity> {
List<LiveSceneDTO> getHotList();
List<LiveSceneDTO> getMoreScenes();
R streamPullEndEntity(LiveSceneLiveInfoEntity infoEntity);
}

View File

@ -15,6 +15,7 @@ import com.platform.modules.foreign.dto.AppSearchDto;
import com.platform.modules.foreign.entity.SceneForeignEntity;
import com.platform.modules.foreign.entity.SceneStreamForeignEntity;
import com.platform.modules.live.constants.SceneConstants;
import com.platform.modules.live.dao.LiveSceneCountDao;
import com.platform.modules.live.dao.LiveSceneDao;
import com.platform.modules.live.dto.LiveSceneDTO;
import com.platform.modules.live.dto.SceneDTO;
@ -117,6 +118,8 @@ public class LiveSceneServiceImpl extends ServiceImpl<LiveSceneDao, LiveSceneEnt
private SysLogServiceImpl sysLogService;
@Autowired
private SysConfigServiceImpl sysConfigService;
@Autowired
private LiveSceneCountDao liveSceneCountDao;
@Override
@Transactional(readOnly = true)
@ -2965,7 +2968,13 @@ public class LiveSceneServiceImpl extends ServiceImpl<LiveSceneDao, LiveSceneEnt
@Override
public List<LiveSceneDTO> getMoreScenes() {
return liveSceneDao.getMoreScenes();
List<LiveSceneDTO> moreScenes = liveSceneDao.getMoreScenes();
moreScenes.forEach(liveSceneDTO -> {
liveSceneDTO.setLiveImageShow(MaterialUtils.getMaterialUrl(liveSceneDTO.getTitleImage(), foreignProperties.getMediaurl()));
LiveSceneCountEntity liveSceneCountEntity = liveSceneCountDao.selectById(liveSceneDTO.getId());
liveSceneDTO.setViews_show(liveSceneCountEntity.getViewsShow());
});
return moreScenes;
}
}

View File

@ -1,5 +1,6 @@
package com.platform.modules.live.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
@ -24,6 +25,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
@ -115,6 +117,30 @@ public class LiveStreamStatusServiceImpl extends ServiceImpl<LiveStreamStatusDao
//20200305 weiyan 获取直播时移的有效地址
flvUrl = liveClient.liveStream().generateTimeShiftUrl(startDate, liveSceneLiveInfoEntity.getAppName(), liveSceneLiveInfoEntity.getStreamName());
}
List<LiveSceneLiveInfoEntity> entities = liveSceneLiveInfoService.selectList(new EntityWrapper<>(liveSceneLiveInfoEntity)
.eq("scene_id", liveSceneLiveInfoEntity.getSceneId()));
boolean flag = true;
for (LiveSceneLiveInfoEntity entity : entities) {
if(entity.getPushState() == 0) {
flag = false;
}
}
if (flag) {
log.info("关播现场:" + scene.getId());
scene.setLiveState(SceneConstants.LIVE_STATE_REVIEW);
scene.setActualLiveEnd(new Date());
liveSceneService.updateById(scene);
//yang 20210803 关闭直播时关闭第三方流
List<LiveSceneLiveInfoEntity> list = liveSceneLiveInfoService.selectList(new EntityWrapper<LiveSceneLiveInfoEntity>().eq("scene_id", scene.getId()));
if (CollectionUtil.isNotEmpty(list))
for (LiveSceneLiveInfoEntity liveInfo : list)
liveSceneService.streamPullEndEntity(liveInfo);
}
}
}
}

View File

@ -17,6 +17,8 @@ import org.springframework.stereotype.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Set;
@Component
@DisallowConcurrentExecution
public class LikeSyncTask {
@ -31,52 +33,95 @@ public class LikeSyncTask {
@Autowired
private LiveReportService liveReportService;
// public void syncLikesToDatabase() {
// RedisConnection connection = null;
// try {
// connection = redisTemplate.getConnectionFactory().getConnection();
// ScanOptions options = ScanOptions.scanOptions().match("scene:liveCount:*").build();
// Cursor<byte[]> cursor = connection.scan(options);
//
// RedisSerializer<String> serializer = new StringRedisSerializer();
//
// while (cursor.hasNext()) {
// byte[] keyBytes = cursor.next();
// String key = serializer.deserialize(keyBytes);
//
// if (key != null) {
// Integer sceneId = Integer.valueOf(key.split(":")[2]);
// Object liveCount = redisTemplate.opsForValue().get(key);
// if (liveCount != null) {
// long totalLikes = Long.parseLong(liveCount.toString());
// try {
// liveSceneCountService.addLiveCountToDb(sceneId, totalLikes);
// redisTemplate.delete(key);
// } catch (Exception e) {
// logger.error("Failed to sync likes for key: {}", key, e);
// }
// }
// }
// }
// }finally {
// if (connection != null) connection.close();
// }
// }
public void syncLikesToDatabase() {
RedisConnection connection = null;
try {
connection = redisTemplate.getConnectionFactory().getConnection();
ScanOptions options = ScanOptions.scanOptions().match("scene:liveCount:*").build();
Cursor<byte[]> cursor = connection.scan(options);
RedisSerializer<String> serializer = new StringRedisSerializer();
while (cursor.hasNext()) {
byte[] keyBytes = cursor.next();
String key = serializer.deserialize(keyBytes);
if (key != null) {
Integer sceneId = Integer.valueOf(key.split(":")[2]);
Object liveCount = redisTemplate.opsForValue().get(key);
if (liveCount != null) {
long totalLikes = Long.parseLong(liveCount.toString());
try {
liveSceneCountService.addLiveCountToDb(sceneId, totalLikes);
redisTemplate.delete(key);
} catch (Exception e) {
logger.error("Failed to sync likes for key: {}", key, e);
}
String pattern = "scene:liveCount:*";
Set<String> keys = redisTemplate.keys(pattern);
for (String key : keys) {
if (key != null) {
Integer sceneId = Integer.valueOf(key.split(":")[2]);
Object liveCount = redisTemplate.opsForValue().get(key);
if (liveCount != null) {
long totalLikes = Long.parseLong(liveCount.toString());
try {
liveSceneCountService.addLiveCountToDb(sceneId, totalLikes);
redisTemplate.delete(key);
} catch (Exception e) {
logger.error("Failed to sync likes for key: {}", key, e);
}
}
}
}finally {
if (connection != null) connection.close();
}
}
// public void syncReportLikesToDatabase() {
// RedisConnection connection = null;
// try {
// connection = redisTemplate.getConnectionFactory().getConnection();
// ScanOptions options = ScanOptions.scanOptions().match("scene:liveCount:*").build();
// Cursor<byte[]> cursor = connection.scan(options);
//
// RedisSerializer<String> serializer = new StringRedisSerializer();
//
// while (cursor.hasNext()) {
// byte[] keyBytes = cursor.next();
// String key = serializer.deserialize(keyBytes);
//
// if (key != null) {
// Integer reportId = Integer.valueOf(key.split(":")[2]);
// Object liveCount = redisTemplate.opsForValue().get(key);
// if (liveCount != null) {
// long totalLikes = Long.parseLong(liveCount.toString());
// try {
// liveReportService.addLiveCountToDb(reportId, totalLikes);
// redisTemplate.delete(key);
// } catch (Exception e) {
// logger.error("Failed to sync likes for key: {}", key, e);
// }
// }
// }
// }
// }finally {
// if (connection != null) connection.close(); // 归还连接
// }
// }
public void syncReportLikesToDatabase() {
RedisConnection connection = null;
try {
connection = redisTemplate.getConnectionFactory().getConnection();
ScanOptions options = ScanOptions.scanOptions().match("scene:liveCount:*").build();
Cursor<byte[]> cursor = connection.scan(options);
RedisSerializer<String> serializer = new StringRedisSerializer();
while (cursor.hasNext()) {
byte[] keyBytes = cursor.next();
String key = serializer.deserialize(keyBytes);
if (key != null) {
String pattern = "report:liveCount:*";
Set<String> keys = redisTemplate.keys(pattern);
for (String key : keys) {
if (key != null) {
Integer reportId = Integer.valueOf(key.split(":")[2]);
Object liveCount = redisTemplate.opsForValue().get(key);
if (liveCount != null) {
@ -90,9 +135,6 @@ public class LikeSyncTask {
}
}
}
}finally {
if (connection != null) connection.close(); // 归还连接
}
}
}