video_danmu
CREATE TABLE `video_danmu` (
`danmu_id` int NOT NULL AUTO_INCREMENT COMMENT '自增ID',
`video_id` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '视频ID',
`file_id` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '唯一ID',
`user_id` varchar(15) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '用户ID',
`post_time` datetime DEFAULT NULL COMMENT '发布时间',
`text` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '内容',
`mode` tinyint(1) DEFAULT NULL COMMENT '展示位置',
`color` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '颜色',
`time` int DEFAULT NULL COMMENT '展示时间',
PRIMARY KEY (`danmu_id`) USING BTREE,
KEY `idx_file_id` (`file_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=24 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='视频弹幕';
发布弹幕
Controller
@RequestMapping("/postDanmu")
@GlobalInterceptor(checkLogin = true)
public ResponseVO postDanmu(@NotEmpty String videoId,
@NotEmpty String fileId,
@NotEmpty @Size(max = 200) String text,
@NotNull Integer mode,
@NotEmpty String color,
@NotNull Integer time) {
VideoDanmu videoDanmu = new VideoDanmu();
videoDanmu.setVideoId(videoId);
videoDanmu.setFileId(fileId);
videoDanmu.setText(text);
videoDanmu.setMode(mode);
videoDanmu.setColor(color);
videoDanmu.setTime(time);
videoDanmu.setUserId(getTokenUserInfoDto().getUserId());
videoDanmu.setPostTime(new Date());
videoDanmuService.saveVideoDanmu(videoDanmu);
return getSuccessResponseVO(null);
}
videoDanmuService.saveVideoDanmu(videoDanmu);
@Override
@Transactional(rollbackFor = Exception.class)
public void saveVideoDanmu(VideoDanmu videoDanmu) {
VideoInfo videoInfo = videoInfoMapper.selectByVideoId(videoDanmu.getVideoId());
if(videoInfo==null){
throw new BusinessException(ResponseCodeEnum.CODE_600);
}
if(videoInfo.getInteraction()!=null&&videoInfo.getInteraction().contains(Constants.ONE.toString())){
throw new BusinessException("UP主已关闭弹幕");
}
videoDanmuMapper.insert(videoDanmu);
videoInfoMapper.updateCountInfo(videoDanmu.getVideoId(),
UserActionTypeEnum.VIDEO_DANMU.getField(),
Constants.ONE);
esSearchComponent.updateDocCount(videoDanmu.getVideoId(),SearchOrderTypeEnum.VIDEO_DANMU.getField(),1);
}
查询弹幕
Controller
@RequestMapping("/loadDanmu")
public ResponseVO loadDanmu(@NotEmpty String fileId, @NotEmpty String videoId) {
VideoInfo videoInfo = videoInfoService.getVideoInfoByVideoId(videoId);
if (videoInfo.getInteraction() != null && videoInfo.getInteraction().contains(Constants.ZERO.toString())) {
return getSuccessResponseVO(new ArrayList<>());
}
VideoDanmuQuery videoDanmuQuery = new VideoDanmuQuery();
videoDanmuQuery.setFileId(fileId);
videoDanmuQuery.setOrderBy("danmu_id asc");
return getSuccessResponseVO(videoDanmuService.findListByParam(videoDanmuQuery));
}
}