SceneProServiceImpl.java 185 KB

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