GzZcdjzxServiceImpl.java 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package com.fdkankan.contro.service.impl;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.io.FileUtil;
  4. import com.alibaba.fastjson.JSONArray;
  5. import com.alibaba.fastjson.JSONObject;
  6. import com.fdkankan.common.constant.RecStatus;
  7. import com.fdkankan.common.util.CmdUtils;
  8. import com.fdkankan.contro.entity.SceneFileBuild;
  9. import com.fdkankan.contro.httpclient.CustomHttpClient;
  10. import com.fdkankan.contro.service.GzZcdjzxService;
  11. import com.fdkankan.contro.service.ISceneFileBuildService;
  12. import com.fdkankan.contro.util.BdUtil;
  13. import com.fdkankan.fyun.config.FYunFileConfig;
  14. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  15. import com.fdkankan.fyun.local.LocalFileService;
  16. import com.fdkankan.fyun.local.config.LocalConfig;
  17. import com.fdkankan.fyun.local.constant.LocalConstants;
  18. import com.fdkankan.model.constants.ConstantFilePath;
  19. import com.fdkankan.model.constants.UploadFilePath;
  20. import com.fdkankan.model.utils.SceneUtil;
  21. import com.fdkankan.web.util.RSAEncrypt;
  22. import lombok.extern.slf4j.Slf4j;
  23. import org.apache.commons.codec.binary.Base64;
  24. import org.springframework.beans.factory.annotation.Autowired;
  25. import org.springframework.stereotype.Service;
  26. import javax.annotation.Resource;
  27. import java.nio.charset.StandardCharsets;
  28. import java.util.Date;
  29. import java.util.Objects;
  30. @Slf4j
  31. @Service
  32. public class GzZcdjzxServiceImpl implements GzZcdjzxService {
  33. @Resource
  34. private BdUtil bdUtil;
  35. @Resource
  36. private CustomHttpClient httpClient;
  37. @Resource
  38. private LocalFileService localFileService;
  39. @Resource
  40. private LocalConstants localConstants;
  41. @Resource
  42. private FYunFileConfig fYunFileConfig;
  43. @Autowired
  44. private ISceneFileBuildService sceneFileBuildService;
  45. @Override
  46. public void bd() {
  47. String token = bdUtil.login();
  48. JSONArray jsonArray = bdUtil.searchDataFerryInner(token);
  49. if(CollUtil.isEmpty(jsonArray)){
  50. return;
  51. }
  52. jsonArray.stream().forEach(v->{
  53. JSONObject o = (JSONObject) v;
  54. String id = o.getString("id");
  55. try {
  56. String finalFileFullName = o.getString("finalFileFullName");
  57. String filePathFdfs = o.getString("filePathFdfs");
  58. String relativePath = finalFileFullName.replace(".zip", "");
  59. String[] split = relativePath.split("_");
  60. String snCode = split[0];
  61. String fileId = split[1];
  62. String unicode = split[2];
  63. String url = bdUtil.getDownloadUrl(filePathFdfs);
  64. String dataSource = ConstantFilePath.BUILD_MODEL_PATH + relativePath;
  65. String ossHomePath = SceneUtil.getHomePath(dataSource);
  66. String ossHomeAbsolutePath = LocalConstants.BASE_PATH + fYunFileConfig.getBucket() + "/" + ossHomePath;
  67. httpClient.downloadFile(url, ossHomeAbsolutePath, finalFileFullName);
  68. String unzipCmd = "unzip -O GBK " + ossHomeAbsolutePath + finalFileFullName + " -d " + ossHomeAbsolutePath;
  69. CmdUtils.callLine(unzipCmd);
  70. SceneFileBuild sceneFileBuild = sceneFileBuildService.findByFileId(fileId);
  71. if(Objects.isNull(sceneFileBuild)){
  72. sceneFileBuild = new SceneFileBuild();
  73. sceneFileBuild.setFileId(fileId);
  74. sceneFileBuild.setUnicode(unicode);
  75. sceneFileBuild.setChildName(snCode);
  76. sceneFileBuild.setCreateTime(new Date());
  77. sceneFileBuild.setRecStatus(RecStatus.VALID.code());
  78. sceneFileBuildService.save(sceneFileBuild);
  79. }
  80. // 私钥解密过程
  81. String paramsStr = relativePath.replaceAll("_", "#");
  82. byte[] res = RSAEncrypt.encrypt(RSAEncrypt.loadPublicKeyByStr(RSAEncrypt.loadPublicKeyByFile()),
  83. paramsStr.getBytes(StandardCharsets.UTF_8));
  84. String params = new Base64().encodeToString(res);
  85. sceneFileBuildService.turntableUploadSuccess(params);
  86. bdUtil.updateDataFerryInner(id, token, "1", "3");
  87. }catch (Exception e){
  88. log.error("场景摆渡失败,bd_data:{}", v, e);
  89. bdUtil.updateDataFerryInner(id, token, "1", "4");
  90. }
  91. });
  92. }
  93. public static void main(String[] args) throws Exception {
  94. String paramsStr = "111#222#333";
  95. byte[] res = RSAEncrypt.encrypt(RSAEncrypt.loadPublicKeyByStr(RSAEncrypt.loadPublicKeyByFile()),
  96. paramsStr.getBytes(StandardCharsets.UTF_8));
  97. System.out.println(new Base64().encodeToString(res));
  98. byte[] res2 = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
  99. new Base64().decode(new Base64().encodeToString(res)));
  100. String restr = new String(res2, "UTF-8");
  101. System.out.println(restr);
  102. }
  103. }