Prechádzať zdrojové kódy

请求laser接口修改场景信息

dengsixing 2 rokov pred
rodič
commit
5a9b22e622

+ 7 - 0
pom.xml

@@ -131,6 +131,13 @@
             </exclusions>
         </dependency>
 
+        <dependency>
+            <groupId>com.dtflys.forest</groupId>
+            <artifactId>forest-spring-boot-starter</artifactId>
+            <version>1.5.26</version>
+        </dependency>
+
+
     </dependencies>
 
     <dependencyManagement>

+ 26 - 0
src/main/java/com/fdkankan/scene/bean/LaserSceneBean.java

@@ -0,0 +1,26 @@
+package com.fdkankan.scene.bean;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * <p>
+ * TODO
+ * </p>
+ *
+ * @author dengsixing
+ * @since 2022/9/27
+ **/
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class LaserSceneBean {
+
+    private String title;
+
+    private String thumb;
+
+}

+ 19 - 0
src/main/java/com/fdkankan/scene/constant/LaserApiConstant.java

@@ -0,0 +1,19 @@
+package com.fdkankan.scene.constant;
+
+/**
+ * <p>
+ * TODO
+ * </p>
+ *
+ * @author dengsixing
+ * @since 2022/9/27
+ **/
+public class LaserApiConstant {
+
+    /**
+     * %s 场景码
+     */
+    public static String EDIT_SCENE = "/laser/4dage/editTitleOrThumb/%s";
+
+
+}

+ 0 - 57
src/main/java/com/fdkankan/scene/httpclient/FdkankanMiniClient.java

@@ -1,57 +0,0 @@
-//package com.fdkankan.scene.httpclient;
-//
-//import com.dtflys.forest.annotation.Get;
-//import com.dtflys.forest.annotation.Header;
-//import com.dtflys.forest.annotation.Post;
-//import com.dtflys.forest.annotation.Retry;
-//import com.dtflys.forest.annotation.Success;
-//import com.dtflys.forest.annotation.Var;
-//import com.dtflys.forest.callback.OnError;
-//import com.dtflys.forest.callback.OnSuccess;
-//import com.fdkankan.common.response.Result;
-//import java.util.Map;
-//import com.fdkankan.scene.bean.CameraBean;
-//import com.fdkankan.scene.bean.UserIncrementBean;
-//import com.fdkankan.scene.callback.FdkkMiniReqSuccessCondition;
-//
-///**
-// * <p>
-// * -
-// * </p>
-// *
-// * @author dengsixing
-// * @since 2022/4/24
-// **/
-//@Success(condition = FdkkMiniReqSuccessCondition.class)
-//public interface FdkankanMiniClient {
-//
-//    @Get(url="{url}"
-////        ,interceptor = TLogForestInterceptor.class    加这个拦截器,打印的tlog日志会详细一些,包括头信息等等
-//    )
-//    @Retry(maxRetryCount = "3", maxRetryInterval = "100")
-//    Result<String> getDataSyncType(@Var("url") String url, OnSuccess<Result> onSuccess, OnError onError);
-//
-//    @Get("{url}")
-//    @Retry(maxRetryCount = "3", maxRetryInterval = "100")
-//    Result<UserIncrementBean> getUserIncrementByCameraId(@Var("url") String url, OnSuccess<Result> onSuccess, OnError onError);
-//
-//    @Get("{url}")
-//    @Retry(maxRetryCount = "3", maxRetryInterval = "100")
-//    Result<CameraBean> getCameraByCameraId(@Var("url") String url, OnSuccess<Result> onSuccess, OnError onError);
-//
-////    @Get(url="{url}")
-////    @Retry(maxRetryCount = "3", maxRetryInterval = "100")
-////    Result<SceneProV3> getSceneProByNum(@Var("url") String url, OnSuccess<Result> onSuccess, OnError onError);
-//
-//    @Post(url="{url}")
-//    @Retry(maxRetryCount = "3", maxRetryInterval = "100")
-//    Result<Map<String, Object>> getIsLogin(@Var("url") String url, @Header("token") String token, OnSuccess<Result> onSuccess, OnError onError);
-//
-////    @Post(
-////        url = "${url}",
-////        contentType = "application/json"
-////    )
-////    @Retry(maxRetryCount = "3", maxRetryInterval = "100")
-////    Result upgradeToV4ResultSync(@Var("url") String url, @Body RequestSceneProV4 param, OnSuccess<Result> onSuccess, OnError onError);
-//
-//}

