|
@@ -64,84 +64,93 @@ public class RepairVideosHandler {
|
|
|
}
|
|
|
List<ScenePro> list = sceneProService.list(queryWrapper);
|
|
|
for (ScenePro pro : list) {
|
|
|
- String videos = pro.getVideos();
|
|
|
- JSONObject videosObj = JSONObject.parseObject(videos);
|
|
|
- String upPath = videosObj.getString("upPath");
|
|
|
-
|
|
|
- String upName = upPath.substring(upPath.lastIndexOf("/") + 1);
|
|
|
- XxlJobHelper.log("文件名:{}", upName);
|
|
|
- String targetUpPath = String.format(ConstantFilePath.DATA_PATH_FORMAT, pro.getNum()).concat(upName);
|
|
|
- String targetUpPath1 = String.format(ConstantFilePath.DATA_PATH_FORMAT, pro.getNum()).concat("Up.xml");
|
|
|
- String targetUpPath2 = String.format(ConstantFilePath.DATA_PATH_FORMAT, pro.getNum()).concat("Up2.xml");
|
|
|
-
|
|
|
- boolean found = false;
|
|
|
-
|
|
|
- //判断home是否被删除,如果home没被删除。直接从home中获取
|
|
|
- upPath = upPath.replace(fYunFileConfig.getHost(), "");
|
|
|
- String upPath1 = upPath.replace(upName, "").concat("Up.xml");
|
|
|
- String upPath2 = upPath.replace(upName, "").concat("Up2.xml");
|
|
|
- boolean exist = fYunFileService.fileExist(upPath);
|
|
|
- XxlJobHelper.log("原始资源是否存在:{}", exist);
|
|
|
- if(exist){
|
|
|
- log.info("场景:{}在原始资源中找到", pro.getNum());
|
|
|
- found = true;
|
|
|
- log.info("upPath=" + upPath);
|
|
|
- log.info("targetUpPath=" + targetUpPath);
|
|
|
+
|
|
|
+ try {
|
|
|
+ String videos = pro.getVideos();
|
|
|
+ JSONObject videosObj = JSONObject.parseObject(videos);
|
|
|
+ String upPath = videosObj.getString("upPath");
|
|
|
+
|
|
|
+ String upName = upPath.substring(upPath.lastIndexOf("/") + 1);
|
|
|
+ XxlJobHelper.log("文件名:{}", upName);
|
|
|
+ String targetUpPath = String.format(ConstantFilePath.DATA_PATH_FORMAT, pro.getNum()).concat(upName);
|
|
|
+ String targetUpPath1 = String.format(ConstantFilePath.DATA_PATH_FORMAT, pro.getNum()).concat("Up.xml");
|
|
|
+ String targetUpPath2 = String.format(ConstantFilePath.DATA_PATH_FORMAT, pro.getNum()).concat("Up2.xml");
|
|
|
+
|
|
|
+ boolean found = false;
|
|
|
+
|
|
|
+ //判断home是否被删除,如果home没被删除。直接从home中获取
|
|
|
+ upPath = upPath.replace(fYunFileConfig.getHost(), "");
|
|
|
+ String upPath1 = upPath.replace(upName, "").concat("Up.xml");
|
|
|
+ String upPath2 = upPath.replace(upName, "").concat("Up2.xml");
|
|
|
+ boolean exist = fYunFileService.fileExist(upPath);
|
|
|
+ XxlJobHelper.log("原始资源是否存在:{}", exist);
|
|
|
+ if (exist) {
|
|
|
+ log.info("场景:{}在原始资源中找到", pro.getNum());
|
|
|
+ found = true;
|
|
|
+ log.info("upPath=" + upPath);
|
|
|
+ log.info("targetUpPath=" + targetUpPath);
|
|
|
// fYunFileService.copyFileBetweenBucket(fYunFileConfig.getBucket(), upPath, fYunFileConfig.getBucket(), targetUpPath);
|
|
|
- fYunFileService.uploadFile(fYunFileService.getFileContent(upPath1).getBytes(StandardCharsets.UTF_8), targetUpPath1);
|
|
|
- fYunFileService.uploadFile(fYunFileService.getFileContent(upPath2).getBytes(StandardCharsets.UTF_8), targetUpPath2);
|
|
|
- }else{
|
|
|
- //如果home已被删除,则找相同相机下的场景,有则取回
|
|
|
- if(Objects.isNull(pro.getCameraId())){
|
|
|
- faildNumList.add(pro.getNum());
|
|
|
- log.info("场景:{}相机id为空", pro.getNum());
|
|
|
- }
|
|
|
- //先查询v3场景
|
|
|
- List<ScenePro> v3List = sceneProService.list(
|
|
|
- new LambdaQueryWrapper<ScenePro>()
|
|
|
- .eq(ScenePro::getCameraId, pro.getCameraId())
|
|
|
- .ne(ScenePro::getNum, pro.getNum())
|
|
|
+ fYunFileService.uploadFile(fYunFileService.getFileContent(upPath1).getBytes(StandardCharsets.UTF_8), targetUpPath1);
|
|
|
+ fYunFileService.uploadFile(fYunFileService.getFileContent(upPath2).getBytes(StandardCharsets.UTF_8), targetUpPath2);
|
|
|
+ } else {
|
|
|
+ //如果home已被删除,则找相同相机下的场景,有则取回
|
|
|
+ if (Objects.isNull(pro.getCameraId())) {
|
|
|
+ faildNumList.add(pro.getNum());
|
|
|
+ log.info("场景:{}相机id为空", pro.getNum());
|
|
|
+ }
|
|
|
+ //先查询v3场景
|
|
|
+ List<ScenePro> v3List = sceneProService.list(
|
|
|
+ new LambdaQueryWrapper<ScenePro>()
|
|
|
+ .eq(ScenePro::getCameraId, pro.getCameraId())
|
|
|
+ .ne(ScenePro::getNum, pro.getNum())
|
|
|
// .like(ScenePro::getVideos, upName)
|
|
|
- .isNotNull(ScenePro::getVideos)
|
|
|
- .orderByDesc(ScenePro::getCreateTime));
|
|
|
- if(CollUtil.isNotEmpty(v3List)){
|
|
|
- for (ScenePro scenePro : v3List) {
|
|
|
- upPath = JSONObject.parseObject(scenePro.getVideos()).getString("upPath").replace(fYunFileConfig.getHost(), "");
|
|
|
- if(!fYunFileService.fileExist(upPath)){
|
|
|
- continue;
|
|
|
+ .isNotNull(ScenePro::getVideos)
|
|
|
+ .orderByDesc(ScenePro::getCreateTime));
|
|
|
+ if (CollUtil.isNotEmpty(v3List)) {
|
|
|
+ for (ScenePro scenePro : v3List) {
|
|
|
+ upPath = JSONObject.parseObject(scenePro.getVideos()).getString("upPath").replace(fYunFileConfig.getHost(), "");
|
|
|
+ if (!fYunFileService.fileExist(upPath)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ found = true;
|
|
|
+ log.info("upPath=" + upPath);
|
|
|
+ log.info("targetUpPath=" + targetUpPath);
|
|
|
+ fYunFileService.uploadFile(fYunFileService.getFileContent(upPath1).getBytes(StandardCharsets.UTF_8), targetUpPath1);
|
|
|
+ fYunFileService.uploadFile(fYunFileService.getFileContent(upPath2).getBytes(StandardCharsets.UTF_8), targetUpPath2);
|
|
|
+ log.info("场景:{}在场景{}中找到,路径为:{}", pro.getNum(), scenePro.getNum(), upPath);
|
|
|
+ break;
|
|
|
}
|
|
|
- found = true;
|
|
|
- log.info("upPath=" + upPath);
|
|
|
- log.info("targetUpPath=" + targetUpPath);
|
|
|
- fYunFileService.uploadFile(fYunFileService.getFileContent(upPath1).getBytes(StandardCharsets.UTF_8), targetUpPath1);
|
|
|
- fYunFileService.uploadFile(fYunFileService.getFileContent(upPath2).getBytes(StandardCharsets.UTF_8), targetUpPath2);
|
|
|
- log.info("场景:{}在场景{}中找到,路径为:{}", pro.getNum(), scenePro.getNum(), upPath);
|
|
|
- break;
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- //更新数据库以及scene.json
|
|
|
- if(found){
|
|
|
- videosObj.put("upPath", fYunFileConfig.getHost().concat(targetUpPath));
|
|
|
- pro.setVideos(videosObj.toJSONString());
|
|
|
- sceneProService.updateById(pro);
|
|
|
-
|
|
|
- String sceneJsonPath = ConstantFilePath.SCENE_PATH + String.format(ConstantFilePath.DATA_PATH_FORMAT, pro.getNum()) + "scene.json";
|
|
|
- if(FileUtil.exist(sceneJsonPath)){
|
|
|
- String sceneJsonStr = FileUtil.readUtf8String(sceneJsonPath);
|
|
|
- if(StrUtil.isNotEmpty(sceneJsonStr)){
|
|
|
- JSONObject sceneJsonObj = JSON.parseObject(sceneJsonStr);
|
|
|
- sceneJsonObj.put("videos", fYunFileConfig.getHost().concat(targetUpPath));
|
|
|
- FileUtil.writeUtf8String(sceneJsonObj.toJSONString(), sceneJsonPath);
|
|
|
+ //更新数据库以及scene.json
|
|
|
+ if (found) {
|
|
|
+ videosObj.put("upPath", fYunFileConfig.getHost().concat(targetUpPath));
|
|
|
+ pro.setVideos(videosObj.toJSONString());
|
|
|
+ sceneProService.updateById(pro);
|
|
|
+
|
|
|
+ String sceneJsonPath = ConstantFilePath.SCENE_PATH + String.format(ConstantFilePath.DATA_PATH_FORMAT, pro.getNum()) + "scene.json";
|
|
|
+ if (FileUtil.exist(sceneJsonPath)) {
|
|
|
+ String sceneJsonStr = FileUtil.readUtf8String(sceneJsonPath);
|
|
|
+ if (StrUtil.isNotEmpty(sceneJsonStr)) {
|
|
|
+ JSONObject sceneJsonObj = JSON.parseObject(sceneJsonStr);
|
|
|
+ sceneJsonObj.put("videos", fYunFileConfig.getHost().concat(targetUpPath));
|
|
|
+ FileUtil.writeUtf8String(sceneJsonObj.toJSONString(), sceneJsonPath);
|
|
|
+ }
|
|
|
}
|
|
|
+ } else {
|
|
|
+ //如果两个目录都没有,则记录为失败
|
|
|
+ faildNumList.add(pro.getNum());
|
|
|
}
|
|
|
- }else{
|
|
|
+ } catch (Exception e) {
|
|
|
//如果两个目录都没有,则记录为失败
|
|
|
+ log.error(pro.getNum() + "修复失败", e);
|
|
|
faildNumList.add(pro.getNum());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
XxlJobHelper.log("待修复场景数:{}", list.size());
|
|
|
XxlJobHelper.log("repairVideosHandler end.....");
|
|
|
XxlJobHelper.log("失败场景码:" + JSON.toJSONString(faildNumList));
|