|
|
@@ -5,25 +5,35 @@ 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.fdkankan.common.constant.ConstantFilePath;
|
|
|
+import com.fdkankan.common.constant.SceneConstant;
|
|
|
+import com.fdkankan.common.exception.BusinessException;
|
|
|
import com.fdkankan.common.response.PageInfo;
|
|
|
+import com.fdkankan.common.util.CreateObjUtil;
|
|
|
import com.fdkankan.common.util.FileUtils;
|
|
|
import com.fdkankan.common.util.JwtUtil;
|
|
|
import com.fdkankan.fyun.oss.UploadToOssUtil;
|
|
|
+import com.fdkankan.ucenter.constant.CameraConstant;
|
|
|
+import com.fdkankan.ucenter.constant.LoginConstant;
|
|
|
import com.fdkankan.ucenter.entity.*;
|
|
|
import com.fdkankan.ucenter.mapper.ISceneProMapper;
|
|
|
import com.fdkankan.ucenter.service.*;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fdkankan.ucenter.util.DateUserUtil;
|
|
|
import com.fdkankan.ucenter.vo.request.SceneParam;
|
|
|
-import com.fdkankan.ucenter.vo.response.FolderVo;
|
|
|
import com.fdkankan.ucenter.vo.response.GroupByCount;
|
|
|
import com.fdkankan.ucenter.vo.response.SceneNumVo;
|
|
|
import com.fdkankan.ucenter.vo.response.SceneVo;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.ObjectUtils;
|
|
|
|
|
|
import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -35,6 +45,7 @@ import java.util.stream.Collectors;
|
|
|
* @since 2022-07-04
|
|
|
*/
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro> implements ISceneProService {
|
|
|
|
|
|
@Autowired
|
|
|
@@ -59,6 +70,12 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
IFolderService folderService;
|
|
|
@Autowired
|
|
|
IFolderSceneService folderSceneService;
|
|
|
+ @Autowired
|
|
|
+ ISceneCopyLogService sceneCopyLogService;
|
|
|
+ @Autowired
|
|
|
+ IScene3dNumService scene3dNumService;
|
|
|
+ @Autowired
|
|
|
+ ISceneProEditService sceneProEditService;
|
|
|
|
|
|
@Override
|
|
|
public HashMap<String, SceneNumVo> findSceneNumber(String token) {
|
|
|
@@ -257,52 +274,45 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
|
|
|
wrapper.in(ScenePro::getId,sceneIds)
|
|
|
.eq(ScenePro::getIsUpgrade,0);
|
|
|
- List<ScenePro> list = this.list(wrapper);
|
|
|
- HashMap<Long ,Long >cameraMap = new HashMap<>();
|
|
|
- for (ScenePro scenePro : list) {
|
|
|
- cameraMap.merge(scenePro.getCameraId(), scenePro.getSpace(), Long::sum);
|
|
|
- }
|
|
|
+ List<ScenePro> proList = this.list(wrapper);
|
|
|
|
|
|
- LambdaQueryWrapper<ScenePlusExt> plusWr = new LambdaQueryWrapper<>();
|
|
|
- plusWr.in(ScenePlusExt::getPlusId,sceneIds);
|
|
|
- List<ScenePlusExt> list2 = scenePlusExtService.list(plusWr);
|
|
|
- HashMap<Long,ScenePlus> scenePlusHashMap = scenePlusService.getMapByIds(sceneIds);
|
|
|
+ LambdaQueryWrapper<ScenePlus> plusWr = new LambdaQueryWrapper<>();
|
|
|
+ plusWr.in(ScenePlus::getId,sceneIds);
|
|
|
+ List<ScenePlus> plusList = scenePlusService.list(plusWr);
|
|
|
|
|
|
- for (ScenePlusExt scenePlusExt : list2) {
|
|
|
- cameraMap.merge(scenePlusHashMap.get(scenePlusExt.getPlusId()).getCameraId(), scenePlusExt.getSpace(), Long::sum);
|
|
|
- }
|
|
|
- this.removeByIds(sceneIds);
|
|
|
- scenePlusService.removeByIds(sceneIds);
|
|
|
- //恢复相机使用容量
|
|
|
- cameraDetailService.addUsedSpace(cameraMap);
|
|
|
+ this.deleteByList(proList,plusList);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public PageInfo newList(SceneParam param, String username) {
|
|
|
+ public JSONObject newList(SceneParam param, String username) {
|
|
|
User user = userService.getByUserName(username);
|
|
|
param.setSourceList(getSceneSource(param.getSceneSource()));
|
|
|
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());
|
|
|
+ Integer folderNum = 0;
|
|
|
if(folderList.size() >0){
|
|
|
List<Long> folderIds = folderList.parallelStream().map(SceneVo::getId).collect(Collectors.toList());
|
|
|
List<Folder> allFolderIds = folderService.getAllFolderIds(folderIds);
|
|
|
+ folderNum = allFolderIds.size();
|
|
|
HashMap<Long,Long> map = folderSceneService.getGroupByFolderIds(allFolderIds);
|
|
|
for (SceneVo vo : sceneVoPage.getRecords()) {
|
|
|
if(vo.getIsFolder() == 1){
|
|
|
Long sceneNum = map.get(vo.getId()) == null ? 0L : map.get(vo.getId());
|
|
|
vo.setSceneNum(sceneNum );
|
|
|
- vo.setCreateTimeStr(DateUserUtil.getDayTime(vo.getCreateTime()));
|
|
|
+ vo.setCreateTimeStr(vo.getCreateTime());
|
|
|
}
|
|
|
- vo.setCreateTime(vo.getCreateTime());
|
|
|
}
|
|
|
Collections.reverse(folderList);
|
|
|
List<SceneVo> records = sceneVoPage.getRecords();
|
|
|
List<SceneVo> sceneList = records.parallelStream().filter(entity -> entity.getIsFolder() == 0).collect(Collectors.toList());
|
|
|
folderList.addAll(sceneList);
|
|
|
+ sceneVoPage.setRecords(folderList);
|
|
|
}
|
|
|
- sceneVoPage.setRecords(folderList);
|
|
|
- return PageInfo.PageInfo(sceneVoPage);
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("pageInfo",PageInfo.PageInfo(sceneVoPage));
|
|
|
+ jsonObject.put("sceneNum",sceneVoPage.getTotal() - folderNum);
|
|
|
+ return jsonObject;
|
|
|
}
|
|
|
|
|
|
public List<String> getSceneSource(String sceneSource){
|
|
|
@@ -320,4 +330,228 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
}
|
|
|
return sceneSourceList;
|
|
|
}
|
|
|
+
|
|
|
+ @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);
|
|
|
+ }
|
|
|
+ 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());
|
|
|
+ if(scenePro !=null){ //v3场景复制
|
|
|
+ this.copyV3Scene(scenePro,newNum,detailEntity);
|
|
|
+ }
|
|
|
+ if(scenePlus != null){ //v4场景复制
|
|
|
+ scenePlusService.copyV4Scene(scenePlus,newNum,detailEntity);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @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 void copyV3Scene(ScenePro oldScene,String newNum,CameraDetail cameraDetail) {
|
|
|
+ SceneProEdit oldEditScene = sceneProEditService.getByProId(oldScene.getId());
|
|
|
+
|
|
|
+ String oldNum = oldScene.getNum();
|
|
|
+ //复制数据库数据
|
|
|
+ oldScene.setId(null);
|
|
|
+ oldScene.setNum(newNum);
|
|
|
+ oldScene.setSceneName(oldScene.getSceneName().concat("(copy)"));
|
|
|
+ oldScene.setWebSite(oldScene.getWebSite().replace(oldScene.getNum(), newNum));
|
|
|
+ oldScene.setThumb(oldScene.getThumb().replace(oldScene.getNum(), newNum));
|
|
|
+ oldScene.setVideos(oldScene.getVideos().replace(oldNum,newNum));
|
|
|
+ //更新video
|
|
|
+ this.save(oldScene);
|
|
|
+
|
|
|
+ sceneCopyLogService.saveByNum(oldNum,newNum,oldScene.getUserId());
|
|
|
+ //复制完成更新相机容量
|
|
|
+ cameraDetail.setUsedSpace(cameraDetail.getUsedSpace() + oldScene.getSpace());
|
|
|
+ cameraDetailService.updateById(cameraDetail);
|
|
|
+
|
|
|
+ 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);
|
|
|
+
|
|
|
+ CompletableFuture.runAsync(() -> {
|
|
|
+ try {
|
|
|
+ log.info("开始复制场景-{}", new Date());
|
|
|
+
|
|
|
+ //oss复制源文件
|
|
|
+ String buildModelPath = ConstantFilePath.BUILD_MODEL_PATH;
|
|
|
+ if(oldScene.getSceneSource().equals(4)){
|
|
|
+ buildModelPath = ConstantFilePath.BUILD_MODEL_LASER_PATH;
|
|
|
+ }
|
|
|
+ CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + oldScene.getDataSource().replace(buildModelPath, "")+"/", oldScene.getDataSource());
|
|
|
+
|
|
|
+ List<String> urlList = new ArrayList<>();
|
|
|
+ FileUtils.readfilePath(oldScene.getDataSource(), urlList);
|
|
|
+ Map<String,String> fileMap = new HashMap<>();
|
|
|
+ for(String url : urlList){
|
|
|
+ fileMap.put(url, ConstantFilePath.OSS_PREFIX + url.replace(buildModelPath, ""));
|
|
|
+ }
|
|
|
+ uploadToOssUtil.uploadMulFiles(fileMap);
|
|
|
+
|
|
|
+ //oss复制计算结果资源
|
|
|
+ downloadFromoldNumFromOss(oldNum, newNum);
|
|
|
+
|
|
|
+ // 复制本地secen.json
|
|
|
+ copyOldSceneLocalToNew(oldNum, newNum);
|
|
|
+ updateSceneJson("v3",oldScene.getVideos(),newNum,oldScene.getSceneName(),oldScene.getWebSite(),oldScene.getThumb(),oldScene.getId());
|
|
|
+ //上传资源到oss
|
|
|
+ uploadNewSceneToOss(newNum);
|
|
|
+ log.info("复制场景结束-{}", new Date());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("复制场景异常", e);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 从旧场景下载资源
|
|
|
+ * @param sceneNum
|
|
|
+ * @param newNum
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ private void downloadFromoldNumFromOss(String sceneNum, String newNum) throws Exception {
|
|
|
+ CreateObjUtil.ossUtilCp("images/images" + sceneNum + "/", ConstantFilePath.SCENE_PATH + "images/images" + newNum);
|
|
|
+ CreateObjUtil.ossUtilCp("data/data" + sceneNum + "/", ConstantFilePath.SCENE_PATH + "data/data" + newNum);
|
|
|
+ CreateObjUtil.ossUtilCp("voice/voice" + sceneNum + "/", ConstantFilePath.SCENE_PATH + "voice/voice" + newNum);
|
|
|
+ CreateObjUtil.ossUtilCp("video/video" + sceneNum + "/", ConstantFilePath.SCENE_PATH + "video/video" + newNum);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 从本地旧场景拷贝资源到新场景
|
|
|
+ * @param sceneNum
|
|
|
+ * @param newNum
|
|
|
+ */
|
|
|
+ private void copyOldSceneLocalToNew(String sceneNum, String newNum) throws IOException {
|
|
|
+ FileUtils.copyFolderAllFiles(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + "/",
|
|
|
+ ConstantFilePath.SCENE_PATH + "data/data" + newNum + "/", true);
|
|
|
+
|
|
|
+ // 复制本地视频
|
|
|
+ FileUtils.copyFolderAllFiles(ConstantFilePath.SCENE_PATH + "video/video" + sceneNum + "/",
|
|
|
+ ConstantFilePath.SCENE_PATH + "video/video" + newNum + "/", true);
|
|
|
+
|
|
|
+ // 复制本地二维码
|
|
|
+ FileUtils.copyFile(ConstantFilePath.SCENE_QR_CODE_PATH + sceneNum + ".png",
|
|
|
+ ConstantFilePath.SCENE_QR_CODE_PATH + newNum + ".png", true);
|
|
|
+
|
|
|
+ // 复制本地二维码
|
|
|
+ FileUtils.copyFile(ConstantFilePath.SCENE_QR_CODE_PATH + sceneNum + "_en.png",
|
|
|
+ ConstantFilePath.SCENE_QR_CODE_PATH + newNum + "_en.png", true);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 上传新场景资源到oss
|
|
|
+ * @param newNum
|
|
|
+ */
|
|
|
+ private void uploadNewSceneToOss(String newNum) {
|
|
|
+ Map<String, String> map = new HashMap();
|
|
|
+ List<String> urlList = new ArrayList<>();
|
|
|
+ FileUtils.readfilePath(ConstantFilePath.SCENE_PATH + "images/images" + newNum, urlList);
|
|
|
+ FileUtils.readfilePath(ConstantFilePath.SCENE_PATH + "data/data" + newNum, urlList);
|
|
|
+ FileUtils.readfilePath(ConstantFilePath.SCENE_PATH + "voice/voice" + newNum, urlList);
|
|
|
+ FileUtils.readfilePath(ConstantFilePath.SCENE_PATH + "video/video" + newNum, urlList);
|
|
|
+ for(String url : urlList){
|
|
|
+ map.put(url, url.replace(ConstantFilePath.SCENE_PATH, ""));
|
|
|
+ }
|
|
|
+ uploadToOssUtil.uploadMulFiles(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updateSceneJson(String type,String videos,String newNum,String sceneName,String webSite,String thumb,Long id) throws Exception {
|
|
|
+ //更新video
|
|
|
+ HashMap<String,Object> map = new HashMap<>();
|
|
|
+ map.put("videos",videos);
|
|
|
+ map.put("sceneName",sceneName);
|
|
|
+ map.put("webSite",webSite);
|
|
|
+ map.put("thumb",thumb);
|
|
|
+ map.put("num",newNum);
|
|
|
+ map.put("id",id);
|
|
|
+ String localPath ;
|
|
|
+ String uploadPath ;
|
|
|
+ if(type.equals("v3")){
|
|
|
+ localPath = ConstantFilePath.SCENE_PATH + "data/data" + newNum + File.separator + "scene.json";
|
|
|
+ uploadPath = localPath.replace(ConstantFilePath.SCENE_PATH, "");
|
|
|
+ }else {
|
|
|
+ localPath = ConstantFilePath.SCENE_V4_PATH +"scene_view_data/"+ newNum + File.separator + "data" +File.separator +"scene.json";
|
|
|
+ uploadPath =localPath.replace(ConstantFilePath.SCENE_V4_PATH, "");
|
|
|
+
|
|
|
+ }
|
|
|
+ FileUtils.writeJsonFile(localPath, map);
|
|
|
+ if(type.equals("v4")){
|
|
|
+ uploadToOssUtil.upload(localPath,uploadPath);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void delete(String sceneNum, String username) {
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void deleteByList(List<ScenePro> proList,List<ScenePlus> plusList) {
|
|
|
+ HashMap<Long ,Long >cameraMap = new HashMap<>();
|
|
|
+ for (ScenePro scenePro : proList) {
|
|
|
+ cameraMap.merge(scenePro.getCameraId(), scenePro.getSpace(), Long::sum);
|
|
|
+ }
|
|
|
+ List<Long> proIds = proList.parallelStream().map(ScenePro::getId).collect(Collectors.toList());
|
|
|
+ List<Long> plusIds = plusList.parallelStream().map(ScenePlus::getId).collect(Collectors.toList());
|
|
|
+ HashMap<Long, ScenePlusExt> plusMap = scenePlusExtService.getByPlusIds(plusIds);
|
|
|
+
|
|
|
+ for (ScenePlus scenePlus : plusList) {
|
|
|
+ cameraMap.merge(scenePlus.getCameraId(), plusMap.get(scenePlus.getId()).getSpace(), Long::sum);
|
|
|
+ }
|
|
|
+ this.removeByIds(proIds);
|
|
|
+ scenePlusService.removeByIds(plusIds);
|
|
|
+ //恢复相机使用容量
|
|
|
+ cameraDetailService.addUsedSpace(cameraMap);
|
|
|
+ }
|
|
|
}
|