浏览代码

深时场景下载

lyhzzz 2 年之前
父节点
当前提交
b4f158bc95

+ 6 - 0
src/main/java/com/fdkankan/ucenter/common/constants/ResultCode.java

@@ -3,4 +3,10 @@ package com.fdkankan.ucenter.common.constants;
 public class ResultCode {
     public static final int FAILURE_CODE_400001 = 400001;
     public static final String FAILURE_MSG_400001 = "场景码池为空";
+    public static final int FAILURE_CODE_400002 = 400002;
+    public static final String FAILURE_MSG_400002 = "场景码不存在";
+    public static final int FAILURE_CODE_400003 = 400003;
+    public static final String FAILURE_MSG_400003 = "获取深时下载状态失败";
+    public static final int FAILURE_CODE_400004 = 400004;
+    public static final String FAILURE_MSG_400004 = "获取深时下载链接失败";
 }

+ 6 - 8
src/main/java/com/fdkankan/ucenter/controller/inner/InnerController.java

@@ -1,5 +1,7 @@
 package com.fdkankan.ucenter.controller.inner;
 
+import com.fdkankan.common.constant.ErrorCode;
+import com.fdkankan.common.exception.BusinessException;
 import com.fdkankan.ucenter.annotation.CheckInnerApiPermit;
 import com.fdkankan.ucenter.common.BaseController;
 import com.fdkankan.ucenter.common.Result;
