SceneProServiceImpl.java 225 KB

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