瀏覽代碼

合并江门动画模块和媒体库

lyhzzz 3 月之前
父節點
當前提交
4076394ffa
共有 23 個文件被更改,包括 661 次插入114 次删除
  1. 7 0
      pom.xml
  2. 13 0
      src/main/java/com/fdkankan/fusion/common/OssPath.java
  3. 6 0
      src/main/java/com/fdkankan/fusion/common/ResultCode.java
  4. 50 0
      src/main/java/com/fdkankan/fusion/common/enums/FileTypeEnum.java
  5. 9 0
      src/main/java/com/fdkankan/fusion/common/util/FileWriterUtil.java
  6. 32 6
      src/main/java/com/fdkankan/fusion/common/util/OBJToGLBUtil.java
  7. 105 0
      src/main/java/com/fdkankan/fusion/common/util/ReadXmlUtil.java
  8. 1 1
      src/main/java/com/fdkankan/fusion/common/util/ShellCmd.java
  9. 0 28
      src/main/java/com/fdkankan/fusion/common/util/ShellUtil.java
  10. 0 14
      src/main/java/com/fdkankan/fusion/common/util/StringUtils.java
  11. 4 0
      src/main/java/com/fdkankan/fusion/common/util/UploadToOssUtil.java
  12. 1 0
      src/main/java/com/fdkankan/fusion/config/CacheUtil.java
  13. 0 2
      src/main/java/com/fdkankan/fusion/controller/CaseImgController.java
  14. 1 19
      src/main/java/com/fdkankan/fusion/controller/NoLoginController.java
  15. 15 4
      src/main/java/com/fdkankan/fusion/controller/UploadController.java
  16. 5 0
      src/main/java/com/fdkankan/fusion/mapper/ICommonUploadMapper.java
  17. 98 0
      src/main/java/com/fdkankan/fusion/mq/consumer/OsgbToB3dmConsumer.java
  18. 12 7
      src/main/java/com/fdkankan/fusion/service/ICommonUploadService.java
  19. 286 31
      src/main/java/com/fdkankan/fusion/service/impl/CommonUploadServiceImpl.java
  20. 1 1
      src/main/java/com/fdkankan/fusion/service/impl/ModelServiceImpl.java
  21. 1 1
      src/main/java/com/fdkankan/fusion/service/impl/ThreadService.java
  22. 11 0
      src/main/resources/mapper/fusion/CommonUploadMapper.xml
  23. 3 0
      src/main/resources/mapper/fusion/DictFileMapper.xml

+ 7 - 0
pom.xml

@@ -25,6 +25,13 @@
         </dependency>
 
         <dependency>
+            <groupId>com.fdkankan</groupId>
+            <artifactId>4dkankan-utils-geo-query</artifactId>
+            <version>3.0.0-SNAPSHOT</version>
+        </dependency>
+
+
+        <dependency>
             <groupId>mysql</groupId>
             <artifactId>mysql-connector-java</artifactId>
             <version>8.0.25</version>

+ 13 - 0
src/main/java/com/fdkankan/fusion/common/OssPath.java

@@ -0,0 +1,13 @@
+package com.fdkankan.fusion.common;
+
+import com.fdkankan.fusion.config.CacheUtil;
+
+public class OssPath {
+
+    public final static String localPath = CacheUtil.basePath;
+    public final static String MANAGE_FILE_PATH = "fusion/media-library/file/%s";
+    public final static String MANAGE_MODEL_FILE_PATH = "fusion/media-library/model/%s";
+
+
+
+}

+ 6 - 0
src/main/java/com/fdkankan/fusion/common/ResultCode.java

@@ -75,6 +75,12 @@ public enum ResultCode {
     CAMERA_VERSION_NOTEXIT(8026, "相机版本号不存在"),
     CAMERA_VERSION_STATUS_ERROR(8027, "相机版本状态错误"),
 
+    FILE_TYPE_ERROR2(8028, "文件类型不符合规则"),
+
+    UNZIP_ERROR(8029, "解压失败"),
+    UPLOAD_FILE_ERROR(8030, "上传失败,请检查文件格式。"),
+
+    FILE_TYPE_ERROR23(8031, "文件名不得含有中文"),
 
     ;
 

+ 50 - 0
src/main/java/com/fdkankan/fusion/common/enums/FileTypeEnum.java

@@ -0,0 +1,50 @@
+package com.fdkankan.fusion.common.enums;
+
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.Arrays;
+import java.util.List;
+
+public enum FileTypeEnum {
+    IMAGE(0,"图片", Arrays.asList("jpg","png","jpeg")),
+    VIDEO(1,"视频",Arrays.asList("mp4")),
+    MUSIC(2,"音频",Arrays.asList("wav","mp3")),
+    MODEL(3,"模型",Arrays.asList("obj","osgb","b3dm","ply","las","laz","glb")),
+    OTHER(4,"其他",Arrays.asList("shp")),
+    DOC(5,"文档",Arrays.asList("doc","docx","pdf")),
+
+    ;
+    int code;
+    String msg;
+    List<String> typeList;
+
+    FileTypeEnum(int code, String msg, List<String> typeList) {
+        this.code = code;
+        this.msg = msg;
+        this.typeList = typeList;
+    }
+
+    public int getCode() {
+        return code;
+    }
+
+    public String getMsg() {
+        return msg;
+    }
+
+    public List<String> getTypeList() {
+        return typeList;
+    }
+
+    public static FileTypeEnum getByType(String fileType){
+        if(StringUtils.isNotBlank(fileType)){
+            FileTypeEnum[] values = FileTypeEnum.values();
+            for (FileTypeEnum value : values) {
+                if(value.typeList.contains(fileType)){
+                    return value;
+                }
+            }
+        }
+        return null;
+    }
+}

+ 9 - 0
src/main/java/com/fdkankan/fusion/common/util/FileWriterUtil.java

@@ -6,6 +6,8 @@ import java.nio.file.Paths;
 import java.nio.file.StandardCopyOption;
 import java.util.List;
 import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import static cn.hutool.core.util.ClassUtil.getClassLoader;
 
@@ -96,4 +98,11 @@ public class FileWriterUtil {
         return null;
     }
 
+
+    public static boolean isChinese(String str) {
+        String regEx = "[\\u4e00-\\u9fa5]+";
+        Pattern p = Pattern.compile(regEx);
+        Matcher m = p.matcher(str);
+        return m.find();
+    }
 }

