12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385 |
- 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.*;
- /**
- * <p>
- * 场景文件建模表 服务实现类
- * </p>
- *
- * @author dengsixing
- * @since 2021-12-23
- */
- @Slf4j
- @Service
- public class SceneFileBuildServiceImpl extends ServiceImpl<ISceneFileBuildMapper, SceneFileBuild> 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<SceneFileBuild> list = this.list(new QueryWrapper<SceneFileBuild>()
- .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<SceneFileBuild> list = this.list(new QueryWrapper<SceneFileBuild>()
- .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<String> 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<String, String> 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<String, Object> 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<String,String> 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<String, Object> 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;
- }
- }
|