package com.fdkankan.scene.service.impl;
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.alibaba.fastjson.serializer.SerializerFeature;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fdkankan.common.util.FileMd5Util;
import com.fdkankan.image.MatrixToImageWriterUtil;
import com.fdkankan.model.constants.ConstantFileName;
import com.fdkankan.model.constants.ConstantFilePath;
import com.fdkankan.common.constant.ConstantUrl;
import com.fdkankan.common.constant.ErrorCode;
import com.fdkankan.common.constant.RecStatus;
import com.fdkankan.common.exception.BusinessException;
import com.fdkankan.model.utils.ComputerUtil;
import com.fdkankan.model.utils.SceneUtil;
import com.fdkankan.scene.bean.RequestScene;
import com.fdkankan.scene.entity.SceneDataDownload;
import com.fdkankan.scene.service.ISceneDataDownloadService;
import com.fdkankan.web.response.Result;
import com.fdkankan.web.response.ResultData;
import com.fdkankan.model.utils.ConvertUtils;
import com.fdkankan.model.utils.CreateObjUtil;
import com.fdkankan.common.util.FileUtils;
import com.fdkankan.common.util.OkHttpUtils;
import com.fdkankan.fyun.constant.FYunTypeEnum;
import com.fdkankan.fyun.face.FYunFileServiceInterface;
import com.fdkankan.redis.constant.RedisKey;
import com.fdkankan.redis.util.RedisUtil;
import com.fdkankan.scene.annotation.SystemServiceLog;
import com.fdkankan.scene.bean.RequestSceneEdit;
import com.fdkankan.scene.bean.RequestSceneProV4;
import com.fdkankan.scene.bean.ResponseScene;
import com.fdkankan.scene.entity.SceneCooperation;
import com.fdkankan.scene.entity.ScenePro;
import com.fdkankan.scene.entity.SceneProEdit;
import com.fdkankan.scene.entity.SceneResource;
import com.fdkankan.scene.entity.SceneResourceCooperation;
import com.fdkankan.scene.mapper.ISceneProMapper;
import com.fdkankan.scene.service.ISceneCooperationService;
import com.fdkankan.scene.service.ISceneProEditService;
import com.fdkankan.scene.service.ISceneProService;
import com.fdkankan.scene.service.ISceneResourceCooperationService;
import com.fdkankan.scene.service.ISceneResourceService;
import com.fdkankan.scene.service.ISceneService;
import com.google.common.collect.Lists;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import net.coobird.thumbnailator.Thumbnails;
import org.joda.time.DateTime;
import org.springframework.beans.BeanUtils;
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 org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
/**
*
* pro场景表 服务实现类
*
*
* @author
* @since 2022-07-04
*/
@Slf4j
@Service
public class SceneProServiceImpl extends ServiceImpl implements ISceneProService {
@Autowired
private ISceneCooperationService sceneCooperationService;
@Autowired
private RedisUtil redisUtil;
@Autowired
private ISceneResourceCooperationService sceneResourceCooperationService;
@Autowired
private ISceneResourceService sceneResourceService;
@Autowired
private ISceneProEditService sceneProEditService;
@Autowired
private FYunFileServiceInterface fYunFileService;
@Autowired
private ISceneService sceneService;
@Autowired
private ISceneDataDownloadService sceneDataDownloadService;
@Value("${main.url}")
private String mainUrl;
@Value("${scene.pro.url}")
private String sceneProUrl;
@Value("${scene.pro.v3.url}")
private String sceneProNewUrl;
@Value("${hot.domain.list}")
private String hotDomainList;
@Value("${hot.delete}")
private String hotDelete;
@Value("${fyun.host}")
private String ossPrefixUrl;
@Value("fyun.type")
private String ossType;
@Value("${ecs.checkFile.maxTimes:5}")
private int maxCheckTimes;
@Value("${ecs.checkFile.waitTime:5000}")
private int waitTime;
@Value("${fyun.host}")
private String fyunHost;
@Override
public ResultData upgradeToV4ResultSync(RequestSceneProV4 param) throws Exception {
ScenePro scenePro = this.getById(param.getId());
scenePro.setWebSite(param.getWebSite());
scenePro.setIsUpgrade(1);
this.updateById(scenePro);
String num = scenePro.getNum();
//如果场景有协作者,默认勾选上v4所有菜单
SceneCooperation SceneCooperation = sceneCooperationService.getByNum(num);
if(Objects.nonNull(SceneCooperation)){
redisUtil.hset(RedisKey.SCENE_COOPERATION_NUM_USERID, num, SceneCooperation.getUserId() + "");
//判断是否已经有了v4的菜单,如果已经有了,证明已经迁移过,不需要再初始化菜单资源
List sceneResourceCooperationList = sceneResourceCooperationService.list(
new LambdaQueryWrapper()
.eq(SceneResourceCooperation::getSceneCooperationId, SceneCooperation.getId()));
if(CollUtil.isNotEmpty(sceneResourceCooperationList)){
List sceneSourceList = sceneResourceCooperationList.stream()
.map(item -> item.getSceneResourceId()).collect(Collectors.toList());
List sceneResourceList
= sceneResourceService.list(
new LambdaQueryWrapper()
.eq(SceneResource::getVersion, "v4")
.in(SceneResource::getId, sceneSourceList));
if(CollUtil.isEmpty(sceneResourceList)){//如果查出来的这个场景的v4资源是空的,证明是第一次升级,需要初始化菜单资源
sceneResourceList = sceneResourceService.list(
new LambdaQueryWrapper()
.eq(SceneResource::getVersion, "v4"));// 查出所有的v4菜单,给这个场景的协作者初始化所有v4菜单资源
if(CollUtil.isNotEmpty(sceneResourceList)){
List list = Lists.newArrayList();
SceneResourceCooperation sceneResourceCooperation = null;
for (SceneResource sceneResource : sceneResourceList) {
sceneResourceCooperation = new SceneResourceCooperation();
sceneResourceCooperation.setSceneResourceId(sceneResource.getId());
sceneResourceCooperation.setSceneCooperationId(SceneCooperation.getId());
sceneResourceCooperation.setCreateTime(new Date());
sceneResourceCooperation.setUpdateTime(new Date());
sceneResourceCooperation.setRecStatus(RecStatus.VALID.code());
list.add(sceneResourceCooperation);
}
sceneResourceCooperationService.saveBatch(list);
}
}
}
}
return ResultData.ok();
}
@Override
public ScenePro findBySceneNum(String num) {
return this.getOne(new LambdaQueryWrapper().eq(ScenePro::getNum, num));
}
@Override
public ResultData uploadLogoBottomStatus(String sceneNum, String status) throws Exception {
ScenePro sceneProEntity = this.findBySceneNum(sceneNum);
if(sceneProEntity == null){
throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
}
SceneProEdit sceneProEditEntity = sceneProEditService.findBySceneProId(sceneProEntity.getId());
if(sceneProEditEntity == null){
throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
}
StringBuffer dataBuf = new StringBuffer()
.append("data").append(File.separator)
.append("data").append(sceneProEntity.getNum())
.append(File.separator);
StringBuffer imagesBuf = new StringBuffer()
.append("images").append(File.separator)
.append("images").append(sceneProEntity.getNum())
.append(File.separator);
StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
JSONObject scenejson = new JSONObject();
if(strsceneInfos!=null) {
scenejson = JSONObject.parseObject(strsceneInfos);
}
scenejson.put("showLogoBottom", Integer.valueOf(status));
scenejson.put("version", scenejson.getIntValue("version") + 1);
FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
sceneProEditEntity.setVersion(scenejson.getIntValue("version") + 1);
sceneProEditEntity.setShowLogoBottom(Integer.valueOf(status));
sceneProEditService.updateById(sceneProEditEntity);
return ResultData.ok();
}
@Override
public ResultData downloadTexData(String sceneNum) throws Exception {
ScenePro sceneProEntity = this.findBySceneNum(sceneNum);
if(sceneProEntity == null){
throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
}
if(!new File(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum).exists()){
new File(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum).mkdirs();
}
//上传过的资源
StringBuffer dataBuf = new StringBuffer()
.append("data").append(File.separator)
.append("data").append(sceneProEntity.getNum())
.append(File.separator);
StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
JSONObject scenejson = new JSONObject();
if(strsceneInfos!=null) {
scenejson = JSONObject.parseObject(strsceneInfos);
}
String newData = sceneProEntity.getDataSource() + "_obj2txt/extras";
String newResultData = sceneProEntity.getDataSource() + "_obj2txt/results/upload.json";
if(scenejson.containsKey("isUploadObj") && new File(newData).exists() && new File(newResultData).exists()){
FileUtils.zipFile(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/" + sceneNum + ".zip", newData);
return ResultData.ok(mainUrl + "/scene/images/images" + sceneNum + "/" + sceneNum + ".zip?t=" +System.currentTimeMillis());
}
String buildType = sceneProEntity.getBuildType();
if("V3".equals(buildType)){
//V3版本去oss下载2048模型
String meshPath = ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + "/mesh";
FileUtils.deleteDirectory(meshPath);
fYunFileService.downloadFileByCommand(meshPath, "data/data" + sceneNum + "/mesh");
if(new File(meshPath.concat("/mesh")).listFiles().length > 0){
for(File file : new File(meshPath.concat("/mesh")).listFiles()){
if(file.getName().endsWith(".obj") && !"output.house.obj".equals(file.getName()) &&
!"mesh.obj".equals(file.getName())){
file.delete();
}
if(file.getName().endsWith(".mtl") && !"output.house.mtl".equals(file.getName()) &&
!"mesh.mtl".equals(file.getName())){
file.delete();
}
}
FileUtils.zipFile(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/" + sceneNum + ".zip", meshPath);
return ResultData.ok(mainUrl + "/scene/images/images" + sceneNum + "/" + sceneNum + ".zip?t=" +System.currentTimeMillis());
}
}
//V2版本在本地获取模型资源
//修改过的资源
String editData = sceneProEntity.getDataSource() + "_edit/caches/tex";
String resultData = sceneProEntity.getDataSource() + "_edit/results";
if (new File(editData).exists() && new File(resultData).exists()){
for(File file : new File(editData).listFiles()){
if(file.getName().endsWith(".obj") && !"output.house.obj".equals(file.getName()) &&
!"mesh.obj".equals(file.getName())){
file.delete();
}
if(file.getName().endsWith(".mtl") && !"output.house.mtl".equals(file.getName()) &&
!"mesh.mtl".equals(file.getName())){
file.delete();
}
}
FileUtils.zipFile(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/" + sceneNum + ".zip", editData);
return ResultData.ok(mainUrl + "/scene/images/images" + sceneNum + "/" + sceneNum + ".zip?t=" +System.currentTimeMillis());
}
//没上传过返回源资源
String dataPath = sceneProEntity.getDataSource() + "/caches/tex";
File dataFile = new File(dataPath);
if(!dataFile.exists()){
throw new BusinessException(ErrorCode.FAILURE_CODE_3018);
}
for(File file : dataFile.listFiles()){
if(file.getName().endsWith(".obj") && !"output.house.obj".equals(file.getName()) &&
!"mesh.obj".equals(file.getName())){
file.delete();
}
if(file.getName().endsWith(".mtl") && !"output.house.mtl".equals(file.getName()) &&
!"mesh.mtl".equals(file.getName())){
file.delete();
}
}
FileUtils.zipFile(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/" + sceneNum + ".zip", dataPath);
return ResultData.ok(mainUrl + "/scene/images/images" + sceneNum + "/" + sceneNum + ".zip?t=" +System.currentTimeMillis());
}
@Override
public ResultData uploadPic(String sceneNum, String folderName, MultipartFile file, String toOss) throws Exception{
ScenePro sceneProEntity = this.findBySceneNum(sceneNum);
if(sceneProEntity == null){
throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
}
if (file.isEmpty() && file.getSize() <= 0) {
throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
}
//文件上传的位置可以自定义
String path = ConstantFilePath.SCENE_PATH+"images"+File.separator+"images"+sceneNum;
if(StrUtil.isNotEmpty(folderName)) {
path = path + File.separator + folderName;
}
File targetFile = new File(path);
if (!targetFile.exists()) {
targetFile.mkdirs();
}
String fileName = file.getOriginalFilename();
targetFile = new File(path + File.separator + fileName);
// 保存
synchronized(this)
{
if(targetFile.exists())
{
FileUtils.deleteFile(path + File.separator + fileName);
}
file.transferTo(targetFile);
}
if(toOss != null && "1".equals(toOss)){
fYunFileService.uploadFile(path + File.separator + fileName, "images"+File.separator+"images"+sceneNum + File.separator + fileName);
}
return ResultData.ok(targetFile.getName());
}
@Override
public ResultData uploadShareLogo(String sceneNum, MultipartFile file) throws Exception {
ScenePro sceneProEntity = findBySceneNum(sceneNum);
if (sceneProEntity == null ) {
throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
}
StringBuffer dataBuf = new StringBuffer()
.append("data").append(File.separator)
.append("data").append(sceneProEntity.getNum())
.append(File.separator);
StringBuffer imagesBuf = new StringBuffer()
.append("images").append(File.separator)
.append("images").append(sceneProEntity.getNum())
.append(File.separator);
StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
String fileName = "";
if (!file.isEmpty()&&file.getSize() > 0) {
//文件上传的位置可以自定义
System.out.println("上传分享的logo");
String path = imagesBuffer.toString();
File targetFile = new File(path);
if (!targetFile.exists()) {
targetFile.mkdirs();
}
fileName = file.getOriginalFilename();
targetFile = new File(path + fileName);
int count = 1;
// 保存
synchronized(this)
{
file.transferTo(targetFile);
}
SceneProEdit sceneProEditEntity = sceneProEditService.findBySceneProId(sceneProEntity.getId());
Map map = new HashMap<>();
map.put("shareLogo", imagesBuf.toString() + fileName);
map.put("version", sceneProEditEntity.getVersion()+1);
FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map);
sceneProEditEntity.setShareLogo(imagesBuf.toString() + fileName);
sceneProEditEntity.setVersion(sceneProEditEntity.getVersion()+1);
sceneProEditService.updateById(sceneProEditEntity);
if("V2".equals(sceneProEntity.getBuildType())){
MatrixToImageWriterUtil.createQRCode(
mainUrl + "/" + sceneProUrl + sceneProEntity.getNum(),
ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneProEntity.getNum()+".png",
true,
path + File.separator + fileName);
MatrixToImageWriterUtil.createQRCode(mainUrl + "/" + sceneProUrl + sceneProEntity.getNum() + "&lang=en",
ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneProEntity.getNum()+"_en.png",
true,
path + File.separator + fileName);
}
if("V3".equals(sceneProEntity.getBuildType())){
MatrixToImageWriterUtil.createQRCode(mainUrl + "/" + sceneProNewUrl + sceneProEntity.getNum(),
ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneProEntity.getNum()+".png",
true,
path + File.separator + fileName);
MatrixToImageWriterUtil.createQRCode(mainUrl + "/" + sceneProNewUrl + sceneProEntity.getNum() + "&lang=en",
ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneProEntity.getNum()+"_en.png",
true,
path + File.separator + fileName);
}
}
return ResultData.ok(imagesBuf.toString() + fileName);
}
@Override
@SystemServiceLog(description = "上传场景的热点媒体文件")
public ResultData uploadHotMedia(String sceneNum, MultipartFile file, String sid) throws Exception {
ScenePro sceneProEntity = findBySceneNum(sceneNum);
if(sceneProEntity == null){
throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
}
String fileName = "hot" + sid + ".mp4";
if (!file.isEmpty()){
String path = ConstantFilePath.SCENE_PATH + "images" + File.separator + "images" + sceneNum;
File targetFile = new File(path);
if (!targetFile.exists()){
targetFile.mkdirs();
}
targetFile = new File(path + File.separator + fileName);
if (targetFile.exists()){
FileUtils.deleteFile(path + File.separator + fileName);
}
file.transferTo(targetFile);
if(targetFile.exists()){
FileUtils.executeCodecs(path + File.separator + fileName, path, "hot" + sid + "-cut");
}
}
return ResultData.ok(fileName);
}
@Override
public ResultData checkVideoUrl(String path) {
if(!path.contains("qq.com") && !path.contains("youku.com") && !path.contains("iqiyi.com")){
throw new BusinessException(ErrorCode.FAILURE_CODE_5016);
}
if(path.contains("v.qq.com/txp/iframe/player.html") || path.contains("player.youku.com/embed")
|| path.contains("open.iqiyi.com/developer/player_js/coopPlayerIndex.html")){
return ResultData.ok(path);
}
String html = "";
try {
URL url = new URL(path);
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setConnectTimeout(60000);
httpConn.setReadTimeout(60000);
InputStreamReader input = new InputStreamReader(httpConn
.getInputStream(), "utf-8");
BufferedReader bufReader = new BufferedReader(input);
String line = "";
String vid = "";
if(path.contains("qq.com")){
while ((line = bufReader.readLine()) != null) {
// System.out.println(line);
if(line.contains("m.v.qq.com/play.html")){
log.info(line.substring(line.indexOf("&vid=") + 5, line.indexOf("&ptag")));
vid = line.substring(line.indexOf("&vid=") + 5, line.indexOf("&ptag"));
break;
}
}
if(!org.springframework.util.StringUtils.isEmpty(vid)){
html = "https://v.qq.com/txp/iframe/player.html?vid=" + vid;
}
}
if(path.contains("youku.com")){
vid = path.substring(path.indexOf("/id_") + "/id_".length(), path.indexOf(".html"));
html = "https://player.youku.com/embed/" + vid;
}
if(path.contains("iqiyi.com")){
String tvid = "";
while ((line = bufReader.readLine()) != null) {
if(line.contains("param['vid']")){
vid = line.substring(line.indexOf("\"") + 1, line.lastIndexOf("\""));
}
if(line.contains("param['tvid']")){
tvid = line.substring(line.indexOf("\"") + 1, line.lastIndexOf("\""));
}
}
if(!org.springframework.util.StringUtils.isEmpty(vid) && !StringUtils.isEmpty(tvid)){
html = "https://open.iqiyi.com/developer/player_js/coopPlayerIndex.html?vid=" + vid +
"&tvId=" + tvid;
}
}
}catch (Exception e){
e.printStackTrace();
}
return ResultData.ok(html);
}
@Override
public ResultData saveSceneInfo(RequestSceneEdit base) throws Exception{
if(StrUtil.isEmpty(base.getSceneNum())){
throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
}
ScenePro sceneProEntity = findBySceneNum(base.getSceneNum());
if(sceneProEntity == null){
throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
}
StringBuffer dataBuf = new StringBuffer()
.append("data").append(File.separator)
.append("data").append(sceneProEntity.getNum())
.append(File.separator);
StringBuffer imagesBuf = new StringBuffer()
.append("images").append(File.separator)
.append("images").append(sceneProEntity.getNum())
.append(File.separator);
StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
int type = Integer.valueOf(base.getSceneType());
String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
JSONObject scenejson = new JSONObject();
if(strsceneInfos!=null) {
scenejson = JSONObject.parseObject(strsceneInfos);
}
//上传七牛
Map map = new HashMap();
SceneProEdit sceneProEditEntity = sceneProEditService.findBySceneProId(sceneProEntity.getId());
if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getTourList())){
if(scenejson.containsKey("uploadTourList") && scenejson.getIntValue("uploadTourList") == 1){
int screencapLen = 0;
File file = new File(dataBuffer.toString() + ConstantFileName.TOURLIST_FOLDER);
String[] strs = file.list();
if(strs!=null) {
for(int i=0;i-1)
{
++screencapLen;
map.put(dataBuffer.toString() + ConstantFileName.TOURLIST_FOLDER+File.separator+strs[i],
"data/data"+base.getSceneNum()+"/tour/"+strs[i]);
}
}
}
scenejson.put("screencapLen", screencapLen);
// sceneProEditEntity.setScreencapLen(screencapLen);
String path = imagesBuffer.toString() + ConstantFileName.TOURLIST_FOLDER;
JSONArray tourJsons = JSONArray.parseArray(base.getTourList());
for(int i=0;i-1) {
String fileName = "201810" + screencapVoiceFileName.substring(screencapVoiceFileName.lastIndexOf("."));
String path = ConstantFilePath.SCENE_PATH + "voice" + File.separator+"voice"+base.getSceneNum()+File.separator+fileName;
map.put(path, "voice/voice"+base.getSceneNum()+"/201810" +screencapVoiceFileName.substring(screencapVoiceFileName.lastIndexOf(".")));
}
sceneProEditEntity.setScreencapVoiceSrc(screencapVoiceSrc);
}
//判断scene.json是否有uploadVoiceSound上传专业版音频
if(scenejson.containsKey("uploadVoiceSound") && scenejson.getIntValue("uploadVoiceSound") == 1){
if(!org.apache.commons.lang3.StringUtils.isEmpty(scenejson.getString("screencapVoiceSound"))){
map.put(ConstantFilePath.SCENE_PATH + scenejson.getString("screencapVoiceSound"), scenejson.getString("screencapVoiceSound"));
}
sceneProEditEntity.setScreencapVoiceSound(scenejson.getString("screencapVoiceSound"));
}
if(scenejson.containsKey("uploadVoiceSoundsync") && scenejson.getIntValue("uploadVoiceSoundsync") == 1){
if(!org.apache.commons.lang3.StringUtils.isEmpty(scenejson.getString("screencapVoiceSoundsync"))){
map.put(ConstantFilePath.SCENE_PATH + scenejson.getString("screencapVoiceSoundsync"), scenejson.getString("screencapVoiceSoundsync"));
}
sceneProEditEntity.setScreencapVoiceSoundsync(scenejson.getString("screencapVoiceSoundsync"));
}
if(base.getScreencapVoiceType() != null){
scenejson.put("screencapVoiceType", base.getScreencapVoiceType());
sceneProEditEntity.setScreencapVoiceType(base.getScreencapVoiceType());
}
if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getCapData())){
FileUtils.writeFile(dataBuffer.toString() + "capData.json", new String(base.getCapData().getBytes(), "UTF-8"));
scenejson.put("capData", dataBuf.toString() + "capData.json");
}
if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getFrameData())){
FileUtils.writeFile(dataBuffer.toString() + "frameData.json", new String(base.getFrameData().getBytes(), "UTF-8"));
scenejson.put("frameData", dataBuf.toString() + "frameData.json");
}
if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getPlayData())){
FileUtils.writeFile(dataBuffer.toString() + "playData.json", new String(base.getPlayData().getBytes(), "UTF-8"));
scenejson.put("playData", dataBuf.toString() + "playData.json");
sceneProEditEntity.setPlayData(dataBuf.toString() + "playData.json");
map.put(dataBuffer.toString() + "playData.json", dataBuf.toString() + "playData.json");
}
if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getScreencapThumb())){
FileUtils.writeFile(dataBuffer.toString() + "screencapThumb.json", new String(base.getScreencapThumb().getBytes(), "UTF-8"));
scenejson.put("screencapThumb", dataBuf.toString() + "screencapThumb.json");
sceneProEditEntity.setScreencapThumb(dataBuf.toString() + "screencapThumb.json");
map.put(dataBuffer.toString() + "screencapThumb.json", dataBuf.toString() + "screencapThumb.json");
}
if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getRecordType())){
scenejson.put("recordType", base.getRecordType());
}
if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getMapVisi())){
scenejson.put("mapVisi", Integer.parseInt(base.getMapVisi()));
sceneProEditEntity.setMapVisi(Integer.parseInt(base.getMapVisi()));
}
if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getTourVisi())){
scenejson.put("tourVisi", Integer.parseInt(base.getTourVisi()));
sceneProEditEntity.setTourVisi(Integer.parseInt(base.getTourVisi()));
}
if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getVrVisi())){
scenejson.put("vrVisi", Integer.parseInt(base.getVrVisi()));
sceneProEditEntity.setVrVisi(Integer.parseInt(base.getVrVisi()));
}
if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getRulerVisi())){
scenejson.put("rulerVisi", Integer.parseInt(base.getRulerVisi()));
sceneProEditEntity.setRulerVisi(Integer.parseInt(base.getRulerVisi()));
}
if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getCadImgVisi())){
scenejson.put("cadImgVisi", Integer.parseInt(base.getCadImgVisi()));
sceneProEditEntity.setCadImgVisi(Integer.parseInt(base.getCadImgVisi()));
}
if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getPanoVisi())){
scenejson.put("panoVisi", Integer.parseInt(base.getPanoVisi()));
sceneProEditEntity.setPanoVisi(Integer.parseInt(base.getPanoVisi()));
}
if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getM2dVisi())){
scenejson.put("m2dVisi", Integer.parseInt(base.getM2dVisi()));
sceneProEditEntity.setM2dVisi(Integer.parseInt(base.getM2dVisi()));
}
if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getM3dVisi())){
scenejson.put("m3dVisi", Integer.parseInt(base.getM3dVisi()));
sceneProEditEntity.setM3dVisi(Integer.parseInt(base.getM3dVisi()));
}
if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getMeasureVisi())){
scenejson.put("measureVisi", Integer.parseInt(base.getMeasureVisi()));
sceneProEditEntity.setMeasureVisi(Integer.parseInt(base.getMeasureVisi()));
}
if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getFloorPlanAngle())){
scenejson.put("floorPlanAngle", base.getFloorPlanAngle());
sceneProEditEntity.setFloorPlanAngle(base.getFloorPlanAngle());
}
if(scenejson.containsKey("uploadFloorPlanPng") && scenejson.getIntValue("uploadFloorPlanPng") == 1){
JSONArray floorPlanPngStr = new JSONArray();
JSONArray floorPlanPng = new JSONArray();
switch (sceneProEntity.getBuildType()){
case "V2":
floorPlanPng.add(scenejson.getString("floorPlanPng"));
break;
case "V3":
try {
floorPlanPng = scenejson.getJSONArray("floorPlanPng");
} catch (Exception e) {
// 旧的V3也是String
floorPlanPng.add(scenejson.getString("floorPlanPng"));
}
break;
}
scenejson.put("uploadFloorPlanPng", 0);
for(int i = 0, len = floorPlanPng.size(); i < len; i++){
map.put(ConstantFilePath.SCENE_PATH+floorPlanPng.getString(i), floorPlanPng.getString(i));
floorPlanPngStr.add(floorPlanPng.getString(i) + "?t=" + System.currentTimeMillis());
}
sceneProEditEntity.setFloorPlanPng(floorPlanPngStr.toJSONString());
}
if(scenejson.containsKey("uploadFloorJson") && scenejson.getIntValue("uploadFloorJson") == 1){
map.put(dataBuffer.toString() + "floor.json", dataBuf.toString() + "floor.json");
scenejson.put("uploadFloorJson", 0);
}
if(StrUtil.isNotEmpty(base.getEntry())) {
//上传七牛
map.put(imagesBuffer.toString() + "thumbBigImg.jpg", imagesBuf.toString() + "thumbBigImg.jpg");
map.put(imagesBuffer.toString() + "thumbFishBigImg.jpg",imagesBuf.toString() + "thumbFishBigImg.jpg");
map.put(imagesBuffer.toString() + "thumbSmallImg.jpg", imagesBuf.toString() + "thumbSmallImg.jpg");
map.put(imagesBuffer.toString() + "smallPic.jpg", imagesBuf.toString() + "smallPic.jpg");
sceneProEditEntity.setEntry(base.getEntry());
scenejson.put("entry", base.getEntry());
if(scenejson.containsKey("thumbImg"))
{
sceneProEditEntity.setThumbStatus(scenejson.getIntValue("thumbImg"));
}
if(sceneProEditEntity.getThumbStatus() == 1)
{
sceneProEntity.setThumb(ossPrefixUrl + imagesBuf.toString() + "thumbSmallImg.jpg");
}
}
if(base.getHotFlag() != null && "1".equals(base.getHotFlag())) {
String str = FileUtils.readFile(dataBuffer.toString() + "hot.json");
JSONArray jsonhots = new JSONArray();
if(str != null&&!str.trim().equals("")) {
jsonhots = JSONArray.parseArray(str);
}
String hotsids = "";
for(int i=0;i 0){
FileUtils.copyFile(path + File.separator + "data.json", target + File.separator+"data.json", true);
FileUtils.copyFile(path + File.separator + "project.json", target + File.separator+"project.json", true);
//data.json增加extras为执行重建算法
String data = FileUtils.readFile(target + File.separator+"data.json");
if(data != null){
JSONObject floorplanJson = new JSONObject();
floorplanJson.put("has_source_images", true);
floorplanJson.put("has_vision_txt", true);
JSONObject dataJson = JSONObject.parseObject(data);
dataJson.put("extras", floorplanJson);
//V5表示不需要生成high,low文件
dataJson.put("skybox_type", "SKYBOX_V6");
if(sceneProEntity.getSceneScheme() == 11){
dataJson.put("skybox_type", "SKYBOX_V7");
}
dataJson.put("split_type", "SPLIT_V8");
//sceneScheme为3切成瓦片图
if(sceneProEntity.getSceneScheme() == 3){
String skybox_type = "SKYBOX_V14";
if(sceneProEntity.getSceneSource() !=null && sceneProEntity.getSceneSource() < 3){
skybox_type = "SKYBOX_V13";
}
dataJson.put("skybox_type", skybox_type);
}
FileUtils.writeFile(target + File.separator+"data.json", new String(dataJson.toString().getBytes(), "UTF-8"));
}
//创建文件夹软连接并且复制data.json和project.json
if(new File(target + File.separator + "capture").exists()){
new File(target + File.separator + "capture").delete();
}
if(new File(target + File.separator + "results").exists()){
FileUtils.delAllFile(target + File.separator + "results");
}
//下载data.fdage
if(FYunTypeEnum.AWS.code().equals(this.ossType)){
//亚马逊保持旧方式,超链接capture
CreateObjUtil.createSoftConnection(path + File.separator + "capture", target + File.separator + "capture");
}
fYunFileService.downloadFile(ConstantFilePath.OSS_PREFIX + path.replace(ConstantFilePath.BUILD_MODEL_PATH, "") + "/data.fdage", target + File.separator + "capture/" + "data.fdage");
CreateObjUtil.build3dModel(target , "1");
//读取upload文件,检验需要上传的文件是否存在
String uploadData = FileUtils.readFile(target + File.separator + "results" +File.separator+"upload.json");
JSONObject uploadJson = null;
JSONArray array = null;
if(uploadData!=null) {
uploadJson = JSONObject.parseObject(uploadData);
array = uploadJson.getJSONArray("upload");
}
if(array == null){
throw new Exception("upload.json数据出错");
}
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,"images/images"+
sceneProEntity.getNum()+"/pan/high/"+ fileName.replace("high/", ""));
continue;
}
//low文件夹
if(fileJson.getIntValue("clazz") == 4){
map.put(target + File.separator + "results" +File.separator+ fileName,"images/images"+
sceneProEntity.getNum()+"/pan/low/"+ fileName.replace("low/", ""));
continue;
}
//tiles文件夹,亚马逊没有裁剪图片api,不需要上传4k图
if(fileJson.getIntValue("clazz") == 5){
map.put(target + File.separator + "results" + File.separator+ fileName,"images/images"+
sceneProEntity.getNum()+ File.separator + fileName);
continue;
}
//tiles文件夹,亚马逊瓦片图
if(fileJson.getIntValue("clazz") == 7 ){
map.put(target + File.separator + "results" + File.separator+ fileName,"images/images"+
sceneProEntity.getNum()+ File.separator + fileName);
continue;
}
}
for(String imagesName : images.list()){
//覆盖原始图片资源
FileUtils.copyFile(target + File.separator + "extras/images/" + imagesName,
path + File.separator + "caches/images/" + imagesName, true);
FileUtils.deleteFile(target + File.separator + "extras/images/" + imagesName);
}
}
if(video.exists() && video.listFiles() != null && video.listFiles().length > 0){
for(String videoName : video.list()){
fYunFileService.uploadFile(target + File.separator + "extras/video/" + videoName,"video/video"+
sceneProEntity.getNum()+ File.separator + videoName);
CreateObjUtil.mp4ToFlv(target + File.separator + "extras/video/" + videoName,
target + File.separator + "extras/video/" + videoName.replace("mp4", "flv"));
fYunFileService.uploadFile(target + File.separator + "extras/video/" + videoName.replace("mp4", "flv"),"video/video"+
sceneProEntity.getNum()+ File.separator + videoName.replace("mp4", "flv"));
//覆盖原始视频资源
FileUtils.copyFile(target + File.separator + "extras/video/" + videoName,
path + File.separator + "caches/videos/" + videoName, true);
}
FileUtils.deleteDirectory(target + File.separator + "extras/video/");
}
// 清除马赛克数据
if(scenejson.containsKey("planId")){
String[] planIds = scenejson.getString("planId").split(",");
String mosaicDatasTr = sceneProEntity.getMosaics();
JSONArray jsonArray = new JSONArray();
if(!ObjectUtils.isEmpty(mosaicDatasTr)){
jsonArray = JSONArray.parseArray(mosaicDatasTr);
}
for (String planId : planIds) {
for (Iterator