Commit 841e314f2ef20a58208f950830319fca292f8593

Authored by 648540858
1 parent 1cce3324

简化assist服务

src/main/java/top/panll/assist/config/StartConfig.java
@@ -64,85 +64,5 @@ public class StartConfig implements CommandLineRunner { @@ -64,85 +64,5 @@ public class StartConfig implements CommandLineRunner {
64 System.exit(1); 64 System.exit(1);
65 } 65 }
66 } 66 }
67 -  
68 - try {  
69 -  
70 - // 对目录进行预整理  
71 - File[] appFiles = recordFile.listFiles();  
72 - if (appFiles != null && appFiles.length > 0) {  
73 - for (File appFile : appFiles) {  
74 - if (appFile.getName().equals("recordTemp")) {  
75 - continue;  
76 - }  
77 - File[] streamFiles = appFile.listFiles();  
78 - if (streamFiles != null && streamFiles.length > 0) {  
79 - for (File streamFile : streamFiles) {  
80 - File[] dateFiles = streamFile.listFiles();  
81 - if (dateFiles != null && dateFiles.length > 0) {  
82 - for (File dateFile : dateFiles) {  
83 - File[] files = dateFile.listFiles();  
84 - if (files != null && files.length > 0) {  
85 - for (File file : files) {  
86 - videoFileService.handFile(file, appFile.getName(), streamFile.getName());  
87 - }  
88 - }  
89 - }  
90 - }  
91 -  
92 - }  
93 - }  
94 -  
95 - }  
96 - }  
97 -  
98 - } catch (Exception exception){  
99 - exception.printStackTrace();  
100 - logger.error("环境错误: " + exception.getMessage());  
101 - }  
102 } 67 }
103 -  
104 -// private void writeAssistDownPage(File recordFile) {  
105 -// try {  
106 -// File file = new File(recordFile.getParentFile().getAbsolutePath(), "download.html");  
107 -// if (file.exists()) {  
108 -// file.delete();  
109 -// }  
110 -// file.createNewFile();  
111 -// FileOutputStream fs = new FileOutputStream(file);  
112 -// StringBuffer stringBuffer = new StringBuffer();  
113 -// String content = "<!DOCTYPE html>\n" +  
114 -// "<html lang=\"en\">\n" +  
115 -// "<head>\n" +  
116 -// " <meta charset=\"UTF-8\">\n" +  
117 -// " <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n" +  
118 -// " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n" +  
119 -// " <title>下载</title>\n" +  
120 -// "</head>\n" +  
121 -// "<body>\n" +  
122 -// " <a id=\"download\" download />\n" +  
123 -// " <script>\n" +  
124 -// " (function(){\n" +  
125 -// " let searchParams = new URLSearchParams(location.search);\n" +  
126 -// " var download = document.getElementById(\"download\");\n" +  
127 -// " download.setAttribute(\"href\", searchParams.get(\"url\"))\n" +  
128 -// " download.click()\n" +  
129 -// " setTimeout(()=>{\n" +  
130 -// " window.location.href=\"about:blank\";\n" +  
131 -// "\t\t\t window.close();\n" +  
132 -// " },200)\n" +  
133 -// " })();\n" +  
134 -// " \n" +  
135 -// " </script>\n" +  
136 -// "</body>\n" +  
137 -// "</html>";  
138 -// fs.write(content.getBytes(StandardCharsets.UTF_8));  
139 -// logger.info("已写入html配置页面: " + file.getAbsolutePath());  
140 -// } catch (FileNotFoundException e) {  
141 -// logger.error("写入html页面错误", e);  
142 -// } catch (IOException e) {  
143 -// logger.error("写入html页面错误", e);  
144 -// }  
145 -//  
146 -//  
147 -// }  
148 } 68 }
src/main/java/top/panll/assist/controller/DownController.java deleted 100755 → 0
1 -package top.panll.assist.controller;  
2 -  
3 -  
4 -import org.apache.catalina.connector.ClientAbortException;  
5 -import org.mp4parser.BasicContainer;  
6 -import org.mp4parser.Container;  
7 -import org.mp4parser.muxer.Movie;  
8 -import org.mp4parser.muxer.Track;  
9 -import org.mp4parser.muxer.builder.DefaultMp4Builder;  
10 -import org.mp4parser.muxer.builder.Mp4Builder;  
11 -import org.mp4parser.muxer.container.mp4.MovieCreator;  
12 -import org.mp4parser.muxer.tracks.AppendTrack;  
13 -import org.slf4j.Logger;  
14 -import org.slf4j.LoggerFactory;  
15 -import org.springframework.beans.factory.annotation.Autowired;  
16 -import org.springframework.stereotype.Controller;  
17 -import org.springframework.web.bind.annotation.GetMapping;  
18 -import org.springframework.web.bind.annotation.RequestMapping;  
19 -import org.springframework.web.bind.annotation.ResponseBody;  
20 -import top.panll.assist.dto.UserSettings;  
21 -  
22 -import javax.servlet.http.HttpServletRequest;  
23 -import javax.servlet.http.HttpServletResponse;  
24 -import java.io.*;  
25 -import java.nio.channels.Channels;  
26 -import java.nio.channels.WritableByteChannel;  
27 -import java.nio.charset.StandardCharsets;  
28 -import java.util.ArrayList;  
29 -import java.util.LinkedList;  
30 -import java.util.List;  
31 -  
32 -@Controller  
33 -@RequestMapping("/down")  
34 -public class DownController {  
35 -  
36 - private final static Logger logger = LoggerFactory.getLogger(DownController.class);  
37 -  
38 - @Autowired  
39 - private UserSettings userSettings;  
40 -  
41 - /**  
42 - * 获取app+stream列表  
43 - *  
44 - * @return  
45 - */  
46 - @GetMapping(value = "/**")  
47 - @ResponseBody  
48 - public void download(HttpServletRequest request, HttpServletResponse response) throws IOException {  
49 -  
50 - List<String> videoList = new ArrayList<>();  
51 - videoList.add("/home/lin/server/test/zlm/Debug/www/record/rtp/34020000002000000003_34020000001310000001/2023-03-20/16-09-07.mp4");  
52 - videoList.add("/home/lin/server/test/zlm/Debug/www/record/rtp/34020000002000000003_34020000001310000001/2023-03-20/17-12-10.mp4");  
53 - videoList.add("/home/lin/server/test/zlm/Debug/www/record/rtp/34020000002000000003_34020000001310000001/2023-03-20/17-38-36.mp4");  
54 - List<Movie> sourceMovies = new ArrayList<>();  
55 - for (String video : videoList) {  
56 - sourceMovies.add(MovieCreator.build(video));  
57 - }  
58 -  
59 - List<Track> videoTracks = new LinkedList<>();  
60 - List<Track> audioTracks = new LinkedList<>();  
61 - for (Movie movie : sourceMovies) {  
62 - for (Track track : movie.getTracks()) {  
63 - if ("soun".equals(track.getHandler())) {  
64 - audioTracks.add(track);  
65 - }  
66 -  
67 - if ("vide".equals(track.getHandler())) {  
68 - videoTracks.add(track);  
69 - }  
70 - }  
71 - }  
72 - Movie mergeMovie = new Movie();  
73 - if (audioTracks.size() > 0) {  
74 - mergeMovie.addTrack(new AppendTrack(audioTracks.toArray(new Track[audioTracks.size()])));  
75 - }  
76 -  
77 - if (videoTracks.size() > 0) {  
78 - mergeMovie.addTrack(new AppendTrack(videoTracks.toArray(new Track[videoTracks.size()])));  
79 - }  
80 -  
81 - BasicContainer out = (BasicContainer)new DefaultMp4Builder().build(mergeMovie);  
82 -  
83 - // 文件名  
84 - String fileName = "测试.mp4";  
85 - // 文件类型  
86 - String contentType = request.getServletContext().getMimeType(fileName);  
87 -  
88 - // 解决下载文件时文件名乱码问题  
89 - byte[] fileNameBytes = fileName.getBytes(StandardCharsets.UTF_8);  
90 - fileName = new String(fileNameBytes, 0, fileNameBytes.length, StandardCharsets.ISO_8859_1);  
91 -  
92 - response.setHeader("Content-Type", contentType);  
93 - response.setHeader("Content-Length", String.valueOf(out));  
94 - //inline表示浏览器直接使用,attachment表示下载,fileName表示下载的文件名  
95 - response.setHeader("Content-Disposition", "inline;filename=" + fileName);  
96 - response.setContentType(contentType);  
97 -  
98 - WritableByteChannel writableByteChannel = Channels.newChannel(response.getOutputStream());  
99 - out.writeContainer(writableByteChannel);  
100 - writableByteChannel.close();  
101 -  
102 - }  
103 -}  
src/main/java/top/panll/assist/controller/RecordController.java
@@ -58,233 +58,215 @@ public class RecordController { @@ -58,233 +58,215 @@ public class RecordController {
58 return userSettings; 58 return userSettings;
59 } 59 }
60 60
61 - /**  
62 - * 获取app+stream列表  
63 - * @return  
64 - */  
65 - @Operation(summary ="分页获取app+stream的列表")  
66 - @Parameter(name = "page", description = "当前页", required = true)  
67 - @Parameter(name = "count", description = "每页查询数量", required = true)  
68 - @GetMapping(value = "/list")  
69 - @ResponseBody  
70 - public PageInfo<Map<String, String>> getList(@RequestParam int page,  
71 - @RequestParam int count){  
72 - List<Map<String, String>> appList = videoFileService.getList();  
73 -  
74 - PageInfo<Map<String, String>> stringPageInfo = new PageInfo<>(appList);  
75 - stringPageInfo.startPage(page, count);  
76 - return stringPageInfo;  
77 - }  
78 -  
79 - /**  
80 - * 分页获取app列表  
81 - * @return  
82 - */  
83 - @Operation(summary ="分页获取app列表")  
84 - @Parameter(name = "page", description = "当前页", required = true)  
85 - @Parameter(name = "count", description = "每页查询数量", required = true)  
86 - @GetMapping(value = "/app/list")  
87 - @ResponseBody  
88 - public PageInfo<String> getAppList(@RequestParam int page,  
89 - @RequestParam int count){  
90 - List<String> resultData = new ArrayList<>();  
91 - List<File> appList = videoFileService.getAppList(true);  
92 - if (appList.size() > 0) {  
93 - for (File file : appList) {  
94 - resultData.add(file.getName());  
95 - }  
96 - }  
97 - Collections.sort(resultData);  
98 -  
99 - PageInfo<String> stringPageInfo = new PageInfo<>(resultData);  
100 - stringPageInfo.startPage(page, count);  
101 - return stringPageInfo;  
102 - }  
103 -  
104 - /**  
105 - * 分页stream列表  
106 - * @return  
107 - */  
108 - @Operation(summary ="分页stream列表")  
109 - @Parameter(name = "page", description = "当前页", required = true)  
110 - @Parameter(name = "count", description = "每页查询数量", required = true)  
111 - @Parameter(name = "app", description = "应用名", required = true)  
112 - @GetMapping(value = "/stream/list")  
113 - @ResponseBody  
114 - public PageInfo<String> getStreamList(@RequestParam int page,  
115 - @RequestParam int count,  
116 - @RequestParam String app ){  
117 - List<String> resultData = new ArrayList<>();  
118 - if (app == null) {  
119 - throw new ControllerException(ErrorCode.ERROR400.getCode(), "app不能为空");  
120 - }  
121 - List<File> streamList = videoFileService.getStreamList(app, true);  
122 - if (streamList != null) {  
123 - for (File file : streamList) {  
124 - resultData.add(file.getName());  
125 - }  
126 - }  
127 - PageInfo<String> stringPageInfo = new PageInfo<>(resultData);  
128 - stringPageInfo.startPage(page, count);  
129 - return stringPageInfo;  
130 - }  
131 -  
132 - /**  
133 - * 获取日期文件夹列表  
134 - * @return  
135 - */  
136 - @Operation(summary ="获取日期文件夹列表")  
137 - @Parameter(name = "year", description = "月", required = true)  
138 - @Parameter(name = "month", description = "年", required = true)  
139 - @Parameter(name = "app", description = "应用名", required = true)  
140 - @Parameter(name = "stream", description = "流ID", required = true)  
141 - @GetMapping(value = "/date/list")  
142 - @ResponseBody  
143 - public List<String> getDateList( @RequestParam(required = false) Integer year,  
144 - @RequestParam(required = false) Integer month,  
145 - @RequestParam String app,  
146 - @RequestParam String stream ){  
147 - List<String> resultData = new ArrayList<>();  
148 - if (app == null) {  
149 - throw new ControllerException(ErrorCode.ERROR400.getCode(), "app不能为空");  
150 - };  
151 - if (stream == null) {  
152 - throw new ControllerException(ErrorCode.ERROR400.getCode(), "stream不能为空");  
153 - }  
154 - List<File> dateList = videoFileService.getDateList(app, stream, year, month, true);  
155 - for (File file : dateList) {  
156 - resultData.add(file.getName());  
157 - }  
158 - return resultData;  
159 - }  
160 -  
161 - /**  
162 - * 获取视频文件列表  
163 - * @return  
164 - */  
165 - @Operation(summary ="获取视频文件列表")  
166 - @Parameter(name = "page", description = "当前页", required = true)  
167 - @Parameter(name = "count", description = "每页查询数量", required = true)  
168 - @Parameter(name = "app", description = "应用名", required = true)  
169 - @Parameter(name = "stream", description = "流ID", required = true)  
170 - @Parameter(name = "startTime", description = "开始时间(yyyy-MM-dd HH:mm:ss)", required = true)  
171 - @Parameter(name = "endTime", description = "结束时间(yyyy-MM-dd HH:mm:ss)", required = true)  
172 - @GetMapping(value = "/file/list")  
173 - @ResponseBody  
174 - public PageInfo<String> getRecordList(@RequestParam int page,  
175 - @RequestParam int count,  
176 - @RequestParam String app,  
177 - @RequestParam String stream,  
178 - @RequestParam(required = false) String startTime,  
179 - @RequestParam(required = false) String endTime  
180 - ){  
181 -  
182 - // 开始时间与结束时间可不传或只传其一  
183 - List<String> recordList = new ArrayList<>();  
184 - try {  
185 - Date startTimeDate = null;  
186 - Date endTimeDate = null;  
187 - if (startTime != null ) {  
188 - startTimeDate = formatter.parse(startTime);  
189 - }  
190 - if (endTime != null ) {  
191 - endTimeDate = formatter.parse(endTime);  
192 - }  
193 -  
194 - List<File> filesInTime = videoFileService.getFilesInTime(app, stream, startTimeDate, endTimeDate);  
195 - if (filesInTime != null && filesInTime.size() > 0) {  
196 - for (File file : filesInTime) {  
197 - recordList.add(file.getName());  
198 - }  
199 - }  
200 - PageInfo<String> stringPageInfo = new PageInfo<>(recordList);  
201 - stringPageInfo.startPage(page, count);  
202 - return stringPageInfo;  
203 - } catch (ParseException e) {  
204 - logger.error("错误的开始时间[{}]或结束时间[{}]", startTime, endTime);  
205 - throw new ControllerException(ErrorCode.ERROR400.getCode(), "错误的开始时间或结束时间, e=" + e.getMessage());  
206 - }  
207 - }  
208 -  
209 - /**  
210 - * 获取视频文件列表  
211 - * @return  
212 - */  
213 - @Operation(summary ="获取视频文件列表")  
214 - @Parameter(name = "page", description = "当前页", required = true)  
215 - @Parameter(name = "count", description = "每页查询数量", required = true)  
216 - @Parameter(name = "app", description = "应用名", required = true)  
217 - @Parameter(name = "stream", description = "流ID", required = true)  
218 - @Parameter(name = "startTime", description = "开始时间(yyyy-MM-dd HH:mm:ss)", required = true)  
219 - @Parameter(name = "endTime", description = "结束时间(yyyy-MM-dd HH:mm:ss)", required = true)  
220 - @GetMapping(value = "/file/listWithDate")  
221 - @ResponseBody  
222 - public PageInfo<RecordFile> getRecordListWithDate(@RequestParam int page,  
223 - @RequestParam int count,  
224 - @RequestParam String app,  
225 - @RequestParam String stream,  
226 - @RequestParam(required = false) String startTime,  
227 - @RequestParam(required = false) String endTime  
228 - ){  
229 -  
230 - // 开始时间与结束时间可不传或只传其一  
231 - List<RecordFile> recordList = new ArrayList<>();  
232 - try {  
233 - Date startTimeDate = null;  
234 - Date endTimeDate = null;  
235 - if (startTime != null ) {  
236 - startTimeDate = formatter.parse(startTime);  
237 - }  
238 - if (endTime != null ) {  
239 - endTimeDate = formatter.parse(endTime);  
240 - }  
241 -  
242 - List<File> filesInTime = videoFileService.getFilesInTime(app, stream, startTimeDate, endTimeDate);  
243 - if (filesInTime != null && filesInTime.size() > 0) {  
244 - for (File file : filesInTime) {  
245 - recordList.add(RecordFile.instance(app, stream, file.getName(), file.getParentFile().getName()));  
246 - }  
247 - }  
248 - PageInfo<RecordFile> stringPageInfo = new PageInfo<>(recordList);  
249 - stringPageInfo.startPage(page, count);  
250 - return stringPageInfo;  
251 - } catch (ParseException e) {  
252 - logger.error("错误的开始时间[{}]或结束时间[{}]", startTime, endTime);  
253 - throw new ControllerException(ErrorCode.ERROR400.getCode(), "错误的开始时间或结束时间, e=" + e.getMessage());  
254 - }  
255 - } 61 +// /**
  62 +// * 获取app+stream列表
  63 +// * @return
  64 +// */
  65 +// @Operation(summary ="分页获取app+stream的列表")
  66 +// @Parameter(name = "page", description = "当前页", required = true)
  67 +// @Parameter(name = "count", description = "每页查询数量", required = true)
  68 +// @GetMapping(value = "/list")
  69 +// @ResponseBody
  70 +// public PageInfo<Map<String, String>> getList(@RequestParam int page,
  71 +// @RequestParam int count){
  72 +// List<Map<String, String>> appList = videoFileService.getList();
  73 +//
  74 +// PageInfo<Map<String, String>> stringPageInfo = new PageInfo<>(appList);
  75 +// stringPageInfo.startPage(page, count);
  76 +// return stringPageInfo;
  77 +// }
  78 +//
  79 +// /**
  80 +// * 分页获取app列表
  81 +// * @return
  82 +// */
  83 +// @Operation(summary ="分页获取app列表")
  84 +// @Parameter(name = "page", description = "当前页", required = true)
  85 +// @Parameter(name = "count", description = "每页查询数量", required = true)
  86 +// @GetMapping(value = "/app/list")
  87 +// @ResponseBody
  88 +// public PageInfo<String> getAppList(@RequestParam int page,
  89 +// @RequestParam int count){
  90 +// List<String> resultData = new ArrayList<>();
  91 +// List<File> appList = videoFileService.getAppList(true);
  92 +// if (appList.size() > 0) {
  93 +// for (File file : appList) {
  94 +// resultData.add(file.getName());
  95 +// }
  96 +// }
  97 +// Collections.sort(resultData);
  98 +//
  99 +// PageInfo<String> stringPageInfo = new PageInfo<>(resultData);
  100 +// stringPageInfo.startPage(page, count);
  101 +// return stringPageInfo;
  102 +// }
  103 +//
  104 +// /**
  105 +// * 分页stream列表
  106 +// * @return
  107 +// */
  108 +// @Operation(summary ="分页stream列表")
  109 +// @Parameter(name = "page", description = "当前页", required = true)
  110 +// @Parameter(name = "count", description = "每页查询数量", required = true)
  111 +// @Parameter(name = "app", description = "应用名", required = true)
  112 +// @GetMapping(value = "/stream/list")
  113 +// @ResponseBody
  114 +// public PageInfo<String> getStreamList(@RequestParam int page,
  115 +// @RequestParam int count,
  116 +// @RequestParam String app ){
  117 +// List<String> resultData = new ArrayList<>();
  118 +// if (app == null) {
  119 +// throw new ControllerException(ErrorCode.ERROR400.getCode(), "app不能为空");
  120 +// }
  121 +// List<File> streamList = videoFileService.getStreamList(app, true);
  122 +// if (streamList != null) {
  123 +// for (File file : streamList) {
  124 +// resultData.add(file.getName());
  125 +// }
  126 +// }
  127 +// PageInfo<String> stringPageInfo = new PageInfo<>(resultData);
  128 +// stringPageInfo.startPage(page, count);
  129 +// return stringPageInfo;
  130 +// }
  131 +//
  132 +// /**
  133 +// * 获取日期文件夹列表
  134 +// * @return
  135 +// */
  136 +// @Operation(summary ="获取日期文件夹列表")
  137 +// @Parameter(name = "year", description = "月", required = true)
  138 +// @Parameter(name = "month", description = "年", required = true)
  139 +// @Parameter(name = "app", description = "应用名", required = true)
  140 +// @Parameter(name = "stream", description = "流ID", required = true)
  141 +// @GetMapping(value = "/date/list")
  142 +// @ResponseBody
  143 +// public List<String> getDateList( @RequestParam(required = false) Integer year,
  144 +// @RequestParam(required = false) Integer month,
  145 +// @RequestParam String app,
  146 +// @RequestParam String stream ){
  147 +// List<String> resultData = new ArrayList<>();
  148 +// if (app == null) {
  149 +// throw new ControllerException(ErrorCode.ERROR400.getCode(), "app不能为空");
  150 +// };
  151 +// if (stream == null) {
  152 +// throw new ControllerException(ErrorCode.ERROR400.getCode(), "stream不能为空");
  153 +// }
  154 +// List<File> dateList = videoFileService.getDateList(app, stream, year, month, true);
  155 +// for (File file : dateList) {
  156 +// resultData.add(file.getName());
  157 +// }
  158 +// return resultData;
  159 +// }
  160 +//
  161 +// /**
  162 +// * 获取视频文件列表
  163 +// * @return
  164 +// */
  165 +// @Operation(summary ="获取视频文件列表")
  166 +// @Parameter(name = "page", description = "当前页", required = true)
  167 +// @Parameter(name = "count", description = "每页查询数量", required = true)
  168 +// @Parameter(name = "app", description = "应用名", required = true)
  169 +// @Parameter(name = "stream", description = "流ID", required = true)
  170 +// @Parameter(name = "startTime", description = "开始时间(yyyy-MM-dd HH:mm:ss)", required = true)
  171 +// @Parameter(name = "endTime", description = "结束时间(yyyy-MM-dd HH:mm:ss)", required = true)
  172 +// @GetMapping(value = "/file/list")
  173 +// @ResponseBody
  174 +// public PageInfo<String> getRecordList(@RequestParam int page,
  175 +// @RequestParam int count,
  176 +// @RequestParam String app,
  177 +// @RequestParam String stream,
  178 +// @RequestParam(required = false) String startTime,
  179 +// @RequestParam(required = false) String endTime
  180 +// ){
  181 +//
  182 +// // 开始时间与结束时间可不传或只传其一
  183 +// List<String> recordList = new ArrayList<>();
  184 +// try {
  185 +// Date startTimeDate = null;
  186 +// Date endTimeDate = null;
  187 +// if (startTime != null ) {
  188 +// startTimeDate = formatter.parse(startTime);
  189 +// }
  190 +// if (endTime != null ) {
  191 +// endTimeDate = formatter.parse(endTime);
  192 +// }
  193 +//
  194 +// List<File> filesInTime = videoFileService.getFilesInTime(app, stream, startTimeDate, endTimeDate);
  195 +// if (filesInTime != null && filesInTime.size() > 0) {
  196 +// for (File file : filesInTime) {
  197 +// recordList.add(file.getName());
  198 +// }
  199 +// }
  200 +// PageInfo<String> stringPageInfo = new PageInfo<>(recordList);
  201 +// stringPageInfo.startPage(page, count);
  202 +// return stringPageInfo;
  203 +// } catch (ParseException e) {
  204 +// logger.error("错误的开始时间[{}]或结束时间[{}]", startTime, endTime);
  205 +// throw new ControllerException(ErrorCode.ERROR400.getCode(), "错误的开始时间或结束时间, e=" + e.getMessage());
  206 +// }
  207 +// }
  208 +//
  209 +// /**
  210 +// * 获取视频文件列表
  211 +// * @return
  212 +// */
  213 +// @Operation(summary ="获取视频文件列表")
  214 +// @Parameter(name = "page", description = "当前页", required = true)
  215 +// @Parameter(name = "count", description = "每页查询数量", required = true)
  216 +// @Parameter(name = "app", description = "应用名", required = true)
  217 +// @Parameter(name = "stream", description = "流ID", required = true)
  218 +// @Parameter(name = "startTime", description = "开始时间(yyyy-MM-dd HH:mm:ss)", required = true)
  219 +// @Parameter(name = "endTime", description = "结束时间(yyyy-MM-dd HH:mm:ss)", required = true)
  220 +// @GetMapping(value = "/file/listWithDate")
  221 +// @ResponseBody
  222 +// public PageInfo<RecordFile> getRecordListWithDate(@RequestParam int page,
  223 +// @RequestParam int count,
  224 +// @RequestParam String app,
  225 +// @RequestParam String stream,
  226 +// @RequestParam(required = false) String startTime,
  227 +// @RequestParam(required = false) String endTime
  228 +// ){
  229 +//
  230 +// // 开始时间与结束时间可不传或只传其一
  231 +// List<RecordFile> recordList = new ArrayList<>();
  232 +// try {
  233 +// Date startTimeDate = null;
  234 +// Date endTimeDate = null;
  235 +// if (startTime != null ) {
  236 +// startTimeDate = formatter.parse(startTime);
  237 +// }
  238 +// if (endTime != null ) {
  239 +// endTimeDate = formatter.parse(endTime);
  240 +// }
  241 +//
  242 +// List<File> filesInTime = videoFileService.getFilesInTime(app, stream, startTimeDate, endTimeDate);
  243 +// if (filesInTime != null && filesInTime.size() > 0) {
  244 +// for (File file : filesInTime) {
  245 +// recordList.add(RecordFile.instance(app, stream, file.getName(), file.getParentFile().getName()));
  246 +// }
  247 +// }
  248 +// PageInfo<RecordFile> stringPageInfo = new PageInfo<>(recordList);
  249 +// stringPageInfo.startPage(page, count);
  250 +// return stringPageInfo;
  251 +// } catch (ParseException e) {
  252 +// logger.error("错误的开始时间[{}]或结束时间[{}]", startTime, endTime);
  253 +// throw new ControllerException(ErrorCode.ERROR400.getCode(), "错误的开始时间或结束时间, e=" + e.getMessage());
  254 +// }
  255 +// }
