|
@@ -4,6 +4,7 @@ import com.fd.constant.Command;
|
|
|
import com.fd.constant.MsgCode;
|
|
|
import com.fd.constant.TypeCode;
|
|
|
import com.fd.dto.PageDto;
|
|
|
+import com.fd.dto.MyQueue;
|
|
|
import com.fd.entity.FileEntity;
|
|
|
import com.fd.server.CmdServer;
|
|
|
import com.fd.server.FileServer;
|
|
@@ -17,12 +18,17 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
import java.io.File;
|
|
|
import java.util.Date;
|
|
|
+import java.util.concurrent.BlockingQueue;
|
|
|
+import java.util.concurrent.LinkedBlockingQueue;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
/**
|
|
|
* Created by Owen on 2019/11/12 0012 9:40
|
|
|
- *
|
|
|
+ * <p>
|
|
|
* 3D模型数据
|
|
|
*/
|
|
|
@Log4j2
|
|
@@ -42,11 +48,170 @@ public class FdModelController {
|
|
|
@Autowired
|
|
|
private CmdServer cmdServer;
|
|
|
|
|
|
+ // 队列
|
|
|
+ BlockingQueue<String> queue = new LinkedBlockingQueue<String>(5);
|
|
|
+
|
|
|
+ BlockingQueue<MyQueue> modelQueue = new LinkedBlockingQueue<MyQueue>(5);
|
|
|
+
|
|
|
+ private static AtomicInteger count = new AtomicInteger();
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始化队列
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PostConstruct
|
|
|
+ private void init() {
|
|
|
+
|
|
|
+ // 多线程运行切片
|
|
|
+// new Thread(new ModelSliceThread(cmd, fileEntity)).start();
|
|
|
+ // 多线程消费队列
|
|
|
+// new Thread(new ConsumerThread()).start();
|
|
|
+
|
|
|
+ new Thread(new modelSliceConsumerThread(modelQueue)).start();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+// @ApiOperation("测试生成队列")
|
|
|
+// @GetMapping("command/queProducer/{fileId}/")
|
|
|
+// private R queProducer(@PathVariable("fileId") Long fileId) {
|
|
|
+// log.info("run queProducer: {}", fileId);
|
|
|
+//
|
|
|
+// // 命令产生的是文件夹
|
|
|
+// FileEntity fileEntity = new FileEntity();
|
|
|
+// fileEntity.setFileName(fileId.toString());
|
|
|
+// fileEntity.setFileUrl("33");
|
|
|
+// fileEntity.setCreateTime(new Date());
|
|
|
+// fileEntity.setUpdateTime(new Date());
|
|
|
+// fileEntity.setStatus(5);
|
|
|
+//
|
|
|
+// fileEntity = fileServer.save(fileEntity);
|
|
|
+//
|
|
|
+// MyQueue que = new MyQueue();
|
|
|
+// que.setObj(fileEntity);
|
|
|
+// que.setStr("cmd1");
|
|
|
+//
|
|
|
+// // 将数据存入队列中
|
|
|
+// boolean offer = false;
|
|
|
+// try {
|
|
|
+// offer = oQueue.offer(que, 2, TimeUnit.SECONDS);
|
|
|
+// } catch (InterruptedException e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+// if (offer) {
|
|
|
+// System.out.println("生产者,存入" + que.toString() + "到队列中,成功.");
|
|
|
+// } else {
|
|
|
+// System.out.println("生产者,存入" + que.toString() + "到队列中,失败.");
|
|
|
+// }
|
|
|
+//
|
|
|
+// return new R(200, fileEntity);
|
|
|
+//
|
|
|
+// }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 消费队列
|
|
|
+ */
|
|
|
+ public class modelSliceConsumerThread implements Runnable{
|
|
|
+
|
|
|
+ private BlockingQueue<MyQueue> queue;
|
|
|
+ public modelSliceConsumerThread(BlockingQueue<MyQueue> queue){
|
|
|
+ this.queue = queue;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ log.warn("run modelSliceConsumerThread");
|
|
|
+ while (true) {
|
|
|
+ try {
|
|
|
+ MyQueue data = queue.poll(2, TimeUnit.SECONDS);
|
|
|
+ if (data != null) {
|
|
|
+ log.info("消费者,拿到队列中的数据data:" + data.toString());
|
|
|
+
|
|
|
+ Integer integer = cmdServer.exeCmdModelSlice(data.getStr());
|
|
|
+ FileEntity obj =(FileEntity) data.getObj();
|
|
|
+
|
|
|
+ if (integer != 0) {
|
|
|
+ log.info("error command exeCmdModelSlice");
|
|
|
+ // 如果命令运行失败,删除刚才创建的实体类
|
|
|
+ fileServer.deleteById(obj.getId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Thread.sleep(4000);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+// @ApiOperation("生成队列")
|
|
|
+// @PostMapping(value = "test")
|
|
|
+// private R test() {
|
|
|
+// log.info("run test");
|
|
|
+// // 将数据存入队列中
|
|
|
+// String data = count.incrementAndGet() + "";
|
|
|
+//
|
|
|
+// boolean offer = false;
|
|
|
+// try {
|
|
|
+// // 将数据存入队列中
|
|
|
+// offer = queue.offer(data, 2, TimeUnit.SECONDS);
|
|
|
+// } catch (InterruptedException e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+// if (offer) {
|
|
|
+// System.out.println("生产者,存入" + data + "到队列中,成功.");
|
|
|
+// } else {
|
|
|
+// System.out.println("生产者,存入" + data + "到队列中,失败.");
|
|
|
+// }
|
|
|
+// return new R(200, data);
|
|
|
+// }
|
|
|
+
|
|
|
+// @ApiOperation("消费队列")
|
|
|
+// @PostMapping(value = "test2")
|
|
|
+// private R test2() {
|
|
|
+// log.info("run test");
|
|
|
+//
|
|
|
+//
|
|
|
+// String data = null;
|
|
|
+// try {
|
|
|
+// data = queue.poll(2, TimeUnit.SECONDS);
|
|
|
+// } catch (InterruptedException e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+// if (data != null) {
|
|
|
+// System.out.println("消费者,拿到队列中的数据data:" + data);
|
|
|
+// }
|
|
|
+// return new R(200, data);
|
|
|
+// }
|
|
|
+
|
|
|
+ public class ConsumerThread implements Runnable{
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ log.warn("run ConsumerThread");
|
|
|
+ while (true) {
|
|
|
+ try {
|
|
|
+ String data = queue.poll(2, TimeUnit.SECONDS);
|
|
|
+ if (data != null) {
|
|
|
+ log.info("消费者,拿到队列中的数据data:" + data);
|
|
|
+ }
|
|
|
+ Thread.sleep(2000);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
@ApiOperation("上传3D模型数据,只能上传zip文件")
|
|
|
- @PostMapping(value = "upload", consumes = { "multipart/form-data" })
|
|
|
- private R upload(@RequestParam("file") MultipartFile file){
|
|
|
+ @PostMapping(value = "upload", consumes = {"multipart/form-data"})
|
|
|
+ private R upload(@RequestParam("file") MultipartFile file) {
|
|
|
log.info("run upload");
|
|
|
|
|
|
// 文件名全名
|
|
@@ -54,7 +219,7 @@ public class FdModelController {
|
|
|
String s = StringUtils.substringAfterLast(fileName, ".");
|
|
|
|
|
|
if (!"zip".equals(s)) {
|
|
|
- return new R(50007,MsgCode.E50007);
|
|
|
+ return new R(50007, MsgCode.E50007);
|
|
|
}
|
|
|
|
|
|
return fileServer.uploadBigFile(file, TypeCode.FILE_TYPE_MODEL);
|
|
@@ -83,6 +248,7 @@ public class FdModelController {
|
|
|
fileEntity.setCreateTime(new Date());
|
|
|
fileEntity.setUpdateTime(new Date());
|
|
|
fileEntity.setType(TypeCode.FILE_TYPE_MODEL);
|
|
|
+ fileEntity.setStatus(4);
|
|
|
fileEntity = fileServer.save(fileEntity);
|
|
|
|
|
|
return new R(200, fileEntity);
|
|
@@ -90,7 +256,7 @@ public class FdModelController {
|
|
|
|
|
|
@ApiOperation("获取3D模型数据列表")
|
|
|
@PostMapping(value = "list")
|
|
|
- private R list(@RequestBody PageDto param){
|
|
|
+ private R list(@RequestBody PageDto param) {
|
|
|
log.info("run list");
|
|
|
return fileServer.findByType(TypeCode.FILE_TYPE_MODEL, param);
|
|
|
}
|
|
@@ -110,10 +276,11 @@ public class FdModelController {
|
|
|
@GetMapping("command/osgb/{fileId}/")
|
|
|
private R cmdModelSlice(@PathVariable("fileId") Long fileId) {
|
|
|
log.info("run cmdModelSlice: {}", fileId);
|
|
|
+
|
|
|
FileEntity entity = fileServer.findById(fileId);
|
|
|
// 传入的是目录
|
|
|
String cmd = Command.MODEL_SLICE_OSGB;
|
|
|
- cmd = cmd.replace("@fileName",entity.getFileName());
|
|
|
+ cmd = cmd.replace("@fileName", entity.getFileName());
|
|
|
log.info("cmd: {}", cmd);
|
|
|
|
|
|
// 命令产生的是文件夹
|
|
@@ -122,43 +289,102 @@ public class FdModelController {
|
|
|
fileEntity.setFileUrl(OUTPUT_FILE_PATH + entity.getFileName());
|
|
|
fileEntity.setCreateTime(new Date());
|
|
|
fileEntity.setUpdateTime(new Date());
|
|
|
+ fileEntity.setStatus(5);
|
|
|
|
|
|
fileEntity = fileServer.save(fileEntity);
|
|
|
|
|
|
-
|
|
|
- // 多线程运行切片
|
|
|
- new Thread(new ModelSliceThread(cmd, fileEntity)).start();
|
|
|
-
|
|
|
- return new R(200, fileEntity) ;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public class ModelSliceThread implements Runnable{
|
|
|
-
|
|
|
- private String cmd;
|
|
|
-
|
|
|
- private FileEntity entity;
|
|
|
-
|
|
|
- private ModelSliceThread(String cmd, FileEntity entity){
|
|
|
- this.cmd = cmd;
|
|
|
- this.entity = entity;
|
|
|
+ // 把数据放入队列中
|
|
|
+ MyQueue data = new MyQueue();
|
|
|
+ data.setObj(fileEntity);
|
|
|
+ data.setStr(cmd);
|
|
|
+ try {
|
|
|
+ modelQueue.offer(data, 1, TimeUnit.SECONDS);
|
|
|
+ log.info("入队成功");
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- log.warn("run ModelSliceThread");
|
|
|
- Integer integer = cmdServer.exeCmdModelSlice(cmd);
|
|
|
- if (integer != 0) {
|
|
|
- log.info("error command exeCmdModelSlice");
|
|
|
- // 如果命令运行失败,删除刚才创建的实体类
|
|
|
- fileServer.deleteById(entity.getId());
|
|
|
- return;
|
|
|
- }
|
|
|
- log.warn("end RasterSliceThread");
|
|
|
- }
|
|
|
+ return new R(200, fileEntity);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+// @ApiOperation("倾斜摄影数据切片")
|
|
|
+// @GetMapping("command/osgb/{fileId}/")
|
|
|
+// private R cmdModelSlice(@PathVariable("fileId") Long fileId) {
|
|
|
+// log.info("run cmdModelSlice: {}", fileId);
|
|
|
+//
|
|
|
+//
|
|
|
+//// // 将数据存入队列中
|
|
|
+//// String data = count.incrementAndGet() + "";
|
|
|
+//// boolean offer = false;
|
|
|
+//// try {
|
|
|
+//// // 将数据存入队列中
|
|
|
+//// offer = queue.offer(data, 2, TimeUnit.SECONDS);
|
|
|
+//// } catch (InterruptedException e) {
|
|
|
+//// e.printStackTrace();
|
|
|
+//// }
|
|
|
+//// if (offer) {
|
|
|
+//// System.out.println("生产者,存入" + data + "到队列中,成功.");
|
|
|
+//// } else {
|
|
|
+//// System.out.println("生产者,存入" + data + "到队列中,失败.");
|
|
|
+//// }
|
|
|
+//
|
|
|
+//
|
|
|
+// FileEntity entity = fileServer.findById(fileId);
|
|
|
+// // 传入的是目录
|
|
|
+// String cmd = Command.MODEL_SLICE_OSGB;
|
|
|
+// cmd = cmd.replace("@fileName", entity.getFileName());
|
|
|
+// 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);
|
|
|
+//
|
|
|
+// fileEntity = fileServer.save(fileEntity);
|
|
|
+//
|
|
|
+// // 多线程运行切片
|
|
|
+// new Thread(new ModelSliceThread(cmd, fileEntity)).start();
|
|
|
+//
|
|
|
+//
|
|
|
+// return new R(200, fileEntity);
|
|
|
+//
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+// public class ModelSliceThread implements Runnable {
|
|
|
+//
|
|
|
+// private volatile boolean flag = true;
|
|
|
+//
|
|
|
+// private String cmd;
|
|
|
+//
|
|
|
+// private FileEntity entity;
|
|
|
+//
|
|
|
+// private ModelSliceThread(String cmd, FileEntity entity) {
|
|
|
+// this.cmd = cmd;
|
|
|
+// this.entity = entity;
|
|
|
+//
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public void run() {
|
|
|
+// log.warn("run ModelSliceThread");
|
|
|
+//
|
|
|
+//// queue.poll(2, Ti)
|
|
|
+//
|
|
|
+// Integer integer = cmdServer.exeCmdModelSlice(cmd);
|
|
|
+// if (integer != 0) {
|
|
|
+// log.info("error command exeCmdModelSlice");
|
|
|
+// // 如果命令运行失败,删除刚才创建的实体类
|
|
|
+// fileServer.deleteById(entity.getId());
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// log.warn("end RasterSliceThread");
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
|
|
|
|
|
@@ -171,10 +397,10 @@ public class FdModelController {
|
|
|
FileEntity entity = fileServer.findById(fileId);
|
|
|
|
|
|
String fileName = StringUtils.substringBefore(entity.getFileName(), ".");
|
|
|
- String path = StringUtils.substringBeforeLast(entity.getFileUrl(),"/");
|
|
|
+ String path = StringUtils.substringBeforeLast(entity.getFileUrl(), "/");
|
|
|
|
|
|
String cmd = Command.CMD_MV;
|
|
|
- cmd = cmd.replace("@fileName",fileName);
|
|
|
+ cmd = cmd.replace("@fileName", fileName);
|
|
|
cmd = cmd.replace("@path", path);
|
|
|
log.info("cmd: {}", cmd);
|
|
|
|
|
@@ -182,5 +408,4 @@ public class FdModelController {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
}
|