|
@@ -0,0 +1,258 @@
|
|
|
+package com.fdkankan.scene.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.util.RuntimeUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.fdkankan.common.constant.ErrorCode;
|
|
|
+import com.fdkankan.common.constant.SceneKind;
|
|
|
+import com.fdkankan.common.constant.SceneStatus;
|
|
|
+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.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.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.Calendar;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.UUID;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+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
|
|
|
+ **/
|
|
|
+@Slf4j
|
|
|
+@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;
|
|
|
+ @Autowired
|
|
|
+ private RedisUtil redisUtil;
|
|
|
+ @Autowired
|
|
|
+ private RedisLockUtil redisLockUtil;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultData uploadMatterproData(String sceneName, String userName, String floor, String sceneKind, 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean lock = redisLockUtil.lock(RedisLockKey.LOCK_GET_MATTERPRO_NUM, RedisKey.EXPIRE_TIME_1_MINUTE);
|
|
|
+ if(!lock){
|
|
|
+ throw new BusinessException(ErrorCode.SYSTEM_BUSY);
|
|
|
+ }
|
|
|
+ Scene3dNumMatterPro numEntity = scene3dNumMatterProService.findSceneNum();
|
|
|
+ String sceneNum = numEntity.getCode();
|
|
|
+ numEntity.setUsed(1);
|
|
|
+ scene3dNumMatterProService.updateById(numEntity);
|
|
|
+ redisLockUtil.unlockLua(RedisLockKey.LOCK_GET_MATTERPRO_NUM);
|
|
|
+
|
|
|
+ String dataSource = ConstantFilePath.BUILD_MODEL_PATH + UUID.randomUUID() + File.separator ;
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ result.put("num", sceneNum);
|
|
|
+ result.put("dataSource", dataSource);
|
|
|
+ result.put("status", SceneStatus.wait.code());
|
|
|
+ String key = String.format(RedisKey.SCENE_UPLOAD_MATTERPRO_NUM, sceneNum);
|
|
|
+ redisUtil.set(key, result.toJSONString(), RedisKey.CAMERA_EXPIRE_7_TIME);
|
|
|
+
|
|
|
+ File data = new File(dataSource + file.getOriginalFilename());
|
|
|
+ if(!data.getParentFile().exists()){
|
|
|
+ data.getParentFile().mkdirs();
|
|
|
+ }
|
|
|
+ file.transferTo(data);
|
|
|
+
|
|
|
+ CompletableFuture.runAsync(() -> {
|
|
|
+ try {
|
|
|
+ if(file.getOriginalFilename().toLowerCase().endsWith(".zip")){
|
|
|
+ CreateObjUtil.unZip(dataSource + file.getOriginalFilename(), dataSource);
|
|
|
+ }
|
|
|
+ if(file.getOriginalFilename().toLowerCase().endsWith(".rar")){
|
|
|
+ CreateObjUtil.unRarWithPath(dataSource + file.getOriginalFilename(), dataSource);
|
|
|
+// log.info("解压rar开始");
|
|
|
+// String command = "unrar x " + dataSource + file.getOriginalFilename() + " " + dataSource;
|
|
|
+// RuntimeUtil.exec(command);
|
|
|
+// log.info("解压rar完毕:" + command);
|
|
|
+ }
|
|
|
+
|
|
|
+ Thread.sleep(2000L);
|
|
|
+
|
|
|
+ //删除压缩包
|
|
|
+ new File(dataSource + file.getOriginalFilename()).delete();
|
|
|
+
|
|
|
+ List<String> fileList = new ArrayList<>();
|
|
|
+ FileUtils.readfilePath(dataSource, fileList);
|
|
|
+ String ossPath = "";
|
|
|
+ Map<String, String> uploadMap = new HashMap<>();
|
|
|
+ for (String filePath : fileList) {
|
|
|
+ ossPath = filePath.replace(dataSource, "images/images" + sceneNum + "/");
|
|
|
+ if(ossPath.endsWith("/")){
|
|
|
+ ossPath = ossPath.substring(0, ossPath.lastIndexOf("/"));
|
|
|
+ }
|
|
|
+ uploadMap.put(filePath, ossPath);
|
|
|
+ }
|
|
|
+ fYunFileService.uploadMulFiles(uploadMap);
|
|
|
+
|
|
|
+ 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(SceneKind.FACE.code().equals(sceneKind) ? 3 : 10);
|
|
|
+ sceneProEntity.setSceneSource(14);
|
|
|
+ sceneProEntity.setBuildType("V3");
|
|
|
+ sceneProEntity.setCreateTime(Calendar.getInstance().getTime());
|
|
|
+ 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");
|
|
|
+ result.put("status", SceneStatus.NO_DISPLAY.code());
|
|
|
+ redisUtil.set(key, result.toJSONString(), RedisKey.CAMERA_EXPIRE_7_TIME);
|
|
|
+ }catch (Exception e){
|
|
|
+ result.put("status", SceneStatus.FAILD.code());
|
|
|
+ redisUtil.set(key, result.toJSONString(), RedisKey.CAMERA_EXPIRE_7_TIME);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ return ResultData.ok(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultData getUploadMatterproDataStatus(String num) {
|
|
|
+ String key = String.format(RedisKey.SCENE_UPLOAD_MATTERPRO_NUM, num);
|
|
|
+ String jsonStr = redisUtil.get(key);
|
|
|
+ if(StrUtil.isEmpty(jsonStr)){
|
|
|
+ throw new BusinessException(-1, "数据已过期,请前往个人中心查看");
|
|
|
+ }
|
|
|
+ JSONObject jsonObject = JSON.parseObject(jsonStr);
|
|
|
+ if(jsonObject.getInteger("status").equals(SceneStatus.NO_DISPLAY.code())){
|
|
|
+ ScenePro scenePro = sceneProService.findBySceneNum(num);
|
|
|
+ return ResultData.ok(scenePro);
|
|
|
+ }
|
|
|
+ return ResultData.ok(JSON.parseObject(jsonStr));
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+// List<String> fileList = new ArrayList<>();
|
|
|
+// FileUtils.readfilePath("F:\\test\\wwwroot\\1115", fileList);
|
|
|
+//// List<String> strings = FileUtil.listFileNames("F:\\test\\wwwroot\\1115");
|
|
|
+// fileList.stream().forEach(s-> System.out.println(s));
|
|
|
+// System.out.println(FileUtil.getPrefix("1115.rar"));
|
|
|
+ FileUtil.move(new File("F:\\test\\wwwroot\\1115"), new File("F:\\test\\wwwroot"), true);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+}
|