256 256
257 257
258 /** 258 /**
259 * 添加视频裁剪合并任务 259 * 添加视频裁剪合并任务
260 */ 260 */
261 @Operation(summary ="添加视频裁剪合并任务") 261 @Operation(summary ="添加视频裁剪合并任务")
262 - @Parameter(name = "app", description = "应用名", required = true)  
263 - @Parameter(name = "stream", description = "流ID", required = true)  
264 - @Parameter(name = "startTime", description = "开始时间(yyyy-MM-dd HH:mm:ss)", required = true)  
265 - @Parameter(name = "endTime", description = "结束时间(yyyy-MM-dd HH:mm:ss)", required = true)  
266 - @Parameter(name = "remoteHost", description = "服务的IP:端口(用于直接返回完整播放地址以及下载地址)", required = true)  
267 - @GetMapping(value = "/file/download/task/add") 262 + @Parameter(name = "videoTaskInfo", description = "视频合并任务的信息", required = true)
  263 + @PostMapping(value = "/file/download/task/add")
268 @ResponseBody 264 @ResponseBody
269 - public String addTaskForDownload(@RequestParam String app,  
270 - @RequestParam String stream,  
271 - @RequestParam(required = false) String startTime,  
272 - @RequestParam(required = false) String endTime,  
273 - @RequestParam(required = false) String remoteHost  
274 - ){  
275 - Date startTimeDate = null;  
276 - Date endTimeDate = null;  
277 - try {  
278 - if (startTime != null ) {  
279 - startTimeDate = formatter.parse(startTime);  
280 - }  
281 - if (endTime != null ) {  
282 - endTimeDate = formatter.parse(endTime);  
283 - }  
284 - } catch (ParseException e) {  
285 - e.printStackTrace(); 265 + public String addTaskForDownload(@RequestBody VideoTaskInfo videoTaskInfo ){
  266 + if (videoTaskInfo.getFilePathList() == null || videoTaskInfo.getFilePathList().isEmpty()) {
  267 + throw new ControllerException(ErrorCode.ERROR100.getCode(), "视频文件列表不可为空");
286 } 268 }
287 - String id = videoFileService.mergeOrCut(app, stream, startTimeDate, endTimeDate, remoteHost); 269 + String id = videoFileService.mergeOrCut(videoTaskInfo.getFilePathList(), videoTaskInfo.getRemoteHost());
288 if (id== null) { 270 if (id== null) {
289 throw new ControllerException(ErrorCode.ERROR100.getCode(), "可能未找到视频文件"); 271 throw new ControllerException(ErrorCode.ERROR100.getCode(), "可能未找到视频文件");
290 } 272 }
@@ -295,18 +277,14 @@ public class RecordController { @@ -295,18 +277,14 @@ public class RecordController {
295 * 查询视频裁剪合并任务列表 277 * 查询视频裁剪合并任务列表
296 */ 278 */
297 @Operation(summary ="查询视频裁剪合并任务列表") 279 @Operation(summary ="查询视频裁剪合并任务列表")
298 - @Parameter(name = "app", description = "应用名", required = true)  
299 - @Parameter(name = "stream", description = "流ID", required = true)  
300 @Parameter(name = "taskId", description = "任务ID", required = true) 280 @Parameter(name = "taskId", description = "任务ID", required = true)
301 @Parameter(name = "isEnd", description = "是否结束", required = true) 281 @Parameter(name = "isEnd", description = "是否结束", required = true)
302 @GetMapping(value = "/file/download/task/list") 282 @GetMapping(value = "/file/download/task/list")
303 @ResponseBody 283 @ResponseBody
304 public List<MergeOrCutTaskInfo> getTaskListForDownload( 284 public List<MergeOrCutTaskInfo> getTaskListForDownload(
305 - @RequestParam(required = false) String app,  
306 - @RequestParam(required = false) String stream,  
307 @RequestParam(required = false) String taskId, 285 @RequestParam(required = false) String taskId,
308 @RequestParam(required = false) Boolean isEnd){ 286 @RequestParam(required = false) Boolean isEnd){
309 - List<MergeOrCutTaskInfo> taskList = videoFileService.getTaskListForDownload(isEnd, app, stream, taskId); 287 + List<MergeOrCutTaskInfo> taskList = videoFileService.getTaskListForDownload(isEnd, taskId);
310 if (taskList == null) { 288 if (taskList == null) {
311 throw new ControllerException(ErrorCode.ERROR100); 289 throw new ControllerException(ErrorCode.ERROR100);
312 } 290 }
@@ -391,35 +369,6 @@ public class RecordController { @@ -391,35 +369,6 @@ public class RecordController {
391 } 369 }
392 370
393 /** 371 /**
394 - * 录制完成的通知, 对用zlm的hook  
395 - * @return  
396 - */  
397 - @ResponseBody  
398 - @PostMapping(value = "/on_record_mp4", produces = "application/json;charset=UTF-8")  
399 - public ResponseEntity<String> onRecordMp4(@RequestBody JSONObject json) {  
400 - JSONObject ret = new JSONObject();  
401 - ret.put("code", 0);  
402 - ret.put("msg", "success");  
403 - String file_path = json.getString("file_path");  
404 -  
405 - String app = json.getString("app");  
406 - String stream = json.getString("stream");  
407 - logger.debug("ZLM 录制完成,文件路径:" + file_path);  
408 -  
409 - if (file_path == null) {  
410 - return new ResponseEntity<String>(ret.toString(), HttpStatus.OK);  
411 - }  
412 - if (userSettings.getRecordDay() <= 0) {  
413 - logger.info("录像保存事件为{}天,直接删除: {}", userSettings.getRecordDay(), file_path);  
414 - FileUtils.deleteQuietly(new File(file_path));  
415 - }else {  
416 - videoFileService.handFile(new File(file_path), app, stream);  
417 - }  
418 -  
419 - return new ResponseEntity<String>(ret.toString(), HttpStatus.OK);  
420 - }  
421 -  
422 - /**  
423 * 磁盘空间查询 372 * 磁盘空间查询
424 */ 373 */
425 @Operation(summary ="磁盘空间查询") 374 @Operation(summary ="磁盘空间查询")
@@ -430,21 +379,6 @@ public class RecordController { @@ -430,21 +379,6 @@ public class RecordController {
430 } 379 }
431 380
432 /** 381 /**
433 - * 增加推流的鉴权信息,用于录像存储使用  
434 - */  
435 - @Operation(summary ="增加推流的鉴权信息")  
436 - @Parameter(name = "app", description = "应用名", required = true)  
437 - @Parameter(name = "stream", description = "流ID", required = true)  
438 - @Parameter(name = "callId", description = "录像自鉴权ID", required = true)  
439 - @ResponseBody  
440 - @GetMapping(value = "/addStreamCallInfo", produces = "application/json;charset=UTF-8")  
441 - @PostMapping(value = "/addStreamCallInfo", produces = "application/json;charset=UTF-8")  
442 - public void addStreamCallInfo(String app, String stream, String callId) {  
443 - String key = AssistConstants.STREAM_CALL_INFO + userSettings.getId() + "_" + app + "_" + stream;  
444 - redisUtil.set(key, callId, -1);  
445 - }  
446 -  
447 - /**  
448 * 录像文件的时长 382 * 录像文件的时长
449 */ 383 */
450 @Operation(summary ="录像文件的时长") 384 @Operation(summary ="录像文件的时长")
src/main/java/top/panll/assist/dto/MergeOrCutTaskInfo.java
@@ -3,12 +3,7 @@ package top.panll.assist.dto; @@ -3,12 +3,7 @@ package top.panll.assist.dto;
3 3
4 public class MergeOrCutTaskInfo { 4 public class MergeOrCutTaskInfo {
5 private String id; 5 private String id;
6 - private String app;  
7 - private String stream;  
8 - private String startTime;  
9 - private String endTime;  
10 private String createTime; 6 private String createTime;
11 -  
12 private String percentage; 7 private String percentage;
13 8
14 private String recordFile; 9 private String recordFile;
@@ -25,38 +20,6 @@ public class MergeOrCutTaskInfo { @@ -25,38 +20,6 @@ public class MergeOrCutTaskInfo {
25 this.id = id; 20 this.id = id;
26 } 21 }
27 22
28 - public String getStartTime() {  
29 - return startTime;  
30 - }  
31 -  
32 - public void setStartTime(String startTime) {  
33 - this.startTime = startTime;  
34 - }  
35 -  
36 - public String getEndTime() {  
37 - return endTime;  
38 - }  
39 -  
40 - public void setEndTime(String endTime) {  
41 - this.endTime = endTime;  
42 - }  
43 -  
44 - public String getApp() {  
45 - return app;  
46 - }  
47 -  
48 - public void setApp(String app) {  
49 - this.app = app;  
50 - }  
51 -  
52 - public String getStream() {  
53 - return stream;  
54 - }  
55 -  
56 - public void setStream(String stream) {  
57 - this.stream = stream;  
58 - }  
59 -  
60 public String getPercentage() { 23 public String getPercentage() {
61 return percentage; 24 return percentage;
62 } 25 }
src/main/java/top/panll/assist/dto/VideoTaskInfo.java 0 → 100644
  1 +package top.panll.assist.dto;
  2 +
  3 +import io.swagger.v3.oas.annotations.Parameter;
  4 +import io.swagger.v3.oas.annotations.media.Schema;
  5 +
  6 +import java.util.List;
  7 +
  8 +@Schema(description = "视频合并任务的信息")
  9 +public class VideoTaskInfo {
  10 +
  11 + @Schema(description = "视频文件路径列表")
  12 + private List<String> filePathList;
  13 +
  14 + @Schema(description = "返回地址时的远程地址")
  15 + private String remoteHost;
  16 +
  17 + public List<String> getFilePathList() {
  18 + return filePathList;
  19 + }
  20 +
  21 + public void setFilePathList(List<String> filePathList) {
  22 + this.filePathList = filePathList;
  23 + }
  24 +
  25 + public String getRemoteHost() {
  26 + return remoteHost;
  27 + }
  28 +
  29 + public void setRemoteHost(String remoteHost) {
  30 + this.remoteHost = remoteHost;
  31 + }
  32 +}
src/main/java/top/panll/assist/service/FFmpegExecUtils.java
@@ -95,7 +95,7 @@ public class FFmpegExecUtils implements InitializingBean{ @@ -95,7 +95,7 @@ public class FFmpegExecUtils implements InitializingBean{
95 BufferedWriter bw =new BufferedWriter(new FileWriter(fileListName)); 95 BufferedWriter bw =new BufferedWriter(new FileWriter(fileListName));
96 for (File file : fils) { 96 for (File file : fils) {
97 VideoFile videoFile = VideoFileFactory.createFile(this, file); 97 VideoFile videoFile = VideoFileFactory.createFile(this, file);
98 - if (videoFile == null || !videoFile.isTargetFormat()) { 98 + if (videoFile == null) {
99 return; 99 return;
100 } 100 }
101 bw.write("file " + file.getAbsolutePath()); 101 bw.write("file " + file.getAbsolutePath());
src/main/java/top/panll/assist/service/FileManagerTimer.java
@@ -115,36 +115,38 @@ public class FileManagerTimer { @@ -115,36 +115,38 @@ public class FileManagerTimer {
115 Date lastTempDate = new Date(); 115 Date lastTempDate = new Date();
116 Calendar lastTempCalendar = Calendar.getInstance(); 116 Calendar lastTempCalendar = Calendar.getInstance();
117 lastTempCalendar.setTime(lastTempDate); 117 lastTempCalendar.setTime(lastTempDate);
118 - lastTempCalendar.add(Calendar.DAY_OF_MONTH, 0 - recordTempDay); 118 + lastTempCalendar.add(Calendar.DAY_OF_MONTH, -recordTempDay);
119 lastTempDate = lastTempCalendar.getTime(); 119 lastTempDate = lastTempCalendar.getTime();
120 logger.info("[录像巡查]移除合并任务临时文件 {} 之前的文件", formatter.format(lastTempDate)); 120 logger.info("[录像巡查]移除合并任务临时文件 {} 之前的文件", formatter.format(lastTempDate));
121 - File recordTempFile = new File(userSettings.getRecord() + "recordTemp"); 121 + File recordTempFile = new File(userSettings.getRecord());
122 if (recordTempFile.exists() && recordTempFile.isDirectory() && recordTempFile.canWrite()) { 122 if (recordTempFile.exists() && recordTempFile.isDirectory() && recordTempFile.canWrite()) {
123 File[] tempFiles = recordTempFile.listFiles(); 123 File[] tempFiles = recordTempFile.listFiles();
124 - for (File tempFile : tempFiles) {  
125 - if (tempFile.isDirectory() && new Date(tempFile.lastModified()).before(lastTempDate)) {  
126 - boolean result = FileUtils.deleteQuietly(tempFile);  
127 - if (result) {  
128 - logger.info("[录像巡查]成功移除合并任务临时文件 {} ", tempFile.getAbsolutePath());  
129 - }else {  
130 - logger.info("[录像巡查]合并任务临时文件移除失败 {} ", tempFile.getAbsolutePath()); 124 + if (tempFiles != null) {
  125 + for (File tempFile : tempFiles) {
  126 + if (tempFile.isFile() && tempFile.lastModified() < lastTempDate.getTime()) {
  127 + boolean result = FileUtils.deleteQuietly(tempFile);
  128 + if (result) {
  129 + logger.info("[录像巡查]成功移除合并任务临时文件 {} ", tempFile.getAbsolutePath());
  130 + }else {
  131 + logger.info("[录像巡查]合并任务临时文件移除失败 {} ", tempFile.getAbsolutePath());
  132 + }
131 } 133 }
132 } 134 }
133 } 135 }
134 } 136 }
135 // 清理redis记录 137 // 清理redis记录
136 - String key = String.format("%S_%S_*_*_*", AssistConstants.MERGEORCUT, userSettings.getId()); 138 + String key = String.format("%S_%S_*", AssistConstants.MERGEORCUT, userSettings.getId());
137 List<Object> taskKeys = redisUtil.scan(key); 139 List<Object> taskKeys = redisUtil.scan(key);
138 for (Object taskKeyObj : taskKeys) { 140 for (Object taskKeyObj : taskKeys) {
139 String taskKey = (String) taskKeyObj; 141 String taskKey = (String) taskKeyObj;
140 MergeOrCutTaskInfo mergeOrCutTaskInfo = (MergeOrCutTaskInfo)redisUtil.get(taskKey); 142 MergeOrCutTaskInfo mergeOrCutTaskInfo = (MergeOrCutTaskInfo)redisUtil.get(taskKey);
141 try { 143 try {
142 - if (StringUtils.isEmpty(mergeOrCutTaskInfo.getCreateTime()) 144 + if (StringUtils.hasLength(mergeOrCutTaskInfo.getCreateTime())
143 || simpleDateFormatForTime.parse(mergeOrCutTaskInfo.getCreateTime()).before(lastTempDate)) { 145 || simpleDateFormatForTime.parse(mergeOrCutTaskInfo.getCreateTime()).before(lastTempDate)) {
144 redisUtil.del(taskKey); 146 redisUtil.del(taskKey);
145 } 147 }
146 } catch (ParseException e) { 148 } catch (ParseException e) {
147 - e.printStackTrace(); 149 + logger.error("[清理过期的redis合并任务信息] 失败", e);
148 } 150 }
149 } 151 }
150 } 152 }
src/main/java/top/panll/assist/service/VideoFileService.java
@@ -10,6 +10,8 @@ import org.springframework.beans.factory.annotation.Autowired; @@ -10,6 +10,8 @@ import org.springframework.beans.factory.annotation.Autowired;
10 import org.springframework.data.redis.core.RedisTemplate; 10 import org.springframework.data.redis.core.RedisTemplate;
11 import org.springframework.stereotype.Service; 11 import org.springframework.stereotype.Service;
12 import org.springframework.util.DigestUtils; 12 import org.springframework.util.DigestUtils;
  13 +import top.panll.assist.controller.bean.ControllerException;
  14 +import top.panll.assist.controller.bean.ErrorCode;
13 import top.panll.assist.dto.*; 15 import top.panll.assist.dto.*;
14 import top.panll.assist.utils.RedisUtil; 16 import top.panll.assist.utils.RedisUtil;
15 import top.panll.assist.utils.DateUtils; 17 import top.panll.assist.utils.DateUtils;
@@ -68,10 +70,6 @@ public class VideoFileService { @@ -68,10 +70,6 @@ public class VideoFileService {
68 return spaceInfo; 70 return spaceInfo;
69 } 71 }
70 72
71 - public List<File> getStreamList(String app, Boolean sort) {  
72 - File appFile = new File(userSettings.getRecord() + File.separator + app);  
73 - return getStreamList(appFile, sort);  
74 - }  
75 73
76 public List<File> getStreamList(File appFile, Boolean sort) { 74 public List<File> getStreamList(File appFile, Boolean sort) {
77 if (appFile != null && appFile.isDirectory()) { 75 if (appFile != null && appFile.isDirectory()) {
@@ -90,79 +88,6 @@ public class VideoFileService { @@ -90,79 +88,6 @@ public class VideoFileService {
90 } 88 }
91 89
92 /** 90 /**
93 - * 对视频文件重命名  
94 - */  
95 - public void handFile(File file,String app, String stream) {  
96 - VideoFile videoFile = VideoFileFactory.createFile(ffmpegExecUtils, file);  
97 - if (videoFile == null || videoFile.isTargetFormat()) {  
98 - return;  
99 - }  
100 -  
101 - SimpleDateFormat dateFormat = new SimpleDateFormat("HHmmss");  
102 -  
103 - String key = AssistConstants.STREAM_CALL_INFO + userSettings.getId() + "_" + app + "_" + stream;  
104 - String callId = (String) redisUtil.get(key);  
105 -  
106 - String streamNew = (callId == null? stream : stream + "_" + callId);  
107 - File newPath = new File(userSettings.getRecord() + File.separator + app + File.separator + streamNew  
108 - + File.separator + DateUtils.getDateStr(videoFile.getStartTime()));  
109 - if (!newPath.exists()) {  
110 - newPath.mkdirs();  
111 - }  
112 -  
113 - String newName = newPath.getAbsolutePath() + File.separator+ dateFormat.format(videoFile.getStartTime())  
114 - + "-" + dateFormat.format(videoFile.getEndTime()) + ".mp4";  
115 - logger.info("[处理文件] {}->{}", file.getAbsolutePath(), newName);  
116 - boolean renameTo = file.renameTo(new File(newName));  
117 - if (!renameTo) {  
118 - logger.info("[处理文件]文件重命名失败 {}->{}", file.getAbsolutePath(), newName);  
119 - }  
120 - }  
121 -  
122 - public List<Map<String, String>> getList() {  
123 -  
124 - List<Map<String, String>> result = new ArrayList<>();  
125 -  
126 - List<File> appList = getAppList(true);  
127 - if (appList != null && appList.size() > 0) {  
128 - for (File appFile : appList) {  
129 - if (appFile.isDirectory()) {  
130 - List<File> streamList = getStreamList(appFile.getName(), true);  
131 - if (streamList != null && streamList.size() > 0) {  
132 - for (File streamFile : streamList) {  
133 - Map<String, String> data = new HashMap<>();  
134 - data.put("app", appFile.getName());  
135 - data.put("stream", streamFile.getName());  
136 -  
137 - BasicFileAttributes bAttributes = null;  
138 - try {  
139 - bAttributes = Files.readAttributes(streamFile.toPath(),  
140 - BasicFileAttributes.class);  
141 - } catch (IOException e) {  
142 - e.printStackTrace();  
143 - }  
144 - data.put("time", simpleDateFormatForTime.format(new Date(bAttributes.lastModifiedTime().toMillis())));  
145 - result.add(data);  
146 - }  
147 - }  
148 - }  
149 - }  
150 - }  
151 - result.sort((Map f1, Map f2)->{  
152 - Date time1 = null;  
153 - Date time2 = null;  
154 - try {  
155 - time1 = simpleDateFormatForTime.parse(f1.get("time").toString());  
156 - time2 = simpleDateFormatForTime.parse(f2.get("time").toString());  
157 - } catch (ParseException e) {  
158 - logger.error("时间格式化失败", e);  
159 - }  
160 - return time1.compareTo(time2) * -1;  
161 - });  
162 - return result;  
163 - }  
164 -  
165 - /**  
166 * 获取制定推流的指定时间段内的推流 91 * 获取制定推流的指定时间段内的推流
167 * @param app 92 * @param app
168 * @param stream 93 * @param stream
@@ -282,64 +207,49 @@ public class VideoFileService { @@ -282,64 +207,49 @@ public class VideoFileService {
282 } 207 }
283 208
284 209
285 - public String mergeOrCut(String app, String stream, Date startTime, Date endTime, String remoteHost) {  
286 - List<File> filesInTime = this.getFilesInTime(app, stream, startTime, endTime);  
287 - if (filesInTime== null || filesInTime.isEmpty()){  
288 - logger.info("此时间段未未找到视频文件, {}/{} {}->{}", app, stream,  
289 - startTime == null? null:DateUtils.getDateTimeStr(startTime),  
290 - endTime == null? null:DateUtils.getDateTimeStr(endTime));  
291 - return null;  
292 - } 210 + public String mergeOrCut(List<String> filePathList, String remoteHost) {
  211 + assert filePathList != null;
  212 + assert !filePathList.isEmpty();
293 String taskId = DigestUtils.md5DigestAsHex(String.valueOf(System.currentTimeMillis()).getBytes()); 213 String taskId = DigestUtils.md5DigestAsHex(String.valueOf(System.currentTimeMillis()).getBytes());
294 - logger.info("[录像合并] 开始合并,APP:{}, STREAM: {}, 任务ID:{}", app, stream, taskId);  
295 - String destDir = "recordTemp" + File.separator + taskId + File.separator + app;  
296 - File recordFile = new File(userSettings.getRecord() + destDir );  
297 - if (!recordFile.exists()) {  
298 - recordFile.mkdirs(); 214 + logger.info("[录像合并] 开始合并, 任务ID:{}: ", taskId);
  215 + List<File> fileList = new ArrayList<>();
  216 + for (String filePath : filePathList) {
  217 + File file = new File(filePath);
  218 + if (!file.exists()) {
  219 + logger.info("[录像合并] 失败, 任务ID:{}, 文件不存在: {}", taskId, filePath);
  220 + throw new ControllerException(ErrorCode.ERROR100.getCode(), filePath + "文件不存在");
  221 + }
  222 + logger.info("[录像合并] 添加文件, 任务ID:{}, 文件: {}", taskId, filePath);
  223 + fileList.add(file);
299 } 224 }
  225 +
  226 + File recordFile = new File(userSettings.getRecord() );
300 MergeOrCutTaskInfo mergeOrCutTaskInfo = new MergeOrCutTaskInfo(); 227 MergeOrCutTaskInfo mergeOrCutTaskInfo = new MergeOrCutTaskInfo();
301 mergeOrCutTaskInfo.setId(taskId); 228 mergeOrCutTaskInfo.setId(taskId);
302 - mergeOrCutTaskInfo.setApp(app);  
303 - mergeOrCutTaskInfo.setStream(stream);  
304 mergeOrCutTaskInfo.setCreateTime(simpleDateFormatForTime.format(System.currentTimeMillis())); 229 mergeOrCutTaskInfo.setCreateTime(simpleDateFormatForTime.format(System.currentTimeMillis()));
305 - if(startTime != null) {  
306 - mergeOrCutTaskInfo.setStartTime(simpleDateFormatForTime.format(startTime));  
307 - }else {  
308 - String startTimeInFile = filesInTime.get(0).getParentFile().getName() + " "  
309 - + filesInTime.get(0).getName().split("-")[0];  
310 - mergeOrCutTaskInfo.setStartTime(startTimeInFile);  
311 - }  
312 - if(endTime != null) {  
313 - mergeOrCutTaskInfo.setEndTime(simpleDateFormatForTime.format(endTime));  
314 - }else {  
315 - String endTimeInFile = filesInTime.get(filesInTime.size()- 1).getParentFile().getName() + " "  
316 - + filesInTime.get(filesInTime.size()- 1).getName().split("-")[1];  
317 - mergeOrCutTaskInfo.setEndTime(endTimeInFile);  
318 - }  
319 - if (filesInTime.size() == 1) { 230 + if (fileList.size() == 1) {
320 231
321 // 文件只有一个则不合并,直接复制过去 232 // 文件只有一个则不合并,直接复制过去
322 mergeOrCutTaskInfo.setPercentage("1"); 233 mergeOrCutTaskInfo.setPercentage("1");
323 // 处理文件路径 234 // 处理文件路径
324 - String recordFileResultPath = recordFile.getAbsolutePath() + File.separator + stream + ".mp4"; 235 + String recordFileResultPath = recordFile.getAbsolutePath() + File.separator + taskId + ".mp4";
325 Path relativize = Paths.get(userSettings.getRecord()).relativize(Paths.get(recordFileResultPath)); 236 Path relativize = Paths.get(userSettings.getRecord()).relativize(Paths.get(recordFileResultPath));
326 try { 237 try {
327 - Files.copy(filesInTime.get(0).toPath(), Paths.get(recordFileResultPath)); 238 + Files.copy(fileList.get(0).toPath(), Paths.get(recordFileResultPath));
328 } catch (IOException e) { 239 } catch (IOException e) {
329 - e.printStackTrace();  
330 - logger.info("[录像合并] 失败,APP:{}, STREAM: {}, 任务ID:{}", app, stream, taskId);  
331 - return taskId; 240 + logger.info("[录像合并] 失败, 任务ID:{}", taskId, e);
  241 + throw new ControllerException(ErrorCode.ERROR100.getCode(), e.getMessage());
332 } 242 }
333 mergeOrCutTaskInfo.setRecordFile("/download/" + relativize.toString()); 243 mergeOrCutTaskInfo.setRecordFile("/download/" + relativize.toString());
334 if (remoteHost != null) { 244 if (remoteHost != null) {
335 mergeOrCutTaskInfo.setDownloadFile(remoteHost + "/download.html?url=download/" + relativize); 245 mergeOrCutTaskInfo.setDownloadFile(remoteHost + "/download.html?url=download/" + relativize);
336 mergeOrCutTaskInfo.setPlayFile(remoteHost + "/download/" + relativize); 246 mergeOrCutTaskInfo.setPlayFile(remoteHost + "/download/" + relativize);
337 } 247 }
338 - String key = String.format("%S_%S_%S_%S_%S", AssistConstants.MERGEORCUT , userSettings.getId(), mergeOrCutTaskInfo.getApp(), mergeOrCutTaskInfo.getStream(), mergeOrCutTaskInfo.getId()); 248 + String key = String.format("%S_%S_%S", AssistConstants.MERGEORCUT , userSettings.getId(), mergeOrCutTaskInfo.getId());
339 redisUtil.set(key, mergeOrCutTaskInfo); 249 redisUtil.set(key, mergeOrCutTaskInfo);
340 - logger.info("[录像合并] 合并完成,APP:{}, STREAM: {}, 任务ID:{}", app, stream, taskId); 250 + logger.info("[录像合并] 成功, 任务ID:{}", taskId);
341 }else { 251 }else {
342 - ffmpegExecUtils.mergeOrCutFile(filesInTime, recordFile, stream, (status, percentage, result)->{ 252 + ffmpegExecUtils.mergeOrCutFile(fileList, recordFile, taskId, (status, percentage, result)->{
343 // 发出redis通知 253 // 发出redis通知
344 if (status.equals(Progress.Status.END.name())) { 254 if (status.equals(Progress.Status.END.name())) {
345 mergeOrCutTaskInfo.setPercentage("1"); 255 mergeOrCutTaskInfo.setPercentage("1");
@@ -351,11 +261,11 @@ public class VideoFileService { @@ -351,11 +261,11 @@ public class VideoFileService {
351 mergeOrCutTaskInfo.setDownloadFile(remoteHost + "/download.html?url=download/" + relativize); 261 mergeOrCutTaskInfo.setDownloadFile(remoteHost + "/download.html?url=download/" + relativize);
352 mergeOrCutTaskInfo.setPlayFile(remoteHost + "/download/" + relativize); 262 mergeOrCutTaskInfo.setPlayFile(remoteHost + "/download/" + relativize);
353 } 263 }
354 - logger.info("[录像合并] 合并完成,APP:{}, STREAM: {}, 任务ID:{}", app, stream, taskId); 264 + logger.info("[录像合并] 成功, 任务ID:{}", taskId);
355 }else { 265 }else {
356 mergeOrCutTaskInfo.setPercentage(percentage + ""); 266 mergeOrCutTaskInfo.setPercentage(percentage + "");
357 } 267 }
358 - String key = String.format("%S_%S_%S_%S_%S", AssistConstants.MERGEORCUT, userSettings.getId(), mergeOrCutTaskInfo.getApp(), mergeOrCutTaskInfo.getStream(), mergeOrCutTaskInfo.getId()); 268 + String key = String.format("%S_%S_%S", AssistConstants.MERGEORCUT, userSettings.getId(), mergeOrCutTaskInfo.getId());
359 redisUtil.set(key, mergeOrCutTaskInfo); 269 redisUtil.set(key, mergeOrCutTaskInfo);
360 }); 270 });
361 } 271 }
@@ -363,19 +273,6 @@ public class VideoFileService { @@ -363,19 +273,6 @@ public class VideoFileService {
363 return taskId; 273 return taskId;
364 } 274 }
365 275
366 - /**  
367 - * 获取指定时间的日期文件夹  
368 - * @param app  
369 - * @param stream  
370 - * @param year  
371 - * @param month  
372 - * @return  
373 - */  
374 - public List<File> getDateList(String app, String stream, Integer year, Integer month, Boolean sort) {  
375 - File recordFile = new File(userSettings.getRecord());  
376 - File streamFile = new File(recordFile.getAbsolutePath() + File.separator + app + File.separator + stream);  
377 - return getDateList(streamFile, year, month, sort);  
378 - }  
379 public List<File> getDateList(File streamFile, Integer year, Integer month, Boolean sort) { 276 public List<File> getDateList(File streamFile, Integer year, Integer month, Boolean sort) {
380 if (!streamFile.exists() && streamFile.isDirectory()) { 277 if (!streamFile.exists() && streamFile.isDirectory()) {
381 logger.warn("获取[]的视频时未找到目录: {}",streamFile.getName()); 278 logger.warn("获取[]的视频时未找到目录: {}",streamFile.getName());
@@ -428,19 +325,13 @@ public class VideoFileService { @@ -428,19 +325,13 @@ public class VideoFileService {
428 return dateFileList; 325 return dateFileList;
429 } 326 }
430 327
431 - public List<MergeOrCutTaskInfo> getTaskListForDownload(Boolean idEnd, String app, String stream, String taskId) { 328 + public List<MergeOrCutTaskInfo> getTaskListForDownload(Boolean idEnd, String taskId) {
432 ArrayList<MergeOrCutTaskInfo> result = new ArrayList<>(); 329 ArrayList<MergeOrCutTaskInfo> result = new ArrayList<>();
433 - if (app == null) {  
434 - app = "*";  
435 - }  
436 - if (stream == null) {  
437 - stream = "*";  
438 - }  
439 if (taskId == null) { 330 if (taskId == null) {
440 taskId = "*"; 331 taskId = "*";
441 } 332 }
442 - List<Object> taskCatch = redisUtil.scan(String.format("%S_%S_%S_%S_%S", AssistConstants.MERGEORCUT,  
443 - userSettings.getId(), app, stream, taskId)); 333 + List<Object> taskCatch = redisUtil.scan(String.format("%S_%S_%S", AssistConstants.MERGEORCUT,
  334 + userSettings.getId(), taskId));
444 for (int i = 0; i < taskCatch.size(); i++) { 335 for (int i = 0; i < taskCatch.size(); i++) {
445 String keyItem = taskCatch.get(i).toString(); 336 String keyItem = taskCatch.get(i).toString();
446 MergeOrCutTaskInfo mergeOrCutTaskInfo = (MergeOrCutTaskInfo)redisUtil.get(keyItem); 337 MergeOrCutTaskInfo mergeOrCutTaskInfo = (MergeOrCutTaskInfo)redisUtil.get(keyItem);
@@ -465,10 +356,10 @@ public class VideoFileService { @@ -465,10 +356,10 @@ public class VideoFileService {
465 try { 356 try {
466 sortResult = simpleDateFormatForTime.parse(m1.getCreateTime()).compareTo(simpleDateFormatForTime.parse(m2.getCreateTime())); 357 sortResult = simpleDateFormatForTime.parse(m1.getCreateTime()).compareTo(simpleDateFormatForTime.parse(m2.getCreateTime()));
467 if (sortResult == 0) { 358 if (sortResult == 0) {
468 - sortResult = simpleDateFormatForTime.parse(m1.getStartTime()).compareTo(simpleDateFormatForTime.parse(m2.getStartTime())); 359 + sortResult = simpleDateFormatForTime.parse(m1.getCreateTime()).compareTo(simpleDateFormatForTime.parse(m2.getCreateTime()));
469 } 360 }
470 if (sortResult == 0) { 361 if (sortResult == 0) {
471 - sortResult = simpleDateFormatForTime.parse(m1.getEndTime()).compareTo(simpleDateFormatForTime.parse(m2.getEndTime())); 362 + sortResult = simpleDateFormatForTime.parse(m1.getCreateTime()).compareTo(simpleDateFormatForTime.parse(m2.getCreateTime()));
472 } 363 }
473 } catch (ParseException e) { 364 } catch (ParseException e) {
474 e.printStackTrace(); 365 e.printStackTrace();
src/main/resources/application-local.yml
@@ -11,7 +11,7 @@ spring: @@ -11,7 +11,7 @@ spring:
11 # [可选] 数据库 DB 11 # [可选] 数据库 DB
12 database: 1 12 database: 1
13 # [可选] 访问密码,若你的redis服务器没有设置密码,就不需要用密码去连接 13 # [可选] 访问密码,若你的redis服务器没有设置密码,就不需要用密码去连接
14 - password: adminadmin123. 14 + password:
15 # 以下为集群配置 15 # 以下为集群配置
16 # cluster: 16 # cluster:
17 # nodes: 192.168.1.242:7001 17 # nodes: 192.168.1.242:7001
@@ -36,7 +36,7 @@ userSettings: @@ -36,7 +36,7 @@ userSettings:
36 # [必选 ] 服务ID 36 # [必选 ] 服务ID
37 id: 334533 37 id: 334533
38 # [必选 ] 录像路径 38 # [必选 ] 录像路径
39 - record: /home/lin/record/ 39 + record: /home/lin/server/zlm/ZLMediaKit/release/linux/Debug/www/record/
40 # [可选 ] 录像保存时长(单位: 天)每天晚12点自动对过期文件执行清理 40 # [可选 ] 录像保存时长(单位: 天)每天晚12点自动对过期文件执行清理
41 recordDay: 10 41 recordDay: 10
42 # [可选 ] 录像下载合成临时文件保存时长, 不配置默认取值recordDay(单位: 天)每天晚12点自动对过期文件执行清理 42 # [可选 ] 录像下载合成临时文件保存时长, 不配置默认取值recordDay(单位: 天)每天晚12点自动对过期文件执行清理