SceneProServiceImpl.java 185 KB

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