BdUtil.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package com.fdkankan.contro.util;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.io.FileUtil;
  4. import cn.hutool.core.util.StrUtil;
  5. import com.alibaba.fastjson.JSONArray;
  6. import com.alibaba.fastjson.JSONObject;
  7. import com.fdkankan.contro.constant.BdProperties;
  8. import com.fdkankan.contro.httpclient.CustomHttpClient;
  9. import org.springframework.stereotype.Component;
  10. import org.springframework.util.DigestUtils;
  11. import javax.annotation.Resource;
  12. import java.util.HashMap;
  13. import java.util.Map;
  14. import java.util.stream.Collectors;
  15. @Component
  16. public class BdUtil {
  17. @Resource
  18. private BdProperties bdProperties;
  19. @Resource
  20. private CustomHttpClient httpClient;
  21. public String login(){
  22. Map<String, String> params = new HashMap<>();
  23. params.put("account", bdProperties.getAccount());
  24. params.put("pass", DigestUtils.md5DigestAsHex(bdProperties.getPass().getBytes()));
  25. String url = bdProperties.getAddress() + bdProperties.getLogin();
  26. JSONObject jsonObject = httpClient.postJson(url, params);
  27. String token = jsonObject.getString("token");
  28. if(StrUtil.isEmpty(token)){
  29. throw new RuntimeException("登录失败");
  30. }
  31. return token;
  32. }
  33. public Map<String, String> uploadFdfs(String zipPath){
  34. String token = this.login();
  35. Map<String, String> headers = new HashMap<>();
  36. headers.put("token", token);
  37. headers.put("account", bdProperties.getAccount());
  38. Map<String, String> params = new HashMap<>();
  39. params.put("fileName", FileUtil.getName(zipPath));
  40. params.put("fileSuffix", FileUtil.extName(zipPath));
  41. params.put("fileGroup", "4dkankan");
  42. String url = bdProperties.getAddress() + bdProperties.getUpload();
  43. JSONObject upload = httpClient.upload(url, headers, zipPath, params);
  44. JSONObject data = upload.getJSONObject("data");
  45. String fileNameRemote = data.getString("fileNameRemote");
  46. Map<String, String> result = new HashMap<>();
  47. result.put("token", token);
  48. result.put("fileNameRemote", fileNameRemote);
  49. return result;
  50. }
  51. public void uploadFerry(String dataPoint, String dataVersion, String fileNameRemote, String token){
  52. Map<String, String> headers = new HashMap<>();
  53. headers.put("token", token);
  54. Map<String, String> params = new HashMap<>();
  55. params.put("dataSystemId", bdProperties.getDataSystemId());
  56. params.put("dataTypeName", "场景原始资源压缩包");
  57. params.put("dataPoint", dataPoint);
  58. params.put("filePath", fileNameRemote);
  59. params.put("dataOrgCode", bdProperties.getDataOrgCode());
  60. if(StrUtil.isNotEmpty(dataVersion)){
  61. params.put("dataVersion", dataVersion);
  62. }
  63. String url = bdProperties.getAddress() + bdProperties.getFerryUpload();
  64. JSONObject upload = httpClient.postJson(url, headers, params);
  65. }
  66. public String upload(String dataPoint, String dataVersion, String zipPath){
  67. Map<String, String> stringStringMap = this.uploadFdfs(zipPath);
  68. String token = stringStringMap.get("token");
  69. String fileNameRemote = stringStringMap.get("fileNameRemote");
  70. this.uploadFerry(dataPoint, dataVersion, fileNameRemote, token);
  71. return fileNameRemote;
  72. }
  73. public JSONArray searchDataFerryInner(String token){
  74. Map<String, String> headers = new HashMap<>();
  75. headers.put("token", token);
  76. Map<String, String> params = new HashMap<>();
  77. params.put("dataSystemId", bdProperties.getDataSystemId());
  78. params.put("thirdFlag", "0");
  79. params.put("operateResult", "1");
  80. String url = bdProperties.getAddress() + bdProperties.getSearchDataFerryInner();
  81. JSONObject upload = httpClient.postJson(url, headers, params);
  82. JSONArray jsonArray = upload.getJSONArray("data");
  83. return jsonArray;
  84. }
  85. public void updateDataFerryInner(String id, String token, String thirdFlag, String operateResult){
  86. Map<String, String> headers = new HashMap<>();
  87. headers.put("token", token);
  88. Map<String, String> params = new HashMap<>();
  89. params.put("id,", id);
  90. params.put("thirdFlag", thirdFlag);
  91. params.put("operateResult", operateResult);
  92. String url = bdProperties.getAddress() + bdProperties.getSearchDataFerryInner();
  93. JSONObject upload = httpClient.postJson(url, headers, params);
  94. }
  95. public String getDownloadUrl(String path){
  96. return bdProperties.getDownloadAddress() + path;
  97. }
  98. }