SceneProServiceImpl.java 203 KB

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