//package com.fdkankan.download.service.impl; // //import cn.hutool.core.collection.CollUtil; //import cn.hutool.core.date.DateUtil; //import cn.hutool.core.date.TimeInterval; //import cn.hutool.core.exceptions.ExceptionUtil; //import cn.hutool.core.io.FileUtil; //import cn.hutool.core.thread.ExecutorBuilder; //import cn.hutool.core.util.ArrayUtil; //import cn.hutool.core.util.StrUtil; //import cn.hutool.core.util.ZipUtil; //import cn.hutool.db.nosql.redis.RedisDS; //import cn.hutool.system.HostInfo; //import cn.hutool.system.SystemUtil; //import com.alibaba.fastjson.JSON; //import com.alibaba.fastjson.JSONObject; //import com.alibaba.fastjson.serializer.SerializerFeature; //import com.aliyun.oss.OSS; //import com.aliyun.oss.OSSClientBuilder; //import com.aliyun.oss.model.*; //import com.fdkankan.common.constant.CommonStatus; //import com.fdkankan.common.constant.CommonSuccessStatus; //import com.fdkankan.common.constant.SceneSource; //import com.fdkankan.download.bean.SceneEditControlsBean; //import com.fdkankan.download.bean.SceneViewInfoBean; //import com.fdkankan.download.entity.*; //import com.fdkankan.download.service.*; //import com.fdkankan.model.constants.UploadFilePath; //import com.fdkankan.redis.constant.RedisKey; //import com.fdkankan.redis.util.RedisLockUtil; //import com.fdkankan.redis.util.RedisUtil; //import com.fdkankan.rabbitmq.util.RabbitMqProducer; //import lombok.extern.slf4j.Slf4j; //import org.springframework.beans.factory.annotation.Autowired; //import org.springframework.boot.CommandLineRunner; //import org.springframework.stereotype.Component; //import org.springframework.util.CollectionUtils; //import redis.clients.jedis.Jedis; // //import java.io.BufferedReader; //import java.io.IOException; //import java.io.InputStream; //import java.io.InputStreamReader; //import java.math.BigDecimal; //import java.util.*; //import java.util.concurrent.LinkedBlockingQueue; //import java.util.concurrent.ThreadPoolExecutor; //import java.util.stream.Collectors; // //@Slf4j //@Component //public class GenSceneRunnerImpl implements CommandLineRunner { // // @Autowired // private ISnService snService; // @Autowired // private IScenePlusService scenePlusService; // @Autowired // private ICameraService cameraService; // @Autowired // private IScenePlusExtService scenePlusExtService; // @Autowired // private IDownloadLogService downloadLogService; // @Autowired // private RedisUtil redisUtil; // @Autowired // private RedisLockUtil redisLockUtil; // @Autowired // private IDownloadService downloadService; // @Autowired // private RabbitMqProducer mqProducer; // // private final static ThreadPoolExecutor threadPoolExecutor = ExecutorBuilder.create().setWorkQueue(new LinkedBlockingQueue<>(10000)).setCorePoolSize(5).setMaxPoolSize(5).build(); // // @Autowired // ILaserService laserService; // // @Override // public void run(String... args) throws Exception { // List snList = snService.list(); // if (CollUtil.isEmpty(snList)) { // return; // } // for (Sn sn : snList) { // List cameras = cameraService.listBySnCodeList(Arrays.asList(sn.getSn())); // if (CollUtil.isEmpty(cameras)) { // continue; // } // Camera camera = cameras.get(0); // List scenePluses = scenePlusService.listByCameraIdList(Arrays.asList(camera.getId())); // if (CollUtil.isEmpty(scenePluses)) { // continue; // } // for (ScenePlus scenePlus : scenePluses) { // //上锁 // HostInfo hostInfo = SystemUtil.getHostInfo(); // String key = "download:tool:" + scenePlus.getNum(); // String lockVal = hostInfo.getAddress(); // try { // boolean lock = redisLockUtil.lock(key, lockVal, 24 * 60 * 60); // if(!lock){ // continue; // } // // Thread.sleep(5000L); // // List downloadLogList = downloadLogService.getByNum(scenePlus.getNum()); // Set types = downloadLogList.stream().map(DownloadLog::getType).collect(Collectors.toSet()); // // int isObj = CommonStatus.NO.code(); // //下载点云场景 // if (scenePlus.getSceneSource() == SceneSource.JG.code() || scenePlus.getSceneSource() == SceneSource.SG.code()) { // if(!types.contains("laser")){ // threadPoolExecutor.submit(() -> { // try { // // TODO: 2024/1/3 文杰实现 // TimeInterval timer = DateUtil.timer(); // String zipPath = laserService.downloadHandler(scenePlus.getNum()); //// if (StrUtil.isNotEmpty(zipPath)){ //// send(zipPath); //// } // downloadLogService.saveLog(scenePlus.getNum(), "laser", CommonSuccessStatus.SUCCESS.code(), null, timer.intervalMinute()); // } catch (Exception e) { // downloadLogService.saveLog(scenePlus.getNum(), "laser", CommonSuccessStatus.FAIL.code(), ExceptionUtil.stacktraceToString(e, 3000), null); // log.error("点云场景打包失败,num:{}", scenePlus.getNum(), e); // } // }); // } // ScenePlusExt scenePlusExt = scenePlusExtService.getByPlusId(scenePlus.getId()); // isObj = scenePlusExt.getIsObj(); // } // // //下载看看、看见、mesh // if (scenePlus.getSceneSource() == SceneSource.BM.code() // || scenePlus.getSceneSource() == SceneSource.ZT.code() // || isObj == CommonStatus.YES.code()) { // if(!types.contains("kankan")) { // threadPoolExecutor.submit(() -> { // try { // TimeInterval timer = DateUtil.timer(); // String zipPath = downloadService.downloadHandler(scenePlus.getNum()); //// send(zipPath); // downloadLogService.saveLog(scenePlus.getNum(), "kankan", CommonSuccessStatus.SUCCESS.code(), null, timer.intervalMinute()); // } catch (Exception e) { // log.error("看看场景打包失败,num:{}", scenePlus.getNum(), e); // downloadLogService.saveLog(scenePlus.getNum(), "kankan", CommonSuccessStatus.FAIL.code(), ExceptionUtil.stacktraceToString(e, 3000), null); // } // }); // } // } // }catch (Exception e){ // log.error("场景打包失败:{}", scenePlus.getNum(), e); // } // } // } // // // // } // // public static void main(String[] args) throws Throwable { // String filePath = "D:\\test\\xuhua.txt"; //// Set collect = list.stream().filter(v -> !v.contains("_laser")).map(v -> v.substring(v.lastIndexOf("/") + 1, v.lastIndexOf("."))).collect(Collectors.toSet()); //// FileUtil.writeUtf8Lines(collect, filePath); // // OSS build = new OSSClientBuilder().build("http://oss-cn-shenzhen.aliyuncs.com","LTAI5tJwboCj3r4vUNkSmbyX", "meDy7VYAWbg8kZCKsoUZcIYQxigWOy"); // // Long all = new Long(0); // List strings = FileUtil.readUtf8Lines(filePath); // // for (String num : strings) { // List keyList = new ArrayList<>(); // Long total = 0L; // boolean flag = true; // String nextMaker = null; // ListObjectsRequest listObjectsRequest = new ListObjectsRequest("4dkankan"); // //指定下一级文件 // listObjectsRequest.setPrefix(String.format(UploadFilePath.IMG_VIEW_PATH, num)); // //设置分页的页容量 // listObjectsRequest.setMaxKeys(200); // do { // //获取下一页的起始点,它的下一项 // listObjectsRequest.setMarker(nextMaker); // ObjectListing objectListing = build.listObjects(listObjectsRequest); // Long space = objectListing.getObjectSummaries().stream().filter(v->!v.getKey().contains("/images/tiles")) // .mapToLong(OSSObjectSummary::getSize).sum(); // List subKeyList = objectListing.getObjectSummaries().stream().filter(v->!v.getKey().contains("/images/tiles")) // .map(OSSObjectSummary::getKey).collect(Collectors.toList()); // if (!CollectionUtils.isEmpty(subKeyList)) { // keyList.addAll(subKeyList); // } // total += space; // nextMaker = objectListing.getNextMarker(); // //全部执行完后,为false // flag = objectListing.isTruncated(); // } while (flag); // all += total; // //// //下载 //// if(CollUtil.isNotEmpty(keyList)){ //// keyList.stream().filter(v->!v.endsWith("/")).forEach(key->{ //// String localPath = "D:\\test222\\" + num + "\\wwwroot\\" + key; //// FileUtil.mkParentDirs(localPath); //// DownloadFileRequest request = new DownloadFileRequest("4dkankan", key); //// request.setDownloadFile(localPath); //// // 默认5个任务并发下载 //// request.setTaskNum(5); //// // 启动断点续传 //// request.setEnableCheckpoint(true); //// try { //// build.downloadFile(request); //// } catch (Throwable e) { //// throw new RuntimeException(e); //// } //// }); //// for (String key : keyList) { //// if(key.endsWith("/")) continue; //// String localPath = "D:\\test222\\" + num + "\\wwwroot\\" + key; //// FileUtil.mkParentDirs(localPath); //// DownloadFileRequest request = new DownloadFileRequest("4dkankan", key); //// request.setDownloadFile(localPath); //// // 默认5个任务并发下载 //// request.setTaskNum(5); //// // 启动断点续传 //// request.setEnableCheckpoint(true); //// build.downloadFile(request); //// } //// } // //// ZipUtil.zip("D:\\test222\\" + num+ "\\wwwroot\\", "D:\\test222\\zip\\" + num+ ".zip"); // // } // System.out.println("总容量:" + all/1024/1024/1024); // // //// String filePath = "D:\\test\\kk.txt"; ////// OSS build = new OSSClientBuilder().build("http://oss-cn-shenzhen.aliyuncs.com","LTAI5tJwboCj3r4vUNkSmbyX", "meDy7VYAWbg8kZCKsoUZcIYQxigWOy"); //// List strings = FileUtil.readUtf8Lines(filePath); //// //// for (String num : strings) { //// Jedis jedis = RedisDS.create().getJedis(); //// String sceneJsonData = jedis.get(String.format(RedisKey.SCENE_JSON, num)); ////// if(StrUtil.isEmpty(sceneJsonData)){ ////// try (OSSObject ossObject = build.getObject("4dkankan", String.format(UploadFilePath.DATA_VIEW_PATH, num) + "scene.json"); ////// InputStream objectContent = ossObject.getObjectContent(); ////// ){ ////// StringBuilder contentJson = new StringBuilder(); ////// BufferedReader reader = new BufferedReader(new InputStreamReader(objectContent)); ////// while (true) { ////// String line = reader.readLine(); ////// if (line == null) break; ////// contentJson.append(line); ////// } ////// sceneJsonData = sceneJsonData.toString(); ////// } ////// } //// sceneJsonData = sceneJsonData.replace("https://4dkk.4dage.com/", ""); //// SceneViewInfoBean sceneInfoVO = JSON.parseObject(sceneJsonData, SceneViewInfoBean.class); //// sceneInfoVO.setScenePassword(null); //// if(Objects.isNull(sceneInfoVO.getFloorPlanAngle())){ //// sceneInfoVO.setFloorPlanAngle(0f); //// } //// if(Objects.isNull(sceneInfoVO.getFloorPlanCompass())){ //// sceneInfoVO.setFloorPlanCompass(0f); //// } //// SceneEditControlsBean controls = sceneInfoVO.getControls(); //// if(Objects.isNull(controls.getShowShare())){ //// controls.setShowShare(CommonStatus.YES.code().intValue()); //// } //// if(Objects.isNull(controls.getShowCapture())){ //// controls.setShowCapture(CommonStatus.YES.code().intValue()); //// } //// if(Objects.isNull(controls.getShowBillboardTitle())){ //// controls.setShowBillboardTitle(CommonStatus.YES.code().intValue()); //// } //// //// FileUtil.writeUtf8String(JSON.toJSONString(sceneInfoVO, SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteNullNumberAsZero), "D:\\test5\\" + num + "\\wwwroot\\scene_view_data\\" + num + "\\data\\scene.json"); //// //// jedis.close(); //// System.out.println("替换完成:" + num); // //// } // // // } // // private void send(String zipPath){ // JSONObject jsonObject = new JSONObject(); // jsonObject.put("path", zipPath); // mqProducer.sendByWorkQueue("rsync-scene", jsonObject); // } // //}