SceneFileBuildServiceImpl.java 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  1. package com.fdkankan.contro.service.impl;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import cn.hutool.core.collection.CollUtil;
  4. import cn.hutool.core.date.DateUtil;
  5. import cn.hutool.core.util.StrUtil;
  6. import com.alibaba.fastjson.JSONObject;
  7. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  8. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  9. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  10. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  11. import com.fdkankan.common.constant.*;
  12. import com.fdkankan.common.exception.BusinessException;
  13. import com.fdkankan.common.util.DateExtUtil;
  14. import com.fdkankan.common.util.FileUtils;
  15. import com.fdkankan.common.util.SnowflakeIdGenerator;
  16. import com.fdkankan.contro.constant.RedisConstants;
  17. import com.fdkankan.contro.entity.*;
  18. import com.fdkankan.contro.mapper.ISceneFileBuildMapper;
  19. import com.fdkankan.contro.service.*;
  20. import com.fdkankan.contro.vo.ResponseSceneFile;
  21. import com.fdkankan.contro.vo.ScenePlusVO;
  22. import com.fdkankan.fyun.config.FYunFileConfig;
  23. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  24. import com.fdkankan.model.constants.ConstantFilePath;
  25. import com.fdkankan.model.constants.UploadFilePath;
  26. import com.fdkankan.rabbitmq.bean.BuildSceneCallMessage;
  27. import com.fdkankan.rabbitmq.util.RabbitMqProducer;
  28. import com.fdkankan.redis.util.RedisUtil;
  29. import com.fdkankan.web.response.ResultData;
  30. import com.fdkankan.web.util.RSAEncrypt;
  31. import lombok.extern.slf4j.Slf4j;
  32. import org.apache.commons.codec.binary.Base64;
  33. import org.apache.commons.lang3.StringUtils;
  34. import org.springframework.beans.factory.annotation.Autowired;
  35. import org.springframework.beans.factory.annotation.Value;
  36. import org.springframework.stereotype.Service;
  37. import org.springframework.util.ObjectUtils;
  38. import java.io.File;
  39. import java.io.IOException;
  40. import java.nio.charset.StandardCharsets;
  41. import java.util.Calendar;
  42. import java.util.List;
  43. import java.util.Objects;
  44. /**
  45. * <p>
  46. * 场景文件建模表 服务实现类
  47. * </p>
  48. *
  49. * @author dengsixing
  50. * @since 2021-12-23
  51. */
  52. @Slf4j
  53. @Service
  54. public class SceneFileBuildServiceImpl extends ServiceImpl<ISceneFileBuildMapper, SceneFileBuild> implements ISceneFileBuildService {
  55. private static final String SPLICE = "#";
  56. @Value("${main.url}")
  57. private String mainUrl;
  58. @Value("${scene.pro.new.url}")
  59. private String sceneProNewUrl;
  60. @Value("${queue.modeling.modeling-pre}")
  61. private String queueModelingPre;
  62. @Autowired
  63. private RedisUtil redisUtil;
  64. @Autowired
  65. private IScenePlusExtService scenePlusExtService;
  66. @Autowired
  67. private IScene3dNumService scene3dNumService;
  68. @Autowired
  69. private IScenePlusService scenePlusService;
  70. @Autowired
  71. private RabbitMqProducer rabbitMqProducer;
  72. @Autowired
  73. private ISceneEditInfoService sceneEditInfoService;
  74. @Autowired
  75. private ISceneEditControlsService sceneEditControlsService;
  76. @Autowired
  77. private ISceneEditInfoExtService sceneEditInfoExtService;
  78. @Autowired
  79. private ISceneCooperationService sceneCooperationService;
  80. @Autowired
  81. private ISceneResourceCameraService sceneResourceCameraService;
  82. @Autowired
  83. private ISceneResourceCooperationService sceneResourceCooperationService;
  84. @Autowired
  85. private ICameraService cameraService;
  86. @Autowired
  87. private ICameraDetailService cameraDetailService;
  88. @Autowired
  89. private IUserService userService;
  90. @Autowired
  91. private ICompanyService companyService;
  92. @Autowired
  93. private FYunFileServiceInterface fYunFileService;
  94. @Autowired
  95. private FYunFileConfig fYunFileConfig;
  96. @Override
  97. public SceneFileBuild findByFileId(String fileId) {
  98. List<SceneFileBuild> list = this.list(new LambdaQueryWrapper<SceneFileBuild>().eq(SceneFileBuild::getFileId, fileId)
  99. .orderByDesc(SceneFileBuild::getId));
  100. if(CollUtil.isEmpty(list)){
  101. return null;
  102. }
  103. return list.get(0);
  104. }
  105. @Override
  106. public ResponseSceneFile preUpload(String params) throws Exception {
  107. log.info("preUpload-params: "+params);
  108. if (StrUtil.isEmpty(params)){
  109. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  110. }
  111. params = params.replaceAll("%2B", "+");
  112. Base64 base64 = new Base64();
  113. String cipher = params;
  114. // 私钥解密过程
  115. byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
  116. base64.decode(cipher));
  117. String restr = new String(res, "UTF-8");
  118. log.debug("preUpload-params解密结果:" + restr);
  119. String[] strArr = restr.split(SPLICE);
  120. if (strArr.length != 5) {
  121. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  122. }
  123. String mac = strArr[0];
  124. String totalPicNum = strArr[1];
  125. String chunks = strArr[2];
  126. String folderName = strArr[3];
  127. if (StrUtil.isEmpty(mac)){
  128. throw new BusinessException(ErrorCode.FAILURE_CODE_5044);
  129. }
  130. if (totalPicNum == null){
  131. throw new BusinessException(ErrorCode.FAILURE_CODE_5045);
  132. }
  133. if (chunks == null){
  134. throw new BusinessException(ErrorCode.FAILURE_CODE_5046);
  135. }
  136. if (folderName == null){
  137. throw new BusinessException(ErrorCode.FAILURE_CODE_5047);
  138. }
  139. log.info("mac:{} 准备上传文件,folderName:{}", mac, folderName);
  140. ResponseSceneFile responseSceneFile = new ResponseSceneFile();
  141. // 检测是否有生成
  142. String fileId = redisUtil.get(String.format(RedisConstants.FOLDER_FILEID_BUILD, folderName));
  143. if (!ObjectUtils.isEmpty(fileId)) {
  144. responseSceneFile.setFileId(fileId);
  145. return responseSceneFile;
  146. }
  147. SceneFileBuild sceneFileBuild = this.findByUnicode(folderName);
  148. if (sceneFileBuild != null) {
  149. fileId = sceneFileBuild.getFileId();
  150. responseSceneFile.setFileId(fileId);
  151. redisUtil.set(String.format(RedisConstants.FOLDER_FILEID_BUILD, folderName), fileId, 2 * 24 * 60 * 60);
  152. return responseSceneFile;
  153. }
  154. // 加锁
  155. long incr = redisUtil.incr(String.format(RedisConstants.FOLDER_LOCK_BUILD, folderName), 1);
  156. if (incr > 1) {
  157. throw new BusinessException(ErrorCode.FAILURE_CODE_5052);
  158. }
  159. redisUtil.expire(String.format(RedisConstants.FOLDER_LOCK_BUILD, folderName), 120);
  160. log.info("开始新生成build数据");
  161. fileId = new SnowflakeIdGenerator(0, 0).nextId() + "";
  162. log.info("新生成build数据,{}", fileId);
  163. sceneFileBuild = new SceneFileBuild();
  164. sceneFileBuild.setChildName(mac);
  165. sceneFileBuild.setFileId(fileId);
  166. sceneFileBuild.setUnicode(folderName);
  167. sceneFileBuild.setTotalPicNum(Integer.valueOf(totalPicNum));
  168. sceneFileBuild.setChunks(Integer.valueOf(chunks));
  169. this.save(sceneFileBuild);
  170. redisUtil.set(String.format(RedisConstants.FOLDER_FILEID_BUILD, folderName), fileId, 2 * 24 * 60 * 60);
  171. redisUtil.set(String.format(RedisConstants.FILEID_FOLDER_BUILD, fileId), folderName, 2 * 24 * 60 * 60);
  172. responseSceneFile.setFileId(fileId);
  173. return responseSceneFile;
  174. }
  175. public SceneFileBuild findByUnicode(String unicode) {
  176. List<SceneFileBuild> list = this.list(new QueryWrapper<SceneFileBuild>()
  177. .eq("unicode", unicode)
  178. .orderByDesc("id"));
  179. if(CollUtil.isEmpty(list))
  180. return null;
  181. return list.get(0);
  182. }
  183. public ScenePlusVO buildScene(String fileId, String prefix,JSONObject jsonObject,String buildType,long cameraType) throws Exception{
  184. //调用createScene方法生成scene数据和加入算法队列
  185. String sceneNum = "";
  186. String cameraName = jsonObject.getJSONObject("cam").getString("uuid");
  187. String unicode = jsonObject.getString("creator") + "_" + jsonObject.getString("uuidtime");
  188. Camera camera = cameraService.getByChildName(cameraName);
  189. if (camera == null) {
  190. throw new BusinessException(CameraConstant.FAILURE_6003);
  191. }
  192. CameraDetail cameraDetail = cameraDetailService.getByCameraId(camera.getId());
  193. if (cameraDetail == null) {
  194. log.error("该相机详情不存在:" + cameraName);
  195. throw new BusinessException(CameraConstant.FAILURE_6003);
  196. }
  197. //查看场景中的文件目录是否有改文件id,有则重新计算改场景,无则新建场景
  198. ScenePlus scenePlus = scenePlusService.getByFileId("/" + fileId + "/");
  199. int rebuild = 1;
  200. if (ObjectUtils.isEmpty(scenePlus)) {
  201. sceneNum = scene3dNumService.generateSceneNum(cameraDetail.getType());
  202. rebuild = 0;
  203. } else {
  204. sceneNum = scenePlus.getNum();
  205. if (scenePlus.getSceneStatus().equals(SceneStatus.wait.code())) {
  206. log.info(scenePlus.getNum() + ":场景处于计算中,不能再计算");
  207. return null;
  208. }
  209. }
  210. if (sceneNum == null) {
  211. log.error("大场景序号为空:" + sceneNum);
  212. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  213. }
  214. String localDataPath = String.format(ConstantFilePath.DATABUFFER_FORMAT, sceneNum);
  215. String imgViewPath = String.format(UploadFilePath.IMG_VIEW_PATH, sceneNum);
  216. String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, sceneNum);
  217. String userName = null;
  218. if (!ObjectUtils.isEmpty(cameraDetail.getUserId())) {
  219. SSOUser user = userService.getSSOUserByUserId(cameraDetail.getUserId());
  220. userName = ObjectUtils.isEmpty(user) ? null : user.getUserName();
  221. }
  222. String icon = null;
  223. if (!ObjectUtils.isEmpty(jsonObject.getString("icon"))) {
  224. fYunFileService.copyFileInBucket(ConstantFilePath.OSS_PREFIX + prefix + jsonObject.getString("icon"),imgViewPath + jsonObject.getString("icon"));
  225. icon = fYunFileConfig.getHost() + imgViewPath + jsonObject.getString("icon");
  226. log.info("上传icon成功....");
  227. }
  228. JSONObject firmwareVersion = new JSONObject();
  229. if (!ObjectUtils.isEmpty(jsonObject.getString("camSoftwareVersion"))) {
  230. firmwareVersion.put("camSoftwareVersion", jsonObject.getString("camSoftwareVersion"));
  231. }
  232. if (!ObjectUtils.isEmpty(jsonObject.getString("version"))) {
  233. firmwareVersion.put("version", jsonObject.getString("version"));
  234. }
  235. String sceneUrl = mainUrl + "/" + sceneProNewUrl;
  236. //重算的场景,先移除该场景对应的容量
  237. if (rebuild == 1) {
  238. scenePlusService.resetSpace(sceneNum);
  239. //删除oss的houst_floor.json(国际版可能会卡住)
  240. fYunFileService.deleteFile(dataViewPath + "houst_floor.json");
  241. } else {
  242. //上传log-main.png
  243. fYunFileService.uploadFile(ConstantFilePath.LOGO_PATH + "logo-main.png", imgViewPath + "logo-main.png");
  244. fYunFileService.uploadFile(ConstantFilePath.LOGO_PATH + "logo-main-en.png", imgViewPath + "logo-main-en.png");
  245. }
  246. String algorithm = jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam";
  247. ScenePlusVO scenePlusVO = this.createScenePlus(sceneNum, camera.getId(), camera.getChildName(), jsonObject.getString("creator"),
  248. jsonObject.getString("pwd"), unicode,cameraType, fileId, icon, cameraDetail.getUserId(), userName,algorithm,
  249. jsonObject.getJSONArray("points").size(), jsonObject.getString("name"), jsonObject.getString("info"),
  250. jsonObject.getInteger("scenetype"), jsonObject.getString("gps"), rebuild,
  251. jsonObject.getInteger("resolution"), firmwareVersion.toString(), sceneUrl, buildType, cameraDetail.getCooperationUser());
  252. if (Objects.nonNull(scenePlusVO)) {
  253. JSONObject statusJson = new JSONObject();
  254. //临时将-2改成1,app还没完全更新
  255. statusJson.put("status", scenePlusVO.getSceneStatus() == -2 ? 1 : scenePlusVO.getSceneStatus());
  256. statusJson.put("webSite", scenePlusVO.getWebSite());
  257. statusJson.put("sceneNum", scenePlusVO.getNum());
  258. statusJson.put("thumb", scenePlusVO.getThumb());
  259. statusJson.put("payStatus", 0);
  260. statusJson.put("recStatus", 'A');
  261. FileUtils.writeFile(localDataPath + "status.json", statusJson.toString());
  262. fYunFileService.uploadFile(localDataPath + "status.json", dataViewPath + "status.json");
  263. }
  264. BuildSceneCallMessage mqMessage = getBuildSceneMqMessage(sceneNum, cameraType, algorithm, jsonObject.getInteger("resolution"), buildType,
  265. scenePlusVO.getDataSource());
  266. if (cameraDetail.getCompanyId() != null) {
  267. Company company = companyService.getById(cameraDetail.getCompanyId());
  268. if (company != null && !ObjectUtils.isEmpty(company.getCalculateFlexibility()) && !company.getCalculateFlexibility()) {
  269. mqMessage.setFlexibility(-1);
  270. }
  271. }
  272. rabbitMqProducer.sendByWorkQueue(queueModelingPre, mqMessage);
  273. return scenePlusVO;
  274. }
  275. @Override
  276. public ResultData uploadSuccessBuild(String params) throws Exception {
  277. log.info("uploadSuccessBuild-params: " + params);
  278. if (StringUtils.isEmpty(params)) {
  279. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  280. }
  281. params = params.replaceAll("%2B", "+");
  282. params = params.replaceAll(" ", "+");
  283. Base64 base64 = new Base64();
  284. String cipher = params;
  285. // 私钥解密过程
  286. byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()), base64.decode(cipher));
  287. String restr = new String(res, "UTF-8");
  288. log.info("uploadSuccessBuild-params解密结果:" + restr);
  289. String[] strArr = restr.split(SPLICE);
  290. if (strArr.length != 3) {
  291. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  292. }
  293. String mac = strArr[0];
  294. String fileId = strArr[1];
  295. String folderName = redisUtil.get(String.format(RedisConstants.FILEID_FOLDER_BUILD, fileId));
  296. if(StringUtils.isEmpty(folderName)){
  297. SceneFileBuild fileBuild = findByFileId(fileId);
  298. if(ObjectUtils.isEmpty(fileBuild)){
  299. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  300. }
  301. folderName = fileBuild.getUnicode();
  302. redisUtil.set(String.format(RedisConstants.FILEID_FOLDER_BUILD, fileId), folderName,2 * 24 * 60 * 60);
  303. }
  304. StringBuilder prefixBuffer = new StringBuilder(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator);
  305. String buildType = "V2";
  306. Long cameraType = 10L;
  307. JSONObject fdageJson = JSONObject.parseObject(fYunFileService.getFileContent(ConstantFilePath.OSS_PREFIX + prefixBuffer + "data.fdage"));
  308. if(ObjectUtils.isEmpty(fdageJson)){
  309. log.info("data.fdage文件不存在");
  310. throw new BusinessException(CameraConstant.FAILURE_6009);
  311. }
  312. //根据videoVersion判断是V2还是V3版本的算法和页面
  313. if (fdageJson.containsKey("videoVersion") && StrUtil.isNotEmpty(fdageJson.getString("videoVersion"))) {
  314. if (fdageJson.getIntValue("videoVersion") >= 4) {
  315. buildType = "V3";
  316. cameraType = 11L;
  317. }
  318. }
  319. buildScene(fileId, prefixBuffer.toString(),fdageJson,buildType,cameraType);
  320. return ResultData.ok();
  321. }
  322. @Override
  323. public ResultData turntableUploadSuccess(String params) throws Exception {
  324. log.info("turntableUploadSuccess-params: " + params);
  325. if (StringUtils.isEmpty(params)) {
  326. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  327. }
  328. params = params.replaceAll("%2B", "+");
  329. params = params.replaceAll(" ", "+");
  330. Base64 base64 = new Base64();
  331. String cipher = params;
  332. // 私钥解密过程
  333. byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
  334. base64.decode(cipher));
  335. String restr = new String(res, "UTF-8");
  336. log.info("uploadSuccessBuild-params解密结果:" + restr);
  337. String[] strArr = restr.split(SPLICE);
  338. if (strArr.length != 3) {
  339. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  340. }
  341. String mac = strArr[0];
  342. String fileId = strArr[1];
  343. String folderName = redisUtil.get(String.format(RedisConstants.FILEID_FOLDER_BUILD, fileId));
  344. if(StringUtils.isEmpty(folderName)){
  345. SceneFileBuild fileBuild = findByFileId(fileId);
  346. if(ObjectUtils.isEmpty(fileBuild)){
  347. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  348. }
  349. folderName = fileBuild.getUnicode();
  350. redisUtil.set(String.format(RedisConstants.FILEID_FOLDER_BUILD, fileId), folderName);
  351. }
  352. //云目录
  353. StringBuilder prefixBuffer = new StringBuilder(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator);
  354. JSONObject fdageJson = JSONObject.parseObject(fYunFileService.getFileContent(ConstantFilePath.OSS_PREFIX + prefixBuffer + "data.fdage"));
  355. if(ObjectUtils.isEmpty(fdageJson)){
  356. log.info("data.fdage文件不存在");
  357. throw new BusinessException(CameraConstant.FAILURE_6009);
  358. }
  359. String buildType = "V3";
  360. //13表示转台
  361. Long cameraType = 13L;
  362. //激光转台 八目相机占用 10 和 11
  363. if(fdageJson.getJSONObject("cam").getIntValue("type") == 10){
  364. //激光转台
  365. cameraType = 14L;
  366. }
  367. ScenePlusVO scenePlusVO = buildScene(fileId, prefixBuffer.toString(), fdageJson, buildType, cameraType);
  368. if(ObjectUtils.isEmpty(scenePlusVO)){
  369. return ResultData.ok();
  370. }
  371. // 通知激光场景系统开始构建场景
  372. if(cameraType.longValue() == 14){
  373. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(scenePlusVO.getNum());
  374. Long sceneUserId = scenePlus.getUserId();
  375. String userName = null;
  376. if(!ObjectUtils.isEmpty(sceneUserId)){
  377. userName = userService.getSSOUserByUserId(sceneUserId).getUserName();
  378. }
  379. //判断 是否为激光相机
  380. Camera camera = cameraService.getByChildName(mac);
  381. }
  382. return ResultData.ok();
  383. }
  384. public ScenePlusVO createScenePlus(String projectNum, Long cameraId, String cameraName, String phoneId, String sceneKey,
  385. String unicode, Long cameraType, String fileId, String pic, Long userId, String userName,
  386. String algorithm, Integer sceneShootCount, String sceneName,
  387. String sceneDec, Integer sceneType, String gps,Integer type,
  388. Integer resolution, String firmwareVersion, String url, String buildType,
  389. Long cooperationUser)throws Exception{
  390. ScenePlusVO scenePlusVO = new ScenePlusVO();
  391. ScenePlus scenePlus = new ScenePlus();
  392. ScenePlusExt scenePlusExt = new ScenePlusExt();
  393. scenePlusExt.setWebSite(url+projectNum);
  394. scenePlus.setCameraId(cameraId);
  395. scenePlus.setPhoneId(phoneId);
  396. scenePlus.setNum(projectNum);
  397. scenePlus.setSceneSource(1);
  398. if(cameraType.longValue() == 14){
  399. scenePlusExt.setDataSource(ConstantFilePath.BUILD_MODEL_LASER_PATH +
  400. cameraName.replace("4DKKPRO_", "").replace("-fdage", "").toLowerCase() + File.separator +
  401. fileId + File.separator + unicode);
  402. }else{
  403. scenePlusExt.setDataSource(ConstantFilePath.BUILD_MODEL_PATH +
  404. cameraName.replace("4DKKPRO_", "").replace("-fdage", "").toLowerCase() + File.separator +
  405. fileId + File.separator + unicode);
  406. }
  407. if(resolution == null || resolution.intValue() == 0){
  408. scenePlusExt.setSceneScheme(cameraType.intValue());
  409. }else {
  410. scenePlusExt.setSceneScheme(4);
  411. }
  412. //转台相机用4k图
  413. if(cameraType.longValue() == 13 ){
  414. scenePlus.setSceneSource(3);
  415. scenePlusExt.setSceneScheme(10);
  416. }
  417. //激光相机
  418. if(cameraType.longValue() == 14 ){
  419. scenePlus.setSceneSource(4);
  420. scenePlusExt.setSceneScheme(10);
  421. }
  422. if (pic != null && pic.length() > 5) {
  423. scenePlusExt.setThumb(pic);
  424. } else {
  425. scenePlusExt.setThumb(ConstantUrl.DEFAULT_SCENE_PIC);
  426. }
  427. scenePlusExt.setThumb(scenePlusExt.getThumb().concat("?t=") + System.currentTimeMillis());
  428. if (!ObjectUtils.isEmpty(userName)) {
  429. scenePlus.setUserId(userId);
  430. }
  431. if (sceneShootCount == null) {
  432. scenePlusExt.setShootCount(0);
  433. } else {
  434. scenePlusExt.setShootCount(sceneShootCount);
  435. }
  436. if (sceneName != null) {
  437. scenePlus.setTitle(sceneName);
  438. }
  439. if (sceneDec != null) {
  440. scenePlus.setDescription("<p>" + new String(sceneDec.getBytes("UTF-8")) + "</p>");
  441. }
  442. if (sceneType != null) {
  443. scenePlus.setSceneType(sceneType);
  444. }
  445. if (gps != null && !gps.trim().equals("")) {
  446. scenePlusExt.setGps(gps);
  447. }
  448. scenePlusExt.setAlgorithm(algorithm);
  449. if(!org.springframework.util.StringUtils.isEmpty(firmwareVersion)){
  450. scenePlusExt.setFirmwareVersion(firmwareVersion);
  451. }
  452. scenePlusExt.setBuildType(buildType);
  453. log.info("场景记录添加到数据库:"+projectNum);
  454. //type=0为新生成场景,其余为重新计算场景
  455. SceneEditInfo sceneEditInfo = new SceneEditInfo();
  456. SceneEditInfoExt sceneEditInfoExt = new SceneEditInfoExt();
  457. SceneEditControls sceneEditControls = new SceneEditControls();
  458. if(type == 0){
  459. scenePlus.setSceneStatus(SceneStatus.wait.code());
  460. scenePlusService.save(scenePlus);
  461. scenePlusExt.setPlusId(scenePlus.getId());
  462. scenePlusExtService.save(scenePlusExt);
  463. sceneEditInfo.setTitle(scenePlus.getTitle());
  464. sceneEditInfo.setDescription(scenePlus.getDescription());
  465. sceneEditInfo.setScenePlusId(scenePlus.getId());
  466. if(StrUtil.isNotBlank(sceneKey)) {
  467. sceneEditInfo.setScenePassword(sceneKey);
  468. sceneEditControls.setShowLock((int) CommonStatus.YES.code());
  469. }
  470. sceneEditInfoService.save(sceneEditInfo);
  471. sceneEditControls.setEditInfoId(sceneEditInfo.getId());
  472. sceneEditControlsService.save(sceneEditControls);
  473. //新增场景时,同时新增场景协作信息
  474. if(cooperationUser != null){
  475. SceneCooperation sceneCooperationEntity = new SceneCooperation();
  476. sceneCooperationEntity.setNum(projectNum);
  477. sceneCooperationEntity.setUserId(cooperationUser);
  478. sceneCooperationService.save(sceneCooperationEntity);
  479. List<SceneResourceCamera> resourceCameraList = sceneResourceCameraService.findListByCameraId(cameraId);
  480. SceneResourceCooperation sceneResourceCooperation = null;
  481. if(resourceCameraList != null && resourceCameraList.size() > 0){
  482. for (SceneResourceCamera sceneResourceCamera : resourceCameraList) {
  483. sceneResourceCooperation = new SceneResourceCooperation();
  484. sceneResourceCooperation.setSceneResourceId(sceneResourceCamera.getSceneResourceId());
  485. sceneResourceCooperation.setSceneCooperationId(sceneCooperationEntity.getId());
  486. sceneResourceCooperationService.save(sceneResourceCooperation);
  487. }
  488. }
  489. }
  490. }else {
  491. ScenePlus oldScene = scenePlusService.getScenePlusByNum(projectNum);
  492. scenePlus.setId(oldScene.getId());
  493. scenePlus.setSceneStatus(0);
  494. scenePlus.setRecStatus(RecStatus.VALID.code());
  495. scenePlus.setPayStatus(0);
  496. scenePlus.setCreateTime(Calendar.getInstance().getTime());
  497. ScenePlusExt oldSceneExt = scenePlusExtService.getScenePlusExtByPlusId(oldScene.getId());
  498. scenePlusExt.setSpace(oldSceneExt.getSpace());
  499. scenePlusExt.setEcs(oldSceneExt.getEcs());
  500. scenePlusExt.setViewCount(oldSceneExt.getViewCount());
  501. if(sceneName!=null) {
  502. scenePlus.setTitle(sceneName);
  503. }
  504. if(sceneType!=null) {
  505. scenePlus.setSceneType(sceneType);
  506. }
  507. scenePlusService.updateById(scenePlus);
  508. scenePlusExtService.updateById(scenePlusExt);
  509. SceneEditInfo oldSceneEditInfo = sceneEditInfoService.getByScenePlusId(oldScene.getId());
  510. SceneEditInfoExt oldSceneEditeIinfoExt = sceneEditInfoExtService.getByEditInfoId(oldSceneEditInfo.getId());
  511. if(StrUtil.isNotBlank(sceneKey)) {
  512. sceneEditInfo.setScenePassword(sceneKey);
  513. sceneEditControls.setShowLock((int) CommonStatus.YES.code());
  514. }else{
  515. sceneEditInfo.setScenePassword("");
  516. sceneEditControls.setShowLock((int)CommonStatus.NO.code());
  517. }
  518. sceneEditInfo.setTitle(scenePlus.getTitle());
  519. sceneEditInfo.setDescription(scenePlus.getDescription());
  520. sceneEditInfo.setId(oldSceneEditInfo.getId());
  521. sceneEditInfo.setScenePlusId(scenePlus.getId());
  522. sceneEditInfo.setFloorLogoSize(100);
  523. sceneEditInfo.setRecStatus(RecStatus.VALID.code());
  524. sceneEditInfo.setFloorPublishVer(oldSceneEditInfo.getFloorEditVer() + 1);
  525. sceneEditInfo.setFloorEditVer(oldSceneEditInfo.getFloorEditVer() + 1);
  526. sceneEditInfo.setVersion(oldSceneEditInfo.getVersion() + 1);
  527. sceneEditInfoService.updateById(sceneEditInfo);
  528. sceneEditInfoExt.setId(oldSceneEditeIinfoExt.getId());
  529. sceneEditInfoExt.setEditInfoId(sceneEditInfo.getId());
  530. sceneEditInfoExt.setScenePlusId(scenePlus.getId());
  531. sceneEditInfoExtService.updateById(sceneEditInfoExt);
  532. }
  533. BeanUtil.copyProperties(scenePlusExt, scenePlusVO);
  534. BeanUtil.copyProperties(scenePlus, scenePlusVO);
  535. return scenePlusVO;
  536. }
  537. public BuildSceneCallMessage getBuildSceneMqMessage(String projectNum,
  538. Long cameraType, String algorithm, Integer resolution,
  539. String buildType, String dataSource) {
  540. BuildSceneCallMessage mqMsg = new BuildSceneCallMessage();
  541. mqMsg.setSceneNum(projectNum);
  542. mqMsg.setCameraType(String.valueOf(cameraType));
  543. mqMsg.setAlgorithm(algorithm);
  544. mqMsg.setResolution(String.valueOf(resolution));
  545. mqMsg.setBuildType(buildType);
  546. mqMsg.setPath(dataSource);
  547. mqMsg.setCreateTime(DateUtil.format(Calendar.getInstance().getTime(), DateExtUtil.dateStyle));
  548. return mqMsg;
  549. }
  550. @Override
  551. public ResultData rebuildScene(String num,Boolean force) throws IOException {
  552. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  553. if(Objects.isNull(scenePlus)){
  554. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  555. }
  556. if (scenePlus.getSceneStatus() == 0 && (ObjectUtils.isEmpty(force) || !force)) {
  557. throw new BusinessException(ErrorCode.FAILURE_CODE_5033);
  558. }
  559. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  560. String path = scenePlusExt.getDataSource();
  561. Integer sceneSource = scenePlus.getSceneSource();
  562. String buildType = scenePlusExt.getBuildType();
  563. Integer sceneScheme = scenePlusExt.getSceneScheme();
  564. //重新计算时需要删除文件夹,否知使用缓存
  565. FileUtils.delAllFile(path + File.separator + "results");
  566. String dataFdageOssPath = ConstantFilePath.OSS_PREFIX+ path.replace(ConstantFilePath.BUILD_MODEL_PATH, "")
  567. .replace(ConstantFilePath.BUILD_MODEL_LASER_PATH, "") + "/data.fdage";
  568. JSONObject fdageData = JSONObject.parseObject(fYunFileService.getFileContent(dataFdageOssPath));
  569. if(ObjectUtils.isEmpty(fdageData)){
  570. log.error("data.fdage文件不存在");
  571. return ResultData.error(CameraConstant.FAILURE_6009.code(), CameraConstant.FAILURE_6009.message());
  572. }
  573. //重算的场景,先移除该场景对应的容量
  574. scenePlusService.resetSpace(num);
  575. String statusJsonOssPath = String.format(UploadFilePath.DATA_VIEW_PATH, num) + "status.json";
  576. JSONObject statusJson = JSONObject.parseObject(fYunFileService.getFileContent(String.format(UploadFilePath.DATA_VIEW_PATH, num) + "status.json"));
  577. //临时将-2改成1,app还没完全更新
  578. statusJson.put("status", SceneStatus.wait.code());
  579. fYunFileService.uploadFile(statusJson.toJSONString().getBytes(StandardCharsets.UTF_8),statusJsonOssPath);
  580. Long cameraType = (long)sceneScheme == 3 ? 12 : (long)sceneScheme;
  581. //判断是否转台相机
  582. if(sceneSource == 3){
  583. cameraType = 13L;
  584. }
  585. if(sceneSource == 4){
  586. cameraType = 14L;
  587. }
  588. if(sceneSource == 4){
  589. BuildSceneCallMessage buildSceneMqMessage = this.getBuildSceneMqMessage(
  590. num, cameraType,
  591. fdageData.getString("location") != null && "1".equals(fdageData.getString("location")) ? "sfm" : "slam",
  592. fdageData.getInteger("resolution"), buildType, path);
  593. rabbitMqProducer.sendByWorkQueue(queueModelingPre, buildSceneMqMessage);
  594. }else{
  595. BuildSceneCallMessage buildSceneMqMessage = this.getBuildSceneMqMessage(
  596. num, cameraType, fdageData.getString("location") != null && "1".equals(fdageData.getString("location")) ? "sfm" : "slam",
  597. fdageData.getInteger("resolution"), buildType,
  598. path);
  599. rabbitMqProducer.sendByWorkQueue(queueModelingPre, buildSceneMqMessage);
  600. }
  601. scenePlusService.update(new LambdaUpdateWrapper<ScenePlus>()
  602. .set(ScenePlus::getSceneStatus, SceneStatus.wait.code())
  603. .eq(ScenePlus::getNum, num));
  604. return ResultData.ok();
  605. }
  606. }