浏览代码

add offline queue3

xiewj 3 月之前
父节点
当前提交
71582b5500

+ 5 - 0
720yun_fd_base/gis_common/src/main/java/com/gis/common/constant/RedisConstant.java

@@ -22,4 +22,9 @@ public class RedisConstant {
 
     /**新增作品*/
     public static final String REPORT_WORK = "report:addWork:";
+
+
+    public static final String WORK_OFFLINE = "work:offline:";
+    public static final String WORK_OFFLINE_PROGRESS = "work:offline:progress";
+
 }

+ 1 - 1
720yun_fd_base/gis_common/src/main/java/com/gis/common/util/RedisUtil.java

@@ -352,7 +352,7 @@ public class RedisUtil {
      * @param key
      * @param value
      */
-    public void set(String key, String value) {
+    public void set(String key, Object value) {
         redisTemplate.opsForValue().set(key, value);
     }
 

+ 1 - 1
720yun_fd_base/gis_domain/src/main/java/com/gis/domain/entity/WorkEntity.java

@@ -100,7 +100,7 @@ public class WorkEntity extends BaseStrEntity implements Serializable {
     @ApiModelProperty(value = "切图状态:-1切图失败 0等待中 1 排队 2切图中 3切图完成", name = "panoStatus")
     private Integer panoStatus;
 
-    @ApiModelProperty(value = "切图状态:-1失败 0未生成 1排队中 2生成中 3生成成功 ", name = "offlineStatus")
+    @ApiModelProperty(value = "离线包 状态:-1失败 0未生成 1排队中 2生成中 3生成成功", name = "offlineStatus")
     private Integer offlineStatus;
 
     public String offlineUrl;

+ 82 - 50
720yun_fd_consumer/src/main/java/com/gis/listener/container/WorkOfflineListener.java

@@ -1,6 +1,7 @@
 package com.gis.listener.container;
 
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.lang.tree.Tree;
 import cn.hutool.core.util.ObjUtil;
@@ -8,9 +9,12 @@ import com.alibaba.fastjson.JSONObject;
 import com.fdkankan.filestorage.FileStorageTemplate;
 import com.gis.common.annotation.LogAnnotation;
 import com.gis.common.constant.ConfigConstant;
+import com.gis.common.constant.RedisConstant;
 import com.gis.common.mq.RabbitMqProducerUtil;
 import com.gis.common.util.FileUtils;
+import com.gis.common.util.RedisUtil;
 import com.gis.common.util.Result;
+import com.gis.constant.SysConstants;
 import com.gis.domain.dto.WorkOfflineDTO;
 import com.gis.domain.dto.WorkOfflineDoneDTO;
 import com.gis.domain.entity.WorkEntity;
@@ -36,6 +40,7 @@ import javax.annotation.Resource;
 import java.io.File;
 import java.nio.charset.StandardCharsets;
 import java.util.List;
+import java.util.concurrent.TimeUnit;
 
 /**
  * @author Xiewj
@@ -46,9 +51,11 @@ import java.util.List;
 public class WorkOfflineListener implements ChannelAwareMessageListener {
     @Autowired
     WorkService workService;
-    /** 服务器文件地址*/
+    /**
+     * 服务器文件地址
+     */
     @Value("${server.file.path}")
-    public  String serverBasePath;
+    public String serverBasePath;
     @Autowired
     private WorkViewService workViewService;
     @Autowired
@@ -68,85 +75,103 @@ public class WorkOfflineListener implements ChannelAwareMessageListener {
 
     @Autowired
     ConfigConstant configConstant;
+
+    @Autowired
+    RedisUtil redisUtil;
+
+
     @Override
     @LogAnnotation
     public void onMessage(Message message, Channel channel) throws Exception {
         if (ObjectUtils.isEmpty(message.getBody())) {
-            log.error("消息内容为空,退出构建,当前服务器id:{}" );
+            log.error("消息内容为空,退出构建,当前服务器id:{}");
             return;
         }
         long deliveryTag = message.getMessageProperties().getDeliveryTag();
         String msg = new String(message.getBody(), StandardCharsets.UTF_8);
         String messageId = message.getMessageProperties().getMessageId();
-        log.info("场景WorkOffline开始,id:{},deliveryTag:{},消息体:{}", messageId,deliveryTag,msg);
+        log.info("场景WorkOffline开始,id:{},deliveryTag:{},消息体:{}", messageId, deliveryTag, msg);
         WorkOfflineDTO param = JSONObject.parseObject(msg, WorkOfflineDTO.class);
+        String key = RedisConstant.WORK_OFFLINE + param.getWorkId();
+        String progressKey = RedisConstant.WORK_OFFLINE_PROGRESS + param.getWorkId();
         try {
+            if (redisUtil.hasKey(key)) {
+                log.error("场景WorkOffline正在已处理,id:{},deliveryTag:{},消息体:{}", messageId, deliveryTag, msg);
+                channel.basicAck(deliveryTag, false);
+                return;
+            }
+            //value存入进度
+            redisUtil.set(key, DateUtil.now(), 5, TimeUnit.HOURS);
+
+
+            redisUtil.set(progressKey, 10);
+
             WorkEntity workEntity = workService.getById(param.getWorkId());
-            if (ObjUtil.isNotEmpty(workEntity)){
+            if (ObjUtil.isNotEmpty(workEntity)) {
                 //切图状态:-1失败 0未生成 1排队中 2生成中 3生成成功
-                workService.updateOfflineStatus(param.getWorkId(),2);
+                workService.updateOfflineStatus(param.getWorkId(), 1);
                 //下载接口数据。
-                String basePath=param.getPath()+ File.separator+"wwwroot";
-                if (!FileUtil.exist(basePath)){
+                String basePath = param.getPath() + File.separator + "wwwroot";
+                if (!FileUtil.exist(basePath)) {
                     FileUtil.mkdir(basePath);
                 }
                 //id场景码接口
-                WorkIdVO workIdVO=new WorkIdVO();
-                BeanUtil.copyProperties(workEntity,workIdVO);
+                WorkIdVO workIdVO = new WorkIdVO();
+                BeanUtil.copyProperties(workEntity, workIdVO);
                 Result getIdInfo = Result.success(workIdVO);
-                String getIdInfoPath =basePath+File.separator+"panorama"+File.separator+"qjkankan"+File.separator+"web"+File.separator+"common"+File.separator+"getIdInfo";
+                String getIdInfoPath = basePath + File.separator + "panorama" + File.separator + "qjkankan" + File.separator + "web" + File.separator + "common" + File.separator + "getIdInfo";
                 FileUtils.writeUtf8String(getIdInfo, getIdInfoPath);
                 //view接口
-                String  getViewInfoPath =basePath+File.separator+"panorama"+File.separator+"qjkankan"+File.separator+"work"+File.separator+"view--workId="+workEntity.getId();
+                String getViewInfoPath = basePath + File.separator + "panorama" + File.separator + "qjkankan" + File.separator + "work" + File.separator + "view--workId=" + workEntity.getId();
                 WorkViewVo viewInfo = workViewService.getViewInfo(workEntity.getId());
-                Result  getViewInfo= Result.success(viewInfo);
+                Result getViewInfo = Result.success(viewInfo);
                 FileUtils.writeUtf8String(getViewInfo, getViewInfoPath);
-                //下载作品的OSS文件夹
+
+                // 下载作品的OSS文件夹
                 String baseOssKey = "720yun_fd_manage";
-                String ossKey =baseOssKey+"/" + workEntity.getId();
-                OssShUtil.yunDownload(ossKey,basePath+File.separator+baseOssKey);
+                String ossKey = baseOssKey + "/" + workEntity.getId();
+                OssShUtil.yunDownload(ossKey, basePath + File.separator + baseOssKey);
 
-                String meshBasePath=param.getPath()+ File.separator+"mesh";
+                String meshBasePath = param.getPath() + File.separator + "mesh";
+                redisUtil.set(progressKey, 20);
 
-                //处理关联的作品和场景
+                // 处理关联的作品和场景
                 List<WorkNavigationEntity> workNavigationEntities = workNavigationService.selectByWorkId(workEntity.getId());
+
+                int totalItems = workNavigationEntities.size();
+                int progressIncrement = (totalItems > 0) ? (70 - 20) / totalItems : 0; // 进度从20增加到70%
+                int currentProgress = 20;
+
                 for (WorkNavigationEntity workNavigationEntity : workNavigationEntities) {
-                    if (ObjUtil.isNotEmpty(workNavigationEntity.getType())){
-                        if (workNavigationEntity.getType().equalsIgnoreCase("pano")){
-                            String PanoOssKey = baseOssKey+"/"+workNavigationEntity.getSceneCode();
-                            log.info("下载作品类-全景图:{},下载路径-PanoOssKey", workNavigationEntity.getSceneCode(),PanoOssKey);
-                            OssShUtil.yunDownload(PanoOssKey,basePath+File.separator+baseOssKey);
-                        }else if (workNavigationEntity.getType().equalsIgnoreCase("4dkk")){
-                            //整合离线包
-                            log.info("整合mesh场景,{}",workNavigationEntity.getSceneCode());
-                            //unzip -n KK-t-4Q9aHYKmDtf.zip 'wwwroot/*' -d /mnt/720yun_fd_manage_data/offlineData/WK1920049367641874432/
-                            String zipPath=meshBasePath+File.separator+workNavigationEntity.getSceneCode()+".zip";
-                            if (FileUtil.exist(zipPath)){
-                                String cmd = String.format(CmdConstant.UNZIP_MESH_ZIP,zipPath,param.getPath());
+                    if (ObjUtil.isNotEmpty(workNavigationEntity.getType())) {
+                        if (workNavigationEntity.getType().equalsIgnoreCase("pano")) {
+                            String PanoOssKey = baseOssKey + "/" + workNavigationEntity.getSceneCode();
+                            log.info("下载作品类-全景图:{},下载路径-PanoOssKey", workNavigationEntity.getSceneCode(), PanoOssKey);
+                            OssShUtil.yunDownload(PanoOssKey, basePath + File.separator + baseOssKey);
+                        } else if (workNavigationEntity.getType().equalsIgnoreCase("4dkk")) {
+                            // 整合离线包
+                            log.info("整合mesh场景,{}", workNavigationEntity.getSceneCode());
+                            String zipPath = meshBasePath + File.separator + workNavigationEntity.getSceneCode() + ".zip";
+                            if (FileUtil.exist(zipPath)) {
+                                String cmd = String.format(CmdConstant.UNZIP_MESH_ZIP, zipPath, param.getPath());
                                 CmdUtils.callLineSh(cmd);
                             }
                             log.info("整合mesh场景解压完成");
                         }
+                    }
 
-
-
-//                        if (workNavigationEntity.getType().equalsIgnoreCase("4dkk") && workNavigationEntity.getVersion().equalsIgnoreCase("V3")){
-//                            log.info("下载mesh场景 V3 ");
-//                            downloadService.downloadMeshSceneV3(workNavigationEntity.getSceneCode());
-//                        }
-//                        if (workNavigationEntity.getType().equalsIgnoreCase("4dkk") && workNavigationEntity.getVersion().equalsIgnoreCase("V4")){
-//                            log.info("下载mesh场景 V4 ");
-//                            downloadService.downloadMeshScene(workNavigationEntity.getSceneCode());
-//                        }
-
-
+                    currentProgress += progressIncrement;
+                    if (currentProgress > 70) {
+                        currentProgress = 70;
                     }
+                    redisUtil.set(progressKey, currentProgress); // 更新进度
                 }
-                if (FileUtil.exist(meshBasePath)){
-                    log.info("删除mesh场景文件夹:{}",meshBasePath);
-                    String cmd = String.format(CmdConstant.RM_Folder,meshBasePath);
+
+                if (FileUtil.exist(meshBasePath)) {
+                    log.info("删除mesh场景文件夹:{}", meshBasePath);
+                    String cmd = String.format(CmdConstant.RM_Folder, meshBasePath);
                     CmdUtils.callLineSh(cmd);
-                    log.info("删除mesh场景文件夹完成:{}",meshBasePath);
+                    log.info("删除mesh场景文件夹完成:{}", meshBasePath);
                 }
 
                 //处理全景看看离线包
@@ -154,23 +179,30 @@ public class WorkOfflineListener implements ChannelAwareMessageListener {
 //                //打成zip包
 //                String zipName=workEntity.getId()+"_offline.zip";
 //                String zipPath="";
+                redisUtil.set(progressKey, 80);
 //                //上传zip包
 //                String zipOssKey = "720yun_fd_manage/"+workEntity.getId()+"/" + zipName;
 //                fileAndOssUtil.uploadBySh(zipPath, zipOssKey);
 //                 String ossUrl= fileStorageTemplate.calculateUrl("") + zipOssKey;
+                redisUtil.set(progressKey, 90);
 //                //通知场景完成
+                redisUtil.set(progressKey, 100);
+//                //修改完成进度
+                workService.updateOfflineStatus(param.getWorkId(), 3);
 //                WorkOfflineDoneDTO workOfflineDoneDTO=new WorkOfflineDoneDTO();
 //                workOfflineDoneDTO.setWorkId(workEntity.getId());
 //                workOfflineDoneDTO.setUrl(ossUrl);
 //                rabbitMqProducerUtil.sendByWorkQueue(workOfflineDoneQueue,workOfflineDoneDTO);
+
             }
 
 
-        }catch (Exception e){
-            log.error("场景WorkOffline报错{}",e.getMessage());
-            workService.updateOfflineStatus(param.getWorkId(),-1);
+        } catch (Exception e) {
+            log.error("场景WorkOffline报错{}", e.getMessage());
+            workService.updateOfflineStatus(param.getWorkId(), -1);
             e.printStackTrace();
-        }finally {
+        } finally {
+            redisUtil.delete(key);
             channel.basicAck(deliveryTag, false);
         }
     }

+ 14 - 7
720yun_fd_manage/src/main/java/com/gis/controller/AgeController.java

@@ -1,7 +1,9 @@
 package com.gis.controller;
 
 import cn.hutool.core.util.ObjUtil;
+import com.gis.common.constant.RedisConstant;
 import com.gis.common.mq.RabbitMqProducerUtil;
+import com.gis.common.util.RedisUtil;
 import com.gis.common.util.Result;
 import com.gis.domain.dto.*;
 import com.gis.domain.entity.WorkEntity;
@@ -44,6 +46,10 @@ public class AgeController {
     public  String serverBasePath;
     @Autowired
     RabbitMqProducerUtil rabbitMqProducerUtil;
+
+
+    @Autowired
+    RedisUtil redisUtil;
     /**
      * 获取所有场景
      * 使用超级管理员权限的
@@ -117,7 +123,7 @@ public class AgeController {
     @ApiOperation(value = "v2.0.0-开始下载离线包重置状态", notes = "")
     @PostMapping("/UpdateDownloadOfflineStatus")
     public Result UpdateDownloadOfflineStatus(@RequestBody WorkOfflineDetailDTO dto) {
-        return Result.success(workService.updateOfflineStatus(dto.getWorkId(),0));
+        return Result.success(workService.updateOfflineStatus(dto.getWorkId(),1));
     }
 
     /*
@@ -130,26 +136,27 @@ public class AgeController {
         WorkEntity workEntity = workService.getById(dto.getWorkId());
         WorkOfflineDetailDTO detailDTO=new WorkOfflineDetailDTO();
         detailDTO.setWorkId(dto.getWorkId());
-        //切图状态:-1失败 0未生成 1排队中 2生成中 3生成成功
+        //离线包 状态:-1失败 0未生成 1排队中 2生成中 3生成成功
+        String progressKey = RedisConstant.WORK_OFFLINE_PROGRESS + dto.getWorkId();
         if (ObjUtil.isNotNull(workEntity)){
             //初次 进来返回 路径
-            if  (workEntity.getOfflineStatus()==0){
+            if  (workEntity.getOfflineStatus()==0 || workEntity.getOfflineStatus()==1){
                 String basePath=serverBasePath+
                         File.separator+"offlineData"+
                         File.separator+dto.getWorkId();
                 detailDTO.setPath(basePath);
-            }else if (workEntity.getOfflineStatus()==1){
                 detailDTO.setProgress(0);
             }else if (workEntity.getOfflineStatus()==2){
                 //从redis获取生成进度
-                detailDTO.setProgress(10);
+                if (redisUtil.hasKey(progressKey)){
+                    detailDTO.setProgress((Integer) redisUtil.get(progressKey));
+                }
             }else if (workEntity.getOfflineStatus()==3){
+                redisUtil.delete(progressKey);
                 //从redis获取生成进度
                 detailDTO.setProgress(100);
                 detailDTO.setUrl(workEntity.getOfflineUrl());
             }
-
-
         }
 
         return Result.success(detailDTO);