|
@@ -1,37 +1,48 @@
|
|
|
package com.fdkankan.extend.service.impl;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.exceptions.ExceptionUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.core.util.ZipUtil;
|
|
|
+import cn.hutool.http.HttpStatus;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.fdkankan.common.constant.CommonSuccessStatus;
|
|
|
+import com.fdkankan.common.constant.ErrorCode;
|
|
|
+import com.fdkankan.common.constant.ServerCode;
|
|
|
+import com.fdkankan.common.exception.BusinessException;
|
|
|
import com.fdkankan.common.util.DateExtUtil;
|
|
|
import com.fdkankan.extend.TowerSceneBean;
|
|
|
+import com.fdkankan.extend.callback.ErrorCallback;
|
|
|
+import com.fdkankan.extend.callback.SuccessCallback;
|
|
|
import com.fdkankan.extend.entity.Camera;
|
|
|
import com.fdkankan.extend.entity.CameraDetail;
|
|
|
import com.fdkankan.extend.entity.ScenePlus;
|
|
|
-import com.fdkankan.extend.service.ICameraDetailService;
|
|
|
-import com.fdkankan.extend.service.ICameraService;
|
|
|
-import com.fdkankan.extend.service.IScenePlusService;
|
|
|
-import com.fdkankan.extend.service.ITowerService;
|
|
|
+import com.fdkankan.extend.httpclient.HttpClient;
|
|
|
+import com.fdkankan.extend.service.*;
|
|
|
import com.fdkankan.extend.util.RsaCryptTools;
|
|
|
import com.fdkankan.fyun.face.FYunFileServiceInterface;
|
|
|
import com.fdkankan.model.constants.UploadFilePath;
|
|
|
+import com.fdkankan.model.utils.SceneUtil;
|
|
|
import com.fdkankan.redis.constant.RedisKey;
|
|
|
import com.fdkankan.redis.util.RedisUtil;
|
|
|
+import com.fdkankan.web.response.ResultData;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import netscape.javascript.JSObject;
|
|
|
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.web.multipart.MultipartFile;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -59,6 +70,9 @@ public class TowerServiceImpl implements ITowerService {
|
|
|
@Value("${tower.url}")
|
|
|
private String url;
|
|
|
|
|
|
+ @Value("fyun.bucket")
|
|
|
+ private String bucket;
|
|
|
+
|
|
|
@Autowired
|
|
|
private FYunFileServiceInterface fYunFileService;
|
|
|
@Autowired
|
|
@@ -72,8 +86,14 @@ public class TowerServiceImpl implements ITowerService {
|
|
|
@Autowired
|
|
|
private ICameraService cameraService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ISsoService ssoService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private HttpClient httpClient;
|
|
|
+
|
|
|
@Override
|
|
|
- public String packSceneDataHandler(String num, String title) throws Exception {
|
|
|
+ public String packSceneDataHandler(String num, String title, String logId) throws Exception {
|
|
|
|
|
|
//校验场景名称是否正确
|
|
|
String sceneStr = fYunFileService.getFileContent(ossScenePoolFilePath);
|
|
@@ -129,6 +149,28 @@ public class TowerServiceImpl implements ITowerService {
|
|
|
//下载vision.txt
|
|
|
fYunFileService.downloadFile(ossImagesPath.concat("vision.txt"), imagesPath.concat("vision.txt"));
|
|
|
|
|
|
+ //下载caches/images
|
|
|
+ List<String> panoramaImageList = SceneUtil.getPanoramaImageList(imagesPath.concat("vision.txt"));
|
|
|
+ log.info(JSON.toJSONString(panoramaImageList));
|
|
|
+ List<String> imageList = fYunFileService.listRemoteFiles(String.format(UploadFilePath.scene_result_data_path, num).concat("caches/images/"));
|
|
|
+ if(CollUtil.isNotEmpty(imageList)){
|
|
|
+ imageList.stream().forEach(key->{
|
|
|
+ if(panoramaImageList.contains(key.substring(key.lastIndexOf("/") + 1))){
|
|
|
+ if(!FileUtil.exist(imagesPath.concat("8K"))){
|
|
|
+ FileUtil.mkdir(imagesPath.concat("8K"));
|
|
|
+ }
|
|
|
+ fYunFileService.downloadFile(key, imagesPath.concat("8K"));
|
|
|
+ }
|
|
|
+ });
|
|
|
+// //移除非必须文件
|
|
|
+// List<String> fileNames = FileUtil.listFileNames(imagesPath.concat("8K/"));
|
|
|
+// fileNames.stream().forEach(name->{
|
|
|
+// if(!panoramaImageList.contains(name)){
|
|
|
+// FileUtil.del(imagesPath.concat("8K/") + name);
|
|
|
+// }
|
|
|
+// });
|
|
|
+ }
|
|
|
+
|
|
|
this.convertVisable(imagesPath.concat("vision.txt"));
|
|
|
|
|
|
//打包
|
|
@@ -137,7 +179,7 @@ public class TowerServiceImpl implements ITowerService {
|
|
|
log.info("结束下载,开始推送:{}", num);
|
|
|
|
|
|
try {
|
|
|
- this.dataPush(num, title, towerSceneBean.getSceneId(), towerSceneBean.getRoomId(), zipPath);
|
|
|
+ this.dataPush(num, title, towerSceneBean.getSceneId(), towerSceneBean.getRoomId(), zipPath, logId);
|
|
|
}finally {
|
|
|
FileUtil.del(scenePath);
|
|
|
}
|
|
@@ -145,6 +187,7 @@ public class TowerServiceImpl implements ITowerService {
|
|
|
return zipPath;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
private void convertVisable(String visionPath){
|
|
|
|
|
|
String visionStr = FileUtil.readUtf8String(visionPath);
|
|
@@ -175,7 +218,6 @@ public class TowerServiceImpl implements ITowerService {
|
|
|
int size = visibles.size();
|
|
|
String[] visibleArr = new String[size];
|
|
|
for(int j = 0; j < size; j++){
|
|
|
- System.out.println(visibles.get(j));
|
|
|
int index = (Integer)visibles.get(j);
|
|
|
String uuid = uuidMap.get(index);
|
|
|
visibleArr[j] = uuid;
|
|
@@ -204,12 +246,10 @@ public class TowerServiceImpl implements ITowerService {
|
|
|
}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));
|
|
|
+ scenePlusList = scenePlusService.list(new LambdaQueryWrapper<ScenePlus>().in(ScenePlus::getTitle, titleList));
|
|
|
List<String> dbTitleList = scenePlusList.stream().map(ScenePlus::getTitle).collect(Collectors.toList());
|
|
|
List<String> notFindList = titleList.stream().filter(title -> {
|
|
|
if (dbTitleList.contains(title)) {
|
|
@@ -230,6 +270,8 @@ public class TowerServiceImpl implements ITowerService {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ String id = DateExtUtil.format(Calendar.getInstance().getTime(), "yyyyMMddHHmmss");
|
|
|
+
|
|
|
//遍历场景列表开始下载
|
|
|
scenePlusList.stream().forEach(plus -> {
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
@@ -237,7 +279,7 @@ public class TowerServiceImpl implements ITowerService {
|
|
|
jsonObject = new JSONObject();
|
|
|
jsonObject.put("title", plus.getTitle());
|
|
|
jsonObject.put("num", plus.getNum());
|
|
|
- String zipPath = towerService.packSceneDataHandler(plus.getNum(), plus.getTitle());
|
|
|
+ String zipPath = towerService.packSceneDataHandler(plus.getNum(), plus.getTitle(), id);
|
|
|
jsonObject.put("status", CommonSuccessStatus.SUCCESS.code());
|
|
|
jsonObject.put("zipPath", zipPath);
|
|
|
redisUtil.hset(key, plus.getNum(), JSON.toJSONString(jsonObject));
|
|
@@ -251,7 +293,7 @@ public class TowerServiceImpl implements ITowerService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void dataPush(String num, String title, String sceneId, String roomId, String zipPath) throws Exception {
|
|
|
+ public void dataPush(String num, String title, String sceneId, String roomId, String zipPath, String logId) throws Exception {
|
|
|
|
|
|
log.info("开始组装参数");
|
|
|
|
|
@@ -271,10 +313,15 @@ public class TowerServiceImpl implements ITowerService {
|
|
|
log.info("compose:{}", compose);
|
|
|
log.info("encrypt:{}", encrypt);
|
|
|
log.info("开始推送");
|
|
|
- String post = HttpUtil.post(url, params);
|
|
|
- JSONObject jsonObject = JSON.parseObject(post);
|
|
|
+ try {
|
|
|
+ String post = HttpUtil.post(url, params);
|
|
|
+ JSONObject jsonObject = JSON.parseObject(post);
|
|
|
+ this.dataPushLog(num, title, jsonObject.getString("resultCode"), jsonObject.getString("resultMsg"), logId);
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("推送失败", e);
|
|
|
+ this.dataPushLog(num, title, String.valueOf(HttpStatus.HTTP_BAD_GATEWAY), "请求失败", logId);
|
|
|
+ }
|
|
|
|
|
|
- this.dataPushLog(num, title, jsonObject.getString("resultCode"), jsonObject.getString("resultMsg"));
|
|
|
|
|
|
}
|
|
|
|
|
@@ -295,40 +342,102 @@ public class TowerServiceImpl implements ITowerService {
|
|
|
// List<TowerSceneBean> towerSceneBeans = JSON.parseArray(sceneStr, TowerSceneBean.class);
|
|
|
// System.out.println(JSON.toJSONString(towerSceneBeans));
|
|
|
|
|
|
- String visionStr = FileUtil.readUtf8String("C:\\Users\\dsx\\Desktop\\vision.txt");
|
|
|
- JSONObject visionObj = JSON.parseObject(visionStr);
|
|
|
- JSONArray array = visionObj.getJSONArray("sweepLocations");
|
|
|
- Map<Integer, String> uuidMap = new HashMap<>();
|
|
|
- for(int i = 0; i < array.size(); i++){
|
|
|
- JSONObject o = (JSONObject)array.get(i);
|
|
|
- uuidMap.put(i, o.getString("uuid"));
|
|
|
+// String visionStr = FileUtil.readUtf8String("C:\\Users\\dsx\\Desktop\\vision.txt");
|
|
|
+// JSONObject visionObj = JSON.parseObject(visionStr);
|
|
|
+// JSONArray array = visionObj.getJSONArray("sweepLocations");
|
|
|
+// Map<Integer, String> uuidMap = new HashMap<>();
|
|
|
+// for(int i = 0; i < array.size(); i++){
|
|
|
+// JSONObject o = (JSONObject)array.get(i);
|
|
|
+// uuidMap.put(i, o.getString("uuid"));
|
|
|
+// }
|
|
|
+//
|
|
|
+// for(int i = 0; i < array.size(); i++){
|
|
|
+// JSONObject o = (JSONObject)array.get(i);
|
|
|
+// JSONArray visibles = o.getJSONArray("visibles");
|
|
|
+// int size = visibles.size();
|
|
|
+// String[] visibleArr = new String[size];
|
|
|
+// for(int j = 0; j < size; j++){
|
|
|
+// System.out.println(visibles.get(j));
|
|
|
+// int index = (Integer)visibles.get(j);
|
|
|
+// String uuid = uuidMap.get(index);
|
|
|
+// visibleArr[j] = uuid;
|
|
|
+// }
|
|
|
+// o.put("visibles", visibleArr);
|
|
|
+// }
|
|
|
+//
|
|
|
+// FileUtil.writeUtf8String(JSON.toJSONString(visionObj), "C:\\Users\\dsx\\Desktop\\vision2.txt");
|
|
|
+
|
|
|
+ String test = "123123/sdfsdf.jpg";
|
|
|
+ System.out.println(test.substring(test.lastIndexOf("/")));
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void dataPushLog(String num, String title, String resultCode, String resultMsg, String logId){
|
|
|
+ Map<String, Object> log = new HashMap<>();
|
|
|
+ log.put("num", num);
|
|
|
+ log.put("title", title);
|
|
|
+ log.put("resultCode", resultCode);
|
|
|
+ log.put("resultMsg", resultMsg);
|
|
|
+ String content = JSON.toJSONString(log).concat("\r\n");
|
|
|
+ FileUtil.appendUtf8String(content, parentPath.concat("download").concat("-").concat(logId).concat(".log"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultData sceneBatchMove(MultipartFile file, String origSnCode, String snCode) throws IOException {
|
|
|
+ if(file.isEmpty()){
|
|
|
+ throw new BusinessException(-1, "文件为空");
|
|
|
+ }
|
|
|
+ String origPath = "/home/backend/4dkankan_v4/modeling-extend/move/";
|
|
|
+ String move_url = "https://www.4dkankan.com/service/manage/scene/move";
|
|
|
+ String orgFileId = DateUtil.format(Calendar.getInstance().getTime(), DateExtUtil.dateStyle11);
|
|
|
+ String orgFilePath = origPath.concat(orgFileId).concat(".txt");
|
|
|
+ FileUtil.mkParentDirs(orgFilePath);
|
|
|
+ file.transferTo(new File(orgFilePath));
|
|
|
+
|
|
|
+ List<String> nums = FileUtil.readUtf8Lines(orgFilePath);
|
|
|
+ if(CollUtil.isEmpty(nums)){
|
|
|
+ throw new BusinessException(-1, "文件为空");
|
|
|
}
|
|
|
|
|
|
- for(int i = 0; i < array.size(); i++){
|
|
|
- JSONObject o = (JSONObject)array.get(i);
|
|
|
- JSONArray visibles = o.getJSONArray("visibles");
|
|
|
- int size = visibles.size();
|
|
|
- String[] visibleArr = new String[size];
|
|
|
- for(int j = 0; j < size; j++){
|
|
|
- System.out.println(visibles.get(j));
|
|
|
- int index = (Integer)visibles.get(j);
|
|
|
- String uuid = uuidMap.get(index);
|
|
|
- visibleArr[j] = uuid;
|
|
|
- }
|
|
|
- o.put("visibles", visibleArr);
|
|
|
+ Camera camera = cameraService.findByChildName(origSnCode);
|
|
|
+ if(Objects.isNull(camera)){
|
|
|
+ throw new BusinessException(ErrorCode.CAMERA_BIND_NO_EXIST);
|
|
|
}
|
|
|
|
|
|
- FileUtil.writeUtf8String(JSON.toJSONString(visionObj), "C:\\Users\\dsx\\Desktop\\vision2.txt");
|
|
|
+ List<String> notExists = new ArrayList<>();
|
|
|
+ for (String num : nums) {
|
|
|
+ ScenePlus byCameraIdAndNum = scenePlusService.getByCameraIdAndNum(num, camera.getId());
|
|
|
+ if(Objects.isNull(byCameraIdAndNum)){
|
|
|
+ notExists.add(num);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(CollUtil.isNotEmpty(notExists)){
|
|
|
+ throw new BusinessException(-1, "在原始相机下查询不到场景,请核查:".concat(JSON.toJSONString(notExists)));
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ //模拟登录
|
|
|
+ Map<String, Object> headers = new HashMap<>();
|
|
|
+ try {
|
|
|
+ String token = ssoService.login("zhongwentong", "4Dage168");
|
|
|
+ headers.put("token", token);
|
|
|
+ }catch (Exception e){
|
|
|
+ return ResultData.error(-1, "登录失败");
|
|
|
+ }
|
|
|
|
|
|
- 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);
|
|
|
+ List<Map<String, Object>> result = new ArrayList<>();
|
|
|
+ for (String num : nums) {
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("num", num);
|
|
|
+ param.put("snCode", snCode);
|
|
|
+ ResultData<Map<String, Object>> resultData = httpClient.post(move_url, headers, param);
|
|
|
+
|
|
|
+ Map<String, Object> item = new HashMap<>();
|
|
|
+ item.put("num", num);
|
|
|
+ item.put("code", resultData.getCode());
|
|
|
+ item.put("message", resultData.getMessage());
|
|
|
+ result.add(item);
|
|
|
}
|
|
|
- content = content.concat("\r\n");
|
|
|
- FileUtil.appendUtf8String(content, parentPath.concat("download.log"));
|
|
|
+ return ResultData.ok(result);
|
|
|
}
|
|
|
-
|
|
|
}
|