|
|
|
@ -164,46 +164,46 @@ public class RecordInspectionCabinetController extends BaseController
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 处理GET请求,返回指定路径的视频文件。
|
|
|
|
|
* @param filePath 视频文件的路径
|
|
|
|
|
* @return ResponseEntity<FileSystemResource> 包含视频文件资源的响应实体
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("/getVisibleVideo/{filePath}")
|
|
|
|
|
public ResponseEntity<FileSystemResource> getVisibleVideo(@PathVariable String filePath) {
|
|
|
|
|
// 获取配置文件中的路径application.yml的profile
|
|
|
|
|
String myPath = RuoYiConfig.getMyPath();
|
|
|
|
|
// 构建完整的文件路径
|
|
|
|
|
String fileUrl = myPath + "/日志信息/巡检录像/可见光/" + filePath;
|
|
|
|
|
// 创建文件对象
|
|
|
|
|
File file = new File(fileUrl);
|
|
|
|
|
// 检查文件是否存在
|
|
|
|
|
if (file.exists()) {
|
|
|
|
|
// 如果文件存在,创建文件系统资源对象
|
|
|
|
|
FileSystemResource resource = new FileSystemResource(file);
|
|
|
|
|
// 设置HTTP头信息
|
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
// 设置文件长度
|
|
|
|
|
headers.setContentLength(file.length());
|
|
|
|
|
// 动态检测文件的MIME类型
|
|
|
|
|
try {
|
|
|
|
|
String contentType = Files.probeContentType(file.toPath());
|
|
|
|
|
if (contentType != null) {
|
|
|
|
|
headers.setContentType(MediaType.parseMediaType(contentType));
|
|
|
|
|
} else {
|
|
|
|
|
/**
|
|
|
|
|
* 处理GET请求,返回指定路径的视频文件。
|
|
|
|
|
* @param filePath 视频文件的路径
|
|
|
|
|
* @return ResponseEntity<FileSystemResource> 包含视频文件资源的响应实体
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("/getVisibleVideo/{filePath}")
|
|
|
|
|
public ResponseEntity<FileSystemResource> getVisibleVideo(@PathVariable String filePath) {
|
|
|
|
|
// 获取配置文件中的路径application.yml的profile
|
|
|
|
|
String myPath = RuoYiConfig.getMyPath();
|
|
|
|
|
// 构建完整的文件路径
|
|
|
|
|
String fileUrl = myPath + "/日志信息/巡检录像/可见光/" + filePath;
|
|
|
|
|
// 创建文件对象
|
|
|
|
|
File file = new File(fileUrl);
|
|
|
|
|
// 检查文件是否存在
|
|
|
|
|
if (file.exists()) {
|
|
|
|
|
// 如果文件存在,创建文件系统资源对象
|
|
|
|
|
FileSystemResource resource = new FileSystemResource(file);
|
|
|
|
|
// 设置HTTP头信息
|
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
// 设置文件长度
|
|
|
|
|
headers.setContentLength(file.length());
|
|
|
|
|
// 动态检测文件的MIME类型
|
|
|
|
|
try {
|
|
|
|
|
String contentType = Files.probeContentType(file.toPath());
|
|
|
|
|
if (contentType != null) {
|
|
|
|
|
headers.setContentType(MediaType.parseMediaType(contentType));
|
|
|
|
|
} else {
|
|
|
|
|
headers.setContentType(MediaType.parseMediaType("video/*"));
|
|
|
|
|
}
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
headers.setContentType(MediaType.parseMediaType("video/*"));
|
|
|
|
|
}
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
headers.setContentType(MediaType.parseMediaType("video/*"));
|
|
|
|
|
// 返回包含文件资源的响应实体
|
|
|
|
|
return ResponseEntity.ok()
|
|
|
|
|
.headers(headers)
|
|
|
|
|
.body(resource);
|
|
|
|
|
} else {
|
|
|
|
|
// 如果文件不存在,返回404状态
|
|
|
|
|
return ResponseEntity.notFound().build();
|
|
|
|
|
}
|
|
|
|
|
// 返回包含文件资源的响应实体
|
|
|
|
|
return ResponseEntity.ok()
|
|
|
|
|
.headers(headers)
|
|
|
|
|
.body(resource);
|
|
|
|
|
} else {
|
|
|
|
|
// 如果文件不存在,返回404状态
|
|
|
|
|
return ResponseEntity.notFound().build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|