|
@@ -1,12 +1,17 @@
|
|
|
package com.fdkankan.job.job;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.fdkankan.fyun.config.FYunFileConfig;
|
|
|
import com.fdkankan.fyun.face.FYunFileServiceInterface;
|
|
|
import com.fdkankan.job.entity.ScenePro;
|
|
|
import com.fdkankan.job.service.*;
|
|
|
+import com.fdkankan.model.constants.ConstantFilePath;
|
|
|
import com.fdkankan.redis.util.RedisUtil;
|
|
|
import com.xxl.job.core.context.XxlJobHelper;
|
|
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
|
@@ -15,9 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -35,13 +38,17 @@ public class RepairVideosHandler {
|
|
|
private ISceneProService sceneProService;
|
|
|
@Autowired
|
|
|
ISceneEditInfoService sceneEditInfoService;
|
|
|
+ @Autowired
|
|
|
+ private FYunFileServiceInterface fYunFileService;
|
|
|
+ @Autowired
|
|
|
+ private FYunFileConfig fYunFileConfig;
|
|
|
|
|
|
|
|
|
@XxlJob("repairVideosHandler")
|
|
|
public void V4toV3Handler(){
|
|
|
XxlJobHelper.log("repairVideosHandler start.....");
|
|
|
|
|
|
- List<String> faildNumList = new ArrayList<>();
|
|
|
+ Set<String> faildNumList = new HashSet<>();
|
|
|
|
|
|
List<String> numList = null;
|
|
|
String nums = XxlJobHelper.getJobParam();
|
|
@@ -50,14 +57,79 @@ public class RepairVideosHandler {
|
|
|
}
|
|
|
|
|
|
LambdaQueryWrapper<ScenePro> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.like(ScenePro::getVideos, "/home/");
|
|
|
+ queryWrapper.like(ScenePro::getVideos, "/home/").like(ScenePro::getVideos, ".xml");
|
|
|
if(CollUtil.isNotEmpty(numList)){
|
|
|
queryWrapper.in(ScenePro::getNum, numList);
|
|
|
}
|
|
|
List<ScenePro> list = sceneProService.list(queryWrapper);
|
|
|
+ for (ScenePro pro : list) {
|
|
|
+ String videos = pro.getVideos();
|
|
|
+ JSONObject videosObj = JSONObject.parseObject(videos);
|
|
|
+ String upPath = videosObj.getString("upPath");
|
|
|
|
|
|
- XxlJobHelper.log("待修复场景数:{}", list.size());
|
|
|
+ String upName = upPath.substring(upPath.lastIndexOf("/"));
|
|
|
+ XxlJobHelper.log("文件名:{}", upName);
|
|
|
+ String targetUpPath = String.format(ConstantFilePath.DATA_PATH_FORMAT, pro.getNum()).concat(upName);
|
|
|
+
|
|
|
+ boolean found = false;
|
|
|
+
|
|
|
+ //判断home是否被删除,如果home没被删除。直接从home中获取
|
|
|
+ upPath = upPath.replace(fYunFileConfig.getHost(), "");
|
|
|
+ boolean exist = fYunFileService.fileExist(upPath);
|
|
|
+ XxlJobHelper.log("原始资源是否存在:{}", exist);
|
|
|
+ if(exist){
|
|
|
+ log.info("场景:{}在原始资源中找到");
|
|
|
+ found = true;
|
|
|
+ fYunFileService.copyFileBetweenBucket(fYunFileConfig.getBucket(), upPath, fYunFileConfig.getBucket(), targetUpPath);
|
|
|
+ }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)
|
|
|
+ .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;
|
|
|
+ fYunFileService.copyFileBetweenBucket(fYunFileConfig.getBucket(), upPath, fYunFileConfig.getBucket(), targetUpPath);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ //如果两个目录都没有,则记录为失败
|
|
|
+ faildNumList.add(pro.getNum());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ XxlJobHelper.log("待修复场景数:{}", list.size());
|
|
|
XxlJobHelper.log("repairVideosHandler end.....");
|
|
|
XxlJobHelper.log("失败场景码:" + JSON.toJSONString(faildNumList));
|
|
|
}
|