Selaa lähdekoodia

思维 下载接口

dengsixing 2 vuotta sitten
vanhempi
commit
e033e2c493

+ 6 - 1
pom.xml

@@ -34,7 +34,7 @@
         <dependency>
             <groupId>com.fdkankan</groupId>
             <artifactId>4dkankan-utils-redis</artifactId>
-            <version>2.0.0-SNAPSHOT</version>
+            <version>3.0.0-SNAPSHOT</version>
         </dependency>
 
 
@@ -92,6 +92,11 @@
             <version>3.0.0-SNAPSHOT</version>
         </dependency>
 
+        <dependency>
+            <groupId>com.fdkankan</groupId>
+            <artifactId>4dkankan-utils-model</artifactId>
+            <version>3.0.0-SNAPSHOT</version>
+        </dependency>
 
         <dependency>
             <groupId>org.springframework.boot</groupId>

+ 131 - 0
src/main/java/com/fdkankan/ucenter/controller/app/SceneApiController.java

@@ -1,18 +1,30 @@
 package com.fdkankan.ucenter.controller.app;
 
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.core.util.ZipUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.fdkankan.common.constant.ErrorCode;
 import com.fdkankan.common.constant.SceneConstant;
 import com.fdkankan.common.exception.BusinessException;
+import com.fdkankan.common.util.DateExtUtil;
 import com.fdkankan.common.util.DateUtil;
+import com.fdkankan.common.util.FileUtils;
 import com.fdkankan.common.util.SecurityUtil;
+import com.fdkankan.fyun.face.FYunFileServiceInterface;
+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.ucenter.common.BaseController;
 import com.fdkankan.ucenter.common.Result;
+import com.fdkankan.ucenter.common.constants.ConstantFilePath;
 import com.fdkankan.ucenter.constant.LoginConstant;
 import com.fdkankan.ucenter.entity.Camera;
 import com.fdkankan.ucenter.entity.CameraDetail;
 import com.fdkankan.ucenter.entity.ScenePlus;
 import com.fdkankan.ucenter.entity.ScenePro;
+import com.fdkankan.ucenter.entity.SceneProEdit;
 import com.fdkankan.ucenter.entity.User;
 import com.fdkankan.ucenter.service.ICameraDetailService;
 import com.fdkankan.ucenter.service.ICameraService;
@@ -20,6 +32,7 @@ import com.fdkankan.ucenter.service.IScene3dNumService;
 import com.fdkankan.ucenter.service.ISceneCooperationService;
 import com.fdkankan.ucenter.service.IScenePlusExtService;
 import com.fdkankan.ucenter.service.IScenePlusService;
+import com.fdkankan.ucenter.service.ISceneProEditService;
 import com.fdkankan.ucenter.service.ISceneProService;
 import com.fdkankan.ucenter.service.ISceneStatisticsService;
 import com.fdkankan.ucenter.service.IUserService;
@@ -27,7 +40,10 @@ import com.fdkankan.ucenter.service.impl.LoginService;
 import com.fdkankan.ucenter.vo.request.LoginParam;
 import com.fdkankan.ucenter.vo.request.RequestSceneStatistics;
 import com.fdkankan.ucenter.vo.response.LoginVo;
+import com.fdkankan.ucenter.vo.response.SceneInfoVo;
 import com.fdkankan.ucenter.vo.response.UserVo;
+import com.sun.xml.bind.v2.TODO;
+import java.io.File;
 import java.net.URLEncoder;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -35,12 +51,15 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
