SceneProServiceImpl.java 236 KB

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