@@ -86,15 +88,11 @@ public class InnerController extends BaseController {
      * 根据场景码获取场景码版本 深时使用
      */
     @GetMapping("/_getSceneNumVersion")
-    public Result getSceneNumVersion(@RequestParam(required = false) String num) throws Exception{
-        String version = innerService.getSceneNumVersion(num);
-        if(StringUtils.isBlank(version)){
-            return Result.failure("场景不存在");
+    public Result getSceneNumVersion(@RequestParam(required = false) String num){
+        if(StringUtils.isBlank(num)){
+            throw new BusinessException(ErrorCode.MISSING_REQUIRED_PARAMETERS);
         }
-        HashMap<String,String> map = new HashMap<>();
-        map.put("num",num);
-        map.put("version",version);
-        return Result.success(map);
+        return Result.success(innerService.getSceneInfo(num));
     }
 
 }

+ 11 - 0
src/main/java/com/fdkankan/ucenter/entity/User.java

@@ -117,6 +117,17 @@ public class User implements Serializable {
      */
     @TableField("download_num")
     private Integer downloadNum;
+    /**
+     * 深时可下载场景总数
+     */
+    @TableField("ss_download_num_total")
+    private Integer ssDownloadNumTotal;
+
+    /**
+     * 深时已下载场景总数
+     */
+    @TableField("ss_download_num")
+    private Integer ssDownloadNum;
 
     /**
      * 创建时间

+ 15 - 0
src/main/java/com/fdkankan/ucenter/httpClient/client/LaserClient.java

@@ -3,6 +3,7 @@ package com.fdkankan.ucenter.httpClient.client;
 import com.dtflys.forest.annotation.*;
 import com.fdkankan.ucenter.common.Result;
 import com.fdkankan.ucenter.httpClient.address.LaserAddressSource;
+import com.fdkankan.ucenter.httpClient.param.SSDownSceneParam;
 
 import java.util.List;
 import java.util.Map;
@@ -50,4 +51,18 @@ public interface LaserClient {
      */
     @Post("/laser/4dage/scene/getScenesBySnCode")
     Result getScenesBySnCode(@JSONBody Map<String, String> param, @Header("fdToken") String token) ;
+
+    /**
+     * 下载深时场景
+     * status :0:正在生成 1,初次生成  2,已经生成直接下载 3,重新生成
+     */
+    @Post("/laser/4dage/downOfflineScene")
+    Result downOfflineScene(@JSONBody SSDownSceneParam param) ;
+    /**
+     * 检测深时场景是否需要重新生成
+     *
+     * status :离线包状态是否需要重新生成 0未生成,1 不需要 2需要
+     */
+    @Post("/laser/4dage/downOfflineSceneStatus")
+    Result downOfflineSceneStatus(@JSONBody SSDownSceneParam param) ;
 }

+ 8 - 0
src/main/java/com/fdkankan/ucenter/httpClient/param/SSDownSceneParam.java

@@ -0,0 +1,8 @@
+package com.fdkankan.ucenter.httpClient.param;
+
+import lombok.Data;
+
+@Data
+public class SSDownSceneParam {
+    private String sceneCode;
+}

+ 38 - 0
src/main/java/com/fdkankan/ucenter/httpClient/service/LaserService.java

@@ -12,6 +12,8 @@ import com.fdkankan.ucenter.entity.Camera;
 import com.fdkankan.ucenter.entity.CameraDetail;
 import com.fdkankan.ucenter.entity.User;
 import com.fdkankan.ucenter.httpClient.client.LaserClient;
+import com.fdkankan.ucenter.httpClient.param.SSDownSceneParam;
+import com.fdkankan.ucenter.httpClient.vo.SSDownSceneVo;
 import com.fdkankan.ucenter.service.ICameraService;
 import com.fdkankan.ucenter.service.IUserService;
 import com.fdkankan.ucenter.vo.SceneBySnCodeVo;
@@ -218,5 +220,41 @@ public class LaserService {
         }
         return sceneVo ;
     }
+    public SSDownSceneVo downOfflineSceneStatus(String num) {
+        try {
+            SSDownSceneVo vo ;
+            SSDownSceneParam param = new SSDownSceneParam();
+            param.setSceneCode(num);
+            Result responseEntity = laserClient.downOfflineSceneStatus(param);
+            if( responseEntity.getCode() != HttpStatus.OK.value()){
+                log.error("downOfflineSceneStatus-根据场景码获取激光转台下载状态失败:{}",responseEntity);
+                return null;
+            }
+            vo = JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getData()), SSDownSceneVo.class);
+            return vo;
+
+        }catch (Exception e){
+            log.error("downOfflineSceneStatus-根据场景码获取激光转台下载状态失败!",e);
+        }
+        return null ;
+    }
+
+    public SSDownSceneVo downOfflineScene(String num) {
+        try {
+            SSDownSceneVo vo ;
+            SSDownSceneParam param = new SSDownSceneParam();
+            param.setSceneCode(num);
+            Result responseEntity = laserClient.downOfflineScene(param);
+            if( responseEntity.getCode() != HttpStatus.OK.value()){
+                log.error("downOfflineScene-根据场景码获取激光转台下载失败:{}",responseEntity);
+                return null;
+            }
+            vo = JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getData()), SSDownSceneVo.class);
+            return vo ;
+        }catch (Exception e){
+            log.error("downOfflineScene-根据场景码获取激光转台下载状态失败!",e);
+        }
+        return null ;
+    }
 
 }

+ 10 - 0
src/main/java/com/fdkankan/ucenter/httpClient/vo/SSDownSceneVo.java

@@ -0,0 +1,10 @@
+package com.fdkankan.ucenter.httpClient.vo;
+
+import lombok.Data;
+
+@Data
+public class SSDownSceneVo {
+                                //离线包状态是否需要重新生成 1 不需要 2需要
+    private Integer status;     //0:正在生成 1,初次生成  2,已经生成直接下载 3,重新生成
+    private String url;         //下载地址
+}

+ 3 - 0
src/main/java/com/fdkankan/ucenter/service/IInnerService.java

@@ -1,6 +1,7 @@
 package com.fdkankan.ucenter.service;
 
 import com.fdkankan.ucenter.common.Result;
