OsgbToB3dmConsumer.java 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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.ResultCode;
  6. import com.fdkankan.fusion.common.util.*;
  7. import com.fdkankan.fusion.exception.BusinessException;
  8. import com.fdkankan.fusion.service.ICommonUploadService;
  9. import com.fdkankan.geo.GeoTransformUtil;
  10. import com.fdkankan.redis.util.RedisUtil;
  11. import com.rabbitmq.client.Channel;
  12. import lombok.extern.slf4j.Slf4j;
  13. import org.locationtech.proj4j.ProjCoordinate;
  14. import org.springframework.amqp.core.Message;
  15. import org.springframework.amqp.rabbit.annotation.Queue;
  16. import org.springframework.amqp.rabbit.annotation.RabbitListener;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.beans.factory.annotation.Value;
  19. import org.springframework.stereotype.Component;
  20. import org.w3c.dom.Document;
  21. import org.w3c.dom.Element;
  22. import javax.xml.parsers.DocumentBuilder;
  23. import javax.xml.parsers.DocumentBuilderFactory;
  24. import java.io.File;
  25. import java.nio.charset.StandardCharsets;
  26. import java.util.HashMap;
  27. import java.util.UUID;
  28. /**
  29. * 场景封存解封 mq
  30. */
  31. @Slf4j
  32. @Component
  33. public class OsgbToB3dmConsumer {
  34. @Autowired
  35. ICommonUploadService commonUploadService;
  36. @Value("${upload.query-path}")
  37. private String ossUrlPrefix;
  38. @RabbitListener(
  39. queuesToDeclare = @Queue("${queue.model.osgbToB3dm:queue-model-osgbToB3dm}")
  40. ,concurrency = "1"
  41. )
  42. public void consumerQueue(Channel channel, Message message) {
  43. String localPath = null;
  44. try {
  45. String messageId = message.getMessageProperties().getMessageId();
  46. String msg = new String(message.getBody(), StandardCharsets.UTF_8);
  47. log.info("osgbToB3dm-mq--messageId:{},msg:{}",messageId,msg);
  48. channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
  49. JSONObject jsonObject = JSONObject.parseObject(msg);
  50. localPath = jsonObject.getString("path");
  51. File file = new File(localPath);
  52. if(!file.exists()){
  53. log.info("osgbToB3dm-mq--messageId:{},msg:{},文件不存在",messageId,localPath);
  54. return;
  55. }
  56. commonUploadService.updateStatus(localPath,0);
  57. ///mnt/manage/media-library/result/ea041f3237df46568f4e83e723e743d4
  58. String sourcePath = file.getParentFile().getPath() +"/"+UUID.randomUUID().toString().replace("-","");
  59. OBJToGLBUtil.OsgbToB3dm(localPath,sourcePath);
  60. String b3dmJsonPath = FileWriterUtil.checkB3dmTileset(new File(sourcePath));
  61. if(b3dmJsonPath == null){
  62. log.info("osgbToB3dm-mq--messageId:{},msg:{},转化失败tileset.json不存在",messageId,localPath);
  63. throw new BusinessException(-1,"转化失败tileset.json不存在");
  64. }
  65. String ossPath = sourcePath.replace("/mnt/","");
  66. ShellUtil.yunUpload(sourcePath,ossPath);
  67. String url = ossUrlPrefix + b3dmJsonPath.replace("/mnt/","");
  68. HashMap<String,String> resultMap = ReadXmlUtil.getLatMap(file);
  69. if(resultMap != null && !resultMap.isEmpty()){
  70. commonUploadService.updateByPath(localPath,url,resultMap.get("wgs84"),resultMap.get("gcj02"));
  71. }else {
  72. commonUploadService.updateByPath(localPath,url);
  73. }
  74. FileUtil.del(localPath);
  75. FileUtil.del(sourcePath);
  76. }catch (Exception e){
  77. log.info("osgbToB3dm-status----消费失败",e);
  78. if(localPath != null){
  79. commonUploadService.updateStatus(localPath,-1);
  80. }
  81. }finally {
  82. }
  83. }
  84. }