SceneProServiceImpl.java 237 KB

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