SceneProServiceImpl.java 225 KB

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