SceneProServiceImpl.java 232 KB

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