SceneProServiceImpl.java 230 KB

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