SceneProServiceImpl.java 53 KB

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