SceneProAppServiceImpl.java 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089
  1. package com.fdkankan.scene.service.impl;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.util.StrUtil;
  4. import cn.hutool.http.HttpStatus;
  5. import com.alibaba.fastjson.JSONArray;
  6. import com.alibaba.fastjson.JSONObject;
  7. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  8. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  9. import com.baomidou.mybatisplus.core.metadata.IPage;
  10. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  11. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  12. import com.fdkankan.common.constant.*;
  13. import com.fdkankan.common.response.PageInfo;
  14. import com.fdkankan.common.util.*;
  15. import com.fdkankan.platform.api.feign.PlatformGoodsClient;
  16. import com.fdkankan.platform.api.feign.PlatformUserClient;
  17. import com.fdkankan.platform.api.vo.Camera;
  18. import com.fdkankan.platform.api.vo.CameraDetail;
  19. import com.fdkankan.platform.api.vo.User;
  20. import com.fdkankan.redis.constant.RedisKey;
  21. import com.fdkankan.redis.constant.RedisLockKey;
  22. import com.fdkankan.redis.util.RedisLockUtil;
  23. import com.fdkankan.scene.entity.SceneCooperation;
  24. import com.fdkankan.scene.entity.ScenePro;
  25. import com.fdkankan.scene.entity.SceneProEdit;
  26. import com.fdkankan.scene.entity.SceneProEditExt;
  27. import com.fdkankan.scene.mapper.ISceneProMapper;
  28. import com.fdkankan.scene.service.*;
  29. import com.fdkankan.scene.vo.SceneEditVO;
  30. import com.fdkankan.common.constant.ErrorCode;
  31. import com.fdkankan.common.exception.BusinessException;
  32. import com.fdkankan.common.response.ResultData;
  33. import com.fdkankan.fyun.oss.UploadToOssUtil;
  34. import com.fdkankan.scene.vo.SceneVO;
  35. import com.fdkankan.scene.vo.UserParamVO;
  36. import com.google.common.collect.Lists;
  37. import lombok.extern.slf4j.Slf4j;
  38. import net.coobird.thumbnailator.Thumbnails;
  39. import org.apache.commons.lang3.StringUtils;
  40. import org.springframework.beans.factory.annotation.Autowired;
  41. import org.springframework.beans.factory.annotation.Qualifier;
  42. import org.springframework.beans.factory.annotation.Value;
  43. import org.springframework.stereotype.Service;
  44. import org.springframework.util.ObjectUtils;
  45. import org.springframework.web.bind.annotation.RequestBody;
  46. import org.springframework.web.multipart.MultipartFile;
  47. import java.io.File;
  48. import java.io.InputStream;
  49. import java.io.PrintWriter;
  50. import java.io.StringWriter;
  51. import java.net.HttpURLConnection;
  52. import java.net.URL;
  53. import java.util.*;
  54. import java.util.stream.Collectors;
  55. /**
  56. * <p>
  57. * pro场景表 服务实现类
  58. * </p>
  59. *
  60. * @author dengsixing
  61. * @since 2021-12-23
  62. */
  63. @Slf4j
  64. @Service
  65. public class SceneProAppServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro> implements ISceneProAppService {
  66. @Value("${oss.type}")
  67. private String type;
  68. @Value("${oss.prefix.ali}")
  69. private String prefixAli;
  70. @Value("${hot.domain.list}")
  71. private String hotDomainList;
  72. @Value("${hot.delete}")
  73. private String hotDelete;
  74. @Autowired
  75. ISceneProService sceneProService;
  76. @Autowired
  77. @Qualifier("uploadToOssUtil")
  78. UploadToOssUtil uploadToOssUtil;
  79. @Autowired
  80. ISceneProEditService sceneProEditService;
  81. @Autowired
  82. RedisLockUtil redisLockUtil;
  83. @Autowired
  84. ISceneProEditExtService sceneProEditExtService;
  85. @Autowired
  86. private PlatformGoodsClient platformGoodsClient;
  87. @Autowired
  88. private PlatformUserClient platformUserClient;
  89. @Autowired
  90. private ISceneCooperationService sceneCooperationService;
  91. @Override
  92. public ResultData saveInitialPage(SceneEditVO base) throws Exception {
  93. if(StringUtils.isEmpty(base.getSceneNum()) || StringUtils.isEmpty(base.getInitialPoint())){
  94. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  95. }
  96. ScenePro scenePro = baseMapper.findByNum(base.getSceneNum());
  97. if(Objects.isNull(scenePro)){
  98. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  99. }
  100. SceneProEdit sceneProEdit= sceneProEditService.findByProId(scenePro.getId());
  101. StringBuffer dataBuf = new StringBuffer()
  102. .append("data").append(File.separator)
  103. .append("data").append(scenePro.getSceneCode())
  104. .append(File.separator);
  105. StringBuffer imagesBuf = new StringBuffer()
  106. .append("images").append(File.separator)
  107. .append("images").append(scenePro.getSceneCode())
  108. .append(File.separator);
  109. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  110. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  111. String path1 = imagesBuffer.toString() + "thumbBigImg.jpg";
  112. String path2 = imagesBuffer.toString() + "thumbSmallImg.jpg";
  113. //生成缩略图
  114. //按指定大小把图片进行缩和放(会遵循原图高宽比例)
  115. //此处把图片压成1024×512的缩略图
  116. Thumbnails.of(path1).size(1024,512).toFile(path2);//变为1024×512
  117. Map map = new HashMap();
  118. map.put("entry", JSONObject.parseObject(base.getInitialPoint()));
  119. map.put("thumbImg", 1);
  120. map.put("version", sceneProEdit.getVersion()+1);
  121. FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map);
  122. Map<String,String> uploadMap = new HashMap<String,String>();
  123. uploadMap.put(imagesBuffer.toString() + "thumbBigImg.jpg", imagesBuf.toString() + "thumbBigImg.jpg");
  124. uploadMap.put(imagesBuffer.toString() + "thumbFishBigImg.jpg", imagesBuf.toString() + "thumbFishBigImg.jpg");
  125. uploadMap.put(imagesBuffer.toString() + "thumbSmallImg.jpg", imagesBuf.toString() + "thumbSmallImg.jpg");
  126. uploadMap.put(imagesBuffer.toString() + "smallPic.jpg", imagesBuf.toString() + "smallPic.jpg");
  127. uploadMap.put(dataBuffer.toString() + "scene.json", dataBuf.toString() + "scene.json");
  128. uploadToOssUtil.uploadMulFiles(uploadMap);
  129. sceneProEdit.setEntry(base.getInitialPoint());
  130. sceneProEdit.setThumbStatus(1);
  131. sceneProEdit.setVersion(sceneProEdit.getVersion() + 1);
  132. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  133. sceneProEditService.updateById(sceneProEdit);
  134. scenePro.setThumb(prefixAli + imagesBuf.toString() + "thumbSmallImg.jpg");
  135. if("s3".equals(type)){
  136. scenePro.setThumb(ConstantUrl.PREFIX_AWS + imagesBuf.toString() + "thumbSmallImg.jpg");
  137. }
  138. sceneProService.updateById(scenePro);
  139. return ResultData.ok();
  140. }
  141. @Override
  142. public ResultData saveFloorLogo(SceneEditVO base) throws Exception {
  143. if(StrUtil.isEmpty(base.getSceneNum()) || StrUtil.isEmpty(base.getSize()) ||
  144. StrUtil.isEmpty(base.getLogoType())){
  145. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  146. }
  147. ScenePro scenePro = baseMapper.findByNum(base.getSceneNum());
  148. if(scenePro == null){
  149. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  150. }
  151. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  152. StringBuffer dataBuf = new StringBuffer()
  153. .append("data").append(File.separator)
  154. .append("data").append(scenePro.getSceneCode())
  155. .append(File.separator);
  156. StringBuffer imagesBuf = new StringBuffer()
  157. .append("images").append(File.separator)
  158. .append("images").append(scenePro.getSceneCode())
  159. .append(File.separator);
  160. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  161. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  162. Map map = new HashMap();
  163. map.put("floorLogo", base.getLogoType());
  164. map.put("floorLogoSize", base.getSize());
  165. map.put("version", sceneProEdit.getVersion()+1);
  166. FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map);
  167. sceneProEdit.setFloorLogo(base.getLogoType());
  168. sceneProEdit.setFloorLogoSize(Integer.parseInt(base.getSize()));
  169. sceneProEdit.setVersion(sceneProEdit.getVersion() + 1);
  170. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  171. sceneProEditService.updateById(sceneProEdit);
  172. uploadToOssUtil.upload(imagesBuffer.toString() + "floorLogoImg.png", imagesBuf.toString() + "floorLogoImg.png");
  173. uploadToOssUtil.upload(dataBuffer.toString() + "scene.json", dataBuf.toString() + "scene.json");
  174. return ResultData.ok();
  175. }
  176. @Override
  177. @SuppressWarnings("unchecked")
  178. public ResultData saveHot(SceneEditVO base) throws Exception {
  179. if(StrUtil.isEmpty(base.getType())){
  180. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  181. }
  182. ScenePro scenePro = baseMapper.findByNum(base.getSceneNum());
  183. if (scenePro == null ) {
  184. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  185. }
  186. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  187. log.info("hotData:" + base.getHotData());
  188. JSONObject jsonhot = JSONObject.parseObject(base.getHotData());
  189. StringBuffer dataBuf = new StringBuffer()
  190. .append("data").append(File.separator)
  191. .append("data").append(scenePro.getSceneCode())
  192. .append(File.separator);
  193. StringBuffer imagesBuf = new StringBuffer()
  194. .append("images").append(File.separator)
  195. .append("images").append(scenePro.getSceneCode())
  196. .append(File.separator);
  197. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  198. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  199. String sid = this.getSidFromParams(base, jsonhot);
  200. JSONArray jsonhots = this.getJsonhots(base, dataBuffer, jsonhot);
  201. //判断是否需要删除自定义热点样式
  202. String hotsids = this.deleteCustomStyleHots(base,jsonhots,jsonhot,sid);
  203. Object[] uploadFileMapAndSceneJson = this.getUploadFileMapAndSceneJson(base,jsonhots, jsonhot, sid, imagesBuf, imagesBuffer, dataBuf, dataBuffer);
  204. Map<String,String> map = (Map<String, String>) uploadFileMapAndSceneJson[0];
  205. JSONObject scenejson = (JSONObject) uploadFileMapAndSceneJson[1];
  206. uploadToOssUtil.uploadMulFiles(map);
  207. if(!StringUtils.isEmpty(base.getPlayData())){
  208. sceneProEdit.setPlayData(dataBuf.toString() + "playData.json");
  209. }
  210. if(!StringUtils.isEmpty(base.getScreencapThumb())){
  211. sceneProEdit.setScreencapThumb(dataBuf.toString() + "screencapThumb.json");
  212. }
  213. sceneProEdit.setHotsIds(hotsids);
  214. sceneProEdit.setVersion(sceneProEdit.getVersion() + 1);
  215. sceneProEditService.updateById(sceneProEdit);
  216. scenejson.put("version", sceneProEdit.getVersion() + 1);
  217. FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
  218. return ResultData.ok();
  219. }
  220. @Override
  221. public ResultData saveBackgroundMusic(SceneEditVO base) throws Exception {
  222. if(StringUtils.isEmpty(base.getSceneNum()) || StringUtils.isEmpty(base.getMusicName())){
  223. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  224. }
  225. ScenePro scenePro = baseMapper.findByNum(base.getSceneNum());
  226. if(scenePro == null){
  227. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  228. }
  229. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  230. StringBuffer dataBuf = new StringBuffer()
  231. .append("data").append(File.separator)
  232. .append("data").append(scenePro.getSceneCode())
  233. .append(File.separator);
  234. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  235. Map map = new HashMap();
  236. map.put("bgMusic", base.getMusicName());
  237. map.put("version", sceneProEdit.getVersion()+1);
  238. FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map);
  239. sceneProEdit.setBgMusic(base.getMusicName());
  240. sceneProEdit.setVersion(sceneProEdit.getVersion() + 1);
  241. sceneProEditService.updateById(sceneProEdit);
  242. return ResultData.ok();
  243. }
  244. @Override
  245. public ResultData saveSceneInfo(SceneEditVO base) throws Exception{
  246. if(StringUtils.isEmpty(base.getSceneNum()) || StringUtils.isEmpty(base.getSceneName()) ||
  247. StringUtils.isEmpty(base.getSceneType()) || StringUtils.isEmpty(base.getSceneDec())){
  248. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  249. }
  250. ScenePro scenePro = baseMapper.findByNum(base.getSceneNum());
  251. if(scenePro == null){
  252. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  253. }
  254. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  255. StringBuffer dataBuf = new StringBuffer()
  256. .append("data").append(File.separator)
  257. .append("data").append(scenePro.getSceneCode())
  258. .append(File.separator);
  259. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  260. Map map = new HashMap();
  261. map.put("sceneName", base.getSceneName());
  262. map.put("sceneDec", base.getSceneDec());
  263. if(StrUtil.isNotEmpty(base.getSceneType())){
  264. if(scenePro.getSceneType() == 99){
  265. map.put("sceneType", scenePro.getSceneType());
  266. }else {
  267. scenePro.setSceneType(Integer.parseInt(base.getSceneType()));
  268. map.put("sceneType", base.getSceneType());
  269. }
  270. }
  271. if(StrUtil.isNotEmpty(base.getSceneKey())) {
  272. map.put("sceneKey", base.getSceneKey());
  273. map.put("needKey", 1);
  274. sceneProEdit.setNeedKey(1);
  275. }else {
  276. sceneProEdit.setNeedKey(0);
  277. map.put("sceneKey", "");
  278. map.put("needKey", 0);
  279. }
  280. map.put("version", sceneProEdit.getVersion()+1);
  281. FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map);
  282. scenePro.setSceneName(base.getSceneName());
  283. scenePro.setSceneDec(base.getSceneDec());
  284. scenePro.setUpdateTime(Calendar.getInstance().getTime());
  285. this.updateById(scenePro);
  286. sceneProEdit.setSceneKey(base.getSceneKey());
  287. sceneProEdit.setVersion(sceneProEdit.getVersion() + 1);
  288. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  289. sceneProEditService.updateById(sceneProEdit);
  290. return ResultData.ok();
  291. }
  292. @Override
  293. public ResultData saveSceneKey(SceneEditVO base) throws Exception{
  294. if(StringUtils.isEmpty(base.getSceneNum()) || StringUtils.isEmpty(base.getSceneKey())){
  295. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  296. }
  297. ScenePro scenePro = baseMapper.findByNum(base.getSceneNum());
  298. if(scenePro == null){
  299. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  300. }
  301. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  302. StringBuffer dataBuf = new StringBuffer()
  303. .append("data").append(File.separator)
  304. .append("data").append(scenePro.getSceneCode())
  305. .append(File.separator);
  306. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  307. Map map = new HashMap();
  308. map.put("sceneKey", base.getSceneKey());
  309. map.put("needKey", 1);
  310. map.put("version", sceneProEdit.getVersion()+1);
  311. FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map);
  312. sceneProEdit.setSceneKey(base.getSceneKey());
  313. sceneProEdit.setNeedKey(1);
  314. sceneProEdit.setVersion(sceneProEdit.getVersion() + 1);
  315. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  316. sceneProEditService.updateById(sceneProEdit);
  317. return ResultData.ok();
  318. }
  319. @Override
  320. public ResultData saveTourList(SceneEditVO base) throws Exception{
  321. if(StringUtils.isEmpty(base.getSceneNum()) || StringUtils.isEmpty(base.getTourList())){
  322. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  323. }
  324. ScenePro scenePro = baseMapper.findByNum(base.getSceneNum());
  325. if(scenePro == null){
  326. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  327. }
  328. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  329. StringBuffer dataBuf = new StringBuffer()
  330. .append("data").append(File.separator)
  331. .append("data").append(scenePro.getSceneCode())
  332. .append(File.separator);
  333. StringBuffer imagesBuf = new StringBuffer()
  334. .append("images").append(File.separator)
  335. .append("images").append(scenePro.getSceneCode())
  336. .append(File.separator);
  337. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  338. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  339. Map<String,String> map = new HashMap<String,String>();
  340. log.info("editForApp/saveTourList:生成tourList.json文件");
  341. String tourListPath = dataBuffer.toString() + ConstantFileName.TOUR_LIST;
  342. FileUtils.writeFile(tourListPath, base.getTourList());
  343. map.put(tourListPath, dataBuf.toString() + ConstantFileName.TOUR_LIST);
  344. JSONArray tourJsons = JSONArray.parseArray(base.getTourList());
  345. String path = imagesBuffer.toString() + ConstantFileName.TOURLIST_FOLDER;
  346. for(int i=0;i<tourJsons.size();++i)
  347. {
  348. String fileName = path + File.separator +"guide"+i+".jpg";
  349. map.put(fileName, imagesBuf.toString() + ConstantFileName.TOURLIST_FOLDER+File.separator+"guide"+i+".jpg");
  350. }
  351. File file = new File(dataBuffer.toString() + ConstantFileName.TOURLIST_FOLDER);
  352. String[] strs = file.list();
  353. if(strs!=null) {
  354. int screencapLen = 0;
  355. for(int i=0;i<strs.length;++i){
  356. if(strs[i].indexOf(ConstantFileName.SCREEN_CRP_DATAFILE)<=-1)
  357. continue;
  358. map.put(dataBuffer.toString() + ConstantFileName.TOURLIST_FOLDER+File.separator+strs[i], dataBuf.toString() + ConstantFileName.TOURLIST_FOLDER+File.separator+strs[i]);
  359. ++screencapLen;
  360. }
  361. Map<String, Object> jsonMap = new HashMap();
  362. jsonMap.put("screenCapLen", screencapLen);
  363. jsonMap.put("version", sceneProEdit.getVersion() + 1);
  364. FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", jsonMap);
  365. sceneProEdit.setVersion(sceneProEdit.getVersion() + 1);
  366. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  367. sceneProEditService.updateById(sceneProEdit);
  368. }
  369. uploadToOssUtil.uploadMulFiles(map);
  370. return ResultData.ok();
  371. }
  372. @Override
  373. public ResultData uploadPic(String sceneNum, String folderName, MultipartFile file) throws Exception{
  374. if(StringUtils.isEmpty(sceneNum)){
  375. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  376. }
  377. ScenePro scenePro = baseMapper.findByNum(sceneNum);
  378. if(scenePro == null){
  379. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  380. }
  381. if (file.isEmpty() && file.getSize() <= 0) {
  382. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  383. }
  384. String lockKey = String.format(RedisLockKey.LOCK_UPLOAD_PRO_PIC, sceneNum);
  385. Boolean lock = redisLockUtil.lock(lockKey, RedisKey.EXPIRE_TIME_10_MINUTE);
  386. if(!lock){
  387. throw new BusinessException(ErrorCode.FAILURE_CODE_5036);
  388. }
  389. File targetFile = null;
  390. try {
  391. //文件上传的位置可以自定义
  392. String path = ConstantFilePath.SCENE_PATH+"images"+File.separator+"images"+sceneNum;
  393. if(StrUtil.isNotEmpty(folderName)) {
  394. path = path+File.separator + folderName;
  395. }
  396. targetFile = new File(path);
  397. if (!targetFile.exists()) {
  398. targetFile.mkdirs();
  399. }
  400. String fileName = file.getOriginalFilename();
  401. targetFile = new File(path + File.separator + fileName);
  402. // 保存
  403. if(targetFile.exists())
  404. {
  405. FileUtils.deleteFile(path + File.separator + fileName);
  406. }
  407. file.transferTo(targetFile);
  408. }catch (Exception e){
  409. log.error("上传图片失败", e);
  410. throw new BusinessException(ErrorCode.FAILURE_CODE_5037);
  411. }finally {
  412. redisLockUtil.unlock(lockKey);
  413. }
  414. return ResultData.ok(targetFile.getName());
  415. }
  416. @Override
  417. public ResultData uploadScreencapVoice(String sceneNum, MultipartFile file) throws Exception{
  418. if(StringUtils.isEmpty(sceneNum)){
  419. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  420. }
  421. ScenePro scenePro = baseMapper.findByNum(sceneNum);
  422. if(scenePro == null){
  423. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  424. }
  425. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  426. if (file.isEmpty() && file.getSize() <= 0) {
  427. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  428. }
  429. String lockKey = String.format(RedisLockKey.LOCK_UPLOAD_PRO_VOICE, sceneNum);
  430. Boolean lock = redisLockUtil.lock(lockKey, RedisKey.EXPIRE_TIME_30_MINUTE);
  431. if(!lock){
  432. throw new BusinessException(ErrorCode.FAILURE_CODE_5036);
  433. }
  434. String originalFileName = null;
  435. try {
  436. //文件上传的位置可以自定义
  437. String path = ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+sceneNum;
  438. File targetFile = new File(path);
  439. if (!targetFile.exists()) {
  440. targetFile.mkdirs();
  441. }
  442. originalFileName = file.getOriginalFilename();
  443. targetFile = new File(path + File.separator +originalFileName);
  444. // 保存
  445. synchronized(this) {
  446. if(targetFile.exists())
  447. {
  448. FileUtils.deleteFile(path + File.separator + originalFileName);
  449. }
  450. file.transferTo(targetFile);
  451. }
  452. uploadToOssUtil.upload(path + File.separator +originalFileName, "voice/voice"+sceneNum+"/"+originalFileName);
  453. Map map = new HashMap();
  454. map.put("screencapVoiceFileName", originalFileName);
  455. String voiceSrc = prefixAli + "voice/voice"+sceneNum+"/"+originalFileName;
  456. if("s3".equals(type)){
  457. voiceSrc = ConstantUrl.PREFIX_AWS + "voice/voice"+sceneNum+"/"+originalFileName;
  458. }
  459. map.put("screencapVoiceSrc", voiceSrc);
  460. map.put("screencapVoiceType", "file");
  461. map.put("version", sceneProEdit.getVersion()+1);
  462. FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + "/scene.json", map);
  463. sceneProEdit.setScreencapVoiceSrc(voiceSrc);
  464. sceneProEdit.setVersion(sceneProEdit.getVersion() + 1);
  465. sceneProEdit.setScreencapVoiceType("file");
  466. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  467. sceneProEditService.updateById(sceneProEdit);
  468. }catch (Exception e){
  469. log.error("上传图音频失败", e);
  470. throw new BusinessException(ErrorCode.FAILURE_CODE_5040);
  471. }finally {
  472. redisLockUtil.unlock(lockKey);
  473. }
  474. return ResultData.ok(originalFileName);
  475. }
  476. @Override
  477. public ResultData saveScreencapFile(SceneEditVO base) throws Exception{
  478. if(StringUtils.isEmpty(base.getSceneNum()) || StringUtils.isEmpty(base.getIndex()) ||
  479. StringUtils.isEmpty(base.getCamerasData())){
  480. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  481. }
  482. ScenePro scenePro = baseMapper.findByNum(base.getSceneNum());
  483. if(scenePro == null){
  484. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  485. }
  486. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  487. StringBuffer dataBuf = new StringBuffer()
  488. .append("data").append(File.separator)
  489. .append("data").append(scenePro.getSceneCode())
  490. .append(File.separator);
  491. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  492. if("1".equals(base.getIndex())){
  493. File file = new File(dataBuffer.toString() + ConstantFileName.TOURLIST_FOLDER);
  494. if(file.isDirectory()){
  495. String[] strs = file.list();
  496. if(strs!=null){
  497. for(int i=0;i<strs.length;++i) {
  498. if(strs[i].indexOf(ConstantFileName.SCREEN_CRP_DATAFILE)>-1) {
  499. FileUtils.deleteFile(dataBuffer.toString() + ConstantFileName.TOURLIST_FOLDER+File.separator+strs[i]);
  500. }
  501. }
  502. }
  503. } else {
  504. file.mkdirs();
  505. }
  506. Map<String, Object> map = new HashMap<>();
  507. map.put("screencapLen", "0");
  508. map.put("version", sceneProEdit.getVersion()+1);
  509. FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map);
  510. sceneProEdit.setVersion(sceneProEdit.getVersion() + 1);
  511. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  512. sceneProEditService.updateById(sceneProEdit);
  513. }
  514. String filePath = dataBuffer.toString() + ConstantFileName.TOURLIST_FOLDER+File.separator+ConstantFileName.SCREEN_CRP_DATAFILE+base.getIndex()+"json";
  515. File file = new File(filePath);
  516. if(!file.exists())
  517. {
  518. file.createNewFile();
  519. }
  520. FileUtils.writeFile(filePath, base.getCamerasData());
  521. return ResultData.ok();
  522. }
  523. @Override
  524. public ResultData saveHotVisible(SceneEditVO base) throws Exception{
  525. if(StringUtils.isEmpty(base.getData())){
  526. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  527. }
  528. ScenePro scenePro = baseMapper.findByNum(base.getSceneNum());
  529. if(scenePro == null){
  530. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  531. }
  532. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  533. JSONArray visiblePanos = JSONArray.parseArray(base.getData());
  534. StringBuffer dataBuf = new StringBuffer()
  535. .append("data").append(File.separator)
  536. .append("data").append(scenePro.getSceneCode())
  537. .append(File.separator);
  538. StringBuffer imagesBuf = new StringBuffer()
  539. .append("images").append(File.separator)
  540. .append("images").append(scenePro.getSceneCode())
  541. .append(File.separator);
  542. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  543. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  544. File file = new File(dataBuffer.toString() + "hot.json");
  545. if (!file.exists()) {
  546. throw new BusinessException(ErrorCode.FAILURE_CODE_3018);
  547. }
  548. String str = FileUtils.readFile(dataBuffer.toString() + "hot.json");
  549. JSONArray hots = JSONArray.parseArray(str);
  550. for (int i = 0; i < hots.size(); ++i) {
  551. JSONObject hot = hots.getJSONObject(i);
  552. for (int j = 0; j < visiblePanos.size(); ++j) {
  553. if (hot.getString("sid").equals(((JSONObject) visiblePanos.get(j)).getString("sid"))) {
  554. hot.put("visiblePanos", ((JSONObject) visiblePanos.get(j)).getJSONArray("value"));
  555. }
  556. }
  557. }
  558. sceneProEdit.setVersion(sceneProEdit.getVersion() + 1);
  559. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  560. sceneProEditService.updateById(sceneProEdit);
  561. FileUtils.deleteFile(dataBuffer.toString() + "hot.json");
  562. FileUtils.writeFile(dataBuffer.toString() + "hot.json", hots.toString());
  563. uploadToOssUtil.upload(dataBuffer.toString() + "hot.json", dataBuf.toString() + "hot.json");
  564. return ResultData.ok();
  565. }
  566. @Override
  567. public ResultData saveLinkPano(SceneEditVO base) throws Exception{
  568. if(StringUtils.isEmpty(base.getData()) || StringUtils.isEmpty(base.getSceneNum())){
  569. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  570. }
  571. ScenePro scenePro = baseMapper.findByNum(base.getSceneNum());
  572. if(scenePro == null){
  573. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  574. }
  575. JSONArray inputData = JSONObject.parseArray(base.getData());
  576. StringBuffer dataBuf = new StringBuffer()
  577. .append("data").append(File.separator)
  578. .append("data").append(scenePro.getSceneCode())
  579. .append(File.separator);
  580. StringBuffer imagesBuf = new StringBuffer()
  581. .append("images").append(File.separator)
  582. .append("images").append(scenePro.getSceneCode())
  583. .append(File.separator);
  584. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  585. File directory = new File(dataBuffer.toString());
  586. if (!directory.exists()) {
  587. directory.mkdirs();
  588. }
  589. JSONArray inputdata = JSONArray.parseArray(base.getData());
  590. String modeldataUrl = prefixAli + imagesBuf.toString() + "vision.modeldata?t=" + System.currentTimeMillis();
  591. if("s3".equals(type)){
  592. modeldataUrl = ConstantUrl.PREFIX_AWS + imagesBuf.toString() + "vision.modeldata?t=" + System.currentTimeMillis();
  593. }
  594. FileUtils.downLoadFromUrl(modeldataUrl, "vision.modeldata", dataBuffer.toString());
  595. File file = new File(dataBuffer.toString() + "vision.modeldata");
  596. if(!file.exists()) {
  597. return ResultData.error(ErrorCode.FAILURE_CODE_5012);
  598. }
  599. ConvertUtils.convertVisionModelDataToTxt(dataBuffer.toString() + "vision.modeldata", dataBuffer.toString() + "vision.json");
  600. String str = FileUtils.readFile(dataBuffer.toString() + "vision.json");
  601. JSONObject json = JSONObject.parseObject(str);
  602. JSONArray panos = json.getJSONArray("sweepLocations");
  603. for (int i = 0; i < panos.size(); ++i) {
  604. JSONObject pano = panos.getJSONObject(i);
  605. for (int j = 0; j < inputData.size(); ++j) {
  606. JSONObject jo = inputData.getJSONObject(j);
  607. String currentPanoId = jo.getString("panoID");
  608. JSONArray visibles = jo.getJSONArray("visibles");
  609. JSONArray visibles3 = jo.getJSONArray("visibles3");
  610. if (pano.getString("uuid").equals(currentPanoId)) {
  611. pano.put("visibles", visibles);
  612. pano.put("visibles3", visibles3);
  613. }
  614. }
  615. }
  616. FileUtils.deleteFile(dataBuffer.toString() + "vision.json");
  617. FileUtils.deleteFile(dataBuffer.toString() + "vision.modeldata");
  618. FileUtils.writeFile(dataBuffer.toString() + "vision.json", json.toString());
  619. ConvertUtils.convertTxtToVisionModelData(dataBuffer.toString() + "vision.json", dataBuffer.toString() + "vision.modeldata");
  620. uploadToOssUtil.upload(dataBuffer.toString() + "vision.modeldata", imagesBuf.toString() + "vision.modeldata");
  621. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  622. JSONObject scenejson = new JSONObject();
  623. if(strsceneInfos!=null){
  624. scenejson = JSONObject.parseObject(strsceneInfos);
  625. }
  626. scenejson.put("version", scenejson.getIntValue("version") + 1);
  627. FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
  628. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  629. if (sceneProEdit == null ) {
  630. return ResultData.error(ErrorCode.FAILURE_CODE_5005);
  631. }
  632. sceneProEdit.setVersion(scenejson.getIntValue("version") + 1);
  633. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  634. sceneProEditService.updateById(sceneProEdit);
  635. return ResultData.ok();
  636. }
  637. @Override
  638. public ResultData getRecordAudioFromWeixin(SceneEditVO base) throws Exception{
  639. if(StringUtils.isEmpty(base.getSceneNum()) || StringUtils.isEmpty(base.getId())){
  640. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  641. }
  642. ScenePro scenePro = baseMapper.findByNum(base.getSceneNum());
  643. if(scenePro == null){
  644. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  645. }
  646. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  647. String accessToken = WeiXinUtils.getAccessToken();
  648. InputStream is = null;
  649. String url = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token="+ accessToken + "&media_id=" + base.getId();
  650. URL urlGet = new URL(url);
  651. HttpURLConnection http = (HttpURLConnection) urlGet
  652. .openConnection();
  653. http.setRequestMethod("GET"); // 必须是get方式请求
  654. http.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
  655. http.setDoOutput(true);
  656. http.setDoInput(true);
  657. System.setProperty("sun.net.client.defaultConnectTimeout", "30000");// 连接超时30秒
  658. System.setProperty("sun.net.client.defaultReadTimeout", "30000"); // 读取超时30秒
  659. http.connect();
  660. // 获取文件转化为byte流
  661. is = http.getInputStream();
  662. File dic = new File(ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+base.getSceneNum());
  663. if(!dic.exists())
  664. {
  665. dic.mkdirs();
  666. }
  667. File voice = new File(ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+base.getSceneNum()+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr");
  668. if(voice.exists())
  669. {
  670. FileUtils.deleteFile(ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+base.getSceneNum()+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr");
  671. }
  672. FileUtils.saveImageToDisk( accessToken, base.getId(), ConstantFileName.WECHAT_VOICE_NAME, ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+base.getSceneNum()+File.separator, is);
  673. try
  674. {
  675. FileUtils.changeVoiceToMp3(ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+base.getSceneNum()+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr",
  676. ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+base.getSceneNum()+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".mp3");
  677. }
  678. catch(Exception e)
  679. {
  680. StringWriter trace=new StringWriter();
  681. e.printStackTrace(new PrintWriter(trace));
  682. log.error("voice:"+ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+base.getSceneNum()+File.separator+ConstantFileName.VOICE_NAME+".amr");
  683. log.error(trace.toString());
  684. return ResultData.error(ErrorCode.FAILURE_CODE_5005);
  685. }
  686. String originalFileName = ConstantFileName.WECHAT_VOICE_NAME+".mp3";
  687. uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+base.getSceneNum()+File.separator +originalFileName, "voice/voice"+base.getSceneNum()+"/"+originalFileName);
  688. Map map = new HashMap();
  689. map.put("screencapVoiceSoundsyncFileName", originalFileName);
  690. String voiceSrc = prefixAli+"voice/voice"+base.getSceneNum()+"/"+originalFileName;
  691. if("s3".equals(type)){
  692. voiceSrc = ConstantUrl.PREFIX_AWS+"voice/voice"+base.getSceneNum()+"/"+originalFileName;
  693. }
  694. map.put("screencapVoiceSoundsync", voiceSrc);
  695. log.info("微信上传的音频路径:{}", voiceSrc);
  696. map.put("screencapVoiceType", "soundsync");
  697. map.put("version", sceneProEdit.getVersion()+1);
  698. FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + base.getSceneNum() + "/scene.json", map);
  699. sceneProEdit.setScreencapVoiceType("soundsync");
  700. sceneProEdit.setScreencapVoiceSoundsync(voiceSrc);
  701. sceneProEdit.setVersion(sceneProEdit.getVersion());
  702. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  703. sceneProEditService.updateById(sceneProEdit);
  704. FileUtils.deleteFile(ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+base.getSceneNum()+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr");
  705. if("s3".equals(type)){
  706. return ResultData.ok(ConstantUrl.PREFIX_AWS+"voice/voice"+base.getSceneNum()+"/"+originalFileName);
  707. }
  708. return ResultData.ok(prefixAli+"voice/voice"+base.getSceneNum()+"/"+originalFileName);
  709. }
  710. @Override
  711. public ResultData getRecordAudioFromWeixinV3(String sceneNum, String id, String type, String fileName, String length, String replace, String times, String index) throws Exception {
  712. if(StringUtils.isEmpty(sceneNum) || StringUtils.isEmpty(id)){
  713. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  714. }
  715. ScenePro scenePro = baseMapper.findByNum(sceneNum);
  716. if(scenePro == null){
  717. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  718. }
  719. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  720. String strsceneInfos = FileUtils.readFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json");
  721. JSONObject scenejson = new JSONObject();
  722. if(strsceneInfos!=null) {
  723. scenejson = JSONObject.parseObject(strsceneInfos);
  724. }
  725. //文件上传的位置可以自定义
  726. String path = ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+sceneNum;
  727. log.info("path:" + path);
  728. this.saveImageToDisk(path, id);
  729. try
  730. {
  731. FileUtils.changeVoiceToMp3(path+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr",
  732. path+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".mp3");
  733. }
  734. catch(Exception e)
  735. {
  736. StringWriter trace=new StringWriter();
  737. e.printStackTrace(new PrintWriter(trace));
  738. log.error("voice:"+path+File.separator+ConstantFileName.VOICE_NAME+".amr");
  739. log.error(trace.toString());
  740. return ResultData.error(ErrorCode.FAILURE_CODE_5005);
  741. }
  742. String originalFileName = ConstantFileName.WECHAT_VOICE_NAME+".mp3";
  743. //判断分房间模块文件夹是否存在
  744. String partPath = path + File.separator + "part";
  745. File partFile = new File(partPath);
  746. if(!partFile.exists()){
  747. partFile.mkdirs();
  748. }
  749. if(!"1".equals(replace)){
  750. return ResultData.ok(this.replaceForWeixinV3(sceneProEdit, scenejson,
  751. path, partPath, fileName, originalFileName, sceneNum, times));
  752. }
  753. FileUtils.delAllFile(path + File.separator + "part");
  754. //保存0.mp3文件到part
  755. FileUtils.changeVoiceToMp3(path+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr",
  756. partPath+File.separator+fileName);
  757. FileUtils.copyFile(partPath+File.separator+fileName, path + File.separator + originalFileName, true);
  758. uploadToOssUtil.upload(path+File.separator +originalFileName, "voice/voice"+sceneNum+"/"+originalFileName);
  759. String voiceSrc = prefixAli+"voice/voice"+sceneNum+"/"+originalFileName;
  760. if("s3".equals(this.type)){
  761. voiceSrc = ConstantUrl.PREFIX_AWS+"voice/voice"+sceneNum+"/"+originalFileName;
  762. }
  763. sceneProEdit.setScreencapVoiceType("soundsync");
  764. sceneProEdit.setScreencapVoiceSoundsync(voiceSrc);
  765. sceneProEdit.setVersion(scenejson.getIntValue("version")+1);
  766. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  767. sceneProEditService.updateById(sceneProEdit);
  768. Map map = new HashMap();
  769. map.put("screencapVoiceSoundsyncFileName", originalFileName);
  770. map.put("screencapVoiceSoundsync", voiceSrc);
  771. map.put("uploadVoiceSoundsync", 1);
  772. map.put("screencapVoiceType", type);
  773. map.put("version", scenejson.getIntValue("version")+1);
  774. FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map);
  775. FileUtils.deleteFile(path+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr");
  776. return ResultData.ok(voiceSrc);
  777. }
  778. @Override
  779. public ResultData getRecordAudioFromAppV3(String sceneNum, String soundFile, String type, String fileName, String length, String replace, String times, String index) throws Exception {
  780. if(StringUtils.isEmpty(sceneNum) || StringUtils.isEmpty(soundFile)){
  781. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  782. }
  783. ScenePro scenePro = baseMapper.findByNum(sceneNum);
  784. if(scenePro == null){
  785. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  786. }
  787. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  788. String strsceneInfos = FileUtils.readFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json");
  789. JSONObject scenejson = new JSONObject();
  790. if(strsceneInfos!=null) {
  791. scenejson = JSONObject.parseObject(strsceneInfos);
  792. }
  793. String originalFileName = ConstantFileName.APP_VOICE_NAME+".mp3";
  794. //文件上传的位置可以自定义
  795. String path = ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+sceneNum;
  796. //判断分房间模块文件夹是否存在
  797. String partPath = path + File.separator + "part";
  798. File partFile = new File(partPath);
  799. if(!partFile.exists()){
  800. partFile.mkdirs();
  801. }
  802. if(!"1".equals(replace)){
  803. return ResultData.ok(this.replaceForAppV3(sceneProEdit, scenejson,
  804. path, partPath, fileName, originalFileName, sceneNum, times, soundFile));
  805. }
  806. FileUtils.delAllFile(path + File.separator + "part");
  807. if("s3".equals(this.type)){
  808. CreateObjUtil.ossFileCp("voice"+File.separator+"voice"+sceneNum + "/" + soundFile, partPath + File.separator + fileName);
  809. }else {
  810. CreateObjUtil.ossUtilCp("voice"+File.separator+"voice"+sceneNum + "/" + soundFile, partPath + File.separator);
  811. new File(partPath + File.separator + soundFile).renameTo(new File(partPath + File.separator + fileName));
  812. }
  813. FileUtils.copyFile(partPath+File.separator+fileName, path + File.separator + originalFileName, true);
  814. uploadToOssUtil.upload(path+File.separator +originalFileName, "voice/voice"+sceneNum+"/"+originalFileName);
  815. String voiceSrc = prefixAli+"voice/voice"+sceneNum+"/"+originalFileName;
  816. if("s3".equals(this.type)){
  817. voiceSrc = ConstantUrl.PREFIX_AWS+"voice/voice"+sceneNum+"/"+originalFileName;
  818. }
  819. sceneProEdit.setScreencapVoiceType("soundsync");
  820. sceneProEdit.setScreencapVoiceSoundsync(voiceSrc);
  821. sceneProEdit.setVersion(scenejson.getIntValue("version")+1);
  822. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  823. sceneProEditService.updateById(sceneProEdit);
  824. Map map = new HashMap();
  825. map.put("screencapVoiceSoundsyncFileName", originalFileName);
  826. map.put("screencapVoiceSoundsync", voiceSrc);
  827. map.put("uploadVoiceSoundsync", 1);
  828. map.put("screencapVoiceType", type);
  829. map.put("version", scenejson.getIntValue("version")+1);
  830. FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map);
  831. FileUtils.deleteFile(path+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr");
  832. return ResultData.ok(voiceSrc);
  833. }
  834. @Override
  835. public ResultData deleteRecordAudioPart(String sceneNum, String fileName, String times, String index, String type) throws Exception {
  836. if(StringUtils.isEmpty(sceneNum)){
  837. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  838. }
  839. ScenePro scenePro = baseMapper.findByNum(sceneNum);
  840. if(scenePro == null){
  841. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  842. }
  843. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  844. //文件上传的位置可以自定义
  845. String path = ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+sceneNum;
  846. File targetFile = new File(path);
  847. if (!targetFile.exists()) {
  848. targetFile.mkdirs();
  849. }
  850. //默认为app文件名
  851. String originalFileName = ConstantFileName.APP_VOICE_NAME + ".mp3";
  852. if("wechat".equals(type)){
  853. originalFileName = ConstantFileName.WECHAT_VOICE_NAME + ".mp3";
  854. }
  855. log.info("上传的音频文件名:" + originalFileName);
  856. String strsceneInfos = FileUtils.readFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json");
  857. JSONObject scenejson = new JSONObject();
  858. if(strsceneInfos!=null) {
  859. scenejson = JSONObject.parseObject(strsceneInfos);
  860. }
  861. //判断分房间模块文件夹是否存在
  862. String partPath = path + File.separator + "part";
  863. File partFile = new File(partPath);
  864. if(!partFile.exists()){
  865. partFile.mkdirs();
  866. }
  867. //删除指定部分音频文件
  868. FileUtils.deleteFile(partPath + File.separator + index + ".mp3");
  869. //获取总音频多少段,每段时长
  870. String[] time = times.split(",");
  871. //删除所有音频
  872. if(StringUtils.isEmpty(times) || time.length == 0){
  873. this.deleteAudio(sceneProEdit, scenejson, sceneNum);
  874. return ResultData.ok();
  875. }
  876. //修改删除的部分视频后面部分音频名字,如删除1.MP3,则将2.mp3修改成1.mp3,往后以此类推
  877. if(Integer.parseInt(index) < time.length) {
  878. for(int i = 0, len = time.length - Integer.parseInt(index); i < len; i++){
  879. if(new File(partPath + File.separator + (Integer.parseInt(index) + 1 + i) + ".mp3").exists()){
  880. FileUtils.copyFile(partPath + File.separator + (Integer.parseInt(index) + 1 + i) + ".mp3",
  881. partPath + File.separator + (Integer.parseInt(index) + i) + ".mp3", true);
  882. }
  883. }
  884. }
  885. //遍历判断音频是否存在,不存在生成空白音效
  886. for(int i = 0, len = time.length; i < len; i++){
  887. if(!new File(partPath + File.separator + i + ".mp3").exists()){
  888. //某部分文件不存在,直接生成一段静音后拼接文件
  889. CreateObjUtil.createMuteViode(Double.valueOf(time[i]), partPath + File.separator + i + ".mp3");
  890. }
  891. }
  892. //拼接所有音频文件
  893. if(time.length > 2){
  894. //若是多部分,两个两个合并,最后合成最终文件
  895. for(int i = 1, len = time.length; i < len; i++){
  896. if(i == 1){
  897. CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + ".mp3", partPath + File.separator + i + ".mp3",
  898. partPath + File.separator + i + "muteSound.mp3");
  899. }else if(i == len - 1){
  900. CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + "muteSound.mp3", partPath + File.separator + i + ".mp3",
  901. path + File.separator + originalFileName);
  902. }else {
  903. CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + "muteSound.mp3", partPath + File.separator + i + ".mp3",
  904. partPath + File.separator + i + "muteSound.mp3");
  905. }
  906. }
  907. }else if(time.length == 2){
  908. //若只有两部分,直接合并成最终文件
  909. CreateObjUtil.mergeVideo(partPath + File.separator + "0.mp3", partPath + File.separator + "1.mp3", path + File.separator + originalFileName);
  910. }else {
  911. FileUtils.copyFile(partPath + File.separator + "0.mp3", path + File.separator + originalFileName, true);
  912. }
  913. uploadToOssUtil.upload(path+File.separator +originalFileName, "voice/voice"+sceneNum+"/"+originalFileName);
  914. String voiceSrc = prefixAli+"voice/voice"+sceneNum+"/"+originalFileName;
  915. if("s3".equals(this.type)){
  916. voiceSrc = ConstantUrl.PREFIX_AWS+"voice/voice"+sceneNum+"/"+originalFileName;
  917. }
  918. Map map = new HashMap();
  919. map.put("screencapVoiceSoundsyncFileName", originalFileName);
  920. map.put("screencapVoiceSoundsync", voiceSrc);
  921. map.put("uploadVoiceSoundsync", 0);
  922. map.put("screencapVoiceType", "soundsync");
  923. map.put("version", scenejson.getIntValue("version")+1);
  924. sceneProEdit.setScreencapVoiceType("soundsync");
  925. sceneProEdit.setScreencapVoiceSoundsync(voiceSrc);
  926. sceneProEdit.setVersion(scenejson.getIntValue("version")+1);
  927. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  928. sceneProEditService.updateById(sceneProEdit);
  929. FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map);
  930. return ResultData.ok(voiceSrc);
  931. }
  932. @Override
  933. public ResultData uploadFloorJsonAndRebuild(SceneEditVO sceneEdit) throws Exception {
  934. String lockKey = String.format(RedisLockKey.LOCK_UPLOAD_FLOORJSON_REBUILD, sceneEdit.getSceneNum());
  935. Boolean lock = redisLockUtil.lock(lockKey, RedisKey.EXPIRE_TIME_2_HOUR);
  936. if(!lock){
  937. throw new BusinessException(ErrorCode.FAILURE_CODE_5036);
  938. }
  939. try {
  940. long start = System.currentTimeMillis();
  941. log.info("画墙重建模型开始时间:{}", start);
  942. if(StringUtils.isEmpty(sceneEdit.getSceneNum())){
  943. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  944. }
  945. ScenePro scenePro = baseMapper.findByNum(sceneEdit.getSceneNum());
  946. if(scenePro == null){
  947. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  948. }
  949. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  950. if(sceneProEdit == null){
  951. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  952. }
  953. //更新scene.json文件
  954. String strsceneInfos = FileUtils.readFile(ConstantFilePath.SCENE_PATH + "data" + File.separator + "data" + sceneEdit.getSceneNum() + File.separator + "scene.json");
  955. JSONObject scenejson = new JSONObject();
  956. if(strsceneInfos!=null)
  957. {
  958. scenejson = JSONObject.parseObject(strsceneInfos);
  959. }else {
  960. new File(ConstantFilePath.SCENE_PATH + "data" + File.separator + "data" + sceneEdit.getSceneNum() + File.separator + "scene.json").createNewFile();
  961. }
  962. if(!StringUtils.isEmpty(sceneEdit.getSceneData())){
  963. JSONObject sceneObject = JSONObject.parseObject(sceneEdit.getSceneData());
  964. Set<String> set =sceneObject.keySet();
  965. for(String key : set){
  966. scenejson.put(key, sceneObject.get(key));
  967. }
  968. }
  969. //保存floor.json前端下次进入需要使用
  970. if(StringUtils.isEmpty(sceneEdit.getWebFloor())){
  971. sceneEdit.setWebFloor(sceneEdit.getFloor());
  972. }
  973. //上传过模型只更新floor.json
  974. FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+sceneEdit.getSceneNum() + File.separator + "floor.json",
  975. new String(sceneEdit.getWebFloor().getBytes(), "UTF-8"));
  976. //更新scene.json文件
  977. if(strsceneInfos!=null)
  978. {
  979. scenejson.put("floorEditVer", sceneProEdit.getFloorPublishVer() + 1);
  980. scenejson.put("floorPublishVer", sceneProEdit.getFloorPublishVer() + 1);
  981. FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+sceneEdit.getSceneNum()+File.separator+"scene.json", scenejson.toString());
  982. log.info("写入scene.json文件完成, sceneCode:{}", sceneEdit.getSceneNum());
  983. }
  984. //floorEditVer字段增加1
  985. sceneProEdit.setFloorEditVer(sceneProEdit.getFloorPublishVer() + 1);
  986. sceneProEdit.setFloorPublishVer(sceneProEdit.getFloorPublishVer() + 1);
  987. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  988. sceneProEditService.updateById(sceneProEdit);
  989. uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+sceneEdit.getSceneNum() + File.separator + "floor.json",
  990. "data"+File.separator+"data"+sceneEdit.getSceneNum() + File.separator + "floor.json");
  991. }catch (Exception e){
  992. log.error("画墙重建模型失败...", e);
  993. throw new BusinessException(ErrorCode.FAILURE_CODE_5039);
  994. }finally {
  995. redisLockUtil.unlock(lockKey);
  996. }
  997. return ResultData.ok();
  998. }
  999. @Override
  1000. public ResultData saveScreencapData(SceneEditVO base) throws Exception {
  1001. if(StringUtils.isEmpty(base.getSceneNum())){
  1002. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  1003. }
  1004. ScenePro scenePro = baseMapper.findByNum(base.getSceneNum());
  1005. if(scenePro == null){
  1006. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1007. }
  1008. StringBuffer dataBuf = new StringBuffer()
  1009. .append("data").append(File.separator)
  1010. .append("data").append(scenePro.getSceneCode())
  1011. .append(File.separator);
  1012. StringBuffer imagesBuf = new StringBuffer()
  1013. .append("images").append(File.separator)
  1014. .append("images").append(scenePro.getSceneCode())
  1015. .append(File.separator);
  1016. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  1017. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  1018. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  1019. JSONObject scenejson = new JSONObject();
  1020. if(strsceneInfos!=null) {
  1021. scenejson = JSONObject.parseObject(strsceneInfos);
  1022. }
  1023. //上传七牛
  1024. Map<String,String> map = new HashMap<String,String>();
  1025. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  1026. scenejson.put("screencapVoiceSound", "");
  1027. sceneProEdit.setScreencapVoiceSound("");
  1028. if(base.getScreencapVoiceType() != null){
  1029. scenejson.put("screencapVoiceType", base.getScreencapVoiceType());
  1030. sceneProEdit.setScreencapVoiceType(base.getScreencapVoiceType());
  1031. }
  1032. if(!StringUtils.isEmpty(base.getCapData())){
  1033. FileUtils.writeFile(dataBuffer.toString() + "capData.json", new String(base.getCapData().getBytes(), "UTF-8"));
  1034. scenejson.put("capData", dataBuf.toString() + "capData.json");
  1035. }
  1036. if(!StringUtils.isEmpty(base.getFrameData())){
  1037. FileUtils.writeFile(dataBuffer.toString() + "frameData.json", new String(base.getFrameData().getBytes(), "UTF-8"));
  1038. scenejson.put("frameData", dataBuf.toString() + "frameData.json");
  1039. }
  1040. if(!StringUtils.isEmpty(base.getPlayData())){
  1041. FileUtils.writeFile(dataBuffer.toString() + "playData.json", new String(base.getPlayData().getBytes(), "UTF-8"));
  1042. scenejson.put("playData", dataBuf.toString() + "playData.json");
  1043. sceneProEdit.setPlayData(dataBuf.toString() + "playData.json");
  1044. map.put(dataBuffer.toString() + "playData.json", dataBuf.toString() + "playData.json");
  1045. }
  1046. if(!StringUtils.isEmpty(base.getScreencapThumb())){
  1047. FileUtils.writeFile(dataBuffer.toString() + "screencapThumb.json", new String(base.getScreencapThumb().getBytes(), "UTF-8"));
  1048. scenejson.put("screencapThumb", dataBuf.toString() + "screencapThumb.json");
  1049. sceneProEdit.setScreencapThumb(dataBuf.toString() + "screencapThumb.json");
  1050. map.put(dataBuffer.toString() + "screencapThumb.json", dataBuf.toString() + "screencapThumb.json");
  1051. }
  1052. if(!StringUtils.isEmpty(base.getRecordType())){
  1053. scenejson.put("recordType", base.getRecordType());
  1054. }
  1055. if(map.size()>0) {
  1056. uploadToOssUtil.uploadMulFiles(map);
  1057. }
  1058. sceneProEdit.setVersion(scenejson.getIntValue("version") + 1);
  1059. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  1060. sceneProEditService.updateById(sceneProEdit);
  1061. log.info("scene.json路径:" + dataBuffer.toString() + "scene.json");
  1062. scenejson.put("version", scenejson.getIntValue("version") + 1);
  1063. FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
  1064. return ResultData.ok();
  1065. }
  1066. public ResultData saveAllVisi(SceneEditVO base) throws Exception {
  1067. if(StrUtil.isEmpty(base.getSceneNum())){
  1068. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  1069. }
  1070. ScenePro scenePro = baseMapper.findByNum(base.getSceneNum());
  1071. if(scenePro == null){
  1072. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1073. }
  1074. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  1075. StringBuffer dataBuf = new StringBuffer()
  1076. .append("data").append(File.separator)
  1077. .append("data").append(scenePro.getSceneCode())
  1078. .append(File.separator);
  1079. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  1080. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  1081. JSONObject scenejson = new JSONObject();
  1082. if(strsceneInfos!=null) {
  1083. scenejson = JSONObject.parseObject(strsceneInfos);
  1084. }
  1085. this.updateVisiData(base, sceneProEdit, scenejson);
  1086. sceneProEdit.setVersion(scenejson.getIntValue("version") + 1);
  1087. scenejson.put("version", scenejson.getIntValue("version") + 1);
  1088. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  1089. sceneProEditService.updateById(sceneProEdit);
  1090. FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
  1091. return ResultData.ok();
  1092. }
  1093. @Override
  1094. public ResultData uploadFloorplanPng(String sceneNum, MultipartFile file, String cadInfo) throws Exception {
  1095. if(StringUtils.isEmpty(sceneNum)){
  1096. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  1097. }
  1098. if (file.isEmpty() && file.getSize() <= 0) {
  1099. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  1100. }
  1101. ScenePro scenePro = baseMapper.findByNum(sceneNum);
  1102. if(scenePro == null){
  1103. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1104. }
  1105. String lockKey = String.format(RedisLockKey.LOCK_UPLOAD_FLOORPLAN_PNG, sceneNum);
  1106. Boolean lock = redisLockUtil.lock(lockKey, RedisKey.EXPIRE_TIME_30_MINUTE);
  1107. if(!lock){
  1108. throw new BusinessException(ErrorCode.FAILURE_CODE_5036);
  1109. }
  1110. String fileName = "floorplan.png";
  1111. try {
  1112. StringBuffer dataBuf = new StringBuffer()
  1113. .append("data").append(File.separator)
  1114. .append("data").append(scenePro.getSceneCode())
  1115. .append(File.separator);
  1116. StringBuffer imagesBuf = new StringBuffer()
  1117. .append("images").append(File.separator)
  1118. .append("images").append(scenePro.getSceneCode())
  1119. .append(File.separator);
  1120. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  1121. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  1122. //文件上传的位置可以自定义
  1123. String path = ConstantFilePath.SCENE_PATH+"images"+File.separator+"images"+sceneNum;
  1124. File targetFile = new File(path);
  1125. if (!targetFile.exists()) {
  1126. targetFile.mkdirs();
  1127. }
  1128. targetFile = new File(path + File.separator + fileName);
  1129. // 保存
  1130. if(targetFile.exists())
  1131. {
  1132. FileUtils.deleteFile(path + File.separator + fileName);
  1133. }
  1134. file.transferTo(targetFile);
  1135. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  1136. SceneProEditExt sceneProEditExt = sceneProEditExtService.getOne(
  1137. new QueryWrapper<SceneProEditExt>().eq("pro_edit_id", sceneProEdit.getId()));
  1138. String floorPlanPng = "images"+File.separator+"images"+sceneNum + File.separator + fileName;
  1139. Map<String, Object> map = new HashMap<>();
  1140. map.put("floorPlanPng", floorPlanPng);
  1141. map.put("uploadFloorPlanPng", 1);
  1142. map.put("version", sceneProEdit.getVersion()+1);
  1143. if(StrUtil.isNotEmpty(cadInfo)){
  1144. map.put("cadInfo", cadInfo);
  1145. sceneProEditExt.setCadInfo(cadInfo);
  1146. }
  1147. sceneProEditExt.setFloorPlanPng(floorPlanPng + "?t=" + System.currentTimeMillis());
  1148. sceneProEditExt.setUpdateTime(Calendar.getInstance().getTime());
  1149. sceneProEditExtService.updateById(sceneProEditExt);
  1150. sceneProEdit.setVersion(sceneProEdit.getVersion() + 1);
  1151. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  1152. sceneProEditService.updateById(sceneProEdit);
  1153. FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map);
  1154. uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH+floorPlanPng, floorPlanPng);
  1155. }catch (Exception e){
  1156. log.error("上传图片多媒体数据失败...", e);
  1157. throw new BusinessException(ErrorCode.FAILURE_CODE_5041);
  1158. }finally {
  1159. redisLockUtil.unlock(lockKey);
  1160. }
  1161. return ResultData.ok("images"+File.separator+"images"+sceneNum + File.separator + fileName);
  1162. }
  1163. @Override
  1164. public ResultData uploadBgMusic(String sceneNum, String fileName, MultipartFile file) throws Exception {
  1165. if(StringUtils.isEmpty(sceneNum) || StringUtils.isEmpty(fileName)){
  1166. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  1167. }
  1168. ScenePro scenePro = baseMapper.findByNum(sceneNum);
  1169. if(scenePro == null){
  1170. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1171. }
  1172. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  1173. SceneProEditExt sceneProEditExt = sceneProEditExtService.getOne(
  1174. new QueryWrapper<SceneProEditExt>().eq("pro_edit_id", sceneProEdit.getId()));
  1175. StringBuffer dataBuf = new StringBuffer()
  1176. .append("data").append(File.separator)
  1177. .append("data").append(scenePro.getSceneCode())
  1178. .append(File.separator);
  1179. StringBuffer imagesBuf = new StringBuffer()
  1180. .append("images").append(File.separator)
  1181. .append("images").append(scenePro.getSceneCode())
  1182. .append(File.separator);
  1183. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  1184. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  1185. File buMusicFile = new File(imagesBuffer.toString() + fileName);
  1186. if(!buMusicFile.getParentFile().exists()){
  1187. buMusicFile.getParentFile().mkdirs();
  1188. }
  1189. //上传文件
  1190. file.transferTo(buMusicFile);
  1191. uploadToOssUtil.upload(imagesBuffer.toString() + fileName, imagesBuf + fileName);
  1192. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  1193. JSONObject scenejson = new JSONObject();
  1194. if(strsceneInfos!=null) {
  1195. scenejson = JSONObject.parseObject(strsceneInfos);
  1196. }
  1197. sceneProEditExt.setBgMusicName(fileName);
  1198. sceneProEditExt.setUpdateTime(Calendar.getInstance().getTime());
  1199. sceneProEditExtService.updateById(sceneProEditExt);
  1200. sceneProEdit.setVersion(scenejson.getIntValue("version") + 1);
  1201. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  1202. sceneProEditService.updateById(sceneProEdit);
  1203. scenejson.put("bgMusicName", fileName);
  1204. scenejson.put("uploadBgMusic", 0);
  1205. scenejson.put("version", scenejson.getIntValue("version") + 1);
  1206. FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
  1207. return ResultData.ok();
  1208. }
  1209. @Override
  1210. public ResultData deleteUploadBgMusic(String sceneNum) throws Exception {
  1211. if(StringUtils.isEmpty(sceneNum)){
  1212. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  1213. }
  1214. ScenePro scenePro = baseMapper.findByNum(sceneNum);
  1215. if(scenePro == null){
  1216. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1217. }
  1218. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  1219. SceneProEditExt sceneProEditExt = sceneProEditExtService.getOne(
  1220. new QueryWrapper<SceneProEditExt>().eq("pro_edit_id", sceneProEdit.getId()));
  1221. StringBuffer dataBuf = new StringBuffer()
  1222. .append("data").append(File.separator)
  1223. .append("data").append(scenePro.getSceneCode())
  1224. .append(File.separator);
  1225. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  1226. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  1227. JSONObject scenejson = new JSONObject();
  1228. if(strsceneInfos!=null) {
  1229. scenejson = JSONObject.parseObject(strsceneInfos);
  1230. }
  1231. sceneProEditExt.setBgMusicName("");
  1232. sceneProEditExt.setUpdateTime(Calendar.getInstance().getTime());
  1233. sceneProEditExtService.updateById(sceneProEditExt);
  1234. sceneProEdit.setVersion(scenejson.getIntValue("version") + 1);
  1235. sceneProEditService.updateById(sceneProEdit);
  1236. scenejson.put("bgMusicName", "");
  1237. scenejson.put("version", scenejson.getIntValue("version") + 1);
  1238. FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
  1239. return ResultData.ok();
  1240. }
  1241. private void updateVisiData(SceneEditVO base, SceneProEdit sceneProEdit, JSONObject scenejson){
  1242. SceneProEditExt sceneProEditExt = sceneProEditExtService.getOne(
  1243. new QueryWrapper<SceneProEditExt>().eq("pro_edit_id", sceneProEdit.getId()));
  1244. if(!StringUtils.isEmpty(base.getMapVisi())){
  1245. scenejson.put("mapVisi", Integer.parseInt(base.getMapVisi()));
  1246. sceneProEditExt.setMapVisi(Integer.parseInt(base.getMapVisi()));
  1247. }
  1248. if(!StringUtils.isEmpty(base.getTourVisi())){
  1249. scenejson.put("tourVisi", Integer.parseInt(base.getTourVisi()));
  1250. sceneProEditExt.setTourVisi(Integer.parseInt(base.getTourVisi()));
  1251. }
  1252. if(!StringUtils.isEmpty(base.getVrVisi())){
  1253. scenejson.put("vrVisi", Integer.parseInt(base.getVrVisi()));
  1254. sceneProEditExt.setVrVisi(Integer.parseInt(base.getVrVisi()));
  1255. }
  1256. if(!StringUtils.isEmpty(base.getRulerVisi())){
  1257. scenejson.put("rulerVisi", Integer.parseInt(base.getRulerVisi()));
  1258. sceneProEditExt.setRulerVisi(Integer.parseInt(base.getRulerVisi()));
  1259. }
  1260. if(!StringUtils.isEmpty(base.getCadImgVisi())){
  1261. scenejson.put("cadImgVisi", Integer.parseInt(base.getCadImgVisi()));
  1262. sceneProEditExt.setCadImgVisi(Integer.parseInt(base.getCadImgVisi()));
  1263. }
  1264. if(!StringUtils.isEmpty(base.getPanoVisi())){
  1265. scenejson.put("panoVisi", Integer.parseInt(base.getPanoVisi()));
  1266. sceneProEditExt.setPanoVisi(Integer.parseInt(base.getPanoVisi()));
  1267. }
  1268. if(!StringUtils.isEmpty(base.getM2dVisi())){
  1269. scenejson.put("m2dVisi", Integer.parseInt(base.getM2dVisi()));
  1270. sceneProEditExt.setM2dVisi(Integer.parseInt(base.getM2dVisi()));
  1271. }
  1272. if(!StringUtils.isEmpty(base.getM3dVisi())){
  1273. scenejson.put("m3dVisi", Integer.parseInt(base.getM3dVisi()));
  1274. sceneProEditExt.setM3dVisi(Integer.parseInt(base.getM3dVisi()));
  1275. }
  1276. if(!StringUtils.isEmpty(base.getMeasureVisi())){
  1277. scenejson.put("measureVisi", Integer.parseInt(base.getMeasureVisi()));
  1278. sceneProEditExt.setMeasureVisi(Integer.parseInt(base.getMeasureVisi()));
  1279. }
  1280. sceneProEditExt.setUpdateTime(Calendar.getInstance().getTime());
  1281. sceneProEditExtService.updateById(sceneProEditExt);
  1282. }
  1283. private void deleteAudio(SceneProEdit sceneProEdit, JSONObject scenejson, String sceneNum) throws Exception {
  1284. sceneProEdit.setScreencapVoiceType("");
  1285. sceneProEdit.setScreencapVoiceSoundsync("");
  1286. sceneProEdit.setVersion(scenejson.getIntValue("version")+1);
  1287. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  1288. sceneProEditService.updateById(sceneProEdit);
  1289. Map map = new HashMap();
  1290. map.put("screencapVoiceSoundsyncFileName", "");
  1291. map.put("screencapVoiceSoundsync", "");
  1292. map.put("uploadVoiceSoundsync", 0);
  1293. map.put("screencapVoiceType", "");
  1294. map.put("version", scenejson.getIntValue("version")+1);
  1295. FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map);
  1296. }
  1297. private String replaceForAppV3(SceneProEdit sceneProEdit, JSONObject scenejson,
  1298. String path, String partPath, String fileName,
  1299. String originalFileName, String sceneNum, String times, String soundFile) throws Exception {
  1300. if(new File(partPath+File.separator+fileName).exists()) {
  1301. FileUtils.deleteFile(partPath + File.separator + fileName);
  1302. }
  1303. if("s3".equals(this.type)){
  1304. CreateObjUtil.ossFileCp("voice"+File.separator+"voice"+sceneNum + "/" + soundFile, partPath + File.separator + fileName);
  1305. }else {
  1306. CreateObjUtil.ossUtilCp("voice"+File.separator+"voice"+sceneNum + "/" + soundFile, partPath + File.separator);
  1307. new File(partPath + File.separator + soundFile).renameTo(new File(partPath + File.separator + fileName));
  1308. }
  1309. //获取总音频多少段,每段时长
  1310. String[] time = times.split(",");
  1311. //遍历判断音频是否存在,不存在生成空白音效
  1312. for(int i = 0, len = time.length; i < len; i++){
  1313. if(!new File(partPath + File.separator + i + ".mp3").exists()){
  1314. //某部分文件不存在,直接生成一段静音后拼接文件
  1315. CreateObjUtil.createMuteViode(Double.valueOf(time[i]), partPath + File.separator + i + ".mp3");
  1316. }
  1317. }
  1318. //拼接所有音频文件
  1319. if(time.length > 2){
  1320. //若是多部分,两个两个合并,最后合成最终文件
  1321. for(int i = 1, len = time.length; i < len; i++){
  1322. if(i == 1){
  1323. CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + ".mp3", partPath + File.separator + i + ".mp3",
  1324. partPath + File.separator + i + "muteSound.mp3");
  1325. }else if(i == len - 1){
  1326. CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + "muteSound.mp3", partPath + File.separator + i + ".mp3",
  1327. path + File.separator + originalFileName);
  1328. }else {
  1329. CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + "muteSound.mp3", partPath + File.separator + i + ".mp3",
  1330. partPath + File.separator + i + "muteSound.mp3");
  1331. }
  1332. }
  1333. }else {
  1334. //若只有两部分,直接合并成最终文件
  1335. CreateObjUtil.mergeVideo(partPath + File.separator + "0.mp3", partPath + File.separator + "1.mp3", path + File.separator + originalFileName);
  1336. }
  1337. uploadToOssUtil.upload(path+File.separator +originalFileName, "voice/voice"+sceneNum+"/"+originalFileName);
  1338. String voiceSrc = prefixAli+"voice/voice"+sceneNum+"/"+originalFileName;
  1339. if("s3".equals(this.type)){
  1340. voiceSrc = ConstantUrl.PREFIX_AWS+"voice/voice"+sceneNum+"/"+originalFileName;
  1341. }
  1342. sceneProEdit.setScreencapVoiceType("soundsync");
  1343. sceneProEdit.setScreencapVoiceSoundsync(voiceSrc);
  1344. sceneProEdit.setVersion(scenejson.getIntValue("version")+1);
  1345. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  1346. sceneProEditService.updateById(sceneProEdit);
  1347. Map map = new HashMap();
  1348. map.put("screencapVoiceSoundsyncFileName", originalFileName);
  1349. map.put("screencapVoiceSoundsync", voiceSrc);
  1350. map.put("uploadVoiceSoundsync", 1);
  1351. map.put("screencapVoiceType", type);
  1352. map.put("version", scenejson.getIntValue("version")+1);
  1353. FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map);
  1354. FileUtils.deleteFile(path+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr");
  1355. return voiceSrc;
  1356. }
  1357. private String replaceForWeixinV3(SceneProEdit sceneProEdit, JSONObject scenejson,
  1358. String path, String partPath, String fileName,
  1359. String originalFileName, String sceneNum, String times) throws Exception {
  1360. this.dealVioce(path, partPath, fileName, originalFileName, sceneNum, times);
  1361. String voiceSrc = prefixAli+"voice/voice"+sceneNum+"/"+originalFileName;
  1362. if("s3".equals(this.type)){
  1363. voiceSrc = ConstantUrl.PREFIX_AWS+"voice/voice"+sceneNum+"/"+originalFileName;
  1364. }
  1365. Map map = new HashMap();
  1366. map.put("screencapVoiceSoundsyncFileName", originalFileName);
  1367. map.put("screencapVoiceSoundsync", voiceSrc);
  1368. map.put("uploadVoiceSoundsync", 1);
  1369. map.put("screencapVoiceType", type);
  1370. map.put("version", scenejson.getIntValue("version")+1);
  1371. sceneProEdit.setScreencapVoiceType("soundsync");
  1372. sceneProEdit.setScreencapVoiceSoundsync(voiceSrc);
  1373. sceneProEdit.setVersion(scenejson.getIntValue("version")+1);
  1374. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  1375. sceneProEditService.updateById(sceneProEdit);
  1376. FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map);
  1377. FileUtils.deleteFile(path+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr");
  1378. return voiceSrc;
  1379. }
  1380. private void dealVioce(String path, String partPath, String fileName, String originalFileName, String sceneNum, String times) throws Exception {
  1381. if(new File(partPath+File.separator+fileName).exists()) {
  1382. FileUtils.deleteFile(partPath + File.separator + fileName);
  1383. }
  1384. FileUtils.changeVoiceToMp3(path+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr",
  1385. partPath+File.separator+fileName);
  1386. //获取总音频多少段,每段时长
  1387. String[] time = times.split(",");
  1388. //遍历判断音频是否存在,不存在生成空白音效
  1389. for(int i = 0, len = time.length; i < len; i++){
  1390. if(!new File(partPath + File.separator + i + ".mp3").exists()){
  1391. //某部分文件不存在,直接生成一段静音后拼接文件
  1392. CreateObjUtil.createMuteViode(Double.valueOf(time[i]), partPath + File.separator + i + ".mp3");
  1393. }
  1394. }
  1395. //拼接所有音频文件
  1396. if(time.length > 2){
  1397. //若是多部分,两个两个合并,最后合成最终文件
  1398. for(int i = 1, len = time.length; i < len; i++){
  1399. if(i == 1){
  1400. // FileUtils.deleteFile(partPath + File.separator + i + "muteSound.mp3");
  1401. CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + ".mp3", partPath + File.separator + i + ".mp3",
  1402. partPath + File.separator + i + "muteSound.mp3");
  1403. }else if(i == len - 1){
  1404. CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + "muteSound.mp3", partPath + File.separator + i + ".mp3",
  1405. path + File.separator + originalFileName);
  1406. }else {
  1407. CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + "muteSound.mp3", partPath + File.separator + i + ".mp3",
  1408. partPath + File.separator + i + "muteSound.mp3");
  1409. }
  1410. }
  1411. }else {
  1412. //若只有两部分,直接合并成最终文件
  1413. CreateObjUtil.mergeVideo(partPath + File.separator + "0.mp3", partPath + File.separator + "1.mp3", path + File.separator + originalFileName);
  1414. }
  1415. uploadToOssUtil.upload(path+File.separator +originalFileName, "voice/voice"+sceneNum+"/"+originalFileName);
  1416. }
  1417. private void saveImageToDisk(String path, String id) throws Exception {
  1418. String accessToken = WeiXinUtils.getAccessToken();
  1419. InputStream is = null;
  1420. String url = "https://file.api.weixin.qq.com/cgi-bin/media/get?access_token="+ accessToken + "&media_id=" + id;
  1421. log.info("url:" + url);
  1422. URL urlGet = new URL(url);
  1423. HttpURLConnection http = (HttpURLConnection) urlGet
  1424. .openConnection();
  1425. http.setRequestMethod("GET"); // 必须是get方式请求
  1426. http.setRequestProperty("Content-Type",
  1427. "application/x-www-form-urlencoded");
  1428. http.setDoOutput(true);
  1429. http.setDoInput(true);
  1430. System.setProperty("sun.net.client.defaultConnectTimeout", "30000");// 连接超时30秒
  1431. System.setProperty("sun.net.client.defaultReadTimeout", "30000"); // 读取超时30秒
  1432. http.connect();
  1433. // 获取文件转化为byte流
  1434. is = http.getInputStream();
  1435. File dic = new File(path);
  1436. if(!dic.exists())
  1437. {
  1438. dic.mkdirs();
  1439. }
  1440. File voice = new File(path+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr");
  1441. if(voice.exists())
  1442. {
  1443. FileUtils.deleteFile(path+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr");
  1444. }
  1445. FileUtils.saveImageToDisk(accessToken, id, ConstantFileName.WECHAT_VOICE_NAME, path+File.separator, is);
  1446. }
  1447. private Object[] getUploadFileMapAndSceneJson(SceneEditVO base, JSONArray jsonhots, JSONObject jsonhot, String sid,
  1448. StringBuffer imagesBuf, StringBuffer imagesBuffer,
  1449. StringBuffer dataBuf, StringBuffer dataBuffer) throws Exception {
  1450. Object[] result = new Object[2];
  1451. Map<String,String> map = new HashMap<String,String>();
  1452. if(jsonhot.containsKey("media")) {
  1453. String fileType = jsonhot.getString("media");
  1454. if(fileType.contains("photo")) {
  1455. if("-1".equals(base.getType())) {
  1456. FileUtils.deleteFile(imagesBuffer.toString() + "hot"+sid+".jpg");
  1457. }
  1458. else {
  1459. map.put(imagesBuffer.toString() + "hot"+sid+".jpg", imagesBuf.toString() + "hot"+sid+".jpg");
  1460. }
  1461. }
  1462. if(fileType.contains("audio") || fileType.contains("voice")) {
  1463. if("-1".equals(base.getType())) {
  1464. FileUtils.deleteFile(imagesBuffer.toString() + "hot"+sid+".mp3");
  1465. }
  1466. else {
  1467. map.put(imagesBuffer.toString() + "hot"+sid+".mp3", imagesBuf.toString() + "hot"+sid+".mp3");
  1468. }
  1469. }
  1470. if(fileType.contains("video")) {
  1471. if("-1".equals(base.getType())) {
  1472. FileUtils.deleteFile(imagesBuffer.toString() + "hot"+sid+".mp4");
  1473. }
  1474. else
  1475. {
  1476. map.put(imagesBuffer.toString() + "hot"+sid+".mp4", imagesBuf.toString() + "hot"+sid+".mp4");
  1477. map.put(imagesBuffer.toString() + "hot"+sid+"-cut.jpg", imagesBuf.toString() + "hot"+sid+"-cut.jpg");
  1478. }
  1479. }
  1480. }
  1481. FileUtils.deleteFile(dataBuffer.toString() + "hot.json");
  1482. File dataPath = new File(dataBuffer.toString());
  1483. if(!dataPath.exists()){
  1484. dataPath.mkdirs();
  1485. }
  1486. FileUtils.writeFile(dataBuffer.toString() + "hot.json", jsonhots.toString());
  1487. map.put(dataBuffer.toString() + "hot.json", dataBuf.toString() + "hot.json");
  1488. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  1489. JSONObject scenejson = new JSONObject();
  1490. if(strsceneInfos!=null){
  1491. scenejson = JSONObject.parseObject(strsceneInfos);
  1492. }
  1493. if(!StringUtils.isEmpty(base.getCapData())){
  1494. FileUtils.writeFile(dataBuffer.toString() + "capData.json", new String(base.getCapData().getBytes(), "UTF-8"));
  1495. scenejson.put("capData", dataBuf.toString() + "capData.json");
  1496. }
  1497. if(!StringUtils.isEmpty(base.getFrameData())){
  1498. FileUtils.writeFile(dataBuffer.toString() + "frameData.json", new String(base.getFrameData().getBytes(), "UTF-8"));
  1499. scenejson.put("frameData", dataBuf.toString() + "frameData.json");
  1500. }
  1501. if(!StringUtils.isEmpty(base.getPlayData())){
  1502. FileUtils.writeFile(dataBuffer.toString() + "playData.json", new String(base.getPlayData().getBytes(), "UTF-8"));
  1503. scenejson.put("playData", dataBuf.toString() + "playData.json");
  1504. map.put(dataBuffer.toString() + "playData.json", dataBuf.toString() + "playData.json");
  1505. }
  1506. if(!StringUtils.isEmpty(base.getScreencapThumb())){
  1507. FileUtils.writeFile(dataBuffer.toString() + "screencapThumb.json", new String(base.getScreencapThumb().getBytes(), "UTF-8"));
  1508. scenejson.put("screencapThumb", dataBuf.toString() + "screencapThumb.json");
  1509. map.put(dataBuffer.toString() + "screencapThumb.json", dataBuf.toString() + "screencapThumb.json");
  1510. }
  1511. if(jsonhots.size()>0){
  1512. scenejson.put("hots", 1);
  1513. }
  1514. else{
  1515. scenejson.put("hots", 0);
  1516. }
  1517. result[0] = map;
  1518. result[1] = scenejson;
  1519. return result;
  1520. }
  1521. private String deleteCustomStyleHots(SceneEditVO base, JSONArray jsonhots, JSONObject jsonhot, String sid){
  1522. String hotsids = "";
  1523. String[] styles = null;
  1524. if(StrUtil.isNotEmpty(base.getStyleName())){
  1525. styles = base.getStyleName().split(",");
  1526. }
  1527. for(int i=0;i<jsonhots.size();++i) {
  1528. JSONObject ele = jsonhots.getJSONObject(i);
  1529. //名字对应上就删除
  1530. if(styles != null){
  1531. for(String style : styles){
  1532. if(style.equals(ele.getString("styleId"))){
  1533. jsonhots.getJSONObject(i).put("styleId", null);
  1534. jsonhots.getJSONObject(i).put("style", "default");
  1535. jsonhots.getJSONObject(i).put("styleImageURL", null);
  1536. }
  1537. }
  1538. }
  1539. hotsids += ele.getString("sid") +",";
  1540. if(ele.getString("sid").equals(sid)) {
  1541. if("-1".equals(base.getType())) {
  1542. jsonhots.remove(i);
  1543. jsonhot = ele;
  1544. if(!"s3".equals(this.type)){
  1545. JSONObject paramData = new JSONObject();
  1546. paramData.put("hotId", sid);
  1547. JSONObject hotListJson = JSONObject.parseObject(OkHttpUtils.httpGet(hotDomainList));
  1548. if(hotListJson != null){
  1549. JSONArray hotListArray = hotListJson.getJSONArray("data");
  1550. if(hotListArray != null){
  1551. for(int l = 0, len = hotListArray.size(); l < len; l++){
  1552. OkHttpUtils.httpPostJson(hotListArray.getString(l) + hotDelete + "?hotId=" + sid
  1553. , paramData.toJSONString());
  1554. }
  1555. }
  1556. }
  1557. }
  1558. }
  1559. else if("0".equals(base.getType())) {
  1560. jsonhots.set(i, jsonhot);
  1561. }
  1562. }
  1563. }
  1564. return hotsids;
  1565. }
  1566. private JSONArray getJsonhots(SceneEditVO base, StringBuffer dataBuffer, JSONObject jsonhot) throws Exception {
  1567. String str = FileUtils.readFile(dataBuffer.toString() + "hot.json");
  1568. JSONArray jsonhots = null;
  1569. if (StrUtil.isNotEmpty(str)) {
  1570. jsonhots = JSONArray.parseArray(str);
  1571. }else {
  1572. File file = new File(dataBuffer.toString() + "hot.json");
  1573. if(!file.getParentFile().exists()){
  1574. file.getParentFile().mkdirs();
  1575. }
  1576. if(!file.exists()){
  1577. file.createNewFile();
  1578. }
  1579. jsonhots = new JSONArray();
  1580. }
  1581. if(SceneEditType.ADD.code().equals(base.getType())){
  1582. jsonhots.add(jsonhot);
  1583. }
  1584. return jsonhots;
  1585. }
  1586. private String getSidFromParams(SceneEditVO base, JSONObject jsonhot){
  1587. String sid = base.getSid();
  1588. //添加或者修改
  1589. if(SceneEditType.ADD.code().equals(base.getType())){
  1590. sid = jsonhot.getString("sid");
  1591. if(StrUtil.isEmpty(sid)){
  1592. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  1593. }
  1594. }
  1595. else if(SceneEditType.UPDATE.code().equals(base.getType())){
  1596. sid = jsonhot.getString("sid");
  1597. if(StrUtil.isEmpty(sid)){
  1598. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  1599. }
  1600. }
  1601. else if(SceneEditType.DELETE.code().equals(base.getType())){
  1602. if(StrUtil.isEmpty(sid)){
  1603. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  1604. }
  1605. }
  1606. return sid;
  1607. }
  1608. @Override
  1609. public Page<SceneVO> getAllSceneByPage(@RequestBody UserParamVO param) {
  1610. if(StrUtil.isEmpty(param.getAppUserName()) && StrUtil.isEmpty(param.getPhoneNum()) ){
  1611. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  1612. }
  1613. Long cameraId = null;
  1614. Long userId = null;
  1615. Integer cameraType = null;
  1616. //获取相机id
  1617. if(!StrUtil.isEmpty(param.getAppUserName()) && !StrUtil.isEmpty(param.getAppPassword())){
  1618. ResultData<Camera> cameraResult = platformGoodsClient.getByChildNameAndChildPassword(param.getAppUserName(), param.getAppPassword());
  1619. Camera camera = cameraResult.getData();
  1620. if (camera == null) {
  1621. throw new BusinessException(ErrorCode.FAILURE_CODE_3014);
  1622. }
  1623. cameraId = camera.getId();
  1624. }
  1625. //获取该用户id协作者的场景码集合
  1626. List<String> sceneCodeList = null;
  1627. if (StrUtil.isNotEmpty(param.getPhoneNum())) {
  1628. ResultData<User> userResult = platformUserClient.getUserByName(param.getPhoneNum());
  1629. User user = userResult.getData();
  1630. if (user == null) {
  1631. throw new BusinessException(ErrorCode.FAILURE_CODE_3015);
  1632. }
  1633. userId = user.getId();
  1634. List<SceneCooperation> list = sceneCooperationService.list(
  1635. new LambdaQueryWrapper<SceneCooperation>()
  1636. .eq(SceneCooperation::getTbStatus, TbStatus.VALID.code())
  1637. .eq(SceneCooperation::getRecStatus, RecStatus.VALID.code())
  1638. .eq(SceneCooperation::getUserId, userId)
  1639. .orderByDesc(SceneCooperation::getId));
  1640. if(CollUtil.isNotEmpty(list)){
  1641. sceneCodeList = list.parallelStream().map(co -> {
  1642. return co.getSceneCode();
  1643. }).collect(Collectors.toList());
  1644. }
  1645. }
  1646. if(param.getCameraType() != null){
  1647. cameraType = param.getCameraType();
  1648. }
  1649. Camera camera = null;
  1650. CameraDetail cameraDetail = null;
  1651. Page<SceneVO> sceneVOPage =
  1652. sceneProService.getAppAllSceneByPage(cameraId, userId, cameraType,
  1653. param.getPageNum(), param.getPageSize(), param.getOrderBy(),
  1654. param.getSceneType(), sceneCodeList, param.getSceneName());
  1655. if(sceneVOPage.getCurrent() == 0){
  1656. return sceneVOPage;
  1657. }
  1658. for(SceneVO sceneVO : sceneVOPage.getRecords()){
  1659. // 当计算时,返回给前端的状态为计算中
  1660. if (!ObjectUtils.isEmpty(sceneVO)) {
  1661. if (sceneVO.getStatus() == -1) {
  1662. sceneVO.setStatus(0);
  1663. } else if (sceneVO.getStatus() == 500) {
  1664. sceneVO.setStatus(-1);
  1665. }
  1666. }
  1667. //相机id为空是123看房的场景
  1668. if(sceneVO.getCameraId() == null){
  1669. //当场景用户id等于该用户id,为用户场景,其余未协作场景
  1670. if(sceneVO.getUserId().longValue() == userId.longValue()){
  1671. sceneVO.setSceneSourceType(1);
  1672. }else {
  1673. sceneVO.setSceneSourceType(2);
  1674. }
  1675. }else {
  1676. ResultData<Camera> cameraResult = platformGoodsClient.getCameraById(sceneVO.getCameraId());
  1677. camera = cameraResult.getData();
  1678. if(Objects.isNull(camera)){
  1679. continue;
  1680. }
  1681. sceneVO.setChildName(camera.getChildName());
  1682. sceneVO.setSnCode(camera.getSnCode());
  1683. ResultData<CameraDetail> cameraDetailResult = platformGoodsClient.getCameraDetailByCameraId(camera.getId());
  1684. cameraDetail = cameraDetailResult.getData();
  1685. if(cameraDetail != null){
  1686. //相机的userId为空,表示相机的场景
  1687. if(cameraDetail.getUserId() == null || userId == null){
  1688. sceneVO.setSceneSourceType(0);
  1689. }else if(userId != null && cameraDetail.getUserId().longValue() == userId.longValue()){
  1690. //相机用户id等于该用户id,既为用户的场景
  1691. sceneVO.setSceneSourceType(1);
  1692. }else if(cameraId != null && cameraDetail.getCameraId() != null && cameraDetail.getCameraId().longValue() == cameraId.longValue()
  1693. && cameraDetail.getCooperationUser() == null){
  1694. //场景相机id等于该相机id
  1695. sceneVO.setSceneSourceType(0);
  1696. }else if(cameraId != null && cameraDetail.getCameraId().longValue() == cameraId.longValue()
  1697. && cameraDetail.getCooperationUser() != null){
  1698. if(userId != null && cameraDetail.getCooperationUser().longValue() == userId.longValue()){
  1699. sceneVO.setSceneSourceType(2);
  1700. }else {
  1701. sceneVO.setSceneSourceType(0);
  1702. }
  1703. }else {
  1704. //最后不等于则为协作者场景
  1705. sceneVO.setSceneSourceType(2);
  1706. }
  1707. }
  1708. }
  1709. }
  1710. return sceneVOPage;
  1711. }
  1712. @Override
  1713. public List<SceneVO> getAllForCameraName(@RequestBody UserParamVO user){
  1714. if(StrUtil.isEmpty(user.getAppUserName()) || StrUtil.isEmpty(user.getAppPassword())){
  1715. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  1716. }
  1717. ResultData<Camera> cameraResult = platformGoodsClient.getByChildNameAndChildPassword(user.getAppUserName(), user.getAppPassword());
  1718. Camera camera = cameraResult.getData();
  1719. if (camera == null) {
  1720. throw new BusinessException(ErrorCode.FAILURE_CODE_3014);
  1721. }
  1722. List<ScenePro> list = sceneProService.list(
  1723. new LambdaQueryWrapper<ScenePro>()
  1724. .eq(ScenePro::getTbStatus, TbStatus.VALID.code())
  1725. .eq(ScenePro::getRecStatus, RecStatus.VALID.code())
  1726. .eq(ScenePro::getCameraId, camera.getId())
  1727. .ne(ScenePro::getSceneType, SceneType.YJHZXNFY.code())
  1728. .in(ScenePro::getSceneStatus, SceneStatus.SUCCESS, SceneStatus.NO_DISPLAY).orderByDesc(ScenePro::getId));
  1729. List<SceneVO> sceneList = sceneProService.convert(list);
  1730. for(SceneVO sceneVO : sceneList){
  1731. sceneVO.setChildName(user.getAppUserName());
  1732. }
  1733. return sceneList;
  1734. }
  1735. }