package com.fdkankan.fusion.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.fdkankan.fusion.common.ResultCode; import com.fdkankan.fusion.common.enums.IdPreEnum; import com.fdkankan.fusion.common.util.IdUtils; import com.fdkankan.fusion.common.util.UploadToOssUtil; import com.fdkankan.fusion.entity.*; import com.fdkankan.fusion.exception.BusinessException; import com.fdkankan.fusion.service.*; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.apache.commons.math3.ode.ODEIntegrator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import java.util.HashMap; import java.util.List; @Service @Slf4j public class CopyCaseService { @Autowired ICaseService caseService; @Autowired ICaseNumService caseNumService; @Autowired ICaseExtractDetailService caseExtractDetailService; @Autowired ICaseFilesService caseFilesService; @Autowired ICaseFusionService caseFusionService; @Autowired ICaseImgService caseImgService; @Autowired ICaseInquestService caseInquestService; @Autowired ICaseSettingsService caseSettingsService; @Autowired ICaseSettingsResourceService caseSettingsResourceService; @Autowired ICaseTagService caseTagService; @Autowired ICaseTagPointService caseTagPointService; @Autowired ICaseVideoFolderService caseVideoFolderService; @Autowired ICaseVideoService caseVideoService; @Autowired ICaseViewService caseViewService; @Autowired IFusionGuideService fusionGuideService; @Autowired IFusionGuidePathService fusionGuidePathService; @Autowired IFusionNumService fusionNumService; @Autowired IFusionMeterService fusionMeterService; @Autowired ITmProjectService projectService; @Autowired ITmMessageService tmMessageService; @Autowired ICaseScriptService caseScriptService; @Autowired ICaseImgTagService caseImgTagService; @Autowired ICasePathService casePathService; @Autowired ICaseAnimationService caseAnimationService; @Autowired ICaseOverviewService caseOverviewService; @Autowired ICaseTabulationService caseTabulationService; @Autowired UploadToOssUtil uploadToOssUtil; public void copyCase(Integer oldCaseId){ Integer newCaseId = this.cpCaseEntity(oldCaseId); this.cpCaseExtractDetail(oldCaseId,newCaseId); this.cpCaseFile(oldCaseId,newCaseId); this.cpCaseImg(oldCaseId,newCaseId); this.cpCaseInquest(oldCaseId,newCaseId); this.cpCaseNum(oldCaseId,newCaseId); this.cpCaseSettings(oldCaseId,newCaseId); this.cpCaseSettingsResource(oldCaseId,newCaseId); this.cpCaseVideo(oldCaseId,newCaseId); this.cpCaseViewByCaseId(oldCaseId,newCaseId); this.cpFusionGuide(oldCaseId,newCaseId); this.cpCaseScript(oldCaseId,newCaseId); this.cpImgTag(oldCaseId,newCaseId); HashMap fusionNumIdMap = this.cpCaseFusion(oldCaseId, newCaseId); this.cpCaseTag(oldCaseId,newCaseId,fusionNumIdMap); HashMap pathIdMap = this.cpPath(oldCaseId,newCaseId,fusionNumIdMap); this.cpAnimation(oldCaseId,newCaseId,pathIdMap); } /** * 复制案件信息 */ private Integer cpCaseEntity(Integer caseId) { CaseEntity caseEntity = caseService.getById(caseId); if(caseEntity == null){ throw new BusinessException(ResultCode.CASE_NOT_EXIST); } caseEntity.setCaseId(null); caseEntity.setCaseTitle(caseEntity.getCaseTitle()+"(copy)"); if(caseEntity.getTmProjectId() != null){ String oldProjectId = caseEntity.getTmProjectId(); String newProjectId = cpProject(oldProjectId); caseEntity.setTmProjectId(newProjectId); } caseService.save(caseEntity); return caseEntity.getCaseId(); } private String cpProject(String oldProjectId) { TmProject tmProject = projectService.getById(oldProjectId); String newId = IdUtils.genId(IdPreEnum.PROJECT_PRE.getPre()); tmProject.setId(newId); String projectSn = tmProject.getProjectSn() +"(copy)"; TmProject byProjectSn = projectService.getByProjectSn(projectSn); if(byProjectSn != null){ List projectSnList = projectService.getLikeByProjectSn(projectSn); projectSn += projectSnList.size(); } tmProject.setProjectSn(projectSn); //tmProject.setCaseNewName(projectService.setCaseNewName(tmProject)); projectService.save(tmProject); cpMessage(oldProjectId,newId); return newId; } private void cpMessage(String oldProjectId, String newId) { List messages = tmMessageService.getByProjectId(oldProjectId); if(messages == null || messages.isEmpty()){ return; } for (TmMessage message : messages) { message.setId(IdUtils.genId(IdPreEnum.MESSAGE_PRE.getPre())); message.setProjectId(newId); tmMessageService.save(message); } } /** * 复制案件提取清单 */ private void cpCaseExtractDetail(Integer oldCaseId,Integer newCaseId){ CaseExtractDetail caseExtractDetail = caseExtractDetailService.getByCaseId(oldCaseId); if(caseExtractDetail== null){ return; } caseExtractDetail.setId(null); caseExtractDetail.setCaseId(newCaseId); caseExtractDetailService.save(caseExtractDetail); } /** * 复制案件方位图等 */ private void cpCaseFile(Integer oldCaseId, Integer newCaseId) { List listByCaseId = caseFilesService.getByCaseId(oldCaseId); if(listByCaseId == null || listByCaseId.isEmpty()){ return; } for (CaseFiles entity : listByCaseId) { if(entity.getOverviewId() != null ){ HashMap map = this.cpOverview(newCaseId,entity.getOverviewId()); entity.setOverviewId(map.get("overviewId")); entity.setTabulationId(map.get("tabulationId")); } if(entity.getOverviewId() == null && entity.getTabulationId() != null ){ Integer newId = this.cpTabluation(newCaseId,entity.getTabulationId()); entity.setTabulationId(newId); } entity.setFilesId(null); entity.setCaseId(newCaseId); caseFilesService.save(entity); } } /** * 复制案件编辑器关联关系 */ private HashMap cpCaseFusion(Integer oldCaseId, Integer newCaseId) { HashMap fusionNumIdMap = new HashMap<>(); List listByCaseId = caseFusionService.getListByCaseId(oldCaseId); if(listByCaseId == null || listByCaseId.isEmpty()){ return fusionNumIdMap; } for (CaseFusion entity : listByCaseId) { Integer oldFusionId = entity.getFusionId(); entity.setFusionId(null); entity.setCaseId(newCaseId); caseFusionService.save(entity); cpCaseViewByFusionId(oldFusionId,entity.getFusionId(),newCaseId); cpFusionNum(oldFusionId,entity.getFusionId(),fusionNumIdMap); cpFusionMeter(oldFusionId,entity.getFusionId(),fusionNumIdMap); } return fusionNumIdMap; } /** * 复制案件照片制卷 */ private void cpCaseImg(Integer oldCaseId, Integer newCaseId) { List listByCaseId = caseImgService.getByCaseId(oldCaseId,null); if(listByCaseId == null || listByCaseId.isEmpty()){ return; } for (CaseImg entity : listByCaseId) { entity.setId(null); entity.setCaseId(newCaseId); caseImgService.save(entity); } } /** * 复制案件勘验笔录 */ private void cpCaseInquest(Integer oldCaseId, Integer newCaseId) { CaseInquest entity = caseInquestService.getByCaseId(oldCaseId); if(entity == null ){ return; } entity.setId(null); entity.setCaseId(newCaseId); caseInquestService.save(entity); } /** * 复制案件脚本 */ private void cpCaseScript(Integer oldCaseId, Integer newCaseId) { CaseScript entity = caseScriptService.getByCaseId(oldCaseId); if(entity == null ){ return; } entity.setId(null); entity.setCaseId(newCaseId); caseScriptService.save(entity); } /** * 复制案件图片标注 */ private void cpImgTag(Integer oldCaseId, Integer newCaseId) { CaseImgTag entity = caseImgTagService.getByCaseId(oldCaseId); if(entity == null ){ return; } entity.setId(null); entity.setCaseId(newCaseId); caseImgTagService.save(entity); } /** * 复制案件场景关系 */ private void cpCaseNum(Integer oldCaseId, Integer newCaseId) { List listByCaseId = caseNumService.getByCaseId(oldCaseId); if(listByCaseId == null || listByCaseId.isEmpty()){ return; } for (CaseNumEntity entity : listByCaseId) { entity.setId(null); entity.setCaseId(newCaseId); caseNumService.save(entity); } } /** * 复制案件系统设置 */ private void cpCaseSettings(Integer oldCaseId, Integer newCaseId) { List listByCaseId = caseSettingsService.getByCaseId(oldCaseId); if(listByCaseId == null || listByCaseId.isEmpty()){ return; } for (CaseSettings entity : listByCaseId) { entity.setSettingsId(null); entity.setCaseId(newCaseId); caseSettingsService.save(entity); } } /** * 复制案件系统设置资源 */ private void cpCaseSettingsResource(Integer oldCaseId, Integer newCaseId) { List listByCaseId = caseSettingsResourceService.getByCaseId(oldCaseId); if(listByCaseId == null || listByCaseId.isEmpty()){ return; } for (CaseSettingsResource entity : listByCaseId) { entity.setId(null); entity.setCaseId(newCaseId); caseSettingsResourceService.save(entity); } } /** * 复制案件标注 */ private void cpCaseTag(Integer oldCaseId, Integer newCaseId, HashMap fusionNumIdMap ) { List listByCaseId = caseTagService.getListByCaseId(oldCaseId); if(listByCaseId == null || listByCaseId.isEmpty()){ return; } for (CaseTag entity : listByCaseId) { Integer oldTagId =entity.getTagId(); entity.setTagId(null); entity.setCaseId(newCaseId); caseTagService.save(entity); Integer newTagId = entity.getTagId(); List caseTagPointList = caseTagPointService.getByTagId(oldTagId); if(caseTagPointList == null || caseTagPointList.isEmpty()){ continue; } for (CaseTagPoint caseTagPoint : caseTagPointList) { caseTagPoint.setTagPointId(null); caseTagPoint.setTagId(newTagId); caseTagPoint.setFusionNumId(fusionNumIdMap.get(caseTagPoint.getFusionNumId())); if(StringUtils.isNotBlank(caseTagPoint.getPose())){ String path = caseTagPoint.getPose(); for (Integer oldId : fusionNumIdMap.keySet()) { path = path.replaceAll("\"modelId\":\""+oldId+"\"","\"modelId\":\""+fusionNumIdMap.get(oldId)+"\""); } caseTagPoint.setPose(path); } caseTagPointService.save(caseTagPoint); } } } /** * 复制案件录制视频 */ private void cpCaseVideo(Integer oldCaseId, Integer newCaseId) { List listByCaseId = caseVideoFolderService.getAllList(oldCaseId); if(listByCaseId == null || listByCaseId.isEmpty()){ return; } for (CaseVideoFolder entity : listByCaseId) { Integer oldFolderId =entity.getVideoFolderId(); entity.setVideoFolderId(null); entity.setCaseId(newCaseId); caseVideoFolderService.save(entity); Integer newFolderId = entity.getVideoFolderId(); if(StringUtils.isNotBlank(entity.getVideoFolderCover())){ String oldVideoFolderCoverOssPath = uploadToOssUtil.getOssPath(entity.getVideoFolderCover()); String newVideoFolderCover= entity.getVideoFolderCover().replace(oldFolderId+"",newFolderId+""); String newVideoFolderCoverOssPath = uploadToOssUtil.getOssPath(newVideoFolderCover); uploadToOssUtil.copyFile(oldVideoFolderCoverOssPath,newVideoFolderCoverOssPath); if(uploadToOssUtil.existKey(newVideoFolderCoverOssPath)){ entity.setVideoFolderCover(newVideoFolderCover); } } if(StringUtils.isNotBlank(entity.getVideoMergeUrl())){ String newVideoMergeUrl = entity.getVideoMergeUrl().replace(oldFolderId+"",newFolderId+""); String oldVideoMergeUrlOssPath = uploadToOssUtil.getOssPath(entity.getVideoMergeUrl()); String newVideoMergeUrlOssPath = uploadToOssUtil.getOssPath(newVideoMergeUrl); uploadToOssUtil.copyFile(oldVideoMergeUrlOssPath,newVideoMergeUrlOssPath); if(uploadToOssUtil.existKey(newVideoMergeUrlOssPath)){ entity.setVideoMergeUrl(newVideoMergeUrl); } } caseVideoFolderService.updateById(entity); List caseVideos = caseVideoService.getAllList(oldFolderId); if(caseVideos == null || caseVideos.isEmpty()){ continue; } for (CaseVideo caseVideo : caseVideos) { caseVideo.setVideoId(null); caseVideo.setFolderId(newFolderId); caseVideo.setVideoPath(caseVideo.getVideoPath().replace(oldFolderId+"",newFolderId+"")); caseVideoService.save(caseVideo); } } } /** * 复制案件视图提取 */ private void cpCaseViewByCaseId(Integer oldCaseId, Integer newCaseId) { List listByCaseId = caseViewService.getByCaseId(oldCaseId); if(listByCaseId == null || listByCaseId.isEmpty()){ return; } for (CaseView entity : listByCaseId) { if(entity.getFusionId() != null){ continue; } entity.setViewId(null); entity.setCaseId(newCaseId); caseViewService.save(entity); } } private void cpCaseViewByFusionId(Integer oldFusionId, Integer newFusionId,Integer newCaseId) { List listByCaseId = caseViewService.getByFusionId(oldFusionId); if(listByCaseId == null || listByCaseId.isEmpty()){ return; } for (CaseView entity : listByCaseId) { entity.setViewId(null); entity.setFusionId(newFusionId+""); entity.setCaseId(newCaseId); caseViewService.save(entity); } } /** * 复制案件导览 */ private void cpFusionGuide(Integer oldCaseId, Integer newCaseId) { List listByCaseId = fusionGuideService.getAllList(oldCaseId); if(listByCaseId == null || listByCaseId.isEmpty()){ return; } for (FusionGuide entity : listByCaseId) { Integer oldGuideId =entity.getFusionGuideId(); entity.setFusionGuideId(null); entity.setCaseId(newCaseId); fusionGuideService.save(entity); Integer newGuideId = entity.getFusionGuideId(); List listByGuideId = fusionGuidePathService.getListByGuideId(oldGuideId); if(listByGuideId == null || listByGuideId.isEmpty()){ continue; } for (FusionGuidePath byId : listByGuideId) { byId.setGuidePathId(null); byId.setGuideId(newGuideId); fusionGuidePathService.save(byId); } } } /** * 复制案件编辑器ID */ private void cpFusionNum(Integer oldFusionId, Integer newFusionId,HashMap fusionNumIdMap) { List listByCaseId = fusionNumService.getByFusionId(oldFusionId); if(listByCaseId == null || listByCaseId.isEmpty()){ return; } for (FusionNum entity : listByCaseId) { Integer oldId = entity.getFusionNumId(); entity.setFusionNumId(null); entity.setFusionId(newFusionId); fusionNumService.save(entity); fusionNumIdMap.put(oldId,entity.getFusionNumId()); } } /** * 复制案件测量数据 */ private void cpFusionMeter(Integer oldFusionId,Integer newFusionId,HashMap fusionNumIdMap) { List listByCaseId = fusionMeterService.getListByFusionId(oldFusionId,null); if(listByCaseId == null || listByCaseId.isEmpty()){ return; } for (FusionMeter entity : listByCaseId) { entity.setFusionMeterId(null); entity.setFusionId(newFusionId); if(StringUtils.isNotBlank(entity.getPosition())){ String path = entity.getPosition(); for (Integer oldId : fusionNumIdMap.keySet()) { path = path.replaceAll("\"fusionNumId\":\""+oldId+"\"","\"fusionNumId\":\""+fusionNumIdMap.get(oldId)+"\""); } entity.setPosition(path); } fusionMeterService.save(entity); } } /** * 复制路线 */ private HashMap cpPath(Integer oldCaseId,Integer newCaseId,HashMap fusionNumIdMap){ HashMap pathIdMap = new HashMap<>(); List casePaths = casePathService.getByCaseId(oldCaseId); for (CasePath casePath : casePaths) { Integer oldPathId = casePath.getId(); casePath.setId(null); casePath.setCaseId(newCaseId); if(StringUtils.isNotBlank(casePath.getPath())){ String path = casePath.getPath(); for (Integer oldId : fusionNumIdMap.keySet()) { path = path.replaceAll("\"modelId\":\""+oldId+"\"","\"modelId\":\""+fusionNumIdMap.get(oldId)+"\""); } casePath.setPath(path); casePathService.save(casePath); } pathIdMap.put(oldPathId,casePath.getId()); } return pathIdMap; } /** * 复制动画数据 */ private void cpAnimation(Integer oldCaseId,Integer newCaseId,HashMap pathIdMap){ List list = caseAnimationService.getListByCaseId(oldCaseId); for (CaseAnimation caseAnimation : list) { caseAnimation.setId(null); caseAnimation.setCaseId(newCaseId); if(StringUtils.isNotBlank(caseAnimation.getPaths())){ String path = caseAnimation.getPaths(); for (Integer oldId : pathIdMap.keySet()) { path = path.replaceAll("\"pathId\":\""+oldId+"\"","\"pathId\":\""+pathIdMap.get(oldId)+"\""); } caseAnimation.setPaths(path); } caseAnimationService.save(caseAnimation); } } private HashMap cpOverview(Integer newCaseId, Integer oldId){ HashMap map = new HashMap<>(); CaseOverview caseOverview = caseOverviewService.getById(oldId); Integer oldOverId = caseOverview.getId(); caseOverview.setId(null); caseOverview.setCaseId(newCaseId); caseOverviewService.save(caseOverview); map.put("overviewId",caseOverview.getId()); List byOverId = caseTabulationService.getByOverId(oldOverId); for (CaseTabulation caseTabulation : byOverId) { caseTabulation.setId(null); caseTabulation.setOverviewId(caseOverview.getId()); caseTabulation.setCaseId(newCaseId); caseTabulationService.save(caseTabulation); map.put("tabulationId",caseTabulation.getId()); } return map; } private Integer cpTabluation( Integer newCaseId,Integer oldId){ CaseTabulation caseTabulation = caseTabulationService.getById(oldId); caseTabulation.setId(null); caseTabulation.setCaseId(newCaseId); caseTabulationService.save(caseTabulation); return caseTabulation.getId(); } }