SceneProServiceImpl.java 241 KB

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