feat(database): 为Camera结构体添加Enabled字段并实现兼容查询
refactor(web): 增强摄像头管理表单和卡片显示功能 移除Java集成示例代码,专注于Go实现 ``` 这个提交消息: 1. 使用中文描述变更内容 2. 分为三个主要部分: - 数据库功能增强:添加Enabled字段并实现兼容查询 - 前端重构:改进摄像头管理界面 - 清理:移除不再需要的Java示例代码 3. 遵循了类型+简要描述的格式 4. 对数据库变更使用了feat类型,对界面改进使用了refactor类型 5. 保持了简洁性,同时涵盖了主要变更点ziyun-rtsp-web
parent
1a617370d6
commit
575fe52b9a
Binary file not shown.
@ -1,342 +0,0 @@
|
|||||||
package com.example.rtspweb;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import org.springframework.http.*;
|
|
||||||
import org.springframework.web.client.RestTemplate;
|
|
||||||
import org.springframework.web.client.HttpClientErrorException;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RTSPtoWeb Java客户端
|
|
||||||
* 用于与RTSPtoWeb Go服务进行API交互
|
|
||||||
*/
|
|
||||||
public class RTSPWebClient {
|
|
||||||
|
|
||||||
private final String baseUrl;
|
|
||||||
private final RestTemplate restTemplate;
|
|
||||||
private final ObjectMapper objectMapper;
|
|
||||||
|
|
||||||
public RTSPWebClient(String baseUrl) {
|
|
||||||
this.baseUrl = baseUrl.endsWith("/") ? baseUrl.substring(0, baseUrl.length() - 1) : baseUrl;
|
|
||||||
this.restTemplate = new RestTemplate();
|
|
||||||
this.objectMapper = new ObjectMapper();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取摄像头列表
|
|
||||||
*/
|
|
||||||
public ApiResponse<CameraListResponse> getCameras(String unitCode, String status, int page, int size) {
|
|
||||||
try {
|
|
||||||
String url = String.format("%s/api/java/cameras?page=%d&size=%d", baseUrl, page, size);
|
|
||||||
if (unitCode != null && !unitCode.isEmpty()) {
|
|
||||||
url += "&unit_code=" + unitCode;
|
|
||||||
}
|
|
||||||
if (status != null && !status.isEmpty()) {
|
|
||||||
url += "&status=" + status;
|
|
||||||
}
|
|
||||||
|
|
||||||
ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
|
|
||||||
|
|
||||||
TypeReference<ApiResponse<CameraListResponse>> typeRef = new TypeReference<ApiResponse<CameraListResponse>>() {};
|
|
||||||
return objectMapper.readValue(response.getBody(), typeRef);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return createErrorResponse("获取摄像头列表失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取流列表
|
|
||||||
*/
|
|
||||||
public ApiResponse<StreamListResponse> getStreams(int page, int size) {
|
|
||||||
try {
|
|
||||||
String url = String.format("%s/api/java/streams?page=%d&size=%d", baseUrl, page, size);
|
|
||||||
|
|
||||||
ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
|
|
||||||
|
|
||||||
TypeReference<ApiResponse<StreamListResponse>> typeRef = new TypeReference<ApiResponse<StreamListResponse>>() {};
|
|
||||||
return objectMapper.readValue(response.getBody(), typeRef);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return createErrorResponse("获取流列表失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取摄像头详情
|
|
||||||
*/
|
|
||||||
public ApiResponse<Camera> getCameraDetail(String cameraId) {
|
|
||||||
try {
|
|
||||||
String url = String.format("%s/api/java/camera/%s", baseUrl, cameraId);
|
|
||||||
|
|
||||||
ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
|
|
||||||
|
|
||||||
TypeReference<ApiResponse<Camera>> typeRef = new TypeReference<ApiResponse<Camera>>() {};
|
|
||||||
return objectMapper.readValue(response.getBody(), typeRef);
|
|
||||||
} catch (HttpClientErrorException e) {
|
|
||||||
if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
|
|
||||||
return createErrorResponse("摄像头不存在");
|
|
||||||
}
|
|
||||||
return createErrorResponse("获取摄像头详情失败: " + e.getMessage());
|
|
||||||
} catch (Exception e) {
|
|
||||||
return createErrorResponse("获取摄像头详情失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取系统信息
|
|
||||||
*/
|
|
||||||
public ApiResponse<SystemInfo> getSystemInfo() {
|
|
||||||
try {
|
|
||||||
String url = String.format("%s/api/java/system/info", baseUrl);
|
|
||||||
|
|
||||||
ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
|
|
||||||
|
|
||||||
TypeReference<ApiResponse<SystemInfo>> typeRef = new TypeReference<ApiResponse<SystemInfo>>() {};
|
|
||||||
return objectMapper.readValue(response.getBody(), typeRef);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return createErrorResponse("获取系统信息失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加摄像头
|
|
||||||
*/
|
|
||||||
public ApiResponse<Camera> addCamera(Camera camera) {
|
|
||||||
try {
|
|
||||||
String url = String.format("%s/camera/add", baseUrl);
|
|
||||||
|
|
||||||
HttpHeaders headers = new HttpHeaders();
|
|
||||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
|
||||||
|
|
||||||
HttpEntity<Camera> request = new HttpEntity<>(camera, headers);
|
|
||||||
|
|
||||||
ResponseEntity<String> response = restTemplate.postForEntity(url, request, String.class);
|
|
||||||
|
|
||||||
TypeReference<ApiResponse<Camera>> typeRef = new TypeReference<ApiResponse<Camera>>() {};
|
|
||||||
return objectMapper.readValue(response.getBody(), typeRef);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return createErrorResponse("添加摄像头失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 刷新摄像头状态
|
|
||||||
*/
|
|
||||||
public ApiResponse<Object> refreshCameras() {
|
|
||||||
try {
|
|
||||||
String url = String.format("%s/cameras/refresh", baseUrl);
|
|
||||||
|
|
||||||
HttpHeaders headers = new HttpHeaders();
|
|
||||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
|
||||||
|
|
||||||
HttpEntity<String> request = new HttpEntity<>("{}", headers);
|
|
||||||
|
|
||||||
ResponseEntity<String> response = restTemplate.postForEntity(url, request, String.class);
|
|
||||||
|
|
||||||
TypeReference<ApiResponse<Object>> typeRef = new TypeReference<ApiResponse<Object>>() {};
|
|
||||||
return objectMapper.readValue(response.getBody(), typeRef);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return createErrorResponse("刷新摄像头状态失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private <T> ApiResponse<T> createErrorResponse(String message) {
|
|
||||||
ApiResponse<T> response = new ApiResponse<>();
|
|
||||||
response.setCode(500);
|
|
||||||
response.setMessage(message);
|
|
||||||
response.setSuccess(false);
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 数据模型类
|
|
||||||
public static class ApiResponse<T> {
|
|
||||||
private int code;
|
|
||||||
private String message;
|
|
||||||
private T data;
|
|
||||||
private boolean success;
|
|
||||||
|
|
||||||
// Getters and Setters
|
|
||||||
public int getCode() { return code; }
|
|
||||||
public void setCode(int code) { this.code = code; }
|
|
||||||
|
|
||||||
public String getMessage() { return message; }
|
|
||||||
public void setMessage(String message) { this.message = message; }
|
|
||||||
|
|
||||||
public T getData() { return data; }
|
|
||||||
public void setData(T data) { this.data = data; }
|
|
||||||
|
|
||||||
public boolean isSuccess() { return success; }
|
|
||||||
public void setSuccess(boolean success) { this.success = success; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class CameraListResponse {
|
|
||||||
private int total;
|
|
||||||
private List<Camera> cameras;
|
|
||||||
|
|
||||||
public int getTotal() { return total; }
|
|
||||||
public void setTotal(int total) { this.total = total; }
|
|
||||||
|
|
||||||
public List<Camera> getCameras() { return cameras; }
|
|
||||||
public void setCameras(List<Camera> cameras) { this.cameras = cameras; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class StreamListResponse {
|
|
||||||
private int total;
|
|
||||||
private List<Stream> streams;
|
|
||||||
|
|
||||||
public int getTotal() { return total; }
|
|
||||||
public void setTotal(int total) { this.total = total; }
|
|
||||||
|
|
||||||
public List<Stream> getStreams() { return streams; }
|
|
||||||
public void setStreams(List<Stream> streams) { this.streams = streams; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Camera {
|
|
||||||
private String id;
|
|
||||||
private String name;
|
|
||||||
private String ip;
|
|
||||||
private int port;
|
|
||||||
private String username;
|
|
||||||
private String password;
|
|
||||||
@JsonProperty("rtsp_url")
|
|
||||||
private String rtspUrl;
|
|
||||||
private String status;
|
|
||||||
private boolean enabled;
|
|
||||||
@JsonProperty("device_type")
|
|
||||||
private String deviceType;
|
|
||||||
@JsonProperty("unit_code")
|
|
||||||
private String unitCode;
|
|
||||||
@JsonProperty("created_at")
|
|
||||||
private LocalDateTime createdAt;
|
|
||||||
@JsonProperty("updated_at")
|
|
||||||
private LocalDateTime updatedAt;
|
|
||||||
@JsonProperty("play_urls")
|
|
||||||
private PlayUrls playUrls;
|
|
||||||
|
|
||||||
// Getters and Setters
|
|
||||||
public String getId() { return id; }
|
|
||||||
public void setId(String id) { this.id = id; }
|
|
||||||
|
|
||||||
public String getName() { return name; }
|
|
||||||
public void setName(String name) { this.name = name; }
|
|
||||||
|
|
||||||
public String getIp() { return ip; }
|
|
||||||
public void setIp(String ip) { this.ip = ip; }
|
|
||||||
|
|
||||||
public int getPort() { return port; }
|
|
||||||
public void setPort(int port) { this.port = port; }
|
|
||||||
|
|
||||||
public String getUsername() { return username; }
|
|
||||||
public void setUsername(String username) { this.username = username; }
|
|
||||||
|
|
||||||
public String getPassword() { return password; }
|
|
||||||
public void setPassword(String password) { this.password = password; }
|
|
||||||
|
|
||||||
public String getRtspUrl() { return rtspUrl; }
|
|
||||||
public void setRtspUrl(String rtspUrl) { this.rtspUrl = rtspUrl; }
|
|
||||||
|
|
||||||
public String getStatus() { return status; }
|
|
||||||
public void setStatus(String status) { this.status = status; }
|
|
||||||
|
|
||||||
public boolean isEnabled() { return enabled; }
|
|
||||||
public void setEnabled(boolean enabled) { this.enabled = enabled; }
|
|
||||||
|
|
||||||
public String getDeviceType() { return deviceType; }
|
|
||||||
public void setDeviceType(String deviceType) { this.deviceType = deviceType; }
|
|
||||||
|
|
||||||
public String getUnitCode() { return unitCode; }
|
|
||||||
public void setUnitCode(String unitCode) { this.unitCode = unitCode; }
|
|
||||||
|
|
||||||
public LocalDateTime getCreatedAt() { return createdAt; }
|
|
||||||
public void setCreatedAt(LocalDateTime createdAt) { this.createdAt = createdAt; }
|
|
||||||
|
|
||||||
public LocalDateTime getUpdatedAt() { return updatedAt; }
|
|
||||||
public void setUpdatedAt(LocalDateTime updatedAt) { this.updatedAt = updatedAt; }
|
|
||||||
|
|
||||||
public PlayUrls getPlayUrls() { return playUrls; }
|
|
||||||
public void setPlayUrls(PlayUrls playUrls) { this.playUrls = playUrls; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Stream {
|
|
||||||
private String id;
|
|
||||||
private String name;
|
|
||||||
private Map<String, String> channels;
|
|
||||||
@JsonProperty("play_urls")
|
|
||||||
private PlayUrls playUrls;
|
|
||||||
|
|
||||||
// Getters and Setters
|
|
||||||
public String getId() { return id; }
|
|
||||||
public void setId(String id) { this.id = id; }
|
|
||||||
|
|
||||||
public String getName() { return name; }
|
|
||||||
public void setName(String name) { this.name = name; }
|
|
||||||
|
|
||||||
public Map<String, String> getChannels() { return channels; }
|
|
||||||
public void setChannels(Map<String, String> channels) { this.channels = channels; }
|
|
||||||
|
|
||||||
public PlayUrls getPlayUrls() { return playUrls; }
|
|
||||||
public void setPlayUrls(PlayUrls playUrls) { this.playUrls = playUrls; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class PlayUrls {
|
|
||||||
private String hls;
|
|
||||||
private String webrtc;
|
|
||||||
private String mse;
|
|
||||||
private String all;
|
|
||||||
|
|
||||||
// Getters and Setters
|
|
||||||
public String getHls() { return hls; }
|
|
||||||
public void setHls(String hls) { this.hls = hls; }
|
|
||||||
|
|
||||||
public String getWebrtc() { return webrtc; }
|
|
||||||
public void setWebrtc(String webrtc) { this.webrtc = webrtc; }
|
|
||||||
|
|
||||||
public String getMse() { return mse; }
|
|
||||||
public void setMse(String mse) { this.mse = mse; }
|
|
||||||
|
|
||||||
public String getAll() { return all; }
|
|
||||||
public void setAll(String all) { this.all = all; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class SystemInfo {
|
|
||||||
private String version;
|
|
||||||
@JsonProperty("database_enabled")
|
|
||||||
private boolean databaseEnabled;
|
|
||||||
@JsonProperty("demo_enabled")
|
|
||||||
private boolean demoEnabled;
|
|
||||||
@JsonProperty("total_streams")
|
|
||||||
private int totalStreams;
|
|
||||||
@JsonProperty("total_cameras")
|
|
||||||
private int totalCameras;
|
|
||||||
@JsonProperty("online_cameras")
|
|
||||||
private int onlineCameras;
|
|
||||||
@JsonProperty("server_time")
|
|
||||||
private String serverTime;
|
|
||||||
|
|
||||||
// Getters and Setters
|
|
||||||
public String getVersion() { return version; }
|
|
||||||
public void setVersion(String version) { this.version = version; }
|
|
||||||
|
|
||||||
public boolean isDatabaseEnabled() { return databaseEnabled; }
|
|
||||||
public void setDatabaseEnabled(boolean databaseEnabled) { this.databaseEnabled = databaseEnabled; }
|
|
||||||
|
|
||||||
public boolean isDemoEnabled() { return demoEnabled; }
|
|
||||||
public void setDemoEnabled(boolean demoEnabled) { this.demoEnabled = demoEnabled; }
|
|
||||||
|
|
||||||
public int getTotalStreams() { return totalStreams; }
|
|
||||||
public void setTotalStreams(int totalStreams) { this.totalStreams = totalStreams; }
|
|
||||||
|
|
||||||
public int getTotalCameras() { return totalCameras; }
|
|
||||||
public void setTotalCameras(int totalCameras) { this.totalCameras = totalCameras; }
|
|
||||||
|
|
||||||
public int getOnlineCameras() { return onlineCameras; }
|
|
||||||
public void setOnlineCameras(int onlineCameras) { this.onlineCameras = onlineCameras; }
|
|
||||||
|
|
||||||
public String getServerTime() { return serverTime; }
|
|
||||||
public void setServerTime(String serverTime) { this.serverTime = serverTime; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue