dsx 2 лет назад
Родитель
Сommit
25e56dbf99

+ 6 - 0
4dkankan-center-scene/pom.xml

@@ -47,6 +47,12 @@
         </dependency>
 
         <dependency>
+            <groupId>com.huaweicloud</groupId>
+            <artifactId>esdk-obs-java-bundle</artifactId>
+            <version>3.22.12</version>
+        </dependency>
+
+        <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-test</artifactId>
             <scope>test</scope>

+ 33 - 23
4dkankan-center-scene/src/main/java/com/fdkankan/scene/service/impl/SceneEditInfoServiceImpl.java

@@ -71,6 +71,7 @@ import com.fdkankan.scene.service.IScenePlusService;
 import com.fdkankan.scene.service.ISceneProExtService;
 import com.fdkankan.scene.service.ISceneProService;
 import com.fdkankan.scene.service.ISceneUploadService;
+import com.fdkankan.scene.util.ObsUtil;
 import com.fdkankan.scene.vo.BallScreenVideoParamVO;
 import com.fdkankan.scene.vo.BaseDataParamVO;
 import com.fdkankan.scene.vo.BaseFileParamVO;
@@ -157,6 +158,8 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
     private String URL_GET_SCENEPRO_BY_NUM;
     @Value("${http.api-v4.upgradeToV4ResultSync}")
     private String URL_UPGRADE_TO_V4_RESULT_SYNC;
+    @Value("${obs.use}")
+    private boolean obs;
 
     @Autowired
     private ISceneEditControlsService sceneEditControlsService;
@@ -182,6 +185,8 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
     private FdkankanMiniClient fdkankanMiniClient;
     @Autowired
     private ISceneUploadService sceneUploadService;
+    @Autowired
+    private ObsUtil obsUtil;
 
     @Transactional
     @Override
