SceneProServiceImpl.java 131 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778
  1. package com.fdkankan.scene.service.impl;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.util.StrUtil;
  4. import com.alibaba.fastjson.JSON;
  5. import com.alibaba.fastjson.JSONArray;
  6. import com.alibaba.fastjson.JSONObject;
  7. import com.alibaba.fastjson.serializer.SerializerFeature;
  8. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  9. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  10. import com.fdkankan.image.MatrixToImageWriterUtil;
  11. import com.fdkankan.model.constants.ConstantFileName;
  12. import com.fdkankan.model.constants.ConstantFilePath;
  13. import com.fdkankan.common.constant.ConstantUrl;
  14. import com.fdkankan.common.constant.ErrorCode;
  15. import com.fdkankan.common.constant.RecStatus;
  16. import com.fdkankan.common.exception.BusinessException;
  17. import com.fdkankan.common.response.ResultData;
  18. import com.fdkankan.model.utils.ConvertUtils;
  19. import com.fdkankan.model.utils.CreateObjUtil;
  20. import com.fdkankan.common.util.FileUtils;
  21. import com.fdkankan.common.util.OkHttpUtils;
  22. import com.fdkankan.fyun.constant.FYunTypeEnum;
  23. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  24. import com.fdkankan.redis.constant.RedisKey;
  25. import com.fdkankan.redis.util.RedisUtil;
  26. import com.fdkankan.scene.annotation.SystemServiceLog;
  27. import com.fdkankan.scene.bean.RequestSceneEdit;
  28. import com.fdkankan.scene.bean.RequestSceneProV4;
  29. import com.fdkankan.scene.bean.ResponseScene;
  30. import com.fdkankan.scene.entity.SceneCooperation;
  31. import com.fdkankan.scene.entity.ScenePro;
  32. import com.fdkankan.scene.entity.SceneProEdit;
  33. import com.fdkankan.scene.entity.SceneResource;
  34. import com.fdkankan.scene.entity.SceneResourceCooperation;
  35. import com.fdkankan.scene.mapper.ISceneProMapper;
  36. import com.fdkankan.scene.service.ISceneCooperationService;
  37. import com.fdkankan.scene.service.ISceneProEditService;
  38. import com.fdkankan.scene.service.ISceneProService;
  39. import com.fdkankan.scene.service.ISceneResourceCooperationService;
  40. import com.fdkankan.scene.service.ISceneResourceService;
  41. import com.fdkankan.scene.service.ISceneService;
  42. import com.google.common.collect.Lists;
  43. import java.io.BufferedReader;
  44. import java.io.File;
  45. import java.io.InputStreamReader;
  46. import java.net.HttpURLConnection;
  47. import java.net.URL;
  48. import java.util.Date;
  49. import java.util.HashMap;
  50. import java.util.Iterator;
  51. import java.util.List;
  52. import java.util.Map;
  53. import java.util.Objects;
  54. import java.util.Set;
  55. import java.util.UUID;
  56. import java.util.stream.Collectors;
  57. import lombok.extern.slf4j.Slf4j;
  58. import net.coobird.thumbnailator.Thumbnails;
  59. import org.joda.time.DateTime;
  60. import org.springframework.beans.BeanUtils;
  61. import org.springframework.beans.factory.annotation.Autowired;
  62. import org.springframework.beans.factory.annotation.Value;
  63. import org.springframework.stereotype.Service;
  64. import org.springframework.util.ObjectUtils;
  65. import org.springframework.util.StringUtils;
  66. import org.springframework.web.multipart.MultipartFile;
  67. /**
  68. * <p>
  69. * pro场景表 服务实现类
  70. * </p>
  71. *
  72. * @author
  73. * @since 2022-07-04
  74. */
  75. @Slf4j
  76. @Service
  77. public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro> implements ISceneProService {
  78. @Autowired
  79. private ISceneCooperationService sceneCooperationService;
  80. @Autowired
  81. private RedisUtil redisUtil;
  82. @Autowired
  83. private ISceneResourceCooperationService sceneResourceCooperationService;
  84. @Autowired
  85. private ISceneResourceService sceneResourceService;
  86. @Autowired
  87. private ISceneProEditService sceneProEditService;
  88. @Autowired
  89. private FYunFileServiceInterface fYunFileService;
  90. @Autowired
  91. private ISceneService sceneService;
  92. @Value("${main.url}")
  93. private String mainUrl;
  94. @Value("${scene.pro.url}")
  95. private String sceneProUrl;
  96. @Value("${scene.pro.new.url}")
  97. private String sceneProNewUrl;
  98. @Value("${hot.domain.list}")
  99. private String hotDomainList;
  100. @Value("${hot.delete}")
  101. private String hotDelete;
  102. @Value("${fyun.host}")
  103. private String ossPrefixUrl;
  104. @Value("fyun.type")
  105. private String ossType;
  106. @Override
  107. public ResultData upgradeToV4ResultSync(RequestSceneProV4 param) throws Exception {
  108. ScenePro scenePro = this.getById(param.getId());
  109. scenePro.setWebSite(param.getWebSite());
  110. scenePro.setIsUpgrade(1);
  111. this.updateById(scenePro);
  112. String num = scenePro.getNum();
  113. //如果场景有协作者,默认勾选上v4所有菜单
  114. SceneCooperation SceneCooperation = sceneCooperationService.getByNum(num);
  115. if(Objects.nonNull(SceneCooperation)){
  116. redisUtil.hset(RedisKey.SCENE_COOPERATION_NUM_USERID, num, SceneCooperation.getUserId() + "");
  117. //判断是否已经有了v4的菜单,如果已经有了,证明已经迁移过,不需要再初始化菜单资源
  118. List<SceneResourceCooperation> sceneResourceCooperationList = sceneResourceCooperationService.list(
  119. new LambdaQueryWrapper<SceneResourceCooperation>()
  120. .eq(SceneResourceCooperation::getSceneCooperationId, SceneCooperation.getId()));
  121. if(CollUtil.isNotEmpty(sceneResourceCooperationList)){
  122. List<Long> sceneSourceList = sceneResourceCooperationList.stream()
  123. .map(item -> item.getSceneResourceId()).collect(Collectors.toList());
  124. List<SceneResource> sceneResourceList
  125. = sceneResourceService.list(
  126. new LambdaQueryWrapper<SceneResource>()
  127. .eq(SceneResource::getVersion, "v4")
  128. .in(SceneResource::getId, sceneSourceList));
  129. if(CollUtil.isEmpty(sceneResourceList)){//如果查出来的这个场景的v4资源是空的,证明是第一次升级,需要初始化菜单资源
  130. sceneResourceList = sceneResourceService.list(
  131. new LambdaQueryWrapper<SceneResource>()
  132. .eq(SceneResource::getVersion, "v4"));// 查出所有的v4菜单,给这个场景的协作者初始化所有v4菜单资源
  133. if(CollUtil.isNotEmpty(sceneResourceList)){
  134. List<SceneResourceCooperation> list = Lists.newArrayList();
  135. SceneResourceCooperation sceneResourceCooperation = null;
  136. for (SceneResource sceneResource : sceneResourceList) {
  137. sceneResourceCooperation = new SceneResourceCooperation();
  138. sceneResourceCooperation.setSceneResourceId(sceneResource.getId());
  139. sceneResourceCooperation.setSceneCooperationId(SceneCooperation.getId());
  140. sceneResourceCooperation.setCreateTime(new Date());
  141. sceneResourceCooperation.setUpdateTime(new Date());
  142. sceneResourceCooperation.setRecStatus(RecStatus.VALID.code());
  143. list.add(sceneResourceCooperation);
  144. }
  145. sceneResourceCooperationService.saveBatch(list);
  146. }
  147. }
  148. }
  149. }
  150. return ResultData.ok();
  151. }
  152. @Override
  153. public ScenePro findBySceneNum(String num) {
  154. return this.getOne(new LambdaQueryWrapper<ScenePro>().eq(ScenePro::getNum, num));
  155. }
  156. @Override
  157. public ResultData uploadLogoBottomStatus(String sceneNum, String status) throws Exception {
  158. ScenePro sceneProEntity = this.findBySceneNum(sceneNum);
  159. if(sceneProEntity == null){
  160. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  161. }
  162. SceneProEdit sceneProEditEntity = sceneProEditService.findBySceneProId(sceneProEntity.getId());
  163. if(sceneProEditEntity == null){
  164. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  165. }
  166. StringBuffer dataBuf = new StringBuffer()
  167. .append("data").append(File.separator)
  168. .append("data").append(sceneProEntity.getNum())
  169. .append(File.separator);
  170. StringBuffer imagesBuf = new StringBuffer()
  171. .append("images").append(File.separator)
  172. .append("images").append(sceneProEntity.getNum())
  173. .append(File.separator);
  174. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  175. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  176. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  177. JSONObject scenejson = new JSONObject();
  178. if(strsceneInfos!=null) {
  179. scenejson = JSONObject.parseObject(strsceneInfos);
  180. }
  181. scenejson.put("showLogoBottom", Integer.valueOf(status));
  182. scenejson.put("version", scenejson.getIntValue("version") + 1);
  183. FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
  184. sceneProEditEntity.setVersion(scenejson.getIntValue("version") + 1);
  185. sceneProEditEntity.setShowLogoBottom(Integer.valueOf(status));
  186. sceneProEditService.updateById(sceneProEditEntity);
  187. return ResultData.ok();
  188. }
  189. @Override
  190. public ResultData downloadTexData(String sceneNum) throws Exception {
  191. ScenePro sceneProEntity = this.findBySceneNum(sceneNum);
  192. if(sceneProEntity == null){
  193. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  194. }
  195. if(!new File(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum).exists()){
  196. new File(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum).mkdirs();
  197. }
  198. //上传过的资源
  199. StringBuffer dataBuf = new StringBuffer()
  200. .append("data").append(File.separator)
  201. .append("data").append(sceneProEntity.getNum())
  202. .append(File.separator);
  203. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  204. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  205. JSONObject scenejson = new JSONObject();
  206. if(strsceneInfos!=null) {
  207. scenejson = JSONObject.parseObject(strsceneInfos);
  208. }
  209. String newData = sceneProEntity.getDataSource() + "_obj2txt/extras";
  210. String newResultData = sceneProEntity.getDataSource() + "_obj2txt/results/upload.json";
  211. if(scenejson.containsKey("isUploadObj") && new File(newData).exists() && new File(newResultData).exists()){
  212. FileUtils.zipFile(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/" + sceneNum + ".zip", newData);
  213. return ResultData.ok(mainUrl + "/scene/images/images" + sceneNum + "/" + sceneNum + ".zip?t=" +System.currentTimeMillis());
  214. }
  215. String buildType = sceneProEntity.getBuildType();
  216. if("V3".equals(buildType)){
  217. //V3版本去oss下载2048模型
  218. String meshPath = ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + "/mesh";
  219. FileUtils.deleteDirectory(meshPath);
  220. CreateObjUtil.ossUtilCp("data/data" + sceneNum + "/mesh", meshPath);
  221. if(new File(meshPath.concat("/mesh")).listFiles().length > 0){
  222. for(File file : new File(meshPath.concat("/mesh")).listFiles()){
  223. if(file.getName().endsWith(".obj") && !"output.house.obj".equals(file.getName()) &&
  224. !"mesh.obj".equals(file.getName())){
  225. file.delete();
  226. }
  227. if(file.getName().endsWith(".mtl") && !"output.house.mtl".equals(file.getName()) &&
  228. !"mesh.mtl".equals(file.getName())){
  229. file.delete();
  230. }
  231. }
  232. FileUtils.zipFile(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/" + sceneNum + ".zip", meshPath);
  233. return ResultData.ok(mainUrl + "/scene/images/images" + sceneNum + "/" + sceneNum + ".zip?t=" +System.currentTimeMillis());
  234. }
  235. }
  236. //V2版本在本地获取模型资源
  237. //修改过的资源
  238. String editData = sceneProEntity.getDataSource() + "_edit/caches/tex";
  239. String resultData = sceneProEntity.getDataSource() + "_edit/results";
  240. if (new File(editData).exists() && new File(resultData).exists()){
  241. for(File file : new File(editData).listFiles()){
  242. if(file.getName().endsWith(".obj") && !"output.house.obj".equals(file.getName()) &&
  243. !"mesh.obj".equals(file.getName())){
  244. file.delete();
  245. }
  246. if(file.getName().endsWith(".mtl") && !"output.house.mtl".equals(file.getName()) &&
  247. !"mesh.mtl".equals(file.getName())){
  248. file.delete();
  249. }
  250. }
  251. FileUtils.zipFile(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/" + sceneNum + ".zip", editData);
  252. return ResultData.ok(mainUrl + "/scene/images/images" + sceneNum + "/" + sceneNum + ".zip?t=" +System.currentTimeMillis());
  253. }
  254. //没上传过返回源资源
  255. String dataPath = sceneProEntity.getDataSource() + "/caches/tex";
  256. File dataFile = new File(dataPath);
  257. if(!dataFile.exists()){
  258. throw new BusinessException(ErrorCode.FAILURE_CODE_3018);
  259. }
  260. for(File file : dataFile.listFiles()){
  261. if(file.getName().endsWith(".obj") && !"output.house.obj".equals(file.getName()) &&
  262. !"mesh.obj".equals(file.getName())){
  263. file.delete();
  264. }
  265. if(file.getName().endsWith(".mtl") && !"output.house.mtl".equals(file.getName()) &&
  266. !"mesh.mtl".equals(file.getName())){
  267. file.delete();
  268. }
  269. }
  270. FileUtils.zipFile(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/" + sceneNum + ".zip", dataPath);
  271. return ResultData.ok(mainUrl + "/scene/images/images" + sceneNum + "/" + sceneNum + ".zip?t=" +System.currentTimeMillis());
  272. }
  273. @Override
  274. public ResultData uploadPic(String sceneNum, String folderName, MultipartFile file, String toOss) throws Exception{
  275. ScenePro sceneProEntity = this.findBySceneNum(sceneNum);
  276. if(sceneProEntity == null){
  277. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  278. }
  279. if (file.isEmpty() && file.getSize() <= 0) {
  280. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  281. }
  282. //文件上传的位置可以自定义
  283. String path = ConstantFilePath.SCENE_PATH+"images"+File.separator+"images"+sceneNum;
  284. if(StrUtil.isNotEmpty(folderName)) {
  285. path = path + File.separator + folderName;
  286. }
  287. File targetFile = new File(path);
  288. if (!targetFile.exists()) {
  289. targetFile.mkdirs();
  290. }
  291. String fileName = file.getOriginalFilename();
  292. targetFile = new File(path + File.separator + fileName);
  293. // 保存
  294. synchronized(this)
  295. {
  296. if(targetFile.exists())
  297. {
  298. FileUtils.deleteFile(path + File.separator + fileName);
  299. }
  300. file.transferTo(targetFile);
  301. }
  302. if(toOss != null && "1".equals(toOss)){
  303. fYunFileService.uploadFile(path + File.separator + fileName, "images"+File.separator+"images"+sceneNum + File.separator + fileName);
  304. }
  305. return ResultData.ok(targetFile.getName());
  306. }
  307. @Override
  308. public ResultData uploadShareLogo(String sceneNum, MultipartFile file) throws Exception {
  309. ScenePro sceneProEntity = findBySceneNum(sceneNum);
  310. if (sceneProEntity == null ) {
  311. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  312. }
  313. StringBuffer dataBuf = new StringBuffer()
  314. .append("data").append(File.separator)
  315. .append("data").append(sceneProEntity.getNum())
  316. .append(File.separator);
  317. StringBuffer imagesBuf = new StringBuffer()
  318. .append("images").append(File.separator)
  319. .append("images").append(sceneProEntity.getNum())
  320. .append(File.separator);
  321. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  322. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  323. String fileName = "";
  324. if (!file.isEmpty()&&file.getSize() > 0) {
  325. //文件上传的位置可以自定义
  326. System.out.println("上传分享的logo");
  327. String path = imagesBuffer.toString();
  328. File targetFile = new File(path);
  329. if (!targetFile.exists()) {
  330. targetFile.mkdirs();
  331. }
  332. fileName = file.getOriginalFilename();
  333. targetFile = new File(path + fileName);
  334. int count = 1;
  335. // 保存
  336. synchronized(this)
  337. {
  338. file.transferTo(targetFile);
  339. }
  340. SceneProEdit sceneProEditEntity = sceneProEditService.findBySceneProId(sceneProEntity.getId());
  341. Map<String, Object> map = new HashMap<>();
  342. map.put("shareLogo", imagesBuf.toString() + fileName);
  343. map.put("version", sceneProEditEntity.getVersion()+1);
  344. FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map);
  345. sceneProEditEntity.setShareLogo(imagesBuf.toString() + fileName);
  346. sceneProEditEntity.setVersion(sceneProEditEntity.getVersion()+1);
  347. sceneProEditService.updateById(sceneProEditEntity);
  348. if("V2".equals(sceneProEntity.getBuildType())){
  349. MatrixToImageWriterUtil.createQRCode(
  350. mainUrl + sceneProUrl + sceneProEntity.getNum(),
  351. ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneProEntity.getNum()+".png",
  352. true,
  353. path + File.separator + fileName);
  354. MatrixToImageWriterUtil.createQRCode(mainUrl + sceneProUrl + sceneProEntity.getNum() + "&lang=en",
  355. ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneProEntity.getNum()+"_en.png",
  356. true,
  357. path + File.separator + fileName);
  358. }
  359. if("V3".equals(sceneProEntity.getBuildType())){
  360. MatrixToImageWriterUtil.createQRCode(mainUrl + sceneProNewUrl + sceneProEntity.getNum(),
  361. ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneProEntity.getNum()+".png",
  362. true,
  363. path + File.separator + fileName);
  364. MatrixToImageWriterUtil.createQRCode(mainUrl + sceneProNewUrl + sceneProEntity.getNum() + "&lang=en",
  365. ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneProEntity.getNum()+"_en.png",
  366. true,
  367. path + File.separator + fileName);
  368. }
  369. }
  370. return ResultData.ok(imagesBuf.toString() + fileName);
  371. }
  372. @Override
  373. @SystemServiceLog(description = "上传场景的热点媒体文件")
  374. public ResultData uploadHotMedia(String sceneNum, MultipartFile file, String sid) throws Exception {
  375. ScenePro sceneProEntity = findBySceneNum(sceneNum);
  376. if(sceneProEntity == null){
  377. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  378. }
  379. String fileName = "hot" + sid + ".mp4";
  380. if (!file.isEmpty()){
  381. String path = ConstantFilePath.SCENE_PATH + "images" + File.separator + "images" + sceneNum;
  382. File targetFile = new File(path);
  383. if (!targetFile.exists()){
  384. targetFile.mkdirs();
  385. }
  386. targetFile = new File(path + File.separator + fileName);
  387. if (targetFile.exists()){
  388. FileUtils.deleteFile(path + File.separator + fileName);
  389. }
  390. file.transferTo(targetFile);
  391. if(targetFile.exists()){
  392. FileUtils.executeCodecs(path + File.separator + fileName, path, "hot" + sid + "-cut");
  393. }
  394. }
  395. return ResultData.ok(fileName);
  396. }
  397. @Override
  398. public ResultData checkVideoUrl(String path) {
  399. if(!path.contains("qq.com") && !path.contains("youku.com") && !path.contains("iqiyi.com")){
  400. throw new BusinessException(ErrorCode.FAILURE_CODE_5016);
  401. }
  402. if(path.contains("v.qq.com/txp/iframe/player.html") || path.contains("player.youku.com/embed")
  403. || path.contains("open.iqiyi.com/developer/player_js/coopPlayerIndex.html")){
  404. return ResultData.ok(path);
  405. }
  406. String html = "";
  407. try {
  408. URL url = new URL(path);
  409. HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
  410. httpConn.setConnectTimeout(60000);
  411. httpConn.setReadTimeout(60000);
  412. InputStreamReader input = new InputStreamReader(httpConn
  413. .getInputStream(), "utf-8");
  414. BufferedReader bufReader = new BufferedReader(input);
  415. String line = "";
  416. String vid = "";
  417. if(path.contains("qq.com")){
  418. while ((line = bufReader.readLine()) != null) {
  419. // System.out.println(line);
  420. if(line.contains("m.v.qq.com/play.html")){
  421. log.info(line.substring(line.indexOf("&vid=") + 5, line.indexOf("&ptag")));
  422. vid = line.substring(line.indexOf("&vid=") + 5, line.indexOf("&ptag"));
  423. break;
  424. }
  425. }
  426. if(!org.springframework.util.StringUtils.isEmpty(vid)){
  427. html = "https://v.qq.com/txp/iframe/player.html?vid=" + vid;
  428. }
  429. }
  430. if(path.contains("youku.com")){
  431. vid = path.substring(path.indexOf("/id_") + "/id_".length(), path.indexOf(".html"));
  432. html = "https://player.youku.com/embed/" + vid;
  433. }
  434. if(path.contains("iqiyi.com")){
  435. String tvid = "";
  436. while ((line = bufReader.readLine()) != null) {
  437. if(line.contains("param['vid']")){
  438. vid = line.substring(line.indexOf("\"") + 1, line.lastIndexOf("\""));
  439. }
  440. if(line.contains("param['tvid']")){
  441. tvid = line.substring(line.indexOf("\"") + 1, line.lastIndexOf("\""));
  442. }
  443. }
  444. if(!org.springframework.util.StringUtils.isEmpty(vid) && !StringUtils.isEmpty(tvid)){
  445. html = "https://open.iqiyi.com/developer/player_js/coopPlayerIndex.html?vid=" + vid +
  446. "&tvId=" + tvid;
  447. }
  448. }
  449. }catch (Exception e){
  450. e.printStackTrace();
  451. }
  452. return ResultData.ok(html);
  453. }
  454. @Override
  455. public ResultData saveSceneInfo(RequestSceneEdit base) throws Exception{
  456. if(StrUtil.isEmpty(base.getSceneNum())){
  457. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  458. }
  459. ScenePro sceneProEntity = findBySceneNum(base.getSceneNum());
  460. if(sceneProEntity == null){
  461. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  462. }
  463. StringBuffer dataBuf = new StringBuffer()
  464. .append("data").append(File.separator)
  465. .append("data").append(sceneProEntity.getNum())
  466. .append(File.separator);
  467. StringBuffer imagesBuf = new StringBuffer()
  468. .append("images").append(File.separator)
  469. .append("images").append(sceneProEntity.getNum())
  470. .append(File.separator);
  471. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  472. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  473. int type = Integer.valueOf(base.getSceneType());
  474. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  475. JSONObject scenejson = new JSONObject();
  476. if(strsceneInfos!=null) {
  477. scenejson = JSONObject.parseObject(strsceneInfos);
  478. }
  479. //上传七牛
  480. Map<String,String> map = new HashMap<String,String>();
  481. SceneProEdit sceneProEditEntity = sceneProEditService.findBySceneProId(sceneProEntity.getId());
  482. if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getTourList())){
  483. if(scenejson.containsKey("uploadTourList") && scenejson.getIntValue("uploadTourList") == 1){
  484. int screencapLen = 0;
  485. File file = new File(dataBuffer.toString() + ConstantFileName.TOURLIST_FOLDER);
  486. String[] strs = file.list();
  487. if(strs!=null) {
  488. for(int i=0;i<strs.length;++i) {
  489. if(strs[i].indexOf(ConstantFileName.SCREEN_CRP_DATAFILE)>-1)
  490. {
  491. ++screencapLen;
  492. map.put(dataBuffer.toString() + ConstantFileName.TOURLIST_FOLDER+File.separator+strs[i],
  493. "data/data"+base.getSceneNum()+"/tour/"+strs[i]);
  494. }
  495. }
  496. }
  497. scenejson.put("screencapLen", screencapLen);
  498. // sceneProEditEntity.setScreencapLen(screencapLen);
  499. String path = imagesBuffer.toString() + ConstantFileName.TOURLIST_FOLDER;
  500. JSONArray tourJsons = JSONArray.parseArray(base.getTourList());
  501. for(int i=0;i<tourJsons.size();++i) {
  502. String fileName = path + File.separator +"guide"+i+".jpg";
  503. map.put(fileName,"images/images"+base.getSceneNum()+"/tour/guide"+i+".jpg");
  504. }
  505. scenejson.put("uploadTourList", 0);
  506. }
  507. String tourListPath = dataBuffer.toString() + ConstantFileName.TOUR_LIST;
  508. FileUtils.deleteFile(tourListPath);
  509. FileUtils.writeFile(tourListPath, base.getTourList());
  510. map.put(tourListPath, dataBuffer.toString() + ConstantFileName.TOUR_LIST);
  511. }
  512. else{
  513. if(scenejson.containsKey("uploadTourList") && scenejson.getIntValue("uploadTourList") == 1){
  514. scenejson.put("uploadTourList", 0);
  515. }
  516. scenejson.put("screencapLen", 0);
  517. // sceneProEditEntity.setScreencapLen(0);
  518. }
  519. //判断scene.json是否有uploadVoiceSrc上传普通版音频
  520. if(scenejson.containsKey("uploadVoiceSrc") && scenejson.getIntValue("uploadVoiceSrc") == 1) {
  521. String screencapVoiceFileName = "";
  522. if(scenejson.containsKey("screencapVoiceFileName")) {
  523. screencapVoiceFileName = scenejson.getString("screencapVoiceFileName");
  524. }
  525. String screencapVoiceSrc = "";
  526. if(scenejson.containsKey("screencapVoiceSrc")) {
  527. screencapVoiceSrc = scenejson.getString("screencapVoiceSrc");
  528. }
  529. if(screencapVoiceFileName.indexOf(".")>-1) {
  530. String fileName = "201810" + screencapVoiceFileName.substring(screencapVoiceFileName.lastIndexOf("."));
  531. String path = ConstantFilePath.SCENE_PATH + "voice" + File.separator+"voice"+base.getSceneNum()+File.separator+fileName;
  532. map.put(path, "voice/voice"+base.getSceneNum()+"/201810" +screencapVoiceFileName.substring(screencapVoiceFileName.lastIndexOf(".")));
  533. }
  534. sceneProEditEntity.setScreencapVoiceSrc(screencapVoiceSrc);
  535. }
  536. //判断scene.json是否有uploadVoiceSound上传专业版音频
  537. if(scenejson.containsKey("uploadVoiceSound") && scenejson.getIntValue("uploadVoiceSound") == 1){
  538. if(!org.apache.commons.lang3.StringUtils.isEmpty(scenejson.getString("screencapVoiceSound"))){
  539. map.put(ConstantFilePath.SCENE_PATH + scenejson.getString("screencapVoiceSound"), scenejson.getString("screencapVoiceSound"));
  540. }
  541. sceneProEditEntity.setScreencapVoiceSound(scenejson.getString("screencapVoiceSound"));
  542. }
  543. if(scenejson.containsKey("uploadVoiceSoundsync") && scenejson.getIntValue("uploadVoiceSoundsync") == 1){
  544. if(!org.apache.commons.lang3.StringUtils.isEmpty(scenejson.getString("screencapVoiceSoundsync"))){
  545. map.put(ConstantFilePath.SCENE_PATH + scenejson.getString("screencapVoiceSoundsync"), scenejson.getString("screencapVoiceSoundsync"));
  546. }
  547. sceneProEditEntity.setScreencapVoiceSoundsync(scenejson.getString("screencapVoiceSoundsync"));
  548. }
  549. if(base.getScreencapVoiceType() != null){
  550. scenejson.put("screencapVoiceType", base.getScreencapVoiceType());
  551. sceneProEditEntity.setScreencapVoiceType(base.getScreencapVoiceType());
  552. }
  553. if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getCapData())){
  554. FileUtils.writeFile(dataBuffer.toString() + "capData.json", new String(base.getCapData().getBytes(), "UTF-8"));
  555. scenejson.put("capData", dataBuf.toString() + "capData.json");
  556. }
  557. if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getFrameData())){
  558. FileUtils.writeFile(dataBuffer.toString() + "frameData.json", new String(base.getFrameData().getBytes(), "UTF-8"));
  559. scenejson.put("frameData", dataBuf.toString() + "frameData.json");
  560. }
  561. if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getPlayData())){
  562. FileUtils.writeFile(dataBuffer.toString() + "playData.json", new String(base.getPlayData().getBytes(), "UTF-8"));
  563. scenejson.put("playData", dataBuf.toString() + "playData.json");
  564. sceneProEditEntity.setPlayData(dataBuf.toString() + "playData.json");
  565. map.put(dataBuffer.toString() + "playData.json", dataBuf.toString() + "playData.json");
  566. }
  567. if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getScreencapThumb())){
  568. FileUtils.writeFile(dataBuffer.toString() + "screencapThumb.json", new String(base.getScreencapThumb().getBytes(), "UTF-8"));
  569. scenejson.put("screencapThumb", dataBuf.toString() + "screencapThumb.json");
  570. sceneProEditEntity.setScreencapThumb(dataBuf.toString() + "screencapThumb.json");
  571. map.put(dataBuffer.toString() + "screencapThumb.json", dataBuf.toString() + "screencapThumb.json");
  572. }
  573. if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getRecordType())){
  574. scenejson.put("recordType", base.getRecordType());
  575. }
  576. if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getMapVisi())){
  577. scenejson.put("mapVisi", Integer.parseInt(base.getMapVisi()));
  578. sceneProEditEntity.setMapVisi(Integer.parseInt(base.getMapVisi()));
  579. }
  580. if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getTourVisi())){
  581. scenejson.put("tourVisi", Integer.parseInt(base.getTourVisi()));
  582. sceneProEditEntity.setTourVisi(Integer.parseInt(base.getTourVisi()));
  583. }
  584. if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getVrVisi())){
  585. scenejson.put("vrVisi", Integer.parseInt(base.getVrVisi()));
  586. sceneProEditEntity.setVrVisi(Integer.parseInt(base.getVrVisi()));
  587. }
  588. if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getRulerVisi())){
  589. scenejson.put("rulerVisi", Integer.parseInt(base.getRulerVisi()));
  590. sceneProEditEntity.setRulerVisi(Integer.parseInt(base.getRulerVisi()));
  591. }
  592. if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getCadImgVisi())){
  593. scenejson.put("cadImgVisi", Integer.parseInt(base.getCadImgVisi()));
  594. sceneProEditEntity.setCadImgVisi(Integer.parseInt(base.getCadImgVisi()));
  595. }
  596. if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getPanoVisi())){
  597. scenejson.put("panoVisi", Integer.parseInt(base.getPanoVisi()));
  598. sceneProEditEntity.setPanoVisi(Integer.parseInt(base.getPanoVisi()));
  599. }
  600. if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getM2dVisi())){
  601. scenejson.put("m2dVisi", Integer.parseInt(base.getM2dVisi()));
  602. sceneProEditEntity.setM2dVisi(Integer.parseInt(base.getM2dVisi()));
  603. }
  604. if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getM3dVisi())){
  605. scenejson.put("m3dVisi", Integer.parseInt(base.getM3dVisi()));
  606. sceneProEditEntity.setM3dVisi(Integer.parseInt(base.getM3dVisi()));
  607. }
  608. if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getMeasureVisi())){
  609. scenejson.put("measureVisi", Integer.parseInt(base.getMeasureVisi()));
  610. sceneProEditEntity.setMeasureVisi(Integer.parseInt(base.getMeasureVisi()));
  611. }
  612. if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getFloorPlanAngle())){
  613. scenejson.put("floorPlanAngle", base.getFloorPlanAngle());
  614. sceneProEditEntity.setFloorPlanAngle(base.getFloorPlanAngle());
  615. }
  616. if(scenejson.containsKey("uploadFloorPlanPng") && scenejson.getIntValue("uploadFloorPlanPng") == 1){
  617. JSONArray floorPlanPngStr = new JSONArray();
  618. JSONArray floorPlanPng = new JSONArray();
  619. switch (sceneProEntity.getBuildType()){
  620. case "V2":
  621. floorPlanPng.add(scenejson.getString("floorPlanPng"));
  622. break;
  623. case "V3":
  624. try {
  625. floorPlanPng = scenejson.getJSONArray("floorPlanPng");
  626. } catch (Exception e) {
  627. // 旧的V3也是String
  628. floorPlanPng.add(scenejson.getString("floorPlanPng"));
  629. }
  630. break;
  631. }
  632. scenejson.put("uploadFloorPlanPng", 0);
  633. for(int i = 0, len = floorPlanPng.size(); i < len; i++){
  634. map.put(ConstantFilePath.SCENE_PATH+floorPlanPng.getString(i), floorPlanPng.getString(i));
  635. floorPlanPngStr.add(floorPlanPng.getString(i) + "?t=" + System.currentTimeMillis());
  636. }
  637. sceneProEditEntity.setFloorPlanPng(floorPlanPngStr.toJSONString());
  638. }
  639. if(scenejson.containsKey("uploadFloorJson") && scenejson.getIntValue("uploadFloorJson") == 1){
  640. map.put(dataBuffer.toString() + "floor.json", dataBuf.toString() + "floor.json");
  641. scenejson.put("uploadFloorJson", 0);
  642. }
  643. if(StrUtil.isNotEmpty(base.getEntry())) {
  644. //上传七牛
  645. map.put(imagesBuffer.toString() + "thumbBigImg.jpg", imagesBuf.toString() + "thumbBigImg.jpg");
  646. map.put(imagesBuffer.toString() + "thumbFishBigImg.jpg",imagesBuf.toString() + "thumbFishBigImg.jpg");
  647. map.put(imagesBuffer.toString() + "thumbSmallImg.jpg", imagesBuf.toString() + "thumbSmallImg.jpg");
  648. map.put(imagesBuffer.toString() + "smallPic.jpg", imagesBuf.toString() + "smallPic.jpg");
  649. sceneProEditEntity.setEntry(base.getEntry());
  650. scenejson.put("entry", base.getEntry());
  651. if(scenejson.containsKey("thumbImg"))
  652. {
  653. sceneProEditEntity.setThumbStatus(scenejson.getIntValue("thumbImg"));
  654. }
  655. if(sceneProEditEntity.getThumbStatus() == 1)
  656. {
  657. sceneProEntity.setThumb(ossPrefixUrl + imagesBuf.toString() + "thumbSmallImg.jpg");
  658. }
  659. }
  660. if(base.getHotFlag() != null && "1".equals(base.getHotFlag())) {
  661. String str = FileUtils.readFile(dataBuffer.toString() + "hot.json");
  662. JSONArray jsonhots = new JSONArray();
  663. if(str != null&&!str.trim().equals("")) {
  664. jsonhots = JSONArray.parseArray(str);
  665. }
  666. String hotsids = "";
  667. for(int i=0;i<jsonhots.size();++i) {
  668. JSONObject ele = jsonhots.getJSONObject(i);
  669. String index = ele.getString("sid");
  670. hotsids+=index+",";
  671. if(ele.containsKey("media"))
  672. {
  673. String fileType = ele.getString("media");
  674. if(fileType.contains("photo"))
  675. {
  676. map.put(imagesBuffer.toString() + "hot"+index+".jpg",
  677. imagesBuf.toString() + "hot"+index+".jpg");
  678. }
  679. if(fileType.contains("audio") || fileType.contains("voice"))
  680. {
  681. map.put(imagesBuffer.toString() + "hot"+index+".mp3",
  682. imagesBuf.toString() + "hot"+index+".mp3");
  683. }
  684. if(fileType.contains("video"))
  685. {
  686. map.put(imagesBuffer.toString() + "hot"+index+".mp4",
  687. imagesBuf.toString() + "hot"+index+".mp4");
  688. map.put(imagesBuffer.toString() + "hot"+index+"-cut.jpg",
  689. imagesBuf.toString() + "hot"+index+"-cut.jpg");
  690. }
  691. }
  692. }
  693. map.put(dataBuffer.toString() + "hot.json",dataBuf.toString() + "hot.json");
  694. sceneProEditEntity.setHotsIds(hotsids);
  695. }
  696. if(StrUtil.isNotEmpty(base.getFloorLogoType())) {
  697. sceneProEditEntity.setFloorLogo(base.getFloorLogoType());
  698. scenejson.put("floorLogo", base.getFloorLogoType());
  699. if(base.getFloorLogoType().trim().equals("1")||base.getFloorLogoType().trim().equals("user")) {
  700. map.put(imagesBuffer.toString() + "floorLogoImg.png", imagesBuf.toString() + "floorLogoImg.png");
  701. }
  702. }
  703. if(StrUtil.isNotEmpty(base.getFloorLogoSize())) {
  704. sceneProEditEntity.setFloorLogoSize(Integer.valueOf(base.getFloorLogoSize()));
  705. scenejson.put("floorLogoSize", base.getFloorLogoSize());
  706. }
  707. if(base.getBgMusic() != null) {
  708. sceneProEditEntity.setBgMusic(base.getBgMusic());
  709. scenejson.put("bgMusic", base.getBgMusic());
  710. }
  711. if(base.getSceneName() != null) {
  712. sceneProEntity.setSceneName(base.getSceneName());
  713. scenejson.put("sceneName", base.getSceneName());
  714. }
  715. if(StrUtil.isNotEmpty(base.getSceneType())) {
  716. if(sceneProEntity.getSceneType() == 99){
  717. scenejson.put("sceneType", sceneProEntity.getSceneType());
  718. }else {
  719. sceneProEntity.setSceneType(type);
  720. scenejson.put("sceneType", base.getSceneType());
  721. }
  722. }
  723. if(base.getSceneDec() != null) {
  724. sceneProEntity.setSceneDec(base.getSceneDec());
  725. scenejson.put("sceneDec", base.getSceneDec());
  726. }
  727. if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getSceneKey())) {
  728. sceneProEditEntity.setSceneKey(base.getSceneKey());
  729. sceneProEditEntity.setNeedKey(1);
  730. scenejson.put("sceneKey", base.getSceneKey());
  731. scenejson.put("needKey", 1);
  732. }else {
  733. sceneProEditEntity.setSceneKey("");
  734. sceneProEditEntity.setNeedKey(0);
  735. scenejson.put("sceneKey", "");
  736. scenejson.put("needKey", 0);
  737. }
  738. if(!scenejson.containsKey("version")) {
  739. scenejson.put("version", 0);
  740. }
  741. scenejson.put("version", scenejson.getIntValue("version")+1);
  742. map.put(dataBuffer.toString() + "scene.json", dataBuf.toString() + "scene.json");
  743. sceneProEditEntity.setCadInfo(scenejson.getString("cadInfo"));
  744. sceneProEditEntity.setVersion(scenejson.getIntValue("version"));
  745. sceneProEditService.updateById(sceneProEditEntity);
  746. //重建上传资源到oss
  747. if(sceneProEditEntity.getFloorEditVer() != sceneProEditEntity.getFloorPublishVer()){
  748. //上传过模型,只更新floor.json
  749. if(scenejson.containsKey("isUploadObj") && scenejson.getBooleanValue("isUploadObj")){
  750. map.put(dataBuffer.toString() + "floor.json", dataBuf.toString() + "floor.json");
  751. //发布重新建模场景,将floorPublishVer设为floorEditVer的值
  752. sceneProEditEntity.setFloorPublishVer(sceneProEditEntity.getFloorEditVer());
  753. scenejson.put("floorEditVer", sceneProEditEntity.getFloorEditVer());
  754. scenejson.put("floorPublishVer", sceneProEditEntity.getFloorEditVer());
  755. }else {
  756. String path = sceneProEntity.getDataSource();
  757. if(path != null && !"".equals(path) && path.startsWith("http")){
  758. path = ConstantFilePath.BUILD_MODEL_PATH + path.split("/")[path.split("/").length - 2];
  759. }
  760. path = path + "_edit";
  761. String projectNum = base.getSceneNum();
  762. //读取upload文件,检验需要上传的文件是否存在
  763. String uploadData = FileUtils.readFile(path + File.separator + "results" +File.separator+"upload.json");
  764. JSONObject uploadJson = null;
  765. JSONArray array = null;
  766. if(uploadData!=null) {
  767. uploadJson = JSONObject.parseObject(uploadData);
  768. array = uploadJson.getJSONArray("upload");
  769. }
  770. if(array != null){
  771. JSONObject fileJson = null;
  772. String fileName = "";
  773. for(int i = 0, len = array.size(); i < len; i++){
  774. fileJson = array.getJSONObject(i);
  775. fileName = fileJson.getString("file");
  776. //文件不存在抛出异常
  777. if(!new File(path + File.separator + "results" +File.separator + fileName).exists()){
  778. throw new Exception(path + File.separator + "results" +File.separator + fileName+"文件不存在");
  779. }
  780. //tex文件夹
  781. if(fileJson.getIntValue("clazz") == 2 && !fileJson.containsKey("pack-file")){
  782. map.put(path + File.separator + "results" +File.separator+ fileName,"images/images"+
  783. projectNum+"/"+ConstantFileName.modelUUID+"_50k_texture_jpg_high1/"+fileName.replace("tex/", ""));
  784. }
  785. //2048的模型和贴图
  786. if(fileJson.getIntValue("clazz") == 16){
  787. map.put(path + File.separator + "results" + File.separator+ fileName,"data/data"+
  788. projectNum+ File.separator + fileName);
  789. }
  790. }
  791. map.put(path + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k.dam.lzma", "images/images"+projectNum+"/"+ConstantFileName.modelUUID+"_50k.dam.lzma");
  792. map.put(path + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k.dam", "images/images"+projectNum+"/"+ConstantFileName.modelUUID+"_50k.dam");
  793. File file = new File(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+projectNum);
  794. if(!file.exists())
  795. {
  796. file.mkdir();
  797. }
  798. log.info("计算大场景:开始上传大场景文件到阿里——"+projectNum);
  799. //上传修改后的本地的缩略图
  800. map.put(dataBuffer.toString() + "floor.json", dataBuf.toString() + "floor.json");
  801. //发布重新建模场景,将floorPublishVer设为floorEditVer的值
  802. sceneProEditEntity.setFloorPublishVer(sceneProEditEntity.getFloorEditVer());
  803. scenejson.put("floorEditVer", sceneProEditEntity.getFloorEditVer());
  804. scenejson.put("floorPublishVer", sceneProEditEntity.getFloorEditVer());
  805. }
  806. }
  807. }
  808. //重算全景图并上传oss或oss
  809. if(scenejson.containsKey("buildImages")){
  810. String path = sceneProEntity.getDataSource();
  811. if(path != null && !"".equals(path) && path.startsWith("http")){
  812. path = ConstantFilePath.BUILD_MODEL_PATH + File.separator + path.split("/")[path.split("/").length - 2];
  813. }
  814. String target = path + "_images";
  815. File images = new File(target + File.separator + "extras/images");
  816. File video = new File(target + File.separator + "extras/video");
  817. if(scenejson.getIntValue("buildImages") == 1){
  818. log.info("下载vision.modeldata文件");
  819. if(FYunTypeEnum.AWS.code().equals(this.ossType)){
  820. FileUtils.downLoadFromUrl(ConstantUrl.PREFIX_AWS + "images/images" + sceneProEntity.getNum() + "/vision.modeldata" + "?m="+new Date().getTime(),
  821. "vision.modeldata", target + File.separator + "extras" + File.separator);
  822. }
  823. if(FYunTypeEnum.OSS.code().equals(this.ossType)){
  824. FileUtils.downLoadFromUrl(ossPrefixUrl + "images/images" + sceneProEntity.getNum() + "/vision.modeldata" + "?m="+new Date().getTime(),
  825. "vision.modeldata", target + File.separator + "extras" + File.separator);
  826. }
  827. CreateObjUtil.convertVisionmodeldataToTxt(target + File.separator + "extras" + File.separator + "vision.modeldata",
  828. target + File.separator + "extras" + File.separator + "vision.txt");
  829. if(images.exists() && images.listFiles() != null && images.listFiles().length > 0){
  830. FileUtils.copyFile(path + File.separator + "data.json", target + File.separator+"data.json", true);
  831. FileUtils.copyFile(path + File.separator + "project.json", target + File.separator+"project.json", true);
  832. //data.json增加extras为执行重建算法
  833. String data = FileUtils.readFile(target + File.separator+"data.json");
  834. if(data != null){
  835. JSONObject floorplanJson = new JSONObject();
  836. floorplanJson.put("has_source_images", true);
  837. floorplanJson.put("has_vision_txt", true);
  838. JSONObject dataJson = JSONObject.parseObject(data);
  839. dataJson.put("extras", floorplanJson);
  840. //V5表示不需要生成high,low文件
  841. dataJson.put("skybox_type", "SKYBOX_V6");
  842. if(sceneProEntity.getSceneScheme() == 11){
  843. dataJson.put("skybox_type", "SKYBOX_V7");
  844. }
  845. dataJson.put("split_type", "SPLIT_V8");
  846. //sceneScheme为3切成瓦片图
  847. if(sceneProEntity.getSceneScheme() == 3){
  848. dataJson.put("skybox_type", "SKYBOX_V4");
  849. }
  850. FileUtils.writeFile(target + File.separator+"data.json", new String(dataJson.toString().getBytes(), "UTF-8"));
  851. }
  852. //创建文件夹软连接并且复制data.json和project.json
  853. if(new File(target + File.separator + "capture").exists()){
  854. new File(target + File.separator + "capture").delete();
  855. }
  856. if(new File(target + File.separator + "results").exists()){
  857. FileUtils.delAllFile(target + File.separator + "results");
  858. }
  859. //下载data.fdage
  860. if(FYunTypeEnum.AWS.code().equals(this.ossType)){
  861. //亚马逊保持旧方式,超链接capture
  862. CreateObjUtil.createSoftConnection(path + File.separator + "capture", target + File.separator + "capture");
  863. }
  864. CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + path.replace(ConstantFilePath.BUILD_MODEL_PATH, "") + "/data.fdage", target + File.separator + "capture/");
  865. CreateObjUtil.build3dModel(target , "1");
  866. //读取upload文件,检验需要上传的文件是否存在
  867. String uploadData = FileUtils.readFile(target + File.separator + "results" +File.separator+"upload.json");
  868. JSONObject uploadJson = null;
  869. JSONArray array = null;
  870. if(uploadData!=null) {
  871. uploadJson = JSONObject.parseObject(uploadData);
  872. array = uploadJson.getJSONArray("upload");
  873. }
  874. if(array == null){
  875. throw new Exception("upload.json数据出错");
  876. }
  877. JSONObject fileJson = null;
  878. String fileName = "";
  879. for(int i = 0, len = array.size(); i < len; i++){
  880. fileJson = array.getJSONObject(i);
  881. fileName = fileJson.getString("file");
  882. //文件不存在抛出异常
  883. if(!new File(target + File.separator + "results" +File.separator + fileName).exists()){
  884. throw new Exception(target + File.separator + "results" +File.separator + fileName+"文件不存在");
  885. }
  886. //high文件夹
  887. if(fileJson.getIntValue("clazz") == 3){
  888. map.put(target + File.separator + "results" +File.separator+ fileName,"images/images"+
  889. sceneProEntity.getNum()+"/pan/high/"+ fileName.replace("high/", ""));
  890. continue;
  891. }
  892. //low文件夹
  893. if(fileJson.getIntValue("clazz") == 4){
  894. map.put(target + File.separator + "results" +File.separator+ fileName,"images/images"+
  895. sceneProEntity.getNum()+"/pan/low/"+ fileName.replace("low/", ""));
  896. continue;
  897. }
  898. //tiles文件夹,亚马逊没有裁剪图片api,不需要上传4k图
  899. if(fileJson.getIntValue("clazz") == 5){
  900. map.put(target + File.separator + "results" + File.separator+ fileName,"images/images"+
  901. sceneProEntity.getNum()+ File.separator + fileName);
  902. continue;
  903. }
  904. //tiles文件夹,亚马逊瓦片图
  905. if(fileJson.getIntValue("clazz") == 7 ){
  906. map.put(target + File.separator + "results" + File.separator+ fileName,"images/images"+
  907. sceneProEntity.getNum()+ File.separator + fileName);
  908. continue;
  909. }
  910. }
  911. for(String imagesName : images.list()){
  912. //覆盖原始图片资源
  913. FileUtils.copyFile(target + File.separator + "extras/images/" + imagesName,
  914. path + File.separator + "caches/images/" + imagesName, true);
  915. FileUtils.deleteFile(target + File.separator + "extras/images/" + imagesName);
  916. }
  917. }
  918. if(video.exists() && video.listFiles() != null && video.listFiles().length > 0){
  919. for(String videoName : video.list()){
  920. fYunFileService.uploadFile(target + File.separator + "extras/video/" + videoName,"video/video"+
  921. sceneProEntity.getNum()+ File.separator + videoName);
  922. CreateObjUtil.mp4ToFlv(target + File.separator + "extras/video/" + videoName,
  923. target + File.separator + "extras/video/" + videoName.replace("mp4", "flv"));
  924. fYunFileService.uploadFile(target + File.separator + "extras/video/" + videoName.replace("mp4", "flv"),"video/video"+
  925. sceneProEntity.getNum()+ File.separator + videoName.replace("mp4", "flv"));
  926. //覆盖原始视频资源
  927. FileUtils.copyFile(target + File.separator + "extras/video/" + videoName,
  928. path + File.separator + "caches/videos/" + videoName, true);
  929. }
  930. FileUtils.deleteDirectory(target + File.separator + "extras/video/");
  931. }
  932. // 清除马赛克数据
  933. if(scenejson.containsKey("planId")){
  934. String[] planIds = scenejson.getString("planId").split(",");
  935. String mosaicDatasTr = sceneProEntity.getMosaics();
  936. JSONArray jsonArray = new JSONArray();
  937. if(!ObjectUtils.isEmpty(mosaicDatasTr)){
  938. jsonArray = JSONArray.parseArray(mosaicDatasTr);
  939. }
  940. for (String planId : planIds) {
  941. for (Iterator<Object> iterator = jsonArray.iterator(); iterator.hasNext(); ) {
  942. JSONObject data = (JSONObject)iterator.next();
  943. if(org.apache.commons.lang3.StringUtils
  944. .equals(data.getString("panoId"),planId)){
  945. iterator.remove();
  946. }
  947. }
  948. }
  949. sceneProEntity.setMosaics(JSON.toJSONString(jsonArray, SerializerFeature.DisableCircularReferenceDetect));
  950. scenejson.remove("planId");
  951. scenejson.put("mosaics",JSON.toJSONString(jsonArray,SerializerFeature.DisableCircularReferenceDetect));
  952. }
  953. }else if(scenejson.getIntValue("buildImages") == 2){
  954. if(video.exists() && video.listFiles() != null && video.listFiles().length > 0){
  955. for(String videoName : video.list()){
  956. fYunFileService.uploadFile(target + File.separator + "extras/video/" + videoName,"video/video"+
  957. sceneProEntity.getNum()+ File.separator + videoName);
  958. CreateObjUtil.mp4ToFlv(target + File.separator + "extras/video/" + videoName,
  959. target + File.separator + "extras/video/" + videoName.replace("mp4", "flv"));
  960. fYunFileService.uploadFile(target + File.separator + "extras/video/" + videoName.replace("mp4", "flv"),"video/video"+
  961. sceneProEntity.getNum()+ File.separator + videoName.replace("mp4", "flv"));
  962. //覆盖原始视频资源
  963. FileUtils.copyFile(target + File.separator + "extras/video/" + videoName,
  964. path + File.separator + "caches/videos/" + videoName, true);
  965. }
  966. FileUtils.deleteDirectory(target + File.separator + "extras/video/");
  967. }
  968. }
  969. scenejson.put("imagesVersion", sceneProEditEntity.getImagesVersion() + 1);
  970. scenejson.put("buildImages", 0);
  971. sceneProEditEntity.setImagesVersion(sceneProEditEntity.getImagesVersion() + 1);
  972. }
  973. if(scenejson.containsKey("uploadBgMusic") && scenejson.getIntValue("uploadBgMusic") == 1){
  974. if(StrUtil.isNotEmpty(scenejson.getString("bgMusicName"))){
  975. map.put(imagesBuffer.toString() + scenejson.getString("bgMusicName"), imagesBuf.toString() + scenejson.getString("bgMusicName"));
  976. }
  977. scenejson.put("uploadBgMusic", 0);
  978. sceneProEditEntity.setBgMusicName(scenejson.getString("bgMusicName"));
  979. }
  980. if(scenejson.containsKey("uploadPanoramaImg") && scenejson.getIntValue("uploadPanoramaImg") == 1){
  981. String targetPath = ConstantFilePath.SCENE_PATH + "images/images" + base.getSceneNum() + "/panorama";
  982. File panoramafile = new File(targetPath);
  983. if(panoramafile.exists()){
  984. for(File targetFile : panoramafile.listFiles()){
  985. if(targetFile.isDirectory()){
  986. String target = targetFile.getAbsolutePath();
  987. String sid = target.substring(target.lastIndexOf(File.separator) + 1);
  988. //读取upload文件,检验需要上传的文件是否存在
  989. String uploadData = FileUtils.readFile(target + File.separator + "results" +File.separator+"upload.json");
  990. JSONObject uploadJson = null;
  991. JSONArray array = null;
  992. if(uploadData!=null) {
  993. uploadJson = JSONObject.parseObject(uploadData);
  994. array = uploadJson.getJSONArray("upload");
  995. }
  996. if(array == null){
  997. continue;
  998. }
  999. JSONObject fileJson = null;
  1000. String fileName = "";
  1001. for(int i = 0, len = array.size(); i < len; i++){
  1002. fileJson = array.getJSONObject(i);
  1003. fileName = fileJson.getString("file");
  1004. //文件不存在抛出异常
  1005. if(!new File(target + File.separator + "results" +File.separator + fileName).exists()){
  1006. throw new Exception(target + File.separator + "results" +File.separator + fileName+"文件不存在");
  1007. }
  1008. //high文件夹
  1009. if(fileJson.getIntValue("clazz") == 3){
  1010. map.put(target + File.separator + "results" +File.separator+ fileName,"images/images"+
  1011. sceneProEntity.getNum()+"/panorama/" + sid + "/pan/high/"+ fileName.replace("high/", ""));
  1012. continue;
  1013. }
  1014. //low文件夹
  1015. if(fileJson.getIntValue("clazz") == 4){
  1016. map.put(target + File.separator + "results" +File.separator+ fileName,"images/images"+
  1017. sceneProEntity.getNum()+"/panorama/" + sid + "/pan/low/"+ fileName.replace("low/", ""));
  1018. continue;
  1019. }
  1020. //tiles文件夹,亚马逊没有裁剪图片api,不需要上传4k图
  1021. if(fileJson.getIntValue("clazz") == 5){
  1022. map.put(target + File.separator + "results" + File.separator+ fileName,"images/images"+
  1023. sceneProEntity.getNum()+ "/panorama/" + sid + File.separator + fileName);
  1024. // uploadToOssUtil.delete("images/images"+ sceneProEntity.getNum()+
  1025. // "/panorama_edit/" + sid + File.separator + fileName);
  1026. continue;
  1027. }
  1028. //tiles文件夹,亚马逊瓦片图
  1029. if(fileJson.getIntValue("clazz") == 7 ){
  1030. map.put(target + File.separator + "results" + File.separator+ fileName,"images/images"+
  1031. sceneProEntity.getNum()+ File.separator + fileName);
  1032. continue;
  1033. }
  1034. }
  1035. }
  1036. }
  1037. }
  1038. scenejson.put("uploadPanoramaImg", 0);
  1039. }
  1040. if(scenejson.containsKey("uploadPanoramaJson") && scenejson.getIntValue("uploadPanoramaJson") == 1){
  1041. scenejson.put("uploadPanoramaJson", 0);
  1042. map.put(dataBuffer.toString() + "link-scene.json", dataBuf.toString() + "link-scene.json");
  1043. sceneProEditEntity.setJumpScene(scenejson.getBooleanValue("jumpScene"));
  1044. }
  1045. log.info("scene.json路径:" + dataBuffer.toString() + "scene.json");
  1046. FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
  1047. if(map.size()>0) {
  1048. fYunFileService.uploadMulFiles(map);
  1049. }
  1050. this.updateById(sceneProEntity);
  1051. sceneProEditService.updateById(sceneProEditEntity);
  1052. return ResultData.ok();
  1053. }
  1054. @Override
  1055. public ResultData uploadFloorplanPng(String sceneNum, MultipartFile[] file, String cadInfo) throws Exception{
  1056. ScenePro sceneProEntity = this.findBySceneNum(sceneNum);
  1057. if(sceneProEntity == null){
  1058. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1059. }
  1060. if (file.length <= 0) {
  1061. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  1062. }
  1063. StringBuffer dataBuf = new StringBuffer()
  1064. .append("data").append(File.separator)
  1065. .append("data").append(sceneProEntity.getNum())
  1066. .append(File.separator);
  1067. StringBuffer imagesBuf = new StringBuffer()
  1068. .append("images").append(File.separator)
  1069. .append("images").append(sceneProEntity.getNum())
  1070. .append(File.separator);
  1071. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  1072. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  1073. //文件上传的位置可以自定义
  1074. String path = ConstantFilePath.SCENE_PATH+"images"+File.separator+"images"+sceneNum;
  1075. File targetFile = new File(path);
  1076. if (!targetFile.exists()) {
  1077. targetFile.mkdirs();
  1078. }
  1079. String fileName = "";
  1080. JSONArray floorPlanPngArr = new JSONArray();
  1081. for (MultipartFile multipartFile : file) {
  1082. fileName = multipartFile.getOriginalFilename();
  1083. targetFile = new File(path + File.separator + fileName);
  1084. // 保存
  1085. synchronized(this)
  1086. {
  1087. if(targetFile.exists())
  1088. {
  1089. FileUtils.deleteFile(path + File.separator + fileName);
  1090. }
  1091. multipartFile.transferTo(targetFile);
  1092. }
  1093. floorPlanPngArr.add("images"+File.separator+"images"+sceneNum + File.separator + fileName);
  1094. }
  1095. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  1096. JSONObject scenejson = new JSONObject();
  1097. if(strsceneInfos!=null) {
  1098. scenejson = JSONObject.parseObject(strsceneInfos);
  1099. }
  1100. Map<String, Object> map = new HashMap<>();
  1101. map.put("floorPlanPng", floorPlanPngArr);
  1102. map.put("uploadFloorPlanPng", 1);
  1103. map.put("version", scenejson.getIntValue("version")+1);
  1104. if(StrUtil.isNotEmpty(cadInfo)){
  1105. map.put("cadInfo", cadInfo);
  1106. }
  1107. FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map);
  1108. return ResultData.ok(floorPlanPngArr);
  1109. }
  1110. @Override
  1111. public ResultData uploadFloorJson(RequestSceneEdit sceneEdit) throws Exception {
  1112. String lock = sceneEdit.getSceneNum().toString().intern();
  1113. synchronized(lock){
  1114. long start = System.currentTimeMillis();
  1115. log.info("画墙重建模型开始时间:" + start);
  1116. if(org.apache.commons.lang3.StringUtils.isEmpty(sceneEdit.getSceneNum())){
  1117. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  1118. }
  1119. ScenePro sceneProEntity = this.findBySceneNum(sceneEdit.getSceneNum());
  1120. if(sceneProEntity == null){
  1121. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1122. }
  1123. SceneProEdit sceneProEditEntity = sceneProEditService.findBySceneProId(sceneProEntity.getId());
  1124. if(sceneProEditEntity == null){
  1125. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1126. }
  1127. //更新scene.json文件
  1128. String strsceneInfos = FileUtils.readFile(ConstantFilePath.SCENE_PATH + "data" + File.separator + "data" + sceneEdit.getSceneNum() + File.separator + "scene.json");
  1129. JSONObject scenejson = new JSONObject();
  1130. if(strsceneInfos!=null)
  1131. {
  1132. scenejson = JSONObject.parseObject(strsceneInfos);
  1133. }else {
  1134. new File(ConstantFilePath.SCENE_PATH + "data" + File.separator + "data" + sceneEdit.getSceneNum() + File.separator + "scene.json").createNewFile();
  1135. }
  1136. if(!org.apache.commons.lang3.StringUtils.isEmpty(sceneEdit.getSceneData())){
  1137. JSONObject sceneObject = JSONObject.parseObject(sceneEdit.getSceneData());
  1138. Set<String> set =sceneObject.keySet();
  1139. for(String key : set){
  1140. scenejson.put(key, sceneObject.get(key));
  1141. }
  1142. }
  1143. //保存floor.json前端下次进入需要使用
  1144. if(org.apache.commons.lang3.StringUtils.isEmpty(sceneEdit.getWebFloor())){
  1145. sceneEdit.setWebFloor(sceneEdit.getFloor());
  1146. }
  1147. //上传过模型只更新floor.json
  1148. // if(scenejson.containsKey("isUploadObj") && scenejson.getBooleanValue("isUploadObj")){
  1149. FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+sceneEdit.getSceneNum() + File.separator + "floor.json", new String(sceneEdit.getWebFloor().getBytes(), "UTF-8"));
  1150. //更新scene.json文件
  1151. if(strsceneInfos!=null)
  1152. {
  1153. scenejson.put("floorEditVer", sceneProEditEntity.getFloorEditVer() + 1);
  1154. scenejson.put("floorPublishVer", sceneProEditEntity.getFloorPublishVer());
  1155. FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+sceneEdit.getSceneNum()+File.separator+"scene.json", scenejson.toString());
  1156. log.info("写入scene.json文件完成——"+sceneEdit.getSceneNum());
  1157. }
  1158. //floorEditVer字段增加1
  1159. sceneProEditEntity.setFloorEditVer(sceneProEditEntity.getFloorEditVer() + 1);
  1160. sceneProEditService.updateById(sceneProEditEntity);
  1161. String path = sceneProEntity.getDataSource();
  1162. if(path != null && !"".equals(path) && path.startsWith("http")){
  1163. path = ConstantFilePath.BUILD_MODEL_PATH + File.separator + path.split("/")[path.split("/").length - 2];
  1164. }
  1165. String target = path + "_edit";
  1166. File editPath = new File(target);
  1167. if(!editPath.exists()){
  1168. editPath.mkdirs();
  1169. }
  1170. //创建文件夹软连接并且复制data.json和project.json
  1171. if(new File(target + File.separator + "capture").exists()){
  1172. new File(target + File.separator + "capture").delete();
  1173. }
  1174. if(new File(target + File.separator + "caches").exists()){
  1175. //删除link
  1176. new File(target + File.separator + "caches" + File.separator + "images").delete();
  1177. //删除所有文件
  1178. FileUtils.delAllFile(target + File.separator + "caches");
  1179. }
  1180. if(new File(target + File.separator + "results").exists()){
  1181. FileUtils.delAllFile(target + File.separator + "results");
  1182. }
  1183. //创建文件夹,并link文件夹
  1184. new File(target + File.separator + "caches").mkdirs();
  1185. CreateObjUtil.createSoftConnection(path + File.separator + "capture", target + File.separator + "capture");
  1186. if(new File(path + File.separator + "caches" + File.separator + "images").exists()){
  1187. CreateObjUtil.createSoftConnection(path + File.separator + "caches" + File.separator + "images", target + File.separator + "caches" + File.separator + "images");
  1188. }
  1189. FileUtils.copyFile(path + File.separator + "data.json", target + File.separator+"data.json", true);
  1190. FileUtils.copyFile(path + File.separator + "project.json", target + File.separator+"project.json", true);
  1191. //data.json增加extras为执行重建算法
  1192. String project = FileUtils.readFile(target + File.separator+"project.json");
  1193. if(project != null){
  1194. JSONObject projectJson = JSONObject.parseObject(project);
  1195. projectJson.put("parent", projectJson.get("uuid"));
  1196. projectJson.put("uuid", UUID.randomUUID().toString());
  1197. projectJson.put("time", System.currentTimeMillis());
  1198. FileUtils.writeFile(path + File.separator + "project.json", projectJson.toString());
  1199. }
  1200. String data = FileUtils.readFile(target + File.separator+"data.json");
  1201. if(data != null){
  1202. JSONObject floorplanJson = new JSONObject();
  1203. floorplanJson.put("has_floorplan_json", true);
  1204. floorplanJson.put("has_vision_txt", true);
  1205. JSONObject dataJson = JSONObject.parseObject(data);
  1206. dataJson.put("extras", floorplanJson);
  1207. //V5表示不需要生成high,low文件
  1208. dataJson.put("skybox_type", "SKYBOX_V5");
  1209. dataJson.put("split_type", "SPLIT_V4");
  1210. FileUtils.writeFile(target + File.separator+"data.json", new String(dataJson.toString().getBytes(), "UTF-8"));
  1211. }
  1212. //文件上传的位置可以自定义
  1213. log.info("画墙重建模型开始");
  1214. File targetFile = new File(target + File.separator + "extras" + File.separator + "floorplan.json");
  1215. if(!targetFile.getParentFile().exists()){
  1216. targetFile.getParentFile().mkdirs();
  1217. }
  1218. if(targetFile.exists()){
  1219. FileUtils.deleteFile(target + File.separator + "extras" + File.separator + "floorplan.json");
  1220. }
  1221. // 保存
  1222. FileUtils.writeFile(target + File.separator + "extras" + File.separator + "floorplan.json", new String(sceneEdit.getFloor().getBytes(), "UTF-8"));
  1223. FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+sceneEdit.getSceneNum() + File.separator + "floor.json", new String(sceneEdit.getWebFloor().getBytes(), "UTF-8"));
  1224. //下载vision.modeldata,解压成vision.txt,并且删除vision.modeldata
  1225. log.info("下载vision.modeldata文件");
  1226. if(FYunTypeEnum.AWS.code().equals(ossType)){
  1227. FileUtils.downLoadFromUrl(ConstantUrl.PREFIX_AWS + "images/images" + sceneEdit.getSceneNum() + "/vision.modeldata" + "?m="+new Date().getTime(),
  1228. "vision.modeldata", target + File.separator + "extras" + File.separator);
  1229. }
  1230. if(FYunTypeEnum.OSS.code().equals(this.ossType)){
  1231. FileUtils.downLoadFromUrl(ossPrefixUrl + "images/images" + sceneEdit.getSceneNum() + "/vision.modeldata" + "?m="+new Date().getTime(),
  1232. "vision.modeldata", target + File.separator + "extras" + File.separator);
  1233. }
  1234. CreateObjUtil.convertVisionmodeldataToTxt(target + File.separator + "extras" + File.separator + "vision.modeldata",
  1235. target + File.separator + "extras" + File.separator + "vision.txt");
  1236. log.info("解压完成,删除vision.modeldata文件");
  1237. FileUtils.deleteFile(target + File.separator + "extras" + File.separator + "vision.modeldata");
  1238. log.info("下载vision2.modeldata文件");
  1239. if(FYunTypeEnum.OSS.code().equals(ossType)){
  1240. FileUtils.downLoadFromUrl(ossPrefixUrl + "images/images" + sceneEdit.getSceneNum() + "/vision2.modeldata" + "?m="+new Date().getTime(),
  1241. "vision2.modeldata", target + File.separator + "extras" + File.separator);
  1242. }
  1243. if(FYunTypeEnum.AWS.code().equals(ossType)){
  1244. FileUtils.downLoadFromUrl(ConstantUrl.PREFIX_AWS + "images/images" + sceneEdit.getSceneNum() + "/vision2.modeldata" + "?m="+new Date().getTime(),
  1245. "vision2.modeldata", target + File.separator + "extras" + File.separator);
  1246. }
  1247. CreateObjUtil.convertVisionmodeldataToTxt(target + File.separator + "extras" + File.separator + "vision2.modeldata",
  1248. target + File.separator + "extras" + File.separator + "vision2.txt");
  1249. log.info("解压完成,删除vision2.modeldata文件");
  1250. FileUtils.deleteFile(target + File.separator + "extras" + File.separator + "vision2.modeldata");
  1251. //重新计算算法
  1252. log.info("重新计算大场景:开始建模——"+sceneEdit.getSceneNum());
  1253. //判断V2还是V3
  1254. if("V2".equals(sceneProEntity.getBuildType())){
  1255. CreateObjUtil.build3dModelOld(target , "1");
  1256. }
  1257. if("V3".equals(sceneProEntity.getBuildType())){
  1258. CreateObjUtil.build3dModel(target , "1");
  1259. }
  1260. log.info("重新计算大场景:开始转换成lzma文件——"+sceneEdit.getSceneNum());
  1261. CreateObjUtil.convertTxtToDam( target + File.separator + "results" + File.separator+"tex"+
  1262. File.separator+"modeldata.txt", target + File.separator + "results" +File.separator+ ConstantFileName.modelUUID+"_50k.dam");
  1263. CreateObjUtil.convertDamToLzma(target + File.separator + "results");
  1264. CreateObjUtil.convertTxtToDam( target + File.separator + "results" +File.separator+"tex"+
  1265. File.separator+"modeldata.txt", target + File.separator + "results" + File.separator+ConstantFileName.modelUUID+"_50k.dam");
  1266. File lzmaFile = new File(target + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k.dam.lzma");
  1267. if(!lzmaFile.exists())
  1268. {
  1269. log.info("lzam文件不存在——"+sceneEdit.getSceneNum());
  1270. Thread.sleep(3000);
  1271. }
  1272. File sceneFile = new File(ConstantFilePath.SCENE_PATH+"images"+File.separator+"images"+sceneEdit.getSceneNum() + File.separator + ConstantFileName.modelUUID + "_50k_texture_jpg_high1");
  1273. if(!sceneFile.exists())
  1274. {
  1275. log.info("high1文件夹不存在——"+sceneEdit.getSceneNum());
  1276. sceneFile.mkdirs();
  1277. }
  1278. //将重新建模的tex里的文件和lzma文件复制到Message.filePath+"images"+File.separator+"images"+sceneNum下。
  1279. List<String> list1 = FileUtils.readfileNamesForDirectory(target+File.separator+ "results" + File.separator +"tex",".jpg");
  1280. if(list1 == null){
  1281. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  1282. }
  1283. log.info("新生成的贴图有:——"+list1.size());
  1284. for(int i=0; i<list1.size(); ++i)
  1285. {
  1286. String imgName = list1.get(i);
  1287. FileUtils.copyFile(target+File.separator + "results" + File.separator+"tex"+File.separator+imgName,
  1288. ConstantFilePath.SCENE_PATH+"images"+File.separator+"images"+sceneEdit.getSceneNum() + File.separator + ConstantFileName.modelUUID + "_50k_texture_jpg_high1"+File.separator+imgName, true);
  1289. }
  1290. FileUtils.copyFile(target+File.separator + "results" + File.separator +ConstantFileName.modelUUID+"_50k.dam",
  1291. ConstantFilePath.SCENE_PATH+"images"+File.separator+"images"+sceneEdit.getSceneNum() + File.separator + ConstantFileName.modelUUID+"_50k.dam", true);
  1292. log.info("文件复制到本地ecs完成——"+sceneEdit.getSceneNum());
  1293. //更新scene.json文件
  1294. if(strsceneInfos!=null)
  1295. {
  1296. scenejson.put("floorEditVer", sceneProEditEntity.getFloorEditVer() + 1);
  1297. scenejson.put("floorPublishVer", sceneProEditEntity.getFloorPublishVer());
  1298. FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+sceneEdit.getSceneNum()+File.separator+"scene.json", scenejson.toString());
  1299. log.info("写入scene.json文件完成——"+sceneEdit.getSceneNum());
  1300. }
  1301. //floorEditVer字段增加1
  1302. sceneProEditEntity.setFloorEditVer(sceneProEditEntity.getFloorEditVer() + 1);
  1303. sceneProEditService.updateById(sceneProEditEntity);
  1304. log.info("修改数据库完成——"+sceneEdit.getSceneNum());
  1305. log.info("花费时间:" + (System.currentTimeMillis() - start));
  1306. }
  1307. return ResultData.ok();
  1308. }
  1309. @Override
  1310. public ResultData copyAndUpdateFloorJson(String sceneNum, String floorJsonData) throws Exception{
  1311. StringBuffer dataBuf = new StringBuffer().append("data").append(File.separator).append("data").append(sceneNum).append(File.separator);
  1312. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  1313. if(StrUtil.isEmpty(floorJsonData)){
  1314. ScenePro sceneProEntity = this.findBySceneNum(sceneNum);
  1315. if(sceneProEntity == null){
  1316. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1317. }
  1318. FileUtils.copyFile(sceneProEntity.getDataSource() + "/results/floor.json", dataBuffer.toString() + "houst_floor.json", true);
  1319. fYunFileService.uploadFile(dataBuffer.toString() + "houst_floor.json", dataBuf.toString() + "houst_floor.json");
  1320. String result = FileUtils.readFile(dataBuffer.toString() + "houst_floor.json");
  1321. return ResultData.ok(result);
  1322. }
  1323. FileUtils.writeFile(dataBuffer.toString() + "houst_floor.json", floorJsonData);
  1324. fYunFileService.uploadFile(dataBuffer.toString() + "houst_floor.json", dataBuf.toString() + "houst_floor.json");
  1325. return ResultData.ok(floorJsonData);
  1326. }
  1327. @Override
  1328. @SystemServiceLog(description = "保存场景热点")
  1329. public ResultData saveHot(RequestSceneEdit base) throws Exception {
  1330. if(StrUtil.isEmpty(base.getType())){
  1331. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  1332. }
  1333. String sid = base.getSid();
  1334. ScenePro sceneProEntity = this.findBySceneNum(base.getSceneNum());
  1335. if (sceneProEntity == null ) {
  1336. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1337. }
  1338. JSONObject jsonhot = JSONObject.parseObject(base.getHotData());
  1339. StringBuffer dataBuf = new StringBuffer()
  1340. .append("data").append(File.separator)
  1341. .append("data").append(sceneProEntity.getNum())
  1342. .append(File.separator);
  1343. StringBuffer imagesBuf = new StringBuffer()
  1344. .append("images").append(File.separator)
  1345. .append("images").append(sceneProEntity.getNum())
  1346. .append(File.separator);
  1347. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  1348. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  1349. String str = FileUtils.readFile(dataBuffer.toString() + "hot.json");
  1350. JSONArray jsonhots = null;
  1351. if (org.apache.commons.lang3.StringUtils.isNotEmpty(str)) {
  1352. jsonhots = JSONArray.parseArray(str);
  1353. }else {
  1354. File file = new File(dataBuffer.toString() + "hot.json");
  1355. if(!file.getParentFile().exists()){
  1356. file.getParentFile().mkdirs();
  1357. }
  1358. if(!file.exists()){
  1359. file.createNewFile();
  1360. }
  1361. jsonhots = new JSONArray();
  1362. }
  1363. //添加或者修改
  1364. if("1".equals(base.getType())){
  1365. sid = jsonhot.getString("sid");
  1366. if(StrUtil.isEmpty(sid)){
  1367. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  1368. }
  1369. jsonhots.add(jsonhot);
  1370. }
  1371. else if("0".equals(base.getType())){
  1372. sid = jsonhot.getString("sid");
  1373. if(StrUtil.isEmpty(sid)){
  1374. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  1375. }
  1376. }
  1377. else if("-1".equals(base.getType())){
  1378. if(StrUtil.isEmpty(sid)){
  1379. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  1380. }
  1381. }
  1382. //判断是否需要删除自定义热点样式
  1383. String[] styles = null;
  1384. if(StrUtil.isNotEmpty(base.getStyleName())){
  1385. styles = base.getStyleName().split(",");
  1386. }
  1387. for(int i=0;i<jsonhots.size();++i){
  1388. JSONObject ele = jsonhots.getJSONObject(i);
  1389. //名字对应上就删除
  1390. if(styles != null){
  1391. for(String style : styles){
  1392. if(style.equals(ele.getString("styleId"))){
  1393. jsonhots.getJSONObject(i).put("styleId", null);
  1394. jsonhots.getJSONObject(i).put("style", "default");
  1395. jsonhots.getJSONObject(i).put("styleImageURL", null);
  1396. }
  1397. }
  1398. }
  1399. if(ele.getString("sid").equals(sid)){
  1400. if("-1".equals(base.getType())){
  1401. jsonhots.remove(i);
  1402. if(ele.containsKey("media")){
  1403. String fileType = ele.getString("media");
  1404. if(fileType.contains("photo"))
  1405. {
  1406. FileUtils.deleteFile(imagesBuffer.toString() + "hot"+sid+".jpg");
  1407. }
  1408. if(fileType.contains("audio") || fileType.contains("voice"))
  1409. {
  1410. FileUtils.deleteFile(imagesBuffer.toString() + "hot"+sid+".mp3");
  1411. }
  1412. if(fileType.contains("video"))
  1413. {
  1414. FileUtils.deleteFile(imagesBuffer.toString() + "hot"+sid+".mp4");
  1415. }
  1416. }
  1417. if(!FYunTypeEnum.AWS.code().equals(this.ossType)){
  1418. JSONObject paramData = new JSONObject();
  1419. paramData.put("hotId", sid);
  1420. JSONObject hotListJson = JSONObject.parseObject(OkHttpUtils.httpGet(hotDomainList));
  1421. if(hotListJson != null){
  1422. JSONArray hotListArray = hotListJson.getJSONArray("data");
  1423. if(hotListArray != null){
  1424. for(int l = 0, len = hotListArray.size(); l < len; l++){
  1425. OkHttpUtils.httpPostJson(hotListArray.getString(l) + hotDelete + "?hotId=" + sid
  1426. , paramData.toJSONString());
  1427. }
  1428. }
  1429. }
  1430. }
  1431. }
  1432. else if("0".equals(base.getType())){
  1433. jsonhots.set(i, jsonhot);
  1434. }
  1435. }
  1436. }
  1437. FileUtils.deleteFile(dataBuffer.toString() + "hot.json");
  1438. File dataPath = new File(dataBuffer.toString());
  1439. if(!dataPath.exists()){
  1440. dataPath.mkdirs();
  1441. }
  1442. FileUtils.writeFile(dataBuffer.toString() + "hot.json", jsonhots.toString());
  1443. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  1444. JSONObject scenejson = new JSONObject();
  1445. if(strsceneInfos!=null){
  1446. scenejson = JSONObject.parseObject(strsceneInfos);
  1447. }
  1448. if(jsonhots.size()>0){
  1449. scenejson.put("hots", 1);
  1450. }
  1451. else{
  1452. scenejson.put("hots", 0);
  1453. }
  1454. if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getCapData())){
  1455. FileUtils.writeFile(dataBuffer.toString() + "capData.json", new String(base.getCapData().getBytes(), "UTF-8"));
  1456. scenejson.put("capData", dataBuf.toString() + "capData.json");
  1457. }
  1458. if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getFrameData())){
  1459. FileUtils.writeFile(dataBuffer.toString() + "frameData.json", new String(base.getFrameData().getBytes(), "UTF-8"));
  1460. scenejson.put("frameData", dataBuf.toString() + "frameData.json");
  1461. }
  1462. if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getPlayData())){
  1463. FileUtils.writeFile(dataBuffer.toString() + "playData.json", new String(base.getPlayData().getBytes(), "UTF-8"));
  1464. scenejson.put("playData", dataBuf.toString() + "playData.json");
  1465. }
  1466. if(!org.apache.commons.lang3.StringUtils.isEmpty(base.getScreencapThumb())){
  1467. FileUtils.writeFile(dataBuffer.toString() + "screencapThumb.json", new String(base.getScreencapThumb().getBytes(), "UTF-8"));
  1468. scenejson.put("screencapThumb", dataBuf.toString() + "screencapThumb.json");
  1469. }
  1470. scenejson.put("version", scenejson.getIntValue("version") + 1);
  1471. FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
  1472. return ResultData.ok();
  1473. }
  1474. @Override
  1475. @SystemServiceLog(description = "保存热点可见性的数据")
  1476. public ResultData saveHotVisible(RequestSceneEdit base) throws Exception {
  1477. if(StrUtil.isEmpty(base.getData()) || StrUtil.isEmpty(base.getSceneNum())){
  1478. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  1479. }
  1480. ScenePro sceneProEntity = this.findBySceneNum(base.getSceneNum());
  1481. if (sceneProEntity == null ) {
  1482. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1483. }
  1484. JSONArray visiblePanos = JSONArray.parseArray(base.getData());
  1485. StringBuffer dataBuf = new StringBuffer()
  1486. .append("data").append(File.separator)
  1487. .append("data").append(sceneProEntity.getNum())
  1488. .append(File.separator);
  1489. StringBuffer imagesBuf = new StringBuffer()
  1490. .append("images").append(File.separator)
  1491. .append("images").append(sceneProEntity.getNum())
  1492. .append(File.separator);
  1493. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  1494. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  1495. File file = new File(dataBuffer.toString() + "hot.json");
  1496. if (!file.exists()) {
  1497. throw new BusinessException(ErrorCode.FAILURE_CODE_3018);
  1498. }
  1499. String str = FileUtils.readFile(dataBuffer.toString() + "hot.json");
  1500. JSONArray hots = JSONArray.parseArray(str);
  1501. for (int i = 0; i < hots.size(); ++i) {
  1502. JSONObject hot = hots.getJSONObject(i);
  1503. for (int j = 0; j < visiblePanos.size(); ++j) {
  1504. if (hot.getString("sid").equals(((JSONObject) visiblePanos.get(j)).getString("sid"))) {
  1505. hot.put("visiblePanos", ((JSONObject) visiblePanos.get(j)).getJSONArray("value"));
  1506. }
  1507. }
  1508. }
  1509. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  1510. JSONObject scenejson = new JSONObject();
  1511. if(strsceneInfos!=null){
  1512. scenejson = JSONObject.parseObject(strsceneInfos);
  1513. }
  1514. scenejson.put("version", scenejson.getIntValue("version") + 1);
  1515. FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
  1516. SceneProEdit sceneProEditEntity = sceneProEditService.findBySceneProId(sceneProEntity.getId());
  1517. sceneProEditEntity.setVersion(sceneProEditEntity.getVersion() + 1);
  1518. sceneProEditService.updateById(sceneProEditEntity);
  1519. FileUtils.deleteFile(dataBuffer.toString() + "hot.json");
  1520. FileUtils.writeFile(dataBuffer.toString() + "hot.json", hots.toString());
  1521. return ResultData.ok();
  1522. }
  1523. @Override
  1524. @SystemServiceLog(description = "漫游可行")
  1525. public ResultData saveLinkPano(RequestSceneEdit base) throws Exception {
  1526. if(StrUtil.isEmpty(base.getData()) || StrUtil.isEmpty(base.getSceneNum())){
  1527. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  1528. }
  1529. ScenePro sceneProEntity = this.findBySceneNum(base.getSceneNum());
  1530. if (sceneProEntity == null ) {
  1531. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1532. }
  1533. JSONArray inputData = JSONObject.parseArray(base.getData());
  1534. StringBuffer dataBuf = new StringBuffer()
  1535. .append("data").append(File.separator)
  1536. .append("data").append(sceneProEntity.getNum())
  1537. .append(File.separator);
  1538. StringBuffer imagesBuf = new StringBuffer()
  1539. .append("images").append(File.separator)
  1540. .append("images").append(sceneProEntity.getNum())
  1541. .append(File.separator);
  1542. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  1543. File directory = new File(dataBuffer.toString());
  1544. if (!directory.exists()) {
  1545. directory.mkdirs();
  1546. }
  1547. JSONArray inputdata = JSONArray.parseArray(base.getData());
  1548. String modeldataUrl = ossPrefixUrl + imagesBuf.toString() + "vision.modeldata?t=" + System.currentTimeMillis();
  1549. FileUtils.downLoadFromUrl(modeldataUrl, "vision.modeldata", dataBuffer.toString());
  1550. File file = new File(dataBuffer.toString() + "vision.modeldata");
  1551. if(!file.exists()) {
  1552. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  1553. }
  1554. ConvertUtils.convertVisionModelDataToTxt(dataBuffer.toString() + "vision.modeldata", dataBuffer.toString() + "vision.json");
  1555. String str = FileUtils.readFile(dataBuffer.toString() + "vision.json");
  1556. JSONObject json = JSONObject.parseObject(str);
  1557. JSONArray panos = json.getJSONArray("sweepLocations");
  1558. for (int i = 0; i < panos.size(); ++i) {
  1559. JSONObject pano = panos.getJSONObject(i);
  1560. for (int j = 0; j < inputData.size(); ++j) {
  1561. JSONObject jo = inputData.getJSONObject(j);
  1562. String currentPanoId = jo.getString("panoID");
  1563. JSONArray visibles = jo.getJSONArray("visibles");
  1564. JSONArray visibles3 = jo.getJSONArray("visibles3");
  1565. if (pano.getString("uuid").equals(currentPanoId)) {
  1566. pano.put("visibles", visibles);
  1567. pano.put("visibles3", visibles3);
  1568. }
  1569. }
  1570. }
  1571. FileUtils.deleteFile(dataBuffer.toString() + "vision.json");
  1572. FileUtils.deleteFile(dataBuffer.toString() + "vision.modeldata");
  1573. FileUtils.writeFile(dataBuffer.toString() + "vision.json", json.toString());
  1574. ConvertUtils.convertTxtToVisionModelData(dataBuffer.toString() + "vision.json", dataBuffer.toString() + "vision.modeldata");
  1575. fYunFileService.uploadFile(dataBuffer.toString() + "vision.modeldata", imagesBuf.toString() + "vision.modeldata");
  1576. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  1577. JSONObject scenejson = new JSONObject();
  1578. if(strsceneInfos!=null){
  1579. scenejson = JSONObject.parseObject(strsceneInfos);
  1580. }
  1581. scenejson.put("version", scenejson.getIntValue("version") + 1);
  1582. FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
  1583. SceneProEdit sceneProEditEntity = sceneProEditService.findBySceneProId(sceneProEntity.getId());
  1584. if (sceneProEditEntity == null ) {
  1585. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1586. }
  1587. sceneProEditEntity.setVersion(scenejson.getIntValue("version") + 1);
  1588. sceneProEditService.updateById(sceneProEditEntity);
  1589. return ResultData.ok();
  1590. }
  1591. @Override
  1592. public ResultData saveInitialPage(RequestSceneEdit base) throws Exception{
  1593. if(StrUtil.isEmpty(base.getSceneNum()) || StrUtil.isEmpty(base.getInitialPoint())){
  1594. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  1595. }
  1596. ScenePro sceneProEntity = this.findBySceneNum(base.getSceneNum());
  1597. if(sceneProEntity == null){
  1598. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1599. }
  1600. StringBuffer dataBuf = new StringBuffer()
  1601. .append("data").append(File.separator)
  1602. .append("data").append(sceneProEntity.getNum())
  1603. .append(File.separator);
  1604. StringBuffer imagesBuf = new StringBuffer()
  1605. .append("images").append(File.separator)
  1606. .append("images").append(sceneProEntity.getNum())
  1607. .append(File.separator);
  1608. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  1609. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  1610. String path1 = imagesBuffer.toString() + "thumbBigImg.jpg";
  1611. String path2 = imagesBuffer.toString() + "thumbSmallImg.jpg";
  1612. //生成缩略图
  1613. //按指定大小把图片进行缩和放(会遵循原图高宽比例)
  1614. //此处把图片压成1024×512的缩略图
  1615. Thumbnails.of(path1).size(1024,512).toFile(path2);//变为1024×512
  1616. String strsceneInfos = FileUtils.readFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneProEntity.getNum() + File.separator + "scene.json");
  1617. JSONObject scenejson = new JSONObject();
  1618. if(strsceneInfos!=null) {
  1619. scenejson = JSONObject.parseObject(strsceneInfos);
  1620. }
  1621. Map map = new HashMap();
  1622. map.put("entry", JSONObject.parseObject(base.getInitialPoint()));
  1623. map.put("thumbImg", 1);
  1624. map.put("version", scenejson.getIntValue("version")+1);
  1625. FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map);
  1626. return ResultData.ok();
  1627. }
  1628. @Override
  1629. public ResultData uploadScreencapVoiceNewV3(String sceneNum, String type, String fileName, MultipartFile file, String length, String replace, String times, String index) throws Exception{
  1630. if(StrUtil.isEmpty(sceneNum)){
  1631. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  1632. }
  1633. ScenePro sceneProEntity = this.findBySceneNum(sceneNum);
  1634. if(sceneProEntity == null){
  1635. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1636. }
  1637. if (!file.isEmpty()&& file.getSize() <= 0) {
  1638. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  1639. }
  1640. //文件上传的位置可以自定义
  1641. String path = ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+sceneNum;
  1642. File targetFile = new File(path);
  1643. if (!targetFile.exists()) {
  1644. targetFile.mkdirs();
  1645. }
  1646. String originalFileName = "sound201810.mp3";
  1647. String strsceneInfos = FileUtils.readFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json");
  1648. JSONObject scenejson = new JSONObject();
  1649. if(strsceneInfos!=null) {
  1650. scenejson = JSONObject.parseObject(strsceneInfos);
  1651. }
  1652. if("soundsync".equals(type) && !"1".equals(replace)){
  1653. //判断分房间模块文件夹是否存在
  1654. String partPath = path + File.separator + "part";
  1655. File partFile = new File(partPath);
  1656. if(!partFile.exists()){
  1657. partFile.mkdirs();
  1658. }
  1659. synchronized(this){
  1660. targetFile = new File(partPath + File.separator + fileName);
  1661. if(targetFile.exists())
  1662. {
  1663. FileUtils.deleteFile(partPath + File.separator + fileName);
  1664. }
  1665. file.transferTo(targetFile);
  1666. }
  1667. //获取总音频多少段,每段时长
  1668. String[] time = times.split(",");
  1669. //遍历判断音频是否存在,不存在生成空白音效
  1670. for(int i = 0, len = time.length; i < len; i++){
  1671. if(!new File(partPath + File.separator + i + ".mp3").exists()){
  1672. //某部分文件不存在,直接生成一段静音后拼接文件
  1673. CreateObjUtil.createMuteViode(Double.valueOf(time[i]), partPath + File.separator + i + ".mp3");
  1674. }
  1675. }
  1676. //拼接所有音频文件
  1677. if(time.length > 2){
  1678. //若是多部分,两个两个合并,最后合成最终文件
  1679. for(int i = 1, len = time.length; i < len; i++){
  1680. if(i == 1){
  1681. // FileUtils.deleteFile(partPath + File.separator + i + "muteSound.mp3");
  1682. CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + ".mp3", partPath + File.separator + i + ".mp3",
  1683. partPath + File.separator + i + "muteSound.mp3");
  1684. }else if(i == len - 1){
  1685. CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + "muteSound.mp3", partPath + File.separator + i + ".mp3",
  1686. path + File.separator + originalFileName);
  1687. }else {
  1688. CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + "muteSound.mp3", partPath + File.separator + i + ".mp3",
  1689. partPath + File.separator + i + "muteSound.mp3");
  1690. }
  1691. }
  1692. }else {
  1693. //若只有两部分,直接合并成最终文件
  1694. CreateObjUtil.mergeVideo(partPath + File.separator + "0.mp3", partPath + File.separator + "1.mp3", path + File.separator + originalFileName);
  1695. }
  1696. Map map = new HashMap();
  1697. map.put("screencapVoiceSoundsyncFileName", originalFileName);
  1698. String proVideo = "voice/voice"+sceneNum+"/"+originalFileName;
  1699. map.put("screencapVoiceSoundsync", proVideo);
  1700. map.put("uploadVoiceSoundsync", 1);
  1701. map.put("screencapVoiceType", type);
  1702. map.put("version", scenejson.getIntValue("version")+1);
  1703. FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map);
  1704. return ResultData.ok("voice/voice"+sceneNum+"/"+originalFileName);
  1705. }
  1706. String name = "201810.wav";
  1707. targetFile = new File(path + File.separator +name);
  1708. // 保存
  1709. synchronized(this){
  1710. if(targetFile.exists())
  1711. {
  1712. FileUtils.deleteFile(path + File.separator + name);
  1713. }
  1714. file.transferTo(targetFile);
  1715. }
  1716. Map map = new HashMap();
  1717. if("soundsync".equals(type)){
  1718. FileUtils.delAllFile(path + File.separator + "part");
  1719. //判断分房间模块文件夹是否存在
  1720. String partPath = path + File.separator + "part";
  1721. File partFile = new File(partPath);
  1722. if(!partFile.exists()){
  1723. partFile.mkdirs();
  1724. }
  1725. //保存0.mp3文件到part
  1726. FileUtils.copyFile(path + File.separator +name, partPath + File.separator + fileName, true);
  1727. FileUtils.changeVoiceToMp3(path + File.separator + name, path + File.separator + originalFileName);
  1728. map.put("screencapVoiceSoundsyncFileName", originalFileName);
  1729. String proVideo = "voice/voice"+sceneNum+"/"+originalFileName;
  1730. map.put("screencapVoiceSoundsync", proVideo);
  1731. map.put("uploadVoiceSoundsync", 1);
  1732. map.put("version", scenejson.getIntValue("version")+1);
  1733. map.put("screencapVoiceType", type);
  1734. FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map);
  1735. return ResultData.ok(proVideo);
  1736. }
  1737. FileUtils.changeVoiceToMp3(path + File.separator + name, path + File.separator +"201810.mp3");
  1738. map.put("screencapVoiceFileName", file.getOriginalFilename());
  1739. String voiceSrc = "voice/voice"+sceneNum+"/"+"201810.mp3";
  1740. map.put("screencapVoiceSrc", voiceSrc);
  1741. map.put("uploadVoiceSrc", 1);
  1742. map.put("version", scenejson.getIntValue("version")+1);
  1743. map.put("screencapVoiceType", type);
  1744. FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map);
  1745. return ResultData.ok(voiceSrc);
  1746. }
  1747. @Override
  1748. public ResultData deleteScreencapVoice(RequestSceneEdit base) throws Exception{
  1749. if(StrUtil.isEmpty(base.getSceneNum())){
  1750. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  1751. }
  1752. ScenePro sceneProEntity = this.findBySceneNum(base.getSceneNum());
  1753. if(sceneProEntity == null){
  1754. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1755. }
  1756. String scenePath = ConstantFilePath.SCENE_PATH+ "data" + File.separator+"data"+base.getSceneNum()+File.separator+"scene.json";
  1757. String str = FileUtils.readFile(scenePath);
  1758. JSONObject json = new JSONObject();
  1759. if(str!=null){
  1760. json = JSONObject.parseObject(str);
  1761. }
  1762. else{
  1763. File file = new File(scenePath);
  1764. if(!file.getParentFile().exists())
  1765. {
  1766. file.getParentFile().mkdirs();
  1767. }
  1768. if(!file.exists())
  1769. {
  1770. file.createNewFile();
  1771. }
  1772. }
  1773. log.info("type:" + base.getType());
  1774. if("soundsync".equals(base.getType())){
  1775. FileUtils.deleteFile(ConstantFilePath.SCENE_PATH+json.getString("screencapVoiceSoundsync"));
  1776. json.put("screencapVoiceSoundsyncFileName", "");
  1777. json.put("screencapVoiceSoundsync", "");
  1778. json.put("version", json.getIntValue("version")+1);
  1779. FileUtils.deleteFile(scenePath);
  1780. FileUtils.writeFile(scenePath, json.toString());
  1781. return ResultData.ok();
  1782. }
  1783. if("sound".equals(base.getType())){
  1784. FileUtils.deleteFile(ConstantFilePath.SCENE_PATH+json.getString("screencapVoiceSound"));
  1785. json.put("screencapVoiceSoundFileName", "");
  1786. json.put("screencapVoiceSound", "");
  1787. json.put("version", json.getIntValue("version")+1);
  1788. FileUtils.deleteFile(scenePath);
  1789. FileUtils.writeFile(scenePath, json.toString());
  1790. return ResultData.ok();
  1791. }
  1792. String path = ConstantFilePath.SCENE_PATH+json.getString("screencapVoiceSrc");
  1793. log.info("path:" + ConstantFilePath.SCENE_PATH+json.getString("screencapVoiceSrc"));
  1794. FileUtils.deleteFile(path);
  1795. json.put("screencapVoiceFileName", "");
  1796. json.put("screencapVoiceSrc", "");
  1797. json.put("version", json.getIntValue("version")+1);
  1798. log.info("scenePath:" + scenePath);
  1799. FileUtils.deleteFile(scenePath);
  1800. FileUtils.writeFile(scenePath, json.toString());
  1801. return ResultData.ok();
  1802. }
  1803. @Override
  1804. public ResultData deleteScreencapVoicePart(String sceneNum, String fileName, String times, String index) throws Exception {
  1805. if(StrUtil.isEmpty(sceneNum)){
  1806. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  1807. }
  1808. ScenePro sceneProEntity = this.findBySceneNum(sceneNum);
  1809. if(sceneProEntity == null){
  1810. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1811. }
  1812. //文件上传的位置可以自定义
  1813. String path = ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+sceneNum;
  1814. File targetFile = new File(path);
  1815. if (!targetFile.exists()) {
  1816. targetFile.mkdirs();
  1817. }
  1818. String originalFileName = "sound201810.mp3";
  1819. log.info("上传的音频文件名:" + originalFileName);
  1820. String strsceneInfos = FileUtils.readFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json");
  1821. JSONObject scenejson = new JSONObject();
  1822. if(strsceneInfos!=null) {
  1823. scenejson = JSONObject.parseObject(strsceneInfos);
  1824. }
  1825. //判断分房间模块文件夹是否存在
  1826. String partPath = path + File.separator + "part";
  1827. File partFile = new File(partPath);
  1828. if(!partFile.exists()){
  1829. partFile.mkdirs();
  1830. }
  1831. //删除指定部分音频文件
  1832. FileUtils.deleteFile(partPath + File.separator + index + ".mp3");
  1833. //获取总音频多少段,每段时长
  1834. String[] time = times.split(",");
  1835. //修改删除的部分视频后面部分音频名字,如删除1.MP3,则将2.mp3修改成1.mp3,往后以此类推
  1836. if(Integer.parseInt(index) < time.length) {
  1837. for(int i = 0, len = time.length - Integer.parseInt(index); i < len; i++){
  1838. if(new File(partPath + File.separator + (Integer.parseInt(index) + 1 + i) + ".mp3").exists()){
  1839. FileUtils.copyFile(partPath + File.separator + (Integer.parseInt(index) + 1 + i) + ".mp3",
  1840. partPath + File.separator + (Integer.parseInt(index) + i) + ".mp3", true);
  1841. }
  1842. }
  1843. }
  1844. //遍历判断音频是否存在,不存在生成空白音效
  1845. for(int i = 0, len = time.length; i < len; i++){
  1846. if(!new File(partPath + File.separator + i + ".mp3").exists()){
  1847. //某部分文件不存在,直接生成一段静音后拼接文件
  1848. CreateObjUtil.createMuteViode(Double.valueOf(time[i]), partPath + File.separator + i + ".mp3");
  1849. }
  1850. }
  1851. //拼接所有音频文件
  1852. if(time.length > 2){
  1853. //若是多部分,两个两个合并,最后合成最终文件
  1854. for(int i = 1, len = time.length; i < len; i++){
  1855. if(i == 1){
  1856. // FileUtils.deleteFile(partPath + File.separator + i + "muteSound.mp3");
  1857. CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + ".mp3", partPath + File.separator + i + ".mp3",
  1858. partPath + File.separator + i + "muteSound.mp3");
  1859. }else if(i == len - 1){
  1860. CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + "muteSound.mp3", partPath + File.separator + i + ".mp3",
  1861. path + File.separator + originalFileName);
  1862. }else {
  1863. CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + "muteSound.mp3", partPath + File.separator + i + ".mp3",
  1864. partPath + File.separator + i + "muteSound.mp3");
  1865. }
  1866. }
  1867. }else if(time.length == 2){
  1868. //若只有两部分,直接合并成最终文件
  1869. CreateObjUtil.mergeVideo(partPath + File.separator + "0.mp3", partPath + File.separator + "1.mp3", path + File.separator + originalFileName);
  1870. }else {
  1871. FileUtils.copyFile(partPath + File.separator + "0.mp3", path + File.separator + originalFileName, true);
  1872. }
  1873. Map map = new HashMap();
  1874. map.put("screencapVoiceSoundsyncFileName", originalFileName);
  1875. String proVideo = "voice/voice"+sceneNum+"/"+originalFileName;
  1876. map.put("screencapVoiceSoundsync", proVideo);
  1877. map.put("uploadVoiceSoundsync", 1);
  1878. map.put("screencapVoiceType", "soundsync");
  1879. map.put("version", scenejson.getIntValue("version")+1);
  1880. FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map);
  1881. return ResultData.ok("voice/voice"+sceneNum+"/"+originalFileName);
  1882. }
  1883. @Override
  1884. public ResultData uploadOverlayMedia(String sceneNum, MultipartFile file, String sid) throws Exception {
  1885. if(StrUtil.isEmpty(sceneNum)){
  1886. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  1887. }
  1888. ScenePro sceneProEntity = this.findBySceneNum(sceneNum);
  1889. if(sceneProEntity == null){
  1890. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1891. }
  1892. String fileName = "overlay" + sid + ".mp4";
  1893. if (!file.isEmpty()){
  1894. String path = ConstantFilePath.SCENE_PATH + "images" + File.separator + "images" + sceneNum;
  1895. File targetFile = new File(path);
  1896. if (!targetFile.exists()){
  1897. targetFile.mkdirs();
  1898. }
  1899. targetFile = new File(path + File.separator + fileName);
  1900. if (targetFile.exists()){
  1901. FileUtils.deleteFile(path + File.separator + fileName);
  1902. }
  1903. file.transferTo(targetFile);
  1904. CreateObjUtil.mp4ToFlv(path + File.separator + fileName, path + File.separator + fileName.replace("mp4", "flv"));
  1905. fYunFileService.uploadFile(path + File.separator + fileName, "images"+File.separator+"images"+sceneNum + File.separator + fileName);
  1906. fYunFileService.uploadFile(path + File.separator + fileName.replace("mp4", "flv"), "images"+File.separator+"images"+sceneNum + File.separator + fileName.replace("mp4", "flv"));
  1907. }
  1908. return ResultData.ok(fileName);
  1909. }
  1910. @Override
  1911. public ResultData saveOverlay(RequestSceneEdit base) throws Exception {
  1912. if(StrUtil.isEmpty(base.getType())){
  1913. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  1914. }
  1915. String sid = base.getSid();
  1916. ScenePro sceneProEntity = this.findBySceneNum(base.getSceneNum());
  1917. if (sceneProEntity == null ) {
  1918. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1919. }
  1920. SceneProEdit sceneProEditEntity = sceneProEditService.findBySceneProId(sceneProEntity.getId());
  1921. if (sceneProEditEntity == null ) {
  1922. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1923. }
  1924. //需要操作的数据
  1925. JSONObject jsonOverlay = JSONObject.parseObject(base.getOverlayData());
  1926. StringBuffer dataBuf = new StringBuffer()
  1927. .append("data").append(File.separator)
  1928. .append("data").append(sceneProEntity.getNum())
  1929. .append(File.separator);
  1930. StringBuffer imagesBuf = new StringBuffer()
  1931. .append("images").append(File.separator)
  1932. .append("images").append(sceneProEntity.getNum())
  1933. .append(File.separator);
  1934. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  1935. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  1936. String str = sceneProEditEntity.getOverlay();
  1937. JSONArray jsonOverlays = null;
  1938. if (org.apache.commons.lang3.StringUtils.isNotEmpty(str)) {
  1939. jsonOverlays = JSONArray.parseArray(str);
  1940. }else {
  1941. jsonOverlays = new JSONArray();
  1942. }
  1943. //添加或者修改
  1944. if("1".equals(base.getType())){
  1945. sid = jsonOverlay.getString("sid");
  1946. if(StrUtil.isEmpty(sid)){
  1947. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  1948. }
  1949. jsonOverlays.add(jsonOverlay);
  1950. }
  1951. else if("0".equals(base.getType())){
  1952. sid = jsonOverlay.getString("sid");
  1953. if(StrUtil.isEmpty(sid)){
  1954. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  1955. }
  1956. }
  1957. else if("-1".equals(base.getType())){
  1958. if(StrUtil.isEmpty(sid)){
  1959. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  1960. }
  1961. }
  1962. for(int i=0;i<jsonOverlays.size();++i){
  1963. JSONObject ele = jsonOverlays.getJSONObject(i);
  1964. if(ele.getString("sid").equals(sid)){
  1965. if("-1".equals(base.getType())){
  1966. jsonOverlays.remove(i);
  1967. if(ele.containsKey("media")){
  1968. String fileType = ele.getString("media");
  1969. if(fileType.contains("photo"))
  1970. {
  1971. FileUtils.deleteFile(imagesBuffer.toString() + "overlay"+sid+".jpg");
  1972. }
  1973. if(fileType.contains("audio") || fileType.contains("voice"))
  1974. {
  1975. FileUtils.deleteFile(imagesBuffer.toString() + "overlay"+sid+".mp3");
  1976. }
  1977. if(fileType.contains("video"))
  1978. {
  1979. FileUtils.deleteFile(imagesBuffer.toString() + "overlay"+sid+".mp4");
  1980. }
  1981. }
  1982. }
  1983. else if("0".equals(base.getType())){
  1984. jsonOverlays.set(i, jsonOverlay);
  1985. }
  1986. break;
  1987. }
  1988. }
  1989. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  1990. JSONObject scenejson = new JSONObject();
  1991. if(strsceneInfos!=null){
  1992. scenejson = JSONObject.parseObject(strsceneInfos);
  1993. }
  1994. scenejson.put("overlay", jsonOverlays.toString());
  1995. scenejson.put("version", scenejson.getIntValue("version") + 1);
  1996. FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
  1997. sceneProEditEntity.setVersion(scenejson.getIntValue("version") + 1);
  1998. sceneProEditEntity.setOverlay(jsonOverlays.toString());
  1999. sceneProEditService.updateById(sceneProEditEntity);
  2000. return ResultData.ok();
  2001. }
  2002. @Override
  2003. public ResultData uploadHotJsonToOss(String sceneNum) throws Exception {
  2004. if(StrUtil.isEmpty(sceneNum)){
  2005. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  2006. }
  2007. String path = ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+sceneNum;
  2008. fYunFileService.uploadFile(path + File.separator + "hot.json", "data"+File.separator+"data"+sceneNum + File.separator + "hot.json");
  2009. return ResultData.ok();
  2010. }
  2011. @Override
  2012. public ResultData saveJsonData(String sceneNum, String fileName, String jsonData) throws Exception {
  2013. if(StrUtil.isEmpty(sceneNum) || StrUtil.isEmpty(fileName) || StrUtil.isEmpty(jsonData)){
  2014. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  2015. }
  2016. ScenePro sceneProEntity = this.findBySceneNum(sceneNum);
  2017. if(sceneProEntity == null){
  2018. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  2019. }
  2020. StringBuffer dataBuf = new StringBuffer()
  2021. .append("data").append(File.separator)
  2022. .append("data").append(sceneProEntity.getNum())
  2023. .append(File.separator);
  2024. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  2025. FileUtils.writeFile(dataBuffer.toString() + fileName, jsonData);
  2026. return ResultData.ok("scene/" + dataBuf.toString() + fileName);
  2027. }
  2028. @Override
  2029. public ResultData savePanorama(String sceneNum, String sid, MultipartFile file, String imagesName) throws Exception {
  2030. if(StrUtil.isEmpty(sceneNum) || StrUtil.isEmpty(sid)){
  2031. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  2032. }
  2033. ScenePro sceneProEntity = this.findBySceneNum(sceneNum);
  2034. if(sceneProEntity == null){
  2035. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  2036. }
  2037. StringBuffer dataBuf = new StringBuffer()
  2038. .append("data").append(File.separator)
  2039. .append("data").append(sceneProEntity.getNum())
  2040. .append(File.separator);
  2041. StringBuffer imagesBuf = new StringBuffer()
  2042. .append("images").append(File.separator)
  2043. .append("images").append(sceneProEntity.getNum())
  2044. .append(File.separator);
  2045. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  2046. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  2047. String path = sceneProEntity.getDataSource();
  2048. String target = imagesBuffer.toString() + "panorama/" + sid;
  2049. FileUtils.deleteDirectory(target);
  2050. //文件上传的位置可以自定义
  2051. String filePath = target + File.separator + "extras/images" + File.separator + imagesName;
  2052. File targetFile = new File(filePath);
  2053. if(!targetFile.getParentFile().exists()){
  2054. targetFile.getParentFile().mkdirs();
  2055. }
  2056. //上传文件
  2057. file.transferTo(targetFile);
  2058. //调用算法切全景图
  2059. FileUtils.copyFile(path + File.separator + "data.json", target + File.separator+"data.json", true);
  2060. FileUtils.copyFile(path + File.separator + "project.json", target + File.separator+"project.json", true);
  2061. JSONObject visionJson = new JSONObject();
  2062. JSONArray visionArray = new JSONArray();
  2063. visionJson.put("uuid", imagesName.substring(0, imagesName.lastIndexOf(".")));
  2064. visionJson.put("group", 1);
  2065. visionJson.put("subgroup", 0);
  2066. visionArray.add(visionJson);
  2067. JSONObject vision = new JSONObject();
  2068. vision.put("sweepLocations", visionArray);
  2069. FileUtils.writeFile(target + "/extras" + File.separator + "vision.txt", new String(vision.toString().getBytes(), "UTF-8"));
  2070. //data.json增加extras为执行重建算法
  2071. String data = FileUtils.readFile(target + File.separator + "data.json");
  2072. if(data != null){
  2073. JSONObject floorplanJson = new JSONObject();
  2074. floorplanJson.put("has_source_images", true);
  2075. floorplanJson.put("has_vision_txt", true);
  2076. JSONObject dataJson = JSONObject.parseObject(data);
  2077. dataJson.put("extras", floorplanJson);
  2078. //V5表示不需要生成high,low文件
  2079. dataJson.put("skybox_type", "SKYBOX_V6");
  2080. if(sceneProEntity.getSceneScheme() == 11){
  2081. dataJson.put("skybox_type", "SKYBOX_V7");
  2082. }
  2083. dataJson.put("split_type", "SPLIT_V8");
  2084. if(sceneProEntity.getSceneScheme() == 3){
  2085. dataJson.put("skybox_type", "SKYBOX_V4");
  2086. }
  2087. FileUtils.writeFile(target + File.separator+"data.json", new String(dataJson.toString().getBytes(), "UTF-8"));
  2088. }
  2089. //创建文件夹软连接并且复制data.json和project.json
  2090. if(new File(target + File.separator + "capture").exists()){
  2091. new File(target + File.separator + "capture").delete();
  2092. }
  2093. if(new File(target + File.separator + "results").exists()){
  2094. FileUtils.delAllFile(target + File.separator + "results");
  2095. }
  2096. //下载data.fdage
  2097. if(FYunTypeEnum.AWS.code().equals(this.ossType)){
  2098. //亚马逊保持旧方式,超链接capture
  2099. CreateObjUtil.createSoftConnection(path + File.separator + "capture", target + File.separator + "capture");
  2100. }
  2101. CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + path.replace(ConstantFilePath.BUILD_MODEL_PATH, "") + "/data.fdage", target + File.separator + "capture/");
  2102. CreateObjUtil.build3dModel(target , "1");
  2103. //读取upload文件,检验需要上传的文件是否存在
  2104. String uploadData = FileUtils.readFile(target + File.separator + "results" +File.separator+"upload.json");
  2105. JSONObject uploadJson = null;
  2106. JSONArray array = null;
  2107. if(uploadData!=null) {
  2108. uploadJson = JSONObject.parseObject(uploadData);
  2109. array = uploadJson.getJSONArray("upload");
  2110. }
  2111. if(array == null){
  2112. log.info("计算全景图失败,没有upload.json");
  2113. }
  2114. Map<String, String> map = new HashMap<>();
  2115. JSONObject fileJson = null;
  2116. String fileName = "";
  2117. String img = "";
  2118. for(int i = 0, len = array.size(); i < len; i++){
  2119. fileJson = array.getJSONObject(i);
  2120. fileName = fileJson.getString("file");
  2121. //文件不存在抛出异常
  2122. if(!new File(target + File.separator + "results" +File.separator + fileName).exists()){
  2123. throw new Exception(target + File.separator + "results" +File.separator + fileName+"文件不存在");
  2124. }
  2125. //low文件夹
  2126. if(fileJson.getIntValue("clazz") == 4){
  2127. img = "/results" + File.separator + fileName;
  2128. map.put(target + File.separator + "results" +File.separator+ fileName,"images/images"+
  2129. sceneProEntity.getNum()+"/pan/low/"+ fileName.replace("low/", ""));
  2130. continue;
  2131. }
  2132. //tiles文件夹,亚马逊没有裁剪图片api,不需要上传4k图
  2133. if(fileJson.getIntValue("clazz") == 5){
  2134. map.put(target + File.separator + "results" + File.separator+ fileName,"images/images"+
  2135. sceneProEntity.getNum()+ "/panorama_edit/" + sid + File.separator + fileName);
  2136. }
  2137. //tiles文件夹,亚马逊瓦片图
  2138. if(fileJson.getIntValue("clazz") == 7 ){
  2139. map.put(target + File.separator + "results" + File.separator+ fileName,"images/images"+
  2140. sceneProEntity.getNum()+ File.separator + fileName);
  2141. }
  2142. }
  2143. //上传全景图
  2144. map.put(filePath, "images/images"+ sceneProEntity.getNum()+ File.separator + "pan/high/" + imagesName);
  2145. fYunFileService.uploadMulFiles(map);
  2146. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  2147. JSONObject scenejson = new JSONObject();
  2148. if(strsceneInfos!=null) {
  2149. scenejson = JSONObject.parseObject(strsceneInfos);
  2150. }
  2151. scenejson.put("uploadPanoramaImg", 1);
  2152. scenejson.put("version", scenejson.getIntValue("version") + 1);
  2153. FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
  2154. Map<String, String> result = new HashMap<>();
  2155. result.put("type", sceneProEntity.getSceneScheme() == 11? "2k" : "4k");
  2156. result.put("img", "scene/" + imagesBuf.toString() + "panorama/" + sid + img);
  2157. result.put("path", "images/images"+ sceneProEntity.getNum()+ "/panorama_edit/" + sid);
  2158. return ResultData.ok(result);
  2159. }
  2160. @Override
  2161. public ResultData savePanoramaJson(String sceneNum, String fileData, String fileName, String sid) throws Exception {
  2162. if(org.apache.commons.lang3.StringUtils
  2163. .isEmpty(sceneNum) || org.apache.commons.lang3.StringUtils.isEmpty(fileName)){
  2164. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  2165. }
  2166. ScenePro sceneProEntity = this.findBySceneNum(sceneNum);
  2167. if(sceneProEntity == null){
  2168. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  2169. }
  2170. StringBuffer dataBuf = new StringBuffer()
  2171. .append("data").append(File.separator)
  2172. .append("data").append(sceneProEntity.getNum())
  2173. .append(File.separator);
  2174. StringBuffer imagesBuf = new StringBuffer()
  2175. .append("images").append(File.separator)
  2176. .append("images").append(sceneProEntity.getNum())
  2177. .append(File.separator);
  2178. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  2179. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  2180. FileUtils.writeFile(dataBuffer.toString() + fileName, fileData);
  2181. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  2182. JSONObject scenejson = new JSONObject();
  2183. if(strsceneInfos!=null) {
  2184. scenejson = JSONObject.parseObject(strsceneInfos);
  2185. }
  2186. scenejson.put("uploadPanoramaJson", 1);
  2187. scenejson.put("version", scenejson.getIntValue("version") + 1);
  2188. if(org.apache.commons.lang3.StringUtils.isNotEmpty(fileData)){
  2189. scenejson.put("jumpScene", true);
  2190. }else {
  2191. scenejson.put("jumpScene", false);
  2192. }
  2193. FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
  2194. if(org.apache.commons.lang3.StringUtils.isNotEmpty(sid)){
  2195. String target = imagesBuffer.toString() + "panorama/" + sid;
  2196. FileUtils.deleteDirectory(target);
  2197. // uploadToOssUtil.deleteFile(imagesBuf.toString() + "panorama/" + sid);
  2198. fYunFileService.deleteFolder(imagesBuf.toString() + "panorama_edit/" + sid);
  2199. }
  2200. return ResultData.ok();
  2201. }
  2202. @Override
  2203. public ResultData updateFloorJson(String sceneNum, String floorJsonData) throws Exception{
  2204. if(StrUtil.isEmpty(sceneNum) || StrUtil.isEmpty(floorJsonData)){
  2205. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  2206. }
  2207. StringBuffer dataBuf = new StringBuffer()
  2208. .append("data").append(File.separator)
  2209. .append("data").append(sceneNum)
  2210. .append(File.separator);
  2211. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  2212. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  2213. JSONObject scenejson = new JSONObject();
  2214. if(strsceneInfos!=null) {
  2215. scenejson = JSONObject.parseObject(strsceneInfos);
  2216. }
  2217. scenejson.put("uploadFloorJson", 1);
  2218. scenejson.put("version", scenejson.getIntValue("version") + 1);
  2219. FileUtils.writeFile(dataBuffer.toString() + "floor.json", floorJsonData);
  2220. FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toJSONString());
  2221. return ResultData.ok(floorJsonData);
  2222. }
  2223. @Override
  2224. public ResultData getInfo(String sceneNum) throws Exception {
  2225. if(StrUtil.isEmpty(sceneNum)){
  2226. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  2227. }
  2228. ScenePro sceneProEntity = this.findBySceneNum(sceneNum);
  2229. if(sceneProEntity == null){
  2230. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  2231. }
  2232. if(sceneProEntity.getStatus() != 1 && sceneProEntity.getStatus() != -2){
  2233. throw new BusinessException(ErrorCode.FAILURE_CODE_5033);
  2234. }
  2235. if(sceneProEntity.getPayStatus() != 1){
  2236. throw new BusinessException(ErrorCode.FAILURE_CODE_5034);
  2237. }
  2238. ResponseScene responseScene = new ResponseScene();
  2239. SceneProEdit editEntity = sceneProEditService.findBySceneProId(sceneProEntity.getId());
  2240. BeanUtils.copyProperties(editEntity, responseScene);
  2241. BeanUtils.copyProperties(sceneProEntity, responseScene);
  2242. if(StrUtil.isNotEmpty(editEntity.getEntry())){
  2243. responseScene.setEntry(JSONObject.parseObject(editEntity.getEntry()).toJSONString());
  2244. }
  2245. if(StrUtil.isNotEmpty(sceneProEntity.getGps())){
  2246. responseScene.setGps(JSONObject.parseObject(sceneProEntity.getGps()).toJSONString());
  2247. }
  2248. responseScene.setCreateTime(new DateTime(sceneProEntity.getCreateTime()).toString("yyyy-MM-dd"));
  2249. responseScene.setCreateDate(sceneProEntity.getCreateTime().getTime());
  2250. if(StrUtil.isEmpty(editEntity.getSceneKey())){
  2251. responseScene.setIsPublic(0);
  2252. }else {
  2253. responseScene.setIsPublic(1);
  2254. }
  2255. //不返回场景访问密码
  2256. responseScene.setSceneKey("");
  2257. //查询是否有随心装场景
  2258. if(sceneNum.indexOf("vr-")!=-1){
  2259. ScenePro vrSceneProEntity = this.findLikeSceneNum(sceneNum);
  2260. if(vrSceneProEntity != null){
  2261. responseScene.setVrNum(null);
  2262. responseScene.setVideosUser(null);
  2263. responseScene.setBgMusicName(null);
  2264. responseScene.setBgMusic(null);
  2265. }
  2266. }
  2267. //更新访问数量
  2268. sceneService.updateViewCount(sceneNum);
  2269. return ResultData.ok(responseScene);
  2270. }
  2271. @Override
  2272. public ScenePro findLikeSceneNum(String sceneNum) throws Exception {
  2273. return this.getOne(new LambdaQueryWrapper<ScenePro>()
  2274. .eq(ScenePro::getRecStatus, RecStatus.VALID.code())
  2275. .like(ScenePro::getNum, sceneNum + "%")
  2276. .orderByDesc(ScenePro::getId)
  2277. .last("LIMIT 1"));
  2278. }
  2279. @Override
  2280. public ResultData downloadPanoramaOrVideo(String sceneNum, String fileName, String type, String planId) throws Exception {
  2281. if(StrUtil.isEmpty(sceneNum)
  2282. || StrUtil.isEmpty(fileName)
  2283. || StrUtil.isEmpty(type)
  2284. || StrUtil.isEmpty(planId)){
  2285. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  2286. }
  2287. if(fileName.contains("..") || fileName.contains("./\\") || fileName.contains(".//")
  2288. || fileName.contains(".\\\\") || fileName.contains(".\\/")){
  2289. throw new BusinessException(ErrorCode.FAILURE_CODE_3018);
  2290. }
  2291. ScenePro sceneProEntity = this.findBySceneNum(sceneNum);
  2292. if(sceneProEntity == null){
  2293. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  2294. }
  2295. StringBuffer imagesBuf = new StringBuffer()
  2296. .append("images").append(File.separator)
  2297. .append("images").append(sceneProEntity.getNum())
  2298. .append(File.separator);
  2299. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  2300. String path = sceneProEntity.getDataSource();
  2301. String url = "";
  2302. if("image".equals(type)){
  2303. if(!new File(path + "/caches/images/" + fileName).exists()){
  2304. throw new BusinessException(ErrorCode.FAILURE_CODE_3018);
  2305. }
  2306. //备份原始数据
  2307. if(!new File(imagesBuffer.toString() + "caches/back-" + fileName).exists()){
  2308. FileUtils.copyFile(path + "/caches/images/" + fileName, imagesBuffer.toString() + "caches/back-" + fileName, false);
  2309. }
  2310. //复制打包数据,并且改名
  2311. FileUtils.copyFile(path + "/caches/images/" + fileName, imagesBuffer.toString() + "caches/" + planId + ".jpg", true);
  2312. url = mainUrl + "scene/" + imagesBuf.toString() + "caches/" + planId + ".jpg";
  2313. }
  2314. if("video".equals(type)){
  2315. //使用oss的路径
  2316. url = ossPrefixUrl + "video/video" + sceneProEntity.getNum() + "/" + planId + ".mp4";
  2317. }
  2318. Map<String, Object> map = new HashMap<>();
  2319. map.put("fileUrl", url + "?t=" + System.currentTimeMillis());
  2320. map.put("fileName", url.substring(url.lastIndexOf("/") + 1));
  2321. return ResultData.ok(map);
  2322. }
  2323. @Override
  2324. public ResultData uploadBgMusic(String sceneNum, String fileName, MultipartFile file) throws Exception {
  2325. if(StrUtil.isEmpty(sceneNum) || StrUtil.isEmpty(fileName)){
  2326. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  2327. }
  2328. ScenePro sceneProEntity = this.findBySceneNum(sceneNum);
  2329. if(sceneProEntity == null){
  2330. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  2331. }
  2332. StringBuffer dataBuf = new StringBuffer()
  2333. .append("data").append(File.separator)
  2334. .append("data").append(sceneProEntity.getNum())
  2335. .append(File.separator);
  2336. StringBuffer imagesBuf = new StringBuffer()
  2337. .append("images").append(File.separator)
  2338. .append("images").append(sceneProEntity.getNum())
  2339. .append(File.separator);
  2340. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  2341. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  2342. File buMusicFile = new File(imagesBuffer.toString() + fileName);
  2343. if(!buMusicFile.getParentFile().exists()){
  2344. buMusicFile.getParentFile().mkdirs();
  2345. }
  2346. //上传文件
  2347. file.transferTo(buMusicFile);
  2348. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  2349. JSONObject scenejson = new JSONObject();
  2350. if(strsceneInfos!=null) {
  2351. scenejson = JSONObject.parseObject(strsceneInfos);
  2352. }
  2353. scenejson.put("bgMusicName", fileName);
  2354. scenejson.put("uploadBgMusic", 1);
  2355. scenejson.put("version", scenejson.getIntValue("version") + 1);
  2356. FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
  2357. return ResultData.ok();
  2358. }
  2359. @Override
  2360. public ResultData deleteUploadBgMusic(String sceneNum) throws Exception {
  2361. if(StrUtil.isEmpty(sceneNum)){
  2362. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  2363. }
  2364. ScenePro sceneProEntity = this.findBySceneNum(sceneNum);
  2365. if(sceneProEntity == null){
  2366. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  2367. }
  2368. StringBuffer dataBuf = new StringBuffer()
  2369. .append("data").append(File.separator)
  2370. .append("data").append(sceneProEntity.getNum())
  2371. .append(File.separator);
  2372. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  2373. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  2374. JSONObject scenejson = new JSONObject();
  2375. if(strsceneInfos!=null) {
  2376. scenejson = JSONObject.parseObject(strsceneInfos);
  2377. }
  2378. scenejson.put("bgMusicName", "");
  2379. scenejson.put("uploadBgMusic", 1);
  2380. scenejson.put("version", scenejson.getIntValue("version") + 1);
  2381. FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
  2382. return ResultData.ok();
  2383. }
  2384. }