|
@@ -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);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|