|
@@ -1,10 +1,14 @@
|
|
package com.fdkankan.fusion.service.impl;
|
|
package com.fdkankan.fusion.service.impl;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
|
+import java.io.IOException;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
import java.util.concurrent.ThreadPoolExecutor;
|
|
import java.util.concurrent.ThreadPoolExecutor;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
+import cn.hutool.core.thread.ThreadUtil;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
@@ -25,6 +29,7 @@ import com.fdkankan.fusion.service.IModelService;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.fdkankan.redis.util.RedisUtil;
|
|
import com.fdkankan.redis.util.RedisUtil;
|
|
import lombok.SneakyThrows;
|
|
import lombok.SneakyThrows;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -42,6 +47,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|
* @since 2022-08-03
|
|
* @since 2022-08-03
|
|
*/
|
|
*/
|
|
@Service
|
|
@Service
|
|
|
|
+@Slf4j
|
|
public class ModelServiceImpl extends ServiceImpl<IModelMapper, Model> implements IModelService {
|
|
public class ModelServiceImpl extends ServiceImpl<IModelMapper, Model> implements IModelService {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
@@ -113,50 +119,54 @@ public class ModelServiceImpl extends ServiceImpl<IModelMapper, Model> implement
|
|
}
|
|
}
|
|
|
|
|
|
public void runThread(MultipartFile file,Model model,IModelService modelService){
|
|
public void runThread(MultipartFile file,Model model,IModelService modelService){
|
|
- new Thread(new Runnable() {
|
|
|
|
- @SneakyThrows
|
|
|
|
- @Override
|
|
|
|
- public void run() {
|
|
|
|
|
|
+ ExecutorService executor = ThreadUtil.newSingleExecutor();
|
|
|
|
+ try {
|
|
|
|
+ CompletableFuture.runAsync(() -> {
|
|
String fileName = UUID.randomUUID().toString().replace("-","") +".zip";
|
|
String fileName = UUID.randomUUID().toString().replace("-","") +".zip";
|
|
File newObjFile = null;
|
|
File newObjFile = null;
|
|
File objPathFile = null;
|
|
File objPathFile = null;
|
|
String objPath = String.format(FilePath.OBJ_LOCAL_PATH,environment , "modelId_"+model.getModelId()) ;
|
|
String objPath = String.format(FilePath.OBJ_LOCAL_PATH,environment , "modelId_"+model.getModelId()) ;
|
|
|
|
+ log.info("uploadObj--ThreadStart-fileName:{},modeId:{}",fileName,model.getModelId());
|
|
|
|
|
|
newObjFile = new File(objPath +"/" + fileName);
|
|
newObjFile = new File(objPath +"/" + fileName);
|
|
if(!newObjFile.getParentFile().exists()){
|
|
if(!newObjFile.getParentFile().exists()){
|
|
newObjFile.mkdirs();
|
|
newObjFile.mkdirs();
|
|
}
|
|
}
|
|
- file.transferTo(newObjFile);
|
|
|
|
|
|
+ try {
|
|
|
|
+ file.transferTo(newObjFile);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
if(fileName.toLowerCase().endsWith(".zip")){
|
|
if(fileName.toLowerCase().endsWith(".zip")){
|
|
ShellUtil.unZip(newObjFile.getPath(),objPath);
|
|
ShellUtil.unZip(newObjFile.getPath(),objPath);
|
|
}
|
|
}
|
|
objPathFile = new File(objPath );
|
|
objPathFile = new File(objPath );
|
|
if(!objPathFile.isDirectory()){
|
|
if(!objPathFile.isDirectory()){
|
|
setCreateStatus(model,-1);
|
|
setCreateStatus(model,-1);
|
|
- throw new BusinessException(ResultCode.UPLOAD_FILE_TYPE_ERROR);
|
|
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
List<File> fileList = new ArrayList<>();
|
|
List<File> fileList = new ArrayList<>();
|
|
FileWriterUtil.getCanRunList(fileList,objPathFile);
|
|
FileWriterUtil.getCanRunList(fileList,objPathFile);
|
|
|
|
|
|
if(fileList.size() <=0){
|
|
if(fileList.size() <=0){
|
|
setCreateStatus(model,-1);
|
|
setCreateStatus(model,-1);
|
|
- throw new BusinessException(ResultCode.UPLOAD_FILE_MSG_ERROR);
|
|
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
|
|
|
|
File file1 = fileList.get(0);
|
|
File file1 = fileList.get(0);
|
|
if(file1 == null){
|
|
if(file1 == null){
|
|
setCreateStatus(model,-1);
|
|
setCreateStatus(model,-1);
|
|
- throw new BusinessException(ResultCode.UPLOAD_FILE_OBJ_ERROR);
|
|
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
if(com.fdkankan.fusion.common.util.StringUtils.isChinese(file1.getName())){
|
|
if(com.fdkankan.fusion.common.util.StringUtils.isChinese(file1.getName())){
|
|
setCreateStatus(model,-1);
|
|
setCreateStatus(model,-1);
|
|
- throw new BusinessException(ResultCode.UPLOAD_FILE_CHINA_NAME);
|
|
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
|
|
|
|
if(file1.getName().endsWith(".b3dm") ){
|
|
if(file1.getName().endsWith(".b3dm") ){
|
|
if(!FileWriterUtil.checkB3dmTileset(objPathFile)){
|
|
if(!FileWriterUtil.checkB3dmTileset(objPathFile)){
|
|
setCreateStatus(model,-1);
|
|
setCreateStatus(model,-1);
|
|
- throw new BusinessException(ResultCode.UPLOAD_FILE_MSG_ERROR);
|
|
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
redisUtil.set(RedisKeyUtil.modelUpload+model.getModelId(),"20");
|
|
redisUtil.set(RedisKeyUtil.modelUpload+model.getModelId(),"20");
|
|
@@ -240,8 +250,13 @@ public class ModelServiceImpl extends ServiceImpl<IModelMapper, Model> implement
|
|
FileUtil.del(mntFile.getParentFile());
|
|
FileUtil.del(mntFile.getParentFile());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
- }).start();
|
|
|
|
|
|
+ }, executor).whenComplete((reslut, e) -> {
|
|
|
|
+ log.info("uploadObj--ThreadEnd-modeId:{}",model.getModelId());
|
|
|
|
+ });
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ setCreateStatus(model,-1);
|
|
|
|
+ log.info("uploadObj--ThreadError-modeId:{},error:{}",model.getModelId(),e);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|