1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486 |
- package com.fdkankan.scene.service.impl;
- import cn.hutool.core.bean.BeanUtil;
- import cn.hutool.core.collection.CollUtil;
- import cn.hutool.core.date.DateUtil;
- import cn.hutool.core.util.StrUtil;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
- import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- 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.ConvertUtils;
- import com.fdkankan.common.util.DateExtUtil;
- import com.fdkankan.common.util.FileUtils;
- import com.fdkankan.common.util.MatrixToImageWriterUtil;
- import com.fdkankan.fyun.oss.UploadToOssUtil;
- import com.fdkankan.fyun.qiniu.QiniuUpload;
- import com.fdkankan.platform.api.dto.User;
- import com.fdkankan.platform.api.feign.PlatformUserClient;
- import com.fdkankan.redis.constant.RedisKey;
- import com.fdkankan.redis.constant.RedisLockKey;
- import com.fdkankan.redis.util.RedisLockUtil;
- import com.fdkankan.redis.util.RedisUtil;
- import com.fdkankan.scene.bean.SceneJsonBean;
- import com.fdkankan.scene.entity.*;
- import com.fdkankan.scene.mapper.ISceneMapper;
- import com.fdkankan.scene.mapper.ISceneProMapper;
- import com.fdkankan.scene.service.*;
- import com.fdkankan.scene.vo.*;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.lang3.ObjectUtils;
- import org.apache.commons.lang3.StringUtils;
- import org.joda.time.DateTime;
- import org.springframework.beans.BeanUtils;
- 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.bind.annotation.RequestBody;
- import org.springframework.web.multipart.MultipartFile;
- import javax.annotation.Resource;
- import java.io.File;
- import java.io.IOException;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * <p>
- * 场景表 服务实现类
- * </p>
- *
- * @author dengsixing
- * @since 2021-12-23
- */
- @Slf4j
- @Service
- public class SceneServiceImpl extends ServiceImpl<ISceneMapper, Scene> implements ISceneService {
- @Value("${upload.type}")
- private String type;
- @Value("${oss.prefix.ali}")
- private String prefixAli;
- @Resource
- ISceneProMapper sceneProMapper;
- @Autowired
- ISceneProService sceneProService;
- @Autowired
- ISceneExtService sceneExtService;
- @Autowired
- @Qualifier("uploadToOssUtil")
- UploadToOssUtil uploadToOssUtil;
- @Autowired
- RedisUtil redisUtil;
- @Autowired
- RedisLockUtil redisLockUtil;
- @Autowired
- ISceneProExtService sceneProExtService;
- @Autowired
- PlatformUserClient platformUserClient;
- @Autowired
- ISceneService sceneService;
- @Autowired
- private IScenePlusService scenePlusService;
- @Autowired
- private IScenePlusExtService scenePlusExtService;
- @Autowired
- private ISceneEditInfoService sceneEditInfoService;
- @Autowired
- private ISceneEditInfoExtService sceneEditInfoExtService;
- @Autowired
- private ISceneEditControlsService sceneEditControlsService;
- @Autowired
- private ISceneDataDownloadService sceneDataDownloadService;
- @Autowired
- private ISurveillanceService surveillanceService;
- @Value("${main.url}")
- private String mainUrl;
- @Value("${scene.pro.new.url}")
- private String sceneProNewUrl;
- @Override
- public void updateUserIdByCameraId(Long userId, Long cameraId) {
- this.update(new LambdaUpdateWrapper<Scene>().eq(Scene::getCameraId, cameraId).set(Scene::getUserId, userId));
- }
- @Override
- // @SystemServiceLog(description = "上传场景的热点媒体文件")
- public void uploadHotMedia(String sceneNum, MultipartFile file) throws IOException {
- if(StrUtil.isEmpty(sceneNum)){
- throw new BusinessException(ErrorCode.PARAM_REQUIRED);
- }
- ScenePO scene = findBySceneNum(sceneNum);
- if(scene == null){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
- }
- if (!file.isEmpty()){
- String path = ConstantFilePath.SCENE_PATH + "images" + File.separator + "images" + scene.getNum() + "hot";
- File 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);
- }
- }
- @Override
- // @SystemServiceLog(description = "上传场景的导览图片")
- public void uploadGuidePic(String sceneId, MultipartFile file) throws IOException {
- Scene scene = this.getValidById(Long.valueOf(sceneId));
- if (scene != null && !file.isEmpty()){
- String path = ConstantFilePath.SCENE_PATH + "images" + File.separator + "images" + scene.getNum()
- + File.separator + ConstantFileName.GUIDE_MEDIA_FOLDER;
- File targetFile = new File(path);
- if (!targetFile.exists()){
- targetFile.mkdirs();
- }
- String fileName = file.getOriginalFilename();
- targetFile = new File(path + File.separator + fileName);
- int count = 1;
- while (targetFile.exists()){
- targetFile = new File(path + File.separator + fileName.substring(0, fileName.lastIndexOf("."))+"("+count+")"+fileName.substring(fileName.lastIndexOf(".")));
- ++count;
- }
- file.transferTo(targetFile);
- }
- }
- @Override
- // @SystemServiceLog(description = "保存热点的导览信息")
- public ResultData saveGuideInfo(SceneParamVO base) throws Exception {
- ResultData result = null;
- Scene scene = getValidById(base.getSceneId());
- if (scene != null){
- String path = ConstantFilePath.SCENE_PATH + "data" + File.separator + "data" + scene.getNum()
- + File.separator + ConstantFileName.GUIDE_DATAFILE;
- File file = new File(path);
- String guideData = null;
- if(file.exists()) {
- guideData = FileUtils.readFile(path);
- }
- if (StrUtil.isEmpty(guideData)){
- result = ResultData.error(ErrorCode.FAILURE_CODE_5001);
- }else{
- JSONObject guideJo = JSONObject.parseObject(guideData);
- if ("1".equals(base.getType())) {
- if (StrUtil.isEmpty(base.getOrder())) {
- result = ResultData.error(ErrorCode.FAILURE_CODE_5002);
- }else{
- if(!StrUtil.isEmpty(base.getItem())) {
- JSONObject jo = new JSONObject();
- JSONArray jy = guideJo.getJSONArray("images");
- jy.add(JSONObject.parse(base.getItem()));
- }
- guideJo.put("imagesOrder", JSONArray.parse(base.getOrder()));
- }
- } else if ("2".equals(base.getType())) {
- if (StrUtil.isEmpty(base.getOrder()) || StrUtil.isEmpty(base.getGuideSid())) {
- result = ResultData.error(ErrorCode.FAILURE_CODE_5003);
- }else{
- JSONArray jy = guideJo.getJSONArray("images");
- for (int i = 0; i < jy.size(); ++i) {
- JSONObject itemData = jy.getJSONObject(i);
- if (itemData.getString("sid").equals(base.getGuideSid())) {
- jy.remove(i);
- break;
- }
- }
- guideJo.put("imagesOrder", JSONArray.parse(base.getOrder()));
- }
- } else if ("3".equals(base.getType())) {
- if (StrUtil.isEmpty(base.getOrder())) {
- result = ResultData.error(ErrorCode.FAILURE_CODE_5002);
- } else {
- guideJo.put("imagesOrder", JSONArray.parse(base.getOrder()));
- }
- } else if ("4".equals(base.getType())) {
- if (StrUtil.isEmpty(base.getGuideName()) || StrUtil.isEmpty(base.getGuideSid())) {
- result = ResultData.error(ErrorCode.FAILURE_CODE_5004);
- }else{
- JSONArray jy = guideJo.getJSONArray("images");
- for (int i = 0; i < jy.size(); ++i) {
- JSONObject itemData = jy.getJSONObject(i);
- if (itemData.getString("sid").equals(base.getGuideSid())) {
- itemData.put("name", base.getGuideName());
- break;
- }
- }
- }
- }
- FileUtils.deleteFile(path);
- FileUtils.writeFileContent(path, guideJo.toString());
- result = ResultData.ok();
- }
- }else{
- result = ResultData.error(ErrorCode.FAILURE_CODE_5005);
- }
- return result;
- }
- @Override
- // @SystemServiceLog(description = "恢复场景的户型图")
- public ResultData recoveryFloor(SceneParamVO base) throws Exception {
- ResultData result = null;
- Scene scene = this.getValidById(base.getSceneId());
- if (scene != null) {
- String unicode = scene.getDataSource();
- if (StrUtil.isNotEmpty(unicode)) {
- unicode = unicode.substring(0, unicode.lastIndexOf("/"));
- unicode = unicode.replace(ConstantUrl.DEFAULT_PREFIX_QINIU_PIC, "");
- String path = ConstantFilePath.BUILD_MODEL_PATH + unicode + File.separator + "tex" + File.separator + "floor.json";
- FileUtils.copyFile(path, ConstantFilePath.SCENE_PATH + "data" + File.separator + "data" + scene.getNum() + File.separator + "floor.json", true);
- }
- result = ResultData.ok();
- } else {
- result = ResultData.error(ErrorCode.FAILURE_CODE_5005);
- }
- return result;
- }
- @Override
- // @SystemServiceLog(description = "保存场景编辑信息")
- public ResultData saveEditInfo(SceneParamVO base) throws Exception {
- ResultData result = ResultData.ok();
- Scene scene = this.getValidById(base.getSceneId());
- if (scene != null) {
- JSONObject json = new JSONObject();
- json.put("sceneName", base.getSceneName());
- json.put("sceneDec", base.getSceneDec());
- json.put("sceneType", base.getSceneType());
- json.put("scenePsd", base.getSceneKey());
- json.put("version", base.getVersion());
- json.put("thumbImg", base.getThumbImg());
- json.put("currentPanoId", base.getCurrentPanoId());
- json.put("floorLogo", base.getFloorLogo());
- json.put("floorLogoSize", base.getFloorLogoSize());
- json.put("entry", base.getEntry());
- json.put("index", base.getIndex());
- json.put("sceneIndex", base.getSceneIndex());
- JSONObject json2 = new JSONObject();
- json2.put("geoData", base.getGeoData());
- json2.put("center", base.getCenter());
- json2.put("zoom", base.getZoom());
- json2.put("realScale", base.getRealScale());
- StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH)
- .append("images").append(File.separator)
- .append("images").append(base.getIndex());
- StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH)
- .append("data").append(File.separator)
- .append("data").append(base.getIndex());
- File imagesFile = new File(imagesBuffer.toString());
- if(!imagesFile.exists() || !imagesFile.isDirectory()) {
- imagesFile.mkdirs();
- }
- File dataFile = new File(dataBuffer.toString());
- if(!dataFile.exists() || !dataFile.isDirectory()) {
- dataFile.mkdirs();
- }
- if (StrUtil.isNotEmpty(base.getThumbFishBigImg()) && !"undefined".equals(base.getThumbFishBigImg())){
- StringBuffer sb = new StringBuffer(imagesBuffer);
- String thumbFishBigImgPath = sb.append(File.separator).append("thumbFishBigImg.jpg").toString();
- FileUtils.deleteFile(thumbFishBigImgPath);
- FileUtils.uploadImg(thumbFishBigImgPath, base.getThumbFishBigImg());
- }
- if (StrUtil.isNotEmpty(base.getThumbBigImg()) && !"undefined".equals(base.getThumbBigImg())) {
- StringBuffer sb = new StringBuffer(imagesBuffer);
- String thumbBigImgPath = sb.append(File.separator).append("thumbBigImg.jpg").toString();
- FileUtils.deleteFile(thumbBigImgPath);
- FileUtils.uploadImg(thumbBigImgPath, base.getThumbBigImg());
- }
- if (StrUtil.isNotEmpty(base.getThumbSmallImg()) && !"undefined".equals(base.getThumbSmallImg())) {
- StringBuffer sb = new StringBuffer(imagesBuffer);
- String thumbSmallImgPath = sb.append(File.separator).append("thumbSmallImg.jpg").toString();
- FileUtils.deleteFile(thumbSmallImgPath);
- FileUtils.uploadImg(thumbSmallImgPath, base.getThumbSmallImg());
- }
- if (StrUtil.isNotEmpty(base.getFloorLogoImg()) && !"undefined".equals(base.getFloorLogoImg())) {
- StringBuffer sb = new StringBuffer(imagesBuffer);
- String floorLogoImgPath = sb.append(File.separator).append("floorLogoImg.png").toString();
- FileUtils.deleteFile(floorLogoImgPath);
- FileUtils.uploadImg(floorLogoImgPath, base.getFloorLogoImg());
- }
- if (StrUtil.isNotEmpty(base.getImgData()) && !"undefined".equals(base.getImgData())) {
- StringBuffer sb = new StringBuffer(imagesBuffer);
- String floorPlanPath = sb.append(File.separator).append("floorplan.png").toString();
- FileUtils.deleteFile(floorPlanPath);
- FileUtils.uploadImg(floorPlanPath, base.getImgData());
- if (base.getFloorPlaneInfo() != null) {
- String floorPath = dataBuffer.append(File.separator).append("floor.json").toString();
- FileUtils.deleteFile(floorPath);
- JSONObject info = JSONObject.parseObject(base.getFloorPlaneInfo());
- if (info.containsKey("height")) {
- json2.put("height", info.getString("height"));
- }
- if (info.containsKey("width")) {
- json2.put("width", info.getString("width"));
- }
- if (info.containsKey("position")) {
- json2.put("position", info.getJSONObject("position"));
- }
- FileUtils.writeFileContent(floorPath, json2.toString());
- }
- }
- String floorFilepath = imagesBuffer.append(File.separator).append("scene.json").toString();
- FileUtils.writeFileContent(floorFilepath, json.toString());
- } else {
- result = ResultData.error(ErrorCode.FAILURE_CODE_5005);
- }
- return result;
- }
- @Override
- // @SystemServiceLog(description = "发布场景")
- public ResultData publishScene(SceneParamVO base) throws Exception {
- ResultData result = ResultData.ok();
- Scene scene = this.getValidById(base.getSceneId());
- if (scene != null) {
- SceneExt sceneExt = sceneExtService.getBySceneId(scene.getId());
- StringBuffer dataBuf = new StringBuffer()
- .append("data").append(File.separator)
- .append("data").append(scene.getNum())
- .append(File.separator);
- StringBuffer imagesBuf = new StringBuffer()
- .append("images").append(File.separator)
- .append("images").append(scene.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 str = FileUtils.readFile(dataBuffer.append("scene.json").toString());
- JSONObject json = JSONObject.parseObject(str);
- String sceneIndex = json.getString("sceneIndex") == null ? "0" : json.getString("sceneIndex");
- String index = json.getString("index");
- if(json.containsKey("entry")) {
- String entry = json.getString("entry");
- sceneExt.setEntry(entry);
- }
- String sceneType = json.getString("sceneType");
- int type = sceneType != null ? Integer.valueOf(sceneType) : 0;
- scene.setNum(index);
- scene.setSceneName(json.getString("sceneName"));
- scene.setSceneDec(json.getString("sceneDec"));
- scene.setSceneType(type);
- scene.setSceneKey(json.getString("scenePsd"));
- scene.setVersion(json.getInteger("version")+1);
- scene.setThumbStatus(json.getInteger("thumbImg"));
- scene.setFloorLogo(json.getString("floorLogo"));
- scene.setFloorLogoSize(json.getInteger("floorLogoSize"));
-
- sceneExt.setStyle(Integer.valueOf(sceneIndex));
- if (scene.getThumbStatus() == 1) {
- scene.setThumb(ConstantUrl.PREFIX_QINIU + imagesBuf.append("thumbSmallImg.jpg").toString());
- } else {
- scene.setThumb(ConstantUrl.PREFIX_QINIU + "loading/pc.jpg");
- }
- //上传文件到七牛云
- QiniuUpload.setFilesToBucket(imagesBuf.toString(), imagesBuffer.toString());
- QiniuUpload.setFilesToBucket(dataBuf.toString(), dataBuffer.toString());
-
- scene.setUpdateTime(Calendar.getInstance().getTime());
- this.updateById(scene);
-
- sceneExt.setUpdateTime(Calendar.getInstance().getTime());
- sceneExtService.updateById(sceneExt);
-
- } else {
- result = ResultData.error(ErrorCode.FAILURE_CODE_5005);
- }
- return result;
- }
- @Override
- // @SystemServiceLog(description = "删除场景热点")
- public ResultData deleteHot(SceneParamVO base) throws Exception {
- ResultData result = ResultData.ok();
- Scene scene = getValidById(base.getSceneId());
- if (scene != null && StrUtil.isNotEmpty(base.getIndex())) {
- SceneExt sceneExt = sceneExtService.getBySceneId(scene.getId());
- StringBuffer dataBuf = new StringBuffer()
- .append("data").append(File.separator)
- .append("data").append(scene.getNum())
- .append(File.separator);
- StringBuffer imagesBuf = new StringBuffer()
- .append("images").append(File.separator)
- .append("images").append(scene.getNum())
- .append(File.separator);
- StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
- StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString()).append("hot.json");
- String str = FileUtils.readFile(dataBuffer.toString());
- JSONArray jsonhots = null;
- if (StrUtil.isNotEmpty(str)){
- jsonhots = JSONArray.parseArray(str);
- for (int i = 0; i < jsonhots.size(); ++i) {
- JSONObject ele = jsonhots.getJSONObject(i);
- if (ele.getString("sid").equals(base.getIndex())) {
- jsonhots.remove(i);
- break;
- }
- }
- }
- String sPath = null;
- File file = new File(imagesBuffer.toString());
- if (file.isDirectory()){
- String[] strs = file.list();
- if (strs != null) {
- for (int i = 0; i < strs.length; ++i) {
- if (strs[i].contains("hot" + base.getIndex())) {
- sPath = imagesBuffer.toString() + strs[i];
- break;
- }
- }
- }
- }
- if (sPath != null){
- FileUtils.deleteFile(sPath);
- }
- FileUtils.deleteFile(dataBuffer.toString());
- if (jsonhots != null){
- FileUtils.writeFileContent(dataBuffer.toString(), jsonhots.toString());
- }
- String hotsIds = sceneExt.getHotsIds();
- if (StrUtil.isNotEmpty(hotsIds)) {
- String updateHotsIds = "";
- String[] sids = hotsIds.split(",");
- boolean flag = false;
- for (int i = 0; i < sids.length; ++i) {
- String s = sids[i];
- if (s.equals(base.getIndex())) {
- flag = true;
- } else {
- updateHotsIds += s + ",";
- }
- }
- if (!flag) {
- scene.setVersion(scene.getVersion() + 1);
- scene.setUpdateTime(Calendar.getInstance().getTime());
- this.updateById(scene);
- sceneExt.setHotsIds(updateHotsIds);
- sceneExt.setUpdateTime(Calendar.getInstance().getTime());
- sceneExtService.updateById(sceneExt);
- }
- }
- } else {
- result = ResultData.error(ErrorCode.FAILURE_CODE_5005);
- }
- return result;
- }
- @Override
- // @SystemServiceLog(description = "保存场景热点")
- public ResultData saveHot(SceneEditParamVO base) throws Exception {
- if(StrUtil.isEmpty(base.getHotData()) || StrUtil.isEmpty(base.getType())){
- throw new BusinessException(ErrorCode.PARAM_REQUIRED);
- }
- String sid = base.getSid();
- ScenePO scene = findBySceneNum(base.getNum());
- if (scene == null ) {
- return ResultData.error(ErrorCode.FAILURE_CODE_5005);
- }
- JSONObject jsonhot = JSONObject.parseObject(base.getHotData());
- StringBuffer dataBuf = new StringBuffer()
- .append("data").append(File.separator)
- .append("data").append(scene.getNum())
- .append(File.separator);
- StringBuffer imagesBuf = new StringBuffer()
- .append("images").append(File.separator)
- .append("images").append(scene.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.append("hot.json").toString());
- JSONArray jsonhots = null;
- if (StrUtil.isNotEmpty(str)) {
- jsonhots = JSONArray.parseArray(str);
- }else {
- File file = new File(dataBuffer.append("hot.json").toString());
- if(!file.getParentFile().exists()){
- file.getParentFile().mkdirs();
- }
- if(!file.exists()){
- file.createNewFile();
- }
- }
- //添加或者修改
- 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);
- }
- }
- for(int i=0;i<jsonhots.size();++i){
- JSONObject ele = jsonhots.getJSONObject(i);
- if(ele.getString("sid").equals(sid)){
- if("-1".equals(base.getType())){
- jsonhots.remove(i);
- if(ele.containsKey("media")){
- String fileType = ele.getString("media");
- if(fileType.contains("photo"))
- {
- FileUtils.deleteFile(imagesBuffer.append("hot").append(sid).append(".jpg").toString());
- }
- if(fileType.contains("audio"))
- {
- FileUtils.deleteFile(imagesBuffer.append("hot").append(sid).append(".mp3").toString());
- }
- if(fileType.contains("video"))
- {
- FileUtils.deleteFile(imagesBuffer.append("hot").append(sid).append(".mp4").toString());
- }
- }
- }
- else if("0".equals(base.getType())){
- jsonhots.set(i, jsonhot);
- }
- break;
- }
- }
- FileUtils.deleteFile(dataBuffer.append("hot.json").toString());
- File dataPath = new File(dataBuffer.toString());
- if(!dataPath.exists()){
- dataPath.mkdirs();
- }
- FileUtils.writeFile(dataBuffer.append("hot.json").toString(), jsonhots.toString());
- String strsceneInfos = FileUtils.readFile(dataBuffer.append("scene.json").toString());
- JSONObject scenejson = new JSONObject();
- if(strsceneInfos!=null){
- scenejson = JSONObject.parseObject(strsceneInfos);
- }
- if(jsonhots.size()>0){
- scenejson.put("hots", 1);
- }
- else{
- scenejson.put("hots", 0);
- }
- FileUtils.writeFile(dataBuffer.append("scene.json").toString(), scenejson.toString());
- return ResultData.ok();
- }
- @Override
- // @SystemServiceLog(description = "漫游可行")
- public ResultData saveLinkPano(SceneEditParamVO base) throws Exception {
- if(StrUtil.isEmpty(base.getData()) || StrUtil.isEmpty(base.getNum())){
- throw new BusinessException(ErrorCode.PARAM_REQUIRED);
- }
- ScenePO scene = baseMapper.findByNum(base.getNum());
- if (scene == null ) {
- return ResultData.error(ErrorCode.FAILURE_CODE_5005);
- }
- JSONArray inputData = JSONObject.parseArray(base.getData());
- StringBuffer dataBuf = new StringBuffer()
- .append("data").append(File.separator)
- .append("data").append(scene.getNum())
- .append(File.separator);
- StringBuffer imagesBuf = new StringBuffer()
- .append("images").append(File.separator)
- .append("images").append(scene.getNum())
- .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("aws".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.append("vision.modeldata").toString());
- if(file.exists()) {
- return ResultData.error(ErrorCode.FAILURE_CODE_5012);
- }
- ConvertUtils.convertVisionModelDataToTxt(dataBuffer.append("vision.modeldata").toString(), dataBuffer.append("vision.json").toString());
- String str = FileUtils.readFile(dataBuffer.append("vision.json").toString());
- 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.append("vision.json").toString());
- FileUtils.deleteFile(dataBuffer.toString() + "vision.modeldata");
- FileUtils.writeFileContent(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");
- return ResultData.ok();
- }
- @Override
- // @SystemServiceLog(description = "保存热点可见性的数据")
- public ResultData saveHotVisible(SceneEditParamVO base) throws Exception {
- if(StrUtil.isEmpty(base.getData())){
- throw new BusinessException(ErrorCode.PARAM_REQUIRED);
- }
- // ScenePO scene = findBySceneNum(base.getNum());
- Scene scene = this.getSceneBySceneCode(base.getNum());
- if (scene == null ) {
- return ResultData.error(ErrorCode.FAILURE_CODE_5005);
- }
- JSONArray visiblePanos = JSONArray.parseArray(base.getData());
- StringBuffer dataBuf = new StringBuffer()
- .append("data").append(File.separator)
- .append("data").append(scene.getNum())
- .append(File.separator);
- StringBuffer imagesBuf = new StringBuffer()
- .append("images").append(File.separator)
- .append("images").append(scene.getNum())
- .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"));
- }
- }
- }
- scene.setVersion(scene.getVersion() + 1);
- scene.setUpdateTime(Calendar.getInstance().getTime());
- this.updateById(scene);
- FileUtils.deleteFile(dataBuffer.append("hot.json").toString());
- FileUtils.writeFileContent(dataBuffer.append("hot.json").toString(), hots.toString());
- return ResultData.ok();
- }
- @Override
- public IPage<SceneVO> queryByParam(SceneParamVO param) {
- int pageNum = param.getPageNum();
- int pageSize = param.getPageSize();
- Page<SceneVO> page = new Page<>(pageNum, pageSize);
- if(StrUtil.isEmpty(param.getUserIds())){
- param.setUserIds("0");
- }
- if(StrUtil.isEmpty(param.getCameraIds())){
- param.setCameraIds("0");
- }
- List<SceneVO> list = baseMapper.queryByParam(page, param);
- page.setRecords(list);
- return page;
- }
- @Override
- public IPage<SceneVO> queryByParamNew(SceneParamVO param) {
- int pageNum = param.getPageNum();
- int pageSize = param.getPageSize();
- Page<SceneVO> page = new Page<>(pageNum, pageSize);
- if(StrUtil.isEmpty(param.getUserIds())){
- param.setUserIds("0");
- }
- if(StrUtil.isEmpty(param.getCameraIds())){
- param.setCameraIds("0");
- }
- List<SceneVO> list = baseMapper.queryByParamNew(page, param);
- page.setRecords(list);
- return page;
- }
- // @Override
- // public List<SceneVO> findSceneProBySnCode(SceneParamVO param) {
- // return sceneMapper.findSceneProBySnCode(param);
- // }
- @Override
- public Scene getValidById(long id) {
- return this.getOne(new LambdaQueryWrapper<Scene>()
- .eq(Scene::getTbStatus, TbStatus.VALID.code())
- .eq(Scene::getId, id));
- }
- @Override
- public List<SceneVO> convert(List<ScenePO> list) {
- List<SceneVO> sceneVOs = list.stream().map(po -> {
- SceneVO sceneVO = new SceneVO();
- BeanUtils.copyProperties(po, sceneVO);
- if (po.getCreateTime() != null) {
- sceneVO.setCreateTime(DateUtil.format(po.getCreateTime(), DateExtUtil.dateStyle4));
- sceneVO.setCreateDate(po.getCreateTime().getTime());
- }
- return sceneVO;
- }).collect(Collectors.toList());
- return sceneVOs;
- }
- @Override
- public List<SceneVO> convertPro(List<SceneProPO> list) {
- List<SceneVO> sceneVOs = list.stream().map(po -> {
- SceneVO sceneVO = new SceneVO();
- BeanUtils.copyProperties(po, sceneVO);
- if (po.getCreateTime() != null) {
- sceneVO.setCreateTime(new DateTime(po.getCreateTime()).toString("yyyy-MM-dd"));
- if ("aws".equals(this.type)) {
- sceneVO.setCreateTime(new DateTime(DateExtUtil.hoursCalculate(po.getCreateTime(), 8)).toString("yyyy-MM-dd"));
- }
- sceneVO.setCreateDate(po.getCreateTime().getTime());
- }
- sceneVO.setIsFolder(0);
- sceneVO.setStatus(po.getSceneStatus());
- return sceneVO;
- }).collect(Collectors.toList());
- return sceneVOs;
- }
- @Override
- public List<ScenePO> findAllByYesterday() throws Exception {
- return baseMapper.findAllByYesterday();
- }
- @Override
- public ScenePO findBySceneNum(String sceneNum) {
- return baseMapper.findByNum(sceneNum);
- }
- @Override
- public Scene getSceneBySceneCode(String sceneCode) {
- List<Scene> list = this.list(new LambdaQueryWrapper<Scene>()
- .eq(Scene::getTbStatus, TbStatus.VALID.code())
- .eq(Scene::getNum, sceneCode));
- if(CollUtil.isEmpty(list)){
- return null;
- }
- return list.get(0);
- }
- @Override
- public ResultData recover(String sceneNum) throws Exception {
- ScenePO scene = baseMapper.findByNum(sceneNum);
- if (scene == null){
- return ResultData.error(ErrorCode.FAILURE_CODE_5005);
- }
- scene.setPayStatus(1);
- this.update(new LambdaUpdateWrapper<Scene>()
- .eq(Scene::getId, scene.getId())
- .set(Scene::getPayStatus, PayStatus.PAY.code()));
- SceneVO SceneVO = new SceneVO();
- BeanUtils.copyProperties(scene, SceneVO);
- return ResultData.ok(SceneVO);
- }
- // public int getSceneCount(Long cameraId) {
- // return sceneMapper.getSceneCount(cameraId);
- // }
- @Override
- public Scene getSceneStatusByUnicode(String unicode, int tbStatus) {
- return this.getOne(new LambdaQueryWrapper<Scene>().eq(Scene::getTbStatus, tbStatus).like(Scene::getDataSource, "%"+unicode+"%"));
- }
- public void updateStatus(String sceneNum, int status) {
- this.update(new LambdaUpdateWrapper<Scene>().eq(Scene::getNum, sceneNum).set(Scene::getSceneStatus, status));
- }
- public void updatePayStatus(String sceneNum, int status) {
- this.update(new LambdaUpdateWrapper<Scene>().eq(Scene::getNum, sceneNum).set(Scene::getPayStatus, status));
- }
- @Override
- public void updateTime(String sceneNum, Long space, int payStatus) {
- List<Scene> sceneList = this.list(new LambdaQueryWrapper<Scene>()
- .select(Scene::getId)
- .eq(Scene::getNum, sceneNum));
- if(CollUtil.isEmpty(sceneList))
- return ;
- List<Long> sceneIds = sceneList.stream().map(scene -> {
- return scene.getId();
- }).collect(Collectors.toList());
- this.update(new LambdaUpdateWrapper<Scene>()
- .in(Scene::getId, sceneIds)
- .set(Scene::getCreateTime, Calendar.getInstance().getTime())
- .set(Scene::getSceneStatus, SceneStatus.NO_DISPLAY.code()));
- sceneExtService.update(new LambdaUpdateWrapper<SceneExt>().in(SceneExt::getSceneId, sceneIds).set(SceneExt::getSpace, space));
- }
- @Override
- public ResultData addHotMediaInfo(SceneEditParamVO base) throws Exception{
- if(StrUtil.isEmpty(base.getNum()) || StrUtil.isEmpty(base.getType()) ||
- StrUtil.isEmpty(base.getInfo())){
- throw new BusinessException(ErrorCode.PARAM_REQUIRED);
- }
- ScenePO scene = findBySceneNum(base.getNum());
- if(scene == null){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
- }
- StringBuffer dataBuf = new StringBuffer()
- .append("data").append(File.separator)
- .append("data").append(scene.getNum())
- .append(File.separator);
- StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
- String infoData = FileUtils.readFile(dataBuffer.append("mediaInfo.json").toString());
- JSONArray medias = null;
- if(infoData != null){
- medias= JSONArray.parseArray(infoData);
- }
- if("1".equals(base.getType())){
- JSONObject jo = JSONObject.parseObject(base.getInfo());
- medias.add(jo);
- }else if("1".equals(base.getType())){
- for(int i=0;i<medias.size();++i){
- JSONObject ob = medias.getJSONObject(i);
- if(ob.getString("file").equals(base.getName())){
- medias.remove(i);
- break;
- }
- }
- }else{
- throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
- }
- FileUtils.writeFile(dataBuffer.append("mediaInfo.json").toString(), medias.toString());
- return ResultData.ok();
- }
- @Override
- public ResultData saveScreencapFile(SceneEditParamVO base) throws Exception{
- if(StrUtil.isEmpty(base.getNum()) || StrUtil.isEmpty(base.getIndex()) ||
- StrUtil.isEmpty(base.getCamerasData())){
- throw new BusinessException(ErrorCode.PARAM_REQUIRED);
- }
- ScenePO scene = findBySceneNum(base.getNum());
- if(scene == null){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
- }
- StringBuffer dataBuf = new StringBuffer()
- .append("data").append(File.separator)
- .append("data").append(scene.getNum())
- .append(File.separator);
- StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
- if("1".equals(base.getIndex())){
- File file = new File(dataBuffer.append(ConstantFileName.TOURLIST_FOLDER).toString());
- 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.append(ConstantFileName.TOURLIST_FOLDER).append(File.separator).append(strs[i]).toString());
- }
- }
- }
- } else {
- file.mkdirs();
- }
- Map<String, Object> map = new HashMap<>();
- map.put("screencapLen", "0");
- map.put("version", scene.getVersion()+1);
- FileUtils.writeJsonFile(dataBuffer.append("scene.json").toString(), map);
- //sceneService.updateScreencapLen(sceneNum, 0);
- }
- String filePath = dataBuffer.append(ConstantFileName.TOURLIST_FOLDER).append(File.separator).append(ConstantFileName.SCREEN_CRP_DATAFILE).append(base.getIndex()).append("json").toString();
- File file = new File(filePath);
- if(!file.exists())
- {
- file.createNewFile();
- }
- FileUtils.writeFile(filePath, base.getCamerasData());
- return ResultData.ok();
- }
- @Override
- public Page<SceneProPO> findAllScene(SceneParamVO param) {
- Page<SceneProPO> page = new Page<>(param.getPageNum(), param.getPageSize());
- return baseMapper.findAllScene(page, param);
- }
- @Override
- public Page<ScenePO> unionSearchBySceneName(SceneParamVO param) {
- Page<ScenePO> page = new Page<>(param.getPageNum(), param.getPageSize());
- return baseMapper.unionSearchBySceneName(page, param.getSearchKey());
- }
- @Override
- public List<SceneProPO> getOnlySceneList(SceneParamVO param) throws Exception {
- return baseMapper.getOnlySceneList(param);
- }
- @Override
- public ResultData updateViewCount(String sceneNum) {
- String key = String.format(RedisKey.SCENE_VISIT_CNT, sceneNum);
- Object countObject = redisUtil.get(key);
- int count = 0;
- if(countObject == null){
- String lockKey = String.format(RedisLockKey.LOCK_SCENE_VISIT_CNT, sceneNum);
- boolean lock = redisLockUtil.lock(lockKey, RedisKey.EXPIRE_TIME_10_MINUTE);
- try {
- if(!lock){
- throw new BusinessException(ErrorCode.SYSTEM_BUSY);
- }
- countObject = redisUtil.get(key);
- if(countObject == null){
- Scene scene = this.getSceneBySceneCode(sceneNum);
- if(scene == null){
- ScenePro scenePro = sceneProMapper.findByNum(sceneNum);
- if(scenePro != null){
- SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
- count = sceneProExt.getViewCount();
- }
- }else {
- count = scene.getViewCount();
- }
- redisUtil.set(key, String.valueOf(count));
- }
- }finally {
- redisLockUtil.unlockLua(lockKey);
- }
- }
- redisUtil.incr(key, 1);
- return ResultData.ok();
- }
- @Override
- public void updatePv(){
- Boolean lock = redisLockUtil.lock(RedisLockKey.LOCK_SCENE_VISIT_UPDATE, RedisKey.EXPIRE_TIME_2_HOUR);
- if(!lock){
- return;
- }
- try {
- Map<String, Integer> pvMap = redisUtil.hmget(RedisKey.SCENE_VISIT_CNT);
- if(CollUtil.isEmpty(pvMap)){
- return;
- }
- for (Map.Entry<String, Integer> entry : pvMap.entrySet()) {
- Scene scene = this.getSceneBySceneCode(entry.getKey());
- if (Objects.nonNull(scene)){
- scene.setViewCount(entry.getValue());
- scene.setUpdateTime(Calendar.getInstance().getTime());
- this.updateById(scene);
- continue;
- }
- ScenePro scenePro = sceneProMapper.findByNum(entry.getKey());
- if(scenePro != null){
- SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
- sceneProExt.setViewCount(entry.getValue());
- sceneProExt.setUpdateTime(Calendar.getInstance().getTime());
- sceneProExtService.updateById(sceneProExt);
- }
- }
- }finally {
- redisLockUtil.unlockLua(RedisLockKey.LOCK_SCENE_VISIT_UPDATE);
- }
- }
- @Override
- public Page search(@RequestBody SceneParamVO param) {
- param.setOrderBy("view_count desc");
- Page<ScenePO> scenePOPage = this.unionSearchBySceneName(param);
- if(CollUtil.isEmpty(scenePOPage.getRecords())){
- return scenePOPage;
- }
- List<SceneVO> voList = this.convert(scenePOPage.getRecords());
- for (SceneVO vo : voList){
- if (vo.getUserId() != null){
- ResultData<User> nickNameResult = platformUserClient.getUserByUserId(vo.getUserId());
- String nickName = nickNameResult.getData().getNickName();
- vo.setNickName(nickName);
- }
- }
- Page<SceneVO> result= new Page<>(param.getPageNum(), param.getPageSize());
- result.setTotal(scenePOPage.getTotal());
- result.setRecords(voList);
- return result;
- }
- @Override
- public Page loadScene(SceneParamVO param){
- String orderBy = null;
- if (StringUtils.isEmpty(param.getSceneInterest()) || "1".equals(param.getSceneInterest())){
- orderBy = " recommend desc, create_time ";
- }else if ("2".equals(param.getSceneInterest())){
- orderBy = " create_time desc ";
- }else if ("3".equals(param.getSceneInterest())){
- orderBy = " view_count desc ";
- }
- param.setOrderBy(orderBy);
- Page<SceneProPO> page = this.findAllScene(param);
- if(CollUtil.isEmpty(page.getRecords())){
- return page;
- }
- List<SceneVO> voList = this.convertPro(page.getRecords());
- for (SceneVO vo : voList){
- ResultData<User> nickNameResult = platformUserClient.getUserByUserId(vo.getUserId());
- vo.setNickName(nickNameResult.getData().getNickName());
- }
- Page<SceneVO> result = new Page<>(param.getPageNum(), param.getPageSize());
- result.setTotal(page.getTotal());
- result.setRecords(voList);
- return result;
- }
- @Override
- public Page loadAllScene2(SceneParamVO param) {
- param.setOrderBy("create_time desc");
- if(param.getSceneScheme()!= null && param.getSceneScheme() == 4){
- Page<ScenePro> page = new Page<>(param.getPageNum(), param.getPageSize());
- Page<ScenePro> sceneProPage = sceneProService.page(page, new LambdaQueryWrapper<ScenePro>()
- .eq(ScenePro::getTbStatus, TbStatus.VALID.code())
- .in(ScenePro::getSceneStatus, SceneStatus.SUCCESS.code(), SceneStatus.NO_DISPLAY.code())
- .and(wrapper -> wrapper.or().like(ScenePro::getSceneName, "%" + param.getSceneKey() + "%")
- .or().like(ScenePro::getNum, "%" + param.getSceneKey() + "%")).orderByDesc(ScenePro::getId));
- if(CollUtil.isEmpty(sceneProPage.getRecords())){
- return sceneProPage;
- }
- List<SceneVO> sceneList = sceneProService.convert(sceneProPage.getRecords());
- Page<SceneVO> result = new Page<>(param.getPageNum(), param.getPageSize());
- result.setTotal(sceneProPage.getTotal());
- result.setRecords(sceneList);
- return result;
- }
- Page<ScenePO> page = new Page<>(param.getPageNum(), param.getPageSize());
- Page<ScenePO> scenePOPage = baseMapper.selectScenePoByCondition(page, param);
- if(CollUtil.isEmpty(scenePOPage.getRecords())){
- return scenePOPage;
- }
- List<SceneVO> sceneList = sceneService.convert(scenePOPage.getRecords());
- Page<SceneVO> result = new Page<>(param.getPageNum(), param.getPageSize());
- result.setTotal(scenePOPage.getTotal());
- result.setRecords(sceneList);
- return result;
- }
- @Override
- public ResultData querySceneDataSource(SceneParamVO param){
- log.info("querySceneDataSource:查询模型数据");
- String num = param.getNum();
- if(StrUtil.isEmpty(num))
- throw new BusinessException(ErrorCode.FAILURE_CODE_7002);
- ScenePO scene = sceneService.findBySceneNum(num);
- String data = null;
- if(scene == null) {
- ScenePro scenePro = sceneProService.findBySceneNum(num);
- if(scenePro == null)
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
- SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
- data = sceneProExt.getDataSource();
- }else {
- data = scene.getDataSource();
- }
- if(data != null && !"".equals(data) && data.startsWith("http")){
- data = ConstantFilePath.BUILD_MODEL_PATH + data.split("/")[data.split("/").length - 2];
- }
- return ResultData.ok(data);
- }
- @Override
- public ResultData querySceneNum(SceneParamVO param){
- log.info("querySceneDataSource:查询模型数据");
- String path = param.getPath();
- if(path==null&&path.trim().equals(""))
- throw new BusinessException(ErrorCode.FAILURE_CODE_7002);
- path = path.split("/")[path.split("/").length - 1];
- Scene scene = sceneService.getSceneStatusByUnicode(path, TbStatus.VALID.code());
- String sceneNum = null;
- if(scene == null)
- {
- SceneProPO scenePro = sceneProService.getSceneStatusByUnicode(path, TbStatus.VALID.code());
- if(scenePro == null)
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
- sceneNum = scenePro.getNum();
- }else {
- sceneNum = scene.getNum();
- }
- return ResultData.ok(sceneNum);
- }
- @Override
- public ResultData downLoadZSData(BaseSceneParamVO param) throws Exception {
- String num = param.getNum();
- ScenePro scenePro = sceneProService.findBySceneNum(num);
- if(scenePro == null){
- throw new BusinessException(ServerCode.PARAM_REQUIRED, "num");
- }
- SceneDataDownload sceneDataDownload = sceneDataDownloadService.findBySceneNum(num);
- if(sceneDataDownload == null){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5025);
- }
- return ResultData.ok(BeanUtil.copyProperties(sceneDataDownload, SceneDataDownloadVO.class));
- }
- @Override
- public ResultData getScenes(DeviceSceneParamVO param) {
- QueryWrapper queryWrapper = new QueryWrapper();
- if(param.getCameraType() == null || param.getCameraType() == 0){
- queryWrapper.setEntityClass(Scene.class);
- }else {
- queryWrapper.setEntityClass(ScenePro.class);
- }
- queryWrapper.eq("tb_status",TbStatus.VALID);
- queryWrapper.orderByDesc("create_time");
- if (param.getCameraId() != null) {
- if (StringUtils.isNotEmpty(param.getStartTime()) && StringUtils.isNotEmpty(param.getEndTime())) {
- queryWrapper.between("create_time", com.fdkankan.common.util.DateUtil.convert2CST(Long.parseLong(param.getStartTime())),
- com.fdkankan.common.util.DateUtil.convert2CST(Long.parseLong(param.getEndTime())));
- }
- if(StringUtils.isNotEmpty(param.getSceneType())){
- queryWrapper.eq("scene_type",param.getSceneType());
- }else{
- queryWrapper.ne("scene_type",99);
- }
- queryWrapper.eq("camera_id", param.getCameraId());
- if(StringUtils.isNotEmpty(param.getSearchKey())){
- queryWrapper.like("scene_name", "%" + param.getSearchKey() + "%");
- }
- }
- Page page = new Page(param.getPageNum(), param.getPageSize());
- if(param.getCameraType() == null || param.getCameraType() == 0){
- page = this.page(page, queryWrapper);
- }else {
- page = sceneProService.page(page,queryWrapper);
- }
- return ResultData.ok(page);
- }
- @Override
- public ResultData deleteScene(String sceneNum) throws IOException {
- ScenePO bySceneNum = this.findBySceneNum(sceneNum);
- if(bySceneNum != null){
- UpdateWrapper<Scene> updateWrapper = new UpdateWrapper<>();
- updateWrapper.lambda()
- .eq(Scene::getNum,sceneNum).set(Scene::getTbStatus,TbStatus.DELETE.code());
- sceneService.update(updateWrapper);
- return ResultData.ok();
- }
- UpdateWrapper<ScenePro> updateWrapper = new UpdateWrapper<>();
- updateWrapper.lambda()
- .eq(ScenePro::getNum,sceneNum).set(ScenePro::getTbStatus,TbStatus.DELETE.code());
- sceneProService.update(updateWrapper);
- ScenePro sceneProEntity = sceneProService.findBySceneNum(sceneNum);
- JSONObject statusJson = new JSONObject();
- //临时将-2改成1,app还没完全更新
- statusJson.put("status", sceneProEntity.getSceneStatus() == -2? 1 : sceneProEntity.getSceneStatus());
- statusJson.put("webSite", sceneProEntity.getWebSite());
- statusJson.put("sceneNum", sceneProEntity.getNum());
- statusJson.put("thumb", sceneProEntity.getThumb());
- statusJson.put("payStatus", sceneProEntity.getPayStatus());
- statusJson.put("recStatus", sceneProEntity.getTbStatus() == 0 ? "A" :"I");
- FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"status.json", statusJson.toString());
- uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"status.json",
- "data/data"+sceneNum+File.separator+"status.json");
- return ResultData.ok();
- }
- @Override
- public Long getSceneCount(Long cameraId,Long userId) {
- LambdaQueryWrapper<Scene> queryWrapper = new LambdaQueryWrapper<Scene>()
- .eq(Scene::getTbStatus, TbStatus.VALID.code())
- .notIn(Scene::getSceneType, SceneType.YJHZXNFY.code());
- if(cameraId !=null){
- queryWrapper.eq(Scene::getCameraId ,cameraId);
- }
- if(userId !=null){
- queryWrapper.eq(Scene::getUserId ,userId);
- }
- return this.count(queryWrapper);
- }
- @Override
- public void copyScene(CopySceneParamVO paramVO) throws Exception {
- String num = paramVO.getOldNum();
- String newNum = paramVO.getNewNum();
- ScenePro scenePro = sceneProService.findBySceneNum(num);
- if (ObjectUtils.isEmpty(scenePro)) {
- return;
- }
- // 拷贝场景编辑资源
- String oldEditPath = String.format(UploadFilePath.EDIT_PATH, num);
- String newEditPath = String.format(UploadFilePath.EDIT_PATH, newNum);
- uploadToOssUtil.copyFiles(oldEditPath, newEditPath);
- // 拷贝场景展示资源
- String oldViewPath = String.format(UploadFilePath.VIEW_PATH, num);
- String newViewPath = String.format(UploadFilePath.VIEW_PATH, newNum);
- uploadToOssUtil.copyFiles(oldViewPath, newViewPath);
- // 拷贝本地资源
- String oldPath = String.format("/mnt/4Dkankan/scene/%s/caches/images/", num);
- String newPath = String.format("/mnt/4Dkankan/scene/%s/caches/images/", newNum);
- if(new File(oldPath).exists()){
- FileUtils.copyDirectiory(oldPath, newPath);
- }
- String scenePath = ConstantFilePath.SCENE_V4_PATH + num;
- File file = new File(scenePath);
- if(file.exists()){
- String newScenePath = ConstantFilePath.SCENE_V4_PATH + newNum;
- FileUtils.copyDirectiory(scenePath, newScenePath);
- }
- // 拷贝数据
- Long proId = scenePro.getId();
- scenePro.setId(paramVO.getNewSceneProId());
- scenePro.setWebSite(scenePro.getWebSite().replace(num, newNum));
- scenePro.setSceneName(paramVO.getNewSceneName());
- scenePro.setThumb(scenePro.getThumb().replace(num, newNum));
- scenePro.setVideos(scenePro.getVideos().replaceAll("https://4dkk.4dage.com/data/data" + num, "https://4dkk.4dage.com/scene_view_data/" + newNum + "/data"));
- scenePro.setNum(newNum);
- sceneProService.saveOrUpdate(scenePro);
- SceneProExt proExt = sceneProExtService.findBySceneProId(proId);
- proExt.setDataSource(paramVO.getDatasource());
- proExt.setId(null);
- proExt.setViewCount(0);
- proExt.setSceneProId(scenePro.getId());
- sceneProExtService.save(proExt);
- ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
- Long plusId = scenePlus.getId();
- scenePlus.setNum(newNum);
- scenePlus.setId(paramVO.getNewSceneProId());
- scenePlus.setTitle(scenePro.getSceneName());
- scenePlusService.saveOrUpdate(scenePlus);
- ScenePlusExt plusExt = scenePlusExtService.getScenePlusExtByPlusId(plusId);
- plusExt.setId(null);
- plusExt.setPlusId(scenePlus.getId());
- plusExt.setDataSource(paramVO.getDatasource());
- plusExt.setWebSite(plusExt.getWebSite().replace(num, newNum));
- plusExt.setThumb(plusExt.getThumb().replace(num, newNum));
- plusExt.setVideos(scenePro.getVideos());
- scenePlusExtService.save(plusExt);
- SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(plusId);
- Long sceneEditInfoId = sceneEditInfo.getId();
- sceneEditInfo.setId(null);
- sceneEditInfo.setScenePlusId(scenePlus.getId());
- sceneEditInfo.setSceneProId(scenePro.getId());
- sceneEditInfo.setTitle(paramVO.getNewSceneName());
- sceneEditInfoService.save(sceneEditInfo);
- SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfoId);
- sceneEditInfoExt.setId(null);
- sceneEditInfoExt.setEditInfoId(sceneEditInfo.getId());
- sceneEditInfoExt.setScenePlusId(scenePlus.getId());
- sceneEditInfoExt.setSceneProId(scenePro.getId());
- sceneEditInfoExtService.save(sceneEditInfoExt);
- SceneEditControls sceneEditControls = sceneEditControlsService.getBySceneEditId(sceneEditInfoId);
- sceneEditControls.setId(null);
- sceneEditControls.setEditInfoId(sceneEditInfo.getId());
- sceneEditControlsService.save(sceneEditControls);
- List<Surveillance> list = surveillanceService.list(new LambdaQueryWrapper<Surveillance>().eq(Surveillance::getNum, num));
- if (!Objects.isNull(list)) {
- list.stream().forEach(item -> {
- item.setNum(newNum);
- item.setId(null);
- surveillanceService.save(item);
- });
- }
- // 生成scene.json
- SceneJsonBean sceneJson = new SceneJsonBean();
- BeanUtil.copyProperties(sceneEditInfoExt, sceneJson);
- BeanUtil.copyProperties(sceneEditInfo, sceneJson);
- SceneEditControlsVO sceneEditControlsVO = BeanUtil.copyProperties(sceneEditControls, SceneEditControlsVO.class);
- sceneJson.setControls(sceneEditControlsVO);
- sceneJson.setNum(newNum);
- sceneJson.setCreateTime(scenePlus.getCreateTime());
- sceneJson.setSceneResolution(plusExt.getSceneResolution());
- sceneJson.setSceneFrom(plusExt.getSceneFrom());
- sceneJson.setSceneKind(plusExt.getSceneKind());
- if(StrUtil.isNotEmpty(plusExt.getVideos())){
- sceneJson.setVideos(plusExt.getVideos());
- }
- sceneJson.setMosaicList(sceneEditInfoService.getMosaicList(num));
- log.info("开始生成本地json文件……");
- String sceneJsonLocalPath = ConstantFilePath.SCENE_PATH + "data" + File.separator + "data" + newNum + File.separator + "scene.json";
- FileUtils.writeFile(sceneJsonLocalPath,JSON.toJSONString(sceneJson));
- String sceneJsonPath = String.format(UploadFilePath.DATA_VIEW_PATH+"scene.json", newNum);
- uploadToOssUtil.upload(JSON.toJSONBytes(sceneJson), sceneJsonPath);
- //删除scenejson缓存
- redisUtil.del(String.format(RedisKey.SCENE_JSON, num));
- // 生成二维码
- String sceneUrl = mainUrl + "/" + sceneProNewUrl;
- String outPathZh = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/" + newNum + ".png";
- String outPathEn = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/" + newNum + "_en.png";
- MatrixToImageWriterUtil.createQRCode(sceneUrl + newNum, outPathZh, false,null);
- MatrixToImageWriterUtil.createQRCode(sceneUrl + newNum + "&lang=en", outPathEn, false, null);
- uploadToOssUtil.upload(outPathZh, String.format(UploadFilePath.DOWNLOADS_QRCODE, newNum) + newNum + ".png");
- uploadToOssUtil.upload(outPathEn, String.format(UploadFilePath.DOWNLOADS_QRCODE, newNum) + newNum + "_en.png");
- }
- }
|