dengsixing 7 kuukautta sitten
vanhempi
commit
9205c24b01

+ 6 - 0
pom.xml

@@ -182,6 +182,12 @@
       <version>2.17.0</version>
     </dependency>
 
+    <dependency>
+      <groupId>com.dtflys.forest</groupId>
+      <artifactId>forest-spring-boot-starter</artifactId>
+      <version>1.5.36</version>
+    </dependency>
+
   </dependencies>
   <build>
     <finalName>${artifactId}</finalName>

+ 22 - 0
src/main/java/com/fdkankan/contro/constant/BdProperties.java

@@ -0,0 +1,22 @@
+package com.fdkankan.contro.constant;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+
+@Data
+@Configuration
+@ConfigurationProperties(prefix = "bd.api")
+public class BdProperties {
+    private String address;
+    private String downloadAddress;
+    private String account;
+    private String pass;
+    private String dataSystemId;
+    private String dataOrgCode;
+    private String login;
+    private String upload;
+    private String ferryUpload;
+    private String searchDataFerryInner;
+    private String updateDataFerryInner;
+}

+ 39 - 0
src/main/java/com/fdkankan/contro/httpclient/CustomHttpClient.java

@@ -0,0 +1,39 @@
+package com.fdkankan.contro.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.InputStream;
+import java.util.Map;
+
+public interface CustomHttpClient {
+
+    @Post(url = "{url}", connectTimeout = 30000,  readTimeout = 30000, maxRetryInterval = 5)
+    JSONObject postJson(@Var("url") String url, @JSONBody Object object);
+
+    @Post(url = "{url}", connectTimeout = 30000,  readTimeout = 30000, maxRetryInterval = 5)
+    JSONObject postJson(@Var("url") String url, @Header Map<String, String> headers, @JSONBody Object object);
+
+    @Post(url = "{url}", connectTimeout = 30000,  readTimeout = 30000, maxRetryInterval = 5)
+    JSONObject post(@Header Map<String, String> headers, @Var("url") String url);
+
+    @Post(url = "{url}", connectTimeout = 30000,  readTimeout = 30000, maxRetryInterval = 5)
+    ResultData post(@Var("url") String url, @Body("params") String params);
+
+    /**
+     * 返回类型用InputStream,用流的方式读取文件内容
+     */
+    @GetRequest(url = "{url}", connectTimeout = 6000, readTimeout = 60000, maxRetryInterval = 5)
+    InputStream downloadFileToInputStream(@Var("url") String url);
+
+    @GetRequest(url = "{url}", connectTimeout = 60000, readTimeout = 600000, maxRetryInterval = 5)
+    @DownloadFile(dir = "{dir}", filename = "{fileName}")
+    void downloadFile(@Var("url") String url, @Var("dir") String dir, @Var("fileName") String fileName);
+
+    @Post(url="{url}", readTimeout = 60*60*1000, connectTimeout = 60*60*1000, timeout = 60*60*1000, maxRetryInterval = 5)
+    JSONObject upload(@Var("url")String url, @Header Map<String, String> headers, @DataFile("file") String filePath, @Body Object param);
+
+}

+ 7 - 0
src/main/java/com/fdkankan/contro/schedule/ScheduleJob.java

@@ -21,4 +21,11 @@ public class ScheduleJob {
     public void generateSceneNum() {
         scene3dNumService.generateSceneNumHandler();
     }
+
+    /**
+     * 每隔十分钟拉取一次压缩包
+     */
+    @Scheduled(fixedDelay = 10*60*1000, initialDelay = 1000)
+    public void bd() {
+    }
 }

+ 7 - 0
src/main/java/com/fdkankan/contro/service/GzZcdjzxService.java

@@ -0,0 +1,7 @@
+package com.fdkankan.contro.service;
+
+public interface GzZcdjzxService {
+
+    void bd();
+
+}

+ 114 - 0
src/main/java/com/fdkankan/contro/service/impl/GzZcdjzxServiceImpl.java