@@ -499,26 +504,26 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
      **/
     private SceneInfoVO getSceneInfo4View(String num) throws Exception{
 
-        // TODO: 2022/5/19 请求v3的接口,获取场景的状态 待v3停机后要换成v4d的逻辑-------------------------start
-        String url = fkankanMiniHost + URL_GET_SCENEPRO_BY_NUM + num + "&addViewCount=yes";
-        Result<SceneProV3> result = fdkankanMiniClient
-            .getSceneProByNum(url, new FdkkMiniReqSuccessCallback(),
-                new FdkkMiniReqErrorCallback());
-        SceneProV3 sceneProV3 = result.getData();
-        if(sceneProV3 == null || sceneProV3.getId() == null){
-            throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
-        }
-        if(sceneProV3.getRecStatus().equals("I")){
-            throw new BusinessException(ErrorCode.FAILURE_CODE_5009);
-        }
-        if((SceneStatus.SUCCESS.code() != sceneProV3.getStatus() && SceneStatus.NO_DISPLAY.code() != sceneProV3.getStatus())
-        || (sceneProV3.getIsUpgrade() != null && sceneProV3.getIsUpgrade()== 2)){
-            throw new BusinessException(ErrorCode.FAILURE_CODE_5033);
-        }
-        if(PayStatus.PAY.code() != sceneProV3.getPayStatus()){
-            throw new BusinessException(ErrorCode.FAILURE_CODE_5034);
-        }
-        // TODO: 2022/5/19 请求v3的接口,获取场景的状态 待v3停机后要换成v4d的逻辑-------------------------send
+//         TODO: 2022/5/19 请求v3的接口,获取场景的状态 待v3停机后要换成v4d的逻辑-------------------------start
+//        String url = fkankanMiniHost + URL_GET_SCENEPRO_BY_NUM + num + "&addViewCount=yes";
+//        Result<SceneProV3> result = fdkankanMiniClient
+//            .getSceneProByNum(url, new FdkkMiniReqSuccessCallback(),
+//                new FdkkMiniReqErrorCallback());
+//        SceneProV3 sceneProV3 = result.getData();
+//        if(sceneProV3 == null || sceneProV3.getId() == null){
+//            throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
+//        }
+//        if(sceneProV3.getRecStatus().equals("I")){
+//            throw new BusinessException(ErrorCode.FAILURE_CODE_5009);
+//        }
+//        if((SceneStatus.SUCCESS.code() != sceneProV3.getStatus() && SceneStatus.NO_DISPLAY.code() != sceneProV3.getStatus())
+//        || (sceneProV3.getIsUpgrade() != null && sceneProV3.getIsUpgrade()== 2)){
+//            throw new BusinessException(ErrorCode.FAILURE_CODE_5033);
+//        }
+//        if(PayStatus.PAY.code() != sceneProV3.getPayStatus()){
+//            throw new BusinessException(ErrorCode.FAILURE_CODE_5034);
+//        }
+//         TODO: 2022/5/19 请求v3的接口,获取场景的状态 待v3停机后要换成v4d的逻辑-------------------------send
 
 //        ScenePro scenePro = sceneProService.findBySceneNum(num);
         ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
@@ -536,7 +541,7 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
             sceneInfoVO = JSON.parseObject(sceneJson, SceneInfoVO.class);
             // TODO: 2022/4/24 v3版本停机要切换---------------------------start
 //        this.setExtData(sceneInfoVO, scenePlus.getCameraId());
-            this.setExtDataFromV3(sceneInfoVO, scenePlus.getCameraId());
+//            this.setExtDataFromV3(sceneInfoVO, scenePlus.getCameraId());
             // TODO: 2022/4/24 v3版本停机要切换---------------------------end
             sceneInfoVO.setScenePassword(null);
             if(Objects.isNull(sceneInfoVO.getFloorPlanAngle())){
@@ -551,13 +556,18 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
 
         //如果redis没找到,从scene.json中获取
         String objectName = String.format(ConstantFilePath.SCENE_VIEW_DATA_DATA_SCENEJSON, num);
-        String objectContent = uploadToOssUtil.getObjectContent(bucket, objectName);
+        String objectContent = null;
+        if(obs){
+            objectContent = obsUtil.getFileContent(bucket, objectName);
+        }else{
+            objectContent = uploadToOssUtil.getObjectContent(bucket, objectName);
+        }
         if(StrUtil.isEmpty(objectContent))
             return null;
         sceneInfoVO = JSON.parseObject(objectContent, SceneInfoVO.class);
         // TODO: 2022/4/24 v3版本停机要切换---------------------------start
 //        this.setExtData(sceneInfoVO, scenePlus.getCameraId());
-        this.setExtDataFromV3(sceneInfoVO, scenePlus.getCameraId());
+//        this.setExtDataFromV3(sceneInfoVO, scenePlus.getCameraId());
         // TODO: 2022/4/24 v3版本停机要切换---------------------------end
         if(Objects.isNull(sceneInfoVO.getFloorPlanAngle())){
             sceneInfoVO.setFloorPlanAngle(0f);

+ 64 - 0
4dkankan-center-scene/src/main/java/com/fdkankan/scene/util/ObsUtil.java

@@ -0,0 +1,64 @@
+package com.fdkankan.scene.util;
+
+import com.aliyun.oss.model.OSSObject;
+import com.amazonaws.services.s3.model.GetObjectRequest;
+import com.amazonaws.services.s3.model.S3Object;
+import com.amazonaws.services.s3.model.S3ObjectInputStream;
+import com.obs.services.ObsClient;
+import com.obs.services.model.ObsObject;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+@Slf4j
+@Configuration
+@ConditionalOnProperty(name = "obs.use", havingValue = "true")
+public class ObsUtil {
+
+    @Value("${obs.endPoint:#{null}}")
+    private String endPoint;
+
+    @Value("${obs.ak:#{null}}")
+    private String ak;
+
+    @Value("${obs.sk:#{null}}")
+    private String sk;
+
+    @Autowired
+    private ObsClient obsClient;
+
+    @Bean("obsClient")
+    public ObsClient initObsClient(){
+        return new ObsClient(ak, sk, endPoint);
+    }
+
+    public String getFileContent(String bucket, String objectname){
+        try {
+            ObsObject object = obsClient.getObject(bucket, objectname);
+            InputStream inputStream = object.getObjectContent();
+            StringBuilder content = new StringBuilder();
+            try(BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))){
+                while (true) {
+                    String line = reader.readLine();
+                    if (line == null) break;
+                    content.append(line);
+                }
+            } catch (IOException e) {
+                log.error("读取华为云文件流失败", e);
+            }
+            return content.toString();
+        } catch (Exception e) {
+            log.error("获取文件内容失败:{}", objectname, e);
+            return null;
+        }
+    }
+
+}