OsgbToB3dmConsumer.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package com.fdkankan.fusion.mq.consumer;
  2. import cn.hutool.core.io.FileUtil;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.fdkankan.fusion.common.FilePath;
  5. import com.fdkankan.fusion.common.OssPath;
  6. import com.fdkankan.fusion.common.ResultCode;
  7. import com.fdkankan.fusion.common.util.*;
  8. import com.fdkankan.fusion.config.CacheUtil;
  9. import com.fdkankan.fusion.exception.BusinessException;
  10. import com.fdkankan.fusion.service.ICommonUploadService;
  11. import com.fdkankan.redis.util.RedisUtil;
  12. import lombok.extern.slf4j.Slf4j;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.beans.factory.annotation.Value;
  15. import org.springframework.scheduling.annotation.Async;
  16. import org.springframework.stereotype.Component;
  17. import org.w3c.dom.Document;
  18. import org.w3c.dom.Element;
  19. import javax.xml.parsers.DocumentBuilder;
  20. import javax.xml.parsers.DocumentBuilderFactory;
  21. import java.io.File;
  22. import java.lang.reflect.Field;
  23. import java.nio.charset.StandardCharsets;
  24. import java.util.HashMap;
  25. import java.util.UUID;
  26. /**
  27. * 场景封存解封 mq
  28. */
  29. @Slf4j
  30. @Component
  31. public class OsgbToB3dmConsumer {
  32. @Autowired
  33. ICommonUploadService commonUploadService;
  34. @Value("${upload.query-path}")
  35. private String ossUrlPrefix;
  36. @Autowired
  37. LocalToOssUtil localToOssUtil;
  38. @Async
  39. public void consumerQueue(String localPath) {
  40. String sourcePath = null;
  41. try {
  42. localPath = CacheUtil.basePath+ localPath;
  43. File file = new File(localPath);
  44. if(!file.exists()){
  45. log.info("osgbToB3dm-mq--,msg:{},文件不存在",localPath);
  46. return;
  47. }
  48. commonUploadService.updateStatus(localPath,0);
  49. ///mnt/manage/media-library/result/ea041f3237df46568f4e83e723e743d4
  50. String dir = String.format(OssPath.MANAGE_MODEL_FILE_PATH ,UUID.randomUUID().toString().replace("-",""));
  51. sourcePath = CacheUtil.basePath +File.separator+ dir;
  52. OBJToGLBUtil.OsgbToB3dm(localPath,sourcePath);
  53. String b3dmJsonPath = FileWriterUtil.checkB3dmTileset(new File(sourcePath));
  54. if(b3dmJsonPath == null){
  55. log.info("osgbToB3dm-mq,msg:{},转化失败tileset.json不存在",localPath);
  56. throw new BusinessException(-1,"转化失败tileset.json不存在");
  57. }
  58. File jsonFile = new File(b3dmJsonPath);
  59. if(!jsonFile.exists()){
  60. log.info("osgbToB3dm-mq,msg:{},转化失败tileset.json不存在",localPath);
  61. throw new BusinessException(-1,"转化失败tileset.json不存在");
  62. }
  63. //String ossPath = sourcePath.replace(CacheUtil.basePath,"");
  64. //localToOssUtil.uploadOss(sourcePath,ossPath);
  65. String url = CacheUtil.mapping + dir+ File.separator +jsonFile.getName();
  66. HashMap<String,String> resultMap = ReadXmlUtil.getLatMap(file);
  67. if(resultMap != null && !resultMap.isEmpty()){
  68. commonUploadService.updateByPath(localPath,url,resultMap.get("wgs84"),resultMap.get("gcj02"));
  69. }else {
  70. commonUploadService.updateByPath(localPath,url);
  71. }
  72. }catch (Exception e){
  73. log.info("osgbToB3dm-status----消费失败",e);
  74. if(localPath != null){
  75. commonUploadService.updateStatus(localPath,-1);
  76. }
  77. }finally {
  78. try {
  79. FileUtil.del(localPath);
  80. //FileUtil.del(sourcePath);
  81. }catch ( Exception e){
  82. log.info("删除文件失败:{}",e);
  83. }
  84. }
  85. }
  86. }