+import org.joda.time.DateTime;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
@@ -70,6 +89,11 @@ public class SceneApiController extends BaseController {
     @Autowired
     private ISceneStatisticsService sceneStatisticsService;
     @Autowired
+    private RedisLockUtil redisLockUtil;
+    @Autowired
+    private ISceneProEditService sceneProEditService;
+    @Autowired
+    private FYunFileServiceInterface fYunFileService;
 
     @Value("${main.url}")
     private String mainUrl;
@@ -86,6 +110,7 @@ public class SceneApiController extends BaseController {
     @Value("${scene.v4.url}")
     private String sceneProV4Url;
 
+
     /**
      * 获取指定场景信息
      * @param num 场景码
@@ -256,5 +281,111 @@ public class SceneApiController extends BaseController {
             param.getSceneNum(), param.getType()));
     }
 
+    /**
+     * 下载思为的html页面
+     */
+    @GetMapping(value = "/downloadSiWeiHtml")
+    public Result downloadSiWeiHtml(HttpServletRequest request) throws Exception{
+        String token = getToken();
+        if(StringUtils.isEmpty(token)){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_3004);
+        }
+
+        User user = userService.getByToken(token);
+        if(user == null){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_3004);
+        }
+
+        String sceneNum = request.getParameter("sceneNum");
+        if(StringUtils.isEmpty(sceneNum)){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
+        }
+
+        //获取getInfo的数据
+        ScenePro sceneProEntity = sceneProService.getByNum(sceneNum);
+        if(sceneProEntity == null){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
+        }
+        if(sceneProEntity.getPayStatus() != 1){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
+        }
+        if(sceneProEntity.getStatus() != 1 && sceneProEntity.getStatus() != -2){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
+        }
+
+        if(user.getId().longValue() != sceneProEntity.getUserId().longValue()){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
+        }
+
+        boolean lock = redisLockUtil.lock(RedisLockKey.LOCK_DOWNLOAD_SIWEI_HTML, RedisKey.EXPIRE_TIME_2_HOUR);
+        if(!lock){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_5024, SceneConstant.FAILURE_MSG_5024);
+        }
+
+        try{
+            SceneInfoVo responseScene = new SceneInfoVo();
+            SceneProEdit editEntity = sceneProEditService.getByProId(sceneProEntity.getId());
+
+            FileUtil.copyContent(new File(ConstantFilePath.BASE_PATH + "/local/localHose"), new File(ConstantFilePath.BASE_PATH + "/local/localHose" + sceneNum), true);
+
+            //14表示matterPro场景,需要调用命令获取切图,并且修改sceneScheme为13
+            if(sceneProEntity.getSceneSource() == 14){
+                sceneProEntity.setSceneScheme(13);
+                CreateObjUtil.matterproCutImg(sceneProEntity.getNum(), ConstantFilePath.BASE_PATH + "/local/localHose" + sceneNum);
+            }
+
+            BeanUtils.copyProperties(editEntity, responseScene);
+            BeanUtils.copyProperties(sceneProEntity, responseScene);
+            if(StrUtil.isNotEmpty(editEntity.getEntry())){
+                responseScene.setEntry(JSONObject.parseObject(editEntity.getEntry()).toJSONString());
+            }
+
+            if(StrUtil.isNotEmpty(sceneProEntity.getGps())){
+                responseScene.setGps(JSONObject.parseObject(sceneProEntity.getGps()).toJSONString());
+            }
+
+            responseScene.setCreateTime(sceneProEntity.getCreateTime());
+            responseScene.setCreateDate(DateExtUtil.parse(sceneProEntity.getCreateTime(), DateExtUtil.dateStyle).getTime());
+            if(StrUtil.isEmpty(editEntity.getSceneKey())){
+                responseScene.setIsPublic(0);
+            }else {
+                responseScene.setIsPublic(1);
+            }
+
+            //不返回场景访问密码
+            responseScene.setSceneKey("");
+
+            //替换index.html里面的场景码
+            String indexPath = ConstantFilePath.BASE_PATH + "/local/localHose" + sceneNum + File.separator + "embed.html";
+            String index = FileUtils.readFile(indexPath);
+            FileUtils.deleteFile(indexPath);
+            FileUtils.writeFile(indexPath, index.replace("__ProjectNum__", sceneNum));
+
+            //下载oss资源
+            fYunFileService.downloadFileByCommand(ConstantFilePath.BASE_PATH + "/local/localHose" + sceneNum + "/data", "data/data" + sceneNum);
+            fYunFileService.downloadFileByCommand(ConstantFilePath.BASE_PATH + "/local/localHose" + sceneNum + "/images", "images/images" + sceneNum);
+            fYunFileService.downloadFileByCommand(ConstantFilePath.BASE_PATH + "/local/localHose" + sceneNum + "/video", "video/video" + sceneNum);
+            fYunFileService.downloadFileByCommand(ConstantFilePath.BASE_PATH + "/local/localHose" + sceneNum + "/voice", "voice/voice" + sceneNum);
+
+            FileUtils.writeFile(ConstantFilePath.BASE_PATH + "/local/localHose" + sceneNum + "/data/data" + sceneNum + "/getInfo.json",
+                JSONObject.toJSONString(responseScene));
+
+            CreateObjUtil.callshell("bash /opt/ossutil/gzip.sh " + ConstantFilePath.BASE_PATH + "/local/localHose" + sceneNum +
+                " " + ConstantFilePath.BASE_PATH + "/local/localHose" + sceneNum);
+
+            ZipUtil.zip(ConstantFilePath.BASE_PATH + "/local/localHose" + sceneNum,  ConstantFilePath.BASE_PATH + "/local/localHose" + sceneNum + ".zip");
+
+            FileUtils.deleteDirectory(ConstantFilePath.BASE_PATH + "/local/localHose" + sceneNum);
+
+            return Result.success((Object)"local/localHose" + sceneNum + ".zip");
+        }catch (Exception e){
+            e.printStackTrace();
+            return Result.failure(LoginConstant.ERROR_MSG);
+        }finally {
+            redisLockUtil.unlockLua(RedisLockKey.LOCK_DOWNLOAD_SIWEI_HTML);
+        }
+
+    }
+
 
 }