+ 32 - 6
src/main/java/com/fdkankan/fusion/common/util/OBJToGLBUtil.java

@@ -1,6 +1,7 @@
 package com.fdkankan.fusion.common.util;
 
 import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.io.file.FileReader;
 import com.alibaba.fastjson.JSONObject;
 import com.fdkankan.fusion.common.FilePath;
 import com.fdkankan.fusion.common.ResultCode;
@@ -140,7 +141,13 @@ public class OBJToGLBUtil {
 
     }
     public static boolean isNumeric2(String str) {
-        return str != null && str.matches("-?\\d+(\\.\\d+)?");
+        try {
+            double i = Double.valueOf(str);
+            return true;
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+        return false;
     }
 
 
@@ -177,7 +184,7 @@ public class OBJToGLBUtil {
         return imgName;
     }
 
-    public static File lasOrPlyToBin(File srcFile) throws IOException {
+    public static File lasOrPlyToBin(File srcFile)  {
         if(!srcFile.exists()){
             srcFile.mkdirs();
         }
@@ -187,11 +194,26 @@ public class OBJToGLBUtil {
         ShellUtil.execCmd(cmd);
         log.info("lasOrPlyToBin---------cmd-over");
         String cloudJs = srcFile.getParentFile().getPath() +"/webcloud/"+ "cloud.js";
-        JSONObject jsonObject = ShellUtil.fixCloud(cloudJs);
+        JSONObject jsonObject = fixCloud(cloudJs);
         FileWriterUtil.writerJson(srcFile.getParentFile().getPath() +"/webcloud/","cloud.js",jsonObject.toJSONString());
         return srcFile.getParentFile();
     }
 
+    public static JSONObject fixCloud(String path)  {
+        cn.hutool.core.io.file.FileReader fileReader = new FileReader(path);
+        String str = fileReader.readString();
+        JSONObject json = JSONObject.parseObject(str);
+
+        String[] pointAttributes = {
+                "POSITION_CARTESIAN",
+                "COLOR_PACKED",
+                "NORMAL_OCT16"
+        };
+
+        json.put("pointAttributes", pointAttributes);
+        return json;
+    }
+
     public static String OsgbToB3dm(File objPathFile) {
         String targetPath = FilePath.MNT_BASE_PATH +"osgb"  +"/" + objPathFile.getName();
         String sourcePath = FilePath.MNT_BASE_PATH +"b3dm"  +"/" + objPathFile.getName();
@@ -200,9 +222,13 @@ public class OBJToGLBUtil {
         File file = new File(targetPath);
         FileUtil.copyContent(objPathFile,file,true);
 
-        String cmd = ShellCmd.osgbTob3dmCmd.replaceAll("@path",FilePath.MNT_BASE_PATH);
-        cmd =cmd.replaceAll("@inputFile",targetPath);
-        cmd =cmd.replaceAll("@outputFile",sourcePath);
+        String cmd = String.format(ShellCmd.osgbTob3dmCmd,targetPath,sourcePath);
+        ShellUtil.execCmd(cmd);
+        return sourcePath;
+    }
+
+    public static String OsgbToB3dm(String  targetPath,String sourcePath) {
+        String cmd = String.format(ShellCmd.osgbTob3dmCmd,targetPath,sourcePath);
         ShellUtil.execCmd(cmd);
         return sourcePath;
     }

+ 105 - 0
src/main/java/com/fdkankan/fusion/common/util/ReadXmlUtil.java

@@ -0,0 +1,105 @@
+package com.fdkankan.fusion.common.util;
+
+import com.fdkankan.geo.GeoTransformUtil;
+import org.locationtech.proj4j.ProjCoordinate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+
+public class ReadXmlUtil {
+
+    public static Logger logger = LoggerFactory.getLogger(ReadXmlUtil.class);
+
+    /**
+     * <?xml version="1.0" encoding="utf-8"?>
+     * <ModelMetadata version="1">
+     * 	<SRS>EPSG:32649</SRS>
+     * 	<SRSOrigin>767052,2475786,0</SRSOrigin>
+     * </ModelMetadata>
+     */
+
+    public static HashMap<String,String> getMapByXml(String path) {
+        try {
+            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+            DocumentBuilder documentBuilder = factory.newDocumentBuilder();
+            Document document = documentBuilder.parse(new File(path));
+            Element root = document.getDocumentElement();
+            NodeList childNodes = root.getChildNodes();
+
+            HashMap<String,String> map = new HashMap<>();
+            for (int temp = 0; temp < childNodes.getLength(); temp++) {
+                org.w3c.dom.Node node = childNodes.item(temp);
+                if (node.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) {
+                    Element eElement = (Element) node;
+                    // 获取元素中的文本内容
+                    map.put(node.getNodeName(),eElement.getTextContent());
+                }
+            }
+            return map;
+        }catch (Exception e){
+            logger.info("getMapByXml-error",e);
+        }
+      return null;
+
+    }
+
+    public static  HashMap<String, String> getLatMap(File file){
+        try {
+            File xmlPath = getXmlPath(file);
+            if(xmlPath == null){
+                return null;
+            }
+            HashMap<String, String> resultMap = new HashMap<>();
+            HashMap<String, String> mapByXml = getMapByXml(xmlPath.getPath());
+            if(mapByXml != null && !mapByXml.isEmpty()){
+                String srs = mapByXml.get("SRS");
+                String sourceCrs = srs.replace("EPSG:","");
+                String srsOrigin = mapByXml.get("SRSOrigin");
+                String[] split = srsOrigin.split(",");
+                Double x = Double.valueOf(split[0]);
+                Double y = Double.valueOf(split[1]);
+                Double z = Double.valueOf(split[2]);
+
+                ProjCoordinate coordinate1 = new ProjCoordinate(x,y,z);
+                Double[] wgs84 = GeoTransformUtil.getWgs84(coordinate1, sourceCrs);
+                resultMap.put("wgs84",wgs84[0]+","+wgs84[1]+","+wgs84[2]);
+                ProjCoordinate coordinate2 = new ProjCoordinate(wgs84[0],wgs84[1],wgs84[2]);
+                Double[] gcj02 = GeoTransformUtil.wgs84ToGcj02(coordinate2);
+                resultMap.put("gcj02",+gcj02[0]+","+gcj02[1]+","+gcj02[2]);
+            }
+            return resultMap;
+        }catch (Exception e){
+            logger.info("getLatMap-error",e);
+        }
+        return null;
+    }
+
+    public static File getXmlPath(File localFile) {
+        try {
+            if(localFile == null || localFile.isFile()){
+                return null;
+            }
+            File[] files = localFile.listFiles();
+            if(files == null || files.length == 0){
+                return null;
+            }
+            for (File file : files) {
+                if(file.getName().contains(".xml")){
+                    return file;
+                }
+            }
+        }catch (Exception e){
+            logger.info("getXmlPath-error",e);
+        }
+
+        return null;
+    }
+}

+ 1 - 1
src/main/java/com/fdkankan/fusion/common/util/ShellCmd.java

@@ -11,5 +11,5 @@ public class ShellCmd {
 	public static final String FYUN_DOWN = "bash /opt/ossutil/fyun-download.sh %s /%s %s %s %s";
 
 	public static final String osgbTob3dmCmd = "sudo docker run --rm -v /mnt/fusion:/mnt/fusion 3dtile:v2 /mnt/fusion/3dtile.sh -f osgb -i " +
-			"@inputFile -o @outputFile";
+			"%s -o %s";
 }

+ 0 - 28
src/main/java/com/fdkankan/fusion/common/util/ShellUtil.java

@@ -139,34 +139,6 @@ public class ShellUtil {
         log.info("解压rar完毕:" + command);
     }
 
-    /**
-     * 修改cloud.js 文件
-     *
-     * @param path
-     * @return
-     * @throws IOException
-     */
-    public static JSONObject fixCloud(String path) throws IOException {
-        FileReader fileReader = new FileReader(path);
-        String str = fileReader.readString();
-        JSONObject json = JSONObject.parseObject(str);
-
-        String[] pointAttributes = {
-                "POSITION_CARTESIAN",
-                "COLOR_PACKED",
-                "NORMAL_OCT16"
-        };
-
-//    String[] pointAttributes = {
-//        "POSITION_CARTESIAN",
-//        "COLOR_PACKED",
-//        "NORMAL_OCT16",
-//        "INTENSITY",
-//        "CLASSIFICATION"
-//    };
-        json.put("pointAttributes", pointAttributes);
-        return json;
-    }
 
 
     /**

+ 0 - 14
src/main/java/com/fdkankan/fusion/common/util/StringUtils.java

@@ -1,14 +0,0 @@
-package com.fdkankan.fusion.common.util;
-
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-public class StringUtils {
-
-    public static boolean isChinese(String str) {
-        String regEx = "[\\u4e00-\\u9fa5]+";
-        Pattern p = Pattern.compile(regEx);
-        Matcher m = p.matcher(str);
-        return m.find();
-    }
-}

+ 4 - 0
src/main/java/com/fdkankan/fusion/common/util/UploadToOssUtil.java

@@ -373,4 +373,8 @@ public class UploadToOssUtil {
 	public String getOssPath(String path) {
 		return path.replace(queryPath,"");
 	}
+
+	public boolean fileExist(String objKey) {
+		return this.existKey(objKey);
+	}
 }

+ 1 - 0
src/main/java/com/fdkankan/fusion/config/CacheUtil.java

@@ -2,5 +2,6 @@ package com.fdkankan.fusion.config;
 
 public class CacheUtil {
     public static String uploadType;
+    public static String basePath ="/mnt";
 
 }

+ 0 - 2
src/main/java/com/fdkankan/fusion/controller/CaseImgController.java

@@ -2,10 +2,8 @@ package com.fdkankan.fusion.controller;
 
 
 import com.fdkankan.fusion.common.FilePath;
-import com.fdkankan.fusion.common.RequestBase;
 import com.fdkankan.fusion.common.ResultCode;
 import com.fdkankan.fusion.common.ResultData;
-import com.fdkankan.fusion.common.util.StringUtils;
 import com.fdkankan.fusion.entity.CaseImg;
 import com.fdkankan.fusion.exception.BusinessException;
 import com.fdkankan.fusion.request.CaseImgParam;

+ 1 - 19
src/main/java/com/fdkankan/fusion/controller/NoLoginController.java

@@ -1,40 +1,22 @@
 package com.fdkankan.fusion.controller;
 
-import cn.hutool.captcha.CaptchaUtil;
-import cn.hutool.captcha.CircleCaptcha;
 import cn.hutool.captcha.LineCaptcha;
-import cn.hutool.captcha.ShearCaptcha;
-import cn.hutool.captcha.generator.CodeGenerator;
-import cn.hutool.captcha.generator.MathGenerator;
 import cn.hutool.captcha.generator.RandomGenerator;
-import cn.hutool.crypto.digest.MD5;
-import cn.hutool.http.ContentType;
 import cn.hutool.http.HttpUtil;
 import com.alibaba.fastjson.JSONObject;
-import com.fdkankan.fusion.common.ResultCode;
 import com.fdkankan.fusion.common.ResultData;
-import com.fdkankan.fusion.common.util.MD5Checksum;
 import com.fdkankan.fusion.common.util.RedisKeyUtil;
-import com.fdkankan.fusion.common.util.StringUtils;
-import com.fdkankan.fusion.exception.BusinessException;
 import com.fdkankan.fusion.response.UserAddRequest;
 import com.fdkankan.fusion.service.ITmUserService;
 import com.fdkankan.redis.util.RedisUtil;
-import jdk.nashorn.internal.runtime.regexp.joni.Config;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.compress.utils.OsgiUtils;
-import org.apache.http.HttpHeaders;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import java.awt.image.BufferedImage;
 import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.security.Security;
-import java.util.Properties;
+
 @RestController
 @RequestMapping("/notAuth")
 @Slf4j

+ 15 - 4
src/main/java/com/fdkankan/fusion/controller/UploadController.java

@@ -5,14 +5,12 @@ import com.fdkankan.fusion.common.ResultCode;
 import com.fdkankan.fusion.exception.BusinessException;
 import com.fdkankan.fusion.common.ResultData;
 import com.fdkankan.fusion.common.ResultCode;
+import com.fdkankan.fusion.service.ICommonUploadService;
 import com.fdkankan.fusion.service.impl.UploadService;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
@@ -27,10 +25,23 @@ public class UploadController {
     UploadService uploadService;
     @Value("${spring.profiles.active}")
     private String environment;
+    @Autowired
+    ICommonUploadService commonUploadService;
 
     @PostMapping("/file")
     public ResultData file(@RequestParam(required = false) MultipartFile file) throws Exception {
 
         return ResultData.ok( uploadService.uploadFile(file,true,String.format(FilePath.File_OSS_PATH,environment,"")));
     }
+
+
+    /**
+     * 文件上传
+     */
+    @RequestMapping(value = "/fileNew", method = RequestMethod.POST)
+    public ResultData uploadNew(@RequestParam(required = false) MultipartFile file,
+            @RequestParam(value = "dictId",required = false) Integer dictId) {
+
+        return commonUploadService.uploadFileNew(dictId,file);
+    }
 }

+ 5 - 0
src/main/java/com/fdkankan/fusion/mapper/ICommonUploadMapper.java

@@ -4,6 +4,8 @@ import com.fdkankan.fusion.entity.CommonUpload;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Mapper;
 
+import java.util.List;
+
 /**
  * <p>
  *  Mapper 接口
@@ -15,4 +17,7 @@ import org.apache.ibatis.annotations.Mapper;
 @Mapper
 public interface ICommonUploadMapper extends BaseMapper<CommonUpload> {
 
+    List<CommonUpload> getDelData();
+
+    void delByIds(List<Integer> ids);
 }

+ 98 - 0
src/main/java/com/fdkankan/fusion/mq/consumer/OsgbToB3dmConsumer.java

@@ -0,0 +1,98 @@
+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.entity.CommonUpload;
+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
+    UploadToOssUtil uploadToOssUtil;
+
+    //@Async
+    public void consumerQueue(Integer uploadId)  {
+        String sourcePath = null;
+        String localPath = null;
+        try {
+            CommonUpload commonUpload = commonUploadService.getById(uploadId);
+            localPath = commonUpload.getUnzipPath();
+            File file = new File(localPath);
+            if(!file.exists()){
+                log.info("osgbToB3dm-mq--,msg:{},文件不存在",localPath);
+                return;
+            }
+            //commonUploadService.updateStatus(uploadId,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不存在");
+            }
+
+            ShellUtil.yunUpload(sourcePath,dir);
+            String url = ossUrlPrefix + dir + File.separator +jsonFile.getName();
+            HashMap<String,String> resultMap = ReadXmlUtil.getLatMap(file);
+            if(resultMap != null && !resultMap.isEmpty()){
+                commonUploadService.updateByPath(uploadId,url,resultMap.get("wgs84"),resultMap.get("gcj02"));
+            }else {
+                commonUploadService.updateByPath(uploadId,url);
+            }
+
+        }catch (Exception e){
+            log.info("osgbToB3dm-status----消费失败",e);
+            if(localPath != null){
+                commonUploadService.updateStatus(uploadId,-1);
+            }
+        }finally {
+            try {
+                FileUtil.del(localPath);
+                FileUtil.del(sourcePath);
+            }catch ( Exception e){
+                log.info("删除文件失败:{}",e);
+            }
+        }
+
+    }
+
+}

+ 12 - 7
src/main/java/com/fdkankan/fusion/service/ICommonUploadService.java

@@ -1,7 +1,10 @@
 package com.fdkankan.fusion.service;
 
+import com.fdkankan.fusion.common.ResultData;
+import com.fdkankan.fusion.common.enums.FileTypeEnum;
 import com.fdkankan.fusion.entity.CommonUpload;
 import com.baomidou.mybatisplus.extension.service.IService;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.util.List;
 
@@ -11,18 +14,20 @@ import java.util.List;
  * </p>
  *
  * @author 
- * @since 2024-12-06
+ * @since 2025-02-10
  */
 public interface ICommonUploadService extends IService<CommonUpload> {
 
-    List<CommonUpload> getByStatus(Integer status);
+    ResultData uploadFileNew( Integer dictId,MultipartFile file);
 
-    void updateByPath(String msg, String url);
-    void updateByPath(String msg, String url,String wgs84 ,String gcj02);
+    CommonUpload add(String replace, String url, String s, String uuid, FileTypeEnum fileTypeEnum,String resultFormat, String replace1, Integer status, String unzipPath, Integer dictId);
 
-    void updateStatus(String localPath,Integer status);
+    void updateStatus(Integer localPath, Integer i);
 
-    List<CommonUpload> getIsSystem();
+    void updateByPath(Integer uploadId, String url, String wgs84, String gcj02);
+    void updateByPath(Integer uploadId, String url);
 
-    CommonUpload addSystemFile(String ossKey,Long fileSize,String fileName);
+    List<CommonUpload> getDelData();
+
+    void delByIds(List<Integer> ids);
 }

+ 286 - 31
src/main/java/com/fdkankan/fusion/service/impl/CommonUploadServiceImpl.java

@@ -1,18 +1,36 @@
 package com.fdkankan.fusion.service.impl;
 
+
 import cn.hutool.core.io.FileUtil;
-import com.baomidou.dynamic.datasource.annotation.DS;
-import com.baomidou.mybatisplus.core.conditions.Wrapper;
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.fdkankan.fusion.common.OssPath;
+import com.fdkankan.fusion.common.ResultCode;
+import com.fdkankan.fusion.common.ResultData;
+import com.fdkankan.fusion.common.enums.FileTypeEnum;
+import com.fdkankan.fusion.common.util.*;
+import com.fdkankan.fusion.config.CacheUtil;
 import com.fdkankan.fusion.entity.CommonUpload;
+import com.fdkankan.fusion.entity.Dict;
+import com.fdkankan.fusion.entity.DictFile;
+import com.fdkankan.fusion.exception.BusinessException;
 import com.fdkankan.fusion.mapper.ICommonUploadMapper;
+import com.fdkankan.fusion.mq.consumer.OsgbToB3dmConsumer;
 import com.fdkankan.fusion.service.ICommonUploadService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fdkankan.fusion.service.IDictFileService;
+import com.fdkankan.fusion.service.IDictService;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.UUID;
 
 /**
  * <p>
@@ -23,36 +41,268 @@ import java.util.List;
  * @since 2024-12-06
  */
 @Service
+@Slf4j
 public class CommonUploadServiceImpl extends ServiceImpl<ICommonUploadMapper, CommonUpload> implements ICommonUploadService {
 
+
+    @Autowired
+    ICommonUploadService commonUploadService;
+    @Autowired
+    IDictFileService dictFileService;
+
+    @Autowired
+    private UploadToOssUtil uploadToOssUtil;
+
+    @Value("${upload.query-path}")
+    private String ossUrlPrefix;
+
+    @Autowired
+    IDictService dictService;
+
     @Override
-    public List<CommonUpload> getByStatus(Integer status) {
-        LambdaQueryWrapper<CommonUpload> wrapper = new LambdaQueryWrapper<>();
-        wrapper.eq(CommonUpload::getStatus,status);
-        return this.list(wrapper);
+    public ResultData uploadFileNew( Integer dictId,MultipartFile file) {
+        if(file.isEmpty() ){
+            throw new BusinessException(ResultCode.UPLOAD_ERROR);
+        }
+        File  tempFile = null;
+        try {
+            String uuid = UUID.randomUUID().toString().replace("-","");
+            String originalFilename = file.getOriginalFilename();
+            String extName = originalFilename.substring(originalFilename.lastIndexOf(".")).toLowerCase();
+
+            if(dictId != null){
+                Dict dict = dictService.getById(dictId);
+                if(dict == null ){
+                    throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
+                }
+                if("animation".equals(dict.getUseType()) && !(extName.equalsIgnoreCase(".zip") || extName.equalsIgnoreCase(".glb"))){
+                    throw new BusinessException(ResultCode.FILE_TYPE_ERROR2);
+                }
+
+            }
+
+            String ossPath = String.format(OssPath.MANAGE_MODEL_FILE_PATH, uuid + extName);
+
+            tempFile = new File(OssPath.localPath + ossPath);
+            if(!tempFile.getParentFile().exists()){
+                tempFile.getParentFile().mkdirs();
+            }
+            file.transferTo(tempFile);
+            if(extName.equals(".zip")){
+                return uploadModelZip(originalFilename.replace(extName, ""),tempFile,dictId);
+            }
+            ShellUtil.yunUpload(tempFile.getPath(),ossPath);
+
+            String url = this.ossUrlPrefix + ossPath;
+
+            FileTypeEnum fileTypeEnum = FileTypeEnum.getByType(extName.replace(".", ""));
+            if(fileTypeEnum == null){
+                throw new BusinessException(ResultCode.FILE_TYPE_ERROR2);
+            }
+            String format = extName.replace(".", "");
+            CommonUpload commonUpload = commonUploadService.add(originalFilename.replace(extName, ""), url, String.valueOf(file.getSize()), uuid, fileTypeEnum, format,format,1,null,dictId);
+            tempFile.delete();
+            return ResultData.ok(commonUpload);
+        }catch ( BusinessException e){
+            log.info("upload-file-error:{}",e);
+            throw e;
+        }catch (Exception e){
+            log.info("upload-file-error:{}",e);
+            throw new BusinessException(ResultCode.UPLOAD_ERROR);
+        }
     }
 
+    private ResultData uploadModelZip(String oldName,File file,Integer dictId) {
+
+        String ossZipPath = String.format(OssPath.MANAGE_MODEL_FILE_PATH, UUID.randomUUID().toString().replace("-", ""));
+        String unzipPath = CacheUtil.basePath + ossZipPath;
+        ShellUtil.unZip(file.getPath(),unzipPath);
+        try {
+            Thread.sleep(1000L);
+            FileUtil.del(file.getPath());
+        }catch (Exception e){
+            log.info("删除文件失败:{}",e);
+        }
+
+        //FileUtil.copyContent(file,new File(unzipPath),true);
+        File unZipFile = new File(unzipPath);
+
+        if(!unZipFile.exists() || !unZipFile.isDirectory() ){
+            throw new BusinessException(ResultCode.UNZIP_ERROR);
+        }
+        List<File> fileList = new ArrayList<>();
+        FileWriterUtil.getCanRunList(fileList,unZipFile);
+        if(fileList.size() <=0){
+            throw new BusinessException(ResultCode.UPLOAD_FILE_ERROR);
+        }
+        File modelFile = fileList.get(0);
+        String modelFileFormat = modelFile.getName().split("\\.")[1].toLowerCase();
+
+        FileTypeEnum fileTypeEnum = FileTypeEnum.getByType(modelFileFormat);
+        if(fileTypeEnum == null){
+            throw new BusinessException(ResultCode.FILE_TYPE_ERROR2);
+        }
+
+        if(dictId != null){
+            Dict dict = dictService.getById(dictId);
+            if(dict == null ){
+                throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
+            }
+            if("animation".equals(dict.getUseType()) && !(modelFileFormat.equals("glb") || modelFileFormat.equals("obj"))){
+                throw new BusinessException(ResultCode.FILE_TYPE_ERROR2);
+            }
+
+        }
+
+        if(FileWriterUtil.isChinese(modelFile.getName())){
+            throw new BusinessException(ResultCode.FILE_TYPE_ERROR23);
+        }
+        if(FileWriterUtil.isChinese(modelFile.getPath())){
+            throw new BusinessException(ResultCode.FILE_TYPE_ERROR23);
+        }
+        String url = null;
+        String resultFormat = modelFileFormat;
+        switch (modelFileFormat){
+            case "obj" :  resultFormat = "obj";
+                url = uploadObjOss(unzipPath,modelFile);break;
+            case "glb" :   url = uploadOss(unzipPath,modelFile);break;
+            case "laz" :    url = uploadLazOss(unzipPath,modelFile); break;
+            case "shp" :   url = uploadOss(unzipPath,modelFile); break;
+            case "b3dm" :  url = uploadB3dm(unzipPath,modelFile); break;
+            case "las" :
+            case "ply" :  url = uploadLasOrPly(unzipPath,modelFile);break;
+            case "osgb":
+                    resultFormat = "b3dm";
+                   break;
+            default: break;
+        }
+
+        Integer status = StringUtils.isNotBlank(url) ?1:-1;
+        url = StringUtils.isNotBlank(url) ?ossUrlPrefix + url:null;
+        CommonUpload commonUpload = commonUploadService.add(oldName,url, String.valueOf(getDirectorySize(unZipFile)),
+                null, fileTypeEnum, modelFileFormat,resultFormat,status,unZipFile.getPath(),dictId);
+        if("osgb".equals(modelFileFormat)){
+            //commonUploadService.updateStatus(commonUpload.getId(),0);
+            uploadOsgb(commonUpload.getId()) ;
+        }
+        return ResultData.ok(commonUpload);
+    }
+
+    private String uploadObjOss(String unzipPath, File modelFile) {
+        OBJToGLBUtil.checkObj(modelFile.getPath());
+        String localGlbPath = modelFile.getPath().replace(".obj",".glb");
+        OBJToGLBUtil.objToGlb2(modelFile.getPath(),localGlbPath);
+        String ossPath = unzipPath.replace(OssPath.localPath,"");
+        ShellUtil.yunUpload(unzipPath,ossPath);
+        if(!uploadToOssUtil.fileExist(localGlbPath.replace(OssPath.localPath,""))){
+            throw new BusinessException(ResultCode.UPLOAD_FILE_ERROR);
+        }
+        FileUtil.del(unzipPath);
+        return  ossUrlPrefix +  localGlbPath.replace(OssPath.localPath,"");
+    }
+
+    private String uploadB3dm(String unzipPath, File modelFile) {
+        String b3dmJsonPath = FileWriterUtil.checkB3dmTileset(new File(unzipPath));
+        if(b3dmJsonPath == null){
+            throw new BusinessException(ResultCode.UPLOAD_FILE_OBJ_ERROR);
+        }
+        String ossPath = b3dmJsonPath.replace(OssPath.localPath, "");
+        uploadOss(unzipPath,modelFile);
+        if(!uploadToOssUtil.fileExist(ossPath)){
+            throw new BusinessException(ResultCode.UPLOAD_FILE_ERROR);
+        }
+        FileUtil.del(unzipPath);
+        return ossUrlPrefix +  ossPath;
+    }
+
+    @Autowired
+    OsgbToB3dmConsumer osgbToB3dmConsumer;
+
+    private void uploadOsgb(Integer uploadId) {
+         osgbToB3dmConsumer.consumerQueue(uploadId);
+    }
+
+    private String uploadLazOss(String unzipPath,File modelFile) {
+        String ossPath = unzipPath.replace(OssPath.localPath,"");
+        String modelOssPath = modelFile.getPath().replace(OssPath.localPath, "");
+        ShellUtil.yunUpload(unzipPath,ossPath);
+        if(!uploadToOssUtil.fileExist(modelOssPath)){
+            throw new BusinessException(ResultCode.UPLOAD_FILE_ERROR);
+        }
+        FileUtil.del(unzipPath);
+        return ossUrlPrefix +  ossPath;
+    }
+
+    private String uploadOss(String unzipPath,File modelFile) {
+        String ossPath = unzipPath.replace(OssPath.localPath,"");
+        String modelOssPath = modelFile.getPath().replace(OssPath.localPath, "");
+        ShellUtil.yunUpload(unzipPath,ossPath);
+        if(!uploadToOssUtil.existKey(modelOssPath)){
+            throw new BusinessException(ResultCode.UPLOAD_FILE_ERROR);
+        }
+        FileUtil.del(unzipPath);
+        return ossUrlPrefix +  modelOssPath;
+    }
+
+    private String uploadLasOrPly(String unzipPath ,File modelFile) {
+        File mntFile = OBJToGLBUtil.lasOrPlyToBin(modelFile);
+        String ossPath = mntFile.getPath().replace(OssPath.localPath,"");
+        ShellUtil.yunUpload(mntFile.getPath(),ossPath);
+        if(!uploadToOssUtil.existKey(ossPath+"/webcloud/cloud.js")){
+            throw new BusinessException(-1,"缺少cloud.js文件");
+        }
+        FileUtil.del(unzipPath);
+        return ossUrlPrefix +  ossPath + "/webcloud";
+    }
+
+
+
     @Override
-    public void updateByPath(String msg, String url) {
+    public CommonUpload add(String fileName, String url, String fileSize, String uuid, FileTypeEnum fileTypeEnum, String resultFormat,String replace1, Integer status, String unzipPath, Integer dictId) {
+        CommonUpload upload = new CommonUpload();
+        upload.setFileName(fileName);
+        upload.setFileUrl(url);
+        upload.setFileSize(fileSize);
+        upload.setNewFileName(uuid);
+        upload.setFileType(fileTypeEnum.getCode());
+        upload.setFileTypeStr(fileTypeEnum.getMsg());
+        upload.setFileFormat(resultFormat);
+        upload.setResultFileFormat(replace1);
+        upload.setStatus(status);
+        upload.setUnzipPath(unzipPath);
+        this.save(upload);
+
+        DictFile dictFile = new DictFile();
+        dictFile.setName(fileName);
+        dictFile.setTypeKey("media-library");
+        dictFile.setUploadId(upload.getId());
+        dictFile.setDictId(dictId);
+        dictFileService.saveOrUpdate(dictFile);
+
+        return upload;
+    }
+
+    @Override
+    public void updateByPath(Integer uploadId, String url) {
         LambdaUpdateWrapper<CommonUpload> wrapper = new LambdaUpdateWrapper<>();
-        wrapper.eq(CommonUpload::getUnzipPath,msg);
+        wrapper.eq(CommonUpload::getId,uploadId);
         wrapper.set(CommonUpload::getStatus,1);
         wrapper.set(CommonUpload::getFileUrl,url);
         this.update(wrapper);
     }
 
     @Override
-    public void updateStatus(String localPath,Integer status) {
+    public void updateStatus(Integer uploadId,Integer status) {
         LambdaUpdateWrapper<CommonUpload> wrapper = new LambdaUpdateWrapper<>();
-        wrapper.eq(CommonUpload::getUnzipPath,localPath);
+        wrapper.eq(CommonUpload::getId,uploadId);
         wrapper.set(CommonUpload::getStatus,status);
         this.update(wrapper);
     }
 
     @Override
-    public void updateByPath(String msg, String url,String wgs84 ,String gcj02) {
+    public void updateByPath(Integer uploadId, String url,String wgs84 ,String gcj02) {
         LambdaUpdateWrapper<CommonUpload> wrapper = new LambdaUpdateWrapper<>();
-        wrapper.eq(CommonUpload::getUnzipPath,msg);
+        wrapper.eq(CommonUpload::getId,uploadId);
         wrapper.set(CommonUpload::getStatus,1);
         wrapper.set(CommonUpload::getFileUrl,url);
         wrapper.set(CommonUpload::getWgs84,wgs84);
@@ -60,27 +310,32 @@ public class CommonUploadServiceImpl extends ServiceImpl<ICommonUploadMapper, Co
         this.update(wrapper);
     }
 
+
+    public static long getDirectorySize(File directory) {
+        long size = 0;
+        try {
+            File[] files = directory.listFiles();
+            if (files != null) {
+                for (File file : files) {
+                    if (file.isFile()) {
+                        size += file.length();
+                    } else if (file.isDirectory()) {
+                        size += getDirectorySize(file);
+                    }
+                }
+            }
+        }catch (Exception e){
+        }
+        return size;
+    }
+
     @Override
-    public List<CommonUpload> getIsSystem() {
-        LambdaQueryWrapper<CommonUpload> wrapper = new LambdaQueryWrapper<>();
-        wrapper.eq(CommonUpload::getUseType,"animation");
-        return this.list(wrapper);
+    public List<CommonUpload> getDelData() {
+        return this.getBaseMapper().getDelData();
     }
 
     @Override
-    public CommonUpload addSystemFile(String ossKey,Long fileSize,String fileName) {
-        CommonUpload commonUpload = new CommonUpload();
-        commonUpload.setFileName(fileName);
-        commonUpload.setFileUrl(ossKey);
-        commonUpload.setFileSize(fileSize+"");
-        commonUpload.setNewFileName(fileName);
-        commonUpload.setFileType(3);
-        commonUpload.setFileTypeStr("模型");
-        commonUpload.setFileFormat("glb");
-        commonUpload.setResultFileFormat("glb");
-        commonUpload.setStatus(1);
-        commonUpload.setUseType("animation");
-        this.save(commonUpload);
-        return commonUpload;
+    public void delByIds(List<Integer> ids) {
+         this.getBaseMapper().delByIds(ids);
     }
 }

+ 1 - 1
src/main/java/com/fdkankan/fusion/service/impl/ModelServiceImpl.java

@@ -87,7 +87,7 @@ public class ModelServiceImpl extends ServiceImpl<IModelMapper, Model> implement
         if(StringUtils.isEmpty(fileName)){
             throw new BusinessException(ResultCode.UPLOAD_FILE_NO_EXIST);
         }
-        if(com.fdkankan.fusion.common.util.StringUtils.isChinese(fileName)){
+        if(FileWriterUtil.isChinese(fileName)){
             throw new BusinessException(ResultCode.UPLOAD_FILE_CHINA_NAME);
         }
         if(fileName.length() >50){

+ 1 - 1
src/main/java/com/fdkankan/fusion/service/impl/ThreadService.java

@@ -65,7 +65,7 @@ public class ThreadService {
             if(file1 == null){
                 throw new BusinessException(-1,"可上传文件不存在");
             }
-            if(com.fdkankan.fusion.common.util.StringUtils.isChinese(file1.getName())){
+            if(FileWriterUtil.isChinese(file1.getName())){
                 throw new BusinessException(-1,"压缩包中文");
             }
             String b3dmJsonPath = null;

+ 11 - 0
src/main/resources/mapper/fusion/CommonUploadMapper.xml

@@ -2,4 +2,15 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.fdkankan.fusion.mapper.ICommonUploadMapper">
 
+
+    <select id="getDelData" resultType="com.fdkankan.fusion.entity.CommonUpload">
+        select * from t_common_upload where rec_status = 'I'
+    </select>
+
+    <delete id="delByIds">
+        delete from t_common_upload where id in
+        <foreach collection="ids" item="id" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+    </delete>
 </mapper>

+ 3 - 0
src/main/resources/mapper/fusion/DictFileMapper.xml

@@ -33,5 +33,8 @@
                 #{dict}
             </foreach>
         </if>
+
+        order by df.id desc
+
     </select>
 </mapper>