SceneProServiceImpl.java 237 KB

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