package com.fdkankan.scene.service.impl; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.fdkankan.common.config.FileRouteConfig; import com.fdkankan.common.constant.*; import com.fdkankan.common.exception.BusinessException; import com.fdkankan.common.response.ResultData; import com.fdkankan.common.util.*; import com.fdkankan.platform.api.feign.client.PlatformClient; import com.fdkankan.scene.entity.*; import com.fdkankan.scene.mapper.ISceneFileBuildMapper; import com.fdkankan.scene.service.*; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.fdkankan.scene.vo.ResponseSceneFile; import lombok.extern.slf4j.Slf4j; import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.time.LocalDate; import java.util.*; /** *

* 场景文件建模表 服务实现类 *

* * @author dengsixing * @since 2021-12-23 */ @Slf4j @Service public class SceneFileBuildServiceImpl extends ServiceImpl implements ISceneFileBuildService { private static final String SPLICE = "#"; @Value("${main.url}") private String mainUrl; @Value("${scene.url}") private String sceneUrl; @Value("${scene.pro.url}") private String sceneProUrl; @Value("${scene.pro.new.url}") private String sceneProNewUrl; @Value("${oss.type}") private String type; @Value("${prefix.ali}") private String prefixAli; @Value("${ecs.type}") private String ecsType; @Autowired PlatformClient platformClient; @Autowired ISceneFileUploadService sceneFileUploadService; @Autowired RedisTemplate redisTemplate; @Autowired ISceneProService sceneProService; @Autowired private FileRouteConfig routeConfig; @Autowired UploadToOssUtil uploadToOssUtil; @Autowired ISceneProEditService sceneProEditService; @Autowired ISceneProEditExtService sceneProEditExtService; @Autowired IScene3dNumService scene3dNumService; @Override public SceneFileBuild findByFileId(String fileId) { List list = this.list(new QueryWrapper() .eq("tb_status", TbStatus.VALID.code()) .eq("rec_status", RecStatus.VALID.code()) .eq("file_id", fileId) .orderByDesc("id")); if(CollUtil.isEmpty(list)) return null; return list.get(0); } @Override public boolean uploadSuccess(String fileId, StringBuilder filePathBuffer) { SceneFileBuild sceneFileBuild = findByFileId(fileId); if (Objects.isNull(sceneFileBuild)) return false; Long uploadSuccessCount = sceneFileUploadService.countUploadSuccessByFileId(fileId); sceneFileBuild.setUploadStatus(UploadStatus.SUCCESS.code()); sceneFileBuild.setChunks(Integer.valueOf(uploadSuccessCount.toString())); sceneFileBuild.setUpdateTime(Calendar.getInstance().getTime()); this.updateById(sceneFileBuild); return true; } @Override public SceneFileBuild findByUnicode(String unicode) { List list = this.list(new QueryWrapper() .eq("tb_status", TbStatus.VALID.code()) .eq("rec_status", RecStatus.VALID.code()) .eq("unicode", unicode) .orderByDesc("id")); if(CollUtil.isEmpty(list)) return null; return list.get(0); } @Async @Override public void unzipSingleFile(String filePath) { log.info("文件路径:{}", filePath); File file = new File(filePath); if (file.exists()){ log.error(filePath + ":文件不存在"); throw new BusinessException(ErrorCode.FAILURE_CODE_5038); } String parentFilePath = file.getParentFile().getPath(); log.info("解压目标目录:{}", parentFilePath); StringBuffer exec = new StringBuffer(" tar xvf "); exec.append(filePath); exec.append(" -C ").append(parentFilePath).append(File.separator); System.out.println(exec.toString()); String[] cmdExec = new String[]{"/bin/sh", "-c", exec.toString()}; int code = executeLinuxShell(cmdExec); if (code == 0){ log.info("解压完成,文件路径:{}, 开始执行删除压缩文件", filePath); file.delete(); }else { log.error("解压失败,文件路径:{},解压状态:{}", filePath, code); } } private int executeLinuxShell(String[] command) { Process shellProcess = null; BufferedReader shellErrorResultReader = null; BufferedReader shellInfoResultReader = null; try { shellProcess = Runtime.getRuntime().exec(command); shellErrorResultReader = new BufferedReader(new InputStreamReader(shellProcess.getErrorStream())); shellInfoResultReader = new BufferedReader(new InputStreamReader(shellProcess.getInputStream())); String infoLine; while ((infoLine = shellInfoResultReader.readLine()) != null) { log.info("linux环境脚本执行信息:{}", infoLine); } String errorLine; while ((errorLine = shellErrorResultReader.readLine()) != null) { log.warn("linux环境脚本执行信息:{}", errorLine); } // 等待程序执行结束并输出状态 int exitCode = shellProcess.waitFor(); if (0 == exitCode) { log.info("linux环境脚本执行成功"); } else { log.error("linux环境脚本执行失败:" + exitCode); } return exitCode; } catch (Exception e) { log.error("linux环境shell脚本执行错误", e); return 1; } finally { if (null != shellInfoResultReader) { try { shellInfoResultReader.close(); } catch (IOException e) { log.error("linux环境脚本流文件关闭异常:", e); } } if (null != shellErrorResultReader) { try { shellErrorResultReader.close(); } catch (IOException e) { log.error("linux环境脚本流文件关闭异常:", e); } } if (null != shellProcess) { shellProcess.destroy(); } } } @Override public ResponseSceneFile preUpload(String params) throws Exception { log.info("preUpload-params: "+params); if (StrUtil.isEmpty(params)){ throw new BusinessException(ErrorCode.PARAM_REQUIRED); } params = params.replaceAll("%2B", "+"); Base64 base64 = new Base64(); String cipher = params; // 私钥解密过程 byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()), base64.decode(cipher)); String restr = new String(res, "UTF-8"); log.debug("preUpload-params解密结果:" + restr); String[] strArr = restr.split(SPLICE); if (strArr.length != 5) { throw new BusinessException(ErrorCode.PARAM_REQUIRED); } String mac = strArr[0]; String totalPicNum = strArr[1]; String chunks = strArr[2]; String folderName = strArr[3]; if (StrUtil.isEmpty(mac)){ throw new BusinessException(ErrorCode.FAILURE_CODE_5044); } if (totalPicNum == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5045); } if (chunks == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5046); } if (folderName == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5047); } log.info("mac:" + mac + "准备上传文件"); SceneProPO scenePro = sceneProService.getSceneStatusByUnicode("/" + folderName, "A"); if(scenePro != null && scenePro.getDataSource() != null){ int n = scenePro.getDataSource().split("/").length; if(n > 1){ String fileId = scenePro.getDataSource().split("/")[n - 2]; ResponseSceneFile responseSceneFile = new ResponseSceneFile(); responseSceneFile.setFileId(fileId); //可以重复上传,文件id保存50年(因为该redis工具无法设置永久保存) redisTemplate.opsForValue().set(fileId, folderName, 1537920000); return responseSceneFile; } }else { SceneFileBuild sceneFileBuild = this.findByUnicode(folderName); if(sceneFileBuild != null){ String fileId = sceneFileBuild.getFileId(); ResponseSceneFile responseSceneFile = new ResponseSceneFile(); responseSceneFile.setFileId(fileId); //可以重复上传,文件id保存50年(因为该redis工具无法设置永久保存) redisTemplate.opsForValue().set(fileId, folderName, 1537920000); return responseSceneFile; } } // 构造方法设置机器码:第0个机房的第0台机器 SnowflakeIdGenerator snowflakeIdGenerator = new SnowflakeIdGenerator(0, 0); long fileId = snowflakeIdGenerator.nextId(); SceneFileBuild sceneFileBuild = new SceneFileBuild(); sceneFileBuild.setChildName(mac); sceneFileBuild.setFileId(String.valueOf(fileId)); sceneFileBuild.setUnicode(folderName); sceneFileBuild.setUploadStatus(0); sceneFileBuild.setBuildStatus(0); sceneFileBuild.setTotalPicNum(Integer.valueOf(totalPicNum)); sceneFileBuild.setChunks(Integer.valueOf(chunks)); this.save(sceneFileBuild); ResponseSceneFile responseSceneFile = new ResponseSceneFile(); responseSceneFile.setFileId(String.valueOf(fileId)); //可以重复上传,文件id保存50年(因为该redis工具无法设置永久保存) redisTemplate.opsForValue().set(String.valueOf(fileId), folderName, 1537920000); return responseSceneFile; } @Override public ResponseSceneFile getProgress(String params) throws Exception { log.info("getProgress-params:{} ", params); if (StrUtil.isEmpty(params)){ throw new BusinessException(ErrorCode.PARAM_REQUIRED); } params = params.replaceAll("%2B", "+"); Base64 base64 = new Base64(); String cipher = params; // 私钥解密过程 byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()), base64.decode(cipher)); String restr = new String(res, "UTF-8"); log.debug("getProgress-params解密结果:{}" , restr); String[] strArr = restr.split(SPLICE); if (strArr.length != 3) { throw new BusinessException(ErrorCode.PARAM_REQUIRED); } String fileId = strArr[0]; String chunk = strArr[1]; chunk = chunk.split(SPLICE)[0]; SceneFileUpload sceneFileUpload = sceneFileUploadService.findByFileIdAndChunk(fileId, Integer.valueOf(chunk)); ResponseSceneFile responseSceneFile = new ResponseSceneFile(); responseSceneFile.setUploadStatus(sceneFileUpload != null ? sceneFileUpload.getUploadStatus() : -1); return responseSceneFile; } @Override public ResultData uploadFile(MultipartFile file, String params) throws Exception{ log.info("upload-params: "+params); if (StringUtils.isEmpty(params)){ throw new BusinessException(ErrorCode.PARAM_REQUIRED); } params = params.replaceAll("%2B", "+"); Base64 base64 = new Base64(); String cipher = params; // 私钥解密过程 byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()), base64.decode(cipher)); String restr = new String(res, "UTF-8"); log.debug("upload-params解密结果:{}", restr); String[] strArr = restr.split(SPLICE); if (strArr.length != 6) { throw new BusinessException(ErrorCode.PARAM_REQUIRED); } String mac = strArr[0]; String fileId = strArr[1]; String picNum = strArr[2]; String md5 = strArr[3]; String chunk = strArr[4]; ResultData result = null; if (file.isEmpty()){ throw new BusinessException(ErrorCode.FAILURE_CODE_5048); } if (StringUtils.isEmpty(fileId)){ throw new BusinessException(ErrorCode.FAILURE_CODE_5049); } if (picNum == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5050); } if (StringUtils.isEmpty(mac)){ throw new BusinessException(ErrorCode.FAILURE_CODE_5044); } if (StringUtils.isEmpty(md5)){ throw new BusinessException(ErrorCode.FAILURE_CODE_5051); } long size = file.getSize(); log.warn("fileId:"+fileId+"---picNum:"+picNum+"---size:"+size+"---md5:"+md5+"---mac:"+mac); chunk = chunk.split(SPLICE)[0]; // 获取文件名 String fileName = file.getOriginalFilename(); log.info("上传的文件名为:" + fileName); // 获取文件的后缀名 String suffixName = fileName.substring(fileName.lastIndexOf(".")); log.info("上传的后缀名为:" + suffixName); String folderName = (String) redisTemplate.opsForValue().get(fileId); if(StringUtils.isEmpty(folderName)){ SceneProPO scenePro = sceneProService.getSceneStatusByUnicode("/" + fileId + "/", "A"); if(scenePro != null){ folderName = scenePro.getDataSource().substring(scenePro.getDataSource().lastIndexOf("/") + 1); } } // 1. 判断该文件是否已经上传过 // 2. 如果已经上传过,判断MD5值和文件大小是否相等。如果相等,更新数据记录。如果不相等,删除该文件,重新上传。 // 3. 如果未上传过,需要上传。 StringBuffer filePathBuffer = new StringBuffer(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator).append("capture"); StringBuffer sb = new StringBuffer(routeConfig.getHardDisk()).append(filePathBuffer.toString()).append(File.separator).append(fileName); boolean needUpload = false; File dbFile = new File(sb.toString()); if (dbFile.exists()){ String fileMD5 = FileMd5Util.getFileMD5(dbFile); if (md5.equals(fileMD5) && dbFile.length() == size){ log.warn("文件已存在,MD5和文件大小一致。"); SceneFileUpload uploadEntity = sceneFileUploadService.findByFileIdAndChunk(fileId, Integer.valueOf(chunk)); if (uploadEntity != null){ uploadEntity.setSize((int) size); uploadEntity.setMd5(md5); uploadEntity.setFilePath(sb.toString()); uploadEntity.setFileSourceName(fileName); uploadEntity.setUploadStatus(1); sceneFileUploadService.updateById(uploadEntity); }else{ SceneFileUpload sceneFileUploadEntity = new SceneFileUpload(); sceneFileUploadEntity.setSize((int) size); sceneFileUploadEntity.setMd5(md5); sceneFileUploadEntity.setFilePath(sb.toString()); sceneFileUploadEntity.setFileSourceName(fileName); sceneFileUploadEntity.setUploadStatus(1); sceneFileUploadEntity.setFileId(fileId); sceneFileUploadEntity.setChunk(Integer.valueOf(chunk)); sceneFileUploadService.save(sceneFileUploadEntity); } result = ResultData.ok(); }else if (!md5.equals(fileMD5)) { log.warn("文件已上传,上传MD5:"+md5+",服务器MD5:"+fileMD5+"。不一致。上传失败"); FileUtil.delFile(sb.toString()); needUpload = true; }else if (dbFile.length() != size){ log.warn("文件已上传,文件大小不一致。上传失败"); FileUtil.delFile(sb.toString()); needUpload = true; } }else { log.warn("文件不存在,需要重新上传"); needUpload = true; } // 4. 上传成功后,校验MD5和文件大小是否相等 // 5. 如果相等,更新数据记录。如果不相等,返回上传失败结果。 try { if (needUpload){ String name = fileName.substring(0, fileName.lastIndexOf(".")); String filePath = this.saveFile(file, filePathBuffer.toString(), name); File uploadFile = new File(filePath); String fileMD5 = FileMd5Util.getFileMD5(uploadFile); SceneFileUpload sceneFileUploadEntity = new SceneFileUpload(); sceneFileUploadEntity.setSize((int) size); sceneFileUploadEntity.setMd5(md5); sceneFileUploadEntity.setFilePath(sb.toString()); sceneFileUploadEntity.setFileSourceName(fileName); sceneFileUploadEntity.setFileId(fileId); sceneFileUploadEntity.setChunk(Integer.valueOf(chunk)); if (md5.equals(fileMD5) && uploadFile.length() == size){ log.warn("文件已上传,MD5和文件大小一致。上传成功"); sceneFileUploadEntity.setUploadStatus(1); sceneFileUploadService.save(sceneFileUploadEntity); result = ResultData.ok(); }else if (!md5.equals(fileMD5)) { log.warn("文件已上传,上传MD5:"+md5+",服务器MD5:"+fileMD5+"。不一致。上传失败"); sceneFileUploadEntity.setUploadStatus(-1); sceneFileUploadService.save(sceneFileUploadEntity); result = ResultData.error(ErrorCode.FAILURE_CODE_5052); }else if (uploadFile.length() != size){ log.warn("文件已上传,文件大小不一致。上传失败"); sceneFileUploadEntity.setUploadStatus(-1); sceneFileUploadService.save(sceneFileUploadEntity); result = ResultData.error(ErrorCode.FAILURE_CODE_5052); } } }catch (IllegalStateException | IOException e) { log.error(ErrorCode.FAILURE_CODE_5052.message(), e); result = ResultData.error(ErrorCode.FAILURE_CODE_5052); } return result; } @Override public ResultData uploadSuccess(String params) throws Exception { log.info("uploadSuccess-params: " + params); if (StrUtil.isEmpty(params)) { throw new BusinessException(ErrorCode.PARAM_REQUIRED); } params = params.replaceAll("%2B", "+"); Base64 base64 = new Base64(); String cipher = params; // 私钥解密过程 byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()), base64.decode(cipher)); String restr = new String(res, "UTF-8"); log.debug("uploadSuccess-params解密结果:" + restr); String[] strArr = restr.split(SPLICE); if (strArr.length != 3) { throw new BusinessException(ErrorCode.PARAM_REQUIRED); } String mac = strArr[0]; String fileId = strArr[1]; String folderName = (String) redisTemplate.opsForValue().get(fileId); if(StringUtils.isEmpty(folderName)){ SceneProPO scenePro = sceneProService.getSceneStatusByUnicode("/" + fileId + "/", "A"); if(scenePro != null){ folderName = scenePro.getDataSource().substring(scenePro.getDataSource().lastIndexOf("/") + 1); } if(StringUtils.isEmpty(folderName)){ SceneFileBuild sceneFileBuild = this.findByFileId(fileId); if(sceneFileBuild != null){ folderName = sceneFileBuild.getUnicode(); } } } StringBuilder filePathBuffer = new StringBuilder(routeConfig.getHardDisk()).append(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator).append("capture").append(File.separator); boolean flag = this.uploadSuccess(fileId, filePathBuffer); if(flag){ //调用建模的方法 // TODO: 2021/12/31 // buildScene(filePathBuffer.toString(), fileId, false, null); } return ResultData.ok(); } @Override public ResultData uploadSuccessBuild(String params) throws Exception { log.info("uploadSuccessBuild-params: " + params); if (StringUtils.isEmpty(params)) { throw new BusinessException(ErrorCode.PARAM_REQUIRED); } params = params.replaceAll("%2B", "+"); Base64 base64 = new Base64(); String cipher = params; // 私钥解密过程 byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()), base64.decode(cipher)); String restr = new String(res, "UTF-8"); log.debug("uploadSuccessBuild-params解密结果:" + restr); String[] strArr = restr.split(SPLICE); if (strArr.length != 3) { throw new BusinessException(ErrorCode.PARAM_REQUIRED); } String mac = strArr[0]; String fileId = strArr[1]; String folderName = (String)redisTemplate.opsForValue().get(fileId); if(StringUtils.isEmpty(folderName)){ SceneProPO sceneProPO = sceneProService.getSceneStatusByUnicode("/" + fileId + "/", "A"); if(sceneProPO != null){ folderName = sceneProPO.getDataSource().substring(sceneProPO.getDataSource().lastIndexOf("/") + 1); } if(StringUtils.isEmpty(folderName)){ SceneFileBuild sceneFileBuild = this.findByFileId(fileId); if(sceneFileBuild != null){ folderName = sceneFileBuild.getUnicode(); } } } StringBuilder filePathBuffer = new StringBuilder(routeConfig.getHardDisk()).append(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator).append("capture").append(File.separator); StringBuilder prefixBuffer = new StringBuilder(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator); File filePath = new File(filePathBuffer.toString()); if(!filePath.exists()){ filePath.mkdirs(); } if("s3".equals(type)){ CreateObjUtil.ossFileCp(ConstantFilePath.OSS_PREFIX + prefixBuffer.toString() + "data.fdage", filePathBuffer.toString() + "data.fdage"); }else { CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + prefixBuffer.toString() + "data.fdage", filePathBuffer.toString()); } // TODO: 2021/12/31 // buildScene(filePathBuffer.toString(), fileId, true, prefixBuffer.toString()); return ResultData.ok(); } @Override public ResultData turntableUploadSuccess(String params) throws Exception { log.info("uploadSuccessBuild-params: " + params); if (StringUtils.isEmpty(params)) { throw new BusinessException(ErrorCode.PARAM_REQUIRED); } params = params.replaceAll("%2B", "+"); Base64 base64 = new Base64(); String cipher = params; // 私钥解密过程 byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()), base64.decode(cipher)); String restr = new String(res, "UTF-8"); log.debug("uploadSuccessBuild-params解密结果:" + restr); String[] strArr = restr.split(SPLICE); if (strArr.length != 3) { throw new BusinessException(ErrorCode.PARAM_REQUIRED); } String mac = strArr[0]; String fileId = strArr[1]; String folderName = (String)redisTemplate.opsForValue().get(fileId); if(StringUtils.isEmpty(folderName)){ SceneProPO sceneProPO = sceneProService.getSceneStatusByUnicode("/" + fileId + "/", "A"); if(sceneProPO != null){ folderName = sceneProPO.getDataSource().substring(sceneProPO.getDataSource().lastIndexOf("/") + 1); } if(StringUtils.isEmpty(folderName)){ SceneFileBuild sceneFileBuild = this.findByFileId(fileId); if(sceneFileBuild != null){ folderName = sceneFileBuild.getUnicode(); } } } //判断 是否为激光相机 // TODO: 2021/12/31 调用跨服务接口 获取CameraEntity CameraDetailEntity // CameraEntity cameraEntity = goodsService.findByChildName(mac); // CameraDetailEntity cameraDetailEntity = goodsService.findCameraDetailByCameraId(cameraEntity.getId()); String hardDisk = routeConfig.getHardDisk(); // if(cameraDetailEntity!=null){ // if(cameraDetailEntity.getType() == 10){ // hardDisk = routeConfig.getHardDiskLaser(); // } // } // log.info("相机 mnt 路径 : " + hardDisk + ", 相机类型 : " + cameraDetailEntity.getType()); StringBuilder filePathBuffer = new StringBuilder(hardDisk).append(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator).append("capture").append(File.separator); StringBuilder prefixBuffer = new StringBuilder(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator); File filePath = new File(filePathBuffer.toString()); if(!filePath.exists()){ filePath.mkdirs(); } if("s3".equals(type)){ CreateObjUtil.ossFileCp(ConstantFilePath.OSS_PREFIX + prefixBuffer.toString() + "data.fdage", filePathBuffer.toString() + "data.fdage"); }else { CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + prefixBuffer.toString() + "data.fdage", filePathBuffer.toString()); } // TODO: 2021/12/31 // turntableBuildScene(filePathBuffer.toString(), fileId, true, prefixBuffer.toString()); return ResultData.ok(); } @Override public ResultData getS3UploadUrl(String params) throws Exception { if (StringUtils.isEmpty(params)) { throw new BusinessException(ErrorCode.PARAM_REQUIRED); } JSONObject jsonObject = JSON.parseObject(params); if(jsonObject == null){ throw new BusinessException(ErrorCode.PARAM_FORMAT_ERROR); } JSONArray files = jsonObject.getJSONArray("Files"); if(files == null){ throw new BusinessException(ErrorCode.PARAM_FORMAT_ERROR); } List urls = new ArrayList<>(); for(int i = 0, len = files.size(); i < len; i++){ urls.add(files.getJSONObject(i).getString("filename")); } return ResultData.ok(uploadToOssUtil.getUploadS3Url(urls)); } @Override public ResultData buildLiteScene(String prefix, String dataFdage, String zipName, String userName, String password, String oldNum) throws Exception{ log.info("参数-prefix: {}, dataFdage: {}, zipName: {}, password: {}, userName: {}", prefix, dataFdage, zipName, password, userName); if(StringUtils.isEmpty(prefix) || StringUtils.isEmpty(dataFdage) || StringUtils.isEmpty(zipName) || StringUtils.isEmpty(userName) || StringUtils.isEmpty(password)){ throw new BusinessException(ErrorCode.FAILURE_CODE_3001); } // TODO: 2021/12/31 feign // CameraEntity cameraEntity = goodsService.findByChildName(userName); // if(cameraEntity == null){ // // TODO: 2021/12/31 feign // cameraEntity = goodsService.findBySnCode(userName); // } // if (cameraEntity == null){ // throw new BusinessException(CameraConstant.FAILURE_6003); // } // if(!password.equals(cameraEntity.getChildPassword())){ // throw new BusinessException(ErrorCode.FAILURE_CODE_3014); // } // // String unicode = prefix.substring(prefix.lastIndexOf("/") + 1); // String path = ConstantFilePath.BUILD_MODEL_PATH + unicode; // // //下载data.fdage // FileUtils.downLoadFromUrl(prefix + "/" + dataFdage + "?m=" + System.currentTimeMillis(), dataFdage, path + File.separator + "capture"); // String data = FileUtils.readFile(path + File.separator + "capture/" + dataFdage); // JSONObject jsonObject = JSONObject.parseObject(data); // if(jsonObject == null){ // log.info("data.fdage不存在"); // throw new BusinessException(CameraConstant.FAILURE_6009); // } // // String sceneNum = ""; // //查看场景中的文件目录是否有改文件id,有则重新计算改场景,无则新建场景 // SceneProPO sceneProPO = sceneProService.findByFileId("/" + unicode); // int rebuild = 1; // if(StrUtil.isNotEmpty(oldNum)){ // sceneNum = oldNum; // }else { // // if(sceneProPO != null){ // sceneNum = sceneProPO.getSceneCode(); // //重算的场景,先移除该场景对应的容量 // userService.rebuildReduceSpaceBySceneNum(sceneNum); // }else { // sceneNum = sceneNumService.generateSceneNum(); // rebuild = 0; // } // } // // String cameraName = jsonObject.getJSONObject("cam").getString("uuid"); // log.info("查询相机:" + cameraName); // // TODO: 2021/12/31 feign // cameraEntity = goodsService.findByChildName(cameraName); // // if(cameraEntity == null){ // log.error("该相机不存在:" + cameraName); // //偶现data.fdage给的相机码多了或少了4DKKPRO_ // if(cameraName.contains("4DKKPRO_")){ // cameraEntity = goodsService.findByChildName(cameraName.replace("4DKKPRO_", "")); // }else { // cameraEntity = goodsService.findByChildName("4DKKPRO_" + cameraName); // } // if(cameraEntity == null){ // throw new BusinessException(CameraConstant.FAILURE_6003); // } // } // // CameraDetailEntity detailEntity = goodsService.findCameraDetailByCameraId(cameraEntity.getId()); // if(detailEntity == null){ // log.error("该相机详情不存在:" + cameraName); // throw new BusinessException(CameraConstant.FAILURE_6003); // } // // String icon = null; // if(jsonObject.containsKey("icon") && StrUtil.isNotEmpty(jsonObject.getString("icon"))){ // //下载封面图icon // FileUtils.downLoadFromUrl(prefix + "/" + jsonObject.getString("icon") + "?m=" + System.currentTimeMillis(), jsonObject.getString("icon"), path + File.separator + "capture"); // uploadToOssUtil.upload(path + File.separator + "capture" + File.separator + // jsonObject.getString("icon"), "images/images" + sceneNum + "/" + jsonObject.getString("icon")); // icon = prefixAli + "images/images" + sceneNum + "/" + jsonObject.getString("icon"); // if("s3".equals(type)){ // icon = ConstantUrl.PREFIX_AWS + "images/images" + sceneNum + "/" + jsonObject.getString("icon"); // } // } // // JSONObject firmwareVersion = new JSONObject(); // if(jsonObject.containsKey("camSoftwareVersion") && StrUtil.isNotEmpty(jsonObject.getString("camSoftwareVersion"))){ // firmwareVersion.put("camSoftwareVersion", jsonObject.getString("camSoftwareVersion")); // } // // if(jsonObject.containsKey("version") && StrUtil.isNotEmpty(jsonObject.getString("version"))){ // firmwareVersion.put("version", jsonObject.getString("version")); // } // // String sceneUrl = mainUrl + sceneProNewUrl; // String buildType = "V3"; // //表示新款双目 // Long cameraType = 5L; // if(jsonObject.getJSONObject("cam").getIntValue("type") == 5){ // // //6表示小红屋双目 // cameraType = 6L; // } // // SceneProEntity scene = ComputerUtil.createScenePro(sceneNum, cameraEntity.getId(), cameraEntity.getChildName(), jsonObject.getString("creator"), // jsonObject.getString("pwd"), unicode, // cameraType, "", prefix, zipName, icon, "0", detailEntity.getUserId(), userName, // jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam", // jsonObject.getJSONArray("points").size(), jsonObject.getString("name"), jsonObject.getString("info"), // jsonObject.getInteger("scenetype"), jsonObject.getString("gps"), sceneProService, sceneProEditService, rebuild, // producer, 4, firmwareVersion.toString(), sceneUrl, buildType, type, ecsType, // sceneCooperationService, sceneResourceCooperationService, sceneResourceCameraService, detailEntity.getCooperationUser(), rubberSheetingUtil); // // if(scene == null){ // log.info("双目相机入库失败"); // return Result.failure("双目相机异常"); // } // JSONObject statusJson = new JSONObject(); // //临时将-2改成1,app还没完全更新 // statusJson.put("status", scene.getStatus() == -2? 1 : scene.getStatus()); // statusJson.put("webSite", scene.getWebSite()); // statusJson.put("sceneNum", scene.getNum()); // statusJson.put("thumb", scene.getThumb()); // statusJson.put("payStatus", scene.getPayStatus()); // FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"status.json", statusJson.toString()); // uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"status.json", // "data/data"+sceneNum+File.separator+"status.json"); // // //删除oss的houst_floor.json // uploadToOssUtil.delete("data/data"+sceneNum+File.separator+"houst_floor.json"); // // producer.sendMsg(scene.getMqMsg()); // // Map map = new HashMap<>(); // map.put("sceneNum", sceneNum); // map.put("sceneUrl", sceneUrl + sceneNum); // return ResultData.ok(map); return null; } @Override public ResultData buildScene(String prefix, String unicode, String zip, String dataFdage) throws Exception{ String data = FileUtils.readFile(ConstantFilePath.BUILD_MODEL_PATH + unicode + "/data.fdage"); JSONObject jsonObject = JSONObject.parseObject(data); // TODO: 2021/12/31 String sceneNum = null; // sceneNumService.generateSceneNum(); return ResultData.ok(mainUrl + sceneProNewUrl + sceneNum); } // public void turntableBuildScene(String filePath, String fileId, boolean fromOss, String prefix) throws Exception{ // String data = FileUtils.readFile(filePath + "data.fdage"); // JSONObject jsonObject = JSONObject.parseObject(data); // // //调用createScene方法生成scene数据和加入算法队列 // if(jsonObject == null) { // log.info("data.fdage文件不存在"); // throw new BusinessException(CameraConstant.FAILURE_6009); // } // // String sceneNum = ""; // // String snCode = jsonObject.getJSONObject("cam").getString("uuid"); // String unicode = jsonObject.getString("creator") + "_" + jsonObject.getString("uuidtime"); //从data.fage 取出 //// sceneProService.updateRecStatus(unicode); // //查看场景中的文件目录是否有改文件id,有则重新计算改场景,无则新建场景 // SceneProPO sceneProPO = sceneProService.findByFileId("/" + fileId + "/"); // int rebuild = 1; // if(sceneProPO != null){ // sceneNum = sceneProPO.getSceneCode(); // if(sceneProPO.getSceneStatus() == SceneStatus.wait.code()){ // log.info(sceneNum + ":场景处于计算中,不能再计算"); // return; // } // }else { // sceneNum = sceneNumService.generateSceneNum(); // rebuild = 0; // } // // if(sceneNum == null){ // log.error("大场景序号为空:" + sceneNum); // throw new BusinessException(ErrorCode.FAILURE_CODE_5005); // } // // log.info("查询相机:" + snCode); // // TODO: 2021/12/31 调用feign //// CameraEntity cameraEntity = goodsService.findByChildName(snCode); // // if(cameraEntity == null){ // log.error("该相机不存在:" + snCode); // cameraEntity = goodsService.findBySnCode(snCode); // if(cameraEntity == null){ // throw new BusinessException(CameraConstant.FAILURE_6003); // } // } // // // TODO: 2021/12/31 调用feign // CameraDetailEntity detailEntity = goodsService.findCameraDetailByCameraId(cameraEntity.getId()); // if(detailEntity == null){ // log.error("该相机详情不存在:" + snCode); // throw new BaseRuntimeException(CameraConstant.FAILURE_CODE_6003, CameraConstant.FAILURE_MSG_6003); // } // // String userName = null; // if(detailEntity.getUserId() != null){ // Result result = userService.findById(detailEntity.getUserId()); // SSOUser user = mapper.convertValue(result.getData(), SSOUser.class); // if(user != null){ // userName = user.getUserName(); // } // } // // String icon = null; // if(jsonObject.containsKey("icon") && StringUtil.isNotEmpty(jsonObject.getString("icon"))){ // CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + prefix + jsonObject.getString("icon"), filePath); // icon = prefixAli + "images/images" + sceneNum + "/" + jsonObject.getString("icon"); // if("s3".equals(type)){ // CreateObjUtil.ossFileCp(ConstantFilePath.OSS_PREFIX + prefix + jsonObject.getString("icon"), filePath + jsonObject.getString("icon")); // icon = ConstantUrl.PREFIX_AWS + "images/images" + sceneNum + "/" + jsonObject.getString("icon"); // } // uploadToOssUtil.upload(filePath + jsonObject.getString("icon"), "images/images" + sceneNum + "/" + jsonObject.getString("icon")); // } // // JSONObject firmwareVersion = new JSONObject(); // if(jsonObject.containsKey("camSoftwareVersion") && StringUtil.isNotEmpty(jsonObject.getString("camSoftwareVersion"))){ // firmwareVersion.put("camSoftwareVersion", jsonObject.getString("camSoftwareVersion")); // } // // if(jsonObject.containsKey("version") && StrUtil.isNotEmpty(jsonObject.getString("version"))){ // firmwareVersion.put("version", jsonObject.getString("version")); // } // // String sceneUrl = mainUrl + sceneProNewUrl; // String buildType = "V3"; // //13表示转台 // Long cameraType = 13L; // // //激光转台 八目相机占用 10 和 11 // if(jsonObject.getJSONObject("cam").getIntValue("type") == 10){ // //激光转台 // cameraType = 14L; // } // // // //重算的场景,先移除该场景对应的容量 // if(rebuild == 1){ // userService.rebuildReduceSpaceBySceneNum(sceneNum); // }else { // //上传log-main.png // uploadToOssUtil.upload(ConstantFilePath.LOGO_PATH + "logo-main.png", "images/images" + sceneNum + "/logo-main.png"); // uploadToOssUtil.upload(ConstantFilePath.LOGO_PATH + "logo-main-en.png", "images/images" + sceneNum + "/logo-main-en.png"); // } // SceneProEntity scene = null; // scene = ComputerUtil.createScenePro(sceneNum, cameraEntity.getId(), cameraEntity.getChildName(), jsonObject.getString("creator"), // jsonObject.getString("pwd"), unicode, // cameraType, String.valueOf(fileId), prefix, "", icon, "0", detailEntity.getUserId(), userName, // jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam", // jsonObject.getJSONArray("points").size(), jsonObject.getString("name"), jsonObject.getString("info"), // jsonObject.getInteger("scenetype"), jsonObject.getString("gps"), sceneProService, sceneProEditService, rebuild, // producer, jsonObject.getInteger("resolution"), firmwareVersion.toString(), sceneUrl, buildType, type, ecsType, // sceneCooperationService, sceneResourceCooperationService, sceneResourceCameraService, detailEntity.getCooperationUser(), rubberSheetingUtil); // // if(scene != null){ // JSONObject statusJson = new JSONObject(); // //临时将-2改成1,app还没完全更新 // statusJson.put("status", scene.getStatus() == -2? 1 : scene.getStatus()); // statusJson.put("webSite", scene.getWebSite()); // statusJson.put("sceneNum", scene.getNum()); // statusJson.put("thumb", scene.getThumb()); // statusJson.put("payStatus", scene.getPayStatus()); // statusJson.put("recStatus", scene.getRecStatus()); // FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"status.json", statusJson.toString()); // uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"status.json", // "data/data"+sceneNum+File.separator+"status.json"); // } // // if(detailEntity.getCompanyId() != null){ // CompanyEntity companyEntity = companyService.findById(detailEntity.getCompanyId()); // if(companyEntity != null){ // // Map jsonMap = new HashMap<>(); // // log.info("复制企业logo"); // SceneProEditEntity sceneProEditEntity = sceneProEditService.findByProId(scene.getId()); // // if(StringUtil.isNotEmpty(companyEntity.getTopLogo())){ // // FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + companyEntity.getTopLogo(), // ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/logo-main.png", true); // uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/logo-main.png", // "images/images" + sceneNum + "/logo-main.png"); // } // // if(StringUtil.isNotEmpty(companyEntity.getFloorLogo())){ // // FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + companyEntity.getFloorLogo(), // ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/floorLogoImg.png", true); // uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/floorLogoImg.png", // "images/images" + sceneNum + "/floorLogoImg.png"); // // sceneProEditEntity.setFloorLogo("user"); // jsonMap.put("floorLogoSize", sceneProEditEntity.getFloorLogoSize()); // jsonMap.put("floorLogo", "user"); // } // // if(StringUtil.isNotEmpty(companyEntity.getQrLogo())){ // // FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + companyEntity.getQrLogo(), // ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png", true); // uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png", // "images/images" + sceneNum + "/QRShareLogo.png"); // sceneProEditEntity.setShareLogo("images/images" + sceneNum + "/QRShareLogo.png"); // // //生成新的分享的二维码 // MatrixToImageWriterUtil.createQRCode(sceneUrl + sceneNum, ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneNum+".png", // ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png"); // MatrixToImageWriterUtil.createQRCode(sceneUrl + sceneNum + "&lang=en", ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneNum+"_en.png", // ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png"); // } // // if(StringUtil.isNotEmpty(companyEntity.getMarkerLogo())){ // // FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + companyEntity.getMarkerLogo(), // ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/marker.png", true); // uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/marker.png", // "images/images" + sceneNum + "/marker.png"); // // sceneProEditEntity.setMarkerLogo("user"); // jsonMap.put("markerLogo", "user"); // } // // sceneProEditEntity.setShowLogoBottom(companyEntity.getShowLogo()); // sceneProEditService.update(sceneProEditEntity); // // jsonMap.put("showLogoBottom", companyEntity.getShowLogo()); // FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + "/scene.json", jsonMap); // } // // //删除oss的houst_floor.json // uploadToOssUtil.delete("data/data"+sceneNum+File.separator+"houst_floor.json"); // // } // // //激光转台 八目相机占用 10 和 11 // if(jsonObject.getJSONObject("cam").getIntValue("type") == 10){ // // producer.sendMsgLaser(scene.getMqMsg()); // }else if(scene != null){ // producer.sendMsg(scene.getMqMsg()); // } // } public void buildScene(String filePath, String fileId, boolean fromOss, String prefix) throws Exception{ //获取解压后的资源的data.fdage中的数据 String data = FileUtils.readFile(filePath + "data.fdage"); JSONObject jsonObject = JSONObject.parseObject(data); //调用createScene方法生成scene数据和加入算法队列 // if(jsonObject != null){ // //有calibration值为标定,1: camera_calibration 2: color_anlysis,0正常计算 // if(jsonObject.get("calibration") != null && jsonObject.getString("calibration").equals("1")){ // String mac = filePath.replace(ConstantFilePath.BUILD_MODEL_PATH, "").split("/")[0]; // String calPath = ConstantFilePath.BUILD_MODEL_PATH + mac + "/camera_calibration"; // //生成标定数据 // ComputerUtil.createCalibrationData(calPath, filePath); // //开始标定计算 // producer.sendMsg(calPath); // // }else if(jsonObject.get("calibration") != null && jsonObject.getString("calibration").equals("2")){ // String mac = filePath.replace(ConstantFilePath.BUILD_MODEL_PATH, "").split("/")[0]; // String calPath = ConstantFilePath.BUILD_MODEL_PATH + mac + "/color_anlysis"; // //生成标定数据 // ComputerUtil.createCalibrationData(calPath, filePath); // //开始标定计算 // Map map = ComputerUtil.computerCalibration(calPath); // }else if(jsonObject.get("calibration") != null && jsonObject.getString("calibration").equals("3")){ // String mac = filePath.replace(ConstantFilePath.BUILD_MODEL_PATH, "").split("/")[0]; // String calPath = ConstantFilePath.BUILD_MODEL_PATH + mac + "/shading"; // //生成标定数据 // ComputerUtil.createCalibrationData(calPath, filePath); // //开始标定计算 // producer.sendMsg(calPath); // // }else { // // String sceneNum = ""; // // String cameraName = jsonObject.getJSONObject("cam").getString("uuid"); // String unicode = jsonObject.getString("creator") + "_" + jsonObject.getString("uuidtime"); // //查看场景中的文件目录是否有改文件id,有则重新计算改场景,无则新建场景 // SceneProPO proEntity = sceneProService.findByFileId("/" + fileId + "/"); // int rebuild = 1; // if(proEntity != null){ // sceneNum = proEntity.getSceneCode(); // if(proEntity.getSceneStatus() == SceneStatus.wait.code()){ // log.info(sceneNum + ":场景处于计算中,不能再计算"); // return; // } // }else { // sceneNum = scene3dNumService.generateSceneNum(); // rebuild = 0; // } // // if(sceneNum == null){ // log.error("大场景序号为空:" + sceneNum); // throw new BusinessException(ErrorCode.FAILURE_CODE_5005); // } // // log.info("查询相机:" + cameraName); // CameraEntity cameraEntity = goodsService.findByChildName(cameraName); // // if(cameraEntity == null){ // log.error("该相机不存在:" + cameraName); // //偶现data.fdage给的相机码多了或少了4DKKPRO_ // if(cameraName.contains("4DKKPRO_")){ // cameraEntity = goodsService.findByChildName(cameraName.replace("4DKKPRO_", "")); // }else { // cameraEntity = goodsService.findByChildName("4DKKPRO_" + cameraName); // } // if(cameraEntity == null){ // throw new BusinessException(CameraConstant.FAILURE_6003); // } // } // // CameraDetailEntity detailEntity = goodsService.findCameraDetailByCameraId(cameraEntity.getId()); // if(detailEntity == null){ // log.error("该相机详情不存在:" + cameraName); // throw new BusinessException(CameraConstant.FAILURE_6003); // } // // String userName = null; // if(detailEntity.getUserId() != null){ // ResultData result = userService.findById(detailEntity.getUserId()); // SSOUser user = mapper.convertValue(result.getData(), SSOUser.class); // if(user != null){ // userName = user.getUserName(); // } // } // String icon = null; // if(jsonObject.containsKey("icon") && StrUtil.isNotEmpty(jsonObject.getString("icon"))){ // CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + prefix + jsonObject.getString("icon"), filePath); // icon = prefixAli + "images/images" + sceneNum + "/" + jsonObject.getString("icon"); // if("s3".equals(type)){ // CreateObjUtil.ossFileCp(ConstantFilePath.OSS_PREFIX + prefix + jsonObject.getString("icon"), filePath + jsonObject.getString("icon")); // icon = ConstantUrl.PREFIX_AWS + "images/images" + sceneNum + "/" + jsonObject.getString("icon"); // } // uploadToOssUtil.upload(filePath + jsonObject.getString("icon"), "images/images" + sceneNum + "/" + jsonObject.getString("icon")); // } // // JSONObject firmwareVersion = new JSONObject(); // if(jsonObject.containsKey("camSoftwareVersion") && StrUtil.isNotEmpty(jsonObject.getString("camSoftwareVersion"))){ // firmwareVersion.put("camSoftwareVersion", jsonObject.getString("camSoftwareVersion")); // } // // if(jsonObject.containsKey("version") && StrUtil.isNotEmpty(jsonObject.getString("version"))){ // firmwareVersion.put("version", jsonObject.getString("version")); // } // // String sceneUrl = mainUrl + sceneProUrl; // String buildType = "V2"; // Long cameraType = 10L; // //根据videoVersion判断是V2还是V3版本的算法和页面 // if(jsonObject.containsKey("videoVersion") && StrUtil.isNotEmpty(jsonObject.getString("videoVersion"))){ // if(jsonObject.getIntValue("videoVersion") >= 4){ // buildType = "V3"; // cameraType = 11L; // sceneUrl = mainUrl + sceneProNewUrl; // } // } // //重算的场景,先移除该场景对应的容量 // if(rebuild == 1){ // userService.rebuildReduceSpaceBySceneNum(sceneNum); // }else { // //上传log-main.png // uploadToOssUtil.upload(ConstantFilePath.LOGO_PATH + "logo-main.png", "images/images" + sceneNum + "/logo-main.png"); // uploadToOssUtil.upload(ConstantFilePath.LOGO_PATH + "logo-main-en.png", "images/images" + sceneNum + "/logo-main-en.png"); // } // SceneProPO scene = null; // if(fromOss){ // scene = ComputerUtil.createScenePro(sceneNum, cameraEntity.getId(), cameraEntity.getChildName(), jsonObject.getString("creator"), // jsonObject.getString("pwd"), unicode, // cameraType, String.valueOf(fileId), prefix, "", icon, "0", detailEntity.getUserId(), userName, // jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam", // jsonObject.getJSONArray("points").size(), jsonObject.getString("name"), jsonObject.getString("info"), // jsonObject.getInteger("scenetype"), jsonObject.getString("gps"), sceneProService, sceneProEditService, rebuild, // producer, jsonObject.getInteger("resolution"), firmwareVersion.toString(), sceneUrl, buildType, type, ecsType, // sceneCooperationService, sceneResourceCooperationService, sceneResourceCameraService, detailEntity.getCooperationUser(), rubberSheetingUtil); // }else { // scene = ComputerUtil.createScenePro(sceneNum, cameraEntity.getId(), cameraEntity.getChildName(), jsonObject.getString("creator"), // jsonObject.getString("pwd"), unicode, // detailEntity.getGoodsId(), String.valueOf(fileId), "", "", icon, "0", detailEntity.getUserId(), userName, // jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam", // jsonObject.getJSONArray("points").size(), jsonObject.getString("name"), jsonObject.getString("info"), // jsonObject.getInteger("scenetype"), jsonObject.getString("gps"), sceneProService, sceneProEditService, rebuild, // producer, jsonObject.getInteger("resolution"), firmwareVersion.toString(), sceneUrl, buildType, type, ecsType, // sceneCooperationService, sceneResourceCooperationService, sceneResourceCameraService, detailEntity.getCooperationUser(), rubberSheetingUtil); // } // // if(scene != null){ // JSONObject statusJson = new JSONObject(); // //临时将-2改成1,app还没完全更新 // statusJson.put("status", scene.getStatus() == -2? 1 : scene.getStatus()); // statusJson.put("webSite", scene.getWebSite()); // statusJson.put("sceneNum", scene.getNum()); // statusJson.put("thumb", scene.getThumb()); // statusJson.put("payStatus", scene.getPayStatus()); // statusJson.put("recStatus", scene.getRecStatus()); // FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"status.json", statusJson.toString()); // uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"status.json", // "data/data"+sceneNum+File.separator+"status.json"); // } // // //删除oss的houst_floor.json(国际版可能会卡住) // uploadToOssUtil.delete("data/data"+sceneNum+File.separator+"houst_floor.json"); // // if(detailEntity.getCompanyId() != null){ // CompanyEntity companyEntity = companyService.findById(detailEntity.getCompanyId()); // if(companyEntity != null){ // // Map jsonMap = new HashMap<>(); // // log.info("复制企业logo"); // SceneProEdit sceneProEdit = sceneProEditService.findByProId(scene.getId()); // SceneProEditExt sceneProEditExt = sceneProEditExtService.getByProEditId(sceneProEdit.getId()); // // if(StrUtil.isNotEmpty(companyEntity.getTopLogo())){ // //复制阿里云主服务器的图片到横琴云副服务器中 // if(!new File(ConstantFilePath.BASE_PATH + File.separator + companyEntity.getTopLogo()).exists()){ // log.info("下载topLogo"); // FileUtils.downLoadFromUrl(mainUrl + companyEntity.getTopLogo() + "?t=" + System.currentTimeMillis(), // companyEntity.getTopLogo().substring(companyEntity.getTopLogo().lastIndexOf("/") + 1), // ConstantFilePath.BASE_PATH + companyEntity.getTopLogo().substring(0, companyEntity.getTopLogo().lastIndexOf("/"))); // } // // FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + companyEntity.getTopLogo(), // ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/logo-main.png", true); // uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/logo-main.png", // "images/images" + sceneNum + "/logo-main.png"); // } // // if(StrUtil.isNotEmpty(companyEntity.getFloorLogo())){ // //复制阿里云主服务器的图片到横琴云副服务器中 // if(!new File(ConstantFilePath.BASE_PATH + File.separator + companyEntity.getFloorLogo()).exists()){ // log.info("下载floorLogo"); // FileUtils.downLoadFromUrl(mainUrl + companyEntity.getFloorLogo() + "?t=" + System.currentTimeMillis(), // companyEntity.getFloorLogo().substring(companyEntity.getFloorLogo().lastIndexOf("/") + 1), // ConstantFilePath.BASE_PATH + companyEntity.getFloorLogo().substring(0, companyEntity.getFloorLogo().lastIndexOf("/"))); // } // // FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + companyEntity.getFloorLogo(), // ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/floorLogoImg.png", true); // uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/floorLogoImg.png", // "images/images" + sceneNum + "/floorLogoImg.png"); // // sceneProEdit.setFloorLogo("user"); // jsonMap.put("floorLogoSize", sceneProEdit.getFloorLogoSize()); // jsonMap.put("floorLogo", "user"); // } // // if(StrUtil.isNotEmpty(companyEntity.getQrLogo())){ // //复制阿里云主服务器的图片到横琴云副服务器中 // if(!new File(ConstantFilePath.BASE_PATH + File.separator + companyEntity.getQrLogo()).exists()){ // log.info("下载qrLogo"); // FileUtils.downLoadFromUrl(mainUrl + companyEntity.getQrLogo() + "?t=" + System.currentTimeMillis(), // companyEntity.getQrLogo().substring(companyEntity.getQrLogo().lastIndexOf("/") + 1), // ConstantFilePath.BASE_PATH + companyEntity.getQrLogo().substring(0, companyEntity.getQrLogo().lastIndexOf("/"))); // } // // FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + companyEntity.getQrLogo(), // ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png", true); // uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png", // "images/images" + sceneNum + "/QRShareLogo.png"); // sceneProEdit.setShareLogo("images/images" + sceneNum + "/QRShareLogo.png"); // // //生成新的分享的二维码 // MatrixToImageWriterUtil.createQRCode(sceneUrl + sceneNum, ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneNum+".png", // ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png"); // MatrixToImageWriterUtil.createQRCode(sceneUrl + sceneNum + "&lang=en", ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneNum+"_en.png", // ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png"); // } // // if(StrUtil.isNotEmpty(companyEntity.getMarkerLogo())){ // //复制阿里云主服务器的图片到横琴云副服务器中 // if(!new File(ConstantFilePath.BASE_PATH + File.separator + companyEntity.getMarkerLogo()).exists()){ // log.info("下载floorLogo"); // FileUtils.downLoadFromUrl(mainUrl + companyEntity.getMarkerLogo() + "?t=" + System.currentTimeMillis(), // companyEntity.getMarkerLogo().substring(companyEntity.getMarkerLogo().lastIndexOf("/") + 1), // ConstantFilePath.BASE_PATH + companyEntity.getMarkerLogo().substring(0, companyEntity.getMarkerLogo().lastIndexOf("/"))); // } // // FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + companyEntity.getMarkerLogo(), // ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/marker.png", true); // uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/marker.png", // "images/images" + sceneNum + "/marker.png"); // // sceneProEdit.setMarkerLogo("user"); // jsonMap.put("markerLogo", "user"); // } // // sceneProEdit.setUpdateTime(Calendar.getInstance().getTime()); // sceneProEditService.updateById(sceneProEdit); // // sceneProEditExt.setUpdateTime(Calendar.getInstance().getTime()); // sceneProEditExt.setShowLogoBottom(companyEntity.getShowLogo()); // sceneProEditExtService.updateById(sceneProEditExt); // // jsonMap.put("showLogoBottom", companyEntity.getShowLogo()); // FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + "/scene.json", jsonMap); // } // // } // // // 正顺相机不予计算 // Long companyId = detailEntity.getCompanyId(); // if(Objects.nonNull(unCalculatedCompanyIds) && Arrays.asList(unCalculatedCompanyIds).contains(companyId)){ // return; // } // if(scene != null){ // producer.sendMsg(scene.getMqMsg()); // } // // } // }else { // log.info("data.fdage文件不存在"); // throw new BusinessException(CameraConstant.FAILURE_6009); // } } public String saveFile(MultipartFile file, String filePath, String fileId) throws IOException { //扩展名格式 String extName = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")); String name; /* 指定上传目录 */ if (filePath != null && !"".equals(filePath.trim())) { name = designatedUp(filePath, fileId, file); return name; } /* 默认上传目录 */ //图片类型文件 if (this.inArray(routeConfig.getImageType(), extName)) { filePath = routeConfig.getImageFolder(); } //视频类型文件 else if (this.inArray(routeConfig.getVideoType(), extName)) { filePath = routeConfig.getVideoFolder(); } //文档类型文件 else if (this.inArray(routeConfig.getDocumentType(), extName)) { filePath = routeConfig.getDocumentFolder(); } //音频类型文件 else if (this.inArray(routeConfig.getMusicType(), extName)) { filePath = routeConfig.getMusicFolder(); } else { return "This upload type is not supported temporarily"; } name = myfileUp(filePath, file); return name; } /** * 删除文件 * * @param filePath 包含文件路径的文件名 * @return */ public String dropFile(String filePath) { try { FileUtil.delFile(routeConfig.getHardDisk() + File.separator + filePath); return "successful operation"; } catch (Exception e) { return "drop file error"; } } /** * 判断数组中是否包含某个元素 * * @param array 类型的数组 * @param element 被检查的类型 * @return */ private boolean inArray(String[] array, String element) { boolean flag = false; for (String type : array) { if (element.equals(type)) { flag = true; break; } } return flag; } /** * 默认上传文件到文件夹 * * @param folder 默认文件夹 * @param file 上传的文件 * @return */ private String myfileUp(String folder, MultipartFile file) throws IOException { LocalDate today = LocalDate.now(); String saveName = File.separator + today.getYear() + "." + today.getMonthValue() + File.separator; String fileCode = UUID.randomUUID().toString().trim().replaceAll("-", ""); String returnName = FileUpload.fileUp(file, routeConfig.getHardDisk() + File.separator + folder + saveName, fileCode); saveName = folder + File.separator + saveName + File.separator + returnName; log.warn("This file has been uploaded: " + saveName); return saveName; } /** * 指定目录上传文件 * * @param folder 指定文件夹 * @param file 上传文件 * @return */ private String designatedUp(String folder, String fileId, MultipartFile file) throws IOException { StringBuffer sb = new StringBuffer(routeConfig.getHardDisk()).append(File.separator).append(folder); String returnName = FileUpload.fileUp(file, sb.toString(), fileId); String filePathName = sb.toString() + File.separator + File.separator + returnName; log.warn("This file has been uploaded: " + filePathName); return filePathName; } }