12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361 |
- package com.fdkankan.scene.service.impl;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.fdkankan.base.aop.SystemServiceLog;
- import com.fdkankan.base.constant.LoginConstant;
- import com.fdkankan.base.constant.SceneConstant;
- import com.fdkankan.base.mapper.base.IBaseMapper;
- import com.fdkankan.base.service.impl.BaseServiceImpl;
- import com.fdkankan.base.util.ConvertUtils;
- import com.fdkankan.base.util.FileMd5Util;
- import com.fdkankan.base.util.FileUtil;
- import com.fdkankan.common.constant.ConstantFileName;
- import com.fdkankan.common.constant.ConstantFilePath;
- import com.fdkankan.common.constant.ConstantUrl;
- import com.fdkankan.common.exception.BaseRuntimeException;
- import com.fdkankan.common.model.Result;
- import com.fdkankan.common.util.FileUtils;
- import com.fdkankan.common.util.MatrixToImageWriterUtil;
- import com.fdkankan.common.util.OkHttpUtils;
- import com.fdkankan.common.util.UploadToOssUtil;
- import com.fdkankan.common.vo.request.RequestScene;
- import com.fdkankan.common.vo.request.RequestSceneEdit;
- import com.fdkankan.common.vo.response.ResponseCamera;
- import com.fdkankan.common.vo.response.ResponseScene;
- import com.fdkankan.scene.entity.*;
- import com.fdkankan.scene.mapper.ISceneProEditMapper;
- import com.fdkankan.scene.mapper.ISceneProMapper;
- import com.fdkankan.scene.service.*;
- import com.fdkankan.scene.util.CreateObjUtil;
- import com.github.pagehelper.Page;
- import com.github.pagehelper.PageHelper;
- import com.github.pagehelper.PageInfo;
- import com.github.pagehelper.util.StringUtil;
- import lombok.extern.slf4j.Slf4j;
- import net.coobird.thumbnailator.Thumbnails;
- import org.apache.commons.lang3.StringUtils;
- 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.transaction.annotation.Transactional;
- import org.springframework.web.multipart.MultipartFile;
- import org.springframework.web.multipart.commons.CommonsMultipartFile;
- import tk.mybatis.mapper.entity.Condition;
- import java.io.*;
- import java.math.BigInteger;
- import java.util.*;
- import java.util.concurrent.atomic.AtomicBoolean;
- /**
- * Created by Hb_zzZ on 2019/7/23.
- */
- @Slf4j
- @Service("sceneProService")
- @Transactional
- public class SceneProServiceImpl extends BaseServiceImpl<SceneProEntity, Long> implements ISceneProService {
- @Autowired
- private ISceneProMapper sceneProMapper;
- @Autowired
- private ISceneProEditMapper sceneProEditMapper;
- @Autowired
- private UploadToOssUtil uploadToOssUtil;
- @Autowired
- private ISceneDataDownloadService sceneDataDownloadService;
- @Autowired
- private ISceneModuleVideoService sceneModuleVideoService;
- @Autowired
- private ISceneService sceneService;
- @Value("${main.url}")
- private String mainUrl;
- @Value("${scene.url}")
- private String sceneUrl;
- @Value("${scene.pro.url}")
- private String sceneProUrl;
- @Value("${scene.pro.new.url}")
- private String sceneProNewUrl;
- @Value("${oss.type}")
- private String type;
- @Value("${prefix.ali}")
- private String prefixAli;
- @Value("${hot.domain.list}")
- private String hotDomainList;
- @Value("${hot.delete}")
- private String hotDelete;
- @Override
- public IBaseMapper<SceneProEntity, Long> getBaseMapper() {
- return sceneProMapper;
- }
- @Override
- public List<ResponseScene> convert(List<SceneProEntity> list) throws Exception {
- List<ResponseScene> responseScenes = new ArrayList<>();
- for (SceneProEntity sceneProEntity : list){
- ResponseScene responseScene = new ResponseScene();
- SceneProEditEntity editEntity = sceneProEditMapper.findByProId(sceneProEntity.getId());
- BeanUtils.copyProperties(editEntity, responseScene);
- BeanUtils.copyProperties(sceneProEntity, responseScene);
- responseScene.setCreateTime(new DateTime(sceneProEntity.getCreateTime()).toString("yyyy-MM-dd"));
- responseScene.setCreateDate(sceneProEntity.getCreateTime().getTime());
- responseScenes.add(responseScene);
- }
- return responseScenes;
- }
- @Override
- public int getSceneCount(Long cameraId) {
- return sceneProMapper.getSceneCount(cameraId);
- }
- @Override
- public SceneProEntity findBySceneNum(String sceneNum){
- return sceneProMapper.findByNum(sceneNum);
- }
- @Override
- public SceneProEntity findLikeSceneNum(String sceneNum) throws Exception {
- return sceneProMapper.findLikeNum(sceneNum);
- }
- @Override
- public SceneProEntity findDeleteSceneBySceneNum(String sceneNum) {
- return sceneProMapper.findDeleteSceneBySceneNum(sceneNum);
- }
- @Override
- public SceneProEntity getSceneStatusByUnicode(String unicode, String recStatus) {
- return sceneProMapper.getSceneStatusByUnicode(unicode, recStatus);
- }
- @Override
- public List<SceneProEntity> findByUserId(Long userId, Integer cameraType) {
- return sceneProMapper.findByUserId(userId, cameraType);
- }
- @Override
- public List<SceneProEntity> findBySceneNums(String nums, Integer cameraType) {
- return sceneProMapper.findBySceneNums(nums, cameraType);
- }
- @Override
- public int updateStatus(String sceneNum, int status) {
- return sceneProMapper.updateStatus(sceneNum, status);
- }
- @Override
- public Result resetUploadFloorJson(RequestSceneEdit sceneEdit) throws Exception{
- if(StringUtils.isEmpty(sceneEdit.getSceneNum())){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = findBySceneNum(sceneEdit.getSceneNum());
- if(sceneProEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_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());
- //更新scene.json文件
- String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
- JSONObject scenejson = new JSONObject();
- if(strsceneInfos!=null)
- {
- scenejson = JSONObject.parseObject(strsceneInfos);
- }else {
- new File(dataBuffer.toString() + "scene.json").createNewFile();
- }
- if(!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));
- }
- }
- SceneProEditEntity sceneProEditEntity = sceneProEditMapper.findByProId(sceneProEntity.getId());
- //重置将floorEditVer回归floorPublishVer
- sceneProEditEntity.setFloorPublishVer(sceneProEditEntity.getFloorEditVer());
- sceneProEditMapper.updateByPrimaryKeySelective(sceneProEditEntity);
- //更新scene.json文件
- if(strsceneInfos!=null){
- scenejson.put("floorEditVer", sceneProEditEntity.getFloorEditVer());
- scenejson.put("floorPublishVer", sceneProEditEntity.getFloorEditVer());
- scenejson.put("cadInfo", sceneProEditEntity.getCadInfo());
- FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
- log.info("写入scene.json文件完成——"+sceneEdit.getSceneNum());
- }
- log.info("重置画墙重建模型版本成功");
- return Result.success();
- }
- @Override
- public Result uploadFloorJson(RequestSceneEdit sceneEdit) throws Exception {
- String lock = sceneEdit.getSceneNum().toString().intern();
- synchronized(lock){
- long start = System.currentTimeMillis();
- log.info("画墙重建模型开始时间:" + start);
- if(StringUtils.isEmpty(sceneEdit.getSceneNum())){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = findBySceneNum(sceneEdit.getSceneNum());
- if(sceneProEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
- }
- SceneProEditEntity sceneProEditEntity = sceneProEditMapper.findByProId(sceneProEntity.getId());
- if(sceneProEditEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_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(!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(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);
- sceneProEditMapper.updateByPrimaryKeySelective(sceneProEditEntity);
- // return Result.success();
- // }
- String path = sceneProEntity.getDataSource();
- if(path != null && !"".equals(path) && path.startsWith("http")){
- path = ConstantFilePath.BUILD_MODEL_PATH + File.separator + path.split("/")[path.split("/").length - 2];
- }
- String target = path + "_edit";
- File editPath = new File(target);
- if(!editPath.exists()){
- editPath.mkdirs();
- }
- //创建文件夹软连接并且复制data.json和project.json
- if(new File(target + File.separator + "capture").exists()){
- new File(target + File.separator + "capture").delete();
- }
- if(new File(target + File.separator + "caches").exists()){
- //删除link
- new File(target + File.separator + "caches" + File.separator + "images").delete();
- //删除所有文件
- FileUtils.delAllFile(target + File.separator + "caches");
- }
- if(new File(target + File.separator + "results").exists()){
- FileUtils.delAllFile(target + File.separator + "results");
- }
- //创建文件夹,并link文件夹
- new File(target + File.separator + "caches").mkdirs();
- CreateObjUtil.createSoftConnection(path + File.separator + "capture", target + File.separator + "capture");
- if(new File(path + File.separator + "caches" + File.separator + "images").exists()){
- CreateObjUtil.createSoftConnection(path + File.separator + "caches" + File.separator + "images", target + File.separator + "caches" + File.separator + "images");
- }
- FileUtils.copyFile(path + File.separator + "data.json", target + File.separator+"data.json", true);
- FileUtils.copyFile(path + File.separator + "project.json", target + File.separator+"project.json", true);
- //data.json增加extras为执行重建算法
- String project = FileUtils.readFile(target + File.separator+"project.json");
- if(project != null){
- JSONObject projectJson = JSONObject.parseObject(project);
- projectJson.put("parent", projectJson.get("uuid"));
- projectJson.put("uuid", UUID.randomUUID().toString());
- projectJson.put("time", System.currentTimeMillis());
- FileUtils.writeFile(path + File.separator + "project.json", projectJson.toString());
- }
- String data = FileUtils.readFile(target + File.separator+"data.json");
- if(data != null){
- JSONObject floorplanJson = new JSONObject();
- floorplanJson.put("has_floorplan_json", true);
- floorplanJson.put("has_vision_txt", true);
- JSONObject dataJson = JSONObject.parseObject(data);
- dataJson.put("extras", floorplanJson);
- //V5表示不需要生成high,low文件
- dataJson.put("skybox_type", "SKYBOX_V5");
- dataJson.put("split_type", "SPLIT_V4");
- FileUtils.writeFile(target + File.separator+"data.json", new String(dataJson.toString().getBytes(), "UTF-8"));
- }
- //文件上传的位置可以自定义
- log.info("画墙重建模型开始");
- File targetFile = new File(target + File.separator + "extras" + File.separator + "floorplan.json");
- if(!targetFile.getParentFile().exists()){
- targetFile.getParentFile().mkdirs();
- }
- if(targetFile.exists()){
- FileUtils.deleteFile(target + File.separator + "extras" + File.separator + "floorplan.json");
- }
- // 保存
- FileUtils.writeFile(target + File.separator + "extras" + File.separator + "floorplan.json", new String(sceneEdit.getFloor().getBytes(), "UTF-8"));
- FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+sceneEdit.getSceneNum() + File.separator + "floor.json", new String(sceneEdit.getWebFloor().getBytes(), "UTF-8"));
- //下载vision.modeldata,解压成vision.txt,并且删除vision.modeldata
- log.info("下载vision.modeldata文件");
- if("s3".equals(type)){
- FileUtils.downLoadFromUrl(ConstantUrl.PREFIX_AWS + "images/images" + sceneEdit.getSceneNum() + "/vision.modeldata" + "?m="+new Date().getTime(),
- "vision.modeldata", target + File.separator + "extras" + File.separator);
- }
- if("oss".equals(type)){
- FileUtils.downLoadFromUrl(prefixAli + "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");
- // File visionFile = new File(Message.filePath+"data"+File.separator+"data"+sceneNum+File.separator+"vision.json");
- // if(visionFile.exists()){
- // FileUtil.copyFile(Message.filePath+"data"+File.separator+"data"+sceneNum+File.separator+"vision.json", target + File.separator + "extras" + File.separator + "vision.txt", true);
- // }else {
- // FileUtil.copyFile(path + File.separator + "results" + File.separator + "vision.txt", target + File.separator + "extras" + File.separator + "vision.txt", true);
- // }
- //复制vision2.txt,修改热点可行性不改动vision2.txt
- // FileUtils.copyFile(path + File.separator + "results" + File.separator + "vision2.txt", target + File.separator + "extras" + File.separator + "vision2.txt", true);
- log.info("下载vision2.modeldata文件");
- if("oss".equals(type)){
- FileUtils.downLoadFromUrl(prefixAli + "images/images" + sceneEdit.getSceneNum() + "/vision2.modeldata" + "?m="+new Date().getTime(),
- "vision2.modeldata", target + File.separator + "extras" + File.separator);
- }
- if("s3".equals(type)){
- FileUtils.downLoadFromUrl(ConstantUrl.PREFIX_AWS + "images/images" + sceneEdit.getSceneNum() + "/vision2.modeldata" + "?m="+new Date().getTime(),
- "vision2.modeldata", target + File.separator + "extras" + File.separator);
- }
- CreateObjUtil.convertVisionmodeldataToTxt(target + File.separator + "extras" + File.separator + "vision2.modeldata",
- target + File.separator + "extras" + File.separator + "vision2.txt");
- log.info("解压完成,删除vision2.modeldata文件");
- FileUtils.deleteFile(target + File.separator + "extras" + File.separator + "vision2.modeldata");
- //重新计算算法
- log.info("重新计算大场景:开始建模——"+sceneEdit.getSceneNum());
- //判断V2还是V3
- if("V2".equals(sceneProEntity.getBuildType())){
- CreateObjUtil.build3dModelOld(target , "1");
- }
- if("V3".equals(sceneProEntity.getBuildType())){
- CreateObjUtil.build3dModel(target , "1");
- }
- log.info("重新计算大场景:开始转换成lzma文件——"+sceneEdit.getSceneNum());
- CreateObjUtil.convertTxtToDam( target + File.separator + "results" + File.separator+"tex"+
- File.separator+"modeldata.txt", target + File.separator + "results" +File.separator+ ConstantFileName.modelUUID+"_50k.dam");
- CreateObjUtil.convertDamToLzma(target + File.separator + "results");
- CreateObjUtil.convertTxtToDam( target + File.separator + "results" +File.separator+"tex"+
- File.separator+"modeldata.txt", target + File.separator + "results" + File.separator+ConstantFileName.modelUUID+"_50k.dam");
- // createObjService.convertTxtToVisionmodeldata(target + File.separator + "results" +File.separator+
- // "vision.txt",target + File.separator + "results" +File.separator+"vision.modeldata");
- //8目相机有两个vision.txt因此第二个叫vision2.txt
- // if(new File(target + File.separator + "results" +File.separator+"vision2.txt").exists()){
- // createObjService.convertTxtToVisionmodeldata(target + File.separator + "results" +File.separator+
- // "vision2.txt",target + File.separator + "results" +File.separator+"vision2.modeldata");
- // }
- 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 BaseRuntimeException(SceneConstant.FAILURE_CODE_5012, SceneConstant.FAILURE_MSG_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);
- sceneProEditMapper.updateByPrimaryKeySelective(sceneProEditEntity);
- log.info("修改数据库完成——"+sceneEdit.getSceneNum());
- log.info("花费时间:" + (System.currentTimeMillis() - start));
- }
- // Thread.sleep(180000);
- return Result.success();
- }
- @Override
- public Result uploadFloorJsonAjk(String sceneNum, String ajkJson, String cameraJson, String floorPlanJson, MultipartFile[] file) throws Exception {
- // log.info("画墙重建模型开始时间:" + start);
- String lock = sceneNum.toString().intern();
- synchronized(lock){
- if(StringUtils.isEmpty(sceneNum)){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = findBySceneNum(sceneNum);
- if(sceneProEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
- }
- SceneProEditEntity sceneProEditEntity = sceneProEditMapper.findByProId(sceneProEntity.getId());
- if(sceneProEditEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_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();
- }
- // if(!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));
- // }
- // }
- 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 Result.failure("算法计算失败!");
- }
- 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/";
- log.info("压缩文件:" + command);
- CreateObjUtil.callshell(command);
- if(!new File(zipPath).exists()){
- return Result.failure("打包zip失败");
- }
- String fileMD5 = FileMd5Util.getFileMD5(new File(zipPath));
- uploadToOssUtil.upload(zipPath, "data_download/" + sceneNum + ".zip");
- SceneDataDownloadEntity sceneDataDownloadEntity = sceneDataDownloadService.findBySceneNum(sceneNum);
- if(sceneDataDownloadEntity == null){
- sceneDataDownloadEntity = new SceneDataDownloadEntity();
- sceneDataDownloadEntity.setSceneNum(sceneNum);
- sceneDataDownloadEntity.setDownloadPath(prefixAli + "data_download/" + sceneNum + ".zip");
- sceneDataDownloadEntity.setFileMd5(fileMD5);
- sceneDataDownloadService.save(sceneDataDownloadEntity);
- return Result.success();
- }
- sceneDataDownloadEntity.setFileMd5(fileMD5);
- sceneDataDownloadEntity.setUpdateTime(new Date());
- sceneDataDownloadService.update(sceneDataDownloadEntity);
- }
- return Result.success();
- }
- @Override
- public Result addHotMediaInfo(RequestSceneEdit base) throws Exception{
- if(StringUtils.isEmpty(base.getSceneNum()) || StringUtils.isEmpty(base.getType()) ||
- StringUtils.isEmpty(base.getInfo())){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = findBySceneNum(base.getSceneNum());
- if(sceneProEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_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 infoData = FileUtils.readFile(dataBuffer.toString() + "mediaInfo.json");
- JSONArray medias = null;
- if(infoData != null){
- medias= JSONArray.parseArray(infoData);
- }
- if("1".equals(base.getType())){
- JSONObject jo = JSONObject.parseObject(base.getInfo());
- medias.add(jo);
- }else if("1".equals(base.getType())){
- for(int i=0;i<medias.size();++i){
- JSONObject ob = medias.getJSONObject(i);
- if(ob.getString("file").equals(base.getName())){
- medias.remove(i);
- break;
- }
- }
- }else{
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5012, SceneConstant.FAILURE_MSG_5012);
- }
- FileUtils.writeFile(dataBuffer.toString() + "mediaInfo.json", medias.toString());
- return Result.success();
- }
- @Override
- public Result saveScreencapFile(RequestSceneEdit base) throws Exception{
- if(StringUtils.isEmpty(base.getSceneNum()) || StringUtils.isEmpty(base.getIndex()) ||
- StringUtils.isEmpty(base.getCamerasData())){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = findBySceneNum(base.getSceneNum());
- if(sceneProEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_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());
- if("1".equals(base.getIndex())){
- File file = new File(dataBuffer.toString() + ConstantFileName.TOURLIST_FOLDER);
- if(file.isDirectory()){
- String[] strs = file.list();
- if(strs!=null){
- for(int i=0;i<strs.length;++i) {
- if(strs[i].indexOf(ConstantFileName.SCREEN_CRP_DATAFILE)>-1) {
- FileUtils.deleteFile(dataBuffer.toString() + ConstantFileName.TOURLIST_FOLDER + File.separator + strs[i]);
- }
- }
- }
- } else {
- file.mkdirs();
- }
- 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("screencapLen", "0");
- map.put("version", scenejson.getIntValue("version")+1);
- FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map);
- //sceneService.updateScreencapLen(sceneNum, 0);
- }
- String filePath = dataBuffer.toString() + ConstantFileName.TOURLIST_FOLDER+File.separator+ConstantFileName.SCREEN_CRP_DATAFILE+base.getIndex()+"json";
- File file = new File(filePath);
- if(!file.exists())
- {
- file.createNewFile();
- }
- FileUtils.writeFile(filePath, base.getCamerasData());
- return Result.success();
- }
- @Override
- public Result saveSceneKey(RequestSceneEdit base) throws Exception{
- if(StringUtils.isEmpty(base.getSceneNum()) || StringUtils.isEmpty(base.getSceneKey())){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = findBySceneNum(base.getSceneNum());
- if(sceneProEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
- }
- SceneProEditEntity sceneProEditEntity = sceneProEditMapper.findByProId(sceneProEntity.getId());
- sceneProEditEntity.setSceneKey(base.getSceneKey());
- sceneProEditEntity.setNeedKey(0);
- sceneProEditEntity.setVersion(sceneProEditEntity.getVersion() + 1);
- sceneProEditMapper.updateByPrimaryKeySelective(sceneProEditEntity);
- return Result.success();
- }
- @Override
- public Result saveFloorLogo(RequestSceneEdit base) throws Exception{
- if(StringUtils.isEmpty(base.getSceneNum()) || StringUtils.isEmpty(base.getSize()) ||
- StringUtil.isEmpty(base.getLogoType())){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = findBySceneNum(base.getSceneNum());
- if(sceneProEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_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(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("floorLogo", base.getLogoType());
- map.put("floorLogoSize", base.getSize());
- map.put("version", scenejson.getIntValue("version")+1);
- FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map);
- return Result.success();
- }
- @Override
- public Result saveBackgroundMusic(RequestSceneEdit base) throws Exception{
- if(StringUtils.isEmpty(base.getSceneNum()) || StringUtils.isEmpty(base.getMusicName())){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = findBySceneNum(base.getSceneNum());
- if(sceneProEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_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(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("bgMusic", base.getMusicName());
- map.put("version", scenejson.getIntValue("version")+1);
- FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map);
- return Result.success();
- }
- @Override
- public Result saveInitialPage(RequestSceneEdit base) throws Exception{
- if(StringUtils.isEmpty(base.getSceneNum()) || StringUtils.isEmpty(base.getInitialPoint())){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = findBySceneNum(base.getSceneNum());
- if(sceneProEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_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 Result.success();
- }
- @Override
- public Result getScreencapVoice(RequestSceneEdit base) throws Exception{
- if(StringUtils.isEmpty(base.getSceneNum())){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = findBySceneNum(base.getSceneNum());
- if(sceneProEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_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 sceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
- JSONObject scenejson = new JSONObject();
- if(sceneInfos!=null)
- {
- scenejson = JSONObject.parseObject(sceneInfos);
- }
- JSONObject result = new JSONObject();
- String screencapVoiceFileName = "";
- if(scenejson.containsKey("screencapVoiceFileName"))
- {
- screencapVoiceFileName = scenejson.getString("screencapVoiceFileName");
- }
- String screencapVoiceSrc = "";
- if(scenejson.containsKey("screencapVoiceSrc"))
- {
- screencapVoiceSrc = scenejson.getString("screencapVoiceSrc");
- }
- if(!screencapVoiceFileName.trim().equals("")&&!screencapVoiceSrc.trim().equals("")&&screencapVoiceFileName.indexOf(".")>-1)
- {
- result.put("screencapVoiceFileName", screencapVoiceFileName);
- result.put("screencapVoiceSrc1", screencapVoiceSrc);
- result.put("screencapVoiceSrc2", "voice/voice"+base.getSceneNum()+"/201810" +screencapVoiceFileName.substring(screencapVoiceFileName.lastIndexOf(".")));
- }
- return Result.success();
- }
- @Override
- public Result uploadScreencapVoiceNew(String sceneNum, String type, String fileName, MultipartFile file, String length, String replace) throws Exception{
- if(StringUtils.isEmpty(sceneNum)){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = findBySceneNum(sceneNum);
- if(sceneProEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
- }
- if (!file.isEmpty()&& file.getSize() <= 0) {
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5012, SceneConstant.FAILURE_MSG_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") && !StringUtils.isEmpty(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 Result.success("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 Result.success(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 Result.success("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 Result.success(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 Result.success(proVideo);
- }
- FileUtils.changeVoiceToMp3(path + File.separator + name, path + File.separator +"201810.mp3");
- if(StringUtils.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 Result.success(voiceSrc);
- }
- @Override
- public Result uploadScreencapVoiceNewV3(String sceneNum, String type, String fileName, MultipartFile file, String length, String replace, String times, String index) throws Exception{
- if(StringUtils.isEmpty(sceneNum)){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = findBySceneNum(sceneNum);
- if(sceneProEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
- }
- if (!file.isEmpty()&& file.getSize() <= 0) {
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5012, SceneConstant.FAILURE_MSG_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 Result.success("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 Result.success(proVideo);
- }
- // if("sound".equals(type)){
- // FileUtils.changeVoiceToMp3(path + File.separator + name, path + File.separator + originalFileName);
- // map.put("screencapVoiceSoundFileName", originalFileName);
- // String proVideo = "voice/voice"+sceneNum+"/"+originalFileName;
- // 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 Result.success(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 Result.success(voiceSrc);
- }
- @Override
- public Result deleteScreencapVoicePart(String sceneNum, String fileName, String times, String index) throws Exception {
- if(StringUtils.isEmpty(sceneNum)){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = findBySceneNum(sceneNum);
- if(sceneProEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_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 Result.success("voice/voice"+sceneNum+"/"+originalFileName);
- }
- @Override
- public Result deleteScreencapVoice(RequestSceneEdit base) throws Exception{
- if(StringUtils.isEmpty(base.getSceneNum())){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = findBySceneNum(base.getSceneNum());
- if(sceneProEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_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 Result.success();
- }
- 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 Result.success();
- }
- 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 Result.success();
- }
- @Override
- public Result deleteScreencap(RequestSceneEdit base) throws Exception{
- if(StringUtils.isEmpty(base.getSceneNum())){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = findBySceneNum(base.getSceneNum());
- if(sceneProEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_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 capPath = dataBuffer.toString() + ConstantFileName.TOURLIST_FOLDER;
- File file1 = new File(capPath);
- String[] strs = file1.list();
- //删除screenCap对应的json数据
- if(strs!=null) {
- for(int i=0;i<strs.length;++i) {
- if(strs[i].indexOf(ConstantFileName.SCREEN_CRP_DATAFILE)>-1) {
- FileUtils.deleteFile(capPath+File.separator+strs[i]);
- }
- }
- }
- String imgPath = imagesBuffer.toString() + ConstantFileName.TOURLIST_FOLDER;
- String tourListPath = dataBuffer.toString() + ConstantFileName.TOUR_LIST;
- String tourList = FileUtils.readFile(tourListPath);
- JSONArray tourJsons = new JSONArray();
- if(tourList!=null) {
- tourJsons = JSONArray.parseArray(tourList);
- }
- for(int i=0;i<tourJsons.size();++i) {
- String filePath = imgPath + File.separator +"guide"+i+".jpg";
- FileUtils.deleteFile(filePath);
- }
- FileUtils.deleteFile(tourListPath);
- 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("screencapLen", 0);
- map.put("uploadTourList", 1);
- map.put("version", scenejson.getIntValue("version") + 1);
- FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map);
- return Result.success();
- }
- @Override
- public Result saveTourList(RequestSceneEdit base) throws Exception{
- if(StringUtils.isEmpty(base.getSceneNum()) || StringUtils.isEmpty(base.getTourList()) ||
- StringUtils.isEmpty(base.getScreencapLen())){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = findBySceneNum(base.getSceneNum());
- if(sceneProEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_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());
- log.info("editScene/saveTourList:生成tourList.json文件");
- String tourListPath = dataBuffer.toString() + ConstantFileName.TOUR_LIST;
- FileUtils.writeFile(tourListPath, base.getTourList());
- 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("screencapLen", String.valueOf(base.getScreencapLen()));
- // map.put("tourList", tourList);
- map.put("uploadTourList", 1);
- map.put("version", scenejson.getIntValue("version")+1);
- FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map);
- return Result.success();
- }
- @Override
- public Result saveSceneInfo(RequestSceneEdit base) throws Exception{
- if(StringUtils.isEmpty(base.getSceneNum())){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = findBySceneNum(base.getSceneNum());
- if(sceneProEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_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>();
- SceneProEditEntity sceneProEditEntity = sceneProEditMapper.findByProId(sceneProEntity.getId());
- if(!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(!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(!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(!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(!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(!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(!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(!StringUtils.isEmpty(base.getRecordType())){
- scenejson.put("recordType", base.getRecordType());
- }
- if(!StringUtils.isEmpty(base.getMapVisi())){
- scenejson.put("mapVisi", Integer.parseInt(base.getMapVisi()));
- sceneProEditEntity.setMapVisi(Integer.parseInt(base.getMapVisi()));
- }
- if(!StringUtils.isEmpty(base.getTourVisi())){
- scenejson.put("tourVisi", Integer.parseInt(base.getTourVisi()));
- sceneProEditEntity.setTourVisi(Integer.parseInt(base.getTourVisi()));
- }
- if(!StringUtils.isEmpty(base.getVrVisi())){
- scenejson.put("vrVisi", Integer.parseInt(base.getVrVisi()));
- sceneProEditEntity.setVrVisi(Integer.parseInt(base.getVrVisi()));
- }
- if(!StringUtils.isEmpty(base.getRulerVisi())){
- scenejson.put("rulerVisi", Integer.parseInt(base.getRulerVisi()));
- sceneProEditEntity.setRulerVisi(Integer.parseInt(base.getRulerVisi()));
- }
- if(!StringUtils.isEmpty(base.getCadImgVisi())){
- scenejson.put("cadImgVisi", Integer.parseInt(base.getCadImgVisi()));
- sceneProEditEntity.setCadImgVisi(Integer.parseInt(base.getCadImgVisi()));
- }
- if(!StringUtils.isEmpty(base.getPanoVisi())){
- scenejson.put("panoVisi", Integer.parseInt(base.getPanoVisi()));
- sceneProEditEntity.setPanoVisi(Integer.parseInt(base.getPanoVisi()));
- }
- if(!StringUtils.isEmpty(base.getM2dVisi())){
- scenejson.put("m2dVisi", Integer.parseInt(base.getM2dVisi()));
- sceneProEditEntity.setM2dVisi(Integer.parseInt(base.getM2dVisi()));
- }
- if(!StringUtils.isEmpty(base.getM3dVisi())){
- scenejson.put("m3dVisi", Integer.parseInt(base.getM3dVisi()));
- sceneProEditEntity.setM3dVisi(Integer.parseInt(base.getM3dVisi()));
- }
- if(!StringUtils.isEmpty(base.getMeasureVisi())){
- scenejson.put("measureVisi", Integer.parseInt(base.getMeasureVisi()));
- sceneProEditEntity.setMeasureVisi(Integer.parseInt(base.getMeasureVisi()));
- }
- if(!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 = scenejson.getJSONArray("floorPlanPng");
- 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(StringUtil.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(prefixAli + imagesBuf.toString() + "thumbSmallImg.jpg");
- if("s3".equals(this.type)){
- sceneProEntity.setThumb(ConstantUrl.PREFIX_AWS + 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");
- }
- }
- }
- // File hotdic = new File(ConstantFilePath.SCENE_PATH+"images"+File.separator+"images"+base.getSceneNum());
- // if(!hotdic.exists()) {
- // hotdic.mkdirs();
- // }
- // String[] fileNames = hotdic.list();
- // for(int i=0;i<fileNames.length;++i) {
- // if(fileNames[i].contains("hot")&&!hotsids.contains(fileNames[i].substring(0, fileNames[i].lastIndexOf(".")).replace("hot", ""))) {
- // FileUtils.deleteFile(imagesBuffer.toString() + fileNames[i]);
- // }
- // }
- map.put(dataBuffer.toString() + "hot.json",dataBuf.toString() + "hot.json");
- //sceneService.updateHots(sceneNum,hotsids);
- sceneProEditEntity.setHotsIds(hotsids);
- }
- if(StringUtil.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(StringUtil.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(StringUtil.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(StringUtil.isNotEmpty(base.getSceneIndex())) {
- // sceneProEntity.setStyle(Integer.valueOf(base.getSceneIndex()));
- // scenejson.put("sceneIndex", base.getSceneIndex());
- // }
- if(!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"));
- sceneProEditMapper.updateByPrimaryKeySelective(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");
- // map.put(path + File.separator + "results" +File.separator+"modeldata.js","data/"+projectNum+"/"+"modeldata.js");
- // map.put(path + File.separator + "results" +File.separator+"vision.modeldata", "images/images"+projectNum+"/"+"vision.modeldata");
- // if(new File(path + File.separator + "results" +File.separator+"vision2.modeldata").exists()){
- // map.put(path + File.separator + "results" +File.separator+"vision2.modeldata", "images/images"+projectNum+"/"+"vision2.modeldata");
- // }
- // List<String> list1 = FileUtil.readfileNamesForDirectory(path + File.separator + "results" +File.separator+"tex",".jpg");
- // for(int i=0;i<list1.size();++i)
- // {
- // String imgName = list1.get(i);
- // map.put(path + File.separator + "results" +File.separator+"tex"+File.separator+imgName,"images/images"+projectNum+"/"+Constant.modelUUID+"_50k_texture_jpg_high1/"+imgName);
- // }
- 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") && scenejson.getIntValue("buildImages") == 1){
- 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");
- log.info("下载vision.modeldata文件");
- if("s3".equals(this.type)){
- FileUtils.downLoadFromUrl(ConstantUrl.PREFIX_AWS + "images/images" + sceneProEntity.getNum() + "/vision.modeldata" + "?m="+new Date().getTime(),
- "vision.modeldata", target + File.separator + "extras" + File.separator);
- }
- if("oss".equals(this.type)){
- FileUtils.downLoadFromUrl(prefixAli + "images/images" + sceneProEntity.getNum() + "/vision.modeldata" + "?m="+new Date().getTime(),
- "vision.modeldata", target + File.separator + "extras" + File.separator);
- }
- CreateObjUtil.convertVisionmodeldataToTxt(target + File.separator + "extras" + File.separator + "vision.modeldata",
- target + File.separator + "extras" + File.separator + "vision.txt");
- if(images.exists() && images.listFiles() != null && images.listFiles().length > 0){
- FileUtils.copyFile(path + File.separator + "data.json", target + File.separator+"data.json", true);
- FileUtils.copyFile(path + File.separator + "project.json", target + File.separator+"project.json", true);
- //data.json增加extras为执行重建算法
- String data = FileUtils.readFile(target + File.separator+"data.json");
- if(data != null){
- JSONObject floorplanJson = new JSONObject();
- floorplanJson.put("has_source_images", true);
- floorplanJson.put("has_vision_txt", true);
- JSONObject dataJson = JSONObject.parseObject(data);
- dataJson.put("extras", floorplanJson);
- //V5表示不需要生成high,low文件
- dataJson.put("skybox_type", "SKYBOX_V6");
- if(sceneProEntity.getSceneScheme() == 11){
- dataJson.put("skybox_type", "SKYBOX_V7");
- }
- dataJson.put("split_type", "SPLIT_V8");
- //sceneScheme为3切成瓦片图
- if(sceneProEntity.getSceneScheme() == 3){
- dataJson.put("skybox_type", "SKYBOX_V4");
- }
- FileUtils.writeFile(target + File.separator+"data.json", new String(dataJson.toString().getBytes(), "UTF-8"));
- }
- //创建文件夹软连接并且复制data.json和project.json
- if(new File(target + File.separator + "capture").exists()){
- new File(target + File.separator + "capture").delete();
- }
- if(new File(target + File.separator + "results").exists()){
- FileUtils.delAllFile(target + File.separator + "results");
- }
- //下载data.fdage
- if("s3".equals(this.type)){
- //亚马逊保持旧方式,超链接capture
- CreateObjUtil.createSoftConnection(path + File.separator + "capture", target + File.separator + "capture");
- }
- CreateObjUtil.ossUtilCpWithZfbBucket(ConstantFilePath.OSS_PREFIX + path.replace(ConstantFilePath.BUILD_MODEL_PATH, "") + "/data.fdage", target + File.separator + "capture/");
- CreateObjUtil.build3dModel(target , "1");
- //读取upload文件,检验需要上传的文件是否存在
- // Thread.sleep(20000L);
- String uploadPath = target + File.separator + "results" +File.separator+"upload.json";
- long timeStamp = System.currentTimeMillis();
- Integer time = 0;
- boolean isExsts = true;
- while (isExsts){
- File f = new File(uploadPath);
- long diff = System.currentTimeMillis() - timeStamp;
- log.info("文件生产时间倒计时 -- " + diff/1000);
- if (f.exists()) {
- isExsts = false;
- }else{
- if(diff/1000 > 30){
- isExsts = false;
- }
- }
- }
- // String pathW = "/mnt/data/02613f6e8/812690850248130560/7ca7b00e9a90_202102200957308970_images/results/upload.json";
- 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");
- }
- log.info("uploadData" + array);
- 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()){
- uploadToOssUtil.upload(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"));
- uploadToOssUtil.upload(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(StringUtil.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";
- for(File targetFile : new File(targetPath).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) {
- uploadToOssUtil.uploadMulFiles(map);
- }
- update(sceneProEntity);
- sceneProEditMapper.updateByPrimaryKeySelective(sceneProEditEntity);
- return Result.success();
- }
- @Override
- @SystemServiceLog(description = "上传场景的热点媒体文件")
- public Result uploadHotMedia(String sceneNum, MultipartFile file, String sid) throws Exception {
- if(StringUtils.isEmpty(sceneNum)){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = findBySceneNum(sceneNum);
- if(sceneProEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_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 Result.success(fileName);
- }
- @Override
- @SystemServiceLog(description = "保存场景热点")
- public Result saveHot(RequestSceneEdit base) throws Exception {
- if(StringUtils.isEmpty(base.getType())){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- String sid = base.getSid();
- SceneProEntity sceneProEntity = findBySceneNum(base.getSceneNum());
- if (sceneProEntity == null ) {
- return Result.failure(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_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 (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(StringUtil.isEmpty(sid)){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5012, SceneConstant.FAILURE_MSG_5012);
- }
- jsonhots.add(jsonhot);
- }
- else if("0".equals(base.getType())){
- sid = jsonhot.getString("sid");
- if(StringUtil.isEmpty(sid)){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5012, SceneConstant.FAILURE_MSG_5012);
- }
- }
- else if("-1".equals(base.getType())){
- if(StringUtil.isEmpty(sid)){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5012, SceneConstant.FAILURE_MSG_5012);
- }
- }
- //判断是否需要删除自定义热点样式
- String[] styles = null;
- if(StringUtil.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(!"s3".equals(this.type)){
- 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(!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(!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(!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(!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 Result.success();
- }
- @Override
- @SystemServiceLog(description = "保存场景热点")
- public Result saveShopHot(RequestSceneEdit base) throws Exception {
- if(StringUtils.isEmpty(base.getType())){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- String fileName = "shopHot.json";
- String sid = base.getSid();
- SceneProEntity sceneProEntity = findBySceneNum(base.getSceneNum());
- if (sceneProEntity == null ) {
- return Result.failure(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_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() + fileName);
- JSONArray jsonhots = null;
- if (StringUtils.isNotEmpty(str)) {
- jsonhots = JSONArray.parseArray(str);
- }else {
- File file = new File(dataBuffer.toString() + fileName);
- 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(StringUtil.isEmpty(sid)){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5012, SceneConstant.FAILURE_MSG_5012);
- }
- jsonhots.add(jsonhot);
- }
- else if("0".equals(base.getType())){
- sid = jsonhot.getString("sid");
- if(StringUtil.isEmpty(sid)){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5012, SceneConstant.FAILURE_MSG_5012);
- }
- }
- else if("-1".equals(base.getType())){
- if(StringUtil.isEmpty(sid)){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5012, SceneConstant.FAILURE_MSG_5012);
- }
- }
- for(int i=0;i<jsonhots.size();++i){
- JSONObject ele = jsonhots.getJSONObject(i);
- 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");
- }
- }
- }
- else if("0".equals(base.getType())){
- jsonhots.set(i, jsonhot);
- }
- break;
- }
- }
- FileUtils.deleteFile(dataBuffer.toString() + fileName);
- File dataPath = new File(dataBuffer.toString());
- if(!dataPath.exists()){
- dataPath.mkdirs();
- }
- FileUtils.writeFile(dataBuffer.toString() + fileName, jsonhots.toString());
- 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());
- return Result.success();
- }
- @Override
- public Result saveOverlay(RequestSceneEdit base) throws Exception {
- if(StringUtils.isEmpty(base.getType())){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- String sid = base.getSid();
- SceneProEntity sceneProEntity = findBySceneNum(base.getSceneNum());
- if (sceneProEntity == null ) {
- return Result.failure(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
- }
- SceneProEditEntity sceneProEditEntity = sceneProEditMapper.findByProId(sceneProEntity.getId());
- if (sceneProEditEntity == null ) {
- return Result.failure(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_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 (StringUtils.isNotEmpty(str)) {
- jsonOverlays = JSONArray.parseArray(str);
- }else {
- jsonOverlays = new JSONArray();
- }
- //添加或者修改
- if("1".equals(base.getType())){
- sid = jsonOverlay.getString("sid");
- if(StringUtil.isEmpty(sid)){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5012, SceneConstant.FAILURE_MSG_5012);
- }
- jsonOverlays.add(jsonOverlay);
- }
- else if("0".equals(base.getType())){
- sid = jsonOverlay.getString("sid");
- if(StringUtil.isEmpty(sid)){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5012, SceneConstant.FAILURE_MSG_5012);
- }
- }
- else if("-1".equals(base.getType())){
- if(StringUtil.isEmpty(sid)){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5012, SceneConstant.FAILURE_MSG_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());
- sceneProEditMapper.updateByPrimaryKey(sceneProEditEntity);
- return Result.success();
- }
- @Override
- public Result uploadOverlayMedia(String sceneNum, MultipartFile file, String sid) throws Exception {
- if(StringUtils.isEmpty(sceneNum)){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = findBySceneNum(sceneNum);
- if(sceneProEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_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"));
- uploadToOssUtil.upload(path + File.separator + fileName, "images"+File.separator+"images"+sceneNum + File.separator + fileName);
- uploadToOssUtil.upload(path + File.separator + fileName.replace("mp4", "flv"), "images"+File.separator+"images"+sceneNum + File.separator + fileName.replace("mp4", "flv"));
- // if(targetFile.exists()){
- // FileUtils.executeCodecs(path + File.separator + fileName, path, "hot" + sid + "-cut");
- // }
- }
- return Result.success(fileName);
- }
- @Override
- @SystemServiceLog(description = "保存场景热点")
- public Result saveScreencapData(RequestSceneEdit base) throws Exception {
- if(StringUtils.isEmpty(base.getSceneNum())){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = findBySceneNum(base.getSceneNum());
- if(sceneProEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_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 strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
- JSONObject scenejson = new JSONObject();
- if(strsceneInfos!=null) {
- scenejson = JSONObject.parseObject(strsceneInfos);
- }
- if(base.getScreencapVoiceType() != null){
- scenejson.put("screencapVoiceType", base.getScreencapVoiceType());
- }
- if(!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(!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(!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(!StringUtils.isEmpty(base.getScreencapThumb())){
- FileUtils.writeFile(dataBuffer.toString() + "screencapThumb.json", new String(base.getScreencapThumb().getBytes(), "UTF-8"));
- scenejson.put("screencapThumb", dataBuf.toString() + "screencapThumb.json");
- }
- if(!StringUtils.isEmpty(base.getRecordType())){
- scenejson.put("recordType", base.getRecordType());
- }
- scenejson.put("version", scenejson.getIntValue("version") + 1);
- FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
- return Result.success();
- }
- @Override
- @SystemServiceLog(description = "漫游可行")
- public Result saveLinkPano(RequestSceneEdit base) throws Exception {
- if(StringUtils.isEmpty(base.getData()) || StringUtils.isEmpty(base.getSceneNum())){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = findBySceneNum(base.getSceneNum());
- if (sceneProEntity == null ) {
- return Result.failure(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_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 = prefixAli + imagesBuf.toString() + "vision.modeldata?t=" + System.currentTimeMillis();
- if("s3".equals(type)){
- modeldataUrl = ConstantUrl.PREFIX_AWS + 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()) {
- return Result.failure(SceneConstant.FAILURE_CODE_5012, SceneConstant.FAILURE_MSG_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");
- // QiniuUpload.setFileToBucket(dataBuffer.toString() + "vision.modeldata", imagesBuf.toString() + "vision.modeldata");
- uploadToOssUtil.upload(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());
- SceneProEditEntity sceneProEditEntity = sceneProEditMapper.findByProId(sceneProEntity.getId());
- if (sceneProEditEntity == null ) {
- return Result.failure(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
- }
- sceneProEditEntity.setVersion(scenejson.getIntValue("version") + 1);
- sceneProEditMapper.updateByPrimaryKey(sceneProEditEntity);
- return Result.success();
- }
- @Override
- @SystemServiceLog(description = "保存热点可见性的数据")
- public Result saveHotVisible(RequestSceneEdit base) throws Exception {
- if(StringUtils.isEmpty(base.getData()) || StringUtils.isEmpty(base.getSceneNum())){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = findBySceneNum(base.getSceneNum());
- if (sceneProEntity == null ) {
- return Result.failure(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_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 BaseRuntimeException(LoginConstant.FAILURE_CODE_3018, LoginConstant.FAILURE_MSG_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());
- SceneProEditEntity sceneProEditEntity = sceneProEditMapper.findByProId(sceneProEntity.getId());
- sceneProEditEntity.setVersion(sceneProEditEntity.getVersion() + 1);
- sceneProEditMapper.updateByPrimaryKeySelective(sceneProEditEntity);
- FileUtils.deleteFile(dataBuffer.toString() + "hot.json");
- FileUtils.writeFile(dataBuffer.toString() + "hot.json", hots.toString());
- return Result.success();
- }
- @Override
- public Result uploadShareLogo(RequestSceneEdit base, MultipartFile file) throws Exception {
- if(file == null || StringUtils.isEmpty(base.getSceneNum())){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = findBySceneNum(base.getSceneNum());
- if (sceneProEntity == null ) {
- return Result.failure(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_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);
- }
- SceneProEditEntity sceneProEditEntity = sceneProEditMapper.findByProId(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);
- sceneProEditMapper.updateByPrimaryKeySelective(sceneProEditEntity);
- if("V2".equals(sceneProEntity.getBuildType())){
- MatrixToImageWriterUtil.createQRCode(mainUrl + sceneProUrl + sceneProEntity.getNum(), ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneProEntity.getNum()+".png", path + File.separator + fileName);
- MatrixToImageWriterUtil.createQRCode(mainUrl + sceneProUrl + sceneProEntity.getNum() + "&lang=en", ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneProEntity.getNum()+"_en.png", path + File.separator + fileName);
- }
- if("V3".equals(sceneProEntity.getBuildType())){
- MatrixToImageWriterUtil.createQRCode(mainUrl + sceneProNewUrl + sceneProEntity.getNum(), ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneProEntity.getNum()+".png", path + File.separator + fileName);
- MatrixToImageWriterUtil.createQRCode(mainUrl + sceneProNewUrl + sceneProEntity.getNum() + "&lang=en", ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneProEntity.getNum()+"_en.png", path + File.separator + fileName);
- }
- }
- return Result.success(imagesBuf.toString() + fileName);
- }
- @Override
- public Result uploadPic(String sceneNum, String folderName, MultipartFile file, String toOss) throws Exception{
- if(StringUtils.isEmpty(sceneNum)){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = sceneProMapper.findByNum(sceneNum);
- if(sceneProEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
- }
- if (file.isEmpty() && file.getSize() <= 0) {
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5012, SceneConstant.FAILURE_MSG_5012);
- }
- //文件上传的位置可以自定义
- String path = ConstantFilePath.SCENE_PATH+"images"+File.separator+"images"+sceneNum;
- if(StringUtil.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)){
- uploadToOssUtil.upload(path + File.separator + fileName, "images"+File.separator+"images"+sceneNum + File.separator + fileName);
- }
- return Result.success(targetFile.getName());
- }
- @Override
- public Result uploadHotJsonToOss(String sceneNum) throws Exception {
- if(StringUtils.isEmpty(sceneNum)){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- String path = ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+sceneNum;
- uploadToOssUtil.upload(path + File.separator + "hot.json", "data"+File.separator+"data"+sceneNum + File.separator + "hot.json");
- return Result.success();
- }
- @Override
- public Result deleteOss(String filePath) throws Exception {
- uploadToOssUtil.deleteFile(filePath);
- return Result.success();
- }
- @Override
- public Result uploadFloorplanPng(String sceneNum, MultipartFile[] file, String cadInfo) throws Exception{
- if(StringUtils.isEmpty(sceneNum)){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = sceneProMapper.findByNum(sceneNum);
- if(sceneProEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
- }
- if (file.length <= 0) {
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5012, SceneConstant.FAILURE_MSG_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(StringUtil.isNotEmpty(cadInfo)){
- map.put("cadInfo", cadInfo);
- }
- FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map);
- return Result.success(floorPlanPngArr);
- }
- @Override
- public int updateTime(String sceneNum, Long space, int payStatus, String videos, long computeTime) {
- return sceneProMapper.updateTime(sceneNum, space, payStatus, videos, computeTime);
- }
- @Override
- public ResponseScene findLatestOneByUserId(Long userId) {
- return sceneProMapper.findLatestOneByUserId(userId);
- }
- @Override
- public void updateUserIdByCameraId(Long userId, Long cameraId) {
- sceneProMapper.updateUserIdByCameraId(userId, cameraId);
- }
- @Override
- public List<SceneProEntity> findByCameraIdPro(Long cameraId) {
- return sceneProMapper.findByCameraIdPro(cameraId);
- }
- @Override
- public void updateCameraIdByCameraIdPro(Long oldCameraId, Long cameraId) {
- sceneProMapper.updateCameraIdByCameraIdPro(oldCameraId, cameraId);
- }
- @Override
- public int updateRecStatus(String unicode) {
- return sceneProMapper.updateRecStatus(unicode);
- }
- @Override
- public SceneProEntity findByFileId(String fileId) {
- return sceneProMapper.findByFileId(fileId);
- }
- @Override
- public List<SceneProEntity> findTempScenes() throws Exception {
- return sceneProMapper.findTempScenes();
- }
- @Override
- public List<String> findByCameraId(Long cameraId) throws Exception {
- return sceneProMapper.findByCameraId(cameraId);
- }
- @Override
- public Result uploadObjAndImg(String sceneNum, MultipartFile file) throws Exception{
- if(StringUtils.isEmpty(sceneNum)){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = sceneProMapper.findByNum(sceneNum);
- if(sceneProEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
- }
- SceneProEditEntity sceneProEditEntity = sceneProEditMapper.findByProId(sceneProEntity.getId());
- if(sceneProEditEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
- }
- if (file == null || file.getSize() <= 0) {
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5012, SceneConstant.FAILURE_MSG_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();
- }
- // if(file.getOriginalFilename().contains(".obj")){
- // targetFile = new File(filePath + File.separator + "mesh.obj");
- // }else {
- // targetFile = new File(filePath + File.separator + file.getOriginalFilename());
- // }
- // 保存
- 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 BaseRuntimeException(SceneConstant.FAILURE_CODE_5018, SceneConstant.FAILURE_MSG_5018);
- }
- if(data.isDirectory() && !flag){
- flag = true;
- targetName = data.getName();
- }
- }
- boolean objFlag = false;
- boolean mtlFlag = false;
- if(StringUtil.isEmpty(targetName)){
- for(File data : dataFile.listFiles()){
- if(data.getName().endsWith(".obj") && objFlag){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5019, SceneConstant.FAILURE_MSG_5019);
- }
- if(data.getName().endsWith(".jpg") || data.getName().endsWith(".png")){
- if(!FileUtils.checkFileSizeIsLimit(data.length(), 1.5, "M")){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5020, SceneConstant.FAILURE_MSG_5020);
- }
- }
- if(data.getName().endsWith(".obj") && !objFlag){
- if(!FileUtils.checkFileSizeIsLimit(data.length(), 20, "M")){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5020, SceneConstant.FAILURE_MSG_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 BaseRuntimeException(SceneConstant.FAILURE_CODE_5018, SceneConstant.FAILURE_MSG_5018);
- }
- if(data.getName().endsWith(".obj") && objFlag){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5019, SceneConstant.FAILURE_MSG_5019);
- }
- if(data.getName().endsWith(".jpg") || data.getName().endsWith(".png")){
- if(!FileUtils.checkFileSizeIsLimit(data.length(), 1.5, "M")){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5020, SceneConstant.FAILURE_MSG_5020);
- }
- }
- if(data.getName().endsWith(".obj") && !objFlag){
- if(!FileUtils.checkFileSizeIsLimit(data.length(), 20, "M")){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5020, SceneConstant.FAILURE_MSG_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 BaseRuntimeException(SceneConstant.FAILURE_CODE_5019, SceneConstant.FAILURE_MSG_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 BaseRuntimeException(SceneConstant.FAILURE_CODE_5017, SceneConstant.FAILURE_MSG_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) {
- // if(fileName.contains("floor.json")){
- // map.put(path + File.separator + "results" + File.separator + fileName, "data/data" +
- // sceneNum + "/floor.json" );
- //
- // FileUtils.copyFile(path + File.separator + "results" + File.separator + fileName,
- // ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + "/floor.json", true);
- // }
- 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");
- 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");
- uploadToOssUtil.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);
- sceneProEditMapper.updateByPrimaryKeySelective(sceneProEditEntity);
- return Result.success();
- }
- @Override
- public Result uploadLogoBottomStatus(String sceneNum, String status) throws Exception {
- if(StringUtils.isEmpty(sceneNum) || StringUtils.isEmpty(status)){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = sceneProMapper.findByNum(sceneNum);
- if(sceneProEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
- }
- SceneProEditEntity sceneProEditEntity = sceneProEditMapper.findByProId(sceneProEntity.getId());
- if(sceneProEditEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_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));
- sceneProEditMapper.updateByPrimaryKey(sceneProEditEntity);
- return Result.success();
- }
- @Override
- public Result saveJsonData(String sceneNum, String fileName, String jsonData) throws Exception {
- if(StringUtils.isEmpty(sceneNum) || StringUtils.isEmpty(fileName) || StringUtils.isEmpty(jsonData)){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = sceneProMapper.findByNum(sceneNum);
- if(sceneProEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_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.toString());
- return Result.success("scene/" + dataBuf.toString() + fileName);
- }
- @Override
- public String downloadPanoramaOrVideo(String sceneNum, String fileName, String type, String planId) throws Exception {
- if(StringUtils.isEmpty(sceneNum) || StringUtils.isEmpty(fileName) || StringUtils.isEmpty(type)|| StringUtils.isEmpty(planId)){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = sceneProMapper.findByNum(sceneNum);
- if(sceneProEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_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 = "";
- // String zipName = "";
- if("image".equals(type)){
- if(!new File(path + "/caches/images/" + fileName).exists()){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3018, LoginConstant.FAILURE_MSG_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);
- // //将图片打成zip包
- // zipName = imagesBuffer.toString() + "caches/" + sceneNum + "-image-" + planId + ".zip";
- // FileUtils.zipFile(zipName, imagesBuffer.toString() + "caches/" + planId + ".jpg");
- //
- // url = mainUrl + zipName.replace(ConstantFilePath.BASE_PATH + "/", "");
- url = mainUrl + "scene/" + imagesBuf.toString() + "caches/" + planId + ".jpg";
- }
- if("video".equals(type)){
- // if(!new File(path + "/caches/videos/" + fileName).exists()){
- // throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3018, LoginConstant.FAILURE_MSG_3018);
- // }
- //
- // //备份原始数据
- // if(!new File(imagesBuffer.toString() + "caches/back-" + fileName).exists()){
- // FileUtils.copyFile(path + "/caches/videos/" + fileName, imagesBuffer.toString() + "caches/back-" + fileName, false);
- // }
- // //复制打包数据,并且改名
- // FileUtils.copyFile(path + "/caches/videos/" + fileName, imagesBuffer.toString() + "caches/" + planId + ".mp4", true);
- //// //将视频打成zip包
- //// zipName = imagesBuffer.toString() + "caches/" + sceneNum + "-video-" + planId + ".zip";
- //// FileUtils.zipFile(zipName, imagesBuffer.toString() + "caches/" + planId + ".mp4");
- //// url = mainUrl + zipName.replace(ConstantFilePath.BASE_PATH + "/", "");
- //
- // url = mainUrl + "scene/" + imagesBuf.toString() + "caches/" + planId + ".mp4";
- //使用oss的路径
- url = prefixAli + "video/video" + sceneProEntity.getNum() + "/" + planId + ".mp4";
- }
- return url;
- }
- @Override
- public Result uploadPanoramaOrVideo(String sceneNum, String fileName, String type, MultipartFile file, String planId) throws Exception {
- if(StringUtils.isEmpty(sceneNum) || StringUtils.isEmpty(fileName) || StringUtils.isEmpty(type) || StringUtils.isEmpty(planId)){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = sceneProMapper.findByNum(sceneNum);
- if(sceneProEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
- }
- if(!fileName.endsWith(".jpg") && !fileName.endsWith(".mp4")){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5023, SceneConstant.FAILURE_MSG_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);
- }
- scenejson.put("buildImages", 1);
- FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
- return Result.success();
- }
- @Override
- public Result uploadROIVideo(String sceneNum, String fileName, MultipartFile file, String planId, String rect,
- String videoDirMatrix, String dir, String hfov, String vfov) throws Exception {
- if(StringUtils.isEmpty(sceneNum) || StringUtils.isEmpty(fileName) ||
- StringUtils.isEmpty(planId) || StringUtil.isEmpty(rect)){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = sceneProMapper.findByNum(sceneNum);
- if(sceneProEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
- }
- // if(!fileName.endsWith(".mp4")){
- // throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5023, SceneConstant.FAILURE_MSG_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 + "_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/", ""));
- }
- }
- uploadToOssUtil.uploadMulFiles(map);
- scenejson.put("videosUser", jsonArray.toJSONString());
- scenejson.put("imagesVersion", scenejson.getIntValue("imagesVersion") + 1);
- FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
- SceneProEditEntity sceneProEditEntity = sceneProEditMapper.findByProId(sceneProEntity.getId());
- if(sceneProEditEntity != null){
- sceneProEditEntity.setVideosUser(jsonArray.toJSONString());
- sceneProEditEntity.setImagesVersion(sceneProEditEntity.getImagesVersion() + 1);
- sceneProEditMapper.updateByPrimaryKey(sceneProEditEntity);
- }
- return Result.success();
- }
- @Override
- public Result deleteROIVideo(String sceneNum, String fileName, String planId) throws Exception {
- if(StringUtils.isEmpty(sceneNum) || StringUtils.isEmpty(fileName) || StringUtils.isEmpty(planId)){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = sceneProMapper.findByNum(sceneNum);
- if(sceneProEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_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);
- }
- JSONArray newArray = new JSONArray();
- JSONArray jsonArray = new JSONArray();
- JSONObject jsonObject = new JSONObject();
- if(scenejson.containsKey("videosUser")){
- jsonArray = JSON.parseArray(scenejson.getString("videosUser"));
- for(int i = 0, len = jsonArray.size(); i < len; i++){
- jsonObject = jsonArray.getJSONObject(i);
- if(planId.equals(jsonObject.getString("panoId"))){
- continue;
- }
- if(!newArray.contains(jsonObject)){
- newArray.add(jsonObject);
- }
- }
- }
- scenejson.put("videosUser", newArray.toJSONString());
- scenejson.put("imagesVersion", scenejson.getIntValue("imagesVersion") + 1);
- FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
- SceneProEditEntity sceneProEditEntity = sceneProEditMapper.findByProId(sceneProEntity.getId());
- if(sceneProEditEntity != null){
- sceneProEditEntity.setVideosUser(newArray.toJSONString());
- sceneProEditEntity.setImagesVersion(sceneProEditEntity.getImagesVersion() + 1);
- sceneProEditMapper.updateByPrimaryKey(sceneProEditEntity);
- }
- uploadToOssUtil.delete("video/video"+ sceneProEntity.getNum() + File.separator +
- fileName.substring(0, fileName.lastIndexOf(".")) + ".mp4");
- uploadToOssUtil.delete("video/video"+ sceneProEntity.getNum() + File.separator +
- fileName.substring(0, fileName.lastIndexOf(".")) + ".flv");
- FileUtils.deleteFile(ConstantFilePath.SCENE_PATH + "video/video"+ sceneProEntity.getNum() + File.separator + fileName);
- return Result.success();
- }
- @Override
- public Result uploadBgMusic(String sceneNum, String fileName, MultipartFile file) throws Exception {
- if(StringUtils.isEmpty(sceneNum) || StringUtils.isEmpty(fileName)){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = sceneProMapper.findByNum(sceneNum);
- if(sceneProEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_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 Result.success();
- }
- @Override
- public Result deleteUploadBgMusic(String sceneNum) throws Exception {
- if(StringUtils.isEmpty(sceneNum)){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = sceneProMapper.findByNum(sceneNum);
- if(sceneProEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_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 Result.success();
- }
- @Override
- public Result savePanorama(String sceneNum, String sid, MultipartFile file, String imagesName) throws Exception {
- if(StringUtils.isEmpty(sceneNum) || StringUtils.isEmpty(sid)){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = sceneProMapper.findByNum(sceneNum);
- if(sceneProEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
- }
- StringBuffer dataBuf = new StringBuffer()
- .append("data").append(File.separator)
- .append("data").append(sceneProEntity.getNum())
- .append(File.separator);
- StringBuffer imagesBuf = new StringBuffer()
- .append("images").append(File.separator)
- .append("images").append(sceneProEntity.getNum())
- .append(File.separator);
- StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
- StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
- String path = sceneProEntity.getDataSource();
- String target = imagesBuffer.toString() + "panorama/" + sid;
- FileUtils.deleteDirectory(target);
- //文件上传的位置可以自定义
- String filePath = target + File.separator + "extras/images" + File.separator + imagesName;
- File targetFile = new File(filePath);
- if(!targetFile.getParentFile().exists()){
- targetFile.getParentFile().mkdirs();
- }
- //上传文件
- file.transferTo(targetFile);
- //调用算法切全景图
- FileUtils.copyFile(path + File.separator + "data.json", target + File.separator+"data.json", true);
- FileUtils.copyFile(path + File.separator + "project.json", target + File.separator+"project.json", true);
- JSONObject visionJson = new JSONObject();
- JSONArray visionArray = new JSONArray();
- visionJson.put("uuid", imagesName.substring(0, imagesName.lastIndexOf(".")));
- visionJson.put("group", 1);
- visionJson.put("subgroup", 0);
- visionArray.add(visionJson);
- JSONObject vision = new JSONObject();
- vision.put("sweepLocations", visionArray);
- FileUtils.writeFile(target + "/extras" + File.separator + "vision.txt", new String(vision.toString().getBytes(), "UTF-8"));
- //data.json增加extras为执行重建算法
- String data = FileUtils.readFile(target + File.separator + "data.json");
- if(data != null){
- JSONObject floorplanJson = new JSONObject();
- floorplanJson.put("has_source_images", true);
- floorplanJson.put("has_vision_txt", true);
- JSONObject dataJson = JSONObject.parseObject(data);
- dataJson.put("extras", floorplanJson);
- //V5表示不需要生成high,low文件
- dataJson.put("skybox_type", "SKYBOX_V6");
- if(sceneProEntity.getSceneScheme() == 11){
- dataJson.put("skybox_type", "SKYBOX_V7");
- }
- dataJson.put("split_type", "SPLIT_V8");
- if(sceneProEntity.getSceneScheme() == 3){
- dataJson.put("skybox_type", "SKYBOX_V4");
- }
- FileUtils.writeFile(target + File.separator+"data.json", new String(dataJson.toString().getBytes(), "UTF-8"));
- }
- //创建文件夹软连接并且复制data.json和project.json
- if(new File(target + File.separator + "capture").exists()){
- new File(target + File.separator + "capture").delete();
- }
- if(new File(target + File.separator + "results").exists()){
- FileUtils.delAllFile(target + File.separator + "results");
- }
- //下载data.fdage
- if("s3".equals(this.type)){
- //亚马逊保持旧方式,超链接capture
- CreateObjUtil.createSoftConnection(path + File.separator + "capture", target + File.separator + "capture");
- }
- CreateObjUtil.ossUtilCpWithZfbBucket(ConstantFilePath.OSS_PREFIX + path.replace(ConstantFilePath.BUILD_MODEL_PATH, "") + "/data.fdage", target + File.separator + "capture/");
- CreateObjUtil.build3dModel(target , "1");
- // CreateObjUtil.build3dModel2(target , "1");
- //读取upload文件,检验需要上传的文件是否存在
- // Thread.sleep(20000L);
- String uploadPath = target + File.separator + "results" +File.separator+"upload.json";
- long timeStamp = System.currentTimeMillis();
- Integer time = 0;
- boolean isExsts = true;
- while (isExsts){
- File f = new File(uploadPath);
- long diff = System.currentTimeMillis() - timeStamp;
- log.info("文件生产时间倒计时 -- " + diff/1000);
- if (f.exists()) {
- isExsts = false;
- }else{
- if(diff/1000 > 30){
- isExsts = false;
- }
- }
- }
- String uploadData = FileUtils.readFile(target + File.separator + "results" +File.separator+"upload.json");
- JSONObject uploadJson = null;
- JSONArray array = null;
- if(uploadData!=null) {
- uploadJson = JSONObject.parseObject(uploadData);
- array = uploadJson.getJSONArray("upload");
- }
- if(array == null){
- log.info("计算全景图失败,没有upload.json");
- }
- Map<String, String> map = new HashMap<>();
- JSONObject fileJson = null;
- String fileName = "";
- String img = "";
- for(int i = 0, len = array.size(); i < len; i++){
- fileJson = array.getJSONObject(i);
- fileName = fileJson.getString("file");
- //文件不存在抛出异常
- if(!new File(target + File.separator + "results" +File.separator + fileName).exists()){
- throw new Exception(target + File.separator + "results" +File.separator + fileName+"文件不存在");
- }
- //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){
- img = "/results" + File.separator + fileName;
- map.put(target + File.separator + "results" +File.separator+ fileName,"images/images"+
- sceneProEntity.getNum()+"/pan/low/"+ fileName.replace("low/", ""));
- continue;
- }
- //tiles文件夹,亚马逊没有裁剪图片api,不需要上传4k图
- if(fileJson.getIntValue("clazz") == 5){
- map.put(target + File.separator + "results" + File.separator+ fileName,"images/images"+
- sceneProEntity.getNum()+ "/panorama_edit/" + sid + File.separator + fileName);
- }
- //tiles文件夹,亚马逊瓦片图
- if(fileJson.getIntValue("clazz") == 7 ){
- map.put(target + File.separator + "results" + File.separator+ fileName,"images/images"+
- sceneProEntity.getNum()+ File.separator + fileName);
- }
- }
- //上传全景图
- map.put(filePath, "images/images"+ sceneProEntity.getNum()+ File.separator + "pan/high/" + imagesName);
- uploadToOssUtil.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 Result.success(result);
- }
- @Override
- public Result savePanoramaJson(String sceneNum, String fileData, String fileName, String sid) throws Exception {
- if(StringUtils.isEmpty(sceneNum) || StringUtils.isEmpty(fileName)){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = sceneProMapper.findByNum(sceneNum);
- if(sceneProEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_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(StringUtils.isNotEmpty(fileData)){
- scenejson.put("jumpScene", true);
- }else {
- scenejson.put("jumpScene", false);
- }
- FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
- if(StringUtils.isNotEmpty(sid)){
- String target = imagesBuffer.toString() + "panorama/" + sid;
- FileUtils.deleteDirectory(target);
- // uploadToOssUtil.deleteFile(imagesBuf.toString() + "panorama/" + sid);
- uploadToOssUtil.deleteFile(imagesBuf.toString() + "panorama_edit/" + sid);
- }
- return Result.success();
- }
- @Override
- public Result copyAndUpdateFloorJson(String sceneNum, String floorJsonData) throws Exception{
- if(StringUtils.isEmpty(sceneNum) ){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_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);
- }
- if(StringUtils.isEmpty(floorJsonData)){
- SceneProEntity sceneProEntity = sceneProMapper.findByNum(sceneNum);
- if(sceneProEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
- }
- FileUtils.copyFile(sceneProEntity.getDataSource() + "/results/floor.json", dataBuffer.toString() + "houst_floor.json", true);
- uploadToOssUtil.upload(dataBuffer.toString() + "houst_floor.json", dataBuf.toString() + "houst_floor.json");
- String result = FileUtils.readFile(dataBuffer.toString() + "houst_floor.json");
- return Result.success((Object) result);
- }
- FileUtils.writeFile(dataBuffer.toString() + "houst_floor.json", floorJsonData);
- uploadToOssUtil.upload(dataBuffer.toString() + "houst_floor.json", dataBuf.toString() + "houst_floor.json");
- return Result.success((Object) floorJsonData);
- }
- @Override
- public Result updateFloorJson(String sceneNum, String floorJsonData) throws Exception{
- if(StringUtils.isEmpty(sceneNum) || StringUtils.isEmpty(floorJsonData)){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_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());
- // uploadToOssUtil.upload(dataBuffer.toString() + "houst_floor.json", dataBuf.toString() + "houst_floor.json");
- return Result.success((Object) floorJsonData);
- }
- @Override
- public PageInfo<ResponseScene> queryCompanySceneListByParams(RequestScene param) {
- int pageNum = param.getPageNum();
- int pageSize = param.getPageSize();
- Page page = PageHelper.startPage(pageNum, pageSize, true);
- PageHelper.orderBy(" a.create_time desc");
- List<ResponseScene> result = sceneProMapper.queryCompanySceneListByParams(param);
- Page<ResponseScene> a = new Page<ResponseScene>(param.getPageNum(), param.getPageSize());
- a.setTotal(page.getTotal());
- PageInfo<ResponseScene> pageInfo = a.toPageInfo();
- pageInfo.setList(result);
- return pageInfo;
- }
- @Override
- public PageInfo<ResponseScene> getAppAllSceneByPage(Long cameraId, Long userId, int cameraType, int pageNum, Integer pageSize, String orderBy, Integer sceneType, String nums, String sceneName) {
- Page page = PageHelper.startPage(pageNum, pageSize, true);
- if(StringUtil.isEmpty(orderBy)){
- PageHelper.orderBy(" create_time desc");
- }else {
- PageHelper.orderBy(orderBy);
- }
- if(StringUtil.isEmpty(nums)){
- nums = null;
- }
- List<ResponseScene> result = sceneProMapper.getAppAllSceneByPage(cameraId, userId, cameraType, sceneType, nums, sceneName);
- Page<ResponseScene> a = new Page<ResponseScene>(pageNum, pageSize);
- a.setTotal(page.getTotal());
- PageInfo<ResponseScene> pageInfo = a.toPageInfo();
- pageInfo.setList(result);
- return pageInfo;
- }
- @Override
- public Integer findSceneNumByCameraId(Long cameraId) {
- return sceneProMapper.findSceneNumByCameraId(cameraId);
- }
- @Override
- public SceneProEntity findLastSceneByCameraId(Long cameraId) {
- return sceneProMapper.findLastSceneByCameraId(cameraId);
- }
- @Override
- public BigInteger findTotalSpaceByCameraId(Long cmaeraId) {
- return sceneProMapper.findTotalSpaceByCameraId(cmaeraId);
- }
- @Override
- public void updatePayStatusByCameraId(Integer payStatus, Long cameraId) {
- sceneProMapper.updatePayStatusByCameraId(payStatus, cameraId);
- }
- @Override
- public Result downloadVisionData(String sceneNum) throws Exception {
- if(StringUtils.isEmpty(sceneNum)){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = findBySceneNum(sceneNum);
- if(sceneProEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_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 modeldataUrl = prefixAli + imagesBuf.toString() + "vision.modeldata?t=" + System.currentTimeMillis();
- if("s3".equals(type)){
- modeldataUrl = ConstantUrl.PREFIX_AWS + 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()) {
- return Result.failure(SceneConstant.FAILURE_CODE_5012, SceneConstant.FAILURE_MSG_5012);
- }
- ConvertUtils.convertVisionModelDataToTxt(dataBuffer.toString() + "vision.modeldata", dataBuffer.toString() + "vision.json");
- uploadToOssUtil.upload(dataBuffer.toString() + "vision.json", dataBuf.toString() + "vision.json");
- return Result.success(prefixAli + dataBuf.toString() + "vision.json?t=" + System.currentTimeMillis());
- }
- @Override
- public Result downloadPanoramaData(String sceneNum) throws Exception {
- if(StringUtils.isEmpty(sceneNum)){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = findBySceneNum(sceneNum);
- if(sceneProEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_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()){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5012, SceneConstant.FAILURE_MSG_5012);
- }
- FileUtils.zipFile(imagesBuffer.toString() + sceneNum + "-high.zip", highPath);
- uploadToOssUtil.upload(imagesBuffer.toString() + sceneNum + "-high.zip", imagesBuf.toString() + sceneNum + "-high.zip");
- return Result.success(prefixAli + imagesBuf.toString() + sceneNum + "-high.zip?t=" + System.currentTimeMillis());
- }
- @Override
- public Result getInfo(String sceneNum) throws Exception {
- if(StringUtils.isEmpty(sceneNum)){
- throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- SceneProEntity sceneProEntity = findBySceneNum(sceneNum);
- if(sceneProEntity == null){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
- }
- if(sceneProEntity.getPayStatus() != 1){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
- }
- if(sceneProEntity.getStatus() != 1 && sceneProEntity.getStatus() != -2){
- throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
- }
- ResponseScene responseScene = new ResponseScene();
- SceneProEditEntity editEntity = sceneProEditMapper.findByProId(sceneProEntity.getId());
- BeanUtils.copyProperties(editEntity, responseScene);
- BeanUtils.copyProperties(sceneProEntity, responseScene);
- if(StringUtil.isNotEmpty(editEntity.getEntry())){
- responseScene.setEntry(JSONObject.parseObject(editEntity.getEntry()).toJSONString());
- }
- if(StringUtil.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(StringUtil.isEmpty(editEntity.getSceneKey())){
- responseScene.setIsPublic(0);
- }else {
- responseScene.setIsPublic(1);
- }
- //不返回场景访问密码
- responseScene.setSceneKey("");
- //查询是否有随心装场景
- if(sceneNum.indexOf("vr-")!=-1){
- SceneProEntity vrSceneProEntity = findLikeSceneNum(sceneNum);
- if(vrSceneProEntity != null){
- responseScene.setVrNum(vrSceneProEntity.getNum());
- responseScene.setVideosUser(null);
- responseScene.setBgMusicName(null);
- responseScene.setBgMusic(null);
- }
- }
-
- //更新访问数量
- sceneService.updateViewCount(sceneNum);
- return Result.success(responseScene);
- }
- @Override
- public Integer findFolderIdScence(Long folderId, Long userId) {
- return sceneProMapper.findFolderIdScence(folderId,userId);
- }
- @Override
- public void updatePayStatus(Long id, Integer status) {
- sceneProMapper.updatePayStatus(id,status);
- }
- @Override
- public SceneProEntity getById(Long id) {
- return sceneProMapper.getById(id);
- }
- public static void main(String[] args) {
- try {
- Thumbnails.of("C:\\Users\\hisun\\Downloads\\100m.jpg").size(1024,512).toFile("C:\\Users\\hisun\\Downloads\\100m-T.jpg");
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
|