Commit a3d583e3b09f3cac9604d09dcd106e5491eb68b9
1 parent
2c470f50
优化常量的使用,服务增加支持redis数据隔离
Showing
8 changed files
with
37 additions
and
30 deletions
src/main/java/top/panll/assist/controller/RecordController.java
| @@ -14,9 +14,7 @@ import org.springframework.web.bind.annotation.*; | @@ -14,9 +14,7 @@ import org.springframework.web.bind.annotation.*; | ||
| 14 | import top.panll.assist.controller.bean.ControllerException; | 14 | import top.panll.assist.controller.bean.ControllerException; |
| 15 | import top.panll.assist.controller.bean.ErrorCode; | 15 | import top.panll.assist.controller.bean.ErrorCode; |
| 16 | import top.panll.assist.controller.bean.WVPResult; | 16 | import top.panll.assist.controller.bean.WVPResult; |
| 17 | -import top.panll.assist.dto.MergeOrCutTaskInfo; | ||
| 18 | -import top.panll.assist.dto.SignInfo; | ||
| 19 | -import top.panll.assist.dto.SpaceInfo; | 17 | +import top.panll.assist.dto.*; |
| 20 | import top.panll.assist.service.VideoFileService; | 18 | import top.panll.assist.service.VideoFileService; |
| 21 | import top.panll.assist.utils.PageInfo; | 19 | import top.panll.assist.utils.PageInfo; |
| 22 | import top.panll.assist.utils.RedisUtil; | 20 | import top.panll.assist.utils.RedisUtil; |
| @@ -43,6 +41,9 @@ public class RecordController { | @@ -43,6 +41,9 @@ public class RecordController { | ||
| 43 | @Autowired | 41 | @Autowired |
| 44 | private RedisUtil redisUtil; | 42 | private RedisUtil redisUtil; |
| 45 | 43 | ||
| 44 | + @Autowired | ||
| 45 | + private UserSettings userSettings; | ||
| 46 | + | ||
| 46 | private SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | 47 | private SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| 47 | 48 | ||
| 48 | 49 | ||
| @@ -372,7 +373,7 @@ public class RecordController { | @@ -372,7 +373,7 @@ public class RecordController { | ||
| 372 | @GetMapping(value = "/addStreamCallInfo", produces = "application/json;charset=UTF-8") | 373 | @GetMapping(value = "/addStreamCallInfo", produces = "application/json;charset=UTF-8") |
| 373 | @PostMapping(value = "/addStreamCallInfo", produces = "application/json;charset=UTF-8") | 374 | @PostMapping(value = "/addStreamCallInfo", produces = "application/json;charset=UTF-8") |
| 374 | public void addStreamCallInfo(String app, String stream, String callId) { | 375 | public void addStreamCallInfo(String app, String stream, String callId) { |
| 375 | - String key = "Stream_Call_Info" + app + "_" + stream; | 376 | + String key = AssistConstants.STREAM_CALL_INFO + userSettings.getId() + "_" + app + "_" + stream; |
| 376 | redisUtil.set(key, callId, -1); | 377 | redisUtil.set(key, callId, -1); |
| 377 | } | 378 | } |
| 378 | 379 |
src/main/java/top/panll/assist/dto/AssistConstants.java
0 → 100644
src/main/java/top/panll/assist/dto/UserSettings.java
| @@ -3,9 +3,15 @@ package top.panll.assist.dto; | @@ -3,9 +3,15 @@ package top.panll.assist.dto; | ||
| 3 | import org.springframework.beans.factory.annotation.Value; | 3 | import org.springframework.beans.factory.annotation.Value; |
| 4 | import org.springframework.stereotype.Component; | 4 | import org.springframework.stereotype.Component; |
| 5 | 5 | ||
| 6 | +/** | ||
| 7 | + * @author lin | ||
| 8 | + */ | ||
| 6 | @Component | 9 | @Component |
| 7 | public class UserSettings { | 10 | public class UserSettings { |
| 8 | 11 | ||
| 12 | + @Value("${userSettings.id}") | ||
| 13 | + private String id; | ||
| 14 | + | ||
| 9 | @Value("${userSettings.record}") | 15 | @Value("${userSettings.record}") |
| 10 | private String record; | 16 | private String record; |
| 11 | 17 | ||
| @@ -24,6 +30,14 @@ public class UserSettings { | @@ -24,6 +30,14 @@ public class UserSettings { | ||
| 24 | @Value("${userSettings.threads:2}") | 30 | @Value("${userSettings.threads:2}") |
| 25 | private int threads; | 31 | private int threads; |
| 26 | 32 | ||
| 33 | + public String getId() { | ||
| 34 | + return id; | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + public void setId(String id) { | ||
| 38 | + this.id = id; | ||
| 39 | + } | ||
| 40 | + | ||
| 27 | public String getRecord() { | 41 | public String getRecord() { |
| 28 | return record; | 42 | return record; |
| 29 | } | 43 | } |
src/main/java/top/panll/assist/service/FFmpegExecUtils.java
| @@ -49,9 +49,6 @@ public class FFmpegExecUtils implements InitializingBean{ | @@ -49,9 +49,6 @@ public class FFmpegExecUtils implements InitializingBean{ | ||
| 49 | @Autowired | 49 | @Autowired |
| 50 | private UserSettings userSettings; | 50 | private UserSettings userSettings; |
| 51 | 51 | ||
| 52 | - @Autowired | ||
| 53 | - private RedisUtil redisUtil; | ||
| 54 | - | ||
| 55 | private FFprobe ffprobe; | 52 | private FFprobe ffprobe; |
| 56 | private FFmpeg ffmpeg; | 53 | private FFmpeg ffmpeg; |
| 57 | 54 |
src/main/java/top/panll/assist/service/FileManagerTimer.java
| @@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired; | @@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired; | ||
| 7 | import org.springframework.scheduling.annotation.Scheduled; | 7 | import org.springframework.scheduling.annotation.Scheduled; |
| 8 | import org.springframework.stereotype.Component; | 8 | import org.springframework.stereotype.Component; |
| 9 | import org.springframework.util.StringUtils; | 9 | import org.springframework.util.StringUtils; |
| 10 | +import top.panll.assist.dto.AssistConstants; | ||
| 10 | import top.panll.assist.dto.MergeOrCutTaskInfo; | 11 | import top.panll.assist.dto.MergeOrCutTaskInfo; |
| 11 | import top.panll.assist.dto.UserSettings; | 12 | import top.panll.assist.dto.UserSettings; |
| 12 | import top.panll.assist.utils.RedisUtil; | 13 | import top.panll.assist.utils.RedisUtil; |
| @@ -35,8 +36,6 @@ public class FileManagerTimer { | @@ -35,8 +36,6 @@ public class FileManagerTimer { | ||
| 35 | @Autowired | 36 | @Autowired |
| 36 | private RedisUtil redisUtil; | 37 | private RedisUtil redisUtil; |
| 37 | 38 | ||
| 38 | - private final String keyStr = "MERGEORCUT"; | ||
| 39 | - | ||
| 40 | // @Scheduled(fixedDelay = 2000) //测试 20秒执行一次 | 39 | // @Scheduled(fixedDelay = 2000) //测试 20秒执行一次 |
| 41 | @Scheduled(cron = "0 0 0 * * ?") //每天的0点执行 | 40 | @Scheduled(cron = "0 0 0 * * ?") //每天的0点执行 |
| 42 | public void execute(){ | 41 | public void execute(){ |
| @@ -128,7 +127,7 @@ public class FileManagerTimer { | @@ -128,7 +127,7 @@ public class FileManagerTimer { | ||
| 128 | } | 127 | } |
| 129 | } | 128 | } |
| 130 | // 清理redis记录 | 129 | // 清理redis记录 |
| 131 | - String key = String.format("%S_*_*_*", keyStr); | 130 | + String key = String.format("%S_%S_*_*_*", AssistConstants.MERGEORCUT, userSettings.getId()); |
| 132 | List<Object> taskKeys = redisUtil.scan(key); | 131 | List<Object> taskKeys = redisUtil.scan(key); |
| 133 | for (Object taskKeyObj : taskKeys) { | 132 | for (Object taskKeyObj : taskKeys) { |
| 134 | String taskKey = (String) taskKeyObj; | 133 | String taskKey = (String) taskKeyObj; |
src/main/java/top/panll/assist/service/VideoFileService.java
| @@ -10,11 +10,8 @@ import org.springframework.beans.factory.annotation.Autowired; | @@ -10,11 +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.dto.SignInfo; | ||
| 14 | -import top.panll.assist.dto.SpaceInfo; | 13 | +import top.panll.assist.dto.*; |
| 15 | import top.panll.assist.utils.RedisUtil; | 14 | import top.panll.assist.utils.RedisUtil; |
| 16 | -import top.panll.assist.dto.MergeOrCutTaskInfo; | ||
| 17 | -import top.panll.assist.dto.UserSettings; | ||
| 18 | import top.panll.assist.utils.DateUtils; | 15 | import top.panll.assist.utils.DateUtils; |
| 19 | 16 | ||
| 20 | import java.io.File; | 17 | import java.io.File; |
| @@ -39,9 +36,6 @@ public class VideoFileService { | @@ -39,9 +36,6 @@ public class VideoFileService { | ||
| 39 | private RedisUtil redisUtil; | 36 | private RedisUtil redisUtil; |
| 40 | 37 | ||
| 41 | @Autowired | 38 | @Autowired |
| 42 | - private RedisTemplate redisTemplate; | ||
| 43 | - | ||
| 44 | - @Autowired | ||
| 45 | private FFmpegExecUtils ffmpegExecUtils; | 39 | private FFmpegExecUtils ffmpegExecUtils; |
| 46 | 40 | ||
| 47 | 41 | ||
| @@ -49,8 +43,6 @@ public class VideoFileService { | @@ -49,8 +43,6 @@ public class VideoFileService { | ||
| 49 | private final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); | 43 | private final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); |
| 50 | private final SimpleDateFormat simpleDateFormatForTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | 44 | private final SimpleDateFormat simpleDateFormatForTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| 51 | 45 | ||
| 52 | - private final String keyStr = "MERGEORCUT"; | ||
| 53 | - | ||
| 54 | public List<File> getAppList(Boolean sort) { | 46 | public List<File> getAppList(Boolean sort) { |
| 55 | File recordFile = new File(userSettings.getRecord()); | 47 | File recordFile = new File(userSettings.getRecord()); |
| 56 | if (recordFile.isDirectory()) { | 48 | if (recordFile.isDirectory()) { |
| @@ -150,7 +142,7 @@ public class VideoFileService { | @@ -150,7 +142,7 @@ public class VideoFileService { | ||
| 150 | long endTime = startTime + durationLong; | 142 | long endTime = startTime + durationLong; |
| 151 | endTime = endTime - endTime%1000; | 143 | endTime = endTime - endTime%1000; |
| 152 | 144 | ||
| 153 | - String key = "Stream_Call_Info" + app + "_" + stream; | 145 | + String key = AssistConstants.STREAM_CALL_INFO + userSettings.getId() + "_" + app + "_" + stream; |
| 154 | String callId = (String) redisUtil.get(key); | 146 | String callId = (String) redisUtil.get(key); |
| 155 | if (callId != null) { | 147 | if (callId != null) { |
| 156 | 148 | ||
| @@ -396,9 +388,8 @@ public class VideoFileService { | @@ -396,9 +388,8 @@ public class VideoFileService { | ||
| 396 | mergeOrCutTaskInfo.setDownloadFile(remoteHost + "/download.html?url=" + relativize); | 388 | mergeOrCutTaskInfo.setDownloadFile(remoteHost + "/download.html?url=" + relativize); |
| 397 | mergeOrCutTaskInfo.setPlayFile(remoteHost + "/" + relativize); | 389 | mergeOrCutTaskInfo.setPlayFile(remoteHost + "/" + relativize); |
| 398 | } | 390 | } |
| 399 | - String key = String.format("%S_%S_%S_%S", keyStr, mergeOrCutTaskInfo.getApp(), mergeOrCutTaskInfo.getStream(), mergeOrCutTaskInfo.getId()); | 391 | + String key = String.format("%S_%S_%S_%S_%S", AssistConstants.MERGEORCUT , userSettings.getId(), mergeOrCutTaskInfo.getApp(), mergeOrCutTaskInfo.getStream(), mergeOrCutTaskInfo.getId()); |
| 400 | redisUtil.set(key, mergeOrCutTaskInfo); | 392 | redisUtil.set(key, mergeOrCutTaskInfo); |
| 401 | - redisUtil.convertAndSend("topic_mergeorcut_end", mergeOrCutTaskInfo); | ||
| 402 | logger.info("[录像合并] 合并完成,APP:{}, STREAM: {}, 任务ID:{}", app, stream, taskId); | 393 | logger.info("[录像合并] 合并完成,APP:{}, STREAM: {}, 任务ID:{}", app, stream, taskId); |
| 403 | }else { | 394 | }else { |
| 404 | ffmpegExecUtils.mergeOrCutFile(filesInTime, recordFile, stream, (status, percentage, result)->{ | 395 | ffmpegExecUtils.mergeOrCutFile(filesInTime, recordFile, stream, (status, percentage, result)->{ |
| @@ -413,13 +404,11 @@ public class VideoFileService { | @@ -413,13 +404,11 @@ public class VideoFileService { | ||
| 413 | mergeOrCutTaskInfo.setDownloadFile(remoteHost + "/download.html?url=" + relativize); | 404 | mergeOrCutTaskInfo.setDownloadFile(remoteHost + "/download.html?url=" + relativize); |
| 414 | mergeOrCutTaskInfo.setPlayFile(remoteHost + "/" + relativize); | 405 | mergeOrCutTaskInfo.setPlayFile(remoteHost + "/" + relativize); |
| 415 | } | 406 | } |
| 416 | - redisUtil.convertAndSend("topic_mergeorcut_end", mergeOrCutTaskInfo); | ||
| 417 | logger.info("[录像合并] 合并完成,APP:{}, STREAM: {}, 任务ID:{}", app, stream, taskId); | 407 | logger.info("[录像合并] 合并完成,APP:{}, STREAM: {}, 任务ID:{}", app, stream, taskId); |
| 418 | }else { | 408 | }else { |
| 419 | mergeOrCutTaskInfo.setPercentage(percentage + ""); | 409 | mergeOrCutTaskInfo.setPercentage(percentage + ""); |
| 420 | - redisUtil.convertAndSend("topic_mergeorcut_continue", mergeOrCutTaskInfo); | ||
| 421 | } | 410 | } |
| 422 | - String key = String.format("%S_%S_%S_%S", keyStr, mergeOrCutTaskInfo.getApp(), mergeOrCutTaskInfo.getStream(), mergeOrCutTaskInfo.getId()); | 411 | + String key = String.format("%S_%S_%S_%S_%S", AssistConstants.MERGEORCUT, userSettings.getId(), mergeOrCutTaskInfo.getApp(), mergeOrCutTaskInfo.getStream(), mergeOrCutTaskInfo.getId()); |
| 423 | redisUtil.set(key, mergeOrCutTaskInfo); | 412 | redisUtil.set(key, mergeOrCutTaskInfo); |
| 424 | }); | 413 | }); |
| 425 | } | 414 | } |
| @@ -500,7 +489,8 @@ public class VideoFileService { | @@ -500,7 +489,8 @@ public class VideoFileService { | ||
| 500 | if (taskId == null) { | 489 | if (taskId == null) { |
| 501 | taskId = "*"; | 490 | taskId = "*"; |
| 502 | } | 491 | } |
| 503 | - List<Object> taskCatch = redisUtil.scan(String.format("%S_%S_%S_%S", keyStr, app, stream, taskId)); | 492 | + List<Object> taskCatch = redisUtil.scan(String.format("%S_%S_%S_%S_%S", AssistConstants.MERGEORCUT, |
| 493 | + userSettings.getId(), app, stream, taskId)); | ||
| 504 | for (int i = 0; i < taskCatch.size(); i++) { | 494 | for (int i = 0; i < taskCatch.size(); i++) { |
| 505 | String keyItem = taskCatch.get(i).toString(); | 495 | String keyItem = taskCatch.get(i).toString(); |
| 506 | MergeOrCutTaskInfo mergeOrCutTaskInfo = (MergeOrCutTaskInfo)redisUtil.get(keyItem); | 496 | MergeOrCutTaskInfo mergeOrCutTaskInfo = (MergeOrCutTaskInfo)redisUtil.get(keyItem); |
src/main/java/top/panll/assist/utils/RedisUtil.java
| 1 | package top.panll.assist.utils; | 1 | package top.panll.assist.utils; |
| 2 | 2 | ||
| 3 | -import com.alibaba.fastjson.JSONObject; | ||
| 4 | import org.springframework.beans.factory.annotation.Autowired; | 3 | import org.springframework.beans.factory.annotation.Autowired; |
| 5 | import org.springframework.data.redis.core.*; | 4 | import org.springframework.data.redis.core.*; |
| 6 | import org.springframework.stereotype.Component; | 5 | import org.springframework.stereotype.Component; |
| @@ -721,7 +720,4 @@ public class RedisUtil { | @@ -721,7 +720,4 @@ public class RedisUtil { | ||
| 721 | return new ArrayList<>(resultKeys); | 720 | return new ArrayList<>(resultKeys); |
| 722 | } | 721 | } |
| 723 | 722 | ||
| 724 | - public void convertAndSend(String channel, Object msg) { | ||
| 725 | -// redisTemplate.convertAndSend(channel, msg); | ||
| 726 | - } | ||
| 727 | } | 723 | } |
src/main/resources/application-local.yml
| @@ -33,6 +33,8 @@ server: | @@ -33,6 +33,8 @@ server: | ||
| 33 | 33 | ||
| 34 | # [根据业务需求配置] | 34 | # [根据业务需求配置] |
| 35 | userSettings: | 35 | userSettings: |
| 36 | + # [必选 ] 服务ID | ||
| 37 | + id: 334533 | ||
| 36 | # [必选 ] zlm配置的录像路径 | 38 | # [必选 ] zlm配置的录像路径 |
| 37 | record: /home/lin/server/test001/default/www/record/ | 39 | record: /home/lin/server/test001/default/www/record/ |
| 38 | # [可选 ] 录像保存时长(单位: 天)每天晚12点自动对过期文件执行清理 | 40 | # [可选 ] 录像保存时长(单位: 天)每天晚12点自动对过期文件执行清理 |