package com.fdkankan.scene.service.impl; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.fdkankan.common.constant.*; import com.fdkankan.common.exception.BusinessException; import com.fdkankan.common.response.ResultData; import com.fdkankan.common.util.*; import com.fdkankan.redis.util.RedisLockUtil; import com.fdkankan.scene.entity.ScenePro; import com.fdkankan.scene.entity.SceneProEdit; import com.fdkankan.scene.entity.SceneProEditExt; import com.fdkankan.scene.mapper.ISceneProMapper; import com.fdkankan.scene.service.ISceneProAppService; import com.fdkankan.scene.service.ISceneProEditExtService; import com.fdkankan.scene.service.ISceneProEditService; import com.fdkankan.scene.service.ISceneProService; import com.fdkankan.scene.vo.SceneEditVO; import lombok.extern.slf4j.Slf4j; import net.coobird.thumbnailator.Thumbnails; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import java.io.File; import java.io.InputStream; import java.io.PrintWriter; import java.io.StringWriter; import java.net.HttpURLConnection; import java.net.URL; import java.util.*; /** *

* pro场景表 服务实现类 *

* * @author dengsixing * @since 2021-12-23 */ @Slf4j @Service public class SceneProAppServiceImpl extends ServiceImpl implements ISceneProAppService { @Value("${oss.type}") private String type; @Value("${prefix.ali}") private String prefixAli; @Value("${hot.domain.list}") private String hotDomainList; @Value("${hot.delete}") private String hotDelete; @Autowired ISceneProService sceneProService; @Autowired @Qualifier("uploadToOssUtil") UploadToOssUtil uploadToOssUtil; @Autowired ISceneProEditService sceneProEditService; @Autowired RedisLockUtil redisLockUtil; @Autowired ISceneProEditExtService sceneProEditExtService; @Override public ResultData saveInitialPage(SceneEditVO base) throws Exception { if(StringUtils.isEmpty(base.getSceneNum()) || StringUtils.isEmpty(base.getInitialPoint())){ throw new BusinessException(ErrorCode.FAILURE_CODE_3001); } ScenePro scenePro = baseMapper.findByNum(base.getSceneNum()); if(Objects.isNull(scenePro)){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } SceneProEdit sceneProEdit= sceneProEditService.findByProId(scenePro.getId()); StringBuffer dataBuf = new StringBuffer() .append("data").append(File.separator) .append("data").append(scenePro.getSceneCode()) .append(File.separator); StringBuffer imagesBuf = new StringBuffer() .append("images").append(File.separator) .append("images").append(scenePro.getSceneCode()) .append(File.separator); StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString()); StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString()); String path1 = imagesBuffer.toString() + "thumbBigImg.jpg"; String path2 = imagesBuffer.toString() + "thumbSmallImg.jpg"; //生成缩略图 //按指定大小把图片进行缩和放(会遵循原图高宽比例) //此处把图片压成1024×512的缩略图 Thumbnails.of(path1).size(1024,512).toFile(path2);//变为1024×512 Map map = new HashMap(); map.put("entry", JSONObject.parseObject(base.getInitialPoint())); map.put("thumbImg", 1); map.put("version", sceneProEdit.getVersion()+1); FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map); Map uploadMap = new HashMap(); uploadMap.put(imagesBuffer.toString() + "thumbBigImg.jpg", imagesBuf.toString() + "thumbBigImg.jpg"); uploadMap.put(imagesBuffer.toString() + "thumbFishBigImg.jpg", imagesBuf.toString() + "thumbFishBigImg.jpg"); uploadMap.put(imagesBuffer.toString() + "thumbSmallImg.jpg", imagesBuf.toString() + "thumbSmallImg.jpg"); uploadMap.put(imagesBuffer.toString() + "smallPic.jpg", imagesBuf.toString() + "smallPic.jpg"); uploadMap.put(dataBuffer.toString() + "scene.json", dataBuf.toString() + "scene.json"); uploadToOssUtil.uploadMulFiles(uploadMap); sceneProEdit.setEntry(base.getInitialPoint()); sceneProEdit.setThumbStatus(1); sceneProEdit.setVersion(sceneProEdit.getVersion() + 1); sceneProEdit.setUpdateTime(Calendar.getInstance().getTime()); sceneProEditService.updateById(sceneProEdit); scenePro.setThumb(prefixAli + imagesBuf.toString() + "thumbSmallImg.jpg"); if("s3".equals(type)){ scenePro.setThumb(ConstantUrl.PREFIX_AWS + imagesBuf.toString() + "thumbSmallImg.jpg"); } sceneProService.updateById(scenePro); return ResultData.ok(); } @Override public ResultData saveFloorLogo(SceneEditVO base) throws Exception { if(StrUtil.isEmpty(base.getSceneNum()) || StrUtil.isEmpty(base.getSize()) || StrUtil.isEmpty(base.getLogoType())){ throw new BusinessException(ErrorCode.FAILURE_CODE_3001); } ScenePro scenePro = baseMapper.findByNum(base.getSceneNum()); if(scenePro == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId()); StringBuffer dataBuf = new StringBuffer() .append("data").append(File.separator) .append("data").append(scenePro.getSceneCode()) .append(File.separator); StringBuffer imagesBuf = new StringBuffer() .append("images").append(File.separator) .append("images").append(scenePro.getSceneCode()) .append(File.separator); StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString()); StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString()); Map map = new HashMap(); map.put("floorLogo", base.getLogoType()); map.put("floorLogoSize", base.getSize()); map.put("version", sceneProEdit.getVersion()+1); FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map); sceneProEdit.setFloorLogo(base.getLogoType()); sceneProEdit.setFloorLogoSize(Integer.parseInt(base.getSize())); sceneProEdit.setVersion(sceneProEdit.getVersion() + 1); sceneProEdit.setUpdateTime(Calendar.getInstance().getTime()); sceneProEditService.updateById(sceneProEdit); uploadToOssUtil.upload(imagesBuffer.toString() + "floorLogoImg.png", imagesBuf.toString() + "floorLogoImg.png"); uploadToOssUtil.upload(dataBuffer.toString() + "scene.json", dataBuf.toString() + "scene.json"); return ResultData.ok(); } @Override @SuppressWarnings("unchecked") public ResultData saveHot(SceneEditVO base) throws Exception { if(StrUtil.isEmpty(base.getType())){ throw new BusinessException(ErrorCode.FAILURE_CODE_3001); } ScenePro scenePro = baseMapper.findByNum(base.getSceneNum()); if (scenePro == null ) { throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId()); log.info("hotData:" + base.getHotData()); JSONObject jsonhot = JSONObject.parseObject(base.getHotData()); StringBuffer dataBuf = new StringBuffer() .append("data").append(File.separator) .append("data").append(scenePro.getSceneCode()) .append(File.separator); StringBuffer imagesBuf = new StringBuffer() .append("images").append(File.separator) .append("images").append(scenePro.getSceneCode()) .append(File.separator); StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString()); StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString()); String sid = this.getSidFromParams(base, jsonhot); JSONArray jsonhots = this.getJsonhots(base, dataBuffer, jsonhot); //判断是否需要删除自定义热点样式 String hotsids = this.deleteCustomStyleHots(base,jsonhots,jsonhot,sid); Object[] uploadFileMapAndSceneJson = this.getUploadFileMapAndSceneJson(base,jsonhots, jsonhot, sid, imagesBuf, imagesBuffer, dataBuf, dataBuffer); Map map = (Map) uploadFileMapAndSceneJson[0]; JSONObject scenejson = (JSONObject) uploadFileMapAndSceneJson[1]; uploadToOssUtil.uploadMulFiles(map); if(!StringUtils.isEmpty(base.getPlayData())){ sceneProEdit.setPlayData(dataBuf.toString() + "playData.json"); } if(!StringUtils.isEmpty(base.getScreencapThumb())){ sceneProEdit.setScreencapThumb(dataBuf.toString() + "screencapThumb.json"); } sceneProEdit.setHotsIds(hotsids); sceneProEdit.setVersion(sceneProEdit.getVersion() + 1); sceneProEditService.updateById(sceneProEdit); scenejson.put("version", sceneProEdit.getVersion() + 1); FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString()); return ResultData.ok(); } @Override public ResultData saveBackgroundMusic(SceneEditVO base) throws Exception { if(StringUtils.isEmpty(base.getSceneNum()) || StringUtils.isEmpty(base.getMusicName())){ throw new BusinessException(ErrorCode.FAILURE_CODE_3001); } ScenePro scenePro = baseMapper.findByNum(base.getSceneNum()); if(scenePro == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId()); StringBuffer dataBuf = new StringBuffer() .append("data").append(File.separator) .append("data").append(scenePro.getSceneCode()) .append(File.separator); StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString()); Map map = new HashMap(); map.put("bgMusic", base.getMusicName()); map.put("version", sceneProEdit.getVersion()+1); FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map); sceneProEdit.setBgMusic(base.getMusicName()); sceneProEdit.setVersion(sceneProEdit.getVersion() + 1); sceneProEditService.updateById(sceneProEdit); return ResultData.ok(); } @Override public ResultData saveSceneInfo(SceneEditVO base) throws Exception{ if(StringUtils.isEmpty(base.getSceneNum()) || StringUtils.isEmpty(base.getSceneName()) || StringUtils.isEmpty(base.getSceneType()) || StringUtils.isEmpty(base.getSceneDec())){ throw new BusinessException(ErrorCode.FAILURE_CODE_3001); } ScenePro scenePro = baseMapper.findByNum(base.getSceneNum()); if(scenePro == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId()); StringBuffer dataBuf = new StringBuffer() .append("data").append(File.separator) .append("data").append(scenePro.getSceneCode()) .append(File.separator); StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString()); Map map = new HashMap(); map.put("sceneName", base.getSceneName()); map.put("sceneDec", base.getSceneDec()); if(StrUtil.isNotEmpty(base.getSceneType())){ if(scenePro.getSceneType() == 99){ map.put("sceneType", scenePro.getSceneType()); }else { scenePro.setSceneType(Integer.parseInt(base.getSceneType())); map.put("sceneType", base.getSceneType()); } } if(StrUtil.isNotEmpty(base.getSceneKey())) { map.put("sceneKey", base.getSceneKey()); map.put("needKey", 1); sceneProEdit.setNeedKey(1); }else { sceneProEdit.setNeedKey(0); map.put("sceneKey", ""); map.put("needKey", 0); } map.put("version", sceneProEdit.getVersion()+1); FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map); scenePro.setSceneName(base.getSceneName()); scenePro.setSceneDec(base.getSceneDec()); scenePro.setUpdateTime(Calendar.getInstance().getTime()); this.updateById(scenePro); sceneProEdit.setSceneKey(base.getSceneKey()); sceneProEdit.setVersion(sceneProEdit.getVersion() + 1); sceneProEdit.setUpdateTime(Calendar.getInstance().getTime()); sceneProEditService.updateById(sceneProEdit); return ResultData.ok(); } @Override public ResultData saveSceneKey(SceneEditVO base) throws Exception{ if(StringUtils.isEmpty(base.getSceneNum()) || StringUtils.isEmpty(base.getSceneKey())){ throw new BusinessException(ErrorCode.FAILURE_CODE_3001); } ScenePro scenePro = baseMapper.findByNum(base.getSceneNum()); if(scenePro == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId()); StringBuffer dataBuf = new StringBuffer() .append("data").append(File.separator) .append("data").append(scenePro.getSceneCode()) .append(File.separator); StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString()); Map map = new HashMap(); map.put("sceneKey", base.getSceneKey()); map.put("needKey", 1); map.put("version", sceneProEdit.getVersion()+1); FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map); sceneProEdit.setSceneKey(base.getSceneKey()); sceneProEdit.setNeedKey(1); sceneProEdit.setVersion(sceneProEdit.getVersion() + 1); sceneProEdit.setUpdateTime(Calendar.getInstance().getTime()); sceneProEditService.updateById(sceneProEdit); return ResultData.ok(); } @Override public ResultData saveTourList(SceneEditVO base) throws Exception{ if(StringUtils.isEmpty(base.getSceneNum()) || StringUtils.isEmpty(base.getTourList())){ throw new BusinessException(ErrorCode.FAILURE_CODE_3001); } ScenePro scenePro = baseMapper.findByNum(base.getSceneNum()); if(scenePro == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId()); StringBuffer dataBuf = new StringBuffer() .append("data").append(File.separator) .append("data").append(scenePro.getSceneCode()) .append(File.separator); StringBuffer imagesBuf = new StringBuffer() .append("images").append(File.separator) .append("images").append(scenePro.getSceneCode()) .append(File.separator); StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString()); StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString()); Map map = new HashMap(); log.info("editForApp/saveTourList:生成tourList.json文件"); String tourListPath = dataBuffer.toString() + ConstantFileName.TOUR_LIST; FileUtils.writeFile(tourListPath, base.getTourList()); map.put(tourListPath, dataBuf.toString() + ConstantFileName.TOUR_LIST); JSONArray tourJsons = JSONArray.parseArray(base.getTourList()); String path = imagesBuffer.toString() + ConstantFileName.TOURLIST_FOLDER; for(int i=0;i jsonMap = new HashMap(); jsonMap.put("screenCapLen", screencapLen); jsonMap.put("version", sceneProEdit.getVersion() + 1); FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", jsonMap); sceneProEdit.setVersion(sceneProEdit.getVersion() + 1); sceneProEdit.setUpdateTime(Calendar.getInstance().getTime()); sceneProEditService.updateById(sceneProEdit); } uploadToOssUtil.uploadMulFiles(map); return ResultData.ok(); } @Override public ResultData uploadPic(String sceneNum, String folderName, MultipartFile file) throws Exception{ if(StringUtils.isEmpty(sceneNum)){ throw new BusinessException(ErrorCode.FAILURE_CODE_3001); } ScenePro scenePro = baseMapper.findByNum(sceneNum); if(scenePro == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } if (file.isEmpty() && file.getSize() <= 0) { throw new BusinessException(ErrorCode.FAILURE_CODE_5012); } String lockKey = String.format(RedisKey.LOCK_UPLOAD_PRO_PIC, sceneNum); Boolean lock = redisLockUtil.lock(lockKey, RedisKey.EXPIRE_TIME_10_MINUTE); if(!lock){ throw new BusinessException(ErrorCode.FAILURE_CODE_5036); } File targetFile = null; try { //文件上传的位置可以自定义 String path = ConstantFilePath.SCENE_PATH+"images"+File.separator+"images"+sceneNum; if(StrUtil.isNotEmpty(folderName)) { path = path+File.separator + folderName; } targetFile = new File(path); if (!targetFile.exists()) { targetFile.mkdirs(); } String fileName = file.getOriginalFilename(); targetFile = new File(path + File.separator + fileName); // 保存 if(targetFile.exists()) { FileUtils.deleteFile(path + File.separator + fileName); } file.transferTo(targetFile); }catch (Exception e){ log.error("上传图片失败", e); throw new BusinessException(ErrorCode.FAILURE_CODE_5037); }finally { redisLockUtil.unlock(lockKey); } return ResultData.ok(targetFile.getName()); } @Override public ResultData uploadScreencapVoice(String sceneNum, MultipartFile file) throws Exception{ if(StringUtils.isEmpty(sceneNum)){ throw new BusinessException(ErrorCode.FAILURE_CODE_3001); } ScenePro scenePro = baseMapper.findByNum(sceneNum); if(scenePro == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId()); if (file.isEmpty() && file.getSize() <= 0) { throw new BusinessException(ErrorCode.FAILURE_CODE_5012); } String lockKey = String.format(RedisKey.LOCK_UPLOAD_PRO_VOICE, sceneNum); Boolean lock = redisLockUtil.lock(lockKey, RedisKey.EXPIRE_TIME_30_MINUTE); if(!lock){ throw new BusinessException(ErrorCode.FAILURE_CODE_5036); } String originalFileName = null; try { //文件上传的位置可以自定义 String path = ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+sceneNum; File targetFile = new File(path); if (!targetFile.exists()) { targetFile.mkdirs(); } originalFileName = file.getOriginalFilename(); targetFile = new File(path + File.separator +originalFileName); // 保存 synchronized(this) { if(targetFile.exists()) { FileUtils.deleteFile(path + File.separator + originalFileName); } file.transferTo(targetFile); } uploadToOssUtil.upload(path + File.separator +originalFileName, "voice/voice"+sceneNum+"/"+originalFileName); Map map = new HashMap(); map.put("screencapVoiceFileName", originalFileName); String voiceSrc = prefixAli + "voice/voice"+sceneNum+"/"+originalFileName; if("s3".equals(type)){ voiceSrc = ConstantUrl.PREFIX_AWS + "voice/voice"+sceneNum+"/"+originalFileName; } map.put("screencapVoiceSrc", voiceSrc); map.put("screencapVoiceType", "file"); map.put("version", sceneProEdit.getVersion()+1); FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + "/scene.json", map); sceneProEdit.setScreencapVoiceSrc(voiceSrc); sceneProEdit.setVersion(sceneProEdit.getVersion() + 1); sceneProEdit.setScreencapVoiceType("file"); sceneProEdit.setUpdateTime(Calendar.getInstance().getTime()); sceneProEditService.updateById(sceneProEdit); }catch (Exception e){ log.error("上传图音频失败", e); throw new BusinessException(ErrorCode.FAILURE_CODE_5040); }finally { redisLockUtil.unlock(lockKey); } return ResultData.ok(originalFileName); } @Override public ResultData saveScreencapFile(SceneEditVO base) throws Exception{ if(StringUtils.isEmpty(base.getSceneNum()) || StringUtils.isEmpty(base.getIndex()) || StringUtils.isEmpty(base.getCamerasData())){ throw new BusinessException(ErrorCode.FAILURE_CODE_3001); } ScenePro scenePro = baseMapper.findByNum(base.getSceneNum()); if(scenePro == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId()); StringBuffer dataBuf = new StringBuffer() .append("data").append(File.separator) .append("data").append(scenePro.getSceneCode()) .append(File.separator); StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString()); if("1".equals(base.getIndex())){ File file = new File(dataBuffer.toString() + ConstantFileName.TOURLIST_FOLDER); if(file.isDirectory()){ String[] strs = file.list(); if(strs!=null){ for(int i=0;i-1) { FileUtils.deleteFile(dataBuffer.toString() + ConstantFileName.TOURLIST_FOLDER+File.separator+strs[i]); } } } } else { file.mkdirs(); } Map map = new HashMap<>(); map.put("screencapLen", "0"); map.put("version", sceneProEdit.getVersion()+1); FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map); sceneProEdit.setVersion(sceneProEdit.getVersion() + 1); sceneProEdit.setUpdateTime(Calendar.getInstance().getTime()); sceneProEditService.updateById(sceneProEdit); } String filePath = dataBuffer.toString() + ConstantFileName.TOURLIST_FOLDER+File.separator+ConstantFileName.SCREEN_CRP_DATAFILE+base.getIndex()+"json"; File file = new File(filePath); if(!file.exists()) { file.createNewFile(); } FileUtils.writeFile(filePath, base.getCamerasData()); return ResultData.ok(); } @Override public ResultData saveHotVisible(SceneEditVO base) throws Exception{ if(StringUtils.isEmpty(base.getData())){ throw new BusinessException(ErrorCode.FAILURE_CODE_3001); } ScenePro scenePro = baseMapper.findByNum(base.getSceneNum()); if(scenePro == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId()); JSONArray visiblePanos = JSONArray.parseArray(base.getData()); StringBuffer dataBuf = new StringBuffer() .append("data").append(File.separator) .append("data").append(scenePro.getSceneCode()) .append(File.separator); StringBuffer imagesBuf = new StringBuffer() .append("images").append(File.separator) .append("images").append(scenePro.getSceneCode()) .append(File.separator); StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString()); StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString()); File file = new File(dataBuffer.toString() + "hot.json"); if (!file.exists()) { throw new BusinessException(ErrorCode.FAILURE_CODE_3018); } String str = FileUtils.readFile(dataBuffer.toString() + "hot.json"); JSONArray hots = JSONArray.parseArray(str); for (int i = 0; i < hots.size(); ++i) { JSONObject hot = hots.getJSONObject(i); for (int j = 0; j < visiblePanos.size(); ++j) { if (hot.getString("sid").equals(((JSONObject) visiblePanos.get(j)).getString("sid"))) { hot.put("visiblePanos", ((JSONObject) visiblePanos.get(j)).getJSONArray("value")); } } } sceneProEdit.setVersion(sceneProEdit.getVersion() + 1); sceneProEdit.setUpdateTime(Calendar.getInstance().getTime()); sceneProEditService.updateById(sceneProEdit); FileUtils.deleteFile(dataBuffer.toString() + "hot.json"); FileUtils.writeFile(dataBuffer.toString() + "hot.json", hots.toString()); uploadToOssUtil.upload(dataBuffer.toString() + "hot.json", dataBuf.toString() + "hot.json"); return ResultData.ok(); } @Override public ResultData saveLinkPano(SceneEditVO base) throws Exception{ if(StringUtils.isEmpty(base.getData()) || StringUtils.isEmpty(base.getSceneNum())){ throw new BusinessException(ErrorCode.FAILURE_CODE_3001); } ScenePro scenePro = baseMapper.findByNum(base.getSceneNum()); if(scenePro == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } JSONArray inputData = JSONObject.parseArray(base.getData()); StringBuffer dataBuf = new StringBuffer() .append("data").append(File.separator) .append("data").append(scenePro.getSceneCode()) .append(File.separator); StringBuffer imagesBuf = new StringBuffer() .append("images").append(File.separator) .append("images").append(scenePro.getSceneCode()) .append(File.separator); StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString()); File directory = new File(dataBuffer.toString()); if (!directory.exists()) { directory.mkdirs(); } JSONArray inputdata = JSONArray.parseArray(base.getData()); String modeldataUrl = prefixAli + imagesBuf.toString() + "vision.modeldata?t=" + System.currentTimeMillis(); if("s3".equals(type)){ modeldataUrl = ConstantUrl.PREFIX_AWS + imagesBuf.toString() + "vision.modeldata?t=" + System.currentTimeMillis(); } FileUtils.downLoadFromUrl(modeldataUrl, "vision.modeldata", dataBuffer.toString()); File file = new File(dataBuffer.toString() + "vision.modeldata"); if(!file.exists()) { return ResultData.error(ErrorCode.FAILURE_CODE_5012); } ConvertUtils.convertVisionModelDataToTxt(dataBuffer.toString() + "vision.modeldata", dataBuffer.toString() + "vision.json"); String str = FileUtils.readFile(dataBuffer.toString() + "vision.json"); JSONObject json = JSONObject.parseObject(str); JSONArray panos = json.getJSONArray("sweepLocations"); for (int i = 0; i < panos.size(); ++i) { JSONObject pano = panos.getJSONObject(i); for (int j = 0; j < inputData.size(); ++j) { JSONObject jo = inputData.getJSONObject(j); String currentPanoId = jo.getString("panoID"); JSONArray visibles = jo.getJSONArray("visibles"); JSONArray visibles3 = jo.getJSONArray("visibles3"); if (pano.getString("uuid").equals(currentPanoId)) { pano.put("visibles", visibles); pano.put("visibles3", visibles3); } } } FileUtils.deleteFile(dataBuffer.toString() + "vision.json"); FileUtils.deleteFile(dataBuffer.toString() + "vision.modeldata"); FileUtils.writeFile(dataBuffer.toString() + "vision.json", json.toString()); ConvertUtils.convertTxtToVisionModelData(dataBuffer.toString() + "vision.json", dataBuffer.toString() + "vision.modeldata"); uploadToOssUtil.upload(dataBuffer.toString() + "vision.modeldata", imagesBuf.toString() + "vision.modeldata"); String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json"); JSONObject scenejson = new JSONObject(); if(strsceneInfos!=null){ scenejson = JSONObject.parseObject(strsceneInfos); } scenejson.put("version", scenejson.getIntValue("version") + 1); FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString()); SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId()); if (sceneProEdit == null ) { return ResultData.error(ErrorCode.FAILURE_CODE_5005); } sceneProEdit.setVersion(scenejson.getIntValue("version") + 1); sceneProEdit.setUpdateTime(Calendar.getInstance().getTime()); sceneProEditService.updateById(sceneProEdit); return ResultData.ok(); } @Override public ResultData getRecordAudioFromWeixin(SceneEditVO base) throws Exception{ if(StringUtils.isEmpty(base.getSceneNum()) || StringUtils.isEmpty(base.getId())){ throw new BusinessException(ErrorCode.FAILURE_CODE_3001); } ScenePro scenePro = baseMapper.findByNum(base.getSceneNum()); if(scenePro == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId()); String accessToken = WeiXinUtils.getAccessToken(); InputStream is = null; String url = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token="+ accessToken + "&media_id=" + base.getId(); URL urlGet = new URL(url); HttpURLConnection http = (HttpURLConnection) urlGet .openConnection(); http.setRequestMethod("GET"); // 必须是get方式请求 http.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); http.setDoOutput(true); http.setDoInput(true); System.setProperty("sun.net.client.defaultConnectTimeout", "30000");// 连接超时30秒 System.setProperty("sun.net.client.defaultReadTimeout", "30000"); // 读取超时30秒 http.connect(); // 获取文件转化为byte流 is = http.getInputStream(); File dic = new File(ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+base.getSceneNum()); if(!dic.exists()) { dic.mkdirs(); } File voice = new File(ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+base.getSceneNum()+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr"); if(voice.exists()) { FileUtils.deleteFile(ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+base.getSceneNum()+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr"); } FileUtils.saveImageToDisk( accessToken, base.getId(), ConstantFileName.WECHAT_VOICE_NAME, ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+base.getSceneNum()+File.separator, is); try { FileUtils.changeVoiceToMp3(ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+base.getSceneNum()+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr", ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+base.getSceneNum()+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".mp3"); } catch(Exception e) { StringWriter trace=new StringWriter(); e.printStackTrace(new PrintWriter(trace)); log.error("voice:"+ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+base.getSceneNum()+File.separator+ConstantFileName.VOICE_NAME+".amr"); log.error(trace.toString()); return ResultData.error(ErrorCode.FAILURE_CODE_5005); } String originalFileName = ConstantFileName.WECHAT_VOICE_NAME+".mp3"; uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+base.getSceneNum()+File.separator +originalFileName, "voice/voice"+base.getSceneNum()+"/"+originalFileName); Map map = new HashMap(); map.put("screencapVoiceSoundsyncFileName", originalFileName); String voiceSrc = prefixAli+"voice/voice"+base.getSceneNum()+"/"+originalFileName; if("s3".equals(type)){ voiceSrc = ConstantUrl.PREFIX_AWS+"voice/voice"+base.getSceneNum()+"/"+originalFileName; } map.put("screencapVoiceSoundsync", voiceSrc); log.info("微信上传的音频路径:{}", voiceSrc); map.put("screencapVoiceType", "soundsync"); map.put("version", sceneProEdit.getVersion()+1); FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + base.getSceneNum() + "/scene.json", map); sceneProEdit.setScreencapVoiceType("soundsync"); sceneProEdit.setScreencapVoiceSoundsync(voiceSrc); sceneProEdit.setVersion(sceneProEdit.getVersion()); sceneProEdit.setUpdateTime(Calendar.getInstance().getTime()); sceneProEditService.updateById(sceneProEdit); FileUtils.deleteFile(ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+base.getSceneNum()+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr"); if("s3".equals(type)){ return ResultData.ok(ConstantUrl.PREFIX_AWS+"voice/voice"+base.getSceneNum()+"/"+originalFileName); } return ResultData.ok(prefixAli+"voice/voice"+base.getSceneNum()+"/"+originalFileName); } @Override public ResultData getRecordAudioFromWeixinV3(String sceneNum, String id, String type, String fileName, String length, String replace, String times, String index) throws Exception { if(StringUtils.isEmpty(sceneNum) || StringUtils.isEmpty(id)){ throw new BusinessException(ErrorCode.FAILURE_CODE_3001); } ScenePro scenePro = baseMapper.findByNum(sceneNum); if(scenePro == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId()); String strsceneInfos = FileUtils.readFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json"); JSONObject scenejson = new JSONObject(); if(strsceneInfos!=null) { scenejson = JSONObject.parseObject(strsceneInfos); } //文件上传的位置可以自定义 String path = ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+sceneNum; log.info("path:" + path); this.saveImageToDisk(path, id); try { FileUtils.changeVoiceToMp3(path+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr", path+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".mp3"); } catch(Exception e) { StringWriter trace=new StringWriter(); e.printStackTrace(new PrintWriter(trace)); log.error("voice:"+path+File.separator+ConstantFileName.VOICE_NAME+".amr"); log.error(trace.toString()); return ResultData.error(ErrorCode.FAILURE_CODE_5005); } String originalFileName = ConstantFileName.WECHAT_VOICE_NAME+".mp3"; //判断分房间模块文件夹是否存在 String partPath = path + File.separator + "part"; File partFile = new File(partPath); if(!partFile.exists()){ partFile.mkdirs(); } if(!"1".equals(replace)){ return ResultData.ok(this.replaceForWeixinV3(sceneProEdit, scenejson, path, partPath, fileName, originalFileName, sceneNum, times)); } FileUtils.delAllFile(path + File.separator + "part"); //保存0.mp3文件到part FileUtils.changeVoiceToMp3(path+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr", partPath+File.separator+fileName); FileUtils.copyFile(partPath+File.separator+fileName, path + File.separator + originalFileName, true); uploadToOssUtil.upload(path+File.separator +originalFileName, "voice/voice"+sceneNum+"/"+originalFileName); String voiceSrc = prefixAli+"voice/voice"+sceneNum+"/"+originalFileName; if("s3".equals(this.type)){ voiceSrc = ConstantUrl.PREFIX_AWS+"voice/voice"+sceneNum+"/"+originalFileName; } sceneProEdit.setScreencapVoiceType("soundsync"); sceneProEdit.setScreencapVoiceSoundsync(voiceSrc); sceneProEdit.setVersion(scenejson.getIntValue("version")+1); sceneProEdit.setUpdateTime(Calendar.getInstance().getTime()); sceneProEditService.updateById(sceneProEdit); Map map = new HashMap(); map.put("screencapVoiceSoundsyncFileName", originalFileName); map.put("screencapVoiceSoundsync", voiceSrc); map.put("uploadVoiceSoundsync", 1); map.put("screencapVoiceType", type); map.put("version", scenejson.getIntValue("version")+1); FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map); FileUtils.deleteFile(path+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr"); return ResultData.ok(voiceSrc); } @Override public ResultData getRecordAudioFromAppV3(String sceneNum, String soundFile, String type, String fileName, String length, String replace, String times, String index) throws Exception { if(StringUtils.isEmpty(sceneNum) || StringUtils.isEmpty(soundFile)){ throw new BusinessException(ErrorCode.FAILURE_CODE_3001); } ScenePro scenePro = baseMapper.findByNum(sceneNum); if(scenePro == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId()); String strsceneInfos = FileUtils.readFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json"); JSONObject scenejson = new JSONObject(); if(strsceneInfos!=null) { scenejson = JSONObject.parseObject(strsceneInfos); } String originalFileName = ConstantFileName.APP_VOICE_NAME+".mp3"; //文件上传的位置可以自定义 String path = ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+sceneNum; //判断分房间模块文件夹是否存在 String partPath = path + File.separator + "part"; File partFile = new File(partPath); if(!partFile.exists()){ partFile.mkdirs(); } if(!"1".equals(replace)){ return ResultData.ok(this.replaceForAppV3(sceneProEdit, scenejson, path, partPath, fileName, originalFileName, sceneNum, times, soundFile)); } FileUtils.delAllFile(path + File.separator + "part"); if("s3".equals(this.type)){ CreateObjUtil.ossFileCp("voice"+File.separator+"voice"+sceneNum + "/" + soundFile, partPath + File.separator + fileName); }else { CreateObjUtil.ossUtilCp("voice"+File.separator+"voice"+sceneNum + "/" + soundFile, partPath + File.separator); new File(partPath + File.separator + soundFile).renameTo(new File(partPath + File.separator + fileName)); } FileUtils.copyFile(partPath+File.separator+fileName, path + File.separator + originalFileName, true); uploadToOssUtil.upload(path+File.separator +originalFileName, "voice/voice"+sceneNum+"/"+originalFileName); String voiceSrc = prefixAli+"voice/voice"+sceneNum+"/"+originalFileName; if("s3".equals(this.type)){ voiceSrc = ConstantUrl.PREFIX_AWS+"voice/voice"+sceneNum+"/"+originalFileName; } sceneProEdit.setScreencapVoiceType("soundsync"); sceneProEdit.setScreencapVoiceSoundsync(voiceSrc); sceneProEdit.setVersion(scenejson.getIntValue("version")+1); sceneProEdit.setUpdateTime(Calendar.getInstance().getTime()); sceneProEditService.updateById(sceneProEdit); Map map = new HashMap(); map.put("screencapVoiceSoundsyncFileName", originalFileName); map.put("screencapVoiceSoundsync", voiceSrc); map.put("uploadVoiceSoundsync", 1); map.put("screencapVoiceType", type); map.put("version", scenejson.getIntValue("version")+1); FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map); FileUtils.deleteFile(path+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr"); return ResultData.ok(voiceSrc); } @Override public ResultData deleteRecordAudioPart(String sceneNum, String fileName, String times, String index, String type) throws Exception { if(StringUtils.isEmpty(sceneNum)){ throw new BusinessException(ErrorCode.FAILURE_CODE_3001); } ScenePro scenePro = baseMapper.findByNum(sceneNum); if(scenePro == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId()); //文件上传的位置可以自定义 String path = ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+sceneNum; File targetFile = new File(path); if (!targetFile.exists()) { targetFile.mkdirs(); } //默认为app文件名 String originalFileName = ConstantFileName.APP_VOICE_NAME + ".mp3"; if("wechat".equals(type)){ originalFileName = ConstantFileName.WECHAT_VOICE_NAME + ".mp3"; } log.info("上传的音频文件名:" + originalFileName); String strsceneInfos = FileUtils.readFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json"); JSONObject scenejson = new JSONObject(); if(strsceneInfos!=null) { scenejson = JSONObject.parseObject(strsceneInfos); } //判断分房间模块文件夹是否存在 String partPath = path + File.separator + "part"; File partFile = new File(partPath); if(!partFile.exists()){ partFile.mkdirs(); } //删除指定部分音频文件 FileUtils.deleteFile(partPath + File.separator + index + ".mp3"); //获取总音频多少段,每段时长 String[] time = times.split(","); //删除所有音频 if(StringUtils.isEmpty(times) || time.length == 0){ this.deleteAudio(sceneProEdit, scenejson, sceneNum); return ResultData.ok(); } //修改删除的部分视频后面部分音频名字,如删除1.MP3,则将2.mp3修改成1.mp3,往后以此类推 if(Integer.parseInt(index) < time.length) { for(int i = 0, len = time.length - Integer.parseInt(index); i < len; i++){ if(new File(partPath + File.separator + (Integer.parseInt(index) + 1 + i) + ".mp3").exists()){ FileUtils.copyFile(partPath + File.separator + (Integer.parseInt(index) + 1 + i) + ".mp3", partPath + File.separator + (Integer.parseInt(index) + i) + ".mp3", true); } } } //遍历判断音频是否存在,不存在生成空白音效 for(int i = 0, len = time.length; i < len; i++){ if(!new File(partPath + File.separator + i + ".mp3").exists()){ //某部分文件不存在,直接生成一段静音后拼接文件 CreateObjUtil.createMuteViode(Double.valueOf(time[i]), partPath + File.separator + i + ".mp3"); } } //拼接所有音频文件 if(time.length > 2){ //若是多部分,两个两个合并,最后合成最终文件 for(int i = 1, len = time.length; i < len; i++){ if(i == 1){ CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + ".mp3", partPath + File.separator + i + ".mp3", partPath + File.separator + i + "muteSound.mp3"); }else if(i == len - 1){ CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + "muteSound.mp3", partPath + File.separator + i + ".mp3", path + File.separator + originalFileName); }else { CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + "muteSound.mp3", partPath + File.separator + i + ".mp3", partPath + File.separator + i + "muteSound.mp3"); } } }else if(time.length == 2){ //若只有两部分,直接合并成最终文件 CreateObjUtil.mergeVideo(partPath + File.separator + "0.mp3", partPath + File.separator + "1.mp3", path + File.separator + originalFileName); }else { FileUtils.copyFile(partPath + File.separator + "0.mp3", path + File.separator + originalFileName, true); } uploadToOssUtil.upload(path+File.separator +originalFileName, "voice/voice"+sceneNum+"/"+originalFileName); String voiceSrc = prefixAli+"voice/voice"+sceneNum+"/"+originalFileName; if("s3".equals(this.type)){ voiceSrc = ConstantUrl.PREFIX_AWS+"voice/voice"+sceneNum+"/"+originalFileName; } Map map = new HashMap(); map.put("screencapVoiceSoundsyncFileName", originalFileName); map.put("screencapVoiceSoundsync", voiceSrc); map.put("uploadVoiceSoundsync", 0); map.put("screencapVoiceType", "soundsync"); map.put("version", scenejson.getIntValue("version")+1); sceneProEdit.setScreencapVoiceType("soundsync"); sceneProEdit.setScreencapVoiceSoundsync(voiceSrc); sceneProEdit.setVersion(scenejson.getIntValue("version")+1); sceneProEdit.setUpdateTime(Calendar.getInstance().getTime()); sceneProEditService.updateById(sceneProEdit); FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map); return ResultData.ok(voiceSrc); } @Override public ResultData uploadFloorJsonAndRebuild(SceneEditVO sceneEdit) throws Exception { String lockKey = String.format(RedisKey.LOCK_UPLOAD_FLOORJSON_REBUILD, sceneEdit.getSceneNum()); Boolean lock = redisLockUtil.lock(lockKey, RedisKey.EXPIRE_TIME_2_HOUR); if(!lock){ throw new BusinessException(ErrorCode.FAILURE_CODE_5036); } try { long start = System.currentTimeMillis(); log.info("画墙重建模型开始时间:{}", start); if(StringUtils.isEmpty(sceneEdit.getSceneNum())){ throw new BusinessException(ErrorCode.FAILURE_CODE_3001); } ScenePro scenePro = baseMapper.findByNum(sceneEdit.getSceneNum()); if(scenePro == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId()); if(sceneProEdit == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } //更新scene.json文件 String strsceneInfos = FileUtils.readFile(ConstantFilePath.SCENE_PATH + "data" + File.separator + "data" + sceneEdit.getSceneNum() + File.separator + "scene.json"); JSONObject scenejson = new JSONObject(); if(strsceneInfos!=null) { scenejson = JSONObject.parseObject(strsceneInfos); }else { new File(ConstantFilePath.SCENE_PATH + "data" + File.separator + "data" + sceneEdit.getSceneNum() + File.separator + "scene.json").createNewFile(); } if(!StringUtils.isEmpty(sceneEdit.getSceneData())){ JSONObject sceneObject = JSONObject.parseObject(sceneEdit.getSceneData()); Set set =sceneObject.keySet(); for(String key : set){ scenejson.put(key, sceneObject.get(key)); } } //保存floor.json前端下次进入需要使用 if(StringUtils.isEmpty(sceneEdit.getWebFloor())){ sceneEdit.setWebFloor(sceneEdit.getFloor()); } //上传过模型只更新floor.json FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+sceneEdit.getSceneNum() + File.separator + "floor.json", new String(sceneEdit.getWebFloor().getBytes(), "UTF-8")); //更新scene.json文件 if(strsceneInfos!=null) { scenejson.put("floorEditVer", sceneProEdit.getFloorPublishVer() + 1); scenejson.put("floorPublishVer", sceneProEdit.getFloorPublishVer() + 1); FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+sceneEdit.getSceneNum()+File.separator+"scene.json", scenejson.toString()); log.info("写入scene.json文件完成, sceneCode:{}", sceneEdit.getSceneNum()); } //floorEditVer字段增加1 sceneProEdit.setFloorEditVer(sceneProEdit.getFloorPublishVer() + 1); sceneProEdit.setFloorPublishVer(sceneProEdit.getFloorPublishVer() + 1); sceneProEdit.setUpdateTime(Calendar.getInstance().getTime()); sceneProEditService.updateById(sceneProEdit); uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+sceneEdit.getSceneNum() + File.separator + "floor.json", "data"+File.separator+"data"+sceneEdit.getSceneNum() + File.separator + "floor.json"); }catch (Exception e){ log.error("画墙重建模型失败...", e); throw new BusinessException(ErrorCode.FAILURE_CODE_5039); }finally { redisLockUtil.unlock(lockKey); } return ResultData.ok(); } @Override public ResultData saveScreencapData(SceneEditVO base) throws Exception { if(StringUtils.isEmpty(base.getSceneNum())){ throw new BusinessException(ErrorCode.FAILURE_CODE_3001); } ScenePro scenePro = baseMapper.findByNum(base.getSceneNum()); if(scenePro == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } StringBuffer dataBuf = new StringBuffer() .append("data").append(File.separator) .append("data").append(scenePro.getSceneCode()) .append(File.separator); StringBuffer imagesBuf = new StringBuffer() .append("images").append(File.separator) .append("images").append(scenePro.getSceneCode()) .append(File.separator); StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString()); StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString()); String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json"); JSONObject scenejson = new JSONObject(); if(strsceneInfos!=null) { scenejson = JSONObject.parseObject(strsceneInfos); } //上传七牛 Map map = new HashMap(); SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId()); scenejson.put("screencapVoiceSound", ""); sceneProEdit.setScreencapVoiceSound(""); if(base.getScreencapVoiceType() != null){ scenejson.put("screencapVoiceType", base.getScreencapVoiceType()); sceneProEdit.setScreencapVoiceType(base.getScreencapVoiceType()); } if(!StringUtils.isEmpty(base.getCapData())){ FileUtils.writeFile(dataBuffer.toString() + "capData.json", new String(base.getCapData().getBytes(), "UTF-8")); scenejson.put("capData", dataBuf.toString() + "capData.json"); } if(!StringUtils.isEmpty(base.getFrameData())){ FileUtils.writeFile(dataBuffer.toString() + "frameData.json", new String(base.getFrameData().getBytes(), "UTF-8")); scenejson.put("frameData", dataBuf.toString() + "frameData.json"); } if(!StringUtils.isEmpty(base.getPlayData())){ FileUtils.writeFile(dataBuffer.toString() + "playData.json", new String(base.getPlayData().getBytes(), "UTF-8")); scenejson.put("playData", dataBuf.toString() + "playData.json"); sceneProEdit.setPlayData(dataBuf.toString() + "playData.json"); map.put(dataBuffer.toString() + "playData.json", dataBuf.toString() + "playData.json"); } if(!StringUtils.isEmpty(base.getScreencapThumb())){ FileUtils.writeFile(dataBuffer.toString() + "screencapThumb.json", new String(base.getScreencapThumb().getBytes(), "UTF-8")); scenejson.put("screencapThumb", dataBuf.toString() + "screencapThumb.json"); sceneProEdit.setScreencapThumb(dataBuf.toString() + "screencapThumb.json"); map.put(dataBuffer.toString() + "screencapThumb.json", dataBuf.toString() + "screencapThumb.json"); } if(!StringUtils.isEmpty(base.getRecordType())){ scenejson.put("recordType", base.getRecordType()); } if(map.size()>0) { uploadToOssUtil.uploadMulFiles(map); } sceneProEdit.setVersion(scenejson.getIntValue("version") + 1); sceneProEdit.setUpdateTime(Calendar.getInstance().getTime()); sceneProEditService.updateById(sceneProEdit); log.info("scene.json路径:" + dataBuffer.toString() + "scene.json"); scenejson.put("version", scenejson.getIntValue("version") + 1); FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString()); return ResultData.ok(); } public ResultData saveAllVisi(SceneEditVO base) throws Exception { if(StrUtil.isEmpty(base.getSceneNum())){ throw new BusinessException(ErrorCode.FAILURE_CODE_3001); } ScenePro scenePro = baseMapper.findByNum(base.getSceneNum()); if(scenePro == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId()); StringBuffer dataBuf = new StringBuffer() .append("data").append(File.separator) .append("data").append(scenePro.getSceneCode()) .append(File.separator); StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString()); String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json"); JSONObject scenejson = new JSONObject(); if(strsceneInfos!=null) { scenejson = JSONObject.parseObject(strsceneInfos); } this.updateVisiData(base, sceneProEdit, scenejson); sceneProEdit.setVersion(scenejson.getIntValue("version") + 1); scenejson.put("version", scenejson.getIntValue("version") + 1); sceneProEdit.setUpdateTime(Calendar.getInstance().getTime()); sceneProEditService.updateById(sceneProEdit); FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString()); return ResultData.ok(); } @Override public ResultData uploadFloorplanPng(String sceneNum, MultipartFile file, String cadInfo) throws Exception { if(StringUtils.isEmpty(sceneNum)){ throw new BusinessException(ErrorCode.FAILURE_CODE_3001); } if (file.isEmpty() && file.getSize() <= 0) { throw new BusinessException(ErrorCode.FAILURE_CODE_5012); } ScenePro scenePro = baseMapper.findByNum(sceneNum); if(scenePro == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } String lockKey = String.format(RedisKey.LOCK_UPLOAD_FLOORPLAN_PNG, sceneNum); Boolean lock = redisLockUtil.lock(lockKey, RedisKey.EXPIRE_TIME_30_MINUTE); if(!lock){ throw new BusinessException(ErrorCode.FAILURE_CODE_5036); } String fileName = "floorplan.png"; try { StringBuffer dataBuf = new StringBuffer() .append("data").append(File.separator) .append("data").append(scenePro.getSceneCode()) .append(File.separator); StringBuffer imagesBuf = new StringBuffer() .append("images").append(File.separator) .append("images").append(scenePro.getSceneCode()) .append(File.separator); StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString()); StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString()); //文件上传的位置可以自定义 String path = ConstantFilePath.SCENE_PATH+"images"+File.separator+"images"+sceneNum; File targetFile = new File(path); if (!targetFile.exists()) { targetFile.mkdirs(); } targetFile = new File(path + File.separator + fileName); // 保存 if(targetFile.exists()) { FileUtils.deleteFile(path + File.separator + fileName); } file.transferTo(targetFile); SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId()); SceneProEditExt sceneProEditExt = sceneProEditExtService.getOne( new QueryWrapper().eq("pro_edit_id", sceneProEdit.getId())); String floorPlanPng = "images"+File.separator+"images"+sceneNum + File.separator + fileName; Map map = new HashMap<>(); map.put("floorPlanPng", floorPlanPng); map.put("uploadFloorPlanPng", 1); map.put("version", sceneProEdit.getVersion()+1); if(StrUtil.isNotEmpty(cadInfo)){ map.put("cadInfo", cadInfo); sceneProEditExt.setCadInfo(cadInfo); } sceneProEditExt.setFloorPlanPng(floorPlanPng + "?t=" + System.currentTimeMillis()); sceneProEditExt.setUpdateTime(Calendar.getInstance().getTime()); sceneProEditExtService.updateById(sceneProEditExt); sceneProEdit.setVersion(sceneProEdit.getVersion() + 1); sceneProEdit.setUpdateTime(Calendar.getInstance().getTime()); sceneProEditService.updateById(sceneProEdit); FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map); uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH+floorPlanPng, floorPlanPng); }catch (Exception e){ log.error("上传图片多媒体数据失败...", e); throw new BusinessException(ErrorCode.FAILURE_CODE_5041); }finally { redisLockUtil.unlock(lockKey); } return ResultData.ok("images"+File.separator+"images"+sceneNum + File.separator + fileName); } @Override public ResultData uploadBgMusic(String sceneNum, String fileName, MultipartFile file) throws Exception { if(StringUtils.isEmpty(sceneNum) || StringUtils.isEmpty(fileName)){ throw new BusinessException(ErrorCode.FAILURE_CODE_3001); } ScenePro scenePro = baseMapper.findByNum(sceneNum); if(scenePro == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId()); SceneProEditExt sceneProEditExt = sceneProEditExtService.getOne( new QueryWrapper().eq("pro_edit_id", sceneProEdit.getId())); StringBuffer dataBuf = new StringBuffer() .append("data").append(File.separator) .append("data").append(scenePro.getSceneCode()) .append(File.separator); StringBuffer imagesBuf = new StringBuffer() .append("images").append(File.separator) .append("images").append(scenePro.getSceneCode()) .append(File.separator); StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString()); StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString()); File buMusicFile = new File(imagesBuffer.toString() + fileName); if(!buMusicFile.getParentFile().exists()){ buMusicFile.getParentFile().mkdirs(); } //上传文件 file.transferTo(buMusicFile); uploadToOssUtil.upload(imagesBuffer.toString() + fileName, imagesBuf + fileName); String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json"); JSONObject scenejson = new JSONObject(); if(strsceneInfos!=null) { scenejson = JSONObject.parseObject(strsceneInfos); } sceneProEditExt.setBgMusicName(fileName); sceneProEditExt.setUpdateTime(Calendar.getInstance().getTime()); sceneProEditExtService.updateById(sceneProEditExt); sceneProEdit.setVersion(scenejson.getIntValue("version") + 1); sceneProEdit.setUpdateTime(Calendar.getInstance().getTime()); sceneProEditService.updateById(sceneProEdit); scenejson.put("bgMusicName", fileName); scenejson.put("uploadBgMusic", 0); scenejson.put("version", scenejson.getIntValue("version") + 1); FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString()); return ResultData.ok(); } @Override public ResultData deleteUploadBgMusic(String sceneNum) throws Exception { if(StringUtils.isEmpty(sceneNum)){ throw new BusinessException(ErrorCode.FAILURE_CODE_3001); } ScenePro scenePro = baseMapper.findByNum(sceneNum); if(scenePro == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId()); SceneProEditExt sceneProEditExt = sceneProEditExtService.getOne( new QueryWrapper().eq("pro_edit_id", sceneProEdit.getId())); StringBuffer dataBuf = new StringBuffer() .append("data").append(File.separator) .append("data").append(scenePro.getSceneCode()) .append(File.separator); StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString()); String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json"); JSONObject scenejson = new JSONObject(); if(strsceneInfos!=null) { scenejson = JSONObject.parseObject(strsceneInfos); } sceneProEditExt.setBgMusicName(""); sceneProEditExt.setUpdateTime(Calendar.getInstance().getTime()); sceneProEditExtService.updateById(sceneProEditExt); sceneProEdit.setVersion(scenejson.getIntValue("version") + 1); sceneProEditService.updateById(sceneProEdit); scenejson.put("bgMusicName", ""); scenejson.put("version", scenejson.getIntValue("version") + 1); FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString()); return ResultData.ok(); } private void updateVisiData(SceneEditVO base, SceneProEdit sceneProEdit, JSONObject scenejson){ SceneProEditExt sceneProEditExt = sceneProEditExtService.getOne( new QueryWrapper().eq("pro_edit_id", sceneProEdit.getId())); if(!StringUtils.isEmpty(base.getMapVisi())){ scenejson.put("mapVisi", Integer.parseInt(base.getMapVisi())); sceneProEditExt.setMapVisi(Integer.parseInt(base.getMapVisi())); } if(!StringUtils.isEmpty(base.getTourVisi())){ scenejson.put("tourVisi", Integer.parseInt(base.getTourVisi())); sceneProEditExt.setTourVisi(Integer.parseInt(base.getTourVisi())); } if(!StringUtils.isEmpty(base.getVrVisi())){ scenejson.put("vrVisi", Integer.parseInt(base.getVrVisi())); sceneProEditExt.setVrVisi(Integer.parseInt(base.getVrVisi())); } if(!StringUtils.isEmpty(base.getRulerVisi())){ scenejson.put("rulerVisi", Integer.parseInt(base.getRulerVisi())); sceneProEditExt.setRulerVisi(Integer.parseInt(base.getRulerVisi())); } if(!StringUtils.isEmpty(base.getCadImgVisi())){ scenejson.put("cadImgVisi", Integer.parseInt(base.getCadImgVisi())); sceneProEditExt.setCadImgVisi(Integer.parseInt(base.getCadImgVisi())); } if(!StringUtils.isEmpty(base.getPanoVisi())){ scenejson.put("panoVisi", Integer.parseInt(base.getPanoVisi())); sceneProEditExt.setPanoVisi(Integer.parseInt(base.getPanoVisi())); } if(!StringUtils.isEmpty(base.getM2dVisi())){ scenejson.put("m2dVisi", Integer.parseInt(base.getM2dVisi())); sceneProEditExt.setM2dVisi(Integer.parseInt(base.getM2dVisi())); } if(!StringUtils.isEmpty(base.getM3dVisi())){ scenejson.put("m3dVisi", Integer.parseInt(base.getM3dVisi())); sceneProEditExt.setM3dVisi(Integer.parseInt(base.getM3dVisi())); } if(!StringUtils.isEmpty(base.getMeasureVisi())){ scenejson.put("measureVisi", Integer.parseInt(base.getMeasureVisi())); sceneProEditExt.setMeasureVisi(Integer.parseInt(base.getMeasureVisi())); } sceneProEditExt.setUpdateTime(Calendar.getInstance().getTime()); sceneProEditExtService.updateById(sceneProEditExt); } private void deleteAudio(SceneProEdit sceneProEdit, JSONObject scenejson, String sceneNum) throws Exception { sceneProEdit.setScreencapVoiceType(""); sceneProEdit.setScreencapVoiceSoundsync(""); sceneProEdit.setVersion(scenejson.getIntValue("version")+1); sceneProEdit.setUpdateTime(Calendar.getInstance().getTime()); sceneProEditService.updateById(sceneProEdit); Map map = new HashMap(); map.put("screencapVoiceSoundsyncFileName", ""); map.put("screencapVoiceSoundsync", ""); map.put("uploadVoiceSoundsync", 0); map.put("screencapVoiceType", ""); map.put("version", scenejson.getIntValue("version")+1); FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map); } private String replaceForAppV3(SceneProEdit sceneProEdit, JSONObject scenejson, String path, String partPath, String fileName, String originalFileName, String sceneNum, String times, String soundFile) throws Exception { if(new File(partPath+File.separator+fileName).exists()) { FileUtils.deleteFile(partPath + File.separator + fileName); } if("s3".equals(this.type)){ CreateObjUtil.ossFileCp("voice"+File.separator+"voice"+sceneNum + "/" + soundFile, partPath + File.separator + fileName); }else { CreateObjUtil.ossUtilCp("voice"+File.separator+"voice"+sceneNum + "/" + soundFile, partPath + File.separator); new File(partPath + File.separator + soundFile).renameTo(new File(partPath + File.separator + fileName)); } //获取总音频多少段,每段时长 String[] time = times.split(","); //遍历判断音频是否存在,不存在生成空白音效 for(int i = 0, len = time.length; i < len; i++){ if(!new File(partPath + File.separator + i + ".mp3").exists()){ //某部分文件不存在,直接生成一段静音后拼接文件 CreateObjUtil.createMuteViode(Double.valueOf(time[i]), partPath + File.separator + i + ".mp3"); } } //拼接所有音频文件 if(time.length > 2){ //若是多部分,两个两个合并,最后合成最终文件 for(int i = 1, len = time.length; i < len; i++){ if(i == 1){ CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + ".mp3", partPath + File.separator + i + ".mp3", partPath + File.separator + i + "muteSound.mp3"); }else if(i == len - 1){ CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + "muteSound.mp3", partPath + File.separator + i + ".mp3", path + File.separator + originalFileName); }else { CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + "muteSound.mp3", partPath + File.separator + i + ".mp3", partPath + File.separator + i + "muteSound.mp3"); } } }else { //若只有两部分,直接合并成最终文件 CreateObjUtil.mergeVideo(partPath + File.separator + "0.mp3", partPath + File.separator + "1.mp3", path + File.separator + originalFileName); } uploadToOssUtil.upload(path+File.separator +originalFileName, "voice/voice"+sceneNum+"/"+originalFileName); String voiceSrc = prefixAli+"voice/voice"+sceneNum+"/"+originalFileName; if("s3".equals(this.type)){ voiceSrc = ConstantUrl.PREFIX_AWS+"voice/voice"+sceneNum+"/"+originalFileName; } sceneProEdit.setScreencapVoiceType("soundsync"); sceneProEdit.setScreencapVoiceSoundsync(voiceSrc); sceneProEdit.setVersion(scenejson.getIntValue("version")+1); sceneProEdit.setUpdateTime(Calendar.getInstance().getTime()); sceneProEditService.updateById(sceneProEdit); Map map = new HashMap(); map.put("screencapVoiceSoundsyncFileName", originalFileName); map.put("screencapVoiceSoundsync", voiceSrc); map.put("uploadVoiceSoundsync", 1); map.put("screencapVoiceType", type); map.put("version", scenejson.getIntValue("version")+1); FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map); FileUtils.deleteFile(path+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr"); return voiceSrc; } private String replaceForWeixinV3(SceneProEdit sceneProEdit, JSONObject scenejson, String path, String partPath, String fileName, String originalFileName, String sceneNum, String times) throws Exception { this.dealVioce(path, partPath, fileName, originalFileName, sceneNum, times); String voiceSrc = prefixAli+"voice/voice"+sceneNum+"/"+originalFileName; if("s3".equals(this.type)){ voiceSrc = ConstantUrl.PREFIX_AWS+"voice/voice"+sceneNum+"/"+originalFileName; } Map map = new HashMap(); map.put("screencapVoiceSoundsyncFileName", originalFileName); map.put("screencapVoiceSoundsync", voiceSrc); map.put("uploadVoiceSoundsync", 1); map.put("screencapVoiceType", type); map.put("version", scenejson.getIntValue("version")+1); sceneProEdit.setScreencapVoiceType("soundsync"); sceneProEdit.setScreencapVoiceSoundsync(voiceSrc); sceneProEdit.setVersion(scenejson.getIntValue("version")+1); sceneProEdit.setUpdateTime(Calendar.getInstance().getTime()); sceneProEditService.updateById(sceneProEdit); FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map); FileUtils.deleteFile(path+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr"); return voiceSrc; } private void dealVioce(String path, String partPath, String fileName, String originalFileName, String sceneNum, String times) throws Exception { if(new File(partPath+File.separator+fileName).exists()) { FileUtils.deleteFile(partPath + File.separator + fileName); } FileUtils.changeVoiceToMp3(path+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr", partPath+File.separator+fileName); //获取总音频多少段,每段时长 String[] time = times.split(","); //遍历判断音频是否存在,不存在生成空白音效 for(int i = 0, len = time.length; i < len; i++){ if(!new File(partPath + File.separator + i + ".mp3").exists()){ //某部分文件不存在,直接生成一段静音后拼接文件 CreateObjUtil.createMuteViode(Double.valueOf(time[i]), partPath + File.separator + i + ".mp3"); } } //拼接所有音频文件 if(time.length > 2){ //若是多部分,两个两个合并,最后合成最终文件 for(int i = 1, len = time.length; i < len; i++){ if(i == 1){ // FileUtils.deleteFile(partPath + File.separator + i + "muteSound.mp3"); CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + ".mp3", partPath + File.separator + i + ".mp3", partPath + File.separator + i + "muteSound.mp3"); }else if(i == len - 1){ CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + "muteSound.mp3", partPath + File.separator + i + ".mp3", path + File.separator + originalFileName); }else { CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + "muteSound.mp3", partPath + File.separator + i + ".mp3", partPath + File.separator + i + "muteSound.mp3"); } } }else { //若只有两部分,直接合并成最终文件 CreateObjUtil.mergeVideo(partPath + File.separator + "0.mp3", partPath + File.separator + "1.mp3", path + File.separator + originalFileName); } uploadToOssUtil.upload(path+File.separator +originalFileName, "voice/voice"+sceneNum+"/"+originalFileName); } private void saveImageToDisk(String path, String id) throws Exception { String accessToken = WeiXinUtils.getAccessToken(); InputStream is = null; String url = "https://file.api.weixin.qq.com/cgi-bin/media/get?access_token="+ accessToken + "&media_id=" + id; log.info("url:" + url); URL urlGet = new URL(url); HttpURLConnection http = (HttpURLConnection) urlGet .openConnection(); http.setRequestMethod("GET"); // 必须是get方式请求 http.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); http.setDoOutput(true); http.setDoInput(true); System.setProperty("sun.net.client.defaultConnectTimeout", "30000");// 连接超时30秒 System.setProperty("sun.net.client.defaultReadTimeout", "30000"); // 读取超时30秒 http.connect(); // 获取文件转化为byte流 is = http.getInputStream(); File dic = new File(path); if(!dic.exists()) { dic.mkdirs(); } File voice = new File(path+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr"); if(voice.exists()) { FileUtils.deleteFile(path+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr"); } FileUtils.saveImageToDisk(accessToken, id, ConstantFileName.WECHAT_VOICE_NAME, path+File.separator, is); } private Object[] getUploadFileMapAndSceneJson(SceneEditVO base, JSONArray jsonhots, JSONObject jsonhot, String sid, StringBuffer imagesBuf, StringBuffer imagesBuffer, StringBuffer dataBuf, StringBuffer dataBuffer) throws Exception { Object[] result = new Object[2]; Map map = new HashMap(); if(jsonhot.containsKey("media")) { String fileType = jsonhot.getString("media"); if(fileType.contains("photo")) { if("-1".equals(base.getType())) { FileUtils.deleteFile(imagesBuffer.toString() + "hot"+sid+".jpg"); } else { map.put(imagesBuffer.toString() + "hot"+sid+".jpg", imagesBuf.toString() + "hot"+sid+".jpg"); } } if(fileType.contains("audio") || fileType.contains("voice")) { if("-1".equals(base.getType())) { FileUtils.deleteFile(imagesBuffer.toString() + "hot"+sid+".mp3"); } else { map.put(imagesBuffer.toString() + "hot"+sid+".mp3", imagesBuf.toString() + "hot"+sid+".mp3"); } } if(fileType.contains("video")) { if("-1".equals(base.getType())) { FileUtils.deleteFile(imagesBuffer.toString() + "hot"+sid+".mp4"); } else { map.put(imagesBuffer.toString() + "hot"+sid+".mp4", imagesBuf.toString() + "hot"+sid+".mp4"); map.put(imagesBuffer.toString() + "hot"+sid+"-cut.jpg", imagesBuf.toString() + "hot"+sid+"-cut.jpg"); } } } FileUtils.deleteFile(dataBuffer.toString() + "hot.json"); File dataPath = new File(dataBuffer.toString()); if(!dataPath.exists()){ dataPath.mkdirs(); } FileUtils.writeFile(dataBuffer.toString() + "hot.json", jsonhots.toString()); map.put(dataBuffer.toString() + "hot.json", dataBuf.toString() + "hot.json"); String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json"); JSONObject scenejson = new JSONObject(); if(strsceneInfos!=null){ scenejson = JSONObject.parseObject(strsceneInfos); } if(!StringUtils.isEmpty(base.getCapData())){ FileUtils.writeFile(dataBuffer.toString() + "capData.json", new String(base.getCapData().getBytes(), "UTF-8")); scenejson.put("capData", dataBuf.toString() + "capData.json"); } if(!StringUtils.isEmpty(base.getFrameData())){ FileUtils.writeFile(dataBuffer.toString() + "frameData.json", new String(base.getFrameData().getBytes(), "UTF-8")); scenejson.put("frameData", dataBuf.toString() + "frameData.json"); } if(!StringUtils.isEmpty(base.getPlayData())){ FileUtils.writeFile(dataBuffer.toString() + "playData.json", new String(base.getPlayData().getBytes(), "UTF-8")); scenejson.put("playData", dataBuf.toString() + "playData.json"); map.put(dataBuffer.toString() + "playData.json", dataBuf.toString() + "playData.json"); } if(!StringUtils.isEmpty(base.getScreencapThumb())){ FileUtils.writeFile(dataBuffer.toString() + "screencapThumb.json", new String(base.getScreencapThumb().getBytes(), "UTF-8")); scenejson.put("screencapThumb", dataBuf.toString() + "screencapThumb.json"); map.put(dataBuffer.toString() + "screencapThumb.json", dataBuf.toString() + "screencapThumb.json"); } if(jsonhots.size()>0){ scenejson.put("hots", 1); } else{ scenejson.put("hots", 0); } result[0] = map; result[1] = scenejson; return result; } private String deleteCustomStyleHots(SceneEditVO base, JSONArray jsonhots, JSONObject jsonhot, String sid){ String hotsids = ""; String[] styles = null; if(StrUtil.isNotEmpty(base.getStyleName())){ styles = base.getStyleName().split(","); } for(int i=0;i