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); } }