| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- package com.fdkankan.contro.service.impl;
- import cn.hutool.core.collection.CollUtil;
- import cn.hutool.core.io.FileUtil;
- import cn.hutool.core.lang.UUID;
- import cn.hutool.core.util.StrUtil;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONObject;
- import com.fdkankan.common.constant.CommonStatus;
- import com.fdkankan.common.constant.ErrorCode;
- import com.fdkankan.common.constant.PayStatus;
- 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.constant.RedisConstants;
- 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.*;
- import java.util.stream.Collectors;
- @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.preview.url}")
- private String sceneProPreviewUrl;
- @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;
- @Autowired
- private IFdkkLaserService fdkkLaserService;
- @Autowired
- private ICameraService cameraService;
- @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();
- String lockKey = RedisConstants.LOCK_UPLOAD_SHOOTING.replace("@uuid@", details.getUuid()).replace("@index@", String.valueOf(details.getIndex()));
- boolean lock = redisLockUtil.lock(lockKey, uuid, 2000);
- if (!lock) {//如果拿不到锁,证明
- Thread.sleep(2000L);
- }
- String batchKey = RedisConstants.BATCH_ID_UPLOAD_SHOOTING.replace("@uuid@", details.getUuid()).replace("@index@", String.valueOf(details.getIndex()));
- String batchId = redisUtil.get(batchKey);
- 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(batchKey);
- if (StrUtil.isEmpty(batchId)) {
- batchId = UUID.fastUUID().toString().replace("-", "");
- redisUtil.set(batchKey, 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(lockKey, uuid);
- }
- }
- @Override
- public void build(SendCallAlgorithmDetail detail) throws Exception {
- //有点位数据的时候,app会传index,所以这里置空
- if(detail.getIndex() != null && detail.getIndex() != -1){
- detail.setIndex(null);
- }
- OrigFileUploadBatch condition = new OrigFileUploadBatch();
- condition.setUuid(detail.getUuid());
- condition.setStatus(0);
- condition.setPtIndex(detail.getIndex());
- List<OrigFileUploadBatch> batches = origFileUploadBatchService.listPreviewByCondition(condition);
- if(CollUtil.isEmpty(batches)){
- return;
- }
- String[] uuidArr = detail.getUuid().split("_");
- String snCode = uuidArr[0];
- Integer camType = null;
- User user = null;
- OrigFileUpload dataFdageFileUpload = origFileUploadService.getLastByFileName("data.fdage");
- String dataFdageLocalPath = ConstantFilePath.BUILD_MODEL_PATH + "upload_while_shooting/" + detail.getUuid() + "/data.fdage";
- HttpUtilExt.downloadFileAndCheck(dataFdageFileUpload.getFileUrl(), dataFdageLocalPath, 300000);
- JSONObject dataFdage = JSON.parseObject(FileUtil.readUtf8String(dataFdageLocalPath));
- String title = dataFdage.getString("name");
- OrigFileUploadBatch origFileUploadBatch = batches.get(0);
- Camera camera = null;
- if(detail.getIndex() == null || detail.getIndex() != -1){
- OrigFileUpload origFileUpload = origFileUploadService.getByBatchIdAndFileName(origFileUploadBatch.getBatchId(), "config.json");
- String localPath = ConstantFilePath.BUILD_MODEL_PATH + "upload_while_shooting/" + detail.getUuid() + "/" + origFileUploadBatch.getPtIndex() + "/" + detail.getFileName();
- HttpUtilExt.downloadFileAndCheck(origFileUpload.getFileUrl(), localPath, 300000);
- //入库相机
- JSONObject configJson = JSONObject.parseObject(FileUtils.readUtf8String(localPath));
- 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);
- camera = cameraService.getBySnCode(snCode);
- 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 = 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();
- scenePlusExt.setDataSource(dataSource);
- scenePlus.setNum(sceneNum);
- scenePlus.setSceneSource(SceneSource.BM.code());
- scenePlus.setCameraId(camera.getId());
- scenePlus.setPreview(CommonStatus.YES.code().intValue());
- 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().intValue());
- }
- if (camType == CameraTypeEnum.LASER_SG.getType()) {
- scenePlus.setSceneSource(SceneSource.SG.code());
- scenePlusExt.setIsObj(CommonStatus.YES.code().intValue());
- }
- scenePlusExt.setThumb(fYunFileConfig.getHost() + "/loading/thumb.jpg");
- if (camType == 5) {//圆周率
- scenePlus.setThreeCamType("yzl");
- }
- sceneEditInfo = new SceneEditInfo();
- sceneEditInfoExt = new SceneEditInfoExt();
- sceneEditControls = new SceneEditControls();
- }
- if(Objects.nonNull(user)){
- scenePlus.setUserId(user.getId());
- }
- scenePlus.setTitle(title);
- scenePlusService.saveOrUpdate(scenePlus);
- scenePlusExt.setPlusId(scenePlus.getId());
- scenePlusExt.setWebSite("/" + sceneProPreviewUrl + 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);
- fdkkLaserService.saveScene(scenePlus, dataFdage, camera, user.getUserName(), false, PayStatus.NOT_PAY.code(), 5);
- JSONObject preParams = new JSONObject();
- preParams.put("sceneCode", sceneNum);
- preParams.put("index", detail.getIndex());
- preParams.put("uuid", detail.getUuid());
- mqProducer.sendByWorkQueue("preview-scene-pre", preParams);
- }
- @Override
- public boolean checkLackFille(Integer index, List<OrigFileUpload> fileUploadList) {
- Set<String> fileNameList = fileUploadList.stream().map(v -> v.getFileName()).collect(Collectors.toSet());
- if(!fileNameList.contains(index + ".jpg") || !fileNameList.contains(index + ".json") || !fileNameList.contains(index + "_web.ply")){
- return true;
- }
- return false;
- }
- }
|