|
@@ -40,6 +40,7 @@ import java.io.File;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Map.Entry;
|
|
|
import java.util.stream.Collectors;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -65,12 +66,14 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
@Service
|
|
|
public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper, SceneEditInfo> implements ISceneEditInfoService {
|
|
|
|
|
|
- @Value("${oss.prefix.ali}")
|
|
|
- private String prefixAli;
|
|
|
+ @Value("${oss.prefix.url}")
|
|
|
+ private String ossUrlPrefix;
|
|
|
@Value("${upload.type}")
|
|
|
private String type;
|
|
|
@Value("${oss.bucket:4dkankan}")
|
|
|
private String bucket;
|
|
|
+ @Value("${main.url}")
|
|
|
+ private String mainUrl;
|
|
|
@Autowired
|
|
|
private ISceneEditControlsService sceneEditControlsService;
|
|
|
@Autowired
|
|
@@ -193,6 +196,10 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
|
|
|
});
|
|
|
String hotJsonPath = String.format(UploadFilePath.USER_EDIT_PATH, sceneNum) + "hot.json";
|
|
|
uploadToOssUtil.upload(jsonhots.toString().getBytes(), hotJsonPath);
|
|
|
+
|
|
|
+ //修改tags状态为是,标识有热点数据
|
|
|
+ ScenePro scenePro = sceneProService.findBySceneNum(sceneNum);
|
|
|
+ this.saveTagsToSceneEditInfo(sceneNum, scenePro.getId());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -301,8 +308,8 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
|
|
|
String editDataPath = String.format(UploadFilePath.DATA_EDIT_PATH, num);
|
|
|
String editUserPath = String.format(UploadFilePath.USER_EDIT_PATH, num);
|
|
|
String localDataPath = String.format(ConstantFilePath.DATABUFFER_FORMAT, num);
|
|
|
- String floorCadUrl = prefixAli + editDataPath + "floorplan_cad.json?t=" + System.currentTimeMillis();
|
|
|
- String floorUserUrl = prefixAli + editUserPath + "floorplan_user.json?t=" + System.currentTimeMillis();
|
|
|
+ String floorCadUrl = ossUrlPrefix + editDataPath + "floorplan_cad.json?t=" + System.currentTimeMillis();
|
|
|
+ String floorUserUrl = ossUrlPrefix + editUserPath + "floorplan_user.json?t=" + System.currentTimeMillis();
|
|
|
|
|
|
JSONObject fileInfoJson = JSON.parseObject(param.getData());
|
|
|
String filePathStr = null;
|
|
@@ -482,68 +489,69 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<String> downloadPanorama(String num) throws Exception {
|
|
|
-
|
|
|
- //先下载到
|
|
|
-
|
|
|
-
|
|
|
-// String sceneNum = param.getNum();
|
|
|
-// String fileName = param.getFileName();
|
|
|
-// String planId = param.getPlanId();
|
|
|
-// String type = param.getPlanId();
|
|
|
-// if(StrUtil.isEmpty(sceneNum) || StrUtil.isEmpty(fileName) || StrUtil.isEmpty(type)|| StrUtil.isEmpty(planId)){
|
|
|
-// throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
|
|
|
-// }
|
|
|
-//
|
|
|
-// if(fileName.contains("..") || fileName.contains("./\\") || fileName.contains(".//")
|
|
|
-// || fileName.contains(".\\\\") || fileName.contains(".\\/")){
|
|
|
-// throw new BusinessException(ErrorCode.FAILURE_CODE_3018);
|
|
|
-// }
|
|
|
-//
|
|
|
-// ScenePro scenePro = baseMapper.findByNum(sceneNum);
|
|
|
-// if(scenePro == null){
|
|
|
-// throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
|
|
|
-// }
|
|
|
-// SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
|
|
|
-//
|
|
|
-// StringBuffer imagesBuf = new StringBuffer()
|
|
|
-// .append("images").append(File.separator)
|
|
|
-// .append("images").append(scenePro.getNum())
|
|
|
-// .append(File.separator);
|
|
|
-//
|
|
|
-// StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
|
|
|
-//
|
|
|
-// String path = sceneProExt.getDataSource();
|
|
|
-//
|
|
|
-// String url = "";
|
|
|
-//
|
|
|
-// if("image".equals(type)){
|
|
|
-// if(!new File(path + "/caches/images/" + fileName).exists()){
|
|
|
-// throw new BusinessException(ErrorCode.FAILURE_CODE_3018);
|
|
|
-// }
|
|
|
-//
|
|
|
-// //备份原始数据
|
|
|
-// if(!new File(imagesBuffer.toString() + "caches/back-" + fileName).exists()){
|
|
|
-// FileUtils.copyFile(path + "/caches/images/" + fileName, imagesBuffer.toString() + "caches/back-" + fileName, false);
|
|
|
-// }
|
|
|
-// //复制打包数据,并且改名
|
|
|
-// FileUtils.copyFile(path + "/caches/images/" + fileName, imagesBuffer.toString() + "caches/" + planId + ".jpg", true);
|
|
|
-//
|
|
|
-// url = mainUrl + "scene/" + imagesBuf.toString() + "caches/" + planId + ".jpg";
|
|
|
-// }
|
|
|
-//
|
|
|
-// if("video".equals(type)){
|
|
|
-// url = prefixAli + "video/video" + scenePro.getNum() + "/" + planId + ".mp4";
|
|
|
-// }
|
|
|
-//
|
|
|
-// Map<String, Object> map = new HashMap<>();
|
|
|
-// map.put("fileUrl", url + "?t=" + System.currentTimeMillis());
|
|
|
-// map.put("fileName", url.substring(url.lastIndexOf("/") + 1));
|
|
|
-// return ResultData.ok(map);
|
|
|
+ public ResultData downloadPanorama(String num) throws Exception {
|
|
|
+
|
|
|
+ String cachePath = String.format(ConstantFilePath.SCENE_CACHE, num);
|
|
|
+ String imgCachePath = String.format(UploadFilePath.IMG_CACHES_PATH, num);
|
|
|
+ String localImagesPath = String.format(ConstantFilePath.SCENE_CACHE_IMAGES, num);
|
|
|
+ List<String> keyList = uploadToOssUtil.listKeys(imgCachePath);
|
|
|
+
|
|
|
+ //先下载到本地
|
|
|
+ if (!StorageType.LOCAL.code().equals(this.type)) {// TODO: 2022/2/15 这里有可能有问题,可能还需要考虑本地部署的情况
|
|
|
+ keyList.stream().forEach(key->{
|
|
|
+ String fileName = key.substring(key.lastIndexOf("/") + 1);
|
|
|
+ String imageUrl = ossUrlPrefix + imgCachePath + fileName + "?t=" + System.currentTimeMillis();
|
|
|
+ FileUtils.downLoadFromUrl(imageUrl, fileName, localImagesPath);
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
+ //打包
|
|
|
+ String zipName = num + "_images.zip";
|
|
|
+ String zipPath = cachePath + zipName;
|
|
|
+ FileUtil.zip(localImagesPath, zipPath, false);
|
|
|
|
|
|
+ //上传压缩包
|
|
|
+ uploadToOssUtil.upload(zipPath, "downloads/caches/" + zipName);
|
|
|
+
|
|
|
+ String url = ossUrlPrefix + "downloads/caches/" + zipName + "?t=" + Calendar.getInstance().getTimeInMillis();
|
|
|
+
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("fileUrl", url + "?t=" + System.currentTimeMillis());
|
|
|
+ map.put("fileName", url.substring(url.lastIndexOf("/") + 1));
|
|
|
+
|
|
|
+ return ResultData.ok(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void saveTagsToSceneEditInfo(String num, Long sceneProId){
|
|
|
+ //查询缓存是否包含热点数据
|
|
|
+ String key = String.format(RedisKey.SCENE_HOT_DATA, num);
|
|
|
+ Map<String, String> allTagsMap = redisUtil.hmget(key);
|
|
|
+ boolean hashTags = false;
|
|
|
+ for (Entry<String, String> tagMap : allTagsMap.entrySet()) {
|
|
|
+ if(StrUtil.isEmpty(tagMap.getValue())){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ hashTags = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ //更改热点状态
|
|
|
+ SceneEditInfo sceneEditInfo = this.getBySceneProId(sceneProId);
|
|
|
+ if(Objects.isNull(sceneEditInfo)){
|
|
|
+ sceneEditInfo = new SceneEditInfo();
|
|
|
+ sceneEditInfo.setSceneProId(sceneProId);
|
|
|
+ sceneEditInfo.setTags(hashTags ? CommonStatus.YES.code() : CommonStatus.NO.code());
|
|
|
+ this.save(sceneEditInfo);
|
|
|
+ }else{
|
|
|
+ //更改场景编辑版本
|
|
|
+ this.update(
|
|
|
+ new LambdaUpdateWrapper<SceneEditInfo>()
|
|
|
+ .setSql("version=version+" + 1)
|
|
|
+ .set(SceneEditInfo::getTags, hashTags ? CommonStatus.YES.code() : CommonStatus.NO.code())
|
|
|
+ .eq(SceneEditInfo::getId, sceneEditInfo.getId()));
|
|
|
+ }
|
|
|
|
|
|
- return null;
|
|
|
}
|
|
|
|
|
|
}
|