123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586 |
- 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<Integer, Integer> fusionNumIdMap = this.cpCaseFusion(oldCaseId, newCaseId);
- this.cpCaseTag(oldCaseId,newCaseId,fusionNumIdMap);
- HashMap<Integer, Integer> 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<TmProject> 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<TmMessage> 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<CaseFiles> listByCaseId = caseFilesService.getByCaseId(oldCaseId);
- if(listByCaseId == null || listByCaseId.isEmpty()){
- return;
- }
- for (CaseFiles entity : listByCaseId) {
- if(entity.getOverviewId() != null ){
- HashMap<String,Integer> 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<Integer,Integer> cpCaseFusion(Integer oldCaseId, Integer newCaseId) {
- HashMap<Integer,Integer> fusionNumIdMap = new HashMap<>();
- List<CaseFusion> 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<CaseImg> 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<CaseNumEntity> 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<CaseSettings> 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<CaseSettingsResource> 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<Integer, Integer> fusionNumIdMap ) {
- List<CaseTag> 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<CaseTagPoint> 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<CaseVideoFolder> 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<CaseVideo> 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<CaseView> 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<CaseView> 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<FusionGuide> 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<FusionGuidePath> 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<Integer,Integer> fusionNumIdMap) {
- List<FusionNum> 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<Integer,Integer> fusionNumIdMap) {
- List<FusionMeter> 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<Integer, Integer> cpPath(Integer oldCaseId,Integer newCaseId,HashMap<Integer, Integer> fusionNumIdMap){
- HashMap<Integer, Integer> pathIdMap = new HashMap<>();
- List<CasePath> 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<Integer, Integer> pathIdMap){
- List<CaseAnimation> 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<String,Integer> cpOverview(Integer newCaseId, Integer oldId){
- HashMap<String,Integer> 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<CaseTabulation> 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();
- }
- }
|