1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252 |
- 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<ISceneProMapper, ScenePro> 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<String, Object> 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<String, Object> 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<String> 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<String,String> uploadMap = new HashMap<String,String>();
- 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<String,String> map = new HashMap<String,String>();
- 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<jsonhots.size();++i) {
- JSONObject ele = jsonhots.getJSONObject(i);
- //名字对应上就删除
- if(styles != null){
- for(String style : styles){
- if(style.equals(ele.getString("styleId"))){
- jsonhots.getJSONObject(i).put("styleId", null);
- jsonhots.getJSONObject(i).put("style", "default");
- jsonhots.getJSONObject(i).put("styleImageURL", null);
- }
- }
- }
- hotsids += ele.getString("sid") +",";
- if(ele.getString("sid").equals(sid)) {
- if("-1".equals(base.getType())) {
- jsonhots.remove(i);
- jsonhot = ele;
- if(!FYunTypeEnum.AWS.code().equals(this.ossType)){
- JSONObject paramData = new JSONObject();
- paramData.put("hotId", sid);
- JSONObject hotListJson = JSONObject.parseObject(OkHttpUtils.httpGet(hotDomainList));
- if(hotListJson != null){
- JSONArray hotListArray = hotListJson.getJSONArray("data");
- if(hotListArray != null){
- for(int l = 0, len = hotListArray.size(); l < len; l++){
- OkHttpUtils.httpPostJson(hotListArray.getString(l) + hotDelete + "?hotId=" + sid
- , paramData.toJSONString());
- }
- }
- }
- }
- }
- else if("0".equals(base.getType())) {
- jsonhots.set(i, jsonhot);
- }
- }
- }
- Map<String,String> map = new HashMap<String,String>();
- 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();
- }
- }
|