@@ -0,0 +1,114 @@
+package com.fdkankan.contro.service.impl;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.io.FileUtil;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.fdkankan.common.constant.RecStatus;
+import com.fdkankan.common.util.CmdUtils;
+import com.fdkankan.contro.entity.SceneFileBuild;
+import com.fdkankan.contro.httpclient.CustomHttpClient;
+import com.fdkankan.contro.service.GzZcdjzxService;
+import com.fdkankan.contro.service.ISceneFileBuildService;
+import com.fdkankan.contro.util.BdUtil;
+import com.fdkankan.fyun.config.FYunFileConfig;
+import com.fdkankan.fyun.face.FYunFileServiceInterface;
+import com.fdkankan.fyun.local.LocalFileService;
+import com.fdkankan.fyun.local.config.LocalConfig;
+import com.fdkankan.fyun.local.constant.LocalConstants;
+import com.fdkankan.model.constants.ConstantFilePath;
+import com.fdkankan.model.constants.UploadFilePath;
+import com.fdkankan.model.utils.SceneUtil;
+import com.fdkankan.web.util.RSAEncrypt;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.codec.binary.Base64;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.nio.charset.StandardCharsets;
+import java.util.Date;
+import java.util.Objects;
+
+@Slf4j
+@Service
+public class GzZcdjzxServiceImpl implements GzZcdjzxService {
+
+    @Resource
+    private BdUtil bdUtil;
+    @Resource
+    private CustomHttpClient httpClient;
+    @Resource
+    private LocalFileService localFileService;
+    @Resource
+    private LocalConstants localConstants;
+    @Resource
+    private FYunFileConfig fYunFileConfig;
+    @Autowired
+    private ISceneFileBuildService sceneFileBuildService;
+
+
+    @Override
+    public void bd() {
+        String token = bdUtil.login();
+        JSONArray jsonArray = bdUtil.searchDataFerryInner(token);
+        if(CollUtil.isEmpty(jsonArray)){
+            return;
+        }
+        jsonArray.stream().forEach(v->{
+            JSONObject o = (JSONObject) v;
+            String id = o.getString("id");
+            try {
+                String finalFileFullName = o.getString("finalFileFullName");
+                String filePathFdfs = o.getString("filePathFdfs");
+                String relativePath = finalFileFullName.replace(".zip", "");
+                String[] split = relativePath.split("_");
+                String snCode = split[0];
+                String fileId = split[1];
+                String unicode = split[2];
+                String url = bdUtil.getDownloadUrl(filePathFdfs);
+                String dataSource =  ConstantFilePath.BUILD_MODEL_PATH + relativePath;
+                String ossHomePath = SceneUtil.getHomePath(dataSource);
+                String ossHomeAbsolutePath = LocalConstants.BASE_PATH + fYunFileConfig.getBucket() + "/" + ossHomePath;
+                httpClient.downloadFile(url, ossHomeAbsolutePath, finalFileFullName);
+                String unzipCmd = "unzip -O GBK " + ossHomeAbsolutePath + finalFileFullName + " -d " + ossHomeAbsolutePath;
+                CmdUtils.callLine(unzipCmd);
+                SceneFileBuild sceneFileBuild = sceneFileBuildService.findByFileId(fileId);
+                if(Objects.isNull(sceneFileBuild)){
+                    sceneFileBuild = new SceneFileBuild();
+                    sceneFileBuild.setFileId(fileId);
+                    sceneFileBuild.setUnicode(unicode);
+                    sceneFileBuild.setChildName(snCode);
+                    sceneFileBuild.setCreateTime(new Date());
+                    sceneFileBuild.setRecStatus(RecStatus.VALID.code());
+                    sceneFileBuildService.save(sceneFileBuild);
+                }
+
+                // 私钥解密过程
+                String paramsStr = relativePath.replaceAll("_", "#");
+                byte[] res = RSAEncrypt.encrypt(RSAEncrypt.loadPublicKeyByStr(RSAEncrypt.loadPublicKeyByFile()),
+                        paramsStr.getBytes(StandardCharsets.UTF_8));
+                String params = new Base64().encodeToString(res);
+
+                sceneFileBuildService.turntableUploadSuccess(params);
+
+                bdUtil.updateDataFerryInner(id, token, "1", "3");
+            }catch (Exception e){
+                log.error("场景摆渡失败,bd_data:{}", v, e);
+                bdUtil.updateDataFerryInner(id, token, "1", "4");
+            }
+        });
+    }
+
+    public static void main(String[] args) throws Exception {
+        String paramsStr = "111#222#333";
+        byte[] res = RSAEncrypt.encrypt(RSAEncrypt.loadPublicKeyByStr(RSAEncrypt.loadPublicKeyByFile()),
+                paramsStr.getBytes(StandardCharsets.UTF_8));
+        System.out.println(new Base64().encodeToString(res));
+
+        byte[] res2 = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
+                new Base64().decode(new Base64().encodeToString(res)));
+        String restr = new String(res2, "UTF-8");
+        System.out.println(restr);
+    }
+}

