SceneProServiceImpl.java 229 KB

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