+ 17 - 0
src/main/java/com/fdkankan/scene/service/ILaserService.java

@@ -0,0 +1,17 @@
+package com.fdkankan.scene.service;
+
+import com.fdkankan.scene.bean.LaserSceneBean;
+
+/**
+ * <p>
+ * TODO
+ * </p>
+ *
+ * @author dengsixing
+ * @since 2022/9/27
+ **/
+public interface ILaserService {
+
+    public void editScene(String num, LaserSceneBean sceneBean);
+
+}

+ 50 - 0
src/main/java/com/fdkankan/scene/service/impl/LaserServiceImpl.java

@@ -0,0 +1,50 @@
+package com.fdkankan.scene.service.impl;
+
+import cn.hutool.core.io.FileUtil;
+import com.alibaba.fastjson.JSONObject;
+import com.fdkankan.scene.bean.LaserSceneBean;
+import com.fdkankan.scene.config.FdkkLaserConfig;
+import com.fdkankan.scene.constant.LaserApiConstant;
+import com.fdkankan.scene.service.ILaserService;
+import com.fdkankan.scene.util.forest.ErrorCallback;
+import com.fdkankan.scene.util.forest.HttpClient;
+import com.fdkankan.scene.util.forest.SuccessCallback;
+import java.io.File;
+import javax.annotation.PostConstruct;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ * TODO
+ * </p>
+ *
+ * @author dengsixing
+ * @since 2022/9/27
+ **/
+@Service
+public class LaserServiceImpl implements ILaserService {
+
+    @Autowired
+    private HttpClient httpClient;
+    @Autowired
+    private FdkkLaserConfig fdkkLaserConfig;
+
+    private String host = "127.0.0.1";
+    private int port;
+
+    @PostConstruct
+    public void initAddress(){
+        String setting = fdkkLaserConfig.getBinPath() + File.separator + "setting.json";
+        String data = FileUtil.readUtf8String(setting);
+        JSONObject config = JSONObject.parseObject(data);
+        this.port = config.getIntValue("javaPort");
+    }
+
+
+    @Override
+    public void editScene(String num, LaserSceneBean sceneBean) {
+        String api = String.format(LaserApiConstant.EDIT_SCENE, num);
+        httpClient.postJson(host, port, api, sceneBean, new SuccessCallback(), new ErrorCallback());
+    }
+}

+ 7 - 0
src/main/java/com/fdkankan/scene/service/impl/SceneEditInfoServiceImpl.java

@@ -27,6 +27,7 @@ import com.fdkankan.redis.constant.RedisLockKey;
 import com.fdkankan.redis.util.RedisLockUtil;
 import com.fdkankan.redis.util.RedisUtil;
 import com.fdkankan.scene.bean.BoxPhotoBean;
+import com.fdkankan.scene.bean.LaserSceneBean;
 import com.fdkankan.scene.bean.PointBean;
 import com.fdkankan.scene.bean.SceneJsonBean;
 import com.fdkankan.scene.bean.SegmentBean;
@@ -41,6 +42,7 @@ import com.fdkankan.scene.entity.ScenePlus;
 import com.fdkankan.scene.entity.ScenePlusExt;
 import com.fdkankan.scene.mapper.ISceneEditInfoMapper;
 import com.fdkankan.scene.oss.OssUtil;
+import com.fdkankan.scene.service.ILaserService;
 import com.fdkankan.scene.service.ISceneDataDownloadService;
 import com.fdkankan.scene.service.ISceneEditControlsService;
 import com.fdkankan.scene.service.ISceneEditInfoExtService;
@@ -130,6 +132,8 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
     private ISceneUploadService sceneUploadService;
     @Autowired
     private OssUtil ossUtil;
+    @Autowired
+    private ILaserService laserService;
 
 
     @Transactional
@@ -170,6 +174,9 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
             }
         }
 
+        //修改laser场景主表的缩略图地址
+        laserService.editScene(param.getNum(), LaserSceneBean.builder().title(sceneEditInfo.getTitle()).build());
+
         SceneEditInfoVO result = BeanUtil.copyProperties(param, SceneEditInfoVO.class);
         result.setCreateTime(sceneEditInfo.getCreateTime());
 