+import com.fdkankan.ucenter.vo.response.LaserSceneInfoVo;
 
 /**
  * <p>
@@ -21,4 +22,6 @@ public interface IInnerService {
     Result downloadCapture(String num);
 
     Result querySceneNum(String path);
+
+    LaserSceneInfoVo getSceneInfo(String num);
 }

+ 108 - 0
src/main/java/com/fdkankan/ucenter/service/impl/DownService.java

@@ -1,14 +1,18 @@
 package com.fdkankan.ucenter.service.impl;
 
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.fdkankan.common.constant.ErrorCode;
 import com.fdkankan.common.constant.SceneConstant;
 import com.fdkankan.common.exception.BusinessException;
 import com.fdkankan.redis.constant.RedisKey;
 import com.fdkankan.redis.util.RedisUtil;
 import com.fdkankan.ucenter.common.DownloadStatusEnum;
+import com.fdkankan.ucenter.common.constants.ResultCode;
 import com.fdkankan.ucenter.constant.LoginConstant;
 import com.fdkankan.ucenter.entity.*;
+import com.fdkankan.ucenter.httpClient.service.LaserService;
+import com.fdkankan.ucenter.httpClient.vo.SSDownSceneVo;
 import com.fdkankan.ucenter.service.*;
 import com.fdkankan.ucenter.vo.response.DownVo;
 import com.fdkankan.ucenter.vo.response.DownloadProcessVo;
@@ -37,6 +41,8 @@ public class DownService implements IDownService {
     ISceneEditInfoService sceneEditInfoService;
     @Autowired
     IUserService userService;
+    @Autowired
+    LaserService laserService;
 
 
     @Override
@@ -49,6 +55,11 @@ public class DownService implements IDownService {
         if(scenePro == null && plus == null){
             throw new BusinessException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
         }
+        Integer sceneType = scenePro !=null ? scenePro.getSceneType() : plus.getSceneType();
+
+        if(sceneType == 10){ //深时场景
+            return SSCheckDownload(sceneNum);
+        }
         SceneDownloadLog sceneDownloadLog;
         int isUp = 0;
         if(scenePro == null){
@@ -82,6 +93,7 @@ public class DownService implements IDownService {
         return downVo;
     }
 
+
     private Integer getSceneVersion(ScenePro scenePro,ScenePlus scenePlus){
         Integer version = 0;
         if(scenePro != null){
@@ -111,6 +123,11 @@ public class DownService implements IDownService {
         if(scenePro == null && scenePlus == null){
             throw new BusinessException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
         }
+        Integer sceneType = scenePro !=null ? scenePro.getSceneType() : scenePlus.getSceneType();
+
+        if(sceneType == 10){ //深时场景
+            return SSDownload(sceneNum,userName);
+        }
         DownVo downVo = new DownVo();
         User user = userService.getByUserName(userName);
         if(user == null || user.getDownloadNumTotal() - user.getDownloadNum() <= 0){
@@ -162,6 +179,11 @@ public class DownService implements IDownService {
         if(scenePro == null && scenePlus == null){
             throw new BusinessException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
         }
+        Integer sceneType = scenePro !=null ? scenePro.getSceneType() : scenePlus.getSceneType();
+
+        if(sceneType == 10){ //深时场景
+            return SSDownloadProcess(sceneNum);
+        }
         String redisKey = RedisKey.PREFIX_DOWNLOAD_PROGRESS;
         if(scenePro == null){
             redisKey = RedisKey.PREFIX_DOWNLOAD_PROGRESS_V4;
@@ -199,4 +221,90 @@ public class DownService implements IDownService {
     }
 
 
+    /**
+     * downloadStatus  1 未下载过,2下载过有修改 ,3下载过没修改
+     */
+    private DownVo SSCheckDownload(String sceneNum) {
+        DownVo downVo = new DownVo();
+        SSDownSceneVo vo = laserService.downOfflineSceneStatus(sceneNum);
+        if(vo == null){
+            throw new BusinessException(ResultCode.FAILURE_CODE_400003,ResultCode.FAILURE_MSG_400003);
+        }
+        downVo.setDownloadStatus(1);
+        if(vo.getStatus() == 1){
+            downVo.setDownloadStatus(3);
+            downVo.setDownloadUrl(vo.getUrl());
+        }
+        if(vo.getStatus() == 2){
+            downVo.setDownloadStatus(2);
+        }
+        return downVo;
+    }
+
+    /**
+     * downloadStatus -1下载失败  1下载成功
+     */
+    private DownVo SSDownload(String sceneNum,String userName) {
+        DownVo downVo = new DownVo();
+
+        User user = userService.getByUserName(userName);
+        if(user == null || user.getSsDownloadNumTotal() - user.getSsDownloadNum() <= 0){
+            downVo.setDownloadStatus(-1);
+            return downVo;
+        }
+        SSDownSceneVo vo = laserService.downOfflineScene(sceneNum);
+        if(vo == null){
+            throw new BusinessException(ResultCode.FAILURE_CODE_400003,ResultCode.FAILURE_MSG_400003);
+        }
+        LambdaUpdateWrapper<User> wrapper = new LambdaUpdateWrapper<>();
+        wrapper.eq(User::getId,user.getId());
+        wrapper.set(User::getSsDownloadNum ,user.getSsDownloadNum() + 1);
+        userService.update(wrapper);
+
+        SceneDownloadLog sceneDownloadLogEntity = new SceneDownloadLog();
+        sceneDownloadLogEntity.setUserId(user.getId());
+        sceneDownloadLogEntity.setSceneNum(sceneNum);
+        sceneDownloadLogEntity.setSceneVersion(0);
+        sceneDownloadLogEntity.setStatus(0);
+        sceneDownloadLogEntity.setSysVersion("ss");
+        sceneDownloadLogService.save(sceneDownloadLogEntity);
+        downVo.setDownloadStatus(1);
+        return downVo;
+    }
+
+    public static HashMap<String,Integer> ssNumProcessNumMap = new HashMap<>();
+
+    private DownloadProcessVo SSDownloadProcess(String sceneNum) {
+        DownloadProcessVo downVo = new DownloadProcessVo();
+        SSDownSceneVo vo = laserService.downOfflineSceneStatus(sceneNum);
+        if(vo == null){
+            throw new BusinessException(ResultCode.FAILURE_CODE_400003,ResultCode.FAILURE_MSG_400003);
+        }
+        downVo.setStatus(1003);
+        if(vo.getStatus() == 0){    //下载中
+            ssNumProcessNumMap.merge(sceneNum, 2, Integer::sum);
+            Integer percent = ssNumProcessNumMap.get(sceneNum);
+            if(percent >100){
+                percent = 99;
+            }
+            downVo.setStatus(1001);
+            downVo.setPercent(percent);
+        }
+        if(vo.getStatus() == 1){    //下载完成
+            downVo.setPercent(100);
+            downVo.setUrl(vo.getUrl());
+            downVo.setStatus(1002);
+
+            LambdaUpdateWrapper<SceneDownloadLog> wrapper = new LambdaUpdateWrapper<>();
+            wrapper.eq(SceneDownloadLog::getSceneNum,sceneNum);
+            wrapper.eq(SceneDownloadLog::getStatus,0);
+            wrapper.set(SceneDownloadLog::getDownloadUrl,vo.getUrl());
+            wrapper.set(SceneDownloadLog::getStatus,1);
+            sceneDownloadLogService.update(wrapper);
+        }
+        return downVo;
+    }
+
+
+
 }

