SceneProServiceImpl.java 202 KB

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