Ver código fonte

dev
model 模块修改好

wuweihao 5 anos atrás
pai
commit
638db9a19a

+ 55 - 91
src/main/java/com/fd/controller/ModelController.java

@@ -11,14 +11,18 @@ import com.fd.entity.OutputFileEntity;
 import com.fd.server.CmdServer;
 //import com.fd.server.FileServer;
 import com.fd.server.ModelServer;
+import com.fd.server.RasterServer;
+import com.fd.server.impl.ModelServerImpl;
 import com.fd.util.FileUtils;
 import com.fd.util.R;
 import com.fd.util.RegexUtils;
+import com.fd.util.SpringContext;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.log4j.Log4j2;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -47,78 +51,16 @@ public class ModelController {
     @Value("${output.file.path.model}")
     private String OUTPUT_FILE_PATH;
 
-    @Autowired
-    private CmdServer cmdServer;
-
-    @Autowired
-    private ModelServer modelServer;
 
     /**
      * 队列
      */
-    private BlockingQueue<MyQueue> modelQueue = new LinkedBlockingQueue<MyQueue>(2);
+    private static BlockingQueue<MyQueue> modelQueue = new LinkedBlockingQueue<MyQueue>(2);
 
 
 
-    /**
-     * 初始化队列
-     *
-     * @return
-     */
-    @PostConstruct
-    private void init() {
-        new Thread(new ModelSliceConsumerThread(modelQueue)).start();
-    }
 
 
-    /**
-     * 消费队列
-     */
-    public class ModelSliceConsumerThread implements Runnable{
-
-        private BlockingQueue<MyQueue> queue;
-        public ModelSliceConsumerThread(BlockingQueue<MyQueue> queue){
-            this.queue = queue;
-        }
-
-        @Override
-        public void run() {
-            while (true) {
-                try {
-                    MyQueue data = queue.poll(2, TimeUnit.SECONDS);
-                    if (data != null) {
-                        log.warn("run ModelSliceConsumerThread");
-                        log.info("cmd: {}", data.getStr());
-//                        Integer integer = cmdServer.exeCmdModelSlice(data.getStr());
-                        Integer integer = modelServer.cmdSlice(data.getStr());
-                        OutputFileEntity entity = data.getOutputFile();
-
-                        if (integer != 0) {
-                            log.info("error command exeCmdModelSlice");
-                            // 如果命令运行失败,删除刚才创建的实体类
-                            // o:代表切片失败
-                            entity.setStatus(0);
-                            entity.setUpdateTime(new Date());
-                            modelServer.save(entity);
-                            return;
-                        }
-
-                        entity.setStatus(5);
-                        entity.setUpdateTime(new Date());
-                        modelServer.save(entity);
-                        log.warn("end ModelSliceConsumerThread");
-                    }
-                } catch (Exception e) {
-                    Thread.currentThread().interrupt();
-
-                    log.error("error  consume queue modelSliceConsumerThread: {}", e);
-
-                    e.printStackTrace();
-                }
-            }
-        }
-    }
-
 
 
     @ApiOperation("上传数据,校验文件名")
@@ -126,6 +68,8 @@ public class ModelController {
     private R checkFileName(@PathVariable("fileName") String fileName) {
         log.info("run checkFileName {}",fileName);
 
+        ModelServer modelServer = SpringContext.getBean(ModelServerImpl.class);
+
         // 文件是否包含中文字符
         if (RegexUtils.regexChinese(fileName)) {
             return new R(51005, MsgCode.E51005);
@@ -148,6 +92,8 @@ public class ModelController {
     private R upload(@RequestParam("file") MultipartFile file) {
         log.info("run upload");
 
+        ModelServer modelServer = SpringContext.getBean(ModelServerImpl.class);
+
         // 文件名全名
         String fileName = file.getOriginalFilename();
 
@@ -173,6 +119,8 @@ public class ModelController {
     @GetMapping("unzip/{fileId}/")
     private R fileUnzip(@PathVariable("fileId") Long fileId) {
         log.info("run fileUnzip: {}", fileId);
+
+        ModelServer modelServer = SpringContext.getBean(ModelServerImpl.class);
         OutputFileEntity entity = modelServer.findById(fileId);
 
         String outputPath = OUTPUT_FILE_PATH + "unzip";
@@ -199,58 +147,44 @@ public class ModelController {
     @ApiOperation("获取3D模型数据列表")
     @PostMapping(value = "list")
     private R list(@RequestBody PageDto param) {
+        ModelServer modelServer = SpringContext.getBean(ModelServerImpl.class);
         return modelServer.findByType(TypeCode.FILE_TYPE_MODEL, param);
     }
 
-//    /**
-//     * 删除文件
-//     */
-//    @ApiOperation("删除文件")
-//    @GetMapping("delete/{fileId}/")
-//    private R deleteFile(@PathVariable("fileId") Long fileId) {
-//        log.info("run deleteFile: {}", fileId);
-//        return modelServer.deleteById(fileId);
-//    }
+
 
     @ApiOperation("删除文件")
     @GetMapping("delete/{fileId}/")
     private R deleteFile(@PathVariable("fileId") Long fileId) {
         log.info("run deleteFile: {}", fileId);
-
+        ModelServer modelServer = SpringContext.getBean(ModelServerImpl.class);
         OutputFileEntity entity = modelServer.findById(fileId);
         entity.setResStatus(1);
         modelServer.save(entity);
 
         FileEntity fileEntity = modelServer.findByInputFileId(entity.getUploadId());
         fileEntity.setResStatus(1);
-        fileEntity = modelServer.saveInputFile(fileEntity);
+        modelServer.saveInputFile(fileEntity);
 
-        new Thread(new DeleteThread(fileId)).start();
+        runDeleteThread(fileId, modelServer);
         return new R(200, MsgCode.SUCCESS);
     }
 
-    public class DeleteThread implements Runnable{
-
-        private Long fileId;
-
-        public DeleteThread(Long fileId){
-            this.fileId = fileId;
-        }
 
-        @Override
-        public void run() {
-            log.info("run ModelDeleteThread");
-            modelServer.deleteById(fileId);
-            log.info("end ModelDeleteThread: {}", fileId);
-        }
+    @Async("taskExecutor")
+    public void runDeleteThread(Long fileId, ModelServer modelServerv) {
+        log.info("run runDeleteThread");
+        modelServerv.deleteById(fileId);
+        log.info("end runDeleteThread id : {}", fileId);
     }
 
 
+
     @ApiOperation("倾斜摄影数据切片")
     @GetMapping("command/osgb/{fileId}/")
     private R cmdModelSlice(@PathVariable("fileId") Long fileId) {
         log.info("run cmdModelSlice: {}", fileId);
-
+        ModelServer modelServer = SpringContext.getBean(ModelServerImpl.class);
         OutputFileEntity entity = modelServer.findById(fileId);
 
 
@@ -296,14 +230,43 @@ public class ModelController {
         entity.setSlicePath(outputPath);
 
         entity = modelServer.save(entity);
-
+            sliceThread(modelQueue, modelServer);
             return new R(200, entity);
         }
-//
         // 入队失败
         return new R(52000 ,MsgCode.E52000);
 
+    }
+
+    @Async("taskExecutor")
+    public void sliceThread(BlockingQueue<MyQueue> queue, ModelServer modelServer){
+        try {
+            MyQueue data = queue.poll(2, TimeUnit.SECONDS);
+            if (data != null) {
+                log.warn("run ModelSliceConsumerThread");
+                log.info("cmd: {}", data.getStr());
+                Integer integer = modelServer.cmdSlice(data.getStr());
+                OutputFileEntity entity = data.getOutputFile();
+
+                if (integer != 0) {
+                    log.info("error command exeCmdModelSlice");
+                    // 如果命令运行失败,删除刚才创建的实体类
+                    // o:代表切片失败
+                    entity.setStatus(0);
+                    entity.setUpdateTime(new Date());
+                    modelServer.save(entity);
+                    return;
+                }
 
+                entity.setStatus(5);
+                entity.setUpdateTime(new Date());
+                modelServer.save(entity);
+                log.warn("end ModelSliceConsumerThread");
+            }
+        } catch (Exception e) {
+            Thread.currentThread().interrupt();
+            e.printStackTrace();
+        }
 
     }
 
@@ -312,6 +275,7 @@ public class ModelController {
     @PostMapping("move/{fileId}/")
     private R moveFile(@PathVariable("fileId") Long fileId, @RequestBody ConfigJsonDto param) {
         log.info("run moveFile: {}", fileId);
+        ModelServer modelServer = SpringContext.getBean(ModelServerImpl.class);
         return modelServer.moveFileToServer(fileId, param);
     }
 

+ 0 - 5
src/main/java/com/fd/controller/RasterController.java

@@ -191,11 +191,6 @@ public class RasterController {
     @Async("taskExecutor")
     public void runDeleteThread(Long fileId, RasterServer rasterServer) {
         log.info("run RasterDeleteThread");
-        try {
-            Thread.sleep(2000);
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
         rasterServer.deleteById(fileId);
         log.info("end RasterDeleteThread: {}", fileId);
     }