UploadShootingServiceImpl.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. package com.fdkankan.contro.service.impl;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.io.FileUtil;
  4. import cn.hutool.core.lang.UUID;
  5. import cn.hutool.core.util.StrUtil;
  6. import com.alibaba.fastjson.JSON;
  7. import com.alibaba.fastjson.JSONObject;
  8. import com.fdkankan.common.constant.CommonStatus;
  9. import com.fdkankan.common.constant.ErrorCode;
  10. import com.fdkankan.common.constant.PayStatus;
  11. import com.fdkankan.common.constant.SceneSource;
  12. import com.fdkankan.common.exception.BusinessException;
  13. import com.fdkankan.common.util.AesUtil;
  14. import com.fdkankan.common.util.FileUtils;
  15. import com.fdkankan.contro.bean.SendCallAlgorithmDetail;
  16. import com.fdkankan.contro.constant.ApiConstant;
  17. import com.fdkankan.contro.constant.RedisConstants;
  18. import com.fdkankan.contro.entity.*;
  19. import com.fdkankan.contro.enums.CameraTypeEnum;
  20. import com.fdkankan.contro.httpclient.MyClient;
  21. import com.fdkankan.contro.service.*;
  22. import com.fdkankan.contro.util.HttpUtilExt;
  23. import com.fdkankan.contro.vo.SendCallAlgorithmParam;
  24. import com.fdkankan.fyun.config.FYunFileConfig;
  25. import com.fdkankan.model.constants.ConstantFilePath;
  26. import com.fdkankan.rabbitmq.util.RabbitMqProducer;
  27. import com.fdkankan.redis.util.RedisLockUtil;
  28. import com.fdkankan.redis.util.RedisUtil;
  29. import com.fdkankan.web.response.ResultData;
  30. import lombok.extern.slf4j.Slf4j;
  31. import org.springframework.beans.factory.annotation.Autowired;
  32. import org.springframework.beans.factory.annotation.Value;
  33. import org.springframework.stereotype.Service;
  34. import javax.annotation.Resource;
  35. import java.io.File;
  36. import java.util.*;
  37. import java.util.stream.Collectors;
  38. @Slf4j
  39. @Service
  40. public class UploadShootingServiceImpl implements UploadShootingService {
  41. @Value("${4dkk.fdService.basePath}")
  42. private String fdServiceUrl;
  43. @Value("${user.password.key:0000000856753656}")
  44. private String userPasswordKey;
  45. @Value("${user.password.iv:pwel781esd6wglxm}")
  46. private String userPasswordIv;
  47. @Value("${scene.pro.preview.url}")
  48. private String sceneProPreviewUrl;
  49. @Resource
  50. private RedisLockUtil redisLockUtil;
  51. @Resource
  52. private RedisUtil redisUtil;
  53. @Autowired
  54. private IOrigFileUploadBatchService origFileUploadBatchService;
  55. @Autowired
  56. private IOrigFileUploadService origFileUploadService;
  57. @Resource
  58. private MyClient myClient;
  59. @Autowired
  60. private IJyUserService jyUserService;
  61. @Autowired
  62. private IUserService userService;
  63. @Autowired
  64. private ISceneFileBuildService sceneFileBuildService;
  65. @Autowired
  66. private IScenePlusService scenePlusService;
  67. @Autowired
  68. private IScene3dNumService scene3dNumService;
  69. @Autowired
  70. private FYunFileConfig fYunFileConfig;
  71. @Autowired
  72. private IScenePlusExtService scenePlusExtService;
  73. @Autowired
  74. private ISceneEditInfoService sceneEditInfoService;
  75. @Autowired
  76. private ISceneEditInfoExtService sceneEditInfoExtService;
  77. @Autowired
  78. private ISceneEditControlsService sceneEditControlsService;
  79. @Autowired
  80. private RabbitMqProducer mqProducer;
  81. @Autowired
  82. private IFdkkLaserService fdkkLaserService;
  83. @Autowired
  84. private ICameraService cameraService;
  85. @Override
  86. public void uploadFile(SendCallAlgorithmParam param) throws InterruptedException {
  87. SendCallAlgorithmDetail details = param.getDetails();
  88. if (details.getIndex() == null) {
  89. throw new BusinessException(ErrorCode.PARAM_REQUIRED.code(), "index不能为空");
  90. }
  91. String uuid = details.getUuid();
  92. String lockKey = RedisConstants.LOCK_UPLOAD_SHOOTING.replace("@uuid@", details.getUuid()).replace("@index@", String.valueOf(details.getIndex()));
  93. boolean lock = redisLockUtil.lock(lockKey, uuid, 2000);
  94. if (!lock) {//如果拿不到锁,证明
  95. Thread.sleep(2000L);
  96. }
  97. String batchKey = RedisConstants.BATCH_ID_UPLOAD_SHOOTING.replace("@uuid@", details.getUuid()).replace("@index@", String.valueOf(details.getIndex()));
  98. String batchId = redisUtil.get(batchKey);
  99. if (StrUtil.isEmpty(batchId)) {
  100. OrigFileUploadBatch condition = new OrigFileUploadBatch();
  101. condition.setUuid(uuid);
  102. condition.setStatus(0);
  103. condition.setPtIndex(details.getIndex());
  104. condition.setCallType(2);
  105. OrigFileUploadBatch origFileUploadBatch = origFileUploadBatchService.getByCondition(condition);
  106. if (Objects.isNull(origFileUploadBatch)) {
  107. batchId = redisUtil.get(batchKey);
  108. if (StrUtil.isEmpty(batchId)) {
  109. batchId = UUID.fastUUID().toString().replace("-", "");
  110. redisUtil.set(batchKey, batchId);
  111. origFileUploadBatch = new OrigFileUploadBatch();
  112. origFileUploadBatch.setUuid(uuid);
  113. origFileUploadBatch.setBatchId(batchId);
  114. origFileUploadBatch.setCallType(2);
  115. origFileUploadBatch.setPtIndex(details.getIndex());
  116. origFileUploadBatchService.save(origFileUploadBatch);
  117. }
  118. }
  119. }
  120. //插入上传明细表
  121. OrigFileUpload origFileUpload = new OrigFileUpload();
  122. origFileUpload.setFileUrl(param.getFilepath());
  123. origFileUpload.setFileName(details.getFileName());
  124. origFileUpload.setBatchId(batchId);
  125. origFileUploadService.save(origFileUpload);
  126. if (lock) {
  127. redisLockUtil.unlockLua(lockKey, uuid);
  128. }
  129. }
  130. @Override
  131. public void build(SendCallAlgorithmDetail detail) throws Exception {
  132. //有点位数据的时候,app会传index,所以这里置空
  133. if(detail.getIndex() != null && detail.getIndex() != -1){
  134. detail.setIndex(null);
  135. }
  136. OrigFileUploadBatch condition = new OrigFileUploadBatch();
  137. condition.setUuid(detail.getUuid());
  138. condition.setStatus(0);
  139. condition.setPtIndex(detail.getIndex());
  140. List<OrigFileUploadBatch> batches = origFileUploadBatchService.listPreviewByCondition(condition);
  141. if(CollUtil.isEmpty(batches)){
  142. return;
  143. }
  144. String[] uuidArr = detail.getUuid().split("_");
  145. String snCode = uuidArr[0];
  146. Integer camType = null;
  147. User user = null;
  148. OrigFileUpload dataFdageFileUpload = origFileUploadService.getLastByFileName("data.fdage");
  149. String dataFdageLocalPath = ConstantFilePath.BUILD_MODEL_PATH + "upload_while_shooting/" + detail.getUuid() + "/data.fdage";
  150. HttpUtilExt.downloadFileAndCheck(dataFdageFileUpload.getFileUrl(), dataFdageLocalPath, 300000);
  151. JSONObject dataFdage = JSON.parseObject(FileUtil.readUtf8String(dataFdageLocalPath));
  152. String title = dataFdage.getString("name");
  153. OrigFileUploadBatch origFileUploadBatch = batches.get(0);
  154. Camera camera = null;
  155. if(detail.getIndex() == null || detail.getIndex() != -1){
  156. OrigFileUpload origFileUpload = origFileUploadService.getByBatchIdAndFileName(origFileUploadBatch.getBatchId(), "config.json");
  157. String localPath = ConstantFilePath.BUILD_MODEL_PATH + "upload_while_shooting/" + detail.getUuid() + "/" + origFileUploadBatch.getPtIndex() + "/" + detail.getFileName();
  158. HttpUtilExt.downloadFileAndCheck(origFileUpload.getFileUrl(), localPath, 300000);
  159. //入库相机
  160. JSONObject configJson = JSONObject.parseObject(FileUtils.readUtf8String(localPath));
  161. camType = configJson.getInteger("cameraType");
  162. String cameraInStoreUrl = fdServiceUrl + ApiConstant.URL_CAMERA_INSTORE;
  163. Map<String, Object> cameraInStoreParams = new HashMap<>();
  164. cameraInStoreParams.put("cameraType", camType);
  165. cameraInStoreParams.put("snCode", snCode);
  166. ResultData post = myClient.post(cameraInStoreUrl, cameraInStoreParams);
  167. camera = cameraService.getBySnCode(snCode);
  168. log.info("---------cameraInStore result:{}-----------", post);
  169. //注册用户
  170. String folderName = configJson.getString("id");
  171. String customUserId = configJson.getString("customUserId");
  172. String customUserName = configJson.getString("customUserName");
  173. String customUserPwd = configJson.getString("customUserPwd");
  174. if (StrUtil.isBlank(folderName) || StrUtil.isBlank(snCode)) {
  175. throw new RuntimeException("config.json 文件有误!");
  176. }
  177. Map<String, Object> params = new HashMap<>();
  178. params.put("ryId", customUserId);
  179. params.put("ryNo", customUserName);
  180. // params.put("nickName", customUserName);//去掉昵称,又燕海的接口进行判断
  181. params.put("password", AesUtil.encryptCBC(customUserPwd, userPasswordKey, userPasswordIv, AesUtil.ALMODE_CBC_NOPADDING));
  182. String url = fdServiceUrl.concat(ApiConstant.URL_ADD_UCENTER_USER);
  183. myClient.post(url, params);
  184. JyUser jyUser = jyUserService.getByRyId(customUserId);
  185. user = userService.getById(jyUser.getUserId());
  186. if (Objects.isNull(jyUser)) {
  187. throw new RuntimeException("注册用户失败");
  188. }
  189. }
  190. //生成场景表
  191. String sceneNum = null;
  192. String fileId = sceneFileBuildService.getFileId(snCode, detail.getUuid());
  193. String subFolder = snCode.concat(File.separator).concat(fileId).concat(File.separator).concat(detail.getUuid());
  194. String dataSource = ConstantFilePath.BUILD_MODEL_PATH.concat(subFolder);
  195. ScenePlus scenePlus = scenePlusService.getByFileId(dataSource);
  196. ScenePlusExt scenePlusExt = null;
  197. SceneEditInfo sceneEditInfo = null;
  198. SceneEditInfoExt sceneEditInfoExt = null;
  199. SceneEditControls sceneEditControls = null;
  200. if (Objects.nonNull(scenePlus)) {
  201. log.info("该场景资源已存在,执行补拍逻辑!");
  202. sceneNum = scenePlus.getNum();
  203. scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  204. sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
  205. sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfo.getId());
  206. sceneEditControls = sceneEditControlsService.getBySceneEditId(sceneEditInfo.getId());
  207. } else {
  208. sceneNum = scene3dNumService.generateSceneNum(camType);
  209. scenePlus = new ScenePlus();
  210. scenePlusExt = new ScenePlusExt();
  211. scenePlusExt.setDataSource(dataSource);
  212. scenePlus.setNum(sceneNum);
  213. scenePlus.setSceneSource(SceneSource.BM.code());
  214. scenePlus.setCameraId(camera.getId());
  215. scenePlus.setPreview(CommonStatus.YES.code().intValue());
  216. if (camType == CameraTypeEnum.DOUBLE_EYE_TURN.getType()) {
  217. scenePlus.setSceneSource(SceneSource.ZT.code());
  218. }
  219. if (camType == CameraTypeEnum.LASER_TURN.getType()) {
  220. scenePlus.setSceneSource(SceneSource.JG.code());
  221. scenePlusExt.setIsObj(CommonStatus.YES.code().intValue());
  222. }
  223. if (camType == CameraTypeEnum.LASER_SG.getType()) {
  224. scenePlus.setSceneSource(SceneSource.SG.code());
  225. scenePlusExt.setIsObj(CommonStatus.YES.code().intValue());
  226. }
  227. scenePlusExt.setThumb(fYunFileConfig.getHost() + "/loading/thumb.jpg");
  228. if (camType == 5) {//圆周率
  229. scenePlus.setThreeCamType("yzl");
  230. }
  231. sceneEditInfo = new SceneEditInfo();
  232. sceneEditInfoExt = new SceneEditInfoExt();
  233. sceneEditControls = new SceneEditControls();
  234. }
  235. if(Objects.nonNull(user)){
  236. scenePlus.setUserId(user.getId());
  237. }
  238. scenePlus.setTitle(title);
  239. scenePlusService.saveOrUpdate(scenePlus);
  240. scenePlusExt.setPlusId(scenePlus.getId());
  241. scenePlusExt.setWebSite("/" + sceneProPreviewUrl + sceneNum);
  242. scenePlusExtService.saveOrUpdate(scenePlusExt);
  243. sceneEditInfo.setTitle(scenePlus.getTitle());
  244. sceneEditInfo.setScenePlusId(scenePlus.getId());
  245. sceneEditInfoService.saveOrUpdate(sceneEditInfo);
  246. sceneEditInfoExt.setEditInfoId(sceneEditInfo.getId());
  247. sceneEditInfoExt.setScenePlusId(scenePlus.getId());
  248. sceneEditInfoExtService.saveOrUpdate(sceneEditInfoExt);
  249. sceneEditControls.setEditInfoId(sceneEditInfo.getId());
  250. sceneEditControlsService.saveOrUpdate(sceneEditControls);
  251. fdkkLaserService.saveScene(scenePlus, dataFdage, camera, user.getUserName(), false, PayStatus.NOT_PAY.code(), 5);
  252. JSONObject preParams = new JSONObject();
  253. preParams.put("sceneCode", sceneNum);
  254. preParams.put("index", detail.getIndex());
  255. preParams.put("uuid", detail.getUuid());
  256. mqProducer.sendByWorkQueue("preview-scene-pre", preParams);
  257. }
  258. @Override
  259. public boolean checkLackFille(Integer index, List<OrigFileUpload> fileUploadList) {
  260. Set<String> fileNameList = fileUploadList.stream().map(v -> v.getFileName()).collect(Collectors.toSet());
  261. if(!fileNameList.contains(index + ".jpg") || !fileNameList.contains(index + ".json") || !fileNameList.contains(index + "_web.ply")){
  262. return true;
  263. }
  264. return false;
  265. }
  266. }