dengsixing 9 months ago
parent
commit
9bc454dda1

+ 7 - 0
pom.xml

@@ -131,6 +131,13 @@
             <artifactId>ant</artifactId>
         </dependency>
 
+        <!--        htt请求工具-->
+        <dependency>
+            <groupId>com.dtflys.forest</groupId>
+            <artifactId>forest-spring-boot-starter</artifactId>
+            <version>1.5.19</version>
+        </dependency>
+
     </dependencies>
 
     <dependencyManagement>

+ 2 - 0
src/main/java/com/fdkankan/download/SceneDownloadApplication.java

@@ -1,5 +1,6 @@
 package com.fdkankan.download;
 
+import com.dtflys.forest.springboot.annotation.ForestScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.cloud.context.config.annotation.RefreshScope;
@@ -20,6 +21,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
 @ComponentScan(basePackages = {"com.fdkankan.*"})
 @RefreshScope
 @EnableAsync
+@ForestScan("com.fdkankan.download.httpclient")
 public class SceneDownloadApplication {
     public static void main(String[] args) {
         SpringApplication.run(SceneDownloadApplication.class, args);

+ 23 - 2
src/main/java/com/fdkankan/download/controller/ScrbController.java

@@ -1,15 +1,21 @@
 package com.fdkankan.download.controller;
 
 
+import cn.hutool.core.exceptions.ExceptionUtil;
 import com.alibaba.fastjson.JSONObject;
+import com.fdkankan.common.constant.CommonSuccessStatus;
+import com.fdkankan.download.service.ISceneBuildProcessLogService;
 import com.fdkankan.download.service.IScrbService;
 import com.fdkankan.web.response.ResultData;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 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.RestController;
 
+import java.util.concurrent.CompletableFuture;
+
 /**
  * <p>
  * pro场景表 前端控制器
@@ -18,16 +24,31 @@ import org.springframework.web.bind.annotation.RestController;
  * @author
  * @since 2022-10-17
  */
+@Slf4j
 @RestController
 @RequestMapping("/download/scrb")
 public class ScrbController {
 
     @Autowired
     private IScrbService scrbService;
+    @Autowired
+    private ISceneBuildProcessLogService sceneBuildProcessLogService;
 
     @PostMapping("/syncScene")
-    public ResultData syncScene(@RequestBody JSONObject param) throws Exception {
-        scrbService.syncScene(param);
+    public ResultData syncScene(@RequestBody JSONObject param){
+        String num = param.getString("num");
+        String key = param.getString("key");
+        CompletableFuture.runAsync(() -> {
+            try {
+                sceneBuildProcessLogService.clearSceneBuildProcessLog(num, "sync", "sync", null);
+                sceneBuildProcessLogService.saveSceneBuildProcessLog(num, "sync", "sync", CommonSuccessStatus.WAITING.code(), null, null);
+                scrbService.syncScene(param);
+                sceneBuildProcessLogService.saveSceneBuildProcessLog(num, "sync", "sync", CommonSuccessStatus.SUCCESS.code(), null, null);
+            } catch (Exception e) {
+                log.error("场景同步失败,num:{}, key:{}", num, key, e);
+                sceneBuildProcessLogService.saveSceneBuildProcessLog(num, "sync", "sync", CommonSuccessStatus.FAIL.code(), ExceptionUtil.stacktraceToString(e, 3000), null);
+            }
+        });
         return ResultData.ok();
     }
 

+ 81 - 0
src/main/java/com/fdkankan/download/entity/SceneBuildProcessLog.java

@@ -0,0 +1,81 @@
+package com.fdkankan.download.entity;
+
+import com.baomidou.mybatisplus.annotation.*;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * <p>
+ * 场景计算流程状态表
+ * </p>
+ *
+ * @author
+ * @since 2023-01-28
+ */
+@Getter
+@Setter
+@TableName("t_scene_build_process_log")
+public class SceneBuildProcessLog implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @TableId(value = "id", type = IdType.AUTO)
+    private Long id;
+
+    /**
+     * 场景码
+     */
+    @TableField("num")
+    private String num;
+
+    /**
+     * 计算流程(pre-前置处理,call-计算,post-后置处理)
+     */
+    @TableField("process")
+    private String process;
+
+    /**
+     * mq消息队列名称
+     */
+    @TableField("queue_name")
+    private String queueName;
+
+    /**
+     * 处理状态(0-处理中,1-成功,2-失败)
+     */
+    @TableField("state")
+    private Integer state;
+
+    /**
+     * 失败原因
+     */
+    @TableField("reason")
+    private String reason;
+
+    /**
+     * 创建时间
+     */
+    @TableField("create_time")
+    private Date createTime;
+
+    /**
+     * 修改时间
+     */
+    @TableField("update_time")
+    private Date updateTime;
+
+    /**
+     * A-有效,I-无效
+     */
+    @TableField("rec_status")
+    @TableLogic(value = "A", delval = "I")
+    private String recStatus;
+
+    @TableField("biz_type")
+    private String bizType;
+
+
+}

+ 16 - 0
src/main/java/com/fdkankan/download/httpclient/MyClient.java

@@ -0,0 +1,16 @@
+package com.fdkankan.download.httpclient;
+
+
+import com.alibaba.fastjson.JSONObject;
+import com.dtflys.forest.annotation.*;
+import com.dtflys.forest.extensions.DownloadFile;
+import com.fdkankan.web.response.ResultData;
+
+import java.io.File;
+
+public interface MyClient {
+
+    @Post(url = "${url}")
+    ResultData postJson(@Var("url") String url, @Header("sign") String sign, @JSONBody JSONObject param);
+
+}

+ 18 - 0
src/main/java/com/fdkankan/download/mapper/ISceneBuildProcessLogMapper.java

@@ -0,0 +1,18 @@
+package com.fdkankan.download.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.fdkankan.download.entity.SceneBuildProcessLog;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * <p>
+ * 场景计算流程状态表 Mapper 接口
+ * </p>
+ *
+ * @author
+ * @since 2023-01-28
+ */
+@Mapper
+public interface ISceneBuildProcessLogMapper extends BaseMapper<SceneBuildProcessLog> {
+
+}

+ 20 - 0
src/main/java/com/fdkankan/download/service/ISceneBuildProcessLogService.java

@@ -0,0 +1,20 @@
+package com.fdkankan.download.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.fdkankan.download.entity.SceneBuildProcessLog;
+
+/**
+ * <p>
+ * 场景计算流程状态表 服务类
+ * </p>
+ *
+ * @author
+ * @since 2023-01-28
+ */
+public interface ISceneBuildProcessLogService extends IService<SceneBuildProcessLog> {
+
+    public void clearSceneBuildProcessLog(String num, String process, String queueName, String bizType);
+
+    public void saveSceneBuildProcessLog(String num, String process, String queueName, int status, String reason, String bizType);
+
+}

+ 72 - 0
src/main/java/com/fdkankan/download/service/impl/SceneBuildProcessLogServiceImpl.java

@@ -0,0 +1,72 @@
+package com.fdkankan.download.service.impl;
+
+import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fdkankan.download.entity.SceneBuildProcessLog;
+import com.fdkankan.download.mapper.ISceneBuildProcessLogMapper;
+import com.fdkankan.download.service.ISceneBuildProcessLogService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+import java.util.Date;
+import java.util.Objects;
+
+/**
+ * <p>
+ * 场景计算流程状态表 服务实现类
+ * </p>
+ *
+ * @author
+ * @since 2023-01-28
+ */
+@Slf4j
+@Service
+public class SceneBuildProcessLogServiceImpl extends ServiceImpl<ISceneBuildProcessLogMapper, SceneBuildProcessLog> implements ISceneBuildProcessLogService {
+
+
+    @Override
+    public void clearSceneBuildProcessLog(String num, String process, String queueName, String bizType) {
+        try {
+            LambdaQueryWrapper<SceneBuildProcessLog> wrapper = new LambdaQueryWrapper<SceneBuildProcessLog>()
+                    .eq(SceneBuildProcessLog::getNum, num)
+                    .eq(SceneBuildProcessLog::getProcess, process);
+            if(StrUtil.isNotEmpty(bizType)){
+                wrapper.eq(SceneBuildProcessLog::getBizType, bizType);
+            }
+            this.remove(wrapper);
+        }catch (Exception e){
+            log.error("清楚计算流程日志报错", e);
+        }
+    }
+
+    @Override
+    public void saveSceneBuildProcessLog(String num, String process, String queueName, int status, String reason, String bizType) {
+        try {
+            LambdaQueryWrapper<SceneBuildProcessLog> wrapper = new LambdaQueryWrapper<SceneBuildProcessLog>()
+                    .eq(SceneBuildProcessLog::getNum, num)
+                    .eq(SceneBuildProcessLog::getProcess, process)
+                    .eq(SceneBuildProcessLog::getQueueName, queueName);
+            if(StrUtil.isNotEmpty(bizType)){
+                wrapper.eq(SceneBuildProcessLog::getBizType, bizType);
+            }
+
+            SceneBuildProcessLog log = this.getOne(wrapper);
+            if(Objects.isNull(log)){
+                log = new SceneBuildProcessLog();
+            }
+            log.setNum(num);
+            log.setProcess(process);
+            log.setProcess(process);
+            log.setQueueName(queueName);
+            log.setState(status);
+            log.setReason(reason);
+            log.setUpdateTime(new Date());
+            log.setBizType(bizType);
+            this.saveOrUpdate(log);
+        }catch (Exception e){
+            log.error("保存计算流程日志报错", e);
+        }
+
+    }
+}

+ 38 - 1
src/main/java/com/fdkankan/download/service/impl/ScrbServiceImpl.java

@@ -16,13 +16,17 @@ import com.fdkankan.download.constant.UserEditDataType;
 import com.fdkankan.download.entity.*;
 import com.fdkankan.download.factory.UserEditData.UserEditDataHandler;
 import com.fdkankan.download.factory.UserEditData.UserEditDataHandlerFactory;
+import com.fdkankan.download.httpclient.MyClient;
 import com.fdkankan.download.service.*;
+import com.fdkankan.download.util.RsaUtils;
 import com.fdkankan.fyun.config.FYunFileConfig;
 import com.fdkankan.fyun.face.FYunFileServiceInterface;
 import com.fdkankan.redis.constant.RedisKey;
 import com.fdkankan.redis.util.RedisUtil;
+import com.fdkankan.web.response.ResultData;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
@@ -33,6 +37,9 @@ import java.util.*;
 @Service
 public class ScrbServiceImpl implements IScrbService {
 
+    @Value("${main.url}")
+    private String mainUrl;
+
     @Resource
     private FYunFileServiceInterface fYunFileService;
     @Autowired
@@ -47,8 +54,11 @@ public class ScrbServiceImpl implements IScrbService {
     private ISceneEditInfoExtService sceneEditInfoExtService;
     @Autowired
     private ISceneEditControlsService sceneEditControlsService;
-    @Autowired
+    @Resource
     private RedisUtil redisUtil;
+    @Resource
+    private MyClient httpClient;
+
 
 
     @Override
@@ -93,12 +103,37 @@ public class ScrbServiceImpl implements IScrbService {
             fYunFileService.uploadFile(file.getAbsolutePath(), file.getAbsolutePath().replace(scenePath, ""));
         });
 
+        //上传mapping
+        files = FileUtil.loopFiles(scenePath + "scene_edit_data/");
+        files.stream().forEach(file -> {
+            fYunFileService.uploadFile(file.getAbsolutePath(), file.getAbsolutePath().replace(scenePath, ""));
+        });
+
         //插入数据库,如果是重推,不需要执行这部
         ScenePlus scenePlus = scenePlusService.getByNum(num);
         if(Objects.isNull(scenePlus)){
+
+            String cameraObjStr = FileUtil.readUtf8String(scenePath + "camera.txt");
+            JSONObject cameraObj = JSON.parseObject(cameraObjStr);
+            Integer cameraType = cameraObj.getInteger("cameraType");
+            String snCode = cameraObj.getString("snCode");
+            //调用接口入库
+            Map<String, Object> signPlayload = new HashMap<>();
+            signPlayload.put("appId", "ucenter");
+            signPlayload.put("timestamp", Calendar.getInstance().getTimeInMillis());
+            String sign = RsaUtils.encipher(JSON.toJSONString(signPlayload), RsaUtils.publicKey);
+
+            JSONObject params = new JSONObject();
+            params.put("cameraType", cameraType);
+            params.put("snCode", snCode);
+            ResultData resultData = httpClient.postJson("http://127.0.0.1:8081/ucenter/_inner/cameraInStore", sign, params);
+            Object data = resultData.getData();
+            Long cameraId = ((JSONObject)data).getLong("id");
+
             String scenePlusStr = FileUtil.readUtf8String(scenePath + "scenePlus.txt");
             scenePlus = JSON.parseObject(scenePlusStr, ScenePlus.class);
             scenePlus.setId(null);
+            scenePlus.setCameraId(cameraId);
             scenePlusService.save(scenePlus);
 
             String scenePlusExtStr = FileUtil.readUtf8String(scenePath + "scenePlusExt.txt");
@@ -109,12 +144,14 @@ public class ScrbServiceImpl implements IScrbService {
             scenePlusExt.setPlusId(scenePlus.getId());
             scenePlusExt.setYunFileBucket(null);
             scenePlusExt.getVideos().replaceAll("https://4dkk.4dage.com/", fYunFileConfig.getHost());
+            scenePlusExt.setWebSite(scenePlusExt.getWebSite().replace("https://test.4dkankan.com", mainUrl).replace("https://www.4dkankan.com", mainUrl));
             scenePlusExtService.save(scenePlusExt);
 
             String sceneEditInfoStr = FileUtil.readUtf8String(scenePath + "sceneEditInfo.txt");
             SceneEditInfo sceneEditInfo = JSON.parseObject(sceneEditInfoStr, SceneEditInfo.class);
             sceneEditInfo.setId(null);
             sceneEditInfo.setScenePlusId(scenePlus.getId());
+            sceneEditInfo.setTags((byte)0);
             sceneEditInfoService.save(sceneEditInfo);
 
             String sceneEditInfoExtStr = FileUtil.readUtf8String(scenePath + "sceneEditInfoExt.txt");

File diff suppressed because it is too large
+ 314 - 0
src/main/java/com/fdkankan/download/util/RsaUtils.java