+ 9 - 0
src/main/java/com/fdkankan/scene/service/impl/SceneProServiceImpl.java

@@ -22,13 +22,16 @@ import com.fdkankan.redis.constant.RedisLockKey;
 import com.fdkankan.redis.util.RedisLockUtil;
 import com.fdkankan.redis.util.RedisUtil;
 import com.fdkankan.scene.bean.IconBean;
+import com.fdkankan.scene.bean.LaserSceneBean;
 import com.fdkankan.scene.bean.TagBean;
+import com.fdkankan.scene.constant.LaserApiConstant;
 import com.fdkankan.scene.entity.SceneEditInfo;
 import com.fdkankan.scene.entity.ScenePlus;
 import com.fdkankan.scene.entity.ScenePlusExt;
 import com.fdkankan.scene.entity.ScenePro;
 import com.fdkankan.scene.mapper.ISceneProMapper;
 import com.fdkankan.scene.oss.OssUtil;
+import com.fdkankan.scene.service.ILaserService;
 import com.fdkankan.scene.service.ISceneDataDownloadService;
 import com.fdkankan.scene.service.ISceneEditControlsService;
 import com.fdkankan.scene.service.ISceneEditInfoService;
@@ -36,6 +39,7 @@ import com.fdkankan.scene.service.IScenePlusExtService;
 import com.fdkankan.scene.service.IScenePlusService;
 import com.fdkankan.scene.service.ISceneProService;
 import com.fdkankan.scene.service.ISceneUploadService;
+import com.fdkankan.scene.util.forest.HttpClient;
 import com.fdkankan.scene.vo.BaseDataParamVO;
 import com.fdkankan.scene.vo.DeleteFileParamVO;
 import com.fdkankan.scene.vo.DeleteHotIconParamVO;
@@ -111,6 +115,8 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
     private ISceneUploadService sceneUploadService;
     @Autowired
     private OssUtil ossUtil;
+    @Autowired
+    private ILaserService laserService;
 
     @Transactional
     @Override
@@ -141,6 +147,9 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
                     .eq(SceneEditInfo::getId, sceneEditInfo.getId()));
         }
 
+        //修改laser场景主表的缩略图地址
+        laserService.editScene(param.getNum(), LaserSceneBean.builder().thumb(thumbUrl).build());
+
         return ResultData.ok();
     }
 

+ 33 - 0
src/main/java/com/fdkankan/scene/util/forest/ErrorCallback.java

@@ -0,0 +1,33 @@
+package com.fdkankan.scene.util.forest;
+
+import cn.hutool.http.HttpStatus;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import com.dtflys.forest.callback.OnError;
+import com.dtflys.forest.exceptions.ForestRuntimeException;
+import com.dtflys.forest.http.ForestRequest;
+import com.dtflys.forest.http.ForestResponse;
+import com.fdkankan.common.constant.ErrorCode;
+import com.fdkankan.common.constant.ServerCode;
+import com.fdkankan.common.exception.BusinessException;
+import com.fdkankan.web.response.ResultData;
+import java.util.Objects;
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * <p>
+ * TODO
+ * </p>
+ *
+ * @author dengsixing
+ * @since 2022/4/25
+ **/
+@Slf4j
+public class ErrorCallback implements OnError {
+
+    @Override
+    public void onError(ForestRuntimeException e, ForestRequest forestRequest, ForestResponse forestResponse) {
+        log.error("请求失败,url:{},result:{}", forestRequest.getUrl(), forestResponse.getContent());
+        throw new BusinessException(ServerCode.FEIGN_REQUEST_FAILD);
+    }
+}

+ 50 - 0
src/main/java/com/fdkankan/scene/util/forest/HttpClient.java

