|
@@ -1,19 +1,26 @@
|
|
package com.fdkankan.modeldemo.mq;
|
|
package com.fdkankan.modeldemo.mq;
|
|
|
|
|
|
|
|
+import cn.hutool.core.date.TimeInterval;
|
|
|
|
+import cn.hutool.core.exceptions.ExceptionUtil;
|
|
|
|
+import cn.hutool.core.img.ImgUtil;
|
|
import cn.hutool.core.io.FileUtil;
|
|
import cn.hutool.core.io.FileUtil;
|
|
import cn.hutool.core.util.ZipUtil;
|
|
import cn.hutool.core.util.ZipUtil;
|
|
import cn.hutool.http.HttpUtil;
|
|
import cn.hutool.http.HttpUtil;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.fdkankan.modeldemo.bean.SceneEditControlsBean;
|
|
import com.fdkankan.modeldemo.bean.SceneEditControlsBean;
|
|
import com.fdkankan.modeldemo.bean.SceneJsonBean;
|
|
import com.fdkankan.modeldemo.bean.SceneJsonBean;
|
|
import com.fdkankan.modeldemo.constant.Constant;
|
|
import com.fdkankan.modeldemo.constant.Constant;
|
|
import com.fdkankan.modeldemo.entity.Scene;
|
|
import com.fdkankan.modeldemo.entity.Scene;
|
|
|
|
+import com.fdkankan.modeldemo.entity.SceneConvertLog;
|
|
import com.fdkankan.modeldemo.entity.SceneFileMapping;
|
|
import com.fdkankan.modeldemo.entity.SceneFileMapping;
|
|
|
|
+import com.fdkankan.modeldemo.service.SceneConvertLogService;
|
|
import com.fdkankan.modeldemo.service.SceneFileMappingService;
|
|
import com.fdkankan.modeldemo.service.SceneFileMappingService;
|
|
import com.fdkankan.modeldemo.service.SceneService;
|
|
import com.fdkankan.modeldemo.service.SceneService;
|
|
import com.fdkankan.modeldemo.utils.ConvertUtil;
|
|
import com.fdkankan.modeldemo.utils.ConvertUtil;
|
|
import com.fdkankan.modeldemo.utils.FdfsUtil;
|
|
import com.fdkankan.modeldemo.utils.FdfsUtil;
|
|
|
|
+import com.fdkankan.modeldemo.utils.HttpUtilExt;
|
|
import com.rabbitmq.client.Channel;
|
|
import com.rabbitmq.client.Channel;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.amqp.core.Message;
|
|
import org.springframework.amqp.core.Message;
|
|
@@ -23,7 +30,10 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
+import java.io.File;
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
+import java.util.Arrays;
|
|
|
|
+import java.util.Date;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
|
|
|
|
@@ -39,6 +49,8 @@ import java.util.Objects;
|
|
@Component
|
|
@Component
|
|
public class ConvertListener{
|
|
public class ConvertListener{
|
|
|
|
|
|
|
|
+ public final static String baseZipPath = "/mnt/scene/convert/";
|
|
|
|
+
|
|
@Autowired
|
|
@Autowired
|
|
private ConvertUtil convertUtil;
|
|
private ConvertUtil convertUtil;
|
|
@Resource
|
|
@Resource
|
|
@@ -48,37 +60,154 @@ public class ConvertListener{
|
|
@Autowired
|
|
@Autowired
|
|
private SceneService sceneService;
|
|
private SceneService sceneService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private SceneConvertLogService sceneConvertLogService;
|
|
|
|
+
|
|
|
|
+// @RabbitListener(
|
|
|
|
+// queuesToDeclare = @Queue(Constant.QUEUE_SCENE_CONVERT),
|
|
|
|
+// concurrency = "1"
|
|
|
|
+// )
|
|
|
|
+// public void buildObjScenePreHandler(Channel channel, Message message) throws Exception {
|
|
|
|
+// String roomId = null;
|
|
|
|
+// try {
|
|
|
|
+// String msg = new String(message.getBody(), StandardCharsets.UTF_8);
|
|
|
|
+// log.info("msg:{}", msg);
|
|
|
|
+// JSONObject jsonObject = JSON.parseObject(msg);
|
|
|
|
+// //roomId
|
|
|
|
+// roomId = jsonObject.getString("roomId");
|
|
|
|
+// String zipUrl = jsonObject.getString("zipUrl");
|
|
|
|
+// String zipName = FileUtil.getName(zipUrl);
|
|
|
|
+// String dirName = FileUtil.getPrefix(zipName);
|
|
|
|
+// log.info("zipUrl:{}", zipUrl);
|
|
|
|
+// //下载压缩包
|
|
|
|
+// String baseZipPath = "/mnt/scene/convert/";
|
|
|
|
+// FileUtil.mkdir(baseZipPath);
|
|
|
|
+// HttpUtil.downloadFile(zipUrl, baseZipPath);
|
|
|
|
+//// FileUtil.copy(zipUrl, baseZipPath, true);
|
|
|
|
+//
|
|
|
|
+// String localZipPath = baseZipPath + zipName;
|
|
|
|
+// ZipUtil.unzip(localZipPath, baseZipPath);
|
|
|
|
+//
|
|
|
|
+// String targetPath = "/oss/4dkankan/scene_view_data/" + roomId + "/";
|
|
|
|
+// String dataSource = baseZipPath + dirName + "/";
|
|
|
|
+// Map<String, String> uploadFileMap = convertUtil.convert(dataSource, roomId);
|
|
|
|
+// String finalRoomId = roomId;
|
|
|
|
+// uploadFileMap.keySet().stream().forEach(key->{
|
|
|
|
+//
|
|
|
|
+// SceneFileMapping sceneFileMapping = sceneFileMappingService.getByNumAndKey(finalRoomId, key);
|
|
|
|
+// if(Objects.isNull(sceneFileMapping)){
|
|
|
|
+// sceneFileMapping = new SceneFileMapping();
|
|
|
|
+// }
|
|
|
|
+// Map<String, String> mapping = fdfsUtil.uploadFile(uploadFileMap.get(key));
|
|
|
|
+// sceneFileMapping.setNum(finalRoomId);
|
|
|
|
+// sceneFileMapping.setFileid(mapping.get("file_id"));
|
|
|
|
+// sceneFileMapping.setUrl(mapping.get("http_url"));
|
|
|
|
+// sceneFileMapping.setKey(key);
|
|
|
|
+// sceneFileMappingService.saveOrUpdate(sceneFileMapping);
|
|
|
|
+// });
|
|
|
|
+//
|
|
|
|
+// }catch (Exception e){
|
|
|
|
+// log.error("convert fail, roomId:{}", roomId, e);
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+// }
|
|
|
|
+
|
|
@RabbitListener(
|
|
@RabbitListener(
|
|
- queuesToDeclare = @Queue(Constant.QUEUE_SCENE_CONVERT),
|
|
|
|
|
|
+ queuesToDeclare = @Queue(Constant.QUEUE_SCENE_CONVERT + "-2"),
|
|
concurrency = "1"
|
|
concurrency = "1"
|
|
)
|
|
)
|
|
public void buildObjScenePreHandler(Channel channel, Message message) throws Exception {
|
|
public void buildObjScenePreHandler(Channel channel, Message message) throws Exception {
|
|
- String roomId = null;
|
|
|
|
|
|
+ //开始急事
|
|
|
|
+ TimeInterval timeInterval = new TimeInterval();
|
|
|
|
+ timeInterval.start();
|
|
|
|
+
|
|
|
|
+ String stationCode = null;
|
|
|
|
+ String entityId = null;
|
|
|
|
+ JSONArray fileList = null;
|
|
|
|
+ SceneConvertLog sceneConvertLog = new SceneConvertLog();
|
|
|
|
+ String dataSource = null;
|
|
try {
|
|
try {
|
|
String msg = new String(message.getBody(), StandardCharsets.UTF_8);
|
|
String msg = new String(message.getBody(), StandardCharsets.UTF_8);
|
|
log.info("msg:{}", msg);
|
|
log.info("msg:{}", msg);
|
|
JSONObject jsonObject = JSON.parseObject(msg);
|
|
JSONObject jsonObject = JSON.parseObject(msg);
|
|
- //roomId
|
|
|
|
- roomId = jsonObject.getString("roomId");
|
|
|
|
- String zipUrl = jsonObject.getString("zipUrl");
|
|
|
|
- String zipName = FileUtil.getName(zipUrl);
|
|
|
|
- String dirName = FileUtil.getPrefix(zipName);
|
|
|
|
- log.info("zipUrl:{}", zipUrl);
|
|
|
|
- //下载压缩包
|
|
|
|
- String baseZipPath = "/mnt/scene/convert/";
|
|
|
|
- FileUtil.mkdir(baseZipPath);
|
|
|
|
- HttpUtil.downloadFile(zipUrl, baseZipPath);
|
|
|
|
-// FileUtil.copy(zipUrl, baseZipPath, true);
|
|
|
|
-
|
|
|
|
- String localZipPath = baseZipPath + zipName;
|
|
|
|
- ZipUtil.unzip(localZipPath, baseZipPath);
|
|
|
|
-
|
|
|
|
- String targetPath = "/oss/4dkankan/scene_view_data/" + roomId + "/";
|
|
|
|
- String dataSource = baseZipPath + dirName + "/";
|
|
|
|
- Map<String, String> uploadFileMap = convertUtil.convert(dataSource, roomId);
|
|
|
|
- String finalRoomId = roomId;
|
|
|
|
- uploadFileMap.keySet().stream().forEach(key->{
|
|
|
|
|
|
+ stationCode = jsonObject.getString("stationCode");
|
|
|
|
+ entityId = jsonObject.getString("entityId");
|
|
|
|
+ fileList = jsonObject.getJSONArray("fileList");
|
|
|
|
+
|
|
|
|
+ sceneConvertLog.setStationCode(stationCode);
|
|
|
|
+ sceneConvertLog.setEntityId(entityId);
|
|
|
|
+ sceneConvertLog.setCreateTime(new Date());
|
|
|
|
+
|
|
|
|
+ //校验文件是否齐全
|
|
|
|
+ boolean exists512 = fileList.stream().anyMatch(v -> {
|
|
|
|
+ JSONObject obj = (JSONObject) v;
|
|
|
|
+ return "1".equals(obj.getString("fileType"));
|
|
|
|
+ });
|
|
|
|
|
|
|
|
+ boolean exists4k = fileList.stream().anyMatch(v -> {
|
|
|
|
+ JSONObject obj = (JSONObject) v;
|
|
|
|
+ return "2".equals(obj.getString("fileType"));
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ boolean exists8k = fileList.stream().anyMatch(v -> {
|
|
|
|
+ JSONObject obj = (JSONObject) v;
|
|
|
|
+ return "3".equals(obj.getString("fileType"));
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ dataSource = baseZipPath + stationCode + "_" + entityId + "/";
|
|
|
|
+ String imagePath = dataSource + "images/";
|
|
|
|
+ String dataPath = dataSource + "data/";
|
|
|
|
+ String meshPath = dataPath + "mesh/";
|
|
|
|
+ String image512Path = imagePath + "512/";
|
|
|
|
+ String image4kPath = imagePath + "4k/";
|
|
|
|
+ String image8kPath = imagePath + "8k/";
|
|
|
|
+ FileUtil.mkdir(image512Path);
|
|
|
|
+ FileUtil.mkdir(image4kPath);
|
|
|
|
+
|
|
|
|
+ fileList.parallelStream().forEach(o->{
|
|
|
|
+ JSONObject obj = (JSONObject) o;
|
|
|
|
+ String fileName = obj.getString("fileName");
|
|
|
|
+ String fileType = obj.getString("fileType");
|
|
|
|
+ String fileUrl = obj.getString("fileUrl");
|
|
|
|
+ if("7".equals(fileType)){//vision.txt
|
|
|
|
+ HttpUtilExt.downloadFileAndCheck(fileUrl, imagePath + fileName, 3000);
|
|
|
|
+ }
|
|
|
|
+ if("1".equals(fileType)){//512图
|
|
|
|
+ HttpUtilExt.downloadFileAndCheck(fileUrl, image512Path + fileName, 30000);
|
|
|
|
+ }
|
|
|
|
+ if("2".equals(fileType)){//4k图
|
|
|
|
+ HttpUtilExt.downloadFileAndCheck(fileUrl, image4kPath + fileName, 30000);
|
|
|
|
+ if(!exists512){
|
|
|
|
+ ImgUtil.scale(new File(image4kPath + fileName), new File(image512Path + fileName), 0.125f);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(!exists4k){//如果资源中没有4k,需要用8k图做一下像素压缩
|
|
|
|
+ if("3".equals(fileType)){
|
|
|
|
+ HttpUtilExt.downloadFileAndCheck(fileUrl, image8kPath + fileName, 30000);
|
|
|
|
+ ImgUtil.scale(new File(image8kPath + fileName),new File(image4kPath + fileName), 0.5f);
|
|
|
|
+ if(!exists512){
|
|
|
|
+ ImgUtil.scale(new File(image8kPath + fileName),new File(image512Path + fileName), 0.0625f);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if("11".equals(fileType)){//mesh.obj
|
|
|
|
+ HttpUtilExt.downloadFileAndCheck(fileUrl, meshPath + fileName, 300000);
|
|
|
|
+ }
|
|
|
|
+ if("5".equals(fileType)){//floorplan.json
|
|
|
|
+ HttpUtilExt.downloadFileAndCheck(fileUrl, dataPath + fileName, 3000);
|
|
|
|
+ }
|
|
|
|
+ if("12".equals(fileType)){//scene.json
|
|
|
|
+ HttpUtilExt.downloadFileAndCheck(fileUrl, dataPath + fileName, 3000);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ Map<String, String> uploadFileMap = convertUtil.convert(dataSource, entityId);
|
|
|
|
+ String finalRoomId = entityId;
|
|
|
|
+ uploadFileMap.keySet().parallelStream().forEach(key->{
|
|
SceneFileMapping sceneFileMapping = sceneFileMappingService.getByNumAndKey(finalRoomId, key);
|
|
SceneFileMapping sceneFileMapping = sceneFileMappingService.getByNumAndKey(finalRoomId, key);
|
|
if(Objects.isNull(sceneFileMapping)){
|
|
if(Objects.isNull(sceneFileMapping)){
|
|
sceneFileMapping = new SceneFileMapping();
|
|
sceneFileMapping = new SceneFileMapping();
|
|
@@ -91,12 +220,35 @@ public class ConvertListener{
|
|
sceneFileMappingService.saveOrUpdate(sceneFileMapping);
|
|
sceneFileMappingService.saveOrUpdate(sceneFileMapping);
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+ sceneConvertLog.setStatus("1");
|
|
|
|
+
|
|
}catch (Exception e){
|
|
}catch (Exception e){
|
|
- log.error("convert fail, roomId:{}", roomId, e);
|
|
|
|
|
|
+ log.error("convert fail, stationCode:{}, roomId:{}", stationCode, entityId, e);
|
|
|
|
+ sceneConvertLog.setStatus("0");
|
|
|
|
+ sceneConvertLog.setRemark(ExceptionUtil.stacktraceToString(e, 4000));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(dataSource != null){
|
|
|
|
+ FileUtil.del(dataSource);
|
|
|
|
+ FileUtil.del(dataSource.substring(0, dataSource.lastIndexOf("/")) + "_obj2txt");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ sceneConvertLog.setTimeConsuming(String.valueOf(timeInterval.intervalSecond()));
|
|
|
|
+ sceneConvertLogService.save(sceneConvertLog);
|
|
|
|
+
|
|
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
|
|
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+// public boolean checkNead8kPic(JSONArray array){
|
|
|
|
+// array.stream().findFirst().stream().anyMatch()
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+// }
|
|
|
|
|
|
|
|
+ public static void main(String[] args) {
|
|
|
|
+ String dataSource = "110106908000001067_001102050200000038732428/";
|
|
|
|
+ System.out.println(dataSource.substring(0, dataSource.lastIndexOf("/") -1) + "_obj2txt");
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|