123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778 |
- 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.alibaba.fastjson.serializer.SerializerFeature;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.fdkankan.image.MatrixToImageWriterUtil;
- import com.fdkankan.model.constants.ConstantFileName;
- import com.fdkankan.model.constants.ConstantFilePath;
- import com.fdkankan.common.constant.ConstantUrl;
- import com.fdkankan.common.constant.ErrorCode;
- import com.fdkankan.common.constant.RecStatus;
- import com.fdkankan.common.exception.BusinessException;
- import com.fdkankan.common.response.ResultData;
- import com.fdkankan.model.utils.ConvertUtils;
- import com.fdkankan.model.utils.CreateObjUtil;
- import com.fdkankan.common.util.FileUtils;
- import com.fdkankan.common.util.OkHttpUtils;
- import com.fdkankan.fyun.constant.FYunTypeEnum;
- import com.fdkankan.fyun.face.FYunFileServiceInterface;
- import com.fdkankan.redis.constant.RedisKey;
- import com.fdkankan.redis.util.RedisUtil;
- import com.fdkankan.scene.annotation.SystemServiceLog;
- import com.fdkankan.scene.bean.RequestSceneEdit;
- import com.fdkankan.scene.bean.RequestSceneProV4;
- import com.fdkankan.scene.bean.ResponseScene;
- import com.fdkankan.scene.entity.SceneCooperation;
- import com.fdkankan.scene.entity.ScenePro;
- import com.fdkankan.scene.entity.SceneProEdit;
- import com.fdkankan.scene.entity.SceneResource;
- import com.fdkankan.scene.entity.SceneResourceCooperation;
- import com.fdkankan.scene.mapper.ISceneProMapper;
- import com.fdkankan.scene.service.ISceneCooperationService;
- import com.fdkankan.scene.service.ISceneProEditService;
- import com.fdkankan.scene.service.ISceneProService;
- import com.fdkankan.scene.service.ISceneResourceCooperationService;
- import com.fdkankan.scene.service.ISceneResourceService;
- import com.fdkankan.scene.service.ISceneService;
- import com.google.common.collect.Lists;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.InputStreamReader;
- import java.net.HttpURLConnection;
- import java.net.URL;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.List;
- import java.util.Map;
- import java.util.Objects;
- import java.util.Set;
- import java.util.UUID;
- import java.util.stream.Collectors;
- import lombok.extern.slf4j.Slf4j;
- import net.coobird.thumbnailator.Thumbnails;
- import org.joda.time.DateTime;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Service;
- import org.springframework.util.ObjectUtils;
- import org.springframework.util.StringUtils;
- import org.springframework.web.multipart.MultipartFile;
- /**
- * <p>
- * pro场景表 服务实现类
- * </p>
- *
- * @author
- * @since 2022-07-04
- */
- @Slf4j
- @Service
- public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro> implements ISceneProService {
- @Autowired
- private ISceneCooperationService sceneCooperationService;
- @Autowired
- private RedisUtil redisUtil;
- @Autowired
- private ISceneResourceCooperationService sceneResourceCooperationService;
- @Autowired
- private ISceneResourceService sceneResourceService;
- @Autowired
- private ISceneProEditService sceneProEditService;
- @Autowired
- private FYunFileServiceInterface fYunFileService;
- @Autowired
- private ISceneService sceneService;
- @Value("${main.url}")
- private String mainUrl;
- @Value("${scene.pro.url}")
- private String sceneProUrl;
- @Value("${scene.pro.new.url}")
- private String sceneProNewUrl;
- @Value("${hot.domain.list}")
- private String hotDomainList;
- @Value("${hot.delete}")
- private String hotDelete;
- @Value("${fyun.host}")
- private String ossPrefixUrl;
- @Value("fyun.type")
- private String ossType;
- @Override
- public ResultData upgradeToV4ResultSync(RequestSceneProV4 param) throws Exception {
- ScenePro scenePro = this.getById(param.getId());
- scenePro.setWebSite(param.getWebSite());
- scenePro.setIsUpgrade(1);
- this.updateById(scenePro);
- String num = scenePro.getNum();
- //如果场景有协作者,默认勾选上v4所有菜单
- SceneCooperation SceneCooperation = sceneCooperationService.getByNum(num);
- if(Objects.nonNull(SceneCooperation)){
- redisUtil.hset(RedisKey.SCENE_COOPERATION_NUM_USERID, num, SceneCooperation.getUserId() + "");
- //判断是否已经有了v4的菜单,如果已经有了,证明已经迁移过,不需要再初始化菜单资源
- List<SceneResourceCooperation> sceneResourceCooperationList = sceneResourceCooperationService.list(
- new LambdaQueryWrapper<SceneResourceCooperation>()
- .eq(SceneResourceCooperation::getSceneCooperationId, SceneCooperation.getId()));
- if(CollUtil.isNotEmpty(sceneResourceCooperationList)){
- List<Long> sceneSourceList = sceneResourceCooperationList.stream()
- .map(item -> item.getSceneResourceId()).collect(Collectors.toList());
- List<SceneResource> sceneResourceList
- = sceneResourceService.list(
- new LambdaQueryWrapper<SceneResource>()
- .eq(SceneResource::getVersion, "v4")
- .in(SceneResource::getId, sceneSourceList));
- if(CollUtil.isEmpty(sceneResourceList)){//如果查出来的这个场景的v4资源是空的,证明是第一次升级,需要初始化菜单资源
- sceneResourceList = sceneResourceService.list(
- new LambdaQueryWrapper<SceneResource>()
- .eq(SceneResource::getVersion, "v4"));// 查出所有的v4菜单,给这个场景的协作者初始化所有v4菜单资源
- if(CollUtil.isNotEmpty(sceneResourceList)){
- List<SceneResourceCooperation> list = Lists.newArrayList();
- SceneResourceCooperation sceneResourceCooperation = null;
- for (SceneResource sceneResource : sceneResourceList) {
- sceneResourceCooperation = new SceneResourceCooperation();
- sceneResourceCooperation.setSceneResourceId(sceneResource.getId());
- sceneResourceCooperation.setSceneCooperationId(SceneCooperation.getId());
- sceneResourceCooperation.setCreateTime(new Date());
- sceneResourceCooperation.setUpdateTime(new Date());
- sceneResourceCooperation.setRecStatus(RecStatus.VALID.code());
- list.add(sceneResourceCooperation);
- }
- sceneResourceCooperationService.saveBatch(list);
- }
- }
- }
- }
- return ResultData.ok();
- }
- @Override
- public ScenePro findBySceneNum(String num) {
- return this.getOne(new LambdaQueryWrapper<ScenePro>().eq(ScenePro::getNum, num));
- }
- @Override
- public ResultData uploadLogoBottomStatus(String sceneNum, String status) throws Exception {
- ScenePro sceneProEntity = this.findBySceneNum(sceneNum);
- if(sceneProEntity == null){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
- }
- SceneProEdit sceneProEditEntity = sceneProEditService.findBySceneProId(sceneProEntity.getId());
- if(sceneProEditEntity == null){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
- }
- StringBuffer dataBuf = new StringBuffer()
- .append("data").append(File.separator)
- .append("data").append(sceneProEntity.getNum())
- .append(File.separator);
- StringBuffer imagesBuf = new StringBuffer()
- .append("images").append(File.separator)
- .append("images").append(sceneProEntity.getNum())
- .append(File.separator);
- StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
- StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
- String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
- JSONObject scenejson = new JSONObject();
- if(strsceneInfos!=null) {
- scenejson = JSONObject.parseObject(strsceneInfos);
- }
- scenejson.put("showLogoBottom", Integer.valueOf(status));
- scenejson.put("version", scenejson.getIntValue("version") + 1);
- FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
- sceneProEditEntity.setVersion(scenejson.getIntValue("version") + 1);
- sceneProEditEntity.setShowLogoBottom(Integer.valueOf(status));
- sceneProEditService.updateById(sceneProEditEntity);
- return ResultData.ok();
- }
- @Override
- public ResultData downloadTexData(String sceneNum) throws Exception {
- ScenePro sceneProEntity = this.findBySceneNum(sceneNum);
- if(sceneProEntity == null){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
- }
- if(!new File(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum).exists()){
- new File(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum).mkdirs();
- }
- //上传过的资源
- StringBuffer dataBuf = new StringBuffer()
- .append("data").append(File.separator)
- .append("data").append(sceneProEntity.getNum())
- .append(File.separator);
- StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
- String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
- JSONObject scenejson = new JSONObject();
- if(strsceneInfos!=null) {
- scenejson = JSONObject.parseObject(strsceneInfos);
- }
- String newData = sceneProEntity.getDataSource() + "_obj2txt/extras";
- String newResultData = sceneProEntity.getDataSource() + "_obj2txt/results/upload.json";
- if(scenejson.containsKey("isUploadObj") && new File(newData).exists() && new File(newResultData).exists()){
- FileUtils.zipFile(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/" + sceneNum + ".zip", newData);
- return ResultData.ok(mainUrl + "/scene/images/images" + sceneNum + "/" + sceneNum + ".zip?t=" +System.currentTimeMillis());
- }
- String buildType = sceneProEntity.getBuildType();
- if("V3".equals(buildType)){
- //V3版本去oss下载2048模型
- String meshPath = ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + "/mesh";
- FileUtils.deleteDirectory(meshPath);
- CreateObjUtil.ossUtilCp("data/data" + sceneNum + "/mesh", meshPath);
- if(new File(meshPath.concat("/mesh")).listFiles().length > 0){
- for(File file : new File(meshPath.concat("/mesh")).listFiles()){
- if(file.getName().endsWith(".obj") && !"output.house.obj".equals(file.getName()) &&
- !"mesh.obj".equals(file.getName())){
- file.delete();
- }
- if(file.getName().endsWith(".mtl") && !"output.house.mtl".equals(file.getName()) &&
- !"mesh.mtl".equals(file.getName())){
- file.delete();
- }
- }
- FileUtils.zipFile(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/" + sceneNum + ".zip", meshPath);
- return ResultData.ok(mainUrl + "/scene/images/images" + sceneNum + "/" + sceneNum + ".zip?t=" +System.currentTimeMillis());
- }
- }
- //V2版本在本地获取模型资源
- //修改过的资源
- String editData = sceneProEntity.getDataSource() + "_edit/caches/tex";
- String resultData = sceneProEntity.getDataSource() + "_edit/results";
- if (new File(editData).exists() && new File(resultData).exists()){
- for(File file : new File(editData).listFiles()){
- if(file.getName().endsWith(".obj") && !"output.house.obj".equals(file.getName()) &&
- !"mesh.obj".equals(file.getName())){
- file.delete();
- }
- if(file.getName().endsWith(".mtl") && !"output.house.mtl".equals(file.getName()) &&
- !"mesh.mtl".equals(file.getName())){
- file.delete();
- }
- }
- FileUtils.zipFile(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/" + sceneNum + ".zip", editData);
- return ResultData.ok(mainUrl + "/scene/images/images" + sceneNum + "/" + sceneNum + ".zip?t=" +System.currentTimeMillis());
- }
- //没上传过返回源资源
- String dataPath = sceneProEntity.getDataSource() + "/caches/tex";
- File dataFile = new File(dataPath);
- if(!dataFile.exists()){
- throw new BusinessException(ErrorCode.FAILURE_CODE_3018);
- }
- for(File file : dataFile.listFiles()){
- if(file.getName().endsWith(".obj") && !"output.house.obj".equals(file.getName()) &&
- !"mesh.obj".equals(file.getName())){
- file.delete();
- }
- if(file.getName().endsWith(".mtl") && !"output.house.mtl".equals(file.getName()) &&
- !"mesh.mtl".equals(file.getName())){
- file.delete();
- }
- }
- FileUtils.zipFile(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/" + sceneNum + ".zip", dataPath);
- return ResultData.ok(mainUrl + "/scene/images/images" + sceneNum + "/" + sceneNum + ".zip?t=" +System.currentTimeMillis());
- }
- @Override
- public ResultData uploadPic(String sceneNum, String folderName, MultipartFile file, String toOss) throws Exception{
- ScenePro sceneProEntity = this.findBySceneNum(sceneNum);
- if(sceneProEntity == null){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
- }
- if (file.isEmpty() && file.getSize() <= 0) {
- throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
- }
- //文件上传的位置可以自定义
- String path = ConstantFilePath.SCENE_PATH+"images"+File.separator+"images"+sceneNum;
- if(StrUtil.isNotEmpty(folderName)) {
- path = path + File.separator + folderName;
- }
- File targetFile = new File(path);
- if (!targetFile.exists()) {
- targetFile.mkdirs();
- }
- String fileName = file.getOriginalFilename();
- targetFile = new File(path + File.separator + fileName);
- // 保存
- synchronized(this)
- {
- if(targetFile.exists())
- {
- FileUtils.deleteFile(path + File.separator + fileName);
- }
- file.transferTo(targetFile);
- }
- if(toOss != null && "1".equals(toOss)){
- fYunFileService.uploadFile(path + File.separator + fileName, "images"+File.separator+"images"+sceneNum + File.separator + fileName);
- }
- return ResultData.ok(targetFile.getName());
- }
- @Override
- public ResultData uploadShareLogo(String sceneNum, MultipartFile file) throws Exception {
- ScenePro sceneProEntity = findBySceneNum(sceneNum);
- if (sceneProEntity == null ) {
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
- }
- StringBuffer dataBuf = new StringBuffer()
- .append("data").append(File.separator)
- .append("data").append(sceneProEntity.getNum())
- .append(File.separator);
- StringBuffer imagesBuf = new StringBuffer()
- .append("images").append(File.separator)
- .append("images").append(sceneProEntity.getNum())
- .append(File.separator);
- StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
- StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
- String fileName = "";
- if (!file.isEmpty()&&file.getSize() > 0) {
- //文件上传的位置可以自定义
- System.out.println("上传分享的logo");
- String path = imagesBuffer.toString();
- File targetFile = new File(path);
- if (!targetFile.exists()) {
- targetFile.mkdirs();
- }
- fileName = file.getOriginalFilename();
- targetFile = new File(path + fileName);
- int count = 1;
- // 保存
- synchronized(this)
- {
- file.transferTo(targetFile);
- }
- SceneProEdit sceneProEditEntity = sceneProEditService.findBySceneProId(sceneProEntity.getId());
- Map<String, Object> map = new HashMap<>();
- map.put("shareLogo", imagesBuf.toString() + fileName);
- map.put("version", sceneProEditEntity.getVersion()+1);
- FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map);
- sceneProEditEntity.setShareLogo(imagesBuf.toString() + fileName);
- sceneProEditEntity.setVersion(sceneProEditEntity.getVersion()+1);
- sceneProEditService.updateById(sceneProEditEntity);
- if("V2".equals(sceneProEntity.getBuildType())){
- MatrixToImageWriterUtil.createQRCode(
- mainUrl + sceneProUrl + sceneProEntity.getNum(),
- ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneProEntity.getNum()+".png",
- true,
- path + File.separator + fileName);
- MatrixToImageWriterUtil.createQRCode(mainUrl + sceneProUrl + sceneProEntity.getNum() + "&lang=en",
- ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneProEntity.getNum()+"_en.png",
- true,
- path + File.separator + fileName);
- }
- if("V3".equals(sceneProEntity.getBuildType())){
- MatrixToImageWriterUtil.createQRCode(mainUrl + sceneProNewUrl + sceneProEntity.getNum(),
- ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneProEntity.getNum()+".png",
- true,
- path + File.separator + fileName);
- MatrixToImageWriterUtil.createQRCode(mainUrl + sceneProNewUrl + sceneProEntity.getNum() + "&lang=en",
- ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneProEntity.getNum()+"_en.png",
- true,
- path + File.separator + fileName);
- }
- }
- return ResultData.ok(imagesBuf.toString() + fileName);
- }
- @Override
- @SystemServiceLog(description = "上传场景的热点媒体文件")
- public ResultData uploadHotMedia(String sceneNum, MultipartFile file, String sid) throws Exception {
- ScenePro sceneProEntity = findBySceneNum(sceneNum);
- if(sceneProEntity == null){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
- }
- String fileName = "hot" + sid + ".mp4";
- if (!file.isEmpty()){
- String path = ConstantFilePath.SCENE_PATH + "images" + File.separator + "images" + sceneNum;
- File targetFile = new File(path);
- if (!targetFile.exists()){
- targetFile.mkdirs();
- }
- targetFile = new File(path + File.separator + fileName);
- if (targetFile.exists()){
- FileUtils.deleteFile(path + File.separator + fileName);
- }
- file.transferTo(targetFile);
- if(targetFile.exists()){
- FileUtils.executeCodecs(path + File.separator + fileName, path, "hot" + sid + "-cut");
- }
- }
- return ResultData.ok(fileName);
- }
- @Override
- public ResultData checkVideoUrl(String path) {
- if(!path.contains("qq.com") && !path.contains("youku.com") && !path.contains("iqiyi.com")){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5016);
- }
- if(path.contains("v.qq.com/txp/iframe/player.html") || path.contains("player.youku.com/embed")
- || path.contains("open.iqiyi.com/developer/player_js/coopPlayerIndex.html")){
- return ResultData.ok(path);
- }
- String html = "";
- try {
- URL url = new URL(path);
- HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
- httpConn.setConnectTimeout(60000);
- httpConn.setReadTimeout(60000);
- InputStreamReader input = new InputStreamReader(httpConn
- .getInputStream(), "utf-8");
- BufferedReader bufReader = new BufferedReader(input);
- String line = "";
- String vid = "";
- if(path.contains("qq.com")){
- while ((line = bufReader.readLine()) != null) {
- // System.out.println(line);
- if(line.contains("m.v.qq.com/play.html")){
- log.info(line.substring(line.indexOf("&vid=") + 5, line.indexOf("&ptag")));
- vid = line.substring(line.indexOf("&vid=") + 5, line.indexOf("&ptag"));
- break;
- }
- }
- if(!org.springframework.util.StringUtils.isEmpty(vid)){
- html = "https://v.qq.com/txp/iframe/player.html?vid=" + vid;
- }
- }
- if(path.contains("youku.com")){
- vid = path.substring(path.indexOf("/id_") + "/id_".length(), path.indexOf(".html"));
- html = "https://player.youku.com/embed/" + vid;
- }
- if(path.contains("iqiyi.com")){
- String tvid = "";
- while ((line = bufReader.readLine()) != null) {
- if(line.contains("param['vid']")){
- vid = line.substring(line.indexOf("\"") + 1, line.lastIndexOf("\""));
- }
- if(line.contains("param['tvid']")){
- tvid = line.substring(line.indexOf("\"") + 1, line.lastIndexOf("\""));
- }
- }
- if(!org.springframework.util.StringUtils.isEmpty(vid) && !StringUtils.isEmpty(tvid)){
- html = "https://open.iqiyi.com/developer/player_js/coopPlayerIndex.html?vid=" + vid +
- "&tvId=" + tvid;
- }
- }
- }catch (Exception e){
- e.printStackTrace();
- }
- return ResultData.ok(html);
- }
- @Override
- public ResultData saveSceneInfo(RequestSceneEdit base) throws Exception{
- if(StrUtil.isEmpty(base.getSceneNum())){
- throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
- }
- ScenePro sceneProEntity = findBySceneNum(base.getSceneNum());
- if(sceneProEntity == null){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
- }
- StringBuffer dataBuf = new StringBuffer()
- .append("data").append(File.separator)
- .append("data").append(sceneProEntity.getNum())
- .append(File.separator);
- StringBuffer imagesBuf = new StringBuffer()
- .append("images").append(File.separator)
- .append("images").append(sceneProEntity.getNum())
- .append(File.separator);
- StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
- StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
- int type = Integer.valueOf(base.getSceneType());
- String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
- JSONObject scenejson = new JSONObject();
- if(strsceneInfos!=null) {
- scenejson = JSONObject.parseObject(strsceneInfos);
- }
- //上传七牛
- Map<String,String> map = new HashMap<String,String>();
- SceneProEdit sceneProEditEntity = sceneProEditService.findBySceneProId(sceneProEntity.getId());
- if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getTourList())){
- if(scenejson.containsKey("uploadTourList") && scenejson.getIntValue("uploadTourList") == 1){
- int screencapLen = 0;
- File file = new File(dataBuffer.toString() + ConstantFileName.TOURLIST_FOLDER);
- String[] strs = file.list();
- if(strs!=null) {
- for(int i=0;i<strs.length;++i) {
- if(strs[i].indexOf(ConstantFileName.SCREEN_CRP_DATAFILE)>-1)
- {
- ++screencapLen;
- map.put(dataBuffer.toString() + ConstantFileName.TOURLIST_FOLDER+File.separator+strs[i],
- "data/data"+base.getSceneNum()+"/tour/"+strs[i]);
- }
- }
- }
- scenejson.put("screencapLen", screencapLen);
- // sceneProEditEntity.setScreencapLen(screencapLen);
- String path = imagesBuffer.toString() + ConstantFileName.TOURLIST_FOLDER;
- JSONArray tourJsons = JSONArray.parseArray(base.getTourList());
- for(int i=0;i<tourJsons.size();++i) {
- String fileName = path + File.separator +"guide"+i+".jpg";
- map.put(fileName,"images/images"+base.getSceneNum()+"/tour/guide"+i+".jpg");
- }
- scenejson.put("uploadTourList", 0);
- }
- String tourListPath = dataBuffer.toString() + ConstantFileName.TOUR_LIST;
- FileUtils.deleteFile(tourListPath);
- FileUtils.writeFile(tourListPath, base.getTourList());
- map.put(tourListPath, dataBuffer.toString() + ConstantFileName.TOUR_LIST);
- }
- else{
- if(scenejson.containsKey("uploadTourList") && scenejson.getIntValue("uploadTourList") == 1){
- scenejson.put("uploadTourList", 0);
- }
- scenejson.put("screencapLen", 0);
- // sceneProEditEntity.setScreencapLen(0);
- }
- //判断scene.json是否有uploadVoiceSrc上传普通版音频
- if(scenejson.containsKey("uploadVoiceSrc") && scenejson.getIntValue("uploadVoiceSrc") == 1) {
- String screencapVoiceFileName = "";
- if(scenejson.containsKey("screencapVoiceFileName")) {
- screencapVoiceFileName = scenejson.getString("screencapVoiceFileName");
- }
- String screencapVoiceSrc = "";
- if(scenejson.containsKey("screencapVoiceSrc")) {
- screencapVoiceSrc = scenejson.getString("screencapVoiceSrc");
- }
- if(screencapVoiceFileName.indexOf(".")>-1) {
- String fileName = "201810" + screencapVoiceFileName.substring(screencapVoiceFileName.lastIndexOf("."));
- String path = ConstantFilePath.SCENE_PATH + "voice" + File.separator+"voice"+base.getSceneNum()+File.separator+fileName;
- map.put(path, "voice/voice"+base.getSceneNum()+"/201810" +screencapVoiceFileName.substring(screencapVoiceFileName.lastIndexOf(".")));
- }
- sceneProEditEntity.setScreencapVoiceSrc(screencapVoiceSrc);
- }
- //判断scene.json是否有uploadVoiceSound上传专业版音频
- if(scenejson.containsKey("uploadVoiceSound") && scenejson.getIntValue("uploadVoiceSound") == 1){
- if(!org.apache.commons.lang3.StringUtils.isEmpty(scenejson.getString("screencapVoiceSound"))){
- map.put(ConstantFilePath.SCENE_PATH + scenejson.getString("screencapVoiceSound"), scenejson.getString("screencapVoiceSound"));
- }
- sceneProEditEntity.setScreencapVoiceSound(scenejson.getString("screencapVoiceSound"));
- }
- if(scenejson.containsKey("uploadVoiceSoundsync") && scenejson.getIntValue("uploadVoiceSoundsync") == 1){
- if(!org.apache.commons.lang3.StringUtils.isEmpty(scenejson.getString("screencapVoiceSoundsync"))){
- map.put(ConstantFilePath.SCENE_PATH + scenejson.getString("screencapVoiceSoundsync"), scenejson.getString("screencapVoiceSoundsync"));
- }
- sceneProEditEntity.setScreencapVoiceSoundsync(scenejson.getString("screencapVoiceSoundsync"));
- }
- if(base.getScreencapVoiceType() != null){
- scenejson.put("screencapVoiceType", base.getScreencapVoiceType());
- sceneProEditEntity.setScreencapVoiceType(base.getScreencapVoiceType());
- }
- if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getCapData())){
- FileUtils.writeFile(dataBuffer.toString() + "capData.json", new String(base.getCapData().getBytes(), "UTF-8"));
- scenejson.put("capData", dataBuf.toString() + "capData.json");
- }
- if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getFrameData())){
- FileUtils.writeFile(dataBuffer.toString() + "frameData.json", new String(base.getFrameData().getBytes(), "UTF-8"));
- scenejson.put("frameData", dataBuf.toString() + "frameData.json");
- }
- if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getPlayData())){
- FileUtils.writeFile(dataBuffer.toString() + "playData.json", new String(base.getPlayData().getBytes(), "UTF-8"));
- scenejson.put("playData", dataBuf.toString() + "playData.json");
- sceneProEditEntity.setPlayData(dataBuf.toString() + "playData.json");
- map.put(dataBuffer.toString() + "playData.json", dataBuf.toString() + "playData.json");
- }
- if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getScreencapThumb())){
- FileUtils.writeFile(dataBuffer.toString() + "screencapThumb.json", new String(base.getScreencapThumb().getBytes(), "UTF-8"));
- scenejson.put("screencapThumb", dataBuf.toString() + "screencapThumb.json");
- sceneProEditEntity.setScreencapThumb(dataBuf.toString() + "screencapThumb.json");
- map.put(dataBuffer.toString() + "screencapThumb.json", dataBuf.toString() + "screencapThumb.json");
- }
- if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getRecordType())){
- scenejson.put("recordType", base.getRecordType());
- }
- if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getMapVisi())){
- scenejson.put("mapVisi", Integer.parseInt(base.getMapVisi()));
- sceneProEditEntity.setMapVisi(Integer.parseInt(base.getMapVisi()));
- }
- if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getTourVisi())){
- scenejson.put("tourVisi", Integer.parseInt(base.getTourVisi()));
- sceneProEditEntity.setTourVisi(Integer.parseInt(base.getTourVisi()));
- }
- if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getVrVisi())){
- scenejson.put("vrVisi", Integer.parseInt(base.getVrVisi()));
- sceneProEditEntity.setVrVisi(Integer.parseInt(base.getVrVisi()));
- }
- if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getRulerVisi())){
- scenejson.put("rulerVisi", Integer.parseInt(base.getRulerVisi()));
- sceneProEditEntity.setRulerVisi(Integer.parseInt(base.getRulerVisi()));
- }
- if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getCadImgVisi())){
- scenejson.put("cadImgVisi", Integer.parseInt(base.getCadImgVisi()));
- sceneProEditEntity.setCadImgVisi(Integer.parseInt(base.getCadImgVisi()));
- }
- if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getPanoVisi())){
- scenejson.put("panoVisi", Integer.parseInt(base.getPanoVisi()));
- sceneProEditEntity.setPanoVisi(Integer.parseInt(base.getPanoVisi()));
- }
- if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getM2dVisi())){
- scenejson.put("m2dVisi", Integer.parseInt(base.getM2dVisi()));
- sceneProEditEntity.setM2dVisi(Integer.parseInt(base.getM2dVisi()));
- }
- if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getM3dVisi())){
- scenejson.put("m3dVisi", Integer.parseInt(base.getM3dVisi()));
- sceneProEditEntity.setM3dVisi(Integer.parseInt(base.getM3dVisi()));
- }
- if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getMeasureVisi())){
- scenejson.put("measureVisi", Integer.parseInt(base.getMeasureVisi()));
- sceneProEditEntity.setMeasureVisi(Integer.parseInt(base.getMeasureVisi()));
- }
- if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getFloorPlanAngle())){
- scenejson.put("floorPlanAngle", base.getFloorPlanAngle());
- sceneProEditEntity.setFloorPlanAngle(base.getFloorPlanAngle());
- }
- if(scenejson.containsKey("uploadFloorPlanPng") && scenejson.getIntValue("uploadFloorPlanPng") == 1){
- JSONArray floorPlanPngStr = new JSONArray();
- JSONArray floorPlanPng = new JSONArray();
- switch (sceneProEntity.getBuildType()){
- case "V2":
- floorPlanPng.add(scenejson.getString("floorPlanPng"));
- break;
- case "V3":
- try {
- floorPlanPng = scenejson.getJSONArray("floorPlanPng");
- } catch (Exception e) {
- // 旧的V3也是String
- floorPlanPng.add(scenejson.getString("floorPlanPng"));
- }
- break;
- }
- scenejson.put("uploadFloorPlanPng", 0);
- for(int i = 0, len = floorPlanPng.size(); i < len; i++){
- map.put(ConstantFilePath.SCENE_PATH+floorPlanPng.getString(i), floorPlanPng.getString(i));
- floorPlanPngStr.add(floorPlanPng.getString(i) + "?t=" + System.currentTimeMillis());
- }
- sceneProEditEntity.setFloorPlanPng(floorPlanPngStr.toJSONString());
- }
- if(scenejson.containsKey("uploadFloorJson") && scenejson.getIntValue("uploadFloorJson") == 1){
- map.put(dataBuffer.toString() + "floor.json", dataBuf.toString() + "floor.json");
- scenejson.put("uploadFloorJson", 0);
- }
- if(StrUtil.isNotEmpty(base.getEntry())) {
- //上传七牛
- map.put(imagesBuffer.toString() + "thumbBigImg.jpg", imagesBuf.toString() + "thumbBigImg.jpg");
- map.put(imagesBuffer.toString() + "thumbFishBigImg.jpg",imagesBuf.toString() + "thumbFishBigImg.jpg");
- map.put(imagesBuffer.toString() + "thumbSmallImg.jpg", imagesBuf.toString() + "thumbSmallImg.jpg");
- map.put(imagesBuffer.toString() + "smallPic.jpg", imagesBuf.toString() + "smallPic.jpg");
- sceneProEditEntity.setEntry(base.getEntry());
- scenejson.put("entry", base.getEntry());
- if(scenejson.containsKey("thumbImg"))
- {
- sceneProEditEntity.setThumbStatus(scenejson.getIntValue("thumbImg"));
- }
- if(sceneProEditEntity.getThumbStatus() == 1)
- {
- sceneProEntity.setThumb(ossPrefixUrl + imagesBuf.toString() + "thumbSmallImg.jpg");
- }
- }
- if(base.getHotFlag() != null && "1".equals(base.getHotFlag())) {
- String str = FileUtils.readFile(dataBuffer.toString() + "hot.json");
- JSONArray jsonhots = new JSONArray();
- if(str != null&&!str.trim().equals("")) {
- jsonhots = JSONArray.parseArray(str);
- }
- String hotsids = "";
- for(int i=0;i<jsonhots.size();++i) {
- JSONObject ele = jsonhots.getJSONObject(i);
- String index = ele.getString("sid");
- hotsids+=index+",";
- if(ele.containsKey("media"))
- {
- String fileType = ele.getString("media");
- if(fileType.contains("photo"))
- {
- map.put(imagesBuffer.toString() + "hot"+index+".jpg",
- imagesBuf.toString() + "hot"+index+".jpg");
- }
- if(fileType.contains("audio") || fileType.contains("voice"))
- {
- map.put(imagesBuffer.toString() + "hot"+index+".mp3",
- imagesBuf.toString() + "hot"+index+".mp3");
- }
- if(fileType.contains("video"))
- {
- map.put(imagesBuffer.toString() + "hot"+index+".mp4",
- imagesBuf.toString() + "hot"+index+".mp4");
- map.put(imagesBuffer.toString() + "hot"+index+"-cut.jpg",
- imagesBuf.toString() + "hot"+index+"-cut.jpg");
- }
- }
- }
- map.put(dataBuffer.toString() + "hot.json",dataBuf.toString() + "hot.json");
- sceneProEditEntity.setHotsIds(hotsids);
- }
- if(StrUtil.isNotEmpty(base.getFloorLogoType())) {
- sceneProEditEntity.setFloorLogo(base.getFloorLogoType());
- scenejson.put("floorLogo", base.getFloorLogoType());
- if(base.getFloorLogoType().trim().equals("1")||base.getFloorLogoType().trim().equals("user")) {
- map.put(imagesBuffer.toString() + "floorLogoImg.png", imagesBuf.toString() + "floorLogoImg.png");
- }
- }
- if(StrUtil.isNotEmpty(base.getFloorLogoSize())) {
- sceneProEditEntity.setFloorLogoSize(Integer.valueOf(base.getFloorLogoSize()));
- scenejson.put("floorLogoSize", base.getFloorLogoSize());
- }
- if(base.getBgMusic() != null) {
- sceneProEditEntity.setBgMusic(base.getBgMusic());
- scenejson.put("bgMusic", base.getBgMusic());
- }
- if(base.getSceneName() != null) {
- sceneProEntity.setSceneName(base.getSceneName());
- scenejson.put("sceneName", base.getSceneName());
- }
- if(StrUtil.isNotEmpty(base.getSceneType())) {
- if(sceneProEntity.getSceneType() == 99){
- scenejson.put("sceneType", sceneProEntity.getSceneType());
- }else {
- sceneProEntity.setSceneType(type);
- scenejson.put("sceneType", base.getSceneType());
- }
- }
- if(base.getSceneDec() != null) {
- sceneProEntity.setSceneDec(base.getSceneDec());
- scenejson.put("sceneDec", base.getSceneDec());
- }
- if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getSceneKey())) {
- sceneProEditEntity.setSceneKey(base.getSceneKey());
- sceneProEditEntity.setNeedKey(1);
- scenejson.put("sceneKey", base.getSceneKey());
- scenejson.put("needKey", 1);
- }else {
- sceneProEditEntity.setSceneKey("");
- sceneProEditEntity.setNeedKey(0);
- scenejson.put("sceneKey", "");
- scenejson.put("needKey", 0);
- }
- if(!scenejson.containsKey("version")) {
- scenejson.put("version", 0);
- }
- scenejson.put("version", scenejson.getIntValue("version")+1);
- map.put(dataBuffer.toString() + "scene.json", dataBuf.toString() + "scene.json");
- sceneProEditEntity.setCadInfo(scenejson.getString("cadInfo"));
- sceneProEditEntity.setVersion(scenejson.getIntValue("version"));
- sceneProEditService.updateById(sceneProEditEntity);
- //重建上传资源到oss
- if(sceneProEditEntity.getFloorEditVer() != sceneProEditEntity.getFloorPublishVer()){
- //上传过模型,只更新floor.json
- if(scenejson.containsKey("isUploadObj") && scenejson.getBooleanValue("isUploadObj")){
- map.put(dataBuffer.toString() + "floor.json", dataBuf.toString() + "floor.json");
- //发布重新建模场景,将floorPublishVer设为floorEditVer的值
- sceneProEditEntity.setFloorPublishVer(sceneProEditEntity.getFloorEditVer());
- scenejson.put("floorEditVer", sceneProEditEntity.getFloorEditVer());
- scenejson.put("floorPublishVer", sceneProEditEntity.getFloorEditVer());
- }else {
- String path = sceneProEntity.getDataSource();
- if(path != null && !"".equals(path) && path.startsWith("http")){
- path = ConstantFilePath.BUILD_MODEL_PATH + path.split("/")[path.split("/").length - 2];
- }
- path = path + "_edit";
- String projectNum = base.getSceneNum();
- //读取upload文件,检验需要上传的文件是否存在
- String uploadData = FileUtils.readFile(path + File.separator + "results" +File.separator+"upload.json");
- JSONObject uploadJson = null;
- JSONArray array = null;
- if(uploadData!=null) {
- uploadJson = JSONObject.parseObject(uploadData);
- array = uploadJson.getJSONArray("upload");
- }
- if(array != null){
- JSONObject fileJson = null;
- String fileName = "";
- for(int i = 0, len = array.size(); i < len; i++){
- fileJson = array.getJSONObject(i);
- fileName = fileJson.getString("file");
- //文件不存在抛出异常
- if(!new File(path + File.separator + "results" +File.separator + fileName).exists()){
- throw new Exception(path + File.separator + "results" +File.separator + fileName+"文件不存在");
- }
- //tex文件夹
- if(fileJson.getIntValue("clazz") == 2 && !fileJson.containsKey("pack-file")){
- map.put(path + File.separator + "results" +File.separator+ fileName,"images/images"+
- projectNum+"/"+ConstantFileName.modelUUID+"_50k_texture_jpg_high1/"+fileName.replace("tex/", ""));
- }
- //2048的模型和贴图
- if(fileJson.getIntValue("clazz") == 16){
- map.put(path + File.separator + "results" + File.separator+ fileName,"data/data"+
- projectNum+ File.separator + fileName);
- }
- }
- map.put(path + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k.dam.lzma", "images/images"+projectNum+"/"+ConstantFileName.modelUUID+"_50k.dam.lzma");
- map.put(path + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k.dam", "images/images"+projectNum+"/"+ConstantFileName.modelUUID+"_50k.dam");
- File file = new File(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+projectNum);
- if(!file.exists())
- {
- file.mkdir();
- }
- log.info("计算大场景:开始上传大场景文件到阿里——"+projectNum);
- //上传修改后的本地的缩略图
- map.put(dataBuffer.toString() + "floor.json", dataBuf.toString() + "floor.json");
- //发布重新建模场景,将floorPublishVer设为floorEditVer的值
- sceneProEditEntity.setFloorPublishVer(sceneProEditEntity.getFloorEditVer());
- scenejson.put("floorEditVer", sceneProEditEntity.getFloorEditVer());
- scenejson.put("floorPublishVer", sceneProEditEntity.getFloorEditVer());
- }
- }
- }
- //重算全景图并上传oss或oss
- if(scenejson.containsKey("buildImages")){
- String path = sceneProEntity.getDataSource();
- if(path != null && !"".equals(path) && path.startsWith("http")){
- path = ConstantFilePath.BUILD_MODEL_PATH + File.separator + path.split("/")[path.split("/").length - 2];
- }
- String target = path + "_images";
- File images = new File(target + File.separator + "extras/images");
- File video = new File(target + File.separator + "extras/video");
- if(scenejson.getIntValue("buildImages") == 1){
- log.info("下载vision.modeldata文件");
- if(FYunTypeEnum.AWS.code().equals(this.ossType)){
- FileUtils.downLoadFromUrl(ConstantUrl.PREFIX_AWS + "images/images" + sceneProEntity.getNum() + "/vision.modeldata" + "?m="+new Date().getTime(),
- "vision.modeldata", target + File.separator + "extras" + File.separator);
- }
- if(FYunTypeEnum.OSS.code().equals(this.ossType)){
- FileUtils.downLoadFromUrl(ossPrefixUrl + "images/images" + sceneProEntity.getNum() + "/vision.modeldata" + "?m="+new Date().getTime(),
- "vision.modeldata", target + File.separator + "extras" + File.separator);
- }
- CreateObjUtil.convertVisionmodeldataToTxt(target + File.separator + "extras" + File.separator + "vision.modeldata",
- target + File.separator + "extras" + File.separator + "vision.txt");
- if(images.exists() && images.listFiles() != null && images.listFiles().length > 0){
- FileUtils.copyFile(path + File.separator + "data.json", target + File.separator+"data.json", true);
- FileUtils.copyFile(path + File.separator + "project.json", target + File.separator+"project.json", true);
- //data.json增加extras为执行重建算法
- String data = FileUtils.readFile(target + File.separator+"data.json");
- if(data != null){
- JSONObject floorplanJson = new JSONObject();
- floorplanJson.put("has_source_images", true);
- floorplanJson.put("has_vision_txt", true);
- JSONObject dataJson = JSONObject.parseObject(data);
- dataJson.put("extras", floorplanJson);
- //V5表示不需要生成high,low文件
- dataJson.put("skybox_type", "SKYBOX_V6");
- if(sceneProEntity.getSceneScheme() == 11){
- dataJson.put("skybox_type", "SKYBOX_V7");
- }
- dataJson.put("split_type", "SPLIT_V8");
- //sceneScheme为3切成瓦片图
- if(sceneProEntity.getSceneScheme() == 3){
- dataJson.put("skybox_type", "SKYBOX_V4");
- }
- FileUtils.writeFile(target + File.separator+"data.json", new String(dataJson.toString().getBytes(), "UTF-8"));
- }
- //创建文件夹软连接并且复制data.json和project.json
- if(new File(target + File.separator + "capture").exists()){
- new File(target + File.separator + "capture").delete();
- }
- if(new File(target + File.separator + "results").exists()){
- FileUtils.delAllFile(target + File.separator + "results");
- }
- //下载data.fdage
- if(FYunTypeEnum.AWS.code().equals(this.ossType)){
- //亚马逊保持旧方式,超链接capture
- CreateObjUtil.createSoftConnection(path + File.separator + "capture", target + File.separator + "capture");
- }
- CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + path.replace(ConstantFilePath.BUILD_MODEL_PATH, "") + "/data.fdage", target + File.separator + "capture/");
- CreateObjUtil.build3dModel(target , "1");
- //读取upload文件,检验需要上传的文件是否存在
- String uploadData = FileUtils.readFile(target + File.separator + "results" +File.separator+"upload.json");
- JSONObject uploadJson = null;
- JSONArray array = null;
- if(uploadData!=null) {
- uploadJson = JSONObject.parseObject(uploadData);
- array = uploadJson.getJSONArray("upload");
- }
- if(array == null){
- throw new Exception("upload.json数据出错");
- }
- JSONObject fileJson = null;
- String fileName = "";
- for(int i = 0, len = array.size(); i < len; i++){
- fileJson = array.getJSONObject(i);
- fileName = fileJson.getString("file");
- //文件不存在抛出异常
- if(!new File(target + File.separator + "results" +File.separator + fileName).exists()){
- throw new Exception(target + File.separator + "results" +File.separator + fileName+"文件不存在");
- }
- //high文件夹
- if(fileJson.getIntValue("clazz") == 3){
- map.put(target + File.separator + "results" +File.separator+ fileName,"images/images"+
- sceneProEntity.getNum()+"/pan/high/"+ fileName.replace("high/", ""));
- continue;
- }
- //low文件夹
- if(fileJson.getIntValue("clazz") == 4){
- map.put(target + File.separator + "results" +File.separator+ fileName,"images/images"+
- sceneProEntity.getNum()+"/pan/low/"+ fileName.replace("low/", ""));
- continue;
- }
- //tiles文件夹,亚马逊没有裁剪图片api,不需要上传4k图
- if(fileJson.getIntValue("clazz") == 5){
- map.put(target + File.separator + "results" + File.separator+ fileName,"images/images"+
- sceneProEntity.getNum()+ File.separator + fileName);
- continue;
- }
- //tiles文件夹,亚马逊瓦片图
- if(fileJson.getIntValue("clazz") == 7 ){
- map.put(target + File.separator + "results" + File.separator+ fileName,"images/images"+
- sceneProEntity.getNum()+ File.separator + fileName);
- continue;
- }
- }
- for(String imagesName : images.list()){
- //覆盖原始图片资源
- FileUtils.copyFile(target + File.separator + "extras/images/" + imagesName,
- path + File.separator + "caches/images/" + imagesName, true);
- FileUtils.deleteFile(target + File.separator + "extras/images/" + imagesName);
- }
- }
- if(video.exists() && video.listFiles() != null && video.listFiles().length > 0){
- for(String videoName : video.list()){
- fYunFileService.uploadFile(target + File.separator + "extras/video/" + videoName,"video/video"+
- sceneProEntity.getNum()+ File.separator + videoName);
- CreateObjUtil.mp4ToFlv(target + File.separator + "extras/video/" + videoName,
- target + File.separator + "extras/video/" + videoName.replace("mp4", "flv"));
- fYunFileService.uploadFile(target + File.separator + "extras/video/" + videoName.replace("mp4", "flv"),"video/video"+
- sceneProEntity.getNum()+ File.separator + videoName.replace("mp4", "flv"));
- //覆盖原始视频资源
- FileUtils.copyFile(target + File.separator + "extras/video/" + videoName,
- path + File.separator + "caches/videos/" + videoName, true);
- }
- FileUtils.deleteDirectory(target + File.separator + "extras/video/");
- }
- // 清除马赛克数据
- if(scenejson.containsKey("planId")){
- String[] planIds = scenejson.getString("planId").split(",");
- String mosaicDatasTr = sceneProEntity.getMosaics();
- JSONArray jsonArray = new JSONArray();
- if(!ObjectUtils.isEmpty(mosaicDatasTr)){
- jsonArray = JSONArray.parseArray(mosaicDatasTr);
- }
- for (String planId : planIds) {
- for (Iterator<Object> iterator = jsonArray.iterator(); iterator.hasNext(); ) {
- JSONObject data = (JSONObject)iterator.next();
- if(org.apache.commons.lang3.StringUtils
- .equals(data.getString("panoId"),planId)){
- iterator.remove();
- }
- }
- }
- sceneProEntity.setMosaics(JSON.toJSONString(jsonArray, SerializerFeature.DisableCircularReferenceDetect));
- scenejson.remove("planId");
- scenejson.put("mosaics",JSON.toJSONString(jsonArray,SerializerFeature.DisableCircularReferenceDetect));
- }
- }else if(scenejson.getIntValue("buildImages") == 2){
- if(video.exists() && video.listFiles() != null && video.listFiles().length > 0){
- for(String videoName : video.list()){
- fYunFileService.uploadFile(target + File.separator + "extras/video/" + videoName,"video/video"+
- sceneProEntity.getNum()+ File.separator + videoName);
- CreateObjUtil.mp4ToFlv(target + File.separator + "extras/video/" + videoName,
- target + File.separator + "extras/video/" + videoName.replace("mp4", "flv"));
- fYunFileService.uploadFile(target + File.separator + "extras/video/" + videoName.replace("mp4", "flv"),"video/video"+
- sceneProEntity.getNum()+ File.separator + videoName.replace("mp4", "flv"));
- //覆盖原始视频资源
- FileUtils.copyFile(target + File.separator + "extras/video/" + videoName,
- path + File.separator + "caches/videos/" + videoName, true);
- }
- FileUtils.deleteDirectory(target + File.separator + "extras/video/");
- }
- }
- scenejson.put("imagesVersion", sceneProEditEntity.getImagesVersion() + 1);
- scenejson.put("buildImages", 0);
- sceneProEditEntity.setImagesVersion(sceneProEditEntity.getImagesVersion() + 1);
- }
- if(scenejson.containsKey("uploadBgMusic") && scenejson.getIntValue("uploadBgMusic") == 1){
- if(StrUtil.isNotEmpty(scenejson.getString("bgMusicName"))){
- map.put(imagesBuffer.toString() + scenejson.getString("bgMusicName"), imagesBuf.toString() + scenejson.getString("bgMusicName"));
- }
- scenejson.put("uploadBgMusic", 0);
- sceneProEditEntity.setBgMusicName(scenejson.getString("bgMusicName"));
- }
- if(scenejson.containsKey("uploadPanoramaImg") && scenejson.getIntValue("uploadPanoramaImg") == 1){
- String targetPath = ConstantFilePath.SCENE_PATH + "images/images" + base.getSceneNum() + "/panorama";
- File panoramafile = new File(targetPath);
- if(panoramafile.exists()){
- for(File targetFile : panoramafile.listFiles()){
- if(targetFile.isDirectory()){
- String target = targetFile.getAbsolutePath();
- String sid = target.substring(target.lastIndexOf(File.separator) + 1);
- //读取upload文件,检验需要上传的文件是否存在
- String uploadData = FileUtils.readFile(target + File.separator + "results" +File.separator+"upload.json");
- JSONObject uploadJson = null;
- JSONArray array = null;
- if(uploadData!=null) {
- uploadJson = JSONObject.parseObject(uploadData);
- array = uploadJson.getJSONArray("upload");
- }
- if(array == null){
- continue;
- }
- JSONObject fileJson = null;
- String fileName = "";
- for(int i = 0, len = array.size(); i < len; i++){
- fileJson = array.getJSONObject(i);
- fileName = fileJson.getString("file");
- //文件不存在抛出异常
- if(!new File(target + File.separator + "results" +File.separator + fileName).exists()){
- throw new Exception(target + File.separator + "results" +File.separator + fileName+"文件不存在");
- }
- //high文件夹
- if(fileJson.getIntValue("clazz") == 3){
- map.put(target + File.separator + "results" +File.separator+ fileName,"images/images"+
- sceneProEntity.getNum()+"/panorama/" + sid + "/pan/high/"+ fileName.replace("high/", ""));
- continue;
- }
- //low文件夹
- if(fileJson.getIntValue("clazz") == 4){
- map.put(target + File.separator + "results" +File.separator+ fileName,"images/images"+
- sceneProEntity.getNum()+"/panorama/" + sid + "/pan/low/"+ fileName.replace("low/", ""));
- continue;
- }
- //tiles文件夹,亚马逊没有裁剪图片api,不需要上传4k图
- if(fileJson.getIntValue("clazz") == 5){
- map.put(target + File.separator + "results" + File.separator+ fileName,"images/images"+
- sceneProEntity.getNum()+ "/panorama/" + sid + File.separator + fileName);
- // uploadToOssUtil.delete("images/images"+ sceneProEntity.getNum()+
- // "/panorama_edit/" + sid + File.separator + fileName);
- continue;
- }
- //tiles文件夹,亚马逊瓦片图
- if(fileJson.getIntValue("clazz") == 7 ){
- map.put(target + File.separator + "results" + File.separator+ fileName,"images/images"+
- sceneProEntity.getNum()+ File.separator + fileName);
- continue;
- }
- }
- }
- }
- }
- scenejson.put("uploadPanoramaImg", 0);
- }
- if(scenejson.containsKey("uploadPanoramaJson") && scenejson.getIntValue("uploadPanoramaJson") == 1){
- scenejson.put("uploadPanoramaJson", 0);
- map.put(dataBuffer.toString() + "link-scene.json", dataBuf.toString() + "link-scene.json");
- sceneProEditEntity.setJumpScene(scenejson.getBooleanValue("jumpScene"));
- }
- log.info("scene.json路径:" + dataBuffer.toString() + "scene.json");
- FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
- if(map.size()>0) {
- fYunFileService.uploadMulFiles(map);
- }
- this.updateById(sceneProEntity);
- sceneProEditService.updateById(sceneProEditEntity);
- return ResultData.ok();
- }
- @Override
- public ResultData uploadFloorplanPng(String sceneNum, MultipartFile[] file, String cadInfo) throws Exception{
- ScenePro sceneProEntity = this.findBySceneNum(sceneNum);
- if(sceneProEntity == null){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
- }
- if (file.length <= 0) {
- throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
- }
- StringBuffer dataBuf = new StringBuffer()
- .append("data").append(File.separator)
- .append("data").append(sceneProEntity.getNum())
- .append(File.separator);
- StringBuffer imagesBuf = new StringBuffer()
- .append("images").append(File.separator)
- .append("images").append(sceneProEntity.getNum())
- .append(File.separator);
- StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
- StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
- //文件上传的位置可以自定义
- String path = ConstantFilePath.SCENE_PATH+"images"+File.separator+"images"+sceneNum;
- File targetFile = new File(path);
- if (!targetFile.exists()) {
- targetFile.mkdirs();
- }
- String fileName = "";
- JSONArray floorPlanPngArr = new JSONArray();
- for (MultipartFile multipartFile : file) {
- fileName = multipartFile.getOriginalFilename();
- targetFile = new File(path + File.separator + fileName);
- // 保存
- synchronized(this)
- {
- if(targetFile.exists())
- {
- FileUtils.deleteFile(path + File.separator + fileName);
- }
- multipartFile.transferTo(targetFile);
- }
- floorPlanPngArr.add("images"+File.separator+"images"+sceneNum + File.separator + fileName);
- }
- String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
- JSONObject scenejson = new JSONObject();
- if(strsceneInfos!=null) {
- scenejson = JSONObject.parseObject(strsceneInfos);
- }
- Map<String, Object> map = new HashMap<>();
- map.put("floorPlanPng", floorPlanPngArr);
- map.put("uploadFloorPlanPng", 1);
- map.put("version", scenejson.getIntValue("version")+1);
- if(StrUtil.isNotEmpty(cadInfo)){
- map.put("cadInfo", cadInfo);
- }
- FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map);
- return ResultData.ok(floorPlanPngArr);
- }
- @Override
- public ResultData uploadFloorJson(RequestSceneEdit sceneEdit) throws Exception {
- String lock = sceneEdit.getSceneNum().toString().intern();
- synchronized(lock){
- long start = System.currentTimeMillis();
- log.info("画墙重建模型开始时间:" + start);
- if(org.apache.commons.lang3.StringUtils.isEmpty(sceneEdit.getSceneNum())){
- throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
- }
- ScenePro sceneProEntity = this.findBySceneNum(sceneEdit.getSceneNum());
- if(sceneProEntity == null){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
- }
- SceneProEdit sceneProEditEntity = sceneProEditService.findBySceneProId(sceneProEntity.getId());
- if(sceneProEditEntity == null){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
- }
- //更新scene.json文件
- String strsceneInfos = FileUtils.readFile(ConstantFilePath.SCENE_PATH + "data" + File.separator + "data" + sceneEdit.getSceneNum() + File.separator + "scene.json");
- JSONObject scenejson = new JSONObject();
- if(strsceneInfos!=null)
- {
- scenejson = JSONObject.parseObject(strsceneInfos);
- }else {
- new File(ConstantFilePath.SCENE_PATH + "data" + File.separator + "data" + sceneEdit.getSceneNum() + File.separator + "scene.json").createNewFile();
- }
- if(!org.apache.commons.lang3.StringUtils.isEmpty(sceneEdit.getSceneData())){
- JSONObject sceneObject = JSONObject.parseObject(sceneEdit.getSceneData());
- Set<String> set =sceneObject.keySet();
- for(String key : set){
- scenejson.put(key, sceneObject.get(key));
- }
- }
- //保存floor.json前端下次进入需要使用
- if(org.apache.commons.lang3.StringUtils.isEmpty(sceneEdit.getWebFloor())){
- sceneEdit.setWebFloor(sceneEdit.getFloor());
- }
- //上传过模型只更新floor.json
- // if(scenejson.containsKey("isUploadObj") && scenejson.getBooleanValue("isUploadObj")){
- FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+sceneEdit.getSceneNum() + File.separator + "floor.json", new String(sceneEdit.getWebFloor().getBytes(), "UTF-8"));
- //更新scene.json文件
- if(strsceneInfos!=null)
- {
- scenejson.put("floorEditVer", sceneProEditEntity.getFloorEditVer() + 1);
- scenejson.put("floorPublishVer", sceneProEditEntity.getFloorPublishVer());
- FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+sceneEdit.getSceneNum()+File.separator+"scene.json", scenejson.toString());
- log.info("写入scene.json文件完成——"+sceneEdit.getSceneNum());
- }
- //floorEditVer字段增加1
- sceneProEditEntity.setFloorEditVer(sceneProEditEntity.getFloorEditVer() + 1);
- sceneProEditService.updateById(sceneProEditEntity);
- String path = sceneProEntity.getDataSource();
- if(path != null && !"".equals(path) && path.startsWith("http")){
- path = ConstantFilePath.BUILD_MODEL_PATH + File.separator + path.split("/")[path.split("/").length - 2];
- }
- String target = path + "_edit";
- File editPath = new File(target);
- if(!editPath.exists()){
- editPath.mkdirs();
- }
- //创建文件夹软连接并且复制data.json和project.json
- if(new File(target + File.separator + "capture").exists()){
- new File(target + File.separator + "capture").delete();
- }
- if(new File(target + File.separator + "caches").exists()){
- //删除link
- new File(target + File.separator + "caches" + File.separator + "images").delete();
- //删除所有文件
- FileUtils.delAllFile(target + File.separator + "caches");
- }
- if(new File(target + File.separator + "results").exists()){
- FileUtils.delAllFile(target + File.separator + "results");
- }
- //创建文件夹,并link文件夹
- new File(target + File.separator + "caches").mkdirs();
- CreateObjUtil.createSoftConnection(path + File.separator + "capture", target + File.separator + "capture");
- if(new File(path + File.separator + "caches" + File.separator + "images").exists()){
- CreateObjUtil.createSoftConnection(path + File.separator + "caches" + File.separator + "images", target + File.separator + "caches" + File.separator + "images");
- }
- FileUtils.copyFile(path + File.separator + "data.json", target + File.separator+"data.json", true);
- FileUtils.copyFile(path + File.separator + "project.json", target + File.separator+"project.json", true);
- //data.json增加extras为执行重建算法
- String project = FileUtils.readFile(target + File.separator+"project.json");
- if(project != null){
- JSONObject projectJson = JSONObject.parseObject(project);
- projectJson.put("parent", projectJson.get("uuid"));
- projectJson.put("uuid", UUID.randomUUID().toString());
- projectJson.put("time", System.currentTimeMillis());
- FileUtils.writeFile(path + File.separator + "project.json", projectJson.toString());
- }
- String data = FileUtils.readFile(target + File.separator+"data.json");
- if(data != null){
- JSONObject floorplanJson = new JSONObject();
- floorplanJson.put("has_floorplan_json", true);
- floorplanJson.put("has_vision_txt", true);
- JSONObject dataJson = JSONObject.parseObject(data);
- dataJson.put("extras", floorplanJson);
- //V5表示不需要生成high,low文件
- dataJson.put("skybox_type", "SKYBOX_V5");
- dataJson.put("split_type", "SPLIT_V4");
- FileUtils.writeFile(target + File.separator+"data.json", new String(dataJson.toString().getBytes(), "UTF-8"));
- }
- //文件上传的位置可以自定义
- log.info("画墙重建模型开始");
- File targetFile = new File(target + File.separator + "extras" + File.separator + "floorplan.json");
- if(!targetFile.getParentFile().exists()){
- targetFile.getParentFile().mkdirs();
- }
- if(targetFile.exists()){
- FileUtils.deleteFile(target + File.separator + "extras" + File.separator + "floorplan.json");
- }
- // 保存
- FileUtils.writeFile(target + File.separator + "extras" + File.separator + "floorplan.json", new String(sceneEdit.getFloor().getBytes(), "UTF-8"));
- FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+sceneEdit.getSceneNum() + File.separator + "floor.json", new String(sceneEdit.getWebFloor().getBytes(), "UTF-8"));
- //下载vision.modeldata,解压成vision.txt,并且删除vision.modeldata
- log.info("下载vision.modeldata文件");
- if(FYunTypeEnum.AWS.code().equals(ossType)){
- FileUtils.downLoadFromUrl(ConstantUrl.PREFIX_AWS + "images/images" + sceneEdit.getSceneNum() + "/vision.modeldata" + "?m="+new Date().getTime(),
- "vision.modeldata", target + File.separator + "extras" + File.separator);
- }
- if(FYunTypeEnum.OSS.code().equals(this.ossType)){
- FileUtils.downLoadFromUrl(ossPrefixUrl + "images/images" + sceneEdit.getSceneNum() + "/vision.modeldata" + "?m="+new Date().getTime(),
- "vision.modeldata", target + File.separator + "extras" + File.separator);
- }
- CreateObjUtil.convertVisionmodeldataToTxt(target + File.separator + "extras" + File.separator + "vision.modeldata",
- target + File.separator + "extras" + File.separator + "vision.txt");
- log.info("解压完成,删除vision.modeldata文件");
- FileUtils.deleteFile(target + File.separator + "extras" + File.separator + "vision.modeldata");
- log.info("下载vision2.modeldata文件");
- if(FYunTypeEnum.OSS.code().equals(ossType)){
- FileUtils.downLoadFromUrl(ossPrefixUrl + "images/images" + sceneEdit.getSceneNum() + "/vision2.modeldata" + "?m="+new Date().getTime(),
- "vision2.modeldata", target + File.separator + "extras" + File.separator);
- }
- if(FYunTypeEnum.AWS.code().equals(ossType)){
- FileUtils.downLoadFromUrl(ConstantUrl.PREFIX_AWS + "images/images" + sceneEdit.getSceneNum() + "/vision2.modeldata" + "?m="+new Date().getTime(),
- "vision2.modeldata", target + File.separator + "extras" + File.separator);
- }
- CreateObjUtil.convertVisionmodeldataToTxt(target + File.separator + "extras" + File.separator + "vision2.modeldata",
- target + File.separator + "extras" + File.separator + "vision2.txt");
- log.info("解压完成,删除vision2.modeldata文件");
- FileUtils.deleteFile(target + File.separator + "extras" + File.separator + "vision2.modeldata");
- //重新计算算法
- log.info("重新计算大场景:开始建模——"+sceneEdit.getSceneNum());
- //判断V2还是V3
- if("V2".equals(sceneProEntity.getBuildType())){
- CreateObjUtil.build3dModelOld(target , "1");
- }
- if("V3".equals(sceneProEntity.getBuildType())){
- CreateObjUtil.build3dModel(target , "1");
- }
- log.info("重新计算大场景:开始转换成lzma文件——"+sceneEdit.getSceneNum());
- CreateObjUtil.convertTxtToDam( target + File.separator + "results" + File.separator+"tex"+
- File.separator+"modeldata.txt", target + File.separator + "results" +File.separator+ ConstantFileName.modelUUID+"_50k.dam");
- CreateObjUtil.convertDamToLzma(target + File.separator + "results");
- CreateObjUtil.convertTxtToDam( target + File.separator + "results" +File.separator+"tex"+
- File.separator+"modeldata.txt", target + File.separator + "results" + File.separator+ConstantFileName.modelUUID+"_50k.dam");
- File lzmaFile = new File(target + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k.dam.lzma");
- if(!lzmaFile.exists())
- {
- log.info("lzam文件不存在——"+sceneEdit.getSceneNum());
- Thread.sleep(3000);
- }
- File sceneFile = new File(ConstantFilePath.SCENE_PATH+"images"+File.separator+"images"+sceneEdit.getSceneNum() + File.separator + ConstantFileName.modelUUID + "_50k_texture_jpg_high1");
- if(!sceneFile.exists())
- {
- log.info("high1文件夹不存在——"+sceneEdit.getSceneNum());
- sceneFile.mkdirs();
- }
- //将重新建模的tex里的文件和lzma文件复制到Message.filePath+"images"+File.separator+"images"+sceneNum下。
- List<String> list1 = FileUtils.readfileNamesForDirectory(target+File.separator+ "results" + File.separator +"tex",".jpg");
- if(list1 == null){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
- }
- log.info("新生成的贴图有:——"+list1.size());
- for(int i=0; i<list1.size(); ++i)
- {
- String imgName = list1.get(i);
- FileUtils.copyFile(target+File.separator + "results" + File.separator+"tex"+File.separator+imgName,
- ConstantFilePath.SCENE_PATH+"images"+File.separator+"images"+sceneEdit.getSceneNum() + File.separator + ConstantFileName.modelUUID + "_50k_texture_jpg_high1"+File.separator+imgName, true);
- }
- FileUtils.copyFile(target+File.separator + "results" + File.separator +ConstantFileName.modelUUID+"_50k.dam",
- ConstantFilePath.SCENE_PATH+"images"+File.separator+"images"+sceneEdit.getSceneNum() + File.separator + ConstantFileName.modelUUID+"_50k.dam", true);
- log.info("文件复制到本地ecs完成——"+sceneEdit.getSceneNum());
- //更新scene.json文件
- if(strsceneInfos!=null)
- {
- scenejson.put("floorEditVer", sceneProEditEntity.getFloorEditVer() + 1);
- scenejson.put("floorPublishVer", sceneProEditEntity.getFloorPublishVer());
- FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+sceneEdit.getSceneNum()+File.separator+"scene.json", scenejson.toString());
- log.info("写入scene.json文件完成——"+sceneEdit.getSceneNum());
- }
- //floorEditVer字段增加1
- sceneProEditEntity.setFloorEditVer(sceneProEditEntity.getFloorEditVer() + 1);
- sceneProEditService.updateById(sceneProEditEntity);
- log.info("修改数据库完成——"+sceneEdit.getSceneNum());
- log.info("花费时间:" + (System.currentTimeMillis() - start));
- }
- return ResultData.ok();
- }
- @Override
- public ResultData copyAndUpdateFloorJson(String sceneNum, String floorJsonData) throws Exception{
- StringBuffer dataBuf = new StringBuffer().append("data").append(File.separator).append("data").append(sceneNum).append(File.separator);
- StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
- if(StrUtil.isEmpty(floorJsonData)){
- ScenePro sceneProEntity = this.findBySceneNum(sceneNum);
- if(sceneProEntity == null){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
- }
- FileUtils.copyFile(sceneProEntity.getDataSource() + "/results/floor.json", dataBuffer.toString() + "houst_floor.json", true);
- fYunFileService.uploadFile(dataBuffer.toString() + "houst_floor.json", dataBuf.toString() + "houst_floor.json");
- String result = FileUtils.readFile(dataBuffer.toString() + "houst_floor.json");
- return ResultData.ok(result);
- }
- FileUtils.writeFile(dataBuffer.toString() + "houst_floor.json", floorJsonData);
- fYunFileService.uploadFile(dataBuffer.toString() + "houst_floor.json", dataBuf.toString() + "houst_floor.json");
- return ResultData.ok(floorJsonData);
- }
- @Override
- @SystemServiceLog(description = "保存场景热点")
- public ResultData saveHot(RequestSceneEdit base) throws Exception {
- if(StrUtil.isEmpty(base.getType())){
- throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
- }
- String sid = base.getSid();
- ScenePro sceneProEntity = this.findBySceneNum(base.getSceneNum());
- if (sceneProEntity == null ) {
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
- }
- JSONObject jsonhot = JSONObject.parseObject(base.getHotData());
- StringBuffer dataBuf = new StringBuffer()
- .append("data").append(File.separator)
- .append("data").append(sceneProEntity.getNum())
- .append(File.separator);
- StringBuffer imagesBuf = new StringBuffer()
- .append("images").append(File.separator)
- .append("images").append(sceneProEntity.getNum())
- .append(File.separator);
- StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
- StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
- String str = FileUtils.readFile(dataBuffer.toString() + "hot.json");
- JSONArray jsonhots = null;
- if (org.apache.commons.lang3.StringUtils.isNotEmpty(str)) {
- jsonhots = JSONArray.parseArray(str);
- }else {
- File file = new File(dataBuffer.toString() + "hot.json");
- if(!file.getParentFile().exists()){
- file.getParentFile().mkdirs();
- }
- if(!file.exists()){
- file.createNewFile();
- }
- jsonhots = new JSONArray();
- }
- //添加或者修改
- if("1".equals(base.getType())){
- sid = jsonhot.getString("sid");
- if(StrUtil.isEmpty(sid)){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
- }
- jsonhots.add(jsonhot);
- }
- else if("0".equals(base.getType())){
- sid = jsonhot.getString("sid");
- if(StrUtil.isEmpty(sid)){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
- }
- }
- else if("-1".equals(base.getType())){
- if(StrUtil.isEmpty(sid)){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
- }
- }
- //判断是否需要删除自定义热点样式
- String[] styles = null;
- if(StrUtil.isNotEmpty(base.getStyleName())){
- styles = base.getStyleName().split(",");
- }
- for(int i=0;i<jsonhots.size();++i){
- JSONObject ele = jsonhots.getJSONObject(i);
- //名字对应上就删除
- if(styles != null){
- for(String style : styles){
- if(style.equals(ele.getString("styleId"))){
- jsonhots.getJSONObject(i).put("styleId", null);
- jsonhots.getJSONObject(i).put("style", "default");
- jsonhots.getJSONObject(i).put("styleImageURL", null);
- }
- }
- }
- if(ele.getString("sid").equals(sid)){
- if("-1".equals(base.getType())){
- jsonhots.remove(i);
- if(ele.containsKey("media")){
- String fileType = ele.getString("media");
- if(fileType.contains("photo"))
- {
- FileUtils.deleteFile(imagesBuffer.toString() + "hot"+sid+".jpg");
- }
- if(fileType.contains("audio") || fileType.contains("voice"))
- {
- FileUtils.deleteFile(imagesBuffer.toString() + "hot"+sid+".mp3");
- }
- if(fileType.contains("video"))
- {
- FileUtils.deleteFile(imagesBuffer.toString() + "hot"+sid+".mp4");
- }
- }
- if(!FYunTypeEnum.AWS.code().equals(this.ossType)){
- JSONObject paramData = new JSONObject();
- paramData.put("hotId", sid);
- JSONObject hotListJson = JSONObject.parseObject(OkHttpUtils.httpGet(hotDomainList));
- if(hotListJson != null){
- JSONArray hotListArray = hotListJson.getJSONArray("data");
- if(hotListArray != null){
- for(int l = 0, len = hotListArray.size(); l < len; l++){
- OkHttpUtils.httpPostJson(hotListArray.getString(l) + hotDelete + "?hotId=" + sid
- , paramData.toJSONString());
- }
- }
- }
- }
- }
- else if("0".equals(base.getType())){
- jsonhots.set(i, jsonhot);
- }
- }
- }
- FileUtils.deleteFile(dataBuffer.toString() + "hot.json");
- File dataPath = new File(dataBuffer.toString());
- if(!dataPath.exists()){
- dataPath.mkdirs();
- }
- FileUtils.writeFile(dataBuffer.toString() + "hot.json", jsonhots.toString());
- String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
- JSONObject scenejson = new JSONObject();
- if(strsceneInfos!=null){
- scenejson = JSONObject.parseObject(strsceneInfos);
- }
- if(jsonhots.size()>0){
- scenejson.put("hots", 1);
- }
- else{
- scenejson.put("hots", 0);
- }
- if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getCapData())){
- FileUtils.writeFile(dataBuffer.toString() + "capData.json", new String(base.getCapData().getBytes(), "UTF-8"));
- scenejson.put("capData", dataBuf.toString() + "capData.json");
- }
- if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getFrameData())){
- FileUtils.writeFile(dataBuffer.toString() + "frameData.json", new String(base.getFrameData().getBytes(), "UTF-8"));
- scenejson.put("frameData", dataBuf.toString() + "frameData.json");
- }
- if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getPlayData())){
- FileUtils.writeFile(dataBuffer.toString() + "playData.json", new String(base.getPlayData().getBytes(), "UTF-8"));
- scenejson.put("playData", dataBuf.toString() + "playData.json");
- }
- if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getScreencapThumb())){
- FileUtils.writeFile(dataBuffer.toString() + "screencapThumb.json", new String(base.getScreencapThumb().getBytes(), "UTF-8"));
- scenejson.put("screencapThumb", dataBuf.toString() + "screencapThumb.json");
- }
- scenejson.put("version", scenejson.getIntValue("version") + 1);
- FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
- return ResultData.ok();
- }
- @Override
- @SystemServiceLog(description = "保存热点可见性的数据")
- public ResultData saveHotVisible(RequestSceneEdit base) throws Exception {
- if(StrUtil.isEmpty(base.getData()) || StrUtil.isEmpty(base.getSceneNum())){
- throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
- }
- ScenePro sceneProEntity = this.findBySceneNum(base.getSceneNum());
- if (sceneProEntity == null ) {
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
- }
- JSONArray visiblePanos = JSONArray.parseArray(base.getData());
- StringBuffer dataBuf = new StringBuffer()
- .append("data").append(File.separator)
- .append("data").append(sceneProEntity.getNum())
- .append(File.separator);
- StringBuffer imagesBuf = new StringBuffer()
- .append("images").append(File.separator)
- .append("images").append(sceneProEntity.getNum())
- .append(File.separator);
- StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
- StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
- File file = new File(dataBuffer.toString() + "hot.json");
- if (!file.exists()) {
- throw new BusinessException(ErrorCode.FAILURE_CODE_3018);
- }
- String str = FileUtils.readFile(dataBuffer.toString() + "hot.json");
- JSONArray hots = JSONArray.parseArray(str);
- for (int i = 0; i < hots.size(); ++i) {
- JSONObject hot = hots.getJSONObject(i);
- for (int j = 0; j < visiblePanos.size(); ++j) {
- if (hot.getString("sid").equals(((JSONObject) visiblePanos.get(j)).getString("sid"))) {
- hot.put("visiblePanos", ((JSONObject) visiblePanos.get(j)).getJSONArray("value"));
- }
- }
- }
- String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
- JSONObject scenejson = new JSONObject();
- if(strsceneInfos!=null){
- scenejson = JSONObject.parseObject(strsceneInfos);
- }
- scenejson.put("version", scenejson.getIntValue("version") + 1);
- FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
- SceneProEdit sceneProEditEntity = sceneProEditService.findBySceneProId(sceneProEntity.getId());
- sceneProEditEntity.setVersion(sceneProEditEntity.getVersion() + 1);
- sceneProEditService.updateById(sceneProEditEntity);
- FileUtils.deleteFile(dataBuffer.toString() + "hot.json");
- FileUtils.writeFile(dataBuffer.toString() + "hot.json", hots.toString());
- return ResultData.ok();
- }
- @Override
- @SystemServiceLog(description = "漫游可行")
- public ResultData saveLinkPano(RequestSceneEdit base) throws Exception {
- if(StrUtil.isEmpty(base.getData()) || StrUtil.isEmpty(base.getSceneNum())){
- throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
- }
- ScenePro sceneProEntity = this.findBySceneNum(base.getSceneNum());
- if (sceneProEntity == null ) {
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
- }
- JSONArray inputData = JSONObject.parseArray(base.getData());
- StringBuffer dataBuf = new StringBuffer()
- .append("data").append(File.separator)
- .append("data").append(sceneProEntity.getNum())
- .append(File.separator);
- StringBuffer imagesBuf = new StringBuffer()
- .append("images").append(File.separator)
- .append("images").append(sceneProEntity.getNum())
- .append(File.separator);
- StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
- File directory = new File(dataBuffer.toString());
- if (!directory.exists()) {
- directory.mkdirs();
- }
- JSONArray inputdata = JSONArray.parseArray(base.getData());
- String modeldataUrl = ossPrefixUrl + imagesBuf.toString() + "vision.modeldata?t=" + System.currentTimeMillis();
- FileUtils.downLoadFromUrl(modeldataUrl, "vision.modeldata", dataBuffer.toString());
- File file = new File(dataBuffer.toString() + "vision.modeldata");
- if(!file.exists()) {
- throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
- }
- ConvertUtils.convertVisionModelDataToTxt(dataBuffer.toString() + "vision.modeldata", dataBuffer.toString() + "vision.json");
- String str = FileUtils.readFile(dataBuffer.toString() + "vision.json");
- JSONObject json = JSONObject.parseObject(str);
- JSONArray panos = json.getJSONArray("sweepLocations");
- for (int i = 0; i < panos.size(); ++i) {
- JSONObject pano = panos.getJSONObject(i);
- for (int j = 0; j < inputData.size(); ++j) {
- JSONObject jo = inputData.getJSONObject(j);
- String currentPanoId = jo.getString("panoID");
- JSONArray visibles = jo.getJSONArray("visibles");
- JSONArray visibles3 = jo.getJSONArray("visibles3");
- if (pano.getString("uuid").equals(currentPanoId)) {
- pano.put("visibles", visibles);
- pano.put("visibles3", visibles3);
- }
- }
- }
- FileUtils.deleteFile(dataBuffer.toString() + "vision.json");
- FileUtils.deleteFile(dataBuffer.toString() + "vision.modeldata");
- FileUtils.writeFile(dataBuffer.toString() + "vision.json", json.toString());
- ConvertUtils.convertTxtToVisionModelData(dataBuffer.toString() + "vision.json", dataBuffer.toString() + "vision.modeldata");
- fYunFileService.uploadFile(dataBuffer.toString() + "vision.modeldata", imagesBuf.toString() + "vision.modeldata");
- String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
- JSONObject scenejson = new JSONObject();
- if(strsceneInfos!=null){
- scenejson = JSONObject.parseObject(strsceneInfos);
- }
- scenejson.put("version", scenejson.getIntValue("version") + 1);
- FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
- SceneProEdit sceneProEditEntity = sceneProEditService.findBySceneProId(sceneProEntity.getId());
- if (sceneProEditEntity == null ) {
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
- }
- sceneProEditEntity.setVersion(scenejson.getIntValue("version") + 1);
- sceneProEditService.updateById(sceneProEditEntity);
- return ResultData.ok();
- }
- @Override
- public ResultData saveInitialPage(RequestSceneEdit base) throws Exception{
- if(StrUtil.isEmpty(base.getSceneNum()) || StrUtil.isEmpty(base.getInitialPoint())){
- throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
- }
- ScenePro sceneProEntity = this.findBySceneNum(base.getSceneNum());
- if(sceneProEntity == null){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
- }
- StringBuffer dataBuf = new StringBuffer()
- .append("data").append(File.separator)
- .append("data").append(sceneProEntity.getNum())
- .append(File.separator);
- StringBuffer imagesBuf = new StringBuffer()
- .append("images").append(File.separator)
- .append("images").append(sceneProEntity.getNum())
- .append(File.separator);
- StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
- StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
- String path1 = imagesBuffer.toString() + "thumbBigImg.jpg";
- String path2 = imagesBuffer.toString() + "thumbSmallImg.jpg";
- //生成缩略图
- //按指定大小把图片进行缩和放(会遵循原图高宽比例)
- //此处把图片压成1024×512的缩略图
- Thumbnails.of(path1).size(1024,512).toFile(path2);//变为1024×512
- String strsceneInfos = FileUtils.readFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneProEntity.getNum() + File.separator + "scene.json");
- JSONObject scenejson = new JSONObject();
- if(strsceneInfos!=null) {
- scenejson = JSONObject.parseObject(strsceneInfos);
- }
- Map map = new HashMap();
- map.put("entry", JSONObject.parseObject(base.getInitialPoint()));
- map.put("thumbImg", 1);
- map.put("version", scenejson.getIntValue("version")+1);
- FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map);
- return ResultData.ok();
- }
- @Override
- public ResultData uploadScreencapVoiceNewV3(String sceneNum, String type, String fileName, MultipartFile file, String length, String replace, String times, String index) throws Exception{
- if(StrUtil.isEmpty(sceneNum)){
- throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
- }
- ScenePro sceneProEntity = this.findBySceneNum(sceneNum);
- if(sceneProEntity == null){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
- }
- if (!file.isEmpty()&& file.getSize() <= 0) {
- throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
- }
- //文件上传的位置可以自定义
- String path = ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+sceneNum;
- File targetFile = new File(path);
- if (!targetFile.exists()) {
- targetFile.mkdirs();
- }
- String originalFileName = "sound201810.mp3";
- String strsceneInfos = FileUtils.readFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json");
- JSONObject scenejson = new JSONObject();
- if(strsceneInfos!=null) {
- scenejson = JSONObject.parseObject(strsceneInfos);
- }
- if("soundsync".equals(type) && !"1".equals(replace)){
- //判断分房间模块文件夹是否存在
- String partPath = path + File.separator + "part";
- File partFile = new File(partPath);
- if(!partFile.exists()){
- partFile.mkdirs();
- }
- synchronized(this){
- targetFile = new File(partPath + File.separator + fileName);
- if(targetFile.exists())
- {
- FileUtils.deleteFile(partPath + File.separator + fileName);
- }
- file.transferTo(targetFile);
- }
- //获取总音频多少段,每段时长
- String[] time = times.split(",");
- //遍历判断音频是否存在,不存在生成空白音效
- for(int i = 0, len = time.length; i < len; i++){
- if(!new File(partPath + File.separator + i + ".mp3").exists()){
- //某部分文件不存在,直接生成一段静音后拼接文件
- CreateObjUtil.createMuteViode(Double.valueOf(time[i]), partPath + File.separator + i + ".mp3");
- }
- }
- //拼接所有音频文件
- if(time.length > 2){
- //若是多部分,两个两个合并,最后合成最终文件
- for(int i = 1, len = time.length; i < len; i++){
- if(i == 1){
- // FileUtils.deleteFile(partPath + File.separator + i + "muteSound.mp3");
- CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + ".mp3", partPath + File.separator + i + ".mp3",
- partPath + File.separator + i + "muteSound.mp3");
- }else if(i == len - 1){
- CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + "muteSound.mp3", partPath + File.separator + i + ".mp3",
- path + File.separator + originalFileName);
- }else {
- CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + "muteSound.mp3", partPath + File.separator + i + ".mp3",
- partPath + File.separator + i + "muteSound.mp3");
- }
- }
- }else {
- //若只有两部分,直接合并成最终文件
- CreateObjUtil.mergeVideo(partPath + File.separator + "0.mp3", partPath + File.separator + "1.mp3", path + File.separator + originalFileName);
- }
- Map map = new HashMap();
- map.put("screencapVoiceSoundsyncFileName", originalFileName);
- String proVideo = "voice/voice"+sceneNum+"/"+originalFileName;
- map.put("screencapVoiceSoundsync", proVideo);
- map.put("uploadVoiceSoundsync", 1);
- map.put("screencapVoiceType", type);
- map.put("version", scenejson.getIntValue("version")+1);
- FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map);
- return ResultData.ok("voice/voice"+sceneNum+"/"+originalFileName);
- }
- String name = "201810.wav";
- targetFile = new File(path + File.separator +name);
- // 保存
- synchronized(this){
- if(targetFile.exists())
- {
- FileUtils.deleteFile(path + File.separator + name);
- }
- file.transferTo(targetFile);
- }
- Map map = new HashMap();
- if("soundsync".equals(type)){
- FileUtils.delAllFile(path + File.separator + "part");
- //判断分房间模块文件夹是否存在
- String partPath = path + File.separator + "part";
- File partFile = new File(partPath);
- if(!partFile.exists()){
- partFile.mkdirs();
- }
- //保存0.mp3文件到part
- FileUtils.copyFile(path + File.separator +name, partPath + File.separator + fileName, true);
- FileUtils.changeVoiceToMp3(path + File.separator + name, path + File.separator + originalFileName);
- map.put("screencapVoiceSoundsyncFileName", originalFileName);
- String proVideo = "voice/voice"+sceneNum+"/"+originalFileName;
- map.put("screencapVoiceSoundsync", proVideo);
- map.put("uploadVoiceSoundsync", 1);
- map.put("version", scenejson.getIntValue("version")+1);
- map.put("screencapVoiceType", type);
- FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map);
- return ResultData.ok(proVideo);
- }
- FileUtils.changeVoiceToMp3(path + File.separator + name, path + File.separator +"201810.mp3");
- map.put("screencapVoiceFileName", file.getOriginalFilename());
- String voiceSrc = "voice/voice"+sceneNum+"/"+"201810.mp3";
- map.put("screencapVoiceSrc", voiceSrc);
- map.put("uploadVoiceSrc", 1);
- map.put("version", scenejson.getIntValue("version")+1);
- map.put("screencapVoiceType", type);
- FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map);
- return ResultData.ok(voiceSrc);
- }
- @Override
- public ResultData deleteScreencapVoice(RequestSceneEdit base) throws Exception{
- if(StrUtil.isEmpty(base.getSceneNum())){
- throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
- }
- ScenePro sceneProEntity = this.findBySceneNum(base.getSceneNum());
- if(sceneProEntity == null){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
- }
- String scenePath = ConstantFilePath.SCENE_PATH+ "data" + File.separator+"data"+base.getSceneNum()+File.separator+"scene.json";
- String str = FileUtils.readFile(scenePath);
- JSONObject json = new JSONObject();
- if(str!=null){
- json = JSONObject.parseObject(str);
- }
- else{
- File file = new File(scenePath);
- if(!file.getParentFile().exists())
- {
- file.getParentFile().mkdirs();
- }
- if(!file.exists())
- {
- file.createNewFile();
- }
- }
- log.info("type:" + base.getType());
- if("soundsync".equals(base.getType())){
- FileUtils.deleteFile(ConstantFilePath.SCENE_PATH+json.getString("screencapVoiceSoundsync"));
- json.put("screencapVoiceSoundsyncFileName", "");
- json.put("screencapVoiceSoundsync", "");
- json.put("version", json.getIntValue("version")+1);
- FileUtils.deleteFile(scenePath);
- FileUtils.writeFile(scenePath, json.toString());
- return ResultData.ok();
- }
- if("sound".equals(base.getType())){
- FileUtils.deleteFile(ConstantFilePath.SCENE_PATH+json.getString("screencapVoiceSound"));
- json.put("screencapVoiceSoundFileName", "");
- json.put("screencapVoiceSound", "");
- json.put("version", json.getIntValue("version")+1);
- FileUtils.deleteFile(scenePath);
- FileUtils.writeFile(scenePath, json.toString());
- return ResultData.ok();
- }
- String path = ConstantFilePath.SCENE_PATH+json.getString("screencapVoiceSrc");
- log.info("path:" + ConstantFilePath.SCENE_PATH+json.getString("screencapVoiceSrc"));
- FileUtils.deleteFile(path);
- json.put("screencapVoiceFileName", "");
- json.put("screencapVoiceSrc", "");
- json.put("version", json.getIntValue("version")+1);
- log.info("scenePath:" + scenePath);
- FileUtils.deleteFile(scenePath);
- FileUtils.writeFile(scenePath, json.toString());
- return ResultData.ok();
- }
- @Override
- public ResultData deleteScreencapVoicePart(String sceneNum, String fileName, String times, String index) throws Exception {
- if(StrUtil.isEmpty(sceneNum)){
- throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
- }
- ScenePro sceneProEntity = this.findBySceneNum(sceneNum);
- if(sceneProEntity == null){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
- }
- //文件上传的位置可以自定义
- String path = ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+sceneNum;
- File targetFile = new File(path);
- if (!targetFile.exists()) {
- targetFile.mkdirs();
- }
- String originalFileName = "sound201810.mp3";
- log.info("上传的音频文件名:" + originalFileName);
- String strsceneInfos = FileUtils.readFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json");
- JSONObject scenejson = new JSONObject();
- if(strsceneInfos!=null) {
- scenejson = JSONObject.parseObject(strsceneInfos);
- }
- //判断分房间模块文件夹是否存在
- String partPath = path + File.separator + "part";
- File partFile = new File(partPath);
- if(!partFile.exists()){
- partFile.mkdirs();
- }
- //删除指定部分音频文件
- FileUtils.deleteFile(partPath + File.separator + index + ".mp3");
- //获取总音频多少段,每段时长
- String[] time = times.split(",");
- //修改删除的部分视频后面部分音频名字,如删除1.MP3,则将2.mp3修改成1.mp3,往后以此类推
- if(Integer.parseInt(index) < time.length) {
- for(int i = 0, len = time.length - Integer.parseInt(index); i < len; i++){
- if(new File(partPath + File.separator + (Integer.parseInt(index) + 1 + i) + ".mp3").exists()){
- FileUtils.copyFile(partPath + File.separator + (Integer.parseInt(index) + 1 + i) + ".mp3",
- partPath + File.separator + (Integer.parseInt(index) + i) + ".mp3", true);
- }
- }
- }
- //遍历判断音频是否存在,不存在生成空白音效
- for(int i = 0, len = time.length; i < len; i++){
- if(!new File(partPath + File.separator + i + ".mp3").exists()){
- //某部分文件不存在,直接生成一段静音后拼接文件
- CreateObjUtil.createMuteViode(Double.valueOf(time[i]), partPath + File.separator + i + ".mp3");
- }
- }
- //拼接所有音频文件
- if(time.length > 2){
- //若是多部分,两个两个合并,最后合成最终文件
- for(int i = 1, len = time.length; i < len; i++){
- if(i == 1){
- // FileUtils.deleteFile(partPath + File.separator + i + "muteSound.mp3");
- CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + ".mp3", partPath + File.separator + i + ".mp3",
- partPath + File.separator + i + "muteSound.mp3");
- }else if(i == len - 1){
- CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + "muteSound.mp3", partPath + File.separator + i + ".mp3",
- path + File.separator + originalFileName);
- }else {
- CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + "muteSound.mp3", partPath + File.separator + i + ".mp3",
- partPath + File.separator + i + "muteSound.mp3");
- }
- }
- }else if(time.length == 2){
- //若只有两部分,直接合并成最终文件
- CreateObjUtil.mergeVideo(partPath + File.separator + "0.mp3", partPath + File.separator + "1.mp3", path + File.separator + originalFileName);
- }else {
- FileUtils.copyFile(partPath + File.separator + "0.mp3", path + File.separator + originalFileName, true);
- }
- Map map = new HashMap();
- map.put("screencapVoiceSoundsyncFileName", originalFileName);
- String proVideo = "voice/voice"+sceneNum+"/"+originalFileName;
- map.put("screencapVoiceSoundsync", proVideo);
- map.put("uploadVoiceSoundsync", 1);
- map.put("screencapVoiceType", "soundsync");
- map.put("version", scenejson.getIntValue("version")+1);
- FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map);
- return ResultData.ok("voice/voice"+sceneNum+"/"+originalFileName);
- }
- @Override
- public ResultData uploadOverlayMedia(String sceneNum, MultipartFile file, String sid) throws Exception {
- if(StrUtil.isEmpty(sceneNum)){
- throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
- }
- ScenePro sceneProEntity = this.findBySceneNum(sceneNum);
- if(sceneProEntity == null){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
- }
- String fileName = "overlay" + sid + ".mp4";
- if (!file.isEmpty()){
- String path = ConstantFilePath.SCENE_PATH + "images" + File.separator + "images" + sceneNum;
- File targetFile = new File(path);
- if (!targetFile.exists()){
- targetFile.mkdirs();
- }
- targetFile = new File(path + File.separator + fileName);
- if (targetFile.exists()){
- FileUtils.deleteFile(path + File.separator + fileName);
- }
- file.transferTo(targetFile);
- CreateObjUtil.mp4ToFlv(path + File.separator + fileName, path + File.separator + fileName.replace("mp4", "flv"));
- fYunFileService.uploadFile(path + File.separator + fileName, "images"+File.separator+"images"+sceneNum + File.separator + fileName);
- fYunFileService.uploadFile(path + File.separator + fileName.replace("mp4", "flv"), "images"+File.separator+"images"+sceneNum + File.separator + fileName.replace("mp4", "flv"));
- }
- return ResultData.ok(fileName);
- }
- @Override
- public ResultData saveOverlay(RequestSceneEdit base) throws Exception {
- if(StrUtil.isEmpty(base.getType())){
- throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
- }
- String sid = base.getSid();
- ScenePro sceneProEntity = this.findBySceneNum(base.getSceneNum());
- if (sceneProEntity == null ) {
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
- }
- SceneProEdit sceneProEditEntity = sceneProEditService.findBySceneProId(sceneProEntity.getId());
- if (sceneProEditEntity == null ) {
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
- }
- //需要操作的数据
- JSONObject jsonOverlay = JSONObject.parseObject(base.getOverlayData());
- StringBuffer dataBuf = new StringBuffer()
- .append("data").append(File.separator)
- .append("data").append(sceneProEntity.getNum())
- .append(File.separator);
- StringBuffer imagesBuf = new StringBuffer()
- .append("images").append(File.separator)
- .append("images").append(sceneProEntity.getNum())
- .append(File.separator);
- StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
- StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
- String str = sceneProEditEntity.getOverlay();
- JSONArray jsonOverlays = null;
- if (org.apache.commons.lang3.StringUtils.isNotEmpty(str)) {
- jsonOverlays = JSONArray.parseArray(str);
- }else {
- jsonOverlays = new JSONArray();
- }
- //添加或者修改
- if("1".equals(base.getType())){
- sid = jsonOverlay.getString("sid");
- if(StrUtil.isEmpty(sid)){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
- }
- jsonOverlays.add(jsonOverlay);
- }
- else if("0".equals(base.getType())){
- sid = jsonOverlay.getString("sid");
- if(StrUtil.isEmpty(sid)){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
- }
- }
- else if("-1".equals(base.getType())){
- if(StrUtil.isEmpty(sid)){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
- }
- }
- for(int i=0;i<jsonOverlays.size();++i){
- JSONObject ele = jsonOverlays.getJSONObject(i);
- if(ele.getString("sid").equals(sid)){
- if("-1".equals(base.getType())){
- jsonOverlays.remove(i);
- if(ele.containsKey("media")){
- String fileType = ele.getString("media");
- if(fileType.contains("photo"))
- {
- FileUtils.deleteFile(imagesBuffer.toString() + "overlay"+sid+".jpg");
- }
- if(fileType.contains("audio") || fileType.contains("voice"))
- {
- FileUtils.deleteFile(imagesBuffer.toString() + "overlay"+sid+".mp3");
- }
- if(fileType.contains("video"))
- {
- FileUtils.deleteFile(imagesBuffer.toString() + "overlay"+sid+".mp4");
- }
- }
- }
- else if("0".equals(base.getType())){
- jsonOverlays.set(i, jsonOverlay);
- }
- break;
- }
- }
- String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
- JSONObject scenejson = new JSONObject();
- if(strsceneInfos!=null){
- scenejson = JSONObject.parseObject(strsceneInfos);
- }
- scenejson.put("overlay", jsonOverlays.toString());
- scenejson.put("version", scenejson.getIntValue("version") + 1);
- FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
- sceneProEditEntity.setVersion(scenejson.getIntValue("version") + 1);
- sceneProEditEntity.setOverlay(jsonOverlays.toString());
- sceneProEditService.updateById(sceneProEditEntity);
- return ResultData.ok();
- }
- @Override
- public ResultData uploadHotJsonToOss(String sceneNum) throws Exception {
- if(StrUtil.isEmpty(sceneNum)){
- throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
- }
- String path = ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+sceneNum;
- fYunFileService.uploadFile(path + File.separator + "hot.json", "data"+File.separator+"data"+sceneNum + File.separator + "hot.json");
- return ResultData.ok();
- }
- @Override
- public ResultData saveJsonData(String sceneNum, String fileName, String jsonData) throws Exception {
- if(StrUtil.isEmpty(sceneNum) || StrUtil.isEmpty(fileName) || StrUtil.isEmpty(jsonData)){
- throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
- }
- ScenePro sceneProEntity = this.findBySceneNum(sceneNum);
- if(sceneProEntity == null){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
- }
- StringBuffer dataBuf = new StringBuffer()
- .append("data").append(File.separator)
- .append("data").append(sceneProEntity.getNum())
- .append(File.separator);
- StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
- FileUtils.writeFile(dataBuffer.toString() + fileName, jsonData);
- return ResultData.ok("scene/" + dataBuf.toString() + fileName);
- }
- @Override
- public ResultData savePanorama(String sceneNum, String sid, MultipartFile file, String imagesName) throws Exception {
- if(StrUtil.isEmpty(sceneNum) || StrUtil.isEmpty(sid)){
- throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
- }
- ScenePro sceneProEntity = this.findBySceneNum(sceneNum);
- if(sceneProEntity == null){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
- }
- StringBuffer dataBuf = new StringBuffer()
- .append("data").append(File.separator)
- .append("data").append(sceneProEntity.getNum())
- .append(File.separator);
- StringBuffer imagesBuf = new StringBuffer()
- .append("images").append(File.separator)
- .append("images").append(sceneProEntity.getNum())
- .append(File.separator);
- StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
- StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
- String path = sceneProEntity.getDataSource();
- String target = imagesBuffer.toString() + "panorama/" + sid;
- FileUtils.deleteDirectory(target);
- //文件上传的位置可以自定义
- String filePath = target + File.separator + "extras/images" + File.separator + imagesName;
- File targetFile = new File(filePath);
- if(!targetFile.getParentFile().exists()){
- targetFile.getParentFile().mkdirs();
- }
- //上传文件
- file.transferTo(targetFile);
- //调用算法切全景图
- FileUtils.copyFile(path + File.separator + "data.json", target + File.separator+"data.json", true);
- FileUtils.copyFile(path + File.separator + "project.json", target + File.separator+"project.json", true);
- JSONObject visionJson = new JSONObject();
- JSONArray visionArray = new JSONArray();
- visionJson.put("uuid", imagesName.substring(0, imagesName.lastIndexOf(".")));
- visionJson.put("group", 1);
- visionJson.put("subgroup", 0);
- visionArray.add(visionJson);
- JSONObject vision = new JSONObject();
- vision.put("sweepLocations", visionArray);
- FileUtils.writeFile(target + "/extras" + File.separator + "vision.txt", new String(vision.toString().getBytes(), "UTF-8"));
- //data.json增加extras为执行重建算法
- String data = FileUtils.readFile(target + File.separator + "data.json");
- if(data != null){
- JSONObject floorplanJson = new JSONObject();
- floorplanJson.put("has_source_images", true);
- floorplanJson.put("has_vision_txt", true);
- JSONObject dataJson = JSONObject.parseObject(data);
- dataJson.put("extras", floorplanJson);
- //V5表示不需要生成high,low文件
- dataJson.put("skybox_type", "SKYBOX_V6");
- if(sceneProEntity.getSceneScheme() == 11){
- dataJson.put("skybox_type", "SKYBOX_V7");
- }
- dataJson.put("split_type", "SPLIT_V8");
- if(sceneProEntity.getSceneScheme() == 3){
- dataJson.put("skybox_type", "SKYBOX_V4");
- }
- FileUtils.writeFile(target + File.separator+"data.json", new String(dataJson.toString().getBytes(), "UTF-8"));
- }
- //创建文件夹软连接并且复制data.json和project.json
- if(new File(target + File.separator + "capture").exists()){
- new File(target + File.separator + "capture").delete();
- }
- if(new File(target + File.separator + "results").exists()){
- FileUtils.delAllFile(target + File.separator + "results");
- }
- //下载data.fdage
- if(FYunTypeEnum.AWS.code().equals(this.ossType)){
- //亚马逊保持旧方式,超链接capture
- CreateObjUtil.createSoftConnection(path + File.separator + "capture", target + File.separator + "capture");
- }
- CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + path.replace(ConstantFilePath.BUILD_MODEL_PATH, "") + "/data.fdage", target + File.separator + "capture/");
- CreateObjUtil.build3dModel(target , "1");
- //读取upload文件,检验需要上传的文件是否存在
- String uploadData = FileUtils.readFile(target + File.separator + "results" +File.separator+"upload.json");
- JSONObject uploadJson = null;
- JSONArray array = null;
- if(uploadData!=null) {
- uploadJson = JSONObject.parseObject(uploadData);
- array = uploadJson.getJSONArray("upload");
- }
- if(array == null){
- log.info("计算全景图失败,没有upload.json");
- }
- Map<String, String> map = new HashMap<>();
- JSONObject fileJson = null;
- String fileName = "";
- String img = "";
- for(int i = 0, len = array.size(); i < len; i++){
- fileJson = array.getJSONObject(i);
- fileName = fileJson.getString("file");
- //文件不存在抛出异常
- if(!new File(target + File.separator + "results" +File.separator + fileName).exists()){
- throw new Exception(target + File.separator + "results" +File.separator + fileName+"文件不存在");
- }
- //low文件夹
- if(fileJson.getIntValue("clazz") == 4){
- img = "/results" + File.separator + fileName;
- map.put(target + File.separator + "results" +File.separator+ fileName,"images/images"+
- sceneProEntity.getNum()+"/pan/low/"+ fileName.replace("low/", ""));
- continue;
- }
- //tiles文件夹,亚马逊没有裁剪图片api,不需要上传4k图
- if(fileJson.getIntValue("clazz") == 5){
- map.put(target + File.separator + "results" + File.separator+ fileName,"images/images"+
- sceneProEntity.getNum()+ "/panorama_edit/" + sid + File.separator + fileName);
- }
- //tiles文件夹,亚马逊瓦片图
- if(fileJson.getIntValue("clazz") == 7 ){
- map.put(target + File.separator + "results" + File.separator+ fileName,"images/images"+
- sceneProEntity.getNum()+ File.separator + fileName);
- }
- }
- //上传全景图
- map.put(filePath, "images/images"+ sceneProEntity.getNum()+ File.separator + "pan/high/" + imagesName);
- fYunFileService.uploadMulFiles(map);
- String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
- JSONObject scenejson = new JSONObject();
- if(strsceneInfos!=null) {
- scenejson = JSONObject.parseObject(strsceneInfos);
- }
- scenejson.put("uploadPanoramaImg", 1);
- scenejson.put("version", scenejson.getIntValue("version") + 1);
- FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
- Map<String, String> result = new HashMap<>();
- result.put("type", sceneProEntity.getSceneScheme() == 11? "2k" : "4k");
- result.put("img", "scene/" + imagesBuf.toString() + "panorama/" + sid + img);
- result.put("path", "images/images"+ sceneProEntity.getNum()+ "/panorama_edit/" + sid);
- return ResultData.ok(result);
- }
- @Override
- public ResultData savePanoramaJson(String sceneNum, String fileData, String fileName, String sid) throws Exception {
- if(org.apache.commons.lang3.StringUtils
- .isEmpty(sceneNum) || org.apache.commons.lang3.StringUtils.isEmpty(fileName)){
- throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
- }
- ScenePro sceneProEntity = this.findBySceneNum(sceneNum);
- if(sceneProEntity == null){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
- }
- StringBuffer dataBuf = new StringBuffer()
- .append("data").append(File.separator)
- .append("data").append(sceneProEntity.getNum())
- .append(File.separator);
- StringBuffer imagesBuf = new StringBuffer()
- .append("images").append(File.separator)
- .append("images").append(sceneProEntity.getNum())
- .append(File.separator);
- StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
- StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
- FileUtils.writeFile(dataBuffer.toString() + fileName, fileData);
- String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
- JSONObject scenejson = new JSONObject();
- if(strsceneInfos!=null) {
- scenejson = JSONObject.parseObject(strsceneInfos);
- }
- scenejson.put("uploadPanoramaJson", 1);
- scenejson.put("version", scenejson.getIntValue("version") + 1);
- if(org.apache.commons.lang3.StringUtils.isNotEmpty(fileData)){
- scenejson.put("jumpScene", true);
- }else {
- scenejson.put("jumpScene", false);
- }
- FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
- if(org.apache.commons.lang3.StringUtils.isNotEmpty(sid)){
- String target = imagesBuffer.toString() + "panorama/" + sid;
- FileUtils.deleteDirectory(target);
- // uploadToOssUtil.deleteFile(imagesBuf.toString() + "panorama/" + sid);
- fYunFileService.deleteFolder(imagesBuf.toString() + "panorama_edit/" + sid);
- }
- return ResultData.ok();
- }
- @Override
- public ResultData updateFloorJson(String sceneNum, String floorJsonData) throws Exception{
- if(StrUtil.isEmpty(sceneNum) || StrUtil.isEmpty(floorJsonData)){
- throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
- }
- StringBuffer dataBuf = new StringBuffer()
- .append("data").append(File.separator)
- .append("data").append(sceneNum)
- .append(File.separator);
- StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
- String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
- JSONObject scenejson = new JSONObject();
- if(strsceneInfos!=null) {
- scenejson = JSONObject.parseObject(strsceneInfos);
- }
- scenejson.put("uploadFloorJson", 1);
- scenejson.put("version", scenejson.getIntValue("version") + 1);
- FileUtils.writeFile(dataBuffer.toString() + "floor.json", floorJsonData);
- FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toJSONString());
- return ResultData.ok(floorJsonData);
- }
- @Override
- public ResultData getInfo(String sceneNum) throws Exception {
- if(StrUtil.isEmpty(sceneNum)){
- throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
- }
- ScenePro sceneProEntity = this.findBySceneNum(sceneNum);
- if(sceneProEntity == null){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
- }
- if(sceneProEntity.getStatus() != 1 && sceneProEntity.getStatus() != -2){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5033);
- }
- if(sceneProEntity.getPayStatus() != 1){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5034);
- }
- ResponseScene responseScene = new ResponseScene();
- SceneProEdit editEntity = sceneProEditService.findBySceneProId(sceneProEntity.getId());
- BeanUtils.copyProperties(editEntity, responseScene);
- BeanUtils.copyProperties(sceneProEntity, responseScene);
- if(StrUtil.isNotEmpty(editEntity.getEntry())){
- responseScene.setEntry(JSONObject.parseObject(editEntity.getEntry()).toJSONString());
- }
- if(StrUtil.isNotEmpty(sceneProEntity.getGps())){
- responseScene.setGps(JSONObject.parseObject(sceneProEntity.getGps()).toJSONString());
- }
- responseScene.setCreateTime(new DateTime(sceneProEntity.getCreateTime()).toString("yyyy-MM-dd"));
- responseScene.setCreateDate(sceneProEntity.getCreateTime().getTime());
- if(StrUtil.isEmpty(editEntity.getSceneKey())){
- responseScene.setIsPublic(0);
- }else {
- responseScene.setIsPublic(1);
- }
- //不返回场景访问密码
- responseScene.setSceneKey("");
- //查询是否有随心装场景
- if(sceneNum.indexOf("vr-")!=-1){
- ScenePro vrSceneProEntity = this.findLikeSceneNum(sceneNum);
- if(vrSceneProEntity != null){
- responseScene.setVrNum(null);
- responseScene.setVideosUser(null);
- responseScene.setBgMusicName(null);
- responseScene.setBgMusic(null);
- }
- }
- //更新访问数量
- sceneService.updateViewCount(sceneNum);
- return ResultData.ok(responseScene);
- }
- @Override
- public ScenePro findLikeSceneNum(String sceneNum) throws Exception {
- return this.getOne(new LambdaQueryWrapper<ScenePro>()
- .eq(ScenePro::getRecStatus, RecStatus.VALID.code())
- .like(ScenePro::getNum, sceneNum + "%")
- .orderByDesc(ScenePro::getId)
- .last("LIMIT 1"));
- }
- @Override
- public ResultData downloadPanoramaOrVideo(String sceneNum, String fileName, String type, String planId) throws Exception {
- if(StrUtil.isEmpty(sceneNum)
- || StrUtil.isEmpty(fileName)
- || StrUtil.isEmpty(type)
- || StrUtil.isEmpty(planId)){
- throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
- }
- if(fileName.contains("..") || fileName.contains("./\\") || fileName.contains(".//")
- || fileName.contains(".\\\\") || fileName.contains(".\\/")){
- throw new BusinessException(ErrorCode.FAILURE_CODE_3018);
- }
- ScenePro sceneProEntity = this.findBySceneNum(sceneNum);
- if(sceneProEntity == null){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
- }
- StringBuffer imagesBuf = new StringBuffer()
- .append("images").append(File.separator)
- .append("images").append(sceneProEntity.getNum())
- .append(File.separator);
- StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
- String path = sceneProEntity.getDataSource();
- String url = "";
- if("image".equals(type)){
- if(!new File(path + "/caches/images/" + fileName).exists()){
- throw new BusinessException(ErrorCode.FAILURE_CODE_3018);
- }
- //备份原始数据
- if(!new File(imagesBuffer.toString() + "caches/back-" + fileName).exists()){
- FileUtils.copyFile(path + "/caches/images/" + fileName, imagesBuffer.toString() + "caches/back-" + fileName, false);
- }
- //复制打包数据,并且改名
- FileUtils.copyFile(path + "/caches/images/" + fileName, imagesBuffer.toString() + "caches/" + planId + ".jpg", true);
- url = mainUrl + "scene/" + imagesBuf.toString() + "caches/" + planId + ".jpg";
- }
- if("video".equals(type)){
- //使用oss的路径
- url = ossPrefixUrl + "video/video" + sceneProEntity.getNum() + "/" + planId + ".mp4";
- }
- Map<String, Object> map = new HashMap<>();
- map.put("fileUrl", url + "?t=" + System.currentTimeMillis());
- map.put("fileName", url.substring(url.lastIndexOf("/") + 1));
- return ResultData.ok(map);
- }
- @Override
- public ResultData uploadBgMusic(String sceneNum, String fileName, MultipartFile file) throws Exception {
- if(StrUtil.isEmpty(sceneNum) || StrUtil.isEmpty(fileName)){
- throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
- }
- ScenePro sceneProEntity = this.findBySceneNum(sceneNum);
- if(sceneProEntity == null){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
- }
- StringBuffer dataBuf = new StringBuffer()
- .append("data").append(File.separator)
- .append("data").append(sceneProEntity.getNum())
- .append(File.separator);
- StringBuffer imagesBuf = new StringBuffer()
- .append("images").append(File.separator)
- .append("images").append(sceneProEntity.getNum())
- .append(File.separator);
- StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
- StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
- File buMusicFile = new File(imagesBuffer.toString() + fileName);
- if(!buMusicFile.getParentFile().exists()){
- buMusicFile.getParentFile().mkdirs();
- }
- //上传文件
- file.transferTo(buMusicFile);
- String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
- JSONObject scenejson = new JSONObject();
- if(strsceneInfos!=null) {
- scenejson = JSONObject.parseObject(strsceneInfos);
- }
- scenejson.put("bgMusicName", fileName);
- scenejson.put("uploadBgMusic", 1);
- scenejson.put("version", scenejson.getIntValue("version") + 1);
- FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
- return ResultData.ok();
- }
- @Override
- public ResultData deleteUploadBgMusic(String sceneNum) throws Exception {
- if(StrUtil.isEmpty(sceneNum)){
- throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
- }
- ScenePro sceneProEntity = this.findBySceneNum(sceneNum);
- if(sceneProEntity == null){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
- }
- StringBuffer dataBuf = new StringBuffer()
- .append("data").append(File.separator)
- .append("data").append(sceneProEntity.getNum())
- .append(File.separator);
- StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
- String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
- JSONObject scenejson = new JSONObject();
- if(strsceneInfos!=null) {
- scenejson = JSONObject.parseObject(strsceneInfos);
- }
- scenejson.put("bgMusicName", "");
- scenejson.put("uploadBgMusic", 1);
- scenejson.put("version", scenejson.getIntValue("version") + 1);
- FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
- return ResultData.ok();
- }
- }
|