|
@@ -0,0 +1,186 @@
|
|
|
|
+package com.fdkankan.scene.service.impl;
|
|
|
|
+
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.fdkankan.common.constant.ErrorCode;
|
|
|
|
+import com.fdkankan.common.exception.BusinessException;
|
|
|
|
+import com.fdkankan.common.util.FileUtils;
|
|
|
|
+import com.fdkankan.fyun.face.FYunFileServiceInterface;
|
|
|
|
+import com.fdkankan.model.constants.ConstantFilePath;
|
|
|
|
+import com.fdkankan.model.utils.CreateObjUtil;
|
|
|
|
+import com.fdkankan.scene.entity.Scene3dNumMatterPro;
|
|
|
|
+import com.fdkankan.scene.entity.ScenePro;
|
|
|
|
+import com.fdkankan.scene.entity.SceneProEdit;
|
|
|
|
+import com.fdkankan.scene.entity.User;
|
|
|
|
+import com.fdkankan.scene.service.IInnerApiService;
|
|
|
|
+import com.fdkankan.scene.service.IScene3dNumMatterProService;
|
|
|
|
+import com.fdkankan.scene.service.ISceneProEditService;
|
|
|
|
+import com.fdkankan.scene.service.ISceneProService;
|
|
|
|
+import com.fdkankan.scene.service.IUserService;
|
|
|
|
+import com.fdkankan.web.response.ResultData;
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.UUID;
|
|
|
|
+import org.joda.time.DateTime;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * <p>
|
|
|
|
+ * TODO
|
|
|
|
+ * </p>
|
|
|
|
+ *
|
|
|
|
+ * @author dengsixing
|
|
|
|
+ * @since 2022/11/24
|
|
|
|
+ **/
|
|
|
|
+@Service
|
|
|
|
+public class InnerApiServiceImpl implements IInnerApiService {
|
|
|
|
+
|
|
|
|
+ @Value("${main.url}")
|
|
|
|
+ private String mainUrl;
|
|
|
|
+ @Value("${scene.pro.v3.url}")
|
|
|
|
+ private String sceneProV3Url;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IScene3dNumMatterProService scene3dNumMatterProService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private FYunFileServiceInterface fYunFileService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IUserService userService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ISceneProService sceneProService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ISceneProEditService sceneProEditService;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public ResultData uploadMatterproData(String sceneName, String userName, String floor, MultipartFile file) throws Exception {
|
|
|
|
+ if(file == null || file.getSize() <=0){
|
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(!file.getOriginalFilename().toLowerCase().endsWith(".zip") && !file.getOriginalFilename().toLowerCase().endsWith(".rar")){
|
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5026);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String sceneNum = "";
|
|
|
|
+ synchronized(this){
|
|
|
|
+ Scene3dNumMatterPro numEntity = scene3dNumMatterProService.findSceneNum();
|
|
|
|
+ sceneNum = numEntity.getCode();
|
|
|
|
+ numEntity.setUsed(1);
|
|
|
|
+ scene3dNumMatterProService.updateById(numEntity);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String dataSource = ConstantFilePath.BUILD_MODEL_PATH + UUID.randomUUID() + File.separator ;
|
|
|
|
+
|
|
|
|
+ File data = new File(dataSource + file.getOriginalFilename());
|
|
|
|
+ if(!data.getParentFile().exists()){
|
|
|
|
+ data.getParentFile().mkdirs();
|
|
|
|
+ }
|
|
|
|
+ file.transferTo(data);
|
|
|
|
+
|
|
|
|
+ if(file.getOriginalFilename().toLowerCase().endsWith(".zip")){
|
|
|
|
+ CreateObjUtil.unZip(dataSource + file.getOriginalFilename(), dataSource);
|
|
|
|
+ }
|
|
|
|
+ if(file.getOriginalFilename().toLowerCase().endsWith(".rar")){
|
|
|
|
+ CreateObjUtil.unRar(dataSource + file.getOriginalFilename(), dataSource);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //删除压缩包
|
|
|
|
+ new File(dataSource + file.getOriginalFilename()).delete();
|
|
|
|
+
|
|
|
|
+ List<String> fileList = new ArrayList<>();
|
|
|
|
+ FileUtils.readfilePath(dataSource, fileList);
|
|
|
|
+ String ossPath = "";
|
|
|
|
+ for (String filePath : fileList) {
|
|
|
|
+ ossPath = filePath.replace(dataSource, "images/images" + sceneNum + "/");
|
|
|
|
+ if(ossPath.endsWith("/")){
|
|
|
|
+ ossPath = ossPath.substring(0, ossPath.lastIndexOf("/"));
|
|
|
|
+ }
|
|
|
|
+ fYunFileService.uploadFile(filePath, ossPath);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ ScenePro sceneProEntity = new ScenePro();
|
|
|
|
+ sceneProEntity.setDataSource(dataSource);
|
|
|
|
+ sceneProEntity.setNum(sceneNum);
|
|
|
|
+ sceneProEntity.setSceneDec("<p>四维看看 让空间讲故事</p>");
|
|
|
|
+ //默认场景名称,若有传场景名称,则以传的为准
|
|
|
|
+ sceneProEntity.setSceneName("手动上传场景");
|
|
|
|
+ if(StrUtil.isNotEmpty(sceneName)){
|
|
|
|
+ sceneProEntity.setSceneName(sceneName);
|
|
|
|
+ }
|
|
|
|
+ sceneProEntity.setWebSite(mainUrl + "/" + sceneProV3Url + sceneNum);
|
|
|
|
+ sceneProEntity.setStatus(-2);
|
|
|
|
+ sceneProEntity.setPayStatus(1);
|
|
|
|
+ //默认用户id,若有传用户信息,则以传的为准
|
|
|
|
+ sceneProEntity.setUserId(2285L);
|
|
|
|
+ if(StrUtil.isNotEmpty(userName)){
|
|
|
|
+ User userEntity = userService.findByUserName(userName);
|
|
|
|
+ if(userEntity != null){
|
|
|
|
+ sceneProEntity.setUserId(userEntity.getId());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ sceneProEntity.setSceneScheme(10);
|
|
|
|
+ sceneProEntity.setSceneSource(14);
|
|
|
|
+ sceneProEntity.setBuildType("V3");
|
|
|
|
+ sceneProService.save(sceneProEntity);
|
|
|
|
+
|
|
|
|
+ SceneProEdit sceneProEditEntity = new SceneProEdit();
|
|
|
|
+ sceneProEditEntity.setProId(sceneProEntity.getId());
|
|
|
|
+ sceneProEditEntity.setMapVisi(0);
|
|
|
|
+ sceneProEditEntity.setM2dVisi(1);
|
|
|
|
+ sceneProEditEntity.setM3dVisi(1);
|
|
|
|
+ sceneProEditEntity.setPanoVisi(1);
|
|
|
|
+ sceneProEditEntity.setCadImgVisi(0);
|
|
|
|
+ sceneProEditService.save(sceneProEditEntity);
|
|
|
|
+
|
|
|
|
+ JSONObject scenejson = JSONObject.parseObject(JSONObject.toJSONString(sceneProEntity));
|
|
|
|
+ scenejson.put("thumbImg", 0);
|
|
|
|
+ scenejson.put("version", 0);
|
|
|
|
+ scenejson.put("floorLogo", 0);
|
|
|
|
+ scenejson.put("sceneKey", "");
|
|
|
|
+ scenejson.put("public", 0);
|
|
|
|
+ scenejson.put("visions", 1);
|
|
|
|
+ scenejson.put("createTime", new DateTime(new Date()).toString("yyyy-MM-dd HH:mm"));
|
|
|
|
+
|
|
|
|
+ scenejson.put("floorPublishVer", sceneProEditEntity.getFloorPublishVer());
|
|
|
|
+ scenejson.put("floorEditVer", sceneProEditEntity.getFloorEditVer());
|
|
|
|
+ scenejson.put("entry", null);
|
|
|
|
+
|
|
|
|
+ scenejson.put("hots", 0);
|
|
|
|
+
|
|
|
|
+ FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"scene.json", scenejson.toString());
|
|
|
|
+
|
|
|
|
+ JSONObject floors = new JSONObject();
|
|
|
|
+ JSONArray floorArr = new JSONArray();
|
|
|
|
+ JSONObject floorObject = new JSONObject();
|
|
|
|
+ if(StrUtil.isEmpty(floor)){
|
|
|
|
+ floorObject = new JSONObject();
|
|
|
|
+ floorObject.put("id", 0);
|
|
|
|
+ floorObject.put("subgroup", 0);
|
|
|
|
+ floorObject.put("name", "1楼");
|
|
|
|
+ floorObject.put("segment", new JSONArray());
|
|
|
|
+ floorObject.put("vertex", new JSONArray());
|
|
|
|
+
|
|
|
|
+ floorArr.add(floorObject);
|
|
|
|
+ }else {
|
|
|
|
+ for(int i = 0; i < Integer.parseInt(floor); i ++){
|
|
|
|
+ floorObject = new JSONObject();
|
|
|
|
+ floorObject.put("id", i);
|
|
|
|
+ floorObject.put("subgroup", i);
|
|
|
|
+ floorObject.put("name", i+ 1 + "楼");
|
|
|
|
+ floorObject.put("segment", new JSONArray());
|
|
|
|
+ floorObject.put("vertex", new JSONArray());
|
|
|
|
+
|
|
|
|
+ floorArr.add(floorObject);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ floors.put("floors", floorArr);
|
|
|
|
+ FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"floor.json",floors.toJSONString());
|
|
|
|
+ fYunFileService.uploadFile(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"floor.json", "data/data"+sceneNum+File.separator+"floor.json");
|
|
|
|
+ return ResultData.ok(sceneProEntity);
|
|
|
|
+ }
|
|
|
|
+}
|