|
@@ -1,18 +1,38 @@
|
|
|
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.FileWriterUtil;
|
|
|
+import com.fdkankan.fusion.common.util.OBJToGLBUtil;
|
|
|
+import com.fdkankan.fusion.common.util.ShellUtil;
|
|
|
+import com.fdkankan.fusion.common.util.LocalToOssUtil;
|
|
|
+import com.fdkankan.fusion.config.CacheUtil;
|
|
|
+import com.fdkankan.fusion.config.FusionConfig;
|
|
|
import com.fdkankan.fusion.entity.CommonUpload;
|
|
|
+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.fyun.face.FYunFileServiceInterface;
|
|
|
+import com.fdkankan.rabbitmq.util.RabbitMqProducer;
|
|
|
+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 scala.Int;
|
|
|
|
|
|
import java.io.File;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -20,40 +40,242 @@ import java.util.List;
|
|
|
* </p>
|
|
|
*
|
|
|
* @author
|
|
|
- * @since 2024-12-06
|
|
|
+ * @since 2025-02-10
|
|
|
*/
|
|
|
@Service
|
|
|
-@DS("db2")
|
|
|
+@Slf4j
|
|
|
public class CommonUploadServiceImpl extends ServiceImpl<ICommonUploadMapper, CommonUpload> implements ICommonUploadService {
|
|
|
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ICommonUploadService commonUploadService;
|
|
|
+ @Autowired
|
|
|
+ IDictFileService dictFileService;
|
|
|
+ @Autowired
|
|
|
+ FusionConfig fusionConfig;
|
|
|
+ @Autowired
|
|
|
+ FYunFileServiceInterface fYunFileServiceInterface;
|
|
|
+ @Autowired
|
|
|
+ RabbitMqProducer rabbitMqProducer;
|
|
|
+ @Override
|
|
|
+ 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 name = file.getOriginalFilename();
|
|
|
+ String extName = name.substring(name.lastIndexOf(".")).toLowerCase();
|
|
|
+ String ossPath = String.format(OssPath.MANAGE_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(name.replace(extName, ""),tempFile,dictId);
|
|
|
+ }
|
|
|
+ fYunFileServiceInterface.uploadFile(tempFile.getPath(), ossPath);
|
|
|
+ //String url = this.ossUrlPrefix + ossPath;
|
|
|
+ String url = fusionConfig.getOssUrlPrefix() + 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(name.replace(extName, ""), url, String.valueOf(file.getSize()), uuid, fileTypeEnum, format,format,1,null,dictId);
|
|
|
+ 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 = OssPath.localPath + 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);
|
|
|
+
|
|
|
+ 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 modelFileFormat = modelFile.getName().split("\\.")[1].toLowerCase();
|
|
|
+ String url = null;
|
|
|
+ String resultFormat = modelFileFormat;
|
|
|
+ switch (modelFileFormat){
|
|
|
+ case "obj" : resultFormat = "obj";
|
|
|
+ url = uploadObjOss(ossZipPath,modelFile);break;
|
|
|
+ case "laz" : url = uploadLazOss(ossZipPath,modelFile); break;
|
|
|
+ case "shp" : url = uploadOss(ossZipPath,modelFile); break;
|
|
|
+ case "b3dm" : url = uploadB3dm(ossZipPath,modelFile); break;
|
|
|
+ case "las" :
|
|
|
+ case "ply" : url = uploadLasOrPly(ossZipPath,modelFile);break;
|
|
|
+ case "osgb":
|
|
|
+ resultFormat = "b3dm";
|
|
|
+ break;
|
|
|
+ default: break;
|
|
|
+ }
|
|
|
+ FileTypeEnum fileTypeEnum = FileTypeEnum.getByType(modelFileFormat);
|
|
|
+ if(fileTypeEnum == null){
|
|
|
+ throw new BusinessException(ResultCode.FILE_TYPE_ERROR2);
|
|
|
+ }
|
|
|
+ Integer status = StringUtils.isNotBlank(url) ? 1: -1;
|
|
|
+ url = StringUtils.isNotBlank(url) ? fusionConfig.getOssUrlPrefix() + url : null;
|
|
|
+ CommonUpload commonUpload = commonUploadService.add(oldName,url, String.valueOf(getDirectorySize(unZipFile)),
|
|
|
+ null, fileTypeEnum, modelFileFormat,resultFormat,status,unZipFile.getPath(),dictId);
|
|
|
+ if("osgb".equals(modelFileFormat)){
|
|
|
+ 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);
|
|
|
+// File file = new File(localGlbPath);
|
|
|
+// if(!file.exists()){
|
|
|
+// throw new BusinessException(ResultCode.UPLOAD_FILE_ERROR);
|
|
|
+// }
|
|
|
+ String ossKey = unzipPath.replace(OssPath.localPath,"");
|
|
|
+ ShellUtil.yunUpload(unzipPath,ossKey);
|
|
|
+ return fusionConfig.getOssUrlPrefix() + ossKey +File.separator+modelFile.getName();
|
|
|
+ }
|
|
|
+
|
|
|
+ private String uploadB3dm(String unzipPath, File modelFile) {
|
|
|
+ String b3dmJsonPath = FileWriterUtil.checkB3dmTileset(new File(OssPath.localPath + unzipPath));
|
|
|
+ if(b3dmJsonPath == null){
|
|
|
+ throw new BusinessException(ResultCode.UPLOAD_FILE_OBJ_ERROR);
|
|
|
+ }
|
|
|
+ //uploadOss(unzipPath,modelFile);
|
|
|
+ File file = new File(b3dmJsonPath);
|
|
|
+ if(!file.exists()){
|
|
|
+ throw new BusinessException(ResultCode.UPLOAD_FILE_ERROR);
|
|
|
+ }
|
|
|
+ String ossKey = unzipPath.replace(OssPath.localPath,"");
|
|
|
+ ShellUtil.yunUpload(unzipPath,ossKey);
|
|
|
+ return ossKey +File.separator +file.getName();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void uploadOsgb(Integer uploadId) {
|
|
|
+ //osgbToB3dmConsumer.consumerQueue(CacheUtil.basePath + unzipPath);
|
|
|
+ HashMap<String,Integer> map = new HashMap<>();
|
|
|
+ map.put("uploadId",uploadId);
|
|
|
+ rabbitMqProducer.sendByWorkQueue("queue-model-osgbToB3dm",map);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String uploadLazOss(String unzipPath,File modelFile) {
|
|
|
+ if(!modelFile.exists()){
|
|
|
+ throw new BusinessException(ResultCode.UPLOAD_FILE_ERROR);
|
|
|
+ }
|
|
|
+ String ossKey = unzipPath.replace(OssPath.localPath,"");
|
|
|
+ ShellUtil.yunUpload(unzipPath,ossKey);
|
|
|
+ return ossKey ;
|
|
|
+ // return modelFile.getParentFile().getPath();
|
|
|
+ }
|
|
|
+
|
|
|
+ private String uploadOss(String unzipPath,File modelFile) {
|
|
|
+ if(!modelFile.exists()){
|
|
|
+ throw new BusinessException(ResultCode.UPLOAD_FILE_ERROR);
|
|
|
+ }
|
|
|
+ String ossKey = unzipPath.replace(OssPath.localPath,"");
|
|
|
+ ShellUtil.yunUpload(unzipPath,ossKey);
|
|
|
+ return ossKey;
|
|
|
+ // return modelFile.getPath();
|
|
|
+ }
|
|
|
+
|
|
|
+ private String uploadLasOrPly(String unzipPath ,File modelFile) {
|
|
|
+ File mntFile = OBJToGLBUtil.lasOrPlyToBin(modelFile);
|
|
|
+ File file = new File(mntFile.getPath() + "/webcloud/cloud.js");
|
|
|
+ if(!file.exists()){
|
|
|
+ throw new BusinessException(ResultCode.UPLOAD_FILE_ERROR);
|
|
|
+ }
|
|
|
+ String ossKey = unzipPath.replace(OssPath.localPath,"");
|
|
|
+ ShellUtil.yunUpload(unzipPath,ossKey);
|
|
|
+ return ossKey + File.separator +"webcloud";
|
|
|
+ // return mntFile.getPath()+ File.separator +"webcloud";
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
- public List<CommonUpload> getByStatus(Integer status) {
|
|
|
- LambdaQueryWrapper<CommonUpload> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.eq(CommonUpload::getStatus,status);
|
|
|
- return this.list(wrapper);
|
|
|
+ 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(String msg, String url) {
|
|
|
+ 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);
|
|
@@ -61,27 +283,23 @@ public class CommonUploadServiceImpl extends ServiceImpl<ICommonUploadMapper, Co
|
|
|
this.update(wrapper);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public List<CommonUpload> getIsSystem() {
|
|
|
- LambdaQueryWrapper<CommonUpload> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.eq(CommonUpload::getUseType,"animation");
|
|
|
- return this.list(wrapper);
|
|
|
- }
|
|
|
|
|
|
- @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 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;
|
|
|
}
|
|
|
+
|
|
|
}
|