123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- package com.fdkankan.fusion.mq.consumer;
- import cn.hutool.core.io.FileUtil;
- import com.alibaba.fastjson.JSONObject;
- import com.fdkankan.fusion.common.FilePath;
- import com.fdkankan.fusion.common.OssPath;
- import com.fdkankan.fusion.common.ResultCode;
- import com.fdkankan.fusion.common.util.*;
- import com.fdkankan.fusion.config.CacheUtil;
- import com.fdkankan.fusion.exception.BusinessException;
- import com.fdkankan.fusion.service.ICommonUploadService;
- import com.fdkankan.redis.util.RedisUtil;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.scheduling.annotation.Async;
- import org.springframework.stereotype.Component;
- import org.w3c.dom.Document;
- import org.w3c.dom.Element;
- import javax.xml.parsers.DocumentBuilder;
- import javax.xml.parsers.DocumentBuilderFactory;
- import java.io.File;
- import java.lang.reflect.Field;
- import java.nio.charset.StandardCharsets;
- import java.util.HashMap;
- import java.util.UUID;
- /**
- * 场景封存解封 mq
- */
- @Slf4j
- @Component
- public class OsgbToB3dmConsumer {
- @Autowired
- ICommonUploadService commonUploadService;
- @Value("${upload.query-path}")
- private String ossUrlPrefix;
- @Autowired
- LocalToOssUtil localToOssUtil;
- @Async
- public void consumerQueue(String localPath) {
- String sourcePath = null;
- try {
- localPath = CacheUtil.basePath+ localPath;
- File file = new File(localPath);
- if(!file.exists()){
- log.info("osgbToB3dm-mq--,msg:{},文件不存在",localPath);
- return;
- }
- commonUploadService.updateStatus(localPath,0);
- ///mnt/manage/media-library/result/ea041f3237df46568f4e83e723e743d4
- String dir = String.format(OssPath.MANAGE_MODEL_FILE_PATH ,UUID.randomUUID().toString().replace("-",""));
- sourcePath = CacheUtil.basePath +File.separator+ dir;
- OBJToGLBUtil.OsgbToB3dm(localPath,sourcePath);
- String b3dmJsonPath = FileWriterUtil.checkB3dmTileset(new File(sourcePath));
- if(b3dmJsonPath == null){
- log.info("osgbToB3dm-mq,msg:{},转化失败tileset.json不存在",localPath);
- throw new BusinessException(-1,"转化失败tileset.json不存在");
- }
- File jsonFile = new File(b3dmJsonPath);
- if(!jsonFile.exists()){
- log.info("osgbToB3dm-mq,msg:{},转化失败tileset.json不存在",localPath);
- throw new BusinessException(-1,"转化失败tileset.json不存在");
- }
- //String ossPath = sourcePath.replace(CacheUtil.basePath,"");
- //localToOssUtil.uploadOss(sourcePath,ossPath);
- String url = CacheUtil.mapping + dir+ File.separator +jsonFile.getName();
- HashMap<String,String> resultMap = ReadXmlUtil.getLatMap(file);
- if(resultMap != null && !resultMap.isEmpty()){
- commonUploadService.updateByPath(localPath,url,resultMap.get("wgs84"),resultMap.get("gcj02"));
- }else {
- commonUploadService.updateByPath(localPath,url);
- }
- }catch (Exception e){
- log.info("osgbToB3dm-status----消费失败",e);
- if(localPath != null){
- commonUploadService.updateStatus(localPath,-1);
- }
- }finally {
- try {
- FileUtil.del(localPath);
- //FileUtil.del(sourcePath);
- }catch ( Exception e){
- log.info("删除文件失败:{}",e);
- }
- }
- }
- }
|