+ 115 - 0
src/main/java/com/fdkankan/contro/util/BdUtil.java

@@ -0,0 +1,115 @@
+package com.fdkankan.contro.util;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.fdkankan.contro.constant.BdProperties;
+import com.fdkankan.contro.httpclient.CustomHttpClient;
+import org.springframework.stereotype.Component;
+import org.springframework.util.DigestUtils;
+
+import javax.annotation.Resource;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+@Component
+public class BdUtil {
+
+    @Resource
+    private BdProperties bdProperties;
+    @Resource
+    private CustomHttpClient httpClient;
+
+    public String login(){
+        Map<String, String> params = new HashMap<>();
+        params.put("account", bdProperties.getAccount());
+        params.put("pass", DigestUtils.md5DigestAsHex(bdProperties.getPass().getBytes()));
+        String url = bdProperties.getAddress() + bdProperties.getLogin();
+        JSONObject jsonObject = httpClient.postJson(url, params);
+        String token = jsonObject.getString("token");
+        if(StrUtil.isEmpty(token)){
+            throw new RuntimeException("登录失败");
+        }
+        return token;
+    }
+
+    public Map<String, String> uploadFdfs(String zipPath){
+        String token = this.login();
+        Map<String, String> headers = new HashMap<>();
+        headers.put("token", token);
+        headers.put("account", bdProperties.getAccount());
+        Map<String, String> params = new HashMap<>();
+        params.put("fileName", FileUtil.getName(zipPath));
+        params.put("fileSuffix", FileUtil.extName(zipPath));
+        params.put("fileGroup", "4dkankan");
+        String url = bdProperties.getAddress() + bdProperties.getUpload();
+        JSONObject upload = httpClient.upload(url, headers, zipPath, params);
+        JSONObject data = upload.getJSONObject("data");
+        String fileNameRemote = data.getString("fileNameRemote");
+        Map<String, String> result = new HashMap<>();
+        result.put("token", token);
+        result.put("fileNameRemote", fileNameRemote);
+        return result;
+    }
+
+    public void uploadFerry(String dataPoint, String dataVersion, String fileNameRemote, String token){
+        Map<String, String> headers = new HashMap<>();
+        headers.put("token", token);
+        Map<String, String> params = new HashMap<>();
+        params.put("dataSystemId", bdProperties.getDataSystemId());
+        params.put("dataTypeName", "场景原始资源压缩包");
+        params.put("dataPoint", dataPoint);
+        params.put("filePath", fileNameRemote);
+        params.put("dataOrgCode", bdProperties.getDataOrgCode());
+        if(StrUtil.isNotEmpty(dataVersion)){
+            params.put("dataVersion", dataVersion);
+        }
+        String url = bdProperties.getAddress() + bdProperties.getFerryUpload();
+        JSONObject upload = httpClient.postJson(url, headers, params);
+    }
+
+    public String upload(String dataPoint, String dataVersion, String zipPath){
+        Map<String, String> stringStringMap = this.uploadFdfs(zipPath);
+        String token = stringStringMap.get("token");
+        String fileNameRemote = stringStringMap.get("fileNameRemote");
+        this.uploadFerry(dataPoint, dataVersion, fileNameRemote, token);
+        return fileNameRemote;
+    }
+
+    public JSONArray searchDataFerryInner(String token){
+        Map<String, String> headers = new HashMap<>();
+        headers.put("token", token);
+        Map<String, String> params = new HashMap<>();
+        params.put("dataSystemId", bdProperties.getDataSystemId());
+        params.put("thirdFlag", "0");
+        params.put("operateResult", "1");
+        String url = bdProperties.getAddress() + bdProperties.getSearchDataFerryInner();
+        JSONObject upload = httpClient.postJson(url, headers, params);
+        JSONArray jsonArray = upload.getJSONArray("data");
+        return jsonArray;
+    }
+
+    public void updateDataFerryInner(String id, String token, String thirdFlag, String operateResult){
+        Map<String, String> headers = new HashMap<>();
+        headers.put("token", token);
+        Map<String, String> params = new HashMap<>();
+        params.put("id,", id);
+        params.put("thirdFlag", thirdFlag);
+        params.put("operateResult", operateResult);
+        String url = bdProperties.getAddress() + bdProperties.getSearchDataFerryInner();
+        JSONObject upload = httpClient.postJson(url, headers, params);
+    }
+
+    public String getDownloadUrl(String path){
+        return bdProperties.getDownloadAddress() + path;
+    }
+
+
+
+
+
+
+}