|
@@ -2,6 +2,7 @@ package com.fdkankan.manage.service.impl;
|
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
@@ -132,6 +133,9 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
*/
|
|
|
@Override
|
|
|
public void lockOrUnLockBySpace(CameraDetail cameraDetail, Long cameraId, Integer payStatus) {
|
|
|
+ if(cameraDetail == null){
|
|
|
+ cameraDetail = cameraDetailService.getByCameraId(cameraId);
|
|
|
+ }
|
|
|
LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
|
|
|
LambdaQueryWrapper<ScenePlus> plusWr = new LambdaQueryWrapper<>();
|
|
|
Long totalSpace = cameraDetail.getTotalSpace();
|
|
@@ -175,7 +179,7 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
|
|
|
List<Long> lockedIds = new ArrayList<>();
|
|
|
|
|
|
- if(totalSpace == -1 && payStatus == 1){
|
|
|
+ if(totalSpace == -1){
|
|
|
List<Long> collect = list.stream().map(ScenePro::getId).collect(Collectors.toList());
|
|
|
List<Long> collect2 = plusList.stream().map(ScenePlus::getId).collect(Collectors.toList());
|
|
|
lockedIds.addAll(collect);
|
|
@@ -187,7 +191,7 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
Long beyondSpace = 0L;
|
|
|
Long accumulateSpace = 0L;
|
|
|
if(payStatus == 1){
|
|
|
- beyondSpace = totalSpace - cameraDetail.getTotalSpace();
|
|
|
+ beyondSpace = totalSpace - cameraDetail.getUsedSpace();
|
|
|
getScenePlusLockedIds(lockedIds, plusList, beyondSpace, accumulateSpace);
|
|
|
getSceneLockedIds(lockedIds,list,beyondSpace,accumulateSpace);
|
|
|
}else {
|
|
@@ -442,70 +446,83 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
if(cameraDetail.getType() == 10){ //深时场景
|
|
|
laserService.move(param.getNum(),oldCamera.getSnCode(),camera.getSnCode(),cameraDetail.getUserId());
|
|
|
}
|
|
|
- updateFdage(oldCamera.getSnCode(),param.getSnCode(),dataSource);
|
|
|
+ updateFdageNewDataSource(scenePro,scenePlus,oldCamera.getSnCode(),param.getSnCode(),dataSource);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void updateFdage(String oldSnCode,String newSnCode,String dataSource) {
|
|
|
- String localPath = String.format(OssPath.localFdagePath,dataSource)+"/data.fdage";
|
|
|
- try {
|
|
|
- String fdagePaht = dataSource.replace("/mnt/data","home") +"/data.fdage";
|
|
|
- String fileContent = fYunFileServiceInterface.getFileContent(fdagePaht);
|
|
|
- String newJson = fileContent.replaceAll("(?i)"+oldSnCode,newSnCode.toLowerCase());
|
|
|
- FileUtils.writeFile(localPath ,newJson);
|
|
|
- log.info("updateFdage--localPath:{},ossPath:{}",localPath,fdagePaht);
|
|
|
- String localPathBack = localPath+"_"+oldSnCode+"-"+newSnCode+"_"+Dateutils.getDateN(new Date())+".back";
|
|
|
- String fdagePathBack = fdagePaht+"_"+oldSnCode+"-"+newSnCode+"_"+Dateutils.getDateN(new Date())+".back";
|
|
|
-
|
|
|
- fYunFileServiceInterface.downloadFile(fdagePaht,localPathBack);
|
|
|
- fYunFileServiceInterface.uploadFile(localPathBack,fdagePathBack);
|
|
|
- fYunFileServiceInterface.uploadFile(localPath,fdagePaht);
|
|
|
- }catch (Exception e){
|
|
|
- log.error("updateFdage-error:oldSnCode:{},newSnCode:{},dataSource:{}",oldSnCode,newSnCode,dataSource);
|
|
|
- log.error("updateFdage-error:",e);
|
|
|
- }finally {
|
|
|
- FileUtil.del(localPath);
|
|
|
+
|
|
|
+
|
|
|
+ private JSONObject updateFdageJson(JSONObject jsonObject,String newSnCode){
|
|
|
+ JSONObject cam = jsonObject.getJSONObject("cam");
|
|
|
+ if(cam != null){
|
|
|
+ cam.put("uuid",newSnCode.toLowerCase()); //替换相机sn uuid
|
|
|
}
|
|
|
+ JSONArray points = jsonObject.getJSONArray("points"); //修改点位中的相机sn
|
|
|
+ if(points !=null){
|
|
|
+ for (Object point : points) {
|
|
|
+ JSONObject jobj = (JSONObject) point;
|
|
|
+ jobj.put("camera",newSnCode.toLowerCase());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ jsonObject.put("creator",newSnCode.toLowerCase()); //替换相机拍摄sn
|
|
|
+ return jsonObject;
|
|
|
}
|
|
|
|
|
|
- public void updateFdageNewDataSource(String oldSnCode,String newSnCode,String dataSource) {
|
|
|
- String localPath = String.format(OssPath.localFdagePath,dataSource);
|
|
|
+ /**
|
|
|
+ * 兼容,之前迁移,不使用旧snCode 替换新snCode。重写文件
|
|
|
+ */
|
|
|
+ public void updateFdageNewDataSource(ScenePro scenePro,ScenePlus scenePlus,String oldSnCode,String newSnCode,String dataSource) {
|
|
|
+ String localPathFdage = null;
|
|
|
try {
|
|
|
- String localPathFdage = String.format(OssPath.localFdagePath,dataSource)+"/data.fdage";
|
|
|
+ newSnCode = newSnCode.toLowerCase();
|
|
|
+ String fdagePaht = dataSource.replace("/mnt/data","home") +"/data.fdage";
|
|
|
+ localPathFdage = String.format(OssPath.localFdagePath,fdagePaht);
|
|
|
|
|
|
- String homeData = dataSource.replace("/mnt/data","home");
|
|
|
- ShellUtil.yunDownload(homeData,localPath);
|
|
|
+ String fileContent = fYunFileServiceInterface.getFileContent(fdagePaht);
|
|
|
|
|
|
- String fileContent = FileUtils.readFile(localPathFdage);
|
|
|
- String newJson = fileContent.replaceAll("(?i)"+oldSnCode,newSnCode.toLowerCase());
|
|
|
- FileUtils.writeFile(localPathFdage ,newJson);
|
|
|
+ JSONObject jsonObject = updateFdageJson(JSONObject.parseObject(fileContent), newSnCode);
|
|
|
+ FileUtils.writeFile(localPathFdage ,JSONObject.toJSONString(jsonObject));
|
|
|
|
|
|
String oldFdagePaht = dataSource.replace("/mnt/data","home") ;
|
|
|
- String newFdagePaht = oldFdagePaht.replaceAll("(?i)"+oldSnCode,newSnCode.toLowerCase()) ;
|
|
|
- ShellUtil.yunUpload(localPath,newFdagePaht);
|
|
|
-
|
|
|
- log.info("updateFdage--localPath:{},ossPath:{}",localPath,newFdagePaht);
|
|
|
- String newDataSource = dataSource.replaceAll("(?i)"+oldSnCode,newSnCode.toLowerCase()) ;
|
|
|
- this.updateDataSource(dataSource,newDataSource);
|
|
|
- fYunFileServiceInterface.deleteFolder(oldFdagePaht);
|
|
|
+ String[] split = oldFdagePaht.split("/");
|
|
|
+ String newFdagePath = split[0] +"/"+ newSnCode +"/"+ split[2] +"/"+ newSnCode +"_" + split[3].split("_")[1];
|
|
|
+ if(!oldFdagePaht.equals(newFdagePath)){
|
|
|
+ log.info("updateFdageCopy--复制oss资源--oldFdagePaht:{},newFdagePath:{}",oldFdagePaht,newFdagePath);
|
|
|
+ fYunFileServiceInterface.copyFileInBucket(oldFdagePaht,newFdagePath);
|
|
|
+ fYunFileServiceInterface.deleteFolder(oldFdagePaht);
|
|
|
+ }
|
|
|
+ fYunFileServiceInterface.copyFileInBucket(newFdagePath+"/data.fdage",newFdagePath+"/"+oldSnCode.toLowerCase()+"-"+newSnCode+"_"+Dateutils.getDate(new Date())+".data.fdage");
|
|
|
+ fYunFileServiceInterface.uploadFile(localPathFdage,newFdagePath+"/data.fdage");
|
|
|
+ log.info("updateFdage--localPathFdage:{},newFdagePath:{}",localPathFdage,newFdagePath);
|
|
|
+ String newDataSource = newFdagePath.replace("home","/mnt/data");
|
|
|
+ this.updateDataSource(scenePro,scenePlus,newDataSource);
|
|
|
}catch (Exception e){
|
|
|
log.error("updateFdage-error:oldSnCode:{},newSnCode:{},dataSource:{}",oldSnCode,newSnCode,dataSource);
|
|
|
log.error("updateFdage-error:",e);
|
|
|
+ throw new BusinessException(ResultCode.MOVE_SCENE_ERROR);
|
|
|
}finally {
|
|
|
- FileUtil.del(localPath);
|
|
|
+ if(localPathFdage != null){
|
|
|
+ FileUtil.del(localPathFdage);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void updateDataSource(String dataSource, String newDataSource) {
|
|
|
- LambdaUpdateWrapper<ScenePro> wrapper = new LambdaUpdateWrapper<>();
|
|
|
- wrapper.eq(ScenePro::getDataSource,dataSource);
|
|
|
- wrapper.set(ScenePro::getDataSource,newDataSource);
|
|
|
- this.update(wrapper);
|
|
|
|
|
|
- LambdaUpdateWrapper<ScenePlusExt> wrapperPlus = new LambdaUpdateWrapper<>();
|
|
|
- wrapperPlus.eq(ScenePlusExt::getDataSource,dataSource);
|
|
|
- wrapperPlus.set(ScenePlusExt::getDataSource,newDataSource);
|
|
|
- scenePlusExtService.update(wrapperPlus);
|
|
|
+ private void updateDataSource(ScenePro scenePro,ScenePlus scenePlus, String newDataSource) {
|
|
|
+ if(scenePro !=null){
|
|
|
+ LambdaUpdateWrapper<ScenePro> wrapper = new LambdaUpdateWrapper<>();
|
|
|
+ wrapper.eq(ScenePro::getId,scenePro.getId());
|
|
|
+ wrapper.eq(ScenePro::getIsUpgrade,0);
|
|
|
+ wrapper.set(ScenePro::getDataSource,newDataSource);
|
|
|
+ this.update(wrapper);
|
|
|
+ }
|
|
|
+ if(scenePlus !=null){
|
|
|
+ LambdaUpdateWrapper<ScenePlusExt> wrapperPlus = new LambdaUpdateWrapper<>();
|
|
|
+ wrapperPlus.eq(ScenePlusExt::getPlusId,scenePlus.getId());
|
|
|
+ wrapperPlus.set(ScenePlusExt::getDataSource,newDataSource);
|
|
|
+ scenePlusExtService.update(wrapperPlus);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -524,9 +541,13 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
if(detailEntity == null){
|
|
|
throw new BusinessException(CameraConstant.FAILURE_CODE_6029, CameraConstant.FAILURE_MSG_6029);
|
|
|
}
|
|
|
- if(detailEntity.getType() == 10){
|
|
|
- throw new BusinessException(ResultCode.SS_NO_COPY);
|
|
|
+ Integer sceneStatus = scenePro == null ? scenePlus.getSceneStatus() : scenePro.getStatus();
|
|
|
+ if(sceneStatus != -2){
|
|
|
+ throw new BusinessException(ResultCode.SCENE_IS_BUILDING);
|
|
|
}
|
|
|
+// if(detailEntity.getType() == 10 ){
|
|
|
+// throw new BusinessException(ResultCode.SS_NO_COPY);
|
|
|
+// }
|
|
|
|
|
|
HashMap<String, Object> param = new HashMap<>();
|
|
|
param.put("num",sceneNum);
|
|
@@ -537,9 +558,13 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
@Override
|
|
|
public void deleteByNum(String num) {
|
|
|
Integer sceneSource = null;
|
|
|
+ Long cameraId = null;
|
|
|
+ Long space = null;
|
|
|
ScenePro scenePro = this.getByNum(num);
|
|
|
if(scenePro!=null){
|
|
|
+ cameraId = scenePro.getCameraId();
|
|
|
sceneSource = scenePro.getSceneSource();
|
|
|
+ space = scenePro.getSpace();
|
|
|
this.removeById(scenePro.getId());
|
|
|
}
|
|
|
Scene scene = sceneService.getByNum(num);
|
|
@@ -548,13 +573,21 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
}
|
|
|
ScenePlus scenePlus = scenePlusService.getByNum(num);
|
|
|
if(scenePlus!=null){
|
|
|
+ cameraId = scenePlus.getCameraId();
|
|
|
sceneSource = scenePlus.getSceneSource();
|
|
|
+ ScenePlusExt plusExt = scenePlusExtService.getByPlusId(scenePlus.getId());
|
|
|
+ if(plusExt != null){
|
|
|
+ space = plusExt.getSpace();
|
|
|
+ scenePlusExtService.delByPlus(scenePlus.getId());
|
|
|
+ }
|
|
|
scenePlusService.removeById(scenePlus.getId());
|
|
|
- scenePlusExtService.delByPlus(scenePlus.getId());
|
|
|
}
|
|
|
if(sceneSource != null && sceneSource == 4){
|
|
|
laserService.delete(num);
|
|
|
}
|
|
|
+ if(cameraId != null){
|
|
|
+ cameraDetailService.addUsedSpace(cameraId,space);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -651,4 +684,18 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
|
|
|
return snCodeMap;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HashMap<Long,Long > getSpaceGroupByCameraId() {
|
|
|
+ List<GroupByCount> proSum = this.getBaseMapper().getProSpaceGroupByCameraId();
|
|
|
+ HashMap<Long,Long > map = new HashMap<>();
|
|
|
+ for (GroupByCount groupByCount : proSum) {
|
|
|
+ map.merge(groupByCount.getId(), groupByCount.getCount(), Long::sum);
|
|
|
+ }
|
|
|
+ List<GroupByCount > plusSum = this.getBaseMapper().getPlusSpaceGroupByCameraId();
|
|
|
+ for (GroupByCount groupByCount : plusSum) {
|
|
|
+ map.merge(groupByCount.getId(), groupByCount.getCount(), Long::sum);
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
}
|