|
@@ -5,35 +5,66 @@ import cn.hutool.core.exceptions.ExceptionUtil;
|
|
import cn.hutool.core.io.FileUtil;
|
|
import cn.hutool.core.io.FileUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.ZipUtil;
|
|
import cn.hutool.core.util.ZipUtil;
|
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.fdkankan.common.constant.CommonSuccessStatus;
|
|
import com.fdkankan.common.constant.CommonSuccessStatus;
|
|
|
|
+import com.fdkankan.extend.TowerSceneBean;
|
|
|
|
+import com.fdkankan.extend.entity.Camera;
|
|
import com.fdkankan.extend.entity.CameraDetail;
|
|
import com.fdkankan.extend.entity.CameraDetail;
|
|
import com.fdkankan.extend.entity.ScenePlus;
|
|
import com.fdkankan.extend.entity.ScenePlus;
|
|
import com.fdkankan.extend.service.ICameraDetailService;
|
|
import com.fdkankan.extend.service.ICameraDetailService;
|
|
|
|
+import com.fdkankan.extend.service.ICameraService;
|
|
import com.fdkankan.extend.service.IScenePlusService;
|
|
import com.fdkankan.extend.service.IScenePlusService;
|
|
import com.fdkankan.extend.service.ITowerService;
|
|
import com.fdkankan.extend.service.ITowerService;
|
|
|
|
+import com.fdkankan.extend.util.RsaCryptTools;
|
|
import com.fdkankan.fyun.face.FYunFileServiceInterface;
|
|
import com.fdkankan.fyun.face.FYunFileServiceInterface;
|
|
import com.fdkankan.redis.constant.RedisKey;
|
|
import com.fdkankan.redis.constant.RedisKey;
|
|
import com.fdkankan.redis.util.RedisUtil;
|
|
import com.fdkankan.redis.util.RedisUtil;
|
|
import com.fdkankan.web.response.ResultData;
|
|
import com.fdkankan.web.response.ResultData;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.cloud.context.config.annotation.RefreshScope;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import com.fdkankan.model.constants.UploadFilePath;
|
|
import com.fdkankan.model.constants.UploadFilePath;
|
|
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Objects;
|
|
|
|
-import java.util.Set;
|
|
|
|
|
|
+import javax.crypto.BadPaddingException;
|
|
|
|
+import javax.crypto.IllegalBlockSizeException;
|
|
|
|
+import javax.crypto.NoSuchPaddingException;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.security.InvalidKeyException;
|
|
|
|
+import java.security.NoSuchAlgorithmException;
|
|
|
|
+import java.security.spec.InvalidKeySpecException;
|
|
|
|
+import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
+@RefreshScope
|
|
@Slf4j
|
|
@Slf4j
|
|
@Service
|
|
@Service
|
|
public class TowerServiceImpl implements ITowerService {
|
|
public class TowerServiceImpl implements ITowerService {
|
|
|
|
|
|
private static String parentPath = "/home/backend/4dkankan_v4/modeling-extend/download/";
|
|
private static String parentPath = "/home/backend/4dkankan_v4/modeling-extend/download/";
|
|
|
|
|
|
|
|
+ private static String ossParentPath = "customer-projects/china-tower/";
|
|
|
|
+
|
|
|
|
+ private static String ossScenePoolFilePath = ossParentPath.concat("scene.txt");
|
|
|
|
+
|
|
|
|
+ private static String ossCameraPoolFilePath = ossParentPath.concat("camera.txt");
|
|
|
|
+
|
|
|
|
+ private static String pushLogPath = parentPath.concat("log.txt");
|
|
|
|
+
|
|
|
|
+ @Value("${tower.manufact}")
|
|
|
|
+ private String manufact;
|
|
|
|
+
|
|
|
|
+ @Value("${tower.private-key}")
|
|
|
|
+ private String privateKey;
|
|
|
|
+
|
|
|
|
+ @Value("${tower.url}")
|
|
|
|
+ private String url;
|
|
|
|
+
|
|
@Autowired
|
|
@Autowired
|
|
private FYunFileServiceInterface fYunFileService;
|
|
private FYunFileServiceInterface fYunFileService;
|
|
@Autowired
|
|
@Autowired
|
|
@@ -44,18 +75,33 @@ public class TowerServiceImpl implements ITowerService {
|
|
private IScenePlusService scenePlusService;
|
|
private IScenePlusService scenePlusService;
|
|
@Autowired
|
|
@Autowired
|
|
private ITowerService towerService;
|
|
private ITowerService towerService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ICameraService cameraService;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public String packSceneDataHandler(String num) {
|
|
|
|
|
|
+ public String packSceneDataHandler(String num, String title) throws Exception {
|
|
|
|
+
|
|
|
|
+ //校验场景名称是否正确
|
|
|
|
+ String sceneStr = fYunFileService.getFileContent(ossScenePoolFilePath);
|
|
|
|
+ List<TowerSceneBean> towerSceneBeans = JSON.parseArray(sceneStr, TowerSceneBean.class);
|
|
|
|
+ if(CollUtil.isEmpty(towerSceneBeans)){
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ TowerSceneBean towerSceneBean = towerSceneBeans.stream().filter(bean -> title.equals(bean.getName())).findFirst().get();
|
|
|
|
+ if(Objects.isNull(towerSceneBean)){
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
log.info("开始下载:{}", num);
|
|
log.info("开始下载:{}", num);
|
|
|
|
|
|
//场景本地数据父目录
|
|
//场景本地数据父目录
|
|
- String sceneSourcePath = parentPath + num + "/";
|
|
|
|
- String zipPath = parentPath + num + ".zip";
|
|
|
|
|
|
+ String scenePath = parentPath.concat(num).concat("/");
|
|
|
|
+ String sceneSourcePath = scenePath.concat(towerSceneBean.getSceneId()).concat("_").concat(towerSceneBean.getRoomId());
|
|
|
|
+ String zipPath = sceneSourcePath.concat(".zip");
|
|
|
|
|
|
//data数据下载
|
|
//data数据下载
|
|
- String dataPath = sceneSourcePath + "data/";
|
|
|
|
|
|
+ String dataPath = sceneSourcePath + "/data/";
|
|
String ossDataPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
|
|
String ossDataPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
|
|
//下载floorplan.json
|
|
//下载floorplan.json
|
|
fYunFileService.downloadFile(ossDataPath.concat("floorplan.json"), dataPath.concat("floorplan.json"));
|
|
fYunFileService.downloadFile(ossDataPath.concat("floorplan.json"), dataPath.concat("floorplan.json"));
|
|
@@ -70,26 +116,44 @@ public class TowerServiceImpl implements ITowerService {
|
|
FileUtil.writeUtf8String(sceneJsonObj.toJSONString(), sceneJsonPath);
|
|
FileUtil.writeUtf8String(sceneJsonObj.toJSONString(), sceneJsonPath);
|
|
|
|
|
|
//下载mesh
|
|
//下载mesh
|
|
- fYunFileService.downloadFileByCommand(dataPath, ossDataPath.concat("mesh"));
|
|
|
|
|
|
+ FileUtil.mkdir(dataPath.concat("mesh/"));
|
|
|
|
+ List<String> meshList = fYunFileService.listRemoteFiles(ossDataPath.concat("mesh"));
|
|
|
|
+ meshList.parallelStream().forEach(key -> fYunFileService.downloadFile(key, dataPath.concat("mesh/")));
|
|
|
|
|
|
//images数据下载
|
|
//images数据下载
|
|
- String imagesPath = sceneSourcePath + "images/";
|
|
|
|
|
|
+ String imagesPath = sceneSourcePath + "/images/";
|
|
String ossImagesPath = String.format(UploadFilePath.IMG_VIEW_PATH, num);
|
|
String ossImagesPath = String.format(UploadFilePath.IMG_VIEW_PATH, num);
|
|
//下载high图
|
|
//下载high图
|
|
- fYunFileService.downloadFileByCommand(imagesPath.concat("4k/"), ossImagesPath.concat("pan/high/"));
|
|
|
|
|
|
+ List<String> highList = fYunFileService.listRemoteFiles(ossImagesPath.concat("pan/high/"));
|
|
|
|
+ FileUtil.mkdir(imagesPath.concat("4k/"));
|
|
|
|
+ highList.parallelStream().forEach(key -> fYunFileService.downloadFile(key, imagesPath.concat("4k/")));
|
|
//下载low图
|
|
//下载low图
|
|
- fYunFileService.downloadFileByCommand(imagesPath.concat("512/"), ossImagesPath.concat("pan/low/"));
|
|
|
|
|
|
+ FileUtil.mkdir(imagesPath.concat("512/"));
|
|
|
|
+ List<String> lowList = fYunFileService.listRemoteFiles(ossImagesPath.concat("pan/low/"));
|
|
|
|
+ lowList.parallelStream().forEach(key -> fYunFileService.downloadFile(key, imagesPath.concat("512/")));
|
|
//下载vision.txt
|
|
//下载vision.txt
|
|
fYunFileService.downloadFile(ossImagesPath.concat("vision.txt"), imagesPath.concat("vision.txt"));
|
|
fYunFileService.downloadFile(ossImagesPath.concat("vision.txt"), imagesPath.concat("vision.txt"));
|
|
|
|
|
|
//打包
|
|
//打包
|
|
- ZipUtil.zip(sceneSourcePath, zipPath);
|
|
|
|
|
|
+ ZipUtil.zip(sceneSourcePath, zipPath, true);
|
|
|
|
+
|
|
|
|
+ log.info("结束下载,开始推送:{}", num);
|
|
|
|
|
|
- log.info("结束下载:{}", num);
|
|
|
|
|
|
+ try {
|
|
|
|
+// this.dataPush(num, title, towerSceneBean.getSceneId(), towerSceneBean.getRoomId(), zipPath);
|
|
|
|
+ }finally {
|
|
|
|
+ FileUtil.del(scenePath);
|
|
|
|
+ FileUtil.del(sceneSourcePath);
|
|
|
|
+ }
|
|
|
|
|
|
return zipPath;
|
|
return zipPath;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public static void main(String[] args) {
|
|
|
|
+ boolean directory = FileUtil.isDirectory("/home/backend/4dkankan_v4/modeling-extend/download/KK-t-rXyBOE9LG8F/123123_456456/images/4k/");
|
|
|
|
+ System.out.println(directory);
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public void packSceneData(Long companyId, List<String> nums) {
|
|
public void packSceneData(Long companyId, List<String> nums) {
|
|
|
|
|
|
@@ -108,6 +172,15 @@ public class TowerServiceImpl implements ITowerService {
|
|
scenePlusList = scenePlusService.getByCameraIds(cameraIds);
|
|
scenePlusList = scenePlusService.getByCameraIds(cameraIds);
|
|
}else if(CollUtil.isNotEmpty(nums)){
|
|
}else if(CollUtil.isNotEmpty(nums)){
|
|
scenePlusList = scenePlusService.list(new LambdaQueryWrapper<ScenePlus>().in(ScenePlus::getNum, nums));
|
|
scenePlusList = scenePlusService.list(new LambdaQueryWrapper<ScenePlus>().in(ScenePlus::getNum, nums));
|
|
|
|
+ }else{
|
|
|
|
+ String snCodeStr = fYunFileService.getFileContent(ossCameraPoolFilePath);
|
|
|
|
+ List<String> snCodeList = Arrays.asList(snCodeStr.split(","));
|
|
|
|
+ List<Camera> cameraList = cameraService.listBySnCodes(snCodeList);
|
|
|
|
+ List<Long> cameraIdList = cameraList.stream().map(Camera::getId).collect(Collectors.toList());
|
|
|
|
+ String sceneStr = fYunFileService.getFileContent(ossScenePoolFilePath);
|
|
|
|
+ List<TowerSceneBean> towerSceneBeans = JSON.parseArray(sceneStr, TowerSceneBean.class);
|
|
|
|
+ List<String> titleList = towerSceneBeans.stream().map(TowerSceneBean::getName).collect(Collectors.toList());
|
|
|
|
+ scenePlusList = scenePlusService.list(new LambdaQueryWrapper<ScenePlus>().in(ScenePlus::getCameraId, cameraIdList).in(ScenePlus::getTitle, titleList));
|
|
}
|
|
}
|
|
if(CollUtil.isEmpty(scenePlusList)){
|
|
if(CollUtil.isEmpty(scenePlusList)){
|
|
return;
|
|
return;
|
|
@@ -115,28 +188,50 @@ public class TowerServiceImpl implements ITowerService {
|
|
|
|
|
|
//遍历场景列表开始下载
|
|
//遍历场景列表开始下载
|
|
scenePlusList.stream().forEach(plus -> {
|
|
scenePlusList.stream().forEach(plus -> {
|
|
- JSONObject jsonObject = null;
|
|
|
|
- String str = redisUtil.hget(key, plus.getNum());
|
|
|
|
- if(StrUtil.isNotEmpty(str)){
|
|
|
|
- jsonObject = JSON.parseObject(str);
|
|
|
|
- }
|
|
|
|
- if(Objects.isNull(jsonObject) || jsonObject.getInteger("status") == CommonSuccessStatus.FAIL.code()){
|
|
|
|
- try {
|
|
|
|
- jsonObject = new JSONObject();
|
|
|
|
- jsonObject.put("num", plus.getNum());
|
|
|
|
- String zipPath = towerService.packSceneDataHandler(plus.getNum());
|
|
|
|
-
|
|
|
|
- // TODO: 2023/6/20 推送到铁塔
|
|
|
|
-
|
|
|
|
- jsonObject.put("status", CommonSuccessStatus.SUCCESS.code());
|
|
|
|
- jsonObject.put("zipPath", zipPath);
|
|
|
|
- redisUtil.hset(key, plus.getNum(), JSON.toJSONString(jsonObject));
|
|
|
|
- }catch (Exception e){
|
|
|
|
- jsonObject.put("status", CommonSuccessStatus.FAIL.code());
|
|
|
|
- jsonObject.put("error", ExceptionUtil.stacktraceToString(e, 3000));
|
|
|
|
- redisUtil.hset(key, plus.getNum(), JSON.toJSONString(jsonObject));
|
|
|
|
- }
|
|
|
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
|
+ try {
|
|
|
|
+ jsonObject = new JSONObject();
|
|
|
|
+ jsonObject.put("title", plus.getTitle());
|
|
|
|
+ jsonObject.put("num", plus.getNum());
|
|
|
|
+ String zipPath = towerService.packSceneDataHandler(plus.getNum(), plus.getTitle());
|
|
|
|
+ jsonObject.put("status", CommonSuccessStatus.SUCCESS.code());
|
|
|
|
+ jsonObject.put("zipPath", zipPath);
|
|
|
|
+ redisUtil.hset(key, plus.getNum(), JSON.toJSONString(jsonObject));
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ log.error("推送失败,num:{},title:{}", plus.getNum(), plus.getTitle(), e);
|
|
|
|
+ jsonObject.put("status", CommonSuccessStatus.FAIL.code());
|
|
|
|
+ jsonObject.put("error", ExceptionUtil.stacktraceToString(e, 3000));
|
|
|
|
+ redisUtil.hset(key, plus.getNum(), JSON.toJSONString(jsonObject));
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void dataPush(String num, String title, String sceneId, String roomId, String zipPath) throws Exception {
|
|
|
|
+
|
|
|
|
+ String fileMd5 = com.fdkankan.extend.util.FileUtil.getMulFileMD5(FileUtil.getInputStream(zipPath));
|
|
|
|
+ String compose = sceneId.concat("+").concat(roomId).concat("+").concat(fileMd5);
|
|
|
|
+ String encrypt = RsaCryptTools.encryptData(compose, privateKey);
|
|
|
|
+
|
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
|
+ params.put("stationCode", sceneId);
|
|
|
|
+ params.put("roomEntityID", roomId);
|
|
|
|
+ params.put("file", FileUtil.file(zipPath));
|
|
|
|
+ params.put("manufact", manufact);
|
|
|
|
+ params.put("encrypt", encrypt);
|
|
|
|
+ String post = HttpUtil.post(url, params);
|
|
|
|
+ JSONObject jsonObject = JSON.parseObject(post);
|
|
|
|
+
|
|
|
|
+ this.dataPushLog(num, title, jsonObject.getString("resultCode"), jsonObject.getString("resultMsg"));
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void dataPushLog(String num, String title, String resultCode, String resultMsg){
|
|
|
|
+ String content = num.concat("-").concat(title).concat(" : ").concat(resultCode);
|
|
|
|
+ if(StrUtil.isNotEmpty(resultMsg)){
|
|
|
|
+ content = content.concat("-").concat(resultMsg);
|
|
|
|
+ }
|
|
|
|
+ content = content.concat("\r\n");
|
|
|
|
+ FileUtil.writeUtf8String(content, parentPath);
|
|
|
|
+ }
|
|
}
|
|
}
|