|
@@ -1,11 +1,15 @@
|
|
|
package com.fdkankan.scene.listener;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.http.HttpStatus;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.fdkankan.common.constant.BuildStatus;
|
|
|
import com.fdkankan.common.constant.ConstantFilePath;
|
|
|
import com.fdkankan.common.constant.ExpiredStatus;
|
|
|
+import com.fdkankan.common.constant.PayStatus;
|
|
|
import com.fdkankan.common.constant.SceneFrom;
|
|
|
import com.fdkankan.common.constant.SceneResolution;
|
|
|
import com.fdkankan.common.constant.SceneSource;
|
|
@@ -13,6 +17,7 @@ import com.fdkankan.common.constant.SceneStatus;
|
|
|
import com.fdkankan.common.constant.ServerCode;
|
|
|
import com.fdkankan.common.constant.UploadFilePath;
|
|
|
import com.fdkankan.common.response.ResultData;
|
|
|
+import com.fdkankan.common.util.FileUtils;
|
|
|
import com.fdkankan.common.util.MatrixToImageWriterUtil;
|
|
|
import com.fdkankan.fyun.oss.UploadToOssUtil;
|
|
|
import com.fdkankan.mq.message.BuildSceneResultMqMessage;
|
|
@@ -23,21 +28,30 @@ import com.fdkankan.platform.api.vo.UserIncrement;
|
|
|
import com.fdkankan.redis.constant.RedisKey;
|
|
|
import com.fdkankan.redis.util.RedisUtil;
|
|
|
import com.fdkankan.scene.bean.SceneJsonBean;
|
|
|
+import com.fdkankan.scene.entity.Scene;
|
|
|
import com.fdkankan.scene.entity.SceneEditControls;
|
|
|
import com.fdkankan.scene.entity.SceneEditInfo;
|
|
|
+import com.fdkankan.scene.entity.SceneExt;
|
|
|
import com.fdkankan.scene.entity.SceneFileBuild;
|
|
|
+import com.fdkankan.scene.entity.ScenePlus;
|
|
|
+import com.fdkankan.scene.entity.ScenePlusExt;
|
|
|
import com.fdkankan.scene.entity.ScenePro;
|
|
|
import com.fdkankan.scene.entity.SceneProExt;
|
|
|
import com.fdkankan.scene.service.IBuildScenePreService;
|
|
|
import com.fdkankan.scene.service.ISceneEditControlsService;
|
|
|
import com.fdkankan.scene.service.ISceneEditInfoService;
|
|
|
import com.fdkankan.scene.service.ISceneFileBuildService;
|
|
|
+import com.fdkankan.scene.service.IScenePlusExtService;
|
|
|
+import com.fdkankan.scene.service.IScenePlusService;
|
|
|
import com.fdkankan.scene.service.ISceneProExtService;
|
|
|
import com.fdkankan.scene.service.ISceneProService;
|
|
|
import com.fdkankan.scene.service.ISceneService;
|
|
|
import com.fdkankan.scene.service.impl.BuildScenePreServiceImpl;
|
|
|
import java.io.File;
|
|
|
+import java.util.Calendar;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.rocketmq.spring.annotation.MessageModel;
|
|
|
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
|
|
@@ -105,6 +119,10 @@ public class BuildSceneResultMQListener implements RocketMQListener<String> {
|
|
|
IBuildScenePreService buildScenePreService;
|
|
|
@Autowired
|
|
|
RedisUtil redisUtil;
|
|
|
+ @Autowired
|
|
|
+ IScenePlusService scenePlusService;
|
|
|
+ @Autowired
|
|
|
+ IScenePlusExtService scenePlusExtService;
|
|
|
|
|
|
|
|
|
@Override
|
|
@@ -132,9 +150,17 @@ public class BuildSceneResultMQListener implements RocketMQListener<String> {
|
|
|
String prefix = message.getPrefix();
|
|
|
try {
|
|
|
if(!buildSuccess){//建模失败,修改状态为失败状态
|
|
|
- log.error("建模失败,修改状态为失败状态");
|
|
|
+ log.info("建模失败,修改状态为失败状态");
|
|
|
+ // TODO: 2022/3/21 plus版本稳定后删除------------------------start
|
|
|
sceneService.updateStatus(sceneCode, SceneStatus.FAILD.code());
|
|
|
sceneProService.updateStatus(sceneCode, SceneStatus.FAILD.code());
|
|
|
+ // TODO: 2022/3/21 plus版本稳定后删除------------------------send
|
|
|
+
|
|
|
+ scenePlusService.update(
|
|
|
+ new LambdaUpdateWrapper<ScenePlus>()
|
|
|
+ .set(ScenePlus::getSceneStatus, SceneStatus.FAILD.code())
|
|
|
+ .eq(ScenePlus::getNum, sceneCode));
|
|
|
+
|
|
|
SceneFileBuild sceneFileBuild = sceneFileBuildService.findByFileId(fileId);
|
|
|
if(Objects.nonNull(sceneFileBuild)){
|
|
|
sceneFileBuild.setBuildStatus(BuildStatus.fail.code());
|
|
@@ -146,10 +172,16 @@ public class BuildSceneResultMQListener implements RocketMQListener<String> {
|
|
|
//建模成功
|
|
|
log.info("cameraType:{}",cameraType);
|
|
|
|
|
|
+ //计算场景消耗磁盘空间
|
|
|
long space = buildScenePreService.calUseSpace(uploadFiles);
|
|
|
|
|
|
if(cameraType < 3){
|
|
|
+ // TODO: 2022/3/21 plus版本稳定后删除------------------------start
|
|
|
sceneService.updateTime(sceneCode, space, payStatus);
|
|
|
+ // TODO: 2022/3/21 plus版本稳定后删除------------------------send
|
|
|
+
|
|
|
+ this.updateDb4Sm(sceneCode, space);
|
|
|
+
|
|
|
uploadToOssUtil.uploadMulFiles(uploadFiles);
|
|
|
return;
|
|
|
}
|
|
@@ -158,9 +190,20 @@ public class BuildSceneResultMQListener implements RocketMQListener<String> {
|
|
|
JSONObject videosJson = buildScenePreService.getVideosJson(path, videoVersion, sceneCode, cameraType);
|
|
|
|
|
|
//写入数据库
|
|
|
- ScenePro scenePro = this.updateDb(sceneCode, space, payStatus, videosJson.toJSONString(), computeTime, fileId);
|
|
|
+ // TODO: 2022/3/21 plus版本稳定后删除------------------------start
|
|
|
+ ScenePro scenePro = this.updateDbPro(sceneCode, space, payStatus, videosJson.toJSONString(), computeTime, fileId);
|
|
|
SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
|
|
|
- Object[] editInfoArr = this.updateEditInfo(scenePro);
|
|
|
+ // TODO: 2022/3/21 plus版本稳定后删除------------------------send
|
|
|
+ ScenePlus scenePlus = this.updateDbPlus(sceneCode, space, payStatus, videosJson.toJSONString(), computeTime, fileId);
|
|
|
+ ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
|
|
|
+
|
|
|
+ //变更容量,arrearCap为true时,代表容量不足
|
|
|
+ boolean arrearCap = this.updateSpace(scenePlus.getCameraId(), space, scenePlus.getId(), scenePro.getId());
|
|
|
+
|
|
|
+ //如果相机容量不足,需要把场景的paystatus改为容量不足状态
|
|
|
+ this.sealScene(arrearCap, scenePlus.getId(), scenePro.getId());
|
|
|
+
|
|
|
+ Object[] editInfoArr = this.updateEditInfo(scenePlus);
|
|
|
SceneEditInfo sceneEditInfo = (SceneEditInfo)editInfoArr[0];
|
|
|
SceneEditControls sceneEditControls = (SceneEditControls)editInfoArr[1];
|
|
|
|
|
@@ -196,7 +239,8 @@ public class BuildSceneResultMQListener implements RocketMQListener<String> {
|
|
|
buildScenePreService.uploadLogFile(sceneCode, sceneProExt.getDataSource());
|
|
|
|
|
|
//写scene.json
|
|
|
- String sceneJson = buildScenePreService.writeSceneJson(sceneCode, videosJson, sceneEditInfo, sceneEditControls, scenePro, sceneProExt);
|
|
|
+ String sceneJson = buildScenePreService.writeSceneJson(sceneCode, videosJson,
|
|
|
+ sceneEditInfo, sceneEditControls, scenePlus, scenePlusExt, arrearCap);
|
|
|
|
|
|
//上传sceneJson文件
|
|
|
String sceneJsonPath = String.format(UploadFilePath.DATA_VIEW_PATH+"scene.json", sceneCode);
|
|
@@ -213,7 +257,59 @@ public class BuildSceneResultMQListener implements RocketMQListener<String> {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private ScenePro updateDb(String sceneCode, Long space, Integer payStatus, String videosJson, Long computeTime, String fileId) throws Exception{
|
|
|
+ private void sealScene(boolean arrearCap, Long scenePlusId, Long sceneProId){
|
|
|
+ if(!arrearCap){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ scenePlusService.update(
|
|
|
+ new LambdaUpdateWrapper<ScenePlus>()
|
|
|
+ .set(ScenePlus::getPayStatus, PayStatus.NO_CAPACITY)
|
|
|
+ .eq(ScenePlus::getId, scenePlusId));
|
|
|
+
|
|
|
+
|
|
|
+ // TODO: 2022/3/22 plus版本稳定后删除---------------------------start
|
|
|
+ sceneProService.update(
|
|
|
+ new LambdaUpdateWrapper<ScenePro>()
|
|
|
+ .set(ScenePro::getPayStatus, PayStatus.NO_CAPACITY)
|
|
|
+ .eq(ScenePro::getId, sceneProId));
|
|
|
+ // TODO: 2022/3/22 plus版本稳定后删除---------------------------end
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * <p>
|
|
|
+ 双目场景更新数据库
|
|
|
+ * </p>
|
|
|
+ * @author dengsixing
|
|
|
+ * @date 2022/3/21
|
|
|
+ * @param num
|
|
|
+ * @param space
|
|
|
+ **/
|
|
|
+ private void updateDb4Sm(String num, long space){
|
|
|
+ List<ScenePlus> ScenePlusList = scenePlusService.list(
|
|
|
+ new LambdaQueryWrapper<ScenePlus>()
|
|
|
+ .select(ScenePlus::getId)
|
|
|
+ .eq(ScenePlus::getNum, num));
|
|
|
+
|
|
|
+ if(CollUtil.isNotEmpty(ScenePlusList))
|
|
|
+ return ;
|
|
|
+ List<Long> sceneIds = ScenePlusList.stream().map(scene -> {
|
|
|
+ return scene.getId();
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ //更新场景创建时间
|
|
|
+ scenePlusService.update(new LambdaUpdateWrapper<ScenePlus>()
|
|
|
+ .in(ScenePlus::getId, sceneIds)
|
|
|
+ .set(ScenePlus::getCreateTime, Calendar.getInstance().getTime())
|
|
|
+ .set(ScenePlus::getSceneStatus, SceneStatus.NO_DISPLAY.code()));
|
|
|
+
|
|
|
+ //更新使用容量
|
|
|
+ scenePlusExtService.update(
|
|
|
+ new LambdaUpdateWrapper<ScenePlusExt>()
|
|
|
+ .in(ScenePlusExt::getPlusId, sceneIds)
|
|
|
+ .set(ScenePlusExt::getSpace, space));
|
|
|
+ }
|
|
|
+
|
|
|
+ private ScenePro updateDbPro(String sceneCode, Long space, Integer payStatus, String videosJson, Long computeTime, String fileId) throws Exception{
|
|
|
ScenePro scenePro = sceneProService.findBySceneNum(sceneCode);
|
|
|
|
|
|
sceneProService.updateTime(sceneCode, space, payStatus, videosJson, computeTime);
|
|
@@ -225,27 +321,6 @@ public class BuildSceneResultMQListener implements RocketMQListener<String> {
|
|
|
|
|
|
if(Objects.nonNull(scenePro)){
|
|
|
SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
|
|
|
- ResultData<CameraDetail> resultData = platformGoodsClient.updateCameraDetailByCameraIdAndSpace(scenePro.getCameraId(), sceneProExt.getSpace());
|
|
|
- if(resultData.getCode() != ServerCode.SUCCESS.code()){
|
|
|
- log.error("调用platform服务updateCameraDetailByCameraIdAndSpace失败,参数{},{}" ,scenePro.getCameraId(), sceneProExt.getSpace());
|
|
|
- throw new Exception(ServerCode.FEIGN_REQUEST_FAILD.message());
|
|
|
- }
|
|
|
- CameraDetail cameraDetail = JSONObject.parseObject(JSONObject.toJSONString(resultData.getData()), CameraDetail.class);
|
|
|
-
|
|
|
- ResultData<UserIncrement> resultData1 = platformUserClient.getUserIncrementByCameraId(scenePro.getCameraId());
|
|
|
- if(resultData1.getCode() != ServerCode.SUCCESS.code()){
|
|
|
- log.error("调用platform服务getUserIncrementByCameraId失败,参数{}" ,scenePro.getCameraId());
|
|
|
- throw new Exception(ServerCode.FEIGN_REQUEST_FAILD.message());
|
|
|
- }
|
|
|
- if( resultData1.getData() == null || resultData1.getData().getIsExpired() == ExpiredStatus.Expired.code()) {
|
|
|
- // 新上传的场景,如果总容量小于使用容量,则该大场景保留在临时存储空间30天
|
|
|
- if (cameraDetail.getTotalSpace().compareTo(cameraDetail.getUsedSpace()) == -1){
|
|
|
- List<Long> ids = new ArrayList<>();
|
|
|
- ids.add(scenePro.getId());
|
|
|
- sceneProService.tempScenes(ids);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
SceneSource sceneSource = SceneSource.get(sceneProExt.getSceneSource());
|
|
|
switch (sceneSource){
|
|
|
case BM:
|
|
@@ -272,14 +347,95 @@ public class BuildSceneResultMQListener implements RocketMQListener<String> {
|
|
|
return scenePro;
|
|
|
}
|
|
|
|
|
|
- private Object[] updateEditInfo(ScenePro scenePro){
|
|
|
- SceneEditInfo sceneEditInfo = sceneEditInfoService.getBySceneProId(scenePro.getId());
|
|
|
+ private ScenePlus updateDbPlus(String num, Long space, Integer payStatus, String videosJson, Long computeTime, String fileId) throws Exception{
|
|
|
+ ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
|
|
|
+ ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
|
|
|
+ List<ScenePlus> list = scenePlusService.list(
|
|
|
+ new LambdaQueryWrapper<ScenePlus>()
|
|
|
+ .select(ScenePlus::getId)
|
|
|
+ .eq(ScenePlus::getNum, num));
|
|
|
+ if(scenePlus == null || CollUtil.isEmpty(list))
|
|
|
+ return null;
|
|
|
+
|
|
|
+ //修改场景状态 空间 支付状态 计算时间
|
|
|
+ List<Long> scenePlusIds = list.stream().map(plus -> {
|
|
|
+ return plus.getId();
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ scenePlusService.update(new LambdaUpdateWrapper<ScenePlus>()
|
|
|
+ .in(ScenePlus::getId, scenePlusIds)
|
|
|
+ .set(ScenePlus::getSceneStatus, SceneStatus.NO_DISPLAY.code())
|
|
|
+ .set(ScenePlus::getCreateTime, Calendar.getInstance().getTime())
|
|
|
+ .set(ScenePlus::getPayStatus, payStatus));
|
|
|
+
|
|
|
+ scenePlusExtService.update(new LambdaUpdateWrapper<ScenePlusExt>()
|
|
|
+ .in(ScenePlusExt::getPlusId, scenePlusIds)
|
|
|
+ .set(ScenePlusExt::getSpace, space)
|
|
|
+ .set(ScenePlusExt::getComputeTime, computeTime)
|
|
|
+ .set(ScenePlusExt::getVideos, videosJson));
|
|
|
+
|
|
|
+ SceneFileBuild sceneFileBuild = sceneFileBuildService.findByFileId(fileId);
|
|
|
+ if(sceneFileBuild != null){
|
|
|
+ sceneFileBuild.setBuildStatus(BuildStatus.success.code());
|
|
|
+ sceneFileBuildService.updateById(sceneFileBuild);
|
|
|
+ }
|
|
|
+
|
|
|
+ SceneSource sceneSource = SceneSource.get(scenePlus.getSceneSource());
|
|
|
+ switch (sceneSource){
|
|
|
+ case BM:
|
|
|
+ scenePlusExt.setSceneResolution(SceneResolution.TILES_2K.code());
|
|
|
+ scenePlusExt.setSceneFrom(SceneFrom.PRO.code());
|
|
|
+ break;
|
|
|
+ case SM:
|
|
|
+ scenePlusExt.setSceneResolution(SceneResolution.TILES_1K.code());
|
|
|
+ scenePlusExt.setSceneFrom(SceneFrom.LITE.code());
|
|
|
+ break;
|
|
|
+ case ZT:
|
|
|
+ scenePlusExt.setSceneResolution(SceneResolution.TILES_4K.code());
|
|
|
+ scenePlusExt.setSceneFrom(SceneFrom.MINION.code());
|
|
|
+ break;
|
|
|
+ case JG:
|
|
|
+ scenePlusExt.setSceneResolution(SceneResolution.TILES_4K.code());
|
|
|
+ scenePlusExt.setSceneFrom(SceneFrom.LASER.code());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ scenePlusExtService.updateById(scenePlusExt);
|
|
|
+
|
|
|
+
|
|
|
+ return scenePlus;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean updateSpace(Long cameraId, Long space, Long scenePlusId, Long sceneProId) throws Exception{
|
|
|
+ //更新相机使用用量
|
|
|
+ ResultData<CameraDetail> resultData = platformGoodsClient.updateCameraDetailByCameraIdAndSpace(cameraId, space);
|
|
|
+ if(resultData.getCode() != ServerCode.SUCCESS.code()){
|
|
|
+ log.error("调用platform服务updateCameraDetailByCameraIdAndSpace失败,参数{},{}" ,cameraId, space);
|
|
|
+ throw new Exception(ServerCode.FEIGN_REQUEST_FAILD.message());
|
|
|
+ }
|
|
|
+ CameraDetail cameraDetail = JSONObject.parseObject(JSONObject.toJSONString(resultData.getData()), CameraDetail.class);
|
|
|
+
|
|
|
+ ResultData<UserIncrement> resultData1 = platformUserClient.getUserIncrementByCameraId(cameraId);
|
|
|
+ if(resultData1.getCode() != ServerCode.SUCCESS.code()){
|
|
|
+ log.error("调用platform服务getUserIncrementByCameraId失败,参数{}" ,cameraId);
|
|
|
+ throw new Exception(ServerCode.FEIGN_REQUEST_FAILD.message());
|
|
|
+ }
|
|
|
+ if( resultData1.getData() == null || resultData1.getData().getIsExpired() == ExpiredStatus.Expired.code()) {
|
|
|
+ // 新上传的场景,如果总容量小于使用容量,则该大场景保留在临时存储空间30天
|
|
|
+ if (cameraDetail.getTotalSpace().compareTo(cameraDetail.getUsedSpace()) == -1){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Object[] updateEditInfo(ScenePlus scenePlus){
|
|
|
+ SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
|
|
|
SceneEditControls sceneEditControls = null;
|
|
|
if(sceneEditInfo == null){
|
|
|
sceneEditInfo = new SceneEditInfo();
|
|
|
- sceneEditInfo.setSceneProId(scenePro.getId());
|
|
|
- sceneEditInfo.setDescription(scenePro.getSceneDec());
|
|
|
- sceneEditInfo.setTitle(scenePro.getSceneName());
|
|
|
+ sceneEditInfo.setSceneProId(scenePlus.getId());
|
|
|
+ sceneEditInfo.setDescription(scenePlus.getDescription());
|
|
|
+ sceneEditInfo.setTitle(scenePlus.getTitle());
|
|
|
sceneEditInfoService.save(sceneEditInfo);
|
|
|
}else{
|
|
|
sceneEditControls = sceneEditControlsService.getBySceneEditId(sceneEditInfo.getId());
|