|
@@ -0,0 +1,570 @@
|
|
|
+package com.fdkankan.scene.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.exceptions.ExceptionUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+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.CommonStatus;
|
|
|
+import com.fdkankan.common.constant.ConstantFilePath;
|
|
|
+import com.fdkankan.common.constant.UploadFilePath;
|
|
|
+import com.fdkankan.common.util.FileUtil;
|
|
|
+import com.fdkankan.common.util.FileUtils;
|
|
|
+import com.fdkankan.common.util.MatrixToImageWriterUtil;
|
|
|
+import com.fdkankan.common.util.SceneUtil;
|
|
|
+import com.fdkankan.fyun.oss.UploadToOssUtil;
|
|
|
+import com.fdkankan.redis.constant.RedisKey;
|
|
|
+import com.fdkankan.redis.constant.RedisLockKey;
|
|
|
+import com.fdkankan.redis.util.RedisLockUtil;
|
|
|
+import com.fdkankan.redis.util.RedisUtil;
|
|
|
+import com.fdkankan.scene.bean.RequestSceneProV4;
|
|
|
+import com.fdkankan.scene.bean.SceneEditControlsBean;
|
|
|
+import com.fdkankan.scene.bean.SceneJsonBean;
|
|
|
+import com.fdkankan.scene.bean.SceneUpgradeProgressBean;
|
|
|
+import com.fdkankan.scene.constant.ProgressStatus;
|
|
|
+import com.fdkankan.scene.entity.SceneEditControls;
|
|
|
+import com.fdkankan.scene.entity.SceneEditInfo;
|
|
|
+import com.fdkankan.scene.entity.SceneEditInfoExt;
|
|
|
+import com.fdkankan.scene.entity.ScenePlusExt;
|
|
|
+import com.fdkankan.scene.entity.ScenePro;
|
|
|
+import com.fdkankan.scene.entity.SceneProEdit;
|
|
|
+import com.fdkankan.scene.entity.SceneRepairLog;
|
|
|
+import com.fdkankan.scene.service.ISceneEditControlsService;
|
|
|
+import com.fdkankan.scene.service.ISceneEditInfoExtService;
|
|
|
+import com.fdkankan.scene.service.ISceneEditInfoService;
|
|
|
+import com.fdkankan.scene.service.IScenePlusExtService;
|
|
|
+import com.fdkankan.scene.service.ISceneProEditService;
|
|
|
+import com.fdkankan.scene.service.ISceneProService;
|
|
|
+import com.fdkankan.scene.service.ISceneRepairLogService;
|
|
|
+import com.fdkankan.scene.service.ISceneUpgradeToV4Service;
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Calendar;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Map.Entry;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+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;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * TODO
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author dengsixing
|
|
|
+ * @since 2022/4/21
|
|
|
+ **/
|
|
|
+@RefreshScope
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class SceneUpgradeToV4Service implements ISceneUpgradeToV4Service {
|
|
|
+
|
|
|
+ @Value("${main.url}")
|
|
|
+ private String mainUrl;
|
|
|
+ @Value("${scene.pro.new.url}")
|
|
|
+ private String sceneProNewUrl;
|
|
|
+ @Value("${oss.prefix.url}")
|
|
|
+ private String ossUrlPrefix;
|
|
|
+ @Value("${http.host.4dkankanMini}")
|
|
|
+ private String fkankanMiniHost;
|
|
|
+ @Value("${http.api-v4.upgradeToV4ResultSync}")
|
|
|
+ private String URL_UPGRADE_TO_V4_RESULT_SYNC;
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RedisLockUtil redisLockUtil;
|
|
|
+ @Autowired
|
|
|
+ private ISceneEditInfoService sceneEditInfoService;
|
|
|
+ @Autowired
|
|
|
+ private ISceneEditInfoExtService sceneEditInfoExtService;
|
|
|
+ @Autowired
|
|
|
+ private ISceneProEditService sceneProEditService;
|
|
|
+ @Autowired
|
|
|
+ private ISceneEditControlsService sceneEditControlsService;
|
|
|
+ @Autowired
|
|
|
+ private ISceneRepairLogService sceneRepairLogService;
|
|
|
+ @Value("${oss.bucket:4dkankan}")
|
|
|
+ private String bucket;
|
|
|
+ @Autowired
|
|
|
+ private ISceneProService sceneProService;
|
|
|
+ @Autowired
|
|
|
+ private IScenePlusExtService scenePlusExtService;
|
|
|
+ @Autowired
|
|
|
+ private UploadToOssUtil uploadToOssUtil;
|
|
|
+ @Autowired
|
|
|
+ RedisUtil redisUtil;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void upgrade(long sceneProId) throws Exception{
|
|
|
+
|
|
|
+ ScenePro scenePro = sceneProService.getById(sceneProId);
|
|
|
+ //线程开始,正在执行线程数+1
|
|
|
+ String num = scenePro.getNum();
|
|
|
+ String dataPath = String.format("data/data%s/", num);
|
|
|
+ String imagePath = String.format("images/images%s/", num);
|
|
|
+ String videoPath = String.format("video/video%s/", num);
|
|
|
+ String voicePath = String.format("voice/voice%s/", num);
|
|
|
+ String dataViewPath = String.format("scene_view_data/%s/data/", num);
|
|
|
+ String imageViewPath = String.format("scene_view_data/%s/images/", num);
|
|
|
+ String videoViewPath = String.format("scene_view_data/%s/video/", num);
|
|
|
+ String voiceViewPath = String.format("scene_view_data/%s/voice/", num);
|
|
|
+ long consumTime = 0;
|
|
|
+ long startTime = Calendar.getInstance().getTimeInMillis();
|
|
|
+ SceneRepairLog sceneRepairLog = null;
|
|
|
+ try {
|
|
|
+ sceneRepairLog = sceneRepairLogService.getOne(new LambdaQueryWrapper<SceneRepairLog>().eq(SceneRepairLog::getNum, num));
|
|
|
+ if(sceneRepairLog == null){
|
|
|
+ sceneRepairLog = SceneRepairLog.builder()
|
|
|
+ .num(scenePro.getNum())
|
|
|
+ .reason("")
|
|
|
+ .state(0).build();
|
|
|
+ }else{
|
|
|
+ sceneRepairLog.setUpdateTime(Calendar.getInstance().getTime());
|
|
|
+ sceneRepairLog.setReason("");
|
|
|
+ sceneRepairLog.setState(0);
|
|
|
+ }
|
|
|
+ //写入日志
|
|
|
+ sceneRepairLogService.saveOrUpdate(sceneRepairLog);
|
|
|
+
|
|
|
+ SceneProEdit sceneProEdit = sceneProEditService.getOne(
|
|
|
+ new LambdaQueryWrapper<SceneProEdit>()
|
|
|
+ .eq(SceneProEdit::getProId, scenePro.getId()));
|
|
|
+
|
|
|
+ String path = scenePro.getDataSource();
|
|
|
+
|
|
|
+ //生成热点json文件
|
|
|
+ Integer tags = this.createHotJson(dataPath, num);
|
|
|
+
|
|
|
+ boolean existLoadingLogo = false;
|
|
|
+ //生成编辑表
|
|
|
+ SceneEditInfo sceneEditInfo = sceneEditInfoService.getOne(
|
|
|
+ new LambdaQueryWrapper<SceneEditInfo>()
|
|
|
+ .eq(SceneEditInfo::getSceneProId, scenePro.getId()));
|
|
|
+ SceneEditInfoExt sceneEditInfoExt = null;
|
|
|
+ SceneEditControls sceneEditControls = null;
|
|
|
+ if(sceneEditInfo == null){
|
|
|
+
|
|
|
+ List<String> loadingLogoFile = uploadToOssUtil.listKeys(imagePath + "logo-main.png");
|
|
|
+ if(CollUtil.isNotEmpty(loadingLogoFile)){
|
|
|
+ existLoadingLogo = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ sceneEditInfo = new SceneEditInfo();
|
|
|
+ sceneEditInfo.setSceneProId(scenePro.getId());
|
|
|
+ sceneEditInfo.setScenePlusId(scenePro.getId());
|
|
|
+ sceneEditInfo.setFloorLogo(sceneProEdit.getFloorLogo());
|
|
|
+ sceneEditInfo.setFloorLogoSize(sceneProEdit.getFloorLogoSize());
|
|
|
+ sceneEditInfo.setFloorLogoFile("user".equals(sceneProEdit.getFloorLogo()) ? "floorLogo-user.png" : null); //floorLogoImg.png -> floorLogo-user.png
|
|
|
+ String music = null;
|
|
|
+ if(!"noMusic".equals(sceneProEdit.getBgMusic()) && !"0".equals(sceneProEdit.getBgMusic())){
|
|
|
+ music = sceneProEdit.getBgMusic();
|
|
|
+ }
|
|
|
+ if(StrUtil.isNotEmpty(music)){
|
|
|
+ if(music.equals("无")) music = "";
|
|
|
+ if(music.equals("欢快")) music = "01";
|
|
|
+ if(music.equals("空灵")) music = "02";
|
|
|
+ if(music.equals("节奏")) music = "03";
|
|
|
+ if(music.equals("怀旧")) music = "04";
|
|
|
+ if(music.equals("想念")) music = "05";
|
|
|
+ if(music.equals("复古")) music = "06";
|
|
|
+ if(music.equals("琴弦")) music = "07";
|
|
|
+ if(music.equals("愉快")) music = "08";
|
|
|
+ }
|
|
|
+ sceneEditInfo.setMusic(music);
|
|
|
+ //如果bgmusicname 不为空 ,MusicFile = BgMusicName
|
|
|
+ if(StrUtil.isNotEmpty(sceneProEdit.getBgMusicName())){
|
|
|
+ sceneEditInfo.setMusicFile(sceneProEdit.getBgMusicName());
|
|
|
+ }
|
|
|
+ //bgmusic=user, music=musicfile
|
|
|
+ if("user".equals(sceneProEdit.getBgMusic())){
|
|
|
+ sceneEditInfo.setMusic(sceneEditInfo.getMusicFile());
|
|
|
+ }
|
|
|
+ sceneEditInfo.setScenePassword(sceneProEdit.getSceneKey());
|
|
|
+ sceneEditInfo.setTitle(scenePro.getSceneName());
|
|
|
+ sceneEditInfo.setDescription(scenePro.getSceneDec());
|
|
|
+ sceneEditInfo.setFloorPlanUser(0);
|
|
|
+ sceneEditInfo.setTags(tags);
|
|
|
+ sceneEditInfo.setVersion(sceneProEdit.getVersion());
|
|
|
+ sceneEditInfo.setIsUploadObj(Integer.parseInt(CommonStatus.NO.code().toString()));
|
|
|
+ sceneEditInfo.setFloorEditVer(sceneProEdit.getFloorEditVer());
|
|
|
+ sceneEditInfo.setFloorPublishVer(sceneProEdit.getFloorPublishVer());
|
|
|
+// sceneEditInfo.setBoxVideos(sceneProEditExt.getOverlay());
|
|
|
+ sceneEditInfo.setEntry(sceneProEdit.getEntry());
|
|
|
+ sceneEditInfo.setLoadingLogo(existLoadingLogo ? "user" : null);
|
|
|
+ sceneEditInfo.setLoadingLogoFile(existLoadingLogo ? "loadingLogo-user.png" : null);
|
|
|
+ sceneEditInfo.setCreateTime(sceneProEdit.getCreateTime());
|
|
|
+ sceneEditInfo.setUpdateTime(sceneProEdit.getUpdateTime());
|
|
|
+ sceneEditInfoService.save(sceneEditInfo);
|
|
|
+
|
|
|
+ sceneEditInfoExt = new SceneEditInfoExt();
|
|
|
+ sceneEditInfoExt.setEditInfoId(sceneEditInfo.getId());
|
|
|
+ sceneEditInfoExt.setSceneProId(scenePro.getId());
|
|
|
+ sceneEditInfoExt.setScenePlusId(scenePro.getId());
|
|
|
+ sceneEditInfoExt.setFloorPlanAngle(sceneProEdit.getFloorPlanAngle() == null ? 0f : Float.parseFloat(sceneProEdit.getFloorPlanAngle()));
|
|
|
+ sceneEditInfoExt.setFloorPlanCompass(this.getFloorPlanCompass(num));
|
|
|
+ sceneEditInfoExt.setVrNum(sceneProEdit.getVrNum());
|
|
|
+ sceneEditInfoExt.setCreateTime(sceneEditInfo.getCreateTime());
|
|
|
+ sceneEditInfoExt.setUpdateTime(sceneEditInfo.getUpdateTime());
|
|
|
+ sceneEditInfoExt.setTbStatus(sceneEditInfo.getTbStatus());
|
|
|
+ sceneEditInfoExtService.save(sceneEditInfoExt);
|
|
|
+
|
|
|
+ sceneEditControls = new SceneEditControls();
|
|
|
+ sceneEditControls.setEditInfoId(sceneEditInfo.getId());
|
|
|
+ sceneEditControls.setShowMap(sceneProEdit.getMapVisi());
|
|
|
+ sceneEditControls.setShowLock(sceneProEdit.getNeedKey());
|
|
|
+ sceneEditControls.setShowTitle(Integer.valueOf(CommonStatus.YES.code()));
|
|
|
+ sceneEditControls.setShowPanorama(sceneProEdit.getPanoVisi());
|
|
|
+ sceneEditControls.setShowDollhouse(sceneProEdit.getM3dVisi());
|
|
|
+ sceneEditControls.setShowFloorplan(sceneProEdit.getM2dVisi());
|
|
|
+ sceneEditControls.setShowVR(sceneProEdit.getVrVisi());
|
|
|
+// sceneEditControls.setShowTour(sceneProEditExt.getTourVisi());
|
|
|
+ sceneEditControls.setShowRule(sceneProEdit.getRulerVisi());
|
|
|
+ sceneEditControls.setCreateTime(sceneEditInfo.getCreateTime());
|
|
|
+ sceneEditControls.setUpdateTime(sceneEditInfo.getUpdateTime());
|
|
|
+ sceneEditControls.setTbStatus(sceneEditInfo.getTbStatus());
|
|
|
+ sceneEditControlsService.save(sceneEditControls);
|
|
|
+ }else{
|
|
|
+ sceneEditInfoExt = sceneEditInfoExtService.getOne(
|
|
|
+ new LambdaQueryWrapper<SceneEditInfoExt>()
|
|
|
+ .eq(SceneEditInfoExt::getEditInfoId, sceneEditInfo.getId()));
|
|
|
+ sceneEditControls = sceneEditControlsService.getOne(
|
|
|
+ new LambdaQueryWrapper<SceneEditControls>()
|
|
|
+ .eq(SceneEditControls::getEditInfoId, sceneEditInfo.getId()));
|
|
|
+
|
|
|
+ sceneEditInfo.setTitle(scenePro.getSceneName());
|
|
|
+ sceneEditInfo.setVersion(sceneEditInfo.getVersion() + 1);
|
|
|
+ sceneEditInfoService.updateById(sceneEditInfo);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //完成数据库操作更新进度条为10
|
|
|
+ this.updateProgress(num, 10, ProgressStatus.DO_DB.code());
|
|
|
+
|
|
|
+ //oss文件拷贝
|
|
|
+ AtomicInteger count = new AtomicInteger(0);
|
|
|
+ AtomicInteger completeCnt = new AtomicInteger(0);
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+ List<String> dataKeys = uploadToOssUtil.listKeys(dataPath);
|
|
|
+ List<String> imageKeys = uploadToOssUtil.listKeys(imagePath);
|
|
|
+ List<String> videoKeys = uploadToOssUtil.listKeys(videoPath);
|
|
|
+ List<String> voiceKeys = uploadToOssUtil.listKeys(voicePath);
|
|
|
+ if(CollUtil.isNotEmpty(dataKeys)) count.addAndGet(dataKeys.size());
|
|
|
+ if(CollUtil.isNotEmpty(imageKeys)) count.addAndGet(imageKeys.size());
|
|
|
+ if(CollUtil.isNotEmpty(videoKeys)) count.addAndGet(videoKeys.size());
|
|
|
+ if(CollUtil.isNotEmpty(voiceKeys)) count.addAndGet(voiceKeys.size());
|
|
|
+ this.copyFileOss(num, completeCnt, count, dataKeys, dataPath, dataViewPath);
|
|
|
+ this.copyFileOss(num, completeCnt, count, imageKeys, imagePath, imageViewPath);
|
|
|
+ this.copyFileOss(num, completeCnt, count, videoKeys, videoPath, videoViewPath);
|
|
|
+ this.copyFileOss(num, completeCnt, count, voiceKeys, voicePath, voiceViewPath);
|
|
|
+
|
|
|
+
|
|
|
+ //将全景图缓存到缓存目录
|
|
|
+ List<String> imagesList = cn.hutool.core.io.FileUtil.listFileNames(path + "/caches/images");
|
|
|
+ String cachedImagesPath = String.format(ConstantFilePath.SCENE_CACHE_IMAGES, num);
|
|
|
+ //先清除旧的全景图
|
|
|
+ cn.hutool.core.io.FileUtil.del(cachedImagesPath);
|
|
|
+ String visionPath = path + "/results/vision.txt";
|
|
|
+ List<String> panoramaImageList = SceneUtil.getPanoramaImageList(visionPath);
|
|
|
+ imagesList.stream().forEach(fileName -> {
|
|
|
+ if(panoramaImageList.contains(fileName)){
|
|
|
+ String srcPath = path + "/caches/images/" + fileName;
|
|
|
+ String targetPath = cachedImagesPath + fileName;
|
|
|
+ log.info("源文件:{}, 目标文件:{}", srcPath, targetPath);
|
|
|
+ cn.hutool.core.io.FileUtil.copy(srcPath, targetPath, true);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ //户型图上传
|
|
|
+ String userEditPath = UploadFilePath.USER_EDIT_PATH + "floor-cad-%s.%s";
|
|
|
+ String userViewPath = UploadFilePath.USER_VIEW_PATH + "floor-cad-%s.%s";
|
|
|
+ String floorCadPath = path + "/results/floorplan_cad";
|
|
|
+ List<String> floorCadList = FileUtil.getFileList(floorCadPath);
|
|
|
+ if(CollUtil.isNotEmpty(floorCadList)){
|
|
|
+ floorCadList.stream().forEach(str->{
|
|
|
+ String substring = str.substring(str.lastIndexOf(File.separator) + 1);
|
|
|
+ String[] arr = substring.split("floor");
|
|
|
+ String[] arr2 = arr[1].split("\\.");
|
|
|
+ uploadToOssUtil.upload(str, String.format(userEditPath, num, arr2[0], arr2[1]));
|
|
|
+ uploadToOssUtil.upload(str, String.format(userViewPath, num, arr2[0], arr2[1]));
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ //拷贝模型文件到用户编辑目录
|
|
|
+ String editImagesPath = String.format(UploadFilePath.IMG_EDIT_PATH, num);
|
|
|
+ String viewImagesPath = String.format(UploadFilePath.IMG_VIEW_PATH, num);
|
|
|
+ String editDataPath = String.format(UploadFilePath.DATA_EDIT_PATH, num);
|
|
|
+ String viewDataPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
|
|
|
+ Map<String, String> map2 = new HashMap<>();
|
|
|
+ map2.put(editImagesPath + "vision.modeldata", viewImagesPath + "vision.modeldata");
|
|
|
+ map2.put(editImagesPath + "vision2.modeldata", viewImagesPath + "vision2.modeldata");
|
|
|
+ map2.put(editDataPath + "floorplan_cad.json", viewDataPath + "floorplan_cad.json");
|
|
|
+ for (Entry<String, String> entry : map2.entrySet()) {
|
|
|
+ uploadToOssUtil.copyFiles(entry.getValue(), entry.getKey());
|
|
|
+ }
|
|
|
+
|
|
|
+ //完成数据库操作更新进度条为10
|
|
|
+ this.updateProgress(num, 90, ProgressStatus.DO_OSS.code());
|
|
|
+
|
|
|
+ //生成二维码
|
|
|
+ String sceneUrl = mainUrl + "/" + sceneProNewUrl;
|
|
|
+ String outPathZh = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/" + num + ".png";
|
|
|
+ String outPathEn = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/" + num + "_en.png";
|
|
|
+ MatrixToImageWriterUtil.createQRCode(sceneUrl + num, outPathZh, false,null);
|
|
|
+ MatrixToImageWriterUtil.createQRCode(sceneUrl + num + "&lang=en", outPathEn, false, null);
|
|
|
+ uploadToOssUtil.upload(outPathZh, String.format(UploadFilePath.DOWNLOADS_QRCODE, num) + num + ".png");
|
|
|
+ uploadToOssUtil.upload(outPathEn, String.format(UploadFilePath.DOWNLOADS_QRCODE, num) + num + "_en.png");
|
|
|
+
|
|
|
+ //根据编辑表 上传用户目录 包括编辑目录 查看目录
|
|
|
+ String editUsersPath = String.format(UploadFilePath.USER_EDIT_PATH, num);
|
|
|
+ String viewUsersPath = String.format(UploadFilePath.USER_VIEW_PATH, num);
|
|
|
+ if("user".equals(sceneProEdit.getFloorLogo())){
|
|
|
+ uploadToOssUtil.copyFiles(imagePath + "floorLogoImg.png", editUsersPath + "floorLogo-user.png");
|
|
|
+ uploadToOssUtil.copyFiles(imagePath + "floorLogoImg.png", viewUsersPath + "floorLogo-user.png");
|
|
|
+ }
|
|
|
+ if("user".equals(sceneProEdit.getBgMusic())){
|
|
|
+ uploadToOssUtil.copyFiles(imagePath + sceneProEdit.getBgMusicName(), editUsersPath + "music-user.mp3");
|
|
|
+ uploadToOssUtil.copyFiles(imagePath + sceneProEdit.getBgMusicName(), viewUsersPath + "music-user.mp3");
|
|
|
+ }
|
|
|
+ if(existLoadingLogo){
|
|
|
+ uploadToOssUtil.copyFiles(imagePath + "logo-main.png", editUsersPath + "loadingLogo-user.png");
|
|
|
+ uploadToOssUtil.copyFiles(imagePath + "logo-main.png", viewUsersPath + "loadingLogo-user.png");
|
|
|
+ }
|
|
|
+ ScenePlusExt scenePlusExt = scenePlusExtService.getOne(
|
|
|
+ new LambdaQueryWrapper<ScenePlusExt>()
|
|
|
+ .eq(ScenePlusExt::getPlusId, scenePro.getId()));
|
|
|
+ if(StrUtil.isNotEmpty(scenePro.getThumb())
|
|
|
+ && scenePro.getThumb().contains(imagePath)){
|
|
|
+ String thumbUrl = null;
|
|
|
+ if(scenePro.getThumb().contains("thumbSmallImg.jpg")){
|
|
|
+ uploadToOssUtil.copyFiles(imagePath + "thumbBigImg.jpg", editUsersPath + "thumb-1k.jpg");
|
|
|
+ uploadToOssUtil.copyFiles(imagePath + "thumbBigImg.jpg", viewUsersPath + "thumb-1k.jpg");
|
|
|
+ uploadToOssUtil.copyFiles(imagePath + "thumbBigImg.jpg", editUsersPath + "thumb-2k.jpg");
|
|
|
+ uploadToOssUtil.copyFiles(imagePath + "thumbBigImg.jpg", viewUsersPath + "thumb-2k.jpg");
|
|
|
+ uploadToOssUtil.copyFiles(imagePath + "thumbSmallImg.jpg", editUsersPath + "thumb-128.jpg");
|
|
|
+ uploadToOssUtil.copyFiles(imagePath + "thumbSmallImg.jpg", viewUsersPath + "thumb-128.jpg");
|
|
|
+ thumbUrl = this.ossUrlPrefix + String.format(UploadFilePath.USER_VIEW_PATH, num) + "thumb-128.jpg";
|
|
|
+ }else{
|
|
|
+ thumbUrl = scenePro.getThumb().replace(imagePath, viewImagesPath);
|
|
|
+ }
|
|
|
+
|
|
|
+ String webSite = sceneUrl + num;
|
|
|
+ scenePro.setThumb(thumbUrl);
|
|
|
+ scenePro.setWebSite(webSite);
|
|
|
+ sceneProService.updateById(scenePro);
|
|
|
+
|
|
|
+ scenePlusExt.setThumb(thumbUrl);
|
|
|
+ scenePlusExt.setWebSite(webSite);
|
|
|
+ scenePlusExtService.updateById(scenePlusExt);
|
|
|
+ }
|
|
|
+ if(StrUtil.isNotEmpty(sceneEditInfo.getBoxVideos())){
|
|
|
+ JSONArray boxVideoArr = JSON.parseArray(sceneEditInfo.getBoxVideos());
|
|
|
+ for(int i = 0; i < boxVideoArr.size(); i++){
|
|
|
+ JSONObject boxVideo = boxVideoArr.getJSONObject(i);
|
|
|
+ String sid = boxVideo.getString("sid");
|
|
|
+ uploadToOssUtil.copyFiles(imagePath + "overlay" + sid + ".mp4", editUsersPath + sid + ".mp4");
|
|
|
+ uploadToOssUtil.copyFiles(imagePath + "overlay" + sid + ".mp4", viewUsersPath + sid + ".mp4");
|
|
|
+ uploadToOssUtil.copyFiles(imagePath + "overlay" + sid + ".flv", editUsersPath + sid + ".flv");
|
|
|
+ uploadToOssUtil.copyFiles(imagePath + "overlay" + sid + ".flv", viewUsersPath + sid + ".flv");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //本地mapping文件上传
|
|
|
+ String mappingOssPath = String.format(UploadFilePath.DATA_EDIT_PATH, num) + "mapping";
|
|
|
+ String mappingPath = "/mnt/4Dkankan/scene/data/data" + num + "/mapping";
|
|
|
+ List<String> mappingList = FileUtils.list(new File(mappingPath));
|
|
|
+ if(CollUtil.isNotEmpty(mappingList)){
|
|
|
+ mappingList.parallelStream().forEach(mapping->{
|
|
|
+ uploadToOssUtil.upload(mapping, mapping.replace(mappingPath, mappingOssPath));
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ //生成scene.json
|
|
|
+// 生成新的scene.json,上传至scene_view_data/<num>/data
|
|
|
+ SceneJsonBean sceneJson = new SceneJsonBean();
|
|
|
+ BeanUtil.copyProperties(sceneEditInfoExt, sceneJson);
|
|
|
+ BeanUtil.copyProperties(sceneEditInfo, sceneJson);
|
|
|
+ SceneEditControlsBean sceneEditControlsBean = BeanUtil.copyProperties(sceneEditControls, SceneEditControlsBean.class);
|
|
|
+ sceneJson.setControls(sceneEditControlsBean);
|
|
|
+ sceneJson.setNum(num);
|
|
|
+ sceneJson.setCreateTime(scenePro.getCreateTime());
|
|
|
+ sceneJson.setSceneResolution(scenePlusExt.getSceneResolution());
|
|
|
+ sceneJson.setSceneFrom(scenePlusExt.getSceneFrom());
|
|
|
+ sceneJson.setSceneKind(scenePlusExt.getSceneKind());
|
|
|
+ if(StrUtil.isNotEmpty(scenePro.getVideos())){
|
|
|
+ sceneJson.setVideos(JSON.parseObject(scenePro.getVideos()));
|
|
|
+ }
|
|
|
+ sceneJson.setVersion(sceneEditInfo.getVersion());
|
|
|
+ //上传sceneJson文件
|
|
|
+ String sceneJsonPath = String.format(UploadFilePath.DATA_VIEW_PATH+"scene.json", num);
|
|
|
+ uploadToOssUtil.upload(JSON.toJSONBytes(sceneJson), sceneJsonPath);
|
|
|
+
|
|
|
+ redisUtil.del(String.format(RedisKey.SCENE_JSON, num));
|
|
|
+
|
|
|
+ //迁移耗时
|
|
|
+ consumTime = Calendar.getInstance().getTimeInMillis() - startTime;
|
|
|
+
|
|
|
+ //记录日志
|
|
|
+ sceneRepairLog.setUpdateTime(Calendar.getInstance().getTime());
|
|
|
+ sceneRepairLog.setState(1);
|
|
|
+ sceneRepairLog.setConsumTime(consumTime);
|
|
|
+ sceneRepairLogService.updateById(sceneRepairLog);
|
|
|
+
|
|
|
+ //处理scenepro的升级状态和协作关系
|
|
|
+ sceneProService.upgradeToV4ResultSync(
|
|
|
+ RequestSceneProV4.builder()
|
|
|
+ .id(sceneProId)
|
|
|
+ .webSite(scenePro.getWebSite())
|
|
|
+ .build());
|
|
|
+
|
|
|
+ this.updateProgress(num, 100, ProgressStatus.SUCCESS.code());
|
|
|
+
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+
|
|
|
+ //完成数据库操作更新进度条为0,状态失败
|
|
|
+ this.updateProgress(num, 0, ProgressStatus.FAIL.code());
|
|
|
+
|
|
|
+ //记录日志
|
|
|
+ consumTime = Calendar.getInstance().getTimeInMillis() - startTime;
|
|
|
+ sceneRepairLog.setUpdateTime(Calendar.getInstance().getTime());
|
|
|
+ sceneRepairLog.setState(2);
|
|
|
+ sceneRepairLog.setReason(ExceptionUtil.stacktraceToString(e));
|
|
|
+ sceneRepairLog.setConsumTime(consumTime);
|
|
|
+ sceneRepairLogService.updateById(sceneRepairLog);
|
|
|
+ } finally {
|
|
|
+ String lockKey = String.format(RedisLockKey.LOCK_SCENE_UPGRADE_V4, num);
|
|
|
+ redisUtil.del(lockKey);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void copyFileOss(String num, AtomicInteger completeCnt, AtomicInteger count, List<String> keyList, String sourcePath, String targetPah){
|
|
|
+ if(CollUtil.isEmpty(keyList))
|
|
|
+ return;
|
|
|
+ keyList.parallelStream().forEach(key->{
|
|
|
+ try {
|
|
|
+ String targetKey = null;
|
|
|
+ if(key.contains(sourcePath)){
|
|
|
+ targetKey = key.replace(sourcePath, targetPah);
|
|
|
+ }
|
|
|
+ uploadToOssUtil.copyObject(key, targetKey);
|
|
|
+ this.updateProgress(num,
|
|
|
+ 10 +
|
|
|
+ (new BigDecimal(completeCnt.incrementAndGet())
|
|
|
+ .divide(new BigDecimal(count.get()), 6, BigDecimal.ROUND_HALF_UP)
|
|
|
+ .multiply(new BigDecimal(0.7))
|
|
|
+ .multiply(new BigDecimal(100))
|
|
|
+ .setScale(0, RoundingMode.UP)
|
|
|
+ .intValue()),
|
|
|
+ ProgressStatus.DO_OSS.code()
|
|
|
+ );
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("文件拷贝出错,key:{}", key);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private Integer createHotJson(String dataPath, String num) throws IOException {
|
|
|
+ Integer tags = Integer.valueOf(CommonStatus.NO.code());
|
|
|
+// Set<String> icons = new HashSet<>();
|
|
|
+// String hotJson = uploadToOssUtil.getObjectContent("4dkankan", dataPath + "hot.json");
|
|
|
+// JSONArray newHotArr = new JSONArray();
|
|
|
+// if(StrUtil.isNotBlank(hotJson)){
|
|
|
+// JSONArray hotArr = JSON.parseArray(hotJson);
|
|
|
+// if(hotArr.size() > 0){
|
|
|
+// tags = Integer.valueOf(CommonStatus.YES.code());
|
|
|
+// for(int i=0; i < hotArr.size(); i++){
|
|
|
+// JSONObject oldHot = (JSONObject)hotArr.get(i);
|
|
|
+// String styleId = oldHot.getString("styleId");
|
|
|
+//
|
|
|
+// JSONObject newHot = new JSONObject();
|
|
|
+// newHot.put("createTime", Calendar.getInstance().getTimeInMillis() + i);
|
|
|
+// newHot.put("icon", styleId);
|
|
|
+//
|
|
|
+// newHot.put("position", oldHot.getJSONObject("position"));
|
|
|
+//
|
|
|
+// JSONObject media = new JSONObject();
|
|
|
+// newHot.put("media", media);
|
|
|
+// JSONObject fileName = oldHot.getJSONObject("fileName");
|
|
|
+// Set<Entry<String, Object>> entries = null;
|
|
|
+// if(fileName != null){
|
|
|
+// entries = fileName.entrySet();
|
|
|
+// }
|
|
|
+// if(CollUtil.isNotEmpty(entries)){
|
|
|
+// for (Entry<String, Object> entry : entries) {
|
|
|
+// JSONArray arr = new JSONArray();
|
|
|
+// media.put(entry.getKey(), arr);
|
|
|
+// JSONObject o = new JSONObject();
|
|
|
+// arr.add(o);
|
|
|
+// String fileSrc = ((String) entry.getValue());
|
|
|
+// o.put("src", oldHot.getString("sid") + fileSrc.substring(fileSrc.lastIndexOf(".")));
|
|
|
+// o.put("name", fileSrc);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// newHot.put("type", oldHot.getString("mediaType"));
|
|
|
+// newHot.put("title", oldHot.getString("label"));
|
|
|
+// newHot.put("content", oldHot.getString("description"));
|
|
|
+// newHot.put("sid", oldHot.getString("sid"));
|
|
|
+//
|
|
|
+// if(StrUtil.isNotBlank(styleId)){
|
|
|
+// icons.add(styleId);
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
+// }
|
|
|
+// String hotJsonEditPath = String.format(UploadFilePath.USER_EDIT_PATH, num) + "hot.json";
|
|
|
+// String hotJsonViewPath = String.format(UploadFilePath.USER_VIEW_PATH, num) + "hot.json";
|
|
|
+// uploadToOssUtil.upload(hotJson.getBytes(), hotJsonEditPath);
|
|
|
+// uploadToOssUtil.upload(hotJson.getBytes(), hotJsonViewPath);
|
|
|
+//
|
|
|
+// //写到本地文件
|
|
|
+// JSONObject localObject = new JSONObject();
|
|
|
+// localObject.put("tags", newHotArr);
|
|
|
+// localObject.put("icons", icons);
|
|
|
+// String hotJsonPath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num) + "hot.json";
|
|
|
+// FileUtils.writeFile(hotJsonPath, localObject.toJSONString());
|
|
|
+// }
|
|
|
+ return tags;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Float getFloorPlanCompass(String num){
|
|
|
+ String objectContent =
|
|
|
+ uploadToOssUtil.getObjectContent(bucket, "data/data" + num + "/houst_floor.json");
|
|
|
+ if(StrUtil.isEmpty(objectContent)){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ JSONObject jsonObject = JSON.parseObject(objectContent);
|
|
|
+ JSONArray floors = jsonObject.getJSONArray("floors");
|
|
|
+ if(CollUtil.isEmpty(floors)){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Object o = floors.get(0);
|
|
|
+ JSONObject object = (JSONObject)o;
|
|
|
+ return object.getFloat("dire");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新进度条
|
|
|
+ * @param num
|
|
|
+ * @param progress
|
|
|
+ * @param status
|
|
|
+ */
|
|
|
+ private void updateProgress(String num, int progress, int status){
|
|
|
+ String key = String.format(RedisKey.scene_upgrade_progress_num, num);
|
|
|
+ redisUtil.set(key,
|
|
|
+ JSON.toJSONString(
|
|
|
+ SceneUpgradeProgressBean.builder()
|
|
|
+ .num(num).status(status)
|
|
|
+ .progress(progress).build()));
|
|
|
+ }
|
|
|
+}
|