|
@@ -0,0 +1,149 @@
|
|
|
|
+package com.fdkankan.ucenter.service.impl;
|
|
|
|
+
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
+import com.fdkankan.common.constant.ErrorCode;
|
|
|
|
+import com.fdkankan.common.constant.SceneKind;
|
|
|
|
+import com.fdkankan.common.constant.SceneResolution;
|
|
|
|
+import com.fdkankan.common.response.ResultData;
|
|
|
|
+import com.fdkankan.fyun.oss.UploadToOssUtil;
|
|
|
|
+import com.fdkankan.rabbitmq.util.RabbitMqProducer;
|
|
|
|
+import com.fdkankan.redis.constant.RedisKey;
|
|
|
|
+import com.fdkankan.redis.constant.RedisLockKey;
|
|
|
|
+import com.fdkankan.redis.util.RedisLockUtil;
|
|
|
|
+import com.fdkankan.redis.util.RedisUtil;
|
|
|
|
+import com.fdkankan.ucenter.bean.SceneUpgradeProgressBean;
|
|
|
|
+import com.fdkankan.ucenter.common.Result;
|
|
|
|
+import com.fdkankan.ucenter.entity.ScenePlus;
|
|
|
|
+import com.fdkankan.ucenter.entity.ScenePlusExt;
|
|
|
|
+import com.fdkankan.ucenter.entity.ScenePro;
|
|
|
|
+import com.fdkankan.ucenter.entity.SceneRepairLog;
|
|
|
|
+import com.fdkankan.ucenter.mapper.ISceneUpgradeMapper;
|
|
|
|
+import com.fdkankan.ucenter.service.ISceneEditControlsService;
|
|
|
|
+import com.fdkankan.ucenter.service.ISceneEditInfoExtService;
|
|
|
|
+import com.fdkankan.ucenter.service.ISceneEditInfoService;
|
|
|
|
+import com.fdkankan.ucenter.service.IScenePlusExtService;
|
|
|
|
+import com.fdkankan.ucenter.service.IScenePlusService;
|
|
|
|
+import com.fdkankan.ucenter.service.ISceneProEditService;
|
|
|
|
+import com.fdkankan.ucenter.service.ISceneProService;
|
|
|
|
+import com.fdkankan.ucenter.service.ISceneRepairLogService;
|
|
|
|
+import com.fdkankan.ucenter.service.ISceneUpgradeToV4Service;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.Objects;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * <p>
|
|
|
|
+ * TODO
|
|
|
|
+ * </p>
|
|
|
|
+ *
|
|
|
|
+ * @author dengsixing
|
|
|
|
+ * @since 2022/4/21
|
|
|
|
+ **/
|
|
|
|
+@Slf4j
|
|
|
|
+@Service
|
|
|
|
+public class SceneUpgradeToV4Service implements ISceneUpgradeToV4Service {
|
|
|
|
+
|
|
|
|
+ @Value("${queue.scene.upgrade-to-v4}")
|
|
|
|
+ private String upgradeToV4;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ISceneRepairLogService sceneRepairLogService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ISceneProService sceneProService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IScenePlusExtService scenePlusExtService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IScenePlusService scenePlusService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ISceneUpgradeMapper sceneUpgradeMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private RedisUtil redisUtil;
|
|
|
|
+ @Autowired
|
|
|
|
+ private RedisLockUtil redisLockUtil;
|
|
|
|
+ @Autowired
|
|
|
|
+ private RabbitMqProducer rabbitMqProducer;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Result upgrade(String num) throws Exception{
|
|
|
|
+
|
|
|
|
+ ScenePro scenePro = sceneProService.getByNum(num);
|
|
|
|
+
|
|
|
|
+ //加锁
|
|
|
|
+ String lockKey = String.format(RedisLockKey.LOCK_SCENE_UPGRADE_V4, num);
|
|
|
|
+ boolean lock = redisLockUtil.lock(lockKey,RedisKey.EXPIRE_TIME_2_HOUR);
|
|
|
|
+ if(!lock){
|
|
|
|
+ return Result.failure(ErrorCode.FAILURE_CODE_7019.code(), ErrorCode.FAILURE_CODE_7019.message());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ //查询升级日志,如果已经升级成功,不允许重复升级
|
|
|
|
+ SceneRepairLog sceneRepairLog = sceneRepairLogService.getOne(
|
|
|
|
+ new LambdaQueryWrapper<SceneRepairLog>()
|
|
|
|
+ .eq(SceneRepairLog::getNum, num));
|
|
|
|
+ if(Objects.nonNull(sceneRepairLog)){
|
|
|
|
+ if(sceneRepairLog.getState() == 0){
|
|
|
|
+ redisLockUtil.unlockLua(lockKey);
|
|
|
|
+ return Result.failure(ErrorCode.FAILURE_CODE_7019.code(), ErrorCode.FAILURE_CODE_7019.message());
|
|
|
|
+ }
|
|
|
|
+// if(!param.isReUpgrade()){
|
|
|
|
+// if(sceneRepairLog.getState() == 1){
|
|
|
|
+// redisLockUtil.unlockLua(lockKey);
|
|
|
|
+// return ResultData.error(ErrorCode.FAILURE_CODE_7020);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //同步到scenePlus、scenePlus
|
|
|
|
+ sceneUpgradeMapper.deleteScenePlus(scenePro.getId());
|
|
|
|
+ sceneUpgradeMapper.transferScenePlus(scenePro.getId());
|
|
|
|
+ sceneUpgradeMapper.deleteScenePlusExt(scenePro.getId());
|
|
|
|
+ String sceneKind = scenePro.getSceneScheme() == 3 ? SceneKind.FACE.code():SceneKind.TILES.code();
|
|
|
|
+ sceneUpgradeMapper.transferScenePlusExt(scenePro.getId(), sceneKind);
|
|
|
|
+
|
|
|
|
+ //国际版需要兼容切片图
|
|
|
|
+ ScenePlus scenePlus = scenePlusService.getById(scenePro.getId());
|
|
|
|
+ ScenePlusExt scenePlusExt = scenePlusExtService.getByPlusId(scenePlus.getId());
|
|
|
|
+ if(scenePlusExt.getSceneScheme() == 3){
|
|
|
|
+ scenePlusExt.setSceneResolution(SceneResolution.TILES.code());
|
|
|
|
+ scenePlusExtService.updateById(scenePlusExt);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //发送mq
|
|
|
|
+ rabbitMqProducer.sendByWorkQueue(upgradeToV4, scenePro.getId());
|
|
|
|
+
|
|
|
|
+ //写入进度条
|
|
|
|
+ Map<String, Integer> progress = new HashMap<>();
|
|
|
|
+ progress.put("status", 0);
|
|
|
|
+ progress.put("progress", 0);
|
|
|
|
+ redisUtil.set(RedisKey.scene_upgrade_progress_num, JSON.toJSONString(progress));
|
|
|
|
+
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ log.error("场景升级失败", e);
|
|
|
|
+ return Result.failure(ErrorCode.FAILURE_CODE_7021.code(), ErrorCode.FAILURE_CODE_7021.message());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return Result.success();
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Result getUpgradeToV4Progress(String num){
|
|
|
|
+ String key = String.format(RedisKey.scene_upgrade_progress_num, num);
|
|
|
|
+ String progress = redisUtil.get(key);
|
|
|
|
+ SceneUpgradeProgressBean progressBean = null;
|
|
|
|
+ if(StrUtil.isNotEmpty(progress)){
|
|
|
|
+ progressBean = JSON.parseObject(progress, SceneUpgradeProgressBean.class);
|
|
|
|
+ }else{
|
|
|
|
+ progressBean = SceneUpgradeProgressBean.builder().num(num).status(0).progress(0).build();
|
|
|
|
+ }
|
|
|
|
+ return Result.success(progressBean);
|
|
|
|
+ }
|
|
|
|
+}
|