SceneProServiceImpl.java 206 KB

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