From 60ebfde91e9c975f59df4d60a6cb5a7861958bd2 Mon Sep 17 00:00:00 2001
From: shinnosuke <tantao@1hoper.com>
Date: 星期三, 30 九月 2026 17:04:37 +0800
Subject: [PATCH] fix(live): 修复管理端「编辑」「查看」直播内容报 500 的问题
---
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TSysLiveController.java | 14 ++++++++++----
ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/TSysLiveController.java | 4 ++--
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TSysLiveServiceImpl.java | 6 ++++--
3 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TSysLiveController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TSysLiveController.java
index b944857..8f51cdc 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TSysLiveController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TSysLiveController.java
@@ -105,6 +105,10 @@
if(Objects.nonNull(dto.getStartTime()) && Objects.nonNull(dto.getExpectedDuration())){
dto.setEndTime(dto.getStartTime().plusMinutes(dto.getExpectedDuration()));
}
+ // 点击次数默认 0,避免后续自增时 NPE
+ if (Objects.isNull(dto.getClickCount())) {
+ dto.setClickCount(0);
+ }
// 创建小鹅通直播
// XiaoeLiveDTO xiaoeLiveDTO = new XiaoeLiveDTO();
@@ -136,8 +140,10 @@
// if (dto.getStartTime().isBefore(LocalDateTime.now())) {
// return R.fail("直播已开始,无法编辑");
// }
- // 计算结束时间
- dto.setEndTime(dto.getStartTime().plusMinutes(dto.getExpectedDuration()));
+ // 计算结束时间(视频类型没有开始时间和预计时长,必须判空,否则编辑接口会 500)
+ if (Objects.nonNull(dto.getStartTime()) && Objects.nonNull(dto.getExpectedDuration())) {
+ dto.setEndTime(dto.getStartTime().plusMinutes(dto.getExpectedDuration()));
+ }
// 编辑小鹅通直播
// XiaoeLiveDTO xiaoeLiveDTO = new XiaoeLiveDTO();
@@ -164,8 +170,8 @@
@GetMapping(value = "/getDetailById")
public R<TSysLive> getDetailById(@RequestParam String id) {
TSysLive sysLive = sysLiveService.getById(id);
- // 查询次数自增 使用数据库原子更新操作
- sysLive.setClickCount(sysLive.getClickCount()+1);
+ // 查询次数自增(历史数据 click_count 可能为 NULL,需判空)
+ sysLive.setClickCount(Objects.isNull(sysLive.getClickCount()) ? 1 : sysLive.getClickCount() + 1);
sysLiveService.updateById(sysLive);
// 如果是诊所
Integer roleType = tokenService.getLoginUser().getUser().getRoleType();
diff --git a/ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/TSysLiveController.java b/ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/TSysLiveController.java
index 143df94..96210ee 100644
--- a/ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/TSysLiveController.java
+++ b/ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/TSysLiveController.java
@@ -74,8 +74,8 @@
@GetMapping(value = "/getDetailById")
public R<TSysLive> getDetailById(@RequestParam String id) {
TSysLive sysLive = sysLiveService.getById(id);
- // 查询次数自增 使用数据库原子更新操作
- sysLive.setClickCount(sysLive.getClickCount() + 1);
+ // 查询次数自增(历史数据 click_count 可能为 NULL,需判空)
+ sysLive.setClickCount(Objects.isNull(sysLive.getClickCount()) ? 1 : sysLive.getClickCount() + 1);
sysLiveService.updateById(sysLive);
return R.ok(sysLive);
}
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TSysLiveServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TSysLiveServiceImpl.java
index 7b7cfa7..3e6f2b6 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TSysLiveServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TSysLiveServiceImpl.java
@@ -50,8 +50,10 @@
public R pushUser(String id, String pushType) {
TSysLive sysLive = this.getById(id);
if (Objects.nonNull(sysLive)){
- // 判断直播开始时间是否在当前时间之后
- if (sysLive.getContentType()==1 && sysLive.getStartTime().isBefore(LocalDateTime.now())){
+ // 判断直播开始时间是否在当前时间之后(contentType / startTime 可能为空,需判空)
+ if (Objects.nonNull(sysLive.getContentType()) && sysLive.getContentType() == 1
+ && Objects.nonNull(sysLive.getStartTime())
+ && sysLive.getStartTime().isBefore(LocalDateTime.now())){
return R.fail("直播已开始,无法配置推送");
}
sysLive.setPushType(pushType);
--
Gitblit v1.7.1