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.extension.service.impl.ServiceImpl; import com.fdkankan.model.constants.ConstantFileName; import com.fdkankan.model.constants.ConstantFilePath; import com.fdkankan.common.constant.ConstantUrl; import com.fdkankan.common.constant.ErrorCode; import com.fdkankan.common.exception.BusinessException; import com.fdkankan.common.response.ResultData; import com.fdkankan.model.utils.CreateObjUtil; import com.fdkankan.common.util.FileUtils; import com.fdkankan.common.util.OkHttpUtils; import com.fdkankan.common.util.WeiXinUtils; import com.fdkankan.fyun.constant.FYunTypeEnum; import com.fdkankan.fyun.face.FYunFileServiceInterface; import com.fdkankan.scene.bean.RequestSceneEdit; import com.fdkankan.scene.entity.ScenePro; import com.fdkankan.scene.entity.SceneProEdit; import com.fdkankan.scene.mapper.ISceneProMapper; import com.fdkankan.scene.service.ISceneProAppService; import com.fdkankan.scene.service.ISceneProEditService; import com.fdkankan.scene.service.ISceneProService; 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.HashMap; import java.util.Map; import java.util.Set; 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.Value; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; /** * Created by Hb_zzZ on 2019/6/28. */ @Slf4j @Service public class SceneProAppServiceImpl extends ServiceImpl implements ISceneProAppService { @Autowired private ISceneProService sceneProService; @Autowired private ISceneProEditService sceneProEditService; @Autowired private FYunFileServiceInterface fYunFileService; @Value("${hot.domain.list}") private String hotDomainList; @Value("${hot.delete}") private String hotDelete; @Value("${fyun.host}") private String ossPrefixUrl; @Value("fyun.type") private String ossType; @Override public ResultData uploadFloorplanPng(String sceneNum, MultipartFile file, String cadInfo) throws Exception { ScenePro sceneProEntity = sceneProService.findBySceneNum(sceneNum); if(sceneProEntity == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } if (file.isEmpty() && file.getSize() <= 0) { throw new BusinessException(ErrorCode.FAILURE_CODE_5012); } StringBuffer dataBuf = new StringBuffer() .append("data").append(File.separator) .append("data").append(sceneProEntity.getNum()) .append(File.separator); StringBuffer imagesBuf = new StringBuffer() .append("images").append(File.separator) .append("images").append(sceneProEntity.getNum()) .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(); } String fileName = "floorplan.png"; targetFile = new File(path + File.separator + fileName); // 保存 synchronized(this) { if(targetFile.exists()) { FileUtils.deleteFile(path + File.separator + fileName); } file.transferTo(targetFile); } SceneProEdit sceneProEditEntity = sceneProEditService.findBySceneProId(sceneProEntity.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", sceneProEditEntity.getVersion()+1); if(StrUtil.isNotEmpty(cadInfo)){ map.put("cadInfo", cadInfo); sceneProEditEntity.setCadInfo(cadInfo); } FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map); sceneProEditEntity.setFloorPlanPng(floorPlanPng + "?t=" + System.currentTimeMillis()); sceneProEditEntity.setVersion(sceneProEditEntity.getVersion() + 1); Map oss = new HashMap<>(); fYunFileService.uploadFile(ConstantFilePath.SCENE_PATH+floorPlanPng, floorPlanPng); sceneProEditService.updateById(sceneProEditEntity); return ResultData.ok("images"+File.separator+"images"+sceneNum + File.separator + fileName); } @Override public ResultData uploadFloorJsonAndRebuild(RequestSceneEdit sceneEdit) throws Exception { String lock = sceneEdit.getSceneNum().toString().intern(); synchronized(lock){ long start = System.currentTimeMillis(); log.info("画墙重建模型开始时间:" + start); if(StringUtils.isEmpty(sceneEdit.getSceneNum())){ throw new BusinessException(ErrorCode.FAILURE_CODE_3001); } ScenePro sceneProEntity = sceneProService.findBySceneNum(sceneEdit.getSceneNum()); if(sceneProEntity == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } SceneProEdit sceneProEditEntity = sceneProEditService.findBySceneProId(sceneProEntity.getId()); if(sceneProEditEntity == 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 // if(scenejson.containsKey("isUploadObj") && scenejson.getBooleanValue("isUploadObj")){ 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", sceneProEditEntity.getFloorPublishVer() + 1); scenejson.put("floorPublishVer", sceneProEditEntity.getFloorPublishVer() + 1); FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+sceneEdit.getSceneNum()+File.separator+"scene.json", scenejson.toString()); log.info("写入scene.json文件完成——"+sceneEdit.getSceneNum()); } //floorEditVer字段增加1 sceneProEditEntity.setFloorEditVer(sceneProEditEntity.getFloorPublishVer() + 1); sceneProEditEntity.setFloorPublishVer(sceneProEditEntity.getFloorPublishVer() + 1); sceneProEditService.updateById(sceneProEditEntity); fYunFileService.uploadFile(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+sceneEdit.getSceneNum() + File.separator + "floor.json", "data"+File.separator+"data"+sceneEdit.getSceneNum() + File.separator + "floor.json"); } return ResultData.ok(); } @Override public ResultData deleteRecordAudioPart(String sceneNum, String fileName, String times, String index, String type) throws Exception { if(StrUtil.isEmpty(sceneNum)){ throw new BusinessException(ErrorCode.FAILURE_CODE_3001 ); } ScenePro sceneProEntity = sceneProService.findBySceneNum(sceneNum); if(sceneProEntity == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } SceneProEdit sceneProEditEntity = sceneProEditService.findBySceneProId(sceneProEntity.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){ Map map = new HashMap(); map.put("screencapVoiceSoundsyncFileName", ""); map.put("screencapVoiceSoundsync", ""); map.put("uploadVoiceSoundsync", 0); map.put("screencapVoiceType", ""); map.put("version", scenejson.getIntValue("version")+1); sceneProEditEntity.setScreencapVoiceType(""); sceneProEditEntity.setScreencapVoiceSoundsync(""); sceneProEditEntity.setVersion(scenejson.getIntValue("version")+1); FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map); sceneProEditService.updateById(sceneProEditEntity); 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){ // 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 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); } fYunFileService.uploadFile(path+File.separator +originalFileName, "voice/voice"+sceneNum+"/"+originalFileName); String voiceSrc = ossPrefixUrl+"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); sceneProEditEntity.setScreencapVoiceType("soundsync"); sceneProEditEntity.setScreencapVoiceSoundsync(voiceSrc); sceneProEditEntity.setVersion(scenejson.getIntValue("version")+1); FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map); sceneProEditService.updateById(sceneProEditEntity); return ResultData.ok(voiceSrc); } @Override public ResultData getRecordAudioFromWeixin(RequestSceneEdit base) throws Exception{ if(StrUtil.isEmpty(base.getSceneNum()) || StrUtil.isEmpty(base.getId())){ throw new BusinessException(ErrorCode.FAILURE_CODE_3001); } ScenePro sceneProEntity = sceneProService.findBySceneNum(base.getSceneNum()); if(sceneProEntity == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } SceneProEdit sceneProEditEntity = sceneProEditService.findBySceneProId(sceneProEntity.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"; fYunFileService.uploadFile(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 = ossPrefixUrl+"voice/voice"+base.getSceneNum()+"/"+originalFileName; map.put("screencapVoiceSoundsync", voiceSrc); log.info("微信上传的音频路径:" + voiceSrc); map.put("screencapVoiceType", "soundsync"); map.put("version", sceneProEditEntity.getVersion()+1); FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + base.getSceneNum() + "/scene.json", map); sceneProEditEntity.setScreencapVoiceType("soundsync"); sceneProEditEntity.setScreencapVoiceSoundsync(voiceSrc); sceneProEditEntity.setVersion(sceneProEditEntity.getVersion()); sceneProEditService.updateById(sceneProEditEntity); FileUtils.deleteFile(ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+base.getSceneNum()+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr"); if(FYunTypeEnum.AWS.code().equals(ossType)){ return ResultData.ok(ConstantUrl.PREFIX_AWS+"voice/voice"+base.getSceneNum()+"/"+originalFileName); } return ResultData.ok(ossPrefixUrl+"voice/voice"+base.getSceneNum()+"/"+originalFileName); } @Override public ResultData uploadPic(String sceneNum, String folderName, MultipartFile file) throws Exception{ if(StrUtil.isEmpty(sceneNum)){ throw new BusinessException(ErrorCode.FAILURE_CODE_3001); } ScenePro sceneProEntity = sceneProService.findBySceneNum(sceneNum); if(sceneProEntity == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } if (file.isEmpty() && file.getSize() <= 0) { throw new BusinessException(ErrorCode.FAILURE_CODE_5012); } //文件上传的位置可以自定义 String path = ConstantFilePath.SCENE_PATH+"images"+File.separator+"images"+sceneNum; if(StrUtil.isNotEmpty(folderName)) { path = path+File.separator + folderName; } File targetFile = new File(path); if (!targetFile.exists()) { targetFile.mkdirs(); } String fileName = file.getOriginalFilename(); targetFile = new File(path + File.separator + fileName); // 保存 synchronized(this) { if(targetFile.exists()) { FileUtils.deleteFile(path + File.separator + fileName); } file.transferTo(targetFile); } return ResultData.ok(targetFile.getName()); } @Override public ResultData saveSceneInfo(RequestSceneEdit base) throws Exception{ if(StrUtil.isEmpty(base.getSceneNum()) || StrUtil.isEmpty(base.getSceneName()) || StrUtil.isEmpty(base.getSceneType()) || StrUtil.isEmpty(base.getSceneDec())){ throw new BusinessException(ErrorCode.FAILURE_CODE_3001); } ScenePro sceneProEntity = sceneProService.findBySceneNum(base.getSceneNum()); if(sceneProEntity == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } SceneProEdit sceneProEditEntity = sceneProEditService.findBySceneProId(sceneProEntity.getId()); StringBuffer dataBuf = new StringBuffer() .append("data").append(File.separator) .append("data").append(sceneProEntity.getNum()) .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(sceneProEntity.getSceneType() == 99){ map.put("sceneType", sceneProEntity.getSceneType()); }else { sceneProEntity.setSceneType(Integer.parseInt(base.getSceneType())); map.put("sceneType", base.getSceneType()); } } if(!StringUtils.isEmpty(base.getSceneKey())) { map.put("sceneKey", base.getSceneKey()); map.put("needKey", 1); sceneProEditEntity.setNeedKey(1); }else { sceneProEditEntity.setNeedKey(0); map.put("sceneKey", ""); map.put("needKey", 0); } map.put("version", sceneProEditEntity.getVersion()+1); FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map); sceneProEntity.setSceneName(base.getSceneName()); sceneProEntity.setSceneDec(base.getSceneDec()); sceneProService.updateById(sceneProEntity); sceneProEditEntity.setSceneKey(base.getSceneKey()); sceneProEditEntity.setVersion(sceneProEditEntity.getVersion() + 1); sceneProEditService.updateById(sceneProEditEntity); return ResultData.ok(); } public ResultData saveAllVisi(RequestSceneEdit base) throws Exception { if(StrUtil.isEmpty(base.getSceneNum())){ throw new BusinessException(ErrorCode.FAILURE_CODE_3001); } ScenePro sceneProEntity = sceneProService.findBySceneNum(base.getSceneNum()); if(sceneProEntity == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } SceneProEdit sceneProEditEntity = sceneProEditService.findBySceneProId(sceneProEntity.getId()); StringBuffer dataBuf = new StringBuffer() .append("data").append(File.separator) .append("data").append(sceneProEntity.getNum()) .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); } if(!StringUtils.isEmpty(base.getMapVisi())){ scenejson.put("mapVisi", Integer.parseInt(base.getMapVisi())); sceneProEditEntity.setMapVisi(Integer.parseInt(base.getMapVisi())); } if(!StringUtils.isEmpty(base.getTourVisi())){ scenejson.put("tourVisi", Integer.parseInt(base.getTourVisi())); sceneProEditEntity.setTourVisi(Integer.parseInt(base.getTourVisi())); } if(!StringUtils.isEmpty(base.getVrVisi())){ scenejson.put("vrVisi", Integer.parseInt(base.getVrVisi())); sceneProEditEntity.setVrVisi(Integer.parseInt(base.getVrVisi())); } if(!StringUtils.isEmpty(base.getRulerVisi())){ scenejson.put("rulerVisi", Integer.parseInt(base.getRulerVisi())); sceneProEditEntity.setRulerVisi(Integer.parseInt(base.getRulerVisi())); } if(!StringUtils.isEmpty(base.getCadImgVisi())){ scenejson.put("cadImgVisi", Integer.parseInt(base.getCadImgVisi())); sceneProEditEntity.setCadImgVisi(Integer.parseInt(base.getCadImgVisi())); } if(!StringUtils.isEmpty(base.getPanoVisi())){ scenejson.put("panoVisi", Integer.parseInt(base.getPanoVisi())); sceneProEditEntity.setPanoVisi(Integer.parseInt(base.getPanoVisi())); } if(!StringUtils.isEmpty(base.getM2dVisi())){ scenejson.put("m2dVisi", Integer.parseInt(base.getM2dVisi())); sceneProEditEntity.setM2dVisi(Integer.parseInt(base.getM2dVisi())); } if(!StringUtils.isEmpty(base.getM3dVisi())){ scenejson.put("m3dVisi", Integer.parseInt(base.getM3dVisi())); sceneProEditEntity.setM3dVisi(Integer.parseInt(base.getM3dVisi())); } if(!StringUtils.isEmpty(base.getMeasureVisi())){ scenejson.put("measureVisi", Integer.parseInt(base.getMeasureVisi())); sceneProEditEntity.setMeasureVisi(Integer.parseInt(base.getMeasureVisi())); } sceneProEditEntity.setVersion(scenejson.getIntValue("version") + 1); scenejson.put("version", scenejson.getIntValue("version") + 1); FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString()); sceneProEditService.updateById(sceneProEditEntity); return ResultData.ok(); } @Override public ResultData saveInitialPage(RequestSceneEdit base) throws Exception { if(StringUtils.isEmpty(base.getSceneNum()) || StringUtils.isEmpty(base.getInitialPoint())){ throw new BusinessException(ErrorCode.FAILURE_CODE_3001); } ScenePro sceneProEntity = sceneProService.findBySceneNum(base.getSceneNum()); if(sceneProEntity == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } SceneProEdit sceneProEditEntity = sceneProEditService.findBySceneProId(sceneProEntity.getId()); StringBuffer dataBuf = new StringBuffer() .append("data").append(File.separator) .append("data").append(sceneProEntity.getNum()) .append(File.separator); StringBuffer imagesBuf = new StringBuffer() .append("images").append(File.separator) .append("images").append(sceneProEntity.getNum()) .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", sceneProEditEntity.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"); fYunFileService.uploadMulFiles(uploadMap); sceneProEditEntity.setEntry(base.getInitialPoint()); sceneProEditEntity.setThumbStatus(1); sceneProEditEntity.setVersion(sceneProEditEntity.getVersion() + 1); sceneProEditService.updateById(sceneProEditEntity); sceneProEntity.setThumb(ossPrefixUrl + imagesBuf.toString() + "thumbSmallImg.jpg"); sceneProService.updateById(sceneProEntity); return ResultData.ok(); } @Override public ResultData saveBackgroundMusic(RequestSceneEdit base) throws Exception { if(StringUtils.isEmpty(base.getSceneNum()) || StringUtils.isEmpty(base.getMusicName())){ throw new BusinessException(ErrorCode.FAILURE_CODE_3001); } ScenePro sceneProEntity = sceneProService.findBySceneNum(base.getSceneNum()); if(sceneProEntity == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } SceneProEdit sceneProEditEntity = sceneProEditService.findBySceneProId(sceneProEntity.getId()); StringBuffer dataBuf = new StringBuffer() .append("data").append(File.separator) .append("data").append(sceneProEntity.getNum()) .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", sceneProEditEntity.getVersion()+1); FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map); sceneProEditEntity.setBgMusic(base.getMusicName()); sceneProEditEntity.setVersion(sceneProEditEntity.getVersion() + 1); sceneProEditService.updateById(sceneProEditEntity); return ResultData.ok(); } @Override public ResultData saveFloorLogo(RequestSceneEdit base) throws Exception { if(StrUtil.isEmpty(base.getSceneNum()) || StrUtil.isEmpty(base.getSize()) || StrUtil.isEmpty(base.getLogoType())){ throw new BusinessException(ErrorCode.FAILURE_CODE_3001); } ScenePro sceneProEntity = sceneProService.findBySceneNum(base.getSceneNum()); if(sceneProEntity == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } SceneProEdit sceneProEditEntity = sceneProEditService.findBySceneProId(sceneProEntity.getId()); StringBuffer dataBuf = new StringBuffer() .append("data").append(File.separator) .append("data").append(sceneProEntity.getNum()) .append(File.separator); StringBuffer imagesBuf = new StringBuffer() .append("images").append(File.separator) .append("images").append(sceneProEntity.getNum()) .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", sceneProEditEntity.getVersion()+1); FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map); sceneProEditEntity.setFloorLogo(base.getLogoType()); sceneProEditEntity.setFloorLogoSize(Integer.parseInt(base.getSize())); sceneProEditEntity.setVersion(sceneProEditEntity.getVersion() + 1); sceneProEditService.updateById(sceneProEditEntity); fYunFileService.uploadFile(imagesBuffer.toString() + "floorLogoImg.png", imagesBuf.toString() + "floorLogoImg.png"); fYunFileService.uploadFile(dataBuffer.toString() + "scene.json", dataBuf.toString() + "scene.json"); return ResultData.ok(); } @Override public ResultData saveScreencapData(RequestSceneEdit base) throws Exception { if(StrUtil.isEmpty(base.getSceneNum())){ throw new BusinessException(ErrorCode.FAILURE_CODE_3001); } ScenePro sceneProEntity = sceneProService.findBySceneNum(base.getSceneNum()); if(sceneProEntity == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } StringBuffer dataBuf = new StringBuffer() .append("data").append(File.separator) .append("data").append(sceneProEntity.getNum()) .append(File.separator); StringBuffer imagesBuf = new StringBuffer() .append("images").append(File.separator) .append("images").append(sceneProEntity.getNum()) .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 sceneProEditEntity = sceneProEditService.findBySceneProId(sceneProEntity.getId()); scenejson.put("screencapVoiceSound", ""); sceneProEditEntity.setScreencapVoiceSound(""); if(base.getScreencapVoiceType() != null){ scenejson.put("screencapVoiceType", base.getScreencapVoiceType()); sceneProEditEntity.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"); sceneProEditEntity.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"); sceneProEditEntity.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) { fYunFileService.uploadMulFiles(map); } sceneProEditEntity.setVersion(scenejson.getIntValue("version") + 1); sceneProEditService.updateById(sceneProEditEntity); 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(); } @Override public ResultData saveHot(RequestSceneEdit base) throws Exception { if(StringUtils.isEmpty(base.getType())){ throw new BusinessException(ErrorCode.FAILURE_CODE_3001); } String sid = base.getSid(); ScenePro sceneProEntity = sceneProService.findBySceneNum(base.getSceneNum()); if (sceneProEntity == null ) { throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } SceneProEdit sceneProEditEntity = sceneProEditService.findBySceneProId(sceneProEntity.getId()); log.info("hotData:" + base.getHotData()); JSONObject jsonhot = JSONObject.parseObject(base.getHotData()); StringBuffer dataBuf = new StringBuffer() .append("data").append(File.separator) .append("data").append(sceneProEntity.getNum()) .append(File.separator); StringBuffer imagesBuf = new StringBuffer() .append("images").append(File.separator) .append("images").append(sceneProEntity.getNum()) .append(File.separator); StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString()); StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString()); String str = FileUtils.readFile(dataBuffer.toString() + "hot.json"); JSONArray jsonhots = null; if (StringUtils.isNotEmpty(str)) { jsonhots = JSONArray.parseArray(str); }else { File file = new File(dataBuffer.toString() + "hot.json"); if(!file.getParentFile().exists()){ file.getParentFile().mkdirs(); } if(!file.exists()){ file.createNewFile(); } jsonhots = new JSONArray(); } String hotsids = ""; //添加或者修改 if("1".equals(base.getType())){ sid = jsonhot.getString("sid"); if(StrUtil.isEmpty(sid)){ throw new BusinessException(ErrorCode.FAILURE_CODE_5012); } jsonhots.add(jsonhot); } else if("0".equals(base.getType())){ sid = jsonhot.getString("sid"); if(StrUtil.isEmpty(sid)){ throw new BusinessException(ErrorCode.FAILURE_CODE_5012); } } else if("-1".equals(base.getType())){ if(StrUtil.isEmpty(sid)){ throw new BusinessException(ErrorCode.FAILURE_CODE_5012); } } //判断是否需要删除自定义热点样式 String[] styles = null; if(StrUtil.isNotEmpty(base.getStyleName())){ styles = base.getStyleName().split(","); } for(int i=0;i 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"); sceneProEditEntity.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"); sceneProEditEntity.setScreencapThumb(dataBuf.toString() + "screencapThumb.json"); map.put(dataBuffer.toString() + "screencapThumb.json", dataBuf.toString() + "screencapThumb.json"); } fYunFileService.uploadMulFiles(map); sceneProEditEntity.setHotsIds(hotsids); sceneProEditEntity.setVersion(sceneProEditEntity.getVersion() + 1); sceneProEditService.updateById(sceneProEditEntity); if(jsonhots.size()>0){ scenejson.put("hots", 1); } else{ scenejson.put("hots", 0); } scenejson.put("version", sceneProEditEntity.getVersion() + 1); FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString()); return ResultData.ok(); } @Override public ResultData getRecordAudioFromWeixinV3(String sceneNum, String id, String type, String fileName, String length, String replace, String times, String index) throws Exception { if(StrUtil.isEmpty(sceneNum) || StrUtil.isEmpty(id)){ throw new BusinessException(ErrorCode.FAILURE_CODE_3001); } ScenePro sceneProEntity = sceneProService.findBySceneNum(sceneNum); if(sceneProEntity == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } SceneProEdit sceneProEditEntity = sceneProEditService.findBySceneProId(sceneProEntity.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); 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); 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)){ 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){ 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); } fYunFileService.uploadFile(path+File.separator +originalFileName, "voice/voice"+sceneNum+"/"+originalFileName); String voiceSrc = ossPrefixUrl+"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); sceneProEditEntity.setScreencapVoiceType("soundsync"); sceneProEditEntity.setScreencapVoiceSoundsync(voiceSrc); sceneProEditEntity.setVersion(scenejson.getIntValue("version")+1); FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map); sceneProEditService.updateById(sceneProEditEntity); FileUtils.deleteFile(path+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr"); return ResultData.ok(voiceSrc); } 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); fYunFileService.uploadFile(path+File.separator +originalFileName, "voice/voice"+sceneNum+"/"+originalFileName); String voiceSrc = ossPrefixUrl+"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); sceneProEditEntity.setScreencapVoiceType("soundsync"); sceneProEditEntity.setScreencapVoiceSoundsync(voiceSrc); sceneProEditEntity.setVersion(scenejson.getIntValue("version")+1); FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map); sceneProEditService.updateById(sceneProEditEntity); FileUtils.deleteFile(path+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr"); return ResultData.ok(voiceSrc); } @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 sceneProEntity = sceneProService.findBySceneNum(sceneNum); if(sceneProEntity == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } SceneProEdit sceneProEditEntity = sceneProEditService.findBySceneProId(sceneProEntity.getId()); StringBuffer dataBuf = new StringBuffer() .append("data").append(File.separator) .append("data").append(sceneProEntity.getNum()) .append(File.separator); StringBuffer imagesBuf = new StringBuffer() .append("images").append(File.separator) .append("images").append(sceneProEntity.getNum()) .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); fYunFileService.uploadFile(imagesBuffer.toString() + fileName, imagesBuf + fileName); String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json"); JSONObject scenejson = new JSONObject(); if(strsceneInfos!=null) { scenejson = JSONObject.parseObject(strsceneInfos); } sceneProEditEntity.setBgMusicName(fileName); sceneProEditEntity.setVersion(scenejson.getIntValue("version") + 1); scenejson.put("bgMusicName", fileName); scenejson.put("uploadBgMusic", 0); scenejson.put("version", scenejson.getIntValue("version") + 1); FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString()); sceneProEditService.updateById(sceneProEditEntity); return ResultData.ok(); } @Override public ResultData deleteUploadBgMusic(String sceneNum) throws Exception { if(StringUtils.isEmpty(sceneNum)){ throw new BusinessException(ErrorCode.FAILURE_CODE_3001); } ScenePro sceneProEntity = sceneProService.findBySceneNum(sceneNum); if(sceneProEntity == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } SceneProEdit sceneProEditEntity = sceneProEditService.findBySceneProId(sceneProEntity.getId()); StringBuffer dataBuf = new StringBuffer() .append("data").append(File.separator) .append("data").append(sceneProEntity.getNum()) .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); } sceneProEditEntity.setBgMusicName(""); sceneProEditEntity.setVersion(scenejson.getIntValue("version") + 1); scenejson.put("bgMusicName", ""); scenejson.put("version", scenejson.getIntValue("version") + 1); FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString()); sceneProEditService.updateById(sceneProEditEntity); return ResultData.ok(); } }