SceneProServiceImpl.java 232 KB

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