123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839 |
- package com.fdkankan.manage.service.impl;
- import cn.dev33.satoken.stp.StpUtil;
- import cn.hutool.core.bean.BeanUtil;
- 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;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.fdkankan.common.constant.SceneConstant;
- import com.fdkankan.fyun.face.FYunFileServiceInterface;
- import com.fdkankan.manage.common.*;
- import com.fdkankan.manage.exception.BusinessException;
- import com.fdkankan.common.util.*;
- import com.fdkankan.manage.httpClient.client.FdKKClient;
- import com.fdkankan.manage.httpClient.service.LaserService;
- import com.fdkankan.manage.entity.*;
- import com.fdkankan.manage.mapper.ISceneProMapper;
- import com.fdkankan.manage.mq.common.MqQueueUtil;
- import com.fdkankan.manage.mq.param.ScenePayStatusVo;
- import com.fdkankan.manage.mq.param.SceneRestStoreVo;
- import com.fdkankan.manage.service.*;
- import com.fdkankan.manage.util.CameraUtils;
- import com.fdkankan.manage.util.DateUtils;
- import com.fdkankan.manage.util.SceneStatusUtil;
- import com.fdkankan.manage.vo.request.SceneParam;
- import com.fdkankan.manage.vo.response.*;
- import com.fdkankan.rabbitmq.util.RabbitMqProducer;
- import com.fdkankan.redis.util.RedisUtil;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * <p>
- * pro场景表 服务实现类
- * </p>
- *
- * @author
- * @since 2022-06-16
- */
- @Service
- @Slf4j
- public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro> implements ISceneProService {
- @Autowired
- private ICameraService cameraService;
- @Autowired
- ICameraDetailService cameraDetailService;
- @Autowired
- ISceneService sceneService;
- @Autowired
- ISceneCopyLogService copyLogService;
- @Autowired
- IUserIncrementService userIncrementService;
- @Autowired
- IIncrementTypeService incrementTypeService;
- @Autowired
- ISceneProEditService sceneProEditService;
- @Autowired
- FYunFileServiceInterface fYunFileServiceInterface;
- @Autowired
- IScenePlusService scenePlusService;
- @Autowired
- IScene3dNumService scene3dNumService;
- @Autowired
- ISceneCopyLogService sceneCopyLogService;
- @Autowired
- IScenePlusExtService scenePlusExtService;
- @Autowired
- LaserService laserService;
- @Autowired
- FdKKClient fdKKClient;
- @Autowired
- IFolderSceneService folderSceneService;
- @Autowired
- ISceneBuildProcessLogService sceneBuildProcessLogService;
- @Autowired
- ISceneMoveLogService sceneMoveLogService;
- @Autowired
- ISceneResourceCameraService sceneResourceCameraService;
- @Autowired
- ISceneDelLogService sceneDelLogService;
- @Autowired
- RabbitMqProducer rabbitMqProducer;
- @Autowired
- RedisUtil redisUtil;
- @Autowired
- ISceneColdStorageService sceneColdStorageService;
- @Autowired
- ICommonService commonService;
- @Autowired
- IUserService userService;
- @Override
- public ScenePro getByNum(String num) {
- LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(ScenePro::getNum,num);
- wrapper.eq(ScenePro::getIsUpgrade,0);
- List<ScenePro> list = this.list(wrapper);
- if(list == null || list.size() <=0){
- return null;
- }
- return list.get(0);
- }
- @Override
- public HashMap<Long, Long> getCountGroupByUserId(List<Long> userIdList,Integer isObj) {
- HashMap<Long,Long> map = new HashMap<>();
- List<GroupByCount> result = this.getBaseMapper().getCountGroupByUserId(userIdList,isObj);
- result.forEach(entity ->map.put(entity.getId(),entity.getCount()));
- return map;
- }
- @Override
- public HashMap<Long, Long> getCountGroupByCameraId(List<Long> cameraIds) {
- HashMap<Long,Long> map = new HashMap<>();
- List<GroupByCount> result = this.getBaseMapper().getCountGroupByCameraId(cameraIds);
- result.forEach(entity ->map.put(entity.getId(),entity.getCount()));
- return map;
- }
- @Override
- public void unbindCamera(Long cameraId) {
- LambdaUpdateWrapper<ScenePro> wrapper = new LambdaUpdateWrapper<>();
- wrapper.set(ScenePro::getUserId,null)
- .eq(ScenePro::getCameraId,cameraId);
- wrapper.eq(ScenePro::getIsUpgrade,0);
- this.update(wrapper);
- }
- @Override
- public List<ScenePro> getListByCameraId(Long cameraId) {
- LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(ScenePro::getCameraId,cameraId);
- wrapper.eq(ScenePro::getIsUpgrade,0);
- return this.list(wrapper);
- }
- /**
- * @param payStatus -2 封存,为 1 解封
- */
- @Override
- public void lockOrUnLockBySpace(CameraDetail cameraDetail) {
- if(cameraDetail == null ){
- return;
- }
- if(!"aws".equals(CacheUtil.uploadType) && ( cameraDetail.getType() ==10 || cameraDetail.getType() == 11)){
- return;
- }
- ScenePayStatusVo scenePayStatusVo = new ScenePayStatusVo(cameraDetail.getCameraId());
- Map<String, Object> map = BeanUtil.beanToMap(scenePayStatusVo);
- rabbitMqProducer.sendByWorkQueue(MqQueueUtil.ucenterScenePayStatusQueue, map);
- }
- @Override
- public void lockOrUnLockBySpace(Long cameraId) {
- CameraDetail cameraDetail = cameraDetailService.getByCameraId(cameraId);
- this.lockOrUnLockBySpace(cameraDetail);
- }
- /**
- * 从oss中获取文件,并重写,上传替换
- */
- private void updateOssStatus(String path,Integer payStatus,String updateStatus) {
- String localPath = String.format(OssPath.localStatusPath, path);
- try {
- if(!fYunFileServiceInterface.fileExist(path)){
- return;
- }
- String data = fYunFileServiceInterface.getFileContent(path);
- if(StringUtils.isBlank(data)){
- return;
- }
- JSONObject jsonObject = JSONObject.parseObject(data);
- jsonObject.put(updateStatus,payStatus);
- String json = JSONUtil.toJsonStr(jsonObject);
- FileUtils.writeFile(localPath,json);
- log.info("updateOssStatus--localPath:{},ossPath:{}",localPath,path);
- fYunFileServiceInterface.uploadFile(localPath,path);
- }catch (Exception e){
- e.printStackTrace();
- }finally {
- FileUtil.del(localPath);
- }
- }
- @Override
- public PageInfo pageList(SceneParam param) {
- if(param.getType() == 2 || param.getType() == 6){ //深时
- return laserService.pageList(param);
- }
- if(param.getType() == 3){ //双目lite
- return sceneService.pageList(param);
- }
- //优化查询,去掉left join
- //snCode 查询,userName 查询,companyId查询
- //snCode回显,userName回显
- if(StringUtils.isNotBlank(param.getSnCode())){
- List<Camera> cameraList = cameraService.getLikeBySnCode(param.getSnCode());
- List<Long> cameraIds = cameraList.stream().map(Camera::getId).collect(Collectors.toList());
- param.setCameraIds(cameraIds);
- }
- if(StringUtils.isNotBlank(param.getUserName())){
- List<User> userList = userService.getLikeByUserName(param.getUserName());
- List<Long> userIds = userList.stream().map(User::getId).collect(Collectors.toList());
- param.setUserIds(userIds);
- }
- if(param.getCompanyId() != null){
- List<CameraDetail> details = cameraDetailService.getListByCompanyId(param.getCompanyId());
- List<Long> cameraIds = details.stream().map(CameraDetail::getCameraId).collect(Collectors.toList());
- if(param.getCameraIds() == null || param.getCameraIds().isEmpty()){
- param.setCameraIds(cameraIds);
- }else {
- List<Long> intersection = cameraIds.stream().filter(param.getCameraIds()::contains).collect(Collectors.toList());
- param.setCameraIds(intersection);
- }
- }
- if((param.getCameraIds() != null && param.getCameraIds().size()<=0) || (param.getUserIds() != null && param.getUserIds().size()<=0)){
- param.setNum("empty");
- }
- Page<SceneVo> page = this.getBaseMapper().pageList(new Page<>(param.getPageNum(),param.getPageSize()),param);
- List<SceneVo> records = page.getRecords();
- HashMap<String,SceneCopyLog> map = null;
- HashMap<String,SceneColdStorage> coldStorageMap = null;
- HashMap<Long, User> userMap = null;
- HashMap<Long, Camera> cameraMap = null;
- if(!records.isEmpty()){
- List<String> numList = records.parallelStream().map(SceneVo::getNum).collect(Collectors.toList());
- map = copyLogService.getByNewNumList(numList);
- coldStorageMap = sceneColdStorageService.getByNumList(numList);
- List<Long> userIds = records.parallelStream().map(SceneVo::getUserId).collect(Collectors.toList());
- userMap = userService.getByIds(userIds);
- List<Long> cameraIds = records.parallelStream().map(SceneVo::getCameraId).collect(Collectors.toList());
- cameraMap = cameraService.getByIds(cameraIds);
- }
- for (SceneVo record : page.getRecords()) {
- record.setStatusString(SceneStatusUtil.getStatusString(record));
- if(userMap != null){
- User user = userMap.get(record.getUserId());
- if(user != null){
- record.setUserName(user.getUserName());
- }
- }
- if(cameraMap != null){
- Camera camera = cameraMap.get(record.getCameraId());
- if(camera != null){
- record.setSnCode(camera.getSnCode());
- }
- }
- if(map !=null ){
- SceneCopyLog sceneCopyLog = map.get(record.getNum());
- if(sceneCopyLog != null){
- record.setCopyTime(sceneCopyLog.getCreateTime());
- record.setIsCopy(true);
- }
- }
- if(coldStorageMap != null){
- SceneColdStorage sceneColdStorage = coldStorageMap.get(record.getNum());
- if(sceneColdStorage != null){
- record.setIsColdStorage(true);
- }
- }
- if(record.getStatus() == -1){ //计算失败
- SceneBuildProcessLog sceneBuildProcessLog = sceneBuildProcessLogService.getByNum(record.getNum());
- if(sceneBuildProcessLog != null){
- record.setSceneBuildProcessLog(sceneBuildProcessLog);
- record.setBuildErrorReason(SceneBuildProcessLogEnum.getReason(sceneBuildProcessLog.getProcess()));
- }
- }
- //{"latitude":22.3672085,"longitude":113.595673,"altitude":9.275519,"horizontalAccuracy":65.0,"verticalAccuracy":10.0,"timestamp":1564381147.2775609}
- record.setAddressComponent(commonService.getAddressComponent(record.getGps()));
- }
- return PageInfo.PageInfo(page);
- }
- @Override
- public synchronized void move(SceneParam param) {
- Camera camera = cameraService.getBySnCode(param.getSnCode());
- if(camera == null){
- throw new BusinessException(ResultCode.CAMERA_SN_NOT_EXIST);
- }
- CameraDetail cameraDetail = cameraDetailService.getByCameraId(camera.getId());
- if(cameraDetail == null){
- throw new BusinessException(ResultCode.CAMERA_SN_NOT_EXIST);
- }
- ScenePro scenePro = this.getByNum(param.getNum());
- ScenePlus scenePlus = scenePlusService.getByNum(param.getNum());
- if((scenePro == null || scenePro.getCameraId() == null ) && (scenePlus== null || scenePlus.getCameraId() == null)){
- throw new BusinessException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
- }
- Integer status = scenePro == null ? scenePlus.getSceneStatus() : scenePro.getStatus();
- if(status == 0){
- throw new BusinessException(SceneConstant.FAILURE_CODE_5037, SceneConstant.FAILURE_MSG_5037);
- }
- Long sceneCameraId = scenePro == null ? scenePlus.getCameraId() : scenePro.getCameraId();
- Long space = scenePro == null ? 0 :scenePro.getSpace();
- String dataSource = scenePro == null ? null :scenePro.getDataSource();
- if(scenePlus !=null){
- ScenePlusExt scenePlusExt = scenePlusExtService.getByPlusId(scenePlus.getId());
- space = scenePlusExt.getSpace();
- dataSource = scenePlusExt.getDataSource();
- }
- space = space == null ? 0 :space;
- cameraDetailService.initSpace(cameraDetail.getCameraId());
- Boolean checkSpace = cameraDetailService.checkSpace(cameraDetail, space);
- //深时场景无限容量
- if( !checkSpace){
- throw new BusinessException(ResultCode.CAMERA_SPACE_ERROR);
- }
- Camera oldCamera = cameraService.getById(sceneCameraId);
- if(oldCamera == null){
- throw new BusinessException(ResultCode.CAMERA_NOT_EXIST);
- }
- CameraDetail oldCameraDetail = cameraDetailService.getByCameraId(oldCamera.getId());
- if(oldCameraDetail == null){
- throw new BusinessException(ResultCode.CAMERA_NOT_EXIST);
- }
- if(oldCameraDetail.getCameraId().equals(cameraDetail.getCameraId())){
- throw new BusinessException(ResultCode.CAMERA_NOT_MOVE);
- }
- if(!oldCameraDetail.getType().equals(cameraDetail.getType())){
- throw new BusinessException(ResultCode.CAMERA_TYPE_NOT_ERROR);
- }
- // String home = dataSource.replace("/mnt/data", "home")+"/data.fdage";
- // if(!fYunFileServiceInterface.fileExist(home)){
- // throw new BusinessException(ResultCode.MOVE_ERROR);
- // }
- // HashMap<String, SceneCopyLog> byNewNumList = copyLogService.getByNewNumList(Arrays.asList(param.getNum()));
- // if(byNewNumList.size() >0){
- // throw new BusinessException(ResultCode.MOVE_ERROR_COPY);
- // }
- Long oldUseSpace = oldCameraDetail.getUsedSpace() - space < 0 ? 0 : oldCameraDetail.getUsedSpace() - space;
- if("GB".equals(oldCameraDetail.getUnit())){
- oldUseSpace = 1L;
- }
- Long subSpace = oldCameraDetail.getTotalSpace() - oldUseSpace;
- if(scenePro!=null){
- LambdaUpdateWrapper<ScenePro> wrapper = new LambdaUpdateWrapper<>();
- wrapper.eq(ScenePro::getId,scenePro.getId());
- wrapper.set(ScenePro::getCameraId,camera.getId());
- wrapper.set(ScenePro::getUserId,cameraDetail.getUserId());
- // wrapper.set(ScenePro::getStatus,0);
- // this.updateOssStatus(String.format(OssPath.v3_statusPath,scenePro.getNum()),0,"status");
- this.update(wrapper);
- //场景迁移到另外的相机清除本身在的文件夹
- folderSceneService.delBySceneId(scenePro.getId());
- }
- if(scenePlus!=null){
- LambdaUpdateWrapper<ScenePlus> wrapper = new LambdaUpdateWrapper<>();
- wrapper.eq(ScenePlus::getId,scenePlus.getId());
- wrapper.set(ScenePlus::getCameraId,camera.getId());
- wrapper.set(ScenePlus::getUserId,cameraDetail.getUserId());
- //wrapper.set(ScenePlus::getSceneStatus,0);
- //this.updateOssStatus(String.format(OssPath.v4_statusPath,scenePlus.getNum()),0,"status");
- scenePlusService.update(wrapper);
- folderSceneService.delBySceneId(scenePlus.getId());
- }
- //协作相机
- sceneResourceCameraService.setCooperationUser(cameraDetail,param.getNum());
- //String newDataSource = updateFdageNewDataSource(scenePro, scenePlus, oldCamera.getSnCode(), param.getSnCode(), dataSource);
- if(cameraDetail.getType() == 10 || cameraDetail.getType() == 11){ //深时场景
- //迁移深时 dataSource
- //FileUtil.move(new File(dataSource +"_laserData"),new File(newDataSource+"_laserData"),true);
- laserService.move(param.getNum(),oldCamera.getSnCode(),camera.getSnCode(),cameraDetail.getUserId(),dataSource);
- }
- cameraDetailService.initSpace(oldCameraDetail);
- cameraDetailService.initSpace(cameraDetail);
- if(!"aws".equals(CacheUtil.uploadType) && oldCameraDetail.getType() != 11 && oldCameraDetail.getType() != 10 && subSpace >0){ //有剩余容量解封容量内场景
- this.lockOrUnLockBySpace(oldCameraDetail.getCameraId());
- }
- if(!"aws".equals(CacheUtil.uploadType) && cameraDetail.getType() != 11 && cameraDetail.getType() != 10){ //有剩余容量解封容量内场景
- this.lockOrUnLockBySpace(cameraDetail.getCameraId());
- }
- if("aws".equals(CacheUtil.uploadType) && subSpace >0){ //有剩余容量解封容量内场景
- this.lockOrUnLockBySpace(oldCameraDetail.getCameraId());
- }
- if("aws".equals(CacheUtil.uploadType)){ //有剩余容量解封容量内场景
- this.lockOrUnLockBySpace(cameraDetail.getCameraId());
- }
- sceneMoveLogService.saveLog(scenePro,scenePlus,camera.getSnCode(),oldCamera.getSnCode(),dataSource,dataSource, null);
- }
- 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;
- }
- /**
- * 兼容,之前迁移,不使用旧snCode 替换新snCode。重写文件
- */
- public String updateFdageNewDataSource(ScenePro scenePro,ScenePlus scenePlus,String oldSnCode,String newSnCode,String dataSource) {
- String localPathFdage = null;
- try {
- newSnCode = newSnCode.toLowerCase();
- String fdagePaht = dataSource.replace("/mnt/data","home") +"/data.fdage";
- if(!fYunFileServiceInterface.fileExist(fdagePaht)){
- return dataSource;
- }
- localPathFdage = String.format(OssPath.localFdagePath,fdagePaht);
- String fileContent = fYunFileServiceInterface.getFileContent(fdagePaht);
- JSONObject jsonObject = updateFdageJson(JSONObject.parseObject(fileContent), newSnCode);
- FileUtils.writeFile(localPathFdage ,JSONObject.toJSONString(jsonObject));
- String oldFdagePaht = dataSource.replace("/mnt/data","home") ;
- String[] split = oldFdagePaht.split("/");
- String newFdagePath = split[0] +"/"+ newSnCode +"/"+ split[2] +"/"+ newSnCode +"_" + split[3].split("_")[1];
- String delPath = null;
- if(!oldFdagePaht.equals(newFdagePath)){
- log.info("updateFdageCopy--复制oss资源--oldFdagePaht:{},newFdagePath:{}",oldFdagePaht,newFdagePath);
- fYunFileServiceInterface.copyFileInBucket(oldFdagePaht,newFdagePath);
- delPath = oldFdagePaht;
- }
- 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);
- if(delPath != null){
- fYunFileServiceInterface.deleteFolder(oldFdagePaht);
- }
- sceneMoveLogService.saveLog(scenePro,scenePlus,oldSnCode,newSnCode,dataSource,newDataSource, fileContent);
- return 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 {
- if(localPathFdage != null){
- FileUtil.del(localPathFdage);
- }
- if(scenePro!=null){
- LambdaUpdateWrapper<ScenePro> wrapper = new LambdaUpdateWrapper<>();
- wrapper.eq(ScenePro::getId,scenePro.getId());
- wrapper.set(ScenePro::getStatus,-2);
- this.update(wrapper);
- this.updateOssStatus(String.format(OssPath.v3_statusPath,scenePro.getNum()),-2,"status");
- }
- if(scenePlus!=null){
- LambdaUpdateWrapper<ScenePlus> wrapper = new LambdaUpdateWrapper<>();
- wrapper.eq(ScenePlus::getId,scenePlus.getId());
- wrapper.set(ScenePlus::getSceneStatus,-2);
- scenePlusService.update(wrapper);
- this.updateOssStatus(String.format(OssPath.v4_statusPath,scenePlus.getNum()),-2,"status");
- }
- }
- }
- 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
- public void copy(String sceneNum) throws Exception {
- ScenePro scenePro = this.getByNum(sceneNum);
- ScenePlus scenePlus = scenePlusService.getByNum(sceneNum);
- if((scenePro == null || scenePro.getCameraId() == null ) && (scenePlus== null || scenePlus.getCameraId() == null)){
- throw new BusinessException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
- }
- Long cameraId = scenePro == null ? scenePlus.getCameraId() : scenePro.getCameraId();
- Camera camera = cameraService.getById(cameraId);
- if(camera == null){
- throw new BusinessException(CameraConstant.FAILURE_CODE_6029, CameraConstant.FAILURE_MSG_6029);
- }
- CameraDetail detailEntity = cameraDetailService.getByCameraId(cameraId);
- if(detailEntity == null){
- throw new BusinessException(CameraConstant.FAILURE_CODE_6029, CameraConstant.FAILURE_MSG_6029);
- }
- Integer sceneStatus = scenePro == null ? scenePlus.getSceneStatus() : scenePro.getStatus();
- if(sceneStatus != -2){
- throw new BusinessException(ResultCode.SCENE_IS_BUILDING);
- }
- Long needSpace = 0L;
- if(scenePro != null){
- needSpace = scenePro.getSpace();
- }
- if(scenePlus != null){
- ScenePlusExt scenePlusExt = scenePlusExtService.getByPlusId(scenePlus.getId());
- if(scenePlusExt != null && scenePlusExt.getSpace() != null){
- needSpace = scenePlusExt.getSpace();
- }
- }
- Boolean checkSpace = cameraDetailService.checkSpace(detailEntity, needSpace);
- if(!checkSpace){
- throw new BusinessException(ResultCode.CAMERA_SPACE_ERROR);
- }
- HashMap<String, Object> param = new HashMap<>();
- param.put("num",sceneNum);
- JSONObject jsonObject = fdKKClient.copyScene(param, "m_a_n_a_g_e");
- Integer code = jsonObject.getInteger("code");
- if(code != 0){
- throw new BusinessException(jsonObject.getInteger("code"),jsonObject.getString("message"));
- }
- }
- @Override
- public void deleteByNum(String num) {
- Integer sceneSource = null;
- Long cameraId = null;
- ScenePro scenePro = this.getByNum(num);
- if(scenePro!=null){
- cameraId = scenePro.getCameraId();
- sceneSource = scenePro.getSceneSource();
- this.removeById(scenePro.getId());
- }
- Scene scene = sceneService.getByNum(num);
- if(scene!=null){
- sceneService.removeById(scene.getId());
- }
- ScenePlus scenePlus = scenePlusService.getByNum(num);
- if(scenePlus!=null){
- cameraId = scenePlus.getCameraId();
- sceneSource = scenePlus.getSceneSource();
- ScenePlusExt plusExt = scenePlusExtService.getByPlusId(scenePlus.getId());
- if(plusExt != null){
- scenePlusExtService.delByPlus(scenePlus.getId());
- }
- scenePlusService.removeById(scenePlus.getId());
- }
- if(sceneSource != null && (sceneSource == 4 || sceneSource == 5)){
- laserService.delete(num);
- }
- if(cameraId != null){
- cameraDetailService.initSpace(cameraId);
- this.lockOrUnLockBySpace(cameraId);
- }
- sceneDelLogService.saveLog(num, StpUtil.getLoginId());
- }
- @Override
- public Long getKkCount(List<String> asList, String startTime) {
- LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
- wrapper.in(ScenePro::getSceneSource,asList);
- wrapper.eq(ScenePro::getIsUpgrade,0);
- wrapper.lt(ScenePro::getCreateTime,startTime);
- long count = this.count(wrapper);
- LambdaQueryWrapper<ScenePlus> wrapper2 = new LambdaQueryWrapper<>();
- wrapper2.in(ScenePlus::getSceneSource,asList);
- wrapper2.lt(ScenePlus::getCreateTime,startTime);
- long count1 = scenePlusService.count(wrapper2);
- return count + count1;
- }
- @Override
- public Long getSsCount(List<String> asList, String startTime) {
- LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
- wrapper.in(ScenePro::getSceneSource,asList);
- wrapper.eq(ScenePro::getIsUpgrade,0);
- wrapper.lt(ScenePro::getCreateTime,startTime);
- LambdaQueryWrapper<ScenePlus> wrapper2 = new LambdaQueryWrapper<>();
- wrapper2.in(ScenePlus::getSceneSource,asList);
- wrapper2.lt(ScenePlus::getCreateTime,startTime);
- long count = scenePlusService.count(wrapper2);
- return this.count(wrapper) + count;
- }
- @Override
- public Long getSsObjCount(List<String> asList, String startTime) {
- LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
- wrapper.in(ScenePro::getSceneSource,asList);
- wrapper.eq(ScenePro::getIsUpgrade,0);
- if(StringUtils.isNotBlank(startTime)){
- wrapper.lt(ScenePro::getCreateTime,startTime);
- }
- wrapper.eq(ScenePro::getIsObj,1);
- LambdaQueryWrapper<ScenePlus> wrapper2 = new LambdaQueryWrapper<>();
- wrapper2.in(ScenePlus::getSceneSource,asList);
- if(StringUtils.isNotBlank(startTime)){
- wrapper2.lt(ScenePlus::getCreateTime,startTime);
- }
- List<ScenePlus> list = scenePlusService.list(wrapper2);
- List<Long> plusIds = list.stream().map(ScenePlus::getId).collect(Collectors.toList());
- long count = 0L;
- if(plusIds.size() >0){
- LambdaQueryWrapper<ScenePlusExt> wrapper3 = new LambdaQueryWrapper<>();
- wrapper3.in(ScenePlusExt::getPlusId,plusIds);
- wrapper3.eq(ScenePlusExt::getIsObj,1);
- count = scenePlusExtService.count(wrapper3);
- }
- return this.count(wrapper) + count;
- }
- @Override
- public HashMap<String, String> getSnCodeByNumList(Set<String> numList) {
- HashMap<String, Long> sceneMap = new HashMap<>();
- HashMap<Long, String> cameraMap = new HashMap<>();
- HashMap<String, String> snCodeMap = new HashMap<>();
- LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(ScenePro::getIsUpgrade,0);
- wrapper.in(ScenePro::getNum,numList);
- List<ScenePro> list = this.list(wrapper);
- if(list.size() >0){
- list.forEach(entity -> sceneMap.put(entity.getNum(),entity.getCameraId()));
- }
- LambdaQueryWrapper<ScenePlus> wrapper2 = new LambdaQueryWrapper<>();
- wrapper2.in(ScenePlus::getNum,numList);
- List<ScenePlus> list2 = scenePlusService.list(wrapper2);
- if(list2.size() >0){
- list2.forEach(entity -> sceneMap.put(entity.getNum(),entity.getCameraId()));
- }
- if(sceneMap.size() <=0){
- return snCodeMap;
- }
- Set<Long> cameraIds = list.stream().map(ScenePro::getCameraId).collect(Collectors.toSet());
- Set<Long> cameraIds2 = list2.stream().map(ScenePlus::getCameraId).collect(Collectors.toSet());
- cameraIds.addAll(cameraIds2);
- if(cameraIds.size() >0){
- List<Camera> cameraList = cameraService.listByIds(cameraIds);
- cameraList.forEach(entity -> cameraMap.put(entity.getId(),entity.getSnCode()));
- for (String num : numList) {
- Long cameraId = sceneMap.get(num);
- if(cameraId != null){
- snCodeMap.put(num,cameraMap.get(cameraId));
- }
- }
- List<CameraDetail> cameraIds1 = cameraDetailService.getByCameraIds(cameraList.stream().map(Camera::getId).collect(Collectors.toList()));
- for (CameraDetail cameraDetail : cameraIds1) {
- snCodeMap.put(cameraMap.get(cameraDetail.getCameraId()), CameraUtils.getCameraTypeStr(cameraDetail.getType()));
- }
- }
- 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()==null?0:groupByCount.getCount(), Long::sum);
- }
- List<GroupByCount > plusSum = this.getBaseMapper().getPlusSpaceGroupByCameraId();
- for (GroupByCount groupByCount : plusSum) {
- map.merge(groupByCount.getId(), groupByCount.getCount()==null?0:groupByCount.getCount(), Long::sum);
- }
- return map;
- }
- @Override
- public void rebuildScene(String num) {
- String redisKey2 = String.format(RedisKeyUtil.numShootKey, num);
- redisUtil.del(redisKey2);
- String dataSource = null;
- ScenePro scenePro = this.getByNum(num);
- if(scenePro!=null && scenePro.getSceneSource() != 4){
- throw new BusinessException(ResultCode.V3_SCENE_REBUILD);
- }
- ScenePlus scenePlus = scenePlusService.getByNum(num);
- if(scenePlus == null && scenePro == null){
- throw new BusinessException(ResultCode.SCENE_NOT_EXIST);
- }
- if(scenePro != null){
- dataSource = scenePro.getDataSource();
- }
- if(scenePlus != null){
- ScenePlusExt scenePlusExt= scenePlusExtService.getByPlusId(scenePlus.getId());
- if(scenePlusExt!= null){
- dataSource = scenePlusExt.getDataSource();
- }
- }
- if(StringUtils.isBlank(dataSource)){
- throw new BusinessException(ResultCode.SCENE_REBUILD_ERROR);
- }
- Long countByNewNum = sceneCopyLogService.getCountByNewNum(num);
- if(countByNewNum >0){
- throw new BusinessException(ResultCode.COPY_NUM_NOTREBUILD);
- }
- SceneColdStorage coldStorage = sceneColdStorageService.getByNum(num);
- if(coldStorage != null){
- throw new BusinessException(ResultCode.SCENE_REBUILD_ERROR2);
- }
- if(!fYunFileServiceInterface.fileExist(dataSource.replace("/mnt/data","home")+"/data.fdage")){
- throw new BusinessException(ResultCode.SCENE_REBUILD_ERROR);
- }
- HashMap<String,Object> paramMap = new HashMap<>();
- paramMap.put("num",num);
- try {
- JSONObject jsonObject = fdKKClient.rebuildScene(paramMap);
- Integer code = jsonObject.getInteger("code");
- if(code != 0){
- log.error("场景重算失败:{},{}",num,jsonObject);
- throw new BusinessException(ResultCode.SCENE_REBUILD_ERROR.code(), jsonObject.getString("msg"));
- }
- }catch (Exception e){
- throw new BusinessException(ResultCode.SCENE_REBUILD_ERROR);
- }
- }
- @Override
- public void restStore(String num) {
- if(StringUtils.isBlank(num)){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- String redisKey = String.format(RedisKeyUtil.restStoreKey, num);
- if(redisUtil.hasKey(redisKey)){
- throw new BusinessException(ResultCode.SCENE_STORE_ING);
- }
- SceneColdStorage sceneColdStorage = sceneColdStorageService.getByNum(num);
- if(sceneColdStorage == null){
- throw new BusinessException(ResultCode.SCENE_NOT_STORE);
- }
- String dataSource = scenePlusService.getDataSourceByNum(num);
- if(StringUtils.isBlank(dataSource)){
- throw new BusinessException(ResultCode.SCENE_NOT_EXIST);
- }
- String homePath = dataSource.replace("/mnt/data","home");
- SceneRestStoreVo sceneRestStoreVo = new SceneRestStoreVo(num,sceneColdStorage.getColdBucket(),sceneColdStorage.getBucket(),homePath);
- Map<String, Object> map = BeanUtil.beanToMap(sceneRestStoreVo);
- redisUtil.set(redisKey,homePath);
- rabbitMqProducer.sendByWorkQueue(MqQueueUtil.sceneRestoreQueue,map);
- //threadService.checkRestore(num,sceneColdStorage.getColdBucket(),sceneColdStorage.getBucket(),homePath);
- }
- @Override
- public void restStoreSuccess(String num) {
- Integer sceneResource = null;
- ScenePro scenePro = this.getByNum(num);
- Date time = DateUtils.dateAddOneMonth(new Date(),-11);
- String date = DateUtils.getDate(time);
- if(scenePro!=null ){
- sceneResource = scenePro.getSceneSource();
- LambdaUpdateWrapper<ScenePro> wrapper = new LambdaUpdateWrapper<>();
- wrapper.eq(ScenePro::getId,scenePro.getId());
- wrapper.set(ScenePro::getCreateTime,date);
- this.update(wrapper);
- }
- ScenePlus scenePlus = scenePlusService.getByNum(num);
- if(scenePlus != null ){
- sceneResource = scenePlus.getSceneSource();
- ScenePlusExt scenePlusExt = scenePlusExtService.getByPlusId(scenePlus.getId());
- if(scenePlusExt != null){
- LambdaUpdateWrapper<ScenePlusExt> wrapper = new LambdaUpdateWrapper<>();
- wrapper.eq(ScenePlusExt::getId,scenePlusExt.getId());
- wrapper.set(ScenePlusExt::getAlgorithmTime,date);
- scenePlusExtService.update(wrapper);
- }
- }
- //深时场景通知修改计算完成时间
- if(sceneResource != null && (sceneResource == 4 || sceneResource == 5)){
- HashMap<String,String> map = new HashMap<>();
- map.put("sceneCode",num);
- map.put("algorithmTime",date);
- rabbitMqProducer.sendByWorkQueue(MqQueueUtil.laserUnfreezeScene,map);
- }
- }
- @Override
- public Object getRestStoreProcess(String num) {
- if(StringUtils.isBlank(num)){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- SceneColdStorage sceneColdStorage = sceneColdStorageService.getByNum(num);
- if(sceneColdStorage == null){
- throw new BusinessException(ResultCode.SCENE_NOT_STORE);
- }
- String dataSource = scenePlusService.getDataSourceByNum(num);
- if(StringUtils.isBlank(dataSource)){
- throw new BusinessException(ResultCode.SCENE_NOT_EXIST);
- }
- String homePath = dataSource.replace("/mnt/data","home");
- return fYunFileServiceInterface.getRestoreFolderProcess(sceneColdStorage.getColdBucket(),homePath);
- }
- @Override
- public Long getSpaceSumByCameraId(Long cameraId) {
- return this.getBaseMapper().getSpaceSumByCameraId(cameraId);
- }
- @Override
- public Long getCountByCameraId(Long cameraId) {
- LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(ScenePro::getIsUpgrade,0);
- wrapper.eq(ScenePro::getCameraId,cameraId);
- wrapper.eq(ScenePro::getStatus,-2);
- return this.count(wrapper);
- }
- }
|