1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823 |
- package com.fdkankan.scene.service.impl;
- import cn.hutool.core.collection.CollUtil;
- import cn.hutool.core.io.FileUtil;
- import cn.hutool.core.util.StrUtil;
- import cn.hutool.core.util.ZipUtil;
- 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.common.util.FileMd5Util;
- 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.model.utils.ComputerUtil;
- import com.fdkankan.model.utils.SceneUtil;
- import com.fdkankan.scene.bean.RequestScene;
- import com.fdkankan.scene.entity.SceneDataDownload;
- import com.fdkankan.scene.service.ISceneDataDownloadService;
- import com.fdkankan.web.response.Result;
- import com.fdkankan.web.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;
- @Autowired
- private ISceneDataDownloadService sceneDataDownloadService;
- @Value("${main.url}")
- private String mainUrl;
- @Value("${scene.pro.url}")
- private String sceneProUrl;
- @Value("${scene.pro.v3.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;
- @Value("${ecs.checkFile.maxTimes:5}")
- private int maxCheckTimes;
- @Value("${ecs.checkFile.waitTime:5000}")
- private int waitTime;
- @Value("${fyun.host}")
- private String fyunHost;
- @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);
- fYunFileService.downloadFileByCommand(meshPath, "data/data" + sceneNum + "/mesh");
- 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文件");
- 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){
- String skybox_type = "SKYBOX_V14";
- if(sceneProEntity.getSceneSource() !=null && sceneProEntity.getSceneSource() < 3){
- skybox_type = "SKYBOX_V13";
- }
- dataJson.put("skybox_type", skybox_type);
- }
- 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");
- }
- fYunFileService.downloadFile(ConstantFilePath.OSS_PREFIX + path.replace(ConstantFilePath.BUILD_MODEL_PATH, "") + "/data.fdage", target + File.separator + "capture/" + "data.fdage");
- 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文件");
- 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文件");
- FileUtils.downLoadFromUrl(ossPrefixUrl + "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){
- String skybox_type = "SKYBOX_V14";
- if(sceneProEntity.getSceneSource() !=null && sceneProEntity.getSceneSource() < 3){
- skybox_type = "SKYBOX_V13";
- }
- dataJson.put("skybox_type", skybox_type);
- }
- 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");
- }
- fYunFileService.downloadFile(ConstantFilePath.OSS_PREFIX + path.replace(ConstantFilePath.BUILD_MODEL_PATH, "") + "/data.fdage", target + File.separator + "capture/" + "data.fdage");
- CreateObjUtil.build3dModel(target , "1");
- //读取upload文件,检验需要上传的文件是否存在
- String uploadJsonPath= target + File.separator + "results" +File.separator+"upload.json";
- Thread.sleep(2000);
- boolean exist = ComputerUtil.checkComputeCompleted(uploadJsonPath, maxCheckTimes, waitTime);
- if(!exist){
- throw new BusinessException(ErrorCode.FAILURE_CODE_7013);
- }
- String uploadData = FileUtils.readFile(uploadJsonPath);
- JSONObject uploadJson = null;
- JSONArray array = null;
- if(uploadData!=null) {
- uploadJson = JSONObject.parseObject(uploadData);
- array = uploadJson.getJSONArray("upload");
- }
- if(array == null){
- log.info("计算全景图失败,没有upload.json");
- throw new BusinessException(ErrorCode.FAILURE_CODE_7013);
- }
- 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/", ""));
- if(sceneProEntity.getSceneScheme() == 3){
- map.put(target + File.separator + "results" + File.separator+ fileName,"images/images"+
- sceneProEntity.getNum()+ "/panorama_edit/" + sid + "/pan/" + fileName);
- }
- continue;
- }
- //tiles文件夹,亚马逊没有裁剪图片api,不需要上传4k图
- if(fileJson.getIntValue("clazz") == 5 || fileJson.getIntValue("clazz") == 7){
- 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();
- }
- @Override
- public ResultData uploadFloorJsonAjk(String sceneNum, String ajkJson, String cameraJson, String floorPlanJson, MultipartFile[] file) throws Exception {
- // log.info("画墙重建模型开始时间:" + start);
- String lock = sceneNum.toString().intern();
- synchronized(lock){
- if(org.apache.commons.lang3.StringUtils.isEmpty(sceneNum)){
- throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
- }
- 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);
- }
- //更新scene.json文件
- String strsceneInfos = FileUtils.readFile(ConstantFilePath.SCENE_PATH + "data" + File.separator + "data" + sceneNum + 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" + sceneNum + File.separator + "scene.json").createNewFile();
- }
- 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 + "_ajk";
- 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_floor_ajk_json", true);
- floorplanJson.put("has_vision_txt", true);
- floorplanJson.put("has_floorplan_json", true);
- JSONObject dataJson = JSONObject.parseObject(data);
- dataJson.put("extras", floorplanJson);
- //V5表示不需要生成high,low文件
- dataJson.put("skybox_type", "SKYBOX_V8");
- dataJson.put("split_type", "SPLIT_V10");
- 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 + "floor_ajk.json");
- if(!targetFile.getParentFile().exists()){
- targetFile.getParentFile().mkdirs();
- }
- if(targetFile.exists()){
- FileUtils.deleteFile(target + File.separator + "extras" + File.separator + "floor_ajk.json");
- }
- // 保存
- FileUtils.writeFile(target + File.separator + "extras" + File.separator + "floorplan.json", new String(floorPlanJson.getBytes(), "UTF-8"));
- FileUtils.writeFile(target + File.separator + "extras" + File.separator + "floor_ajk.json", new String(ajkJson.getBytes(), "UTF-8"));
- FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+sceneNum + File.separator + "floor_ajk.json", new String(ajkJson.getBytes(), "UTF-8"));
- FileUtils.writeFile(target + File.separator + "extras" + File.separator + "vision.txt", new String(cameraJson.getBytes(), "UTF-8"));
- FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+sceneNum + File.separator + "camera.json", new String(cameraJson.getBytes(), "UTF-8"));
- for(int i = 0; i < file.length; i ++){
- File cadImg = new File(target + File.separator + "extras" + File.separator + "Floorplans/" + file[i].getOriginalFilename());
- if(!cadImg.getParentFile().exists()){
- cadImg.getParentFile().mkdirs();
- }
- if(cadImg.exists())
- {
- cadImg.delete();
- }
- file[i].transferTo(cadImg);
- }
- //下载封面图
- FileUtils.downLoadFromUrl(sceneProEntity.getThumb() + "?t=" + System.currentTimeMillis(),
- "Cover.png", target + File.separator + "extras" + File.separator + "CoverImage");
- //转换成jpg
- FileUtils.pngToJpg(target + File.separator + "extras" + File.separator + "CoverImage/Cover.png",
- target + File.separator + "extras" + File.separator + "CoverImage/Cover.jpg");
- // FileUtils.deleteFile(target + File.separator + "extras" + File.separator + "CoverImage/Cover.png");
- //安居客算法运行
- log.info("安居客算法:开始建模——"+sceneNum);
- CreateObjUtil.build3dModel(target , "1");
- if(!new File(target + File.separator + "results" + File.separator + "upload.json").exists()){
- return ResultData.error(ErrorCode.FAILURE_CODE_5042);
- }
- String zipPath = target + File.separator + "results/" + sceneNum + ".zip";
- new File(zipPath).delete();
- // FileUtils.zipFile(zipPath, target + File.separator + "results/ajk/");
- // String command = "bash /opt/ossutil/gzip.sh " + zipPath.replace(".zip", "") + " " + target + File.separator + "results/ajk/";
- ZipUtil.zip(target + File.separator + "results/ajk/", zipPath);
- // log.info("压缩文件:" + command);
- // CreateObjUtil.callshell(command);
- if(!new File(zipPath).exists()){
- return ResultData.error(ErrorCode.FAILURE_CODE_5043);
- }
- String fileMD5 = FileMd5Util.getFileMD5(new File(zipPath));
- fYunFileService.uploadFile(zipPath, "data_download/" + sceneNum + ".zip");
- SceneDataDownload sceneDataDownloadEntity = sceneDataDownloadService.findBySceneNum(sceneNum);
- if(sceneDataDownloadEntity == null){
- sceneDataDownloadEntity = new SceneDataDownload();
- sceneDataDownloadEntity.setSceneNum(sceneNum);
- sceneDataDownloadEntity.setDownloadPath(ossPrefixUrl + "data_download/" + sceneNum + ".zip");
- sceneDataDownloadEntity.setFileMd5(fileMD5);
- sceneDataDownloadService.save(sceneDataDownloadEntity);
- return ResultData.ok();
- }
- sceneDataDownloadEntity.setFileMd5(fileMD5);
- sceneDataDownloadEntity.setUpdateTime(new Date());
- sceneDataDownloadService.updateById(sceneDataDownloadEntity);
- }
- return ResultData.ok();
- }
- @Override
- public ResultData uploadPanoramaOrVideo(String sceneNum, String fileName, String type, MultipartFile file, String planId) throws Exception {
- if(org.apache.commons.lang3.StringUtils
- .isEmpty(sceneNum) || org.apache.commons.lang3.StringUtils
- .isEmpty(fileName) || org.apache.commons.lang3.StringUtils
- .isEmpty(type) || org.apache.commons.lang3.StringUtils.isEmpty(planId)){
- throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
- }
- ScenePro sceneProEntity = this.findBySceneNum(sceneNum);
- if(sceneProEntity == null){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
- }
- if(!fileName.endsWith(".jpg") && !fileName.endsWith(".mp4")){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5023);
- }
- 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 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";
- //文件上传的位置可以自定义
- String filePath = "";
- if("image".equals(type)){
- filePath = target + File.separator + "extras/images" + File.separator + fileName;
- }
- if("video".equals(type)){
- filePath = target + File.separator + "extras/video" + File.separator + fileName;
- }
- File targetFile = new File(filePath);
- if(!targetFile.getParentFile().exists()){
- targetFile.getParentFile().mkdirs();
- }
- //上传文件
- file.transferTo(targetFile);
- String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
- JSONObject scenejson = new JSONObject();
- if(strsceneInfos!=null) {
- scenejson = JSONObject.parseObject(strsceneInfos);
- }
- if(type.equals("video")){
- scenejson.put("buildImages", 2);
- FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
- }else{
- scenejson.put("buildImages", 1);
- if(scenejson.containsKey("planId")){
- scenejson.put("planId",scenejson.getString("planId").concat(","+planId));
- }else{
- scenejson.put("planId",planId);
- }
- FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
- }
- return ResultData.ok();
- }
- @Override
- public ResultData uploadObjAndImg(String sceneNum, MultipartFile file) throws Exception{
- if(org.apache.commons.lang3.StringUtils.isEmpty(sceneNum)){
- throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
- }
- 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);
- }
- if (file == null || file.getSize() <= 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 dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
- //文件上传的位置可以自定义
- String path = sceneProEntity.getDataSource() + "_obj2txt";
- String zipPath = path + "/zip/";
- String filePath = path + "/extras/";
- FileUtils.delAllFile(path + "/results/");
- File targetFile = new File(filePath);
- if (!targetFile.exists()) {
- targetFile.mkdirs();
- }else {
- FileUtils.delAllFile(filePath);
- }
- targetFile = new File(zipPath);
- if (!targetFile.exists()) {
- targetFile.mkdirs();
- }else {
- FileUtils.delAllFile(zipPath);
- }
- targetFile = new File(zipPath + file.getOriginalFilename());
- if(!targetFile.getParentFile().exists()){
- targetFile.getParentFile().mkdirs();
- }
- // 保存
- synchronized(this)
- {
- if(targetFile.exists())
- {
- FileUtils.deleteFile(zipPath + file.getOriginalFilename());
- }
- file.transferTo(targetFile);
- }
- FileUtils.decompress(zipPath + file.getOriginalFilename(), zipPath + "data/");
- //源文件数据,判断是否有多个文件夹,有多个就提示错误,有一个就将文件夹里数据迁移到extras目录,无直接迁移到extras目录
- boolean flag = false;
- String targetName = "";
- File dataFile = new File(zipPath + "data/");
- for(File data : dataFile.listFiles()){
- if(data.isDirectory() && flag){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5018);
- }
- if(data.isDirectory() && !flag){
- flag = true;
- targetName = data.getName();
- }
- }
- boolean objFlag = false;
- boolean mtlFlag = false;
- if(StrUtil.isEmpty(targetName)){
- for(File data : dataFile.listFiles()){
- if(data.getName().endsWith(".obj") && objFlag){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5019);
- }
- if(data.getName().endsWith(".jpg") || data.getName().endsWith(".png")){
- if(!FileUtils.checkFileSizeIsLimit(data.length(), 1.5, "M")){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5020);
- }
- }
- if(data.getName().endsWith(".obj") && !objFlag){
- if(!FileUtils.checkFileSizeIsLimit(data.length(), 20, "M")){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5020);
- }
- objFlag = true;
- FileUtils.copyFile(zipPath + "data/" + data.getName(), filePath + "mesh.obj", true);
- continue;
- }
- if(data.getName().endsWith(".mtl")){
- mtlFlag = true;
- }
- FileUtils.copyFile(zipPath + "data/" + data.getName(), filePath + data.getName(), true);
- }
- }else {
- for(File data : new File(zipPath + "data/" + targetName).listFiles()){
- if(data.isDirectory()){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5018);
- }
- if(data.getName().endsWith(".obj") && objFlag){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5019);
- }
- if(data.getName().endsWith(".jpg") || data.getName().endsWith(".png")){
- if(!FileUtils.checkFileSizeIsLimit(data.length(), 1.5, "M")){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5020);
- }
- }
- if(data.getName().endsWith(".obj") && !objFlag){
- if(!FileUtils.checkFileSizeIsLimit(data.length(), 20, "M")){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5020);
- }
- objFlag = true;
- FileUtils.copyFile(zipPath + "data/" + targetName + File.separator + data.getName(), filePath + "mesh.obj", true);
- continue;
- }
- if(data.getName().endsWith(".mtl")){
- mtlFlag = true;
- }
- FileUtils.copyFile(zipPath + "data/" + targetName + File.separator + data.getName(), filePath + data.getName(), true);
- }
- }
- if(!mtlFlag && !objFlag){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5019);
- }
- //创建data.json
- JSONObject dataJson = new JSONObject();
- dataJson.put("obj2txt", true);
- dataJson.put("split_type", "SPLIT_V6");
- dataJson.put("data_describe", "double spherical");
- dataJson.put("skybox_type", "SKYBOX_V5");
- FileUtils.writeFile(path + "/data.json", dataJson.toString());
- //调用objToTxt算法
- //判断V2还是V3
- if("V2".equals(sceneProEntity.getBuildType())){
- CreateObjUtil.objToTxt(path , "1");
- }
- if("V3".equals(sceneProEntity.getBuildType())){
- CreateObjUtil.build3dModel(path , "1");
- }
- 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){
- log.error("upload.json数据出错");
- throw new BusinessException(ErrorCode.FAILURE_CODE_5017);
- }
- Map<String,String> map = new HashMap<String,String>();
- JSONObject fileJson = null;
- String fileName = "";
- for(int i = 0, len = array.size(); i < len; i++) {
- fileJson = array.getJSONObject(i);
- fileName = fileJson.getString("file");
- //文件不存在抛出异常
- 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") == 15) {
- map.put(path + File.separator + "results" + File.separator + fileName, "images/images" +
- sceneNum + "/" + ConstantFileName.modelUUID + "_50k_texture_jpg_high1/" + fileName.replace("tex/", ""));
- //复制一份到images本地
- FileUtils.copyFile(path + File.separator + "results" +File.separator + fileName,
- ConstantFilePath.SCENE_PATH+"images"+File.separator+"images"+sceneNum + File.separator +
- ConstantFileName.modelUUID + "_50k_texture_jpg_high1/" + fileName.replace("tex/", ""), true);
- continue;
- }
- }
- CreateObjUtil.convertTxtToDam( path + File.separator + "results" +File.separator+"modeldata.txt", path + File.separator + "results" +File.separator+ ConstantFileName.modelUUID+"_50k.dam");
- CreateObjUtil.convertDamToLzma(path + File.separator + "results" + File.separator);
- CreateObjUtil.convertTxtToDam( path + File.separator + "results" +File.separator+"modeldata.txt", path + File.separator + "results" + File.separator+ConstantFileName.modelUUID+"_50k.dam");
- map.put(path + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k.dam.lzma", "images/images"+sceneNum+"/"+ConstantFileName.modelUUID+"_50k.dam.lzma");
- map.put(path + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k.dam", "images/images"+sceneNum+"/"+ConstantFileName.modelUUID+"_50k.dam");
- fYunFileService.uploadMulFiles(map);
- FileUtils.copyFile(path + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k.dam",
- ConstantFilePath.SCENE_PATH+"images"+File.separator+"images"+sceneNum + File.separator + ConstantFileName.modelUUID+"_50k.dam", true);
- FileUtils.copyFile(path + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k.dam.lzma",
- ConstantFilePath.SCENE_PATH+"images"+File.separator+"images"+sceneNum + File.separator + ConstantFileName.modelUUID+"_50k.dam.lzma", true);
- log.info("文件复制到本地ecs完成——"+sceneNum);
- String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
- JSONObject scenejson = new JSONObject();
- if(strsceneInfos!=null) {
- scenejson = JSONObject.parseObject(strsceneInfos);
- }
- //更新scene.json文件
- if(strsceneInfos!=null)
- {
- scenejson.put("isUploadObj", true);
- scenejson.put("version", sceneProEditEntity.getVersion() + 1);
- scenejson.put("floorEditVer", sceneProEditEntity.getFloorEditVer() + 1);
- scenejson.put("floorPublishVer", sceneProEditEntity.getFloorPublishVer() + 1);
- FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+sceneNum+File.separator+"scene.json", scenejson.toString());
- log.info("写入scene.json文件完成——"+sceneNum);
- }
- //floorEditVer字段增加1
- sceneProEditEntity.setVersion(sceneProEditEntity.getVersion() + 1);
- sceneProEditEntity.setFloorPublishVer(sceneProEditEntity.getFloorPublishVer() + 1);
- sceneProEditEntity.setFloorEditVer(sceneProEditEntity.getFloorEditVer() + 1);
- sceneProEditService.updateById(sceneProEditEntity);
- return ResultData.ok();
- }
- @Override
- public Result createScene(RequestScene param) throws Exception {
- if(StrUtil.isEmpty(param.getNum())){
- throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
- }
- StringBuffer dataBuf = new StringBuffer()
- .append("data").append(File.separator)
- .append("data").append(param.getNum());
- StringBuffer imagesBuf = new StringBuffer()
- .append("images").append(File.separator)
- .append("images").append(param.getNum());
- StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
- StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
- FileUtils.delAllFile(imagesBuffer.toString() + "/results/");
- FileUtils.delAllFile(imagesBuffer.toString() + "/extras/");
- //远程复制oss资源
- fYunFileService.downloadFileByCommand(imagesBuffer.toString() + "/extras/" + param.getObjName(), imagesBuf.toString() + File.separator + param.getObjName());
- //obj文件修改名字
- FileUtils.copyFile(imagesBuffer.toString() + "/extras/" + param.getObjName(), imagesBuffer.toString() + "/extras/mesh.obj", true);
- FileUtils.deleteFile(imagesBuffer.toString() + "/extras/" + param.getObjName());
- fYunFileService.downloadFileByCommand(imagesBuffer.toString() + "/extras/" + param.getMntName(), imagesBuf.toString() + File.separator + param.getMntName());
- fYunFileService.downloadFileByCommand(imagesBuffer.toString() + "/extras/", imagesBuf.toString() + File.separator + "dacf7dfa24ae47fab8fcebfe4dc41ab9_50k_texture_jpg_high1");
- //将文件复制出去
- String[] imgs = new File(imagesBuffer.toString() + "/extras/dacf7dfa24ae47fab8fcebfe4dc41ab9_50k_texture_jpg_high1").list();
- for(String img : imgs){
- FileUtils.copyFile(imagesBuffer.toString() + "/extras/dacf7dfa24ae47fab8fcebfe4dc41ab9_50k_texture_jpg_high1/" + img,
- imagesBuffer.toString() + "/extras/" + img, true);
- }
- fYunFileService.downloadFileByCommand(imagesBuffer.toString() + File.separator + "vision.txt", imagesBuf.toString() + File.separator + "vision.txt");
- //创建data.json
- JSONObject dataJson = new JSONObject();
- dataJson.put("obj2txt", true);
- dataJson.put("split_type", "SPLIT_V6");
- dataJson.put("data_describe", "double spherical");
- dataJson.put("skybox_type", "SKYBOX_V5");
- FileUtils.writeFile(imagesBuffer.toString() + "/data.json", dataJson.toString());
- //调用objToTxt算法
- CreateObjUtil.objToTxt(imagesBuffer.toString(), "");
- String uploadJsonPath = imagesBuffer.toString() + File.separator + "results" +File.separator+"upload.json";
- boolean exist = ComputerUtil.checkComputeCompleted(uploadJsonPath, maxCheckTimes, waitTime);
- if(!exist){
- log.error("upload.json数据出错");
- throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
- }
- String uploadData = FileUtils.readFile(uploadJsonPath);
- JSONObject uploadJson = null;
- JSONArray array = null;
- if(uploadData!=null) {
- uploadJson = JSONObject.parseObject(uploadData);
- array = uploadJson.getJSONArray("upload");
- }
- if(array == null){
- log.error("upload.json数据出错");
- throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
- }
- Map<String,String> map = new HashMap<String,String>();
- JSONObject fileJson = null;
- String fileName = "";
- for(int i = 0, len = array.size(); i < len; i++) {
- fileJson = array.getJSONObject(i);
- fileName = fileJson.getString("file");
- //文件不存在抛出异常
- if (!new File(imagesBuffer.toString() + File.separator + "results" + File.separator + fileName).exists()) {
- throw new Exception(imagesBuffer.toString() + File.separator + "results" + File.separator + fileName + "文件不存在");
- }
- //tex文件夹
- if (fileJson.getIntValue("clazz") == 15) {
- map.put(imagesBuffer.toString() + File.separator + "results" + File.separator + fileName, "images/images" +
- param.getNum() + "/dacf7dfa24ae47fab8fcebfe4dc41ab9_50k_texture_jpg_high1/" + fileName.replace("tex/", ""));
- continue;
- }
- }
- CreateObjUtil.convertTxtToDam(imagesBuffer.toString() + File.separator + "results" +File.separator+"modeldata.txt", imagesBuffer.toString() + File.separator + "results" +File.separator+ "dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam");
- CreateObjUtil.convertDamToLzma(imagesBuffer.toString() + File.separator + "results" +File.separator+ "dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam");
- CreateObjUtil.convertTxtToDam(imagesBuffer.toString() + File.separator + "results" +File.separator+"modeldata.txt", imagesBuffer.toString() + File.separator + "results" + File.separator+ "dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam");
- map.put(imagesBuffer.toString() + File.separator + "results" +File.separator+"dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam.lzma", "images/images"+param.getNum()+"/"+"dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam.lzma");
- map.put(imagesBuffer.toString() + File.separator + "results" +File.separator+"dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam", "images/images"+param.getNum()+"/"+"dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam");
- FileUtils.deleteFile(imagesBuffer.toString() + "/vision.modeldata");
- CreateObjUtil.convertTxtToVisionmodeldata(imagesBuffer.toString() + "/vision.txt", imagesBuffer.toString() + "/vision.modeldata");
- map.put(imagesBuffer.toString() + "/vision.modeldata", "images/images"+param.getNum()+"/vision.modeldata");
- fYunFileService.uploadMulFiles(map);
- ScenePro proEntity = this.findBySceneNum(param.getNum());
- if(proEntity == null){
- proEntity = new ScenePro();
- proEntity.setSceneName("四维看看");
- proEntity.setSceneDec("<p>四维看看 让空间讲故事</p>");
- proEntity.setSceneScheme(2);
- proEntity.setNum(param.getNum());
- proEntity.setUserId(param.getUserId());
- proEntity.setWebSite(mainUrl + "/" + sceneProNewUrl + param.getNum());
- proEntity.setStatus(1);
- proEntity.setPayStatus(1);
- proEntity.setBuildType("V3");
- if(param.getSceneSource()!=null){
- proEntity.setSceneSource(Integer.parseInt(param.getSceneSource()));
- }
- this.save(proEntity);
- SceneProEdit proEditEntity = new SceneProEdit();
- proEditEntity.setProId(proEntity.getId());
- sceneProEditService.save(proEditEntity);
- JSONObject scenejson = JSONObject.parseObject(JSONObject.toJSONString(proEntity));
- scenejson.put("visions", 1);
- FileUtils.writeFile(dataBuffer.toString() + File.separator+"scene.json", scenejson.toString());
- }
- return Result.success(mainUrl + "/" + sceneProNewUrl + param.getNum());
- }
- @Override
- public ResultData downloadPanoramaData(String sceneNum) throws Exception {
- ScenePro sceneProEntity = 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 highPath = sceneProEntity.getDataSource() + "/results/high";
- if(!new File(highPath).exists()){
- fYunFileService.downloadFileByCommand(highPath, sceneProEntity.getDataSource().replace(ConstantFilePath.BUILD_MODEL_LASER_PATH,ConstantFilePath.OSS_PREFIX).replace(ConstantFilePath.BUILD_MODEL_PATH,ConstantFilePath.OSS_PREFIX)+"_results/results/high/");
- if(!new File(highPath).exists()){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
- }
- }
- //获取高清图,拷贝高清图
- String content = FileUtils.readFile(sceneProEntity.getDataSource() + "/results/vision.txt");
- if (!ObjectUtils.isEmpty(content)) {
- File file = new File(highPath.concat("/pano"));
- if(!file.exists()){
- file.mkdirs();
- }
- JSONObject.parseObject(content).getJSONArray("sweepLocations").stream()
- .map(o -> (JSONObject) o)
- .map(o -> o.getString("uuid"))
- .forEach(fileName -> FileUtils.copyFile(sceneProEntity.getDataSource().concat("/caches/images/").concat(fileName).concat(".jpg"),
- highPath.concat("/pano/").concat(fileName).concat(".jpg"), true)
- );
- }
- if(!new File(imagesBuffer.toString()).exists()){
- new File(imagesBuffer.toString()).mkdirs();
- }
- ZipUtil.zip(highPath, imagesBuffer.toString() + sceneNum + "-high.zip");
- fYunFileService.uploadFileByCommand(imagesBuffer.toString() + sceneNum + "-high.zip", imagesBuf.toString() + sceneNum + "-high.zip");
- return ResultData.ok(fyunHost + imagesBuf.toString() + sceneNum + "-high.zip?t=" + System.currentTimeMillis());
- }
- @Override
- public ResultData downloadVisionData(String sceneNum) 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 dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
- StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
- fYunFileService.downloadFile(imagesBuf.toString() + "vision.modeldata", dataBuffer.toString() + "vision.modeldata");
- 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");
- fYunFileService.uploadFile(dataBuffer.toString() + "vision.json", dataBuf.toString() + "vision.json");
- return ResultData.ok(fyunHost + dataBuf.toString() + "vision.json?t=" + System.currentTimeMillis());
- }
- @Override
- public ResultData uploadScreencapVoiceNew(String sceneNum, String type, String fileName, MultipartFile file, String length, String replace) 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 = file.getOriginalFilename().substring(0,
- file.getOriginalFilename().indexOf(".") > 0 ? file.getOriginalFilename().indexOf(".") : file.getOriginalFilename().length());
- log.info("上传的音频文件名:" + file.getOriginalFilename());
- String soundFileName = "sound201810.wav";
- 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)){
- synchronized(this){
- if(scenejson.containsKey("screencapVoiceSoundsync") && StrUtil.isNotEmpty(scenejson.getString("screencapVoiceSoundsync"))){
- String target = ConstantFilePath.SCENE_PATH + scenejson.getString("screencapVoiceSoundsync").substring(
- scenejson.getString("screencapVoiceSoundsync").indexOf("voice"));
- if(new File(target).exists()){
- targetFile = new File(path + File.separator +soundFileName);
- if(targetFile.exists())
- {
- FileUtils.deleteFile(path + File.separator + soundFileName);
- }
- file.transferTo(targetFile);
- FileUtils.changeVoiceToMp3(path + File.separator + soundFileName, path + File.separator + "newSound201810.mp3");
- //目标文件改名
- new File(target).renameTo(new File(path + File.separator + "oldSound201810.mp3"));
- //判断音频时长,不够拼接空白音效
- double total = Double.parseDouble(length);
- double now = (FileUtils.getAudioPlayTime(new File(path + File.separator + "oldSound201810.mp3")) +
- FileUtils.getAudioPlayTime(new File(path + File.separator + "newSound201810.mp3"))) / 1000.0;
- if(total - now > 0.5){
- CreateObjUtil.createMuteViode(total - now, path + File.separator + "muteSound.mp3");
- if(new File(path + File.separator + "muteSound.mp3").exists()){
- //需要将旧的音频改名
- new File(path + File.separator + "oldSound201810.mp3").renameTo(new File(path + File.separator + "oldMuteSound201810.mp3"));
- log.info("生成新的静音音频和旧的音频合并");
- CreateObjUtil.mergeVideo(path + File.separator + "oldMuteSound201810.mp3", path + File.separator + "muteSound.mp3",
- path + File.separator + "oldSound201810.mp3");
- }
- }
- //app端和pc端名字不一致,统一文件名字
- target = path + File.separator + originalFileName + ".mp3";
- CreateObjUtil.mergeVideo(path + File.separator + "oldSound201810.mp3", path + File.separator + "newSound201810.mp3", target);
- //删除改名后的文件
- // new File(path + File.separator + "oldSound201810.mp3").delete();
- Map map = new HashMap();
- map.put("screencapVoiceSoundsyncFileName", originalFileName + ".mp3");
- String proVideo = "voice/voice"+sceneNum+"/"+originalFileName + ".mp3";
- 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 + ".mp3");
- }
- }else {
- targetFile = new File(path + File.separator +soundFileName);
- if(targetFile.exists())
- {
- FileUtils.deleteFile(path + File.separator + soundFileName);
- }
- file.transferTo(targetFile);
- //判断音频时长,不够拼接空白音效
- FileUtils.changeVoiceToMp3(path + File.separator + soundFileName, path + File.separator + "newSound201810.mp3");
- double total = Double.parseDouble(length);
- double now = (FileUtils.getAudioPlayTime(new File(path + File.separator + "newSound201810.mp3"))) / 1000.0;
- log.info("前端传的时长:" + total);
- log.info("获取文件的时长:" + now);
- //同步录音前一段没空白,直接生成文件
- if(total - now < 0.5){
- FileUtils.changeVoiceToMp3(path + File.separator + soundFileName, path + File.separator + originalFileName + ".mp3");
- Map map = new HashMap();
- map.put("screencapVoiceSoundsyncFileName", originalFileName + ".mp3");
- String proVideo = "voice/voice"+sceneNum+"/"+originalFileName + ".mp3";
- 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);
- //uploadToQiniuForScene3DService.upload(path + File.separator +fileName, "voice/voice"+sceneNum+"/"+CONSTANTFILENAME.VOICENAME +fileName.substring(fileName.lastIndexOf(".")));
- //sceneService.updateScreencapMusic(sceneNum, voiceSrc);
- return ResultData.ok(proVideo);
- }
- ////同步录音前一段有空白,生成一段静音后拼接文件
- CreateObjUtil.createMuteViode(total - now, path + File.separator + "muteSound.mp3");
- //app端和pc端名字不一致,统一文件名字
- String target = path + File.separator + originalFileName + ".mp3";
- CreateObjUtil.mergeVideo(path + File.separator + "muteSound.mp3", path + File.separator + "newSound201810.mp3", target);
- Map map = new HashMap();
- map.put("screencapVoiceSoundsyncFileName", originalFileName + ".mp3");
- String proVideo = "voice/voice"+sceneNum+"/"+originalFileName + ".mp3";
- 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 + ".mp3");
- }
- }
- }
- 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.changeVoiceToMp3(path + File.separator + name, path + File.separator + originalFileName + ".mp3");
- map.put("screencapVoiceSoundsyncFileName", originalFileName + ".mp3");
- String proVideo = "voice/voice"+sceneNum+"/"+originalFileName + ".mp3";
- 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);
- }
- if("sound".equals(type)){
- FileUtils.changeVoiceToMp3(path + File.separator + name, path + File.separator + originalFileName + ".mp3");
- map.put("screencapVoiceSoundFileName", originalFileName + ".mp3");
- String proVideo = "voice/voice"+sceneNum+"/"+originalFileName + ".mp3";
- map.put("screencapVoiceSound", proVideo);
- map.put("uploadVoiceSound", 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");
- if(StrUtil.isEmpty(fileName)){
- map.put("screencapVoiceFileName", originalFileName + ".mp3");
- }else {
- map.put("screencapVoiceFileName", fileName);
- }
- 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);
- //uploadToQiniuForScene3DService.upload(path + File.separator +fileName, "voice/voice"+sceneNum+"/"+CONSTANTFILENAME.VOICENAME +fileName.substring(fileName.lastIndexOf(".")));
- //sceneService.updateScreencapMusic(sceneNum, voiceSrc);
- return ResultData.ok(voiceSrc);
- }
- @Override
- public ResultData uploadROIVideo(String sceneNum, String fileName, MultipartFile file, String planId, String rect,
- String videoDirMatrix, String dir, String hfov, String vfov) throws Exception {
- if(StrUtil.isEmpty(sceneNum) || StrUtil.isEmpty(fileName) ||
- StrUtil.isEmpty(planId) || StrUtil.isEmpty(rect)){
- 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 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 + "_roi";
- FileUtils.deleteDirectory(target);
- //文件上传的位置可以自定义
- String filePath = target + File.separator + "extras" + File.separator + fileName;
- File targetFile = new File(filePath);
- if(!targetFile.getParentFile().exists()){
- targetFile.getParentFile().mkdirs();
- }
- if(file == null){
- FileUtils.copyFile(ConstantFilePath.SCENE_PATH + "video/video"+
- sceneProEntity.getNum() + File.separator + fileName, filePath, true);
- }else {
- //上传文件
- file.transferTo(targetFile);
- FileUtils.copyFile(filePath, ConstantFilePath.SCENE_PATH + "video/video"+
- sceneProEntity.getNum() + File.separator + fileName, true);
- }
- String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
- JSONObject scenejson = new JSONObject();
- if(strsceneInfos!=null) {
- scenejson = JSONObject.parseObject(strsceneInfos);
- }
- JSONArray jsonArray = new JSONArray();
- JSONObject jsonObject = new JSONObject();
- JSONObject rectJson = JSON.parseObject(rect);
- boolean noPanoId = true;
- if(scenejson.containsKey("videosUser")){
- jsonArray = scenejson.getJSONArray("videosUser");
- for(int i = 0, len = jsonArray.size(); i < len; i++){
- jsonObject = jsonArray.getJSONObject(i);
- if(planId.equals(jsonObject.getString("panoId"))){
- jsonObject.put("rect", rectJson);
- jsonObject.put("name", fileName.substring(0, fileName.lastIndexOf(".")));
- // jsonObject.put("videoDirMatrix", JSON.parseArray(videoDirMatrix));
- jsonObject.put("dir", JSON.parseObject(dir));
- jsonObject.put("hfov", hfov);
- jsonObject.put("vfov", vfov);
- noPanoId = false;
- break;
- }
- }
- }
- if(noPanoId){
- jsonObject = new JSONObject();
- jsonObject.put("name", fileName.substring(0, fileName.lastIndexOf(".")));
- jsonObject.put("panoId", planId);
- jsonObject.put("rect", rectJson);
- // jsonObject.put("videoDirMatrix", JSON.parseArray(videoDirMatrix));
- jsonObject.put("dir", JSON.parseObject(dir));
- jsonObject.put("hfov", hfov);
- jsonObject.put("vfov", vfov);
- if(!jsonArray.contains(jsonObject)){
- jsonArray.add(jsonObject);
- }
- }
- //保存rect的json数据
- FileUtils.writeFile(target + File.separator + "extras" + File.separator + "video-ROI.json", jsonObject.toJSONString());
- //复制原始图片
- FileUtils.copyFile(path + "/caches/images/" + planId + ".jpg",
- target + File.separator + "extras" + File.separator + planId + ".jpg", true);
- 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 dataJson = JSONObject.parseObject(data);
- //V5表示不需要生成high,low文件
- dataJson.put("skybox_type", "SKYBOX_V5");
- dataJson.put("split_type", "SPLIT_V11");
- FileUtils.writeFile(target + File.separator+"data.json", new String(dataJson.toString().getBytes(), "UTF-8"));
- }
- //进行计算
- log.info("绿幕抠图视频:开始建模——" + sceneProEntity.getNum());
- CreateObjUtil.build3dModel2(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数据出错");
- }
- Map<String, String> map = new HashMap<>();
- JSONObject fileJson = null;
- 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+"文件不存在");
- }
- if(fileJson.getIntValue("clazz") == 19 ){
- map.put(target + File.separator + "results" + File.separator+ fileName,"video/video"+
- sceneProEntity.getNum() + File.separator + fileName.replace("videos/", ""));
- }
- }
- fYunFileService.uploadMulFiles(map);
- scenejson.put("videosUser", jsonArray.toJSONString());
- scenejson.put("imagesVersion", scenejson.getIntValue("imagesVersion") + 1);
- FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
- SceneProEdit sceneProEditEntity = sceneProEditService.findBySceneProId(sceneProEntity.getId());
- if(sceneProEditEntity != null){
- sceneProEditEntity.setVideosUser(jsonArray.toJSONString());
- sceneProEditEntity.setImagesVersion(sceneProEditEntity.getImagesVersion() + 1);
- sceneProEditService.updateById(sceneProEditEntity);
- }
- return ResultData.ok();
- }
- }
|