|
@@ -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;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|