SceneFileBuildServiceImpl.java 108 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443
  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.exceptions.ExceptionUtil;
  6. import cn.hutool.core.io.FileUtil;
  7. import cn.hutool.core.lang.UUID;
  8. import cn.hutool.core.thread.ThreadUtil;
  9. import cn.hutool.core.util.StrUtil;
  10. import cn.hutool.core.util.ZipUtil;
  11. import cn.hutool.extra.qrcode.QrCodeUtil;
  12. import cn.hutool.extra.qrcode.QrConfig;
  13. import cn.hutool.http.HttpUtil;
  14. import com.alibaba.fastjson.JSON;
  15. import com.alibaba.fastjson.JSONObject;
  16. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  17. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  18. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  19. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  20. import com.fdkankan.common.constant.*;
  21. import com.fdkankan.common.exception.BusinessException;
  22. import com.fdkankan.common.util.*;
  23. import com.fdkankan.contro.bean.SendCallAlgorithmDetail;
  24. import com.fdkankan.contro.common.Result;
  25. import com.fdkankan.contro.constant.RedisConstants;
  26. import com.fdkankan.contro.entity.*;
  27. import com.fdkankan.contro.httpclient.MyClient;
  28. import com.fdkankan.contro.enums.CameraTypeEnum;
  29. import com.fdkankan.contro.mapper.ISceneFileBuildMapper;
  30. import com.fdkankan.contro.service.*;
  31. import com.fdkankan.contro.util.HttpUtilExt;
  32. import com.fdkankan.contro.vo.ResponseSceneFile;
  33. import com.fdkankan.contro.vo.ScenePlusVO;
  34. import com.fdkankan.contro.vo.SendCallAlgorithmParam;
  35. import com.fdkankan.fyun.config.FYunFileConfig;
  36. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  37. import com.fdkankan.fyun.local.constant.LocalConstants;
  38. import com.fdkankan.image.MatrixToImageWriterUtil;
  39. import com.fdkankan.model.constants.ConstantFilePath;
  40. import com.fdkankan.model.constants.UploadFilePath;
  41. import com.fdkankan.model.utils.SceneUtil;
  42. import com.fdkankan.rabbitmq.bean.BuildSceneCallMessage;
  43. import com.fdkankan.rabbitmq.util.RabbitMqProducer;
  44. import com.fdkankan.redis.constant.RedisKey;
  45. import com.fdkankan.redis.util.RedisLockUtil;
  46. import com.fdkankan.redis.util.RedisUtil;
  47. import com.fdkankan.web.response.ResultData;
  48. import com.fdkankan.web.util.RSAEncrypt;
  49. import lombok.extern.slf4j.Slf4j;
  50. import net.lingala.zip4j.core.ZipFile;
  51. import org.apache.commons.codec.binary.Base64;
  52. import org.apache.commons.lang3.StringUtils;
  53. import org.joda.time.DateTime;
  54. import org.springframework.beans.factory.annotation.Autowired;
  55. import org.springframework.beans.factory.annotation.Value;
  56. import org.springframework.cloud.context.config.annotation.RefreshScope;
  57. import org.springframework.http.*;
  58. import org.springframework.stereotype.Service;
  59. import org.springframework.util.LinkedMultiValueMap;
  60. import org.springframework.util.MultiValueMap;
  61. import org.springframework.util.ObjectUtils;
  62. import org.springframework.web.client.RestTemplate;
  63. import org.springframework.web.multipart.MultipartFile;
  64. import javax.annotation.Resource;
  65. import java.io.File;
  66. import java.io.IOException;
  67. import java.nio.charset.StandardCharsets;
  68. import java.util.*;
  69. import java.util.concurrent.CompletableFuture;
  70. import java.util.concurrent.ExecutorService;
  71. /**
  72. * <p>
  73. * 场景文件建模表 服务实现类
  74. * </p>
  75. *
  76. * @author dengsixing
  77. * @since 2021-12-23
  78. */
  79. @RefreshScope
  80. @Slf4j
  81. @Service
  82. public class SceneFileBuildServiceImpl extends ServiceImpl<ISceneFileBuildMapper, SceneFileBuild> implements ISceneFileBuildService {
  83. private static final String SPLICE = "#";
  84. private static final String sendCallAlgorithmPath = "/mnt/sendCallAlgorithm/";
  85. private static final String zipPassword = "a3ad34136de359536af553f9e7f3cefd";
  86. private static final String URL_ADD_UCENTER_USER = "/service/manage/inner/addUcenterUser";
  87. @Value("${main.url}")
  88. private String mainUrl;
  89. @Value("${fyun.type}")
  90. private String fyunType;
  91. @Value("${scene.pro.new.url}")
  92. private String sceneProNewUrl;
  93. @Value("${scene.pro.v3.url}")
  94. private String sceneProV3Url;
  95. @Value("${queue.modeling.modeling-pre}")
  96. private String queueModelingPre;
  97. @Value("${queue.modeling.v3.modeling-pre}")
  98. private String queueV3ModelingPre;
  99. @Value("${queue.modeling.intermit.modeling-pre}")
  100. private String queueIntermitModelingPre;
  101. @Value("${v3.controlUrl:#{null}}")
  102. private String v3controlUrl;
  103. @Value("${model.modelKind:3dtiles}")
  104. private String modelKind;
  105. @Value("#{'${model.3dtiles.sceneSource:}'.split(',')}")
  106. private List<Integer> sdTilesSceneSourceList;
  107. @Value("#{'${camType.laser:}'.split(',')}")
  108. private List<Integer> laserCamTypeList;
  109. @Value("${build.notSupport.beforeTime:202203}")
  110. private String jgNotSupportBuildTime;
  111. @Value("${4dkk.fdService.basePath}")
  112. private String fdServiceUrl;
  113. @Value("${user.password.key:0000000856753656}")
  114. private String userPasswordKey;
  115. @Value("${user.password.iv:pwel781esd6wglxm}")
  116. private String userPasswordIv;
  117. @Autowired
  118. private RedisUtil redisUtil;
  119. @Autowired
  120. private IScenePlusExtService scenePlusExtService;
  121. @Autowired
  122. private IScene3dNumService scene3dNumService;
  123. @Autowired
  124. private IScenePlusService scenePlusService;
  125. @Autowired
  126. private RabbitMqProducer rabbitMqProducer;
  127. @Autowired
  128. private ISceneEditInfoService sceneEditInfoService;
  129. @Autowired
  130. private ISceneEditControlsService sceneEditControlsService;
  131. @Autowired
  132. private ISceneEditInfoExtService sceneEditInfoExtService;
  133. @Autowired
  134. private ISceneCooperationService sceneCooperationService;
  135. @Autowired
  136. private ISceneResourceCameraService sceneResourceCameraService;
  137. @Autowired
  138. private ISceneResourceCooperationService sceneResourceCooperationService;
  139. @Autowired
  140. private ICameraService cameraService;
  141. @Autowired
  142. private ICameraDetailService cameraDetailService;
  143. @Autowired
  144. private IUserService userService;
  145. @Autowired
  146. private ISceneFileUploadService sceneFileUploadService;
  147. @Resource
  148. private ICompanyService companyService;
  149. @Resource
  150. private FYunFileServiceInterface fYunFileService;
  151. @Autowired
  152. private FYunFileConfig fYunFileConfig;
  153. @Autowired
  154. private RedisLockUtil redisLockUtil;
  155. @Autowired
  156. private IScenePreService scenePreService;
  157. private RestTemplate restTemplate = new RestTemplate();
  158. @Autowired
  159. private ISceneCopyDistinctEnvService sceneCopyDistinctEnvService;
  160. @Autowired
  161. private ISceneCopyLogService sceneCopyLogService;
  162. @Autowired
  163. private ISceneCleanOrigService sceneCleanOrigService;
  164. @Autowired
  165. private ICommonService commonService;
  166. @Autowired
  167. private IExceedSpaceSceneService exceedSpaceSceneService;
  168. @Autowired
  169. private ISceneColdStorageLogService sceneColdStorageLogService;
  170. @Autowired
  171. private ISceneColdStorageService sceneColdStorageService;
  172. @Autowired
  173. private IntermitSceneService intermitSceneService;
  174. @Autowired
  175. private ISceneRebuildLogService sceneRebuildLogService;
  176. @Autowired
  177. private ISceneUploadCountService sceneUploadCountService;
  178. @Autowired
  179. private ISceneProService sceneProService;
  180. @Autowired
  181. private ISceneProEditService sceneProEditService;
  182. @Autowired
  183. private IFdkkLaserService fdkkLaserService;
  184. @Resource
  185. private MyClient myClient;
  186. @Autowired
  187. IJySceneAuthService jySceneAuthService;
  188. @Autowired
  189. private IJyUserService jyUserService;
  190. @Autowired
  191. private IOrigFileUploadService origFileUploadService;
  192. @Autowired
  193. private IOrigFileUploadBatchService origFileUploadBatchService;
  194. @Autowired
  195. private IJmgaService jmgaService;
  196. @Autowired
  197. private ISceneOrigBdService sceneOrigBdService;
  198. @Autowired
  199. private ISceneFilenameService sceneFilenameService;
  200. @Override
  201. public SceneFileBuild findByFileId(String fileId) {
  202. List<SceneFileBuild> list = this.list(new LambdaQueryWrapper<SceneFileBuild>().eq(SceneFileBuild::getFileId, fileId)
  203. .orderByDesc(SceneFileBuild::getId));
  204. if(CollUtil.isEmpty(list)){
  205. return null;
  206. }
  207. return list.get(0);
  208. }
  209. @Override
  210. public ResponseSceneFile preUpload(String params) throws Exception {
  211. log.info("preUpload-params: "+params);
  212. if (StrUtil.isEmpty(params)){
  213. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  214. }
  215. params = params.replaceAll("%2B", "+");
  216. Base64 base64 = new Base64();
  217. String cipher = params;
  218. // 私钥解密过程
  219. byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
  220. base64.decode(cipher));
  221. String restr = new String(res, "UTF-8");
  222. log.debug("preUpload-params解密结果:" + restr);
  223. String[] strArr = restr.split(SPLICE);
  224. if (strArr.length != 5) {
  225. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  226. }
  227. String mac = strArr[0];
  228. String totalPicNum = strArr[1];
  229. String chunks = strArr[2];
  230. String folderName = strArr[3];
  231. if (StrUtil.isEmpty(mac)){
  232. throw new BusinessException(ErrorCode.FAILURE_CODE_5044);
  233. }
  234. if (totalPicNum == null){
  235. throw new BusinessException(ErrorCode.FAILURE_CODE_5045);
  236. }
  237. if (chunks == null){
  238. throw new BusinessException(ErrorCode.FAILURE_CODE_5046);
  239. }
  240. if (folderName == null){
  241. throw new BusinessException(ErrorCode.FAILURE_CODE_5047);
  242. }
  243. log.info("mac:{} 准备上传文件,folderName:{}", mac, folderName);
  244. ResponseSceneFile responseSceneFile = new ResponseSceneFile();
  245. // 检测是否有生成
  246. String fileId = redisUtil.get(String.format(RedisConstants.FOLDER_FILEID_BUILD, folderName));
  247. if (StrUtil.isEmpty(fileId)) {
  248. SceneFileBuild sceneFileBuild = this.findByUnicode(folderName);
  249. if (sceneFileBuild != null) {
  250. fileId = sceneFileBuild.getFileId();
  251. }
  252. }
  253. if(StrUtil.isNotEmpty(fileId)){
  254. //校验目录是否被上锁,如果上锁,抛出错误(避免删除原始资源定时任务执行过程中,有场景补拍重新上传)
  255. String homePath = redisUtil.get(String.format(RedisKey.SCENE_OSS_HOME_DIR_DELETE, folderName));
  256. if(StrUtil.isNotEmpty(homePath)){
  257. throw new BusinessException(ErrorCode.FAILURE_CODE_5073);
  258. }
  259. //如果原始资源目录不是正在被定时任务删除中,就加上上传锁,并正常返回
  260. homePath = ConstantFilePath.OSS_PREFIX.concat(mac).concat("/").concat(fileId).concat("/").concat(folderName);
  261. redisUtil.set(String.format(RedisKey.SCENE_OSS_HOME_DIR_UPLOAD, folderName), homePath, RedisKey.CAMERA_EXPIRE_7_TIME);
  262. responseSceneFile.setFileId(fileId);
  263. redisUtil.set(String.format(RedisConstants.FOLDER_FILEID_BUILD, folderName), fileId, 2 * 24 * 60 * 60);
  264. return responseSceneFile;
  265. }
  266. // 加锁
  267. boolean lock = redisLockUtil.lock(String.format(RedisConstants.FOLDER_LOCK_BUILD, folderName), 120);
  268. if (!lock) {
  269. throw new BusinessException(ErrorCode.FAILURE_CODE_5052);
  270. }
  271. // 查找场景表
  272. LambdaQueryWrapper<ScenePro> proWrapper = new LambdaQueryWrapper<>();
  273. proWrapper.like(ScenePro::getDataSource, "/" + folderName);
  274. ScenePro pro = sceneProService.getOne(proWrapper);
  275. String dataSource = null;
  276. if (!ObjectUtils.isEmpty(pro)) {
  277. dataSource = pro.getDataSource();
  278. } else {
  279. dataSource = scenePlusService.getDataSourceLikeUnicode("/" + folderName);
  280. }
  281. if (StrUtil.isNotEmpty(dataSource)) {
  282. log.info("从数据库中查到与 fileId:{} 匹配的路径为:{}", fileId, dataSource);
  283. int n = dataSource.split("/").length;
  284. if (n > 1) {
  285. fileId = dataSource.split("/")[n - 2];
  286. }
  287. }
  288. if (StrUtil.isEmpty(fileId)) {
  289. fileId = new SnowflakeIdGenerator(0, 0).nextId() + "";
  290. log.info("新生成build数据,{}", fileId);
  291. }
  292. SceneFileBuild sceneFileBuild = new SceneFileBuild();
  293. sceneFileBuild.setChildName(mac);
  294. sceneFileBuild.setFileId(fileId);
  295. sceneFileBuild.setRecStatus("A");
  296. sceneFileBuild.setUnicode(folderName);
  297. sceneFileBuild.setTotalPicNum(Integer.valueOf(totalPicNum));
  298. sceneFileBuild.setChunks(Integer.valueOf(chunks));
  299. sceneFileBuild.setCreateTime(new Date());
  300. this.save(sceneFileBuild);
  301. redisUtil.set(String.format(RedisConstants.FOLDER_FILEID_BUILD, folderName), fileId, 2 * 24 * 60 * 60);
  302. redisUtil.set(String.format(RedisConstants.FILEID_FOLDER_BUILD, fileId), folderName, 2 * 24 * 60 * 60);
  303. responseSceneFile.setFileId(fileId);
  304. return responseSceneFile;
  305. }
  306. public SceneFileBuild findByUnicode(String unicode) {
  307. List<SceneFileBuild> list = this.list(new QueryWrapper<SceneFileBuild>()
  308. .eq("unicode", unicode)
  309. .orderByDesc("id"));
  310. if(CollUtil.isEmpty(list))
  311. return null;
  312. return list.get(0);
  313. }
  314. public ScenePlusVO buildScene(String fileId, String prefix,JSONObject jsonObject,String buildType,long cameraType) throws Exception{
  315. //调用createScene方法生成scene数据和加入算法队列
  316. String sceneNum = "";
  317. String cameraName = jsonObject.getJSONObject("cam").getString("uuid");
  318. String unicode = jsonObject.getString("creator") + "_" + jsonObject.getString("uuidtime");
  319. Camera camera = cameraService.getByChildName(cameraName);
  320. if (camera == null) {
  321. throw new BusinessException(CameraConstant.FAILURE_6003);
  322. }
  323. CameraDetail cameraDetail = cameraDetailService.getByCameraId(camera.getId());
  324. if (cameraDetail == null) {
  325. log.error("该相机详情不存在:" + cameraName);
  326. throw new BusinessException(CameraConstant.FAILURE_6003);
  327. }
  328. //查看场景中的文件目录是否有改文件id,有则重新计算改场景,无则新建场景
  329. ScenePlus scenePlus = scenePlusService.getByFileId("/" + fileId + "/");
  330. int rebuild = CommonStatus.YES.code();
  331. if (ObjectUtils.isEmpty(scenePlus)) {
  332. //清除超容量场景记录
  333. exceedSpaceSceneService.repeal(camera.getId(), fileId, unicode);
  334. sceneNum = scene3dNumService.generateSceneNum(cameraDetail.getType());
  335. rebuild = CommonStatus.NO.code();
  336. } else {
  337. sceneNum = scenePlus.getNum();
  338. sceneCopyLogService.checkCanBuild(sceneNum);
  339. if (scenePlus.getSceneStatus().equals(SceneStatus.wait.code())) {
  340. log.info(scenePlus.getNum() + ":场景处于计算中,不能再计算");
  341. return null;
  342. }
  343. }
  344. if (sceneNum == null) {
  345. log.error("大场景序号为空:" + sceneNum);
  346. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  347. }
  348. //如果是相机计算容量的模式是场景个数模式,则需要拦截计算
  349. if(rebuild == CommonStatus.NO.code()){//新场景需要校验容量是否超出限制
  350. boolean exceedSpace = exceedSpaceSceneService.cehckExceedSpace(sceneNum, cameraDetail, cameraName, fileId, unicode);
  351. if(exceedSpace){
  352. ScenePlusVO scenePlusVO = new ScenePlusVO();
  353. scenePlusVO.setNum(sceneNum);
  354. scenePlusVO.setSceneStatus(SceneStatus.EXCEED_SPACE.code());
  355. return scenePlusVO;
  356. }
  357. }
  358. String dataSource = cameraName.replace("4DKKPRO_", "").replace("-fdage", "").toLowerCase() + File.separator +
  359. fileId + File.separator + unicode;
  360. if (cameraType == 14) {
  361. dataSource = ConstantFilePath.BUILD_MODEL_LASER_PATH +dataSource;
  362. } else {
  363. dataSource = ConstantFilePath.BUILD_MODEL_PATH + dataSource;
  364. }
  365. String imgViewPath = String.format(UploadFilePath.IMG_VIEW_PATH, sceneNum);
  366. String icon = null;
  367. if (!ObjectUtils.isEmpty(jsonObject.getString("icon"))) {
  368. fYunFileService.copyFileInBucket(ConstantFilePath.OSS_PREFIX + prefix + jsonObject.getString("icon"),imgViewPath + jsonObject.getString("icon"));
  369. icon = fYunFileConfig.getHost() + imgViewPath + jsonObject.getString("icon");
  370. log.info("上传icon成功....");
  371. }
  372. return buildScenePost(dataSource, jsonObject, buildType, cameraType, sceneNum, camera, cameraDetail, rebuild,icon);
  373. }
  374. private ScenePlusVO buildScenePost(String dataSource, JSONObject jsonObject, String buildType, long cameraType,
  375. String sceneNum, Camera camera, CameraDetail cameraDetail, int rebuild,String icon) throws Exception {
  376. String imgViewPath = String.format(UploadFilePath.IMG_VIEW_PATH, sceneNum);
  377. String userName = null;
  378. if (!ObjectUtils.isEmpty(cameraDetail.getUserId())) {
  379. SSOUser user = userService.getSSOUserByUserId(cameraDetail.getUserId());
  380. userName = ObjectUtils.isEmpty(user) ? null : user.getUserName();
  381. }
  382. JSONObject firmwareVersion = new JSONObject();
  383. if (!ObjectUtils.isEmpty(jsonObject.getString("camSoftwareVersion"))) {
  384. firmwareVersion.put("camSoftwareVersion", jsonObject.getString("camSoftwareVersion"));
  385. }
  386. if (!ObjectUtils.isEmpty(jsonObject.getString("version"))) {
  387. firmwareVersion.put("version", jsonObject.getString("version"));
  388. }
  389. String sceneUrl = "/" + sceneProNewUrl;
  390. //重算的场景,先移除该场景对应的容量
  391. if (rebuild == 1) {
  392. scenePlusService.resetSpace(sceneNum);
  393. } else {
  394. //上传log-main.png
  395. fYunFileService.uploadFile(ConstantFilePath.LOGO_PATH + "logo-main.png", imgViewPath + "logo-main.png");
  396. fYunFileService.uploadFile(ConstantFilePath.LOGO_PATH + "logo-main-en.png", imgViewPath + "logo-main-en.png");
  397. }
  398. String algorithm = jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam";
  399. String unicode = jsonObject.getString("creator") + "_" + jsonObject.getString("uuidtime");
  400. ScenePlusVO scenePlusVO = this.createScenePlus(sceneNum, camera.getId(), camera.getChildName(), jsonObject.getString("creator"),
  401. jsonObject.getString("pwd"), unicode,cameraType,jsonObject.getJSONObject("cam").getIntValue("type"), dataSource, icon, cameraDetail.getUserId(), userName,algorithm,jsonObject.getInteger("location"),
  402. jsonObject.getJSONArray("points").size(), jsonObject.getString("name"), jsonObject.getString("info"),
  403. jsonObject.getInteger("scenetype"), jsonObject.getString("gps"), rebuild,
  404. jsonObject.getInteger("resolution"), firmwareVersion.toString(), sceneUrl, buildType, cameraDetail.getCooperationUser());
  405. //上传app状态文件
  406. commonService.uploadStatusJson(sceneNum, scenePlusVO.getSceneStatus(),
  407. scenePlusVO.getWebSite(),scenePlusVO.getThumb(),PayStatus.NOT_PAY.code(),
  408. String.format(UploadFilePath.DATA_VIEW_PATH, sceneNum));
  409. BuildSceneCallMessage mqMessage = getBuildSceneMqMessage(sceneNum, cameraType, algorithm, jsonObject, buildType,
  410. scenePlusVO.getDataSource());
  411. mqMessage.getExt().put("uuid", unicode);
  412. if (cameraDetail.getCompanyId() != null) {
  413. Company company = companyService.getById(cameraDetail.getCompanyId());
  414. if (company != null && !ObjectUtils.isEmpty(company.getCalculateFlexibility()) && !company.getCalculateFlexibility()) {
  415. mqMessage.setFlexibility(-1);
  416. }
  417. }
  418. mqMessage.getExt().put("deleteExtras", true);
  419. rabbitMqProducer.sendByWorkQueue(queueModelingPre, mqMessage);
  420. if(jsonObject.getIntValue("location") == 7){
  421. //发送到全景看看进行初始化
  422. intermitSceneService.sendMq(scenePlusVO.getNum(), jsonObject, CommonSuccessStatus.WAITING.code());
  423. rabbitMqProducer.sendByWorkQueue(queueIntermitModelingPre, mqMessage);
  424. }else{
  425. rabbitMqProducer.sendByWorkQueue(queueModelingPre, mqMessage);
  426. }
  427. return scenePlusVO;
  428. }
  429. public ScenePlusVO buildV3Scene(ScenePro scenePro,String fileId, String prefix,JSONObject jsonObject,String buildType,long cameraType) throws Exception{
  430. sceneCopyLogService.checkCanBuild(scenePro.getNum());
  431. //调用createScene方法生成scene数据和加入算法队列
  432. String cameraName = jsonObject.getJSONObject("cam").getString("uuid");
  433. String unicode = jsonObject.getString("creator") + "_" + jsonObject.getString("uuidtime");
  434. Camera camera = cameraService.getByChildName(cameraName);
  435. if (camera == null) {
  436. throw new BusinessException(CameraConstant.FAILURE_6003);
  437. }
  438. CameraDetail cameraDetail = cameraDetailService.getByCameraId(camera.getId());
  439. if (cameraDetail == null) {
  440. log.error("该相机详情不存在:" + cameraName);
  441. throw new BusinessException(CameraConstant.FAILURE_6003);
  442. }
  443. String sceneNum = scenePro.getNum();
  444. if (scenePro.getStatus().equals(SceneStatus.wait.code())) {
  445. log.info(scenePro.getNum() + ":场景处于计算中,不能再计算");
  446. return null;
  447. }
  448. String localDataPath = String.format(ConstantFilePath.DATABUFFER_FORMAT, sceneNum);
  449. String imgViewPath = String.format(ConstantFilePath.IMAGE_PATH_FORMAT, sceneNum);
  450. String dataViewPath = String.format(ConstantFilePath.DATA_PATH_FORMAT, sceneNum);
  451. String userName = null;
  452. if (!ObjectUtils.isEmpty(cameraDetail.getUserId())) {
  453. SSOUser user = userService.getSSOUserByUserId(cameraDetail.getUserId());
  454. userName = ObjectUtils.isEmpty(user) ? null : user.getUserName();
  455. }
  456. String icon = null;
  457. if (!ObjectUtils.isEmpty(jsonObject.getString("icon"))) {
  458. fYunFileService.copyFileInBucket(ConstantFilePath.OSS_PREFIX + prefix + jsonObject.getString("icon"),imgViewPath + jsonObject.getString("icon"));
  459. icon = fYunFileConfig.getHost() + imgViewPath + jsonObject.getString("icon");
  460. log.info("上传icon成功....");
  461. }
  462. JSONObject firmwareVersion = new JSONObject();
  463. if (!ObjectUtils.isEmpty(jsonObject.getString("camSoftwareVersion"))) {
  464. firmwareVersion.put("camSoftwareVersion", jsonObject.getString("camSoftwareVersion"));
  465. }
  466. if (!ObjectUtils.isEmpty(jsonObject.getString("version"))) {
  467. firmwareVersion.put("version", jsonObject.getString("version"));
  468. }
  469. //删除oss的houst_floor.json(国际版可能会卡住)
  470. fYunFileService.deleteFile(dataViewPath + "houst_floor.json");
  471. String algorithm = jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam";
  472. ScenePlusVO scenePlusVO = this.createScenePro(sceneNum, camera.getId(), camera.getChildName(), jsonObject.getString("creator"),
  473. jsonObject.getString("pwd"), unicode,cameraType, fileId, icon, cameraDetail.getUserId(), userName,algorithm,
  474. jsonObject.getJSONArray("points").size(), jsonObject.getString("name"), jsonObject.getString("info"),
  475. jsonObject.getInteger("scenetype"), jsonObject.getString("gps"),
  476. jsonObject.getInteger("resolution"), firmwareVersion.toString(), buildType);
  477. //上传场景状态文件
  478. commonService.uploadStatusJson(sceneNum, scenePlusVO.getSceneStatus(),
  479. scenePlusVO.getWebSite(),scenePlusVO.getThumb(),PayStatus.NOT_PAY.code(),
  480. String.format(ConstantFilePath.DATA_PATH_FORMAT, sceneNum));
  481. BuildSceneCallMessage mqMessage = getBuildSceneMqMessage(sceneNum, cameraType, algorithm, jsonObject, buildType,
  482. scenePlusVO.getDataSource());
  483. if (cameraDetail.getCompanyId() != null) {
  484. Company company = companyService.getById(cameraDetail.getCompanyId());
  485. if (company != null) {
  486. log.info("复制企业logo");
  487. SceneProEdit sceneEditInfo = sceneProEditService.getByProId(scenePlusVO.getId());
  488. if (StrUtil.isNotEmpty(company.getTopLogo())) {
  489. fYunFileService.copyFileInBucket(company.getTopLogo(),imgViewPath + "logo-main.png");
  490. }
  491. if (StrUtil.isNotEmpty(company.getFloorLogo())) {
  492. fYunFileService.copyFileInBucket(company.getFloorLogo(),imgViewPath + "floorLogoImg.png");
  493. sceneEditInfo.setFloorLogo("user");
  494. }
  495. if (StrUtil.isNotEmpty(company.getQrLogo())) {
  496. createQrCode(sceneNum,scenePlusVO.getWebSite(),company.getQrLogo());
  497. }
  498. sceneProEditService.updateById(sceneEditInfo);
  499. if (!ObjectUtils.isEmpty(company.getCalculateFlexibility()) && !company.getCalculateFlexibility()) {
  500. mqMessage.setFlexibility(-1);
  501. }
  502. }
  503. }
  504. rabbitMqProducer.sendByWorkQueue(queueV3ModelingPre, mqMessage);
  505. return scenePlusVO;
  506. }
  507. private void createQrCode(String num, String url, String qrLogo) {
  508. String localLogoPath = null;
  509. if (!org.apache.commons.lang3.ObjectUtils.isEmpty(qrLogo)) {
  510. try {
  511. localLogoPath = ConstantFilePath.AGENT_PATH + qrLogo.substring(qrLogo.lastIndexOf("//") + 1);
  512. HttpUtil.downloadFile(qrLogo, localLogoPath);
  513. } catch (Exception e) {
  514. log.error("公司logo下载失败:{}", qrLogo);
  515. localLogoPath = null;
  516. }
  517. }
  518. //生成二维码
  519. String outPathZh = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+ num +".png";
  520. String outPathEn = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+ num +"_en.png";
  521. QrConfig qrConfig = QrConfig.create();
  522. qrConfig.setWidth(512);
  523. qrConfig.setHeight(512);
  524. if(!org.apache.commons.lang3.ObjectUtils.isEmpty(localLogoPath)){
  525. qrConfig.setImg(localLogoPath);
  526. }
  527. QrCodeUtil.generate(url, qrConfig, FileUtil.file(outPathZh));
  528. QrCodeUtil.generate(url + "&lang=en", qrConfig, FileUtil.file(outPathEn));
  529. //上传二维码
  530. fYunFileService.uploadFile(outPathZh, String.format(UploadFilePath.DOWNLOADS_QRCODE, num) + num + ".png");
  531. fYunFileService.uploadFile(outPathEn, String.format(UploadFilePath.DOWNLOADS_QRCODE, num) + num + "_en.png");
  532. if(!org.apache.commons.lang3.ObjectUtils.isEmpty(localLogoPath)){
  533. FileUtils.deleteFile(localLogoPath);
  534. }
  535. }
  536. @Override
  537. public ResultData uploadSuccessBuild(String params) throws Exception {
  538. log.info("uploadSuccessBuild-params: " + params);
  539. String preParams = params;
  540. if (StringUtils.isEmpty(params)) {
  541. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  542. }
  543. params = params.replaceAll("%2B", "+");
  544. params = params.replaceAll(" ", "+");
  545. Base64 base64 = new Base64();
  546. String cipher = params;
  547. // 私钥解密过程
  548. byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()), base64.decode(cipher));
  549. String restr = new String(res, "UTF-8");
  550. log.info("uploadSuccessBuild-params解密结果:" + restr);
  551. String[] strArr = restr.split(SPLICE);
  552. if (strArr.length != 3) {
  553. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  554. }
  555. String mac = strArr[0];
  556. String fileId = strArr[1];
  557. String folderName = redisUtil.get(String.format(RedisConstants.FILEID_FOLDER_BUILD, fileId));
  558. if(StringUtils.isEmpty(folderName)){
  559. SceneFileBuild fileBuild = findByFileId(fileId);
  560. if(ObjectUtils.isEmpty(fileBuild)){
  561. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  562. }
  563. folderName = fileBuild.getUnicode();
  564. redisUtil.set(String.format(RedisConstants.FILEID_FOLDER_BUILD, fileId), folderName,2 * 24 * 60 * 60);
  565. }
  566. sceneUploadCountService.resetCountByUuid(folderName);
  567. StringBuilder prefixBuffer = new StringBuilder(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator);
  568. String buildType = "V2";
  569. Long cameraType = 10L;
  570. if(!fYunFileService.fileExist(ConstantFilePath.OSS_PREFIX + prefixBuffer + "data.fdage")){
  571. log.error("data.fdage文件不存在");
  572. throw new BusinessException(CameraConstant.FAILURE_6009);
  573. }
  574. JSONObject fdageJson = JSONObject.parseObject(fYunFileService.getFileContent(ConstantFilePath.OSS_PREFIX + prefixBuffer + "data.fdage"));
  575. if(ObjectUtils.isEmpty(fdageJson)){
  576. log.info("data.fdage文件为空!");
  577. throw new BusinessException(CameraConstant.FAILURE_6009);
  578. }
  579. //根据videoVersion判断是V2还是V3版本的算法和页面
  580. if (fdageJson.containsKey("videoVersion") && StrUtil.isNotEmpty(fdageJson.getString("videoVersion"))) {
  581. if (fdageJson.getIntValue("videoVersion") >= 4) {
  582. buildType = "V3";
  583. cameraType = 11L;
  584. }
  585. }
  586. this.removeUpdateV4(ConstantFilePath.OSS_PREFIX + prefixBuffer + "data.fdage", fdageJson);
  587. // 判断是否是V3的场景
  588. ScenePro scenePro = sceneProService.getOne(
  589. new LambdaQueryWrapper<ScenePro>().like(ScenePro::getDataSource, "/".concat(fileId).concat("/")));
  590. boolean callV3 = callV3(scenePro, preParams, fdageJson, "api/scene/file/uploadSuccessBuild");
  591. if(callV3) return ResultData.ok();
  592. if (ObjectUtils.isEmpty(scenePro) || (!ObjectUtils.isEmpty(scenePro.getIsUpgrade()) && scenePro.getIsUpgrade() == 1)) {
  593. buildScene(fileId, prefixBuffer.toString(),fdageJson,buildType,cameraType);
  594. }else{
  595. buildV3Scene(scenePro,fileId, prefixBuffer.toString(),fdageJson,buildType,cameraType);
  596. }
  597. return ResultData.ok();
  598. }
  599. private void removeUpdateV4(String dataFdagePath, JSONObject fdageJson){
  600. Integer updateV4 = fdageJson.getInteger("updateV4");
  601. if(Objects.isNull(updateV4) || updateV4 == 0){
  602. return;
  603. }
  604. fdageJson.put("updateV4", CommonStatus.NO.code());
  605. fYunFileService.uploadFile(fdageJson.toJSONString().getBytes(StandardCharsets.UTF_8), dataFdagePath);
  606. }
  607. private boolean callV3(ScenePro scenePro, String preParams, JSONObject fdageJson,String api) throws Exception {
  608. //复制出来的场景不支持补拍上传
  609. if(Objects.nonNull(scenePro)){
  610. sceneCopyLogService.checkCanBuild(scenePro.getNum());
  611. }
  612. String cameraName = fdageJson.getJSONObject("cam").getString("uuid");
  613. Camera camera = cameraService.getByChildName(cameraName);
  614. if (camera == null) {
  615. throw new BusinessException(CameraConstant.FAILURE_6003);
  616. }
  617. CameraDetail cameraDetail = cameraDetailService.getByCameraId(camera.getId());
  618. if (cameraDetail == null) {
  619. log.error("该相机详情不存在:" + cameraName);
  620. throw new BusinessException(CameraConstant.FAILURE_6003);
  621. }
  622. // 判断是否是正顺|火调|普通v3的场景,如果是正顺|火调|普通v3的场景,则发送到原来的系统进行计算
  623. if (!ObjectUtils.isEmpty(cameraDetail.getCompanyId())) {
  624. Company company = companyService.getById(cameraDetail.getCompanyId());
  625. if(ObjectUtils.isEmpty(company)){
  626. log.error("企业配置有误:" + cameraName);
  627. throw new BusinessException(CameraConstant.FAILURE_6003);
  628. }
  629. if (!ObjectUtils.isEmpty(company.getSceneVersion()) && company.getSceneVersion().equals("V3")) {
  630. //如果是app重新上传,需要解冻结
  631. if(Objects.nonNull(scenePro)){
  632. sceneColdStorageService.unfreeze(scenePro.getNum(), "用户相机重新全量上传", scenePro.getDataSource());
  633. }
  634. callV3Service(preParams, api);
  635. return Boolean.TRUE;
  636. }
  637. }
  638. // else if (Objects.nonNull(scenePro) &&
  639. // scenePro.getSceneSource() != SceneSource.JG.code() &&
  640. // scenePro.getIsUpgrade() == CommonStatus.NO.code().intValue()){
  641. // callV3Service(preParams,api);
  642. // return Boolean.TRUE;
  643. // }
  644. return Boolean.FALSE;
  645. }
  646. public void callV3Service(String params,String api) throws Exception {
  647. log.info("params:{}", params);
  648. if(ObjectUtils.isEmpty(v3controlUrl)){
  649. log.error("未配置V3服务器!");
  650. throw new Exception("未配置V3服务器!");
  651. }
  652. HttpHeaders headers = new HttpHeaders();
  653. headers.setContentType(MediaType.MULTIPART_FORM_DATA);
  654. MultiValueMap<String,String> paramMap = new LinkedMultiValueMap();
  655. paramMap.add("params",params);
  656. HttpEntity<Object> formEntity = new HttpEntity<>(paramMap,headers);
  657. ResponseEntity<Result> responseEntity = restTemplate.postForEntity(v3controlUrl+api, formEntity, Result.class);
  658. if (responseEntity.getStatusCode().value() != HttpStatus.OK.value() || responseEntity.getBody().getCode() != ServerCode.SUCCESS.code()) {
  659. log.error("正顺场景请求V3服务器失败, params:{}, result:{}",params, JSON.toJSONString(responseEntity));
  660. throw new BusinessException(ErrorCode.SYSTEM_BUSY);
  661. }
  662. log.info("正顺场景请求V3服务器成功!");
  663. }
  664. @Override
  665. public ResultData turntableUploadSuccess(String params) throws Exception {
  666. log.info("turntableUploadSuccess-params: " + params);
  667. String preParams = params;
  668. if (StringUtils.isEmpty(params)) {
  669. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  670. }
  671. params = params.replaceAll("%2B", "+");
  672. params = params.replaceAll(" ", "+");
  673. Base64 base64 = new Base64();
  674. String cipher = params;
  675. // 私钥解密过程
  676. byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
  677. base64.decode(cipher));
  678. String restr = new String(res, "UTF-8");
  679. log.info("turntableUploadSuccess-params解密结果:" + restr);
  680. String[] strArr = restr.split(SPLICE);
  681. if (strArr.length != 3) {
  682. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  683. }
  684. String mac = strArr[0];
  685. String fileId = strArr[1];
  686. String folderName = redisUtil.get(String.format(RedisConstants.FILEID_FOLDER_BUILD, fileId));
  687. if(StringUtils.isEmpty(folderName)){
  688. SceneFileBuild fileBuild = findByFileId(fileId);
  689. if(ObjectUtils.isEmpty(fileBuild)){
  690. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  691. }
  692. folderName = fileBuild.getUnicode();
  693. redisUtil.set(String.format(RedisConstants.FILEID_FOLDER_BUILD, fileId), folderName);
  694. }
  695. sceneUploadCountService.resetCountByUuid(folderName);
  696. //云目录
  697. StringBuilder prefixBuffer = new StringBuilder(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator);
  698. if(!fYunFileService.fileExist(ConstantFilePath.OSS_PREFIX + prefixBuffer + "data.fdage")){
  699. log.error("data.fdage文件不存在");
  700. throw new BusinessException(CameraConstant.FAILURE_6009);
  701. }
  702. JSONObject fdageJson = JSONObject.parseObject(fYunFileService.getFileContent(ConstantFilePath.OSS_PREFIX + prefixBuffer + "data.fdage"));
  703. if(ObjectUtils.isEmpty(fdageJson)){
  704. log.info("data.fdage文件为空");
  705. throw new BusinessException(CameraConstant.FAILURE_6009);
  706. }
  707. this.removeUpdateV4(ConstantFilePath.OSS_PREFIX + prefixBuffer + "data.fdage", fdageJson);
  708. String buildType = "V3";
  709. //13表示转台
  710. Long cameraType = 13L;
  711. //激光相机10 13
  712. int camType = fdageJson.getJSONObject("cam").getIntValue("type");
  713. log.info("camType:{}", camType);
  714. if(laserCamTypeList.contains(camType)){
  715. //激光转台
  716. cameraType = 14L;
  717. }
  718. // 判断是否是V3的场景
  719. ScenePro scenePro = sceneProService.getOne(
  720. new LambdaQueryWrapper<ScenePro>().like(ScenePro::getDataSource, "/".concat(fileId).concat("/")));
  721. boolean callV3 = callV3(scenePro, preParams, fdageJson, "api/scene/file/turntableUploadSuccess");
  722. if (callV3) return ResultData.ok();
  723. //激光场景校验是否能够计算
  724. this.checkJgCanBuild(scenePro);
  725. ScenePlusVO scenePlusVO = null;
  726. if (ObjectUtils.isEmpty(scenePro) || (!ObjectUtils.isEmpty(scenePro.getIsUpgrade()) && scenePro.getIsUpgrade() == 1)) {
  727. scenePlusVO = buildScene(fileId, prefixBuffer.toString(), fdageJson, buildType, cameraType);
  728. } else {
  729. scenePlusVO = buildV3Scene(scenePro,fileId, prefixBuffer.toString(), fdageJson, buildType, cameraType);
  730. }
  731. if(ObjectUtils.isEmpty(scenePlusVO) || scenePlusVO.getSceneStatus() == SceneStatus.EXCEED_SPACE.code()){
  732. return ResultData.ok();
  733. }
  734. // 通知激光场景系统开始构建场景
  735. if(cameraType.longValue() == 14 && fdageJson.getIntValue("location") != 7){
  736. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(scenePlusVO.getNum());
  737. Long sceneUserId = scenePlus.getUserId();
  738. String userName = null;
  739. if(!ObjectUtils.isEmpty(sceneUserId)){
  740. userName = userService.getSSOUserByUserId(sceneUserId).getUserName();
  741. }
  742. //判断 是否为激光相机
  743. Camera camera = cameraService.getByChildName(mac);
  744. if(Objects.nonNull(scenePlus)){
  745. fdkkLaserService.saveScene(scenePlus,fdageJson,camera,userName,false, scenePlus.getPayStatus());
  746. }else{
  747. fdkkLaserService.saveScene(scenePro,fdageJson.getString("pwd"),camera,userName,false, scenePro.getPayStatus());
  748. }
  749. }
  750. return ResultData.ok();
  751. }
  752. public ScenePlusVO createScenePlus(String projectNum, Long cameraId, String cameraName, String phoneId, String sceneKey,
  753. String unicode, Long cameraType, int camType, String dataSource, String pic, Long userId, String userName,
  754. String algorithm, Integer location, Integer sceneShootCount, String sceneName,
  755. String sceneDec, Integer sceneType, String gps,Integer type,
  756. Integer resolution, String firmwareVersion, String url, String buildType,
  757. Long cooperationUser)throws Exception{
  758. ScenePlusVO scenePlusVO = new ScenePlusVO();
  759. ScenePlus scenePlus = new ScenePlus();
  760. ScenePlusExt scenePlusExt = new ScenePlusExt();
  761. scenePlusExt.setWebSite(url+projectNum);
  762. scenePlus.setCameraId(cameraId);
  763. scenePlus.setPhoneId(phoneId);
  764. scenePlus.setNum(projectNum);
  765. scenePlus.setSceneSource(SceneSource.BM.code());
  766. scenePlusExt.setDataSource(dataSource);
  767. scenePlusExt.setLocation(location);
  768. if(resolution == null || resolution.intValue() == 0){
  769. scenePlusExt.setSceneScheme(cameraType.intValue());
  770. }else {
  771. scenePlusExt.setSceneScheme(SceneScheme.BM.code());
  772. }
  773. if(cameraType == 6){
  774. scenePlusVO.setThreeCamType("yzl");
  775. }
  776. //转台相机用4k图
  777. if(cameraType.longValue() == 13){
  778. scenePlus.setSceneSource(SceneSource.ZT.code());
  779. scenePlusExt.setSceneScheme(SceneScheme.FOUR_K.code());
  780. }
  781. //激光相机
  782. if(cameraType.longValue() == 14){
  783. scenePlus.setSceneSource(SceneSource.JG.code());
  784. scenePlusExt.setSceneScheme(SceneScheme.FOUR_K.code());
  785. if(camType == CameraTypeEnum.LASER_SG.getType()){
  786. scenePlus.setSceneSource(SceneSource.SG.code());
  787. }
  788. }
  789. //全景看看场景用相机类型包括 看看 看见 深时 深光,所以这里做一个统一处理,为了让场景不在各平台中显示出来
  790. if(Objects.nonNull(location) && location == 7){
  791. scenePlus.setSceneSource(SceneSource.QJKK.code());
  792. }
  793. if(ModelKind.THREE_D_TILE.code().equals(modelKind)
  794. && CollUtil.isNotEmpty(sdTilesSceneSourceList)
  795. && sdTilesSceneSourceList.contains(scenePlus.getSceneSource())){
  796. scenePlusExt.setModelKind(modelKind);
  797. }
  798. if (pic != null && pic.length() > 5) {
  799. scenePlusExt.setThumb(pic);
  800. } else {
  801. scenePlusExt.setThumb(fYunFileConfig.getHost() + "/loading/thumb.jpg");
  802. }
  803. scenePlusExt.setThumb(scenePlusExt.getThumb().concat("?t=") + System.currentTimeMillis());
  804. scenePlus.setUserId(userId);
  805. if (sceneShootCount == null) {
  806. scenePlusExt.setShootCount(0);
  807. } else {
  808. scenePlusExt.setShootCount(sceneShootCount);
  809. }
  810. if (sceneName != null) {
  811. scenePlus.setTitle(sceneName);
  812. }
  813. if (sceneDec != null) {
  814. scenePlus.setDescription("<p>" + new String(sceneDec.getBytes("UTF-8")) + "</p>");
  815. }
  816. if (sceneType != null) {
  817. scenePlus.setSceneType(sceneType);
  818. }
  819. if (gps != null && !gps.trim().equals("")) {
  820. scenePlusExt.setGps(gps);
  821. }
  822. scenePlusExt.setAlgorithm(algorithm);
  823. if(!org.springframework.util.StringUtils.isEmpty(firmwareVersion)){
  824. scenePlusExt.setFirmwareVersion(firmwareVersion);
  825. }
  826. scenePlusExt.setBuildType(buildType);
  827. log.info("场景记录添加到数据库:"+projectNum);
  828. //type=0为新生成场景,其余为重新计算场景
  829. if(camType == 5){//圆周率
  830. scenePlus.setThreeCamType("yzl");
  831. }
  832. SceneEditInfo sceneEditInfo = new SceneEditInfo();
  833. SceneEditInfoExt sceneEditInfoExt = new SceneEditInfoExt();
  834. SceneEditControls sceneEditControls = new SceneEditControls();
  835. if(type == 0){
  836. scenePlus.setSceneStatus(SceneStatus.wait.code());
  837. scenePlusService.save(scenePlus);
  838. scenePlusExt.setPlusId(scenePlus.getId());
  839. scenePlusExtService.save(scenePlusExt);
  840. sceneEditInfo.setTitle(scenePlus.getTitle());
  841. sceneEditInfo.setDescription(scenePlus.getDescription());
  842. sceneEditInfo.setScenePlusId(scenePlus.getId());
  843. if(StrUtil.isNotBlank(sceneKey)) {
  844. sceneEditInfo.setScenePassword(sceneKey);
  845. sceneEditControls.setShowLock((int) CommonStatus.YES.code());
  846. }
  847. sceneEditInfoService.save(sceneEditInfo);
  848. sceneEditInfoExt.setEditInfoId(sceneEditInfo.getId());
  849. sceneEditInfoExt.setScenePlusId(scenePlus.getId());
  850. sceneEditInfoExtService.save(sceneEditInfoExt);
  851. sceneEditControls.setEditInfoId(sceneEditInfo.getId());
  852. sceneEditControlsService.save(sceneEditControls);
  853. //新增场景时,同时新增场景协作信息
  854. if(cooperationUser != null){
  855. SceneCooperation sceneCooperationEntity = new SceneCooperation();
  856. sceneCooperationEntity.setNum(projectNum);
  857. sceneCooperationEntity.setUserId(cooperationUser);
  858. sceneCooperationService.save(sceneCooperationEntity);
  859. List<SceneResourceCamera> resourceCameraList = sceneResourceCameraService.findListByCameraId(cameraId);
  860. SceneResourceCooperation sceneResourceCooperation = null;
  861. if(resourceCameraList != null && resourceCameraList.size() > 0){
  862. for (SceneResourceCamera sceneResourceCamera : resourceCameraList) {
  863. sceneResourceCooperation = new SceneResourceCooperation();
  864. sceneResourceCooperation.setSceneResourceId(sceneResourceCamera.getSceneResourceId());
  865. sceneResourceCooperation.setSceneCooperationId(sceneCooperationEntity.getId());
  866. sceneResourceCooperationService.save(sceneResourceCooperation);
  867. }
  868. }
  869. }
  870. }else {
  871. ScenePlus oldScene = scenePlusService.getScenePlusByNum(projectNum);
  872. scenePlus.setId(oldScene.getId());
  873. scenePlus.setSceneStatus(SceneStatus.wait.code());
  874. scenePlus.setRecStatus(RecStatus.VALID.code());
  875. scenePlus.setPayStatus(PayStatus.NOT_PAY.code());
  876. scenePlus.setCreateTime(Calendar.getInstance().getTime());
  877. ScenePlusExt oldSceneExt = scenePlusExtService.getScenePlusExtByPlusId(oldScene.getId());
  878. scenePlusExt.setSpace(oldSceneExt.getSpace());
  879. scenePlusExt.setEcs(oldSceneExt.getEcs());
  880. scenePlusExt.setViewCount(oldSceneExt.getViewCount());
  881. if(sceneName!=null) {
  882. scenePlus.setTitle(sceneName);
  883. }
  884. if(sceneType!=null) {
  885. scenePlus.setSceneType(sceneType);
  886. }
  887. scenePlusService.updateById(scenePlus);
  888. scenePlusExtService.updateById(scenePlusExt);
  889. SceneEditInfo oldSceneEditInfo = sceneEditInfoService.getByScenePlusId(oldScene.getId());
  890. SceneEditInfoExt oldSceneEditeIinfoExt = sceneEditInfoExtService.getByEditInfoId(oldSceneEditInfo.getId());
  891. sceneEditInfo.setTitle(scenePlus.getTitle());
  892. sceneEditInfo.setDescription(scenePlus.getDescription());
  893. sceneEditInfo.setId(oldSceneEditInfo.getId());
  894. sceneEditInfo.setScenePlusId(scenePlus.getId());
  895. sceneEditInfo.setFloorLogoSize(100);
  896. sceneEditInfo.setRecStatus(RecStatus.VALID.code());
  897. sceneEditInfo.setFloorPublishVer(oldSceneEditInfo.getFloorEditVer() + 1);
  898. sceneEditInfo.setFloorEditVer(oldSceneEditInfo.getFloorEditVer() + 1);
  899. sceneEditInfo.setVersion(oldSceneEditInfo.getVersion() + 1);
  900. sceneEditInfoService.updateById(sceneEditInfo);
  901. if(Objects.nonNull(oldSceneEditeIinfoExt)){
  902. sceneEditInfoExt.setId(oldSceneEditeIinfoExt.getId());
  903. }
  904. sceneEditInfoExt.setEditInfoId(sceneEditInfo.getId());
  905. sceneEditInfoExt.setScenePlusId(scenePlus.getId());
  906. sceneEditInfoExtService.saveOrUpdate(sceneEditInfoExt);
  907. }
  908. BeanUtil.copyProperties(scenePlusExt, scenePlusVO);
  909. BeanUtil.copyProperties(scenePlus, scenePlusVO);
  910. return scenePlusVO;
  911. }
  912. public ScenePlusVO createScenePro(String projectNum, Long cameraId, String cameraName, String phoneId, String sceneKey,
  913. String unicode, Long cameraType, String fileId, String pic, Long userId, String userName,
  914. String algorithm, Integer sceneShootCount, String sceneName,String sceneDec,
  915. Integer sceneType, String gps,Integer resolution, String firmwareVersion, String buildType
  916. )throws Exception{
  917. ScenePro scene = sceneProService.getByNum(projectNum);
  918. SceneProEdit sceneEdit = sceneProEditService.getByProId(scene.getId());
  919. scene.setCameraId(cameraId);
  920. scene.setPhoneId(phoneId);
  921. scene.setNum(projectNum);
  922. scene.setSpace(0L);
  923. if (pic != null && pic.length() > 5) {
  924. scene.setThumb(pic);
  925. } else {
  926. scene.setThumb(ConstantUrl.DEFAULT_SCENE_PIC);
  927. }
  928. scene.setThumb(scene.getThumb().concat("?t=") + System.currentTimeMillis());
  929. if (!ObjectUtils.isEmpty(userName)) {
  930. scene.setUserId(userId);
  931. }
  932. if (sceneShootCount == null) {
  933. scene.setShootCount(0);
  934. } else {
  935. scene.setShootCount(sceneShootCount);
  936. }
  937. if (sceneName != null) {
  938. scene.setSceneName(sceneName);
  939. }
  940. if (sceneDec != null) {
  941. scene.setSceneDec("<p>" + new String(sceneDec.getBytes("UTF-8")) + "</p>");
  942. }
  943. if (sceneType != null) {
  944. scene.setSceneType(sceneType);
  945. }
  946. if (gps != null && !gps.trim().equals("")) {
  947. scene.setGps(gps);
  948. }
  949. scene.setAlgorithm(algorithm);
  950. if(!org.springframework.util.StringUtils.isEmpty(firmwareVersion)){
  951. scene.setFirmwareVersion(firmwareVersion);
  952. }
  953. scene.setBuildType(buildType);
  954. log.info("场景记录添加到数据库:"+projectNum);
  955. scene.setStatus(0);
  956. scene.setPayStatus(0);
  957. scene.setRecStatus("A");
  958. scene.setCreateTime(new Date());
  959. if (sceneName != null) {
  960. scene.setSceneName(sceneName);
  961. }
  962. if (sceneType != null) {
  963. scene.setSceneType(sceneType);
  964. }
  965. sceneProService.updateById(scene);
  966. sceneEdit.setNeedKey(0);
  967. if (cameraType.longValue() != 14 && !ObjectUtils.isEmpty(sceneKey)) {
  968. sceneEdit.setNeedKey(1);
  969. sceneEdit.setSceneKey(sceneKey);
  970. }
  971. sceneEdit.setProId(scene.getId());
  972. sceneEdit.setMapVisi(1);
  973. sceneEdit.setTourVisi(1);
  974. sceneEdit.setVrVisi(1);
  975. sceneEdit.setCadImgVisi(1);
  976. sceneEdit.setPanoVisi(1);
  977. sceneEdit.setOverlay(null);
  978. sceneEdit.setM2dVisi(1);
  979. sceneEdit.setPlayData(null);
  980. sceneEdit.setFloorLogo("0");
  981. sceneEdit.setM3dVisi(1);
  982. sceneEdit.setJumpScene(false);
  983. sceneEdit.setMeasureVisi(0);
  984. sceneEdit.setFloorLogoSize(100);
  985. sceneEdit.setUpdateTime(new Date());
  986. sceneEdit.setRecStatus("A");
  987. sceneEdit.setFloorPublishVer(sceneEdit.getFloorEditVer() + 1);
  988. sceneEdit.setFloorEditVer(sceneEdit.getFloorEditVer() + 1);
  989. sceneEdit.setVersion(sceneEdit.getVersion() + 1);
  990. sceneEdit.setImagesVersion(sceneEdit.getImagesVersion() + 1);
  991. sceneProEditService.updateById(sceneEdit);
  992. JSONObject scenejson = JSONObject.parseObject(JSONObject.toJSONString(scene));
  993. scenejson.put("thumbImg", 0);
  994. scenejson.put("version", sceneEdit.getVersion());
  995. scenejson.put("floorLogo", 0);
  996. if(!ObjectUtils.isEmpty(sceneKey)){
  997. scenejson.put("sceneKey", sceneKey);
  998. scenejson.put("public", 1);
  999. }else{
  1000. scenejson.put("sceneKey", "");
  1001. scenejson.put("public", 0);
  1002. }
  1003. if(cameraType.longValue() < 4 || cameraType.longValue() == 5 || cameraType.longValue() == 6){
  1004. scenejson.put("visions", 1);
  1005. }else {
  1006. scenejson.put("visions", 2);
  1007. }
  1008. scenejson.put("createTime", new DateTime(new Date()).toString("yyyy-MM-dd HH:mm"));
  1009. scenejson.put("floorPublishVer", sceneEdit.getFloorPublishVer());
  1010. scenejson.put("floorEditVer", sceneEdit.getFloorEditVer());
  1011. scenejson.put("rulerVisi", sceneEdit.getRulerVisi());
  1012. scenejson.put("entry", null);
  1013. if(!org.springframework.util.StringUtils.isEmpty(sceneEdit.getHotsIds())){
  1014. scenejson.put("hots", 1);
  1015. }
  1016. File file = new File(ConstantFilePath.SCENE_PATH+"data/data"+projectNum);
  1017. if(!file.exists()||!file.isDirectory())
  1018. {
  1019. file.mkdirs();
  1020. }
  1021. FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data/data"+projectNum+File.separator+"scene.json", scenejson.toString());
  1022. //生成二维码
  1023. MatrixToImageWriterUtil.createQRCode(scene.getWebSite(), ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+projectNum+".png",false, null);
  1024. MatrixToImageWriterUtil.createQRCode(scene.getWebSite() + "&lang=en", ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+projectNum+"_en.png",false, null);
  1025. log.info("二维码生成完成");
  1026. ScenePlusVO scenePlusVO = new ScenePlusVO();
  1027. scenePlusVO.setSceneStatus(scene.getStatus());
  1028. scenePlusVO.setThumb(scene.getThumb());
  1029. scenePlusVO.setPayStatus(scene.getPayStatus());
  1030. scenePlusVO.setId(scene.getId());
  1031. scenePlusVO.setNum(scene.getNum());
  1032. scenePlusVO.setWebSite(scene.getWebSite());
  1033. scenePlusVO.setDataSource(scene.getDataSource());
  1034. return scenePlusVO;
  1035. }
  1036. public BuildSceneCallMessage getBuildSceneMqMessage(String projectNum,
  1037. Long cameraType, String algorithm, JSONObject fdageJson,
  1038. String buildType, String dataSource) {
  1039. BuildSceneCallMessage mqMsg = new BuildSceneCallMessage();
  1040. mqMsg.setSceneNum(projectNum);
  1041. mqMsg.setCameraType(String.valueOf(cameraType));
  1042. mqMsg.setAlgorithm(algorithm);
  1043. mqMsg.setResolution(String.valueOf(fdageJson.getInteger("resolution")));
  1044. mqMsg.setBuildType(buildType);
  1045. mqMsg.setPath(dataSource);
  1046. mqMsg.setCreateTime(DateUtil.format(Calendar.getInstance().getTime(), DateExtUtil.dateStyle));
  1047. Map<String, Object> ext = new HashMap<>();
  1048. ext.put("location", fdageJson.getInteger("location"));
  1049. mqMsg.setExt(ext);
  1050. return mqMsg;
  1051. }
  1052. @Override
  1053. public ResultData rebuildScene(String num,Boolean force,Boolean deleteExtras, String from) throws IOException {
  1054. ScenePro scenePro = sceneProService.getByNum(num);
  1055. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  1056. //复制出来的场景不支持重算
  1057. List<SceneCopyLog> sceneCopyLogs = sceneCopyLogService. listByNewNum(num);
  1058. if(CollUtil.isNotEmpty(sceneCopyLogs)){
  1059. throw new BusinessException(ErrorCode.FAILURE_CODE_5071);
  1060. }
  1061. //已删除原始资源的场景不支持重算
  1062. Long cameraId = null;
  1063. Date laseCallTime = null;
  1064. ScenePlusExt scenePlusExt = null;
  1065. if(Objects.nonNull(scenePlus)){
  1066. scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  1067. laseCallTime = scenePlusExt.getAlgorithmTime();
  1068. cameraId = scenePlus.getCameraId();
  1069. }else{
  1070. laseCallTime = scenePro.getCreateTime();
  1071. cameraId = scenePro.getCameraId();
  1072. }
  1073. // //查询场景是否处于冻结状态,如果已冻结,不允许重算
  1074. // SceneColdStorage sceneColdStorage = sceneColdStorageService.getOne(new LambdaQueryWrapper<SceneColdStorage>().eq(SceneColdStorage::getNum, num).eq(SceneColdStorage::getState, 1));
  1075. // if(Objects.nonNull(sceneColdStorage)){
  1076. // throw new BusinessException(ErrorCode.FAILURE_CODE_5074);
  1077. // }
  1078. //
  1079. // //查询最后一次计算时间后是否有删除过目录,如果有,则不支持重算
  1080. // List<SceneCleanOrig> sceneCleanOrigs = sceneCleanOrigService.lisByNumAfterLastCall(num, laseCallTime);
  1081. // if(CollUtil.isNotEmpty(sceneCleanOrigs)){
  1082. // throw new BusinessException(ErrorCode.FAILURE_CODE_5072);
  1083. // }
  1084. //激光场景校验是否能够计算
  1085. this.checkJgCanBuild(scenePro);
  1086. // if(Objects.nonNull(scenePro) && (Objects.isNull(scenePro.getIsUpgrade())
  1087. // || scenePro.getIsUpgrade() != CommonStatus.YES.code().intValue())){
  1088. // return rebuildV3Scene(scenePro,num,force);
  1089. // }
  1090. if(Objects.isNull(scenePlus)){
  1091. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1092. }
  1093. if (scenePlus.getSceneStatus() == 0 && (ObjectUtils.isEmpty(force) || !force)) {
  1094. throw new BusinessException(ErrorCode.FAILURE_CODE_5033);
  1095. }
  1096. String path = scenePlusExt.getDataSource();
  1097. Integer sceneSource = scenePlus.getSceneSource();
  1098. String buildType = scenePlusExt.getBuildType();
  1099. Integer sceneScheme = scenePlusExt.getSceneScheme();
  1100. String dataFdageOssPath = ConstantFilePath.OSS_PREFIX+ path.replace(ConstantFilePath.BUILD_MODEL_PATH, "")
  1101. .replace(ConstantFilePath.BUILD_MODEL_LASER_PATH, "") + "/data.fdage";
  1102. JSONObject fdageData = JSONObject.parseObject(fYunFileService.getFileContent(dataFdageOssPath));
  1103. if(ObjectUtils.isEmpty(fdageData)){
  1104. log.error("data.fdage文件不存在");
  1105. return ResultData.error(CameraConstant.FAILURE_6009.code(), CameraConstant.FAILURE_6009.message());
  1106. }
  1107. //重算的场景,先移除该场景对应的容量
  1108. CameraDetail cameraDetail = cameraDetailService.getByCameraId(cameraId);
  1109. if(CollUtil.isEmpty(laserCamTypeList) || !laserCamTypeList.contains(cameraDetail.getType())){
  1110. try {
  1111. scenePlusService.resetSpace(num);
  1112. }catch (Exception e){
  1113. log.error("重置容量失败", e);
  1114. }
  1115. }
  1116. String statusJsonOssPath = String.format(UploadFilePath.DATA_VIEW_PATH, num) + "status.json";
  1117. JSONObject statusJson = JSONObject.parseObject(fYunFileService.getFileContent(String.format(UploadFilePath.DATA_VIEW_PATH, num) + "status.json"));
  1118. if(ObjectUtils.isEmpty(statusJson)){
  1119. statusJson = new JSONObject();
  1120. }
  1121. //临时将-2改成1,app还没完全更新
  1122. statusJson.put("status", SceneStatus.wait.code());
  1123. fYunFileService.uploadFile(statusJson.toJSONString().getBytes(StandardCharsets.UTF_8),statusJsonOssPath);
  1124. Long cameraType = (long)sceneScheme == 3 ? 12 : (long)sceneScheme;
  1125. //判断是否转台相机
  1126. if(sceneSource == 3){
  1127. cameraType = 13L;
  1128. }
  1129. if(sceneSource == 4 || sceneSource == 5){
  1130. cameraType = 14L;
  1131. }
  1132. String threeCamType = scenePlus.getThreeCamType();
  1133. if(StrUtil.isNotEmpty(threeCamType) && "yzl".equals(threeCamType)){
  1134. cameraType = 6L;
  1135. }
  1136. BuildSceneCallMessage message = null;
  1137. if(cameraType == 14){
  1138. String userName = null;
  1139. Long sceneUserId = scenePlus.getUserId();
  1140. if (!ObjectUtils.isEmpty(sceneUserId)) {
  1141. SSOUser user = userService.getSSOUserByUserId(sceneUserId);
  1142. userName = user.getUserName();
  1143. }
  1144. Camera cameraEntity = cameraService.getById(scenePlus.getCameraId());
  1145. if(Objects.isNull(scenePlusExt.getLocation()) || scenePlusExt.getLocation() != 7){
  1146. fdkkLaserService.saveScene(scenePlus,null,cameraEntity,userName,true, scenePlus.getPayStatus());
  1147. }
  1148. message = this.getBuildSceneMqMessage(
  1149. num, cameraType, fdageData.getString("location") != null && "1".equals(fdageData.getString("location")) ? "sfm" : "slam",
  1150. fdageData, buildType, path);
  1151. }else{
  1152. message = this.getBuildSceneMqMessage(
  1153. num, cameraType, fdageData.getString("location") != null && "1".equals(fdageData.getString("location")) ? "sfm" : "slam",
  1154. fdageData, buildType, path);
  1155. message.getExt().put("threeCamType", threeCamType);
  1156. }
  1157. if(deleteExtras){
  1158. message.getExt().put("deleteExtras",deleteExtras);
  1159. }
  1160. if (force) {
  1161. message.setRebuild("1");
  1162. }
  1163. if(Objects.nonNull(scenePlusExt.getLocation()) && scenePlusExt.getLocation() == 7){
  1164. //发送到全景看看进行初始化
  1165. JSONObject jsonObject = JSONObject.parseObject(fYunFileService.getFileContent(SceneUtil.getHomePath(scenePlusExt.getDataSource()) + "data.fdage"));
  1166. intermitSceneService.sendMq(num, jsonObject, CommonSuccessStatus.WAITING.code());
  1167. rabbitMqProducer.sendByWorkQueue(queueIntermitModelingPre, message);
  1168. }else{
  1169. rabbitMqProducer.sendByWorkQueue(queueModelingPre, message);
  1170. }
  1171. scenePlusService.update(new LambdaUpdateWrapper<ScenePlus>()
  1172. .set(ScenePlus::getSceneStatus, SceneStatus.wait.code())
  1173. .eq(ScenePlus::getNum, num));
  1174. if(ModelKind.THREE_D_TILE.code().equals(modelKind)
  1175. && CollUtil.isNotEmpty(sdTilesSceneSourceList)
  1176. && sdTilesSceneSourceList.contains(scenePlus.getSceneSource())){
  1177. scenePlusExt.setModelKind(modelKind);
  1178. }
  1179. scenePlusExtService.updateById(scenePlusExt);
  1180. //记录日志表
  1181. SceneRebuildLog rebuildLog = new SceneRebuildLog();
  1182. rebuildLog.setNum(num);
  1183. rebuildLog.setSource(from);
  1184. sceneRebuildLogService.save(rebuildLog);
  1185. return ResultData.ok();
  1186. }
  1187. /**
  1188. * 由于算法不支持2022年三月份前的激光场景计算,这里需要校验是否是能计算,不能就退出重算
  1189. * @return
  1190. */
  1191. private void checkJgCanBuild(ScenePro scenePro){
  1192. if(Objects.isNull(scenePro) || StrUtil.isEmpty(scenePro.getDataSource()) || !SceneSource.JG.code().equals(scenePro.getSceneSource())){
  1193. return;
  1194. }
  1195. cn.hutool.core.date.DateTime limitTime = DateExtUtil.parse(jgNotSupportBuildTime, DateExtUtil.dateStyle10);
  1196. String dataSource = scenePro.getDataSource();
  1197. String sceneDateTimeStr = dataSource.substring(dataSource.lastIndexOf("_") + 1).substring(0, 6);
  1198. //如果截取的时间串是空的,无法判断时间,就退出,正常走计算逻辑
  1199. if(StrUtil.isEmpty(sceneDateTimeStr)){
  1200. return;
  1201. }
  1202. cn.hutool.core.date.DateTime sceneDateTime = null;
  1203. try{
  1204. sceneDateTime = DateExtUtil.parse(sceneDateTimeStr, DateExtUtil.dateStyle10);
  1205. if(Objects.isNull(sceneDateTime)){
  1206. return;
  1207. }
  1208. }catch (Exception e){
  1209. //如果截取的时间串转换日期错误,无法判断时间,退出函数
  1210. return;
  1211. }
  1212. if(sceneDateTime.before(limitTime)){
  1213. throw new BusinessException(ErrorCode.FAILURE_CODE_5067);
  1214. }
  1215. }
  1216. // public ResultData rebuildV3Scene(ScenePro scenePro,String num,Boolean force) throws IOException {
  1217. //
  1218. // JSONObject configJson = JSONObject.parseObject(FileUtils.readFile(configJsonPath));
  1219. // String folderName = configJson.getString("id");
  1220. // String customUserId = configJson.getString("customUserId");
  1221. // if(StrUtil.isBlank(folderName) || StrUtil.isBlank(snCode)){
  1222. // throw new RuntimeException("config.json 文件有误!");
  1223. // }
  1224. //
  1225. // // 检测是否有生成
  1226. // String fileId = getFileIdByFolderName(folderName);
  1227. // String subFolder = snCode.concat(File.separator).concat(fileId).concat(File.separator).concat(folderName);
  1228. // // 解压获取dataSource 并上传资源到OSS
  1229. // String dataSource = ConstantFilePath.BUILD_MODEL_PATH.concat(subFolder);
  1230. // log.info("dataSource 为:{}", dataSource);
  1231. //
  1232. // scenePre.setFileId(fileId);
  1233. // scenePre.setStatus(1);
  1234. // scenePre.setUpdateTime(new Date());
  1235. // scenePreService.updateById(scenePre);
  1236. // log.info("异步开始上传文件");
  1237. // // 上传oaas
  1238. // fYunFileService.uploadFileByCommand(dataPath, ConstantFilePath.OSS_PREFIX.concat(subFolder));
  1239. //
  1240. // //删除本地压缩包,防止补拍上传文件不一致
  1241. // FileUtil.del(parentPath);
  1242. //
  1243. // scenePre.setOssPath(ConstantFilePath.OSS_PREFIX.concat(subFolder));
  1244. // scenePre.setStatus(2);
  1245. // scenePre.setUpdateTime(new Date());
  1246. // scenePreService.updateById(scenePre);
  1247. // log.info("文件上传成功,开始通知计算");
  1248. // // 通知计算
  1249. // this.copyDataAndBuild(null, dataSource, "V4", null, customUserId);
  1250. // log.info("通知计算成功");
  1251. //
  1252. // scenePre.setStatus(3);
  1253. // scenePre.setUpdateTime(new Date());
  1254. // scenePreService.updateById(scenePre);
  1255. // } catch (Exception e) {
  1256. // log.error("上传失败", e);
  1257. // scenePre.setStatus(CommonSuccessStatus.FAIL.code());
  1258. // scenePreService.updateById(scenePre);
  1259. // }
  1260. // }, executor);
  1261. // }finally {
  1262. // executor.shutdown();
  1263. // }
  1264. // return ResultData.ok();
  1265. // }
  1266. private String getFileIdByFolderName(String folderName) {
  1267. // 检测是否有生成
  1268. String fileId = redisUtil.get(String.format(RedisConstants.FOLDER_FILEID_BUILD, folderName));
  1269. if (!org.springframework.util.ObjectUtils.isEmpty(fileId)) {
  1270. return fileId;
  1271. }
  1272. SceneFileBuild sceneFileBuild = this.findByUnicode(folderName);
  1273. if (sceneFileBuild != null) {
  1274. fileId = sceneFileBuild.getFileId();
  1275. redisUtil.set(String.format(RedisConstants.FOLDER_FILEID_BUILD, folderName), fileId, 2 * 24 * 60 * 60);
  1276. return fileId;
  1277. }
  1278. // 加锁
  1279. boolean lock = redisLockUtil.lock(String.format(RedisConstants.FOLDER_LOCK_BUILD, folderName), 120);
  1280. if (!lock) {
  1281. throw new BusinessException(ErrorCode.FAILURE_CODE_5052);
  1282. }
  1283. String dataSource = scenePlusService.getDataSourceLikeUnicode("/" + folderName);
  1284. if (!org.springframework.util.ObjectUtils.isEmpty(dataSource)) {
  1285. log.info("从数据库中查到与 fileId:{} 匹配的路径为:{}", fileId, dataSource);
  1286. int n = dataSource.split("/").length;
  1287. if (n > 1) {
  1288. fileId = dataSource.split("/")[n - 2];
  1289. }
  1290. }
  1291. if (org.springframework.util.ObjectUtils.isEmpty(fileId)) {
  1292. fileId = new SnowflakeIdGenerator(0, 0).nextId() + "";
  1293. log.info("新生成build数据,{}", fileId);
  1294. }
  1295. sceneFileBuild = new SceneFileBuild();
  1296. sceneFileBuild.setChildName(folderName.split("_")[0]);
  1297. sceneFileBuild.setFileId(fileId);
  1298. sceneFileBuild.setRecStatus("A");
  1299. sceneFileBuild.setUnicode(folderName);
  1300. sceneFileBuild.setCreateTime(new Date());
  1301. this.save(sceneFileBuild);
  1302. redisUtil.set(String.format(RedisConstants.FOLDER_FILEID_BUILD, folderName), fileId, 2 * 24 * 60 * 60);
  1303. redisUtil.set(String.format(RedisConstants.FILEID_FOLDER_BUILD, fileId), folderName, 2 * 24 * 60 * 60);
  1304. return fileId;
  1305. }
  1306. public ResultData copyDataAndBuild(String sourceBucet,String dataSource,String sceneVer,User user, String customUserId) throws Exception {
  1307. if(!StringUtils.equals(sceneVer,"V3") && ! StringUtils.equals(sceneVer,"V4")){
  1308. throw new BusinessException(ErrorCode.PARAM_FORMAT_ERROR.code(),"版本有误,请填写 V3 或者 V4");
  1309. }
  1310. String fYunPath = ConstantFilePath.OSS_PREFIX + dataSource.replace(ConstantFilePath.BUILD_MODEL_PATH, "")
  1311. .replace(ConstantFilePath.BUILD_MODEL_LASER_PATH, "");
  1312. if(!ObjectUtils.isEmpty(sourceBucet)){
  1313. fYunFileService.copyFileBetweenBucket(sourceBucet,fYunPath,fYunFileConfig.getBucket(),fYunPath);
  1314. }
  1315. // 下载data.fdage
  1316. JSONObject fdageData = JSONObject.parseObject(fYunFileService.getFileContent(fYunPath + "/data.fdage"));
  1317. if(ObjectUtils.isEmpty(fdageData)){
  1318. throw new BusinessException(ErrorCode.SYSTEM_ERROR.code(),"4dage 文件不存在");
  1319. }
  1320. String cameraName = fdageData.getJSONObject("cam").getString("uuid");
  1321. Camera cameraEntity = cameraService.getByChildName(cameraName);
  1322. if(cameraEntity == null){
  1323. log.error("该相机不存在:" + cameraName);
  1324. throw new BusinessException(ErrorCode.FAILURE_CODE_6003);
  1325. }
  1326. CameraDetail detailEntity = cameraDetailService.getByCameraId(cameraEntity.getId());
  1327. if(detailEntity == null){
  1328. log.error("该相机详情不存在:" + cameraName);
  1329. throw new BusinessException(ErrorCode.FAILURE_CODE_6003);
  1330. }
  1331. Long cameraType = 11L;
  1332. //判断是否转台相机
  1333. if (detailEntity.getType() == 9) {
  1334. cameraType = 13L;
  1335. }
  1336. if (CollUtil.isNotEmpty(laserCamTypeList) && laserCamTypeList.contains(detailEntity.getType())) {
  1337. cameraType = 14L;
  1338. }
  1339. String sceneNum = scene3dNumService.generateSceneNum(detailEntity.getType());
  1340. String icon = null;
  1341. String imgViewPath = null;
  1342. switch (sceneVer) {
  1343. case "V3":
  1344. case "V4":
  1345. int rebuild = 0;
  1346. ScenePlus scenePlus = scenePlusService.getByFileId(dataSource);
  1347. if (!ObjectUtils.isEmpty(scenePlus)) {
  1348. log.info("该场景资源已存在,执行补拍逻辑!");
  1349. rebuild = 1;
  1350. sceneNum = scenePlus.getNum();
  1351. }
  1352. imgViewPath = String.format(UploadFilePath.IMG_VIEW_PATH, sceneNum);
  1353. if(fdageData.containsKey("icon") && StringUtils.isNotEmpty(fdageData.getString("icon"))){
  1354. String ossPath = ConstantFilePath.OSS_PREFIX + dataSource.replace(ConstantFilePath.BUILD_MODEL_PATH, "")
  1355. .replace(ConstantFilePath.BUILD_MODEL_LASER_PATH, "");
  1356. fYunFileService.copyFileInBucket(ossPath + File.separator + fdageData.getString("icon"),imgViewPath + fdageData.getString("icon"));
  1357. icon = fYunFileConfig.getHost() + imgViewPath + fdageData.getString("icon");
  1358. log.info("上传icon成功....");
  1359. }
  1360. // buildScenePost(dataSource, fdageData, "V3", cameraType, sceneNum, cameraEntity, detailEntity, rebuild, icon, user, customUserId, "zip");
  1361. scenePlus = scenePlusService.getScenePlusByNum(sceneNum);
  1362. fdkkLaserService.saveScene(scenePlus,fdageData,cameraEntity,user.getUserName(),rebuild == 1 ? true : false, scenePlus.getPayStatus());
  1363. break;
  1364. }
  1365. Map<String,Object> result = new HashMap<>();
  1366. result.put("code",sceneNum);
  1367. return ResultData.ok(result);
  1368. }
  1369. private ScenePlusVO buildScenePost(String dataSource, JSONObject jsonObject, String buildType, long cameraType,
  1370. String sceneNum, Camera camera, CameraDetail cameraDetail, int rebuild,String icon,User user) throws Exception {
  1371. String imgViewPath = String.format(UploadFilePath.IMG_VIEW_PATH, sceneNum);
  1372. JSONObject firmwareVersion = new JSONObject();
  1373. if (!ObjectUtils.isEmpty(jsonObject.getString("camSoftwareVersion"))) {
  1374. firmwareVersion.put("camSoftwareVersion", jsonObject.getString("camSoftwareVersion"));
  1375. }
  1376. if (!ObjectUtils.isEmpty(jsonObject.getString("version"))) {
  1377. firmwareVersion.put("version", jsonObject.getString("version"));
  1378. }
  1379. String sceneUrl = "/" + sceneProNewUrl;
  1380. //重算的场景,先移除该场景对应的容量
  1381. if (rebuild == 1) {
  1382. // try {
  1383. // scenePlusService.resetSpace(sceneNum);
  1384. // }catch (Exception e){
  1385. // log.error("重置容量失败", e);
  1386. // }
  1387. // //删除oss的houst_floor.json(国际版可能会卡住)
  1388. // fYunFileService.deleteFile(dataViewPath + "houst_floor.json");
  1389. } else {
  1390. //上传log-main.png
  1391. fYunFileService.uploadFile(ConstantFilePath.LOGO_PATH + "logo-main.png", imgViewPath + "logo-main.png");
  1392. fYunFileService.uploadFile(ConstantFilePath.LOGO_PATH + "logo-main-en.png", imgViewPath + "logo-main-en.png");
  1393. }
  1394. String algorithm = jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam";
  1395. String unicode = jsonObject.getString("creator") + "_" + jsonObject.getString("uuidtime");
  1396. ScenePlusVO scenePlusVO = this.createScenePlus(sceneNum, camera.getId(), camera.getChildName(), jsonObject.getString("creator"),
  1397. jsonObject.getString("pwd"), unicode, cameraType,jsonObject.getJSONObject("cam").getIntValue("type"), dataSource, icon, user.getId() , null, algorithm, jsonObject.getInteger("location"),
  1398. jsonObject.getJSONArray("points").size(), jsonObject.getString("name"), jsonObject.getString("info"),
  1399. jsonObject.getInteger("scenetype"), jsonObject.getString("gps"), rebuild,
  1400. jsonObject.getInteger("resolution"), firmwareVersion.toString(), sceneUrl, buildType, cameraDetail.getCooperationUser());
  1401. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(sceneNum);
  1402. scenePlus.setTaskId(jsonObject.getString("taskId"));
  1403. scenePlus.setKNo(jsonObject.getString("kNo"));
  1404. scenePlusService.updateById(scenePlus);
  1405. BuildSceneCallMessage mqMessage = getBuildSceneMqMessage(sceneNum, cameraType, algorithm, jsonObject, buildType, scenePlusVO.getDataSource());
  1406. if (cameraDetail.getCompanyId() != null) {
  1407. Company company = companyService.getById(cameraDetail.getCompanyId());
  1408. if (company != null && !ObjectUtils.isEmpty(company.getCalculateFlexibility()) && !company.getCalculateFlexibility()) {
  1409. mqMessage.setFlexibility(-1);
  1410. }
  1411. }
  1412. mqMessage.getExt().put("deleteExtras", true);
  1413. mqMessage.getExt().put("gps", jsonObject.getString("gps"));
  1414. mqMessage.getExt().put("threeCamType", scenePlusVO.getThreeCamType());
  1415. rabbitMqProducer.sendByWorkQueue(queueModelingPre, mqMessage);
  1416. return scenePlusVO;
  1417. }
  1418. private void buildV3Scene2(String dataSource,JSONObject jsonObject,long cameraType,String sceneNum,Camera cameraEntity,CameraDetail detailEntity,String icon) throws Exception {
  1419. String cameraName = jsonObject.getJSONObject("cam").getString("uuid");
  1420. log.info("查询相机:" + cameraName);
  1421. String userName = null;
  1422. if(detailEntity.getUserId() != null){
  1423. SSOUser user = userService.getSSOUserByUserId(detailEntity.getUserId());
  1424. userName = user.getUserName();
  1425. }
  1426. JSONObject firmwareVersion = new JSONObject();
  1427. if(jsonObject.containsKey("camSoftwareVersion") && StringUtils.isNotEmpty(jsonObject.getString("camSoftwareVersion"))){
  1428. firmwareVersion.put("camSoftwareVersion", jsonObject.getString("camSoftwareVersion"));
  1429. }
  1430. if(jsonObject.containsKey("version") && StringUtils.isNotEmpty(jsonObject.getString("version"))){
  1431. firmwareVersion.put("version", jsonObject.getString("version"));
  1432. }
  1433. String buildType = "V3";
  1434. String sceneUrl = mainUrl + "/" + sceneProV3Url;
  1435. boolean isObj = jsonObject.containsKey("exportMeshObj") && jsonObject.getIntValue("exportMeshObj") == 1;
  1436. ScenePro scenePro = createScenePro(sceneNum, detailEntity.getCameraId(), jsonObject.getString("creator"),
  1437. jsonObject.getString("pwd"),
  1438. cameraType, dataSource, "", icon, detailEntity.getUserId(), userName,
  1439. jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam",
  1440. jsonObject.getJSONArray("points").size(), jsonObject.getString("name"), jsonObject.getString("info"),
  1441. jsonObject.getInteger("scenetype"), jsonObject.getString("gps"), 0,
  1442. jsonObject.getInteger("resolution"), firmwareVersion.toString(), sceneUrl, buildType,
  1443. detailEntity.getCooperationUser(), isObj);
  1444. // 通知激光场景系统开始构建场景
  1445. if(cameraType == 14){
  1446. scenePro.setStatus(0);
  1447. fdkkLaserService.saveScene(scenePro, jsonObject.getString("pwd"), cameraEntity, userName, false, scenePro.getPayStatus());
  1448. }
  1449. BuildSceneCallMessage buildSceneMqMessage = this.getBuildSceneMqMessage(
  1450. sceneNum, cameraType, jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam",
  1451. jsonObject, buildType, dataSource);
  1452. rabbitMqProducer.sendByWorkQueue(queueV3ModelingPre, buildSceneMqMessage);
  1453. }
  1454. public ScenePro createScenePro(String projectNum, Long cameraId, String phoneId, String sceneKey,
  1455. Long cameraType, String dataSource, String imgsName,
  1456. String pic, Long userId, String userName, String algorithm,
  1457. Integer sceneShootCount, String sceneName, String sceneDec, Integer sceneType,
  1458. String gps, Integer type, Integer resolution, String firmwareVersion, String url,
  1459. String buildType, Long cooperationUser,Boolean isObj) throws Exception {
  1460. ScenePro scene;
  1461. SceneProEdit sceneEdit;
  1462. if (type == 0) {
  1463. scene = new ScenePro();
  1464. sceneEdit = new SceneProEdit();
  1465. } else {
  1466. scene = sceneProService.getByNum(projectNum);
  1467. sceneEdit = sceneProEditService.getByProId(scene.getId());
  1468. }
  1469. //先返回链接地址
  1470. scene.setWebSite(url + projectNum);
  1471. scene.setCameraId(cameraId);
  1472. scene.setPhoneId(phoneId);
  1473. scene.setNum(projectNum);
  1474. scene.setSceneSource(1);
  1475. scene.setDataSource(dataSource);
  1476. if (cameraType.longValue() == 5 || cameraType.longValue() == 6) {
  1477. //场景来源双目相机
  1478. scene.setSceneSource(2);
  1479. }
  1480. if (resolution == null || resolution.intValue() == 0) {
  1481. scene.setSceneScheme(cameraType.intValue());
  1482. } else {
  1483. scene.setSceneScheme(4);
  1484. }
  1485. //场景来源双目相机,sceneScheme为4,加载high,low图
  1486. if (cameraType.longValue() == 5 || cameraType.longValue() == 6) {
  1487. scene.setSceneScheme(4);
  1488. }
  1489. //转台相机用4k图
  1490. if (cameraType.longValue() == 13) {
  1491. scene.setSceneSource(3);
  1492. scene.setSceneScheme(10);
  1493. }
  1494. //激光相机
  1495. if (cameraType.longValue() == 14) {
  1496. scene.setSceneSource(4);
  1497. scene.setSceneScheme(10);
  1498. }
  1499. if (pic != null && pic.length() > 5) {
  1500. scene.setThumb(pic);
  1501. } else {
  1502. scene.setThumb(ConstantUrl.DEFAULT_SCENE_PIC);
  1503. }
  1504. scene.setThumb(scene.getThumb().concat("?t=") + System.currentTimeMillis());
  1505. if (!ObjectUtils.isEmpty(userName)) {
  1506. scene.setUserId(userId);
  1507. }
  1508. if (sceneShootCount == null) {
  1509. scene.setShootCount(0);
  1510. } else {
  1511. scene.setShootCount(sceneShootCount);
  1512. }
  1513. if (sceneName != null) {
  1514. scene.setSceneName(sceneName);
  1515. }
  1516. if (sceneDec != null) {
  1517. scene.setSceneDec("<p>" + new String(sceneDec.getBytes("UTF-8")) + "</p>");
  1518. }
  1519. if (sceneType != null) {
  1520. scene.setSceneType(sceneType);
  1521. }
  1522. if (gps != null && !gps.trim().equals("")) {
  1523. scene.setGps(gps);
  1524. }
  1525. scene.setAlgorithm(algorithm);
  1526. scene.setFilesName(imgsName);
  1527. if (!org.springframework.util.StringUtils.isEmpty(firmwareVersion)) {
  1528. scene.setFirmwareVersion(firmwareVersion);
  1529. }
  1530. scene.setBuildType(buildType);
  1531. log.info("场景记录添加到数据库:" + projectNum);
  1532. //type=0为新生成场景,其余为重新计算场景
  1533. if (type == 0) {
  1534. scene.setIsObj(ObjectUtils.isEmpty(isObj) || !isObj ? 0 : 1);
  1535. sceneProService.save(scene);
  1536. sceneEdit = new SceneProEdit();
  1537. sceneEdit.setNeedKey(0);
  1538. if (sceneKey == null) {
  1539. sceneKey = "";
  1540. }
  1541. sceneEdit.setSceneKey(sceneKey);
  1542. if (!sceneKey.equals("")) {
  1543. sceneEdit.setNeedKey(1);
  1544. } else {
  1545. sceneEdit.setNeedKey(0);
  1546. }
  1547. sceneEdit.setProId(scene.getId());
  1548. sceneEdit.setMapVisi(1);
  1549. sceneEdit.setTourVisi(1);
  1550. sceneEdit.setVrVisi(1);
  1551. sceneEdit.setRulerVisi(0);
  1552. sceneEdit.setCadImgVisi(1);
  1553. sceneEdit.setPanoVisi(1);
  1554. sceneEdit.setM2dVisi(1);
  1555. sceneEdit.setM3dVisi(1);
  1556. sceneEdit.setMeasureVisi(0);
  1557. sceneEdit.setFloorLogoSize(100);
  1558. sceneEdit.setCreateTime(new Date());
  1559. sceneProEditService.save(sceneEdit);
  1560. //新增场景时,同时新增场景协作信息
  1561. if (cooperationUser != null) {
  1562. SceneCooperation sceneCooperationEntity = new SceneCooperation();
  1563. sceneCooperationEntity.setNum(projectNum);
  1564. sceneCooperationEntity.setUserId(cooperationUser);
  1565. sceneCooperationService.save(sceneCooperationEntity);
  1566. List<SceneResourceCamera> resourceCameraList = sceneResourceCameraService.findListByCameraId(cameraId);
  1567. SceneResourceCooperation sceneResourceCooperationEntity = null;
  1568. if (resourceCameraList != null && resourceCameraList.size() > 0) {
  1569. for (SceneResourceCamera sceneResourceCameraEntity : resourceCameraList) {
  1570. sceneResourceCooperationEntity = new SceneResourceCooperation();
  1571. sceneResourceCooperationEntity.setSceneResourceId(sceneResourceCameraEntity.getSceneResourceId());
  1572. sceneResourceCooperationEntity.setSceneCooperationId(sceneCooperationEntity.getId());
  1573. sceneResourceCooperationService.save(sceneResourceCooperationEntity);
  1574. }
  1575. }
  1576. }
  1577. } else {
  1578. scene.setStatus(0);
  1579. scene.setPayStatus(0);
  1580. scene.setRecStatus("A");
  1581. scene.setCreateTime(new Date());
  1582. if (sceneName != null) {
  1583. scene.setSceneName(sceneName);
  1584. }
  1585. if (sceneType != null) {
  1586. scene.setSceneType(sceneType);
  1587. }
  1588. sceneProService.updateById(scene);
  1589. sceneEdit.setNeedKey(0);
  1590. if (cameraType.longValue() != 14 && !ObjectUtils.isEmpty(sceneKey)) {
  1591. sceneEdit.setNeedKey(1);
  1592. sceneEdit.setSceneKey(sceneKey);
  1593. }
  1594. sceneEdit.setProId(scene.getId());
  1595. sceneEdit.setMapVisi(1);
  1596. sceneEdit.setTourVisi(1);
  1597. sceneEdit.setVrVisi(1);
  1598. sceneEdit.setCadImgVisi(1);
  1599. sceneEdit.setPanoVisi(1);
  1600. sceneEdit.setOverlay(null);
  1601. sceneEdit.setM2dVisi(1);
  1602. sceneEdit.setPlayData(null);
  1603. sceneEdit.setFloorLogo("0");
  1604. sceneEdit.setM3dVisi(1);
  1605. sceneEdit.setJumpScene(false);
  1606. sceneEdit.setMeasureVisi(0);
  1607. sceneEdit.setFloorLogoSize(100);
  1608. sceneEdit.setUpdateTime(new Date());
  1609. sceneEdit.setRecStatus("A");
  1610. sceneEdit.setFloorPublishVer(sceneEdit.getFloorEditVer() + 1);
  1611. sceneEdit.setFloorEditVer(sceneEdit.getFloorEditVer() + 1);
  1612. sceneEdit.setVersion(sceneEdit.getVersion() + 1);
  1613. sceneEdit.setImagesVersion(sceneEdit.getImagesVersion() + 1);
  1614. sceneProEditService.updateById(sceneEdit);
  1615. }
  1616. JSONObject scenejson = JSONObject.parseObject(JSONObject.toJSONString(scene));
  1617. scenejson.put("thumbImg", 0);
  1618. scenejson.put("version", sceneEdit.getVersion());
  1619. scenejson.put("floorLogo", 0);
  1620. if (!ObjectUtils.isEmpty(sceneKey)) {
  1621. scenejson.put("sceneKey", sceneKey);
  1622. scenejson.put("public", 1);
  1623. } else {
  1624. scenejson.put("sceneKey", "");
  1625. scenejson.put("public", 0);
  1626. }
  1627. if (cameraType.longValue() < 4 || cameraType.longValue() == 5 || cameraType.longValue() == 6) {
  1628. scenejson.put("visions", 1);
  1629. } else {
  1630. scenejson.put("visions", 2);
  1631. }
  1632. scenejson.put("createTime", new DateTime(new Date()).toString("yyyy-MM-dd HH:mm"));
  1633. scenejson.put("floorPublishVer", sceneEdit.getFloorPublishVer());
  1634. scenejson.put("floorEditVer", sceneEdit.getFloorEditVer());
  1635. scenejson.put("rulerVisi", sceneEdit.getRulerVisi());
  1636. scenejson.put("entry", null);
  1637. if (!org.springframework.util.StringUtils.isEmpty(sceneEdit.getHotsIds())) {
  1638. scenejson.put("hots", 1);
  1639. }
  1640. File file = new File(ConstantFilePath.SCENE_PATH + "data/data" + projectNum);
  1641. if (!file.exists() || !file.isDirectory()) {
  1642. file.mkdirs();
  1643. }
  1644. FileUtils.writeFile(ConstantFilePath.SCENE_PATH + "data/data" + projectNum + File.separator + "scene.json", scenejson.toString());
  1645. return scene;
  1646. }
  1647. private ResultData rebuildV3SceneToMini(ScenePro scenePro){
  1648. log.info("v3场景重算,请求v3服务器,url:{}",v3controlUrl+"api/scene/rebuildScene?num=" + scenePro.getNum());
  1649. ResponseEntity<Result> responseEntity = restTemplate.getForEntity(v3controlUrl+"api/scene/rebuildScene?num=" + scenePro.getNum(), Result.class);
  1650. if (responseEntity.getStatusCode().value() != HttpStatus.OK.value() || responseEntity.getBody().getCode() != ServerCode.SUCCESS.code()) {
  1651. log.error("请求V3服务器重算场景失败, num:{}, result:{}",scenePro.getNum(), JSON.toJSONString(responseEntity));
  1652. throw new BusinessException(ErrorCode.SYSTEM_BUSY);
  1653. }
  1654. log.info("v3场景重算,请求v3服务器,url:{}, result",v3controlUrl+"api/scene/rebuildScene?num=" + scenePro.getNum(), JSON.toJSONString(responseEntity));
  1655. return ResultData.ok();
  1656. }
  1657. @Override
  1658. public ResultData uploadFile(MultipartFile file, String params) throws Exception {
  1659. log.info("upload-params: "+params);
  1660. if (StringUtils.isEmpty(params)){
  1661. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  1662. }
  1663. params = params.replaceAll("%2B", "+");
  1664. Base64 base64 = new Base64();
  1665. String cipher = params;
  1666. // 私钥解密过程
  1667. byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
  1668. base64.decode(cipher));
  1669. String restr = new String(res, "UTF-8");
  1670. log.info("upload-params解密结果:" + restr);
  1671. String[] strArr = restr.split(SPLICE);
  1672. if (strArr.length != 6) {
  1673. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  1674. }
  1675. String mac = strArr[0];
  1676. String fileId = strArr[1];
  1677. String picNum = strArr[2];
  1678. String md5 = strArr[3];
  1679. String chunk = strArr[4];
  1680. log.info("mac:{},fileId:{},picNum:{},md5:{},chunk:{}", mac, fileId, picNum, md5, chunk);
  1681. ResultData result = null;
  1682. if (file.isEmpty()){
  1683. log.error("文件为空。");
  1684. throw new BusinessException(ErrorCode.PARAM_REQUIRED.code(),"文件为空。");
  1685. }
  1686. if (StringUtils.isEmpty(fileId)){
  1687. log.error("文件Id为空。");
  1688. throw new BusinessException(ErrorCode.PARAM_REQUIRED.code(),"文件Id为空。");
  1689. }
  1690. if (picNum == null){
  1691. log.error("照片数目为空。");
  1692. throw new BusinessException(ErrorCode.PARAM_REQUIRED.code(),"照片数目为空。");
  1693. }
  1694. if (StringUtils.isEmpty(mac)){
  1695. log.error("mac为空。");
  1696. throw new BusinessException(ErrorCode.PARAM_REQUIRED.code(),"mac为空。");
  1697. }
  1698. if (StringUtils.isEmpty(md5)){
  1699. log.error("md5为空。");
  1700. throw new BusinessException(ErrorCode.PARAM_REQUIRED.code(),"md5为空。");
  1701. }
  1702. long size = file.getSize();
  1703. log.info("mac:{}, fileId:{}, picNum:{}, md5:{}, chunk:{}", mac, fileId, picNum, md5, chunk);
  1704. chunk = chunk.split(SPLICE)[0];
  1705. // 获取文件名
  1706. String fileName = file.getOriginalFilename();
  1707. log.info("上传的文件名为:" + fileName);
  1708. // 获取文件的后缀名
  1709. String folderName = redisUtil.get(String.format(RedisConstants.FILEID_FOLDER_BUILD, fileId));
  1710. if(StringUtils.isEmpty(folderName)){
  1711. SceneFileBuild fileBuild = findByFileId(fileId);
  1712. if(ObjectUtils.isEmpty(fileBuild)){
  1713. log.error("数据不正常,fileBuild没找到");
  1714. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  1715. }
  1716. folderName = fileBuild.getUnicode();
  1717. redisUtil.set(String.format(RedisConstants.FILEID_FOLDER_BUILD, fileId), folderName,2 * 24 * 60 * 60);
  1718. }
  1719. // 1. 判断该文件是否已经上传过
  1720. // 2. 如果已经上传过,判断MD5值和文件大小是否相等。如果相等,更新数据记录。如果不相等,删除该文件,重新上传。
  1721. // 3. 如果未上传过,需要上传。
  1722. String filePath = mac.concat(File.separator).concat(fileId).concat(File.separator).concat(folderName);
  1723. String yunFilePath = LocalConstants.BASE_PATH.concat(fYunFileConfig.getBucket()).concat(File.separator).concat(ConstantFilePath.OSS_PREFIX)
  1724. .concat(filePath).concat(File.separator).concat(fileName);
  1725. log.info("yunFilePath:{}", yunFilePath);
  1726. boolean needUpload = false;
  1727. File yunFile = new File(yunFilePath);
  1728. if (yunFile.exists()){
  1729. String fileMD5 = FileMd5Util.getFileMD5(yunFile);
  1730. if (md5.equals(fileMD5) && yunFile.length() == size){
  1731. log.info("文件已存在,MD5和文件大小一致。");
  1732. SceneFileUpload uploadEntity = sceneFileUploadService.findByFileIdAndChunk(fileId, Integer.valueOf(chunk));
  1733. if (uploadEntity != null){
  1734. uploadEntity.setSize((int) size);
  1735. uploadEntity.setMd5(md5);
  1736. uploadEntity.setFilePath(yunFilePath);
  1737. uploadEntity.setFileSourceName(fileName);
  1738. uploadEntity.setUploadStatus(1);
  1739. sceneFileUploadService.updateById(uploadEntity);
  1740. }else{
  1741. SceneFileUpload sceneFileUploadEntity = new SceneFileUpload();
  1742. sceneFileUploadEntity.setSize((int) size);
  1743. sceneFileUploadEntity.setMd5(md5);
  1744. sceneFileUploadEntity.setFilePath(yunFilePath.toString());
  1745. sceneFileUploadEntity.setFileSourceName(fileName);
  1746. sceneFileUploadEntity.setUploadStatus(1);
  1747. sceneFileUploadEntity.setFileId(fileId);
  1748. sceneFileUploadEntity.setChunk(Integer.valueOf(chunk));
  1749. sceneFileUploadService.save(sceneFileUploadEntity);
  1750. }
  1751. result = ResultData.ok();
  1752. }else if (!md5.equals(fileMD5)) {
  1753. log.error("文件已上传,上传MD5:"+md5+",服务器MD5:"+fileMD5+"。不一致。上传失败");
  1754. FileUtils.delFile(yunFilePath.toString());
  1755. needUpload = true;
  1756. }else if (yunFile.length() != size){
  1757. log.error("文件已上传,文件大小不一致。上传失败");
  1758. FileUtils.delFile(yunFilePath);
  1759. needUpload = true;
  1760. }
  1761. }else {
  1762. log.error("文件不存在,需要重新上传");
  1763. needUpload = true;
  1764. }
  1765. // 4. 上传成功后,校验MD5和文件大小是否相等
  1766. // 5. 如果相等,更新数据记录。如果不相等,返回上传失败结果。
  1767. try {
  1768. if (needUpload){
  1769. fYunFileService.uploadFile(file.getInputStream(),ConstantFilePath.OSS_PREFIX.concat(filePath).concat(File.separator).concat(fileName));
  1770. File uploadFile = new File(yunFilePath);
  1771. String fileMD5 = FileMd5Util.getFileMD5(uploadFile);
  1772. SceneFileUpload sceneFileUploadEntity = new SceneFileUpload();
  1773. sceneFileUploadEntity.setSize((int) size);
  1774. sceneFileUploadEntity.setMd5(md5);
  1775. sceneFileUploadEntity.setFilePath(yunFilePath);
  1776. sceneFileUploadEntity.setFileSourceName(fileName);
  1777. sceneFileUploadEntity.setFileId(fileId);
  1778. sceneFileUploadEntity.setChunk(Integer.valueOf(chunk));
  1779. if (md5.equals(fileMD5) && uploadFile.length() == size){
  1780. log.info("文件已上传,MD5和文件大小一致。上传成功");
  1781. sceneFileUploadEntity.setUploadStatus(1);
  1782. sceneFileUploadService.save(sceneFileUploadEntity);
  1783. result = ResultData.ok();
  1784. }else if (!md5.equals(fileMD5)) {
  1785. log.error("文件已上传,上传MD5:"+md5+",服务器MD5:"+fileMD5+"。不一致。上传失败");
  1786. sceneFileUploadEntity.setUploadStatus(-1);
  1787. sceneFileUploadService.save(sceneFileUploadEntity);
  1788. result = ResultData.error(ErrorCode.SYSTEM_ERROR,"上传失败, 请重新上传。");
  1789. }else if (uploadFile.length() != size){
  1790. log.error("文件已上传,文件大小不一致。上传失败");
  1791. sceneFileUploadEntity.setUploadStatus(-1);
  1792. sceneFileUploadService.save(sceneFileUploadEntity);
  1793. result = ResultData.error(ErrorCode.SYSTEM_ERROR,"上传失败, 请重新上传。");
  1794. }
  1795. }
  1796. }catch (IllegalStateException | IOException e) {
  1797. log.error("上传失败, 请重新上传,md5:{},chunk:{}", md5, chunk);
  1798. log.error("上传失败", e);
  1799. result = ResultData.error(ErrorCode.SYSTEM_ERROR,"上传失败, 请重新上传。");
  1800. }
  1801. return result;
  1802. }
  1803. @Override
  1804. public ResultData sendCallAlgorithm(SendCallAlgorithmParam param) throws Exception {
  1805. log.info("sendCallAlgorithm 参数为:{}", JSONObject.toJSONString(param));
  1806. String filePath = param.getFilepath();
  1807. SendCallAlgorithmDetail detail = param.getDetails();
  1808. String uploadType = detail.getUploadType();
  1809. if(StrUtil.isNotEmpty(uploadType) && "log".equals(uploadType)){
  1810. return ResultData.ok();
  1811. }
  1812. Integer fileChunkSum = detail.getFileChunkSum();
  1813. String uuid = detail.getUuid();
  1814. if(Objects.isNull(fileChunkSum) || StrUtil.isBlank(uuid)){
  1815. throw new BusinessException(ErrorCode.PARAM_REQUIRED.code(), "details参数中fileChunkSum和uuid不能为空");
  1816. }
  1817. String snCode = uuid.split("_")[0];
  1818. String parentPath = sendCallAlgorithmPath.concat(uuid);
  1819. // if(FileUtil.exist(parentPath)){
  1820. // FileUtil.del(parentPath);
  1821. // }
  1822. Camera camera = cameraService.getByChildName(snCode);
  1823. if(Objects.isNull(camera)){
  1824. throw new BusinessException(ErrorCode.CAMERA_BIND_NO_EXIST.code(), "相机未入库");
  1825. }
  1826. String localFilePath = parentPath.concat(File.separator).concat(uuid).concat(".zip");
  1827. try {
  1828. String extName = FileUtil.extName(filePath);
  1829. String subFilePath = parentPath.concat(File.separator).concat(uuid).concat(".").concat(extName);
  1830. FileUtil.mkParentDirs(localFilePath);
  1831. HttpUtil.downloadFile(filePath, subFilePath);
  1832. }catch (Exception e){
  1833. throw new BusinessException(ErrorCode.FAILURE_CODE_5063.code(), "原始资源压缩包下载失败");
  1834. }
  1835. //检测压缩包分卷是否与detail中的总数一样
  1836. List<String> fileNames = FileUtil.listFileNames(parentPath);
  1837. if(fileNames.size() != fileChunkSum){
  1838. return ResultData.ok("压缩包分卷不完整,请继续上传剩余的分卷");
  1839. }
  1840. if(!FileUtil.exist(localFilePath)){
  1841. throw new BusinessException(ErrorCode.FAILURE_CODE_5063.code(), "zip压缩包不存在");
  1842. }
  1843. ScenePre scenePre = new ScenePre();
  1844. scenePre.setZipPath(parentPath);
  1845. scenePre.setCreateTime(new Date());
  1846. scenePre.setUpdateTime(new Date());
  1847. scenePre.setStatus(0);
  1848. scenePreService.save(scenePre);
  1849. // 异步解压资源文件上传
  1850. ExecutorService executor = ThreadUtil.newSingleExecutor();
  1851. try {
  1852. CompletableFuture.runAsync(() -> {
  1853. try {
  1854. log.info("开始异步解压文件");
  1855. ZipFile zipFile = new ZipFile(new File(localFilePath));
  1856. if (zipFile.isEncrypted()) {
  1857. zipFile.setPassword(zipPassword);
  1858. zipFile.extractAll(parentPath);
  1859. } else {
  1860. ZipUtil.unzip(localFilePath, parentPath);
  1861. }
  1862. List<String> filePathList = FileUtils.list(new File(parentPath));
  1863. String configJsonPath = null;
  1864. for (String item : filePathList) {
  1865. if(!item.contains("config.json")){
  1866. continue;
  1867. }
  1868. configJsonPath = item;
  1869. }
  1870. String dataPath = FileUtil.getParent(configJsonPath, 1);
  1871. // 读取本地文件并校验文件
  1872. // 读取config.json
  1873. log.info("config.json路径:{}", configJsonPath);
  1874. if(!FileUtil.exist(configJsonPath)){
  1875. throw new RuntimeException("config.json 文件有误!");
  1876. }
  1877. JSONObject configJson = JSONObject.parseObject(FileUtils.readFile(configJsonPath));
  1878. String folderName = configJson.getString("id");
  1879. String customUserId = configJson.getString("customUserId");
  1880. String customUserName = configJson.getString("customUserName");
  1881. String customUserPwd = configJson.getString("customUserPwd");
  1882. if(StrUtil.isBlank(folderName) || StrUtil.isBlank(snCode)){
  1883. throw new RuntimeException("config.json 文件有误!");
  1884. }
  1885. // 检测是否有生成
  1886. String fileId = getFileIdByFolderName(folderName);
  1887. String subFolder = snCode.concat(File.separator).concat(fileId).concat(File.separator).concat(folderName);
  1888. // 解压获取dataSource 并上传资源到OSS
  1889. String dataSource = ConstantFilePath.BUILD_MODEL_PATH.concat(subFolder);
  1890. log.info("dataSource 为:{}", dataSource);
  1891. scenePre.setFileId(fileId);
  1892. scenePre.setStatus(1);
  1893. scenePre.setUpdateTime(new Date());
  1894. scenePreService.updateById(scenePre);
  1895. log.info("异步开始上传文件");
  1896. // 上传oaas
  1897. fYunFileService.uploadFileByCommand(dataPath, ConstantFilePath.OSS_PREFIX.concat(subFolder));
  1898. //删除本地压缩包,防止补拍上传文件不一致
  1899. FileUtil.del(parentPath);
  1900. scenePre.setOssPath(ConstantFilePath.OSS_PREFIX.concat(subFolder));
  1901. scenePre.setStatus(2);
  1902. scenePre.setUpdateTime(new Date());
  1903. scenePreService.updateById(scenePre);
  1904. log.info("开始判断人员是否存在,走注册用户逻辑");
  1905. log.info("userPasswordKey:{}", userPasswordKey);
  1906. log.info("userPasswordIv:{}", userPasswordIv);
  1907. //调注册用户接口
  1908. Map<String, Object> params = new HashMap<>();
  1909. params.put("ryId", customUserId);
  1910. params.put("ryNo", customUserName);
  1911. params.put("nickName", customUserName);
  1912. params.put("password", AesUtil.encryptCBC(customUserPwd, userPasswordKey, userPasswordIv, AesUtil.ALMODE_CBC_NOPADDING));
  1913. String url = fdServiceUrl.concat(URL_ADD_UCENTER_USER);
  1914. myClient.post(url, params);
  1915. JyUser jyUser = jyUserService.getByRyId(customUserId);
  1916. User user = userService.getById(jyUser.getUserId());
  1917. if(Objects.isNull(jyUser)){
  1918. throw new RuntimeException("注册用户失败");
  1919. }
  1920. log.info("文件上传成功,开始通知计算");
  1921. // 通知计算
  1922. ResultData resultData = this.copyDataAndBuild(null, dataSource, "V4", user, customUserId);
  1923. log.info("通知计算成功");
  1924. scenePre.setStatus(3);
  1925. scenePre.setUpdateTime(new Date());
  1926. scenePreService.updateById(scenePre);
  1927. } catch (Exception e) {
  1928. log.error("上传失败", e);
  1929. scenePre.setStatus(CommonSuccessStatus.FAIL.code());
  1930. scenePreService.updateById(scenePre);
  1931. }
  1932. }, executor);
  1933. }finally {
  1934. executor.shutdown();
  1935. }
  1936. return ResultData.ok();
  1937. }
  1938. public static void main(String[] args) throws Exception {
  1939. // final String s = AesUtil.encryptCBC("Aa123456", "0000000856753656", "pwel781esd6wglxm", AesUtil.ALMODE_CBC_NOPADDING);
  1940. // System.out.println(s);
  1941. // System.out.println(UUID.fastUUID());
  1942. }
  1943. @Override
  1944. public ResultData uploadFile(SendCallAlgorithmParam param) throws Exception {
  1945. log.info("sendCallAlgorithm 参数为:{}", JSONObject.toJSONString(param));
  1946. String filePath = param.getFilepath();
  1947. if(StrUtil.isBlank(filePath)){
  1948. throw new BusinessException(ErrorCode.PARAM_REQUIRED.code(), "filePath不能为空");
  1949. }
  1950. SendCallAlgorithmDetail detail = param.getDetails();
  1951. String uploadType = detail.getUploadType();
  1952. if(StrUtil.isNotEmpty(uploadType) && "log".equals(uploadType)){
  1953. return ResultData.ok();
  1954. }
  1955. String uuid = detail.getUuid();
  1956. if(StrUtil.isBlank(uuid)){
  1957. throw new BusinessException(ErrorCode.PARAM_REQUIRED.code(), "uuid不能为空");
  1958. }
  1959. String fileName = detail.getFileName();
  1960. if(StrUtil.isBlank(fileName)){
  1961. throw new BusinessException(ErrorCode.PARAM_REQUIRED.code(), "fileName不能为空");
  1962. }
  1963. boolean lock = redisLockUtil.lock("lock:single:upload:uuid:" + uuid, uuid, 1);
  1964. if(!lock){//如果拿不到锁,证明
  1965. Thread.sleep(2000L);
  1966. }
  1967. String batchId = redisUtil.get("single:upload:uuid:" + uuid);
  1968. if(StrUtil.isEmpty(batchId)){
  1969. OrigFileUploadBatch condition = new OrigFileUploadBatch();
  1970. condition.setUuid(uuid);
  1971. condition.setStatus(0);
  1972. OrigFileUploadBatch origFileUploadBatch = origFileUploadBatchService.getByCondition(condition);
  1973. if(Objects.isNull(origFileUploadBatch)){
  1974. batchId = redisUtil.get("single:upload:uuid:" + uuid);
  1975. if(StrUtil.isEmpty(batchId)){
  1976. batchId = UUID.fastUUID().toString().replace("-", "");
  1977. redisUtil.set("single:upload:uuid:" + uuid, batchId);
  1978. origFileUploadBatch = new OrigFileUploadBatch();
  1979. origFileUploadBatch.setUuid(uuid);
  1980. origFileUploadBatch.setBatchId(batchId);
  1981. origFileUploadBatchService.save(origFileUploadBatch);
  1982. }
  1983. }
  1984. }
  1985. //插入上传明细表
  1986. OrigFileUpload origFileUpload = new OrigFileUpload();
  1987. origFileUpload.setFileUrl(filePath);
  1988. origFileUpload.setFileName(fileName);
  1989. origFileUpload.setBatchId(batchId);
  1990. origFileUploadService.save(origFileUpload);
  1991. if(lock){
  1992. redisLockUtil.unlockLua("lock:single:upload:uuid:" + uuid, uuid);
  1993. }
  1994. if(fileName.equals("config.json")){
  1995. HttpUtilExt.downloadFileAndCheck(filePath, sendCallAlgorithmPath.concat(uuid).concat("/config.json"), 300000);
  1996. }
  1997. if(fileName.equals("data.fdage")){
  1998. HttpUtilExt.downloadFileAndCheck(filePath, sendCallAlgorithmPath.concat(uuid).concat("/data.fdage"), 300000);
  1999. }
  2000. if(fileName.equals("scene_up_data.txt")){
  2001. HttpUtilExt.downloadFileAndCheck(filePath, sendCallAlgorithmPath.concat(uuid).concat("/scene_up_data.txt"), 300000);
  2002. }
  2003. return ResultData.ok();
  2004. }
  2005. @Override
  2006. public ResultData noticeBuild(String uuid, Long bdId, String dataSource) throws Exception {
  2007. log.info("通知计算,uuid:{} " + uuid);
  2008. SceneOrigBd sceneOrigBd = sceneOrigBdService.getById(bdId);
  2009. try {
  2010. String[] uuidArr = uuid.split("_");
  2011. String snCode = uuidArr[0];
  2012. String homePath = SceneUtil.getHomePath(dataSource);
  2013. JSONObject fdageData = JSONObject.parseObject(fYunFileService.getFileContent(homePath + "data.fdage"));
  2014. int camType = fdageData.getJSONObject("cam").getIntValue("type");
  2015. fdageData.put("taskId", sceneOrigBd.getTaskId());
  2016. fdageData.put("kNo", sceneOrigBd.getKNo());
  2017. //相机入库
  2018. String cameraInStoreUrl = fdServiceUrl + "/service/manage/inner/cameraInStore";
  2019. Map<String, Object> cameraInStoreParams = new HashMap<>();
  2020. cameraInStoreParams.put("cameraType", camType);
  2021. cameraInStoreParams.put("snCode", snCode);
  2022. ResultData post = myClient.post(cameraInStoreUrl, cameraInStoreParams);
  2023. log.info("---------cameraInStore result:{}-----------", post);
  2024. Long cameraType = 13L;//默认为看见相机
  2025. Camera camera = cameraService.getBySnCode(snCode);
  2026. if(Objects.isNull(camera)){
  2027. throw new BusinessException(ErrorCode.CAMERA_BIND_NO_EXIST.code(), "相机未入库");
  2028. }
  2029. CameraDetail cameraDetail = cameraDetailService.getByCameraId(camera.getId());
  2030. if(Objects.isNull(cameraDetail)){
  2031. throw new BusinessException(ErrorCode.CAMERA_BIND_NO_EXIST.code(), "相机未入库");
  2032. }
  2033. camType = cameraDetail.getType();
  2034. if(camType == 10 || camType == 11){
  2035. cameraType = 14L;//深时或者深光
  2036. }else if(camType == 9){
  2037. cameraType = 13L;//看见
  2038. }else if(camType == 5){
  2039. cameraType = 6L;//圆周率
  2040. }else {
  2041. cameraType = 10L;//看看
  2042. }
  2043. //校验文件是否完整
  2044. // jmgaService.checkFileWhole(uuid, dataSource, fdageData);
  2045. //调注册用户接口
  2046. Map<String, Object> params = new HashMap<>();
  2047. params.put("ryId", sceneOrigBd.getRyId());
  2048. params.put("ryNo", sceneOrigBd.getRyNo());
  2049. params.put("password", AesUtil.encryptCBC(sceneOrigBd.getPassword(), userPasswordKey, userPasswordIv, AesUtil.ALMODE_CBC_NOPADDING));
  2050. String url = fdServiceUrl.concat(URL_ADD_UCENTER_USER);
  2051. ResultData post1 = myClient.post(url, params);
  2052. log.info("---------registerUser result:{}-----------", post1);
  2053. JyUser jyUser = jyUserService.getByRyId(sceneOrigBd.getRyId());
  2054. User user = userService.getById(jyUser.getUserId());
  2055. if(Objects.isNull(jyUser)){
  2056. throw new RuntimeException("注册用户失败");
  2057. }
  2058. String sceneNum = null;
  2059. int rebuild = 0;
  2060. ScenePlus scenePlus = scenePlusService.getByFileId(dataSource);
  2061. if (!ObjectUtils.isEmpty(scenePlus)) {
  2062. log.info("该场景资源已存在,执行补拍逻辑!");
  2063. rebuild = 1;
  2064. sceneNum = scenePlus.getNum();
  2065. }else{
  2066. sceneNum = scene3dNumService.generateSceneNum(cameraDetail.getType());
  2067. }
  2068. buildScenePost(dataSource, fdageData, "V3", cameraType, sceneNum, camera, cameraDetail, rebuild, "", user);
  2069. scenePlus = scenePlusService.getScenePlusByNum(sceneNum);
  2070. if(cameraType == 14){
  2071. fdkkLaserService.saveScene(scenePlus,fdageData,camera,user.getUserName(),rebuild == 1 ? true : false, scenePlus.getPayStatus());
  2072. }
  2073. sceneOrigBd.setStatus(CommonSuccessStatus.SUCCESS.code());
  2074. }catch (Exception e){
  2075. sceneOrigBd.setStatus(CommonSuccessStatus.FAIL.code());
  2076. sceneOrigBd.setReason(ExceptionUtil.stacktraceToString(e,5000));
  2077. }
  2078. sceneOrigBd.setUpdateTime(null);
  2079. sceneOrigBdService.updateById(sceneOrigBd);
  2080. return ResultData.ok();
  2081. }
  2082. public String getFileId(String unicode) throws Exception {
  2083. return this.getOne(new LambdaQueryWrapper<SceneFileBuild>().eq(SceneFileBuild::getUnicode, unicode)).getFileId();
  2084. }
  2085. }