SceneProServiceImpl.java 184 KB

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