|
@@ -6,8 +6,11 @@ import com.fd.constant.TypeCode;
|
|
|
import com.fd.dto.PageDto;
|
|
|
import com.fd.dto.MyQueue;
|
|
|
import com.fd.entity.FileEntity;
|
|
|
+import com.fd.entity.FileSchedule;
|
|
|
+import com.fd.entity.OutputFileEntity;
|
|
|
import com.fd.server.CmdServer;
|
|
|
import com.fd.server.FileServer;
|
|
|
+import com.fd.server.ModelServer;
|
|
|
import com.fd.util.FileUtils;
|
|
|
import com.fd.util.R;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
@@ -48,6 +51,9 @@ public class FdModelController {
|
|
|
@Autowired
|
|
|
private CmdServer cmdServer;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ModelServer modelServer;
|
|
|
+
|
|
|
// 队列
|
|
|
BlockingQueue<String> queue = new LinkedBlockingQueue<String>(5);
|
|
|
|
|
@@ -64,10 +70,6 @@ public class FdModelController {
|
|
|
@PostConstruct
|
|
|
private void init() {
|
|
|
|
|
|
- // 多线程运行切片
|
|
|
-// new Thread(new ModelSliceThread(cmd, fileEntity)).start();
|
|
|
- // 多线程消费队列
|
|
|
-// new Thread(new ConsumerThread()).start();
|
|
|
|
|
|
new Thread(new modelSliceConsumerThread(modelQueue)).start();
|
|
|
|
|
@@ -130,16 +132,18 @@ public class FdModelController {
|
|
|
log.info("消费者,拿到队列中的数据data:" + data.toString());
|
|
|
|
|
|
Integer integer = cmdServer.exeCmdModelSlice(data.getStr());
|
|
|
- FileEntity obj =(FileEntity) data.getObj();
|
|
|
+ OutputFileEntity obj = data.getOutputFile();
|
|
|
|
|
|
if (integer != 0) {
|
|
|
log.info("error command exeCmdModelSlice");
|
|
|
// 如果命令运行失败,删除刚才创建的实体类
|
|
|
- fileServer.deleteById(obj.getId());
|
|
|
+ // o:代表切片失败
|
|
|
+ obj.setStatus(0);
|
|
|
+ modelServer.save(obj);
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
- Thread.sleep(4000);
|
|
|
+// Thread.sleep(4000);
|
|
|
} catch (InterruptedException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
@@ -221,8 +225,7 @@ public class FdModelController {
|
|
|
if (!"zip".equals(s)) {
|
|
|
return new R(50007, MsgCode.E50007);
|
|
|
}
|
|
|
-
|
|
|
- return fileServer.uploadBigFile(file, TypeCode.FILE_TYPE_MODEL);
|
|
|
+ return modelServer.uploadBigFile(file);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -230,35 +233,38 @@ public class FdModelController {
|
|
|
@GetMapping("unzip/{fileId}/")
|
|
|
private R fileUnzip(@PathVariable("fileId") Long fileId) {
|
|
|
log.info("run fileUnzip: {}", fileId);
|
|
|
- FileEntity entity = fileServer.findById(fileId);
|
|
|
+// FileEntity entity = fileServer.findById(fileId);
|
|
|
+ OutputFileEntity entity = modelServer.findById(fileId);
|
|
|
+
|
|
|
+ FileEntity uploadFiel = fileServer.findById(entity.getUploadId());
|
|
|
+
|
|
|
|
|
|
- boolean unzip = FileUtils.unzip(entity.getFileUrl(), INPUT_FILE_PATH);
|
|
|
+ String outputPath = OUTPUT_FILE_PATH + "unzip";
|
|
|
+ FileUtils.createDir(outputPath);
|
|
|
+
|
|
|
+ boolean unzip = FileUtils.unzip(uploadFiel.getFileUrl(), outputPath);
|
|
|
|
|
|
if (!unzip) {
|
|
|
log.info("zip error: {}", MsgCode.E51001);
|
|
|
return new R(50001, MsgCode.E51001);
|
|
|
}
|
|
|
|
|
|
- String fileName = StringUtils.substringBefore(entity.getFileName(), ".");
|
|
|
+ String fileName = StringUtils.substringBeforeLast(entity.getFileName(), ".");
|
|
|
|
|
|
- FileEntity fileEntity = new FileEntity();
|
|
|
+ entity.setStatus(4);
|
|
|
+ entity.setUpdateTime(new Date());
|
|
|
+ entity.setUnZipPath(outputPath + File.separator + fileName);
|
|
|
|
|
|
- fileEntity.setFileName(fileName);
|
|
|
- fileEntity.setFileUrl(INPUT_FILE_PATH + File.separator + fileName);
|
|
|
- fileEntity.setCreateTime(new Date());
|
|
|
- fileEntity.setUpdateTime(new Date());
|
|
|
- fileEntity.setType(TypeCode.FILE_TYPE_MODEL);
|
|
|
- fileEntity.setStatus(4);
|
|
|
- fileEntity = fileServer.save(fileEntity);
|
|
|
+ entity = modelServer.save(entity);
|
|
|
|
|
|
- return new R(200, fileEntity);
|
|
|
+ return new R(200, entity);
|
|
|
}
|
|
|
|
|
|
@ApiOperation("获取3D模型数据列表")
|
|
|
@PostMapping(value = "list")
|
|
|
private R list(@RequestBody PageDto param) {
|
|
|
log.info("run list");
|
|
|
- return fileServer.findByType(TypeCode.FILE_TYPE_MODEL, param);
|
|
|
+ return modelServer.findByType(TypeCode.FILE_TYPE_MODEL, param);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -277,25 +283,32 @@ public class FdModelController {
|
|
|
private R cmdModelSlice(@PathVariable("fileId") Long fileId) {
|
|
|
log.info("run cmdModelSlice: {}", fileId);
|
|
|
|
|
|
- FileEntity entity = fileServer.findById(fileId);
|
|
|
+// FileEntity entity = fileServer.findById(fileId);
|
|
|
+ OutputFileEntity entity = modelServer.findById(fileId);
|
|
|
+
|
|
|
+
|
|
|
+ String fileName = StringUtils.substringBeforeLast(entity.getFileName(), ".");
|
|
|
+ String outputPath = OUTPUT_FILE_PATH + "model";
|
|
|
+ FileUtils.createDir(outputPath);
|
|
|
+
|
|
|
+ outputPath = outputPath + File.separator + fileName;
|
|
|
// 传入的是目录
|
|
|
String cmd = Command.MODEL_SLICE_OSGB;
|
|
|
- cmd = cmd.replace("@fileName", entity.getFileName());
|
|
|
+ cmd = cmd.replace("@inputFile", entity.getUnZipPath());
|
|
|
+ cmd = cmd.replace("@outputFile", outputPath);
|
|
|
log.info("cmd: {}", cmd);
|
|
|
|
|
|
// 命令产生的是文件夹
|
|
|
- FileEntity fileEntity = new FileEntity();
|
|
|
- fileEntity.setFileName(entity.getFileName());
|
|
|
- fileEntity.setFileUrl(OUTPUT_FILE_PATH + entity.getFileName());
|
|
|
- fileEntity.setCreateTime(new Date());
|
|
|
- fileEntity.setUpdateTime(new Date());
|
|
|
- fileEntity.setStatus(5);
|
|
|
+ entity.setStatus(5);
|
|
|
+ entity.setUpdateTime(new Date());
|
|
|
+ entity.setSlicePath(outputPath);
|
|
|
+
|
|
|
+ entity = modelServer.save(entity);
|
|
|
|
|
|
- fileEntity = fileServer.save(fileEntity);
|
|
|
|
|
|
// 把数据放入队列中
|
|
|
MyQueue data = new MyQueue();
|
|
|
- data.setObj(fileEntity);
|
|
|
+ data.setOutputFile(entity);
|
|
|
data.setStr(cmd);
|
|
|
try {
|
|
|
modelQueue.offer(data, 1, TimeUnit.SECONDS);
|
|
@@ -304,7 +317,7 @@ public class FdModelController {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
|
|
|
- return new R(200, fileEntity);
|
|
|
+ return new R(200, entity);
|
|
|
|
|
|
}
|
|
|
|