|
|
@@ -0,0 +1,249 @@
|
|
|
+//package com.fdkankan.rabbitmq.util;
|
|
|
+//
|
|
|
+//import cn.hutool.core.collection.CollUtil;
|
|
|
+//import cn.hutool.core.date.DatePattern;
|
|
|
+//import cn.hutool.core.date.DateUtil;
|
|
|
+//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.util.StrUtil;
|
|
|
+//import com.alibaba.fastjson.JSON;
|
|
|
+//import com.alibaba.fastjson.JSONArray;
|
|
|
+//import com.alibaba.fastjson.JSONObject;
|
|
|
+//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+//import com.fdkankan.modeldemo.constant.Constant;
|
|
|
+//import com.fdkankan.modeldemo.entity.Scene;
|
|
|
+//import com.fdkankan.modeldemo.entity.SceneConvertLog;
|
|
|
+//import com.fdkankan.modeldemo.entity.SceneFileMapping;
|
|
|
+//import com.fdkankan.modeldemo.service.SceneConvertLogService;
|
|
|
+//import com.fdkankan.modeldemo.service.SceneFileMappingService;
|
|
|
+//import com.fdkankan.modeldemo.service.SceneService;
|
|
|
+//import com.fdkankan.modeldemo.utils.ConvertUtil;
|
|
|
+//import com.fdkankan.modeldemo.utils.FdfsUtil;
|
|
|
+//import com.fdkankan.modeldemo.utils.HttpUtilExt;
|
|
|
+//import com.fdkankan.redis.RedisClient;
|
|
|
+//import com.rabbitmq.client.Channel;
|
|
|
+//import lombok.extern.slf4j.Slf4j;
|
|
|
+//import org.springframework.amqp.core.Message;
|
|
|
+//import org.springframework.amqp.rabbit.annotation.Queue;
|
|
|
+//import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
|
|
+//import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+//import org.springframework.stereotype.Component;
|
|
|
+//
|
|
|
+//import javax.annotation.Resource;
|
|
|
+//import java.io.File;
|
|
|
+//import java.nio.charset.StandardCharsets;
|
|
|
+//import java.util.Date;
|
|
|
+//import java.util.List;
|
|
|
+//
|
|
|
+///**
|
|
|
+// * <p>
|
|
|
+// * TODO
|
|
|
+// * </p>
|
|
|
+// * 场景转换监听器
|
|
|
+// * @since 2022/4/19
|
|
|
+// **/
|
|
|
+//@Slf4j
|
|
|
+//@Component
|
|
|
+//public class ConvertListenerUtil {
|
|
|
+//
|
|
|
+// public final static String baseZipPath = "/mnt/scene/convert/";
|
|
|
+//
|
|
|
+// public final static String file_type_key = "fileType";
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// private ConvertUtil convertUtil;
|
|
|
+// @Resource
|
|
|
+// private FdfsUtil fdfsUtil;
|
|
|
+// @Autowired
|
|
|
+// private SceneFileMappingService sceneFileMappingService;
|
|
|
+// @Autowired
|
|
|
+// private SceneService sceneService;
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// private SceneConvertLogService sceneConvertLogService;
|
|
|
+// @Resource
|
|
|
+// private RedisClient redisClient;
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 场景转换监听器
|
|
|
+// * @throws Exception
|
|
|
+// */
|
|
|
+// @RabbitListener(
|
|
|
+// queuesToDeclare = @Queue(Constant.QUEUE_SCENE_CONVERT),
|
|
|
+// concurrency = "1"
|
|
|
+// )
|
|
|
+// public void buildObjScenePreHandler(Channel channel, Message message) throws Exception {
|
|
|
+// // 开始计时
|
|
|
+// TimeInterval timeInterval = new TimeInterval();
|
|
|
+// timeInterval.start();
|
|
|
+//
|
|
|
+// // 获取消息id
|
|
|
+// String messageId = message.getMessageProperties().getMessageId();
|
|
|
+// // 消息开始消费,立即ack,防止二次消费
|
|
|
+// channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
|
|
|
+//
|
|
|
+// String stationCode = null;
|
|
|
+// String entityId = null;
|
|
|
+// Date upTime = null;
|
|
|
+// JSONArray fileList = null;
|
|
|
+// SceneConvertLog sceneConvertLog = new SceneConvertLog();
|
|
|
+// String dataSource = null;
|
|
|
+// String convertIngKey = null;
|
|
|
+// String convertType = null;
|
|
|
+// String upTimeStr = null;
|
|
|
+// String upTimeKey = null;
|
|
|
+// try {
|
|
|
+// String msg = new String(message.getBody(), StandardCharsets.UTF_8);
|
|
|
+// log.info("msg:{}", msg);
|
|
|
+// JSONObject jsonObject = JSON.parseObject(msg);
|
|
|
+// stationCode = jsonObject.getString("stationCode");
|
|
|
+// entityId = jsonObject.getString("entityId");
|
|
|
+// upTimeStr = jsonObject.getString("upTime");
|
|
|
+// convertType = jsonObject.getString("convertType");
|
|
|
+// if(StrUtil.isEmpty(convertType)){
|
|
|
+// convertType = "standar";
|
|
|
+// }
|
|
|
+// if(StrUtil.isNotEmpty(upTimeStr)){
|
|
|
+// // 将字符串转为时间格式
|
|
|
+// upTime = DateUtil.parse(upTimeStr, DatePattern.NORM_DATETIME_PATTERN);
|
|
|
+// // 将字符串转为YYYYMMDDHHMMSS格式
|
|
|
+// upTimeKey = upTimeStr.replace("-", "").replace(" ", "").replace(":", "");
|
|
|
+// }
|
|
|
+// fileList = jsonObject.getJSONArray("fileList");
|
|
|
+// convertIngKey = String.format(Constant.REDIS_SCENE_CONVERT_ING, messageId);
|
|
|
+// String convert = redisClient.get(convertIngKey);
|
|
|
+// log.info("-----------------convert:{}-----------------", convert);
|
|
|
+// // 铁塔的rabbitmq有问题,简单队列不能负载均衡,所以这里用redis做了一个锁,方式重复消费
|
|
|
+// if(StrUtil.isNotEmpty(convert)){// 正在转换,直接丢弃
|
|
|
+// log.warn("场景正在转换,此消息丢弃, stationCode:{}, entityId:{}", stationCode, entityId);
|
|
|
+// convertIngKey = null;
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// redisClient.add(convertIngKey, stationCode + "_" + entityId, 60 * 60 * 1000L);
|
|
|
+//
|
|
|
+// sceneConvertLog.setStationCode(stationCode);
|
|
|
+// sceneConvertLog.setEntityId(entityId);
|
|
|
+// sceneConvertLog.setCreateTime(new Date());
|
|
|
+// sceneConvertLog.setConverttype(convertType);
|
|
|
+//
|
|
|
+// // 只更新上传时间
|
|
|
+// if(convertType.equals("upTime")){
|
|
|
+//
|
|
|
+// List<Scene> list = sceneService.list(new LambdaQueryWrapper<Scene>().eq(Scene::getNum, entityId).eq(Scene::getStationcode, stationCode));
|
|
|
+// if(CollUtil.isNotEmpty(list)){
|
|
|
+// Date finalUpTime = upTime;
|
|
|
+// String finalUpTimeKey = upTimeKey;
|
|
|
+// list.stream().forEach(v->{
|
|
|
+// v.setUpTime(finalUpTime);
|
|
|
+// v.setUpTimeKey(finalUpTimeKey);
|
|
|
+// });
|
|
|
+// sceneService.updateBatchById(list);
|
|
|
+//
|
|
|
+// // 有中高低点位的场景的公有visiontxt文件
|
|
|
+// List<SceneFileMapping> visionTxt = sceneFileMappingService.getByNumAndKey(list.get(0).getNum(), -1, "scene_view_data/" + list.get(0).getNum() + "/images/vision.txt");
|
|
|
+// if(CollUtil.isNotEmpty(visionTxt)){
|
|
|
+// visionTxt.stream().forEach(v -> v.setUpTime(finalUpTimeKey));
|
|
|
+// sceneFileMappingService.updateBatchById(visionTxt);
|
|
|
+// }
|
|
|
+//
|
|
|
+// for (Scene scene : list) {
|
|
|
+// List<SceneFileMapping> sceneFileMappingList = sceneFileMappingService.getByNumAndSubgroup(scene.getNum(), scene.getSubgroup());
|
|
|
+// if(CollUtil.isEmpty(sceneFileMappingList)){
|
|
|
+// continue;
|
|
|
+// }
|
|
|
+// sceneFileMappingList.stream().forEach(v -> v.setUpTime(scene.getUpTimeKey()));
|
|
|
+// sceneFileMappingService.updateBatchById(sceneFileMappingList);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }else{
|
|
|
+// // 校验文件是否齐全
|
|
|
+// boolean exists512 = fileList.stream().anyMatch(v -> {
|
|
|
+// JSONObject obj = (JSONObject) v;
|
|
|
+// return "1".equals(obj.getString(file_type_key));
|
|
|
+// });
|
|
|
+//
|
|
|
+// boolean exists4k = fileList.stream().anyMatch(v -> {
|
|
|
+// JSONObject obj = (JSONObject) v;
|
|
|
+// return "2".equals(obj.getString(file_type_key));
|
|
|
+// });
|
|
|
+//
|
|
|
+// boolean exists8k = fileList.stream().anyMatch(v -> {
|
|
|
+// JSONObject obj = (JSONObject) v;
|
|
|
+// return "3".equals(obj.getString(file_type_key));
|
|
|
+// });
|
|
|
+//
|
|
|
+// dataSource = baseZipPath + stationCode + "_" + entityId + "_" + DateUtil.format(upTime, DatePattern.PURE_DATETIME_PATTERN) + "/";
|
|
|
+// 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.stream().forEach(o->{
|
|
|
+// JSONObject obj = (JSONObject) o;
|
|
|
+// String fileName = obj.getString("fileName");
|
|
|
+// String fileType = obj.getString(file_type_key);
|
|
|
+// String fileUrl = obj.getString("fileUrl");
|
|
|
+// if("7".equals(fileType)){// vision.txt
|
|
|
+// HttpUtilExt.downloadFileAndCheck(fileUrl, imagePath + fileName, 300000);
|
|
|
+// }
|
|
|
+// if("1".equals(fileType)){// 512图
|
|
|
+// HttpUtilExt.downloadFileAndCheck(fileUrl, image512Path + fileName, 300000);
|
|
|
+// }
|
|
|
+// if("2".equals(fileType)){// 4k图
|
|
|
+// HttpUtilExt.downloadFileAndCheck(fileUrl, image4kPath + fileName, 300000);
|
|
|
+// 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, 300000);
|
|
|
+// }
|
|
|
+// if("12".equals(fileType)){// scene.json
|
|
|
+// HttpUtilExt.downloadFileAndCheck(fileUrl, dataPath + fileName, 300000);
|
|
|
+// }
|
|
|
+// });
|
|
|
+//
|
|
|
+// // 转换并上传文件
|
|
|
+// convertUtil.convert(dataSource, entityId, stationCode, upTime, convertType, upTimeKey);
|
|
|
+// }
|
|
|
+//
|
|
|
+// sceneConvertLog.setStatus("1");
|
|
|
+// sceneConvertLog.setTimeConsuming(String.valueOf(timeInterval.intervalSecond()));
|
|
|
+// sceneConvertLogService.save(sceneConvertLog);
|
|
|
+//
|
|
|
+// }catch (Exception e){
|
|
|
+// log.error("convert fail, stationCode:{}, roomId:{}, upTimeKey:{}", stationCode, entityId, upTimeKey, e);
|
|
|
+// sceneConvertLog.setStatus("0");
|
|
|
+// sceneConvertLog.setRemark(ExceptionUtil.stacktraceToString(e, 4000));
|
|
|
+// sceneConvertLog.setTimeConsuming(String.valueOf(timeInterval.intervalSecond()));
|
|
|
+// sceneConvertLogService.save(sceneConvertLog);
|
|
|
+// }finally{
|
|
|
+// if(dataSource != null){
|
|
|
+// FileUtil.del(dataSource);
|
|
|
+// FileUtil.del(dataSource.substring(0, dataSource.lastIndexOf("/")) + "_obj2txt");
|
|
|
+// }
|
|
|
+//
|
|
|
+// if(StrUtil.isNotEmpty(convertIngKey)){
|
|
|
+// redisClient.del(convertIngKey);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//}
|