瀏覽代碼

增加先下班版本队列处理

xiewenjie 3 年之前
父節點
當前提交
bc0aa4e7a2

+ 249 - 0
sxz-core/src/main/java/com/fdkk/sxz/other/listener/Model3dBuild.java

@@ -0,0 +1,249 @@
+package com.fdkk.sxz.other.listener;
+
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.fdkk.sxz.constant.ConstantFileName;
+import com.fdkk.sxz.constant.ConstantFilePath;
+import com.fdkk.sxz.other.mq.TopicRabbitConfig;
+import com.fdkk.sxz.util.*;
+import com.fdkk.sxz.vo.request.RequestQueue;
+import com.fdkk.sxz.webApi.service.IRenovationPartsDetailService;
+import com.fdkk.sxz.webApi.service.custom.ICustomComponentService;
+import com.fdkk.sxz.webApi.service.custom.ICustomProductService;
+import lombok.extern.slf4j.Slf4j;
+import org.slf4j.MDC;
+import org.springframework.amqp.rabbit.annotation.RabbitHandler;
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.messaging.Message;
+import org.springframework.stereotype.Component;
+
+import java.io.File;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * @author Xiewj
+ * @date 2021/11/12
+ */
+
+@Component
+@Slf4j
+public class Model3dBuild {
+    @Value("${server.file.location}")
+    private String buildPath;
+    @Value("${build.url}")
+    private String buildUrl;
+    @Autowired
+    private UploadToOssUtil uploadToOssUtil;
+    @Autowired
+    private IRenovationPartsDetailService renovationPartsDetailService;
+    @Autowired
+    private ICustomProductService customProductService;
+
+    @Autowired
+    private ICustomComponentService customComponentService;
+
+
+    @RabbitHandler
+    @RabbitListener(queues = TopicRabbitConfig.MODEL_BIZ_3D)
+    public void modelBiz3d(Message<RequestQueue> message) {
+        Model3dBuild.log.info("modelBiz3d同步消息开始:" + message + ",开始同步");
+        String token = RedisUtil.tryLock(message.getPayload().getTaskId().toString(), 60 * 60 * 1000);
+        try {
+            if (token != null) {
+                modelBiz3dHandler(message.getPayload());
+            }
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        } finally {
+            MDC.clear();
+            if (token != null) {
+                RedisUtil.unlock(message.getPayload().getTaskId().toString(), token);
+            }
+        }
+
+    }
+
+    public void modelBiz3dHandler(RequestQueue str) throws InterruptedException {
+
+        while (true) {
+            String buildResult = OkHttpUtils.httpPostJson(buildUrl + "pro", JSON.toJSONString(str));
+            JSONObject buildJson = JSONObject.parseObject(buildResult);
+
+            Model3dBuild.log.info("str.getName()-{}, 请求3d场景渲染接口获取接口数据-{}", str.getName(), buildJson);
+
+            if ("isBusy".equals(buildJson.getString("msg"))) {
+                Thread.sleep(2000L);
+                continue;
+            }
+
+            if ("error".equals(buildJson.getString("state"))) {
+                throw new RuntimeException(str.getName() + ":build方式pro接口返回error错误");
+            }
+            break;
+        }
+        
+        boolean over = false;
+        int times = 0;
+        //是否处理obj文件
+        boolean uploadObj = true;
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("name", str.getName());
+        jsonObject.put("taskType", "localDataUpload");
+        while (true) {
+            String checkResult = OkHttpUtils.httpPostJson(buildUrl + "check", jsonObject.toJSONString());
+            Thread.sleep(2000L);
+            JSONObject checkJson = JSONObject.parseObject(checkResult);
+
+            Model3dBuild.log.info("str.getName()-{}, 请求检查3d场景渲染接口获取接口数据-{}", str.getName(), checkJson);
+
+            JSONArray checkArray = checkJson.getJSONArray("msg");
+
+            if (checkArray.size() == 0) {
+                throw new RuntimeException(str.getName() + ":build方式pro接口返回error错误");
+            }
+
+            for (int i = 0, len = checkArray.size(); i < len; i++) {
+                JSONObject objectJson = checkArray.getJSONObject(i);
+
+                if ("error".equals(objectJson.getString("state"))) {
+                    throw new RuntimeException(str.getName() + ":build方式pro接口返回error错误");
+                }
+
+                if (objectJson.containsKey("state") && ("".equals(objectJson.getString("state")) ||
+                        "done".equals(objectJson.getString("state")) || "error".equals(objectJson.getString("state")))) {
+                    over = true;
+                }
+
+                if (objectJson.containsKey("progress")) {
+                    Integer progress = objectJson.getInteger("progress");
+                    Model3dBuild.log.info("str.getName()-{}, 第{}次获取渲染进度,进度为{}%", str.getName(), times++, progress);
+                }
+            }
+
+            if (over) {
+                break;
+            }
+
+            Thread.sleep(2000L);
+        }
+
+    }
+
+    /**
+     * 转换obj,并且上传
+     *
+     * @param vrNum
+     * @param sceneNum
+     * @throws Exception
+     */
+    public void uploadObjData(String vrNum, String sceneNum) throws Exception {
+        //创建data.json
+        String path = buildPath + "Output/" + vrNum + File.separator + "obj";
+        CreateObjUtil.ossUtilCp("images/images" + vrNum + "/obj/", path);
+
+        Model3dBuild.log.info("vrNum-{},删除文件开始");
+        FileUtils.deleteDirectory(path + File.separator + "results");
+        FileUtils.deleteDirectory(path + File.separator + "caches");
+        Model3dBuild.log.info("vrNum-{},删除文件结束");
+
+        Model3dBuild.log.info("vrNum-{},拷贝obj文件开始");
+        FileUtils.copyFile(path + "/extras/mesh.obj", path + "/extras/copy-mesh.obj", true);
+        Model3dBuild.log.info("vrNum-{},拷贝obj文件结束");
+
+//        OkHttpUtils.httpGet(maxObjUrl + "objToObj?inObj=" + path + "/extras/copy-mesh.obj" +
+//                "&outObj=" + path + "/extras/mesh.obj" + "&r=40");
+
+        JSONObject dataJson = new JSONObject();
+        dataJson.put("obj2txt", true);
+        dataJson.put("split_type", "SPLIT_V6");
+        dataJson.put("data_describe", "double spherical");
+        dataJson.put("skybox_type", "SKYBOX_V5");
+        FileUtils.writeFile(path + "/data.json", dataJson.toString());
+
+        JSONObject projectJson = new JSONObject();
+        projectJson.put("version", "201909231830");
+        projectJson.put("protocol", "file api 1.4");
+        projectJson.put("uuid", UUID.randomUUID().toString());
+        projectJson.put("description", "");
+        projectJson.put("time", System.currentTimeMillis());
+        projectJson.put("category", "default");
+        projectJson.put("tag", null);
+        projectJson.put("status", null);
+        FileUtils.writeFile(path + "/project.json", projectJson.toString());
+
+        Model3dBuild.log.info("vrNum-{},计算模型", vrNum);
+        CreateObjUtil.build3dModel(path, "");
+        Model3dBuild.log.info("vrNum-{},计算模型完毕", vrNum);
+
+        String uploadData = FileUtils.readFile(path + File.separator + "results" + File.separator + "upload.json");
+        JSONObject uploadJson = null;
+        JSONArray array = null;
+        if (uploadData != null) {
+            uploadJson = JSONObject.parseObject(uploadData);
+            array = uploadJson.getJSONArray("upload");
+        }
+        Model3dBuild.log.info("uploadJson-{}", uploadJson);
+        if (array == null) {
+            Model3dBuild.log.error("upload.json数据出错");
+            throw new RuntimeException("upload.json数据出错");
+        }
+
+        Map<String, String> map = new HashMap<String, String>();
+        JSONObject fileJson = null;
+        String fileName = "";
+        for (int i = 0, len = array.size(); i < len; i++) {
+            fileJson = array.getJSONObject(i);
+            fileName = fileJson.getString("file");
+            //文件不存在抛出异常
+            if (!new File(path + File.separator + "results" + File.separator + fileName).exists()) {
+                throw new Exception(path + File.separator + "results" + File.separator + fileName + "文件不存在");
+            }
+
+            //tex文件夹
+            if (fileJson.getIntValue("clazz") == 15) {
+//                if(fileName.contains("floor.json")){
+//                    map.put(path + File.separator + "results" + File.separator + fileName, "data/data" +
+//                            vrNum + "/floor.json" );
+//
+//                    FileUtils.copyFile(path + File.separator + "results" + File.separator + fileName,
+//                            ConstantFilePath.SCENE_PATH + "data/data" + vrNum + "/floor.json", true);
+//                }
+                map.put(path + File.separator + "results" + File.separator + fileName, "images/images" +
+                        vrNum + "/" + ConstantFileName.modelUUID + "_50k_texture_jpg_high1/" + fileName.replace("tex/", ""));
+
+                //复制一份到images本地
+                FileUtils.copyFile(path + File.separator + "results" + File.separator + fileName,
+                        ConstantFilePath.SCENE_PATH + "images" + File.separator + "images" + vrNum + File.separator +
+                                ConstantFileName.modelUUID + "_50k_texture_jpg_high1/" + fileName.replace("tex/", ""), true);
+                continue;
+            }
+        }
+
+        Model3dBuild.log.info("vrnum-{}, txt转换dam,开始时间-{}", vrNum, new Date());
+        CreateObjUtil.convertTxtToDam(path + File.separator + "results" + File.separator + "modeldata.txt", path + File.separator + "results" + File.separator + ConstantFileName.modelUUID +
+                "_50k" +
+                ".dam");
+        Model3dBuild.log.info("vrnum-{}, txt转换dam,结束时间-{}", vrNum, new Date());
+
+        map.put(path + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam.lzma", "images/images" + vrNum + "/" + ConstantFileName.modelUUID + "_50k.dam.lzma");
+        map.put(path + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam", "images/images" + vrNum + "/" + ConstantFileName.modelUUID + "_50k.dam");
+
+        //下载源场景vision.modeldata上传到新风格场景
+        Model3dBuild.log.info("vrnum-{}, 下载源场景vision.modeldata上传到新风格场景,开始时间-{}", vrNum, new Date());
+        FileUtils.downLoadFromUrl("https://4dkk.4dage.com/images/images" + sceneNum + "/vision.modeldata",
+                "vision.modeldata", path);
+        Model3dBuild.log.info("vrnum-{}, 下载源场景vision.modeldata上传到新风格场景,结束时间-{}", vrNum, new Date());
+        map.put(path + File.separator + "vision.modeldata", "images/images" + vrNum + "/" + "vision.modeldata");
+        Model3dBuild.log.info("vrNum-{},上传文件", vrNum);
+        uploadToOssUtil.uploadMulFiles(map);
+        Model3dBuild.log.info("vrNum执行完方法-{}", vrNum);
+    }
+
+}

+ 12 - 1
sxz-core/src/main/java/com/fdkk/sxz/other/mq/TopicRabbitConfig.java

@@ -25,7 +25,8 @@ public class TopicRabbitConfig {
     public final static String MODEL = "topic.model.dev";
     //上传模型处理业务
     public final static String MODEL_BIZ = "topic.modelBiz.dev";
-
+    // 线下版本使用队列
+    public final static String MODEL_BIZ_3D = "topic.3dModelBiz.dev";
     //"更新模型库,syncmodel
     public final static String SYNCMODEL = "topic.syncmodel.dev";
 
@@ -73,6 +74,11 @@ public class TopicRabbitConfig {
     }
 
     @Bean
+    public Queue modelBiz3dQueue() {
+        return new Queue(TopicRabbitConfig.MODEL_BIZ_3D);
+    }
+
+    @Bean
     public Queue syncModelQueue() {
         return new Queue(TopicRabbitConfig.SYNCMODEL);
     }
@@ -132,6 +138,11 @@ public class TopicRabbitConfig {
     }
 
     @Bean
+    Binding bindingExchangeMessage8() {
+        return BindingBuilder.bind(modelBiz3dQueue()).to(exchange()).with(TopicRabbitConfig.MODEL_BIZ_3D);
+    }
+
+    @Bean
     Binding bindingExchangeMessage7() {
         return BindingBuilder.bind(addModelQueue()).to(exchange()).with(TopicRabbitConfig.ADDMODEL);
     }

+ 68 - 0
sxz-core/src/main/java/com/fdkk/sxz/webApi/controller/QueueController.java

@@ -0,0 +1,68 @@
+package com.fdkk.sxz.webApi.controller;
+
+import com.alibaba.fastjson.JSONObject;
+import com.fdkk.sxz.annotation.auth.NoAuthentication;
+import com.fdkk.sxz.annotation.log.AroundLog;
+import com.fdkk.sxz.base.Result;
+import com.fdkk.sxz.other.mq.TopicRabbitConfig;
+import com.fdkk.sxz.util.OkHttpUtils;
+import com.fdkk.sxz.vo.request.RequestQueue;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @author Xiewj
+ * @date 2021/10/19
+ */
+@Slf4j
+@RestController
+@RequestMapping("/change/queue")
+@Api(tags = "数据迁移模块")
+public class QueueController {
+
+    @Autowired
+    private RabbitTemplate rabbitTemplate;  //使用RabbitTemplate,这提供了接收/发送等等方
+    @Value("${build.url}")
+    private String buildUrl;
+
+    /**
+     * 数据上传
+     *
+     * @return
+     */
+    @ApiOperation("数据处理任务接收")
+    @RequestMapping(value = "/dataHandle", method = RequestMethod.GET)
+    @NoAuthentication
+    @AroundLog(name = "数据处理任务接收")
+    public Result dataHandle(@RequestBody RequestQueue params) {
+        QueueController.log.info("数据处理任务接收:{}", params);
+        rabbitTemplate.convertAndSend(TopicRabbitConfig.TOPICE, TopicRabbitConfig.MODEL_BIZ, params);
+        return Result.success("处理结果");
+    }
+
+    /**
+     * 数据上传
+     *
+     * @return
+     */
+    @ApiOperation("获取任务状态")
+    @RequestMapping(value = "/dataHandleGetInfo", method = RequestMethod.GET)
+    @NoAuthentication
+    @AroundLog(name = "获取任务状态")
+    public Result dataHandleGetInfo(@RequestBody RequestQueue params) {
+        QueueController.log.info("数据处理任务接收:{}", params);
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("name", params.getName());
+        jsonObject.put("taskType", "localDataUpload");
+        String checkResult = OkHttpUtils.httpPostJson(buildUrl + "check", jsonObject.toJSONString());
+        return Result.success(checkResult);
+    }
+}

+ 20 - 0
sxz-modules/src/main/java/com/fdkk/sxz/vo/request/RequestQueue.java

@@ -0,0 +1,20 @@
+package com.fdkk.sxz.vo.request;
+
+import lombok.Data;
+
+/**
+ * Created by Xiewj 2022年3月14日09:38:04
+ */
+@Data
+public class RequestQueue {
+
+    private String taskType;
+
+    private String name;
+
+    private String postfix;
+
+    private Long taskId;
+
+
+}