package com.fdkankan.openApi.service.www.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.ZipUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fdkankan.common.constant.*;
import com.fdkankan.common.exception.BusinessException;
import com.fdkankan.common.util.DateUtil;
import com.fdkankan.fyun.config.FYunFileConfig;
import com.fdkankan.fyun.face.FYunFileServiceInterface;
import com.fdkankan.model.constants.ConstantFilePath;
import com.fdkankan.model.constants.UploadFilePath;
import com.fdkankan.model.utils.ComputerUtil;
import com.fdkankan.model.utils.CreateObjUtil;
import com.fdkankan.openApi.bean.www.SceneJsonBean;
import com.fdkankan.openApi.common.PageInfo;
import com.fdkankan.openApi.entity.laser.SceneEntity;
import com.fdkankan.openApi.entity.www.*;
import com.fdkankan.openApi.mapper.www.IScenePlusMapper;
import com.fdkankan.openApi.service.laser.SceneService;
import com.fdkankan.openApi.service.www.*;
import com.fdkankan.openApi.vo.www.CreateFicTitiousSceneParamVO;
import com.fdkankan.openApi.vo.www.PageScenesParamVo;
import com.fdkankan.openApi.vo.www.SceneEditControlsVO;
import com.fdkankan.openApi.vo.www.SceneVO;
import com.fdkankan.redis.constant.RedisKey;
import com.fdkankan.redis.util.RedisUtil;
import com.fdkankan.web.response.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.io.File;
import java.util.*;
import java.util.stream.Collectors;
/**
*
* 场景主表 服务实现类
*
*
* @author
* @since 2023-02-15
*/
@DS("www")
@Service
public class ScenePlusServiceImpl extends ServiceImpl implements IScenePlusService {
@Value("${main.url}")
private String mainUrl;
@Value("${scene.pro.new.url}")
private String sceneUrl;
@Value("#{'${camType.laser:}'.split(',')}")
private List laserCamTypeList;
@Autowired
private FYunFileServiceInterface fYunFileService;
@Autowired
private ISceneEditInfoService sceneEditInfoService;
@Autowired
private IScenePlusExtService scenePlusExtService;
@Autowired
private ISceneEditInfoExtService sceneEditInfoExtService;
@Autowired
private ISceneEditControlsService sceneEditControlsService;
@Autowired
private RedisUtil redisUtil;
@Autowired
private ICameraService cameraService;
@Autowired
private ICameraDetailService cameraDetailService;
@Autowired
private FYunFileConfig fYunFileConfig;
@Autowired
private SceneService sceneService;
@Autowired
private ISceneCooperationService sceneCooperationService;
@Override
public ScenePlus getByNumAndUserId(long userId, String num) {
return this.getOne(new LambdaQueryWrapper().eq(ScenePlus::getNum, num).eq(ScenePlus::getUserId, userId));
}
@Override
public ScenePlus getByNum(String num) {
return this.getOne(new LambdaQueryWrapper().eq(ScenePlus::getNum, num));
}
@Override
public ResultData createVirtualScene(CreateFicTitiousSceneParamVO param) throws Exception {
this.checkParams4createVirtualScene(param);
this.buildScene4CreateVirtualScene(param);
String website = this.updateScene4CreateVirtualScene(param);
return ResultData.ok(website);
}
@Override
public ResultData createVirtualSceneV2(CreateFicTitiousSceneParamVO param) throws Exception {
this.checkParams4createVirtualScene(param);
this.buildScene4CreateVirtualScene(param);
this.cutPanorama4CreateVirtualScene(param);
String website = this.updateScene4CreateVirtualScene(param);
return ResultData.ok(website);
}
private void cutPanorama4CreateVirtualScene(CreateFicTitiousSceneParamVO param) throws Exception {
if(!param.getSceneKind().equals(SceneKind.TILES.code())){
return;
}
String num = param.getNum();
//检测原始图片是否存在
String ossImagePath = String.format(UploadFilePath.IMG_VIEW_PATH, num);
String ossCaptruePath = ossImagePath.concat("capture/");
List captrueList = fYunFileService.listRemoteFiles(ossCaptruePath);
if(CollUtil.isEmpty(captrueList)){
throw new BusinessException(ErrorCode.FAILURE_CODE_3018.code(), "全景图不能为空");
}
String target = String.format(ConstantFilePath.SCENE_IMAGES_PATH_V4, num);
String targetImagesPath = target + "extras/images/";
FileUtil.del(targetImagesPath);
String ossVisionTxtPath = ossImagePath + "vision.txt";
fYunFileService.downloadFile(ossVisionTxtPath, target + "extras" + File.separator + "vision.txt");
//下载全景图
fYunFileService.downloadFileByCommand(targetImagesPath, ossCaptruePath);
JSONObject dataJson = new JSONObject();
dataJson.put("split_type", "SPLIT_V8");
JSONObject jsonObject = new JSONObject();
jsonObject.put("has_vision_txt",true);
jsonObject.put("has_source_images",true);
dataJson.put("extras", jsonObject);
//V5表示不需要生成high,low文件
String skyboxType = "SKYBOX_V6";
SceneResolution sceneResolution = SceneResolution.get(param.getSceneResolution());
switch (sceneResolution){
case one_k:
skyboxType = "SKYBOX_V9";
break;
case two_K:
skyboxType = "SKYBOX_V7";
break;
case four_K:
skyboxType = "SKYBOX_V6";
}
dataJson.put("skybox_type", skyboxType);
FileUtil.writeUtf8String(dataJson.toJSONString(), target + File.separator+"data.json");
//调用算法切图
CreateObjUtil.build3dModel(target , "1");
String uploadJsonPath= target + File.separator + "results" +File.separator+"upload.json";
Thread.sleep(2000);
boolean exist = ComputerUtil.checkComputeCompleted(uploadJsonPath, 5, 200);
if(!exist){
throw new BusinessException(ErrorCode.FAILURE_CODE_7013);
}
String uploadData = FileUtil.readUtf8String(uploadJsonPath);
JSONObject uploadJson = null;
JSONArray array = null;
if(uploadData!=null) {
uploadJson = JSONObject.parseObject(uploadData);
array = uploadJson.getJSONArray("upload");
}
if(array == null){
throw new BusinessException(ErrorCode.FAILURE_CODE_7013);
}
Map map = new HashMap<>();
JSONObject fileJson = null;
String fileName = "";
for(int i = 0, len = array.size(); i < len; i++) {
fileJson = array.getJSONObject(i);
fileName = fileJson.getString("file");
//文件不存在抛出异常
if (!new File(target + File.separator + "results" + File.separator + fileName)
.exists()) {
throw new Exception(
target + File.separator + "results" + File.separator + fileName + "文件不存在");
}
//high文件夹
if (fileJson.getIntValue("clazz") == 3) {
map.put(target + File.separator + "results" + File.separator + fileName,
ossImagePath + "pan/high/" + fileName.replace("high/", ""));
continue;
}
//low文件夹
if (fileJson.getIntValue("clazz") == 4) {
map.put(target + File.separator + "results" + File.separator + fileName,
ossImagePath + "pan/low/" + fileName.replace("low/", ""));
continue;
}
//tiles文件夹,亚马逊没有裁剪图片api,不需要上传4k图
if (fileJson.getIntValue("clazz") == 5) {
map.put(target + File.separator + "results" + File.separator + fileName,
ossImagePath + fileName);
continue;
}
//tiles文件夹,亚马逊瓦片图
if (fileJson.getIntValue("clazz") == 7) {
map.put(target + File.separator + "results" + File.separator + fileName,
ossImagePath + fileName);
continue;
}
}
if(map.size()>0) {
fYunFileService.uploadMulFiles(map);
}
}
private void checkParams4createVirtualScene(CreateFicTitiousSceneParamVO param){
SceneFrom sceneFrom = SceneFrom.get(param.getSceneFrom());
if(Objects.isNull(sceneFrom)){
throw new BusinessException(ErrorCode.PARAM_ERROR.code(), "sceneFrom错误");
}
Integer sceneSource = null;
switch (sceneFrom){
case SXZ:
sceneSource = SceneSource.YJHZ.code();
break;
}
if(Objects.isNull(sceneSource)){
throw new BusinessException(ErrorCode.PARAM_ERROR.code(), "sceneFrom错误");
}
param.setSceneSource(sceneSource);
}
private void buildScene4CreateVirtualScene(CreateFicTitiousSceneParamVO param) throws Exception {
String num = param.getNum();
String objName = param.getObjName();
String mtlName = param.getMtlName();
String localImagePath = String.format(ConstantFilePath.SCENE_IMAGES_PATH_V4, num);
String ossImagePath = String.format(UploadFilePath.IMG_VIEW_PATH, num);
String ossObjPath = ossImagePath + objName;
if(!fYunFileService.fileExist(ossObjPath)){
throw new BusinessException(ErrorCode.FAILURE_CODE_4001, objName);
}
String ossMtlPath = ossImagePath + mtlName;
if(!fYunFileService.fileExist(ossMtlPath)){
throw new BusinessException(ErrorCode.FAILURE_CODE_4001, mtlName);
}
String ossTexturePath = ossImagePath + "dacf7dfa24ae47fab8fcebfe4dc41ab9_50k_texture_jpg_high1/";
// if(CollUtil.isEmpty(fYunFileService.listRemoteFiles(ossTexturePath))){
// throw new BusinessException(ErrorCode.FAILURE_CODE_4001, "贴图");
// }
String ossVisionTxtPath = ossImagePath + "vision.txt";
if(!fYunFileService.fileExist(ossVisionTxtPath)){
throw new BusinessException(ErrorCode.FAILURE_CODE_4001, "vision.txt");
}
FileUtil.del(localImagePath + "/result/");
FileUtil.del(localImagePath + "extras/");
fYunFileService.downloadFile(ossObjPath, localImagePath + "extras/" + "mesh.obj");
fYunFileService.downloadFile(ossMtlPath, localImagePath + "extras/" + mtlName);
fYunFileService.downloadFileByCommand(localImagePath + "extras/", ossTexturePath);
fYunFileService.downloadFile(ossVisionTxtPath, localImagePath + "vision.txt");
//创建data.json
JSONObject dataJson = new JSONObject();
dataJson.put("obj2txt", true);
dataJson.put("split_type", "SPLIT_V6");
dataJson.put("data_describe", "double spherical");
dataJson.put("skybox_type", "SKYBOX_V5");
FileUtil.writeUtf8String(dataJson.toJSONString(), localImagePath + "data.json");
//调用objToTxt算法
CreateObjUtil.build3dModel(localImagePath, "");
Thread.sleep(2000);
String uploadJsonPath = localImagePath + "results/upload.json";
boolean exist = ComputerUtil.checkComputeCompleted(uploadJsonPath, 3, 3000);
if(!exist){
throw new BusinessException(ErrorCode.FAILURE_CODE_5042);
}
String uploadData = FileUtil.readUtf8String(uploadJsonPath);
JSONObject uploadJson = null;
JSONArray array = null;
if(uploadData!=null) {
uploadJson = JSONObject.parseObject(uploadData);
array = uploadJson.getJSONArray("upload");
}
if(array == null){
log.error("upload.json数据出错");
throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
}
Map map = new HashMap();
JSONObject fileJson = null;
String fileName = "";
for(int i = 0, len = array.size(); i < len; i++) {
fileJson = array.getJSONObject(i);
fileName = fileJson.getString("file");
String filePath = localImagePath + "results/" + fileName;
//文件不存在抛出异常
if(!FileUtil.exist(filePath)){
throw new BusinessException(ErrorCode.FAILURE_CODE_4002, filePath);
}
//tex文件夹
if (fileJson.getIntValue("clazz") == 15) {
map.put(filePath, ossImagePath + "dacf7dfa24ae47fab8fcebfe4dc41ab9_50k_texture_jpg_high1/" + fileName.replace("tex/", ""));
continue;
}
}
CreateObjUtil.convertTxtToDam(localImagePath + "results/" + "modeldata.txt", localImagePath + "results/" + "dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam");
// CreateObjUtil.convertDamToLzma(imagesBuffer.toString() + File.separator + "results" +File.separator+ "dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam");
// CreateObjUtil.convertTxtToDam(imagesBuffer.toString() + File.separator + "results" +File.separator+"modeldata.txt", imagesBuffer.toString() + File.separator + "results" + File.separator+ "dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam");
// map.put(imagesBuffer.toString() + File.separator + "results" +File.separator+"dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam.lzma", "images/images"+param.getNum()+"/"+"dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam.lzma");
map.put(localImagePath + "results/" + "dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam", ossImagePath + "dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam");
FileUtil.del(localImagePath + "vision.modeldata");
CreateObjUtil.convertTxtToVisionmodeldata(localImagePath + "vision.txt", localImagePath + "vision.modeldata");
map.put(localImagePath + "vision.modeldata", ossImagePath + "vision.modeldata");
fYunFileService.uploadMulFiles(map);
}
private String updateScene4CreateVirtualScene(CreateFicTitiousSceneParamVO param){
ScenePlus scenePlus = this.getByNum(param.getNum());
ScenePlusExt scenePlusExt = null;
SceneEditInfo sceneEditInfo = null;
SceneEditInfoExt sceneEditInfoExt = null;
SceneEditControls sceneEditControls = null;
if(Objects.nonNull(scenePlus)){
scenePlusExt = scenePlusExtService.getByPlusId(scenePlus.getId());
sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfo.getId());
sceneEditControls = sceneEditControlsService.getByEditInfoId(sceneEditInfo.getId());
}else {
scenePlus = new ScenePlus();
scenePlusExt = new ScenePlusExt();
sceneEditInfo = new SceneEditInfo();
sceneEditInfoExt = new SceneEditInfoExt();
sceneEditControls = new SceneEditControls();
}
scenePlus.setNum(param.getNum());
scenePlus.setUserId(param.getUserId());
scenePlus.setTitle("四维看看");
scenePlus.setDescription("四维看看 让空间讲故事
");
scenePlus.setSceneStatus(SceneStatus.SUCCESS.code());
scenePlus.setPayStatus(PayStatus.PAY.code());
scenePlus.setSceneSource(param.getSceneSource());
this.saveOrUpdate(scenePlus);
scenePlus = this.getByNum(param.getNum());
scenePlusExt.setPlusId(scenePlus.getId());
scenePlusExt.setWebSite(mainUrl + "/" + sceneUrl + param.getNum());
scenePlusExt.setBuildType("V3");
scenePlusExt.setSceneResolution(param.getSceneResolution());
scenePlusExt.setSceneFrom(param.getSceneFrom());
scenePlusExt.setSceneKind(param.getSceneKind());
scenePlusExt.setModelKind(ModelKind.DAM.code());
scenePlusExtService.saveOrUpdate(scenePlusExt);
scenePlusExt = scenePlusExtService.getByPlusId(scenePlus.getId());
sceneEditInfo.setScenePlusId(scenePlus.getId());
sceneEditInfo.setVersion(Objects.isNull(sceneEditInfo.getVersion()) ? 0 : sceneEditInfo.getVersion() + 1);
sceneEditInfo.setImgVersion(Objects.isNull(sceneEditInfo.getImgVersion()) ? 0 : sceneEditInfo.getImgVersion() + 1);
sceneEditInfo.setTitle(scenePlus.getTitle());
sceneEditInfo.setDescription(scenePlus.getDescription());
sceneEditInfoService.saveOrUpdate(sceneEditInfo);
sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
sceneEditInfoExt.setEditInfoId(sceneEditInfo.getId());
sceneEditInfoExt.setScenePlusId(scenePlus.getId());
sceneEditInfoExtService.saveOrUpdate(sceneEditInfoExt);
sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfo.getId());
sceneEditControls.setEditInfoId(sceneEditInfo.getId());
sceneEditControlsService.saveOrUpdate(sceneEditControls);
sceneEditControls = sceneEditControlsService.getByEditInfoId(sceneEditInfo.getId());
SceneJsonBean sceneJson = new SceneJsonBean();
BeanUtil.copyProperties(sceneEditInfoExt, sceneJson);
BeanUtil.copyProperties(sceneEditInfo, sceneJson);
SceneEditControlsVO sceneEditControlsVO = BeanUtil.copyProperties(sceneEditControls, SceneEditControlsVO.class);
sceneJson.setControls(sceneEditControlsVO);
sceneJson.setNum(param.getNum());
sceneJson.setCreateTime(scenePlus.getCreateTime());
sceneJson.setSceneResolution(scenePlusExt.getSceneResolution());
sceneJson.setVersion(sceneEditInfo.getVersion());
sceneJson.setImgVersion(sceneEditInfo.getImgVersion());
sceneJson.setSceneFrom(scenePlusExt.getSceneFrom());
sceneJson.setSceneKind(scenePlusExt.getSceneKind());
sceneJson.setModelKind(scenePlusExt.getModelKind());
sceneJson.setPayStatus(scenePlus.getPayStatus());
String sceneJsonStr = JSON.toJSONString(sceneJson);
//上传sceneJson文件
fYunFileService.uploadFile(sceneJsonStr.getBytes(), String.format(UploadFilePath.DATA_VIEW_PATH, param.getNum()) + "scene.json");
//scenejson写入缓存
redisUtil.set(String.format(RedisKey.SCENE_JSON, param.getNum()), sceneJsonStr);
return scenePlusExt.getWebSite();
}
@Override
public PageInfo getScenesByUserId(Long userId, PageScenesParamVo param) {
param.setUserId(userId);
//查询协作场景列表
List cooperationNumList = sceneCooperationService.getNumByUserIds(Arrays.asList(userId));
param.setCooperationNumList(cooperationNumList);
if (!ObjectUtils.isEmpty(param.getCameraType())) {
switch (param.getCameraType()){
case "mega":
param.setSceneSourceIn(Arrays.asList(SceneSource.JG.code(), SceneSource.SG.code()));
break;
case "kankan":
param.setSceneSourceNotIn(Arrays.asList(SceneSource.JG.code(), SceneSource.SG.code()));
break;
}
}
Page scenePage = this.baseMapper.pageList(new Page<>(param.getPageNum(), param.getPageSize()), param);
if(CollUtil.isEmpty(scenePage.getRecords())){
return PageInfo.PageInfo(scenePage);
}
List plusIdList = new ArrayList<>();
List megaSceneNumList = new ArrayList<>();
Set cameraIds = new HashSet<>();
scenePage.getRecords().stream().forEach(plus -> {
plusIdList.add(plus.getId());
if(plus.getSceneSource() == SceneSource.JG.code()){
megaSceneNumList.add(plus.getNum());
}
if(Objects.nonNull(plus.getCameraId())){
cameraIds.add(plus.getCameraId());
}
});
Map cameraMap = new HashMap<>();
Map cameraTypeMap = new HashMap<>();
if(CollUtil.isNotEmpty(cameraIds)){
cameraMap = cameraService
.list(new LambdaQueryWrapper().in(Camera::getId, cameraIds))
.stream().collect(Collectors.toMap(Camera::getId, Camera::getSnCode));
List cameraDetails = cameraDetailService.listByCameraIds(cameraIds);
if(CollUtil.isNotEmpty(cameraDetails)){
cameraDetails.stream().forEach(detail->{
int cameraType = detail.getType();
CameraTypeEnum cameraTypeEnum = CameraTypeEnum.get(cameraType);
cameraTypeMap.put(detail.getCameraId(), cameraTypeEnum.getCameraName());
});
}
}
List scenePlusExtList = scenePlusExtService.list(new LambdaQueryWrapper().in(ScenePlusExt::getPlusId, plusIdList));
Map plusExtMap = new HashMap<>();
scenePlusExtList.stream().forEach(ext->plusExtMap.put(ext.getPlusId(), ext));
List megaSceneList = null;
Map megaSceneMap = new HashMap<>();
if(CollUtil.isNotEmpty(megaSceneNumList)){
megaSceneList = sceneService.list(new LambdaQueryWrapper().in(SceneEntity::getSceneCode, megaSceneNumList));
if(CollUtil.isNotEmpty(megaSceneList)){
megaSceneList.stream().forEach(scene -> megaSceneMap.put(scene.getSceneCode(), scene));
}
}
Map finalCameraMap = cameraMap;
List sceneVos = scenePage.getRecords().stream().map(scenePlus -> {
SceneVO vo = new SceneVO();
vo.setSceneCode(scenePlus.getNum());
vo.setSceneName(scenePlus.getTitle());
vo.setCreateTime(DateUtil.date2String(scenePlus.getCreateTime(), null));
ScenePlusExt plusExt = plusExtMap.get(scenePlus.getId());
if(Objects.nonNull(plusExt)){
vo.setShootCount(plusExt.getShootCount());
}
vo.setSnCode(finalCameraMap.get(scenePlus.getCameraId()));
vo.setCameraType(cameraTypeMap.get(scenePlus.getCameraId()));
if (scenePlus.getSceneSource() == 4) {
SceneEntity scene = megaSceneMap.get(scenePlus.getNum());
if (Objects.nonNull(scene) && StrUtil.isNotEmpty(scene.getTitle())) {
vo.setSceneName(scene.getTitle());
}
}
return vo;
}).collect(Collectors.toList());
return PageInfo.PageInfo(scenePage.getCurrent(), scenePage.getSize(), scenePage.getTotal(), sceneVos);
}
@Override
public Object getPointInfo(String sceneCode) {
// 获取vision.txt 文件内容返回
String content = fYunFileService.getFileContent(String.format(UploadFilePath.IMG_VIEW_PATH, sceneCode).concat("vision.txt"));
JSONObject jsonObject = JSONObject.parseObject(content);
return jsonObject.get("sweepLocations");
}
@Override
public List getSceneObjFilePaths(String sceneCode) {
List objFiles = fYunFileService.listRemoteFiles(String.format(UploadFilePath.DATA_VIEW_PATH, sceneCode).concat("mesh"))
.stream().map(file -> fYunFileConfig.getHost() + file).collect(Collectors.toList());
return objFiles;
}
@Override
public List getScenePanoramicImageFiles(String sceneCode) {
// 根据vision.txt 获取全景图文件
String content = fYunFileService.getFileContent(String.format(UploadFilePath.IMG_VIEW_PATH, sceneCode).concat("vision.txt"));
JSONObject jsonObject = JSONObject.parseObject(content);
return jsonObject.getJSONArray("sweepLocations").stream()
.map(json -> String.format(fYunFileConfig.getHost()
+ UploadFilePath.scene_result_data_path, sceneCode).concat("caches/images/")
+ ((JSONObject) json).getString("uuid").concat(".jpg")).collect(Collectors.toList());
}
@Override
public ResultData getSceneViewUserFile(String sceneCode, Long userId) {
ScenePlus scenePlus = this.getByNumAndUserId(userId, sceneCode);
if (Objects.isNull(scenePlus)) {
scenePlus = sceneCooperationService.getCooperaSceneByUserIdAndNum(userId, sceneCode);
if(Objects.isNull(scenePlus)){
throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
}
}
if(Objects.isNull(scenePlus.getCameraId())){
throw new BusinessException(ErrorCode.FAILURE_CODE_7010);
}
CameraDetail cameraDetail = cameraDetailService.getByCameraId(scenePlus.getCameraId());
Integer cameraType = cameraDetail.getType();
if(laserCamTypeList.contains(cameraType)){
throw new BusinessException(ErrorCode.FAILURE_CODE_4004);
}
String userOssPath = String.format(UploadFilePath.USER_VIEW_PATH, scenePlus.getNum());
List userFileList = fYunFileService.listRemoteFiles(userOssPath);
if(CollUtil.isEmpty(userFileList)){
throw new BusinessException(ErrorCode.FAILURE_CODE_5027);
}
String userDowbloadPath = String.format(ConstantFilePath.OPENAPI_DOWNLOAD_PATH, scenePlus.getNum());
String userLocalPath = userDowbloadPath.concat("user");
String zipName = scenePlus.getNum().concat("_user.zip");
String usesZipPath = userDowbloadPath.concat(zipName);
fYunFileService.downloadFileByCommand(userLocalPath, userOssPath);
ZipUtil.zip(userLocalPath, usesZipPath);
String usesZipOssPath = String.format("downloads/scene/%s/user/", scenePlus.getNum()).concat(zipName);
fYunFileService.uploadFileByCommand(usesZipPath, usesZipOssPath);
return ResultData.ok(fYunFileConfig.getHost().concat(usesZipOssPath));
}
@Override
public ResultData getSceneVideo(String sceneCode, Long userId) {
ScenePlus scenePlus = this.getByNumAndUserId(userId, sceneCode);
if (Objects.isNull(scenePlus)) {
scenePlus = sceneCooperationService.getCooperaSceneByUserIdAndNum(userId, sceneCode);
if(Objects.isNull(scenePlus)){
throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
}
}
if(Objects.isNull(scenePlus.getCameraId())){
throw new BusinessException(ErrorCode.FAILURE_CODE_7010);
}
CameraDetail cameraDetail = cameraDetailService.getByCameraId(scenePlus.getCameraId());
Integer cameraType = cameraDetail.getType();
if(laserCamTypeList.contains(cameraType)){
throw new BusinessException(ErrorCode.FAILURE_CODE_4004);
}
String userOssPath = String.format(UploadFilePath.VIDEOS_VIEW_PATH, scenePlus.getNum());
List userFileList = fYunFileService.listRemoteFiles(userOssPath);
if(CollUtil.isEmpty(userFileList)){
throw new BusinessException(ErrorCode.FAILURE_CODE_5027);
}
String userDowbloadPath = String.format(ConstantFilePath.OPENAPI_DOWNLOAD_PATH, scenePlus.getNum());
String userLocalPath = userDowbloadPath.concat("video/");
String zipName = scenePlus.getNum().concat("_video.zip");
String usesZipPath = userDowbloadPath.concat(zipName);
fYunFileService.downloadFileByCommand(userLocalPath, userOssPath);
String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, sceneCode);
if(fYunFileService.fileExist(dataViewPath.concat("Up.xml"))){
fYunFileService.downloadFile(dataViewPath.concat("Up.xml"), userLocalPath.concat("Up.xml"));
}
if(fYunFileService.fileExist(dataViewPath.concat("Up2.xml"))){
fYunFileService.downloadFile(dataViewPath.concat("Up2.xml"), userLocalPath.concat("Up2.xml"));
}
if(fYunFileService.fileExist(dataViewPath.concat("Up.txt"))){
fYunFileService.downloadFile(dataViewPath.concat("Up.txt"), userLocalPath.concat("Up.txt"));
}
if(fYunFileService.fileExist(dataViewPath.concat("Up2.txt"))){
fYunFileService.downloadFile(dataViewPath.concat("Up2.txt"), userLocalPath.concat("Up2.txt"));
}
String sceneJson = redisUtil.get(String.format(RedisKey.SCENE_JSON, sceneCode));
if(StrUtil.isEmpty(sceneJson)){
sceneJson = fYunFileService.getFileContent(dataViewPath.concat("scene.json"));
}
SceneJsonBean sceneJsonBean = JSON.parseObject(sceneJson, SceneJsonBean.class);
if(StrUtil.isEmpty(sceneJsonBean.getVideos())){
sceneJsonBean.setVideos("{}");
}
FileUtil.writeUtf8String(sceneJsonBean.getVideos(), userLocalPath.concat("mapping.json"));
ZipUtil.zip(userLocalPath, usesZipPath);
String usesZipOssPath = String.format("downloads/scene/%s/video/", scenePlus.getNum()).concat(zipName);
fYunFileService.uploadFileByCommand(usesZipPath, usesZipOssPath);
FileUtil.del(userLocalPath);
FileUtil.del(usesZipPath);
return ResultData.ok(fYunFileConfig.getHost().concat(usesZipOssPath));
}
}