补上家长选班、巡课多画面、找回密码和管理端的节次与安全设置。
This commit is contained in:
1 parent
339641040e
commit
0afc29d431
17 files changed
+381
-113
No files matched your search
@@ -0,0 +1,70 @@
|
||||
package com.xh.xunke.recording;
|
||||
|
||||
import com.xh.xunke.config.AppProperties;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Component
|
||||
public class MediaProbe {
|
||||
private static final Logger log = LoggerFactory.getLogger(MediaProbe.class);
|
||||
private final RecordingRepository recordings;
|
||||
private final ObjectStorage storage;
|
||||
private final AppProperties props;
|
||||
|
||||
public MediaProbe(RecordingRepository recordings, ObjectStorage storage, AppProperties props) {
|
||||
this.recordings = recordings;
|
||||
this.storage = storage;
|
||||
this.props = props;
|
||||
}
|
||||
|
||||
@Async("mediaExecutor")
|
||||
public void probe(Long recordingId) {
|
||||
Recording recording = recordings.findById(recordingId).orElse(null);
|
||||
if (recording == null || recording.getObjectKey() == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
String url = storage.presignInternal(recording.getObjectKey(), 10);
|
||||
Process process = new ProcessBuilder(props.getFfprobePath(), "-v", "error", "-show_streams",
|
||||
"-print_format", "json", url)
|
||||
.redirectErrorStream(true)
|
||||
.start();
|
||||
boolean finished = process.waitFor(20, TimeUnit.SECONDS);
|
||||
String output;
|
||||
try (InputStream in = process.getInputStream()) {
|
||||
output = new String(in.readAllBytes(), StandardCharsets.UTF_8);
|
||||
}
|
||||
if (!finished) {
|
||||
process.destroyForcibly();
|
||||
markFailed(recording, "探针超时");
|
||||
return;
|
||||
}
|
||||
ProbeParser.Result result = ProbeParser.parse(output);
|
||||
recording.setHasVideo(result.video());
|
||||
recording.setHasAudio(result.audio());
|
||||
if (result.video() && result.audio()) {
|
||||
recording.setStatus("COMPLETED");
|
||||
recording.setErrorMessage(null);
|
||||
} else {
|
||||
recording.setStatus("FAILED");
|
||||
recording.setErrorMessage(result.video() ? "录像缺少音轨" : "录像缺少视频轨");
|
||||
}
|
||||
recordings.save(recording);
|
||||
} catch (Exception ex) {
|
||||
log.warn("录像探针失败");
|
||||
markFailed(recording, "无法检查录像文件");
|
||||
}
|
||||
}
|
||||
|
||||
private void markFailed(Recording recording, String reason) {
|
||||
recording.setStatus("FAILED");
|
||||
recording.setErrorMessage(reason);
|
||||
recordings.save(recording);
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,8 @@ import java.util.Optional;
|
||||
public interface RecordingRepository extends JpaRepository<Recording, Long> {
|
||||
Optional<Recording> findFirstBySessionIdOrderByIdDesc(Long sessionId);
|
||||
|
||||
Optional<Recording> findFirstByEgressId(String egressId);
|
||||
|
||||
Page<Recording> findBySchoolId(Long schoolId, Pageable pageable);
|
||||
|
||||
Page<Recording> findByClassId(Long classId, Pageable pageable);
|
||||
|
||||
@@ -12,21 +12,14 @@ import com.xh.xunke.school.BindingService;
|
||||
import com.xh.xunke.school.SchoolRepository;
|
||||
import com.xh.xunke.security.UserPrincipal;
|
||||
import livekit.LivekitWebhook;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Service
|
||||
public class RecordingService {
|
||||
private static final Logger log = LoggerFactory.getLogger(RecordingService.class);
|
||||
private final RecordingRepository recordings;
|
||||
private final LiveSessionRepository sessions;
|
||||
private final LiveKitGateway liveKit;
|
||||
@@ -34,9 +27,11 @@ public class RecordingService {
|
||||
private final BindingService bindings;
|
||||
private final SchoolRepository schools;
|
||||
private final AppProperties props;
|
||||
private final MediaProbe mediaProbe;
|
||||
|
||||
public RecordingService(RecordingRepository recordings, LiveSessionRepository sessions, LiveKitGateway liveKit,
|
||||
ObjectStorage storage, BindingService bindings, SchoolRepository schools, AppProperties props) {
|
||||
ObjectStorage storage, BindingService bindings, SchoolRepository schools, AppProperties props,
|
||||
MediaProbe mediaProbe) {
|
||||
this.recordings = recordings;
|
||||
this.sessions = sessions;
|
||||
this.liveKit = liveKit;
|
||||
@@ -44,6 +39,7 @@ public class RecordingService {
|
||||
this.bindings = bindings;
|
||||
this.schools = schools;
|
||||
this.props = props;
|
||||
this.mediaProbe = mediaProbe;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@@ -87,10 +83,7 @@ public class RecordingService {
|
||||
return;
|
||||
}
|
||||
String egressId = event.getEgressInfo().getEgressId();
|
||||
recordings.findAll().stream()
|
||||
.filter(item -> egressId.equals(item.getEgressId()))
|
||||
.findFirst()
|
||||
.ifPresent(recording -> {
|
||||
recordings.findFirstByEgressId(egressId).ifPresent(recording -> {
|
||||
String name = event.getEvent();
|
||||
if ("egress_ended".equals(name) || "egress_complete".equals(name) || name.contains("ended")) {
|
||||
recording.setStatus("PROCESSING");
|
||||
@@ -100,7 +93,7 @@ public class RecordingService {
|
||||
recording.setDurationSeconds((int) event.getEgressInfo().getFileResults(0).getDuration());
|
||||
}
|
||||
recordings.save(recording);
|
||||
probeLater(recording.getId());
|
||||
mediaProbe.probe(recording.getId());
|
||||
} else if (name.contains("failed") || name.contains("aborted")) {
|
||||
recording.setStatus("FAILED");
|
||||
recording.setErrorMessage("录像任务失败");
|
||||
@@ -110,45 +103,6 @@ public class RecordingService {
|
||||
});
|
||||
}
|
||||
|
||||
@Async("mediaExecutor")
|
||||
public void probeLater(Long recordingId) {
|
||||
Recording recording = recordings.findById(recordingId).orElse(null);
|
||||
if (recording == null || recording.getObjectKey() == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
String url = storage.presignInternal(recording.getObjectKey(), 10);
|
||||
Process process = new ProcessBuilder(props.getFfprobePath(), "-v", "error", "-show_streams",
|
||||
"-print_format", "json", url)
|
||||
.redirectErrorStream(true)
|
||||
.start();
|
||||
boolean finished = process.waitFor(20, TimeUnit.SECONDS);
|
||||
String output;
|
||||
try (InputStream in = process.getInputStream()) {
|
||||
output = new String(in.readAllBytes(), StandardCharsets.UTF_8);
|
||||
}
|
||||
if (!finished) {
|
||||
process.destroyForcibly();
|
||||
markFailed(recording, "探针超时");
|
||||
return;
|
||||
}
|
||||
ProbeParser.Result result = ProbeParser.parse(output);
|
||||
recording.setHasVideo(result.video());
|
||||
recording.setHasAudio(result.audio());
|
||||
if (result.video() && result.audio()) {
|
||||
recording.setStatus("COMPLETED");
|
||||
recording.setErrorMessage(null);
|
||||
} else {
|
||||
recording.setStatus("FAILED");
|
||||
recording.setErrorMessage(result.video() ? "录像缺少音轨" : "录像缺少视频轨");
|
||||
}
|
||||
recordings.save(recording);
|
||||
} catch (Exception ex) {
|
||||
log.warn("录像探针失败");
|
||||
markFailed(recording, "无法检查录像文件");
|
||||
}
|
||||
}
|
||||
|
||||
public PagePayload<Recording> list(UserPrincipal me, Long classId, int page, int size) {
|
||||
var result = classId != null
|
||||
? recordings.findByClassId(classId, Pages.of(page, size))
|
||||
@@ -203,7 +157,7 @@ public class RecordingService {
|
||||
return recordings.save(recording);
|
||||
}
|
||||
if (storage.exists(recording.getObjectKey())) {
|
||||
probeLater(recording.getId());
|
||||
mediaProbe.probe(recording.getId());
|
||||
recording.setStatus("PROCESSING");
|
||||
return recordings.save(recording);
|
||||
}
|
||||
@@ -239,9 +193,4 @@ public class RecordingService {
|
||||
return sessions.findById(recording.getSessionId()).map(session -> session.getTeacherId().equals(me.id())).orElse(false);
|
||||
}
|
||||
|
||||
private void markFailed(Recording recording, String reason) {
|
||||
recording.setStatus("FAILED");
|
||||
recording.setErrorMessage(reason);
|
||||
recordings.save(recording);
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,10 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class SchoolService {
|
||||
@@ -159,6 +162,25 @@ public class SchoolService {
|
||||
grades.delete(grade);
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> directory() {
|
||||
Map<Long, String> schoolNames = new LinkedHashMap<>();
|
||||
List<Map<String, Object>> rows = new ArrayList<>();
|
||||
for (ClassRoom room : classes.findAll()) {
|
||||
if (!"ACTIVE".equals(room.getStatus())) {
|
||||
continue;
|
||||
}
|
||||
String schoolName = schoolNames.computeIfAbsent(room.getSchoolId(), id ->
|
||||
schools.findById(id).map(School::getName).orElse(""));
|
||||
Map<String, Object> row = new LinkedHashMap<>();
|
||||
row.put("id", room.getId());
|
||||
row.put("name", room.getName());
|
||||
row.put("schoolId", room.getSchoolId());
|
||||
row.put("schoolName", schoolName);
|
||||
rows.add(row);
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
public PagePayload<ClassRoom> classes(UserPrincipal me, Long schoolId, int page, int size) {
|
||||
Long scoped = me.superAdmin() ? schoolId : me.schoolId();
|
||||
var result = scoped == null
|
||||
|
||||
@@ -427,6 +427,11 @@ public class ResourceController {
|
||||
return ApiResponse.ok(stats);
|
||||
}
|
||||
|
||||
@GetMapping("/directory/classes")
|
||||
public ApiResponse<List<Map<String, Object>>> directory() {
|
||||
return ApiResponse.ok(schools.directory());
|
||||
}
|
||||
|
||||
@GetMapping("/parent/home")
|
||||
public ApiResponse<Map<String, Object>> parentHome() {
|
||||
var mine = bindings.list(me(), null, 0, 50);
|
||||
|
||||
Reference in new issue
Block a user