SceneProServiceImpl.java 231 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181
  1. package com.fdkankan.scene.service.impl;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import cn.hutool.core.collection.CollUtil;
  4. import cn.hutool.core.date.DateUtil;
  5. import cn.hutool.core.util.StrUtil;
  6. import cn.hutool.core.util.ZipUtil;
  7. import com.alibaba.csp.sentinel.util.StringUtil;
  8. import com.alibaba.fastjson.JSON;
  9. import com.alibaba.fastjson.JSONArray;
  10. import com.alibaba.fastjson.JSONObject;
  11. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  12. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  13. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  14. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  15. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  16. import com.fdkankan.common.constant.CameraConstant;
  17. import com.fdkankan.common.constant.CommonStatus;
  18. import com.fdkankan.common.constant.ConstantFileName;
  19. import com.fdkankan.common.constant.ConstantFilePath;
  20. import com.fdkankan.common.constant.ConstantUrl;
  21. import com.fdkankan.common.constant.ErrorCode;
  22. import com.fdkankan.common.constant.OperationType;
  23. import com.fdkankan.common.constant.PayStatus;
  24. import com.fdkankan.common.constant.RecStatus;
  25. import com.fdkankan.common.constant.SceneEditType;
  26. import com.fdkankan.common.constant.SceneStatus;
  27. import com.fdkankan.common.constant.SceneType;
  28. import com.fdkankan.common.constant.ServerCode;
  29. import com.fdkankan.common.constant.TbStatus;
  30. import com.fdkankan.common.constant.UploadFilePath;
  31. import com.fdkankan.common.exception.BusinessException;
  32. import com.fdkankan.common.response.ResultData;
  33. import com.fdkankan.common.user.SSOLoginHelper;
  34. import com.fdkankan.common.user.SSOUser;
  35. import com.fdkankan.common.util.ComputerUtil;
  36. import com.fdkankan.common.util.ConvertUtils;
  37. import com.fdkankan.common.util.CreateObjUtil;
  38. import com.fdkankan.common.util.DateExtUtil;
  39. import com.fdkankan.common.util.FileMd5Util;
  40. import com.fdkankan.common.util.FileUtils;
  41. import com.fdkankan.common.util.MatrixToImageWriterUtil;
  42. import com.fdkankan.common.util.OkHttpUtils;
  43. import com.fdkankan.fyun.constant.StorageType;
  44. import com.fdkankan.fyun.oss.UploadToOssUtil;
  45. import com.fdkankan.platform.api.dto.Camera;
  46. import com.fdkankan.platform.api.dto.CameraDetail;
  47. import com.fdkankan.platform.api.feign.PlatformGoodsClient;
  48. import com.fdkankan.redis.constant.RedisKey;
  49. import com.fdkankan.redis.constant.RedisLockKey;
  50. import com.fdkankan.redis.util.RedisLockUtil;
  51. import com.fdkankan.redis.util.RedisUtil;
  52. import com.fdkankan.scene.bean.IconBean;
  53. import com.fdkankan.scene.bean.TagBean;
  54. import com.fdkankan.scene.entity.SceneDataDownload;
  55. import com.fdkankan.scene.entity.SceneDownloadLog;
  56. import com.fdkankan.scene.entity.SceneEditInfo;
  57. import com.fdkankan.scene.entity.ScenePlus;
  58. import com.fdkankan.scene.entity.ScenePlusExt;
  59. import com.fdkankan.scene.entity.ScenePro;
  60. import com.fdkankan.scene.entity.SceneProEdit;
  61. import com.fdkankan.scene.entity.SceneProEditExt;
  62. import com.fdkankan.scene.entity.SceneProExt;
  63. import com.fdkankan.scene.entity.SceneProPO;
  64. import com.fdkankan.scene.mapper.ISceneProMapper;
  65. import com.fdkankan.scene.service.IFdkkLaserService;
  66. import com.fdkankan.scene.service.ISceneDataDownloadService;
  67. import com.fdkankan.scene.service.ISceneDownloadLogService;
  68. import com.fdkankan.scene.service.ISceneEditControlsService;
  69. import com.fdkankan.scene.service.ISceneEditInfoService;
  70. import com.fdkankan.scene.service.IScenePlusExtService;
  71. import com.fdkankan.scene.service.IScenePlusService;
  72. import com.fdkankan.scene.service.ISceneProEditExtService;
  73. import com.fdkankan.scene.service.ISceneProEditService;
  74. import com.fdkankan.scene.service.ISceneProExtService;
  75. import com.fdkankan.scene.service.ISceneProService;
  76. import com.fdkankan.scene.service.ISceneService;
  77. import com.fdkankan.scene.vo.BaseDataParamVO;
  78. import com.fdkankan.scene.vo.DeleteHotIconParamVO;
  79. import com.fdkankan.scene.vo.DeleteHotParamVO;
  80. import com.fdkankan.scene.vo.FileNameAndDataParamVO;
  81. import com.fdkankan.scene.vo.FileParamVO;
  82. import com.fdkankan.scene.vo.HotParamVO;
  83. import com.fdkankan.scene.vo.SaveTagsParamVO;
  84. import com.fdkankan.scene.vo.SaveTagsVisibleParamVO;
  85. import com.fdkankan.scene.vo.SceneBySnCodeVo;
  86. import com.fdkankan.scene.vo.SceneEditParamVO;
  87. import com.fdkankan.scene.vo.SceneParamVO;
  88. import com.fdkankan.scene.vo.SceneProVO;
  89. import com.fdkankan.scene.vo.SceneVO;
  90. import com.google.common.collect.Lists;
  91. import com.google.common.collect.Sets;
  92. import java.nio.charset.StandardCharsets;
  93. import java.io.BufferedReader;
  94. import java.io.File;
  95. import java.io.IOException;
  96. import java.io.InputStreamReader;
  97. import java.net.HttpURLConnection;
  98. import java.net.URL;
  99. import java.util.ArrayList;
  100. import java.util.Calendar;
  101. import java.util.Comparator;
  102. import java.util.Date;
  103. import java.util.HashMap;
  104. import java.util.List;
  105. import java.util.Map;
  106. import java.util.Map.Entry;
  107. import java.util.Objects;
  108. import java.util.Set;
  109. import java.util.UUID;
  110. import java.util.stream.Collectors;
  111. import javax.annotation.Resource;
  112. import java.nio.charset.StandardCharsets;
  113. import lombok.extern.slf4j.Slf4j;
  114. import org.apache.commons.lang3.StringUtils;
  115. import org.joda.time.DateTime;
  116. import org.springframework.beans.BeanUtils;
  117. import org.springframework.beans.factory.annotation.Autowired;
  118. import org.springframework.beans.factory.annotation.Qualifier;
  119. import org.springframework.beans.factory.annotation.Value;
  120. import org.springframework.stereotype.Service;
  121. import org.springframework.transaction.annotation.Transactional;
  122. import org.springframework.util.ObjectUtils;
  123. import org.springframework.web.multipart.MultipartFile;
  124. /**
  125. * <p>
  126. * pro场景表 服务实现类
  127. * </p>
  128. *
  129. * @author dengsixing
  130. * @since 2021-12-23
  131. */
  132. @Slf4j
  133. @Service
  134. public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro> implements ISceneProService {
  135. @Value("${oss.prefix.ali}")
  136. private String prefixAli;
  137. @Value("${oss.prefix.url}")
  138. private String ossUrlPrefix;
  139. @Value("${upload.type}")
  140. private String type;
  141. @Value("${hot.domain.list}")
  142. private String hotDomainList;
  143. @Value("${hot.delete}")
  144. private String hotDelete;
  145. @Value("${main.url}")
  146. private String mainUrl;
  147. @Value("${scene.url}")
  148. private String sceneUrl;
  149. @Value("${scene.pro.url}")
  150. private String sceneProUrl;
  151. @Value("${scene.pro.new.url}")
  152. private String sceneProNewUrl;
  153. @Value("${ecs.checkFile.maxTimes:5}")
  154. private int maxCheckTimes;
  155. @Value("${ecs.checkFile.waitTime:5000}")
  156. private int waitTime;
  157. @Value("${http.host.4dkankanMini}")
  158. private String fkankanMiniHost;
  159. @Value("${http.api-v4.upgradeToV4ResultSync}")
  160. private String URL_UPGRADE_TO_V4_RESULT_SYNC;
  161. @Autowired
  162. @Qualifier("uploadToOssUtil")
  163. UploadToOssUtil uploadToOssUtil;
  164. @Autowired
  165. ISceneProExtService sceneProExtService;
  166. @Autowired
  167. ISceneProEditService sceneProEditService;
  168. @Autowired
  169. ISceneProEditExtService sceneProEditExtService;
  170. @Autowired
  171. ISceneService sceneService;
  172. @Autowired
  173. RedisLockUtil redisLockUtil;
  174. @Autowired
  175. private RedisUtil redisUtil;
  176. @Autowired
  177. ISceneDataDownloadService sceneDataDownloadService;
  178. @Autowired
  179. PlatformGoodsClient platformGoodsClient;
  180. @Autowired
  181. ISceneProService sceneProService;
  182. @Autowired
  183. ISceneEditInfoService sceneEditInfoService;
  184. @Autowired
  185. ISceneEditControlsService sceneEditControlsService;
  186. @Autowired
  187. IScenePlusService scenePlusService;
  188. @Autowired
  189. IScenePlusExtService scenePlusExtService;
  190. @Autowired
  191. ISceneDownloadLogService sceneDownloadLogService;
  192. @Autowired
  193. SSOLoginHelper ssoLoginHelper;
  194. @Autowired
  195. IFdkkLaserService fdkkLaserService;
  196. @Resource
  197. ISceneProMapper sceneProMapper;
  198. @Override
  199. public List<SceneVO> convert(List<ScenePro> list){
  200. List<SceneVO> sceneVOS = list.parallelStream().map(scenePro -> {
  201. SceneVO sceneVo = new SceneVO();
  202. SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
  203. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  204. SceneProEditExt sceneProEditExt = sceneProEditExtService.getByProEditId(sceneProEdit.getId());
  205. BeanUtils.copyProperties(sceneProEditExt, sceneVo);
  206. BeanUtils.copyProperties(sceneProEdit, sceneVo);
  207. BeanUtils.copyProperties(sceneProExt, sceneVo);
  208. BeanUtils.copyProperties(scenePro, sceneVo);
  209. sceneVo.setCreateTime(DateUtil.format(scenePro.getCreateTime(), DateExtUtil.dateStyle4));
  210. sceneVo.setCreateDate(scenePro.getCreateTime().getTime());
  211. return sceneVo;
  212. }).collect(Collectors.toList());
  213. return sceneVOS;
  214. }
  215. @Override
  216. public List<SceneVO> convert2(List<SceneProPO> list){
  217. List<SceneVO> sceneVOS = list.parallelStream().map(po -> {
  218. SceneVO sceneVo = new SceneVO();
  219. SceneProEdit sceneProEdit = sceneProEditService.findByProId(po.getId());
  220. SceneProEditExt sceneProEditExt = sceneProEditExtService.getByProEditId(sceneProEdit.getId());
  221. BeanUtils.copyProperties(sceneProEditExt, sceneVo);
  222. BeanUtils.copyProperties(sceneProEdit, sceneVo);
  223. BeanUtils.copyProperties(po, sceneVo);
  224. sceneVo.setCreateTime(DateUtil.format(po.getCreateTime(), DateExtUtil.dateStyle4));
  225. sceneVo.setCreateDate(po.getCreateTime().getTime());
  226. return sceneVo;
  227. }).collect(Collectors.toList());
  228. return sceneVOS;
  229. }
  230. @Override
  231. public Long getSceneCount(Long cameraId,Long userId) {
  232. LambdaQueryWrapper<ScenePro> queryWrapper = new LambdaQueryWrapper<ScenePro>()
  233. .eq(ScenePro::getTbStatus, TbStatus.VALID.code())
  234. .notIn(ScenePro::getSceneType, SceneType.YJHZXNFY.code());
  235. if(cameraId !=null){
  236. queryWrapper.eq(ScenePro::getCameraId ,cameraId);
  237. }
  238. if(userId !=null){
  239. queryWrapper.eq(ScenePro::getUserId ,userId);
  240. }
  241. return this.count(queryWrapper);
  242. }
  243. @Override
  244. public ScenePro findBySceneNum(String sceneNum) {
  245. return this.getOne(new LambdaQueryWrapper<ScenePro>()
  246. .eq(ScenePro::getTbStatus, TbStatus.VALID.code())
  247. .eq(ScenePro::getNum, sceneNum));
  248. }
  249. @Override
  250. public ScenePro findDeleteSceneBySceneNum(String sceneNum) {
  251. List<ScenePro> list = this.list(new LambdaQueryWrapper<ScenePro>()
  252. .eq(ScenePro::getTbStatus, TbStatus.DELETE.code())
  253. .eq(ScenePro::getNum, sceneNum));
  254. if(CollUtil.isEmpty(list)){
  255. return null;
  256. }
  257. return list.get(0);
  258. }
  259. @Override
  260. public SceneProPO getSceneStatusByUnicode(String unicode, Integer tbStatus) {
  261. return baseMapper.getSceneStatusByUnicode(unicode, tbStatus);
  262. }
  263. @Override
  264. public List<SceneProPO> findByUserIdAndCameraType(Long userId, Integer cameraType) {
  265. return baseMapper.findByUserIdAndCameraType(userId, cameraType);
  266. }
  267. public List<SceneProPO> findByUserId(Long userId, List<String> excludeNums) {
  268. return baseMapper.findByUserId(userId,excludeNums);
  269. }
  270. @Override
  271. public List<SceneProPO> findBySceneNums(List<String> sceneCodeList, Integer cameraType) {
  272. return baseMapper.findBySceneNums(sceneCodeList, cameraType);
  273. }
  274. @Override
  275. public void updateStatus(String sceneNum, int sceneStatus) {
  276. this.update(new LambdaUpdateWrapper<ScenePro>()
  277. .eq(ScenePro::getNum, sceneNum)
  278. .set(ScenePro::getSceneStatus, sceneStatus));
  279. }
  280. @Override
  281. public ResultData resetUploadFloorJson(SceneEditParamVO sceneEdit) throws Exception{
  282. if(StrUtil.isEmpty(sceneEdit.getNum())){
  283. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  284. }
  285. ScenePro scenePro = findBySceneNum(sceneEdit.getNum());
  286. if(scenePro == null){
  287. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  288. }
  289. StringBuffer dataBuf = new StringBuffer()
  290. .append("data").append(File.separator)
  291. .append("data").append(scenePro.getNum())
  292. .append(File.separator);
  293. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  294. //更新scene.json文件
  295. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  296. JSONObject scenejson = new JSONObject();
  297. if(strsceneInfos!=null)
  298. {
  299. scenejson = JSONObject.parseObject(strsceneInfos);
  300. }else {
  301. new File(dataBuffer.toString() + "scene.json").createNewFile();
  302. }
  303. if(!StrUtil.isEmpty(sceneEdit.getSceneData())){
  304. JSONObject sceneObject = JSONObject.parseObject(sceneEdit.getSceneData());
  305. Set<String> set =sceneObject.keySet();
  306. for(String key : set){
  307. scenejson.put(key, sceneObject.get(key));
  308. }
  309. }
  310. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  311. SceneProEditExt sceneProEditExt = sceneProEditExtService.getByProEditId(sceneProEdit.getId());
  312. //重置将floorEditVer回归floorPublishVer
  313. sceneProEdit.setFloorPublishVer(sceneProEdit.getFloorEditVer());
  314. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  315. sceneProEditService.updateById(sceneProEdit);
  316. //更新scene.json文件
  317. if(strsceneInfos!=null){
  318. scenejson.put("floorEditVer", sceneProEdit.getFloorEditVer());
  319. scenejson.put("floorPublishVer", sceneProEdit.getFloorEditVer());
  320. scenejson.put("cadInfo", sceneProEditExt.getCadInfo());
  321. FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
  322. log.info("写入scene.json文件完成, sceneCode:{}", sceneEdit.getNum());
  323. }
  324. log.info("重置画墙重建模型版本成功");
  325. return ResultData.ok();
  326. }
  327. @Override
  328. public ResultData uploadFloorJson(SceneEditParamVO sceneEdit) throws Exception {
  329. String lockKey = String.format(RedisLockKey.LOCK_UPLOAD_FLOORJSON_REBUILD, sceneEdit.getNum());
  330. Boolean lock = redisLockUtil.lock(lockKey, RedisKey.EXPIRE_TIME_2_HOUR);
  331. if(!lock){
  332. throw new BusinessException(ErrorCode.FAILURE_CODE_5036);
  333. }
  334. try {
  335. long start = System.currentTimeMillis();
  336. log.info("画墙重建模型开始时间:" + start);
  337. if(StrUtil.isEmpty(sceneEdit.getNum())){
  338. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  339. }
  340. ScenePro scenePro = findBySceneNum(sceneEdit.getNum());
  341. if(scenePro == null){
  342. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  343. }
  344. SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
  345. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  346. if(sceneProEdit == null){
  347. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  348. }
  349. //更新scene.json文件
  350. String strsceneInfos = FileUtils.readFile(ConstantFilePath.SCENE_PATH + "data" + File.separator + "data" + sceneEdit.getNum() + File.separator + "scene.json");
  351. JSONObject scenejson = new JSONObject();
  352. if(strsceneInfos!=null)
  353. {
  354. scenejson = JSONObject.parseObject(strsceneInfos);
  355. }else {
  356. new File(ConstantFilePath.SCENE_PATH + "data" + File.separator + "data" + sceneEdit.getNum() + File.separator + "scene.json").createNewFile();
  357. }
  358. if(!StrUtil.isEmpty(sceneEdit.getSceneData())){
  359. JSONObject sceneObject = JSONObject.parseObject(sceneEdit.getSceneData());
  360. Set<String> set =sceneObject.keySet();
  361. for(String key : set){
  362. scenejson.put(key, sceneObject.get(key));
  363. }
  364. }
  365. //保存floor.json前端下次进入需要使用
  366. if(StrUtil.isEmpty(sceneEdit.getWebFloor())){
  367. sceneEdit.setWebFloor(sceneEdit.getFloor());
  368. }
  369. //上传过模型只更新floor.json
  370. FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+sceneEdit.getNum() + File.separator + "floor.json", new String(sceneEdit.getWebFloor().getBytes(), "UTF-8"));
  371. //更新scene.json文件
  372. if(strsceneInfos!=null)
  373. {
  374. scenejson.put("floorEditVer", sceneProEdit.getFloorEditVer() + 1);
  375. scenejson.put("floorPublishVer", sceneProEdit.getFloorPublishVer());
  376. FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+sceneEdit.getNum()+File.separator+"scene.json", scenejson.toString());
  377. log.info("写入scene.json文件完成——"+sceneEdit.getNum());
  378. }
  379. //floorEditVer字段增加1
  380. sceneProEdit.setFloorEditVer(sceneProEdit.getFloorEditVer() + 1);
  381. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  382. sceneProEditService.updateById(sceneProEdit);
  383. String path = sceneProExt.getDataSource();
  384. if(path != null && !"".equals(path) && path.startsWith("http")){
  385. path = ConstantFilePath.BUILD_MODEL_PATH + File.separator + path.split("/")[path.split("/").length - 2];
  386. }
  387. String target = path + "_edit";
  388. File editPath = new File(target);
  389. if(!editPath.exists()){
  390. editPath.mkdirs();
  391. }
  392. //创建文件夹软连接并且复制data.json和project.json
  393. if(new File(target + File.separator + "capture").exists()){
  394. new File(target + File.separator + "capture").delete();
  395. }
  396. if(new File(target + File.separator + "caches").exists()){
  397. //删除link
  398. new File(target + File.separator + "caches" + File.separator + "images").delete();
  399. //删除所有文件
  400. FileUtils.delAllFile(target + File.separator + "caches");
  401. }
  402. if(new File(target + File.separator + "results").exists()){
  403. FileUtils.delAllFile(target + File.separator + "results");
  404. }
  405. //创建文件夹,并link文件夹
  406. new File(target + File.separator + "caches").mkdirs();
  407. CreateObjUtil.createSoftConnection(path + File.separator + "capture", target + File.separator + "capture");
  408. if(new File(path + File.separator + "caches" + File.separator + "images").exists()){
  409. CreateObjUtil.createSoftConnection(path + File.separator + "caches" + File.separator + "images", target + File.separator + "caches" + File.separator + "images");
  410. }
  411. FileUtils.copyFile(path + File.separator + "data.json", target + File.separator+"data.json", true);
  412. FileUtils.copyFile(path + File.separator + "project.json", target + File.separator+"project.json", true);
  413. //data.json增加extras为执行重建算法
  414. String project = FileUtils.readFile(target + File.separator+"project.json");
  415. if(project != null){
  416. JSONObject projectJson = JSONObject.parseObject(project);
  417. projectJson.put("parent", projectJson.get("uuid"));
  418. projectJson.put("uuid", UUID.randomUUID().toString());
  419. projectJson.put("time", System.currentTimeMillis());
  420. FileUtils.writeFile(path + File.separator + "project.json", projectJson.toString());
  421. }
  422. String data = FileUtils.readFile(target + File.separator+"data.json");
  423. if(data != null){
  424. JSONObject floorplanJson = new JSONObject();
  425. floorplanJson.put("has_floorplan_json", true);
  426. floorplanJson.put("has_vision_txt", true);
  427. JSONObject dataJson = JSONObject.parseObject(data);
  428. dataJson.put("extras", floorplanJson);
  429. //V5表示不需要生成high,low文件
  430. dataJson.put("skybox_type", "SKYBOX_V5");
  431. dataJson.put("split_type", "SPLIT_V4");
  432. FileUtils.writeFile(target + File.separator+"data.json", new String(dataJson.toString().getBytes(), "UTF-8"));
  433. }
  434. //文件上传的位置可以自定义
  435. log.info("画墙重建模型开始");
  436. File targetFile = new File(target + File.separator + "extras" + File.separator + "floorplan.json");
  437. if(!targetFile.getParentFile().exists()){
  438. targetFile.getParentFile().mkdirs();
  439. }
  440. if(targetFile.exists()){
  441. FileUtils.deleteFile(target + File.separator + "extras" + File.separator + "floorplan.json");
  442. }
  443. // 保存
  444. FileUtils.writeFile(target + File.separator + "extras" + File.separator + "floorplan.json", new String(sceneEdit.getFloor().getBytes(), "UTF-8"));
  445. FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+sceneEdit.getNum() + File.separator + "floor.json", new String(sceneEdit.getWebFloor().getBytes(), "UTF-8"));
  446. //下载vision.modeldata,解压成vision.txt,并且删除vision.modeldata
  447. log.info("下载vision.modeldata文件");
  448. if("aws".equals(type)){
  449. FileUtils.downLoadFromUrl(ConstantUrl.PREFIX_AWS + "images/images" + sceneEdit.getNum() + "/vision.modeldata" + "?m="+new Date().getTime(),
  450. "vision.modeldata", target + File.separator + "extras" + File.separator);
  451. }
  452. if("oss".equals(type)){
  453. FileUtils.downLoadFromUrl(prefixAli + "images/images" + sceneEdit.getNum() + "/vision.modeldata" + "?m="+new Date().getTime(),
  454. "vision.modeldata", target + File.separator + "extras" + File.separator);
  455. }
  456. CreateObjUtil.convertVisionmodeldataToTxt(target + File.separator + "extras" + File.separator + "vision.modeldata",
  457. target + File.separator + "extras" + File.separator + "vision.txt");
  458. log.info("解压完成,删除vision.modeldata文件");
  459. FileUtils.deleteFile(target + File.separator + "extras" + File.separator + "vision.modeldata");
  460. log.info("下载vision2.modeldata文件");
  461. if("oss".equals(type)){
  462. FileUtils.downLoadFromUrl(prefixAli + "images/images" + sceneEdit.getNum() + "/vision2.modeldata" + "?m="+new Date().getTime(),
  463. "vision2.modeldata", target + File.separator + "extras" + File.separator);
  464. }
  465. if("aws".equals(type)){
  466. FileUtils.downLoadFromUrl(ConstantUrl.PREFIX_AWS + "images/images" + sceneEdit.getNum() + "/vision2.modeldata" + "?m="+new Date().getTime(),
  467. "vision2.modeldata", target + File.separator + "extras" + File.separator);
  468. }
  469. CreateObjUtil.convertVisionmodeldataToTxt(target + File.separator + "extras" + File.separator + "vision2.modeldata",
  470. target + File.separator + "extras" + File.separator + "vision2.txt");
  471. log.info("解压完成,删除vision2.modeldata文件");
  472. FileUtils.deleteFile(target + File.separator + "extras" + File.separator + "vision2.modeldata");
  473. //重新计算算法
  474. log.info("重新计算大场景:开始建模——"+sceneEdit.getNum());
  475. //判断V2还是V3
  476. if("V2".equals(scenePro.getBuildType())){
  477. CreateObjUtil.build3dModelOld(target , "1");
  478. }
  479. if("V3".equals(scenePro.getBuildType())){
  480. CreateObjUtil.build3dModel(target , "1");
  481. }
  482. log.info("重新计算大场景:开始转换成lzma文件——"+sceneEdit.getNum());
  483. CreateObjUtil.convertTxtToDam( target + File.separator + "results" + File.separator+"tex"+
  484. File.separator+"modeldata.txt", target + File.separator + "results" +File.separator+ ConstantFileName.modelUUID+"_50k.dam");
  485. CreateObjUtil.convertDamToLzma(target + File.separator + "results");
  486. CreateObjUtil.convertTxtToDam( target + File.separator + "results" +File.separator+"tex"+
  487. File.separator+"modeldata.txt", target + File.separator + "results" + File.separator+ConstantFileName.modelUUID+"_50k.dam");
  488. File lzmaFile = new File(target + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k.dam.lzma");
  489. if(!lzmaFile.exists())
  490. {
  491. log.info("lzam文件不存在——"+sceneEdit.getNum());
  492. Thread.sleep(3000);
  493. }
  494. File sceneFile = new File(ConstantFilePath.SCENE_PATH+"images"+File.separator+"images"+sceneEdit.getNum() + File.separator + ConstantFileName.modelUUID + "_50k_texture_jpg_high1");
  495. if(!sceneFile.exists())
  496. {
  497. log.info("high1文件夹不存在——"+sceneEdit.getNum());
  498. sceneFile.mkdirs();
  499. }
  500. //将重新建模的tex里的文件和lzma文件复制到Message.filePath+"images"+File.separator+"images"+sceneNum下。
  501. List<String> list1 = FileUtils.readfileNamesForDirectory(target+File.separator+ "results" + File.separator +"tex",".jpg");
  502. if(list1 == null){
  503. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  504. }
  505. log.info("新生成的贴图有:——"+list1.size());
  506. for(int i=0; i<list1.size(); ++i)
  507. {
  508. String imgName = list1.get(i);
  509. FileUtils.copyFile(target+File.separator + "results" + File.separator+"tex"+File.separator+imgName,
  510. ConstantFilePath.SCENE_PATH+"images"+File.separator+"images"+sceneEdit.getNum() + File.separator + ConstantFileName.modelUUID + "_50k_texture_jpg_high1"+File.separator+imgName, true);
  511. }
  512. FileUtils.copyFile(target+File.separator + "results" + File.separator +ConstantFileName.modelUUID+"_50k.dam",
  513. ConstantFilePath.SCENE_PATH+"images"+File.separator+"images"+sceneEdit.getNum() + File.separator + ConstantFileName.modelUUID+"_50k.dam", true);
  514. log.info("文件复制到本地ecs完成——"+sceneEdit.getNum());
  515. //更新scene.json文件
  516. if(strsceneInfos!=null)
  517. {
  518. scenejson.put("floorEditVer", sceneProEdit.getFloorEditVer() + 1);
  519. scenejson.put("floorPublishVer", sceneProEdit.getFloorPublishVer());
  520. FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+sceneEdit.getNum()+File.separator+"scene.json", scenejson.toString());
  521. log.info("写入scene.json文件完成——"+sceneEdit.getNum());
  522. }
  523. //floorEditVer字段增加1
  524. sceneProEdit.setFloorEditVer(sceneProEdit.getFloorEditVer() + 1);
  525. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  526. sceneProEditService.updateById(sceneProEdit);
  527. log.info("修改数据库完成, sceneCode:{}, 花费时间:{}", sceneEdit.getNum(), System.currentTimeMillis() - start);
  528. }catch (Exception e){
  529. log.error("画墙重建模型失败...", e);
  530. throw new BusinessException(ErrorCode.FAILURE_CODE_5039);
  531. }finally {
  532. redisLockUtil.unlock(lockKey);
  533. }
  534. return ResultData.ok();
  535. }
  536. @Override
  537. public ResultData uploadFloorJsonAjk(FileParamVO param, MultipartFile[] file) throws Exception {
  538. String sceneNum = param.getNum();
  539. String floorPlanJson = param.getFloorPlanJson();
  540. String ajkJson = param.getAjkJson();
  541. String cameraJson = param.getCameraJson();
  542. String lockKey = String.format(RedisLockKey.LOCK_UPLOAD_FLOORJSON_REBUILD, sceneNum);
  543. Boolean lock = redisLockUtil.lock(lockKey, RedisKey.EXPIRE_TIME_2_HOUR);
  544. if(!lock){
  545. throw new BusinessException(ErrorCode.FAILURE_CODE_5036);
  546. }
  547. try {
  548. if(StrUtil.isEmpty(sceneNum)){
  549. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  550. }
  551. ScenePro scenePro = findBySceneNum(sceneNum);
  552. if(scenePro == null){
  553. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  554. }
  555. SceneProEdit sceneProEdit= sceneProEditService.findByProId(scenePro.getId());
  556. if(sceneProEdit == null){
  557. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  558. }
  559. SceneProExt sceneProExt = sceneProExtService.getOne(new LambdaQueryWrapper<SceneProExt>().eq(SceneProExt::getSceneProId, scenePro.getId()));
  560. //更新scene.json文件
  561. String strsceneInfos = FileUtils.readFile(ConstantFilePath.SCENE_PATH + "data" + File.separator + "data" + sceneNum + File.separator + "scene.json");
  562. JSONObject scenejson = new JSONObject();
  563. if(strsceneInfos!=null)
  564. {
  565. scenejson = JSONObject.parseObject(strsceneInfos);
  566. }else {
  567. new File(ConstantFilePath.SCENE_PATH + "data" + File.separator + "data" + sceneNum + File.separator + "scene.json").createNewFile();
  568. }
  569. String path = sceneProExt.getDataSource();// /mnt/data/0662c5389/831989883441512448/4898cab04f8c_202104141602356060/
  570. if(path != null && !"".equals(path) && path.startsWith("http")){
  571. path = ConstantFilePath.BUILD_MODEL_PATH + File.separator + path.split("/")[path.split("/").length - 2];
  572. }
  573. String target = path + "_ajk"; // /mnt/data/0662c5389/831989883441512448/4898cab04f8c_202104141602356060_ajk
  574. File editPath = new File(target);
  575. if(!editPath.exists()){
  576. editPath.mkdirs();
  577. }
  578. //创建文件夹软连接并且复制data.json和project.json
  579. if(new File(target + File.separator + "capture").exists()){
  580. new File(target + File.separator + "capture").delete();
  581. }
  582. if(new File(target + File.separator + "caches").exists()){
  583. //删除link
  584. new File(target + File.separator + "caches" + File.separator + "images").delete();
  585. //删除所有文件
  586. FileUtils.delAllFile(target + File.separator + "caches");
  587. }
  588. if(new File(target + File.separator + "results").exists()){
  589. FileUtils.delAllFile(target + File.separator + "results");
  590. }
  591. //创建文件夹,并link文件夹
  592. new File(target + File.separator + "caches").mkdirs();
  593. CreateObjUtil.createSoftConnection(path + File.separator + "capture", target + File.separator + "capture");
  594. if(new File(path + File.separator + "caches" + File.separator + "images").exists()){
  595. CreateObjUtil.createSoftConnection(path + File.separator + "caches" + File.separator + "images", target + File.separator + "caches" + File.separator + "images");
  596. }
  597. FileUtils.copyFile(path + File.separator + "data.json", target + File.separator+"data.json", true);
  598. FileUtils.copyFile(path + File.separator + "project.json", target + File.separator+"project.json", true);
  599. //data.json增加extras为执行重建算法
  600. String project = FileUtils.readFile(target + File.separator+"project.json");
  601. if(project != null){
  602. JSONObject projectJson = JSONObject.parseObject(project);
  603. projectJson.put("parent", projectJson.get("uuid"));
  604. projectJson.put("uuid", UUID.randomUUID().toString());
  605. projectJson.put("time", System.currentTimeMillis());
  606. FileUtils.writeFile(path + File.separator + "project.json", projectJson.toString());
  607. }
  608. String data = FileUtils.readFile(target + File.separator+"data.json");
  609. if(data != null){
  610. JSONObject floorplanJson = new JSONObject();
  611. floorplanJson.put("has_floor_ajk_json", true);
  612. floorplanJson.put("has_vision_txt", true);
  613. floorplanJson.put("has_floorplan_json", true);
  614. JSONObject dataJson = JSONObject.parseObject(data);
  615. dataJson.put("extras", floorplanJson);
  616. //V5表示不需要生成high,low文件
  617. dataJson.put("skybox_type", "SKYBOX_V8");
  618. dataJson.put("split_type", "SPLIT_V10");
  619. FileUtils.writeFile(target + File.separator+"data.json", new String(dataJson.toString().getBytes(), "UTF-8"));
  620. }
  621. //文件上传的位置可以自定义
  622. log.info("画墙重建模型开始");
  623. File targetFile = new File(target + File.separator + "extras" + File.separator + "floor_ajk.json");
  624. if(!targetFile.getParentFile().exists()){
  625. targetFile.getParentFile().mkdirs();
  626. }
  627. if(targetFile.exists()){
  628. FileUtils.deleteFile(target + File.separator + "extras" + File.separator + "floor_ajk.json");
  629. }
  630. // 保存
  631. FileUtils.writeFile(target + File.separator + "extras" + File.separator + "floorplan.json", new String(floorPlanJson.getBytes(), "UTF-8"));
  632. FileUtils.writeFile(target + File.separator + "extras" + File.separator + "floor_ajk.json", new String(ajkJson.getBytes(), "UTF-8"));
  633. FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+sceneNum + File.separator + "floor_ajk.json", new String(ajkJson.getBytes(), "UTF-8"));
  634. FileUtils.writeFile(target + File.separator + "extras" + File.separator + "vision.txt", new String(cameraJson.getBytes(), "UTF-8"));
  635. FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+sceneNum + File.separator + "camera.json", new String(cameraJson.getBytes(), "UTF-8"));
  636. for(int i = 0; i < file.length; i ++){
  637. File cadImg = new File(target + File.separator + "extras" + File.separator + "Floorplans/" + file[i].getOriginalFilename());
  638. if(!cadImg.getParentFile().exists()){
  639. cadImg.getParentFile().mkdirs();
  640. }
  641. if(cadImg.exists())
  642. {
  643. cadImg.delete();
  644. }
  645. file[i].transferTo(cadImg);
  646. }
  647. //下载封面图
  648. FileUtils.downLoadFromUrl(scenePro.getThumb() + "?t=" + System.currentTimeMillis(),
  649. "Cover.png", target + File.separator + "extras" + File.separator + "CoverImage");
  650. //转换成jpg
  651. FileUtils.pngToJpg(target + File.separator + "extras" + File.separator + "CoverImage/Cover.png",
  652. target + File.separator + "extras" + File.separator + "CoverImage/Cover.jpg");
  653. //安居客算法运行
  654. log.info("安居客算法:开始建模——"+sceneNum);
  655. CreateObjUtil.build3dModel(target , "1");
  656. if(!new File(target + File.separator + "results" + File.separator + "upload.json").exists()){
  657. return ResultData.error(ErrorCode.FAILURE_CODE_5042);
  658. }
  659. String zipPath = target + File.separator + "results/" + sceneNum + ".zip";
  660. new File(zipPath).delete();
  661. // FileUtils.zipFile(zipPath, target + File.separator + "results/ajk/");
  662. String command = "bash /opt/ossutil/gzip.sh " + zipPath.replace(".zip", "") + " " + target + File.separator + "results/ajk/";
  663. log.info("压缩文件:" + command);
  664. CreateObjUtil.callshell(command);
  665. if(!new File(zipPath).exists()){
  666. return ResultData.error(ErrorCode.FAILURE_CODE_5043);
  667. }
  668. String fileMD5 = FileMd5Util.getFileMD5(new File(zipPath));
  669. uploadToOssUtil.upload(zipPath, "data_download/" + sceneNum + ".zip");
  670. SceneDataDownload sceneDataDownload = sceneDataDownloadService.findBySceneNum(sceneNum);
  671. if(sceneDataDownload == null){
  672. sceneDataDownload = new SceneDataDownload();
  673. sceneDataDownload.setNum(sceneNum);
  674. sceneDataDownload.setDownloadPath(prefixAli + "data_download/" + sceneNum + ".zip");
  675. sceneDataDownload.setFileMd5(fileMD5);
  676. sceneDataDownloadService.save(sceneDataDownload);
  677. return ResultData.ok();
  678. }
  679. sceneDataDownload.setFileMd5(fileMD5);
  680. sceneDataDownload.setUpdateTime(Calendar.getInstance().getTime());
  681. sceneDataDownloadService.updateById(sceneDataDownload);
  682. }catch (Exception e){
  683. log.error("画墙重建模型失败...", e);
  684. throw new BusinessException(ErrorCode.FAILURE_CODE_5039);
  685. }finally {
  686. redisLockUtil.unlock(lockKey);
  687. }
  688. return ResultData.ok();
  689. }
  690. @Override
  691. public ResultData addHotMediaInfo(SceneEditParamVO base) throws Exception{
  692. if(StrUtil.isEmpty(base.getNum()) || StrUtil.isEmpty(base.getType()) ||
  693. StrUtil.isEmpty(base.getInfo())){
  694. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  695. }
  696. ScenePro scenePro = findBySceneNum(base.getNum());
  697. if(scenePro == null){
  698. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  699. }
  700. String mediaInfoPath = String.format(ConstantFilePath.MEDIAINFO_PATH_FORMAT, scenePro.getNum());
  701. String infoData = FileUtils.readFile(mediaInfoPath);
  702. JSONArray medias = null;
  703. if(infoData != null){
  704. medias= JSONArray.parseArray(infoData);
  705. }
  706. if(SceneEditType.ADD.code().equals(base.getType())){
  707. JSONObject jo = JSONObject.parseObject(base.getInfo());
  708. medias.add(jo);
  709. }
  710. else{
  711. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  712. }
  713. FileUtils.writeFile(mediaInfoPath, medias.toString());
  714. return ResultData.ok();
  715. }
  716. @Override
  717. public ResultData saveScreencapFile(SceneEditParamVO base) throws Exception{
  718. if(StrUtil.isEmpty(base.getNum()) || StrUtil.isEmpty(base.getIndex()) ||
  719. StrUtil.isEmpty(base.getCamerasData())){
  720. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  721. }
  722. ScenePro scenePro = findBySceneNum(base.getNum());
  723. if(scenePro == null){
  724. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  725. }
  726. String sceneJsonPath = String.format(ConstantFilePath.SCENE_PATH_FORMAT, scenePro.getNum());
  727. String tourlistfolderPath = String.format(ConstantFilePath.TOURLIST_FOLDER_PATH_FORMAT, scenePro.getNum());
  728. if("1".equals(base.getIndex())){
  729. File file = new File(tourlistfolderPath);
  730. if(file.isDirectory()){
  731. String[] strs = file.list();
  732. if(strs!=null){
  733. for(int i=0;i<strs.length;++i) {
  734. if(strs[i].indexOf(ConstantFileName.SCREEN_CRP_DATAFILE)>-1) {
  735. FileUtils.deleteFile(tourlistfolderPath + File.separator + strs[i]);
  736. }
  737. }
  738. }
  739. } else {
  740. file.mkdirs();
  741. }
  742. String strsceneInfos = FileUtils.readFile(sceneJsonPath);
  743. JSONObject scenejson = new JSONObject();
  744. if(strsceneInfos!=null) {
  745. scenejson = JSONObject.parseObject(strsceneInfos);
  746. }
  747. Map<String, Object> map = new HashMap<>();
  748. map.put("screencapLen", "0");
  749. map.put("version", scenejson.getIntValue("version")+1);
  750. FileUtils.writeJsonFile(sceneJsonPath, map);
  751. }
  752. String filePath = tourlistfolderPath+File.separator+ConstantFileName.SCREEN_CRP_DATAFILE+base.getIndex()+"json";
  753. File file = new File(filePath);
  754. if(!file.exists())
  755. {
  756. file.createNewFile();
  757. }
  758. FileUtils.writeFile(filePath, base.getCamerasData());
  759. return ResultData.ok();
  760. }
  761. @Override
  762. public ResultData saveSceneKey(SceneEditParamVO base) throws Exception{
  763. if(StrUtil.isEmpty(base.getNum()) || StrUtil.isEmpty(base.getSceneKey())){
  764. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  765. }
  766. ScenePro scenePro = findBySceneNum(base.getNum());
  767. if(scenePro == null){
  768. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  769. }
  770. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  771. sceneProEdit.setSceneKey(base.getSceneKey());
  772. sceneProEdit.setNeedKey(0);
  773. sceneProEdit.setVersion(sceneProEdit.getVersion() + 1);
  774. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  775. sceneProEditService.updateById(sceneProEdit);
  776. return ResultData.ok();
  777. }
  778. @Override
  779. public ResultData saveFloorLogo(SceneEditParamVO base) throws Exception{
  780. if(StrUtil.isEmpty(base.getNum()) || StrUtil.isEmpty(base.getSize()) ||
  781. StrUtil.isEmpty(base.getLogoType())){
  782. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  783. }
  784. ScenePro scenePro = findBySceneNum(base.getNum());
  785. if(scenePro == null){
  786. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  787. }
  788. String sceneJsonPath = String.format(ConstantFilePath.SCENE_PATH_FORMAT, scenePro.getNum());
  789. String strsceneInfos = FileUtils.readFile(sceneJsonPath);
  790. JSONObject scenejson = new JSONObject();
  791. if(strsceneInfos!=null) {
  792. scenejson = JSONObject.parseObject(strsceneInfos);
  793. }
  794. Map map = new HashMap();
  795. map.put("floorLogo", base.getLogoType());
  796. map.put("floorLogoSize", base.getSize());
  797. map.put("version", scenejson.getIntValue("version")+1);
  798. FileUtils.writeJsonFile(sceneJsonPath, map);
  799. return ResultData.ok();
  800. }
  801. @Override
  802. public ResultData saveBackgroundMusic(SceneEditParamVO base) throws Exception{
  803. if(StrUtil.isEmpty(base.getNum()) || StrUtil.isEmpty(base.getMusicName())){
  804. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  805. }
  806. ScenePro scenePro = findBySceneNum(base.getNum());
  807. if(scenePro == null){
  808. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  809. }
  810. String sceneJsonPath = String.format(ConstantFilePath.SCENE_PATH_FORMAT, scenePro.getNum());
  811. String strsceneInfos = FileUtils.readFile(sceneJsonPath);
  812. JSONObject scenejson = new JSONObject();
  813. if(strsceneInfos!=null) {
  814. scenejson = JSONObject.parseObject(strsceneInfos);
  815. }
  816. Map map = new HashMap();
  817. map.put("bgMusic", base.getMusicName());
  818. map.put("version", scenejson.getIntValue("version")+1);
  819. FileUtils.writeJsonFile(sceneJsonPath, map);
  820. return ResultData.ok();
  821. }
  822. @Transactional
  823. @Override
  824. public ResultData saveInitialPage(FileNameAndDataParamVO param) throws Exception{
  825. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
  826. if(scenePlus == null){
  827. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  828. }
  829. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  830. //更新缩略图url
  831. String thumbUrl = this.ossUrlPrefix +
  832. String.format(UploadFilePath.USER_EDIT_PATH, param.getNum()) +
  833. param.getFileName() +
  834. "&t=" + Calendar.getInstance().getTimeInMillis();
  835. scenePlusExt.setThumb(thumbUrl);
  836. scenePlusExtService.updateById(scenePlusExt);
  837. SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
  838. if(sceneEditInfo == null){
  839. sceneEditInfo = new SceneEditInfo();
  840. sceneEditInfo.setScenePlusId(scenePlus.getId());
  841. sceneEditInfo.setEntry(param.getData());
  842. sceneEditInfoService.save(sceneEditInfo);
  843. }else{
  844. sceneEditInfoService.update(
  845. new LambdaUpdateWrapper<SceneEditInfo>()
  846. .set(SceneEditInfo::getEntry, param.getData())
  847. .setSql("version = version + 1")
  848. .eq(SceneEditInfo::getId, sceneEditInfo.getId()));
  849. }
  850. return ResultData.ok();
  851. }
  852. @Override
  853. public ResultData getScreencapVoice(SceneEditParamVO base) throws Exception{
  854. if(StrUtil.isEmpty(base.getNum())){
  855. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  856. }
  857. ScenePro scenePro = findBySceneNum(base.getNum());
  858. if(scenePro == null){
  859. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  860. }
  861. String sceneInfos = String.format(ConstantFilePath.SCENE_PATH_FORMAT, scenePro.getNum());
  862. JSONObject scenejson = new JSONObject();
  863. if(sceneInfos!=null)
  864. {
  865. scenejson = JSONObject.parseObject(sceneInfos);
  866. }
  867. JSONObject result = new JSONObject();
  868. String screencapVoiceFileName = "";
  869. if(scenejson.containsKey("screencapVoiceFileName"))
  870. {
  871. screencapVoiceFileName = scenejson.getString("screencapVoiceFileName");
  872. }
  873. String screencapVoiceSrc = "";
  874. if(scenejson.containsKey("screencapVoiceSrc"))
  875. {
  876. screencapVoiceSrc = scenejson.getString("screencapVoiceSrc");
  877. }
  878. if(!screencapVoiceFileName.trim().equals("")&&!screencapVoiceSrc.trim().equals("")&&screencapVoiceFileName.indexOf(".")>-1)
  879. {
  880. result.put("screencapVoiceFileName", screencapVoiceFileName);
  881. result.put("screencapVoiceSrc1", screencapVoiceSrc);
  882. result.put("screencapVoiceSrc2", "voice/voice"+base.getNum()+"/201810" +screencapVoiceFileName.substring(screencapVoiceFileName.lastIndexOf(".")));
  883. }
  884. return ResultData.ok();
  885. }
  886. @Override
  887. public ResultData uploadScreencapVoiceNew(FileParamVO param, MultipartFile file) throws Exception{
  888. String sceneNum = param.getNum();
  889. String fileName = param.getFileName();
  890. ScenePro scenePro = findBySceneNum(sceneNum);
  891. if(scenePro == null){
  892. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  893. }
  894. if (!file.isEmpty()&& file.getSize() <= 0) {
  895. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  896. }
  897. String lockKey = String.format(RedisLockKey.LOCK_UPLOAD_PRO_VOICE, sceneNum);
  898. boolean lock = redisLockUtil.lock(lockKey, RedisKey.EXPIRE_TIME_30_MINUTE);
  899. if(!lock){
  900. throw new BusinessException(ErrorCode.FAILURE_CODE_5036);
  901. }
  902. String voiceSrc = null;
  903. try{
  904. //文件上传的位置可以自定义
  905. String path = ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+sceneNum;
  906. File targetFile = new File(path);
  907. if (!targetFile.exists()) {
  908. targetFile.mkdirs();
  909. }
  910. //获取文件名去掉后缀
  911. String originalFileName = file.getOriginalFilename().substring(0,
  912. file.getOriginalFilename().indexOf(".") > 0 ? file.getOriginalFilename().indexOf(".") : file.getOriginalFilename().length());
  913. log.info("上传的音频文件名:" + file.getOriginalFilename());
  914. String soundFileName = "sound201810.wav";
  915. String strsceneInfos = FileUtils.readFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json");
  916. JSONObject scenejson = new JSONObject();
  917. if(strsceneInfos!=null) {
  918. scenejson = JSONObject.parseObject(strsceneInfos);
  919. }
  920. if("soundsync".equals(type) && !"1".equals(param.getReplace())){
  921. if(scenejson.containsKey("screencapVoiceSoundsync") && !StrUtil.isEmpty(scenejson.getString("screencapVoiceSoundsync"))){
  922. String target = ConstantFilePath.SCENE_PATH + scenejson.getString("screencapVoiceSoundsync").substring(
  923. scenejson.getString("screencapVoiceSoundsync").indexOf("voice"));
  924. if(new File(target).exists()){
  925. targetFile = new File(path + File.separator +soundFileName);
  926. if(targetFile.exists())
  927. {
  928. FileUtils.deleteFile(path + File.separator + soundFileName);
  929. }
  930. file.transferTo(targetFile);
  931. FileUtils.changeVoiceToMp3(path + File.separator + soundFileName, path + File.separator + "newSound201810.mp3");
  932. //目标文件改名
  933. new File(target).renameTo(new File(path + File.separator + "oldSound201810.mp3"));
  934. //判断音频时长,不够拼接空白音效
  935. double total = param.getLength();
  936. double now = (FileUtils.getAudioPlayTime(new File(path + File.separator + "oldSound201810.mp3")) +
  937. FileUtils.getAudioPlayTime(new File(path + File.separator + "newSound201810.mp3"))) / 1000.0;
  938. if(total - now > 0.5){
  939. CreateObjUtil.createMuteViode(total - now, path + File.separator + "muteSound.mp3");
  940. if(new File(path + File.separator + "muteSound.mp3").exists()){
  941. //需要将旧的音频改名
  942. new File(path + File.separator + "oldSound201810.mp3").renameTo(new File(path + File.separator + "oldMuteSound201810.mp3"));
  943. log.info("生成新的静音音频和旧的音频合并");
  944. CreateObjUtil.mergeVideo(path + File.separator + "oldMuteSound201810.mp3", path + File.separator + "muteSound.mp3",
  945. path + File.separator + "oldSound201810.mp3");
  946. }
  947. }
  948. //app端和pc端名字不一致,统一文件名字
  949. target = path + File.separator + originalFileName + ".mp3";
  950. CreateObjUtil.mergeVideo(path + File.separator + "oldSound201810.mp3", path + File.separator + "newSound201810.mp3", target);
  951. //删除改名后的文件
  952. // new File(path + File.separator + "oldSound201810.mp3").delete();
  953. Map map = new HashMap();
  954. map.put("screencapVoiceSoundsyncFileName", originalFileName + ".mp3");
  955. String proVideo = "voice/voice"+sceneNum+"/"+originalFileName + ".mp3";
  956. map.put("screencapVoiceSoundsync", proVideo);
  957. map.put("uploadVoiceSoundsync", 1);
  958. map.put("screencapVoiceType", type);
  959. map.put("version", scenejson.getIntValue("version")+1);
  960. FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map);
  961. return ResultData.ok("voice/voice"+sceneNum+"/"+originalFileName + ".mp3");
  962. }
  963. }else {
  964. targetFile = new File(path + File.separator +soundFileName);
  965. if(targetFile.exists())
  966. {
  967. FileUtils.deleteFile(path + File.separator + soundFileName);
  968. }
  969. file.transferTo(targetFile);
  970. //判断音频时长,不够拼接空白音效
  971. FileUtils.changeVoiceToMp3(path + File.separator + soundFileName, path + File.separator + "newSound201810.mp3");
  972. double total = param.getLength();
  973. double now = (FileUtils.getAudioPlayTime(new File(path + File.separator + "newSound201810.mp3"))) / 1000.0;
  974. log.info("前端传的时长:" + total);
  975. log.info("获取文件的时长:" + now);
  976. //同步录音前一段没空白,直接生成文件
  977. if(total - now < 0.5){
  978. FileUtils.changeVoiceToMp3(path + File.separator + soundFileName, path + File.separator + originalFileName + ".mp3");
  979. Map map = new HashMap();
  980. map.put("screencapVoiceSoundsyncFileName", originalFileName + ".mp3");
  981. String proVideo = "voice/voice"+sceneNum+"/"+originalFileName + ".mp3";
  982. map.put("screencapVoiceSoundsync", proVideo);
  983. map.put("uploadVoiceSoundsync", 1);
  984. map.put("screencapVoiceType", type);
  985. map.put("version", scenejson.getIntValue("version")+1);
  986. FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map);
  987. return ResultData.ok(proVideo);
  988. }
  989. ////同步录音前一段有空白,生成一段静音后拼接文件
  990. CreateObjUtil.createMuteViode(total - now, path + File.separator + "muteSound.mp3");
  991. //app端和pc端名字不一致,统一文件名字
  992. String target = path + File.separator + originalFileName + ".mp3";
  993. CreateObjUtil.mergeVideo(path + File.separator + "muteSound.mp3", path + File.separator + "newSound201810.mp3", target);
  994. Map map = new HashMap();
  995. map.put("screencapVoiceSoundsyncFileName", originalFileName + ".mp3");
  996. String proVideo = "voice/voice"+sceneNum+"/"+originalFileName + ".mp3";
  997. map.put("screencapVoiceSoundsync", proVideo);
  998. map.put("uploadVoiceSoundsync", 1);
  999. map.put("screencapVoiceType", type);
  1000. map.put("version", scenejson.getIntValue("version")+1);
  1001. FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map);
  1002. return ResultData.ok("voice/voice"+sceneNum+"/"+originalFileName + ".mp3");
  1003. }
  1004. }
  1005. String name = "201810.wav";
  1006. targetFile = new File(path + File.separator +name);
  1007. // 保存
  1008. if(targetFile.exists())
  1009. {
  1010. FileUtils.deleteFile(path + File.separator + name);
  1011. }
  1012. file.transferTo(targetFile);
  1013. Map map = new HashMap();
  1014. if("soundsync".equals(type)){
  1015. FileUtils.changeVoiceToMp3(path + File.separator + name, path + File.separator + originalFileName + ".mp3");
  1016. map.put("screencapVoiceSoundsyncFileName", originalFileName + ".mp3");
  1017. String proVideo = "voice/voice"+sceneNum+"/"+originalFileName + ".mp3";
  1018. map.put("screencapVoiceSoundsync", proVideo);
  1019. map.put("uploadVoiceSoundsync", 1);
  1020. map.put("version", scenejson.getIntValue("version")+1);
  1021. map.put("screencapVoiceType", type);
  1022. FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map);
  1023. return ResultData.ok(proVideo);
  1024. }
  1025. if("sound".equals(type)){
  1026. FileUtils.changeVoiceToMp3(path + File.separator + name, path + File.separator + originalFileName + ".mp3");
  1027. map.put("screencapVoiceSoundFileName", originalFileName + ".mp3");
  1028. String proVideo = "voice/voice"+sceneNum+"/"+originalFileName + ".mp3";
  1029. map.put("screencapVoiceSound", proVideo);
  1030. map.put("uploadVoiceSound", 1);
  1031. map.put("version", scenejson.getIntValue("version")+1);
  1032. map.put("screencapVoiceType", type);
  1033. FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map);
  1034. return ResultData.ok(proVideo);
  1035. }
  1036. FileUtils.changeVoiceToMp3(path + File.separator + name, path + File.separator +"201810.mp3");
  1037. if(StrUtil.isEmpty(fileName)){
  1038. map.put("screencapVoiceFileName", originalFileName + ".mp3");
  1039. }else {
  1040. map.put("screencapVoiceFileName", fileName);
  1041. }
  1042. voiceSrc = "voice/voice"+sceneNum+"/"+"201810.mp3";
  1043. map.put("screencapVoiceSrc", voiceSrc);
  1044. map.put("uploadVoiceSrc", 1);
  1045. map.put("version", scenejson.getIntValue("version")+1);
  1046. map.put("screencapVoiceType", type);
  1047. FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map);
  1048. }finally {
  1049. redisLockUtil.unlock(lockKey);
  1050. }
  1051. return ResultData.ok(voiceSrc);
  1052. }
  1053. @Override
  1054. public ResultData uploadScreencapVoiceNewV3(FileParamVO param, MultipartFile file) throws Exception{
  1055. String sceneNum = param.getNum();
  1056. String fileName = param.getFileName();
  1057. if(StrUtil.isEmpty(sceneNum)){
  1058. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  1059. }
  1060. ScenePro scenePro = findBySceneNum(sceneNum);
  1061. if(scenePro == null){
  1062. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1063. }
  1064. if (!file.isEmpty()&& file.getSize() <= 0) {
  1065. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  1066. }
  1067. String lockKey = String.format(RedisLockKey.LOCK_UPLOAD_PRO_VOICE, sceneNum);
  1068. boolean lock = redisLockUtil.lock(lockKey, RedisKey.EXPIRE_TIME_30_MINUTE);
  1069. if(!lock){
  1070. throw new BusinessException(ErrorCode.FAILURE_CODE_5036);
  1071. }
  1072. String voiceSrc = null;
  1073. try{
  1074. //文件上传的位置可以自定义
  1075. String path = ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+sceneNum;
  1076. File targetFile = new File(path);
  1077. if (!targetFile.exists()) {
  1078. targetFile.mkdirs();
  1079. }
  1080. String originalFileName = "sound201810.mp3";
  1081. String strsceneInfos = FileUtils.readFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json");
  1082. JSONObject scenejson = new JSONObject();
  1083. if(strsceneInfos!=null) {
  1084. scenejson = JSONObject.parseObject(strsceneInfos);
  1085. }
  1086. if("soundsync".equals(type) && !"1".equals(param.getReplace())){
  1087. //判断分房间模块文件夹是否存在
  1088. String partPath = path + File.separator + "part";
  1089. File partFile = new File(partPath);
  1090. if(!partFile.exists()){
  1091. partFile.mkdirs();
  1092. }
  1093. targetFile = new File(partPath + File.separator + fileName);
  1094. if(targetFile.exists())
  1095. {
  1096. FileUtils.deleteFile(partPath + File.separator + fileName);
  1097. }
  1098. file.transferTo(targetFile);
  1099. //获取总音频多少段,每段时长
  1100. String[] time = param.getTimes().split(",");
  1101. //遍历判断音频是否存在,不存在生成空白音效
  1102. for(int i = 0, len = time.length; i < len; i++){
  1103. if(!new File(partPath + File.separator + i + ".mp3").exists()){
  1104. //某部分文件不存在,直接生成一段静音后拼接文件
  1105. CreateObjUtil.createMuteViode(Double.valueOf(time[i]), partPath + File.separator + i + ".mp3");
  1106. }
  1107. }
  1108. //拼接所有音频文件
  1109. if(time.length > 2){
  1110. //若是多部分,两个两个合并,最后合成最终文件
  1111. for(int i = 1, len = time.length; i < len; i++){
  1112. if(i == 1){
  1113. CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + ".mp3", partPath + File.separator + i + ".mp3",
  1114. partPath + File.separator + i + "muteSound.mp3");
  1115. }else if(i == len - 1){
  1116. CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + "muteSound.mp3", partPath + File.separator + i + ".mp3",
  1117. path + File.separator + originalFileName);
  1118. }else {
  1119. CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + "muteSound.mp3", partPath + File.separator + i + ".mp3",
  1120. partPath + File.separator + i + "muteSound.mp3");
  1121. }
  1122. }
  1123. }else {
  1124. //若只有两部分,直接合并成最终文件
  1125. CreateObjUtil.mergeVideo(partPath + File.separator + "0.mp3", partPath + File.separator + "1.mp3", path + File.separator + originalFileName);
  1126. }
  1127. Map map = new HashMap();
  1128. map.put("screencapVoiceSoundsyncFileName", originalFileName);
  1129. String proVideo = "voice/voice"+sceneNum+"/"+originalFileName;
  1130. map.put("screencapVoiceSoundsync", proVideo);
  1131. map.put("uploadVoiceSoundsync", 1);
  1132. map.put("screencapVoiceType", type);
  1133. map.put("version", scenejson.getIntValue("version")+1);
  1134. FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map);
  1135. return ResultData.ok("voice/voice"+sceneNum+"/"+originalFileName);
  1136. }
  1137. String name = "201810.wav";
  1138. targetFile = new File(path + File.separator +name);
  1139. // 保存
  1140. if(targetFile.exists())
  1141. {
  1142. FileUtils.deleteFile(path + File.separator + name);
  1143. }
  1144. file.transferTo(targetFile);
  1145. Map map = new HashMap();
  1146. if("soundsync".equals(type)){
  1147. FileUtils.delAllFile(path + File.separator + "part");
  1148. //判断分房间模块文件夹是否存在
  1149. String partPath = path + File.separator + "part";
  1150. File partFile = new File(partPath);
  1151. if(!partFile.exists()){
  1152. partFile.mkdirs();
  1153. }
  1154. //保存0.mp3文件到part
  1155. FileUtils.copyFile(path + File.separator +name, partPath + File.separator + fileName, true);
  1156. FileUtils.changeVoiceToMp3(path + File.separator + name, path + File.separator + originalFileName);
  1157. map.put("screencapVoiceSoundsyncFileName", originalFileName);
  1158. String proVideo = "voice/voice"+sceneNum+"/"+originalFileName;
  1159. map.put("screencapVoiceSoundsync", proVideo);
  1160. map.put("uploadVoiceSoundsync", 1);
  1161. map.put("version", scenejson.getIntValue("version")+1);
  1162. map.put("screencapVoiceType", type);
  1163. FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map);
  1164. return ResultData.ok(proVideo);
  1165. }
  1166. FileUtils.changeVoiceToMp3(path + File.separator + name, path + File.separator +"201810.mp3");
  1167. map.put("screencapVoiceFileName", file.getOriginalFilename());
  1168. voiceSrc = "voice/voice"+sceneNum+"/"+"201810.mp3";
  1169. map.put("screencapVoiceSrc", voiceSrc);
  1170. map.put("uploadVoiceSrc", 1);
  1171. map.put("version", scenejson.getIntValue("version")+1);
  1172. map.put("screencapVoiceType", type);
  1173. FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map);
  1174. }finally {
  1175. redisLockUtil.unlock(lockKey);
  1176. }
  1177. return ResultData.ok(voiceSrc);
  1178. }
  1179. @Override
  1180. public ResultData deleteScreencapVoicePart(FileParamVO param) throws Exception {
  1181. String sceneNum = param.getNum();
  1182. String index = param.getIndex();
  1183. if(StrUtil.isEmpty(sceneNum)){
  1184. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  1185. }
  1186. ScenePro scenePro = findBySceneNum(sceneNum);
  1187. if(scenePro == null){
  1188. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1189. }
  1190. //文件上传的位置可以自定义
  1191. String path = ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+sceneNum;
  1192. File targetFile = new File(path);
  1193. if (!targetFile.exists()) {
  1194. targetFile.mkdirs();
  1195. }
  1196. String originalFileName = "sound201810.mp3";
  1197. log.info("上传的音频文件名:" + originalFileName);
  1198. String scenePath = String.format(ConstantFilePath.SCENE_PATH_FORMAT, scenePro.getNum());
  1199. String strsceneInfos = FileUtils.readFile(scenePath);
  1200. JSONObject scenejson = new JSONObject();
  1201. if(strsceneInfos!=null) {
  1202. scenejson = JSONObject.parseObject(strsceneInfos);
  1203. }
  1204. //判断分房间模块文件夹是否存在
  1205. String partPath = path + File.separator + "part";
  1206. File partFile = new File(partPath);
  1207. if(!partFile.exists()){
  1208. partFile.mkdirs();
  1209. }
  1210. //删除指定部分音频文件
  1211. FileUtils.deleteFile(partPath + File.separator + index + ".mp3");
  1212. //获取总音频多少段,每段时长
  1213. String[] time = param.getTimes().split(",");
  1214. //修改删除的部分视频后面部分音频名字,如删除1.MP3,则将2.mp3修改成1.mp3,往后以此类推
  1215. if(Integer.parseInt(index) < time.length) {
  1216. for(int i = 0, len = time.length - Integer.parseInt(index); i < len; i++){
  1217. if(new File(partPath + File.separator + (Integer.parseInt(index) + 1 + i) + ".mp3").exists()){
  1218. FileUtils.copyFile(partPath + File.separator + (Integer.parseInt(index) + 1 + i) + ".mp3",
  1219. partPath + File.separator + (Integer.parseInt(index) + i) + ".mp3", true);
  1220. }
  1221. }
  1222. }
  1223. //遍历判断音频是否存在,不存在生成空白音效
  1224. for(int i = 0, len = time.length; i < len; i++){
  1225. if(!new File(partPath + File.separator + i + ".mp3").exists()){
  1226. //某部分文件不存在,直接生成一段静音后拼接文件
  1227. CreateObjUtil.createMuteViode(Double.valueOf(time[i]), partPath + File.separator + i + ".mp3");
  1228. }
  1229. }
  1230. //拼接所有音频文件
  1231. if(time.length > 2){
  1232. //若是多部分,两个两个合并,最后合成最终文件
  1233. for(int i = 1, len = time.length; i < len; i++){
  1234. if(i == 1){
  1235. // FileUtils.deleteFile(partPath + File.separator + i + "muteSound.mp3");
  1236. CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + ".mp3", partPath + File.separator + i + ".mp3",
  1237. partPath + File.separator + i + "muteSound.mp3");
  1238. }else if(i == len - 1){
  1239. CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + "muteSound.mp3", partPath + File.separator + i + ".mp3",
  1240. path + File.separator + originalFileName);
  1241. }else {
  1242. CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + "muteSound.mp3", partPath + File.separator + i + ".mp3",
  1243. partPath + File.separator + i + "muteSound.mp3");
  1244. }
  1245. }
  1246. }else if(time.length == 2){
  1247. //若只有两部分,直接合并成最终文件
  1248. CreateObjUtil.mergeVideo(partPath + File.separator + "0.mp3", partPath + File.separator + "1.mp3", path + File.separator + originalFileName);
  1249. }else {
  1250. FileUtils.copyFile(partPath + File.separator + "0.mp3", path + File.separator + originalFileName, true);
  1251. }
  1252. Map map = new HashMap();
  1253. map.put("screencapVoiceSoundsyncFileName", originalFileName);
  1254. String proVideo = "voice/voice"+sceneNum+"/"+originalFileName;
  1255. map.put("screencapVoiceSoundsync", proVideo);
  1256. map.put("uploadVoiceSoundsync", 1);
  1257. map.put("screencapVoiceType", "soundsync");
  1258. map.put("version", scenejson.getIntValue("version")+1);
  1259. FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map);
  1260. return ResultData.ok("voice/voice"+sceneNum+"/"+originalFileName);
  1261. }
  1262. @Override
  1263. public ResultData deleteScreencapVoice(SceneEditParamVO base) throws Exception{
  1264. if(StrUtil.isEmpty(base.getNum())){
  1265. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  1266. }
  1267. ScenePro scenePro = findBySceneNum(base.getNum());
  1268. if(scenePro == null){
  1269. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1270. }
  1271. String scenePath = String.format(ConstantFilePath.SCENE_PATH_FORMAT, scenePro.getNum());
  1272. String str = FileUtils.readFile(scenePath);
  1273. JSONObject json = new JSONObject();
  1274. if(str!=null){
  1275. json = JSONObject.parseObject(str);
  1276. }
  1277. else{
  1278. File file = new File(scenePath);
  1279. if(!file.getParentFile().exists())
  1280. {
  1281. file.getParentFile().mkdirs();
  1282. }
  1283. if(!file.exists())
  1284. {
  1285. file.createNewFile();
  1286. }
  1287. }
  1288. log.info("type:" + base.getType());
  1289. if("soundsync".equals(base.getType())){
  1290. FileUtils.deleteFile(ConstantFilePath.SCENE_PATH+json.getString("screencapVoiceSoundsync"));
  1291. json.put("screencapVoiceSoundsyncFileName", "");
  1292. json.put("screencapVoiceSoundsync", "");
  1293. json.put("version", json.getIntValue("version")+1);
  1294. FileUtils.deleteFile(scenePath);
  1295. FileUtils.writeFile(scenePath, json.toString());
  1296. return ResultData.ok();
  1297. }
  1298. if("sound".equals(base.getType())){
  1299. FileUtils.deleteFile(ConstantFilePath.SCENE_PATH+json.getString("screencapVoiceSound"));
  1300. json.put("screencapVoiceSoundFileName", "");
  1301. json.put("screencapVoiceSound", "");
  1302. json.put("version", json.getIntValue("version")+1);
  1303. FileUtils.deleteFile(scenePath);
  1304. FileUtils.writeFile(scenePath, json.toString());
  1305. return ResultData.ok();
  1306. }
  1307. String path = ConstantFilePath.SCENE_PATH+json.getString("screencapVoiceSrc");
  1308. log.info("path:" + ConstantFilePath.SCENE_PATH+json.getString("screencapVoiceSrc"));
  1309. FileUtils.deleteFile(path);
  1310. json.put("screencapVoiceFileName", "");
  1311. json.put("screencapVoiceSrc", "");
  1312. json.put("version", json.getIntValue("version")+1);
  1313. log.info("scenePath:" + scenePath);
  1314. FileUtils.deleteFile(scenePath);
  1315. FileUtils.writeFile(scenePath, json.toString());
  1316. return ResultData.ok();
  1317. }
  1318. @Override
  1319. public ResultData deleteScreencap(SceneEditParamVO base) throws Exception{
  1320. if(StrUtil.isEmpty(base.getNum())){
  1321. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  1322. }
  1323. ScenePro scenePro = findBySceneNum(base.getNum());
  1324. if(scenePro == null){
  1325. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1326. }
  1327. String imagesPath = String.format(ConstantFilePath.IMAGESBUFFER_FORMAT, scenePro.getNum());
  1328. String sceneJsonPath = String.format(ConstantFilePath.SCENE_PATH_FORMAT, scenePro.getNum());
  1329. String tourListPath = String.format(ConstantFilePath.TOURLIST_PATH_FORMAT, scenePro.getNum());
  1330. String capPath = String.format(ConstantFilePath.TOURLIST_FOLDER_PATH_FORMAT, scenePro.getNum());
  1331. String imgPath = imagesPath + ConstantFileName.TOURLIST_FOLDER;
  1332. File file1 = new File(capPath);
  1333. String[] strs = file1.list();
  1334. //删除screenCap对应的json数据
  1335. if(strs!=null) {
  1336. for(int i=0;i<strs.length;++i) {
  1337. if(strs[i].indexOf(ConstantFileName.SCREEN_CRP_DATAFILE)>-1) {
  1338. FileUtils.deleteFile(capPath+File.separator+strs[i]);
  1339. }
  1340. }
  1341. }
  1342. String tourList = FileUtils.readFile(tourListPath);
  1343. JSONArray tourJsons = new JSONArray();
  1344. if(tourList!=null) {
  1345. tourJsons = JSONArray.parseArray(tourList);
  1346. }
  1347. for(int i=0;i<tourJsons.size();++i) {
  1348. String filePath = imgPath + File.separator +"guide"+i+".jpg";
  1349. FileUtils.deleteFile(filePath);
  1350. }
  1351. FileUtils.deleteFile(tourListPath);
  1352. String strsceneInfos = FileUtils.readFile(sceneJsonPath);
  1353. JSONObject scenejson = new JSONObject();
  1354. if(strsceneInfos!=null) {
  1355. scenejson = JSONObject.parseObject(strsceneInfos);
  1356. }
  1357. Map<String, Object> map = new HashMap<>();
  1358. map.put("screencapLen", 0);
  1359. map.put("uploadTourList", 1);
  1360. map.put("version", scenejson.getIntValue("version") + 1);
  1361. FileUtils.writeJsonFile(sceneJsonPath, map);
  1362. return ResultData.ok();
  1363. }
  1364. @Override
  1365. public ResultData saveTourList(SceneEditParamVO base) throws Exception{
  1366. if(StrUtil.isEmpty(base.getNum()) || StrUtil.isEmpty(base.getTourList()) ||
  1367. StrUtil.isEmpty(base.getScreencapLen())){
  1368. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  1369. }
  1370. ScenePro scenePro = findBySceneNum(base.getNum());
  1371. if(scenePro == null){
  1372. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1373. }
  1374. log.info("editScene/saveTourList:生成tourList.json文件");
  1375. String tourListPath = String.format(ConstantFilePath.TOURLIST_PATH_FORMAT, scenePro.getNum());
  1376. FileUtils.writeFile(tourListPath, base.getTourList());
  1377. String sceneJsonPath = String.format(ConstantFilePath.SCENE_PATH_FORMAT, scenePro.getNum());
  1378. String strsceneInfos = FileUtils.readFile(sceneJsonPath);
  1379. JSONObject scenejson = new JSONObject();
  1380. if(strsceneInfos!=null) {
  1381. scenejson = JSONObject.parseObject(strsceneInfos);
  1382. }
  1383. Map<String, Object> map = new HashMap<>();
  1384. map.put("screencapLen", String.valueOf(base.getScreencapLen()));
  1385. map.put("uploadTourList", 1);
  1386. map.put("version", scenejson.getIntValue("version")+1);
  1387. FileUtils.writeJsonFile(sceneJsonPath, map);
  1388. return ResultData.ok();
  1389. }
  1390. @Override
  1391. public ResultData saveSceneInfo(SceneEditParamVO base) throws Exception{
  1392. if(StrUtil.isEmpty(base.getNum())){
  1393. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  1394. }
  1395. ScenePro scenePro = this.findBySceneNum(base.getNum());
  1396. if(scenePro == null){
  1397. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1398. }
  1399. SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
  1400. StringBuffer dataBuf = new StringBuffer()
  1401. .append("data").append(File.separator)
  1402. .append("data").append(scenePro.getNum())
  1403. .append(File.separator);
  1404. StringBuffer imagesBuf = new StringBuffer()
  1405. .append("images").append(File.separator)
  1406. .append("images").append(scenePro.getNum())
  1407. .append(File.separator);
  1408. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  1409. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  1410. int type = Integer.valueOf(base.getSceneType());
  1411. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  1412. JSONObject scenejson = new JSONObject();
  1413. if(strsceneInfos!=null) {
  1414. scenejson = JSONObject.parseObject(strsceneInfos);
  1415. }
  1416. //上传七牛
  1417. Map<String,String> map = new HashMap<>();
  1418. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  1419. SceneProEditExt sceneProEditExt = sceneProEditExtService.getByProEditId(sceneProEdit.getId());
  1420. //处理漫游数据
  1421. this.dealTour(base, scenejson, map, dataBuffer, imagesBuffer);
  1422. //判断scene.json是否有uploadVoiceSrc上传普通版音频
  1423. if(scenejson.containsKey("uploadVoiceSrc") && scenejson.getIntValue("uploadVoiceSrc") == 1) {
  1424. String screencapVoiceFileName = "";
  1425. if(scenejson.containsKey("screencapVoiceFileName")) {
  1426. screencapVoiceFileName = scenejson.getString("screencapVoiceFileName");
  1427. }
  1428. String screencapVoiceSrc = "";
  1429. if(scenejson.containsKey("screencapVoiceSrc")) {
  1430. screencapVoiceSrc = scenejson.getString("screencapVoiceSrc");
  1431. }
  1432. if(screencapVoiceFileName.indexOf(".")>-1) {
  1433. String fileName = "201810" + screencapVoiceFileName.substring(screencapVoiceFileName.lastIndexOf("."));
  1434. String path = ConstantFilePath.SCENE_PATH + "voice" + File.separator+"voice"+base.getNum()+File.separator+fileName;
  1435. map.put(path, "voice/voice"+base.getNum()+"/201810" +screencapVoiceFileName.substring(screencapVoiceFileName.lastIndexOf(".")));
  1436. }
  1437. sceneProEdit.setScreencapVoiceSrc(screencapVoiceSrc);
  1438. }
  1439. //判断scene.json是否有uploadVoiceSound上传专业版音频
  1440. if(scenejson.containsKey("uploadVoiceSound") && scenejson.getIntValue("uploadVoiceSound") == 1){
  1441. if(!StrUtil.isEmpty(scenejson.getString("screencapVoiceSound"))){
  1442. map.put(ConstantFilePath.SCENE_PATH + scenejson.getString("screencapVoiceSound"), scenejson.getString("screencapVoiceSound"));
  1443. }
  1444. sceneProEdit.setScreencapVoiceSound(scenejson.getString("screencapVoiceSound"));
  1445. }
  1446. if(scenejson.containsKey("uploadVoiceSoundsync") && scenejson.getIntValue("uploadVoiceSoundsync") == 1){
  1447. if(!StrUtil.isEmpty(scenejson.getString("screencapVoiceSoundsync"))){
  1448. map.put(ConstantFilePath.SCENE_PATH + scenejson.getString("screencapVoiceSoundsync"), scenejson.getString("screencapVoiceSoundsync"));
  1449. }
  1450. sceneProEdit.setScreencapVoiceSoundsync(scenejson.getString("screencapVoiceSoundsync"));
  1451. }
  1452. if(base.getScreencapVoiceType() != null){
  1453. scenejson.put("screencapVoiceType", base.getScreencapVoiceType());
  1454. sceneProEdit.setScreencapVoiceType(base.getScreencapVoiceType());
  1455. }
  1456. if(!StrUtil.isEmpty(base.getCapData())){
  1457. FileUtils.writeFile(dataBuffer.toString() + "capData.json", new String(base.getCapData().getBytes(), "UTF-8"));
  1458. scenejson.put("capData", dataBuf.toString() + "capData.json");
  1459. }
  1460. if(!StrUtil.isEmpty(base.getFrameData())){
  1461. FileUtils.writeFile(dataBuffer.toString() + "frameData.json", new String(base.getFrameData().getBytes(), "UTF-8"));
  1462. scenejson.put("frameData", dataBuf.toString() + "frameData.json");
  1463. }
  1464. if(!StrUtil.isEmpty(base.getPlayData())){
  1465. FileUtils.writeFile(dataBuffer.toString() + "playData.json", new String(base.getPlayData().getBytes(), "UTF-8"));
  1466. scenejson.put("playData", dataBuf.toString() + "playData.json");
  1467. sceneProEdit.setPlayData(dataBuf.toString() + "playData.json");
  1468. map.put(dataBuffer.toString() + "playData.json", dataBuf.toString() + "playData.json");
  1469. }
  1470. if(!StrUtil.isEmpty(base.getScreencapThumb())){
  1471. FileUtils.writeFile(dataBuffer.toString() + "screencapThumb.json", new String(base.getScreencapThumb().getBytes(), "UTF-8"));
  1472. scenejson.put("screencapThumb", dataBuf.toString() + "screencapThumb.json");
  1473. sceneProEdit.setScreencapThumb(dataBuf.toString() + "screencapThumb.json");
  1474. map.put(dataBuffer.toString() + "screencapThumb.json", dataBuf.toString() + "screencapThumb.json");
  1475. }
  1476. if(!StrUtil.isEmpty(base.getRecordType())){
  1477. scenejson.put("recordType", base.getRecordType());
  1478. }
  1479. if(!StrUtil.isEmpty(base.getMapVisi())){
  1480. scenejson.put("mapVisi", Integer.parseInt(base.getMapVisi()));
  1481. sceneProEditExt.setMapVisi(Integer.parseInt(base.getMapVisi()));
  1482. }
  1483. if(!StrUtil.isEmpty(base.getTourVisi())){
  1484. scenejson.put("tourVisi", Integer.parseInt(base.getTourVisi()));
  1485. sceneProEditExt.setTourVisi(Integer.parseInt(base.getTourVisi()));
  1486. }
  1487. if(!StrUtil.isEmpty(base.getVrVisi())){
  1488. scenejson.put("vrVisi", Integer.parseInt(base.getVrVisi()));
  1489. sceneProEditExt.setVrVisi(Integer.parseInt(base.getVrVisi()));
  1490. }
  1491. if(!StrUtil.isEmpty(base.getRulerVisi())){
  1492. scenejson.put("rulerVisi", Integer.parseInt(base.getRulerVisi()));
  1493. sceneProEditExt.setRulerVisi(Integer.parseInt(base.getRulerVisi()));
  1494. }
  1495. if(!StrUtil.isEmpty(base.getCadImgVisi())){
  1496. scenejson.put("cadImgVisi", Integer.parseInt(base.getCadImgVisi()));
  1497. sceneProEditExt.setCadImgVisi(Integer.parseInt(base.getCadImgVisi()));
  1498. }
  1499. if(!StrUtil.isEmpty(base.getPanoVisi())){
  1500. scenejson.put("panoVisi", Integer.parseInt(base.getPanoVisi()));
  1501. sceneProEditExt.setPanoVisi(Integer.parseInt(base.getPanoVisi()));
  1502. }
  1503. if(!StrUtil.isEmpty(base.getM2dVisi())){
  1504. scenejson.put("m2dVisi", Integer.parseInt(base.getM2dVisi()));
  1505. sceneProEditExt.setM2dVisi(Integer.parseInt(base.getM2dVisi()));
  1506. }
  1507. if(!StrUtil.isEmpty(base.getM3dVisi())){
  1508. scenejson.put("m3dVisi", Integer.parseInt(base.getM3dVisi()));
  1509. sceneProEditExt.setM3dVisi(Integer.parseInt(base.getM3dVisi()));
  1510. }
  1511. if(!StrUtil.isEmpty(base.getMeasureVisi())){
  1512. scenejson.put("measureVisi", Integer.parseInt(base.getMeasureVisi()));
  1513. sceneProEditExt.setMeasureVisi(Integer.parseInt(base.getMeasureVisi()));
  1514. }
  1515. if(!StrUtil.isEmpty(base.getFloorPlanAngle())){
  1516. scenejson.put("floorPlanAngle", base.getFloorPlanAngle());
  1517. sceneProEditExt.setFloorPlanAngle(base.getFloorPlanAngle());
  1518. }
  1519. if(scenejson.containsKey("uploadFloorPlanPng") && scenejson.getIntValue("uploadFloorPlanPng") == 1){
  1520. JSONArray floorPlanPngStr = new JSONArray();
  1521. JSONArray floorPlanPng = new JSONArray();
  1522. switch (scenePro.getBuildType()){
  1523. case "V2":
  1524. floorPlanPng.add(scenejson.getString("floorPlanPng"));
  1525. break;
  1526. case "V3":
  1527. try {
  1528. floorPlanPng = scenejson.getJSONArray("floorPlanPng");
  1529. } catch (Exception e) {
  1530. // 旧的V3也是String
  1531. floorPlanPng.add(scenejson.getString("floorPlanPng"));
  1532. }
  1533. break;
  1534. }
  1535. scenejson.put("uploadFloorPlanPng", 0);
  1536. for(int i = 0, len = floorPlanPng.size(); i < len; i++){
  1537. map.put(ConstantFilePath.SCENE_PATH+floorPlanPng.getString(i), floorPlanPng.getString(i));
  1538. floorPlanPngStr.add(floorPlanPng.getString(i) + "?t=" + System.currentTimeMillis());
  1539. }
  1540. sceneProEditExt.setFloorPlanPng(floorPlanPngStr.toJSONString());
  1541. }
  1542. if(scenejson.containsKey("uploadFloorJson") && scenejson.getIntValue("uploadFloorJson") == 1){
  1543. map.put(dataBuffer.toString() + "floor.json", dataBuf.toString() + "floor.json");
  1544. scenejson.put("uploadFloorJson", 0);
  1545. }
  1546. if(StrUtil.isNotEmpty(base.getEntry())) {
  1547. //上传七牛
  1548. map.put(imagesBuffer.toString() + "thumbBigImg.jpg", imagesBuf.toString() + "thumbBigImg.jpg");
  1549. map.put(imagesBuffer.toString() + "thumbFishBigImg.jpg",imagesBuf.toString() + "thumbFishBigImg.jpg");
  1550. map.put(imagesBuffer.toString() + "thumbSmallImg.jpg", imagesBuf.toString() + "thumbSmallImg.jpg");
  1551. map.put(imagesBuffer.toString() + "smallPic.jpg", imagesBuf.toString() + "smallPic.jpg");
  1552. sceneProEdit.setEntry(base.getEntry());
  1553. scenejson.put("entry", base.getEntry());
  1554. if(scenejson.containsKey("thumbImg"))
  1555. {
  1556. sceneProEdit.setThumbStatus(scenejson.getIntValue("thumbImg"));
  1557. }
  1558. if(sceneProEdit.getThumbStatus() == 1)
  1559. {
  1560. scenePro.setThumb(prefixAli + imagesBuf.toString() + "thumbSmallImg.jpg");
  1561. if("aws".equals(this.type)){
  1562. scenePro.setThumb(ConstantUrl.PREFIX_AWS + imagesBuf.toString() + "thumbSmallImg.jpg");
  1563. }
  1564. }
  1565. }
  1566. if(base.getHotFlag() != null && "1".equals(base.getHotFlag())) {
  1567. String str = FileUtils.readFile(dataBuffer.toString() + "hot.json");
  1568. JSONArray jsonhots = new JSONArray();
  1569. if(str != null&&!str.trim().equals("")) {
  1570. jsonhots = JSONArray.parseArray(str);
  1571. }
  1572. String hotsids = "";
  1573. for(int i=0;i<jsonhots.size();++i) {
  1574. JSONObject ele = jsonhots.getJSONObject(i);
  1575. String index = ele.getString("sid");
  1576. hotsids+=index+",";
  1577. if(ele.containsKey("media"))
  1578. {
  1579. String fileType = ele.getString("media");
  1580. if(fileType.contains("photo"))
  1581. {
  1582. map.put(imagesBuffer.toString() + "hot"+index+".jpg",
  1583. imagesBuf.toString() + "hot"+index+".jpg");
  1584. }
  1585. if(fileType.contains("audio") || fileType.contains("voice"))
  1586. {
  1587. map.put(imagesBuffer.toString() + "hot"+index+".mp3",
  1588. imagesBuf.toString() + "hot"+index+".mp3");
  1589. }
  1590. if(fileType.contains("video"))
  1591. {
  1592. map.put(imagesBuffer.toString() + "hot"+index+".mp4",
  1593. imagesBuf.toString() + "hot"+index+".mp4");
  1594. map.put(imagesBuffer.toString() + "hot"+index+"-cut.jpg",
  1595. imagesBuf.toString() + "hot"+index+"-cut.jpg");
  1596. }
  1597. }
  1598. }
  1599. map.put(dataBuffer.toString() + "hot.json",dataBuf.toString() + "hot.json");
  1600. sceneProEdit.setHotsIds(hotsids);
  1601. }
  1602. if(StrUtil.isNotEmpty(base.getFloorLogoType())) {
  1603. sceneProEdit.setFloorLogo(base.getFloorLogoType());
  1604. scenejson.put("floorLogo", base.getFloorLogoType());
  1605. if(base.getFloorLogoType().trim().equals("1")||base.getFloorLogoType().trim().equals("user")) {
  1606. map.put(imagesBuffer.toString() + "floorLogoImg.png", imagesBuf.toString() + "floorLogoImg.png");
  1607. }
  1608. }
  1609. if(StrUtil.isNotEmpty(base.getFloorLogoSize())) {
  1610. sceneProEdit.setFloorLogoSize(Integer.valueOf(base.getFloorLogoSize()));
  1611. scenejson.put("floorLogoSize", base.getFloorLogoSize());
  1612. }
  1613. if(base.getBgMusic() != null) {
  1614. sceneProEdit.setBgMusic(base.getBgMusic());
  1615. scenejson.put("bgMusic", base.getBgMusic());
  1616. }
  1617. if(base.getSceneName() != null) {
  1618. scenePro.setSceneName(base.getSceneName());
  1619. scenejson.put("sceneName", base.getSceneName());
  1620. }
  1621. if(StrUtil.isNotEmpty(base.getSceneType())) {
  1622. if(scenePro.getSceneType() == 99){
  1623. scenejson.put("sceneType", scenePro.getSceneType());
  1624. }else {
  1625. scenePro.setSceneType(type);
  1626. scenejson.put("sceneType", base.getSceneType());
  1627. }
  1628. }
  1629. if(base.getSceneDec() != null) {
  1630. scenePro.setSceneDec(base.getSceneDec());
  1631. scenejson.put("sceneDec", base.getSceneDec());
  1632. }
  1633. if(!StrUtil.isEmpty(base.getSceneKey())) {
  1634. sceneProEdit.setSceneKey(base.getSceneKey());
  1635. sceneProEdit.setNeedKey(1);
  1636. scenejson.put("sceneKey", base.getSceneKey());
  1637. scenejson.put("needKey", 1);
  1638. }else {
  1639. sceneProEdit.setSceneKey("");
  1640. sceneProEdit.setNeedKey(0);
  1641. scenejson.put("sceneKey", "");
  1642. scenejson.put("needKey", 0);
  1643. }
  1644. if(!scenejson.containsKey("version")) {
  1645. scenejson.put("version", 0);
  1646. }
  1647. scenejson.put("version", scenejson.getIntValue("version")+1);
  1648. map.put(dataBuffer.toString() + "scene.json", dataBuf.toString() + "scene.json");
  1649. sceneProEditExt.setCadInfo(scenejson.getString("cadInfo"));
  1650. sceneProEditExt.setUpdateTime(Calendar.getInstance().getTime());
  1651. sceneProEditExtService.updateById(sceneProEditExt);
  1652. sceneProEdit.setVersion(scenejson.getIntValue("version"));
  1653. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  1654. sceneProEditService.updateById(sceneProEdit);
  1655. //重建上传资源到oss
  1656. if(sceneProEdit.getFloorEditVer() != sceneProEdit.getFloorPublishVer()){
  1657. //上传过模型,只更新floor.json
  1658. if(scenejson.containsKey("isUploadObj") && scenejson.getBooleanValue("isUploadObj")){
  1659. map.put(dataBuffer.toString() + "floor.json", dataBuf.toString() + "floor.json");
  1660. //发布重新建模场景,将floorPublishVer设为floorEditVer的值
  1661. sceneProEdit.setFloorPublishVer(sceneProEdit.getFloorEditVer());
  1662. scenejson.put("floorEditVer", sceneProEdit.getFloorEditVer());
  1663. scenejson.put("floorPublishVer", sceneProEdit.getFloorEditVer());
  1664. }else {
  1665. String path = sceneProExt.getDataSource();
  1666. if(path != null && !"".equals(path) && path.startsWith("http")){
  1667. path = ConstantFilePath.BUILD_MODEL_PATH + path.split("/")[path.split("/").length - 2];
  1668. }
  1669. path = path + "_edit";
  1670. String projectNum = base.getNum();
  1671. //读取upload文件,检验需要上传的文件是否存在
  1672. String uploadData = FileUtils.readFile(path + File.separator + "results" +File.separator+"upload.json");
  1673. JSONObject uploadJson = null;
  1674. JSONArray array = null;
  1675. if(uploadData!=null) {
  1676. uploadJson = JSONObject.parseObject(uploadData);
  1677. array = uploadJson.getJSONArray("upload");
  1678. }
  1679. if(array != null){
  1680. JSONObject fileJson = null;
  1681. String fileName = "";
  1682. for(int i = 0, len = array.size(); i < len; i++){
  1683. fileJson = array.getJSONObject(i);
  1684. fileName = fileJson.getString("file");
  1685. //文件不存在抛出异常
  1686. if(!new File(path + File.separator + "results" +File.separator + fileName).exists()){
  1687. throw new Exception(path + File.separator + "results" +File.separator + fileName+"文件不存在");
  1688. }
  1689. //tex文件夹
  1690. if(fileJson.getIntValue("clazz") == 2 && !fileJson.containsKey("pack-file")){
  1691. map.put(path + File.separator + "results" +File.separator+ fileName,"images/images"+
  1692. projectNum+"/"+ConstantFileName.modelUUID+"_50k_texture_jpg_high1/"+fileName.replace("tex/", ""));
  1693. }
  1694. //2048的模型和贴图
  1695. if(fileJson.getIntValue("clazz") == 16){
  1696. map.put(path + File.separator + "results" + File.separator+ fileName,"data/data"+
  1697. projectNum+ File.separator + fileName);
  1698. }
  1699. }
  1700. map.put(path + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k.dam.lzma", "images/images"+projectNum+"/"+ConstantFileName.modelUUID+"_50k.dam.lzma");
  1701. map.put(path + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k.dam", "images/images"+projectNum+"/"+ConstantFileName.modelUUID+"_50k.dam");
  1702. File file = new File(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+projectNum);
  1703. if(!file.exists())
  1704. {
  1705. file.mkdir();
  1706. }
  1707. log.info("计算大场景:开始上传大场景文件到阿里——"+projectNum);
  1708. //上传修改后的本地的缩略图
  1709. map.put(dataBuffer.toString() + "floor.json", dataBuf.toString() + "floor.json");
  1710. //发布重新建模场景,将floorPublishVer设为floorEditVer的值
  1711. sceneProEdit.setFloorPublishVer(sceneProEdit.getFloorEditVer());
  1712. scenejson.put("floorEditVer", sceneProEdit.getFloorEditVer());
  1713. scenejson.put("floorPublishVer", sceneProEdit.getFloorEditVer());
  1714. }
  1715. }
  1716. }
  1717. //重算全景图并上传oss或oss
  1718. if(scenejson.containsKey("buildImages")){
  1719. String path = sceneProExt.getDataSource();
  1720. if(path != null && !"".equals(path) && path.startsWith("http")){
  1721. path = ConstantFilePath.BUILD_MODEL_PATH + File.separator + path.split("/")[path.split("/").length - 2];
  1722. }
  1723. String target = path + "_images";
  1724. File images = new File(target + File.separator + "extras/images");
  1725. File video = new File(target + File.separator + "extras/video");
  1726. if(scenejson.getIntValue("buildImages") == 1){
  1727. log.info("下载vision.modeldata文件");
  1728. if("aws".equals(this.type)){
  1729. FileUtils.downLoadFromUrl(ConstantUrl.PREFIX_AWS + "images/images" + scenePro.getNum() + "/vision.modeldata" + "?m="+new Date().getTime(),
  1730. "vision.modeldata", target + File.separator + "extras" + File.separator);
  1731. }
  1732. if("oss".equals(this.type)){
  1733. FileUtils.downLoadFromUrl(prefixAli + "images/images" + scenePro.getNum() + "/vision.modeldata" + "?m="+new Date().getTime(),
  1734. "vision.modeldata", target + File.separator + "extras" + File.separator);
  1735. }
  1736. CreateObjUtil.convertVisionmodeldataToTxt(target + File.separator + "extras" + File.separator + "vision.modeldata",
  1737. target + File.separator + "extras" + File.separator + "vision.txt");
  1738. if(images.exists() && images.listFiles() != null && images.listFiles().length > 0){
  1739. FileUtils.copyFile(path + File.separator + "data.json", target + File.separator+"data.json", true);
  1740. FileUtils.copyFile(path + File.separator + "project.json", target + File.separator+"project.json", true);
  1741. //data.json增加extras为执行重建算法
  1742. String data = FileUtils.readFile(target + File.separator+"data.json");
  1743. if(data != null){
  1744. JSONObject floorplanJson = new JSONObject();
  1745. floorplanJson.put("has_source_images", true);
  1746. floorplanJson.put("has_vision_txt", true);
  1747. JSONObject dataJson = JSONObject.parseObject(data);
  1748. dataJson.put("extras", floorplanJson);
  1749. //V5表示不需要生成high,low文件
  1750. dataJson.put("skybox_type", "SKYBOX_V6");
  1751. if(scenePro.getSceneScheme() == 11){
  1752. dataJson.put("skybox_type", "SKYBOX_V7");
  1753. }
  1754. dataJson.put("split_type", "SPLIT_V8");
  1755. //sceneScheme为3切成瓦片图
  1756. if(scenePro.getSceneScheme() == 3){
  1757. dataJson.put("skybox_type", "SKYBOX_V4");
  1758. }
  1759. FileUtils.writeFile(target + File.separator+"data.json", new String(dataJson.toString().getBytes(), "UTF-8"));
  1760. }
  1761. //创建文件夹软连接并且复制data.json和project.json
  1762. if(new File(target + File.separator + "capture").exists()){
  1763. new File(target + File.separator + "capture").delete();
  1764. }
  1765. if(new File(target + File.separator + "results").exists()){
  1766. FileUtils.delAllFile(target + File.separator + "results");
  1767. }
  1768. //下载data.fdage
  1769. if("aws".equals(this.type)){
  1770. //亚马逊保持旧方式,超链接capture
  1771. CreateObjUtil.createSoftConnection(path + File.separator + "capture", target + File.separator + "capture");
  1772. }
  1773. CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + path.replace(ConstantFilePath.BUILD_MODEL_PATH, "") + "/data.fdage", target + File.separator + "capture/");
  1774. CreateObjUtil.build3dModel(target , "1");
  1775. //读取upload文件,检验需要上传的文件是否存在
  1776. String uploadData = FileUtils.readFile(target + File.separator + "results" +File.separator+"upload.json");
  1777. JSONObject uploadJson = null;
  1778. JSONArray array = null;
  1779. if(uploadData!=null) {
  1780. uploadJson = JSONObject.parseObject(uploadData);
  1781. array = uploadJson.getJSONArray("upload");
  1782. }
  1783. if(array == null){
  1784. throw new Exception("upload.json数据出错");
  1785. }
  1786. JSONObject fileJson = null;
  1787. String fileName = "";
  1788. for(int i = 0, len = array.size(); i < len; i++){
  1789. fileJson = array.getJSONObject(i);
  1790. fileName = fileJson.getString("file");
  1791. //文件不存在抛出异常
  1792. if(!new File(target + File.separator + "results" +File.separator + fileName).exists()){
  1793. throw new Exception(target + File.separator + "results" +File.separator + fileName+"文件不存在");
  1794. }
  1795. //high文件夹
  1796. if(fileJson.getIntValue("clazz") == 3){
  1797. map.put(target + File.separator + "results" +File.separator+ fileName,"images/images"+
  1798. scenePro.getNum()+"/pan/high/"+ fileName.replace("high/", ""));
  1799. continue;
  1800. }
  1801. //low文件夹
  1802. if(fileJson.getIntValue("clazz") == 4){
  1803. map.put(target + File.separator + "results" +File.separator+ fileName,"images/images"+
  1804. scenePro.getNum()+"/pan/low/"+ fileName.replace("low/", ""));
  1805. continue;
  1806. }
  1807. //tiles文件夹,亚马逊没有裁剪图片api,不需要上传4k图
  1808. if(fileJson.getIntValue("clazz") == 5){
  1809. map.put(target + File.separator + "results" + File.separator+ fileName,"images/images"+
  1810. scenePro.getNum()+ File.separator + fileName);
  1811. continue;
  1812. }
  1813. //tiles文件夹,亚马逊瓦片图
  1814. if(fileJson.getIntValue("clazz") == 7 ){
  1815. map.put(target + File.separator + "results" + File.separator+ fileName,"images/images"+
  1816. scenePro.getNum()+ File.separator + fileName);
  1817. continue;
  1818. }
  1819. }
  1820. for(String imagesName : images.list()){
  1821. //覆盖原始图片资源
  1822. FileUtils.copyFile(target + File.separator + "extras/images/" + imagesName,
  1823. path + File.separator + "caches/images/" + imagesName, true);
  1824. FileUtils.deleteFile(target + File.separator + "extras/images/" + imagesName);
  1825. }
  1826. }
  1827. if(video.exists() && video.listFiles() != null && video.listFiles().length > 0){
  1828. for(String videoName : video.list()){
  1829. uploadToOssUtil.upload(target + File.separator + "extras/video/" + videoName,"video/video"+
  1830. scenePro.getNum()+ File.separator + videoName);
  1831. CreateObjUtil.mp4ToFlv(target + File.separator + "extras/video/" + videoName,
  1832. target + File.separator + "extras/video/" + videoName.replace("mp4", "flv"));
  1833. uploadToOssUtil.upload(target + File.separator + "extras/video/" + videoName.replace("mp4", "flv"),"video/video"+
  1834. scenePro.getNum()+ File.separator + videoName.replace("mp4", "flv"));
  1835. //覆盖原始视频资源
  1836. FileUtils.copyFile(target + File.separator + "extras/video/" + videoName,
  1837. path + File.separator + "caches/videos/" + videoName, true);
  1838. }
  1839. FileUtils.deleteDirectory(target + File.separator + "extras/video/");
  1840. }
  1841. }else if(scenejson.getIntValue("buildImages") == 2){
  1842. if(video.exists() && video.listFiles() != null && video.listFiles().length > 0){
  1843. for(String videoName : video.list()){
  1844. uploadToOssUtil.upload(target + File.separator + "extras/video/" + videoName,"video/video"+
  1845. scenePro.getNum()+ File.separator + videoName);
  1846. CreateObjUtil.mp4ToFlv(target + File.separator + "extras/video/" + videoName,
  1847. target + File.separator + "extras/video/" + videoName.replace("mp4", "flv"));
  1848. uploadToOssUtil.upload(target + File.separator + "extras/video/" + videoName.replace("mp4", "flv"),"video/video"+
  1849. scenePro.getNum()+ File.separator + videoName.replace("mp4", "flv"));
  1850. //覆盖原始视频资源
  1851. FileUtils.copyFile(target + File.separator + "extras/video/" + videoName,
  1852. path + File.separator + "caches/videos/" + videoName, true);
  1853. }
  1854. FileUtils.deleteDirectory(target + File.separator + "extras/video/");
  1855. }
  1856. }
  1857. scenejson.put("imagesVersion", sceneProEditExt.getImagesVersion() + 1);
  1858. scenejson.put("buildImages", 0);
  1859. sceneProEditExt.setImagesVersion(sceneProEditExt.getImagesVersion() + 1);
  1860. }
  1861. if(scenejson.containsKey("uploadBgMusic") && scenejson.getIntValue("uploadBgMusic") == 1){
  1862. if(StrUtil.isNotEmpty(scenejson.getString("bgMusicName"))){
  1863. map.put(imagesBuffer.toString() + scenejson.getString("bgMusicName"), imagesBuf.toString() + scenejson.getString("bgMusicName"));
  1864. }
  1865. scenejson.put("uploadBgMusic", 0);
  1866. sceneProEditExt.setBgMusicName(scenejson.getString("bgMusicName"));
  1867. }
  1868. if(scenejson.containsKey("uploadPanoramaImg") && scenejson.getIntValue("uploadPanoramaImg") == 1){
  1869. String targetPath = ConstantFilePath.SCENE_PATH + "images/images" + base.getNum() + "/panorama";
  1870. for(File targetFile : new File(targetPath).listFiles()){
  1871. if(targetFile.isDirectory()){
  1872. String target = targetFile.getAbsolutePath();
  1873. String sid = target.substring(target.lastIndexOf(File.separator) + 1);
  1874. //读取upload文件,检验需要上传的文件是否存在
  1875. String uploadData = FileUtils.readFile(target + File.separator + "results" +File.separator+"upload.json");
  1876. JSONObject uploadJson = null;
  1877. JSONArray array = null;
  1878. if(uploadData!=null) {
  1879. uploadJson = JSONObject.parseObject(uploadData);
  1880. array = uploadJson.getJSONArray("upload");
  1881. }
  1882. if(array == null){
  1883. continue;
  1884. }
  1885. JSONObject fileJson = null;
  1886. String fileName = "";
  1887. for(int i = 0, len = array.size(); i < len; i++){
  1888. fileJson = array.getJSONObject(i);
  1889. fileName = fileJson.getString("file");
  1890. //文件不存在抛出异常
  1891. if(!new File(target + File.separator + "results" +File.separator + fileName).exists()){
  1892. throw new Exception(target + File.separator + "results" +File.separator + fileName+"文件不存在");
  1893. }
  1894. //high文件夹
  1895. if(fileJson.getIntValue("clazz") == 3){
  1896. map.put(target + File.separator + "results" +File.separator+ fileName,"images/images"+
  1897. scenePro.getNum()+"/panorama/" + sid + "/pan/high/"+ fileName.replace("high/", ""));
  1898. continue;
  1899. }
  1900. //low文件夹
  1901. if(fileJson.getIntValue("clazz") == 4){
  1902. map.put(target + File.separator + "results" +File.separator+ fileName,"images/images"+
  1903. scenePro.getNum()+"/panorama/" + sid + "/pan/low/"+ fileName.replace("low/", ""));
  1904. continue;
  1905. }
  1906. //tiles文件夹,亚马逊没有裁剪图片api,不需要上传4k图
  1907. if(fileJson.getIntValue("clazz") == 5){
  1908. map.put(target + File.separator + "results" + File.separator+ fileName,"images/images"+
  1909. scenePro.getNum()+ "/panorama/" + sid + File.separator + fileName);
  1910. continue;
  1911. }
  1912. //tiles文件夹,亚马逊瓦片图
  1913. if(fileJson.getIntValue("clazz") == 7 ){
  1914. map.put(target + File.separator + "results" + File.separator+ fileName,"images/images"+
  1915. scenePro.getNum()+ File.separator + fileName);
  1916. continue;
  1917. }
  1918. }
  1919. }
  1920. }
  1921. scenejson.put("uploadPanoramaImg", 0);
  1922. }
  1923. if(scenejson.containsKey("uploadPanoramaJson") && scenejson.getIntValue("uploadPanoramaJson") == 1){
  1924. scenejson.put("uploadPanoramaJson", 0);
  1925. map.put(dataBuffer.toString() + "link-scene.json", dataBuf.toString() + "link-scene.json");
  1926. sceneProEditExt.setJumpScene(scenejson.getBooleanValue("jumpScene"));
  1927. }
  1928. log.info("scene.json路径:" + dataBuffer.toString() + "scene.json");
  1929. FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
  1930. if(map.size()>0) {
  1931. uploadToOssUtil.uploadMulFiles(map);
  1932. }
  1933. scenePro.setUpdateTime(Calendar.getInstance().getTime());
  1934. this.updateById(scenePro);
  1935. sceneProExt.setUpdateTime(Calendar.getInstance().getTime());
  1936. sceneProExtService.updateById(sceneProExt);
  1937. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  1938. sceneProEditService.updateById(sceneProEdit);
  1939. sceneProEditExt.setUpdateTime(Calendar.getInstance().getTime());
  1940. sceneProEditExtService.updateById(sceneProEditExt);
  1941. return ResultData.ok();
  1942. }
  1943. @Override
  1944. // @SystemServiceLog(description = "上传场景的热点媒体文件")
  1945. public ResultData uploadHotMedia(FileParamVO param, MultipartFile file) throws Exception {
  1946. String sceneNum = param.getNum();
  1947. String sid = param.getSid();
  1948. if(StrUtil.isEmpty(sceneNum)){
  1949. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  1950. }
  1951. ScenePro scenePro = this.findBySceneNum(sceneNum);
  1952. if(scenePro == null){
  1953. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1954. }
  1955. String fileName = "hot" + sid + ".mp4";
  1956. if (file.isEmpty())
  1957. return ResultData.ok(fileName);
  1958. String path = String.format(ConstantFilePath.IMAGESBUFFER_FORMAT, sceneNum);
  1959. File targetFile = new File(path);
  1960. if (!targetFile.exists()){
  1961. targetFile.mkdirs();
  1962. }
  1963. targetFile = new File(path + File.separator + fileName);
  1964. if (targetFile.exists()){
  1965. FileUtils.deleteFile(path + File.separator + fileName);
  1966. }
  1967. file.transferTo(targetFile);
  1968. if(targetFile.exists()){
  1969. //获取指定视频的帧并保存为图片至指定目录
  1970. FileUtils.executeCodecs(path + File.separator + fileName, path, "hot" + sid + "-cut");
  1971. }
  1972. return ResultData.ok(fileName);
  1973. }
  1974. @Override
  1975. public ResultData tagSave(SaveTagsParamVO param) throws Exception {
  1976. ScenePro scenePro = this.findBySceneNum(param.getNum());
  1977. if (scenePro == null)
  1978. return ResultData.error(ErrorCode.FAILURE_CODE_5005);
  1979. List<HotParamVO> hotDataList = param.getHotDataList();
  1980. Map<String, String> addOrUpdateMap = new HashMap<>();
  1981. List<String> deleteSidList = Lists.newArrayList();
  1982. hotDataList.stream().forEach(hotData -> {
  1983. if(hotData.getType().equals(OperationType.DELETE.code()))
  1984. deleteSidList.add(hotData.getSid());
  1985. else
  1986. addOrUpdateMap.put(hotData.getSid(), hotData.getHotData());
  1987. });
  1988. //处理删除状态数据
  1989. this.deleteHotData(param.getNum(), deleteSidList);
  1990. //处理新增和修改数据
  1991. this.addOrUpdateHotDataHandler(param.getNum(), addOrUpdateMap);
  1992. //保存数据库
  1993. // sceneEditInfoService.saveTagsToSceneEditInfo(param.getNum(), scenePro.getId());
  1994. return ResultData.ok();
  1995. }
  1996. @Override
  1997. public ResultData addOrUpdateTag(SaveTagsParamVO param) throws Exception {
  1998. // ScenePro scenePro = this.findBySceneNum(param.getNum());
  1999. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
  2000. if (scenePlus == null)
  2001. return ResultData.error(ErrorCode.FAILURE_CODE_5005);
  2002. this.addOrUpdateHotData(param.getNum(), param.getHotDataList());
  2003. this.addOrUpdateIcons(param.getNum(), param.getIcons());
  2004. //写入本地文件,作为备份
  2005. this.writeHotJson(param.getNum());
  2006. //保存数据库
  2007. SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
  2008. sceneEditInfoService.saveTagsToSceneEditInfo(param.getNum(), sceneEditInfo);
  2009. sceneEditInfoService.updateById(sceneEditInfo);
  2010. return ResultData.ok();
  2011. }
  2012. private void addOrUpdateHotData(String num, List<HotParamVO> hotDataList) throws Exception{
  2013. Map<String, String> addOrUpdateMap = new HashMap<>();
  2014. // hotDataList.stream().forEach(hotData -> {
  2015. // JSONObject jsonObject = JSON.parseObject(hotData.getHotData());
  2016. // jsonObject.put("createTime", Calendar.getInstance().getTimeInMillis());
  2017. // addOrUpdateMap.put(hotData.getSid(), jsonObject.toJSONString());
  2018. // });
  2019. int i = 0;
  2020. for (HotParamVO hotParamVO : hotDataList) {
  2021. JSONObject jsonObject = JSON.parseObject(hotParamVO.getHotData());
  2022. jsonObject.put("createTime", Calendar.getInstance().getTimeInMillis() + i++);
  2023. addOrUpdateMap.put(hotParamVO.getSid(), jsonObject.toJSONString());
  2024. }
  2025. this.syncHotFromFileToRedis(num);
  2026. //处理新增和修改数据
  2027. this.addOrUpdateHotDataHandler(num, addOrUpdateMap);
  2028. }
  2029. private void addOrUpdateIcons(String num, List<String> icons) throws Exception{
  2030. this.syncIconsFromFileToRedis(num);
  2031. String key = String.format(RedisKey.SCENE_HOT_ICONS, num);
  2032. redisUtil.sSet(key, icons.toArray());
  2033. // Map<String, String> addOrUpdateMap = new HashMap<>();
  2034. // hotDataList.stream().forEach(hotData -> {
  2035. // addOrUpdateMap.put(hotData.getSid(), hotData.getHotData());
  2036. // });
  2037. //处理新增和修改数据
  2038. // this.addOrUpdateHotData(num, addOrUpdateMap);
  2039. }
  2040. @Override
  2041. public ResultData deleteTag(DeleteHotParamVO param) throws Exception {
  2042. // ScenePro scenePro = this.findBySceneNum(param.getNum());
  2043. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
  2044. if (scenePlus == null)
  2045. return ResultData.error(ErrorCode.FAILURE_CODE_5005);
  2046. List<String> deleteSidList = param.getSidList();
  2047. //处理删除状态数据
  2048. this.deleteHotData(param.getNum(), deleteSidList);
  2049. //写入本地文件,作为备份
  2050. this.writeHotJson(param.getNum());
  2051. //保存数据库
  2052. SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
  2053. sceneEditInfoService.saveTagsToSceneEditInfo(param.getNum(), sceneEditInfo);
  2054. sceneEditInfoService.updateById(sceneEditInfo);
  2055. return ResultData.ok();
  2056. }
  2057. @Override
  2058. public ResultData deleteIcons(DeleteHotIconParamVO param) throws Exception {
  2059. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
  2060. if (scenePlus == null)
  2061. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  2062. List<String> fileNameList = param.getFileNameList();
  2063. this.syncIconsFromFileToRedis(param.getNum());
  2064. String key = String.format(RedisKey.SCENE_HOT_ICONS, param.getNum());
  2065. redisUtil.setRemove(key, fileNameList.toArray());
  2066. //写入本地文件,作为备份
  2067. this.writeHotJson(param.getNum());
  2068. return ResultData.ok();
  2069. }
  2070. @Override
  2071. public ResultData listTags(String num) throws Exception{
  2072. //保证热点数据安全性,当redis宕机导致热点数据丢失时,可以从文件中读取,恢复到redis
  2073. this.syncHotFromFileToRedis(num);
  2074. //保证icons数据安全性,当redis宕机导致icons数据丢失时,可以从文件中读取,恢复到redis
  2075. this.syncIconsFromFileToRedis(num);
  2076. JSONObject result = new JSONObject();
  2077. //查询缓存是否包含热点数据
  2078. String key = String.format(RedisKey.SCENE_HOT_DATA, num);
  2079. Map<String, String> allTagsMap = redisUtil.hmget(key);
  2080. List<JSONObject> tags = Lists.newArrayList();
  2081. List<TagBean> tagBeanList = new ArrayList<>();
  2082. if(CollUtil.isNotEmpty(allTagsMap)){
  2083. allTagsMap.entrySet().stream().forEach(entry -> {
  2084. JSONObject jsonObject = JSON.parseObject(entry.getValue());
  2085. tagBeanList.add(
  2086. TagBean.builder()
  2087. .createTime(jsonObject.getLong("createTime"))
  2088. .tag(jsonObject).build());
  2089. });
  2090. //按创建时间倒叙排序
  2091. tagBeanList.sort(Comparator.comparingLong(TagBean::getCreateTime).reversed());
  2092. //移除createTime字段
  2093. tags = tagBeanList.stream().map(tagBean -> {
  2094. JSONObject tag = tagBean.getTag();
  2095. tag.remove("createTime");
  2096. return tag;
  2097. }).collect(Collectors.toList());
  2098. }
  2099. result.put("tags", tags);
  2100. //查询缓存是否包含icons
  2101. key = String.format(RedisKey.SCENE_HOT_ICONS, num);
  2102. Set<String> icons = redisUtil.sGet(key);
  2103. if(icons == null){
  2104. icons = Sets.newHashSet();
  2105. }
  2106. List<String> iconList = this.sortIcons(tags, icons);
  2107. result.put("icons", iconList);
  2108. return ResultData.ok(result);
  2109. }
  2110. private List<String> sortIcons(List<JSONObject> tags, Set<String> icons){
  2111. //统计使用频次
  2112. List<IconBean> iconBeans = Lists.newArrayList();
  2113. for (String icon : icons) {
  2114. int count = 0;
  2115. for (JSONObject tag : tags) {
  2116. String sid = tag.getString("icon");
  2117. if(StrUtil.isEmpty(sid) || !icon.equals(sid)){
  2118. continue;
  2119. }
  2120. ++count;
  2121. }
  2122. iconBeans.add(IconBean.builder().icon(icon).count(count).build());
  2123. }
  2124. //排序
  2125. List<String> iconList = iconBeans.stream().sorted(Comparator.comparing(IconBean::getCount).reversed())
  2126. .map(item -> {
  2127. return item.getIcon();
  2128. }).collect(Collectors.toList());
  2129. return iconList;
  2130. }
  2131. /**
  2132. * <p>
  2133. 保证热点数据安全性,当redis宕机导致热点数据丢失时,可以从文件中读取,恢复到redis
  2134. * </p>
  2135. * @author dengsixing
  2136. * @date 2022/3/3
  2137. **/
  2138. private void syncHotFromFileToRedis(String num) throws Exception{
  2139. String key = String.format(RedisKey.SCENE_HOT_DATA, num);
  2140. boolean exist = redisUtil.hasKey(key);
  2141. if(exist){
  2142. return;
  2143. }
  2144. String lockKey = String.format(RedisLockKey.LOCK_HOT_DATA_SYNC, num);
  2145. boolean lock = redisLockUtil.lock(lockKey, RedisKey.EXPIRE_TIME_1_MINUTE);
  2146. if(!lock){
  2147. throw new BusinessException(ErrorCode.SYSTEM_BUSY);
  2148. }
  2149. try{
  2150. exist = redisUtil.hasKey(key);
  2151. if(exist){
  2152. return;
  2153. }
  2154. String tagsFilePath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num);
  2155. String tagsData = FileUtils.readFile(tagsFilePath + "hot.json");
  2156. if(StrUtil.isEmpty(tagsData)){
  2157. return;
  2158. }
  2159. JSONObject jsonObject = JSON.parseObject(tagsData);
  2160. JSONArray tagsArr = jsonObject.getJSONArray("tags");
  2161. if(CollUtil.isEmpty(tagsArr)){
  2162. return;
  2163. }
  2164. Map<String, String> map = new HashMap<>();
  2165. for (Object o : tagsArr) {
  2166. JSONObject jo = (JSONObject)o;
  2167. map.put(jo.getString("sid"), jo.toJSONString());
  2168. }
  2169. redisUtil.hmset(key, map);
  2170. }finally {
  2171. redisLockUtil.unlockLua(lockKey);
  2172. }
  2173. }
  2174. /**
  2175. * <p>
  2176. 保证icons数据安全性,当redis宕机导致icons数据丢失时,可以从文件中读取,恢复到redis
  2177. * </p>
  2178. * @author dengsixing
  2179. * @date 2022/3/3
  2180. **/
  2181. private void syncIconsFromFileToRedis(String num) throws Exception{
  2182. String key = String.format(RedisKey.SCENE_HOT_ICONS, num);
  2183. boolean exist = redisUtil.hasKey(key);
  2184. if(exist){
  2185. return;
  2186. }
  2187. String lockKey = String.format(RedisLockKey.LOCK_HOT_ICONS_SYNC, num);
  2188. boolean lock = redisLockUtil.lock(lockKey, RedisKey.EXPIRE_TIME_1_MINUTE);
  2189. if(!lock){
  2190. throw new BusinessException(ErrorCode.SYSTEM_BUSY);
  2191. }
  2192. try{
  2193. exist = redisUtil.hasKey(key);
  2194. if(exist){
  2195. return;
  2196. }
  2197. String tagsFilePath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num);
  2198. String tagsData = FileUtils.readFile(tagsFilePath + "hot.json");
  2199. if(StrUtil.isEmpty(tagsData)){
  2200. return;
  2201. }
  2202. JSONObject jsonObject = JSON.parseObject(tagsData);
  2203. JSONArray iconArr = jsonObject.getJSONArray("icons");
  2204. if(CollUtil.isEmpty(iconArr)){
  2205. return;
  2206. }
  2207. redisUtil.sSet(key, iconArr.toJavaList(String.class).toArray());
  2208. }finally {
  2209. redisLockUtil.unlockLua(lockKey);
  2210. }
  2211. }
  2212. /**
  2213. * <p>
  2214. 热点数据保存
  2215. * </p>
  2216. * @author dengsixing
  2217. * @date 2022/3/3
  2218. **/
  2219. private void writeHotJson(String num) throws Exception{
  2220. String dataKey = String.format(RedisKey.SCENE_HOT_DATA, num);
  2221. Map<String, String> tagMap = redisUtil.hmget(dataKey);
  2222. List<String> tagList = Lists.newArrayList();
  2223. tagMap.entrySet().stream().forEach(entry->{
  2224. if(StrUtil.isNotEmpty(entry.getValue())){
  2225. tagList.add(entry.getValue());
  2226. }
  2227. });
  2228. JSONObject jsonObject = new JSONObject();
  2229. JSONArray tagJsonArr = new JSONArray();
  2230. if(CollUtil.isNotEmpty(tagList)){
  2231. tagList.stream().forEach(hot->{
  2232. tagJsonArr.add(JSONObject.parseObject(hot));
  2233. });
  2234. }
  2235. jsonObject.put("tags", tagJsonArr);
  2236. String iconsKey = String.format(RedisKey.SCENE_HOT_ICONS, num);
  2237. Set<String> iconList = redisUtil.sGet(iconsKey);
  2238. jsonObject.put("icons", iconList);
  2239. String hotJsonPath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num) + "hot.json";
  2240. String lockKey = String.format(RedisLockKey.LOCK_HOT_JSON, num);
  2241. boolean lock = redisLockUtil.lock(lockKey, RedisKey.EXPIRE_TIME_1_MINUTE);
  2242. if(!lock){
  2243. return;
  2244. }
  2245. try{
  2246. FileUtils.writeFile(hotJsonPath, jsonObject.toJSONString());
  2247. }finally {
  2248. redisLockUtil.unlockLua(lockKey);
  2249. }
  2250. }
  2251. private void addOrUpdateHotDataHandler(String num, Map<String, String> addOrUpdateMap){
  2252. if(CollUtil.isEmpty(addOrUpdateMap))
  2253. return;
  2254. //数据验证,新增、修改状态,hotdata不能为空
  2255. for (String sid : addOrUpdateMap.keySet()) {
  2256. String hotData = addOrUpdateMap.get(sid);
  2257. if(StrUtil.isEmpty(hotData)){
  2258. throw new BusinessException(ErrorCode.FAILURE_CODE_7004);
  2259. }
  2260. }
  2261. //批量写入缓存
  2262. String key = String.format(RedisKey.SCENE_HOT_DATA, num);
  2263. redisUtil.hmset(key, addOrUpdateMap);
  2264. }
  2265. private void deleteHotData(String num, List<String> deleteSidList) throws Exception {
  2266. this.syncHotFromFileToRedis(num);
  2267. if(CollUtil.isEmpty(deleteSidList)){
  2268. return;
  2269. }
  2270. //从redis中加载热点数据
  2271. String key = String.format(RedisKey.SCENE_HOT_DATA, num);
  2272. List<String> deletDataList = redisUtil.hMultiGet(key, deleteSidList);
  2273. if(CollUtil.isEmpty(deletDataList))
  2274. return;
  2275. String userDataPath = String.format(UploadFilePath.USER_EDIT_PATH, num);
  2276. //删除图片音频视频等资源文件
  2277. for (String data : deletDataList) {
  2278. if(StrUtil.isBlank(data)){
  2279. continue;
  2280. }
  2281. JSONObject jsonObject = JSON.parseObject(data);
  2282. String sid = jsonObject.getString("sid");
  2283. if(jsonObject.containsKey("media")){
  2284. String fileType = jsonObject.getString("media");
  2285. if(fileType.contains("photo"))
  2286. {
  2287. uploadToOssUtil.delete(userDataPath + "hot"+sid+".jpg");
  2288. }
  2289. if(fileType.contains("audio") || fileType.contains("voice"))
  2290. {
  2291. uploadToOssUtil.delete(userDataPath + "hot"+sid+".mp3");
  2292. }
  2293. if(fileType.contains("video"))
  2294. {
  2295. uploadToOssUtil.delete(userDataPath + "hot"+sid+".mp4");
  2296. }
  2297. }
  2298. if(!StorageType.AWS.code().equals(this.type)){
  2299. JSONObject paramData = new JSONObject();
  2300. paramData.put("hotId", sid);
  2301. JSONObject hotListJson = JSONObject.parseObject(OkHttpUtils.httpGet(hotDomainList));
  2302. if(hotListJson != null){
  2303. JSONArray hotListArray = hotListJson.getJSONArray("data");
  2304. if(hotListArray != null){
  2305. for(int l = 0, len = hotListArray.size(); l < len; l++){
  2306. OkHttpUtils.httpPostJson(hotListArray.getString(l) + hotDelete + "?hotId=" + sid
  2307. , paramData.toJSONString());
  2308. }
  2309. }
  2310. }
  2311. }
  2312. }
  2313. //从redis中移除热点数据
  2314. redisUtil.hdel(key, deleteSidList.toArray());
  2315. }
  2316. @Override
  2317. // @SystemServiceLog(description = "保存场景热点")
  2318. public ResultData saveShopHot(SceneEditParamVO base) throws Exception {
  2319. if(StrUtil.isEmpty(base.getType())){
  2320. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  2321. }
  2322. String fileName = "shopHot.json";
  2323. String sid = base.getSid();
  2324. ScenePro scenePro = findBySceneNum(base.getNum());
  2325. if (scenePro == null ) {
  2326. return ResultData.error(ErrorCode.FAILURE_CODE_5005);
  2327. }
  2328. JSONObject jsonhot = JSONObject.parseObject(base.getHotData());
  2329. StringBuffer dataBuf = new StringBuffer()
  2330. .append("data").append(File.separator)
  2331. .append("data").append(scenePro.getNum())
  2332. .append(File.separator);
  2333. StringBuffer imagesBuf = new StringBuffer()
  2334. .append("images").append(File.separator)
  2335. .append("images").append(scenePro.getNum())
  2336. .append(File.separator);
  2337. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  2338. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  2339. String str = FileUtils.readFile(dataBuffer.toString() + fileName);
  2340. JSONArray jsonhots = null;
  2341. if (StrUtil.isNotEmpty(str)) {
  2342. jsonhots = JSONArray.parseArray(str);
  2343. }else {
  2344. File file = new File(dataBuffer.toString() + fileName);
  2345. if(!file.getParentFile().exists()){
  2346. file.getParentFile().mkdirs();
  2347. }
  2348. if(!file.exists()){
  2349. file.createNewFile();
  2350. }
  2351. jsonhots = new JSONArray();
  2352. }
  2353. //添加或者修改
  2354. if("1".equals(base.getType())){
  2355. sid = jsonhot.getString("sid");
  2356. if(StrUtil.isEmpty(sid)){
  2357. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  2358. }
  2359. jsonhots.add(jsonhot);
  2360. }
  2361. else if("0".equals(base.getType())){
  2362. sid = jsonhot.getString("sid");
  2363. if(StrUtil.isEmpty(sid)){
  2364. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  2365. }
  2366. }
  2367. else if("-1".equals(base.getType())){
  2368. if(StrUtil.isEmpty(sid)){
  2369. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  2370. }
  2371. }
  2372. for(int i=0;i<jsonhots.size();++i){
  2373. JSONObject ele = jsonhots.getJSONObject(i);
  2374. if(ele.getString("sid").equals(sid)){
  2375. if("-1".equals(base.getType())){
  2376. jsonhots.remove(i);
  2377. if(ele.containsKey("media")){
  2378. String fileType = ele.getString("media");
  2379. if(fileType.contains("photo"))
  2380. {
  2381. FileUtils.deleteFile(imagesBuffer.toString() + "hot"+sid+".jpg");
  2382. }
  2383. if(fileType.contains("audio") || fileType.contains("voice"))
  2384. {
  2385. FileUtils.deleteFile(imagesBuffer.toString() + "hot"+sid+".mp3");
  2386. }
  2387. if(fileType.contains("video"))
  2388. {
  2389. FileUtils.deleteFile(imagesBuffer.toString() + "hot"+sid+".mp4");
  2390. }
  2391. }
  2392. }
  2393. else if("0".equals(base.getType())){
  2394. jsonhots.set(i, jsonhot);
  2395. }
  2396. break;
  2397. }
  2398. }
  2399. FileUtils.deleteFile(dataBuffer.toString() + fileName);
  2400. File dataPath = new File(dataBuffer.toString());
  2401. if(!dataPath.exists()){
  2402. dataPath.mkdirs();
  2403. }
  2404. FileUtils.writeFile(dataBuffer.toString() + fileName, jsonhots.toString());
  2405. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  2406. JSONObject scenejson = new JSONObject();
  2407. if(strsceneInfos!=null){
  2408. scenejson = JSONObject.parseObject(strsceneInfos);
  2409. }
  2410. scenejson.put("version", scenejson.getIntValue("version") + 1);
  2411. FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
  2412. return ResultData.ok();
  2413. }
  2414. @Override
  2415. public ResultData saveOverlay(SceneEditParamVO base) throws Exception {
  2416. if(StrUtil.isEmpty(base.getType())){
  2417. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  2418. }
  2419. String sid = base.getSid();
  2420. ScenePro scenePro = findBySceneNum(base.getNum());
  2421. if (scenePro == null ) {
  2422. return ResultData.error(ErrorCode.FAILURE_CODE_5005);
  2423. }
  2424. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  2425. if (sceneProEdit == null ) {
  2426. return ResultData.error(ErrorCode.FAILURE_CODE_5005);
  2427. }
  2428. SceneProEditExt sceneProEditExt = sceneProEditExtService.getByProEditId(sceneProEdit.getId());
  2429. //需要操作的数据
  2430. JSONObject jsonOverlay = JSONObject.parseObject(base.getOverlayData());
  2431. StringBuffer dataBuf = new StringBuffer()
  2432. .append("data").append(File.separator)
  2433. .append("data").append(scenePro.getNum())
  2434. .append(File.separator);
  2435. StringBuffer imagesBuf = new StringBuffer()
  2436. .append("images").append(File.separator)
  2437. .append("images").append(scenePro.getNum())
  2438. .append(File.separator);
  2439. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  2440. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  2441. String str = sceneProEditExt.getOverlay();
  2442. JSONArray jsonOverlays = null;
  2443. if (StrUtil.isNotEmpty(str)) {
  2444. jsonOverlays = JSONArray.parseArray(str);
  2445. }else {
  2446. jsonOverlays = new JSONArray();
  2447. }
  2448. //添加或者修改
  2449. if("1".equals(base.getType())){
  2450. sid = jsonOverlay.getString("sid");
  2451. if(StrUtil.isEmpty(sid)){
  2452. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  2453. }
  2454. jsonOverlays.add(jsonOverlay);
  2455. }
  2456. else if("0".equals(base.getType())){
  2457. sid = jsonOverlay.getString("sid");
  2458. if(StrUtil.isEmpty(sid)){
  2459. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  2460. }
  2461. }
  2462. else if("-1".equals(base.getType())){
  2463. if(StrUtil.isEmpty(sid)){
  2464. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  2465. }
  2466. }
  2467. for(int i=0;i<jsonOverlays.size();++i){
  2468. JSONObject ele = jsonOverlays.getJSONObject(i);
  2469. if(ele.getString("sid").equals(sid)){
  2470. if("-1".equals(base.getType())){
  2471. jsonOverlays.remove(i);
  2472. if(ele.containsKey("media")){
  2473. String fileType = ele.getString("media");
  2474. if(fileType.contains("photo"))
  2475. {
  2476. FileUtils.deleteFile(imagesBuffer.toString() + "overlay"+sid+".jpg");
  2477. }
  2478. if(fileType.contains("audio") || fileType.contains("voice"))
  2479. {
  2480. FileUtils.deleteFile(imagesBuffer.toString() + "overlay"+sid+".mp3");
  2481. }
  2482. if(fileType.contains("video"))
  2483. {
  2484. FileUtils.deleteFile(imagesBuffer.toString() + "overlay"+sid+".mp4");
  2485. }
  2486. }
  2487. }
  2488. else if("0".equals(base.getType())){
  2489. jsonOverlays.set(i, jsonOverlay);
  2490. }
  2491. break;
  2492. }
  2493. }
  2494. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  2495. JSONObject scenejson = new JSONObject();
  2496. if(strsceneInfos!=null){
  2497. scenejson = JSONObject.parseObject(strsceneInfos);
  2498. }
  2499. scenejson.put("overlay", jsonOverlays.toString());
  2500. scenejson.put("version", scenejson.getIntValue("version") + 1);
  2501. FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
  2502. sceneProEdit.setVersion(scenejson.getIntValue("version") + 1);
  2503. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  2504. sceneProEditExt.setOverlay(jsonOverlays.toString());
  2505. sceneProEditExt.setUpdateTime(Calendar.getInstance().getTime());
  2506. sceneProEditService.updateById(sceneProEdit);
  2507. sceneProEditExtService.updateById(sceneProEditExt);
  2508. return ResultData.ok();
  2509. }
  2510. @Override
  2511. public ResultData uploadOverlayMedia(FileParamVO param, MultipartFile file) throws Exception {
  2512. String sceneNum = param.getNum();
  2513. String sid = param.getSid();
  2514. if(StrUtil.isEmpty(sceneNum)){
  2515. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  2516. }
  2517. ScenePro scenePro = findBySceneNum(sceneNum);
  2518. if(scenePro == null){
  2519. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  2520. }
  2521. String fileName = "overlay" + sid + ".mp4";
  2522. if (!file.isEmpty()){
  2523. String path = ConstantFilePath.SCENE_PATH + "images" + File.separator + "images" + sceneNum;
  2524. File targetFile = new File(path);
  2525. if (!targetFile.exists()){
  2526. targetFile.mkdirs();
  2527. }
  2528. targetFile = new File(path + File.separator + fileName);
  2529. if (targetFile.exists()){
  2530. FileUtils.deleteFile(path + File.separator + fileName);
  2531. }
  2532. file.transferTo(targetFile);
  2533. CreateObjUtil.mp4ToFlv(path + File.separator + fileName, path + File.separator + fileName.replace("mp4", "flv"));
  2534. uploadToOssUtil.upload(path + File.separator + fileName, "images"+File.separator+"images"+sceneNum + File.separator + fileName);
  2535. uploadToOssUtil.upload(path + File.separator + fileName.replace("mp4", "flv"), "images"+File.separator+"images"+sceneNum + File.separator + fileName.replace("mp4", "flv"));
  2536. }
  2537. return ResultData.ok(fileName);
  2538. }
  2539. @Override
  2540. // @SystemServiceLog(description = "保存场景热点")
  2541. public ResultData saveScreencapData(SceneEditParamVO base) throws Exception {
  2542. if(StrUtil.isEmpty(base.getNum())){
  2543. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  2544. }
  2545. ScenePro scenePro = findBySceneNum(base.getNum());
  2546. if(scenePro == null){
  2547. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  2548. }
  2549. StringBuffer dataBuf = new StringBuffer()
  2550. .append("data").append(File.separator)
  2551. .append("data").append(scenePro.getNum())
  2552. .append(File.separator);
  2553. StringBuffer imagesBuf = new StringBuffer()
  2554. .append("images").append(File.separator)
  2555. .append("images").append(scenePro.getNum())
  2556. .append(File.separator);
  2557. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  2558. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  2559. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  2560. JSONObject scenejson = new JSONObject();
  2561. if(strsceneInfos!=null) {
  2562. scenejson = JSONObject.parseObject(strsceneInfos);
  2563. }
  2564. if(base.getScreencapVoiceType() != null){
  2565. scenejson.put("screencapVoiceType", base.getScreencapVoiceType());
  2566. }
  2567. if(!StrUtil.isEmpty(base.getCapData())){
  2568. FileUtils.writeFile(dataBuffer.toString() + "capData.json", new String(base.getCapData().getBytes(), "UTF-8"));
  2569. scenejson.put("capData", dataBuf.toString() + "capData.json");
  2570. }
  2571. if(!StrUtil.isEmpty(base.getFrameData())){
  2572. FileUtils.writeFile(dataBuffer.toString() + "frameData.json", new String(base.getFrameData().getBytes(), "UTF-8"));
  2573. scenejson.put("frameData", dataBuf.toString() + "frameData.json");
  2574. }
  2575. if(!StrUtil.isEmpty(base.getPlayData())){
  2576. FileUtils.writeFile(dataBuffer.toString() + "playData.json", new String(base.getPlayData().getBytes(), "UTF-8"));
  2577. scenejson.put("playData", dataBuf.toString() + "playData.json");
  2578. }
  2579. if(!StrUtil.isEmpty(base.getScreencapThumb())){
  2580. FileUtils.writeFile(dataBuffer.toString() + "screencapThumb.json", new String(base.getScreencapThumb().getBytes(), "UTF-8"));
  2581. scenejson.put("screencapThumb", dataBuf.toString() + "screencapThumb.json");
  2582. }
  2583. if(!StrUtil.isEmpty(base.getRecordType())){
  2584. scenejson.put("recordType", base.getRecordType());
  2585. }
  2586. scenejson.put("version", scenejson.getIntValue("version") + 1);
  2587. FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
  2588. return ResultData.ok();
  2589. }
  2590. @Override
  2591. // @SystemServiceLog(description = "保存热点可见性的数据")
  2592. public ResultData saveTagsVisible(SaveTagsVisibleParamVO param) throws Exception {
  2593. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
  2594. if (scenePlus == null ) {
  2595. return ResultData.error(ErrorCode.FAILURE_CODE_5005);
  2596. }
  2597. JSONArray visiblePanos = JSONArray.parseArray(param.getData());
  2598. //如果redis找不到,就从本地文件中reload
  2599. this.syncHotFromFileToRedis(param.getNum());
  2600. //从缓存中获取热点数据,如果为空,抛出异常
  2601. String key = String.format(RedisKey.SCENE_HOT_DATA, param.getNum());
  2602. Map<String, String> map = redisUtil.hmget(key);
  2603. if (CollUtil.isEmpty(map)) {
  2604. throw new BusinessException(ErrorCode.FAILURE_CODE_7005);
  2605. }
  2606. List<Entry<String, String>> allTags = map.entrySet().stream().filter(item -> {
  2607. if (StrUtil.isBlank(item.getValue())) {
  2608. return false;
  2609. }
  2610. return true;
  2611. }).collect(Collectors.toList());
  2612. if (CollUtil.isEmpty(allTags)) {
  2613. throw new BusinessException(ErrorCode.FAILURE_CODE_7005);
  2614. }
  2615. allTags.stream().forEach(entry->{
  2616. JSONObject hot = JSON.parseObject(entry.getValue());
  2617. visiblePanos.stream().forEach(item->{
  2618. if (hot.getString("sid").equals(((JSONObject) item).getString("sid"))) {
  2619. hot.put("visiblePanos", ((JSONObject) item).getJSONArray("value"));
  2620. hot.put("isHidden", ((JSONObject) item).getBoolean("isHidden"));
  2621. entry.setValue(hot.toJSONString());
  2622. }
  2623. });
  2624. });
  2625. //更新版本号
  2626. SceneEditInfo editInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
  2627. sceneEditInfoService.upgradeVersionById(editInfo.getId());
  2628. //放入缓存
  2629. Map<String, String> finalMap = new HashMap<>();
  2630. allTags.stream().forEach(entry->{
  2631. finalMap.put(entry.getKey(), entry.getValue());
  2632. });
  2633. redisUtil.hmset(key, finalMap);
  2634. //写入本地文件,作为备份,以防redis数据丢失
  2635. this.writeHotJson(param.getNum());
  2636. return ResultData.ok();
  2637. }
  2638. @Override
  2639. // @SystemServiceLog(description = "漫游可行")
  2640. public ResultData saveRoam(BaseDataParamVO param) throws Exception {
  2641. // ScenePro scenePro = this.findBySceneNum(param.getNum());
  2642. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
  2643. if (scenePlus == null ) {
  2644. return ResultData.error(ErrorCode.FAILURE_CODE_5005);
  2645. }
  2646. JSONArray inputData = JSONObject.parseArray(param.getData());
  2647. String localDataPath = String.format(ConstantFilePath.SCENE_DATA_PATH_V4, param.getNum());
  2648. File directory = new File(localDataPath);
  2649. if (!directory.exists()) {
  2650. directory.mkdirs();
  2651. }
  2652. String viewImagesPath = String.format(UploadFilePath.IMG_VIEW_PATH, param.getNum());
  2653. String modeldataUrl = ossUrlPrefix + viewImagesPath + "vision.modeldata?t=" + System.currentTimeMillis();
  2654. //如果是云存储,将vision.modeldata下载到本地,如果是本地存储,场景计算完就已经将这个文件拷贝到编辑目录了存在这个文件了,不需要再下载
  2655. if(!StorageType.LOCAL.code().equals(this.type)){
  2656. FileUtils.downLoadFromUrl(modeldataUrl, "vision.modeldata", localDataPath);
  2657. }
  2658. //检查vision.modeldata本地是否存在,不存在抛出异常
  2659. File file = new File(localDataPath + "vision.modeldata");
  2660. if(!file.exists()) {
  2661. return ResultData.error(ErrorCode.FAILURE_CODE_5012);
  2662. }
  2663. //将vision.modeldata解压缩至vision.json
  2664. ConvertUtils.convertVisionModelDataToTxt(localDataPath + "vision.modeldata", localDataPath + "vision.json");
  2665. String str = FileUtils.readFile(localDataPath + "vision.json");
  2666. JSONObject json = JSONObject.parseObject(str);
  2667. JSONArray panos = json.getJSONArray("sweepLocations");
  2668. for (int i = 0; i < panos.size(); ++i) {
  2669. JSONObject pano = panos.getJSONObject(i);
  2670. for (int j = 0; j < inputData.size(); ++j) {
  2671. JSONObject jo = inputData.getJSONObject(j);
  2672. String currentPanoId = jo.getString("panoID");
  2673. JSONArray visibles = jo.getJSONArray("visibles");
  2674. JSONArray visibles3 = jo.getJSONArray("visibles3");
  2675. if (pano.getString("uuid").equals(currentPanoId)) {
  2676. pano.put("visibles", visibles);
  2677. pano.put("visibles3", visibles3);
  2678. }
  2679. }
  2680. }
  2681. FileUtils.deleteFile(localDataPath + "vision.json");
  2682. FileUtils.deleteFile(localDataPath + "vision.modeldata");
  2683. FileUtils.writeFile(localDataPath + "vision.json", json.toString());
  2684. ConvertUtils.convertTxtToVisionModelData(localDataPath + "vision.json", localDataPath + "vision.modeldata");
  2685. uploadToOssUtil.upload(localDataPath + "vision.modeldata", viewImagesPath + "vision.modeldata");
  2686. //更新版本号
  2687. SceneEditInfo editInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
  2688. if(Objects.isNull(editInfo)){
  2689. editInfo = new SceneEditInfo();
  2690. editInfo.setScenePlusId(scenePlus.getId());
  2691. sceneEditInfoService.save(editInfo);
  2692. }else{
  2693. sceneEditInfoService.upgradeVersionById(editInfo.getId());
  2694. //更新scenejson缓存和oss文件版本号
  2695. sceneEditInfoService.upgradeSceneJsonVersion(param.getNum(), editInfo.getVersion() + 1);
  2696. }
  2697. //更新scene.json版本号
  2698. // sceneEditInfoService.upgradeVersionToSceneJson(param.getNum());
  2699. return ResultData.ok();
  2700. }
  2701. @Override
  2702. public ResultData uploadShareLogo(SceneEditParamVO base, MultipartFile file) throws Exception {
  2703. if(file == null || StrUtil.isEmpty(base.getNum())){
  2704. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  2705. }
  2706. ScenePro scenePro = findBySceneNum(base.getNum());
  2707. if (scenePro == null ) {
  2708. return ResultData.error(ErrorCode.FAILURE_CODE_5005);
  2709. }
  2710. StringBuffer dataBuf = new StringBuffer()
  2711. .append("data").append(File.separator)
  2712. .append("data").append(scenePro.getNum())
  2713. .append(File.separator);
  2714. StringBuffer imagesBuf = new StringBuffer()
  2715. .append("images").append(File.separator)
  2716. .append("images").append(scenePro.getNum())
  2717. .append(File.separator);
  2718. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  2719. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  2720. String fileName = "";
  2721. if (!file.isEmpty()&&file.getSize() > 0) {
  2722. //文件上传的位置可以自定义
  2723. System.out.println("上传分享的logo");
  2724. String path = imagesBuffer.toString();
  2725. File targetFile = new File(path);
  2726. if (!targetFile.exists()) {
  2727. targetFile.mkdirs();
  2728. }
  2729. fileName = file.getOriginalFilename();
  2730. targetFile = new File(path + fileName);
  2731. int count = 1;
  2732. // 保存
  2733. synchronized(this)
  2734. {
  2735. file.transferTo(targetFile);
  2736. }
  2737. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  2738. // Map<String, Object> map = new HashMap<>();
  2739. // map.put("shareLogo", imagesBuf.toString() + fileName);
  2740. // map.put("version", sceneProEdit.getVersion()+1);
  2741. // FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map);
  2742. sceneProEdit.setShareLogo(imagesBuf.toString() + fileName);
  2743. sceneProEdit.setVersion(sceneProEdit.getVersion()+1);
  2744. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  2745. sceneProEditService.updateById(sceneProEdit);
  2746. if("V2".equals(scenePro.getBuildType())){
  2747. MatrixToImageWriterUtil.createQRCode(mainUrl + sceneProUrl + scenePro.getNum(), ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+scenePro.getNum()+".png", true, path + File.separator + fileName);
  2748. MatrixToImageWriterUtil.createQRCode(mainUrl + sceneProUrl + scenePro.getNum() + "&lang=en", ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+scenePro.getNum()+"_en.png", true, path + File.separator + fileName);
  2749. }
  2750. if("V3".equals(scenePro.getBuildType())){
  2751. MatrixToImageWriterUtil.createQRCode(mainUrl + sceneProNewUrl + scenePro.getNum(), ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+scenePro.getNum()+".png", true, path + File.separator + fileName);
  2752. MatrixToImageWriterUtil.createQRCode(mainUrl + sceneProNewUrl + scenePro.getNum() + "&lang=en", ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+scenePro.getNum()+"_en.png", true, path + File.separator + fileName);
  2753. }
  2754. }
  2755. return ResultData.ok(imagesBuf.toString() + fileName);
  2756. }
  2757. @Override
  2758. public ResultData uploadPic(FileParamVO param, MultipartFile file) throws Exception{
  2759. String sceneNum = param.getNum();
  2760. String folderName = param.getFolderName();
  2761. String toOss = param.getToOss();
  2762. if(StrUtil.isEmpty(sceneNum)){
  2763. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  2764. }
  2765. ScenePro scenePro = baseMapper.findByNum(sceneNum);
  2766. if(scenePro == null){
  2767. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  2768. }
  2769. if (file.isEmpty() && file.getSize() <= 0) {
  2770. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  2771. }
  2772. //文件上传的位置可以自定义
  2773. String path = ConstantFilePath.SCENE_PATH+"images"+File.separator+"images"+sceneNum;
  2774. if(StrUtil.isNotEmpty(folderName)) {
  2775. path = path+File.separator + folderName;
  2776. }
  2777. File targetFile = new File(path);
  2778. if (!targetFile.exists()) {
  2779. targetFile.mkdirs();
  2780. }
  2781. String fileName = file.getOriginalFilename();
  2782. targetFile = new File(path + File.separator + fileName);
  2783. // 保存
  2784. synchronized(this)
  2785. {
  2786. if(targetFile.exists())
  2787. {
  2788. FileUtils.deleteFile(path + File.separator + fileName);
  2789. }
  2790. file.transferTo(targetFile);
  2791. }
  2792. if(toOss != null && "1".equals(toOss)){
  2793. uploadToOssUtil.upload(path + File.separator + fileName, "images"+File.separator+"images"+sceneNum + File.separator + fileName);
  2794. }
  2795. return ResultData.ok(targetFile.getName());
  2796. }
  2797. @Override
  2798. public ResultData uploadHotJsonToOss(SceneEditParamVO param) throws Exception {
  2799. String sceneNum = param.getNum();
  2800. if(StrUtil.isEmpty(sceneNum)){
  2801. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  2802. }
  2803. String path = ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+sceneNum;
  2804. uploadToOssUtil.upload(path + File.separator + "hot.json", "data"+File.separator+"data"+sceneNum + File.separator + "hot.json");
  2805. return ResultData.ok();
  2806. }
  2807. @Override
  2808. public ResultData deleteOss(FileParamVO param) throws Exception {
  2809. uploadToOssUtil.deleteFile(param.getFilePath());
  2810. return ResultData.ok();
  2811. }
  2812. @Override
  2813. public ResultData uploadFloorplanPng(FileParamVO param, MultipartFile[] file) throws Exception{
  2814. String sceneNum = param.getNum();
  2815. String cadInfo = param.getCadInfo();
  2816. if(StrUtil.isEmpty(sceneNum)){
  2817. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  2818. }
  2819. ScenePro scenePro = baseMapper.findByNum(sceneNum);
  2820. if(scenePro == null){
  2821. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  2822. }
  2823. if (file.length <= 0) {
  2824. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  2825. }
  2826. StringBuffer dataBuf = new StringBuffer()
  2827. .append("data").append(File.separator)
  2828. .append("data").append(scenePro.getNum())
  2829. .append(File.separator);
  2830. StringBuffer imagesBuf = new StringBuffer()
  2831. .append("images").append(File.separator)
  2832. .append("images").append(scenePro.getNum())
  2833. .append(File.separator);
  2834. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  2835. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  2836. //文件上传的位置可以自定义
  2837. String path = ConstantFilePath.SCENE_PATH+"images"+File.separator+"images"+sceneNum;
  2838. File targetFile = new File(path);
  2839. if (!targetFile.exists()) {
  2840. targetFile.mkdirs();
  2841. }
  2842. String fileName = "";
  2843. JSONArray floorPlanPngArr = new JSONArray();
  2844. for (MultipartFile multipartFile : file) {
  2845. fileName = multipartFile.getOriginalFilename();
  2846. targetFile = new File(path + File.separator + fileName);
  2847. // 保存
  2848. synchronized(this)
  2849. {
  2850. if(targetFile.exists())
  2851. {
  2852. FileUtils.deleteFile(path + File.separator + fileName);
  2853. }
  2854. multipartFile.transferTo(targetFile);
  2855. }
  2856. floorPlanPngArr.add("images"+File.separator+"images"+sceneNum + File.separator + fileName);
  2857. }
  2858. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  2859. JSONObject scenejson = new JSONObject();
  2860. if(strsceneInfos!=null) {
  2861. scenejson = JSONObject.parseObject(strsceneInfos);
  2862. }
  2863. Map<String, Object> map = new HashMap<>();
  2864. map.put("floorPlanPng", floorPlanPngArr);
  2865. map.put("uploadFloorPlanPng", 1);
  2866. map.put("version", scenejson.getIntValue("version")+1);
  2867. if(StrUtil.isNotEmpty(cadInfo)){
  2868. map.put("cadInfo", cadInfo);
  2869. }
  2870. FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map);
  2871. return ResultData.ok(floorPlanPngArr);
  2872. }
  2873. @Override
  2874. public void updateTime(String sceneNum, Long space, int payStatus, String videos, long computeTime) {
  2875. List<ScenePro> list = this.list(new LambdaQueryWrapper<ScenePro>().eq(ScenePro::getNum, sceneNum));
  2876. if(CollUtil.isEmpty(list))
  2877. return;
  2878. //修改场景状态 空间 支付状态 计算时间
  2879. List<Long> sceneProIds = list.stream().map(scenePro -> {
  2880. return scenePro.getId();
  2881. }).collect(Collectors.toList());
  2882. this.update(new LambdaUpdateWrapper<ScenePro>()
  2883. .in(ScenePro::getId, sceneProIds)
  2884. .set(ScenePro::getSceneStatus, SceneStatus.NO_DISPLAY.code())
  2885. .set(ScenePro::getCreateTime, Calendar.getInstance().getTime())
  2886. .set(ScenePro::getUpdateTime, Calendar.getInstance().getTime())
  2887. .set(ScenePro::getPayStatus, payStatus)
  2888. .set(ScenePro::getVideos, videos));
  2889. sceneProExtService.update(new LambdaUpdateWrapper<SceneProExt>()
  2890. .in(SceneProExt::getSceneProId, sceneProIds)
  2891. .set(SceneProExt::getSpace, space)
  2892. .set(SceneProExt::getComputeTime, computeTime));
  2893. }
  2894. @Override
  2895. public void updateTime2(String sceneNum, String videos, long computeTime) {
  2896. List<ScenePro> list = this.list(new LambdaQueryWrapper<ScenePro>().eq(ScenePro::getNum, sceneNum));
  2897. if(CollUtil.isEmpty(list))
  2898. return;
  2899. //修改场景状态 空间 支付状态 计算时间
  2900. List<Long> sceneProIds = list.stream().map(scenePro -> {
  2901. return scenePro.getId();
  2902. }).collect(Collectors.toList());
  2903. this.update(new LambdaUpdateWrapper<ScenePro>()
  2904. .in(ScenePro::getId, sceneProIds)
  2905. .set(ScenePro::getSceneStatus, SceneStatus.NO_DISPLAY.code())
  2906. .set(ScenePro::getCreateTime, Calendar.getInstance().getTime())
  2907. .set(ScenePro::getUpdateTime, Calendar.getInstance().getTime())
  2908. .set(ScenePro::getVideos, videos));
  2909. sceneProExtService.update(new LambdaUpdateWrapper<SceneProExt>()
  2910. .in(SceneProExt::getSceneProId, sceneProIds)
  2911. .set(SceneProExt::getComputeTime, computeTime));
  2912. }
  2913. @Override
  2914. public SceneVO findLatestOneByUserId(Long userId) {
  2915. return baseMapper.findLatestOneByUserId(userId);
  2916. }
  2917. @Override
  2918. public void updateUserIdByCameraId(Long userId, Long cameraId) {
  2919. this.update(new LambdaUpdateWrapper<ScenePro>()
  2920. .eq(ScenePro::getCameraId, cameraId)
  2921. .set(ScenePro::getUserId, userId));
  2922. }
  2923. @Override
  2924. public List<SceneProPO> findByCameraIdPro(Long cameraId) {
  2925. return baseMapper.findByCameraIdPro(cameraId);
  2926. }
  2927. @Override
  2928. public void updateCameraIdByCameraIdPro(Long oldCameraId, Long cameraId) {
  2929. List<ScenePro> list = this.list(
  2930. new LambdaQueryWrapper<ScenePro>()
  2931. .select(ScenePro::getId)
  2932. .eq(ScenePro::getCameraId, oldCameraId));
  2933. if(CollUtil.isEmpty(list))
  2934. return;
  2935. //修改场景状态 空间 支付状态 计算时间
  2936. List<Long> sceneProIds = list.stream().map(scenePro -> {
  2937. return scenePro.getId();
  2938. }).collect(Collectors.toList());
  2939. this.update(new LambdaUpdateWrapper<ScenePro>()
  2940. .eq(ScenePro::getCameraId, oldCameraId)
  2941. .set(ScenePro::getCameraId, cameraId)
  2942. .set(ScenePro::getPayStatus, PayStatus.NO_CAPACITY.code()));
  2943. }
  2944. @Override
  2945. public void updateRecStatus(String unicode) {
  2946. List<SceneProExt> list = sceneProExtService.list(
  2947. new LambdaQueryWrapper<SceneProExt>()
  2948. .like(SceneProExt::getDataSource, "%" + unicode + "%"));
  2949. if(CollUtil.isEmpty(list)){
  2950. return ;
  2951. }
  2952. List<Long> sceneProIds = list.stream().map(sceneProExt -> {
  2953. return sceneProExt.getSceneProId();
  2954. }).collect(Collectors.toList());
  2955. this.update(new LambdaUpdateWrapper<ScenePro>()
  2956. .in(ScenePro::getId, sceneProIds)
  2957. .set(ScenePro::getTbStatus, TbStatus.DELETE.code()));
  2958. }
  2959. @Override
  2960. public SceneProPO findByFileId(String fileId) {
  2961. return baseMapper.findByFileId(fileId);
  2962. }
  2963. @Override
  2964. public List<ScenePro> findTempScenes() throws Exception {
  2965. return baseMapper.findTempScenes();
  2966. }
  2967. @Override
  2968. public List<String> findByCameraId(Long cameraId) throws Exception {
  2969. List<ScenePro> list = this.list(new LambdaQueryWrapper<ScenePro>()
  2970. .select(ScenePro::getWebSite)
  2971. .eq(ScenePro::getTbStatus, TbStatus.VALID.code())
  2972. .eq(ScenePro::getTbStatus, TbStatus.VALID.code())
  2973. .eq(ScenePro::getCameraId, cameraId));
  2974. if(CollUtil.isEmpty(list))
  2975. return null;
  2976. return list.stream().map(scenePro -> {
  2977. return scenePro.getWebSite();
  2978. }).collect(Collectors.toList());
  2979. }
  2980. @Override
  2981. public ResultData uploadLogoBottomStatus(FileParamVO param) throws Exception {
  2982. String sceneNum = param.getNum();
  2983. String status = param.getStatus();
  2984. if(StrUtil.isEmpty(sceneNum) || StrUtil.isEmpty(status)){
  2985. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  2986. }
  2987. ScenePro scenePro = baseMapper.findByNum(sceneNum);
  2988. if(scenePro == null){
  2989. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  2990. }
  2991. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  2992. if(sceneProEdit == null){
  2993. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  2994. }
  2995. SceneProEditExt sceneProEditExt = sceneProEditExtService.getByProEditId(sceneProEdit.getId());
  2996. StringBuffer dataBuf = new StringBuffer()
  2997. .append("data").append(File.separator)
  2998. .append("data").append(scenePro.getNum())
  2999. .append(File.separator);
  3000. StringBuffer imagesBuf = new StringBuffer()
  3001. .append("images").append(File.separator)
  3002. .append("images").append(scenePro.getNum())
  3003. .append(File.separator);
  3004. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  3005. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  3006. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  3007. JSONObject scenejson = new JSONObject();
  3008. if(strsceneInfos!=null) {
  3009. scenejson = JSONObject.parseObject(strsceneInfos);
  3010. }
  3011. scenejson.put("showLogoBottom", Integer.valueOf(status));
  3012. scenejson.put("version", scenejson.getIntValue("version") + 1);
  3013. FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
  3014. sceneProEdit.setVersion(scenejson.getIntValue("version") + 1);
  3015. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  3016. sceneProEditExt.setShowLogoBottom(Integer.valueOf(status));
  3017. sceneProEditExt.setUpdateTime(Calendar.getInstance().getTime());
  3018. sceneProEditExtService.updateById(sceneProEditExt);
  3019. sceneProEditService.updateById(sceneProEdit);
  3020. return ResultData.ok();
  3021. }
  3022. @Override
  3023. public ResultData uploadObjAndImg(String num, MultipartFile file) throws Exception{
  3024. if(StrUtil.isEmpty(num)){
  3025. throw new BusinessException(ServerCode.PARAM_REQUIRED, "num");
  3026. }
  3027. if(!file.getOriginalFilename().endsWith(".zip")){
  3028. throw new BusinessException(ErrorCode.FAILURE_CODE_7015);
  3029. }
  3030. // ScenePro scenePro = this.findBySceneNum(num);
  3031. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  3032. if(scenePlus == null){
  3033. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  3034. }
  3035. // SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
  3036. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  3037. //文件上传的位置可以自定义
  3038. String path = scenePlusExt.getDataSource() + "_obj2txt";
  3039. String zipPath = path + "/zip/";
  3040. String filePath = path + "/extras/";
  3041. String resultPath = path + "/results/";
  3042. // String path = "F:\\uploadModel" + "_obj2txt";
  3043. // String zipPath = path + "\\zip\\";
  3044. // String filePath = path + "\\extras\\";
  3045. // String resultPath = path + "\\results\\";
  3046. //压缩文件处理:解压缩,解压缩后复制等操作
  3047. this.objAndImgFileHandler(resultPath, filePath, zipPath, file);
  3048. //创建data.json
  3049. this.writeDataJson(path);
  3050. //调用算法,不同的类型调用不同的算法
  3051. if("V2".equals(scenePlusExt.getBuildType())){
  3052. CreateObjUtil.objToTxt(path , "1");
  3053. }
  3054. if("V3".equals(scenePlusExt.getBuildType())){
  3055. CreateObjUtil.build3dModel(path , "1");
  3056. }
  3057. //算法计算完后,生成压缩文件,上传到oss
  3058. this.uploadFileofterRebuildPanoram(path, num);
  3059. //更新版本信息
  3060. SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
  3061. if(Objects.isNull(sceneEditInfo)){
  3062. sceneEditInfo = new SceneEditInfo();
  3063. sceneEditInfo.setScenePlusId(scenePlus.getId());
  3064. sceneEditInfo.setFloorPublishVer(1);
  3065. sceneEditInfo.setFloorEditVer(1);
  3066. sceneEditInfo.setIsUploadObj(CommonStatus.YES.code());
  3067. sceneEditInfoService.save(sceneEditInfo);
  3068. }else{
  3069. sceneEditInfoService.update(
  3070. new LambdaUpdateWrapper<SceneEditInfo>()
  3071. .setSql("version = version + 1")
  3072. .setSql("floor_edit_ver = floor_edit_ver + 1")
  3073. .setSql("floor_publish_ver = floor_publish_ver + 1")
  3074. .set(SceneEditInfo::getIsUploadObj, CommonStatus.YES.code())
  3075. .eq(SceneEditInfo::getId, sceneEditInfo.getId()));
  3076. sceneEditInfoService.upgradeSceneJsonVersion(num, sceneEditInfo.getVersion() + 1);
  3077. }
  3078. return ResultData.ok();
  3079. }
  3080. private void uploadFileofterRebuildPanoram(String path, String sceneNum) throws Exception {
  3081. //因为共享目录有延迟,这里循环检测算法是否计算完毕3次,每次隔五秒
  3082. String uploadJsonPath = path + File.separator + "results" +File.separator+"upload.json";
  3083. boolean exist = ComputerUtil.checkComputeCompleted(uploadJsonPath, maxCheckTimes, waitTime);
  3084. if(!exist){
  3085. throw new BusinessException(ErrorCode.FAILURE_CODE_7013);
  3086. }
  3087. String uploadData = FileUtils.readFile(uploadJsonPath);
  3088. JSONObject uploadJson = null;
  3089. JSONArray array = null;
  3090. if(uploadData!=null) {
  3091. uploadJson = JSONObject.parseObject(uploadData);
  3092. array = uploadJson.getJSONArray("upload");
  3093. }
  3094. Map<String,String> map = new HashMap<String,String>();
  3095. JSONObject fileJson = null;
  3096. String fileName = "";
  3097. String imgViewPath = String.format(UploadFilePath.IMG_VIEW_PATH, sceneNum);
  3098. for(int i = 0, len = array.size(); i < len; i++) {
  3099. fileJson = array.getJSONObject(i);
  3100. fileName = fileJson.getString("file");
  3101. //文件不存在抛出异常
  3102. if (!new File(path + File.separator + "results" + File.separator + fileName).exists()) {
  3103. throw new Exception(path + File.separator + "results" + File.separator + fileName + "文件不存在");
  3104. }
  3105. //tex文件夹
  3106. if (fileJson.getIntValue("clazz") == 15) {
  3107. map.put(path + File.separator + "results" + File.separator + fileName,
  3108. imgViewPath + ConstantFileName.modelUUID + "_50k_texture_jpg_high1/" + fileName.replace("tex/", ""));
  3109. // TODO: 2022/2/17 这里复制一份到本地,不知道需不需要,先注释掉
  3110. //复制一份到images本地
  3111. // FileUtils.copyFile(path + File.separator + "results" +File.separator + fileName,
  3112. // ConstantFilePath.SCENE_PATH+"images"+File.separator+"images"+sceneNum + File.separator +
  3113. // ConstantFileName.modelUUID + "_50k_texture_jpg_high1/" + fileName.replace("tex/", ""), true);
  3114. continue;
  3115. }
  3116. }
  3117. CreateObjUtil.convertTxtToDam( path + File.separator + "results" +File.separator+"modeldata.txt", path + File.separator + "results" +File.separator+ ConstantFileName.modelUUID+"_50k.dam");
  3118. CreateObjUtil.convertDamToLzma(path + File.separator + "results");
  3119. CreateObjUtil.convertTxtToDam( path + File.separator + "results" +File.separator+"modeldata.txt", path + File.separator + "results" + File.separator+ConstantFileName.modelUUID+"_50k.dam");
  3120. map.put(path + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k.dam.lzma", imgViewPath +ConstantFileName.modelUUID+"_50k.dam.lzma");
  3121. map.put(path + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k.dam", imgViewPath+ConstantFileName.modelUUID+"_50k.dam");
  3122. uploadToOssUtil.uploadMulFiles(map);
  3123. // TODO: 2022/2/17 这里复制一份到本地,不知道需不需要,先注释掉
  3124. // FileUtils.copyFile(path + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k.dam",
  3125. // ConstantFilePath.SCENE_PATH+"images"+File.separator+"images"+sceneNum + File.separator + ConstantFileName.modelUUID+"_50k.dam", true);
  3126. // FileUtils.copyFile(path + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k.dam.lzma",
  3127. // ConstantFilePath.SCENE_PATH+"images"+File.separator+"images"+sceneNum + File.separator + ConstantFileName.modelUUID+"_50k.dam.lzma", true);
  3128. }
  3129. private void writeDataJson(String path) throws IOException {
  3130. JSONObject dataJson = new JSONObject();
  3131. dataJson.put("obj2txt", true);
  3132. dataJson.put("split_type", "SPLIT_V6");
  3133. dataJson.put("data_describe", "double spherical");
  3134. dataJson.put("skybox_type", "SKYBOX_V5");
  3135. FileUtils.writeFile(path + "/data.json", dataJson.toString());
  3136. }
  3137. private void objAndImgFileHandler(String resultPath, String filePath, String zipPath, MultipartFile file)
  3138. throws Exception {
  3139. FileUtils.delAllFile(resultPath);
  3140. File targetFile = new File(filePath);
  3141. if (!targetFile.exists()) {
  3142. targetFile.mkdirs();
  3143. }else {
  3144. FileUtils.delAllFile(filePath);
  3145. }
  3146. targetFile = new File(zipPath);
  3147. if (!targetFile.exists()) {
  3148. targetFile.mkdirs();
  3149. }else {
  3150. FileUtils.delAllFile(zipPath);
  3151. }
  3152. targetFile = new File(zipPath + file.getOriginalFilename());
  3153. if(!targetFile.getParentFile().exists()){
  3154. targetFile.getParentFile().mkdirs();
  3155. }
  3156. // 保存压缩包到本地
  3157. if(targetFile.exists())
  3158. {
  3159. FileUtils.deleteFile(zipPath + file.getOriginalFilename());
  3160. }
  3161. file.transferTo(targetFile);
  3162. FileUtils.decompress(zipPath + file.getOriginalFilename(), zipPath + "data/");
  3163. //源文件数据,判断是否有多个文件夹,有多个就提示错误,有一个就将文件夹里数据迁移到extras目录,无直接迁移到extras目录
  3164. boolean flag = false;
  3165. //目录名称,如果不为空,则压缩文件第一层是目录
  3166. String targetName = "";
  3167. File dataFile = new File(zipPath + "data/");
  3168. for(File data : dataFile.listFiles()){
  3169. if(data.isDirectory() && flag){
  3170. throw new BusinessException(ErrorCode.FAILURE_CODE_5018);
  3171. }
  3172. if(data.isDirectory() && !flag){
  3173. flag = true;
  3174. targetName = data.getName();
  3175. }
  3176. }
  3177. //是否包含obj文件
  3178. boolean objFlag = false;
  3179. //是否包含mtl文件
  3180. boolean mtlFlag = false;
  3181. File[] files = null;
  3182. String dataPath = null;
  3183. if(StrUtil.isEmpty(targetName)){
  3184. files = dataFile.listFiles();
  3185. dataPath = zipPath + "data/";
  3186. }else{
  3187. files = new File(zipPath + "data/" + targetName).listFiles();
  3188. dataPath = zipPath + "data/" + targetName + File.separator;
  3189. }
  3190. for(File data : files){
  3191. if(data.isDirectory()){
  3192. throw new BusinessException(ErrorCode.FAILURE_CODE_5018);
  3193. }
  3194. if(data.getName().endsWith(".jpg") || data.getName().endsWith(".png")){
  3195. if(!FileUtils.checkFileSizeIsLimit(data.length(), 1.5, "M")){
  3196. throw new BusinessException(ErrorCode.FAILURE_CODE_5020);
  3197. }
  3198. }
  3199. if(data.getName().endsWith(".obj")){
  3200. if(objFlag){
  3201. throw new BusinessException(ErrorCode.FAILURE_CODE_5019);
  3202. }
  3203. if(!data.getName().equals("mesh.obj")){
  3204. throw new BusinessException(ErrorCode.FAILURE_CODE_5060);
  3205. }
  3206. if(!FileUtils.checkFileSizeIsLimit(data.length(), 20, "M")){
  3207. throw new BusinessException(ErrorCode.FAILURE_CODE_5020);
  3208. }
  3209. objFlag = true;
  3210. FileUtils.copyFile(dataPath + data.getName(), filePath + "mesh.obj", true);
  3211. continue;
  3212. }
  3213. if(data.getName().endsWith(".mtl")){
  3214. mtlFlag = true;
  3215. }
  3216. FileUtils.copyFile(dataPath + data.getName(), filePath + data.getName(), true);
  3217. }
  3218. //压缩文件中必须有且仅有一个obj和mtl文件,否则抛出异常
  3219. if(!mtlFlag || !objFlag){
  3220. throw new BusinessException(ErrorCode.FAILURE_CODE_5059);
  3221. }
  3222. }
  3223. @Override
  3224. public ResultData saveJsonData(FileParamVO param) throws Exception {
  3225. String sceneNum = param.getNum();
  3226. String fileName = param.getFileName();
  3227. String jsonData = param.getJsonData();
  3228. if(StrUtil.isEmpty(sceneNum) || StrUtil.isEmpty(fileName) || StrUtil.isEmpty(jsonData)){
  3229. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  3230. }
  3231. ScenePro scenePro = baseMapper.findByNum(sceneNum);
  3232. if(scenePro == null){
  3233. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  3234. }
  3235. StringBuffer dataBuf = new StringBuffer()
  3236. .append("data").append(File.separator)
  3237. .append("data").append(scenePro.getNum())
  3238. .append(File.separator);
  3239. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  3240. FileUtils.writeFile(dataBuffer.toString() + fileName, jsonData.toString());
  3241. return ResultData.ok("scene/" + dataBuf.toString() + fileName);
  3242. }
  3243. @Override
  3244. public ResultData downloadPanoramaOrVideo(FileParamVO param) throws Exception {
  3245. String sceneNum = param.getNum();
  3246. String fileName = param.getFileName();
  3247. String planId = param.getPlanId();
  3248. String type = param.getPlanId();
  3249. if(StrUtil.isEmpty(sceneNum) || StrUtil.isEmpty(fileName) || StrUtil.isEmpty(type)|| StrUtil.isEmpty(planId)){
  3250. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  3251. }
  3252. if(fileName.contains("..") || fileName.contains("./\\") || fileName.contains(".//")
  3253. || fileName.contains(".\\\\") || fileName.contains(".\\/")){
  3254. throw new BusinessException(ErrorCode.FAILURE_CODE_3018);
  3255. }
  3256. ScenePro scenePro = baseMapper.findByNum(sceneNum);
  3257. if(scenePro == null){
  3258. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  3259. }
  3260. SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
  3261. StringBuffer imagesBuf = new StringBuffer()
  3262. .append("images").append(File.separator)
  3263. .append("images").append(scenePro.getNum())
  3264. .append(File.separator);
  3265. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  3266. String path = sceneProExt.getDataSource();
  3267. String url = "";
  3268. if("image".equals(type)){
  3269. if(!new File(path + "/caches/images/" + fileName).exists()){
  3270. throw new BusinessException(ErrorCode.FAILURE_CODE_3018);
  3271. }
  3272. //备份原始数据
  3273. if(!new File(imagesBuffer.toString() + "caches/back-" + fileName).exists()){
  3274. FileUtils.copyFile(path + "/caches/images/" + fileName, imagesBuffer.toString() + "caches/back-" + fileName, false);
  3275. }
  3276. //复制打包数据,并且改名
  3277. FileUtils.copyFile(path + "/caches/images/" + fileName, imagesBuffer.toString() + "caches/" + planId + ".jpg", true);
  3278. url = mainUrl + "scene/" + imagesBuf.toString() + "caches/" + planId + ".jpg";
  3279. }
  3280. if("video".equals(type)){
  3281. url = prefixAli + "video/video" + scenePro.getNum() + "/" + planId + ".mp4";
  3282. }
  3283. Map<String, Object> map = new HashMap<>();
  3284. map.put("fileUrl", url + "?t=" + System.currentTimeMillis());
  3285. map.put("fileName", url.substring(url.lastIndexOf("/") + 1));
  3286. return ResultData.ok(map);
  3287. }
  3288. @Override
  3289. public ResultData uploadPanoramaOrVideo(FileParamVO param, MultipartFile file) throws Exception {
  3290. String sceneNum = param.getNum();
  3291. String fileName = param.getFileName();
  3292. String planId = param.getPlanId();
  3293. if(StrUtil.isEmpty(sceneNum) || StrUtil.isEmpty(fileName) || StrUtil.isEmpty(type) || StrUtil.isEmpty(planId)){
  3294. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  3295. }
  3296. ScenePro scenePro = baseMapper.findByNum(sceneNum);
  3297. if(scenePro == null){
  3298. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  3299. }
  3300. SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
  3301. if(!fileName.endsWith(".jpg") && !fileName.endsWith(".mp4")){
  3302. throw new BusinessException(ErrorCode.FAILURE_CODE_5023);
  3303. }
  3304. StringBuffer dataBuf = new StringBuffer()
  3305. .append("data").append(File.separator)
  3306. .append("data").append(scenePro.getNum())
  3307. .append(File.separator);
  3308. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  3309. String path = sceneProExt.getDataSource();
  3310. if(path != null && !"".equals(path) && path.startsWith("http")){
  3311. path = ConstantFilePath.BUILD_MODEL_PATH + File.separator + path.split("/")[path.split("/").length - 2];
  3312. }
  3313. String target = path + "_images";
  3314. //文件上传的位置可以自定义
  3315. String filePath = "";
  3316. if("image".equals(type)){
  3317. filePath = target + File.separator + "extras/images" + File.separator + fileName;
  3318. }
  3319. if("video".equals(type)){
  3320. filePath = target + File.separator + "extras/video" + File.separator + fileName;
  3321. }
  3322. File targetFile = new File(filePath);
  3323. if(!targetFile.getParentFile().exists()){
  3324. targetFile.getParentFile().mkdirs();
  3325. }
  3326. //上传文件
  3327. file.transferTo(targetFile);
  3328. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  3329. JSONObject scenejson = new JSONObject();
  3330. if(strsceneInfos!=null) {
  3331. scenejson = JSONObject.parseObject(strsceneInfos);
  3332. }
  3333. if(type.equals("video")){
  3334. scenejson.put("buildImages", 2);
  3335. FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
  3336. }else{
  3337. scenejson.put("buildImages", 1);
  3338. FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
  3339. }
  3340. return ResultData.ok();
  3341. }
  3342. @Override
  3343. public ResultData uploadROIVideo(FileParamVO param, MultipartFile file) throws Exception {
  3344. String sceneNum = param.getNum();
  3345. String fileName = param.getFileName();
  3346. String planId = param.getPlanId();
  3347. String rect = param.getRect();
  3348. String dir = param.getDir();
  3349. String hfov = param.getHfov();
  3350. String vfov = param.getVfov();
  3351. if(StrUtil.isEmpty(sceneNum) || StrUtil.isEmpty(fileName) ||
  3352. StrUtil.isEmpty(planId) || StrUtil.isEmpty(rect)){
  3353. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  3354. }
  3355. ScenePro scenePro = baseMapper.findByNum(sceneNum);
  3356. if(scenePro == null){
  3357. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  3358. }
  3359. SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
  3360. StringBuffer dataBuf = new StringBuffer()
  3361. .append("data").append(File.separator)
  3362. .append("data").append(scenePro.getNum())
  3363. .append(File.separator);
  3364. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  3365. String path = sceneProExt.getDataSource();
  3366. if(path != null && !"".equals(path) && path.startsWith("http")){
  3367. path = ConstantFilePath.BUILD_MODEL_PATH + File.separator + path.split("/")[path.split("/").length - 2];
  3368. }
  3369. String target = path + "_roi";
  3370. FileUtils.deleteDirectory(target);
  3371. //文件上传的位置可以自定义
  3372. String filePath = target + File.separator + "extras" + File.separator + fileName;
  3373. File targetFile = new File(filePath);
  3374. if(!targetFile.getParentFile().exists()){
  3375. targetFile.getParentFile().mkdirs();
  3376. }
  3377. if(file == null){
  3378. FileUtils.copyFile(ConstantFilePath.SCENE_PATH + "video/video"+
  3379. scenePro.getNum() + File.separator + fileName, filePath, true);
  3380. }else {
  3381. //上传文件
  3382. file.transferTo(targetFile);
  3383. FileUtils.copyFile(filePath, ConstantFilePath.SCENE_PATH + "video/video"+
  3384. scenePro.getNum() + File.separator + fileName, true);
  3385. }
  3386. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  3387. JSONObject scenejson = new JSONObject();
  3388. if(strsceneInfos!=null) {
  3389. scenejson = JSONObject.parseObject(strsceneInfos);
  3390. }
  3391. JSONArray jsonArray = new JSONArray();
  3392. JSONObject jsonObject = new JSONObject();
  3393. JSONObject rectJson = JSON.parseObject(rect);
  3394. boolean noPanoId = true;
  3395. if(scenejson.containsKey("videosUser")){
  3396. jsonArray = scenejson.getJSONArray("videosUser");
  3397. for(int i = 0, len = jsonArray.size(); i < len; i++){
  3398. jsonObject = jsonArray.getJSONObject(i);
  3399. if(planId.equals(jsonObject.getString("panoId"))){
  3400. jsonObject.put("rect", rectJson);
  3401. jsonObject.put("name", fileName.substring(0, fileName.lastIndexOf(".")));
  3402. jsonObject.put("dir", JSON.parseObject(dir));
  3403. jsonObject.put("hfov", hfov);
  3404. jsonObject.put("vfov", vfov);
  3405. noPanoId = false;
  3406. break;
  3407. }
  3408. }
  3409. }
  3410. if(noPanoId){
  3411. jsonObject = new JSONObject();
  3412. jsonObject.put("name", fileName.substring(0, fileName.lastIndexOf(".")));
  3413. jsonObject.put("panoId", planId);
  3414. jsonObject.put("rect", rectJson);
  3415. jsonObject.put("dir", JSON.parseObject(dir));
  3416. jsonObject.put("hfov", hfov);
  3417. jsonObject.put("vfov", vfov);
  3418. if(!jsonArray.contains(jsonObject)){
  3419. jsonArray.add(jsonObject);
  3420. }
  3421. }
  3422. //保存rect的json数据
  3423. FileUtils.writeFile(target + File.separator + "extras" + File.separator + "video-ROI.json", jsonObject.toJSONString());
  3424. //复制原始图片
  3425. FileUtils.copyFile(path + "/caches/images/" + planId + ".jpg",
  3426. target + File.separator + "extras" + File.separator + planId + ".jpg", true);
  3427. FileUtils.copyFile(path + File.separator + "data.json", target + File.separator+"data.json", true);
  3428. FileUtils.copyFile(path + File.separator + "project.json", target + File.separator+"project.json", true);
  3429. //data.json增加extras为执行重建算法
  3430. String project = FileUtils.readFile(target + File.separator+"project.json");
  3431. if(project != null){
  3432. JSONObject projectJson = JSONObject.parseObject(project);
  3433. projectJson.put("parent", projectJson.get("uuid"));
  3434. projectJson.put("uuid", UUID.randomUUID().toString());
  3435. projectJson.put("time", System.currentTimeMillis());
  3436. FileUtils.writeFile(path + File.separator + "project.json", projectJson.toString());
  3437. }
  3438. String data = FileUtils.readFile(target + File.separator+"data.json");
  3439. if(data != null){
  3440. JSONObject dataJson = JSONObject.parseObject(data);
  3441. //V5表示不需要生成high,low文件
  3442. dataJson.put("skybox_type", "SKYBOX_V5");
  3443. dataJson.put("split_type", "SPLIT_V11");
  3444. FileUtils.writeFile(target + File.separator+"data.json", new String(dataJson.toString().getBytes(), "UTF-8"));
  3445. }
  3446. //进行计算
  3447. log.info("绿幕抠图视频:开始建模——" + scenePro.getNum());
  3448. CreateObjUtil.build3dModel2(target , "1");
  3449. //读取upload文件,检验需要上传的文件是否存在
  3450. String uploadData = FileUtils.readFile(target + File.separator + "results" +File.separator+"upload.json");
  3451. JSONObject uploadJson = null;
  3452. JSONArray array = null;
  3453. if(uploadData!=null) {
  3454. uploadJson = JSONObject.parseObject(uploadData);
  3455. array = uploadJson.getJSONArray("upload");
  3456. }
  3457. if(array == null){
  3458. throw new Exception("upload.json数据出错");
  3459. }
  3460. Map<String, String> map = new HashMap<>();
  3461. JSONObject fileJson = null;
  3462. for(int i = 0, len = array.size(); i < len; i++){
  3463. fileJson = array.getJSONObject(i);
  3464. fileName = fileJson.getString("file");
  3465. //文件不存在抛出异常
  3466. if(!new File(target + File.separator + "results" +File.separator + fileName).exists()){
  3467. throw new Exception(target + File.separator + "results" +File.separator + fileName+"文件不存在");
  3468. }
  3469. if(fileJson.getIntValue("clazz") == 19 ){
  3470. map.put(target + File.separator + "results" + File.separator+ fileName,"video/video"+
  3471. scenePro.getNum() + File.separator + fileName.replace("videos/", ""));
  3472. }
  3473. }
  3474. uploadToOssUtil.uploadMulFiles(map);
  3475. scenejson.put("videosUser", jsonArray.toJSONString());
  3476. scenejson.put("imagesVersion", scenejson.getIntValue("imagesVersion") + 1);
  3477. FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
  3478. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  3479. if(sceneProEdit != null){
  3480. SceneProEditExt sceneProEditExt = sceneProEditExtService.getByProEditId(sceneProEdit.getId());
  3481. sceneProEditExt.setVideosUser(jsonArray.toJSONString());
  3482. sceneProEditExt.setImagesVersion(sceneProEditExt.getImagesVersion() + 1);
  3483. sceneProEditExt.setUpdateTime(Calendar.getInstance().getTime());
  3484. sceneProEditExtService.updateById(sceneProEditExt);
  3485. }
  3486. return ResultData.ok();
  3487. }
  3488. @Override
  3489. public ResultData deleteROIVideo(FileParamVO param) throws Exception {
  3490. String sceneNum = param.getNum();
  3491. String fileName = param.getFileName();
  3492. String planId = param.getPlanId();
  3493. if(StrUtil.isEmpty(sceneNum) || StrUtil.isEmpty(fileName) || StrUtil.isEmpty(planId)){
  3494. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  3495. }
  3496. ScenePro scenePro = baseMapper.findByNum(sceneNum);
  3497. if(scenePro == null){
  3498. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  3499. }
  3500. StringBuffer dataBuf = new StringBuffer()
  3501. .append("data").append(File.separator)
  3502. .append("data").append(scenePro.getNum())
  3503. .append(File.separator);
  3504. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  3505. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  3506. JSONObject scenejson = new JSONObject();
  3507. if(strsceneInfos!=null) {
  3508. scenejson = JSONObject.parseObject(strsceneInfos);
  3509. }
  3510. JSONArray newArray = new JSONArray();
  3511. JSONArray jsonArray = new JSONArray();
  3512. JSONObject jsonObject = new JSONObject();
  3513. if(scenejson.containsKey("videosUser")){
  3514. jsonArray = JSON.parseArray(scenejson.getString("videosUser"));
  3515. for(int i = 0, len = jsonArray.size(); i < len; i++){
  3516. jsonObject = jsonArray.getJSONObject(i);
  3517. if(planId.equals(jsonObject.getString("panoId"))){
  3518. continue;
  3519. }
  3520. if(!newArray.contains(jsonObject)){
  3521. newArray.add(jsonObject);
  3522. }
  3523. }
  3524. }
  3525. scenejson.put("videosUser", newArray.toJSONString());
  3526. scenejson.put("imagesVersion", scenejson.getIntValue("imagesVersion") + 1);
  3527. FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
  3528. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  3529. if(sceneProEdit != null){
  3530. SceneProEditExt sceneProEditExt = sceneProEditExtService.getByProEditId(sceneProEdit.getId());
  3531. sceneProEditExt.setVideosUser(newArray.toJSONString());
  3532. sceneProEditExt.setImagesVersion(sceneProEditExt.getImagesVersion() + 1);
  3533. sceneProEditExt.setUpdateTime(Calendar.getInstance().getTime());
  3534. sceneProEditExtService.updateById(sceneProEditExt);
  3535. }
  3536. uploadToOssUtil.delete("video/video"+ scenePro.getNum() + File.separator +
  3537. fileName.substring(0, fileName.lastIndexOf(".")) + ".mp4");
  3538. uploadToOssUtil.delete("video/video"+ scenePro.getNum() + File.separator +
  3539. fileName.substring(0, fileName.lastIndexOf(".")) + ".flv");
  3540. FileUtils.deleteFile(ConstantFilePath.SCENE_PATH + "video/video"+ scenePro.getNum() + File.separator + fileName);
  3541. return ResultData.ok();
  3542. }
  3543. @Override
  3544. public ResultData uploadBgMusic(FileParamVO param, MultipartFile file) throws Exception {
  3545. String sceneNum = param.getNum();
  3546. String fileName = param.getFileName();
  3547. if(StrUtil.isEmpty(sceneNum) || StrUtil.isEmpty(fileName)){
  3548. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  3549. }
  3550. ScenePro scenePro = baseMapper.findByNum(sceneNum);
  3551. if(scenePro == null){
  3552. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  3553. }
  3554. StringBuffer dataBuf = new StringBuffer()
  3555. .append("data").append(File.separator)
  3556. .append("data").append(scenePro.getNum())
  3557. .append(File.separator);
  3558. StringBuffer imagesBuf = new StringBuffer()
  3559. .append("images").append(File.separator)
  3560. .append("images").append(scenePro.getNum())
  3561. .append(File.separator);
  3562. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  3563. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  3564. File buMusicFile = new File(imagesBuffer.toString() + fileName);
  3565. if(!buMusicFile.getParentFile().exists()){
  3566. buMusicFile.getParentFile().mkdirs();
  3567. }
  3568. //上传文件
  3569. file.transferTo(buMusicFile);
  3570. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  3571. JSONObject scenejson = new JSONObject();
  3572. if(strsceneInfos!=null) {
  3573. scenejson = JSONObject.parseObject(strsceneInfos);
  3574. }
  3575. scenejson.put("bgMusicName", fileName);
  3576. scenejson.put("uploadBgMusic", 1);
  3577. scenejson.put("version", scenejson.getIntValue("version") + 1);
  3578. FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
  3579. return ResultData.ok();
  3580. }
  3581. @Override
  3582. public ResultData deleteUploadBgMusic(FileParamVO param) throws Exception {
  3583. String sceneNum = param.getNum();
  3584. if(StrUtil.isEmpty(sceneNum)){
  3585. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  3586. }
  3587. ScenePro scenePro = baseMapper.findByNum(sceneNum);
  3588. if(scenePro == null){
  3589. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  3590. }
  3591. StringBuffer dataBuf = new StringBuffer()
  3592. .append("data").append(File.separator)
  3593. .append("data").append(scenePro.getNum())
  3594. .append(File.separator);
  3595. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  3596. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  3597. JSONObject scenejson = new JSONObject();
  3598. if(strsceneInfos!=null) {
  3599. scenejson = JSONObject.parseObject(strsceneInfos);
  3600. }
  3601. scenejson.put("bgMusicName", "");
  3602. scenejson.put("uploadBgMusic", 1);
  3603. scenejson.put("version", scenejson.getIntValue("version") + 1);
  3604. FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
  3605. return ResultData.ok();
  3606. }
  3607. @Override
  3608. public ResultData copyAndUpdateFloorJson(FileParamVO param) throws Exception{
  3609. String sceneNum = param.getNum();
  3610. String floorJsonData = param.getFloorJsonData();
  3611. if(StrUtil.isEmpty(sceneNum) ){
  3612. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  3613. }
  3614. StringBuffer dataBuf = new StringBuffer()
  3615. .append("data").append(File.separator)
  3616. .append("data").append(sceneNum)
  3617. .append(File.separator);
  3618. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  3619. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  3620. JSONObject scenejson = new JSONObject();
  3621. if(strsceneInfos!=null) {
  3622. scenejson = JSONObject.parseObject(strsceneInfos);
  3623. }
  3624. if(StrUtil.isEmpty(floorJsonData)){
  3625. ScenePro scenePro = baseMapper.findByNum(sceneNum);
  3626. if(scenePro == null){
  3627. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  3628. }
  3629. SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
  3630. FileUtils.copyFile(sceneProExt.getDataSource() + "/results/floor.json", dataBuffer.toString() + "houst_floor.json", true);
  3631. uploadToOssUtil.upload(dataBuffer.toString() + "houst_floor.json", dataBuf.toString() + "houst_floor.json");
  3632. String result = FileUtils.readFile(dataBuffer.toString() + "houst_floor.json");
  3633. return ResultData.ok((Object) result);
  3634. }
  3635. FileUtils.writeFile(dataBuffer.toString() + "houst_floor.json", floorJsonData);
  3636. uploadToOssUtil.upload(dataBuffer.toString() + "houst_floor.json", dataBuf.toString() + "houst_floor.json");
  3637. return ResultData.ok(floorJsonData);
  3638. }
  3639. @Override
  3640. public ResultData updateFloorJson(FileParamVO param) throws Exception{
  3641. String sceneNum = param.getNum();
  3642. String floorJsonData = param.getFloorJsonData();
  3643. if(StrUtil.isEmpty(sceneNum) || StrUtil.isEmpty(floorJsonData)){
  3644. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  3645. }
  3646. StringBuffer dataBuf = new StringBuffer()
  3647. .append("data").append(File.separator)
  3648. .append("data").append(sceneNum)
  3649. .append(File.separator);
  3650. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  3651. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  3652. JSONObject scenejson = new JSONObject();
  3653. if(strsceneInfos!=null) {
  3654. scenejson = JSONObject.parseObject(strsceneInfos);
  3655. }
  3656. scenejson.put("uploadFloorJson", 1);
  3657. scenejson.put("version", scenejson.getIntValue("version") + 1);
  3658. FileUtils.writeFile(dataBuffer.toString() + "floor.json", floorJsonData);
  3659. FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toJSONString());
  3660. return ResultData.ok((Object) floorJsonData);
  3661. }
  3662. @Override
  3663. public Page<SceneVO> getAppAllSceneByPage(Long cameraId, Long userId, int cameraType, int pageNum, Integer pageSize, String orderBy, Integer sceneType, List<String> sceneCodeList, String sceneName) {
  3664. Page<SceneVO> page = new Page<>(pageNum, pageSize);
  3665. List<SceneVO> list = baseMapper.getAppAllSceneByPage(page, cameraId, userId, cameraType, sceneType, sceneCodeList, sceneName, orderBy);
  3666. page.setRecords(list);
  3667. return page;
  3668. }
  3669. @Override
  3670. public Long findSceneNumByCameraId(Long cameraId) {
  3671. return this.count(new LambdaQueryWrapper<ScenePro>()
  3672. .eq(ScenePro::getCameraId, cameraId));
  3673. }
  3674. @Override
  3675. public SceneProPO findLastSceneByCameraId(Long cameraId) {
  3676. return baseMapper.findLastSceneByCameraId(cameraId);
  3677. }
  3678. @Override
  3679. public Long findTotalSpaceByCameraId(Long cameraId) {
  3680. List<ScenePro> list = this.list(new LambdaQueryWrapper<ScenePro>()
  3681. .select(ScenePro::getId)
  3682. .eq(ScenePro::getTbStatus, TbStatus.VALID.code())
  3683. .eq(ScenePro::getCameraId, cameraId)
  3684. .in(ScenePro::getSceneStatus, SceneStatus.SUCCESS.code(), SceneStatus.NO_DISPLAY.code())
  3685. .eq(ScenePro::getPayStatus, PayStatus.PAY.code()));
  3686. if(CollUtil.isEmpty(list)){
  3687. return 0l;
  3688. }
  3689. List<Long> sceneProIds = list.stream().map(scenePro -> {
  3690. return scenePro.getId();
  3691. }).collect(Collectors.toList());
  3692. List<SceneProExt> extList = sceneProExtService.list(new LambdaQueryWrapper<SceneProExt>()
  3693. .in(SceneProExt::getSceneProId, sceneProIds));
  3694. long sum = extList.parallelStream().mapToLong(ext -> ext.getSpace()).sum();
  3695. return sum;
  3696. }
  3697. @Override
  3698. public void updatePayStatusByCameraId(Integer payStatus, Long cameraId) {
  3699. this.update(new LambdaUpdateWrapper<ScenePro>()
  3700. .eq(ScenePro::getTbStatus, TbStatus.VALID.code())
  3701. .eq(ScenePro::getCameraId, cameraId)
  3702. .set(ScenePro::getPayStatus, payStatus));
  3703. }
  3704. @Override
  3705. public ResultData downloadPanoramaData(SceneEditParamVO param) throws Exception {
  3706. String sceneNum = param.getNum();
  3707. if(StrUtil.isEmpty(sceneNum)){
  3708. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  3709. }
  3710. ScenePro scenePro = findBySceneNum(sceneNum);
  3711. if(scenePro == null){
  3712. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  3713. }
  3714. SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
  3715. StringBuffer imagesBuf = new StringBuffer()
  3716. .append("images").append(File.separator)
  3717. .append("images").append(scenePro.getNum())
  3718. .append(File.separator);
  3719. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  3720. String highPath = sceneProExt.getDataSource() + "/results/high";
  3721. if(!new File(highPath).exists()){
  3722. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  3723. }
  3724. FileUtils.zipFile(imagesBuffer.toString() + sceneNum + "-high.zip", highPath);
  3725. uploadToOssUtil.upload(imagesBuffer.toString() + sceneNum + "-high.zip", imagesBuf.toString() + sceneNum + "-high.zip");
  3726. return ResultData.ok(prefixAli + imagesBuf.toString() + sceneNum + "-high.zip?t=" + System.currentTimeMillis());
  3727. }
  3728. public ResultData getSceneAndCameras(Long userId,List<String> excludeNums) {
  3729. List<SceneProPO> scenes = findByUserId(userId,excludeNums);
  3730. Map<String,Object> result = new HashMap<>(2);
  3731. if(ObjectUtils.isEmpty(scenes)){
  3732. result.put("scenes",new ArrayList<>());
  3733. result.put("cameras",new ArrayList<>());
  3734. return ResultData.ok(result);
  3735. }
  3736. List<String> ids = scenes.parallelStream().map(scene->String.valueOf(scene.getCameraId()))
  3737. .collect(Collectors.toList());
  3738. // TODO: 2021/12/29 这里需要feign接口
  3739. // List<CameraEntity> cameras = cameraService.getCamerasByIds(ids);
  3740. // result.put("scenes",scenes);
  3741. // result.put("cameras",cameras);
  3742. return ResultData.ok(result);
  3743. }
  3744. @Override
  3745. public SceneProPO findBySceneNumWithOutCheckRecStatus(String sceneNum) throws Exception {
  3746. return baseMapper.findByNumWithOutCheckRecStatus(sceneNum);
  3747. }
  3748. @Override
  3749. public Integer findFolderIdScence(Long folderId, Long userId) {
  3750. return baseMapper.findFolderIdScence(SceneProVO.builder().folderId(folderId).userId(userId).build());
  3751. }
  3752. @Override
  3753. public ResultData downloadVisionData(SceneEditParamVO param) throws Exception {
  3754. String sceneCode = param.getSceneName();
  3755. if(StrUtil.isEmpty(sceneCode)){
  3756. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  3757. }
  3758. List<ScenePro> sceneProList = this.list(
  3759. new QueryWrapper<ScenePro>()
  3760. .eq("tb_status", TbStatus.VALID.code())
  3761. .eq("scene_code",sceneCode));
  3762. if(CollUtil.isEmpty(sceneProList)){
  3763. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  3764. }
  3765. ScenePro scenePro = sceneProList.get(0);
  3766. StringBuffer dataBuf = new StringBuffer()
  3767. .append("data").append(File.separator)
  3768. .append("data").append(scenePro.getNum())
  3769. .append(File.separator);
  3770. StringBuffer imagesBuf = new StringBuffer()
  3771. .append("images").append(File.separator)
  3772. .append("images").append(scenePro.getNum())
  3773. .append(File.separator);
  3774. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  3775. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  3776. String modeldataUrl = prefixAli + imagesBuf.toString() + "vision.modeldata?t=" + System.currentTimeMillis();
  3777. if("aws".equals(type)){
  3778. modeldataUrl = ConstantUrl.PREFIX_AWS + imagesBuf.toString() + "vision.modeldata?t=" + System.currentTimeMillis();
  3779. }
  3780. FileUtils.downLoadFromUrl(modeldataUrl, "vision.modeldata", dataBuffer.toString());
  3781. File file = new File(dataBuffer.toString() + "vision.modeldata");
  3782. if(!file.exists()) {
  3783. return ResultData.error(ErrorCode.FAILURE_CODE_5012);
  3784. }
  3785. ConvertUtils.convertVisionModelDataToTxt(dataBuffer.toString() + "vision.modeldata", dataBuffer.toString() + "vision.json");
  3786. uploadToOssUtil.upload(dataBuffer.toString() + "vision.json", dataBuf.toString() + "vision.json");
  3787. return ResultData.ok(prefixAli + dataBuf.toString() + "vision.json?t=" + System.currentTimeMillis());
  3788. }
  3789. @Override
  3790. public SceneVO getInfo(String sceneNum) {
  3791. if(StrUtil.isEmpty(sceneNum)){
  3792. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  3793. }
  3794. List<ScenePro> sceneProList = this.list(
  3795. new QueryWrapper<ScenePro>()
  3796. .eq("tb_status", TbStatus.VALID.code())
  3797. .eq("scene_code",sceneNum));
  3798. if(CollUtil.isEmpty(sceneProList)){
  3799. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  3800. }
  3801. ScenePro scenePro = sceneProList.get(0);
  3802. if(scenePro == null){
  3803. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  3804. }
  3805. if(scenePro.getTbStatus().equals(TbStatus.DELETE.code())){
  3806. throw new BusinessException(ErrorCode.FAILURE_CODE_5009);
  3807. }
  3808. if(!SceneStatus.SUCCESS.code().equals(scenePro.getSceneStatus())
  3809. && !SceneStatus.NO_DISPLAY.code().equals(scenePro.getSceneStatus())){
  3810. throw new BusinessException(ErrorCode.FAILURE_CODE_5033);
  3811. }
  3812. if(scenePro.getPayStatus() != 1){
  3813. throw new BusinessException(ErrorCode.FAILURE_CODE_5034);
  3814. }
  3815. SceneVO sceneVo = new SceneVO();
  3816. SceneProEdit sceneProEdit =
  3817. sceneProEditService.getOne(
  3818. new QueryWrapper<SceneProEdit>()
  3819. .eq("rec_status", RecStatus.VALID.code())
  3820. .eq("tb_status", RecStatus.VALID.code())
  3821. .eq("pro_id", scenePro.getId()));// .findByProId(scenePro.getId());
  3822. SceneProEditExt sceneProEditExt
  3823. = sceneProEditExtService.getOne(
  3824. new QueryWrapper<SceneProEditExt>()
  3825. .eq("pro_edit_id", sceneProEdit.getId()));
  3826. BeanUtils.copyProperties(sceneProEditExt, sceneVo);
  3827. BeanUtils.copyProperties(sceneProEdit, sceneVo);
  3828. BeanUtils.copyProperties(scenePro, sceneVo);
  3829. if(StrUtil.isNotEmpty(sceneProEdit.getEntry())){
  3830. sceneVo.setEntry(JSONObject.parseObject(sceneProEdit.getEntry()).toJSONString());
  3831. }
  3832. if(StrUtil.isNotEmpty(scenePro.getGps())){
  3833. sceneVo.setGps(JSONObject.parseObject(scenePro.getGps()).toJSONString());
  3834. }
  3835. sceneVo.setCreateTime(new DateTime(scenePro.getCreateTime()).toString("yyyy-MM-dd"));
  3836. sceneVo.setCreateDate(scenePro.getCreateTime().getTime());
  3837. if(StrUtil.isEmpty(sceneProEdit.getSceneKey())){
  3838. sceneVo.setIsPublic(0);
  3839. }else {
  3840. sceneVo.setIsPublic(1);
  3841. }
  3842. //不返回场景访问密码
  3843. sceneVo.setSceneKey("");
  3844. //查询是否有随心装场景
  3845. if(sceneNum.indexOf("vr-")!=-1){
  3846. ScenePro vrScenePro= findLikeSceneNum(sceneNum);
  3847. if(Objects.nonNull(vrScenePro)){
  3848. sceneVo.setVrNum(null);
  3849. sceneVo.setVideosUser(null);
  3850. sceneVo.setBgMusicName(null);
  3851. sceneVo.setBgMusic(null);
  3852. }
  3853. }
  3854. //更新访问数量
  3855. sceneService.updateViewCount(sceneNum);
  3856. return sceneVo;
  3857. }
  3858. @Override
  3859. public ScenePro findLikeSceneNum(String sceneNum) {
  3860. return baseMapper.findLikeNum(sceneNum);
  3861. }
  3862. @Override
  3863. public ResultData rebuildReduceSpaceBySceneNum(String sceneNum) throws Exception{
  3864. ScenePro scenePro = this.findBySceneNum(sceneNum);
  3865. if(scenePro == null){
  3866. log.info("该场景不存在无法扣除容量,场景码为:" + sceneNum);
  3867. return ResultData.error(ErrorCode.FAILURE_CODE_5054);
  3868. }
  3869. if (scenePro.getSceneScheme() < 4){
  3870. log.info("该场景不属于八目相机无法扣除容量,场景码为:" + sceneNum);
  3871. return ResultData.error(ErrorCode.FAILURE_CODE_5055);
  3872. }
  3873. SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
  3874. platformGoodsClient.updateCameraDetailByCameraIdAndSpace(scenePro.getCameraId(), -sceneProExt.getSpace());
  3875. sceneProExt.setSpace(Long.parseLong("0"));
  3876. sceneProExt.setUpdateTime(Calendar.getInstance().getTime());
  3877. sceneProExtService.updateById(sceneProExt);
  3878. return ResultData.ok();
  3879. }
  3880. @Override
  3881. public void tempScenes(List<Long> lockedIds) {
  3882. if (lockedIds == null || lockedIds.size() == 0){
  3883. return;
  3884. }
  3885. for (Long id : lockedIds){
  3886. ScenePro scenePro = this.getById(id);
  3887. scenePro.setPayStatus(-2);
  3888. this.updateById(scenePro);
  3889. ScenePro sceneProEntity = this.getById(id);
  3890. try{
  3891. Map<String, Object> map = new HashMap<>();
  3892. map.put("payStatus", -2);
  3893. FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneProEntity.getNum() + "/scene.json", map);
  3894. }catch (Exception e){
  3895. e.printStackTrace();
  3896. }
  3897. }
  3898. }
  3899. @Override
  3900. public ResultData getRecordAudioFromBrowser(FileParamVO param, MultipartFile file) throws IOException {
  3901. String sceneNum = param.getNum();
  3902. if(StrUtil.isEmpty(sceneNum) || file.isEmpty() || file.getSize() <= 0){
  3903. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  3904. }
  3905. ScenePro scenePro = this.findBySceneNum(sceneNum);
  3906. if(scenePro == null){
  3907. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  3908. }
  3909. //文件上传的位置可以自定义
  3910. log.info("开始上传文件");
  3911. String path = ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+sceneNum;
  3912. File targetFile = new File(path);
  3913. if (!targetFile.exists()) {
  3914. targetFile.mkdirs();
  3915. }
  3916. String fileName = file.getOriginalFilename();
  3917. targetFile = new File(path + File.separator + fileName);
  3918. // 保存
  3919. synchronized(this){
  3920. file.transferTo(targetFile);
  3921. }
  3922. return ResultData.ok();
  3923. }
  3924. @Override
  3925. public ResultData checkVideoUrl(FileParamVO param) {
  3926. String path = param.getPath();
  3927. if(StrUtil.isEmpty(path)){
  3928. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  3929. }
  3930. if(!path.contains("qq.com") && !path.contains("youku.com") && !path.contains("iqiyi.com")){
  3931. throw new BusinessException(ErrorCode.FAILURE_CODE_5016);
  3932. }
  3933. if(path.contains("v.qq.com/txp/iframe/player.html") || path.contains("player.youku.com/embed")
  3934. || path.contains("open.iqiyi.com/developer/player_js/coopPlayerIndex.html")){
  3935. return ResultData.ok(path);
  3936. }
  3937. String html = "";
  3938. try {
  3939. URL url = new URL(path);
  3940. HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
  3941. httpConn.setConnectTimeout(60000);
  3942. httpConn.setReadTimeout(60000);
  3943. InputStreamReader input = new InputStreamReader(httpConn
  3944. .getInputStream(), "utf-8");
  3945. BufferedReader bufReader = new BufferedReader(input);
  3946. String line = "";
  3947. String vid = "";
  3948. if(path.contains("qq.com")){
  3949. while ((line = bufReader.readLine()) != null) {
  3950. // System.out.println(line);
  3951. if(line.contains("m.v.qq.com/play.html")){
  3952. System.out.println(line.substring(line.indexOf("&vid=") + 5, line.indexOf("&ptag")));
  3953. vid = line.substring(line.indexOf("&vid=") + 5, line.indexOf("&ptag"));
  3954. break;
  3955. }
  3956. }
  3957. if(!StrUtil.isEmpty(vid)){
  3958. html = "https://v.qq.com/txp/iframe/player.html?vid=" + vid;
  3959. }
  3960. }
  3961. if(path.contains("youku.com")){
  3962. vid = path.substring(path.indexOf("/id_") + "/id_".length(), path.indexOf(".html"));
  3963. html = "https://player.youku.com/embed/" + vid;
  3964. }
  3965. if(path.contains("iqiyi.com")){
  3966. String tvid = "";
  3967. while ((line = bufReader.readLine()) != null) {
  3968. if(line.contains("param['vid']")){
  3969. vid = line.substring(line.indexOf("\"") + 1, line.lastIndexOf("\""));
  3970. }
  3971. if(line.contains("param['tvid']")){
  3972. tvid = line.substring(line.indexOf("\"") + 1, line.lastIndexOf("\""));
  3973. }
  3974. }
  3975. if(!StrUtil.isEmpty(vid) && !StrUtil.isEmpty(tvid)){
  3976. html = "https://open.iqiyi.com/developer/player_js/coopPlayerIndex.html?vid=" + vid +
  3977. "&tvId=" + tvid;
  3978. }
  3979. }
  3980. }catch (Exception e){
  3981. e.printStackTrace();
  3982. }
  3983. return ResultData.ok(html);
  3984. }
  3985. public ResultData downloadTexData(String num) throws Exception {
  3986. if(StrUtil.isEmpty(num)){
  3987. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  3988. }
  3989. // ScenePro scenePro = this.findBySceneNum(num);
  3990. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  3991. if(scenePlus == null){
  3992. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  3993. }
  3994. // SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
  3995. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  3996. SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
  3997. String localImagePath = String.format(ConstantFilePath.IMAGESBUFFER_FORMAT, num);
  3998. if(!new File(localImagePath).exists()){
  3999. new File(localImagePath).mkdirs();
  4000. }
  4001. String newData = scenePlusExt.getDataSource() + "_obj2txt/extras";
  4002. String newResultData = scenePlusExt.getDataSource() + "_obj2txt/results/upload.json";
  4003. String zipName = num + "_extras.zip";
  4004. String zipPath = localImagePath + zipName;
  4005. //如果用户上传过模型,就打包上传到oss,直接返回
  4006. if(CommonStatus.YES.code().equals(sceneEditInfo.getIsUploadObj())
  4007. && new File(newData).exists()
  4008. && new File(newResultData).exists()){
  4009. //打包
  4010. ZipUtil.zip(newData, zipPath);
  4011. //上传压缩包
  4012. uploadToOssUtil.upload(zipPath, "downloads/extras/" + zipName);
  4013. String url = ossUrlPrefix + "downloads/extras/" + zipName + "?t=" + Calendar.getInstance().getTimeInMillis();
  4014. return ResultData.ok(url);
  4015. }
  4016. String buildType = scenePlusExt.getBuildType();
  4017. if("V3".equals(buildType)){
  4018. String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
  4019. //V3版本去oss下载2048模型
  4020. String meshPath = String.format(ConstantFilePath.DATABUFFER_FORMAT, num) + "mesh";
  4021. FileUtils.deleteDirectory(meshPath);
  4022. CreateObjUtil.ossUtilCp(dataViewPath + "mesh", meshPath);
  4023. log.info("meshPath="+meshPath);
  4024. if(!new File(meshPath).exists()){
  4025. throw new BusinessException(ErrorCode.FAILURE_CODE_7006);
  4026. }
  4027. log.info(new File(meshPath).listFiles().toString());
  4028. if(new File(meshPath).listFiles().length > 0){
  4029. for(File file : new File(meshPath).listFiles()){
  4030. if(file.isDirectory()){
  4031. for (File item : file.listFiles()) {
  4032. if(item.getName().endsWith(".obj") && !"output.house.obj".equals(item.getName()) &&
  4033. !"mesh.obj".equals(item.getName())){
  4034. item.delete();
  4035. }
  4036. if(item.getName().endsWith(".mtl") && !"output.house.mtl".equals(item.getName()) &&
  4037. !"mesh.mtl".equals(item.getName())){
  4038. item.delete();
  4039. }
  4040. }
  4041. continue;
  4042. }
  4043. if(file.getName().endsWith(".obj") && !"output.house.obj".equals(file.getName()) &&
  4044. !"mesh.obj".equals(file.getName())){
  4045. file.delete();
  4046. }
  4047. if(file.getName().endsWith(".mtl") && !"output.house.mtl".equals(file.getName()) &&
  4048. !"mesh.mtl".equals(file.getName())){
  4049. file.delete();
  4050. }
  4051. }
  4052. //打包
  4053. ZipUtil.zip(meshPath, zipPath);
  4054. //上传压缩包
  4055. uploadToOssUtil.upload(zipPath, "downloads/extras/" + zipName);
  4056. String url = ossUrlPrefix + "downloads/extras/" + zipName + "?t=" + Calendar.getInstance().getTimeInMillis();
  4057. // FileUtil.del(zipPath);
  4058. return ResultData.ok(url);
  4059. }
  4060. }
  4061. //V2版本在本地获取模型资源
  4062. //修改过的资源
  4063. String editData = scenePlusExt.getDataSource() + "_edit/caches/tex";
  4064. String results = scenePlusExt.getDataSource() + "_edit/results";
  4065. if (new File(editData).exists() && new File(results).exists()){
  4066. for(File file : new File(editData).listFiles()){
  4067. if(file.getName().endsWith(".obj") && !"output.house.obj".equals(file.getName()) &&
  4068. !"mesh.obj".equals(file.getName())){
  4069. file.delete();
  4070. }
  4071. if(file.getName().endsWith(".mtl") && !"output.house.mtl".equals(file.getName()) &&
  4072. !"mesh.mtl".equals(file.getName())){
  4073. file.delete();
  4074. }
  4075. }
  4076. ZipUtil.zip(editData, zipPath);
  4077. //上传压缩包
  4078. uploadToOssUtil.upload(zipPath, "downloads/extras/" + zipName);
  4079. String url = ossUrlPrefix + "downloads/extras/" + zipName + "?t=" + Calendar.getInstance().getTimeInMillis();
  4080. return ResultData.ok(url);
  4081. }
  4082. //没上传过返回源资源
  4083. String dataPath = scenePlusExt.getDataSource() + "/caches/tex";
  4084. File dataFile = new File(dataPath);
  4085. if(!dataFile.exists()){
  4086. throw new BusinessException(ErrorCode.FAILURE_CODE_3018);
  4087. }
  4088. for(File file : dataFile.listFiles()){
  4089. if(file.getName().endsWith(".obj") && !"output.house.obj".equals(file.getName()) &&
  4090. !"mesh.obj".equals(file.getName())){
  4091. file.delete();
  4092. }
  4093. if(file.getName().endsWith(".mtl") && !"output.house.mtl".equals(file.getName()) &&
  4094. !"mesh.mtl".equals(file.getName())){
  4095. file.delete();
  4096. }
  4097. }
  4098. ZipUtil.zip(dataPath, zipPath);
  4099. //上传压缩包
  4100. uploadToOssUtil.upload(zipPath, "downloads/extras/" + zipName);
  4101. String url = ossUrlPrefix + "downloads/extras/" + zipName + "?t=" + Calendar.getInstance().getTimeInMillis();
  4102. return ResultData.ok(url);
  4103. }
  4104. private void dealTour(SceneEditParamVO base, JSONObject scenejson, Map<String,String> map,
  4105. StringBuffer dataBuffer, StringBuffer imagesBuffer) throws IOException {
  4106. if(!StrUtil.isEmpty(base.getTourList())){
  4107. if(scenejson.containsKey("uploadTourList") && scenejson.getIntValue("uploadTourList") == 1){
  4108. int screencapLen = 0;
  4109. File file = new File(dataBuffer.toString() + ConstantFileName.TOURLIST_FOLDER);
  4110. String[] strs = file.list();
  4111. if(strs!=null) {
  4112. for(int i=0;i<strs.length;++i) {
  4113. if(strs[i].indexOf(ConstantFileName.SCREEN_CRP_DATAFILE)>-1)
  4114. {
  4115. ++screencapLen;
  4116. map.put(dataBuffer.toString() + ConstantFileName.TOURLIST_FOLDER+File.separator+strs[i],
  4117. "data/data"+base.getNum()+"/tour/"+strs[i]);
  4118. }
  4119. }
  4120. }
  4121. scenejson.put("screencapLen", screencapLen);
  4122. String path = imagesBuffer.toString() + ConstantFileName.TOURLIST_FOLDER;
  4123. JSONArray tourJsons = JSONArray.parseArray(base.getTourList());
  4124. for(int i=0;i<tourJsons.size();++i) {
  4125. String fileName = path + File.separator +"guide"+i+".jpg";
  4126. map.put(fileName,"images/images"+base.getNum()+"/tour/guide"+i+".jpg");
  4127. }
  4128. scenejson.put("uploadTourList", 0);
  4129. }
  4130. String tourListPath = dataBuffer.toString() + ConstantFileName.TOUR_LIST;
  4131. FileUtils.deleteFile(tourListPath);
  4132. FileUtils.writeFile(tourListPath, base.getTourList());
  4133. map.put(tourListPath, dataBuffer.toString() + ConstantFileName.TOUR_LIST);
  4134. }else{
  4135. if(scenejson.containsKey("uploadTourList") && scenejson.getIntValue("uploadTourList") == 1){
  4136. scenejson.put("uploadTourList", 0);
  4137. }
  4138. scenejson.put("screencapLen", 0);
  4139. }
  4140. }
  4141. @Override
  4142. public ResultData downloadCapture(SceneParamVO param) throws Exception {
  4143. log.info("querySceneDataSource:查询模型数据");
  4144. String num = param.getNum();
  4145. if(num==null&&num.trim().equals(""))
  4146. throw new BusinessException(ErrorCode.FAILURE_CODE_7002);
  4147. String data = null;
  4148. ScenePro scenePro= sceneProService.findBySceneNum(num);
  4149. if(scenePro == null)
  4150. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  4151. SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
  4152. data = sceneProExt.getDataSource();
  4153. CreateObjUtil.ossUtilCp(data.replace(ConstantFilePath.BUILD_MODEL_PATH, ConstantFilePath.OSS_PREFIX) + File.separator,
  4154. data + "/capture");
  4155. return ResultData.ok(data);
  4156. }
  4157. public ResultData uploadResultsData(SceneParamVO param) throws Exception{
  4158. String path = param.getPath();
  4159. String projectNum = param.getNum();
  4160. String type = param.getType();
  4161. String oldNum = param.getOldNum();
  4162. if("change".equals(type)){
  4163. ScenePro scenePro = sceneProService.findBySceneNum(projectNum);
  4164. if(scenePro != null){
  4165. sceneProService.updateStatus(projectNum, SceneStatus.wait.code());
  4166. return ResultData.ok("一键换装场景存在,不重复生成");
  4167. }
  4168. //根据旧的场景生成新的vr场景
  4169. scenePro = sceneProService.findBySceneNum(oldNum);
  4170. if(scenePro == null)
  4171. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  4172. SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
  4173. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  4174. SceneProEditExt sceneProEditExt = sceneProEditExtService.getByProEditId(sceneProEdit.getId());
  4175. scenePro.setId(null);
  4176. scenePro.setSceneType(99);
  4177. scenePro.setWebSite(scenePro.getWebSite().replace(oldNum, projectNum));
  4178. scenePro.setNum(projectNum);
  4179. scenePro.setSceneStatus(0);
  4180. scenePro.setSceneScheme(11);
  4181. scenePro.setCreateTime(new Date());
  4182. sceneProService.save(scenePro);
  4183. sceneProExt.setSceneSource(11);
  4184. sceneProExt.setSpace(new Long("0"));
  4185. sceneProExt.setId(null);
  4186. sceneProExt.setSceneProId(scenePro.getId());
  4187. sceneProExtService.save(sceneProExt);
  4188. sceneProEdit.setId(null);
  4189. sceneProEdit.setProId(scenePro.getId());
  4190. sceneProEditService.save(sceneProEdit);
  4191. sceneProEditExt.setId(null);
  4192. sceneProEditExt.setProEditId(sceneProEdit.getId());
  4193. sceneProEditExtService.save(sceneProEditExt);
  4194. SceneProPO sceneProPO = new SceneProPO();
  4195. BeanUtil.copyProperties(sceneProExt, sceneProPO);
  4196. BeanUtil.copyProperties(scenePro, sceneProPO);
  4197. JSONObject scenejson = JSONObject.parseObject(JSONObject.toJSONString(sceneProPO));
  4198. FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data/data"+projectNum+File.separator+"scene.json", scenejson.toString());
  4199. uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + oldNum + File.separator + "floorplan.png",
  4200. "images/images" + projectNum + File.separator + "floorplan.png");
  4201. path = sceneProExt.getDataSource();
  4202. }
  4203. Map<String, String> map = new HashMap<>();
  4204. if(StringUtils.isEmpty(path) || StringUtils.isEmpty(projectNum)){
  4205. return ResultData.error(ErrorCode.PARAM_REQUIRED);
  4206. }
  4207. boolean vision2 = false;
  4208. //读取upload文件,检验需要上传的文件是否存在
  4209. String uploadData = FileUtils.readFile(path + File.separator + "results" +File.separator+"upload.json");
  4210. JSONObject uploadJson = null;
  4211. JSONArray array = null;
  4212. if(uploadData!=null) {
  4213. uploadJson = JSONObject.parseObject(uploadData);
  4214. array = uploadJson.getJSONArray("upload");
  4215. }
  4216. if(array == null){
  4217. throw new Exception("upload.json数据出错");
  4218. }
  4219. JSONObject fileJson = null;
  4220. String fileName = "";
  4221. String meshfix = ""; //双模型时候会有改文件路径
  4222. for(int i = 0, len = array.size(); i < len; i++){
  4223. fileJson = array.getJSONObject(i);
  4224. fileName = fileJson.getString("file");
  4225. //文件不存在抛出异常
  4226. if(!new File(path + File.separator + "results" +File.separator + fileName).exists()){
  4227. throw new Exception(path + File.separator + "results" +File.separator + fileName+"文件不存在");
  4228. }
  4229. //判断是否有vision2.txt
  4230. if("vision2.txt".equals(fileName)){
  4231. vision2 = true;
  4232. }
  4233. //tex文件夹
  4234. if(fileJson.getIntValue("clazz") == 2 && !fileJson.containsKey("pack-file")){
  4235. if(fileName.contains("meshfix.txt")){
  4236. meshfix = fileName;
  4237. }else {
  4238. map.put(path + File.separator + "results" +File.separator+ fileName,"images/images"+
  4239. projectNum+"/"+ ConstantFileName.modelUUID+"_50k_texture_jpg_high1/"+fileName.replace("tex/", ""));
  4240. }
  4241. continue;
  4242. }
  4243. //high文件夹
  4244. if(fileJson.getIntValue("clazz") == 3){
  4245. map.put(path + File.separator + "results" +File.separator+ fileName,"images/images"+
  4246. projectNum+"/pan/high/"+ fileName.replace("high/", ""));
  4247. continue;
  4248. }
  4249. //low文件夹
  4250. if(fileJson.getIntValue("clazz") == 4){
  4251. map.put(path + File.separator + "results" +File.separator+ fileName,"images/images"+
  4252. projectNum+"/pan/low/"+ fileName.replace("low/", ""));
  4253. continue;
  4254. }
  4255. //tiles文件夹
  4256. if(fileJson.getIntValue("clazz") == 5 ){
  4257. map.put(path + File.separator + "results" + File.separator+ fileName,"images/images"+
  4258. projectNum+ File.separator + fileName);
  4259. continue;
  4260. }
  4261. //updown文件复制一份到ecs中并去掉换行符
  4262. if(fileJson.getIntValue("clazz") == 10){
  4263. String updown = FileUtils.readFile(path + File.separator + "results" +File.separator+ fileName);
  4264. JSONObject updownJson = JSONObject.parseObject(updown);
  4265. FileUtils.writeFile(ConstantFilePath.SCENE_PATH + "data" + File.separator + "data" + projectNum +
  4266. File.separator + fileName.replace("updown", "mapping"), updownJson.toString());
  4267. continue;
  4268. }
  4269. //video视频文件或封面图
  4270. if(fileJson.getIntValue("clazz") == 11 || fileJson.getIntValue("clazz") == 12){
  4271. map.put(path + File.separator + "results" + File.separator+ fileName,"video/video"+
  4272. projectNum+ File.separator + fileName.replace("videos/", ""));
  4273. }
  4274. //2048的模型和贴图
  4275. if(fileJson.getIntValue("clazz") == 16){
  4276. map.put(path + File.separator + "results" + File.separator+ fileName,"data/data"+
  4277. projectNum+ File.separator + fileName);
  4278. }
  4279. }
  4280. CreateObjUtil.convertTxtToDam( path + File.separator + "results" + File.separator+"tex"+File.separator+"modeldata.txt", path + File.separator + "results" +File.separator+ ConstantFileName.modelUUID+"_50k.dam");
  4281. CreateObjUtil.convertDamToLzma(path + File.separator + "results");
  4282. CreateObjUtil.convertTxtToDam( path + File.separator + "results" +File.separator+"tex"+File.separator+"modeldata.txt", path + File.separator + "results" + File.separator+ConstantFileName.modelUUID+"_50k.dam");
  4283. //有meshfix,表示双模型
  4284. if(!"".equals(meshfix)){
  4285. CreateObjUtil.convertTxtToDam( path + File.separator + "results" + File.separator+meshfix, path + File.separator + "results" +File.separator+ ConstantFileName.modelUUID+"_50k2.dam");
  4286. CreateObjUtil.convertDamToLzma2(path + File.separator + "results");
  4287. CreateObjUtil.convertTxtToDam( path + File.separator + "results" +File.separator+meshfix, path + File.separator + "results" + File.separator+ConstantFileName.modelUUID+"_50k2.dam");
  4288. map.put(path + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k2.dam.lzma", "images/images"+projectNum+"/"+ConstantFileName.modelUUID+"_50k2.dam.lzma");
  4289. map.put(path + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k2.dam", "images/images"+projectNum+"/"+ConstantFileName.modelUUID+"_50k2.dam");
  4290. }
  4291. CreateObjUtil.convertTxtToVisionmodeldata(path + File.separator + "results" +File.separator+"vision.txt",path + File.separator + "results" +File.separator+"vision.modeldata");
  4292. //8目相机有两个vision.txt因此第二个叫vision2.txt
  4293. if(vision2){
  4294. CreateObjUtil.convertTxtToVisionmodeldata(path + File.separator + "results" +File.separator+"vision2.txt",path + File.separator + "results" +File.separator+"vision2.modeldata");
  4295. map.put(path + File.separator + "results" +File.separator+"vision2.modeldata", "images/images"+projectNum+"/"+"vision2.modeldata");
  4296. }
  4297. log.info("数据转换完成:"+projectNum);
  4298. File file = new File(path + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k.dam.lzma");
  4299. while(!file.exists())
  4300. {
  4301. Thread.sleep(60000);
  4302. }
  4303. map.put(path + File.separator + "results" +File.separator+"vision.modeldata", "images/images"+projectNum+"/"+"vision.modeldata");
  4304. map.put(path + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k.dam.lzma", "images/images"+projectNum+"/"+ConstantFileName.modelUUID+"_50k.dam.lzma");
  4305. map.put(path + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k.dam", "images/images"+projectNum+"/"+ConstantFileName.modelUUID+"_50k.dam");
  4306. file = new File(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+projectNum);
  4307. if(!file.exists())
  4308. {
  4309. file.mkdir();
  4310. }
  4311. FileUtils.copyFile(path + File.separator + "results" +File.separator+"floor.json", ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+projectNum+File.separator+"floor.json", true);
  4312. log.info("floor.json路径:"+ path + File.separator + "results" +File.separator+"floor.json");
  4313. map.put(path + File.separator + "results" +File.separator+"floor.json","data/data"+projectNum+"/floor.json");
  4314. log.info("准备上传文件到oss:"+projectNum);
  4315. uploadToOssUtil.uploadMulFiles(map);
  4316. return ResultData.ok("上传完成");
  4317. }
  4318. @Override
  4319. public ResultData updateStatusByScene(SceneParamVO param) throws Exception{
  4320. String sceneNum = param.getNum();
  4321. Integer status = param.getStatus();
  4322. if(StrUtil.isEmpty(sceneNum)){
  4323. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  4324. }
  4325. ScenePro scenePro = sceneProService.findBySceneNum(sceneNum);
  4326. if(scenePro != null){
  4327. scenePro.setSceneStatus(status);
  4328. sceneProService.updateById(scenePro);
  4329. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  4330. SceneProEditExt sceneProEditExt = sceneProEditExtService.getByProEditId(sceneProEdit.getId());
  4331. sceneProEdit.setVersion(sceneProEdit.getVersion() + 1);
  4332. sceneProEdit.setFloorEditVer(sceneProEdit.getFloorEditVer() + 1);
  4333. sceneProEdit.setFloorPublishVer(sceneProEdit.getFloorPublishVer() + 1);
  4334. sceneProEditService.updateById(sceneProEdit);
  4335. sceneProEditExt.setImagesVersion(sceneProEditExt.getImagesVersion() + 1);
  4336. sceneProEditExt.setVideosUser(null);
  4337. sceneProEditExtService.updateById(sceneProEditExt);
  4338. }
  4339. return ResultData.ok();
  4340. }
  4341. @Override
  4342. public ResultData getStatusByScene(SceneParamVO param) throws Exception{
  4343. String sceneNum = param.getNum();
  4344. if(StrUtil.isEmpty(sceneNum)){
  4345. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  4346. }
  4347. ScenePro scenePro = sceneProService.findBySceneNum(sceneNum);
  4348. if(scenePro != null){
  4349. return ResultData.ok(scenePro.getSceneStatus() == -2? 1 : scenePro.getSceneStatus());
  4350. }
  4351. return ResultData.ok();
  4352. }
  4353. @Override
  4354. public ResultData checkDownLoad(String sceneNum) {
  4355. if(StringUtils.isEmpty(sceneNum)){
  4356. throw new BusinessException(ErrorCode.MISSING_REQUIRED_PARAMETERS);
  4357. }
  4358. ScenePro scenePro = sceneProService.findBySceneNum(sceneNum);
  4359. if(scenePro == null ){
  4360. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  4361. }
  4362. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  4363. if(sceneProEdit == null){
  4364. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  4365. }
  4366. //downloadStatus,1打包资源下载,2已下载过,3下载过,并且没有修改过,无需打包直接返回下载地址,-1没下载次数不足
  4367. SceneDownloadLog sceneDownloadLogEntity = sceneDownloadLogService.findByStatusAndNum(sceneNum, 0);
  4368. Map<String, Object> result = new HashMap<>();
  4369. if(sceneDownloadLogEntity != null){
  4370. result.put("downloadStatus", 1);
  4371. return ResultData.ok(result);
  4372. }
  4373. sceneDownloadLogEntity = sceneDownloadLogService.findByStatusAndNum(sceneNum, 1);
  4374. //3下载过,并且没有修改过
  4375. if(sceneDownloadLogEntity != null && sceneDownloadLogEntity.getSceneVersion().intValue() ==
  4376. sceneProEdit.getVersion()){
  4377. result.put("downloadStatus", 3);
  4378. result.put("downloadUrl", sceneDownloadLogEntity.getDownloadUrl());
  4379. return ResultData.ok(result);
  4380. }
  4381. //下载过
  4382. if(sceneDownloadLogEntity != null){
  4383. result.put("downloadStatus", 2);
  4384. // 清除旧的下载信息
  4385. redisUtil.del(RedisKey.PREFIX_DOWNLOAD_PROGRESS_V4.concat(sceneNum));
  4386. return ResultData.ok(result);
  4387. }
  4388. //未下载过
  4389. result.put("downloadStatus", 0);
  4390. return ResultData.ok(result);
  4391. }
  4392. @Override
  4393. public List<SceneProPO> findByCameraIds(String cameraIds, String startTime, String endTime) {
  4394. return this.baseMapper.findByCameraIds(cameraIds, startTime, endTime);
  4395. }
  4396. @Override
  4397. public ResultData getScenesBySnCode(String snCode, String token) {
  4398. if(StringUtils.isEmpty(token)){
  4399. throw new BusinessException(3004, "无token参数");
  4400. }
  4401. SSOUser ssoUser = ssoLoginHelper.loginCheck(token);
  4402. if(ssoUser == null){
  4403. throw new BusinessException(3004, "token参数不正确");
  4404. }
  4405. if(StringUtil.isEmpty(snCode)){
  4406. throw new BusinessException(ErrorCode.MISSING_REQUIRED_PARAMETERS);
  4407. }
  4408. Camera cameraEntity = platformGoodsClient.getCameraBySnCode(snCode).getData();
  4409. if(cameraEntity == null ){
  4410. throw new BusinessException(CameraConstant.FAILURE_6018);
  4411. }
  4412. CameraDetail cameraDetailEntity = platformGoodsClient.getCameraDetailByCameraId(cameraEntity.getId()).getData();
  4413. if(cameraDetailEntity == null ){
  4414. throw new BusinessException(CameraConstant.FAILURE_6018);
  4415. }
  4416. if(!cameraDetailEntity.getUserId().equals(ssoUser.getId())){
  4417. return ResultData.ok();
  4418. }
  4419. if(cameraDetailEntity.getCameraType() == 10 ){ //激光场景
  4420. List<SceneBySnCodeVo> scenesBySnCode = fdkkLaserService.getScenesBySnCode(snCode, token);
  4421. return ResultData.ok(scenesBySnCode);
  4422. }
  4423. List<SceneBySnCodeVo> sceneVo = sceneProMapper.getNumAndNameByCameraId(cameraEntity.getId(), ssoUser.getId());
  4424. return ResultData.ok(sceneVo);
  4425. }
  4426. }