|
@@ -0,0 +1,253 @@
|
|
|
+package com.fdkankan.contro.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.lang.UUID;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.fdkankan.common.constant.CommonStatus;
|
|
|
+import com.fdkankan.common.constant.ErrorCode;
|
|
|
+import com.fdkankan.common.constant.SceneSource;
|
|
|
+import com.fdkankan.common.exception.BusinessException;
|
|
|
+import com.fdkankan.common.util.AesUtil;
|
|
|
+import com.fdkankan.common.util.FileUtils;
|
|
|
+import com.fdkankan.contro.bean.SendCallAlgorithmDetail;
|
|
|
+import com.fdkankan.contro.constant.ApiConstant;
|
|
|
+import com.fdkankan.contro.entity.*;
|
|
|
+import com.fdkankan.contro.enums.CameraTypeEnum;
|
|
|
+import com.fdkankan.contro.httpclient.MyClient;
|
|
|
+import com.fdkankan.contro.service.*;
|
|
|
+import com.fdkankan.contro.util.HttpUtilExt;
|
|
|
+import com.fdkankan.contro.vo.SendCallAlgorithmParam;
|
|
|
+import com.fdkankan.fyun.config.FYunFileConfig;
|
|
|
+import com.fdkankan.model.constants.ConstantFilePath;
|
|
|
+import com.fdkankan.rabbitmq.util.RabbitMqProducer;
|
|
|
+import com.fdkankan.redis.util.RedisLockUtil;
|
|
|
+import com.fdkankan.redis.util.RedisUtil;
|
|
|
+import com.fdkankan.web.response.ResultData;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.io.File;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class UploadShootingServiceImpl implements UploadShootingService {
|
|
|
+
|
|
|
+ @Value("${4dkk.fdService.basePath}")
|
|
|
+ private String fdServiceUrl;
|
|
|
+ @Value("${user.password.key:0000000856753656}")
|
|
|
+ private String userPasswordKey;
|
|
|
+ @Value("${user.password.iv:pwel781esd6wglxm}")
|
|
|
+ private String userPasswordIv;
|
|
|
+ @Value("${scene.pro.new.url}")
|
|
|
+ private String sceneProNewUrl;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private RedisLockUtil redisLockUtil;
|
|
|
+ @Resource
|
|
|
+ private RedisUtil redisUtil;
|
|
|
+ @Autowired
|
|
|
+ private IOrigFileUploadBatchService origFileUploadBatchService;
|
|
|
+ @Autowired
|
|
|
+ private IOrigFileUploadService origFileUploadService;
|
|
|
+ @Resource
|
|
|
+ private MyClient myClient;
|
|
|
+ @Autowired
|
|
|
+ private IJyUserService jyUserService;
|
|
|
+ @Autowired
|
|
|
+ private IUserService userService;
|
|
|
+ @Autowired
|
|
|
+ private ISceneFileBuildService sceneFileBuildService;
|
|
|
+ @Autowired
|
|
|
+ private IScenePlusService scenePlusService;
|
|
|
+ @Autowired
|
|
|
+ private IScene3dNumService scene3dNumService;
|
|
|
+ @Autowired
|
|
|
+ private FYunFileConfig fYunFileConfig;
|
|
|
+ @Autowired
|
|
|
+ private IScenePlusExtService scenePlusExtService;
|
|
|
+ @Autowired
|
|
|
+ private ISceneEditInfoService sceneEditInfoService;
|
|
|
+ @Autowired
|
|
|
+ private ISceneEditInfoExtService sceneEditInfoExtService;
|
|
|
+ @Autowired
|
|
|
+ private ISceneEditControlsService sceneEditControlsService;
|
|
|
+ @Autowired
|
|
|
+ private RabbitMqProducer mqProducer;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void uploadFile(SendCallAlgorithmParam param) throws InterruptedException {
|
|
|
+ SendCallAlgorithmDetail details = param.getDetails();
|
|
|
+ if (details.getIndex() == null) {
|
|
|
+ throw new BusinessException(ErrorCode.PARAM_REQUIRED.code(), "index不能为空");
|
|
|
+ }
|
|
|
+ String uuid = details.getUuid();
|
|
|
+
|
|
|
+ boolean lock = redisLockUtil.lock("lock:uploadshooting:upload:uuid:" + uuid, uuid, 1);
|
|
|
+ if (!lock) {//如果拿不到锁,证明
|
|
|
+ Thread.sleep(2000L);
|
|
|
+ }
|
|
|
+
|
|
|
+ String batchId = redisUtil.get("uploadshooting:upload:uuid:" + uuid);
|
|
|
+ if (StrUtil.isEmpty(batchId)) {
|
|
|
+ OrigFileUploadBatch condition = new OrigFileUploadBatch();
|
|
|
+ condition.setUuid(uuid);
|
|
|
+ condition.setStatus(0);
|
|
|
+ condition.setPtIndex(details.getIndex());
|
|
|
+ condition.setCallType(2);
|
|
|
+ OrigFileUploadBatch origFileUploadBatch = origFileUploadBatchService.getByCondition(condition);
|
|
|
+ if (Objects.isNull(origFileUploadBatch)) {
|
|
|
+ batchId = redisUtil.get("uploadshooting:upload:uuid:" + uuid);
|
|
|
+ if (StrUtil.isEmpty(batchId)) {
|
|
|
+ batchId = UUID.fastUUID().toString().replace("-", "");
|
|
|
+ redisUtil.set("uploadshooting:upload:uuid:" + uuid, batchId);
|
|
|
+ origFileUploadBatch = new OrigFileUploadBatch();
|
|
|
+ origFileUploadBatch.setUuid(uuid);
|
|
|
+ origFileUploadBatch.setBatchId(batchId);
|
|
|
+ origFileUploadBatch.setCallType(2);
|
|
|
+ origFileUploadBatch.setPtIndex(details.getIndex());
|
|
|
+ origFileUploadBatchService.save(origFileUploadBatch);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //插入上传明细表
|
|
|
+ OrigFileUpload origFileUpload = new OrigFileUpload();
|
|
|
+ origFileUpload.setFileUrl(param.getFilepath());
|
|
|
+ origFileUpload.setFileName(details.getFileName());
|
|
|
+ origFileUpload.setBatchId(batchId);
|
|
|
+ origFileUploadService.save(origFileUpload);
|
|
|
+
|
|
|
+ if (lock) {
|
|
|
+ redisLockUtil.unlockLua("lock:single:upload:uuid:" + uuid, uuid);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void build(SendCallAlgorithmDetail detail) throws Exception {
|
|
|
+
|
|
|
+ OrigFileUploadBatch condition = new OrigFileUploadBatch();
|
|
|
+ condition.setUuid(detail.getUuid());
|
|
|
+ condition.setStatus(0);
|
|
|
+ condition.setPtIndex(detail.getIndex());
|
|
|
+ condition.setCallType(2);
|
|
|
+ OrigFileUploadBatch origFileUploadBatch = origFileUploadBatchService.getByCondition(condition);
|
|
|
+
|
|
|
+ OrigFileUpload origFileUpload = origFileUploadService.getByBatchIdAndFileName(origFileUploadBatch.getBatchId(), "config.json");
|
|
|
+ String localPath = ConstantFilePath.BUILD_MODEL_PATH + "upload_while_shooting/" + detail.getUuid() + "/" + detail.getIndex() + "/" + detail.getFileName();
|
|
|
+ HttpUtilExt.downloadFileAndCheck(origFileUpload.getFileUrl(), localPath, 300000);
|
|
|
+
|
|
|
+ //入库相机
|
|
|
+ String[] uuidArr = detail.getUuid().split("_");
|
|
|
+ String snCode = uuidArr[0];
|
|
|
+ JSONObject configJson = JSONObject.parseObject(FileUtils.readUtf8String(localPath));
|
|
|
+ int camType = configJson.getInteger("cameraType");
|
|
|
+ String cameraInStoreUrl = fdServiceUrl + ApiConstant.URL_CAMERA_INSTORE;
|
|
|
+ Map<String, Object> cameraInStoreParams = new HashMap<>();
|
|
|
+ cameraInStoreParams.put("cameraType", camType);
|
|
|
+ cameraInStoreParams.put("snCode", snCode);
|
|
|
+ ResultData post = myClient.post(cameraInStoreUrl, cameraInStoreParams);
|
|
|
+ log.info("---------cameraInStore result:{}-----------", post);
|
|
|
+
|
|
|
+ //注册用户
|
|
|
+ String folderName = configJson.getString("id");
|
|
|
+ String customUserId = configJson.getString("customUserId");
|
|
|
+ String customUserName = configJson.getString("customUserName");
|
|
|
+ String customUserPwd = configJson.getString("customUserPwd");
|
|
|
+ if (StrUtil.isBlank(folderName) || StrUtil.isBlank(snCode)) {
|
|
|
+ throw new RuntimeException("config.json 文件有误!");
|
|
|
+ }
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ params.put("ryId", customUserId);
|
|
|
+ params.put("ryNo", customUserName);
|
|
|
+// params.put("nickName", customUserName);//去掉昵称,又燕海的接口进行判断
|
|
|
+ params.put("password", AesUtil.encryptCBC(customUserPwd, userPasswordKey, userPasswordIv, AesUtil.ALMODE_CBC_NOPADDING));
|
|
|
+ String url = fdServiceUrl.concat(ApiConstant.URL_ADD_UCENTER_USER);
|
|
|
+ myClient.post(url, params);
|
|
|
+ JyUser jyUser = jyUserService.getByRyId(customUserId);
|
|
|
+ User user = userService.getById(jyUser.getUserId());
|
|
|
+ if (Objects.isNull(jyUser)) {
|
|
|
+ throw new RuntimeException("注册用户失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ //生成场景表
|
|
|
+ String sceneNum = null;
|
|
|
+ String fileId = sceneFileBuildService.getFileId(snCode, detail.getUuid());
|
|
|
+ String subFolder = snCode.concat(File.separator).concat(fileId).concat(File.separator).concat(detail.getUuid());
|
|
|
+ String dataSource = ConstantFilePath.BUILD_MODEL_PATH.concat(subFolder);
|
|
|
+ ScenePlus scenePlus = scenePlusService.getByFileId(dataSource);
|
|
|
+ ScenePlusExt scenePlusExt = null;
|
|
|
+ SceneEditInfo sceneEditInfo = null;
|
|
|
+ SceneEditInfoExt sceneEditInfoExt = null;
|
|
|
+ SceneEditControls sceneEditControls = null;
|
|
|
+ if (Objects.nonNull(scenePlus)) {
|
|
|
+ log.info("该场景资源已存在,执行补拍逻辑!");
|
|
|
+ sceneNum = scenePlus.getNum();
|
|
|
+ scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
|
|
|
+ sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
|
|
|
+ sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfo.getId());
|
|
|
+ sceneEditControls = sceneEditControlsService.getBySceneEditId(sceneEditInfo.getId());
|
|
|
+ } else {
|
|
|
+ sceneNum = scene3dNumService.generateSceneNum(camType);
|
|
|
+ scenePlus = new ScenePlus();
|
|
|
+ scenePlusExt = new ScenePlusExt();
|
|
|
+ scenePlus.setNum(sceneNum);
|
|
|
+ scenePlus.setSceneSource(SceneSource.BM.code());
|
|
|
+ if (camType == CameraTypeEnum.DOUBLE_EYE_TURN.getType()) {
|
|
|
+ scenePlus.setSceneSource(SceneSource.ZT.code());
|
|
|
+ }
|
|
|
+ if (camType == CameraTypeEnum.LASER_TURN.getType()) {
|
|
|
+ scenePlus.setSceneSource(SceneSource.JG.code());
|
|
|
+ scenePlusExt.setIsObj(CommonStatus.YES.code());
|
|
|
+ }
|
|
|
+ if (camType == CameraTypeEnum.LASER_SG.getType()) {
|
|
|
+ scenePlus.setSceneSource(SceneSource.SG.code());
|
|
|
+ scenePlusExt.setIsObj(CommonStatus.YES.code());
|
|
|
+ }
|
|
|
+ scenePlusExt.setThumb(fYunFileConfig.getHost() + "/loading/thumb.jpg");
|
|
|
+ if (camType == 5) {//圆周率
|
|
|
+ scenePlus.setThreeCamType("yzl");
|
|
|
+ }
|
|
|
+ sceneEditInfo = new SceneEditInfo();
|
|
|
+ sceneEditInfoExt = new SceneEditInfoExt();
|
|
|
+ sceneEditControls = new SceneEditControls();
|
|
|
+ }
|
|
|
+ String title = configJson.getString("title");
|
|
|
+ scenePlus.setUserId(user.getId());
|
|
|
+ scenePlus.setTitle(title);
|
|
|
+ scenePlus.setPreview(CommonStatus.YES.code());
|
|
|
+ scenePlusService.saveOrUpdate(scenePlus);
|
|
|
+
|
|
|
+ scenePlusExt.setPlusId(scenePlus.getId());
|
|
|
+ scenePlusExt.setWebSite("/" + sceneProNewUrl + sceneNum);
|
|
|
+ scenePlusExtService.saveOrUpdate(scenePlusExt);
|
|
|
+
|
|
|
+ sceneEditInfo.setTitle(scenePlus.getTitle());
|
|
|
+ sceneEditInfo.setScenePlusId(scenePlus.getId());
|
|
|
+ sceneEditInfoService.saveOrUpdate(sceneEditInfo);
|
|
|
+
|
|
|
+ sceneEditInfoExt.setEditInfoId(sceneEditInfo.getId());
|
|
|
+ sceneEditInfoExt.setScenePlusId(scenePlus.getId());
|
|
|
+ sceneEditInfoExtService.saveOrUpdate(sceneEditInfoExt);
|
|
|
+
|
|
|
+ sceneEditControls.setEditInfoId(sceneEditInfo.getId());
|
|
|
+ sceneEditControlsService.saveOrUpdate(sceneEditControls);
|
|
|
+
|
|
|
+ JSONObject preParams = new JSONObject();
|
|
|
+ preParams.put("batchId", origFileUploadBatch.getBatchId());
|
|
|
+ preParams.put("sceneCode", sceneNum);
|
|
|
+ preParams.put("index", detail.getIndex());
|
|
|
+ mqProducer.sendByWorkQueue("preview-scene-pre", preParams);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|