SceneProServiceImpl.java 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258
  1. package com.fdkankan.ucenter.service.impl;
  2. import cn.hutool.core.io.FileUtil;
  3. import cn.hutool.json.JSONUtil;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  6. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  7. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  8. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  9. import com.fdkankan.common.constant.SceneConstant;
  10. import com.fdkankan.common.constant.SceneKind;
  11. import com.fdkankan.common.exception.BusinessException;
  12. import com.fdkankan.common.util.*;
  13. import com.fdkankan.rabbitmq.bean.BuildSceneCallMessage;
  14. import com.fdkankan.rabbitmq.util.RabbitMqProducer;
  15. import com.fdkankan.redis.constant.RedisKey;
  16. import com.fdkankan.ucenter.common.OssPath;
  17. import com.fdkankan.ucenter.common.PageInfo;
  18. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  19. import com.fdkankan.image.MatrixToImageWriterUtil;
  20. import com.fdkankan.ucenter.common.constants.ConstantFilePath;
  21. import com.fdkankan.redis.util.RedisUtil;
  22. import com.fdkankan.ucenter.common.utils.ShellUtil;
  23. import com.fdkankan.ucenter.constant.CameraConstant;
  24. import com.fdkankan.ucenter.constant.LoginConstant;
  25. import com.fdkankan.ucenter.entity.*;
  26. import com.fdkankan.ucenter.httpClient.service.LaserService;
  27. import com.fdkankan.ucenter.mapper.ISceneProMapper;
  28. import com.fdkankan.ucenter.mapper.ISceneUpgradeMapper;
  29. import com.fdkankan.ucenter.service.*;
  30. import com.fdkankan.ucenter.util.DateUserUtil;
  31. import com.fdkankan.ucenter.vo.ResponseScene;
  32. import com.fdkankan.ucenter.vo.request.RequestScene;
  33. import com.fdkankan.ucenter.vo.request.SceneParam;
  34. import com.fdkankan.ucenter.vo.response.GroupByCount;
  35. import com.fdkankan.ucenter.vo.response.SceneInfoVo;
  36. import com.fdkankan.ucenter.vo.response.SceneNumVo;
  37. import com.fdkankan.ucenter.vo.response.SceneVo;
  38. import java.io.File;
  39. import java.util.ArrayList;
  40. import java.util.Arrays;
  41. import java.util.Collections;
  42. import java.util.Date;
  43. import java.util.HashMap;
  44. import java.util.List;
  45. import java.util.Map;
  46. import java.util.Objects;
  47. import java.util.concurrent.CompletableFuture;
  48. import java.util.concurrent.locks.Condition;
  49. import java.util.stream.Collectors;
  50. import javax.annotation.Resource;
  51. import lombok.extern.slf4j.Slf4j;
  52. import org.apache.commons.lang3.StringUtils;
  53. import org.joda.time.DateTime;
  54. import org.springframework.beans.BeanUtils;
  55. import org.springframework.beans.factory.annotation.Autowired;
  56. import org.springframework.beans.factory.annotation.Value;
  57. import org.springframework.stereotype.Service;
  58. import org.springframework.util.ObjectUtils;
  59. /**
  60. * <p>
  61. * pro场景表 服务实现类
  62. * </p>
  63. *
  64. * @author
  65. * @since 2022-07-04
  66. */
  67. @Service
  68. @Slf4j
  69. public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro> implements ISceneProService {
  70. @Autowired
  71. private IUserService userService;
  72. @Autowired
  73. private ISceneCooperationService sceneCooperationService;
  74. @Autowired
  75. private IScenePlusService scenePlusService;
  76. @Autowired
  77. private ISceneService sceneService;
  78. @Autowired
  79. private LaserService fdkkLaserService;
  80. @Autowired
  81. private FYunFileServiceInterface fYunFileService;
  82. @Autowired
  83. private IUserIncrementService userIncrementService;
  84. @Autowired
  85. private IIncrementTypeService incrementTypeService;
  86. @Autowired
  87. private IScenePlusExtService scenePlusExtService;
  88. @Autowired
  89. private ISceneEditInfoService sceneEditInfoService;
  90. @Autowired
  91. private ICameraDetailService cameraDetailService;
  92. @Autowired
  93. ICameraService cameraService;
  94. @Autowired
  95. private IFolderService folderService;
  96. @Autowired
  97. private IFolderSceneService folderSceneService;
  98. @Autowired
  99. private ISceneCopyLogService sceneCopyLogService;
  100. @Autowired
  101. private IScene3dNumService scene3dNumService;
  102. @Autowired
  103. private ISceneProEditService sceneProEditService;
  104. @Autowired
  105. private RedisUtil redisUtil;
  106. @Autowired
  107. private ISceneUpgradeMapper sceneUpgradeMapper;
  108. @Autowired
  109. private IInnerService innerService;
  110. @Autowired
  111. LaserService laserService;
  112. @Value("${main.url}")
  113. private String mainUrl;
  114. @Value("${scene.pro.url}")
  115. private String sceneProUrl;
  116. @Value("${scene.pro.new.url}")
  117. private String sceneProNewUrl;
  118. @Value("${queue.modeling.obj.modeling-pre}")
  119. private String queueObjModelingPre;
  120. @Autowired
  121. private RabbitMqProducer mqProducer;
  122. @Override
  123. public HashMap<String, SceneNumVo> findSceneNumber(String token) {
  124. User user = userService.getByUserName(JwtUtil.getUsername(token));
  125. SceneNumVo sceneNumVoKk = getSceneNumVoByType(Arrays.asList(1,2,12,13,14), user.getId());
  126. Integer oldNum = sceneService.getCountByUserId(user.getId());
  127. sceneNumVoKk.setSceneNum( oldNum + sceneNumVoKk.getSceneNum());
  128. sceneNumVoKk.setTotalNum(oldNum + sceneNumVoKk.getTotalNum());
  129. SceneNumVo sceneNumVoKj = getSceneNumVoByType(Collections.singletonList(3), user.getId());
  130. SceneNumVo sceneNumVoSS = fdkkLaserService.getLaserSceneNumByUser(token);
  131. SceneNumVo sceneNumVoSSObj = getSceneNumVoByObjType(Arrays.asList(4), user.getId());
  132. HashMap<String, SceneNumVo> hashMap = new HashMap<>();
  133. hashMap.put("kk",sceneNumVoKk);
  134. hashMap.put("kJ",sceneNumVoKj);
  135. hashMap.put("SS",sceneNumVoSS);
  136. hashMap.put("SS_OBJ",sceneNumVoSSObj);
  137. return hashMap;
  138. }
  139. private SceneNumVo getSceneNumVoByType(List<Integer> sceneSourceList, Long userId){
  140. SceneNumVo sceneNumVo = new SceneNumVo();
  141. LambdaQueryWrapper<ScenePro> queryWrapper = new LambdaQueryWrapper<>();
  142. queryWrapper.eq(ScenePro::getUserId, userId);
  143. queryWrapper.in(ScenePro::getSceneSource, sceneSourceList);
  144. queryWrapper.eq(ScenePro::getIsUpgrade, 0);
  145. Integer sceneNum = Math.toIntExact(this.count(queryWrapper));
  146. Long count = scenePlusService.getCountByUserId(userId,sceneSourceList);
  147. sceneNumVo.setCooperationSceneNum(sceneCooperationService.getCooperationSceneNum(userId,sceneSourceList));
  148. sceneNumVo.setSceneNum(sceneNum + count);
  149. sceneNumVo.setTotalNum(sceneNumVo.getSceneNum() + sceneNumVo.getCooperationSceneNum());
  150. return sceneNumVo;
  151. }
  152. private SceneNumVo getSceneNumVoByObjType(List<Integer> sceneSourceList, Long userId){
  153. SceneNumVo sceneNumVo = new SceneNumVo();
  154. LambdaQueryWrapper<ScenePro> queryWrapper = new LambdaQueryWrapper<>();
  155. queryWrapper.eq(ScenePro::getUserId, userId);
  156. queryWrapper.in(ScenePro::getSceneSource, sceneSourceList);
  157. queryWrapper.eq(ScenePro::getIsUpgrade, 0);
  158. queryWrapper.eq(ScenePro::getIsObj,1);
  159. Integer sceneNum = Math.toIntExact(this.count(queryWrapper));
  160. LambdaQueryWrapper<ScenePlusExt> wrapper = new LambdaQueryWrapper<>();
  161. wrapper.eq(ScenePlusExt::getIsObj,1);
  162. List<ScenePlusExt> list = scenePlusExtService.list(wrapper);
  163. List<Long> plusIds = list.stream().map(ScenePlusExt::getPlusId).collect(Collectors.toList());
  164. long plusCount = 0L;
  165. long cooperNum = 0L;
  166. if(plusIds.size() >0){
  167. LambdaQueryWrapper<ScenePlus> plusWr = new LambdaQueryWrapper<>();
  168. plusWr.in(ScenePlus::getId,plusIds);
  169. plusWr.in(ScenePlus::getSceneSource,sceneSourceList);
  170. List<ScenePlus> plusList = scenePlusService.list(plusWr);
  171. if(plusList.size() >0){
  172. List<ScenePlus> userList = plusList.stream().filter(entity -> userId.equals(entity.getUserId())).collect(Collectors.toList());
  173. plusCount = userList.size();
  174. List<String> numList = plusList.stream().map(ScenePlus::getNum).collect(Collectors.toList());
  175. HashMap<String, User> cooNumList = sceneCooperationService.getByNumList(numList);
  176. for (String num : cooNumList.keySet()) {
  177. if(userId.equals(cooNumList.get(num).getId())){
  178. cooperNum ++;
  179. }
  180. }
  181. }
  182. }
  183. sceneNumVo.setCooperationSceneNum(cooperNum);
  184. sceneNumVo.setSceneNum(sceneNum + plusCount);
  185. sceneNumVo.setTotalNum(sceneNumVo.getSceneNum() + sceneNumVo.getCooperationSceneNum());
  186. return sceneNumVo;
  187. }
  188. @Override
  189. public HashMap<Long,GroupByCount> findSceneNumByCameraIds(List<Long> cameraIdList) {
  190. HashMap<Long,GroupByCount> map = new HashMap<>();
  191. List<GroupByCount> result = this.getBaseMapper().findSceneProNumByCameraIds(cameraIdList);
  192. List<GroupByCount> result2 = this.getBaseMapper().findScenePlusNumByCameraIds(cameraIdList);
  193. result.forEach(entity ->map.put(entity.getId(),entity));
  194. for (GroupByCount groupByCount : result2) {
  195. if (map.get(groupByCount.getId()) != null) {
  196. Long totalCount = map.get(groupByCount.getId()).getCount() + groupByCount.getCount();
  197. String lastTime = DateUserUtil.getLastTime(map.get(groupByCount.getId()).getLastTime(), groupByCount.getLastTime());
  198. groupByCount.setCount(totalCount);
  199. groupByCount.setLastTime(lastTime);
  200. }
  201. map.put(groupByCount.getId(),groupByCount);
  202. }
  203. return map;
  204. }
  205. /**
  206. * @param payStatus -2 封存,为 1 解封
  207. */
  208. @Override
  209. public void lockOrUnLockBySpace(CameraDetail cameraDetail, Long cameraId, Integer payStatus) {
  210. LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
  211. LambdaQueryWrapper<ScenePlus> plusWr = new LambdaQueryWrapper<>();
  212. Long totalSpace = cameraDetail.getTotalSpace();
  213. UserIncrement userIncrement = userIncrementService.getByCameraId(cameraId);
  214. if(userIncrement!=null){
  215. IncrementType incrementType = incrementTypeService.getById(userIncrement.getIncrementTypeId());
  216. if(incrementType!=null){
  217. if(incrementType.getCameraCapacity() == -1){
  218. totalSpace = -1L;
  219. }else {
  220. totalSpace = incrementType.getCameraCapacity() * 1024 * 1024L;
  221. }
  222. }
  223. }
  224. log.info("lockOrUnLockBySpace---cameraId:{},payStatus:{},totalSpace:{},useSpace{}",
  225. cameraId,payStatus,totalSpace,cameraDetail.getUsedSpace());
  226. if(payStatus == 1){ //解封,判断用户权益,用户会员权益无限容量
  227. wrapper.orderByAsc(ScenePro::getCreateTime);
  228. plusWr.orderByAsc(ScenePlus::getCreateTime);
  229. wrapper.eq(ScenePro::getPayStatus,-2);
  230. plusWr.eq(ScenePlus::getPayStatus,-2);
  231. }else {
  232. if (totalSpace >= cameraDetail.getUsedSpace()) {
  233. // 总容量大于已使用容量,不予封存
  234. return;
  235. }
  236. wrapper.orderByDesc(ScenePro::getCreateTime);
  237. plusWr.orderByDesc(ScenePlus::getCreateTime);
  238. wrapper.eq(ScenePro::getPayStatus,1);
  239. plusWr.eq(ScenePlus::getPayStatus,1);
  240. }
  241. wrapper.eq(ScenePro::getCameraId,cameraId)
  242. .eq(ScenePro::getIsUpgrade,0);
  243. plusWr.eq(ScenePlus::getCameraId,cameraId);
  244. List<ScenePro> list = this.list(wrapper);
  245. List<ScenePlus> plusList = scenePlusService.list(plusWr);
  246. Long beyondSpace = Math.abs(cameraDetail.getUsedSpace() - totalSpace);
  247. Long accumulateSpace = 0L;
  248. List<Long> lockedIds = new ArrayList<>();
  249. if(payStatus == 1){
  250. Long doSpace = getScenePlusLockedIds(lockedIds, plusList, totalSpace, beyondSpace, accumulateSpace);
  251. beyondSpace -= doSpace;
  252. getSceneLockedIds(lockedIds,list,totalSpace,beyondSpace,accumulateSpace);
  253. }else {
  254. Long doSpace = getSceneLockedIds(lockedIds, list, totalSpace, beyondSpace, accumulateSpace);
  255. beyondSpace -= doSpace;
  256. getScenePlusLockedIds(lockedIds,plusList,totalSpace,beyondSpace,accumulateSpace);
  257. }
  258. lockOrUnLockScenes(lockedIds,payStatus);
  259. }
  260. private Long getSceneLockedIds(List<Long> lockedIds ,List<ScenePro> list,Long count,Long beyondSpace,Long accumulateSpace){
  261. if (list != null && list.size() > 0){
  262. for (ScenePro scenePro : list){
  263. accumulateSpace += scenePro.getSpace();
  264. if (count ==-1 && accumulateSpace.compareTo(beyondSpace) > 0){
  265. return accumulateSpace - scenePro.getSpace();
  266. }
  267. lockedIds.add(scenePro.getId());
  268. }
  269. }
  270. return accumulateSpace;
  271. }
  272. private Long getScenePlusLockedIds(List<Long> lockedIds , List<ScenePlus> list, Long count, Long beyondSpace, Long accumulateSpace){
  273. if (list != null && list.size() > 0){
  274. List<Long> plusIds = list.parallelStream().map(ScenePlus::getId).collect(Collectors.toList());
  275. HashMap<Long, ScenePlusExt> byPlusIds = scenePlusExtService.getByPlusIds(plusIds);
  276. for (ScenePlus scenePlus : list){
  277. ScenePlusExt scenePlusExt = byPlusIds.get(scenePlus.getId());
  278. accumulateSpace += scenePlusExt.getSpace();
  279. if (count ==-1 && accumulateSpace.compareTo(beyondSpace) > 0){
  280. return accumulateSpace - scenePlusExt.getSpace();
  281. }
  282. lockedIds.add(scenePlus.getId());
  283. }
  284. }
  285. return accumulateSpace;
  286. }
  287. // payStatus 为 -2 封存,为 1 解封
  288. private void lockOrUnLockScenes(List<Long> lockedIds,Integer payStatus) {
  289. if (lockedIds == null || lockedIds.size() == 0){
  290. return;
  291. }
  292. LambdaUpdateWrapper<ScenePro> updateWrapper = new LambdaUpdateWrapper<>();
  293. updateWrapper.set(ScenePro::getPayStatus,payStatus)
  294. .eq(ScenePro::getIsUpgrade,0)
  295. .in(ScenePro::getId,lockedIds);
  296. this.update(updateWrapper);
  297. LambdaUpdateWrapper<ScenePlus> updatePlusWrapper = new LambdaUpdateWrapper<>();
  298. updatePlusWrapper.set(ScenePlus::getPayStatus,payStatus)
  299. .in(ScenePlus::getId,lockedIds);
  300. scenePlusService.update(updatePlusWrapper);
  301. this.updateOssStatus(lockedIds,payStatus);
  302. }
  303. /**
  304. * 修改oss status.json中 payStatus
  305. */
  306. private void updateOssStatus(List<Long> lockedIds, Integer payStatus) {
  307. LambdaQueryWrapper<ScenePro> proWr = new LambdaQueryWrapper<>();
  308. proWr.eq(ScenePro::getIsUpgrade,0);
  309. proWr.in(ScenePro::getId,lockedIds);
  310. List<ScenePro> proList = this.list(proWr);
  311. LambdaQueryWrapper<ScenePlus> pluWr = new LambdaQueryWrapper<>();
  312. pluWr.in(ScenePlus::getId,lockedIds);
  313. List<ScenePlus> plusList = scenePlusService.list(pluWr);
  314. for (ScenePro scenePro : proList) {
  315. this.updateOssStatus(String.format(OssPath.v3_statusPath,scenePro.getNum()),payStatus);
  316. }
  317. for (ScenePlus scenePlus : plusList) {
  318. this.updateOssStatus(String.format(OssPath.v4_statusPath,scenePlus.getNum()),payStatus);
  319. }
  320. }
  321. /**
  322. * 从oss中获取文件,并重写,上传替换
  323. */
  324. private void updateOssStatus(String path,Integer payStatus) {
  325. try {
  326. if(!fYunFileService.fileExist(path)){
  327. return;
  328. }
  329. String data = fYunFileService.getFileContent(path);
  330. if(StringUtils.isBlank(data)){
  331. return;
  332. }
  333. JSONObject jsonObject = JSONObject.parseObject(data);
  334. jsonObject.put("payStatus",payStatus);
  335. String json = JSONUtil.toJsonStr(jsonObject);
  336. FileUtils.writeFile(OssPath.localStatusPath ,json);
  337. log.info("updateOssStatus--localPath:{},ossPath:{}",OssPath.localStatusPath,path);
  338. fYunFileService.uploadFile(OssPath.localStatusPath,path);
  339. }catch (Exception e){
  340. e.printStackTrace();
  341. }finally {
  342. FileUtil.del(OssPath.localStatusPath);
  343. }
  344. }
  345. @Override
  346. public List<ScenePro> getListByCameraId(Long cameraId) {
  347. LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
  348. wrapper.eq(ScenePro::getCameraId,cameraId)
  349. .eq(ScenePro::getIsUpgrade,0);
  350. return this.list(wrapper);
  351. }
  352. @Override
  353. public void bindOrUnCamera(List<Long> cameraIds, Long userId) {
  354. if(cameraIds.size() >0){
  355. LambdaUpdateWrapper<ScenePro> wrapper = new LambdaUpdateWrapper<>();
  356. wrapper.in(ScenePro::getCameraId,cameraIds)
  357. .eq(ScenePro::getIsUpgrade,0)
  358. .set(ScenePro::getUserId,userId);
  359. this.update(wrapper);
  360. }
  361. }
  362. @Override
  363. public List<ScenePro> getListByCameraIds(List<Long> cameraIds) {
  364. LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
  365. wrapper.in(ScenePro::getCameraId,cameraIds)
  366. .eq(ScenePro::getIsUpgrade,0);
  367. return this.list(wrapper);
  368. }
  369. @Override
  370. public List<ScenePro> getListByNums(List<String> numList) {
  371. LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
  372. wrapper.in(ScenePro::getNum,numList)
  373. .eq(ScenePro::getIsUpgrade,0);
  374. return this.list(wrapper);
  375. }
  376. @Override
  377. public Long getCountByUserId(Long userId, List<?> resourceList) {
  378. LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
  379. wrapper.eq(ScenePro::getUserId,userId);
  380. wrapper.eq(ScenePro::getIsUpgrade,0);
  381. wrapper.in(ScenePro::getSceneSource,resourceList);
  382. return this.count(wrapper);
  383. }
  384. @Override
  385. public Long getCountByUserId(Long id, Integer cameraType) {
  386. return this.getBaseMapper().getCountByUserId(id,cameraType);
  387. }
  388. @Override
  389. public void deleteByIds(List<Long> sceneIds) {
  390. LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
  391. wrapper.in(ScenePro::getId,sceneIds)
  392. .eq(ScenePro::getIsUpgrade,0);
  393. List<ScenePro> proList = this.list(wrapper);
  394. LambdaQueryWrapper<ScenePlus> plusWr = new LambdaQueryWrapper<>();
  395. plusWr.in(ScenePlus::getId,sceneIds);
  396. List<ScenePlus> plusList = scenePlusService.list(plusWr);
  397. this.deleteByList(proList,plusList);
  398. }
  399. @Override
  400. public Page<SceneVo> pageListAndFolder(Page<Object> page, SceneParam param) {
  401. return getBaseMapper().pageListAndFolder(new Page<>(param.getPageNum(),param.getPageSize()),param);
  402. }
  403. @Override
  404. public Object getScenes(String username, RequestScene param) {
  405. User user = userService.getByUserName(username);
  406. log.info("搜索条件是:"+ param.getSearchKey());
  407. //type为12表示一键换装的请求,不查询相机数据
  408. if(StringUtils.isNotEmpty(param.getSearchKey()) && !"11".equals(param.getType())){
  409. List<Long> userIds = userService.getLikeUserName(param.getSearchKey());
  410. if(userIds.size() > 0){
  411. List<String> cooperationList = sceneCooperationService.getNumByUserIds(userIds);
  412. param.setNumList(cooperationList);
  413. }
  414. }
  415. param.setUserId(user.getId());
  416. Page<SceneVo> sceneList = sceneService.getSceneList(param);
  417. for (SceneVo record : sceneList.getRecords()) {
  418. record.setUserName(username);
  419. SceneCooperation sceneCooperationEntity = sceneCooperationService.getByNum(record.getNum());
  420. if(sceneCooperationEntity != null && sceneCooperationEntity.getUserId()!= null){
  421. User user1 = userService.getById(sceneCooperationEntity.getUserId());
  422. if(user1 != null){
  423. record.setCooperationUserId(String.valueOf(sceneCooperationEntity.getUserId()));
  424. record.setCooperationUserName(user1.getUserName());
  425. }
  426. }
  427. }
  428. return PageInfo.PageInfo(sceneList);
  429. }
  430. @Override
  431. public JSONObject newList(SceneParam param, String username) {
  432. param.setSourceList(getSceneSource(param.getSceneSource()));
  433. if(StringUtils.isNotBlank(username)){
  434. User user = userService.getByUserName(username);
  435. param.setUserId(user.getId());
  436. }
  437. Page<SceneVo> sceneVoPage = getBaseMapper().pageListAndFolder(new Page<>(param.getPageNum(),param.getPageSize()),param);
  438. List<SceneVo> folderList = sceneVoPage.getRecords().parallelStream().filter(entity -> entity.getIsFolder() == 1).collect(Collectors.toList());
  439. Long totalSceneNum = 0L;
  440. if(folderList.size() >0){
  441. List<Long> folderIds = folderList.parallelStream().map(SceneVo::getId).collect(Collectors.toList());
  442. List<Folder> allFolderIds = folderService.getAllFolderIds(folderIds);
  443. HashMap<Long,Long> map = folderSceneService.getGroupByFolderIds(allFolderIds);
  444. for (SceneVo vo : sceneVoPage.getRecords()) {
  445. if(vo.getIsFolder() == 1 && vo.getType()!= null && vo.getType()!= 3){
  446. Long sceneNum = map.get(vo.getId()) == null ? 0L : map.get(vo.getId());
  447. vo.setSceneNum(sceneNum);
  448. vo.setCreateTimeStr(vo.getCreateTime());
  449. }else if(vo.getIsFolder() == 1 && vo.getType()!= null && vo.getType() == 3){
  450. if(param.getUserId()!= null){
  451. Integer count = sceneService.getCountByUserId(param.getUserId());
  452. vo.setSceneNum(Long.valueOf(count));
  453. }
  454. }
  455. }
  456. }
  457. //设置协作者信息
  458. if(sceneVoPage.getRecords().size() >0){
  459. List<String> numList = sceneVoPage.getRecords().parallelStream().map(SceneVo::getNum).collect(Collectors.toList());
  460. HashMap<String,User> cooMap = sceneCooperationService.getByNumList(numList);
  461. for (SceneVo vo : sceneVoPage.getRecords()) {
  462. if (StringUtils.isNotBlank(vo.getNum())) {
  463. User userVo = cooMap.get(vo.getNum());
  464. if (userVo != null) {
  465. vo.setCooperationUserId(userVo.getId().toString());
  466. vo.setCooperationUserName(userVo.getUserName());
  467. }
  468. }
  469. }
  470. }
  471. List<SceneVo> sceneList = sceneVoPage.getRecords().parallelStream().filter(entity -> entity.getIsFolder() == 0)
  472. .peek(vo->{
  473. if (ObjectUtils.isEmpty(vo.getStatus())) {
  474. return;
  475. }
  476. if (vo.getStatus().equals(500)) { //500状态为数据库中手动修改值,当场景本身异常,算法,算不了
  477. vo.setStatus(-1);
  478. }
  479. if (vo.getStatus().equals(-1)) { //计算失败,钉钉通知之后,判定是否重算,还是修改为 500
  480. vo.setStatus(0);
  481. }
  482. }).collect(Collectors.toList());
  483. if(sceneList.size() >0){
  484. folderList.addAll(sceneList);
  485. }
  486. sceneVoPage.setRecords(folderList);
  487. if(param.getFolderId() == null && param.getIsObj() == null ){
  488. List<String> sourceList = param.getSourceList();
  489. if(param.getUserId()!= null){
  490. totalSceneNum = this.getCountByUserId(param.getUserId(),sourceList);
  491. totalSceneNum += scenePlusService.getCountByUserId(param.getUserId(),sourceList);
  492. totalSceneNum += sceneService.getCountByUserId(param.getUserId());
  493. }
  494. }else if(param.getFolderId() != null ){
  495. totalSceneNum = folderSceneService.getCountByFolderAndSon(param.getFolderId());
  496. }else if(param.getIsObj() != null && param.getIsObj() ==1){
  497. if(param.getUserId()!= null){
  498. totalSceneNum = this.getCountByLaserAndIsObj(param.getUserId());
  499. }
  500. }
  501. JSONObject jsonObject = new JSONObject();
  502. jsonObject.put("pageInfo",PageInfo.PageInfo(sceneVoPage));
  503. jsonObject.put("sceneNum",totalSceneNum);
  504. return jsonObject;
  505. }
  506. private Long getCountByLaserAndIsObj(Long userId) {
  507. Long proCount = 0L;
  508. Long plusCount = 0L;
  509. LambdaQueryWrapper<ScenePro> proWr = new LambdaQueryWrapper<>();
  510. proWr.eq(ScenePro::getUserId,userId);
  511. proWr.eq(ScenePro::getSceneSource,4);
  512. proWr.eq(ScenePro::getIsObj,1);
  513. proWr.eq(ScenePro::getIsUpgrade,0);
  514. proCount = this.count(proWr);
  515. LambdaQueryWrapper<ScenePlus> plusWr = new LambdaQueryWrapper<>();
  516. plusWr.eq(ScenePlus::getUserId,userId);
  517. plusWr.eq(ScenePlus::getSceneSource,4);
  518. List<ScenePlus> list = scenePlusService.list(plusWr);
  519. if(list.size() >0){
  520. List<Long> plusIds = list.stream().map(ScenePlus::getId).collect(Collectors.toList());
  521. LambdaQueryWrapper<ScenePlusExt> extWr = new LambdaQueryWrapper<>();
  522. extWr.in(ScenePlusExt::getPlusId,plusIds);
  523. extWr.eq(ScenePlusExt::getIsObj,1);
  524. plusCount = scenePlusExtService.count(extWr);
  525. }
  526. return proCount +plusCount;
  527. }
  528. public List<String> getSceneSource(String sceneSource){
  529. List<String> sceneSourceList ;
  530. if(StringUtils.isNotBlank(sceneSource)){
  531. switch (sceneSource){
  532. case "1" : sceneSourceList = Arrays.asList("1","2","12","13","14"); break; //四维看看
  533. case "3" : sceneSourceList = Collections.singletonList("3"); break;//四维看见
  534. case "4" : sceneSourceList = Collections.singletonList("4"); break;//深时场景
  535. default:
  536. if(sceneSource.contains(",")){
  537. sceneSource = sceneSource + ",12,13,14";
  538. sceneSourceList = Arrays.asList(sceneSource.split(","));
  539. break;
  540. }
  541. sceneSourceList = Collections.singletonList(sceneSource);break;
  542. }
  543. return sceneSourceList;
  544. }
  545. return Arrays.asList("0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15");
  546. }
  547. @Override
  548. public void copyScene(String sceneNum,String userName) throws Exception {
  549. if(StringUtils.isEmpty(sceneNum)){
  550. throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
  551. }
  552. ScenePro scenePro = this.getByNum(sceneNum);
  553. ScenePlus scenePlus = scenePlusService.getByNum(sceneNum);
  554. if((scenePro == null || scenePro.getCameraId() == null ) && (scenePlus== null || scenePlus.getCameraId() == null)){
  555. throw new BusinessException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
  556. }
  557. Long cameraId = scenePro == null ? scenePlus.getCameraId() : scenePro.getCameraId();
  558. Long userId = scenePro == null ? scenePlus.getUserId() :scenePro.getUserId();
  559. // 判断是否有绑定会员权益
  560. Long count = userIncrementService.getValidCountByCameraId(cameraId);
  561. if(count <= 0){
  562. throw new BusinessException(LoginConstant.FAILURE_CODE_3030, LoginConstant.FAILURE_MSG_3030);
  563. }
  564. if(userId == null){
  565. throw new BusinessException(SceneConstant.FAILURE_CODE_5013, SceneConstant.FAILURE_MSG_5013);
  566. }
  567. //只能复制自己的场景
  568. User user = userService.getByUserName(userName);
  569. if(user == null || !user.getId().equals(userId) ){
  570. throw new BusinessException(SceneConstant.FAILURE_CODE_5013, SceneConstant.FAILURE_MSG_5013);
  571. }
  572. this.copySceneNoCheck(sceneNum);
  573. }
  574. @Override
  575. public void copySceneNoCheck(String sceneNum) throws Exception {
  576. ScenePro scenePro = this.getByNum(sceneNum);
  577. ScenePlus scenePlus = scenePlusService.getByNum(sceneNum);
  578. Long cameraId = scenePro == null ? scenePlus.getCameraId() : scenePro.getCameraId();
  579. CameraDetail detailEntity = cameraDetailService.getByCameraId(cameraId);
  580. if(detailEntity == null){
  581. throw new BusinessException(CameraConstant.FAILURE_CODE_6029, CameraConstant.FAILURE_MSG_6029);
  582. }
  583. String newNum = scene3dNumService.generateSceneNum(detailEntity.getType());
  584. String title = scenePro == null ? scenePlus.getTitle() : scenePro.getSceneName();
  585. String newTitle = title.concat("(copy)");
  586. Long sceneId = scenePro == null ? scenePlus.getId() :scenePro.getId();
  587. Long newSceneId = null;
  588. FolderScene folderScene = folderSceneService.getByType(sceneId, null);
  589. String time = DateUtil.date2String(new Date(),DateUtil.YYYYMMDDHHMMSSSSS_DATA_FORMAT);
  590. if(scenePro !=null){ //v3场景复制
  591. log.info("场景复制--V3--OldNum:{},oldTitle:{},newNum:{},newTitle:{}",
  592. scenePro.getNum(),scenePro.getSceneName(),newNum,newTitle);
  593. scenePro.setSceneName(newTitle);
  594. newSceneId = this.copyV3Scene(scenePro, newNum, detailEntity,time);
  595. }
  596. if(scenePlus != null){ //v4场景复制
  597. log.info("场景复制--V4--OldNum:{},oldTitle:{},newNum:{},newTitle:{}",
  598. scenePlus.getNum(),scenePlus.getTitle(),newNum,newTitle);
  599. scenePlus.setTitle(newTitle);
  600. newSceneId = scenePlusService.copyV4Scene(scenePlus,newNum,detailEntity,time);
  601. }
  602. log.info("场景复制--完成--sceneId:{}",newSceneId);
  603. if(newSceneId != null && folderScene!= null){
  604. folderScene.setId(null);
  605. folderScene.setSceneId(newSceneId);
  606. folderSceneService.save(folderScene);
  607. }
  608. }
  609. @Override
  610. public ScenePro getByNum(String sceneNum) {
  611. LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
  612. wrapper.eq(ScenePro::getNum,sceneNum);
  613. wrapper.eq(ScenePro::getIsUpgrade,0);
  614. List<ScenePro> list = this.list(wrapper);
  615. if(list!= null && list.size() >0){
  616. return list.get(0);
  617. }
  618. return null;
  619. }
  620. @Override
  621. public Long copyV3Scene(ScenePro oldScene,String newNum,CameraDetail cameraDetail,String time) throws Exception {
  622. SceneProEdit oldEditScene = sceneProEditService.getByProId(oldScene.getId());
  623. String oldNum = oldScene.getNum();
  624. //复制数据库数据
  625. oldScene.setId(null);
  626. oldScene.setStatus(0);
  627. oldScene.setNum(newNum);
  628. oldScene.setWebSite(oldScene.getWebSite().replace(oldNum, newNum));
  629. oldScene.setThumb(oldScene.getThumb().replace(oldNum, newNum));
  630. oldScene.setVideos(this.setVideos(oldScene.getVideos(),oldNum,newNum));
  631. oldScene.setViewCount(0);
  632. String preDataSource = oldScene.getDataSource();
  633. String newDataSource = this.setDataSource(preDataSource,time);
  634. oldScene.setDataSource(newDataSource);
  635. this.save(oldScene);
  636. if(oldScene.getSceneSource() == 4){ //深时复制
  637. laserService.copy(oldScene.getCameraId(),oldScene.getCreateTime(),newNum,0,null,
  638. oldEditScene.getSceneKey(),oldScene.getSceneName(),oldScene.getUserId(),"V3");
  639. }
  640. //更新video
  641. Map map = new HashMap();
  642. JSONObject object = new JSONObject();
  643. if(StringUtils.isNotEmpty(oldScene.getVideos())){
  644. object = JSONObject.parseObject(oldScene.getVideos());
  645. if(object.containsKey("upPath")){
  646. String upPath = object.getString("upPath");
  647. upPath = upPath.replace(oldNum,newNum);
  648. object.put("upPath",upPath);
  649. }
  650. oldScene.setVideos(object.toJSONString());
  651. log.info("更新 scene.json");
  652. map.put("videos",oldScene.getVideos());
  653. }
  654. map.put("sceneName",oldScene.getSceneName());
  655. map.put("webSite",oldScene.getWebSite());
  656. map.put("thumb",oldScene.getThumb());
  657. map.put("num",oldScene.getNum());
  658. map.put("id",oldScene.getId());
  659. map.put("dataSource",oldScene.getDataSource());
  660. //复制完成更新相机容量
  661. oldEditScene.setId(null);
  662. oldEditScene.setProId(oldScene.getId());
  663. oldEditScene.setScreencapVoiceSrc(oldEditScene.getScreencapVoiceSrc() == null ? null : oldEditScene.getScreencapVoiceSrc().replace(oldNum, newNum));
  664. oldEditScene.setScreencapVoiceSound(oldEditScene.getScreencapVoiceSound() == null ? null : oldEditScene.getScreencapVoiceSound().replace(oldNum, newNum));
  665. oldEditScene.setScreencapVoiceSoundsync(oldEditScene.getScreencapVoiceSoundsync() == null ? null : oldEditScene.getScreencapVoiceSoundsync().replace(oldNum, newNum));
  666. oldEditScene.setPlayData(oldEditScene.getPlayData() == null ? null : oldEditScene.getPlayData().replace(oldNum, newNum));
  667. oldEditScene.setScreencapThumb(oldEditScene.getScreencapThumb() == null ? null : oldEditScene.getScreencapThumb().replace(oldNum, newNum));
  668. oldEditScene.setFloorPlanPng(oldEditScene.getFloorPlanPng() == null ? null : oldEditScene.getFloorPlanPng().replace(oldNum, newNum));
  669. sceneProEditService.save(oldEditScene);
  670. this.setQrCode(oldScene.getBuildType(), oldScene.getNum());
  671. CompletableFuture.runAsync(() -> {
  672. try {
  673. log.info("开始复制场景-{}", new Date());
  674. String buildModelPath = ConstantFilePath.BUILD_MODEL_PATH;
  675. if(oldScene.getSceneSource().equals(4)){
  676. buildModelPath = ConstantFilePath.BUILD_MODEL_LASER_PATH;
  677. }
  678. this.copyFdage(preDataSource,newDataSource,buildModelPath,time);
  679. //oss复制计算结果资源
  680. downloadFromOldNumFromOss(oldNum, newNum);
  681. // 复制本地secen.json
  682. copyOldSceneLocalToNew(oldNum, newNum);
  683. FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + newNum + File.separator + "scene.json", map);
  684. //上传资源到oss
  685. uploadNewSceneToOss(newNum);
  686. FileUtils.delFolder(ConstantFilePath.SCENE_PATH + "images/images" + newNum);
  687. FileUtils.delFolder(ConstantFilePath.SCENE_PATH + "data/data" + newNum);
  688. FileUtils.delFolder(ConstantFilePath.SCENE_PATH + "voice/voice" + newNum);
  689. FileUtils.delFolder(ConstantFilePath.SCENE_PATH + "video/video" + newNum);
  690. FileUtils.copyDirectiory(ConstantFilePath.SCENE_PATH +"images/images" + oldNum,ConstantFilePath.SCENE_PATH +"images/images" + newNum);
  691. FileUtils.copyDirectiory(ConstantFilePath.SCENE_PATH +"data/data" + oldNum,ConstantFilePath.SCENE_PATH +"data/data" + newNum);
  692. FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + newNum + File.separator + "scene.json", map);
  693. reloadFile(ConstantFilePath.SCENE_PATH + "data/data" + newNum + "/link-scene.json",oldNum, newNum);
  694. reloadFile(ConstantFilePath.SCENE_PATH + "data/data" + newNum + "/hot.json",oldNum, newNum);
  695. FileUtils.copyDirectiory(ConstantFilePath.SCENE_PATH +"voice/voice" + oldNum,ConstantFilePath.SCENE_PATH +"voice/voice" + newNum);
  696. FileUtils.copyDirectiory(ConstantFilePath.SCENE_PATH +"video/video" + oldNum,ConstantFilePath.SCENE_PATH +"video/video" + newNum);
  697. oldScene.setStatus(-2);
  698. this.updateById(oldScene);
  699. log.info("复制场景结束-{}", new Date());
  700. if(oldScene.getSceneSource() == 4){ //深时复制
  701. String laserPath = laserService.copyDataSource(preDataSource,oldScene.getDataSource());
  702. laserService.copy(oldScene.getCameraId(),oldScene.getCreateTime(),newNum,2,laserPath,
  703. oldEditScene.getSceneKey(),oldScene.getSceneName(),oldScene.getUserId(),"V3");
  704. }
  705. sceneCopyLogService.saveByNum(oldNum,newNum,oldScene.getUserId());
  706. } catch (Exception e) {
  707. this.removeById(oldScene.getId());
  708. log.error("复制场景异常", e);
  709. }
  710. });
  711. return oldScene.getId();
  712. }
  713. /**
  714. * 从旧场景下载资源
  715. * @param sceneNum
  716. * @param newNum
  717. * @throws Exception
  718. */
  719. private void downloadFromOldNumFromOss(String sceneNum, String newNum) {
  720. ShellUtil.yunDownload("images/images" + sceneNum + "/", ConstantFilePath.SCENE_PATH + "images/images" + newNum);
  721. ShellUtil.yunDownload("data/data" + sceneNum + "/", ConstantFilePath.SCENE_PATH + "data/data" + newNum);
  722. ShellUtil.yunDownload("voice/voice" + sceneNum + "/", ConstantFilePath.SCENE_PATH + "voice/voice" + newNum);
  723. ShellUtil.yunDownload("video/video" + sceneNum + "/", ConstantFilePath.SCENE_PATH + "video/video" + newNum);
  724. }
  725. /**
  726. * 从本地旧场景拷贝资源到新场景
  727. * @param sceneNum
  728. * @param newNum
  729. */
  730. private void copyOldSceneLocalToNew(String sceneNum, String newNum) throws Exception {
  731. FileUtils.copyFolderAllFiles(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + "/",
  732. ConstantFilePath.SCENE_PATH + "data/data" + newNum + "/", true);
  733. reloadFile(ConstantFilePath.SCENE_PATH + "data/data" + newNum + "/link-scene.json",sceneNum, newNum);
  734. reloadFile(ConstantFilePath.SCENE_PATH + "data/data" + newNum + "/hot.json",sceneNum, newNum);
  735. }
  736. public void copyFdage(String oldDataSource,String newDataSource,String buildModelPath,String time) throws Exception {
  737. ShellUtil.yunDownload(ConstantFilePath.OSS_PREFIX + oldDataSource.replace(buildModelPath, "")+"/", newDataSource);
  738. // 修改data.fdage
  739. String data = FileUtils.readFile(newDataSource + "/data.fdage");
  740. JSONObject jsonObject = JSONObject.parseObject(data);
  741. if(ObjectUtils.isEmpty(jsonObject)){
  742. log.error("data.fdage文件不存在");
  743. throw new BusinessException(-1,"拷贝场景出错,data.fdage文件不存在");
  744. }
  745. jsonObject.put("uuidtime",time);
  746. FileUtils.writeFile(newDataSource + "/data.fdage", jsonObject.toJSONString());
  747. ShellUtil.yunUpload(newDataSource, ConstantFilePath.OSS_PREFIX + newDataSource.replace(buildModelPath, ""));
  748. // 复制计算结果
  749. ShellUtil.yunDownload(ConstantFilePath.OSS_PREFIX + oldDataSource.concat("_results/").replace(buildModelPath, ""), newDataSource.concat("_results"));
  750. if(new File(newDataSource.concat("_results")).exists()){
  751. ShellUtil.yunUpload(newDataSource.concat("_results"), ConstantFilePath.OSS_PREFIX + newDataSource.concat("_results").replace(buildModelPath, ""));
  752. FileUtils.delAllFile(newDataSource.concat("_results"));
  753. }
  754. FileUtils.delAllFile(newDataSource);
  755. try {
  756. FileUtils.copyFolderAllFiles(oldDataSource+"/",newDataSource+"/", true);
  757. }catch (Exception e){
  758. log.error("dataSource复制失败,{}不存在",oldDataSource);
  759. }
  760. }
  761. @Override
  762. public String setDataSource(String preDataSource,String time) throws Exception {
  763. SnowflakeIdGenerator snowflakeIdGenerator = new SnowflakeIdGenerator(0,1);
  764. String[] datasource = preDataSource.split("/");
  765. datasource[4] = snowflakeIdGenerator.nextId()+"";
  766. datasource[5] = datasource[5].split("_")[0] + "_" + time;
  767. return Arrays.stream(datasource).collect(Collectors.joining("/"));
  768. }
  769. @Override
  770. public String setVideos(String videos,String oldNum,String newNum) {
  771. JSONObject object = new JSONObject();
  772. if(StringUtils.isNotEmpty(videos)){
  773. object = JSONObject.parseObject(videos);
  774. if(object.containsKey("upPath")){
  775. String upPath = object.getString("upPath");
  776. upPath = upPath.replace(oldNum,newNum);
  777. object.put("upPath",upPath);
  778. }
  779. log.info("更新 scene.json");
  780. }
  781. return object.toJSONString();
  782. }
  783. private void reloadFile(String filePath,String sceneNum, String newNum) throws Exception {
  784. // 修改link-scene.json
  785. String content = FileUtils.readFile(filePath);
  786. if (!ObjectUtils.isEmpty(content)) {
  787. content = content.replaceAll(sceneNum, newNum);
  788. FileUtils.writeFile(filePath,content);
  789. }
  790. }
  791. /**
  792. * 上传新场景资源到oss
  793. * @param newNum
  794. */
  795. private void uploadNewSceneToOss(String newNum) {
  796. ShellUtil.yunUpload("/mnt/4Dkankan/scene/images/images" + newNum, "images/images" + newNum);
  797. ShellUtil.yunUpload("/mnt/4Dkankan/scene/data/data" + newNum, "data/data" + newNum);
  798. ShellUtil.yunUpload("/mnt/4Dkankan/scene/voice/voice" + newNum, "voice/voice" + newNum);
  799. ShellUtil.yunUpload("/mnt/4Dkankan/scene/video/video" + newNum, "video/video" + newNum);
  800. }
  801. @Override
  802. public void delete(String sceneNum) {
  803. if(StringUtils.isEmpty(sceneNum)){
  804. throw new BusinessException(LoginConstant.FAILURE_CODE_3001,LoginConstant.FAILURE_MSG_3001);
  805. }
  806. String[] nums = sceneNum.split(",");
  807. List<String> numList = Arrays.asList(nums);
  808. List<ScenePro> proList = this.getListByNums(numList);
  809. List<ScenePlus> plusList = scenePlusService.getListByNums(numList);
  810. this.deleteByList(proList,plusList);
  811. }
  812. @Override
  813. public void deleteByList(List<ScenePro> proList,List<ScenePlus> plusList) {
  814. HashMap<Long ,Long >cameraMap = new HashMap<>();
  815. if(proList.size() >0){
  816. for (ScenePro scenePro : proList) {
  817. cameraMap.merge(scenePro.getCameraId(), scenePro.getSpace(), Long::sum);
  818. }
  819. List<Long> proIds = proList.parallelStream().map(ScenePro::getId).collect(Collectors.toList());
  820. this.removeByIds(proIds);
  821. }
  822. if(plusList.size() >0){
  823. List<Long> plusIds = plusList.parallelStream().map(ScenePlus::getId).collect(Collectors.toList());
  824. HashMap<Long, ScenePlusExt> plusMap = scenePlusExtService.getByPlusIds(plusIds);
  825. for (ScenePlus scenePlus : plusList) {
  826. if(scenePlus.getCameraId()!= null && plusMap.get(scenePlus.getId())!=null){
  827. cameraMap.merge(scenePlus.getCameraId(), plusMap.get(scenePlus.getId()).getSpace(), Long::sum);
  828. }
  829. }
  830. scenePlusService.removeByIds(plusIds);
  831. scenePlusExtService.removeByPlusIds(plusIds);
  832. }
  833. //恢复相机使用容量
  834. if(cameraMap.size() >0){
  835. cameraDetailService.addUsedSpace(cameraMap);
  836. }
  837. }
  838. @Override
  839. public ScenePro getByUnicode(String unicode) {
  840. LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
  841. wrapper.like(ScenePro::getDataSource,unicode);
  842. wrapper.eq(ScenePro::getIsUpgrade,0);
  843. wrapper.orderByDesc(ScenePro::getCreateTime);
  844. List<ScenePro> list = this.list(wrapper);
  845. if(list !=null && list.size() >0){
  846. return list.get(0);
  847. }
  848. return null;
  849. }
  850. @Override
  851. public SceneInfoVo getInfo(String num) {
  852. if(StringUtils.isEmpty(num)){
  853. throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
  854. }
  855. ScenePro scenePro = this.getByNum(num);
  856. ScenePlus scenePlus = scenePlusService.getByNum(num);
  857. if(scenePro == null && scenePlus == null){
  858. throw new BusinessException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
  859. }
  860. if(scenePro!=null && scenePro.getStatus() != 1 && scenePro.getStatus() != -2){
  861. throw new BusinessException(SceneConstant.FAILURE_CODE_5033, SceneConstant.FAILURE_MSG_5033);
  862. }
  863. if(scenePlus!=null && scenePlus.getSceneStatus() != 1 && scenePlus.getSceneStatus() != -2){
  864. throw new BusinessException(SceneConstant.FAILURE_CODE_5033, SceneConstant.FAILURE_MSG_5033);
  865. }
  866. if(scenePro!=null && scenePro.getPayStatus() != 1){
  867. throw new BusinessException(SceneConstant.FAILURE_CODE_5034, SceneConstant.FAILURE_MSG_5034);
  868. }
  869. if(scenePlus!=null && scenePlus.getPayStatus() != 1){
  870. throw new BusinessException(SceneConstant.FAILURE_CODE_5034, SceneConstant.FAILURE_MSG_5034);
  871. }
  872. SceneInfoVo infoVo = new SceneInfoVo();
  873. if(scenePro!=null){
  874. SceneProEdit sceneProEdit = sceneProEditService.getByProId(scenePro.getId());
  875. if(sceneProEdit !=null){
  876. BeanUtils.copyProperties(sceneProEdit, infoVo);
  877. }
  878. BeanUtils.copyProperties(scenePro,infoVo);
  879. if(StringUtils.isNotEmpty(scenePro.getGps())){
  880. infoVo.setGps(JSONObject.parseObject(scenePro.getGps()).toJSONString());
  881. }
  882. infoVo.setSceneKey("");
  883. infoVo.setCreateDate(DateUserUtil.getDate(scenePro.getCreateTime()).getTime());
  884. }else {
  885. SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
  886. ScenePlusExt scenePlusExt = scenePlusExtService.getByPlusId(scenePlus.getId());
  887. if(sceneEditInfo != null){
  888. BeanUtils.copyProperties(sceneEditInfo,infoVo);
  889. }
  890. if(scenePlusExt !=null){
  891. BeanUtils.copyProperties(scenePlusExt,infoVo);
  892. }
  893. BeanUtils.copyProperties(scenePlus,infoVo);
  894. infoVo.setSceneName(scenePlus.getTitle());
  895. infoVo.setStatus(scenePlus.getSceneStatus());
  896. }
  897. if(StringUtils.isNotEmpty(infoVo.getEntry())){
  898. infoVo.setEntry(JSONObject.parseObject(infoVo.getEntry()).toJSONString());
  899. }
  900. if(StringUtils.isEmpty(infoVo.getSceneKey())){
  901. infoVo.setIsPublic(0);
  902. }else {
  903. infoVo.setIsPublic(1);
  904. }
  905. //查询是否有随心装场景
  906. if(num.contains("vr-")){
  907. infoVo.setVrNum(null);
  908. infoVo.setVideosUser(null);
  909. infoVo.setBgMusicName(null);
  910. infoVo.setBgMusic(null);
  911. }
  912. infoVo.setSceneVer(innerService.getSceneNumVersion(num));
  913. infoVo.setVersion(infoVo.getSceneVer());
  914. this.updateViewCount(num);
  915. return infoVo;
  916. }
  917. @Override
  918. public void updateViewCount(String num) {
  919. String redisKey = RedisKey.SCENE_VISIT_CNT;
  920. if(!redisUtil.hHasKey(redisKey,num)){
  921. Integer count = 0;
  922. ScenePro pro = this.getByNum(num);
  923. if(pro !=null){
  924. count = pro.getViewCount() == null ? 0 : pro.getViewCount();
  925. }else {
  926. ScenePlus plus = scenePlusService.getByNum(num);
  927. if(plus !=null){
  928. ScenePlusExt scenePlusExt = scenePlusExtService.getByPlusId(plus.getId());
  929. if(scenePlusExt != null){
  930. count = scenePlusExt.getViewCount() == null ? 0 :scenePlusExt.getViewCount();
  931. }
  932. }
  933. }
  934. redisUtil.hset(redisKey,num,String.valueOf(count));
  935. }
  936. redisUtil.hincr(redisKey,num,1);
  937. }
  938. @Override
  939. public void updateDbViewCount(String num, String count) {
  940. LambdaUpdateWrapper<ScenePro> wrapper = new LambdaUpdateWrapper<>();
  941. wrapper.eq(ScenePro::getNum,num);
  942. wrapper.set(ScenePro::getViewCount,count);
  943. this.update(wrapper);
  944. ScenePlus plus = scenePlusService.getByNum(num);
  945. if(plus !=null){
  946. LambdaUpdateWrapper<ScenePlusExt> exWr = new LambdaUpdateWrapper<>();
  947. exWr.eq(ScenePlusExt::getPlusId,plus.getId())
  948. .set(ScenePlusExt::getViewCount,count);
  949. scenePlusExtService.update(exWr);
  950. }
  951. }
  952. @Override
  953. public ScenePro findByFileId(String fileId) {
  954. LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
  955. wrapper.like(ScenePro::getDataSource,fileId);
  956. List<ScenePro> list = this.list(wrapper);
  957. if(list !=null && list.size() >0){
  958. return list.get(0);
  959. }
  960. return null;
  961. }
  962. @Override
  963. public void setQrCode(String buildType,String num) throws Exception {
  964. String basePath = mainUrl;
  965. if("V2".equals(buildType)){
  966. basePath += sceneProUrl;
  967. }
  968. if("V3".equals(buildType)){
  969. basePath += sceneProNewUrl;
  970. }
  971. MatrixToImageWriterUtil.createQRCode(basePath + num, ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+num+".png", false,null);
  972. MatrixToImageWriterUtil.createQRCode(basePath + num + "&lang=en", ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+num+"_en.png", false,null);
  973. }
  974. @Override
  975. public void generateObjFile(String num) {
  976. LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
  977. wrapper.eq(ScenePro::getNum,num).eq(ScenePro::getRecStatus,"A");
  978. ScenePro sceneProEntity = this.getOne(wrapper);
  979. if(ObjectUtils.isEmpty(sceneProEntity)){
  980. generatePlusObjFile(num);
  981. return;
  982. }
  983. if(sceneProEntity.getSceneSource() != 4){
  984. throw new BusinessException(LoginConstant.FAILURE_CODE_3003, "只能操作激光场景");
  985. }
  986. // 拷贝文件
  987. String path = sceneProEntity.getDataSource();
  988. if (!new File(path + "/caches/reconstruction/final.bin").exists()
  989. || !new File(path + "/caches/reconstruction/chunk.json").exists()
  990. || !new File(path + "/caches/images").exists()
  991. || !new File(path + "/caches/depthmap").exists()
  992. || !new File(path + "/caches/depthmap_csc").exists()
  993. || !new File(path + "/caches/panorama.json").exists()
  994. || !new File(path + "/results/laserData/laser.ply").exists()) {
  995. log.error("生成obj缺少必要文件,生成失败!");
  996. throw new BusinessException(SceneConstant.FAILURE_CODE_5038, SceneConstant.FAILURE_MSG_5038);
  997. }
  998. // 获取最新的场景名称
  999. JSONObject sceneInfo = fdkkLaserService.getSceneByNum(sceneProEntity.getNum());
  1000. LambdaUpdateWrapper<ScenePro> updateWrapper = new LambdaUpdateWrapper<>();
  1001. updateWrapper
  1002. .set(ScenePro::getStatus, 0)
  1003. .set(ScenePro::getIsObj, 1)
  1004. .set(ScenePro::getIsUpgrade, 2) // 升级中
  1005. .set(ScenePro::getSceneName, sceneInfo.getString("title"))
  1006. .eq(ScenePro::getNum, sceneProEntity.getNum());
  1007. this.update(updateWrapper);
  1008. //同步到scenePlus、scenePlus
  1009. //同步到scenePlus、scenePlus
  1010. ScenePlus scenePlus = scenePlusService.getByNum(num);
  1011. if(Objects.nonNull(scenePlus)){
  1012. sceneUpgradeMapper.deleteScenePlus(num);
  1013. sceneUpgradeMapper.deleteScenePlusExt(scenePlus.getId());
  1014. }
  1015. sceneUpgradeMapper.transferScenePlus(num);
  1016. scenePlus = scenePlusService.getByNum(num);
  1017. String sceneKind = sceneProEntity.getSceneScheme() == 3 ? SceneKind.FACE.code():SceneKind.TILES.code();
  1018. sceneUpgradeMapper.transferScenePlusExt(num, scenePlus.getId(), sceneKind);
  1019. log.info("开始发送激光场景生成obj mq消息");
  1020. // 发送MQ
  1021. BuildSceneCallMessage mqMsg = new BuildSceneCallMessage();
  1022. mqMsg.setSceneNum(sceneProEntity.getNum());
  1023. mqMsg.setAlgorithm(sceneProEntity.getAlgorithm());
  1024. mqMsg.setBuildType(sceneProEntity.getBuildType());
  1025. mqMsg.setPath(sceneProEntity.getDataSource());
  1026. mqProducer.sendByWorkQueue(queueObjModelingPre,mqMsg);
  1027. }
  1028. public void generatePlusObjFile(String num) {
  1029. ScenePlus scenePlus = scenePlusService.getByNum(num);
  1030. if(ObjectUtils.isEmpty(scenePlus)){
  1031. throw new BusinessException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
  1032. }
  1033. if(scenePlus.getSceneSource() != 4){
  1034. throw new BusinessException(LoginConstant.FAILURE_CODE_3003, "只能操作激光场景");
  1035. }
  1036. ScenePlusExt scenePlusExt = scenePlusExtService.getByPlusId(scenePlus.getId());
  1037. // 拷贝文件
  1038. String path = scenePlusExt.getDataSource();
  1039. if (!new File(path + "/caches/reconstruction/final.bin").exists()
  1040. || !new File(path + "/caches/reconstruction/chunk.json").exists()
  1041. || !new File(path + "/caches/images").exists()
  1042. || !new File(path + "/caches/depthmap").exists()
  1043. || !new File(path + "/caches/depthmap_csc").exists()
  1044. || !new File(path + "/caches/panorama.json").exists()
  1045. || !new File(path + "/results/laserData/laser.ply").exists()) {
  1046. log.error("生成obj缺少必要文件,生成失败!");
  1047. throw new BusinessException(SceneConstant.FAILURE_CODE_5038, SceneConstant.FAILURE_MSG_5038);
  1048. }
  1049. // 获取最新的场景名称
  1050. JSONObject sceneInfo = fdkkLaserService.getSceneByNum(num);
  1051. LambdaUpdateWrapper<ScenePlus> updateWrapper = new LambdaUpdateWrapper<>();
  1052. updateWrapper
  1053. .set(ScenePlus::getSceneStatus, 0)
  1054. .set(ScenePlus::getTitle, sceneInfo.getString("title"))
  1055. .eq(ScenePlus::getNum, num);
  1056. scenePlusService.update(updateWrapper);
  1057. LambdaUpdateWrapper<ScenePlusExt> plusExtUpdateWrapper = new LambdaUpdateWrapper<>();
  1058. plusExtUpdateWrapper
  1059. .set(ScenePlusExt::getIsObj, 1)
  1060. .eq(ScenePlusExt::getPlusId, scenePlus.getId());
  1061. scenePlusExtService.update(plusExtUpdateWrapper);
  1062. log.info("开始发送激光场景生成obj mq消息");
  1063. // 发送MQ
  1064. BuildSceneCallMessage mqMsg = new BuildSceneCallMessage();
  1065. mqMsg.setSceneNum(num);
  1066. mqMsg.setAlgorithm(scenePlusExt.getAlgorithm());
  1067. mqMsg.setBuildType(scenePlusExt.getBuildType());
  1068. mqMsg.setPath(scenePlusExt.getDataSource());
  1069. mqProducer.sendByWorkQueue(queueObjModelingPre,mqMsg);
  1070. }
  1071. @Override
  1072. public ResponseScene getSceneDetail(String sceneNum) {
  1073. if(StringUtils.isBlank(sceneNum)){
  1074. return null;
  1075. }
  1076. ResponseScene vo = new ResponseScene();
  1077. Scene sceneEntity = sceneService.getByNum(sceneNum);
  1078. if(sceneEntity != null){
  1079. return getResponseScene(vo, sceneEntity);
  1080. }
  1081. ScenePro sceneProEntity = this.getByNum(sceneNum);
  1082. if(sceneProEntity != null){
  1083. SceneProEdit sceneProEditEntity = sceneProEditService.getByProId(sceneProEntity.getId());
  1084. return getResponseProScene(vo, sceneProEntity, sceneProEditEntity);
  1085. }
  1086. ScenePlus scenePlus = scenePlusService.getByNum(sceneNum);
  1087. if(scenePlus != null){
  1088. ScenePlusExt ext = scenePlusExtService.getByPlusId(scenePlus.getId());
  1089. SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
  1090. return getResponseProScene(vo, scenePlus, ext,sceneEditInfo);
  1091. }
  1092. return vo;
  1093. }
  1094. private ResponseScene getResponseScene(ResponseScene vo, Scene sceneEntity) {
  1095. if (sceneEntity != null){
  1096. BeanUtils.copyProperties(sceneEntity, vo);
  1097. vo.setThumbImg(sceneEntity.getThumbStatus());
  1098. vo.setCreateTime(new DateTime(sceneEntity.getCreateTime()).toString("yyyy-MM-dd HH:mm"));
  1099. vo.setSceneIndex(sceneEntity.getStyle());
  1100. vo.setHasBGM(sceneEntity.getBgMusic());
  1101. vo.setCameraType(sceneEntity.getSceneScheme());
  1102. vo.setIsPublic(StringUtils.isEmpty(sceneEntity.getSceneKey()) ? 0 : 1);
  1103. }
  1104. return vo;
  1105. }
  1106. private ResponseScene getResponseProScene(ResponseScene vo, ScenePro sceneProEntity, SceneProEdit sceneProEditEntity) {
  1107. if (sceneProEntity != null){
  1108. BeanUtils.copyProperties(sceneProEditEntity, vo);
  1109. BeanUtils.copyProperties(sceneProEntity, vo);
  1110. vo.setCreateTime(DateUserUtil.getMDate(vo.getCreateTime()));
  1111. vo.setCameraType(sceneProEntity.getSceneScheme());
  1112. vo.setThumbImg(sceneProEditEntity.getThumbStatus());
  1113. vo.setHasBGM(sceneProEditEntity.getBgMusic());
  1114. vo.setIsPublic(StringUtils.isEmpty(sceneProEditEntity.getSceneKey()) ? 0 : 1);
  1115. }
  1116. return vo;
  1117. }
  1118. private ResponseScene getResponseProScene(ResponseScene vo, ScenePlus plus, ScenePlusExt ext,SceneEditInfo editInfo) {
  1119. if (plus != null){
  1120. BeanUtils.copyProperties(plus, vo);
  1121. BeanUtils.copyProperties(ext, vo);
  1122. BeanUtils.copyProperties(editInfo, vo);
  1123. vo.setNum(plus.getNum());
  1124. vo.setSceneName(plus.getTitle());
  1125. vo.setCreateTime(DateUserUtil.getMDate(vo.getCreateTime()));
  1126. vo.setCameraType(ext.getSceneScheme());
  1127. vo.setThumbImg(1);
  1128. vo.setHasBGM(editInfo.getMusic());
  1129. vo.setIsPublic(StringUtils.isEmpty(editInfo.getScenePassword()) ? 0 : 1);
  1130. }
  1131. return vo;
  1132. }
  1133. }