1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258 |
- package com.fdkankan.ucenter.service.impl;
- import cn.hutool.core.io.FileUtil;
- import cn.hutool.json.JSONUtil;
- 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.common.constant.SceneKind;
- import com.fdkankan.common.exception.BusinessException;
- import com.fdkankan.common.util.*;
- import com.fdkankan.rabbitmq.bean.BuildSceneCallMessage;
- import com.fdkankan.rabbitmq.util.RabbitMqProducer;
- import com.fdkankan.redis.constant.RedisKey;
- import com.fdkankan.ucenter.common.OssPath;
- import com.fdkankan.ucenter.common.PageInfo;
- import com.fdkankan.fyun.face.FYunFileServiceInterface;
- import com.fdkankan.image.MatrixToImageWriterUtil;
- import com.fdkankan.ucenter.common.constants.ConstantFilePath;
- import com.fdkankan.redis.util.RedisUtil;
- import com.fdkankan.ucenter.common.utils.ShellUtil;
- import com.fdkankan.ucenter.constant.CameraConstant;
- import com.fdkankan.ucenter.constant.LoginConstant;
- import com.fdkankan.ucenter.entity.*;
- import com.fdkankan.ucenter.httpClient.service.LaserService;
- import com.fdkankan.ucenter.mapper.ISceneProMapper;
- import com.fdkankan.ucenter.mapper.ISceneUpgradeMapper;
- import com.fdkankan.ucenter.service.*;
- import com.fdkankan.ucenter.util.DateUserUtil;
- import com.fdkankan.ucenter.vo.ResponseScene;
- import com.fdkankan.ucenter.vo.request.RequestScene;
- import com.fdkankan.ucenter.vo.request.SceneParam;
- import com.fdkankan.ucenter.vo.response.GroupByCount;
- import com.fdkankan.ucenter.vo.response.SceneInfoVo;
- import com.fdkankan.ucenter.vo.response.SceneNumVo;
- import com.fdkankan.ucenter.vo.response.SceneVo;
- import java.io.File;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Collections;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.Objects;
- import java.util.concurrent.CompletableFuture;
- import java.util.concurrent.locks.Condition;
- import java.util.stream.Collectors;
- import javax.annotation.Resource;
- import lombok.extern.slf4j.Slf4j;
- 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.Value;
- import org.springframework.stereotype.Service;
- import org.springframework.util.ObjectUtils;
- /**
- * <p>
- * pro场景表 服务实现类
- * </p>
- *
- * @author
- * @since 2022-07-04
- */
- @Service
- @Slf4j
- public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro> implements ISceneProService {
- @Autowired
- private IUserService userService;
- @Autowired
- private ISceneCooperationService sceneCooperationService;
- @Autowired
- private IScenePlusService scenePlusService;
- @Autowired
- private ISceneService sceneService;
- @Autowired
- private LaserService fdkkLaserService;
- @Autowired
- private FYunFileServiceInterface fYunFileService;
- @Autowired
- private IUserIncrementService userIncrementService;
- @Autowired
- private IIncrementTypeService incrementTypeService;
- @Autowired
- private IScenePlusExtService scenePlusExtService;
- @Autowired
- private ISceneEditInfoService sceneEditInfoService;
- @Autowired
- private ICameraDetailService cameraDetailService;
- @Autowired
- ICameraService cameraService;
- @Autowired
- private IFolderService folderService;
- @Autowired
- private IFolderSceneService folderSceneService;
- @Autowired
- private ISceneCopyLogService sceneCopyLogService;
- @Autowired
- private IScene3dNumService scene3dNumService;
- @Autowired
- private ISceneProEditService sceneProEditService;
- @Autowired
- private RedisUtil redisUtil;
- @Autowired
- private ISceneUpgradeMapper sceneUpgradeMapper;
- @Autowired
- private IInnerService innerService;
- @Autowired
- LaserService laserService;
- @Value("${main.url}")
- private String mainUrl;
- @Value("${scene.pro.url}")
- private String sceneProUrl;
- @Value("${scene.pro.new.url}")
- private String sceneProNewUrl;
- @Value("${queue.modeling.obj.modeling-pre}")
- private String queueObjModelingPre;
- @Autowired
- private RabbitMqProducer mqProducer;
- @Override
- public HashMap<String, SceneNumVo> findSceneNumber(String token) {
- User user = userService.getByUserName(JwtUtil.getUsername(token));
- SceneNumVo sceneNumVoKk = getSceneNumVoByType(Arrays.asList(1,2,12,13,14), user.getId());
- Integer oldNum = sceneService.getCountByUserId(user.getId());
- sceneNumVoKk.setSceneNum( oldNum + sceneNumVoKk.getSceneNum());
- sceneNumVoKk.setTotalNum(oldNum + sceneNumVoKk.getTotalNum());
- SceneNumVo sceneNumVoKj = getSceneNumVoByType(Collections.singletonList(3), user.getId());
- SceneNumVo sceneNumVoSS = fdkkLaserService.getLaserSceneNumByUser(token);
- SceneNumVo sceneNumVoSSObj = getSceneNumVoByObjType(Arrays.asList(4), user.getId());
- HashMap<String, SceneNumVo> hashMap = new HashMap<>();
- hashMap.put("kk",sceneNumVoKk);
- hashMap.put("kJ",sceneNumVoKj);
- hashMap.put("SS",sceneNumVoSS);
- hashMap.put("SS_OBJ",sceneNumVoSSObj);
- return hashMap;
- }
- private SceneNumVo getSceneNumVoByType(List<Integer> sceneSourceList, Long userId){
- SceneNumVo sceneNumVo = new SceneNumVo();
- LambdaQueryWrapper<ScenePro> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(ScenePro::getUserId, userId);
- queryWrapper.in(ScenePro::getSceneSource, sceneSourceList);
- queryWrapper.eq(ScenePro::getIsUpgrade, 0);
- Integer sceneNum = Math.toIntExact(this.count(queryWrapper));
- Long count = scenePlusService.getCountByUserId(userId,sceneSourceList);
- sceneNumVo.setCooperationSceneNum(sceneCooperationService.getCooperationSceneNum(userId,sceneSourceList));
- sceneNumVo.setSceneNum(sceneNum + count);
- sceneNumVo.setTotalNum(sceneNumVo.getSceneNum() + sceneNumVo.getCooperationSceneNum());
- return sceneNumVo;
- }
- private SceneNumVo getSceneNumVoByObjType(List<Integer> sceneSourceList, Long userId){
- SceneNumVo sceneNumVo = new SceneNumVo();
- LambdaQueryWrapper<ScenePro> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(ScenePro::getUserId, userId);
- queryWrapper.in(ScenePro::getSceneSource, sceneSourceList);
- queryWrapper.eq(ScenePro::getIsUpgrade, 0);
- queryWrapper.eq(ScenePro::getIsObj,1);
- Integer sceneNum = Math.toIntExact(this.count(queryWrapper));
- LambdaQueryWrapper<ScenePlusExt> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(ScenePlusExt::getIsObj,1);
- List<ScenePlusExt> list = scenePlusExtService.list(wrapper);
- List<Long> plusIds = list.stream().map(ScenePlusExt::getPlusId).collect(Collectors.toList());
- long plusCount = 0L;
- long cooperNum = 0L;
- if(plusIds.size() >0){
- LambdaQueryWrapper<ScenePlus> plusWr = new LambdaQueryWrapper<>();
- plusWr.in(ScenePlus::getId,plusIds);
- plusWr.in(ScenePlus::getSceneSource,sceneSourceList);
- List<ScenePlus> plusList = scenePlusService.list(plusWr);
- if(plusList.size() >0){
- List<ScenePlus> userList = plusList.stream().filter(entity -> userId.equals(entity.getUserId())).collect(Collectors.toList());
- plusCount = userList.size();
- List<String> numList = plusList.stream().map(ScenePlus::getNum).collect(Collectors.toList());
- HashMap<String, User> cooNumList = sceneCooperationService.getByNumList(numList);
- for (String num : cooNumList.keySet()) {
- if(userId.equals(cooNumList.get(num).getId())){
- cooperNum ++;
- }
- }
- }
- }
- sceneNumVo.setCooperationSceneNum(cooperNum);
- sceneNumVo.setSceneNum(sceneNum + plusCount);
- sceneNumVo.setTotalNum(sceneNumVo.getSceneNum() + sceneNumVo.getCooperationSceneNum());
- return sceneNumVo;
- }
- @Override
- public HashMap<Long,GroupByCount> findSceneNumByCameraIds(List<Long> cameraIdList) {
- HashMap<Long,GroupByCount> map = new HashMap<>();
- List<GroupByCount> result = this.getBaseMapper().findSceneProNumByCameraIds(cameraIdList);
- List<GroupByCount> result2 = this.getBaseMapper().findScenePlusNumByCameraIds(cameraIdList);
- result.forEach(entity ->map.put(entity.getId(),entity));
- for (GroupByCount groupByCount : result2) {
- if (map.get(groupByCount.getId()) != null) {
- Long totalCount = map.get(groupByCount.getId()).getCount() + groupByCount.getCount();
- String lastTime = DateUserUtil.getLastTime(map.get(groupByCount.getId()).getLastTime(), groupByCount.getLastTime());
- groupByCount.setCount(totalCount);
- groupByCount.setLastTime(lastTime);
- }
- map.put(groupByCount.getId(),groupByCount);
- }
- return map;
- }
- /**
- * @param payStatus -2 封存,为 1 解封
- */
- @Override
- public void lockOrUnLockBySpace(CameraDetail cameraDetail, Long cameraId, Integer payStatus) {
- LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
- LambdaQueryWrapper<ScenePlus> plusWr = new LambdaQueryWrapper<>();
- Long totalSpace = cameraDetail.getTotalSpace();
- UserIncrement userIncrement = userIncrementService.getByCameraId(cameraId);
- if(userIncrement!=null){
- IncrementType incrementType = incrementTypeService.getById(userIncrement.getIncrementTypeId());
- if(incrementType!=null){
- if(incrementType.getCameraCapacity() == -1){
- totalSpace = -1L;
- }else {
- totalSpace = incrementType.getCameraCapacity() * 1024 * 1024L;
- }
- }
- }
- log.info("lockOrUnLockBySpace---cameraId:{},payStatus:{},totalSpace:{},useSpace{}",
- cameraId,payStatus,totalSpace,cameraDetail.getUsedSpace());
- if(payStatus == 1){ //解封,判断用户权益,用户会员权益无限容量
- wrapper.orderByAsc(ScenePro::getCreateTime);
- plusWr.orderByAsc(ScenePlus::getCreateTime);
- wrapper.eq(ScenePro::getPayStatus,-2);
- plusWr.eq(ScenePlus::getPayStatus,-2);
- }else {
- if (totalSpace >= cameraDetail.getUsedSpace()) {
- // 总容量大于已使用容量,不予封存
- return;
- }
- wrapper.orderByDesc(ScenePro::getCreateTime);
- plusWr.orderByDesc(ScenePlus::getCreateTime);
- wrapper.eq(ScenePro::getPayStatus,1);
- plusWr.eq(ScenePlus::getPayStatus,1);
- }
- wrapper.eq(ScenePro::getCameraId,cameraId)
- .eq(ScenePro::getIsUpgrade,0);
- plusWr.eq(ScenePlus::getCameraId,cameraId);
- List<ScenePro> list = this.list(wrapper);
- List<ScenePlus> plusList = scenePlusService.list(plusWr);
- Long beyondSpace = Math.abs(cameraDetail.getUsedSpace() - totalSpace);
- Long accumulateSpace = 0L;
- List<Long> lockedIds = new ArrayList<>();
- if(payStatus == 1){
- Long doSpace = getScenePlusLockedIds(lockedIds, plusList, totalSpace, beyondSpace, accumulateSpace);
- beyondSpace -= doSpace;
- getSceneLockedIds(lockedIds,list,totalSpace,beyondSpace,accumulateSpace);
- }else {
- Long doSpace = getSceneLockedIds(lockedIds, list, totalSpace, beyondSpace, accumulateSpace);
- beyondSpace -= doSpace;
- getScenePlusLockedIds(lockedIds,plusList,totalSpace,beyondSpace,accumulateSpace);
- }
- lockOrUnLockScenes(lockedIds,payStatus);
- }
- private Long getSceneLockedIds(List<Long> lockedIds ,List<ScenePro> list,Long count,Long beyondSpace,Long accumulateSpace){
- if (list != null && list.size() > 0){
- for (ScenePro scenePro : list){
- accumulateSpace += scenePro.getSpace();
- if (count ==-1 && accumulateSpace.compareTo(beyondSpace) > 0){
- return accumulateSpace - scenePro.getSpace();
- }
- lockedIds.add(scenePro.getId());
- }
- }
- return accumulateSpace;
- }
- private Long getScenePlusLockedIds(List<Long> lockedIds , List<ScenePlus> list, Long count, Long beyondSpace, Long accumulateSpace){
- if (list != null && list.size() > 0){
- List<Long> plusIds = list.parallelStream().map(ScenePlus::getId).collect(Collectors.toList());
- HashMap<Long, ScenePlusExt> byPlusIds = scenePlusExtService.getByPlusIds(plusIds);
- for (ScenePlus scenePlus : list){
- ScenePlusExt scenePlusExt = byPlusIds.get(scenePlus.getId());
- accumulateSpace += scenePlusExt.getSpace();
- if (count ==-1 && accumulateSpace.compareTo(beyondSpace) > 0){
- return accumulateSpace - scenePlusExt.getSpace();
- }
- lockedIds.add(scenePlus.getId());
- }
- }
- return accumulateSpace;
- }
- // payStatus 为 -2 封存,为 1 解封
- private void lockOrUnLockScenes(List<Long> lockedIds,Integer payStatus) {
- if (lockedIds == null || lockedIds.size() == 0){
- return;
- }
- LambdaUpdateWrapper<ScenePro> updateWrapper = new LambdaUpdateWrapper<>();
- updateWrapper.set(ScenePro::getPayStatus,payStatus)
- .eq(ScenePro::getIsUpgrade,0)
- .in(ScenePro::getId,lockedIds);
- this.update(updateWrapper);
- LambdaUpdateWrapper<ScenePlus> updatePlusWrapper = new LambdaUpdateWrapper<>();
- updatePlusWrapper.set(ScenePlus::getPayStatus,payStatus)
- .in(ScenePlus::getId,lockedIds);
- scenePlusService.update(updatePlusWrapper);
- this.updateOssStatus(lockedIds,payStatus);
- }
- /**
- * 修改oss status.json中 payStatus
- */
- private void updateOssStatus(List<Long> lockedIds, Integer payStatus) {
- LambdaQueryWrapper<ScenePro> proWr = new LambdaQueryWrapper<>();
- proWr.eq(ScenePro::getIsUpgrade,0);
- proWr.in(ScenePro::getId,lockedIds);
- List<ScenePro> proList = this.list(proWr);
- LambdaQueryWrapper<ScenePlus> pluWr = new LambdaQueryWrapper<>();
- pluWr.in(ScenePlus::getId,lockedIds);
- List<ScenePlus> plusList = scenePlusService.list(pluWr);
- for (ScenePro scenePro : proList) {
- this.updateOssStatus(String.format(OssPath.v3_statusPath,scenePro.getNum()),payStatus);
- }
- for (ScenePlus scenePlus : plusList) {
- this.updateOssStatus(String.format(OssPath.v4_statusPath,scenePlus.getNum()),payStatus);
- }
- }
- /**
- * 从oss中获取文件,并重写,上传替换
- */
- private void updateOssStatus(String path,Integer payStatus) {
- try {
- if(!fYunFileService.fileExist(path)){
- return;
- }
- String data = fYunFileService.getFileContent(path);
- if(StringUtils.isBlank(data)){
- return;
- }
- JSONObject jsonObject = JSONObject.parseObject(data);
- jsonObject.put("payStatus",payStatus);
- String json = JSONUtil.toJsonStr(jsonObject);
- FileUtils.writeFile(OssPath.localStatusPath ,json);
- log.info("updateOssStatus--localPath:{},ossPath:{}",OssPath.localStatusPath,path);
- fYunFileService.uploadFile(OssPath.localStatusPath,path);
- }catch (Exception e){
- e.printStackTrace();
- }finally {
- FileUtil.del(OssPath.localStatusPath);
- }
- }
- @Override
- public List<ScenePro> getListByCameraId(Long cameraId) {
- LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(ScenePro::getCameraId,cameraId)
- .eq(ScenePro::getIsUpgrade,0);
- return this.list(wrapper);
- }
- @Override
- public void bindOrUnCamera(List<Long> cameraIds, Long userId) {
- if(cameraIds.size() >0){
- LambdaUpdateWrapper<ScenePro> wrapper = new LambdaUpdateWrapper<>();
- wrapper.in(ScenePro::getCameraId,cameraIds)
- .eq(ScenePro::getIsUpgrade,0)
- .set(ScenePro::getUserId,userId);
- this.update(wrapper);
- }
- }
- @Override
- public List<ScenePro> getListByCameraIds(List<Long> cameraIds) {
- LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
- wrapper.in(ScenePro::getCameraId,cameraIds)
- .eq(ScenePro::getIsUpgrade,0);
- return this.list(wrapper);
- }
- @Override
- public List<ScenePro> getListByNums(List<String> numList) {
- LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
- wrapper.in(ScenePro::getNum,numList)
- .eq(ScenePro::getIsUpgrade,0);
- return this.list(wrapper);
- }
- @Override
- public Long getCountByUserId(Long userId, List<?> resourceList) {
- LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(ScenePro::getUserId,userId);
- wrapper.eq(ScenePro::getIsUpgrade,0);
- wrapper.in(ScenePro::getSceneSource,resourceList);
- return this.count(wrapper);
- }
- @Override
- public Long getCountByUserId(Long id, Integer cameraType) {
- return this.getBaseMapper().getCountByUserId(id,cameraType);
- }
- @Override
- public void deleteByIds(List<Long> sceneIds) {
- LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
- wrapper.in(ScenePro::getId,sceneIds)
- .eq(ScenePro::getIsUpgrade,0);
- List<ScenePro> proList = this.list(wrapper);
- LambdaQueryWrapper<ScenePlus> plusWr = new LambdaQueryWrapper<>();
- plusWr.in(ScenePlus::getId,sceneIds);
- List<ScenePlus> plusList = scenePlusService.list(plusWr);
- this.deleteByList(proList,plusList);
- }
- @Override
- public Page<SceneVo> pageListAndFolder(Page<Object> page, SceneParam param) {
- return getBaseMapper().pageListAndFolder(new Page<>(param.getPageNum(),param.getPageSize()),param);
- }
- @Override
- public Object getScenes(String username, RequestScene param) {
- User user = userService.getByUserName(username);
- log.info("搜索条件是:"+ param.getSearchKey());
- //type为12表示一键换装的请求,不查询相机数据
- if(StringUtils.isNotEmpty(param.getSearchKey()) && !"11".equals(param.getType())){
- List<Long> userIds = userService.getLikeUserName(param.getSearchKey());
- if(userIds.size() > 0){
- List<String> cooperationList = sceneCooperationService.getNumByUserIds(userIds);
- param.setNumList(cooperationList);
- }
- }
- param.setUserId(user.getId());
- Page<SceneVo> sceneList = sceneService.getSceneList(param);
- for (SceneVo record : sceneList.getRecords()) {
- record.setUserName(username);
- SceneCooperation sceneCooperationEntity = sceneCooperationService.getByNum(record.getNum());
- if(sceneCooperationEntity != null && sceneCooperationEntity.getUserId()!= null){
- User user1 = userService.getById(sceneCooperationEntity.getUserId());
- if(user1 != null){
- record.setCooperationUserId(String.valueOf(sceneCooperationEntity.getUserId()));
- record.setCooperationUserName(user1.getUserName());
- }
- }
- }
- return PageInfo.PageInfo(sceneList);
- }
- @Override
- public JSONObject newList(SceneParam param, String username) {
- param.setSourceList(getSceneSource(param.getSceneSource()));
- if(StringUtils.isNotBlank(username)){
- User user = userService.getByUserName(username);
- param.setUserId(user.getId());
- }
- Page<SceneVo> sceneVoPage = getBaseMapper().pageListAndFolder(new Page<>(param.getPageNum(),param.getPageSize()),param);
- List<SceneVo> folderList = sceneVoPage.getRecords().parallelStream().filter(entity -> entity.getIsFolder() == 1).collect(Collectors.toList());
- Long totalSceneNum = 0L;
- if(folderList.size() >0){
- List<Long> folderIds = folderList.parallelStream().map(SceneVo::getId).collect(Collectors.toList());
- List<Folder> allFolderIds = folderService.getAllFolderIds(folderIds);
- HashMap<Long,Long> map = folderSceneService.getGroupByFolderIds(allFolderIds);
- for (SceneVo vo : sceneVoPage.getRecords()) {
- if(vo.getIsFolder() == 1 && vo.getType()!= null && vo.getType()!= 3){
- Long sceneNum = map.get(vo.getId()) == null ? 0L : map.get(vo.getId());
- vo.setSceneNum(sceneNum);
- vo.setCreateTimeStr(vo.getCreateTime());
- }else if(vo.getIsFolder() == 1 && vo.getType()!= null && vo.getType() == 3){
- if(param.getUserId()!= null){
- Integer count = sceneService.getCountByUserId(param.getUserId());
- vo.setSceneNum(Long.valueOf(count));
- }
- }
- }
- }
- //设置协作者信息
- if(sceneVoPage.getRecords().size() >0){
- List<String> numList = sceneVoPage.getRecords().parallelStream().map(SceneVo::getNum).collect(Collectors.toList());
- HashMap<String,User> cooMap = sceneCooperationService.getByNumList(numList);
- for (SceneVo vo : sceneVoPage.getRecords()) {
- if (StringUtils.isNotBlank(vo.getNum())) {
- User userVo = cooMap.get(vo.getNum());
- if (userVo != null) {
- vo.setCooperationUserId(userVo.getId().toString());
- vo.setCooperationUserName(userVo.getUserName());
- }
- }
- }
- }
- List<SceneVo> sceneList = sceneVoPage.getRecords().parallelStream().filter(entity -> entity.getIsFolder() == 0)
- .peek(vo->{
- if (ObjectUtils.isEmpty(vo.getStatus())) {
- return;
- }
- if (vo.getStatus().equals(500)) { //500状态为数据库中手动修改值,当场景本身异常,算法,算不了
- vo.setStatus(-1);
- }
- if (vo.getStatus().equals(-1)) { //计算失败,钉钉通知之后,判定是否重算,还是修改为 500
- vo.setStatus(0);
- }
- }).collect(Collectors.toList());
- if(sceneList.size() >0){
- folderList.addAll(sceneList);
- }
- sceneVoPage.setRecords(folderList);
- if(param.getFolderId() == null && param.getIsObj() == null ){
- List<String> sourceList = param.getSourceList();
- if(param.getUserId()!= null){
- totalSceneNum = this.getCountByUserId(param.getUserId(),sourceList);
- totalSceneNum += scenePlusService.getCountByUserId(param.getUserId(),sourceList);
- totalSceneNum += sceneService.getCountByUserId(param.getUserId());
- }
- }else if(param.getFolderId() != null ){
- totalSceneNum = folderSceneService.getCountByFolderAndSon(param.getFolderId());
- }else if(param.getIsObj() != null && param.getIsObj() ==1){
- if(param.getUserId()!= null){
- totalSceneNum = this.getCountByLaserAndIsObj(param.getUserId());
- }
- }
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("pageInfo",PageInfo.PageInfo(sceneVoPage));
- jsonObject.put("sceneNum",totalSceneNum);
- return jsonObject;
- }
- private Long getCountByLaserAndIsObj(Long userId) {
- Long proCount = 0L;
- Long plusCount = 0L;
- LambdaQueryWrapper<ScenePro> proWr = new LambdaQueryWrapper<>();
- proWr.eq(ScenePro::getUserId,userId);
- proWr.eq(ScenePro::getSceneSource,4);
- proWr.eq(ScenePro::getIsObj,1);
- proWr.eq(ScenePro::getIsUpgrade,0);
- proCount = this.count(proWr);
- LambdaQueryWrapper<ScenePlus> plusWr = new LambdaQueryWrapper<>();
- plusWr.eq(ScenePlus::getUserId,userId);
- plusWr.eq(ScenePlus::getSceneSource,4);
- List<ScenePlus> list = scenePlusService.list(plusWr);
- if(list.size() >0){
- List<Long> plusIds = list.stream().map(ScenePlus::getId).collect(Collectors.toList());
- LambdaQueryWrapper<ScenePlusExt> extWr = new LambdaQueryWrapper<>();
- extWr.in(ScenePlusExt::getPlusId,plusIds);
- extWr.eq(ScenePlusExt::getIsObj,1);
- plusCount = scenePlusExtService.count(extWr);
- }
- return proCount +plusCount;
- }
- public List<String> getSceneSource(String sceneSource){
- List<String> sceneSourceList ;
- if(StringUtils.isNotBlank(sceneSource)){
- switch (sceneSource){
- case "1" : sceneSourceList = Arrays.asList("1","2","12","13","14"); break; //四维看看
- case "3" : sceneSourceList = Collections.singletonList("3"); break;//四维看见
- case "4" : sceneSourceList = Collections.singletonList("4"); break;//深时场景
- default:
- if(sceneSource.contains(",")){
- sceneSource = sceneSource + ",12,13,14";
- sceneSourceList = Arrays.asList(sceneSource.split(","));
- break;
- }
- sceneSourceList = Collections.singletonList(sceneSource);break;
- }
- return sceneSourceList;
- }
- return Arrays.asList("0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15");
- }
- @Override
- public void copyScene(String sceneNum,String userName) throws Exception {
- if(StringUtils.isEmpty(sceneNum)){
- throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- 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();
- Long userId = scenePro == null ? scenePlus.getUserId() :scenePro.getUserId();
- // 判断是否有绑定会员权益
- Long count = userIncrementService.getValidCountByCameraId(cameraId);
- if(count <= 0){
- throw new BusinessException(LoginConstant.FAILURE_CODE_3030, LoginConstant.FAILURE_MSG_3030);
- }
- if(userId == null){
- throw new BusinessException(SceneConstant.FAILURE_CODE_5013, SceneConstant.FAILURE_MSG_5013);
- }
- //只能复制自己的场景
- User user = userService.getByUserName(userName);
- if(user == null || !user.getId().equals(userId) ){
- throw new BusinessException(SceneConstant.FAILURE_CODE_5013, SceneConstant.FAILURE_MSG_5013);
- }
- this.copySceneNoCheck(sceneNum);
- }
- @Override
- public void copySceneNoCheck(String sceneNum) throws Exception {
- ScenePro scenePro = this.getByNum(sceneNum);
- ScenePlus scenePlus = scenePlusService.getByNum(sceneNum);
- Long cameraId = scenePro == null ? scenePlus.getCameraId() : scenePro.getCameraId();
- CameraDetail detailEntity = cameraDetailService.getByCameraId(cameraId);
- if(detailEntity == null){
- throw new BusinessException(CameraConstant.FAILURE_CODE_6029, CameraConstant.FAILURE_MSG_6029);
- }
- String newNum = scene3dNumService.generateSceneNum(detailEntity.getType());
- String title = scenePro == null ? scenePlus.getTitle() : scenePro.getSceneName();
- String newTitle = title.concat("(copy)");
- Long sceneId = scenePro == null ? scenePlus.getId() :scenePro.getId();
- Long newSceneId = null;
- FolderScene folderScene = folderSceneService.getByType(sceneId, null);
- String time = DateUtil.date2String(new Date(),DateUtil.YYYYMMDDHHMMSSSSS_DATA_FORMAT);
- if(scenePro !=null){ //v3场景复制
- log.info("场景复制--V3--OldNum:{},oldTitle:{},newNum:{},newTitle:{}",
- scenePro.getNum(),scenePro.getSceneName(),newNum,newTitle);
- scenePro.setSceneName(newTitle);
- newSceneId = this.copyV3Scene(scenePro, newNum, detailEntity,time);
- }
- if(scenePlus != null){ //v4场景复制
- log.info("场景复制--V4--OldNum:{},oldTitle:{},newNum:{},newTitle:{}",
- scenePlus.getNum(),scenePlus.getTitle(),newNum,newTitle);
- scenePlus.setTitle(newTitle);
- newSceneId = scenePlusService.copyV4Scene(scenePlus,newNum,detailEntity,time);
- }
- log.info("场景复制--完成--sceneId:{}",newSceneId);
- if(newSceneId != null && folderScene!= null){
- folderScene.setId(null);
- folderScene.setSceneId(newSceneId);
- folderSceneService.save(folderScene);
- }
- }
- @Override
- public ScenePro getByNum(String sceneNum) {
- LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(ScenePro::getNum,sceneNum);
- wrapper.eq(ScenePro::getIsUpgrade,0);
- List<ScenePro> list = this.list(wrapper);
- if(list!= null && list.size() >0){
- return list.get(0);
- }
- return null;
- }
- @Override
- public Long copyV3Scene(ScenePro oldScene,String newNum,CameraDetail cameraDetail,String time) throws Exception {
- SceneProEdit oldEditScene = sceneProEditService.getByProId(oldScene.getId());
- String oldNum = oldScene.getNum();
- //复制数据库数据
- oldScene.setId(null);
- oldScene.setStatus(0);
- oldScene.setNum(newNum);
- oldScene.setWebSite(oldScene.getWebSite().replace(oldNum, newNum));
- oldScene.setThumb(oldScene.getThumb().replace(oldNum, newNum));
- oldScene.setVideos(this.setVideos(oldScene.getVideos(),oldNum,newNum));
- oldScene.setViewCount(0);
- String preDataSource = oldScene.getDataSource();
- String newDataSource = this.setDataSource(preDataSource,time);
- oldScene.setDataSource(newDataSource);
- this.save(oldScene);
- if(oldScene.getSceneSource() == 4){ //深时复制
- laserService.copy(oldScene.getCameraId(),oldScene.getCreateTime(),newNum,0,null,
- oldEditScene.getSceneKey(),oldScene.getSceneName(),oldScene.getUserId(),"V3");
- }
- //更新video
- Map map = new HashMap();
- JSONObject object = new JSONObject();
- if(StringUtils.isNotEmpty(oldScene.getVideos())){
- object = JSONObject.parseObject(oldScene.getVideos());
- if(object.containsKey("upPath")){
- String upPath = object.getString("upPath");
- upPath = upPath.replace(oldNum,newNum);
- object.put("upPath",upPath);
- }
- oldScene.setVideos(object.toJSONString());
- log.info("更新 scene.json");
- map.put("videos",oldScene.getVideos());
- }
- map.put("sceneName",oldScene.getSceneName());
- map.put("webSite",oldScene.getWebSite());
- map.put("thumb",oldScene.getThumb());
- map.put("num",oldScene.getNum());
- map.put("id",oldScene.getId());
- map.put("dataSource",oldScene.getDataSource());
- //复制完成更新相机容量
- oldEditScene.setId(null);
- oldEditScene.setProId(oldScene.getId());
- oldEditScene.setScreencapVoiceSrc(oldEditScene.getScreencapVoiceSrc() == null ? null : oldEditScene.getScreencapVoiceSrc().replace(oldNum, newNum));
- oldEditScene.setScreencapVoiceSound(oldEditScene.getScreencapVoiceSound() == null ? null : oldEditScene.getScreencapVoiceSound().replace(oldNum, newNum));
- oldEditScene.setScreencapVoiceSoundsync(oldEditScene.getScreencapVoiceSoundsync() == null ? null : oldEditScene.getScreencapVoiceSoundsync().replace(oldNum, newNum));
- oldEditScene.setPlayData(oldEditScene.getPlayData() == null ? null : oldEditScene.getPlayData().replace(oldNum, newNum));
- oldEditScene.setScreencapThumb(oldEditScene.getScreencapThumb() == null ? null : oldEditScene.getScreencapThumb().replace(oldNum, newNum));
- oldEditScene.setFloorPlanPng(oldEditScene.getFloorPlanPng() == null ? null : oldEditScene.getFloorPlanPng().replace(oldNum, newNum));
- sceneProEditService.save(oldEditScene);
- this.setQrCode(oldScene.getBuildType(), oldScene.getNum());
- CompletableFuture.runAsync(() -> {
- try {
- log.info("开始复制场景-{}", new Date());
- String buildModelPath = ConstantFilePath.BUILD_MODEL_PATH;
- if(oldScene.getSceneSource().equals(4)){
- buildModelPath = ConstantFilePath.BUILD_MODEL_LASER_PATH;
- }
- this.copyFdage(preDataSource,newDataSource,buildModelPath,time);
- //oss复制计算结果资源
- downloadFromOldNumFromOss(oldNum, newNum);
- // 复制本地secen.json
- copyOldSceneLocalToNew(oldNum, newNum);
- FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + newNum + File.separator + "scene.json", map);
- //上传资源到oss
- uploadNewSceneToOss(newNum);
- FileUtils.delFolder(ConstantFilePath.SCENE_PATH + "images/images" + newNum);
- FileUtils.delFolder(ConstantFilePath.SCENE_PATH + "data/data" + newNum);
- FileUtils.delFolder(ConstantFilePath.SCENE_PATH + "voice/voice" + newNum);
- FileUtils.delFolder(ConstantFilePath.SCENE_PATH + "video/video" + newNum);
- FileUtils.copyDirectiory(ConstantFilePath.SCENE_PATH +"images/images" + oldNum,ConstantFilePath.SCENE_PATH +"images/images" + newNum);
- FileUtils.copyDirectiory(ConstantFilePath.SCENE_PATH +"data/data" + oldNum,ConstantFilePath.SCENE_PATH +"data/data" + newNum);
- FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + newNum + File.separator + "scene.json", map);
- reloadFile(ConstantFilePath.SCENE_PATH + "data/data" + newNum + "/link-scene.json",oldNum, newNum);
- reloadFile(ConstantFilePath.SCENE_PATH + "data/data" + newNum + "/hot.json",oldNum, newNum);
- FileUtils.copyDirectiory(ConstantFilePath.SCENE_PATH +"voice/voice" + oldNum,ConstantFilePath.SCENE_PATH +"voice/voice" + newNum);
- FileUtils.copyDirectiory(ConstantFilePath.SCENE_PATH +"video/video" + oldNum,ConstantFilePath.SCENE_PATH +"video/video" + newNum);
- oldScene.setStatus(-2);
- this.updateById(oldScene);
- log.info("复制场景结束-{}", new Date());
- if(oldScene.getSceneSource() == 4){ //深时复制
- String laserPath = laserService.copyDataSource(preDataSource,oldScene.getDataSource());
- laserService.copy(oldScene.getCameraId(),oldScene.getCreateTime(),newNum,2,laserPath,
- oldEditScene.getSceneKey(),oldScene.getSceneName(),oldScene.getUserId(),"V3");
- }
- sceneCopyLogService.saveByNum(oldNum,newNum,oldScene.getUserId());
- } catch (Exception e) {
- this.removeById(oldScene.getId());
- log.error("复制场景异常", e);
- }
- });
- return oldScene.getId();
- }
- /**
- * 从旧场景下载资源
- * @param sceneNum
- * @param newNum
- * @throws Exception
- */
- private void downloadFromOldNumFromOss(String sceneNum, String newNum) {
- ShellUtil.yunDownload("images/images" + sceneNum + "/", ConstantFilePath.SCENE_PATH + "images/images" + newNum);
- ShellUtil.yunDownload("data/data" + sceneNum + "/", ConstantFilePath.SCENE_PATH + "data/data" + newNum);
- ShellUtil.yunDownload("voice/voice" + sceneNum + "/", ConstantFilePath.SCENE_PATH + "voice/voice" + newNum);
- ShellUtil.yunDownload("video/video" + sceneNum + "/", ConstantFilePath.SCENE_PATH + "video/video" + newNum);
- }
- /**
- * 从本地旧场景拷贝资源到新场景
- * @param sceneNum
- * @param newNum
- */
- private void copyOldSceneLocalToNew(String sceneNum, String newNum) throws Exception {
- FileUtils.copyFolderAllFiles(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + "/",
- ConstantFilePath.SCENE_PATH + "data/data" + newNum + "/", true);
- reloadFile(ConstantFilePath.SCENE_PATH + "data/data" + newNum + "/link-scene.json",sceneNum, newNum);
- reloadFile(ConstantFilePath.SCENE_PATH + "data/data" + newNum + "/hot.json",sceneNum, newNum);
- }
- public void copyFdage(String oldDataSource,String newDataSource,String buildModelPath,String time) throws Exception {
- ShellUtil.yunDownload(ConstantFilePath.OSS_PREFIX + oldDataSource.replace(buildModelPath, "")+"/", newDataSource);
- // 修改data.fdage
- String data = FileUtils.readFile(newDataSource + "/data.fdage");
- JSONObject jsonObject = JSONObject.parseObject(data);
- if(ObjectUtils.isEmpty(jsonObject)){
- log.error("data.fdage文件不存在");
- throw new BusinessException(-1,"拷贝场景出错,data.fdage文件不存在");
- }
- jsonObject.put("uuidtime",time);
- FileUtils.writeFile(newDataSource + "/data.fdage", jsonObject.toJSONString());
- ShellUtil.yunUpload(newDataSource, ConstantFilePath.OSS_PREFIX + newDataSource.replace(buildModelPath, ""));
- // 复制计算结果
- ShellUtil.yunDownload(ConstantFilePath.OSS_PREFIX + oldDataSource.concat("_results/").replace(buildModelPath, ""), newDataSource.concat("_results"));
- if(new File(newDataSource.concat("_results")).exists()){
- ShellUtil.yunUpload(newDataSource.concat("_results"), ConstantFilePath.OSS_PREFIX + newDataSource.concat("_results").replace(buildModelPath, ""));
- FileUtils.delAllFile(newDataSource.concat("_results"));
- }
- FileUtils.delAllFile(newDataSource);
- try {
- FileUtils.copyFolderAllFiles(oldDataSource+"/",newDataSource+"/", true);
- }catch (Exception e){
- log.error("dataSource复制失败,{}不存在",oldDataSource);
- }
- }
- @Override
- public String setDataSource(String preDataSource,String time) throws Exception {
- SnowflakeIdGenerator snowflakeIdGenerator = new SnowflakeIdGenerator(0,1);
- String[] datasource = preDataSource.split("/");
- datasource[4] = snowflakeIdGenerator.nextId()+"";
- datasource[5] = datasource[5].split("_")[0] + "_" + time;
- return Arrays.stream(datasource).collect(Collectors.joining("/"));
- }
- @Override
- public String setVideos(String videos,String oldNum,String newNum) {
- JSONObject object = new JSONObject();
- if(StringUtils.isNotEmpty(videos)){
- object = JSONObject.parseObject(videos);
- if(object.containsKey("upPath")){
- String upPath = object.getString("upPath");
- upPath = upPath.replace(oldNum,newNum);
- object.put("upPath",upPath);
- }
- log.info("更新 scene.json");
- }
- return object.toJSONString();
- }
- private void reloadFile(String filePath,String sceneNum, String newNum) throws Exception {
- // 修改link-scene.json
- String content = FileUtils.readFile(filePath);
- if (!ObjectUtils.isEmpty(content)) {
- content = content.replaceAll(sceneNum, newNum);
- FileUtils.writeFile(filePath,content);
- }
- }
- /**
- * 上传新场景资源到oss
- * @param newNum
- */
- private void uploadNewSceneToOss(String newNum) {
- ShellUtil.yunUpload("/mnt/4Dkankan/scene/images/images" + newNum, "images/images" + newNum);
- ShellUtil.yunUpload("/mnt/4Dkankan/scene/data/data" + newNum, "data/data" + newNum);
- ShellUtil.yunUpload("/mnt/4Dkankan/scene/voice/voice" + newNum, "voice/voice" + newNum);
- ShellUtil.yunUpload("/mnt/4Dkankan/scene/video/video" + newNum, "video/video" + newNum);
- }
- @Override
- public void delete(String sceneNum) {
- if(StringUtils.isEmpty(sceneNum)){
- throw new BusinessException(LoginConstant.FAILURE_CODE_3001,LoginConstant.FAILURE_MSG_3001);
- }
- String[] nums = sceneNum.split(",");
- List<String> numList = Arrays.asList(nums);
- List<ScenePro> proList = this.getListByNums(numList);
- List<ScenePlus> plusList = scenePlusService.getListByNums(numList);
- this.deleteByList(proList,plusList);
- }
- @Override
- public void deleteByList(List<ScenePro> proList,List<ScenePlus> plusList) {
- HashMap<Long ,Long >cameraMap = new HashMap<>();
- if(proList.size() >0){
- for (ScenePro scenePro : proList) {
- cameraMap.merge(scenePro.getCameraId(), scenePro.getSpace(), Long::sum);
- }
- List<Long> proIds = proList.parallelStream().map(ScenePro::getId).collect(Collectors.toList());
- this.removeByIds(proIds);
- }
- if(plusList.size() >0){
- List<Long> plusIds = plusList.parallelStream().map(ScenePlus::getId).collect(Collectors.toList());
- HashMap<Long, ScenePlusExt> plusMap = scenePlusExtService.getByPlusIds(plusIds);
- for (ScenePlus scenePlus : plusList) {
- if(scenePlus.getCameraId()!= null && plusMap.get(scenePlus.getId())!=null){
- cameraMap.merge(scenePlus.getCameraId(), plusMap.get(scenePlus.getId()).getSpace(), Long::sum);
- }
- }
- scenePlusService.removeByIds(plusIds);
- scenePlusExtService.removeByPlusIds(plusIds);
- }
- //恢复相机使用容量
- if(cameraMap.size() >0){
- cameraDetailService.addUsedSpace(cameraMap);
- }
- }
- @Override
- public ScenePro getByUnicode(String unicode) {
- LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
- wrapper.like(ScenePro::getDataSource,unicode);
- wrapper.eq(ScenePro::getIsUpgrade,0);
- wrapper.orderByDesc(ScenePro::getCreateTime);
- List<ScenePro> list = this.list(wrapper);
- if(list !=null && list.size() >0){
- return list.get(0);
- }
- return null;
- }
- @Override
- public SceneInfoVo getInfo(String num) {
- if(StringUtils.isEmpty(num)){
- throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- ScenePro scenePro = this.getByNum(num);
- ScenePlus scenePlus = scenePlusService.getByNum(num);
- if(scenePro == null && scenePlus == null){
- throw new BusinessException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
- }
- if(scenePro!=null && scenePro.getStatus() != 1 && scenePro.getStatus() != -2){
- throw new BusinessException(SceneConstant.FAILURE_CODE_5033, SceneConstant.FAILURE_MSG_5033);
- }
- if(scenePlus!=null && scenePlus.getSceneStatus() != 1 && scenePlus.getSceneStatus() != -2){
- throw new BusinessException(SceneConstant.FAILURE_CODE_5033, SceneConstant.FAILURE_MSG_5033);
- }
- if(scenePro!=null && scenePro.getPayStatus() != 1){
- throw new BusinessException(SceneConstant.FAILURE_CODE_5034, SceneConstant.FAILURE_MSG_5034);
- }
- if(scenePlus!=null && scenePlus.getPayStatus() != 1){
- throw new BusinessException(SceneConstant.FAILURE_CODE_5034, SceneConstant.FAILURE_MSG_5034);
- }
- SceneInfoVo infoVo = new SceneInfoVo();
- if(scenePro!=null){
- SceneProEdit sceneProEdit = sceneProEditService.getByProId(scenePro.getId());
- if(sceneProEdit !=null){
- BeanUtils.copyProperties(sceneProEdit, infoVo);
- }
- BeanUtils.copyProperties(scenePro,infoVo);
- if(StringUtils.isNotEmpty(scenePro.getGps())){
- infoVo.setGps(JSONObject.parseObject(scenePro.getGps()).toJSONString());
- }
- infoVo.setSceneKey("");
- infoVo.setCreateDate(DateUserUtil.getDate(scenePro.getCreateTime()).getTime());
- }else {
- SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
- ScenePlusExt scenePlusExt = scenePlusExtService.getByPlusId(scenePlus.getId());
- if(sceneEditInfo != null){
- BeanUtils.copyProperties(sceneEditInfo,infoVo);
- }
- if(scenePlusExt !=null){
- BeanUtils.copyProperties(scenePlusExt,infoVo);
- }
- BeanUtils.copyProperties(scenePlus,infoVo);
- infoVo.setSceneName(scenePlus.getTitle());
- infoVo.setStatus(scenePlus.getSceneStatus());
- }
- if(StringUtils.isNotEmpty(infoVo.getEntry())){
- infoVo.setEntry(JSONObject.parseObject(infoVo.getEntry()).toJSONString());
- }
- if(StringUtils.isEmpty(infoVo.getSceneKey())){
- infoVo.setIsPublic(0);
- }else {
- infoVo.setIsPublic(1);
- }
- //查询是否有随心装场景
- if(num.contains("vr-")){
- infoVo.setVrNum(null);
- infoVo.setVideosUser(null);
- infoVo.setBgMusicName(null);
- infoVo.setBgMusic(null);
- }
- infoVo.setSceneVer(innerService.getSceneNumVersion(num));
- infoVo.setVersion(infoVo.getSceneVer());
- this.updateViewCount(num);
- return infoVo;
- }
- @Override
- public void updateViewCount(String num) {
- String redisKey = RedisKey.SCENE_VISIT_CNT;
- if(!redisUtil.hHasKey(redisKey,num)){
- Integer count = 0;
- ScenePro pro = this.getByNum(num);
- if(pro !=null){
- count = pro.getViewCount() == null ? 0 : pro.getViewCount();
- }else {
- ScenePlus plus = scenePlusService.getByNum(num);
- if(plus !=null){
- ScenePlusExt scenePlusExt = scenePlusExtService.getByPlusId(plus.getId());
- if(scenePlusExt != null){
- count = scenePlusExt.getViewCount() == null ? 0 :scenePlusExt.getViewCount();
- }
- }
- }
- redisUtil.hset(redisKey,num,String.valueOf(count));
- }
- redisUtil.hincr(redisKey,num,1);
- }
- @Override
- public void updateDbViewCount(String num, String count) {
- LambdaUpdateWrapper<ScenePro> wrapper = new LambdaUpdateWrapper<>();
- wrapper.eq(ScenePro::getNum,num);
- wrapper.set(ScenePro::getViewCount,count);
- this.update(wrapper);
- ScenePlus plus = scenePlusService.getByNum(num);
- if(plus !=null){
- LambdaUpdateWrapper<ScenePlusExt> exWr = new LambdaUpdateWrapper<>();
- exWr.eq(ScenePlusExt::getPlusId,plus.getId())
- .set(ScenePlusExt::getViewCount,count);
- scenePlusExtService.update(exWr);
- }
- }
- @Override
- public ScenePro findByFileId(String fileId) {
- LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
- wrapper.like(ScenePro::getDataSource,fileId);
- List<ScenePro> list = this.list(wrapper);
- if(list !=null && list.size() >0){
- return list.get(0);
- }
- return null;
- }
- @Override
- public void setQrCode(String buildType,String num) throws Exception {
- String basePath = mainUrl;
- if("V2".equals(buildType)){
- basePath += sceneProUrl;
- }
- if("V3".equals(buildType)){
- basePath += sceneProNewUrl;
- }
- MatrixToImageWriterUtil.createQRCode(basePath + num, ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+num+".png", false,null);
- MatrixToImageWriterUtil.createQRCode(basePath + num + "&lang=en", ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+num+"_en.png", false,null);
- }
- @Override
- public void generateObjFile(String num) {
- LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(ScenePro::getNum,num).eq(ScenePro::getRecStatus,"A");
- ScenePro sceneProEntity = this.getOne(wrapper);
- if(ObjectUtils.isEmpty(sceneProEntity)){
- generatePlusObjFile(num);
- return;
- }
- if(sceneProEntity.getSceneSource() != 4){
- throw new BusinessException(LoginConstant.FAILURE_CODE_3003, "只能操作激光场景");
- }
- // 拷贝文件
- String path = sceneProEntity.getDataSource();
- if (!new File(path + "/caches/reconstruction/final.bin").exists()
- || !new File(path + "/caches/reconstruction/chunk.json").exists()
- || !new File(path + "/caches/images").exists()
- || !new File(path + "/caches/depthmap").exists()
- || !new File(path + "/caches/depthmap_csc").exists()
- || !new File(path + "/caches/panorama.json").exists()
- || !new File(path + "/results/laserData/laser.ply").exists()) {
- log.error("生成obj缺少必要文件,生成失败!");
- throw new BusinessException(SceneConstant.FAILURE_CODE_5038, SceneConstant.FAILURE_MSG_5038);
- }
- // 获取最新的场景名称
- JSONObject sceneInfo = fdkkLaserService.getSceneByNum(sceneProEntity.getNum());
- LambdaUpdateWrapper<ScenePro> updateWrapper = new LambdaUpdateWrapper<>();
- updateWrapper
- .set(ScenePro::getStatus, 0)
- .set(ScenePro::getIsObj, 1)
- .set(ScenePro::getIsUpgrade, 2) // 升级中
- .set(ScenePro::getSceneName, sceneInfo.getString("title"))
- .eq(ScenePro::getNum, sceneProEntity.getNum());
- this.update(updateWrapper);
- //同步到scenePlus、scenePlus
- //同步到scenePlus、scenePlus
- ScenePlus scenePlus = scenePlusService.getByNum(num);
- if(Objects.nonNull(scenePlus)){
- sceneUpgradeMapper.deleteScenePlus(num);
- sceneUpgradeMapper.deleteScenePlusExt(scenePlus.getId());
- }
- sceneUpgradeMapper.transferScenePlus(num);
- scenePlus = scenePlusService.getByNum(num);
- String sceneKind = sceneProEntity.getSceneScheme() == 3 ? SceneKind.FACE.code():SceneKind.TILES.code();
- sceneUpgradeMapper.transferScenePlusExt(num, scenePlus.getId(), sceneKind);
- log.info("开始发送激光场景生成obj mq消息");
- // 发送MQ
- BuildSceneCallMessage mqMsg = new BuildSceneCallMessage();
- mqMsg.setSceneNum(sceneProEntity.getNum());
- mqMsg.setAlgorithm(sceneProEntity.getAlgorithm());
- mqMsg.setBuildType(sceneProEntity.getBuildType());
- mqMsg.setPath(sceneProEntity.getDataSource());
- mqProducer.sendByWorkQueue(queueObjModelingPre,mqMsg);
- }
- public void generatePlusObjFile(String num) {
- ScenePlus scenePlus = scenePlusService.getByNum(num);
- if(ObjectUtils.isEmpty(scenePlus)){
- throw new BusinessException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
- }
- if(scenePlus.getSceneSource() != 4){
- throw new BusinessException(LoginConstant.FAILURE_CODE_3003, "只能操作激光场景");
- }
- ScenePlusExt scenePlusExt = scenePlusExtService.getByPlusId(scenePlus.getId());
- // 拷贝文件
- String path = scenePlusExt.getDataSource();
- if (!new File(path + "/caches/reconstruction/final.bin").exists()
- || !new File(path + "/caches/reconstruction/chunk.json").exists()
- || !new File(path + "/caches/images").exists()
- || !new File(path + "/caches/depthmap").exists()
- || !new File(path + "/caches/depthmap_csc").exists()
- || !new File(path + "/caches/panorama.json").exists()
- || !new File(path + "/results/laserData/laser.ply").exists()) {
- log.error("生成obj缺少必要文件,生成失败!");
- throw new BusinessException(SceneConstant.FAILURE_CODE_5038, SceneConstant.FAILURE_MSG_5038);
- }
- // 获取最新的场景名称
- JSONObject sceneInfo = fdkkLaserService.getSceneByNum(num);
- LambdaUpdateWrapper<ScenePlus> updateWrapper = new LambdaUpdateWrapper<>();
- updateWrapper
- .set(ScenePlus::getSceneStatus, 0)
- .set(ScenePlus::getTitle, sceneInfo.getString("title"))
- .eq(ScenePlus::getNum, num);
- scenePlusService.update(updateWrapper);
- LambdaUpdateWrapper<ScenePlusExt> plusExtUpdateWrapper = new LambdaUpdateWrapper<>();
- plusExtUpdateWrapper
- .set(ScenePlusExt::getIsObj, 1)
- .eq(ScenePlusExt::getPlusId, scenePlus.getId());
- scenePlusExtService.update(plusExtUpdateWrapper);
- log.info("开始发送激光场景生成obj mq消息");
- // 发送MQ
- BuildSceneCallMessage mqMsg = new BuildSceneCallMessage();
- mqMsg.setSceneNum(num);
- mqMsg.setAlgorithm(scenePlusExt.getAlgorithm());
- mqMsg.setBuildType(scenePlusExt.getBuildType());
- mqMsg.setPath(scenePlusExt.getDataSource());
- mqProducer.sendByWorkQueue(queueObjModelingPre,mqMsg);
- }
- @Override
- public ResponseScene getSceneDetail(String sceneNum) {
- if(StringUtils.isBlank(sceneNum)){
- return null;
- }
- ResponseScene vo = new ResponseScene();
- Scene sceneEntity = sceneService.getByNum(sceneNum);
- if(sceneEntity != null){
- return getResponseScene(vo, sceneEntity);
- }
- ScenePro sceneProEntity = this.getByNum(sceneNum);
- if(sceneProEntity != null){
- SceneProEdit sceneProEditEntity = sceneProEditService.getByProId(sceneProEntity.getId());
- return getResponseProScene(vo, sceneProEntity, sceneProEditEntity);
- }
- ScenePlus scenePlus = scenePlusService.getByNum(sceneNum);
- if(scenePlus != null){
- ScenePlusExt ext = scenePlusExtService.getByPlusId(scenePlus.getId());
- SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
- return getResponseProScene(vo, scenePlus, ext,sceneEditInfo);
- }
- return vo;
- }
- private ResponseScene getResponseScene(ResponseScene vo, Scene sceneEntity) {
- if (sceneEntity != null){
- BeanUtils.copyProperties(sceneEntity, vo);
- vo.setThumbImg(sceneEntity.getThumbStatus());
- vo.setCreateTime(new DateTime(sceneEntity.getCreateTime()).toString("yyyy-MM-dd HH:mm"));
- vo.setSceneIndex(sceneEntity.getStyle());
- vo.setHasBGM(sceneEntity.getBgMusic());
- vo.setCameraType(sceneEntity.getSceneScheme());
- vo.setIsPublic(StringUtils.isEmpty(sceneEntity.getSceneKey()) ? 0 : 1);
- }
- return vo;
- }
- private ResponseScene getResponseProScene(ResponseScene vo, ScenePro sceneProEntity, SceneProEdit sceneProEditEntity) {
- if (sceneProEntity != null){
- BeanUtils.copyProperties(sceneProEditEntity, vo);
- BeanUtils.copyProperties(sceneProEntity, vo);
- vo.setCreateTime(DateUserUtil.getMDate(vo.getCreateTime()));
- vo.setCameraType(sceneProEntity.getSceneScheme());
- vo.setThumbImg(sceneProEditEntity.getThumbStatus());
- vo.setHasBGM(sceneProEditEntity.getBgMusic());
- vo.setIsPublic(StringUtils.isEmpty(sceneProEditEntity.getSceneKey()) ? 0 : 1);
- }
- return vo;
- }
- private ResponseScene getResponseProScene(ResponseScene vo, ScenePlus plus, ScenePlusExt ext,SceneEditInfo editInfo) {
- if (plus != null){
- BeanUtils.copyProperties(plus, vo);
- BeanUtils.copyProperties(ext, vo);
- BeanUtils.copyProperties(editInfo, vo);
- vo.setNum(plus.getNum());
- vo.setSceneName(plus.getTitle());
- vo.setCreateTime(DateUserUtil.getMDate(vo.getCreateTime()));
- vo.setCameraType(ext.getSceneScheme());
- vo.setThumbImg(1);
- vo.setHasBGM(editInfo.getMusic());
- vo.setIsPublic(StringUtils.isEmpty(editInfo.getScenePassword()) ? 0 : 1);
- }
- return vo;
- }
- }
|