|
@@ -0,0 +1,520 @@
|
|
|
+package com.gis.listener;
|
|
|
+
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.http.HttpRequest;
|
|
|
+import cn.hutool.http.HttpResponse;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.gis.constant.CmdConstant;
|
|
|
+import com.gis.constant.ConfigConstant;
|
|
|
+import com.gis.entity.RelicsSceneInitQueueDTO;
|
|
|
+import com.gis.entity.ScenePanoEntity;
|
|
|
+import com.gis.entity.SceneQueueDTO;
|
|
|
+import com.gis.entity.WorkEntity;
|
|
|
+import com.gis.exception.BaseRuntimeException;
|
|
|
+import com.gis.mq.RabbitMqProducerUtil;
|
|
|
+import com.gis.oss.util.AliYunOssUtil;
|
|
|
+import com.gis.oss.util.FileAndOssUtil;
|
|
|
+import com.gis.service.ScenePanoService;
|
|
|
+import com.gis.service.WorkService;
|
|
|
+import com.gis.util.CmdUtils;
|
|
|
+import com.gis.util.FileUtils;
|
|
|
+import com.gis.util.QrCodeUtils;
|
|
|
+import com.gis.util.RandomUtils;
|
|
|
+import com.rabbitmq.client.Channel;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.slf4j.MDC;
|
|
|
+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.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.util.ObjectUtils;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.PrintWriter;
|
|
|
+import java.io.StringWriter;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.*;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 消息监听器
|
|
|
+ *
|
|
|
+ * @author Xiewj
|
|
|
+ * @version 1.0
|
|
|
+ * @since 2023/08/07
|
|
|
+ */
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
+public class SceneListener {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ AliYunOssUtil aliyunOssUtil;
|
|
|
+ @Autowired
|
|
|
+ ConfigConstant configConstant;
|
|
|
+ @Autowired
|
|
|
+ FileAndOssUtil fileAndOssUtil;
|
|
|
+ @Autowired
|
|
|
+ WorkService workService;
|
|
|
+ @Autowired
|
|
|
+ QrCodeUtils qrCodeUtils;
|
|
|
+ @Autowired
|
|
|
+ ScenePanoService scenePanoService;
|
|
|
+ @Autowired
|
|
|
+ RabbitMqProducerUtil rabbitMqProducerUtil;
|
|
|
+ @Value("${queue.relics-init-queue}")
|
|
|
+ String relicsInitQueue;
|
|
|
+ /**
|
|
|
+ * 全景场景初始化方法
|
|
|
+ *
|
|
|
+ * @param channel
|
|
|
+ * @param message
|
|
|
+ * @throws Exception the io exception 这里异常需要处理
|
|
|
+ */
|
|
|
+ @RabbitListener(
|
|
|
+ queuesToDeclare = @Queue("${queue.scene-queue}"),concurrency = "1"
|
|
|
+ )
|
|
|
+ public void sceneQueue(Channel channel, Message message) throws IOException {
|
|
|
+ if (ObjectUtils.isEmpty(message.getBody())) {
|
|
|
+ log.error("消息内容为空,退出构建,当前服务器id:{}" );
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String traceId = System.currentTimeMillis()+"";
|
|
|
+ MDC.put("TRACE_ID", traceId);
|
|
|
+
|
|
|
+ long deliveryTag = message.getMessageProperties().getDeliveryTag();
|
|
|
+ try {
|
|
|
+ String msg = new String(message.getBody(), StandardCharsets.UTF_8);
|
|
|
+ String messageId = message.getMessageProperties().getMessageId();
|
|
|
+ log.info("场景sceneQueue开始,id:{},deliveryTag:{},消息体:{}", messageId,deliveryTag,msg);
|
|
|
+ SceneQueueDTO param = JSONObject.parseObject(msg, SceneQueueDTO.class);
|
|
|
+ if (ObjectUtil.isEmpty(param.getSceneCode())) {
|
|
|
+ log.error("参数列表错误(缺少),格式不匹配,{}",param);
|
|
|
+ channel.basicAck(deliveryTag, false);
|
|
|
+ }
|
|
|
+ WorkEntity workEntity=workService.findByNum(param.getSceneCode());
|
|
|
+ if (ObjectUtil.isEmpty(workEntity)&¶m.getStatus()==0){
|
|
|
+ //初始化创建work表数据
|
|
|
+ workService.entityAdd(param);
|
|
|
+ sendStartMq(param);
|
|
|
+ channel.basicAck(deliveryTag, false);
|
|
|
+ }if (ObjectUtil.isNotEmpty(workEntity)&¶m.getStatus()!=1){
|
|
|
+ //修改状态
|
|
|
+ workEntity.setCalcStatus(param.getStatus());
|
|
|
+ if (ObjectUtil.isNotEmpty(param.getPwd())&&ObjectUtil.isEmpty(workEntity.getPassword())){
|
|
|
+ workEntity.setPassword(param.getPwd());
|
|
|
+ workEntity.setIsPassword(1);
|
|
|
+ }
|
|
|
+ workService.update(workEntity);
|
|
|
+ sendStartMq(param);
|
|
|
+ channel.basicAck(deliveryTag, false);
|
|
|
+ }else if (ObjectUtil.isNotEmpty(param.getSceneCode())&¶m.getStatus()==1){
|
|
|
+ //计算完成处理
|
|
|
+ //1,下载场景的全景图 默认 。scene_view_data/panorama/目录下的全景图图片
|
|
|
+ workEntity.setAlgorithmTime(param.getAlgorithmTime());
|
|
|
+ workEntity.setCalcStatus(0);
|
|
|
+ if (ObjectUtil.isNotEmpty(param.getSceneSource())){
|
|
|
+ workEntity.setSceneSource(param.getSceneSource());
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotEmpty(param.getPwd())&&ObjectUtil.isEmpty(workEntity.getPassword())){
|
|
|
+ workEntity.setPassword(param.getPwd());
|
|
|
+ workEntity.setIsPassword(1);
|
|
|
+ }
|
|
|
+ workService.update(workEntity);
|
|
|
+ //清理旧数据
|
|
|
+ List<ScenePanoEntity> list = scenePanoService.findByWorkId(workEntity.getId());
|
|
|
+ for (ScenePanoEntity scenePanoEntity : list) {
|
|
|
+ scenePanoEntity.setIsDelete(1);
|
|
|
+ scenePanoEntity.setUpdateTime(new Date());
|
|
|
+ scenePanoService.update(scenePanoEntity);
|
|
|
+ }
|
|
|
+
|
|
|
+ String visionUrl = "http://4dkk.4dage.com/scene_view_data/"+param.getSceneCode()+"/images/vision.txt";
|
|
|
+ HttpResponse execute = HttpRequest.get(visionUrl+"?m="+System.currentTimeMillis()).execute();
|
|
|
+ JSONArray sweepLocations = new JSONArray();
|
|
|
+ if (execute.getStatus()==200){
|
|
|
+ log.info("vision.txt存在: {}");
|
|
|
+ JSONObject visJson = JSONObject.parseObject(execute.body());
|
|
|
+ if(visJson.containsKey("sweepLocations")){
|
|
|
+ sweepLocations = visJson.getJSONArray("sweepLocations");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //2,使用krpano工具生成全景图数据
|
|
|
+ List<Map<String,Object>> scenes=new ArrayList<>();
|
|
|
+ for (int i = 0; i < sweepLocations.size(); i++) {
|
|
|
+ JSONObject jsonObject = sweepLocations.getJSONObject(i);
|
|
|
+ String uuid = jsonObject.getString("uuid");
|
|
|
+ String id = jsonObject.getString("id");
|
|
|
+ String ossKey="scene_view_data/"+param.getSceneCode()+"/images/panoramas/"+uuid+".jpg";
|
|
|
+ Map<String,Object> scene=new HashMap<>();
|
|
|
+ ScenePanoEntity scenePanoEntity = this.doSlice(traceId ,ossKey, param.getSceneCode(), workEntity.getId(),uuid+".jpg",uuid,id);
|
|
|
+ // "icon": "https://ossxiaoan.4dage.com/720yun_fd_manage/fd720_8nRkFlzpp/vtour/panos/fd720_8nRkFlzpp.tiles/thumb.jpg",
|
|
|
+ // "sceneCode": "fd720_8nRkFlzpp",
|
|
|
+ // "sceneTitle": "0",
|
|
|
+ // "category": 1,
|
|
|
+ // "type": "pano",
|
|
|
+ // "id": "s_xId8vevp",
|
|
|
+ scene.put("icon", scenePanoEntity.getIcon());
|
|
|
+ scene.put("sceneCode", scenePanoEntity.getSceneCode());
|
|
|
+ scene.put("sceneTitle", id);
|
|
|
+ scene.put("category", 1);
|
|
|
+ scene.put("type", "pano");
|
|
|
+ //id生成规则是 s_ 拼接,随机8位字符串,字母加数字组合,有大小写
|
|
|
+ String customId = generateCustomId();
|
|
|
+ scene.put("id", customId);
|
|
|
+ scenes.add(scene);
|
|
|
+ if (i==0){
|
|
|
+ workEntity.setIcon(scenePanoEntity.getIcon());
|
|
|
+ workService.update(workEntity);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("场景切图完成组装json");
|
|
|
+ //3,修改json文件,并创建work作品表数据,增加作品类型为相机拍摄全景图
|
|
|
+ JSONObject someDataToJson= this.editSomeData(workEntity,scenes);
|
|
|
+
|
|
|
+
|
|
|
+ // 更新跟目录tour.xml 2022-09-15
|
|
|
+ this.updateTour(someDataToJson, workEntity.getId());
|
|
|
+
|
|
|
+ workEntity.setCalcStatus(1);
|
|
|
+ workService.update(workEntity);
|
|
|
+ sendEndMq(param);
|
|
|
+ channel.basicAck(deliveryTag, false);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ channel.basicAck(deliveryTag, false);
|
|
|
+ log.error("场景sceneQueue报错{}",e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private void sendStartMq(SceneQueueDTO param) {
|
|
|
+ RelicsSceneInitQueueDTO relicsSceneInitQueueDTO = new RelicsSceneInitQueueDTO();
|
|
|
+ relicsSceneInitQueueDTO.setSceneCode(param.getSceneCode());
|
|
|
+ relicsSceneInitQueueDTO.setLocation(param.getLocation());
|
|
|
+ relicsSceneInitQueueDTO.setCreateTime(param.getCreateTime());
|
|
|
+ relicsSceneInitQueueDTO.setPhoneNum(param.getPhoneNum());
|
|
|
+ relicsSceneInitQueueDTO.setUserId(param.getUserId());
|
|
|
+ relicsSceneInitQueueDTO.setSnCode(param.getSnCode());
|
|
|
+ relicsSceneInitQueueDTO.setStatus(param.getStatus());
|
|
|
+ relicsSceneInitQueueDTO.setSceneName(param.getSceneName());
|
|
|
+ relicsSceneInitQueueDTO.setShootCount(param.getShootCount());
|
|
|
+ relicsSceneInitQueueDTO.setSceneSource(param.getSceneSource());
|
|
|
+ rabbitMqProducerUtil.sendByWorkQueue(relicsInitQueue, relicsSceneInitQueueDTO);
|
|
|
+ }
|
|
|
+ private void sendEndMq(SceneQueueDTO param) {
|
|
|
+ RelicsSceneInitQueueDTO relicsSceneInitQueueDTO = new RelicsSceneInitQueueDTO();
|
|
|
+ relicsSceneInitQueueDTO.setSceneCode(param.getSceneCode());
|
|
|
+ relicsSceneInitQueueDTO.setLocation(param.getLocation());
|
|
|
+ relicsSceneInitQueueDTO.setAlgorithmTime(param.getAlgorithmTime());
|
|
|
+ relicsSceneInitQueueDTO.setCreateTime(param.getCreateTime());
|
|
|
+ relicsSceneInitQueueDTO.setPhoneNum(param.getPhoneNum());
|
|
|
+ relicsSceneInitQueueDTO.setUserId(param.getUserId());
|
|
|
+ relicsSceneInitQueueDTO.setSnCode(param.getSnCode());
|
|
|
+ relicsSceneInitQueueDTO.setStatus(param.getStatus());
|
|
|
+ relicsSceneInitQueueDTO.setSceneName(param.getSceneName());
|
|
|
+ relicsSceneInitQueueDTO.setShootCount(param.getShootCount());
|
|
|
+ relicsSceneInitQueueDTO.setSceneSource(param.getSceneSource());
|
|
|
+ rabbitMqProducerUtil.sendByWorkQueue(relicsInitQueue, relicsSceneInitQueueDTO);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static final String CHARACTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
|
+
|
|
|
+ public static String generateRandomId() {
|
|
|
+ Random random = new Random();
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ for (int i = 0; i < 8; i++) {
|
|
|
+ int index = random.nextInt(CHARACTERS.length());
|
|
|
+ sb.append(CHARACTERS.charAt(index));
|
|
|
+ }
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String generateCustomId() {
|
|
|
+ return "s_" + generateRandomId();
|
|
|
+ }
|
|
|
+ private ScenePanoEntity doSlice(String traceId, String item, String num, String workId, String imgName, String uuid, String id){
|
|
|
+ ScenePanoEntity entity=scenePanoService.findByWorkIdAndName(workId,imgName);
|
|
|
+ String sceneCode ="";
|
|
|
+ String newName = "";
|
|
|
+ String filePath = "";
|
|
|
+ if (ObjectUtil.isEmpty(entity)) {
|
|
|
+ //未生成
|
|
|
+ sceneCode = RandomUtils.getSceneCode("fd720_");
|
|
|
+ newName = sceneCode + ".jpg";
|
|
|
+ filePath = configConstant.serverBasePath + sceneCode+ "/" + newName;
|
|
|
+ aliyunOssUtil.downloadFile("4dkankan",item,filePath );
|
|
|
+ entity = new ScenePanoEntity();
|
|
|
+ entity.setFilePath(filePath);
|
|
|
+ entity.setFileName(FileUtil.getName(filePath));
|
|
|
+ entity.setSceneCode(sceneCode);
|
|
|
+ entity.setNum(num);
|
|
|
+ entity.setOssPath(item);
|
|
|
+ entity.setName(imgName);
|
|
|
+ entity.setWorkId(workId);
|
|
|
+ entity.setVisid(id);
|
|
|
+ entity.setUuid(uuid);
|
|
|
+ long size = FileUtil.size(new File(filePath));
|
|
|
+ size = size / 1024;
|
|
|
+ log.info("fileSize: " + size);
|
|
|
+ entity.setFileSize(size + "");
|
|
|
+
|
|
|
+ scenePanoService.save(entity);
|
|
|
+ }else {
|
|
|
+ entity.setStatus(0);
|
|
|
+
|
|
|
+ filePath = entity.getFilePath();
|
|
|
+ sceneCode = entity.getSceneCode();
|
|
|
+ boolean exist = FileUtil.exist(filePath);
|
|
|
+ if (exist){
|
|
|
+ FileUtil.del(filePath);
|
|
|
+ }
|
|
|
+ if (filePath.endsWith(".jpg")){
|
|
|
+ String parent = FileUtil.getParent(filePath, 1);
|
|
|
+ FileUtil.del(parent);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ log.info("生成过,重新下载");
|
|
|
+ aliyunOssUtil.downloadFile("4dkankan",item,filePath );
|
|
|
+ log.info("下载完成重新切图");
|
|
|
+ long size = FileUtil.size(new File(filePath));
|
|
|
+ size = size / 1024;
|
|
|
+ log.info("fileSize: " + size);
|
|
|
+ entity.setFileSize(size + "");
|
|
|
+ scenePanoService.update(entity);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ log.info("切图流程开始 : " + filePath);
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+
|
|
|
+ String cmd = CmdConstant.PANO_KRPANO + filePath;
|
|
|
+ // 超时处理机制
|
|
|
+ final ExecutorService exec = Executors.newFixedThreadPool(1);
|
|
|
+ Callable<String> call = new Callable<String>() {
|
|
|
+ @Override
|
|
|
+ public String call() throws Exception {
|
|
|
+ MDC.put("TRACE_ID", traceId);
|
|
|
+ CmdUtils.callLine(cmd, 200);
|
|
|
+ long end = System.currentTimeMillis();
|
|
|
+ log.info("切图完成耗时: {} s" ,(end-start)/1000);
|
|
|
+ return "执行完成";
|
|
|
+ }
|
|
|
+ };
|
|
|
+ // 超时回调
|
|
|
+ Future<String> future = exec.submit(call);
|
|
|
+ try {
|
|
|
+ String obj = future.get(20, TimeUnit.MINUTES); //任务处理超时时间设为 3分钟
|
|
|
+ entity.setStatus(3);
|
|
|
+ String tourXmlScene = this.getTourXmlScene(sceneCode);
|
|
|
+ entity.setTour(tourXmlScene);
|
|
|
+ // 上传切图
|
|
|
+ this.uploadOss(sceneCode);
|
|
|
+ String ossUrl = configConstant.ossDomain + configConstant.ossBasePath + sceneCode+"/vtour/panos/"+sceneCode+".tiles/thumb.jpg";
|
|
|
+ log.info("切图预览图ossUrl: {}",ossUrl);
|
|
|
+ entity.setIcon(ossUrl);
|
|
|
+ log.info("任务成功返回: " + obj);
|
|
|
+
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ entity.setStatus(2);
|
|
|
+ StringWriter trace=new StringWriter();
|
|
|
+ log.error(trace.toString());
|
|
|
+ log.error("异常了 InterruptedException");
|
|
|
+ } catch (ExecutionException | BaseRuntimeException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ StringWriter trace=new StringWriter();
|
|
|
+ e.printStackTrace(new PrintWriter(trace));
|
|
|
+ log.error("超时了 1");
|
|
|
+ // 异常日志要打印,不然不会出现在日志文件中,只会出现在控制台
|
|
|
+ log.error(trace.toString());
|
|
|
+ entity.setStatus(2);
|
|
|
+ future.cancel(true);
|
|
|
+ } catch (TimeoutException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ StringWriter trace=new StringWriter();
|
|
|
+ e.printStackTrace(new PrintWriter(trace));
|
|
|
+ log.error("超时了 2");
|
|
|
+ log.error(trace.toString());
|
|
|
+ entity.setStatus(2);
|
|
|
+ future.cancel(true);
|
|
|
+ } finally {
|
|
|
+ scenePanoService.update(entity);
|
|
|
+ log.info("切图流程, 更新数据库完成 : ");
|
|
|
+ }
|
|
|
+ log.info("切图流程结束 : ");
|
|
|
+ return entity;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新 tour.xml
|
|
|
+ * @param someDataToJson
|
|
|
+ * @param id
|
|
|
+ */
|
|
|
+ private void updateTour(JSONObject someDataToJson, String id) {
|
|
|
+ long startTime = System.currentTimeMillis();
|
|
|
+ String scenes = someDataToJson.getString("scenes");
|
|
|
+ BaseRuntimeException.isBlank(scenes, null, "someData的场景码参数未空");
|
|
|
+ List<ScenePanoEntity> list = scenePanoService.findByWorkId(id);
|
|
|
+
|
|
|
+ // 读取tour.xml模板
|
|
|
+ String baseTour = getBaseTour();
|
|
|
+ StringBuilder builder = new StringBuilder();
|
|
|
+ builder.append(baseTour).append("\r\n");
|
|
|
+ for (ScenePanoEntity entity : list) {
|
|
|
+ String tour = entity.getTour();
|
|
|
+ builder.append(tour).append("\r\n");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加结束标签
|
|
|
+ builder.append("</krpano>");
|
|
|
+
|
|
|
+ String tourPath = configConstant.serverBasePath + id + "/tour.xml";
|
|
|
+ FileUtil.writeUtf8String(builder.toString(), tourPath);
|
|
|
+ log.info("作品tour.xml写入完成");
|
|
|
+
|
|
|
+ String ossKeyPath = configConstant.ossBasePath + id + "/tour.xml";
|
|
|
+ fileAndOssUtil.upload(tourPath, ossKeyPath);
|
|
|
+ log.info("tour.xml上传完成 : {}", ossKeyPath);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getBaseTour(){
|
|
|
+ String baseTourPath = configConstant.serverBasePath + "baseData/tour.xml";
|
|
|
+ String s = FileUtil.readString(baseTourPath, "utf-8");
|
|
|
+ // 结束标签置空, 方便操作
|
|
|
+ s = s.replace("</krpano>", "");
|
|
|
+ return s;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取切图后的tour.xml
|
|
|
+ private String getTourXmlScene(String code) {
|
|
|
+ log.info("处理tour.xml");
|
|
|
+ String tourPath = configConstant.serverBasePath + code + "/vtour/tour.xml";
|
|
|
+ log.info("tourPath: {}", tourPath);
|
|
|
+ BaseRuntimeException.isTrue(!FileUtil.isFile(tourPath), null, code + "_tour.xml文件不存在");
|
|
|
+
|
|
|
+ String tour = FileUtil.readUtf8String(tourPath);
|
|
|
+ tour = this.extractSceneTag(tour);
|
|
|
+ String trim = StrUtil.trim(tour);
|
|
|
+ // log.info("trim: {}", trim);
|
|
|
+ BaseRuntimeException.isTrue(StrUtil.isAllBlank(trim), null, code + "_tour.xml文件不存在");
|
|
|
+
|
|
|
+ // 2022-09-15 加入相对路径
|
|
|
+ String basePath = "%CURRENTXML%../" + code + "/vtour/panos/";
|
|
|
+ trim = trim.replaceAll("panos/", basePath);
|
|
|
+
|
|
|
+ return trim;
|
|
|
+ }
|
|
|
+ public static String extractSceneTag(String xmlString) {
|
|
|
+ Pattern pattern = Pattern.compile("<scene.*?</scene>", Pattern.DOTALL);
|
|
|
+ Matcher matcher = pattern.matcher(xmlString);
|
|
|
+
|
|
|
+ if (matcher.find()) {
|
|
|
+ return matcher.group();
|
|
|
+ }
|
|
|
+
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ private void uploadOss(String sceneCode) {
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+ String filePath = "/mnt/720yun_fd_manage_data/" + sceneCode;
|
|
|
+ String ossKey = "/720yun_fd_manage/" + sceneCode;
|
|
|
+ fileAndOssUtil.uploadBySh(filePath, ossKey);
|
|
|
+ long end = System.currentTimeMillis();
|
|
|
+ log.info("切图上传完成, 耗时:{} s" , (end-start)/1000 );
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private JSONObject editSomeData(WorkEntity workEntity, List<Map<String, Object>> scenes){
|
|
|
+ // 如基someData作出修改,记得把代码里的someData 跟服务器里的someData都修改
|
|
|
+ String baseSomeDataPath = configConstant.serverBasePath + "baseData/someData.json";
|
|
|
+ String baseSomeDataSceneDataPath = configConstant.serverBasePath + "baseData/someDataSceneData.json";
|
|
|
+ log.info("服务器base someData.json path: {}", baseSomeDataPath);
|
|
|
+ // someData.json 内容
|
|
|
+ String content = null;
|
|
|
+ if (FileUtil.isFile(baseSomeDataPath)) {
|
|
|
+ log.info("使用服务器someData.json");
|
|
|
+ content = FileUtil.readUtf8String(baseSomeDataPath);
|
|
|
+ } else {
|
|
|
+ // 获取文件内容
|
|
|
+ log.info("创建someData.json");
|
|
|
+ content = FileUtils.getResourceContent("data/someData.json");
|
|
|
+ FileUtil.writeUtf8String(content, baseSomeDataPath);
|
|
|
+ }
|
|
|
+ String someDataSceneDatContent = null;
|
|
|
+ if (FileUtil.isFile(baseSomeDataSceneDataPath)) {
|
|
|
+ log.info("使用服务器SomeDataSceneData.json");
|
|
|
+ someDataSceneDatContent = FileUtil.readUtf8String(baseSomeDataSceneDataPath);
|
|
|
+ } else {
|
|
|
+ // 获取文件内容
|
|
|
+ log.info("创建SomeDataSceneData.json");
|
|
|
+ someDataSceneDatContent = FileUtils.getResourceContent("data/someDataSceneData.json");
|
|
|
+ FileUtil.writeUtf8String(someDataSceneDatContent, baseSomeDataSceneDataPath);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(content);
|
|
|
+ jsonObject.put("id", workEntity.getId() + "");
|
|
|
+
|
|
|
+
|
|
|
+ // 创建二维码、二维码url
|
|
|
+ String shareUrl = configConstant.domain4dKK + "/panorama/showMobile.html?id=" + workEntity.getId();
|
|
|
+ String qrCode = qrCodeUtils.generateLogoQrCode(shareUrl, configConstant.serverBasePath, configConstant.ossBasePath, configConstant.ossDomain, workEntity.getId());
|
|
|
+ jsonObject.put("share", shareUrl);
|
|
|
+ jsonObject.put("qrCode", qrCode);
|
|
|
+ jsonObject.put("icon",workEntity.getIcon());
|
|
|
+ jsonObject.put("name",workEntity.getName());
|
|
|
+ if (ObjectUtil.isNotEmpty(workEntity.getPassword())){
|
|
|
+ jsonObject.put("password", workEntity.getPassword());
|
|
|
+ }
|
|
|
+
|
|
|
+ String ossKeyPath = configConstant.ossBasePath + workEntity.getId() + "/someData.json";
|
|
|
+ workEntity.setQrCode(qrCode);
|
|
|
+ workEntity.setShare(shareUrl);
|
|
|
+ workService.update(workEntity);
|
|
|
+
|
|
|
+ JSONArray scenesJson = new JSONArray();
|
|
|
+ for (Map<String, Object> scene : scenes) {
|
|
|
+ JSONObject SomeDataSceneDataJsonObject = JSONObject.parseObject(someDataSceneDatContent);
|
|
|
+ SomeDataSceneDataJsonObject.putAll(scene);
|
|
|
+ scenesJson.add(JSON.toJSON(SomeDataSceneDataJsonObject));
|
|
|
+ }
|
|
|
+ jsonObject.remove("scenes");
|
|
|
+ jsonObject.put("scenes",JSON.toJSON(scenesJson));
|
|
|
+
|
|
|
+ try {
|
|
|
+ fileAndOssUtil.upload(jsonObject.toJSONString().getBytes(), ossKeyPath);
|
|
|
+
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ String ossUrl = configConstant.ossDomain + ossKeyPath;
|
|
|
+ log.info("ossSomeData:{}", ossUrl);
|
|
|
+ return jsonObject;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ List<String> list=new ArrayList<>();
|
|
|
+ list.add("scene_view_data/KJ-t-QPqp92mGf1c/images/pan/high/0.jpg");
|
|
|
+ list.add("scene_view_data/KJ-t-QPqp92mGf1c/images/pan/high/1.jpg");
|
|
|
+ list.add("scene_view_data/KJ-t-QPqp92mGf1c/images/pan/high/3.jpg");
|
|
|
+ list.add("scene_view_data/KJ-t-QPqp92mGf1c/images/pan/high/4.jpg");
|
|
|
+ //循环只打印文件是偶数的图片
|
|
|
+
|
|
|
+ }
|
|
|
+}
|