CopyCaseService.java 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. package com.fdkankan.fusion.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.fdkankan.fusion.common.ResultCode;
  4. import com.fdkankan.fusion.common.enums.IdPreEnum;
  5. import com.fdkankan.fusion.common.util.IdUtils;
  6. import com.fdkankan.fusion.common.util.UploadToOssUtil;
  7. import com.fdkankan.fusion.entity.*;
  8. import com.fdkankan.fusion.exception.BusinessException;
  9. import com.fdkankan.fusion.service.*;
  10. import lombok.extern.slf4j.Slf4j;
  11. import org.apache.commons.lang3.StringUtils;
  12. import org.apache.commons.math3.ode.ODEIntegrator;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.beans.factory.annotation.Value;
  15. import org.springframework.stereotype.Service;
  16. import java.util.HashMap;
  17. import java.util.List;
  18. @Service
  19. @Slf4j
  20. public class CopyCaseService {
  21. @Autowired
  22. ICaseService caseService;
  23. @Autowired
  24. ICaseNumService caseNumService;
  25. @Autowired
  26. ICaseExtractDetailService caseExtractDetailService;
  27. @Autowired
  28. ICaseFilesService caseFilesService;
  29. @Autowired
  30. ICaseFusionService caseFusionService;
  31. @Autowired
  32. ICaseImgService caseImgService;
  33. @Autowired
  34. ICaseInquestService caseInquestService;
  35. @Autowired
  36. ICaseSettingsService caseSettingsService;
  37. @Autowired
  38. ICaseSettingsResourceService caseSettingsResourceService;
  39. @Autowired
  40. ICaseTagService caseTagService;
  41. @Autowired
  42. ICaseTagPointService caseTagPointService;
  43. @Autowired
  44. ICaseVideoFolderService caseVideoFolderService;
  45. @Autowired
  46. ICaseVideoService caseVideoService;
  47. @Autowired
  48. ICaseViewService caseViewService;
  49. @Autowired
  50. IFusionGuideService fusionGuideService;
  51. @Autowired
  52. IFusionGuidePathService fusionGuidePathService;
  53. @Autowired
  54. IFusionNumService fusionNumService;
  55. @Autowired
  56. IFusionMeterService fusionMeterService;
  57. @Autowired
  58. ITmProjectService projectService;
  59. @Autowired
  60. ITmMessageService tmMessageService;
  61. @Autowired
  62. ICaseScriptService caseScriptService;
  63. @Autowired
  64. ICaseImgTagService caseImgTagService;
  65. @Autowired
  66. ICasePathService casePathService;
  67. @Autowired
  68. ICaseAnimationService caseAnimationService;
  69. @Autowired
  70. UploadToOssUtil uploadToOssUtil;
  71. public void copyCase(Integer oldCaseId){
  72. Integer newCaseId = this.cpCaseEntity(oldCaseId);
  73. this.cpCaseExtractDetail(oldCaseId,newCaseId);
  74. this.cpCaseFile(oldCaseId,newCaseId);
  75. this.cpCaseImg(oldCaseId,newCaseId);
  76. this.cpCaseInquest(oldCaseId,newCaseId);
  77. this.cpCaseNum(oldCaseId,newCaseId);
  78. this.cpCaseSettings(oldCaseId,newCaseId);
  79. this.cpCaseSettingsResource(oldCaseId,newCaseId);
  80. this.cpCaseVideo(oldCaseId,newCaseId);
  81. this.cpCaseViewByCaseId(oldCaseId,newCaseId);
  82. this.cpFusionGuide(oldCaseId,newCaseId);
  83. this.cpCaseScript(oldCaseId,newCaseId);
  84. this.cpImgTag(oldCaseId,newCaseId);
  85. HashMap<Integer, Integer> fusionNumIdMap = this.cpCaseFusion(oldCaseId, newCaseId);
  86. this.cpCaseTag(oldCaseId,newCaseId,fusionNumIdMap);
  87. HashMap<Integer, Integer> pathIdMap = this.cpPath(oldCaseId,newCaseId,fusionNumIdMap);
  88. this.cpAnimation(oldCaseId,newCaseId,pathIdMap);
  89. }
  90. /**
  91. * 复制案件信息
  92. */
  93. private Integer cpCaseEntity(Integer caseId) {
  94. CaseEntity caseEntity = caseService.getById(caseId);
  95. if(caseEntity == null){
  96. throw new BusinessException(ResultCode.CASE_NOT_EXIST);
  97. }
  98. caseEntity.setCaseId(null);
  99. caseEntity.setCaseTitle(caseEntity.getCaseTitle()+"(copy)");
  100. if(caseEntity.getTmProjectId() != null){
  101. String oldProjectId = caseEntity.getTmProjectId();
  102. String newProjectId = cpProject(oldProjectId);
  103. caseEntity.setTmProjectId(newProjectId);
  104. }
  105. caseService.save(caseEntity);
  106. return caseEntity.getCaseId();
  107. }
  108. private String cpProject(String oldProjectId) {
  109. TmProject tmProject = projectService.getById(oldProjectId);
  110. String newId = IdUtils.genId(IdPreEnum.PROJECT_PRE.getPre());
  111. tmProject.setId(newId);
  112. String projectSn = tmProject.getProjectSn() +"(copy)";
  113. TmProject byProjectSn = projectService.getByProjectSn(projectSn);
  114. if(byProjectSn != null){
  115. List<TmProject> projectSnList = projectService.getLikeByProjectSn(projectSn);
  116. projectSn += projectSnList.size();
  117. }
  118. tmProject.setProjectSn(projectSn);
  119. //tmProject.setCaseNewName(projectService.setCaseNewName(tmProject));
  120. projectService.save(tmProject);
  121. cpMessage(oldProjectId,newId);
  122. return newId;
  123. }
  124. private void cpMessage(String oldProjectId, String newId) {
  125. List<TmMessage> messages = tmMessageService.getByProjectId(oldProjectId);
  126. if(messages == null || messages.isEmpty()){
  127. return;
  128. }
  129. for (TmMessage message : messages) {
  130. message.setId(IdUtils.genId(IdPreEnum.MESSAGE_PRE.getPre()));
  131. message.setProjectId(newId);
  132. tmMessageService.save(message);
  133. }
  134. }
  135. /**
  136. * 复制案件提取清单
  137. */
  138. private void cpCaseExtractDetail(Integer oldCaseId,Integer newCaseId){
  139. CaseExtractDetail caseExtractDetail = caseExtractDetailService.getByCaseId(oldCaseId);
  140. if(caseExtractDetail== null){
  141. return;
  142. }
  143. caseExtractDetail.setId(null);
  144. caseExtractDetail.setCaseId(newCaseId);
  145. caseExtractDetailService.save(caseExtractDetail);
  146. }
  147. /**
  148. * 复制案件方位图等
  149. */
  150. private void cpCaseFile(Integer oldCaseId, Integer newCaseId) {
  151. List<CaseFiles> listByCaseId = caseFilesService.getByCaseId(oldCaseId);
  152. if(listByCaseId == null || listByCaseId.isEmpty()){
  153. return;
  154. }
  155. for (CaseFiles entity : listByCaseId) {
  156. entity.setFilesId(null);
  157. entity.setCaseId(newCaseId);
  158. caseFilesService.save(entity);
  159. }
  160. }
  161. /**
  162. * 复制案件编辑器关联关系
  163. */
  164. private HashMap<Integer,Integer> cpCaseFusion(Integer oldCaseId, Integer newCaseId) {
  165. HashMap<Integer,Integer> fusionNumIdMap = new HashMap<>();
  166. List<CaseFusion> listByCaseId = caseFusionService.getListByCaseId(oldCaseId);
  167. if(listByCaseId == null || listByCaseId.isEmpty()){
  168. return fusionNumIdMap;
  169. }
  170. for (CaseFusion entity : listByCaseId) {
  171. Integer oldFusionId = entity.getFusionId();
  172. entity.setFusionId(null);
  173. entity.setCaseId(newCaseId);
  174. caseFusionService.save(entity);
  175. cpCaseViewByFusionId(oldFusionId,entity.getFusionId(),newCaseId);
  176. cpFusionNum(oldFusionId,entity.getFusionId(),fusionNumIdMap);
  177. cpFusionMeter(oldFusionId,entity.getFusionId(),fusionNumIdMap);
  178. }
  179. return fusionNumIdMap;
  180. }
  181. /**
  182. * 复制案件照片制卷
  183. */
  184. private void cpCaseImg(Integer oldCaseId, Integer newCaseId) {
  185. List<CaseImg> listByCaseId = caseImgService.getByCaseId(oldCaseId,null);
  186. if(listByCaseId == null || listByCaseId.isEmpty()){
  187. return;
  188. }
  189. for (CaseImg entity : listByCaseId) {
  190. entity.setId(null);
  191. entity.setCaseId(newCaseId);
  192. caseImgService.save(entity);
  193. }
  194. }
  195. /**
  196. * 复制案件勘验笔录
  197. */
  198. private void cpCaseInquest(Integer oldCaseId, Integer newCaseId) {
  199. CaseInquest entity = caseInquestService.getByCaseId(oldCaseId);
  200. if(entity == null ){
  201. return;
  202. }
  203. entity.setId(null);
  204. entity.setCaseId(newCaseId);
  205. caseInquestService.save(entity);
  206. }
  207. /**
  208. * 复制案件脚本
  209. */
  210. private void cpCaseScript(Integer oldCaseId, Integer newCaseId) {
  211. CaseScript entity = caseScriptService.getByCaseId(oldCaseId);
  212. if(entity == null ){
  213. return;
  214. }
  215. entity.setId(null);
  216. entity.setCaseId(newCaseId);
  217. caseScriptService.save(entity);
  218. }
  219. /**
  220. * 复制案件图片标注
  221. */
  222. private void cpImgTag(Integer oldCaseId, Integer newCaseId) {
  223. CaseImgTag entity = caseImgTagService.getByCaseId(oldCaseId);
  224. if(entity == null ){
  225. return;
  226. }
  227. entity.setId(null);
  228. entity.setCaseId(newCaseId);
  229. caseImgTagService.save(entity);
  230. }
  231. /**
  232. * 复制案件场景关系
  233. */
  234. private void cpCaseNum(Integer oldCaseId, Integer newCaseId) {
  235. List<CaseNumEntity> listByCaseId = caseNumService.getByCaseId(oldCaseId);
  236. if(listByCaseId == null || listByCaseId.isEmpty()){
  237. return;
  238. }
  239. for (CaseNumEntity entity : listByCaseId) {
  240. entity.setId(null);
  241. entity.setCaseId(newCaseId);
  242. caseNumService.save(entity);
  243. }
  244. }
  245. /**
  246. * 复制案件系统设置
  247. */
  248. private void cpCaseSettings(Integer oldCaseId, Integer newCaseId) {
  249. List<CaseSettings> listByCaseId = caseSettingsService.getByCaseId(oldCaseId);
  250. if(listByCaseId == null || listByCaseId.isEmpty()){
  251. return;
  252. }
  253. for (CaseSettings entity : listByCaseId) {
  254. entity.setSettingsId(null);
  255. entity.setCaseId(newCaseId);
  256. caseSettingsService.save(entity);
  257. }
  258. }
  259. /**
  260. * 复制案件系统设置资源
  261. */
  262. private void cpCaseSettingsResource(Integer oldCaseId, Integer newCaseId) {
  263. List<CaseSettingsResource> listByCaseId = caseSettingsResourceService.getByCaseId(oldCaseId);
  264. if(listByCaseId == null || listByCaseId.isEmpty()){
  265. return;
  266. }
  267. for (CaseSettingsResource entity : listByCaseId) {
  268. entity.setId(null);
  269. entity.setCaseId(newCaseId);
  270. caseSettingsResourceService.save(entity);
  271. }
  272. }
  273. /**
  274. * 复制案件标注
  275. */
  276. private void cpCaseTag(Integer oldCaseId, Integer newCaseId, HashMap<Integer, Integer> fusionNumIdMap ) {
  277. List<CaseTag> listByCaseId = caseTagService.getListByCaseId(oldCaseId);
  278. if(listByCaseId == null || listByCaseId.isEmpty()){
  279. return;
  280. }
  281. for (CaseTag entity : listByCaseId) {
  282. Integer oldTagId =entity.getTagId();
  283. entity.setTagId(null);
  284. entity.setCaseId(newCaseId);
  285. caseTagService.save(entity);
  286. Integer newTagId = entity.getTagId();
  287. List<CaseTagPoint> caseTagPointList = caseTagPointService.getByTagId(oldTagId);
  288. if(caseTagPointList == null || caseTagPointList.isEmpty()){
  289. continue;
  290. }
  291. for (CaseTagPoint caseTagPoint : caseTagPointList) {
  292. caseTagPoint.setTagPointId(null);
  293. caseTagPoint.setTagId(newTagId);
  294. caseTagPoint.setFusionNumId(fusionNumIdMap.get(caseTagPoint.getFusionNumId()));
  295. String path = caseTagPoint.getPose();
  296. if(StringUtils.isNotBlank(path)){
  297. for (Integer oldId : fusionNumIdMap.keySet()) {
  298. path = path.replaceAll("\"modelId\":\""+oldId+"\"","\"modelId\":\""+fusionNumIdMap.get(oldId)+"\"");
  299. }
  300. caseTagPoint.setPose(path);
  301. }
  302. caseTagPointService.save(caseTagPoint);
  303. }
  304. }
  305. }
  306. /**
  307. * 复制案件录制视频
  308. */
  309. private void cpCaseVideo(Integer oldCaseId, Integer newCaseId) {
  310. List<CaseVideoFolder> listByCaseId = caseVideoFolderService.getAllList(oldCaseId);
  311. if(listByCaseId == null || listByCaseId.isEmpty()){
  312. return;
  313. }
  314. for (CaseVideoFolder entity : listByCaseId) {
  315. Integer oldFolderId =entity.getVideoFolderId();
  316. entity.setVideoFolderId(null);
  317. entity.setCaseId(newCaseId);
  318. caseVideoFolderService.save(entity);
  319. Integer newFolderId = entity.getVideoFolderId();
  320. String newVideoFolderCover= entity.getVideoFolderCover().replace(oldFolderId+"",newFolderId+"");
  321. String newVideoMergeUrl = entity.getVideoMergeUrl().replace(oldFolderId+"",newFolderId+"");
  322. String oldVideoFolderCoverOssPath = uploadToOssUtil.getOssPath(entity.getVideoFolderCover());
  323. String newVideoFolderCoverOssPath = uploadToOssUtil.getOssPath(newVideoFolderCover);
  324. uploadToOssUtil.copyFile(oldVideoFolderCoverOssPath,newVideoFolderCoverOssPath);
  325. if(uploadToOssUtil.existKey(newVideoFolderCoverOssPath)){
  326. entity.setVideoFolderCover(newVideoFolderCover);
  327. }
  328. String oldVideoMergeUrlOssPath = uploadToOssUtil.getOssPath(entity.getVideoMergeUrl());
  329. String newVideoMergeUrlOssPath = uploadToOssUtil.getOssPath(newVideoMergeUrl);
  330. uploadToOssUtil.copyFile(oldVideoMergeUrlOssPath,newVideoMergeUrlOssPath);
  331. if(uploadToOssUtil.existKey(newVideoMergeUrlOssPath)){
  332. entity.setVideoMergeUrl(newVideoMergeUrl);
  333. }
  334. caseVideoFolderService.updateById(entity);
  335. List<CaseVideo> caseVideos = caseVideoService.getAllList(oldFolderId);
  336. if(caseVideos == null || caseVideos.isEmpty()){
  337. continue;
  338. }
  339. for (CaseVideo caseVideo : caseVideos) {
  340. caseVideo.setVideoId(null);
  341. caseVideo.setFolderId(newFolderId);
  342. caseVideo.setVideoPath(caseVideo.getVideoPath().replace(oldFolderId+"",newFolderId+""));
  343. caseVideoService.save(caseVideo);
  344. }
  345. }
  346. }
  347. /**
  348. * 复制案件视图提取
  349. */
  350. private void cpCaseViewByCaseId(Integer oldCaseId, Integer newCaseId) {
  351. List<CaseView> listByCaseId = caseViewService.getByCaseId(oldCaseId);
  352. if(listByCaseId == null || listByCaseId.isEmpty()){
  353. return;
  354. }
  355. for (CaseView entity : listByCaseId) {
  356. if(entity.getFusionId() != null){
  357. continue;
  358. }
  359. entity.setViewId(null);
  360. entity.setCaseId(newCaseId);
  361. caseViewService.save(entity);
  362. }
  363. }
  364. private void cpCaseViewByFusionId(Integer oldFusionId, Integer newFusionId,Integer newCaseId) {
  365. List<CaseView> listByCaseId = caseViewService.getByFusionId(oldFusionId);
  366. if(listByCaseId == null || listByCaseId.isEmpty()){
  367. return;
  368. }
  369. for (CaseView entity : listByCaseId) {
  370. entity.setViewId(null);
  371. entity.setFusionId(newFusionId+"");
  372. entity.setCaseId(newCaseId);
  373. caseViewService.save(entity);
  374. }
  375. }
  376. /**
  377. * 复制案件导览
  378. */
  379. private void cpFusionGuide(Integer oldCaseId, Integer newCaseId) {
  380. List<FusionGuide> listByCaseId = fusionGuideService.getAllList(oldCaseId);
  381. if(listByCaseId == null || listByCaseId.isEmpty()){
  382. return;
  383. }
  384. for (FusionGuide entity : listByCaseId) {
  385. Integer oldGuideId =entity.getFusionGuideId();
  386. entity.setFusionGuideId(null);
  387. entity.setCaseId(newCaseId);
  388. fusionGuideService.save(entity);
  389. Integer newGuideId = entity.getFusionGuideId();
  390. List<FusionGuidePath> listByGuideId = fusionGuidePathService.getListByGuideId(oldGuideId);
  391. if(listByGuideId == null || listByGuideId.isEmpty()){
  392. continue;
  393. }
  394. for (FusionGuidePath byId : listByGuideId) {
  395. byId.setGuidePathId(null);
  396. byId.setGuideId(newGuideId);
  397. fusionGuidePathService.save(byId);
  398. }
  399. }
  400. }
  401. /**
  402. * 复制案件编辑器ID
  403. */
  404. private void cpFusionNum(Integer oldFusionId, Integer newFusionId,HashMap<Integer,Integer> fusionNumIdMap) {
  405. List<FusionNum> listByCaseId = fusionNumService.getByFusionId(oldFusionId);
  406. if(listByCaseId == null || listByCaseId.isEmpty()){
  407. return;
  408. }
  409. for (FusionNum entity : listByCaseId) {
  410. Integer oldId = entity.getFusionNumId();
  411. entity.setFusionNumId(null);
  412. entity.setFusionId(newFusionId);
  413. fusionNumService.save(entity);
  414. fusionNumIdMap.put(oldId,entity.getFusionNumId());
  415. }
  416. }
  417. /**
  418. * 复制案件测量数据
  419. */
  420. private void cpFusionMeter(Integer oldFusionId,Integer newFusionId,HashMap<Integer,Integer> fusionNumIdMap) {
  421. List<FusionMeter> listByCaseId = fusionMeterService.getListByFusionId(oldFusionId,null);
  422. if(listByCaseId == null || listByCaseId.isEmpty()){
  423. return;
  424. }
  425. for (FusionMeter entity : listByCaseId) {
  426. entity.setFusionMeterId(null);
  427. entity.setFusionId(newFusionId);
  428. String path = entity.getPosition();
  429. if(StringUtils.isNotBlank(path)){
  430. for (Integer oldId : fusionNumIdMap.keySet()) {
  431. path = path.replaceAll("\"fusionNumId\":\""+oldId+"\"","\"fusionNumId\":\""+fusionNumIdMap.get(oldId)+"\"");
  432. }
  433. entity.setPosition(path);
  434. }
  435. fusionMeterService.save(entity);
  436. }
  437. }
  438. /**
  439. * 复制路线
  440. */
  441. private HashMap<Integer, Integer> cpPath(Integer oldCaseId,Integer newCaseId,HashMap<Integer, Integer> fusionNumIdMap){
  442. HashMap<Integer, Integer> pathIdMap = new HashMap<>();
  443. List<CasePath> casePaths = casePathService.getByCaseId(oldCaseId);
  444. for (CasePath casePath : casePaths) {
  445. Integer oldPathId = casePath.getId();
  446. casePath.setId(null);
  447. casePath.setCaseId(newCaseId);
  448. String path = casePath.getPath();
  449. if(StringUtils.isNotBlank(path)){
  450. for (Integer oldId : fusionNumIdMap.keySet()) {
  451. path = path.replaceAll("\"modelId\":\""+oldId+"\"","\"modelId\":\""+fusionNumIdMap.get(oldId)+"\"");
  452. }
  453. casePath.setPath(path);
  454. }
  455. casePathService.save(casePath);
  456. pathIdMap.put(oldPathId,casePath.getId());
  457. }
  458. return pathIdMap;
  459. }
  460. /**
  461. * 复制动画数据
  462. */
  463. private void cpAnimation(Integer oldCaseId,Integer newCaseId,HashMap<Integer, Integer> pathIdMap){
  464. List<CaseAnimation> list = caseAnimationService.getListByCaseId(oldCaseId);
  465. for (CaseAnimation caseAnimation : list) {
  466. caseAnimation.setId(null);
  467. caseAnimation.setCaseId(newCaseId);
  468. String path = caseAnimation.getPaths();
  469. if(StringUtils.isNotBlank(path)){
  470. for (Integer oldId : pathIdMap.keySet()) {
  471. path = path.replaceAll("\"pathId\":\""+oldId+"\"","\"pathId\":\""+pathIdMap.get(oldId)+"\"");
  472. }
  473. caseAnimation.setPaths(path);
  474. }
  475. caseAnimationService.save(caseAnimation);
  476. }
  477. }
  478. }