SceneProServiceImpl.java 232 KB

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