123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790 |
- package com.fdkankan.contro.service.impl;
- import cn.hutool.core.bean.BeanUtil;
- import cn.hutool.core.collection.CollUtil;
- import cn.hutool.core.io.FileUtil;
- import cn.hutool.core.util.ZipUtil;
- import cn.hutool.http.HttpUtil;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.fdkankan.common.constant.*;
- import com.fdkankan.common.util.FileUtils;
- import cn.hutool.core.util.StrUtil;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.fdkankan.common.util.FileUtils;
- import com.fdkankan.contro.bean.SceneJsonBean;
- import com.fdkankan.contro.entity.*;
- import com.fdkankan.contro.factory.UserEditData.UserEditDataHandler;
- import com.fdkankan.contro.factory.UserEditData.UserEditDataHandlerFactory;
- import com.fdkankan.contro.service.ICommonService;
- import com.fdkankan.contro.service.*;
- import com.fdkankan.contro.vo.SceneEditControlsVO;
- import com.fdkankan.contro.vo.ScenePlusVO;
- import com.fdkankan.fyun.config.FYunFileConfig;
- import com.fdkankan.fyun.face.FYunFileServiceInterface;
- import com.fdkankan.model.constants.ConstantFileName;
- import com.fdkankan.model.constants.ConstantFilePath;
- import com.fdkankan.model.constants.UploadFilePath;
- import com.fdkankan.model.utils.CreateObjUtil;
- import com.fdkankan.model.utils.FloorPlanUserUtil;
- import com.fdkankan.rabbitmq.bean.BuildSceneCallMessage;
- import com.fdkankan.rabbitmq.util.RabbitMqProducer;
- import com.fdkankan.redis.constant.RedisKey;
- import com.fdkankan.redis.util.RedisUtil;
- import com.fdkankan.sms.SendMailAcceUtils;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.lang3.ObjectUtils;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.cloud.context.config.annotation.RefreshScope;
- import org.springframework.stereotype.Service;
- import javax.annotation.Resource;
- import java.io.File;
- import java.io.IOException;
- import java.security.GeneralSecurityException;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.Objects;
- import java.util.Set;
- import java.util.Objects;
- import java.util.*;
- import java.util.stream.Collectors;
- @Slf4j
- @Service
- @RefreshScope
- public class CommonServiceImpl implements ICommonService {
- @Value("${main.laserUrl:#{null}}")
- private String laserUrl;
- @Value("${env:gn}")
- private String env;
- @Value("${helpLink.zh-cn:https://docs.4dkankan.com/#/product/4dkk/zh-cn/README}")
- private String helpLinkZh;
- @Value("${helpLink.en-us:https://docs.4dkankan.com/#/product/4dkk/en-us/README}")
- private String helpLinkEn;
- @Value("#{'${camType.laser:}'.split(',')}")
- private List<Integer> laserCamTypeList;
- @Value("${model.modelKind:3dtiles}")
- private String modelKind;
- @Value("#{'${model.3dtiles.sceneSource:}'.split(',')}")
- private List<Integer> sdTilesSceneSourceList;
- @Autowired
- private ISceneAsynOperLogService sceneAsynOperLogService;
- @Resource
- private FYunFileServiceInterface fYunFileServiceInterface;
- @Autowired
- private IScenePlusService scenePlusService;
- @Autowired
- private IScenePlusExtService scenePlusExtService;
- @Autowired
- private IMailTemplateService mailTemplateService;
- @Autowired
- private IUserService userService;
- @Autowired
- private ISceneProService sceneProService;
- @Autowired
- private ICameraDetailService cameraDetailService;
- @Autowired
- private IUserIncrementService userIncrementService;
- @Autowired
- private IIncrementTypeService incrementTypeService;
- @Autowired
- private ICameraService cameraService;
- @Autowired
- private FYunFileConfig fYunFileConfig;
- @Autowired
- private ISceneEditInfoService sceneEditInfoService;
- @Autowired
- private ISceneEditControlsService sceneEditControlsService;
- @Autowired
- private ISceneEditInfoExtService sceneEditInfoExtService;
- @Autowired
- private RedisUtil redisUtil;
- @Autowired
- private IMqSendLogService mqSendLogService;
- @Autowired
- private RabbitMqProducer rabbitMqProducer;
- @Autowired
- private ISceneInfoSyncMqConfigService sceneInfoSyncMqConfigService;
- @Override
- public void uploadBuildResultData(String num, String dataSource, String version) {
- Map<String, String> uploadMap = new HashMap<>();
- String ossResultPath = String.format(UploadFilePath.scene_result_data_path, num);
- //删除旧的文件目录
- fYunFileServiceInterface.deleteFolder(ossResultPath);
- //上传caches/images
- String localCachesImagePath = dataSource + "/caches/images/";
- String ossCachesImagePath = ossResultPath + "caches/images/";
- //先清除旧的全景图
- if(FileUtil.exist(localCachesImagePath)){
- fYunFileServiceInterface.uploadFileByCommand(localCachesImagePath, ossCachesImagePath);
- }
- //上传project.json
- String localProjectJsonPath = dataSource + "/project.json";
- String ossProjectJsonPath = ossResultPath + "project.json";
- if(FileUtil.exist(localProjectJsonPath)){
- uploadMap.put(localProjectJsonPath, ossProjectJsonPath);
- }
- //上传data.json
- String localDataJsonPath = dataSource + "/data.json";
- String ossDataJsonPath = ossResultPath + "data.json";
- if(FileUtil.exist(localDataJsonPath)){
- uploadMap.put(localDataJsonPath, ossDataJsonPath);
- }
- //户型图上传
- String floorplanCadPath = ossResultPath + "floorplan_cad";
- String cadPicPathFormat = floorplanCadPath + "/floor-cad-%s.%s";
- String floorCadPath = dataSource + "/results/floorplan_cad";
- //清除原有旧的cad图
- fYunFileServiceInterface.deleteFolder(floorplanCadPath);
- List<String> floorCadList = FileUtils.getFileList(floorCadPath);
- if(CollUtil.isNotEmpty(floorCadList)){
- floorCadList.stream().forEach(str->{
- String substring = str.substring(str.lastIndexOf(File.separator) + 1);
- String[] arr = substring.split("floor");
- String[] arr2 = arr[1].split("\\.");
- //上传到用户编辑目录
- uploadMap.put(str, String.format(cadPicPathFormat, arr2[0], arr2[1]));
- });
- }
- //上传深时场景生成obj需要的文件
- String localReconstruction = dataSource + "/caches/reconstruction/";
- String ossReconstruction = ossResultPath + "caches/reconstruction/";
- if(FileUtil.exist(localReconstruction)){
- fYunFileServiceInterface.uploadFileByCommand(localReconstruction, ossReconstruction);
- }
- String localDepthmap = dataSource + "/caches/depthmap/";
- String ossDepthmap = ossResultPath + "caches/depthmap/";
- if(FileUtil.exist(localDepthmap)){
- fYunFileServiceInterface.uploadFileByCommand(localDepthmap, ossDepthmap);
- }
- String localDepthmapAsc = dataSource + "/caches/depthmap_csc/";
- String ossDepthmapAsc = ossResultPath + "caches/depthmap_csc/";
- if(FileUtil.exist(localDepthmapAsc)){
- fYunFileServiceInterface.uploadFileByCommand(localDepthmapAsc, ossDepthmapAsc);
- }
- String localPanoramaJson = dataSource + "/caches/panorama.json";
- String ossPanoramaJson = ossResultPath + "caches/panorama.json";
- if(FileUtil.exist(localPanoramaJson)){
- fYunFileServiceInterface.uploadFile(localPanoramaJson, ossPanoramaJson);
- }
- // String localLaserPly = dataSource + "/results/laserData/laser.ply";
- // String ossLaserPly = ossResultPath + "results/laserData/laser.ply";
- // if(FileUtil.exist(localLaserPly)){
- // fYunFileServiceInterface.uploadFile(localLaserPly, ossLaserPly);
- // }
- String localFloorGroupFixJson = dataSource + "/caches/floor_group_fix.json";
- String ossFloorGroupFixJson = ossResultPath + "caches/floor_group_fix.json";
- if(FileUtil.exist(localFloorGroupFixJson)){
- fYunFileServiceInterface.uploadFile(localFloorGroupFixJson, ossFloorGroupFixJson);
- }
- String localDepthmapVis = dataSource + "/caches/depthmap_vis";
- String ossDepthmapVis = ossResultPath + "caches/depthmap_vis";
- if(FileUtil.exist(localDepthmapVis)){
- fYunFileServiceInterface.uploadFileByCommand(localDepthmapVis, ossDepthmapVis);
- }
- String localIntensity = dataSource + "/caches/intensity";
- String ossIntensity = ossResultPath + "caches/intensity";
- if(FileUtil.exist(localIntensity)){
- fYunFileServiceInterface.uploadFileByCommand(localIntensity, ossIntensity);
- }
- //上传点位校准相关文件
- String localExtras = dataSource + "/extras";
- String ossExtras = ossResultPath + "extras";
- if(FileUtil.exist(localExtras)){
- fYunFileServiceInterface.uploadFileByCommand(localExtras, ossExtras);
- }
- //开始上传
- fYunFileServiceInterface.uploadMulFiles(uploadMap);
- }
- @Override
- public void uploadFloorplanJson(String num, String dataSource) throws Exception{
- String floorPlanCardFilePath = dataSource + File.separator + "results/floorplan_cad.json";
- if (!new File(floorPlanCardFilePath).exists()) {
- log.warn("floorplan_cad.json 文件不存在,文件路径:{}", floorPlanCardFilePath);
- return;
- }
- JSONObject json = FloorPlanUserUtil.createFloorPlanUserJson(floorPlanCardFilePath);
- if(Objects.isNull(json)){
- log.warn("生成floorplan.json失败,cadPath:{}", floorPlanCardFilePath);
- return;
- }
- String floorplanJsonPath = String.format(UploadFilePath.DATA_VIEW_PATH, num) + "floorplan.json";
- fYunFileServiceInterface.uploadFile(json.toJSONString().getBytes(), floorplanJsonPath);
- }
- @Override
- public void initUserEditData(String num, Set<String> bizs, Map<String, Map<String ,Object>> params) throws Exception {
- if(StrUtil.isEmpty(num) || CollUtil.isEmpty(bizs)){
- return;
- }
- for (String biz : bizs) {
- UserEditDataHandler handler = UserEditDataHandlerFactory.getHandler(biz);
- handler.init(num, CollUtil.isEmpty(params) ? null : params.get(biz));
- }
- }
- @Override
- public void sendEmail(String num, String type) {
- try {
- Long userId = null;
- String websize = "";
- String title = "";
- Integer sceneSource = null;
- ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
- if(Objects.isNull(scenePlus)){
- ScenePro scenePro = sceneProService.getByNum(num);
- if(Objects.isNull(scenePro)){
- return;
- }
- userId = scenePro.getUserId();
- websize = scenePro.getWebSite();
- title = scenePro.getSceneName();
- sceneSource = scenePro.getSceneSource();
- }else{
- userId = scenePlus.getUserId();
- ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
- websize = scenePlusExt.getWebSite();
- title = scenePlus.getTitle();
- sceneSource = scenePlus.getSceneSource();
- }
- if(Objects.isNull(userId)){
- return;
- }
- User user = userService.getById(userId);
- if(Objects.isNull(user) || StrUtil.isEmpty(user.getUserName())){
- return;
- }
- String toEmail = user.getUserName();
- String helpLink = helpLinkEn;
- String lang = "en";
- if("gn".equals(env)){
- lang = "zh";
- helpLink = helpLinkZh;
- }
- websize += "&lang=" + lang;
- if(("standar".equals(type))
- && (sceneSource == SceneSource.JG.code() || sceneSource == SceneSource.SG.code())){
- websize = String.format(laserUrl, num, lang);
- }
- MailTemplate mailTemplate = mailTemplateService.getOne(new LambdaQueryWrapper<MailTemplate>().eq(MailTemplate::getRemark, "计算完成").eq(MailTemplate::getLang, lang));
- String content = mailTemplate.getMsg().replaceAll("scene_name", title).replaceAll("scene_link", websize).replaceAll("help_link", helpLink);
- SendMailAcceUtils.sendMail(mailTemplate.getSendMail(), mailTemplate.getSendPassword(), mailTemplate.getSendHost(), toEmail, mailTemplate.getSubject(), content, null);
- }catch (Exception e){
- log.error("发送邮件失败,num:" + num, e);
- }
- }
- public static void main(String[] args) throws GeneralSecurityException {
- String content = "<p>Dear Valued Customer, </p>\n" +
- "<p> </p>\n" +
- "<p>The scene \"scene_name\" has been successfully calculated, please review the following: <a href=\"scene_link\" target=\"_blank\" rel=\"noopener\">scene_link</a> </p>\n" +
- "<p> </p>\n" +
- "<p>If you need to edit the scene, the User Manual can provide instructions: <a href=\"help_link\" target=\"_blank\" rel=\"noopener\">help_link</a> </p>\n" +
- "<p> </p>\n" +
- "<p>Sincerely, </p>\n" +
- "<p>4Dage Support Team</p>\n" +
- "<p> </p>\n" +
- "<p>------------------</p>\n" +
- "<p><img src=\"http://4dkk.4dage.com/ucenter/image/4dkankan_en.png\" /></p>\n" +
- "<p><br /><strong><em>Web:</em></strong><a href=\"http://eur.4dkankan.com/\" target=\"_blank\" rel=\"noopener\">eur.4dkankan.com</a></p>";
- SendMailAcceUtils.sendMail("4Dkankan@4dage.com", "6996790AAaa", "smtp.exmail.qq.com", "qinyongcheng@cgaii.com", "The Scene Calculation is Now Complete.", content, null);
- }
- public String getOssOrignPath(String path) {
- String ossPath = ConstantFilePath.OSS_PREFIX
- + path.replace(ConstantFilePath.BUILD_MODEL_PATH, "")
- .replace(ConstantFilePath.BUILD_MODEL_LASER_PATH, "");
- if (!ossPath.endsWith("/")) {
- ossPath = ossPath.concat("/");
- }
- return ossPath;
- }
- @Override
- public int getPayStatus(Long cameraId, Long space){
- //查询权益统计容量的方式
- String unit = SpaceType.GB.code();
- CameraDetail cameraDetail = cameraDetailService.getByCameraId(cameraId);
- if(StrUtil.isNotEmpty(cameraDetail.getUnit())){
- unit = cameraDetail.getUnit();
- }
- Long limit = this.getSpaceLimit(cameraDetail);
- if(SpaceType.SP.code().equals(unit)){//如果按空间方式统计,则space置为1
- space = 1L;
- }
- //更新相机使用用量,非激光相机或者是空间个数计算方式的,需要叠加相机容量
- cameraDetailService.updateCameraDetailByCameraIdAndSpace(cameraId, space);
- //无限容量或者激光相机,直接返回已支付
- if(limit == -1 || ("gn".equals(env) && CollUtil.isNotEmpty(laserCamTypeList) && laserCamTypeList.contains(cameraDetail.getType()))){
- return PayStatus.PAY.code();
- }
- Long usedSpace = cameraService.getUsedSpace(cameraId, unit);
- if(usedSpace + space > limit){
- return PayStatus.NO_CAPACITY.code();
- }
- return PayStatus.PAY.code();
- }
- @Override
- public void uploadStatusJson(String num, Integer sceneStatus, String webSite, String thumb, Integer payStatus, String uploadPath) {
- String localDataPath = String.format(ConstantFilePath.DATABUFFER_FORMAT, num);
- JSONObject statusJson = new JSONObject();
- statusJson.put("status", sceneStatus);
- statusJson.put("webSite", webSite);
- statusJson.put("sceneNum", num);
- statusJson.put("thumb", thumb);
- statusJson.put("payStatus", PayStatus.NOT_PAY.code());
- statusJson.put("recStatus", 'A');
- FileUtils.writeFile(localDataPath + "status.json", statusJson.toString());
- fYunFileServiceInterface.uploadFile(localDataPath + "status.json", uploadPath + "status.json");
- }
- @Override
- public Long getSpaceLimit(CameraDetail cameraDetail){
- Long limit = cameraDetail.getTotalSpace();
- UserIncrement userIncrement = userIncrementService.getByCameraId(cameraDetail.getCameraId());
- if(Objects.nonNull(userIncrement) && userIncrement.getIsExpired() == CommonStatus.NO.code().intValue()){
- IncrementType incrementType = incrementTypeService.getById(userIncrement.getIncrementTypeId());
- switch (SpaceType.get(cameraDetail.getUnit())){
- case GB:
- limit = incrementType.getCameraCapacity();
- if(limit != -1){
- limit = limit * 1024 * 1024 * 1024;
- }
- break;
- case SP:
- limit = incrementType.getCameraSpace();
- break;
- }
- }
- return limit;
- }
- @Override
- public Long getSpace(String num){
- Long space = fYunFileServiceInterface.getSpace(fYunFileConfig.getBucket(), String.format(UploadFilePath.DATA_VIEW_PATH, num));
- space += fYunFileServiceInterface.getSpace(fYunFileConfig.getBucket(), String.format(UploadFilePath.IMG_VIEW_PATH, num));
- space += fYunFileServiceInterface.getSpace(fYunFileConfig.getBucket(), String.format(UploadFilePath.VIDEOS_VIEW_PATH, num));
- space += fYunFileServiceInterface.getSpace(fYunFileConfig.getBucket(), String.format(UploadFilePath.VOICE_VIEW_PATH, num));
- space += fYunFileServiceInterface.getSpace(fYunFileConfig.getBucket(), String.format(UploadFilePath.scene_result_data_path, num).concat("caches"));
- return space;
- }
- public Object[] updateEditInfo(ScenePlus scenePlus){
- SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
- SceneEditControls sceneEditControls = null;
- SceneEditInfoExt sceneEditInfoExt = null;
- if(sceneEditInfo == null){
- sceneEditInfo = new SceneEditInfo();
- sceneEditInfo.setScenePlusId(scenePlus.getId());
- sceneEditInfo.setDescription(scenePlus.getDescription());
- sceneEditInfo.setTitle(scenePlus.getTitle());
- sceneEditInfoService.save(sceneEditInfo);
- }else{
- int version = 0;
- int imgVersion = 0;
- int linkVersion = 0;
- //获取展示页的版本号
- String sceneJsonStr = fYunFileServiceInterface.getFileContent(String.format(UploadFilePath.DATA_VIEW_PATH, scenePlus.getNum()) + "scene.json");
- if(StrUtil.isNotEmpty(sceneJsonStr)){
- JSONObject sceneJson = JSON.parseObject(sceneJsonStr);
- version = sceneJson.getIntValue("version");
- imgVersion = sceneJson.getIntValue("imgVersion");
- linkVersion = sceneJson.getIntValue("linkVersion");
- }
- if(version < sceneEditInfo.getVersion()){
- version = sceneEditInfo.getVersion();
- }
- if(imgVersion < sceneEditInfo.getImgVersion()){
- imgVersion = sceneEditInfo.getImgVersion();
- }
- if(linkVersion < sceneEditInfo.getLinkVersion()){
- linkVersion = sceneEditInfo.getLinkVersion();
- }
- sceneEditControls = sceneEditControlsService.getBySceneEditId(sceneEditInfo.getId());
- sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfo.getId());
- sceneEditInfo.setVersion(version + 1);
- sceneEditInfo.setImgVersion(imgVersion + 1);
- sceneEditInfo.setLinkVersion(linkVersion + 1);
- sceneEditInfo.setIsUploadObj(CommonStatus.NO.code());
- sceneEditInfoService.updateById(sceneEditInfo);
- }
- if(sceneEditControls == null){
- sceneEditControls = new SceneEditControls();
- sceneEditControls.setEditInfoId(sceneEditInfo.getId());
- sceneEditControlsService.save(sceneEditControls);
- }
- if(sceneEditInfoExt == null){
- sceneEditInfoExt = new SceneEditInfoExt();
- sceneEditInfoExt.setScenePlusId(scenePlus.getId());
- sceneEditInfoExt.setEditInfoId(sceneEditInfo.getId());
- sceneEditInfoExtService.save(sceneEditInfoExt);
- }
- return new Object[]{sceneEditInfo, sceneEditInfoExt, sceneEditControls};
- }
- public void writeSceneJson(String num, SceneEditInfo sceneEditInfo, SceneEditInfoExt sceneEditInfoExt,
- SceneEditControls sceneEditControls, ScenePlus scenePlus, ScenePlusExt scenePlusExt,Company company){
- String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
- String oldSceneJson = fYunFileServiceInterface.getFileContent(dataViewPath + "scene.json");
- SceneJsonBean sceneJson = new SceneJsonBean();
- BeanUtil.copyProperties(sceneEditInfoExt, sceneJson, "started");
- BeanUtil.copyProperties(sceneEditInfo, sceneJson);
- SceneEditControlsVO sceneEditControlsVO = BeanUtil.copyProperties(sceneEditControls, SceneEditControlsVO.class);
- sceneJson.setControls(sceneEditControlsVO);
- sceneJson.setNum(num);
- sceneJson.setCreateTime(scenePlus.getCreateTime());
- sceneJson.setSceneResolution(scenePlusExt.getSceneResolution());
- sceneJson.setVersion(sceneEditInfo.getVersion());
- sceneJson.setImgVersion(sceneEditInfo.getImgVersion());
- sceneJson.setSceneFrom(scenePlusExt.getSceneFrom());
- sceneJson.setSceneKind(scenePlusExt.getSceneKind());
- sceneJson.setModelKind(scenePlusExt.getModelKind());
- sceneJson.setVideos(scenePlusExt.getVideos());
- sceneJson.setPayStatus(scenePlus.getPayStatus());
- if(StrUtil.isNotEmpty(oldSceneJson)){
- SceneJsonBean oldSceneJsonBean = JSON.parseObject(oldSceneJson, SceneJsonBean.class);
- List<JSONObject> mosaicList = JSON.parseObject(oldSceneJson, SceneJsonBean.class).getMosaicList();
- sceneJson.setMosaicList(mosaicList);
- sceneJson.setFloorLogo(oldSceneJsonBean.getFloorLogo());
- sceneJson.setFloorLogoFile(oldSceneJsonBean.getFloorLogoFile());
- sceneJson.setBoxModels(oldSceneJsonBean.getBoxModels());
- sceneJson.setBoxVideos(oldSceneJsonBean.getBoxVideos());
- sceneJson.setBoxPhotos(oldSceneJsonBean.getBoxPhotos());
- }
- if(StrUtil.isNotEmpty(sceneEditInfoExt.getStarted())){
- sceneJson.setStarted(JSON.parseObject(sceneEditInfoExt.getStarted()));
- }
- if(!ObjectUtils.isEmpty(company)){
- String userViewPath = String.format(UploadFilePath.USER_VIEW_PATH, num);
- String userEditPath = String.format(UploadFilePath.USER_EDIT_PATH, num);
- String localLogoPath = null;
- if (StrUtil.isNotEmpty(company.getTopLogo())) {
- localLogoPath = ConstantFilePath.AGENT_PATH + company.getTopLogo().substring(company.getTopLogo().lastIndexOf("//") + 1);
- HttpUtil.downloadFile(company.getTopLogo(), localLogoPath);
- fYunFileServiceInterface.uploadFile(localLogoPath, userViewPath + "loadingLogo-user.png");
- fYunFileServiceInterface.uploadFile(localLogoPath, userEditPath + "loadingLogo-user.png");
- sceneJson.setLoadingLogo("user");
- sceneJson.setLoadingLogoFile("loadingLogo-user.png");
- sceneEditInfo.setLoadingLogo("user");
- sceneEditInfo.setLoadingLogoFile("loadingLogo-user.png");
- }
- if (StrUtil.isNotEmpty(company.getFloorLogo())) {
- localLogoPath = ConstantFilePath.AGENT_PATH + company.getFloorLogo().substring(company.getFloorLogo().lastIndexOf("//") + 1);
- HttpUtil.downloadFile(company.getFloorLogo(), localLogoPath);
- fYunFileServiceInterface.uploadFile(localLogoPath, userViewPath + "floorLogo-user.png");
- fYunFileServiceInterface.uploadFile(localLogoPath, userEditPath + "floorLogo-user.png");
- sceneJson.setFloorLogo("user");
- sceneJson.setFloorLogoFile("floorLogo-user.png");
- sceneEditInfo.setFloorLogo("user");
- sceneEditInfo.setFloorLogoFile("floorLogo-user.png");
- }
- if(!ObjectUtils.isEmpty(localLogoPath)){
- sceneEditInfoService.updateById(sceneEditInfo);
- FileUtils.deleteFile(localLogoPath);
- }
- }
- String sceneJsonStr = JSON.toJSONString(sceneJson);
- //上传sceneJson文件
- fYunFileServiceInterface.uploadFile(sceneJsonStr.getBytes(), dataViewPath + "scene.json");
- //scenejson写入缓存
- redisUtil.set(String.format(RedisKey.SCENE_JSON, num), sceneJsonStr);
- }
- @Override
- public void saveMqSendLog(String num, BuildSceneCallMessage message) {
- MqSendLog mqSendLog = new MqSendLog();
- mqSendLog.setNum(num);
- mqSendLog.setContent(JSON.toJSONString(message));
- mqSendLogService.save(mqSendLog);
- }
- @Override
- public void sendUpdateSceneStatusMqToQueues(Map<String, Object> content) {
- List<SceneInfoSyncMqConfig> configs = sceneInfoSyncMqConfigService.listByInfoType("update_scene_status");
- if(CollUtil.isEmpty(configs)){
- return;
- }
- for (SceneInfoSyncMqConfig config : configs) {
- rabbitMqProducer.sendByWorkQueue(config.getQueueName(), content);
- }
- }
- @Override
- public void removeSceneAsynOperLog(String num) {
- List<SceneAsynOperLog> list = sceneAsynOperLogService.list(new LambdaQueryWrapper<SceneAsynOperLog>().eq(SceneAsynOperLog::getNum, num));
- if(CollUtil.isEmpty(list)){
- return;
- }
- //删除数据库记录
- List<Long> deleteIdList = list.parallelStream().map(item -> item.getId()).collect(Collectors.toList());
- sceneAsynOperLogService.removeByIds(deleteIdList);
- list.parallelStream().forEach(item -> {
- if(StrUtil.isNotEmpty(item.getUrl())){
- try {
- fYunFileServiceInterface.deleteFile(item.getUrl());
- } catch (IOException e) {
- log.warn("删除oss全景图下载压缩包失败,key:{}", item.getUrl());
- }
- }
- });
- }
- public JSONObject getVideosJson(String path, Integer videoVersion, String projectNum, int cameraType){
- //读取videos_hdr_param.json, 保存点位视频的value
- Map<String, Object> videoMap = new HashMap<>();
- String videosHdr = FileUtils.readFile(path + File.separator + "results/videos/videos_hdr_param.json");
- JSONArray videoArray = null;
- if(StringUtils.isNotEmpty(videosHdr)){
- videoArray = JSONObject.parseObject(videosHdr).getJSONArray("hdr_param");
- }
- if(videoArray != null){
- for(int i = 0, len = videoArray.size(); i < len; i++) {
- videoMap.put(videoArray.getJSONObject(i).getString("name"), videoArray.getJSONObject(i).getString("value"));
- if(videoArray.getJSONObject(i).containsKey("fov")){
- videoMap.put(videoArray.getJSONObject(i).getString("name") + "_fov", videoArray.getJSONObject(i).getString("fov"));
- }
- }
- }
- //获取upload中的video视频名称
- String uploadData = FileUtils.readFile(path + File.separator + "results" +File.separator+"upload.json");
- JSONObject uploadJson = null;
- JSONArray array = null;
- if(uploadData!=null) {
- uploadJson = JSONObject.parseObject(uploadData);
- array = uploadJson.getJSONArray("upload");
- }
- JSONObject fileJson = null;
- String fileName = "";
- //计算ts文件的大小,并拼接成json格式
- JSONArray jsonArray = new JSONArray();
- JSONObject videoJson = null;
- JSONObject videosJson = new JSONObject();
- long videoSize = 0L;
- for(int i = 0, len = array.size(); i < len; i++) {
- fileJson = array.getJSONObject(i);
- fileName = fileJson.getString("file");
- if(fileJson.getIntValue("clazz") == 11 && fileName.contains(".mp4") && !fileName.contains("-ios.mp4")){
- videoJson = new JSONObject();
- videoJson.put("id", fileName.substring(
- 0, fileName.lastIndexOf(".")).replace("videos/", ""));
- //如果ts文件存在,就计算ts大小
- if(new File(path + File.separator + "results" +File.separator+ fileName.replace(".mp4", ".ts")).exists()){
- videoSize = new File(path + File.separator + "results" +File.separator+ fileName.replace(".mp4", ".ts")).length();
- videoJson.put("tsSize", videoSize);
- }
- if(videoMap.containsKey(videoJson.get("id"))){
- videoJson.put("value", videoMap.get(videoJson.get("id")));
- }
- if(videoMap.containsKey(videoJson.get("id") + "_fov")){
- videoJson.put("blend_fov", videoMap.get(videoJson.get("id") + "_fov"));
- }else {
- videoJson.put("blend_fov", 7);
- }
- jsonArray.add(videoJson);
- }
- }
- videosJson.put("data", jsonArray);
- if(Objects.nonNull(videoVersion) && videoVersion >= 4){
- videosJson.put("version", 3);
- videosJson.put("upPath", fYunFileConfig.getHost() + String.format(UploadFilePath.DATA_VIEW_PATH, projectNum) + "Up.xml");
- if(cameraType == 13 || cameraType == 14){
- //转台相机
- videosJson.put("upPath", videosJson.getString("upPath").replace(".xml", ".txt"));
- }
- }else {
- videosJson.put("version", 1);
- videosJson.put("upPath", fYunFileConfig.getHost() + String.format(UploadFilePath.DATA_VIEW_PATH, projectNum) + "Up2.xml");
- if(cameraType == 13 || cameraType == 14){
- //转台相机
- videosJson.put("upPath", videosJson.getString("upPath").replace(".xml", ".txt"));
- }
- }
- if(cameraType == 5 || cameraType == 6){
- videosJson.put("version", 1);
- videosJson.put("upPath", fYunFileConfig.getHost() + String.format(UploadFilePath.DATA_VIEW_PATH, projectNum) + "stitch_params.txt");
- }
- return videosJson;
- }
- @Override
- public JSONObject getFdageData(String dataFdagePath) {
- log.info("dataFdagePath 文件路径 :{}", dataFdagePath);
- String data = FileUtils.readFile(dataFdagePath);
- //获取data.fdage的内容
- JSONObject dataJson = new JSONObject();
- if(data!=null){
- dataJson = JSONObject.parseObject(data);
- }
- return dataJson;
- }
- @Override
- public Map<String, String> getUploadFiles(ScenePlus scenePlus,String path,Integer cameraType,JSONObject fdageData) throws Exception {
- if (ObjectUtils.isEmpty(scenePlus)) {
- throw new Exception("未找到场景信息:" + path);
- }
- String projectNum = scenePlus.getNum();
- String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, projectNum);
- String imagesPath = String.format(UploadFilePath.IMG_VIEW_PATH, projectNum);
- String videoPath = String.format(UploadFilePath.VIDEOS_VIEW_PATH, projectNum);
- String resultsPath = path + File.separator + "results" + File.separator;
- String uploadData = FileUtils.readFile(resultsPath + "upload.json");
- JSONArray array = JSONObject.parseObject(uploadData).getJSONArray("upload");
- JSONObject fileJson = null;
- String fileName = "";
- Map<String, String> map = new HashMap();
- for (int i = 0; i < array.size(); ++i) {
- fileJson = array.getJSONObject(i);
- fileName = fileJson.getString("file");
- String filePath = resultsPath + fileName;
- if (!(new File(filePath)).exists()) {
- throw new Exception(filePath + "文件不存在");
- }
- if ("vision2.txt".equals(fileName)) {
- CreateObjUtil.convertTxtToVisionmodeldata(resultsPath + "vision2.txt", resultsPath + "vision2.modeldata");
- map.put(resultsPath + "vision2.modeldata", imagesPath + "vision2.modeldata");
- map.put(resultsPath + "vision2.txt", imagesPath + "vision2.txt");
- }
- if (fileJson.getIntValue("clazz") == 2) {
- map.put(filePath, imagesPath + ConstantFileName.modelUUID + "_50k_texture_jpg_high1/" + fileName.replace("tex/", ""));
- } else if (fileJson.getIntValue("clazz") == 3) {
- map.put(filePath, imagesPath + "pan/high/" + fileName.replace("high/", ""));
- } else if (fileJson.getIntValue("clazz") == 4) {
- map.put(filePath, imagesPath + "pan/low/" + fileName.replace("low/", ""));
- } else if (fileJson.getIntValue("clazz") == 5) {
- map.put(filePath, imagesPath + fileName);
- } else if (fileJson.getIntValue("clazz") == 7) {
- map.put(filePath, imagesPath + fileName);
- } else if (fileJson.getIntValue("clazz") == 10) {
- String updown = FileUtils.readFile(filePath);
- JSONObject updownJson = JSONObject.parseObject(updown);
- String mappingOssPath = String.format("scene_edit_data/%s/data/", projectNum) + fileName.replace("updown", "mapping");
- map.put(filePath, mappingOssPath);
- } else {
- if (fileJson.getIntValue("clazz") == 11 || fileJson.getIntValue("clazz") == 12) {
- map.put(filePath, videoPath + fileName.replace("videos/", ""));
- if (fileName.contains(".mp4")) {
- map.put(resultsPath + fileName.replace("mp4", "flv"), videoPath + fileName.replace("videos/", "").replace("mp4", "flv"));
- }
- }
- if (fileJson.getIntValue("clazz") == 16) {
- map.put(filePath, dataViewPath + fileName);
- }
- if (fileJson.getIntValue("clazz") == 18) {
- map.put(filePath, imagesPath + fileName);
- }
- }
- }
- //exportMeshObj这个是字段由app写入的
- boolean genModel = true;//是否生成模型 默认生成,深时场景要根据 exportMeshObj判断是否生成
- if(!ObjectUtils.isEmpty(cameraType)
- && cameraType == 14
- && (!fdageData.containsKey("exportMeshObj") || fdageData.getIntValue("exportMeshObj") != 1)){
- genModel = false;
- }
- boolean gen3dTiles = true;//是否生成3dtiles模型 默认生成
- if(!ModelKind.THREE_D_TILE.code().equals(modelKind)
- || CollUtil.isEmpty(sdTilesSceneSourceList)
- || !sdTilesSceneSourceList.contains(scenePlus.getSceneSource())){
- gen3dTiles = false;
- }
- if(genModel){
- if (!gen3dTiles) {
- String damPath = path + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam";
- CreateObjUtil.convertTxtToDam(path + File.separator + "results" + File.separator + "tex" + File.separator + "modeldata.txt", damPath);
- FileUtil.writeBytes(ZipUtil.gzip(new File(damPath)), damPath);
- map.put(damPath, imagesPath + ConstantFileName.modelUUID + "_50k.dam");
- }else{
- List<String> list = FileUtils.list(new File(path + File.separator + "results" + File.separator + ModelKind.THREE_D_TILE.code()));
- if(CollUtil.isEmpty(list)){
- log.error("3dtiles目录异常,3dtiles地址:{}", new File(path + File.separator + "results" + File.separator + ModelKind.THREE_D_TILE.code()));
- throw new Exception("3dtiles目录异常");
- }
- list.stream().forEach(str->{
- map.put(str, str.replace(path + File.separator + "results" + File.separator, imagesPath));
- });
- }
- }
- CreateObjUtil.convertTxtToVisionmodeldata(resultsPath + "vision.txt", resultsPath + "vision.modeldata");
- map.put(resultsPath + "vision.txt", imagesPath + "vision.txt");
- map.put(resultsPath + "vision.modeldata", imagesPath + "vision.modeldata");
- log.info("数据转换完成:" + projectNum);
- if(!new File("/mnt/4Dkankan/scene/data" + File.separator + "data" + projectNum).exists()){
- FileUtil.mkdir("/mnt/4Dkankan/scene/data" + File.separator + "data" + projectNum);
- }
- // map.put(resultsPath + "floorplan.json", dataViewPath + "floor.json");
- map.put(resultsPath + "floorplan_cad.json", dataViewPath + "floorplan_cad.json");
- map.put(path + File.separator + "capture/stitch_params.txt", dataViewPath + "stitch_params.txt");
- map.put(path + File.separator + "capture/Up.xml", dataViewPath + "Up.xml");
- map.put(path + File.separator + "capture/Up2.xml", dataViewPath + "Up2.xml");
- map.put(path + File.separator + "capture/Up.txt", dataViewPath + "Up.txt");
- map.put(path + File.separator + "capture/Up2.txt", dataViewPath + "Up2.txt");
- return map;
- }
- }
|