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