+ 3 - 5
src/main/java/com/fdkankan/ucenter/service/impl/IncrementOrderServiceImpl.java

@@ -55,8 +55,6 @@ public class IncrementOrderServiceImpl extends ServiceImpl<IIncrementOrderMapper
     IGoodsSkuService goodsSkuService;
     @Autowired
     IIncrementTypeService incrementTypeService;
-    @Value("${environment}")
-    private String environment;
 
     @Override
     public PageInfo pageList(IncrementOrderParam param) {
@@ -98,17 +96,17 @@ public class IncrementOrderServiceImpl extends ServiceImpl<IIncrementOrderMapper
         GoodsSkuVo goodsSkuVo = new GoodsSkuVo();
         IncrementType incrementType = null;
         switch (dateType){
-            case 5 : incrementType = incrementTypeService.getByType(environment).get(0);
+            case 5 : incrementType = incrementTypeService.list().get(0);
                 goodsSkuVo.setPrice(incrementType.getPrice());
                 goodsSkuVo.setSkuSn(incrementType.getId().toString());
                 goodsSkuVo.setDeadLine(getDateTime(incrementType,userIncrementId,monthDy).toDate().getTime());
                 break;
-            case 6: incrementType = incrementTypeService.getByType(environment).get(0);
+            case 6: incrementType = incrementTypeService.list().get(0);
                 goodsSkuVo.setPrice(incrementType.getDownloadPrice());
                 goodsSkuVo.setSkuSn(incrementType.getId().toString());
                 goodsSkuVo.setDeadLine(getDateTime(incrementType,userIncrementId,monthDy).toDate().getTime());
                 break;
-            case 7 : incrementType = incrementTypeService.getByType(environment).get(1);
+            case 7 : incrementType = incrementTypeService.list().get(1);
                 goodsSkuVo.setPrice(incrementType.getPrice());
                 goodsSkuVo.setSkuSn(incrementType.getId().toString());
                 goodsSkuVo.setDeadLine(getDateTime(incrementType,userIncrementId,monthDy).toDate().getTime());

+ 33 - 2
src/main/java/com/fdkankan/ucenter/service/impl/InnerServiceImpl.java

@@ -3,23 +3,24 @@ package com.fdkankan.ucenter.service.impl;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.fdkankan.common.constant.ErrorCode;
+import com.fdkankan.common.exception.BusinessException;
 import com.fdkankan.common.util.JwtUtil;
 import com.fdkankan.fyun.face.FYunFileServiceInterface;
 import com.fdkankan.redis.constant.RedisKey;
 import com.fdkankan.redis.util.RedisUtil;
 import com.fdkankan.ucenter.common.Result;
 import com.fdkankan.ucenter.common.constants.ConstantFilePath;
+import com.fdkankan.ucenter.common.constants.ResultCode;
 import com.fdkankan.ucenter.entity.ScenePlus;
 import com.fdkankan.ucenter.entity.ScenePlusExt;
 import com.fdkankan.ucenter.entity.ScenePro;
 import com.fdkankan.ucenter.entity.User;
 import com.fdkankan.ucenter.service.*;
+import com.fdkankan.ucenter.vo.response.LaserSceneInfoVo;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.ObjectUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
-import org.springframework.web.client.RestTemplate;
 
 import java.io.File;
 import java.util.Objects;
@@ -147,4 +148,34 @@ public class InnerServiceImpl implements IInnerService {
         }
         return null;
     }
+
+    @Override
+    public LaserSceneInfoVo getSceneInfo(String num) {
+        LaserSceneInfoVo vo = new LaserSceneInfoVo();
+        ScenePro scenepro = sceneProService.getByNum(num);
+        if(scenepro != null){
+            vo.setNum(scenepro.getNum());
+            vo.setVersion("V3");
+            vo.setSceneSource(scenepro.getSceneSource());
+            vo.setSceneScheme(scenepro.getSceneScheme());
+            vo.setSceneKind(null);
+            vo.setSceneResolution(null);
+            return vo;
+        }
+
+        ScenePlus plus = scenePlusService.getByNum(num);
+        if(plus != null){
+            ScenePlusExt plusExt = scenePlusExtService.getByPlusId(plus.getId());
+            if(plusExt != null){
+                vo.setNum(plus.getNum());
+                vo.setVersion("V3");
+                vo.setSceneSource(plus.getSceneSource());
+                vo.setSceneScheme(plusExt.getSceneScheme());
+                vo.setSceneKind(plusExt.getSceneKind());
+                vo.setSceneResolution(plusExt.getSceneResolution());
+                return vo;
+            }
+        }
+        throw new BusinessException(ResultCode.FAILURE_CODE_400002,ResultCode.FAILURE_MSG_400002);
+    }
 }

+ 13 - 0
src/main/java/com/fdkankan/ucenter/vo/response/LaserSceneInfoVo.java

@@ -0,0 +1,13 @@
+package com.fdkankan.ucenter.vo.response;
+
+import lombok.Data;
+
+@Data
+public class LaserSceneInfoVo {
+    private String num;
+    private String version;
+    private Integer sceneSource;
+    private Integer sceneScheme;
+    private String sceneKind;
+    private String sceneResolution;
+}