@@ -0,0 +1,50 @@
+package com.fdkankan.scene.util.forest;
+
+import com.dtflys.forest.annotation.Address;
+import com.dtflys.forest.annotation.Body;
+import com.dtflys.forest.annotation.Delete;
+import com.dtflys.forest.annotation.Get;
+import com.dtflys.forest.annotation.JSONBody;
+import com.dtflys.forest.annotation.Post;
+import com.dtflys.forest.annotation.Query;
+import com.dtflys.forest.annotation.Success;
+import com.dtflys.forest.annotation.Var;
+import com.dtflys.forest.callback.OnError;
+import com.dtflys.forest.callback.OnSuccess;
+import com.fdkankan.web.response.ResultData;
+
+/**
+ * <p>
+ * TODO
+ * </p>
+ *
+ * @author dengsixing
+ * @since 2022/4/24
+ **/
+@Success(condition = SuccessCondition.class)
+public interface HttpClient {
+
+    @Get("{2}")
+    @Address(host = "{0}", port = "{1}")
+    ResultData get(String host, int port, String api, OnSuccess onSuccess, OnError onError);
+
+    @Get("{2}")
+    @Address(host = "{0}", port = "{1}")
+    ResultData get(String host, int port, String api, @Query Object params, OnSuccess onSuccess, OnError onError);
+
+    @Post("{2}")
+    @Address(host = "{0}", port = "{1}")
+    ResultData postForm(String host, int port, String api, @Body Object params, OnSuccess onSuccess, OnError onError);
+
+    @Post("{2}")
+    @Address(host = "{0}", port = "{1}")
+    ResultData postJson(String host, int port, String api, @JSONBody Object params, OnSuccess onSuccess, OnError onError);
+
+    @Delete("{2}")
+    @Address(host = "{0}", port = "{1}")
+    ResultData deleteForm(String host, int port, String api, @Body Object params, OnSuccess onSuccess, OnError onError);
+
+
+
+
+}

+ 24 - 0
src/main/java/com/fdkankan/scene/util/forest/SuccessCallback.java

@@ -0,0 +1,24 @@
+package com.fdkankan.scene.util.forest;
+
+import com.dtflys.forest.callback.OnSuccess;
+import com.dtflys.forest.http.ForestRequest;
+import com.dtflys.forest.http.ForestResponse;
+import com.fdkankan.web.response.ResultData;
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * <p>
+ * TODO
+ * </p>
+ *
+ * @author dengsixing
+ * @since 2022/4/25
+ **/
+@Slf4j
+public class SuccessCallback implements OnSuccess<ResultData> {
+
+    @Override
+    public void onSuccess(ResultData result, ForestRequest forestRequest, ForestResponse forestResponse) {
+        log.info("请求成功,url:{},result:{}", forestRequest.getUrl(), forestResponse.getContent());
+    }
+}

+ 51 - 0
src/main/java/com/fdkankan/scene/util/forest/SuccessCondition.java

@@ -0,0 +1,51 @@
+package com.fdkankan.scene.util.forest;
+
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.json.JSONUtil;
+import com.dtflys.forest.callback.SuccessWhen;
+import com.dtflys.forest.http.ForestRequest;
+import com.dtflys.forest.http.ForestResponse;
+import com.dtflys.forest.http.HttpStatus;
+import com.fdkankan.common.constant.ServerCode;
+import com.fdkankan.web.response.ResultData;
+
+/**
+ * <p>
+ *  自定义成功/失败条件实现类
+ *  需要实现 SuccessWhen 接口
+ * </p>
+ *
+ * @author dengsixing
+ * @since 2022/4/25
+ **/
+
+public class SuccessCondition implements SuccessWhen {
+
+    /**
+     * 请求成功条件
+     * @param req Forest请求对象
+     * @param res Forest响应对象
+     * @return 是否成功,true: 请求成功,false: 请求失败
+     */
+    @Override
+    public boolean successWhen(ForestRequest req, ForestResponse res) {
+        boolean reqStatus = res.noException() &&   // 请求过程没有异常
+            res.statusOk() &&     // 并且状态码在 100 ~ 399 范围内
+            res.statusIsNot(203);
+        if(!reqStatus){
+            return reqStatus;
+        }
+
+        String content = res.getContent();
+        if(StrUtil.isEmpty(content)){
+            reqStatus = false;
+            return reqStatus;
+        }
+        ResultData result = JSONUtil.toBean(content, ResultData.class);
+        if(result.getCode() != ServerCode.SUCCESS.code() || result.getCode() != HttpStatus.OK){
+            reqStatus = false;
+            return reqStatus;
+        }
+        return true;
+    }
+}

+ 1 - 0
src/main/resources/application-dev.yml

@@ -64,6 +64,7 @@ spring:
   redis:
     host: 192.168.0.211
     port: 6379
+    password:
     timeout: 6000ms
     jedis:
       pool: