123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407 |
- package com.fdkankan.openApi.service.www.impl;
- import cn.hutool.core.bean.BeanUtil;
- import cn.hutool.core.collection.CollUtil;
- 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.dynamic.datasource.annotation.DS;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.fdkankan.common.constant.*;
- import com.fdkankan.common.exception.BusinessException;
- import com.fdkankan.common.util.DateUtil;
- import com.fdkankan.common.util.FileUtils;
- import com.fdkankan.fyun.config.FYunFileConfig;
- import com.fdkankan.fyun.face.FYunFileServiceInterface;
- import com.fdkankan.model.constants.ConstantFilePath;
- import com.fdkankan.model.constants.UploadFilePath;
- import com.fdkankan.model.utils.ComputerUtil;
- import com.fdkankan.model.utils.CreateObjUtil;
- import com.fdkankan.openApi.bean.www.SceneJsonBean;
- import com.fdkankan.openApi.common.PageInfo;
- import com.fdkankan.openApi.entity.laser.SceneEntity;
- import com.fdkankan.openApi.entity.www.*;
- import com.fdkankan.openApi.mapper.www.IScenePlusMapper;
- import com.fdkankan.openApi.service.laser.FilterService;
- import com.fdkankan.openApi.service.laser.SceneService;
- import com.fdkankan.openApi.service.www.*;
- import com.fdkankan.openApi.vo.www.CreateFicTitiousSceneParamVO;
- import com.fdkankan.openApi.vo.www.PageScenesParamVo;
- import com.fdkankan.openApi.vo.www.SceneEditControlsVO;
- import com.fdkankan.openApi.vo.www.SceneVO;
- import com.fdkankan.redis.constant.RedisKey;
- import com.fdkankan.redis.util.RedisUtil;
- import com.fdkankan.web.response.ResultData;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Service;
- import org.springframework.util.ObjectUtils;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * <p>
- * 场景主表 服务实现类
- * </p>
- *
- * @author
- * @since 2023-02-15
- */
- @DS("www")
- @Service
- public class ScenePlusServiceImpl extends ServiceImpl<IScenePlusMapper, ScenePlus> implements IScenePlusService {
- @Value("${main.url}")
- private String mainUrl;
- @Value("${scene.pro.new.url}")
- private String sceneUrl;
- @Autowired
- private FYunFileServiceInterface fYunFileService;
- @Autowired
- private ISceneEditInfoService sceneEditInfoService;
- @Autowired
- private IScenePlusExtService scenePlusExtService;
- @Autowired
- private ISceneEditInfoExtService sceneEditInfoExtService;
- @Autowired
- private ISceneEditControlsService sceneEditControlsService;
- @Autowired
- private RedisUtil redisUtil;
- @Autowired
- private ICameraService cameraService;
- @Autowired
- private FYunFileConfig fYunFileConfig;
- @Autowired
- private FilterService filterService;
- @Autowired
- private SceneService sceneService;
- @Override
- public ScenePlus getByNumAndUserId(long userId, String num) {
- return this.getOne(new LambdaQueryWrapper<ScenePlus>().eq(ScenePlus::getNum, num).eq(ScenePlus::getUserId, userId));
- }
- @Override
- public ScenePlus getByNum(String num) {
- return this.getOne(new LambdaQueryWrapper<ScenePlus>().eq(ScenePlus::getNum, num));
- }
- @Override
- public ResultData createVirtualScene(CreateFicTitiousSceneParamVO param) throws Exception {
- this.checkParams4createVirtualScene(param);
- this.buildScene4CreateVirtualScene(param);
- String website = this.updateScene4CreateVirtualScene(param);
- return ResultData.ok(website);
- }
- private void checkParams4createVirtualScene(CreateFicTitiousSceneParamVO param){
- SceneFrom sceneFrom = SceneFrom.get(param.getSceneFrom());
- if(Objects.isNull(sceneFrom)){
- throw new BusinessException(ErrorCode.PARAM_ERROR.code(), "sceneFrom错误");
- }
- Integer sceneSource = null;
- switch (sceneFrom){
- case SXZ:
- sceneSource = SceneSource.YJHZ.code();
- break;
- }
- if(Objects.isNull(sceneSource)){
- throw new BusinessException(ErrorCode.PARAM_ERROR.code(), "sceneFrom错误");
- }
- param.setSceneSource(sceneSource);
- }
- private void buildScene4CreateVirtualScene(CreateFicTitiousSceneParamVO param) throws Exception {
- String num = param.getNum();
- String objName = param.getObjName();
- String mtlName = param.getMtlName();
- String localImagePath = String.format(ConstantFilePath.SCENE_IMAGES_PATH_V4, num);
- String ossImagePath = String.format(UploadFilePath.IMG_VIEW_PATH, num);
- String ossObjPath = ossImagePath + objName;
- if(!fYunFileService.fileExist(ossObjPath)){
- throw new BusinessException(ErrorCode.FAILURE_CODE_4001, objName);
- }
- String ossMtlPath = ossImagePath + mtlName;
- if(!fYunFileService.fileExist(ossMtlPath)){
- throw new BusinessException(ErrorCode.FAILURE_CODE_4001, mtlName);
- }
- String ossTexturePath = ossImagePath + "dacf7dfa24ae47fab8fcebfe4dc41ab9_50k_texture_jpg_high1/";
- // if(CollUtil.isEmpty(fYunFileService.listRemoteFiles(ossTexturePath))){
- // throw new BusinessException(ErrorCode.FAILURE_CODE_4001, "贴图");
- // }
- String ossVisionTxtPath = ossImagePath + "vision.txt";
- if(!fYunFileService.fileExist(ossVisionTxtPath)){
- throw new BusinessException(ErrorCode.FAILURE_CODE_4001, "vision.txt");
- }
- FileUtil.del(localImagePath + "/result/");
- FileUtil.del(localImagePath + "extras/");
- fYunFileService.downloadFile(ossObjPath, localImagePath + "extras/" + "mesh.obj");
- fYunFileService.downloadFile(ossMtlPath, localImagePath + "extras/" + mtlName);
- fYunFileService.downloadFileByCommand(localImagePath + "extras/", ossTexturePath);
- fYunFileService.downloadFile(ossVisionTxtPath, localImagePath + "vision.txt");
- //创建data.json
- JSONObject dataJson = new JSONObject();
- dataJson.put("obj2txt", true);
- dataJson.put("split_type", "SPLIT_V6");
- dataJson.put("data_describe", "double spherical");
- dataJson.put("skybox_type", "SKYBOX_V5");
- FileUtil.writeUtf8String(dataJson.toJSONString(), localImagePath + "data.json");
- //调用objToTxt算法
- CreateObjUtil.build3dModel(localImagePath, "");
- Thread.sleep(2000);
- String uploadJsonPath = localImagePath + "results/upload.json";
- boolean exist = ComputerUtil.checkComputeCompleted(uploadJsonPath, 3, 3000);
- if(!exist){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5042);
- }
- String uploadData = FileUtils.readFile(uploadJsonPath);
- JSONObject uploadJson = null;
- JSONArray array = null;
- if(uploadData!=null) {
- uploadJson = JSONObject.parseObject(uploadData);
- array = uploadJson.getJSONArray("upload");
- }
- if(array == null){
- log.error("upload.json数据出错");
- throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
- }
- Map<String,String> map = new HashMap<String,String>();
- JSONObject fileJson = null;
- String fileName = "";
- for(int i = 0, len = array.size(); i < len; i++) {
- fileJson = array.getJSONObject(i);
- fileName = fileJson.getString("file");
- String filePath = localImagePath + "results/" + fileName;
- //文件不存在抛出异常
- if(!FileUtil.exist(filePath)){
- throw new BusinessException(ErrorCode.FAILURE_CODE_4002, filePath);
- }
- //tex文件夹
- if (fileJson.getIntValue("clazz") == 15) {
- map.put(filePath, ossImagePath + "dacf7dfa24ae47fab8fcebfe4dc41ab9_50k_texture_jpg_high1/" + fileName.replace("tex/", ""));
- continue;
- }
- }
- CreateObjUtil.convertTxtToDam(localImagePath + "results/" + "modeldata.txt", localImagePath + "results/" + "dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam");
- // CreateObjUtil.convertDamToLzma(imagesBuffer.toString() + File.separator + "results" +File.separator+ "dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam");
- // CreateObjUtil.convertTxtToDam(imagesBuffer.toString() + File.separator + "results" +File.separator+"modeldata.txt", imagesBuffer.toString() + File.separator + "results" + File.separator+ "dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam");
- // map.put(imagesBuffer.toString() + File.separator + "results" +File.separator+"dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam.lzma", "images/images"+param.getNum()+"/"+"dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam.lzma");
- map.put(localImagePath + "results/" + "dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam", ossImagePath + "dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam");
- FileUtils.deleteFile(localImagePath + "vision.modeldata");
- CreateObjUtil.convertTxtToVisionmodeldata(localImagePath + "vision.txt", localImagePath + "vision.modeldata");
- map.put(localImagePath + "vision.modeldata", ossImagePath + "vision.modeldata");
- fYunFileService.uploadMulFiles(map);
- }
- private String updateScene4CreateVirtualScene(CreateFicTitiousSceneParamVO param){
- ScenePlus scenePlus = this.getByNum(param.getNum());
- ScenePlusExt scenePlusExt = null;
- SceneEditInfo sceneEditInfo = null;
- SceneEditInfoExt sceneEditInfoExt = null;
- SceneEditControls sceneEditControls = null;
- if(Objects.nonNull(scenePlus)){
- scenePlusExt = scenePlusExtService.getByPlusId(scenePlus.getId());
- sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
- sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfo.getId());
- sceneEditControls = sceneEditControlsService.getByEditInfoId(sceneEditInfo.getId());
- }else {
- scenePlus = new ScenePlus();
- scenePlusExt = new ScenePlusExt();
- sceneEditInfo = new SceneEditInfo();
- sceneEditInfoExt = new SceneEditInfoExt();
- sceneEditControls = new SceneEditControls();
- }
- scenePlus.setNum(param.getNum());
- scenePlus.setUserId(param.getUserId());
- scenePlus.setTitle("四维看看");
- scenePlus.setDescription("<p>四维看看 让空间讲故事</p>");
- scenePlus.setSceneStatus(SceneStatus.SUCCESS.code());
- scenePlus.setPayStatus(PayStatus.PAY.code());
- scenePlus.setSceneSource(param.getSceneSource());
- this.saveOrUpdate(scenePlus);
- scenePlus = this.getByNum(param.getNum());
- scenePlusExt.setPlusId(scenePlus.getId());
- scenePlusExt.setWebSite(mainUrl + "/" + sceneUrl + param.getNum());
- scenePlusExt.setBuildType("V3");
- scenePlusExt.setSceneResolution(param.getSceneResolution());
- scenePlusExt.setSceneFrom(param.getSceneFrom());
- scenePlusExt.setSceneKind(param.getSceneKind());
- scenePlusExt.setModelKind(ModelKind.DAM.code());
- scenePlusExtService.saveOrUpdate(scenePlusExt);
- scenePlusExt = scenePlusExtService.getByPlusId(scenePlus.getId());
- sceneEditInfo.setScenePlusId(scenePlus.getId());
- sceneEditInfo.setVersion(Objects.isNull(sceneEditInfo.getVersion()) ? 0 : sceneEditInfo.getVersion() + 1);
- sceneEditInfo.setImgVersion(Objects.isNull(sceneEditInfo.getImgVersion()) ? 0 : sceneEditInfo.getImgVersion() + 1);
- sceneEditInfo.setTitle(scenePlus.getTitle());
- sceneEditInfo.setDescription(scenePlus.getDescription());
- sceneEditInfoService.saveOrUpdate(sceneEditInfo);
- sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
- sceneEditInfoExt.setEditInfoId(sceneEditInfo.getId());
- sceneEditInfoExt.setScenePlusId(scenePlus.getId());
- sceneEditInfoExtService.saveOrUpdate(sceneEditInfoExt);
- sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfo.getId());
- sceneEditControls.setEditInfoId(sceneEditInfo.getId());
- sceneEditControlsService.saveOrUpdate(sceneEditControls);
- sceneEditControls = sceneEditControlsService.getByEditInfoId(sceneEditInfo.getId());
- SceneJsonBean sceneJson = new SceneJsonBean();
- BeanUtil.copyProperties(sceneEditInfoExt, sceneJson);
- BeanUtil.copyProperties(sceneEditInfo, sceneJson);
- SceneEditControlsVO sceneEditControlsVO = BeanUtil.copyProperties(sceneEditControls, SceneEditControlsVO.class);
- sceneJson.setControls(sceneEditControlsVO);
- sceneJson.setNum(param.getNum());
- 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.setPayStatus(scenePlus.getPayStatus());
- String sceneJsonStr = JSON.toJSONString(sceneJson);
- //上传sceneJson文件
- fYunFileService.uploadFile(sceneJsonStr.getBytes(), String.format(UploadFilePath.DATA_VIEW_PATH, param.getNum()) + "scene.json");
- //scenejson写入缓存
- redisUtil.set(String.format(RedisKey.SCENE_JSON, param.getNum()), sceneJsonStr);
- return scenePlusExt.getWebSite();
- }
- @Override
- public PageInfo<SceneVO> getScenesByUserId(Long userId, PageScenesParamVo param) {
- LambdaQueryWrapper<ScenePlus> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(ScenePlus::getUserId,userId);
- if (!ObjectUtils.isEmpty(param.getCameraType())) {
- switch (param.getCameraType()){
- case "mega":
- queryWrapper.eq(ScenePlus::getSceneSource, 4);
- break;
- case "kankan":
- queryWrapper.ne(ScenePlus::getSceneSource, 4);
- break;
- }
- }
- Page<ScenePlus> scenePage = this.page(new Page<>(param.getPageNum(), param.getPageSize()), queryWrapper);
- if(CollUtil.isEmpty(scenePage.getRecords())){
- return PageInfo.PageInfo(scenePage);
- }
- List<Long> plusIdList = new ArrayList<>();
- List<String> megaSceneNumList = new ArrayList<>();
- Set<Long> cameraIds = new HashSet<>();
- scenePage.getRecords().stream().forEach(plus -> {
- plusIdList.add(plus.getId());
- if(plus.getSceneSource() == SceneSource.JG.code()){
- megaSceneNumList.add(plus.getNum());
- }
- if(Objects.nonNull(plus.getCameraId())){
- cameraIds.add(plus.getCameraId());
- }
- });
- Map<Long, String> cameraMap = new HashMap<>();
- if(CollUtil.isNotEmpty(cameraIds)){
- cameraMap = cameraService
- .list(new LambdaQueryWrapper<Camera>().in(Camera::getId, cameraIds))
- .stream().collect(Collectors.toMap(Camera::getId, Camera::getSnCode));
- }
- List<ScenePlusExt> scenePlusExtList = scenePlusExtService.list(new LambdaQueryWrapper<ScenePlusExt>().in(ScenePlusExt::getPlusId, plusIdList));
- Map<Long, ScenePlusExt> plusExtMap = new HashMap<>();
- scenePlusExtList.stream().forEach(ext->plusExtMap.put(ext.getPlusId(), ext));
- List<SceneEntity> megaSceneList = null;
- Map<String, SceneEntity> megaSceneMap = new HashMap<>();
- if(CollUtil.isNotEmpty(megaSceneNumList)){
- megaSceneList = sceneService.list(new LambdaQueryWrapper<SceneEntity>().in(SceneEntity::getSceneCode, megaSceneNumList));
- if(CollUtil.isNotEmpty(megaSceneList)){
- megaSceneList.stream().forEach(scene -> megaSceneMap.put(scene.getSceneCode(), scene));
- }
- }
- Map<Long, String> finalCameraMap = cameraMap;
- List<SceneVO> sceneVos = scenePage.getRecords().stream().map(scenePlus -> {
- SceneVO vo = new SceneVO();
- vo.setSceneCode(scenePlus.getNum());
- vo.setSceneName(scenePlus.getTitle());
- vo.setCreateTime(DateUtil.date2String(scenePlus.getCreateTime(), null));
- ScenePlusExt plusExt = plusExtMap.get(scenePlus.getId());
- if(Objects.nonNull(plusExt)){
- vo.setShootCount(plusExt.getShootCount());
- }
- vo.setSnCode(finalCameraMap.get(scenePlus.getCameraId()));
- vo.setCameraType("kankan");
- if (scenePlus.getSceneSource() == 4) {
- SceneEntity scene = megaSceneMap.get(scenePlus.getNum());
- if (Objects.nonNull(scene) && StrUtil.isNotEmpty(scene.getTitle())) {
- vo.setSceneName(scene.getTitle());
- }
- vo.setCameraType("mega");
- }
- return vo;
- }).collect(Collectors.toList());
- return PageInfo.PageInfo(scenePage.getCurrent(), scenePage.getSize(), scenePage.getTotal(), sceneVos);
- }
- @Override
- public Object getPointInfo(String sceneCode) {
- // 获取vision.txt 文件内容返回
- String content = fYunFileService.getFileContent(String.format(UploadFilePath.IMG_VIEW_PATH, sceneCode).concat("vision.txt"));
- JSONObject jsonObject = JSONObject.parseObject(content);
- return jsonObject.get("sweepLocations");
- }
- @Override
- public List<String> getSceneObjFilePaths(String sceneCode) {
- List<String> objFiles = fYunFileService.listRemoteFiles(String.format(UploadFilePath.DATA_VIEW_PATH, sceneCode).concat("mesh"))
- .stream().map(file -> fYunFileConfig.getHost() + file).collect(Collectors.toList());
- return objFiles;
- }
- @Override
- public List<String> getScenePanoramicImageFiles(String sceneCode) {
- // 根据vision.txt 获取全景图文件
- String content = fYunFileService.getFileContent(String.format(UploadFilePath.IMG_VIEW_PATH, sceneCode).concat("vision.txt"));
- JSONObject jsonObject = JSONObject.parseObject(content);
- return jsonObject.getJSONArray("sweepLocations").stream()
- .map(json -> String.format(fYunFileConfig.getHost()
- + UploadFilePath.scene_result_data_path, sceneCode).concat("caches/images/")
- + ((JSONObject) json).getString("uuid").concat(".jpg")).collect(Collectors.toList());
- }
- }
|