|
@@ -0,0 +1,78 @@
|
|
|
+package com.fdkankan.scene.factory.UserEditData;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.fdkankan.model.constants.UploadFilePath;
|
|
|
+import com.fdkankan.redis.constant.RedisKey;
|
|
|
+import com.fdkankan.redis.util.RedisUtil;
|
|
|
+import com.fdkankan.scene.entity.SceneEditInfo;
|
|
|
+import com.fdkankan.scene.entity.ScenePlus;
|
|
|
+import com.fdkankan.scene.entity.ScenePlusExt;
|
|
|
+import com.fdkankan.scene.oss.OssUtil;
|
|
|
+import com.fdkankan.scene.service.ISceneEditInfoService;
|
|
|
+import com.fdkankan.scene.service.IScenePlusExtService;
|
|
|
+import com.fdkankan.scene.service.IScenePlusService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.nio.file.FileSystemException;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 初始化空间模型
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Component("boxModelHandler")
|
|
|
+public class BoxModelHandler implements UserEditDataHandler {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IScenePlusService scenePlusService;
|
|
|
+ @Autowired
|
|
|
+ private IScenePlusExtService scenePlusExtService;
|
|
|
+ @Autowired
|
|
|
+ private ISceneEditInfoService sceneEditInfoService;
|
|
|
+ @Autowired
|
|
|
+ private OssUtil ossUtil;
|
|
|
+ @Autowired
|
|
|
+ private RedisUtil redisUtil;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void init(String num, Map<String, Object> params) {
|
|
|
+ String modelEditPath = String.format(UploadFilePath.USER_EDIT_PATH, num) + "boxModels";
|
|
|
+ String modelViewPath = String.format(UploadFilePath.USER_VIEW_PATH, num) + "boxModels";
|
|
|
+ String sceneJsonPath = String.format(UploadFilePath.DATA_VIEW_PATH, num) + "scene.json";
|
|
|
+
|
|
|
+ //修改数据库,将boxModels字段置为空
|
|
|
+ ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
|
|
|
+ ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
|
|
|
+ SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
|
|
|
+ sceneEditInfoService.update(new LambdaUpdateWrapper<SceneEditInfo>().set(SceneEditInfo::getBoxModels, null).eq(SceneEditInfo::getId, sceneEditInfo.getId()));
|
|
|
+ String bucket = scenePlusExt.getYunFileBucket();
|
|
|
+
|
|
|
+ //更新scene.json
|
|
|
+ if(ossUtil.doesObjectExist(bucket, sceneJsonPath)){
|
|
|
+ String sceneJsonStr = ossUtil.getFileContent(bucket, sceneJsonPath);
|
|
|
+ JSONObject sceneJson = JSON.parseObject(sceneJsonStr);
|
|
|
+ sceneJson.remove("boxModels");
|
|
|
+ sceneJsonStr = sceneJson.toJSONString();
|
|
|
+ ossUtil.uploadFileBytes(bucket, sceneJsonPath, sceneJsonStr.getBytes(StandardCharsets.UTF_8));
|
|
|
+ //scenejson写入缓存
|
|
|
+ redisUtil.set(String.format(RedisKey.SCENE_JSON, num), sceneJsonStr);
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ //删除oss资源
|
|
|
+ if(ossUtil.doesObjectExist(bucket, modelEditPath)){
|
|
|
+ ossUtil.deleteObject(bucket, modelEditPath);
|
|
|
+ }
|
|
|
+ if(ossUtil.doesObjectExist(bucket, modelViewPath)){
|
|
|
+ ossUtil.deleteObject(bucket, modelViewPath);
|
|
|
+ }
|
|
|
+ } catch (FileSystemException e) {
|
|
|
+ log.error("删除三维模型文件失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|