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