| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- package com.fdkankan.task.service.impl;
- import cn.hutool.core.collection.CollUtil;
- import cn.hutool.core.io.FileUtil;
- 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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.fdkankan.common.constant.ConstantFilePath;
- import com.fdkankan.common.constant.UploadFilePath;
- import com.fdkankan.fyun.oss.UploadToOssUtil;
- import com.fdkankan.redis.constant.RedisKey;
- import com.fdkankan.redis.util.RedisUtil;
- import com.fdkankan.task.constant.TaskConstant;
- import com.fdkankan.task.entity.ScenePlus;
- import com.fdkankan.task.entity.ScenePlusExt;
- import com.fdkankan.task.mapper.IScenePlusMapper;
- import com.fdkankan.task.service.IScenePlusExtService;
- import com.fdkankan.task.service.IScenePlusService;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.List;
- /**
- * <p>
- * 场景主表 服务实现类
- * </p>
- *
- * @author
- * @since 2022-03-16
- */
- @Slf4j
- @Service
- public class ScenePlusServiceImpl extends ServiceImpl<IScenePlusMapper, ScenePlus> implements IScenePlusService {
- @Autowired
- private IScenePlusExtService scenePlusExtService;
- @Autowired
- private UploadToOssUtil uploadToOssUtil;
- @Autowired
- private RedisUtil redisUtil;
- @Override
- public ScenePlus getScenePlusByNumWithDelete(String num) {
- return null;
- }
- @Override
- public ScenePlus getScenePlusByNum(String num) {
- return this.getOne(new LambdaQueryWrapper<ScenePlus>().eq(ScenePlus::getNum, num));
- }
- public void deleteV3DirHandler(String num){
- try {
- log.info("删除v3目录开始,num:{}", num);
- String dataPath = String.format(TaskConstant.dataPathFormat, num);
- ScenePlus scenePlus = this.getScenePlusByNum(num);
- ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
- String bucket = scenePlusExt.getYunFileBucket();
- String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
- String sceneJsonPath = dataViewPath + "scene.json";
- if(StrUtil.isNotEmpty(scenePlusExt.getVideos()) && scenePlusExt.getVideos().contains(dataPath)){
- scenePlusExt.setVideos(scenePlusExt.getVideos().replaceAll(dataPath, dataViewPath));
- scenePlusExtService.updateById(scenePlusExt);
- String sceneJson = uploadToOssUtil.getObjectContent(bucket, sceneJsonPath);
- JSONObject sceneJsonObj = JSON.parseObject(sceneJson);
- sceneJsonObj.put("videos", JSON.parseObject(scenePlusExt.getVideos()));
- uploadToOssUtil.upload(bucket, sceneJsonObj.toJSONString().getBytes(), sceneJsonPath);
- redisUtil.del(String.format(RedisKey.SCENE_JSON, num));
- }
- //删除data目录
- List<String> dataList = uploadToOssUtil.listKeys(bucket, dataPath);
- if(CollUtil.isNotEmpty(dataList)){
- uploadToOssUtil.deleteFile(bucket, dataPath);
- }
- //删除img目录
- String imgPath = String.format(TaskConstant.imgPathFormat, num);
- List<String> imgList = uploadToOssUtil.listKeys(bucket, imgPath);
- if(CollUtil.isNotEmpty(imgList)){
- uploadToOssUtil.deleteFile(bucket, imgPath);
- }
- //删除video目录
- String videoPath = String.format(TaskConstant.videoPathFormat, num);
- List<String> videoList = uploadToOssUtil.listKeys(bucket, videoPath);
- if(CollUtil.isNotEmpty(videoList)){
- uploadToOssUtil.deleteFile(bucket, videoPath);
- }
- //删除voice目录
- String voicePath = String.format(TaskConstant.voicePathFormat, num);
- List<String> voiceList = uploadToOssUtil.listKeys(bucket, voicePath);
- if(CollUtil.isNotEmpty(voiceList)){
- uploadToOssUtil.deleteFile(bucket, voicePath);
- }
- redisUtil.sSet(TaskConstant.numKey, num);
- log.info("删除v3目录完毕,num:{}", num);
- }catch (Exception e){
- log.info("删除v3目录失败,num:" + num, e);
- }
- }
- public void deleteSceneHandler(String num){
- try {
- log.info("删除场景全部数据开始,num:{}", num);
- ScenePlus scenePlus = this.baseMapper.selectDeleteScene(num);
- ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
- String bucket = scenePlusExt.getYunFileBucket();
- //删除data目录
- String dataPath = String.format(TaskConstant.dataPathFormat, num);
- List<String> dataList = uploadToOssUtil.listKeys(bucket, dataPath);
- if(CollUtil.isNotEmpty(dataList)){
- uploadToOssUtil.deleteFile(bucket, dataPath);
- }
- //删除img目录
- String imgPath = String.format(TaskConstant.imgPathFormat, num);
- List<String> imgList = uploadToOssUtil.listKeys(bucket, imgPath);
- if(CollUtil.isNotEmpty(imgList)){
- uploadToOssUtil.deleteFile(bucket, imgPath);
- }
- //删除video目录
- String videoPath = String.format(TaskConstant.videoPathFormat, num);
- List<String> videoList = uploadToOssUtil.listKeys(bucket, videoPath);
- if(CollUtil.isNotEmpty(videoList)){
- uploadToOssUtil.deleteFile(bucket, videoPath);
- }
- //删除voice目录
- String voicePath = String.format(TaskConstant.voicePathFormat, num);
- List<String> voiceList = uploadToOssUtil.listKeys(bucket, voicePath);
- if(CollUtil.isNotEmpty(voiceList)){
- uploadToOssUtil.deleteFile(bucket, voicePath);
- }
- //删除dataview目录
- String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
- List<String> dataViewList = uploadToOssUtil.listKeys(bucket, dataViewPath);
- if(CollUtil.isNotEmpty(dataViewList)){
- uploadToOssUtil.deleteFile(bucket, dataViewPath);
- }
- //删除img目录
- String imgViewPath = String.format(UploadFilePath.IMG_VIEW_PATH, num);
- List<String> imgViewList = uploadToOssUtil.listKeys(bucket, imgViewPath);
- if(CollUtil.isNotEmpty(imgViewList)){
- uploadToOssUtil.deleteFile(bucket, imgViewPath);
- }
- //删除video目录
- String videoViewPath = String.format(UploadFilePath.VIDEOS_VIEW_PATH, num);
- List<String> videoViewList = uploadToOssUtil.listKeys(bucket, videoViewPath);
- if(CollUtil.isNotEmpty(videoViewList)){
- uploadToOssUtil.deleteFile(bucket, videoViewPath);
- }
- //删除voice目录
- String voiceViewPath = String.format(UploadFilePath.VOICE_VIEW_PATH, num);
- List<String> voiceViewList = uploadToOssUtil.listKeys(bucket, voiceViewPath);
- if(CollUtil.isNotEmpty(voiceViewList)){
- uploadToOssUtil.deleteFile(bucket, voiceViewPath);
- }
- //删除user目录
- String userViewPath = String.format(UploadFilePath.USER_VIEW_PATH, num);
- List<String> userViewList = uploadToOssUtil.listKeys(bucket, userViewPath);
- if(CollUtil.isNotEmpty(userViewList)){
- uploadToOssUtil.deleteFile(bucket, userViewPath);
- }
- //删除user目录
- String userEditPath = String.format(UploadFilePath.USER_EDIT_PATH, num);
- List<String> userEditList = uploadToOssUtil.listKeys(bucket, userEditPath);
- if(CollUtil.isNotEmpty(userEditList)){
- uploadToOssUtil.deleteFile(bucket, userEditPath);
- }
- //删除nas目录
- String dataSource = scenePlusExt.getDataSource();
- if(dataSource.length() > "/mnt/data/".length()){
- FileUtil.del(dataSource);
- }
- redisUtil.sSet(TaskConstant.deleteNumKey, num);
- log.info("删除场景全部数据结束,num:{}", num);
- }catch (Exception e){
- log.error("删除场景全部数据失败,num:" + num, e);
- }
- }
- }
|