GenSceneRunnerImpl.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. //package com.fdkankan.download.service.impl;
  2. //
  3. //import cn.hutool.core.collection.CollUtil;
  4. //import cn.hutool.core.date.DateUtil;
  5. //import cn.hutool.core.date.TimeInterval;
  6. //import cn.hutool.core.exceptions.ExceptionUtil;
  7. //import cn.hutool.core.io.FileUtil;
  8. //import cn.hutool.core.thread.ExecutorBuilder;
  9. //import cn.hutool.core.util.ArrayUtil;
  10. //import cn.hutool.core.util.StrUtil;
  11. //import cn.hutool.core.util.ZipUtil;
  12. //import cn.hutool.db.nosql.redis.RedisDS;
  13. //import cn.hutool.system.HostInfo;
  14. //import cn.hutool.system.SystemUtil;
  15. //import com.alibaba.fastjson.JSON;
  16. //import com.alibaba.fastjson.JSONObject;
  17. //import com.alibaba.fastjson.serializer.SerializerFeature;
  18. //import com.aliyun.oss.OSS;
  19. //import com.aliyun.oss.OSSClientBuilder;
  20. //import com.aliyun.oss.model.*;
  21. //import com.fdkankan.common.constant.CommonStatus;
  22. //import com.fdkankan.common.constant.CommonSuccessStatus;
  23. //import com.fdkankan.common.constant.SceneSource;
  24. //import com.fdkankan.download.bean.SceneEditControlsBean;
  25. //import com.fdkankan.download.bean.SceneViewInfoBean;
  26. //import com.fdkankan.download.entity.*;
  27. //import com.fdkankan.download.service.*;
  28. //import com.fdkankan.model.constants.UploadFilePath;
  29. //import com.fdkankan.redis.constant.RedisKey;
  30. //import com.fdkankan.redis.util.RedisLockUtil;
  31. //import com.fdkankan.redis.util.RedisUtil;
  32. //import com.fdkankan.rabbitmq.util.RabbitMqProducer;
  33. //import lombok.extern.slf4j.Slf4j;
  34. //import org.springframework.beans.factory.annotation.Autowired;
  35. //import org.springframework.boot.CommandLineRunner;
  36. //import org.springframework.stereotype.Component;
  37. //import org.springframework.util.CollectionUtils;
  38. //import redis.clients.jedis.Jedis;
  39. //
  40. //import java.io.BufferedReader;
  41. //import java.io.IOException;
  42. //import java.io.InputStream;
  43. //import java.io.InputStreamReader;
  44. //import java.math.BigDecimal;
  45. //import java.util.*;
  46. //import java.util.concurrent.LinkedBlockingQueue;
  47. //import java.util.concurrent.ThreadPoolExecutor;
  48. //import java.util.stream.Collectors;
  49. //
  50. //@Slf4j
  51. //@Component
  52. //public class GenSceneRunnerImpl implements CommandLineRunner {
  53. //
  54. // @Autowired
  55. // private ISnService snService;
  56. // @Autowired
  57. // private IScenePlusService scenePlusService;
  58. // @Autowired
  59. // private ICameraService cameraService;
  60. // @Autowired
  61. // private IScenePlusExtService scenePlusExtService;
  62. // @Autowired
  63. // private IDownloadLogService downloadLogService;
  64. // @Autowired
  65. // private RedisUtil redisUtil;
  66. // @Autowired
  67. // private RedisLockUtil redisLockUtil;
  68. // @Autowired
  69. // private IDownloadService downloadService;
  70. // @Autowired
  71. // private RabbitMqProducer mqProducer;
  72. //
  73. // private final static ThreadPoolExecutor threadPoolExecutor = ExecutorBuilder.create().setWorkQueue(new LinkedBlockingQueue<>(10000)).setCorePoolSize(5).setMaxPoolSize(5).build();
  74. //
  75. // @Autowired
  76. // ILaserService laserService;
  77. //
  78. // @Override
  79. // public void run(String... args) throws Exception {
  80. // List<Sn> snList = snService.list();
  81. // if (CollUtil.isEmpty(snList)) {
  82. // return;
  83. // }
  84. // for (Sn sn : snList) {
  85. // List<Camera> cameras = cameraService.listBySnCodeList(Arrays.asList(sn.getSn()));
  86. // if (CollUtil.isEmpty(cameras)) {
  87. // continue;
  88. // }
  89. // Camera camera = cameras.get(0);
  90. // List<ScenePlus> scenePluses = scenePlusService.listByCameraIdList(Arrays.asList(camera.getId()));
  91. // if (CollUtil.isEmpty(scenePluses)) {
  92. // continue;
  93. // }
  94. // for (ScenePlus scenePlus : scenePluses) {
  95. // //上锁
  96. // HostInfo hostInfo = SystemUtil.getHostInfo();
  97. // String key = "download:tool:" + scenePlus.getNum();
  98. // String lockVal = hostInfo.getAddress();
  99. // try {
  100. // boolean lock = redisLockUtil.lock(key, lockVal, 24 * 60 * 60);
  101. // if(!lock){
  102. // continue;
  103. // }
  104. //
  105. // Thread.sleep(5000L);
  106. //
  107. // List<DownloadLog> downloadLogList = downloadLogService.getByNum(scenePlus.getNum());
  108. // Set<String> types = downloadLogList.stream().map(DownloadLog::getType).collect(Collectors.toSet());
  109. //
  110. // int isObj = CommonStatus.NO.code();
  111. // //下载点云场景
  112. // if (scenePlus.getSceneSource() == SceneSource.JG.code() || scenePlus.getSceneSource() == SceneSource.SG.code()) {
  113. // if(!types.contains("laser")){
  114. // threadPoolExecutor.submit(() -> {
  115. // try {
  116. // // TODO: 2024/1/3 文杰实现
  117. // TimeInterval timer = DateUtil.timer();
  118. // String zipPath = laserService.downloadHandler(scenePlus.getNum());
  119. //// if (StrUtil.isNotEmpty(zipPath)){
  120. //// send(zipPath);
  121. //// }
  122. // downloadLogService.saveLog(scenePlus.getNum(), "laser", CommonSuccessStatus.SUCCESS.code(), null, timer.intervalMinute());
  123. // } catch (Exception e) {
  124. // downloadLogService.saveLog(scenePlus.getNum(), "laser", CommonSuccessStatus.FAIL.code(), ExceptionUtil.stacktraceToString(e, 3000), null);
  125. // log.error("点云场景打包失败,num:{}", scenePlus.getNum(), e);
  126. // }
  127. // });
  128. // }
  129. // ScenePlusExt scenePlusExt = scenePlusExtService.getByPlusId(scenePlus.getId());
  130. // isObj = scenePlusExt.getIsObj();
  131. // }
  132. //
  133. // //下载看看、看见、mesh
  134. // if (scenePlus.getSceneSource() == SceneSource.BM.code()
  135. // || scenePlus.getSceneSource() == SceneSource.ZT.code()
  136. // || isObj == CommonStatus.YES.code()) {
  137. // if(!types.contains("kankan")) {
  138. // threadPoolExecutor.submit(() -> {
  139. // try {
  140. // TimeInterval timer = DateUtil.timer();
  141. // String zipPath = downloadService.downloadHandler(scenePlus.getNum());
  142. //// send(zipPath);
  143. // downloadLogService.saveLog(scenePlus.getNum(), "kankan", CommonSuccessStatus.SUCCESS.code(), null, timer.intervalMinute());
  144. // } catch (Exception e) {
  145. // log.error("看看场景打包失败,num:{}", scenePlus.getNum(), e);
  146. // downloadLogService.saveLog(scenePlus.getNum(), "kankan", CommonSuccessStatus.FAIL.code(), ExceptionUtil.stacktraceToString(e, 3000), null);
  147. // }
  148. // });
  149. // }
  150. // }
  151. // }catch (Exception e){
  152. // log.error("场景打包失败:{}", scenePlus.getNum(), e);
  153. // }
  154. // }
  155. // }
  156. //
  157. //
  158. //
  159. // }
  160. //
  161. // public static void main(String[] args) throws Throwable {
  162. // String filePath = "D:\\test\\xuhua.txt";
  163. //// Set<String> collect = list.stream().filter(v -> !v.contains("_laser")).map(v -> v.substring(v.lastIndexOf("/") + 1, v.lastIndexOf("."))).collect(Collectors.toSet());
  164. //// FileUtil.writeUtf8Lines(collect, filePath);
  165. //
  166. // OSS build = new OSSClientBuilder().build("http://oss-cn-shenzhen.aliyuncs.com","LTAI5tJwboCj3r4vUNkSmbyX", "meDy7VYAWbg8kZCKsoUZcIYQxigWOy");
  167. //
  168. // Long all = new Long(0);
  169. // List<String> strings = FileUtil.readUtf8Lines(filePath);
  170. //
  171. // for (String num : strings) {
  172. // List<String> keyList = new ArrayList<>();
  173. // Long total = 0L;
  174. // boolean flag = true;
  175. // String nextMaker = null;
  176. // ListObjectsRequest listObjectsRequest = new ListObjectsRequest("4dkankan");
  177. // //指定下一级文件
  178. // listObjectsRequest.setPrefix(String.format(UploadFilePath.IMG_VIEW_PATH, num));
  179. // //设置分页的页容量
  180. // listObjectsRequest.setMaxKeys(200);
  181. // do {
  182. // //获取下一页的起始点,它的下一项
  183. // listObjectsRequest.setMarker(nextMaker);
  184. // ObjectListing objectListing = build.listObjects(listObjectsRequest);
  185. // Long space = objectListing.getObjectSummaries().stream().filter(v->!v.getKey().contains("/images/tiles"))
  186. // .mapToLong(OSSObjectSummary::getSize).sum();
  187. // List<String> subKeyList = objectListing.getObjectSummaries().stream().filter(v->!v.getKey().contains("/images/tiles"))
  188. // .map(OSSObjectSummary::getKey).collect(Collectors.toList());
  189. // if (!CollectionUtils.isEmpty(subKeyList)) {
  190. // keyList.addAll(subKeyList);
  191. // }
  192. // total += space;
  193. // nextMaker = objectListing.getNextMarker();
  194. // //全部执行完后,为false
  195. // flag = objectListing.isTruncated();
  196. // } while (flag);
  197. // all += total;
  198. //
  199. //// //下载
  200. //// if(CollUtil.isNotEmpty(keyList)){
  201. //// keyList.stream().filter(v->!v.endsWith("/")).forEach(key->{
  202. //// String localPath = "D:\\test222\\" + num + "\\wwwroot\\" + key;
  203. //// FileUtil.mkParentDirs(localPath);
  204. //// DownloadFileRequest request = new DownloadFileRequest("4dkankan", key);
  205. //// request.setDownloadFile(localPath);
  206. //// // 默认5个任务并发下载
  207. //// request.setTaskNum(5);
  208. //// // 启动断点续传
  209. //// request.setEnableCheckpoint(true);
  210. //// try {
  211. //// build.downloadFile(request);
  212. //// } catch (Throwable e) {
  213. //// throw new RuntimeException(e);
  214. //// }
  215. //// });
  216. //// for (String key : keyList) {
  217. //// if(key.endsWith("/")) continue;
  218. //// String localPath = "D:\\test222\\" + num + "\\wwwroot\\" + key;
  219. //// FileUtil.mkParentDirs(localPath);
  220. //// DownloadFileRequest request = new DownloadFileRequest("4dkankan", key);
  221. //// request.setDownloadFile(localPath);
  222. //// // 默认5个任务并发下载
  223. //// request.setTaskNum(5);
  224. //// // 启动断点续传
  225. //// request.setEnableCheckpoint(true);
  226. //// build.downloadFile(request);
  227. //// }
  228. //// }
  229. //
  230. //// ZipUtil.zip("D:\\test222\\" + num+ "\\wwwroot\\", "D:\\test222\\zip\\" + num+ ".zip");
  231. //
  232. // }
  233. // System.out.println("总容量:" + all/1024/1024/1024);
  234. //
  235. //
  236. //// String filePath = "D:\\test\\kk.txt";
  237. ////// OSS build = new OSSClientBuilder().build("http://oss-cn-shenzhen.aliyuncs.com","LTAI5tJwboCj3r4vUNkSmbyX", "meDy7VYAWbg8kZCKsoUZcIYQxigWOy");
  238. //// List<String> strings = FileUtil.readUtf8Lines(filePath);
  239. ////
  240. //// for (String num : strings) {
  241. //// Jedis jedis = RedisDS.create().getJedis();
  242. //// String sceneJsonData = jedis.get(String.format(RedisKey.SCENE_JSON, num));
  243. ////// if(StrUtil.isEmpty(sceneJsonData)){
  244. ////// try (OSSObject ossObject = build.getObject("4dkankan", String.format(UploadFilePath.DATA_VIEW_PATH, num) + "scene.json");
  245. ////// InputStream objectContent = ossObject.getObjectContent();
  246. ////// ){
  247. ////// StringBuilder contentJson = new StringBuilder();
  248. ////// BufferedReader reader = new BufferedReader(new InputStreamReader(objectContent));
  249. ////// while (true) {
  250. ////// String line = reader.readLine();
  251. ////// if (line == null) break;
  252. ////// contentJson.append(line);
  253. ////// }
  254. ////// sceneJsonData = sceneJsonData.toString();
  255. ////// }
  256. ////// }
  257. //// sceneJsonData = sceneJsonData.replace("https://4dkk.4dage.com/", "");
  258. //// SceneViewInfoBean sceneInfoVO = JSON.parseObject(sceneJsonData, SceneViewInfoBean.class);
  259. //// sceneInfoVO.setScenePassword(null);
  260. //// if(Objects.isNull(sceneInfoVO.getFloorPlanAngle())){
  261. //// sceneInfoVO.setFloorPlanAngle(0f);
  262. //// }
  263. //// if(Objects.isNull(sceneInfoVO.getFloorPlanCompass())){
  264. //// sceneInfoVO.setFloorPlanCompass(0f);
  265. //// }
  266. //// SceneEditControlsBean controls = sceneInfoVO.getControls();
  267. //// if(Objects.isNull(controls.getShowShare())){
  268. //// controls.setShowShare(CommonStatus.YES.code().intValue());
  269. //// }
  270. //// if(Objects.isNull(controls.getShowCapture())){
  271. //// controls.setShowCapture(CommonStatus.YES.code().intValue());
  272. //// }
  273. //// if(Objects.isNull(controls.getShowBillboardTitle())){
  274. //// controls.setShowBillboardTitle(CommonStatus.YES.code().intValue());
  275. //// }
  276. ////
  277. //// FileUtil.writeUtf8String(JSON.toJSONString(sceneInfoVO, SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteNullNumberAsZero), "D:\\test5\\" + num + "\\wwwroot\\scene_view_data\\" + num + "\\data\\scene.json");
  278. ////
  279. //// jedis.close();
  280. //// System.out.println("替换完成:" + num);
  281. //
  282. //// }
  283. //
  284. //
  285. // }
  286. //
  287. // private void send(String zipPath){
  288. // JSONObject jsonObject = new JSONObject();
  289. // jsonObject.put("path", zipPath);
  290. // mqProducer.sendByWorkQueue("rsync-scene", jsonObject);
  291. // }
  292. //
  293. //}