SceneProServiceImpl.java 203 KB

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