SceneFileBuildServiceImpl.java 90 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974
  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.DatePattern;
  5. import cn.hutool.core.date.DateUtil;
  6. import cn.hutool.core.exceptions.ExceptionUtil;
  7. import cn.hutool.core.io.FileUtil;
  8. import cn.hutool.core.lang.UUID;
  9. import cn.hutool.core.util.StrUtil;
  10. import cn.hutool.crypto.digest.MD5;
  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.ApiConstant;
  26. import com.fdkankan.contro.constant.ModelingControlRespCode;
  27. import com.fdkankan.contro.constant.RedisConstants;
  28. import com.fdkankan.contro.constant.RedisKeyExt;
  29. import com.fdkankan.contro.entity.*;
  30. import com.fdkankan.contro.enums.CameraTypeEnum;
  31. import com.fdkankan.contro.httpclient.MyClient;
  32. import com.fdkankan.contro.mapper.ISceneFileBuildMapper;
  33. import com.fdkankan.contro.service.*;
  34. import com.fdkankan.contro.util.HttpUtilExt;
  35. import com.fdkankan.contro.vo.ResponseSceneFile;
  36. import com.fdkankan.contro.vo.ScenePlusVO;
  37. import com.fdkankan.contro.vo.SendCallAlgorithmParam;
  38. import com.fdkankan.fyun.config.FYunFileConfig;
  39. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  40. import com.fdkankan.fyun.local.constant.LocalConstants;
  41. import com.fdkankan.image.MatrixToImageWriterUtil;
  42. import com.fdkankan.model.constants.ConstantFilePath;
  43. import com.fdkankan.model.constants.UploadFilePath;
  44. import com.fdkankan.model.utils.SceneUtil;
  45. import com.fdkankan.rabbitmq.bean.BuildSceneCallMessage;
  46. import com.fdkankan.rabbitmq.util.RabbitMqProducer;
  47. import com.fdkankan.redis.constant.RedisKey;
  48. import com.fdkankan.redis.util.RedisLockUtil;
  49. import com.fdkankan.redis.util.RedisUtil;
  50. import com.fdkankan.web.response.ResultData;
  51. import com.fdkankan.web.util.RSAEncrypt;
  52. import lombok.extern.slf4j.Slf4j;
  53. import net.lingala.zip4j.ZipFile;
  54. import org.apache.commons.codec.binary.Base64;
  55. import org.apache.commons.lang3.StringUtils;
  56. import org.joda.time.DateTime;
  57. import org.springframework.beans.factory.annotation.Autowired;
  58. import org.springframework.beans.factory.annotation.Value;
  59. import org.springframework.cloud.context.config.annotation.RefreshScope;
  60. import org.springframework.http.*;
  61. import org.springframework.stereotype.Service;
  62. import org.springframework.util.LinkedMultiValueMap;
  63. import org.springframework.util.MultiValueMap;
  64. import org.springframework.util.ObjectUtils;
  65. import org.springframework.web.client.RestTemplate;
  66. import org.springframework.web.multipart.MultipartFile;
  67. import javax.annotation.Resource;
  68. import java.io.File;
  69. import java.io.IOException;
  70. import java.nio.charset.StandardCharsets;
  71. import java.util.*;
  72. /**
  73. * <p>
  74. * 场景文件建模表 服务实现类
  75. * </p>
  76. *
  77. * @author dengsixing
  78. * @since 2021-12-23
  79. */
  80. @RefreshScope
  81. @Slf4j
  82. @Service
  83. public class SceneFileBuildServiceImpl extends ServiceImpl<ISceneFileBuildMapper, SceneFileBuild> implements ISceneFileBuildService {
  84. private static final String SPLICE = "#";
  85. private static final String sendCallAlgorithmPath = "/mnt/sendCallAlgorithm/";
  86. private static final String zipPassword = "a3ad34136de359536af553f9e7f3cefd";
  87. private static final String URL_ADD_UCENTER_USER = "/service/manage/inner/addUcenterUser";
  88. @Value("${scene.pro.new.url}")
  89. private String sceneProNewUrl;
  90. @Value("${queue.modeling.modeling-pre}")
  91. private String queueModelingPre;
  92. @Value("${queue.modeling.v3.modeling-pre}")
  93. private String queueV3ModelingPre;
  94. @Value("${queue.modeling.intermit.modeling-pre}")
  95. private String queueIntermitModelingPre;
  96. @Value("${v3.controlUrl:#{null}}")
  97. private String v3controlUrl;
  98. @Value("${model.modelKind:3dtiles}")
  99. private String modelKind;
  100. @Value("#{'${model.3dtiles.sceneSource:}'.split(',')}")
  101. private List<Integer> sdTilesSceneSourceList;
  102. @Value("#{'${camType.laser:}'.split(',')}")
  103. private List<Integer> laserCamTypeList;
  104. @Value("${build.notSupport.beforeTime:202203}")
  105. private String jgNotSupportBuildTime;
  106. @Value("${4dkk.fdService.basePath}")
  107. private String fdServiceUrl;
  108. @Value("${user.password.key:0000000856753656}")
  109. private String userPasswordKey;
  110. @Value("${user.password.iv:pwel781esd6wglxm}")
  111. private String userPasswordIv;
  112. @Autowired
  113. private RedisUtil redisUtil;
  114. @Autowired
  115. private IScenePlusExtService scenePlusExtService;
  116. @Autowired
  117. private IScene3dNumService scene3dNumService;
  118. @Autowired
  119. private IScenePlusService scenePlusService;
  120. @Autowired
  121. private RabbitMqProducer rabbitMqProducer;
  122. @Autowired
  123. private ISceneEditInfoService sceneEditInfoService;
  124. @Autowired
  125. private ISceneEditControlsService sceneEditControlsService;
  126. @Autowired
  127. private ISceneEditInfoExtService sceneEditInfoExtService;
  128. @Autowired
  129. private ISceneCooperationService sceneCooperationService;
  130. @Autowired
  131. private ISceneResourceCameraService sceneResourceCameraService;
  132. @Autowired
  133. private ISceneResourceCooperationService sceneResourceCooperationService;
  134. @Autowired
  135. private ICameraService cameraService;
  136. @Autowired
  137. private ICameraDetailService cameraDetailService;
  138. @Autowired
  139. private IUserService userService;
  140. @Autowired
  141. private ISceneFileUploadService sceneFileUploadService;
  142. @Resource
  143. private ICompanyService companyService;
  144. @Resource
  145. private FYunFileServiceInterface fYunFileService;
  146. @Autowired
  147. private FYunFileConfig fYunFileConfig;
  148. @Autowired
  149. private RedisLockUtil redisLockUtil;
  150. private RestTemplate restTemplate = new RestTemplate();
  151. @Autowired
  152. private ISceneCopyLogService sceneCopyLogService;
  153. @Autowired
  154. private ICommonService commonService;
  155. @Autowired
  156. private IExceedSpaceSceneService exceedSpaceSceneService;
  157. @Autowired
  158. private ISceneColdStorageService sceneColdStorageService;
  159. @Autowired
  160. private IntermitSceneService intermitSceneService;
  161. @Autowired
  162. private ISceneRebuildLogService sceneRebuildLogService;
  163. @Autowired
  164. private ISceneUploadCountService sceneUploadCountService;
  165. @Autowired
  166. private ISceneProService sceneProService;
  167. @Autowired
  168. private ISceneProEditService sceneProEditService;
  169. @Autowired
  170. private IFdkkLaserService fdkkLaserService;
  171. @Resource
  172. private MyClient myClient;
  173. @Autowired
  174. private IJyUserService jyUserService;
  175. @Autowired
  176. private IOrigFileUploadService origFileUploadService;
  177. @Autowired
  178. private IOrigFileUploadBatchService origFileUploadBatchService;
  179. @Autowired
  180. private IJmgaService jmgaService;
  181. @Autowired
  182. private ISceneOrigBdService sceneOrigBdService;
  183. @Autowired
  184. private UploadShootingService uploadShootingService;
  185. @Override
  186. public SceneFileBuild findByFileId(String fileId) {
  187. List<SceneFileBuild> list = this.list(new LambdaQueryWrapper<SceneFileBuild>().eq(SceneFileBuild::getFileId, fileId)
  188. .orderByDesc(SceneFileBuild::getId));
  189. if(CollUtil.isEmpty(list)){
  190. return null;
  191. }
  192. return list.get(0);
  193. }
  194. @Override
  195. public ResponseSceneFile preUpload(String params) throws Exception {
  196. log.info("preUpload-params: "+params);
  197. if (StrUtil.isEmpty(params)){
  198. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  199. }
  200. params = params.replaceAll("%2B", "+");
  201. Base64 base64 = new Base64();
  202. String cipher = params;
  203. // 私钥解密过程
  204. byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
  205. base64.decode(cipher));
  206. String restr = new String(res, "UTF-8");
  207. log.debug("preUpload-params解密结果:" + restr);
  208. String[] strArr = restr.split(SPLICE);
  209. if (strArr.length != 5) {
  210. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  211. }
  212. String mac = strArr[0];
  213. String totalPicNum = strArr[1];
  214. String chunks = strArr[2];
  215. String folderName = strArr[3];
  216. if (StrUtil.isEmpty(mac)){
  217. throw new BusinessException(ErrorCode.FAILURE_CODE_5044);
  218. }
  219. if (totalPicNum == null){
  220. throw new BusinessException(ErrorCode.FAILURE_CODE_5045);
  221. }
  222. if (chunks == null){
  223. throw new BusinessException(ErrorCode.FAILURE_CODE_5046);
  224. }
  225. if (folderName == null){
  226. throw new BusinessException(ErrorCode.FAILURE_CODE_5047);
  227. }
  228. log.info("mac:{} 准备上传文件,folderName:{}", mac, folderName);
  229. ResponseSceneFile responseSceneFile = new ResponseSceneFile();
  230. // 检测是否有生成
  231. String fileId = redisUtil.get(String.format(RedisConstants.FOLDER_FILEID_BUILD, folderName));
  232. if (StrUtil.isEmpty(fileId)) {
  233. SceneFileBuild sceneFileBuild = this.findByUnicode(folderName);
  234. if (sceneFileBuild != null) {
  235. fileId = sceneFileBuild.getFileId();
  236. }
  237. }
  238. if(StrUtil.isNotEmpty(fileId)){
  239. //校验目录是否被上锁,如果上锁,抛出错误(避免删除原始资源定时任务执行过程中,有场景补拍重新上传)
  240. String homePath = redisUtil.get(String.format(RedisKey.SCENE_OSS_HOME_DIR_DELETE, folderName));
  241. if(StrUtil.isNotEmpty(homePath)){
  242. throw new BusinessException(ErrorCode.FAILURE_CODE_5073);
  243. }
  244. //如果原始资源目录不是正在被定时任务删除中,就加上上传锁,并正常返回
  245. homePath = ConstantFilePath.OSS_PREFIX.concat(mac).concat("/").concat(fileId).concat("/").concat(folderName);
  246. redisUtil.set(String.format(RedisKey.SCENE_OSS_HOME_DIR_UPLOAD, folderName), homePath, RedisKey.CAMERA_EXPIRE_7_TIME);
  247. responseSceneFile.setFileId(fileId);
  248. redisUtil.set(String.format(RedisConstants.FOLDER_FILEID_BUILD, folderName), fileId, 2 * 24 * 60 * 60);
  249. return responseSceneFile;
  250. }
  251. // 加锁
  252. boolean lock = redisLockUtil.lock(String.format(RedisConstants.FOLDER_LOCK_BUILD, folderName), 120);
  253. if (!lock) {
  254. throw new BusinessException(ErrorCode.FAILURE_CODE_5052);
  255. }
  256. // 查找场景表
  257. LambdaQueryWrapper<ScenePro> proWrapper = new LambdaQueryWrapper<>();
  258. proWrapper.like(ScenePro::getDataSource, "/" + folderName);
  259. ScenePro pro = sceneProService.getOne(proWrapper);
  260. String dataSource = null;
  261. if (!ObjectUtils.isEmpty(pro)) {
  262. dataSource = pro.getDataSource();
  263. } else {
  264. dataSource = scenePlusService.getDataSourceLikeUnicode("/" + folderName);
  265. }
  266. if (StrUtil.isNotEmpty(dataSource)) {
  267. log.info("从数据库中查到与 fileId:{} 匹配的路径为:{}", fileId, dataSource);
  268. int n = dataSource.split("/").length;
  269. if (n > 1) {
  270. fileId = dataSource.split("/")[n - 2];
  271. }
  272. }
  273. if (StrUtil.isEmpty(fileId)) {
  274. fileId = new SnowflakeIdGenerator(0, 0).nextId() + "";
  275. log.info("新生成build数据,{}", fileId);
  276. }
  277. SceneFileBuild sceneFileBuild = new SceneFileBuild();
  278. sceneFileBuild.setChildName(mac);
  279. sceneFileBuild.setFileId(fileId);
  280. sceneFileBuild.setRecStatus("A");
  281. sceneFileBuild.setUnicode(folderName);
  282. sceneFileBuild.setTotalPicNum(Integer.valueOf(totalPicNum));
  283. sceneFileBuild.setChunks(Integer.valueOf(chunks));
  284. sceneFileBuild.setCreateTime(new Date());
  285. this.save(sceneFileBuild);
  286. redisUtil.set(String.format(RedisConstants.FOLDER_FILEID_BUILD, folderName), fileId, 2 * 24 * 60 * 60);
  287. redisUtil.set(String.format(RedisConstants.FILEID_FOLDER_BUILD, fileId), folderName, 2 * 24 * 60 * 60);
  288. responseSceneFile.setFileId(fileId);
  289. return responseSceneFile;
  290. }
  291. public SceneFileBuild findByUnicode(String unicode) {
  292. List<SceneFileBuild> list = this.list(new QueryWrapper<SceneFileBuild>()
  293. .eq("unicode", unicode)
  294. .orderByDesc("id"));
  295. if(CollUtil.isEmpty(list))
  296. return null;
  297. return list.get(0);
  298. }
  299. public ScenePlusVO buildScene(String fileId, String prefix,JSONObject jsonObject,String buildType,long cameraType, User user, boolean forceBuild) throws Exception{
  300. //调用createScene方法生成scene数据和加入算法队列
  301. String sceneNum = "";
  302. String cameraName = jsonObject.getJSONObject("cam").getString("uuid");
  303. String unicode = jsonObject.getString("creator") + "_" + jsonObject.getString("uuidtime");
  304. int camType = jsonObject.getJSONObject("cam").getIntValue("type");
  305. String cameraInStoreUrl = fdServiceUrl + ApiConstant.URL_CAMERA_INSTORE;
  306. Map<String, Object> cameraInStoreParams = new HashMap<>();
  307. cameraInStoreParams.put("cameraType", camType);
  308. cameraInStoreParams.put("snCode", jsonObject.getString("creator"));
  309. ResultData post = myClient.post(cameraInStoreUrl, cameraInStoreParams);
  310. log.info("---------cameraInStore result:{}-----------", post);
  311. if(Objects.isNull(user)){
  312. JSONObject configJson = JSONObject.parseObject(fYunFileService.getFileContent(ConstantFilePath.OSS_PREFIX + prefix + "config.json"));
  313. String folderName = configJson.getString("id");
  314. String customUserId = configJson.getString("customUserId");
  315. String customUserName = configJson.getString("customUserName");
  316. String customUserPwd = configJson.getString("customUserPwd");
  317. if(StrUtil.isBlank(folderName) || StrUtil.isBlank(jsonObject.getString("creator"))){
  318. throw new RuntimeException("config.json 文件有误!");
  319. }
  320. //调注册用户接口
  321. Map<String, Object> params = new HashMap<>();
  322. params.put("ryId", customUserId);
  323. params.put("ryNo", customUserName);
  324. // params.put("nickName", customUserName);//去掉昵称,又燕海的接口进行判断
  325. params.put("password", AesUtil.encryptCBC(customUserPwd, userPasswordKey, userPasswordIv, AesUtil.ALMODE_CBC_NOPADDING));
  326. String url = fdServiceUrl.concat(ApiConstant.URL_ADD_UCENTER_USER);
  327. myClient.post(url, params);
  328. JyUser jyUser = jyUserService.getByRyId(customUserId);
  329. user = userService.getById(jyUser.getUserId());
  330. if(Objects.isNull(jyUser)){
  331. throw new RuntimeException("注册用户失败");
  332. }
  333. }
  334. Camera camera = cameraService.getByChildName(cameraName);
  335. if (camera == null) {
  336. throw new BusinessException(CameraConstant.FAILURE_6003);
  337. }
  338. CameraDetail cameraDetail = cameraDetailService.getByCameraId(camera.getId());
  339. if (cameraDetail == null) {
  340. log.error("该相机详情不存在:" + cameraName);
  341. throw new BusinessException(CameraConstant.FAILURE_6003);
  342. }
  343. //查看场景中的文件目录是否有改文件id,有则重新计算改场景,无则新建场景
  344. ScenePlus scenePlus = scenePlusService.getByFileId("/" + fileId + "/");
  345. int rebuild = CommonStatus.YES.code();
  346. if (ObjectUtils.isEmpty(scenePlus)) {
  347. //清除超容量场景记录
  348. exceedSpaceSceneService.repeal(camera.getId(), fileId, unicode);
  349. sceneNum = scene3dNumService.generateSceneNum(cameraDetail.getType());
  350. rebuild = CommonStatus.NO.code();
  351. } else {
  352. sceneNum = scenePlus.getNum();
  353. sceneCopyLogService.checkCanBuild(sceneNum);
  354. if (scenePlus.getSceneStatus().equals(SceneStatus.wait.code())) {
  355. log.info(scenePlus.getNum() + ":场景处于计算中,不能再计算");
  356. if(!forceBuild){
  357. return null;
  358. }
  359. }
  360. }
  361. if (sceneNum == null) {
  362. log.error("大场景序号为空:" + sceneNum);
  363. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  364. }
  365. //如果是相机计算容量的模式是场景个数模式,则需要拦截计算
  366. if(rebuild == CommonStatus.NO.code()){//新场景需要校验容量是否超出限制
  367. boolean exceedSpace = exceedSpaceSceneService.cehckExceedSpace(sceneNum, cameraDetail, cameraName, fileId, unicode);
  368. if(exceedSpace){
  369. ScenePlusVO scenePlusVO = new ScenePlusVO();
  370. scenePlusVO.setNum(sceneNum);
  371. scenePlusVO.setSceneStatus(SceneStatus.EXCEED_SPACE.code());
  372. return scenePlusVO;
  373. }
  374. }
  375. String dataSource = cameraName.replace("4DKKPRO_", "").replace("-fdage", "").toLowerCase() + File.separator +
  376. fileId + File.separator + unicode;
  377. if (cameraType == 14) {
  378. dataSource = ConstantFilePath.BUILD_MODEL_LASER_PATH +dataSource;
  379. } else {
  380. dataSource = ConstantFilePath.BUILD_MODEL_PATH + dataSource;
  381. }
  382. String imgViewPath = String.format(UploadFilePath.IMG_VIEW_PATH, sceneNum);
  383. String icon = null;
  384. if (!ObjectUtils.isEmpty(jsonObject.getString("icon"))) {
  385. fYunFileService.copyFileInBucket(ConstantFilePath.OSS_PREFIX + prefix + jsonObject.getString("icon"),imgViewPath + jsonObject.getString("icon"));
  386. icon = fYunFileConfig.getHost() + imgViewPath + jsonObject.getString("icon");
  387. log.info("上传icon成功....");
  388. }
  389. return buildScenePost(dataSource, jsonObject, buildType, cameraType, sceneNum, camera, cameraDetail, rebuild,icon, user);
  390. }
  391. private ScenePlusVO buildScenePost(String dataSource, JSONObject jsonObject, String buildType, long cameraType,
  392. String sceneNum, Camera camera, CameraDetail cameraDetail, int rebuild,String icon, User user) throws Exception {
  393. String imgViewPath = String.format(UploadFilePath.IMG_VIEW_PATH, sceneNum);
  394. String userName = null;
  395. if (!ObjectUtils.isEmpty(cameraDetail.getUserId())) {
  396. // SSOUser user = userService.getSSOUserByUserId(cameraDetail.getUserId());
  397. userName = ObjectUtils.isEmpty(user) ? null : user.getUserName();
  398. }
  399. JSONObject firmwareVersion = new JSONObject();
  400. if (!ObjectUtils.isEmpty(jsonObject.getString("camSoftwareVersion"))) {
  401. firmwareVersion.put("camSoftwareVersion", jsonObject.getString("camSoftwareVersion"));
  402. }
  403. if (!ObjectUtils.isEmpty(jsonObject.getString("version"))) {
  404. firmwareVersion.put("version", jsonObject.getString("version"));
  405. }
  406. String sceneUrl = "/" + sceneProNewUrl;
  407. //重算的场景,先移除该场景对应的容量
  408. if (rebuild == 1) {
  409. scenePlusService.resetSpace(sceneNum);
  410. } else {
  411. //上传log-main.png
  412. fYunFileService.uploadFile(ConstantFilePath.LOGO_PATH + "logo-main.png", imgViewPath + "logo-main.png");
  413. fYunFileService.uploadFile(ConstantFilePath.LOGO_PATH + "logo-main-en.png", imgViewPath + "logo-main-en.png");
  414. }
  415. String algorithm = jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam";
  416. String unicode = jsonObject.getString("creator") + "_" + jsonObject.getString("uuidtime");
  417. ScenePlusVO scenePlusVO = this.createScenePlus(sceneNum, camera.getId(), camera.getChildName(), jsonObject.getString("creator"),
  418. jsonObject.getString("pwd"), unicode,cameraType,jsonObject.getJSONObject("cam").getIntValue("type"), dataSource, icon, user.getId(), userName,algorithm,jsonObject.getInteger("location"),
  419. jsonObject.getJSONArray("points").size(), jsonObject.getString("name"), jsonObject.getString("info"),
  420. jsonObject.getInteger("scenetype"), jsonObject.getString("gps"), rebuild,
  421. jsonObject.getInteger("resolution"), firmwareVersion.toString(), sceneUrl, buildType, cameraDetail.getCooperationUser());
  422. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(sceneNum);
  423. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  424. boolean isObj = jsonObject.containsKey("exportMeshObj") && jsonObject.getIntValue("exportMeshObj") == 1;
  425. scenePlusExt.setIsObj(isObj ? CommonStatus.YES.code().intValue() : CommonStatus.NO.code().intValue());
  426. scenePlusExtService.updateById(scenePlusExt);
  427. //上传app状态文件
  428. commonService.uploadStatusJson(sceneNum, scenePlusVO.getSceneStatus(),
  429. scenePlusVO.getWebSite(),scenePlusVO.getThumb(),PayStatus.NOT_PAY.code(),
  430. String.format(UploadFilePath.DATA_VIEW_PATH, sceneNum));
  431. BuildSceneCallMessage mqMessage = getBuildSceneMqMessage(sceneNum, cameraType, algorithm, jsonObject, buildType,
  432. scenePlusVO.getDataSource());
  433. mqMessage.getExt().put("uuid", unicode);
  434. if (cameraDetail.getCompanyId() != null) {
  435. Company company = companyService.getById(cameraDetail.getCompanyId());
  436. if (company != null && !ObjectUtils.isEmpty(company.getCalculateFlexibility()) && !company.getCalculateFlexibility()) {
  437. mqMessage.setFlexibility(-1);
  438. }
  439. }
  440. mqMessage.getExt().put("deleteExtras", true);
  441. if(jsonObject.getIntValue("location") == 7){
  442. //发送到全景看看进行初始化
  443. intermitSceneService.sendMq(scenePlusVO.getNum(), jsonObject, CommonSuccessStatus.WAITING.code());
  444. rabbitMqProducer.sendByWorkQueue(queueIntermitModelingPre, mqMessage);
  445. }else{
  446. rabbitMqProducer.sendByWorkQueue(queueModelingPre, mqMessage);
  447. }
  448. return scenePlusVO;
  449. }
  450. public ScenePlusVO buildV3Scene(ScenePro scenePro,String fileId, String prefix,JSONObject jsonObject,String buildType,long cameraType) throws Exception{
  451. sceneCopyLogService.checkCanBuild(scenePro.getNum());
  452. //调用createScene方法生成scene数据和加入算法队列
  453. String cameraName = jsonObject.getJSONObject("cam").getString("uuid");
  454. String unicode = jsonObject.getString("creator") + "_" + jsonObject.getString("uuidtime");
  455. Camera camera = cameraService.getByChildName(cameraName);
  456. if (camera == null) {
  457. throw new BusinessException(CameraConstant.FAILURE_6003);
  458. }
  459. CameraDetail cameraDetail = cameraDetailService.getByCameraId(camera.getId());
  460. if (cameraDetail == null) {
  461. log.error("该相机详情不存在:" + cameraName);
  462. throw new BusinessException(CameraConstant.FAILURE_6003);
  463. }
  464. String sceneNum = scenePro.getNum();
  465. if (scenePro.getStatus().equals(SceneStatus.wait.code())) {
  466. log.info(scenePro.getNum() + ":场景处于计算中,不能再计算");
  467. return null;
  468. }
  469. String localDataPath = String.format(ConstantFilePath.DATABUFFER_FORMAT, sceneNum);
  470. String imgViewPath = String.format(ConstantFilePath.IMAGE_PATH_FORMAT, sceneNum);
  471. String dataViewPath = String.format(ConstantFilePath.DATA_PATH_FORMAT, sceneNum);
  472. String userName = null;
  473. if (!ObjectUtils.isEmpty(cameraDetail.getUserId())) {
  474. SSOUser user = userService.getSSOUserByUserId(cameraDetail.getUserId());
  475. userName = ObjectUtils.isEmpty(user) ? null : user.getUserName();
  476. }
  477. String icon = null;
  478. if (!ObjectUtils.isEmpty(jsonObject.getString("icon"))) {
  479. fYunFileService.copyFileInBucket(ConstantFilePath.OSS_PREFIX + prefix + jsonObject.getString("icon"),imgViewPath + jsonObject.getString("icon"));
  480. icon = fYunFileConfig.getHost() + imgViewPath + jsonObject.getString("icon");
  481. log.info("上传icon成功....");
  482. }
  483. JSONObject firmwareVersion = new JSONObject();
  484. if (!ObjectUtils.isEmpty(jsonObject.getString("camSoftwareVersion"))) {
  485. firmwareVersion.put("camSoftwareVersion", jsonObject.getString("camSoftwareVersion"));
  486. }
  487. if (!ObjectUtils.isEmpty(jsonObject.getString("version"))) {
  488. firmwareVersion.put("version", jsonObject.getString("version"));
  489. }
  490. //删除oss的houst_floor.json(国际版可能会卡住)
  491. fYunFileService.deleteFile(dataViewPath + "houst_floor.json");
  492. String algorithm = jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam";
  493. ScenePlusVO scenePlusVO = this.createScenePro(sceneNum, camera.getId(), camera.getChildName(), jsonObject.getString("creator"),
  494. jsonObject.getString("pwd"), unicode,cameraType, fileId, icon, cameraDetail.getUserId(), userName,algorithm,
  495. jsonObject.getJSONArray("points").size(), jsonObject.getString("name"), jsonObject.getString("info"),
  496. jsonObject.getInteger("scenetype"), jsonObject.getString("gps"),
  497. jsonObject.getInteger("resolution"), firmwareVersion.toString(), buildType);
  498. //上传场景状态文件
  499. commonService.uploadStatusJson(sceneNum, scenePlusVO.getSceneStatus(),
  500. scenePlusVO.getWebSite(),scenePlusVO.getThumb(),PayStatus.NOT_PAY.code(),
  501. String.format(ConstantFilePath.DATA_PATH_FORMAT, sceneNum));
  502. BuildSceneCallMessage mqMessage = getBuildSceneMqMessage(sceneNum, cameraType, algorithm, jsonObject, buildType,
  503. scenePlusVO.getDataSource());
  504. if (cameraDetail.getCompanyId() != null) {
  505. Company company = companyService.getById(cameraDetail.getCompanyId());
  506. if (company != null) {
  507. log.info("复制企业logo");
  508. SceneProEdit sceneEditInfo = sceneProEditService.getByProId(scenePlusVO.getId());
  509. if (StrUtil.isNotEmpty(company.getTopLogo())) {
  510. fYunFileService.copyFileInBucket(company.getTopLogo(),imgViewPath + "logo-main.png");
  511. }
  512. if (StrUtil.isNotEmpty(company.getFloorLogo())) {
  513. fYunFileService.copyFileInBucket(company.getFloorLogo(),imgViewPath + "floorLogoImg.png");
  514. sceneEditInfo.setFloorLogo("user");
  515. }
  516. if (StrUtil.isNotEmpty(company.getQrLogo())) {
  517. createQrCode(sceneNum,scenePlusVO.getWebSite(),company.getQrLogo());
  518. }
  519. sceneProEditService.updateById(sceneEditInfo);
  520. if (!ObjectUtils.isEmpty(company.getCalculateFlexibility()) && !company.getCalculateFlexibility()) {
  521. mqMessage.setFlexibility(-1);
  522. }
  523. }
  524. }
  525. rabbitMqProducer.sendByWorkQueue(queueV3ModelingPre, mqMessage);
  526. return scenePlusVO;
  527. }
  528. private void createQrCode(String num, String url, String qrLogo) {
  529. String localLogoPath = null;
  530. if (!org.apache.commons.lang3.ObjectUtils.isEmpty(qrLogo)) {
  531. try {
  532. localLogoPath = ConstantFilePath.AGENT_PATH + qrLogo.substring(qrLogo.lastIndexOf("//") + 1);
  533. HttpUtil.downloadFile(qrLogo, localLogoPath);
  534. } catch (Exception e) {
  535. log.error("公司logo下载失败:{}", qrLogo);
  536. localLogoPath = null;
  537. }
  538. }
  539. //生成二维码
  540. String outPathZh = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+ num +".png";
  541. String outPathEn = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+ num +"_en.png";
  542. QrConfig qrConfig = QrConfig.create();
  543. qrConfig.setWidth(512);
  544. qrConfig.setHeight(512);
  545. if(!org.apache.commons.lang3.ObjectUtils.isEmpty(localLogoPath)){
  546. qrConfig.setImg(localLogoPath);
  547. }
  548. QrCodeUtil.generate(url, qrConfig, FileUtil.file(outPathZh));
  549. QrCodeUtil.generate(url + "&lang=en", qrConfig, FileUtil.file(outPathEn));
  550. //上传二维码
  551. fYunFileService.uploadFile(outPathZh, String.format(UploadFilePath.DOWNLOADS_QRCODE, num) + num + ".png");
  552. fYunFileService.uploadFile(outPathEn, String.format(UploadFilePath.DOWNLOADS_QRCODE, num) + num + "_en.png");
  553. if(!org.apache.commons.lang3.ObjectUtils.isEmpty(localLogoPath)){
  554. FileUtils.deleteFile(localLogoPath);
  555. }
  556. }
  557. @Override
  558. public ResultData uploadSuccessBuild(String params, User user, boolean forceBuild, boolean checkUploadFile) throws Exception {
  559. log.info("uploadSuccessBuild-params: " + params);
  560. String preParams = params;
  561. if (StringUtils.isEmpty(params)) {
  562. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  563. }
  564. params = params.replaceAll("%2B", "+");
  565. params = params.replaceAll(" ", "+");
  566. Base64 base64 = new Base64();
  567. String cipher = params;
  568. // 私钥解密过程
  569. byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()), base64.decode(cipher));
  570. String restr = new String(res, "UTF-8");
  571. log.info("uploadSuccessBuild-params解密结果:" + restr);
  572. String[] strArr = restr.split(SPLICE);
  573. if (strArr.length != 3) {
  574. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  575. }
  576. String mac = strArr[0];
  577. String fileId = strArr[1];
  578. String folderName = redisUtil.get(String.format(RedisConstants.FILEID_FOLDER_BUILD, fileId));
  579. if(StringUtils.isEmpty(folderName)){
  580. SceneFileBuild fileBuild = findByFileId(fileId);
  581. if(ObjectUtils.isEmpty(fileBuild)){
  582. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  583. }
  584. folderName = fileBuild.getUnicode();
  585. redisUtil.set(String.format(RedisConstants.FILEID_FOLDER_BUILD, fileId), folderName,2 * 24 * 60 * 60);
  586. }
  587. sceneUploadCountService.resetCountByUuid(folderName);
  588. StringBuilder prefixBuffer = new StringBuilder(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator);
  589. String buildType = "V2";
  590. Long cameraType = 10L;
  591. String fileUploadedOpName = "fileUploadedOp.cam";
  592. String fileUploadedOpKey = new StringBuilder( ConstantFilePath.OSS_PREFIX).append(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator).append(fileUploadedOpName).toString();
  593. if(fYunFileService.fileExist(fileUploadedOpKey)){
  594. Set<String> notExistsFiles = commonService.checkUploadFile(mac, fileId, folderName, fYunFileConfig.getFyunType());
  595. if(CollUtil.isNotEmpty(notExistsFiles)){
  596. log.error("文件缺失, unicode:{}, 缺失文件:{}", folderName, notExistsFiles);
  597. if(checkUploadFile){
  598. throw new BusinessException(ModelingControlRespCode.FILE_EMPTY.code(), ModelingControlRespCode.FILE_EMPTY.message());
  599. }
  600. }
  601. }
  602. if(!fYunFileService.fileExist(ConstantFilePath.OSS_PREFIX + prefixBuffer + "data.fdage")){
  603. log.error("data.fdage文件不存在");
  604. throw new BusinessException(CameraConstant.FAILURE_6009);
  605. }
  606. JSONObject fdageJson = JSONObject.parseObject(fYunFileService.getFileContent(ConstantFilePath.OSS_PREFIX + prefixBuffer + "data.fdage"));
  607. if(ObjectUtils.isEmpty(fdageJson)){
  608. log.info("data.fdage文件为空!");
  609. throw new BusinessException(CameraConstant.FAILURE_6009);
  610. }
  611. //根据videoVersion判断是V2还是V3版本的算法和页面
  612. if (fdageJson.containsKey("videoVersion") && StrUtil.isNotEmpty(fdageJson.getString("videoVersion"))) {
  613. if (fdageJson.getIntValue("videoVersion") >= 4) {
  614. buildType = "V3";
  615. cameraType = 11L;
  616. }
  617. }
  618. int camType = fdageJson.getJSONObject("cam").getIntValue("type");
  619. if(camType == 5){
  620. cameraType = 6L;
  621. }
  622. buildScene(fileId, prefixBuffer.toString(),fdageJson,buildType,cameraType, user, forceBuild);
  623. return ResultData.ok();
  624. }
  625. private void removeUpdateV4(String dataFdagePath, JSONObject fdageJson){
  626. Integer updateV4 = fdageJson.getInteger("updateV4");
  627. if(Objects.isNull(updateV4) || updateV4 == 0){
  628. return;
  629. }
  630. fdageJson.put("updateV4", CommonStatus.NO.code());
  631. fYunFileService.uploadFile(fdageJson.toJSONString().getBytes(StandardCharsets.UTF_8), dataFdagePath);
  632. }
  633. private boolean callV3(ScenePro scenePro, String preParams, JSONObject fdageJson,String api) throws Exception {
  634. //复制出来的场景不支持补拍上传
  635. if(Objects.nonNull(scenePro)){
  636. sceneCopyLogService.checkCanBuild(scenePro.getNum());
  637. }
  638. String cameraName = fdageJson.getJSONObject("cam").getString("uuid");
  639. Camera camera = cameraService.getByChildName(cameraName);
  640. if (camera == null) {
  641. throw new BusinessException(CameraConstant.FAILURE_6003);
  642. }
  643. CameraDetail cameraDetail = cameraDetailService.getByCameraId(camera.getId());
  644. if (cameraDetail == null) {
  645. log.error("该相机详情不存在:" + cameraName);
  646. throw new BusinessException(CameraConstant.FAILURE_6003);
  647. }
  648. // 判断是否是正顺|火调|普通v3的场景,如果是正顺|火调|普通v3的场景,则发送到原来的系统进行计算
  649. if (!ObjectUtils.isEmpty(cameraDetail.getCompanyId())) {
  650. Company company = companyService.getById(cameraDetail.getCompanyId());
  651. if(ObjectUtils.isEmpty(company)){
  652. log.error("企业配置有误:" + cameraName);
  653. throw new BusinessException(CameraConstant.FAILURE_6003);
  654. }
  655. if (!ObjectUtils.isEmpty(company.getSceneVersion()) && company.getSceneVersion().equals("V3")) {
  656. //如果是app重新上传,需要解冻结
  657. if(Objects.nonNull(scenePro)){
  658. sceneColdStorageService.unfreeze(scenePro.getNum(), "用户相机重新全量上传", scenePro.getDataSource());
  659. }
  660. callV3Service(preParams, api);
  661. return Boolean.TRUE;
  662. }
  663. }
  664. return Boolean.FALSE;
  665. }
  666. public void callV3Service(String params,String api) throws Exception {
  667. log.info("params:{}", params);
  668. if(ObjectUtils.isEmpty(v3controlUrl)){
  669. log.error("未配置V3服务器!");
  670. throw new Exception("未配置V3服务器!");
  671. }
  672. HttpHeaders headers = new HttpHeaders();
  673. headers.setContentType(MediaType.MULTIPART_FORM_DATA);
  674. MultiValueMap<String,String> paramMap = new LinkedMultiValueMap();
  675. paramMap.add("params",params);
  676. HttpEntity<Object> formEntity = new HttpEntity<>(paramMap,headers);
  677. ResponseEntity<Result> responseEntity = restTemplate.postForEntity(v3controlUrl+api, formEntity, Result.class);
  678. if (responseEntity.getStatusCode().value() != HttpStatus.OK.value() || responseEntity.getBody().getCode() != ServerCode.SUCCESS.code()) {
  679. log.error("正顺场景请求V3服务器失败, params:{}, result:{}",params, JSON.toJSONString(responseEntity));
  680. throw new BusinessException(ErrorCode.SYSTEM_BUSY);
  681. }
  682. log.info("正顺场景请求V3服务器成功!");
  683. }
  684. @Override
  685. public ResultData turntableUploadSuccess(String params, User user, boolean forceBuild, boolean checkUploadFille) throws Exception {
  686. log.info("turntableUploadSuccess-params: " + params);
  687. String preParams = params;
  688. if (StringUtils.isEmpty(params)) {
  689. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  690. }
  691. params = params.replaceAll("%2B", "+");
  692. params = params.replaceAll(" ", "+");
  693. Base64 base64 = new Base64();
  694. String cipher = params;
  695. // 私钥解密过程
  696. byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
  697. base64.decode(cipher));
  698. String restr = new String(res, "UTF-8");
  699. log.info("turntableUploadSuccess-params解密结果:" + restr);
  700. String[] strArr = restr.split(SPLICE);
  701. if (strArr.length != 3) {
  702. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  703. }
  704. String mac = strArr[0];
  705. String fileId = strArr[1];
  706. String folderName = redisUtil.get(String.format(RedisConstants.FILEID_FOLDER_BUILD, fileId));
  707. if(StringUtils.isEmpty(folderName)){
  708. SceneFileBuild fileBuild = findByFileId(fileId);
  709. if(ObjectUtils.isEmpty(fileBuild)){
  710. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  711. }
  712. folderName = fileBuild.getUnicode();
  713. redisUtil.set(String.format(RedisConstants.FILEID_FOLDER_BUILD, fileId), folderName);
  714. }
  715. sceneUploadCountService.resetCountByUuid(folderName);
  716. //云目录
  717. StringBuilder prefixBuffer = new StringBuilder(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator);
  718. String fileUploadedOpName = "fileUploadedOp.cam";
  719. String fileUploadedOpKey = new StringBuilder( ConstantFilePath.OSS_PREFIX).append(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator).append(fileUploadedOpName).toString();
  720. if(fYunFileService.fileExist(fileUploadedOpKey)){
  721. Set<String> notExistsFiles = commonService.checkUploadFile(mac, fileId, folderName, fYunFileConfig.getFyunType());
  722. if(CollUtil.isNotEmpty(notExistsFiles)){
  723. log.error("文件缺失, unicode:{}, 缺失文件:{}", folderName, notExistsFiles);
  724. if(checkUploadFille){
  725. throw new BusinessException(ModelingControlRespCode.FILE_EMPTY.code(), ModelingControlRespCode.FILE_EMPTY.message());
  726. }
  727. }
  728. }
  729. if(!fYunFileService.fileExist(ConstantFilePath.OSS_PREFIX + prefixBuffer + "data.fdage")){
  730. log.error("data.fdage文件不存在");
  731. throw new BusinessException(CameraConstant.FAILURE_6009);
  732. }
  733. JSONObject fdageJson = JSONObject.parseObject(fYunFileService.getFileContent(ConstantFilePath.OSS_PREFIX + prefixBuffer + "data.fdage"));
  734. if(ObjectUtils.isEmpty(fdageJson)){
  735. log.info("data.fdage文件为空");
  736. throw new BusinessException(CameraConstant.FAILURE_6009);
  737. }
  738. String buildType = "V3";
  739. //13表示转台
  740. Long cameraType = 13L;
  741. //激光相机10 13
  742. int camType = fdageJson.getJSONObject("cam").getIntValue("type");
  743. log.info("camType:{}", camType);
  744. if(laserCamTypeList.contains(camType)){
  745. //激光转台
  746. cameraType = 14L;
  747. }
  748. ScenePlusVO scenePlusVO = buildScene(fileId, prefixBuffer.toString(), fdageJson, buildType, cameraType, user, forceBuild);
  749. // 通知激光场景系统开始构建场景
  750. if(cameraType.longValue() == 14 && fdageJson.getIntValue("location") != 7){
  751. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(scenePlusVO.getNum());
  752. Long sceneUserId = scenePlus.getUserId();
  753. String userName = null;
  754. if(!ObjectUtils.isEmpty(sceneUserId)){
  755. userName = userService.getSSOUserByUserId(sceneUserId).getUserName();
  756. }
  757. //判断 是否为激光相机
  758. Camera camera = cameraService.getByChildName(mac);
  759. fdkkLaserService.saveScene(scenePlus,fdageJson,camera,userName,false, scenePlus.getPayStatus(), null);
  760. }
  761. return ResultData.ok();
  762. }
  763. public ScenePlusVO createScenePlus(String projectNum, Long cameraId, String cameraName, String phoneId, String sceneKey,
  764. String unicode, Long cameraType, int camType, String dataSource, String pic, Long userId, String userName,
  765. String algorithm, Integer location, Integer sceneShootCount, String sceneName,
  766. String sceneDec, Integer sceneType, String gps,Integer type,
  767. Integer resolution, String firmwareVersion, String url, String buildType,
  768. Long cooperationUser)throws Exception{
  769. ScenePlusVO scenePlusVO = new ScenePlusVO();
  770. ScenePlus scenePlus = new ScenePlus();
  771. ScenePlusExt scenePlusExt = new ScenePlusExt();
  772. scenePlusExt.setWebSite(url+projectNum);
  773. scenePlus.setCameraId(cameraId);
  774. scenePlus.setPhoneId(phoneId);
  775. scenePlus.setNum(projectNum);
  776. scenePlus.setSceneSource(SceneSource.BM.code());
  777. scenePlusExt.setDataSource(dataSource);
  778. scenePlusExt.setLocation(location);
  779. scenePlus.setStartBuildTime(new Date());
  780. if(resolution == null || resolution.intValue() == 0){
  781. scenePlusExt.setSceneScheme(cameraType.intValue());
  782. }else {
  783. scenePlusExt.setSceneScheme(SceneScheme.BM.code());
  784. }
  785. if(cameraType == 6){
  786. scenePlusVO.setThreeCamType("yzl");
  787. }
  788. //转台相机用4k图
  789. if(cameraType.longValue() == 13){
  790. scenePlus.setSceneSource(SceneSource.ZT.code());
  791. scenePlusExt.setSceneScheme(SceneScheme.FOUR_K.code());
  792. }
  793. //激光相机
  794. if(cameraType.longValue() == 14){
  795. scenePlus.setSceneSource(SceneSource.JG.code());
  796. scenePlusExt.setSceneScheme(SceneScheme.FOUR_K.code());
  797. if(camType == CameraTypeEnum.LASER_SG.getType()){
  798. scenePlus.setSceneSource(SceneSource.SG.code());
  799. }
  800. }
  801. //全景看看场景用相机类型包括 看看 看见 深时 深光,所以这里做一个统一处理,为了让场景不在各平台中显示出来
  802. if(Objects.nonNull(location) && location == 7){
  803. scenePlus.setSceneSource(SceneSource.QJKK.code());
  804. }
  805. if(ModelKind.THREE_D_TILE.code().equals(modelKind)
  806. && CollUtil.isNotEmpty(sdTilesSceneSourceList)
  807. && sdTilesSceneSourceList.contains(scenePlus.getSceneSource())){
  808. scenePlusExt.setModelKind(modelKind);
  809. }
  810. //圆周率相机场景用3dtiles模型是
  811. if(cameraType == 6){
  812. scenePlusExt.setModelKind(modelKind);
  813. }
  814. if (pic != null && pic.length() > 5) {
  815. scenePlusExt.setThumb(pic);
  816. } else {
  817. scenePlusExt.setThumb(fYunFileConfig.getHost() + "/loading/thumb.jpg");
  818. }
  819. scenePlusExt.setThumb(scenePlusExt.getThumb().concat("?t=") + System.currentTimeMillis());
  820. scenePlus.setUserId(userId);
  821. if (sceneShootCount == null) {
  822. scenePlusExt.setShootCount(0);
  823. } else {
  824. scenePlusExt.setShootCount(sceneShootCount);
  825. }
  826. if (sceneName != null) {
  827. scenePlus.setTitle(sceneName);
  828. }
  829. if (sceneType != null) {
  830. scenePlus.setSceneType(sceneType);
  831. }
  832. if (gps != null && !gps.trim().equals("")) {
  833. scenePlusExt.setGps(gps);
  834. }
  835. scenePlusExt.setAlgorithm(algorithm);
  836. if(!org.springframework.util.StringUtils.isEmpty(firmwareVersion)){
  837. scenePlusExt.setFirmwareVersion(firmwareVersion);
  838. }
  839. scenePlusExt.setBuildType(buildType);
  840. log.info("场景记录添加到数据库:"+projectNum);
  841. //type=0为新生成场景,其余为重新计算场景
  842. if(camType == 5){//圆周率
  843. scenePlus.setThreeCamType("yzl");
  844. }
  845. SceneEditInfo sceneEditInfo = new SceneEditInfo();
  846. SceneEditInfoExt sceneEditInfoExt = new SceneEditInfoExt();
  847. SceneEditControls sceneEditControls = new SceneEditControls();
  848. if(type == 0){
  849. scenePlus.setSceneStatus(SceneStatus.wait.code());
  850. scenePlusService.save(scenePlus);
  851. scenePlusExt.setPlusId(scenePlus.getId());
  852. scenePlusExtService.save(scenePlusExt);
  853. sceneEditInfo.setTitle(scenePlus.getTitle());
  854. sceneEditInfo.setScenePlusId(scenePlus.getId());
  855. if(StrUtil.isNotBlank(sceneKey)) {
  856. sceneEditInfo.setScenePassword(sceneKey);
  857. sceneEditControls.setShowLock((int) CommonStatus.YES.code());
  858. }
  859. sceneEditInfoService.save(sceneEditInfo);
  860. sceneEditInfoExt.setEditInfoId(sceneEditInfo.getId());
  861. sceneEditInfoExt.setScenePlusId(scenePlus.getId());
  862. sceneEditInfoExtService.save(sceneEditInfoExt);
  863. sceneEditControls.setEditInfoId(sceneEditInfo.getId());
  864. sceneEditControlsService.save(sceneEditControls);
  865. //新增场景时,同时新增场景协作信息
  866. if(cooperationUser != null){
  867. SceneCooperation sceneCooperationEntity = new SceneCooperation();
  868. sceneCooperationEntity.setNum(projectNum);
  869. sceneCooperationEntity.setUserId(cooperationUser);
  870. sceneCooperationService.save(sceneCooperationEntity);
  871. List<SceneResourceCamera> resourceCameraList = sceneResourceCameraService.findListByCameraId(cameraId);
  872. SceneResourceCooperation sceneResourceCooperation = null;
  873. if(resourceCameraList != null && resourceCameraList.size() > 0){
  874. for (SceneResourceCamera sceneResourceCamera : resourceCameraList) {
  875. sceneResourceCooperation = new SceneResourceCooperation();
  876. sceneResourceCooperation.setSceneResourceId(sceneResourceCamera.getSceneResourceId());
  877. sceneResourceCooperation.setSceneCooperationId(sceneCooperationEntity.getId());
  878. sceneResourceCooperationService.save(sceneResourceCooperation);
  879. }
  880. }
  881. }
  882. }else {
  883. ScenePlus oldScene = scenePlusService.getScenePlusByNum(projectNum);
  884. scenePlus.setId(oldScene.getId());
  885. scenePlus.setSceneStatus(SceneStatus.wait.code());
  886. scenePlus.setRecStatus(RecStatus.VALID.code());
  887. scenePlus.setCreateTime(Calendar.getInstance().getTime());
  888. scenePlus.setBuildFailReason("");
  889. //只要开始常规场景上传计算,场景就不可以预览了
  890. scenePlus.setPreview(CommonStatus.NO.code().intValue());
  891. ScenePlusExt oldSceneExt = scenePlusExtService.getScenePlusExtByPlusId(oldScene.getId());
  892. scenePlusExt.setSpace(oldSceneExt.getSpace());
  893. scenePlusExt.setEcs(oldSceneExt.getEcs());
  894. scenePlusExt.setViewCount(oldSceneExt.getViewCount());
  895. scenePlusExt.setId(oldSceneExt.getId());
  896. if(sceneName!=null) {
  897. scenePlus.setTitle(sceneName);
  898. }
  899. if(sceneType!=null) {
  900. scenePlus.setSceneType(sceneType);
  901. }
  902. scenePlusService.updateById(scenePlus);
  903. scenePlusExtService.updateById(scenePlusExt);
  904. SceneEditInfo oldSceneEditInfo = sceneEditInfoService.getByScenePlusId(oldScene.getId());
  905. SceneEditInfoExt oldSceneEditeIinfoExt = sceneEditInfoExtService.getByEditInfoId(oldSceneEditInfo.getId());
  906. sceneEditInfo.setTitle(scenePlus.getTitle());
  907. sceneEditInfo.setDescription(scenePlus.getDescription());
  908. sceneEditInfo.setId(oldSceneEditInfo.getId());
  909. sceneEditInfo.setScenePlusId(scenePlus.getId());
  910. sceneEditInfo.setFloorLogoSize(100);
  911. sceneEditInfo.setRecStatus(RecStatus.VALID.code());
  912. sceneEditInfo.setFloorPublishVer(oldSceneEditInfo.getFloorEditVer() + 1);
  913. sceneEditInfo.setFloorEditVer(oldSceneEditInfo.getFloorEditVer() + 1);
  914. sceneEditInfo.setVersion(oldSceneEditInfo.getVersion() + 1);
  915. sceneEditInfoService.updateById(sceneEditInfo);
  916. if(Objects.nonNull(oldSceneEditeIinfoExt)){
  917. sceneEditInfoExt.setId(oldSceneEditeIinfoExt.getId());
  918. }
  919. sceneEditInfoExt.setEditInfoId(sceneEditInfo.getId());
  920. sceneEditInfoExt.setScenePlusId(scenePlus.getId());
  921. sceneEditInfoExtService.saveOrUpdate(sceneEditInfoExt);
  922. }
  923. BeanUtil.copyProperties(scenePlusExt, scenePlusVO);
  924. BeanUtil.copyProperties(scenePlus, scenePlusVO);
  925. return scenePlusVO;
  926. }
  927. public ScenePlusVO createScenePro(String projectNum, Long cameraId, String cameraName, String phoneId, String sceneKey,
  928. String unicode, Long cameraType, String fileId, String pic, Long userId, String userName,
  929. String algorithm, Integer sceneShootCount, String sceneName,String sceneDec,
  930. Integer sceneType, String gps,Integer resolution, String firmwareVersion, String buildType
  931. )throws Exception{
  932. ScenePro scene = sceneProService.getByNum(projectNum);
  933. SceneProEdit sceneEdit = sceneProEditService.getByProId(scene.getId());
  934. scene.setCameraId(cameraId);
  935. scene.setPhoneId(phoneId);
  936. scene.setNum(projectNum);
  937. scene.setSpace(0L);
  938. if (pic != null && pic.length() > 5) {
  939. scene.setThumb(pic);
  940. } else {
  941. scene.setThumb(ConstantUrl.DEFAULT_SCENE_PIC);
  942. }
  943. scene.setThumb(scene.getThumb().concat("?t=") + System.currentTimeMillis());
  944. if (!ObjectUtils.isEmpty(userName)) {
  945. scene.setUserId(userId);
  946. }
  947. if (sceneShootCount == null) {
  948. scene.setShootCount(0);
  949. } else {
  950. scene.setShootCount(sceneShootCount);
  951. }
  952. if (sceneName != null) {
  953. scene.setSceneName(sceneName);
  954. }
  955. if (sceneDec != null) {
  956. scene.setSceneDec("<p>" + new String(sceneDec.getBytes("UTF-8")) + "</p>");
  957. }
  958. if (sceneType != null) {
  959. scene.setSceneType(sceneType);
  960. }
  961. if (gps != null && !gps.trim().equals("")) {
  962. scene.setGps(gps);
  963. }
  964. scene.setAlgorithm(algorithm);
  965. if(!org.springframework.util.StringUtils.isEmpty(firmwareVersion)){
  966. scene.setFirmwareVersion(firmwareVersion);
  967. }
  968. scene.setBuildType(buildType);
  969. log.info("场景记录添加到数据库:"+projectNum);
  970. scene.setStatus(0);
  971. scene.setPayStatus(0);
  972. scene.setRecStatus("A");
  973. scene.setCreateTime(new Date());
  974. if (sceneName != null) {
  975. scene.setSceneName(sceneName);
  976. }
  977. if (sceneType != null) {
  978. scene.setSceneType(sceneType);
  979. }
  980. sceneProService.updateById(scene);
  981. sceneEdit.setNeedKey(0);
  982. if (cameraType.longValue() != 14 && !ObjectUtils.isEmpty(sceneKey)) {
  983. sceneEdit.setNeedKey(1);
  984. sceneEdit.setSceneKey(sceneKey);
  985. }
  986. sceneEdit.setProId(scene.getId());
  987. sceneEdit.setMapVisi(1);
  988. sceneEdit.setTourVisi(1);
  989. sceneEdit.setVrVisi(1);
  990. sceneEdit.setCadImgVisi(1);
  991. sceneEdit.setPanoVisi(1);
  992. sceneEdit.setOverlay(null);
  993. sceneEdit.setM2dVisi(1);
  994. sceneEdit.setPlayData(null);
  995. sceneEdit.setFloorLogo("0");
  996. sceneEdit.setM3dVisi(1);
  997. sceneEdit.setJumpScene(false);
  998. sceneEdit.setMeasureVisi(0);
  999. sceneEdit.setFloorLogoSize(100);
  1000. sceneEdit.setUpdateTime(new Date());
  1001. sceneEdit.setRecStatus("A");
  1002. sceneEdit.setFloorPublishVer(sceneEdit.getFloorEditVer() + 1);
  1003. sceneEdit.setFloorEditVer(sceneEdit.getFloorEditVer() + 1);
  1004. sceneEdit.setVersion(sceneEdit.getVersion() + 1);
  1005. sceneEdit.setImagesVersion(sceneEdit.getImagesVersion() + 1);
  1006. sceneProEditService.updateById(sceneEdit);
  1007. JSONObject scenejson = JSONObject.parseObject(JSONObject.toJSONString(scene));
  1008. scenejson.put("thumbImg", 0);
  1009. scenejson.put("version", sceneEdit.getVersion());
  1010. scenejson.put("floorLogo", 0);
  1011. if(!ObjectUtils.isEmpty(sceneKey)){
  1012. scenejson.put("sceneKey", sceneKey);
  1013. scenejson.put("public", 1);
  1014. }else{
  1015. scenejson.put("sceneKey", "");
  1016. scenejson.put("public", 0);
  1017. }
  1018. if(cameraType.longValue() < 4 || cameraType.longValue() == 5 || cameraType.longValue() == 6){
  1019. scenejson.put("visions", 1);
  1020. }else {
  1021. scenejson.put("visions", 2);
  1022. }
  1023. scenejson.put("createTime", new DateTime(new Date()).toString("yyyy-MM-dd HH:mm"));
  1024. scenejson.put("floorPublishVer", sceneEdit.getFloorPublishVer());
  1025. scenejson.put("floorEditVer", sceneEdit.getFloorEditVer());
  1026. scenejson.put("rulerVisi", sceneEdit.getRulerVisi());
  1027. scenejson.put("entry", null);
  1028. if(!org.springframework.util.StringUtils.isEmpty(sceneEdit.getHotsIds())){
  1029. scenejson.put("hots", 1);
  1030. }
  1031. File file = new File(ConstantFilePath.SCENE_PATH+"data/data"+projectNum);
  1032. if(!file.exists()||!file.isDirectory())
  1033. {
  1034. file.mkdirs();
  1035. }
  1036. FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data/data"+projectNum+File.separator+"scene.json", scenejson.toString());
  1037. //生成二维码
  1038. MatrixToImageWriterUtil.createQRCode(scene.getWebSite(), ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+projectNum+".png",false, null);
  1039. MatrixToImageWriterUtil.createQRCode(scene.getWebSite() + "&lang=en", ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+projectNum+"_en.png",false, null);
  1040. log.info("二维码生成完成");
  1041. ScenePlusVO scenePlusVO = new ScenePlusVO();
  1042. scenePlusVO.setSceneStatus(scene.getStatus());
  1043. scenePlusVO.setThumb(scene.getThumb());
  1044. scenePlusVO.setPayStatus(scene.getPayStatus());
  1045. scenePlusVO.setId(scene.getId());
  1046. scenePlusVO.setNum(scene.getNum());
  1047. scenePlusVO.setWebSite(scene.getWebSite());
  1048. scenePlusVO.setDataSource(scene.getDataSource());
  1049. return scenePlusVO;
  1050. }
  1051. public BuildSceneCallMessage getBuildSceneMqMessage(String projectNum,
  1052. Long cameraType, String algorithm, JSONObject fdageJson,
  1053. String buildType, String dataSource) {
  1054. BuildSceneCallMessage mqMsg = new BuildSceneCallMessage();
  1055. mqMsg.setSceneNum(projectNum);
  1056. mqMsg.setCameraType(String.valueOf(cameraType));
  1057. mqMsg.setAlgorithm(algorithm);
  1058. mqMsg.setResolution(String.valueOf(fdageJson.getInteger("resolution")));
  1059. mqMsg.setBuildType(buildType);
  1060. mqMsg.setPath(dataSource);
  1061. mqMsg.setCreateTime(DateUtil.format(Calendar.getInstance().getTime(), DateExtUtil.dateStyle));
  1062. Map<String, Object> ext = new HashMap<>();
  1063. ext.put("location", fdageJson.getInteger("location"));
  1064. mqMsg.setExt(ext);
  1065. return mqMsg;
  1066. }
  1067. @Override
  1068. public ResultData rebuildScene(String num,Boolean force,Boolean deleteExtras, String from) throws IOException {
  1069. ScenePro scenePro = sceneProService.getByNum(num);
  1070. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  1071. //复制出来的场景不支持重算
  1072. List<SceneCopyLog> sceneCopyLogs = sceneCopyLogService. listByNewNum(num);
  1073. if(CollUtil.isNotEmpty(sceneCopyLogs)){
  1074. throw new BusinessException(ErrorCode.FAILURE_CODE_5071);
  1075. }
  1076. //已删除原始资源的场景不支持重算
  1077. Long cameraId = null;
  1078. Date laseCallTime = null;
  1079. ScenePlusExt scenePlusExt = null;
  1080. if(Objects.nonNull(scenePlus)){
  1081. scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  1082. laseCallTime = scenePlusExt.getAlgorithmTime();
  1083. cameraId = scenePlus.getCameraId();
  1084. }else{
  1085. laseCallTime = scenePro.getCreateTime();
  1086. cameraId = scenePro.getCameraId();
  1087. }
  1088. //激光场景校验是否能够计算
  1089. this.checkJgCanBuild(scenePro);
  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(), null);
  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.getExt().put("forceRebuild", force);
  1162. }
  1163. message.setRebuild("1");
  1164. if(Objects.nonNull(scenePlusExt.getLocation()) && scenePlusExt.getLocation() == 7){
  1165. //发送到全景看看进行初始化
  1166. JSONObject jsonObject = JSONObject.parseObject(fYunFileService.getFileContent(SceneUtil.getHomePath(scenePlusExt.getDataSource()) + "data.fdage"));
  1167. intermitSceneService.sendMq(num, jsonObject, CommonSuccessStatus.WAITING.code());
  1168. rabbitMqProducer.sendByWorkQueue(queueIntermitModelingPre, message);
  1169. }else{
  1170. rabbitMqProducer.sendByWorkQueue(queueModelingPre, message);
  1171. }
  1172. redisUtil.incr("modeling-count:" + num, 1);
  1173. scenePlusService.update(new LambdaUpdateWrapper<ScenePlus>()
  1174. .set(ScenePlus::getSceneStatus, SceneStatus.wait.code())
  1175. .set(ScenePlus::getBuildFailReason, null)
  1176. .set(ScenePlus::getStartBuildTime, new Date())
  1177. .eq(ScenePlus::getNum, num));
  1178. if(ModelKind.THREE_D_TILE.code().equals(modelKind)
  1179. && CollUtil.isNotEmpty(sdTilesSceneSourceList)
  1180. && sdTilesSceneSourceList.contains(scenePlus.getSceneSource())){
  1181. scenePlusExt.setModelKind(modelKind);
  1182. }
  1183. if(cameraType == 6L){
  1184. scenePlusExt.setModelKind(modelKind);
  1185. }
  1186. scenePlusExt.setUpdateTime(new Date());
  1187. scenePlusExtService.updateById(scenePlusExt);
  1188. //记录日志表
  1189. SceneRebuildLog rebuildLog = new SceneRebuildLog();
  1190. rebuildLog.setNum(num);
  1191. rebuildLog.setSource(from);
  1192. sceneRebuildLogService.save(rebuildLog);
  1193. return ResultData.ok();
  1194. }
  1195. /**
  1196. * 由于算法不支持2022年三月份前的激光场景计算,这里需要校验是否是能计算,不能就退出重算
  1197. * @return
  1198. */
  1199. private void checkJgCanBuild(ScenePro scenePro){
  1200. if(Objects.isNull(scenePro) || StrUtil.isEmpty(scenePro.getDataSource()) || !SceneSource.JG.code().equals(scenePro.getSceneSource())){
  1201. return;
  1202. }
  1203. cn.hutool.core.date.DateTime limitTime = DateExtUtil.parse(jgNotSupportBuildTime, DateExtUtil.dateStyle10);
  1204. String dataSource = scenePro.getDataSource();
  1205. String sceneDateTimeStr = dataSource.substring(dataSource.lastIndexOf("_") + 1).substring(0, 6);
  1206. //如果截取的时间串是空的,无法判断时间,就退出,正常走计算逻辑
  1207. if(StrUtil.isEmpty(sceneDateTimeStr)){
  1208. return;
  1209. }
  1210. cn.hutool.core.date.DateTime sceneDateTime = null;
  1211. try{
  1212. sceneDateTime = DateExtUtil.parse(sceneDateTimeStr, DateExtUtil.dateStyle10);
  1213. if(Objects.isNull(sceneDateTime)){
  1214. return;
  1215. }
  1216. }catch (Exception e){
  1217. //如果截取的时间串转换日期错误,无法判断时间,退出函数
  1218. return;
  1219. }
  1220. if(sceneDateTime.before(limitTime)){
  1221. throw new BusinessException(ErrorCode.FAILURE_CODE_5067);
  1222. }
  1223. }
  1224. private ScenePlusVO buildScenePost(String dataSource, JSONObject jsonObject, String buildType, long cameraType,
  1225. String sceneNum, Camera camera, CameraDetail cameraDetail, int rebuild,String icon,User user, String customUserId, String uploadType) throws Exception {
  1226. String imgViewPath = String.format(UploadFilePath.IMG_VIEW_PATH, sceneNum);
  1227. JSONObject firmwareVersion = new JSONObject();
  1228. if (!ObjectUtils.isEmpty(jsonObject.getString("camSoftwareVersion"))) {
  1229. firmwareVersion.put("camSoftwareVersion", jsonObject.getString("camSoftwareVersion"));
  1230. }
  1231. if (!ObjectUtils.isEmpty(jsonObject.getString("version"))) {
  1232. firmwareVersion.put("version", jsonObject.getString("version"));
  1233. }
  1234. String sceneUrl = "/" + sceneProNewUrl;
  1235. //重算的场景,先移除该场景对应的容量
  1236. if (rebuild == 1) {
  1237. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(sceneNum);
  1238. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  1239. scenePlusExt.setSpace(0L);
  1240. scenePlusExt.setUpdateTime(null);
  1241. scenePlusExtService.updateById(scenePlusExt);
  1242. } else {
  1243. //上传log-main.png
  1244. fYunFileService.uploadFile(ConstantFilePath.LOGO_PATH + "logo-main.png", imgViewPath + "logo-main.png");
  1245. fYunFileService.uploadFile(ConstantFilePath.LOGO_PATH + "logo-main-en.png", imgViewPath + "logo-main-en.png");
  1246. }
  1247. String algorithm = jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam";
  1248. String unicode = jsonObject.getString("creator") + "_" + jsonObject.getString("uuidtime");
  1249. ScenePlusVO scenePlusVO = this.createScenePlus(sceneNum, camera.getId(), camera.getChildName(), jsonObject.getString("creator"),
  1250. jsonObject.getString("pwd"), unicode, cameraType,jsonObject.getJSONObject("cam").getIntValue("type"), dataSource, icon, user.getId() , null, algorithm, jsonObject.getInteger("location"),
  1251. jsonObject.getJSONArray("points").size(), jsonObject.getString("name"), jsonObject.getString("info"),
  1252. jsonObject.getInteger("scenetype"), jsonObject.getString("gps"), rebuild,
  1253. jsonObject.getInteger("resolution"), firmwareVersion.toString(), sceneUrl, buildType, cameraDetail.getCooperationUser());
  1254. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(sceneNum);
  1255. scenePlus.setTaskId(jsonObject.getString("taskId"));
  1256. scenePlus.setKNo(jsonObject.getString("kNo"));
  1257. scenePlus.setPushAddress(jsonObject.getString("pushAddress"));
  1258. scenePlus.setDistrictCode(jsonObject.getString("districtCode"));
  1259. scenePlus.setDistrictName(jsonObject.getString("districtName"));
  1260. scenePlusService.updateById(scenePlus);
  1261. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  1262. boolean isObj = jsonObject.containsKey("exportMeshObj") && jsonObject.getIntValue("exportMeshObj") == 1;
  1263. scenePlusExt.setIsObj(isObj ? CommonStatus.YES.code().intValue() : CommonStatus.NO.code().intValue());
  1264. scenePlusExtService.updateById(scenePlusExt);
  1265. BuildSceneCallMessage mqMessage = getBuildSceneMqMessage(sceneNum, cameraType, algorithm, jsonObject, buildType, scenePlusVO.getDataSource());
  1266. if (cameraDetail.getCompanyId() != null) {
  1267. Company company = companyService.getById(cameraDetail.getCompanyId());
  1268. if (company != null && !ObjectUtils.isEmpty(company.getCalculateFlexibility()) && !company.getCalculateFlexibility()) {
  1269. mqMessage.setFlexibility(-1);
  1270. }
  1271. }
  1272. mqMessage.setRebuild(String.valueOf(rebuild));
  1273. mqMessage.getExt().put("deleteExtras", true);
  1274. mqMessage.getExt().put("customUserId", customUserId);
  1275. mqMessage.getExt().put("gps", jsonObject.getString("gps"));
  1276. mqMessage.getExt().put("threeCamType", scenePlusVO.getThreeCamType());
  1277. mqMessage.getExt().put("sceneOrigBdId", jsonObject.getLong("sceneOrigBdId"));
  1278. if(uploadType.equals("single")){//场景上传模式(single-细小文件上传, zip-压缩包上传)
  1279. OrigFileUploadBatch condition = new OrigFileUploadBatch();
  1280. condition.setUuid(unicode);
  1281. condition.setStatus(0);
  1282. OrigFileUploadBatch origFileUploadBatch = origFileUploadBatchService.getByCondition(condition);
  1283. origFileUploadBatch.setStatus(4);//修改为等待通知计算状态,由定时任务统一分配计算
  1284. origFileUploadBatch.setMqContent(JSON.toJSONString(mqMessage));
  1285. origFileUploadBatchService.updateById(origFileUploadBatch);
  1286. redisUtil.del("single:upload:uuid:" + unicode);
  1287. }else{
  1288. rabbitMqProducer.sendByWorkQueue(queueModelingPre, mqMessage);
  1289. }
  1290. jmgaService.sendStatus(sceneNum, "上传完毕");
  1291. return scenePlusVO;
  1292. }
  1293. @Override
  1294. public ResultData uploadFile(MultipartFile file, String params, String dir) throws Exception {
  1295. log.info("upload-params: "+params);
  1296. if (StringUtils.isEmpty(params)){
  1297. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  1298. }
  1299. params = params.replaceAll("%2B", "+");
  1300. Base64 base64 = new Base64();
  1301. String cipher = params;
  1302. // 私钥解密过程
  1303. byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
  1304. base64.decode(cipher));
  1305. String restr = new String(res, "UTF-8");
  1306. log.info("upload-params解密结果:" + restr);
  1307. String[] strArr = restr.split(SPLICE);
  1308. if (strArr.length != 6) {
  1309. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  1310. }
  1311. String mac = strArr[0];
  1312. String fileId = strArr[1];
  1313. String picNum = strArr[2];
  1314. String md5 = strArr[3];
  1315. String chunk = strArr[4];
  1316. log.info("mac:{},fileId:{},picNum:{},md5:{},chunk:{}", mac, fileId, picNum, md5, chunk);
  1317. ResultData result = null;
  1318. if (file.isEmpty()){
  1319. log.error("文件为空。");
  1320. throw new BusinessException(ErrorCode.PARAM_REQUIRED.code(),"文件为空。");
  1321. }
  1322. if (StringUtils.isEmpty(fileId)){
  1323. log.error("文件Id为空。");
  1324. throw new BusinessException(ErrorCode.PARAM_REQUIRED.code(),"文件Id为空。");
  1325. }
  1326. if (picNum == null){
  1327. log.error("照片数目为空。");
  1328. throw new BusinessException(ErrorCode.PARAM_REQUIRED.code(),"照片数目为空。");
  1329. }
  1330. if (StringUtils.isEmpty(mac)){
  1331. log.error("mac为空。");
  1332. throw new BusinessException(ErrorCode.PARAM_REQUIRED.code(),"mac为空。");
  1333. }
  1334. if (StringUtils.isEmpty(md5)){
  1335. log.error("md5为空。");
  1336. throw new BusinessException(ErrorCode.PARAM_REQUIRED.code(),"md5为空。");
  1337. }
  1338. long size = file.getSize();
  1339. log.info("mac:{}, fileId:{}, picNum:{}, md5:{}, chunk:{}", mac, fileId, picNum, md5, chunk);
  1340. chunk = chunk.split(SPLICE)[0];
  1341. // 获取文件名
  1342. String fileName = file.getOriginalFilename();
  1343. log.info("上传的文件名为:" + fileName);
  1344. // 获取文件的后缀名
  1345. String folderName = redisUtil.get(String.format(RedisConstants.FILEID_FOLDER_BUILD, fileId));
  1346. if(StringUtils.isEmpty(folderName)){
  1347. SceneFileBuild fileBuild = findByFileId(fileId);
  1348. if(ObjectUtils.isEmpty(fileBuild)){
  1349. log.error("数据不正常,fileBuild没找到");
  1350. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  1351. }
  1352. folderName = fileBuild.getUnicode();
  1353. redisUtil.set(String.format(RedisConstants.FILEID_FOLDER_BUILD, fileId), folderName,2 * 24 * 60 * 60);
  1354. }
  1355. // 1. 判断该文件是否已经上传过
  1356. // 2. 如果已经上传过,判断MD5值和文件大小是否相等。如果相等,更新数据记录。如果不相等,删除该文件,重新上传。
  1357. // 3. 如果未上传过,需要上传。
  1358. String filePath = mac.concat(File.separator).concat(fileId).concat(File.separator).concat(folderName);
  1359. String yunFilePath = LocalConstants.BASE_PATH.concat(fYunFileConfig.getBucket()).concat(File.separator).concat(ConstantFilePath.OSS_PREFIX)
  1360. .concat(filePath).concat(File.separator).concat(dir).concat(fileName);
  1361. log.info("yunFilePath:{}", yunFilePath);
  1362. String key = RedisKeyExt.CAM_FILE_LIST.replace("@unicode@", folderName);
  1363. String value = size + "_" + fileName;
  1364. boolean needUpload = false;
  1365. File yunFile = new File(yunFilePath);
  1366. if (yunFile.exists()){
  1367. String fileMD5 = FileMd5Util.getFileMD5(yunFile);
  1368. if (md5.equals(fileMD5) && yunFile.length() == size){
  1369. log.info("文件已存在,MD5和文件大小一致。");
  1370. SceneFileUpload uploadEntity = sceneFileUploadService.findByFileIdAndChunk(fileId, Integer.valueOf(chunk));
  1371. if (uploadEntity != null){
  1372. uploadEntity.setSize((int) size);
  1373. uploadEntity.setMd5(md5);
  1374. uploadEntity.setFilePath(yunFilePath);
  1375. uploadEntity.setFileSourceName(fileName);
  1376. uploadEntity.setUploadStatus(1);
  1377. sceneFileUploadService.updateById(uploadEntity);
  1378. }else{
  1379. SceneFileUpload sceneFileUploadEntity = new SceneFileUpload();
  1380. sceneFileUploadEntity.setSize((int) size);
  1381. sceneFileUploadEntity.setMd5(md5);
  1382. sceneFileUploadEntity.setFilePath(yunFilePath.toString());
  1383. sceneFileUploadEntity.setFileSourceName(fileName);
  1384. sceneFileUploadEntity.setUploadStatus(1);
  1385. sceneFileUploadEntity.setFileId(fileId);
  1386. sceneFileUploadEntity.setChunk(Integer.valueOf(chunk));
  1387. sceneFileUploadService.save(sceneFileUploadEntity);
  1388. }
  1389. redisUtil.sSet(key, value);
  1390. result = ResultData.ok();
  1391. }else if (!md5.equals(fileMD5)) {
  1392. log.warn("文件已上传,上传MD5:"+md5+",服务器MD5:"+fileMD5+"。不一致。上传失败");
  1393. FileUtils.delFile(yunFilePath.toString());
  1394. needUpload = true;
  1395. }else if (yunFile.length() != size){
  1396. log.warn("文件已上传,文件大小不一致。上传失败");
  1397. FileUtils.delFile(yunFilePath);
  1398. needUpload = true;
  1399. }
  1400. }else {
  1401. log.info("文件不存在,需要重新上传");
  1402. needUpload = true;
  1403. }
  1404. // 4. 上传成功后,校验MD5和文件大小是否相等
  1405. // 5. 如果相等,更新数据记录。如果不相等,返回上传失败结果。
  1406. try {
  1407. if (needUpload){
  1408. fYunFileService.uploadFile(file.getInputStream(),ConstantFilePath.OSS_PREFIX.concat(filePath).concat(File.separator).concat(dir).concat(fileName));
  1409. File uploadFile = new File(yunFilePath);
  1410. String fileMD5 = FileMd5Util.getFileMD5(uploadFile);
  1411. SceneFileUpload sceneFileUploadEntity = new SceneFileUpload();
  1412. sceneFileUploadEntity.setSize((int) size);
  1413. sceneFileUploadEntity.setMd5(md5);
  1414. sceneFileUploadEntity.setFilePath(yunFilePath);
  1415. sceneFileUploadEntity.setFileSourceName(fileName);
  1416. sceneFileUploadEntity.setFileId(fileId);
  1417. sceneFileUploadEntity.setChunk(Integer.valueOf(chunk));
  1418. if (md5.equals(fileMD5) && uploadFile.length() == size){
  1419. log.info("文件已上传,MD5和文件大小一致。上传成功");
  1420. sceneFileUploadEntity.setUploadStatus(1);
  1421. sceneFileUploadService.save(sceneFileUploadEntity);
  1422. redisUtil.sSet(key, value);
  1423. result = ResultData.ok();
  1424. }else if (!md5.equals(fileMD5)) {
  1425. log.error("文件已上传,上传MD5:"+md5+",服务器MD5:"+fileMD5+"。不一致。上传失败");
  1426. sceneFileUploadEntity.setUploadStatus(-1);
  1427. sceneFileUploadService.save(sceneFileUploadEntity);
  1428. result = ResultData.error(ErrorCode.SYSTEM_ERROR,"上传失败, 请重新上传。");
  1429. }else if (uploadFile.length() != size){
  1430. log.error("文件已上传,文件大小不一致。上传失败");
  1431. sceneFileUploadEntity.setUploadStatus(-1);
  1432. sceneFileUploadService.save(sceneFileUploadEntity);
  1433. result = ResultData.error(ErrorCode.SYSTEM_ERROR,"上传失败, 请重新上传。");
  1434. }
  1435. }
  1436. }catch (IllegalStateException | IOException e) {
  1437. log.error("上传失败, 请重新上传,md5:{},chunk:{}", md5, chunk);
  1438. log.error("上传失败", e);
  1439. result = ResultData.error(ErrorCode.SYSTEM_ERROR,"上传失败, 请重新上传。");
  1440. }
  1441. return result;
  1442. }
  1443. @Override
  1444. public ResultData uploadFile(SendCallAlgorithmParam param) throws Exception {
  1445. log.info("sendCallAlgorithm 参数为:{}", JSONObject.toJSONString(param));
  1446. String filePath = param.getFilepath();
  1447. if(StrUtil.isBlank(filePath)){
  1448. throw new BusinessException(ErrorCode.PARAM_REQUIRED.code(), "filePath不能为空");
  1449. }
  1450. SendCallAlgorithmDetail detail = param.getDetails();
  1451. String uploadType = detail.getUploadType();
  1452. if(StrUtil.isNotEmpty(uploadType) && "log".equals(uploadType)){
  1453. return ResultData.ok();
  1454. }
  1455. String uuid = detail.getUuid();
  1456. if(StrUtil.isBlank(uuid)){
  1457. throw new BusinessException(ErrorCode.PARAM_REQUIRED.code(), "uuid不能为空");
  1458. }
  1459. String fileName = detail.getFileName();
  1460. if(StrUtil.isBlank(fileName)){
  1461. throw new BusinessException(ErrorCode.PARAM_REQUIRED.code(), "fileName不能为空");
  1462. }
  1463. String callType = param.getDetails().getCallType();
  1464. if(StrUtil.isNotEmpty(callType) && callType.equals("UPLOAD_WHILE_SHOOTING")){
  1465. uploadShootingService.uploadFile(param);
  1466. return ResultData.ok();
  1467. }
  1468. boolean lock = redisLockUtil.lock("lock:single:upload:uuid:" + uuid, uuid, 1);
  1469. if(!lock){//如果拿不到锁,证明
  1470. Thread.sleep(2000L);
  1471. }
  1472. String batchId = redisUtil.get("single:upload:uuid:" + uuid);
  1473. if(StrUtil.isEmpty(batchId)){
  1474. OrigFileUploadBatch condition = new OrigFileUploadBatch();
  1475. condition.setUuid(uuid);
  1476. condition.setStatus(0);
  1477. OrigFileUploadBatch origFileUploadBatch = origFileUploadBatchService.getByCondition(condition);
  1478. if(Objects.isNull(origFileUploadBatch)){
  1479. batchId = redisUtil.get("single:upload:uuid:" + uuid);
  1480. if(StrUtil.isEmpty(batchId)){
  1481. batchId = UUID.fastUUID().toString().replace("-", "");
  1482. redisUtil.set("single:upload:uuid:" + uuid, batchId);
  1483. origFileUploadBatch = new OrigFileUploadBatch();
  1484. origFileUploadBatch.setUuid(uuid);
  1485. origFileUploadBatch.setBatchId(batchId);
  1486. origFileUploadBatchService.save(origFileUploadBatch);
  1487. }
  1488. }
  1489. }
  1490. //插入上传明细表
  1491. OrigFileUpload origFileUpload = new OrigFileUpload();
  1492. origFileUpload.setFileUrl(filePath);
  1493. origFileUpload.setFileName(fileName);
  1494. origFileUpload.setBatchId(batchId);
  1495. origFileUploadService.save(origFileUpload);
  1496. if(lock){
  1497. redisLockUtil.unlockLua("lock:single:upload:uuid:" + uuid, uuid);
  1498. }
  1499. if(fileName.equals("config.json")){
  1500. HttpUtilExt.downloadFileAndCheck(filePath, sendCallAlgorithmPath.concat(uuid).concat("/config.json"), 300000);
  1501. }
  1502. if(fileName.equals("data.fdage")){
  1503. HttpUtilExt.downloadFileAndCheck(filePath, sendCallAlgorithmPath.concat(uuid).concat("/data.fdage"), 300000);
  1504. }
  1505. if(fileName.equals("scene_up_data.txt")){
  1506. HttpUtilExt.downloadFileAndCheck(filePath, sendCallAlgorithmPath.concat(uuid).concat("/scene_up_data.txt"), 300000);
  1507. }
  1508. return ResultData.ok();
  1509. }
  1510. @Override
  1511. public ResultData noticeBuild(String uuid, Long bdId, String dataSource, String uploadType) throws Exception {
  1512. log.info("通知计算,uuid:{} " + uuid);
  1513. String sceneNum = null;
  1514. SceneOrigBd sceneOrigBd = null;
  1515. try {
  1516. String[] uuidArr = uuid.split("_");
  1517. String snCode = uuidArr[0];
  1518. JSONObject fdageData = null;
  1519. if(StrUtil.isNotEmpty(dataSource)){
  1520. String homePath = SceneUtil.getHomePath(dataSource);
  1521. fdageData = JSONObject.parseObject(fYunFileService.getFileContent(homePath + "data.fdage"));
  1522. }else{
  1523. fdageData = JSONObject.parseObject(FileUtils.readFile(sendCallAlgorithmPath.concat(uuid).concat("/data.fdage")));
  1524. }
  1525. int camType = fdageData.getJSONObject("cam").getIntValue("type");
  1526. if(Objects.nonNull(bdId)){
  1527. sceneOrigBd = sceneOrigBdService.getById(bdId);
  1528. fdageData.put("taskId", sceneOrigBd.getTaskId());
  1529. fdageData.put("kNo", sceneOrigBd.getKNo());
  1530. fdageData.put("sceneOrigBdId", bdId);
  1531. fdageData.put("pushAddress", sceneOrigBd.getPushAddress());
  1532. fdageData.put("districtCode", sceneOrigBd.getDistrictCode());
  1533. fdageData.put("districtName", sceneOrigBd.getDistrictName());
  1534. }
  1535. //相机入库
  1536. String cameraInStoreUrl = fdServiceUrl + ApiConstant.URL_CAMERA_INSTORE;
  1537. Map<String, Object> cameraInStoreParams = new HashMap<>();
  1538. cameraInStoreParams.put("cameraType", camType);
  1539. cameraInStoreParams.put("snCode", snCode);
  1540. ResultData post = myClient.post(cameraInStoreUrl, cameraInStoreParams);
  1541. log.info("---------cameraInStore result:{}-----------", post);
  1542. Long cameraType = 13L;//默认为看见相机
  1543. Camera camera = cameraService.getBySnCode(snCode);
  1544. if(Objects.isNull(camera)){
  1545. throw new BusinessException(ErrorCode.CAMERA_BIND_NO_EXIST.code(), "相机未入库");
  1546. }
  1547. CameraDetail cameraDetail = cameraDetailService.getByCameraId(camera.getId());
  1548. if(Objects.isNull(cameraDetail)){
  1549. throw new BusinessException(ErrorCode.CAMERA_BIND_NO_EXIST.code(), "相机未入库");
  1550. }
  1551. camType = cameraDetail.getType();
  1552. if(camType == 10 || camType == 11){
  1553. cameraType = 14L;//深时或者深光
  1554. }else if(camType == 9){
  1555. cameraType = 13L;//看见
  1556. }else if(camType == 5){
  1557. cameraType = 6L;//圆周率
  1558. }else {
  1559. cameraType = 10L;//看看
  1560. }
  1561. String ryId = null;
  1562. String ryNo = null;
  1563. String password = null;
  1564. String phone = null;
  1565. String idCard = null;
  1566. String jyNo = null;
  1567. String nickName = null;
  1568. String districtCode = null;
  1569. String districtName = null;
  1570. String ryOrgCode = null;
  1571. String ryOrgName = null;
  1572. if(uploadType != null && uploadType.equals("single")){
  1573. String fileId = this.getFileId(snCode, uuid);
  1574. String subFolder = snCode.concat(File.separator).concat(fileId).concat(File.separator).concat(uuid);
  1575. dataSource = ConstantFilePath.BUILD_MODEL_PATH.concat(subFolder);
  1576. log.info("dataSource 为:{}", dataSource);
  1577. JSONObject configJson = JSONObject.parseObject(FileUtils.readFile(sendCallAlgorithmPath.concat(uuid).concat("/config.json")));
  1578. String folderName = configJson.getString("id");
  1579. ryId = configJson.getString("customUserId");
  1580. ryNo = configJson.getString("customUserName");
  1581. // password = AesUtil.encryptCBC(configJson.getString("customUserPwd"), userPasswordKey, userPasswordIv, AesUtil.ALMODE_CBC_NOPADDING);
  1582. password = MD5.create().digestHex(configJson.getString("customUserPwd"));
  1583. if(StrUtil.isBlank(folderName) || StrUtil.isBlank(snCode)){
  1584. throw new RuntimeException("config.json 文件有误!");
  1585. }
  1586. }else{
  1587. ryId = sceneOrigBd.getRyId();
  1588. ryNo = sceneOrigBd.getRyId();
  1589. password = sceneOrigBd.getPassword();
  1590. phone = sceneOrigBd.getRyPhone();
  1591. idCard = sceneOrigBd.getRyCid();
  1592. jyNo = sceneOrigBd.getRyNo();
  1593. nickName = sceneOrigBd.getRyName();
  1594. districtCode = sceneOrigBd.getDistrictCode();
  1595. districtName = sceneOrigBd.getDistrictName();
  1596. ryOrgCode = sceneOrigBd.getRyOrgCode();
  1597. ryOrgName = sceneOrigBd.getRyOrgName();
  1598. }
  1599. //调注册用户接口
  1600. Map<String, Object> params = new HashMap<>();
  1601. params.put("ryId", ryId);
  1602. params.put("ryNo", ryNo);
  1603. params.put("password", password);
  1604. params.put("phone", phone);
  1605. params.put("idCard", idCard);
  1606. params.put("jyNo", jyNo);
  1607. params.put("nickName", nickName);
  1608. params.put("districtCode", districtCode);
  1609. params.put("districtName", districtName);
  1610. params.put("ryOrgCode", ryOrgCode);
  1611. params.put("ryOrgName", ryOrgName);
  1612. String url = fdServiceUrl.concat(ApiConstant.URL_ADD_UCENTER_USER);
  1613. ResultData post1 = myClient.post(url, params);
  1614. log.info("---------registerUser result:{}-----------", post1);
  1615. JyUser jyUser = jyUserService.getByRyId(ryId);
  1616. User user = userService.getById(jyUser.getUserId());
  1617. if(Objects.isNull(jyUser)){
  1618. throw new RuntimeException("注册用户失败");
  1619. }
  1620. int rebuild = 0;
  1621. ScenePlus scenePlus = scenePlusService.getByFileId(dataSource);
  1622. if (!ObjectUtils.isEmpty(scenePlus)) {
  1623. log.info("该场景资源已存在,执行补拍逻辑!");
  1624. rebuild = 1;
  1625. sceneNum = scenePlus.getNum();
  1626. }else{
  1627. sceneNum = scene3dNumService.generateSceneNum(cameraDetail.getType());
  1628. }
  1629. buildScenePost(dataSource, fdageData, "V3", cameraType, sceneNum, camera, cameraDetail, rebuild, "", user, ryId, uploadType);
  1630. scenePlus = scenePlusService.getScenePlusByNum(sceneNum);
  1631. if(cameraType == 14){
  1632. fdkkLaserService.saveScene(scenePlus,fdageData,camera,user.getUserName(),rebuild == 1 ? true : false, scenePlus.getPayStatus(), null);
  1633. }
  1634. }catch (Exception e){
  1635. log.error("通知计算报错,uuid:{}", uuid, e);
  1636. if(StrUtil.isNotEmpty(sceneNum)){
  1637. jmgaService.updateSceneFailAndZipLog(sceneNum, "通知计算报错");
  1638. String buildLogPath = String.format(UploadFilePath.BUILD_LOG_PATH, sceneNum);
  1639. String preLogPath = buildLogPath + "noticeBuild-error-" + DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN) + ".log";
  1640. fYunFileService.uploadFile(ExceptionUtil.stacktraceToString(e).getBytes(StandardCharsets.UTF_8), preLogPath);
  1641. jmgaService.sendStatus(sceneNum, "通知计算失败");
  1642. }
  1643. throw e;
  1644. }
  1645. return ResultData.ok();
  1646. }
  1647. @Override
  1648. public ResultData noticeBuild(SendCallAlgorithmDetail detail) throws Exception {
  1649. String unicode = detail.getUuid();
  1650. log.info("通知计算,uuid:{} " + unicode);
  1651. String sceneNum = null;
  1652. try {
  1653. String[] uuidArr = unicode.split("_");
  1654. JSONObject fdageData = JSONObject.parseObject(FileUtils.readFile(sendCallAlgorithmPath.concat(unicode).concat("/data.fdage")));
  1655. OrigFileUploadBatch condition = new OrigFileUploadBatch();
  1656. condition.setUuid(unicode);
  1657. condition.setStatus(0);
  1658. OrigFileUploadBatch origFileUploadBatch = origFileUploadBatchService.getByCondition(condition);
  1659. origFileUploadBatch.setStatus(4);//修改为等待通知计算状态,由定时任务统一分配计算
  1660. origFileUploadBatchService.updateById(origFileUploadBatch);
  1661. redisUtil.del("single:upload:uuid:" + unicode);//删除当前批次缓存,如果场景补拍上传就会创建一个新的批次号
  1662. buildScenePost(dataSource, fdageData, "V3", cameraType, sceneNum, camera, cameraDetail, rebuild, "", user, ryId, uploadType);
  1663. }catch (Exception e){
  1664. log.error("通知计算报错,uuid:{}", uuid, e);
  1665. if(StrUtil.isNotEmpty(sceneNum)){
  1666. jmgaService.updateSceneFailAndZipLog(sceneNum, "通知计算报错");
  1667. String buildLogPath = String.format(UploadFilePath.BUILD_LOG_PATH, sceneNum);
  1668. String preLogPath = buildLogPath + "noticeBuild-error-" + DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN) + ".log";
  1669. fYunFileService.uploadFile(ExceptionUtil.stacktraceToString(e).getBytes(StandardCharsets.UTF_8), preLogPath);
  1670. jmgaService.sendStatus(sceneNum, "通知计算失败");
  1671. }
  1672. throw e;
  1673. }
  1674. return ResultData.ok();
  1675. }
  1676. @Override
  1677. public String getFileId(String snCode, String uuid){
  1678. // 检测是否有生成
  1679. String fileId = null;
  1680. SceneFileBuild sceneFileBuild = this.findByUnicode(uuid);
  1681. if(Objects.nonNull(sceneFileBuild)){
  1682. fileId = sceneFileBuild.getFileId();
  1683. return fileId;
  1684. }
  1685. fileId = new SnowflakeIdGenerator(0, 0).nextId() + "";
  1686. log.info("新场景,fileid:{}", fileId);
  1687. sceneFileBuild = new SceneFileBuild();
  1688. sceneFileBuild.setChildName(snCode);
  1689. sceneFileBuild.setFileId(fileId);
  1690. sceneFileBuild.setRecStatus("A");
  1691. sceneFileBuild.setUnicode(uuid);
  1692. sceneFileBuild.setCreateTime(new Date());
  1693. this.save(sceneFileBuild);
  1694. return fileId;
  1695. }
  1696. }